2010-07-02 14:09:48 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=4 sw=4 et tw=99 ft=cpp:
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-07-02 14:09:48 -07:00
|
|
|
|
|
|
|
#include "XrayWrapper.h"
|
|
|
|
#include "AccessCheck.h"
|
|
|
|
#include "FilteringWrapper.h"
|
2012-07-16 10:22:51 -07:00
|
|
|
#include "WaiveXrayWrapper.h"
|
2010-07-02 14:09:48 -07:00
|
|
|
#include "WrapperFactory.h"
|
|
|
|
|
2011-09-21 18:30:27 -07:00
|
|
|
#include "nsINode.h"
|
2013-03-21 17:05:20 -07:00
|
|
|
#include "nsIContent.h"
|
2011-09-21 18:30:27 -07:00
|
|
|
#include "nsIDocument.h"
|
2012-10-05 09:59:23 -07:00
|
|
|
#include "nsContentUtils.h"
|
2011-09-21 18:30:27 -07:00
|
|
|
|
2010-07-02 14:09:48 -07:00
|
|
|
#include "XPCWrapper.h"
|
|
|
|
#include "xpcprivate.h"
|
|
|
|
|
2012-01-15 00:13:11 -08:00
|
|
|
#include "jsapi.h"
|
2012-08-27 06:15:20 -07:00
|
|
|
#include "nsJSUtils.h"
|
2012-01-11 00:23:08 -08:00
|
|
|
|
2012-05-02 21:35:38 -07:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2013-01-17 09:30:37 -08:00
|
|
|
#include "nsGlobalWindow.h"
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2012-05-02 21:35:38 -07:00
|
|
|
using namespace mozilla::dom;
|
2013-03-27 04:33:30 -07:00
|
|
|
using namespace JS;
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
using js::PropertyDescriptor;
|
|
|
|
using js::Wrapper;
|
2010-07-02 14:09:48 -07:00
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
namespace xpc {
|
2010-07-02 14:09:48 -07:00
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
static const uint32_t JSSLOT_RESOLVING = 0;
|
2010-09-23 15:56:28 -07:00
|
|
|
|
2012-03-23 14:59:04 -07:00
|
|
|
static XPCWrappedNative *GetWrappedNative(JSObject *obj);
|
|
|
|
|
2010-09-23 15:56:28 -07:00
|
|
|
namespace XrayUtils {
|
|
|
|
|
2010-07-02 14:09:48 -07:00
|
|
|
JSClass HolderClass = {
|
|
|
|
"NativePropertyHolder",
|
2012-06-05 10:07:37 -07:00
|
|
|
JSCLASS_HAS_RESERVED_SLOTS(2),
|
2013-04-05 21:22:55 -07:00
|
|
|
JS_PropertyStub, JS_DeletePropertyStub, holder_get, holder_set,
|
2012-03-19 07:27:58 -07:00
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub
|
2010-07-02 14:09:48 -07:00
|
|
|
};
|
2012-10-05 09:59:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
using namespace XrayUtils;
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
XrayType
|
|
|
|
GetXrayType(JSObject *obj)
|
|
|
|
{
|
2013-04-11 11:50:18 -07:00
|
|
|
obj = js::UncheckedUnwrap(obj, /* stopAtOuter = */ false);
|
2012-10-09 11:50:27 -07:00
|
|
|
if (mozilla::dom::UseDOMXray(obj))
|
2012-10-05 09:59:23 -07:00
|
|
|
return XrayForDOMObject;
|
|
|
|
|
|
|
|
js::Class* clasp = js::GetObjectClass(obj);
|
|
|
|
if (IS_WRAPPER_CLASS(clasp) || clasp->ext.innerObject) {
|
|
|
|
NS_ASSERTION(clasp->ext.innerObject || IS_WN_WRAPPER_OBJECT(obj),
|
|
|
|
"We forgot to Morph a slim wrapper!");
|
|
|
|
return XrayForWrappedNative;
|
|
|
|
}
|
|
|
|
return NotXray;
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
ResolvingId::ResolvingId(JSObject *wrapper, jsid id)
|
|
|
|
: mId(id),
|
|
|
|
mHolder(getHolderObject(wrapper)),
|
|
|
|
mPrev(getResolvingId(mHolder)),
|
|
|
|
mXrayShadowing(false)
|
|
|
|
{
|
|
|
|
js::SetReservedSlot(mHolder, JSSLOT_RESOLVING, js::PrivateValue(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
ResolvingId::~ResolvingId()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(getResolvingId(mHolder) == this, "unbalanced ResolvingIds");
|
|
|
|
js::SetReservedSlot(mHolder, JSSLOT_RESOLVING, js::PrivateValue(mPrev));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ResolvingId::isXrayShadowing(jsid id)
|
|
|
|
{
|
|
|
|
if (!mXrayShadowing)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return mId == id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ResolvingId::isResolving(jsid id)
|
|
|
|
{
|
|
|
|
for (ResolvingId *cur = this; cur; cur = cur->mPrev) {
|
|
|
|
if (cur->mId == id)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResolvingId *
|
|
|
|
ResolvingId::getResolvingId(JSObject *holder)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(strcmp(JS_GetClass(holder)->name, "NativePropertyHolder") == 0);
|
|
|
|
return (ResolvingId *)js::GetReservedSlot(holder, JSSLOT_RESOLVING).toPrivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *
|
|
|
|
ResolvingId::getHolderObject(JSObject *wrapper)
|
|
|
|
{
|
|
|
|
return &js::GetProxyExtra(wrapper, 0).toObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
ResolvingId *
|
|
|
|
ResolvingId::getResolvingIdFromWrapper(JSObject *wrapper)
|
|
|
|
{
|
|
|
|
return getResolvingId(getHolderObject(wrapper));
|
|
|
|
}
|
|
|
|
|
|
|
|
class ResolvingIdDummy
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ResolvingIdDummy(JSObject *wrapper, jsid id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class XrayTraits
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static JSObject* getTargetObject(JSObject *wrapper) {
|
2013-04-11 11:50:18 -07:00
|
|
|
return js::UncheckedUnwrap(wrapper, /* stopAtOuter = */ false);
|
2012-10-05 09:59:23 -07:00
|
|
|
}
|
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
virtual bool resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper,
|
|
|
|
HandleObject wrapper, HandleObject holder,
|
|
|
|
HandleId id, JSPropertyDescriptor *desc, unsigned flags);
|
2012-10-05 09:59:23 -07:00
|
|
|
|
2013-04-04 00:02:24 -07:00
|
|
|
static bool call(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args)
|
2012-10-05 09:59:23 -07:00
|
|
|
{
|
|
|
|
MOZ_NOT_REACHED("Call trap currently implemented only for XPCWNs");
|
|
|
|
}
|
2013-04-04 00:02:24 -07:00
|
|
|
static bool construct(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args)
|
2012-10-05 09:59:23 -07:00
|
|
|
{
|
|
|
|
MOZ_NOT_REACHED("Call trap currently implemented only for XPCWNs");
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
virtual void preserveWrapper(JSObject *target) = 0;
|
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
JSObject* getExpandoObject(JSContext *cx, HandleObject target,
|
|
|
|
HandleObject consumer);
|
|
|
|
JSObject* ensureExpandoObject(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleObject target);
|
2012-10-05 09:59:23 -07:00
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
JSObject* getHolder(JSObject *wrapper);
|
2013-03-27 04:33:30 -07:00
|
|
|
JSObject* ensureHolder(JSContext *cx, HandleObject wrapper);
|
2012-10-05 09:59:23 -07:00
|
|
|
virtual JSObject* createHolder(JSContext *cx, JSObject *wrapper) = 0;
|
2012-10-05 09:59:23 -07:00
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
virtual JSObject* getExpandoChain(JSObject *obj) = 0;
|
|
|
|
virtual void setExpandoChain(JSObject *obj, JSObject *chain) = 0;
|
2013-03-27 04:33:30 -07:00
|
|
|
bool cloneExpandoChain(JSContext *cx, HandleObject dst, HandleObject src);
|
2012-10-05 09:59:23 -07:00
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
private:
|
2013-03-27 04:33:30 -07:00
|
|
|
bool expandoObjectMatchesConsumer(JSContext *cx, HandleObject expandoObject,
|
2012-10-05 09:59:23 -07:00
|
|
|
nsIPrincipal *consumerOrigin,
|
2013-03-27 04:33:30 -07:00
|
|
|
HandleObject exclusiveGlobal);
|
|
|
|
JSObject* getExpandoObjectInternal(JSContext *cx, HandleObject target,
|
2012-10-05 09:59:23 -07:00
|
|
|
nsIPrincipal *origin,
|
|
|
|
JSObject *exclusiveGlobal);
|
2013-03-27 04:33:30 -07:00
|
|
|
JSObject* attachExpandoObject(JSContext *cx, HandleObject target,
|
2012-10-05 09:59:23 -07:00
|
|
|
nsIPrincipal *origin,
|
2013-03-27 04:33:30 -07:00
|
|
|
HandleObject exclusiveGlobal);
|
2012-10-05 09:59:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class XPCWrappedNativeXrayTraits : public XrayTraits
|
|
|
|
{
|
|
|
|
public:
|
2013-03-14 22:38:26 -07:00
|
|
|
static const XrayType Type = XrayForWrappedNative;
|
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
static bool resolveNativeProperty(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleObject holder, HandleId id,
|
2013-01-03 13:31:36 -08:00
|
|
|
JSPropertyDescriptor *desc, unsigned flags);
|
2013-03-27 04:33:30 -07:00
|
|
|
virtual bool resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper, HandleObject wrapper,
|
|
|
|
HandleObject holder, HandleId id,
|
|
|
|
JSPropertyDescriptor *desc, unsigned flags);
|
|
|
|
static bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id,
|
|
|
|
PropertyDescriptor *desc, PropertyDescriptor &existingDesc,
|
2013-01-14 02:29:48 -08:00
|
|
|
bool *defined);
|
2013-03-27 04:33:30 -07:00
|
|
|
static bool enumerateNames(JSContext *cx, HandleObject wrapper, unsigned flags,
|
|
|
|
AutoIdVector &props);
|
2013-04-04 00:02:24 -07:00
|
|
|
static bool call(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args);
|
|
|
|
static bool construct(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args);
|
2012-10-05 09:59:23 -07:00
|
|
|
|
|
|
|
static bool isResolving(JSContext *cx, JSObject *holder, jsid id);
|
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
static bool resolveDOMCollectionProperty(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleObject holder, HandleId id,
|
|
|
|
PropertyDescriptor *desc, unsigned flags);
|
2012-10-05 09:59:23 -07:00
|
|
|
|
|
|
|
static XPCWrappedNative* getWN(JSObject *wrapper) {
|
|
|
|
return GetWrappedNative(getTargetObject(wrapper));
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
virtual void preserveWrapper(JSObject *target);
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
typedef ResolvingId ResolvingIdImpl;
|
|
|
|
|
|
|
|
virtual JSObject* createHolder(JSContext *cx, JSObject *wrapper);
|
2012-10-05 09:59:23 -07:00
|
|
|
virtual JSObject* getExpandoChain(JSObject *obj) {
|
|
|
|
return GetWNExpandoChain(obj);
|
|
|
|
}
|
|
|
|
virtual void setExpandoChain(JSObject *obj, JSObject *chain) {
|
|
|
|
SetWNExpandoChain(obj, chain);
|
|
|
|
}
|
2012-10-05 09:59:23 -07:00
|
|
|
|
|
|
|
static XPCWrappedNativeXrayTraits singleton;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DOMXrayTraits : public XrayTraits
|
|
|
|
{
|
|
|
|
public:
|
2013-03-14 22:38:26 -07:00
|
|
|
static const XrayType Type = XrayForDOMObject;
|
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
static bool resolveNativeProperty(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleObject holder, HandleId id,
|
2013-01-03 13:31:36 -08:00
|
|
|
JSPropertyDescriptor *desc, unsigned flags);
|
2013-03-27 04:33:30 -07:00
|
|
|
virtual bool resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper, HandleObject wrapper,
|
|
|
|
HandleObject holder, HandleId id,
|
|
|
|
JSPropertyDescriptor *desc, unsigned flags);
|
2013-03-21 15:23:47 -07:00
|
|
|
static bool defineProperty(JSContext *cx, HandleObject wrapper, HandleId id,
|
2013-03-27 04:33:30 -07:00
|
|
|
PropertyDescriptor *desc, PropertyDescriptor &existingDesc,
|
2013-01-14 02:29:48 -08:00
|
|
|
bool *defined);
|
2013-03-27 04:33:30 -07:00
|
|
|
static bool enumerateNames(JSContext *cx, HandleObject wrapper, unsigned flags,
|
|
|
|
AutoIdVector &props);
|
2013-04-04 00:02:24 -07:00
|
|
|
static bool call(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args);
|
|
|
|
static bool construct(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args);
|
2012-10-05 09:59:23 -07:00
|
|
|
|
|
|
|
static bool isResolving(JSContext *cx, JSObject *holder, jsid id)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef ResolvingIdDummy ResolvingIdImpl;
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
virtual void preserveWrapper(JSObject *target);
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
virtual JSObject* createHolder(JSContext *cx, JSObject *wrapper);
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
virtual JSObject* getExpandoChain(JSObject *obj) {
|
2012-10-05 09:59:23 -07:00
|
|
|
return mozilla::dom::GetXrayExpandoChain(obj);
|
2012-10-05 09:59:23 -07:00
|
|
|
}
|
|
|
|
virtual void setExpandoChain(JSObject *obj, JSObject *chain) {
|
2012-10-05 09:59:23 -07:00
|
|
|
mozilla::dom::SetXrayExpandoChain(obj, chain);
|
2012-10-05 09:59:23 -07:00
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
static DOMXrayTraits singleton;
|
|
|
|
};
|
|
|
|
|
|
|
|
XPCWrappedNativeXrayTraits XPCWrappedNativeXrayTraits::singleton;
|
|
|
|
DOMXrayTraits DOMXrayTraits::singleton;
|
2010-07-02 14:09:48 -07:00
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
XrayTraits*
|
|
|
|
GetXrayTraits(JSObject *obj)
|
|
|
|
{
|
|
|
|
switch (GetXrayType(obj)) {
|
|
|
|
case XrayForDOMObject:
|
|
|
|
return &DOMXrayTraits::singleton;
|
|
|
|
case XrayForWrappedNative:
|
|
|
|
return &XPCWrappedNativeXrayTraits::singleton;
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-05 10:07:37 -07:00
|
|
|
/*
|
|
|
|
* Xray expando handling.
|
|
|
|
*
|
|
|
|
* We hang expandos for Xray wrappers off a reserved slot on the target object
|
|
|
|
* so that same-origin compartments can share expandos for a given object. We
|
|
|
|
* have a linked list of expando objects, one per origin. The properties on these
|
|
|
|
* objects are generally wrappers pointing back to the compartment that applied
|
|
|
|
* them.
|
|
|
|
*
|
|
|
|
* The expando objects should _never_ be exposed to script. The fact that they
|
|
|
|
* live in the target compartment is a detail of the implementation, and does
|
|
|
|
* not imply that code in the target compartment should be allowed to inspect
|
|
|
|
* them. They are private to the origin that placed them.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum ExpandoSlots {
|
|
|
|
JSSLOT_EXPANDO_NEXT = 0,
|
|
|
|
JSSLOT_EXPANDO_ORIGIN,
|
|
|
|
JSSLOT_EXPANDO_EXCLUSIVE_GLOBAL,
|
|
|
|
JSSLOT_EXPANDO_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
static nsIPrincipal*
|
|
|
|
ObjectPrincipal(JSObject *obj)
|
|
|
|
{
|
|
|
|
return GetCompartmentPrincipal(js::GetObjectCompartment(obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIPrincipal*
|
|
|
|
GetExpandoObjectPrincipal(JSObject *expandoObject)
|
|
|
|
{
|
2013-03-27 04:33:30 -07:00
|
|
|
Value v = JS_GetReservedSlot(expandoObject, JSSLOT_EXPANDO_ORIGIN);
|
2012-06-05 10:07:37 -07:00
|
|
|
return static_cast<nsIPrincipal*>(v.toPrivate());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ExpandoObjectFinalize(JSFreeOp *fop, JSObject *obj)
|
|
|
|
{
|
|
|
|
// Release the principal.
|
|
|
|
nsIPrincipal *principal = GetExpandoObjectPrincipal(obj);
|
|
|
|
NS_RELEASE(principal);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSClass ExpandoObjectClass = {
|
|
|
|
"XrayExpandoObject",
|
|
|
|
JSCLASS_HAS_RESERVED_SLOTS(JSSLOT_EXPANDO_COUNT),
|
2013-04-05 21:22:55 -07:00
|
|
|
JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
|
2012-06-05 10:07:37 -07:00
|
|
|
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, ExpandoObjectFinalize
|
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
2012-10-05 09:59:23 -07:00
|
|
|
XrayTraits::expandoObjectMatchesConsumer(JSContext *cx,
|
2013-03-27 04:33:30 -07:00
|
|
|
HandleObject expandoObject,
|
2012-10-05 09:59:23 -07:00
|
|
|
nsIPrincipal *consumerOrigin,
|
2013-03-27 04:33:30 -07:00
|
|
|
HandleObject exclusiveGlobal)
|
2012-06-05 10:07:37 -07:00
|
|
|
{
|
2012-06-18 06:28:11 -07:00
|
|
|
MOZ_ASSERT(js::IsObjectInContextCompartment(expandoObject, cx));
|
|
|
|
|
2012-06-05 10:07:37 -07:00
|
|
|
// First, compare the principals.
|
|
|
|
nsIPrincipal *o = GetExpandoObjectPrincipal(expandoObject);
|
|
|
|
bool equal;
|
|
|
|
// Note that it's very important here to ignore document.domain. We
|
|
|
|
// pull the principal for the expando object off of the first consumer
|
|
|
|
// for a given origin, and freely share the expandos amongst multiple
|
|
|
|
// same-origin consumers afterwards. However, this means that we have
|
|
|
|
// no way to know whether _all_ consumers have opted in to collaboration
|
|
|
|
// by explicitly setting document.domain. So we just mandate that expando
|
|
|
|
// sharing is unaffected by it.
|
|
|
|
nsresult rv = consumerOrigin->EqualsIgnoringDomain(o, &equal);
|
|
|
|
if (NS_FAILED(rv) || !equal)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Sandboxes want exclusive expando objects.
|
|
|
|
JSObject *owner = JS_GetReservedSlot(expandoObject,
|
|
|
|
JSSLOT_EXPANDO_EXCLUSIVE_GLOBAL)
|
|
|
|
.toObjectOrNull();
|
|
|
|
if (!owner && !exclusiveGlobal)
|
|
|
|
return true;
|
2012-06-18 06:28:11 -07:00
|
|
|
|
|
|
|
// The exclusive global should always be wrapped in the target's compartment.
|
|
|
|
MOZ_ASSERT(!exclusiveGlobal || js::IsObjectInContextCompartment(exclusiveGlobal, cx));
|
|
|
|
MOZ_ASSERT(!owner || js::IsObjectInContextCompartment(owner, cx));
|
2012-06-05 10:07:37 -07:00
|
|
|
return owner == exclusiveGlobal;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayTraits::getExpandoObjectInternal(JSContext *cx, HandleObject target,
|
2012-10-05 09:59:23 -07:00
|
|
|
nsIPrincipal *origin,
|
2013-04-15 07:29:37 -07:00
|
|
|
JSObject *exclusiveGlobalArg)
|
2012-06-05 10:07:37 -07:00
|
|
|
{
|
2012-06-18 06:28:11 -07:00
|
|
|
// The expando object lives in the compartment of the target, so all our
|
|
|
|
// work needs to happen there.
|
2013-04-15 07:29:37 -07:00
|
|
|
RootedObject exclusiveGlobal(cx, exclusiveGlobalArg);
|
2012-08-21 18:42:53 -07:00
|
|
|
JSAutoCompartment ac(cx, target);
|
2013-03-27 04:33:30 -07:00
|
|
|
if (!JS_WrapObject(cx, exclusiveGlobal.address()))
|
2012-06-18 06:28:11 -07:00
|
|
|
return NULL;
|
|
|
|
|
2012-06-05 10:07:37 -07:00
|
|
|
// Iterate through the chain, looking for a same-origin object.
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject head(cx, getExpandoChain(target));
|
2012-06-05 10:07:37 -07:00
|
|
|
while (head) {
|
2012-10-05 09:59:23 -07:00
|
|
|
if (expandoObjectMatchesConsumer(cx, head, origin, exclusiveGlobal))
|
2012-06-05 10:07:37 -07:00
|
|
|
return head;
|
|
|
|
head = JS_GetReservedSlot(head, JSSLOT_EXPANDO_NEXT).toObjectOrNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not found.
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-06-05 10:07:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayTraits::getExpandoObject(JSContext *cx, HandleObject target, HandleObject consumer)
|
2012-06-05 10:07:37 -07:00
|
|
|
{
|
|
|
|
JSObject *consumerGlobal = js::GetGlobalForObjectCrossCompartment(consumer);
|
|
|
|
bool isSandbox = !strcmp(js::GetObjectJSClass(consumerGlobal)->name, "Sandbox");
|
2012-10-05 09:59:23 -07:00
|
|
|
return getExpandoObjectInternal(cx, target, ObjectPrincipal(consumer),
|
|
|
|
isSandbox ? consumerGlobal : nullptr);
|
2012-06-05 10:07:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayTraits::attachExpandoObject(JSContext *cx, HandleObject target,
|
|
|
|
nsIPrincipal *origin, HandleObject exclusiveGlobal)
|
2012-06-05 10:07:37 -07:00
|
|
|
{
|
2012-06-18 06:28:11 -07:00
|
|
|
// Make sure the compartments are sane.
|
|
|
|
MOZ_ASSERT(js::IsObjectInContextCompartment(target, cx));
|
|
|
|
MOZ_ASSERT(!exclusiveGlobal || js::IsObjectInContextCompartment(exclusiveGlobal, cx));
|
|
|
|
|
2012-06-05 10:07:37 -07:00
|
|
|
// No duplicates allowed.
|
2012-10-05 09:59:23 -07:00
|
|
|
MOZ_ASSERT(!getExpandoObjectInternal(cx, target, origin, exclusiveGlobal));
|
2012-06-05 10:07:37 -07:00
|
|
|
|
|
|
|
// Create the expando object. We parent it directly to the target object.
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject expandoObject(cx, JS_NewObjectWithGivenProto(cx, &ExpandoObjectClass,
|
|
|
|
nullptr, target));
|
2012-06-05 10:07:37 -07:00
|
|
|
if (!expandoObject)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-06-05 10:07:37 -07:00
|
|
|
|
|
|
|
// AddRef and store the principal.
|
|
|
|
NS_ADDREF(origin);
|
|
|
|
JS_SetReservedSlot(expandoObject, JSSLOT_EXPANDO_ORIGIN, PRIVATE_TO_JSVAL(origin));
|
|
|
|
|
|
|
|
// Note the exclusive global, if any.
|
|
|
|
JS_SetReservedSlot(expandoObject, JSSLOT_EXPANDO_EXCLUSIVE_GLOBAL,
|
|
|
|
OBJECT_TO_JSVAL(exclusiveGlobal));
|
|
|
|
|
|
|
|
// If this is our first expando object, take the opportunity to preserve
|
|
|
|
// the wrapper. This keeps our expandos alive even if the Xray wrapper gets
|
|
|
|
// collected.
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject chain(cx, getExpandoChain(target));
|
2012-10-05 09:59:23 -07:00
|
|
|
if (!chain)
|
|
|
|
preserveWrapper(target);
|
2012-06-05 10:07:37 -07:00
|
|
|
|
|
|
|
// Insert it at the front of the chain.
|
|
|
|
JS_SetReservedSlot(expandoObject, JSSLOT_EXPANDO_NEXT, OBJECT_TO_JSVAL(chain));
|
2012-10-05 09:59:23 -07:00
|
|
|
setExpandoChain(target, expandoObject);
|
2012-06-05 10:07:37 -07:00
|
|
|
|
|
|
|
return expandoObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayTraits::ensureExpandoObject(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleObject target)
|
2012-06-05 10:07:37 -07:00
|
|
|
{
|
2012-06-18 06:28:11 -07:00
|
|
|
// Expando objects live in the target compartment.
|
2012-08-21 18:42:53 -07:00
|
|
|
JSAutoCompartment ac(cx, target);
|
2012-10-05 09:59:23 -07:00
|
|
|
JSObject *expandoObject = getExpandoObject(cx, target, wrapper);
|
2012-06-05 10:07:37 -07:00
|
|
|
if (!expandoObject) {
|
|
|
|
// If the object is a sandbox, we don't want it to share expandos with
|
|
|
|
// anyone else, so we tag it with the sandbox global.
|
2012-06-18 06:28:11 -07:00
|
|
|
//
|
|
|
|
// NB: We first need to check the class, _then_ wrap for the target's
|
|
|
|
// compartment.
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject consumerGlobal(cx, js::GetGlobalForObjectCrossCompartment(wrapper));
|
2012-06-05 10:07:37 -07:00
|
|
|
bool isSandbox = !strcmp(js::GetObjectJSClass(consumerGlobal)->name, "Sandbox");
|
2013-03-27 04:33:30 -07:00
|
|
|
if (!JS_WrapObject(cx, consumerGlobal.address()))
|
2012-06-18 06:28:11 -07:00
|
|
|
return NULL;
|
2012-10-05 09:59:23 -07:00
|
|
|
expandoObject = attachExpandoObject(cx, target, ObjectPrincipal(wrapper),
|
2013-03-27 04:33:30 -07:00
|
|
|
isSandbox ? (HandleObject)consumerGlobal : NullPtr());
|
2012-06-05 10:07:37 -07:00
|
|
|
}
|
|
|
|
return expandoObject;
|
|
|
|
}
|
|
|
|
|
2012-06-05 10:07:37 -07:00
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayTraits::cloneExpandoChain(JSContext *cx, HandleObject dst, HandleObject src)
|
2012-06-05 10:07:37 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(js::IsObjectInContextCompartment(dst, cx));
|
2012-10-05 09:59:23 -07:00
|
|
|
MOZ_ASSERT(getExpandoChain(dst) == nullptr);
|
2012-06-05 10:07:37 -07:00
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject oldHead(cx, getExpandoChain(src));
|
2012-06-05 10:07:37 -07:00
|
|
|
while (oldHead) {
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject exclusive(cx, JS_GetReservedSlot(oldHead,
|
|
|
|
JSSLOT_EXPANDO_EXCLUSIVE_GLOBAL)
|
|
|
|
.toObjectOrNull());
|
|
|
|
if (!JS_WrapObject(cx, exclusive.address()))
|
2012-06-18 06:28:11 -07:00
|
|
|
return false;
|
2012-10-05 09:59:23 -07:00
|
|
|
JSObject *newHead = attachExpandoObject(cx, dst, GetExpandoObjectPrincipal(oldHead),
|
|
|
|
exclusive);
|
2012-06-05 10:07:37 -07:00
|
|
|
if (!JS_CopyPropertiesFrom(cx, newHead, oldHead))
|
|
|
|
return false;
|
|
|
|
oldHead = JS_GetReservedSlot(oldHead, JSSLOT_EXPANDO_NEXT).toObjectOrNull();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-10-05 09:59:23 -07:00
|
|
|
|
|
|
|
namespace XrayUtils {
|
2013-04-15 07:29:37 -07:00
|
|
|
bool CloneExpandoChain(JSContext *cx, JSObject *dstArg, JSObject *srcArg)
|
2012-10-05 09:59:23 -07:00
|
|
|
{
|
2013-04-15 07:29:37 -07:00
|
|
|
RootedObject dst(cx, dstArg);
|
|
|
|
RootedObject src(cx, srcArg);
|
2012-10-05 09:59:23 -07:00
|
|
|
return GetXrayTraits(src)->cloneExpandoChain(cx, dst, src);
|
|
|
|
}
|
|
|
|
}
|
2012-10-05 09:59:22 -07:00
|
|
|
|
2010-09-23 15:56:28 -07:00
|
|
|
static JSObject *
|
|
|
|
GetHolder(JSObject *obj)
|
|
|
|
{
|
2011-05-23 08:39:25 -07:00
|
|
|
return &js::GetProxyExtra(obj, 0).toObject();
|
2010-09-23 15:56:28 -07:00
|
|
|
}
|
|
|
|
|
2010-07-02 14:09:48 -07:00
|
|
|
static XPCWrappedNative *
|
|
|
|
GetWrappedNative(JSObject *obj)
|
|
|
|
{
|
2012-03-27 16:31:37 -07:00
|
|
|
MOZ_ASSERT(IS_WN_WRAPPER_OBJECT(obj));
|
2011-10-04 07:06:54 -07:00
|
|
|
return static_cast<XPCWrappedNative *>(js::GetObjectPrivate(obj));
|
2010-07-02 14:09:48 -07:00
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
JSObject*
|
|
|
|
XrayTraits::getHolder(JSObject *wrapper)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(WrapperFactory::IsXrayWrapper(wrapper));
|
|
|
|
js::Value v = js::GetProxyExtra(wrapper, 0);
|
|
|
|
return v.isObject() ? &v.toObject() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayTraits::ensureHolder(JSContext *cx, HandleObject wrapper)
|
2012-10-05 09:59:23 -07:00
|
|
|
{
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject holder(cx, getHolder(wrapper));
|
2012-10-05 09:59:23 -07:00
|
|
|
if (holder)
|
|
|
|
return holder;
|
|
|
|
holder = createHolder(cx, wrapper); // virtual trap.
|
|
|
|
if (holder)
|
|
|
|
js::SetProxyExtra(wrapper, 0, ObjectValue(*holder));
|
|
|
|
return holder;
|
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
bool
|
|
|
|
XPCWrappedNativeXrayTraits::isResolving(JSContext *cx, JSObject *holder,
|
|
|
|
jsid id)
|
|
|
|
{
|
2013-03-18 08:58:05 -07:00
|
|
|
ResolvingId *cur = ResolvingId::getResolvingId(holder);
|
|
|
|
if (!cur)
|
|
|
|
return false;
|
|
|
|
return cur->isResolving(id);
|
2012-03-27 16:31:37 -07:00
|
|
|
}
|
|
|
|
|
2010-07-02 14:09:48 -07:00
|
|
|
// Some DOM objects have shared properties that don't have an explicit
|
|
|
|
// getter/setter and rely on the class getter/setter. We install a
|
|
|
|
// class getter/setter on the holder object to trigger them.
|
2012-04-19 11:19:41 -07:00
|
|
|
JSBool
|
2013-04-08 12:51:24 -07:00
|
|
|
holder_get(JSContext *cx, HandleObject wrapper, HandleId id, MutableHandleValue vp)
|
2010-07-02 14:09:48 -07:00
|
|
|
{
|
2013-04-08 12:51:24 -07:00
|
|
|
// JSClass::getProperty is wacky enough that it's hard to be sure someone
|
|
|
|
// can't inherit this getter by prototyping a random object to an
|
|
|
|
// XrayWrapper. Be safe.
|
|
|
|
NS_ENSURE_TRUE(WrapperFactory::IsXrayWrapper(wrapper), true);
|
2010-09-23 15:56:28 -07:00
|
|
|
JSObject *holder = GetHolder(wrapper);
|
2010-09-02 16:02:51 -07:00
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
XPCWrappedNative *wn = XPCWrappedNativeXrayTraits::getWN(wrapper);
|
2010-07-02 14:09:48 -07:00
|
|
|
if (NATIVE_HAS_FLAG(wn, WantGetProperty)) {
|
2012-08-21 18:42:53 -07:00
|
|
|
JSAutoCompartment ac(cx, holder);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool retval = true;
|
2012-03-27 16:31:37 -07:00
|
|
|
nsresult rv = wn->GetScriptableCallback()->GetProperty(wn, cx, wrapper,
|
2012-07-30 04:19:09 -07:00
|
|
|
id, vp.address(), &retval);
|
2011-02-15 19:00:55 -08:00
|
|
|
if (NS_FAILED(rv) || !retval) {
|
2010-09-23 15:56:28 -07:00
|
|
|
if (retval)
|
2010-07-02 14:09:48 -07:00
|
|
|
XPCThrower::Throw(rv, cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-19 11:19:41 -07:00
|
|
|
JSBool
|
2013-04-08 12:51:24 -07:00
|
|
|
holder_set(JSContext *cx, HandleObject wrapper, HandleId id, JSBool strict, MutableHandleValue vp)
|
2010-07-02 14:09:48 -07:00
|
|
|
{
|
2013-04-08 12:51:24 -07:00
|
|
|
// JSClass::setProperty is wacky enough that it's hard to be sure someone
|
|
|
|
// can't inherit this getter by prototyping a random object to an
|
|
|
|
// XrayWrapper. Be safe.
|
|
|
|
NS_ENSURE_TRUE(WrapperFactory::IsXrayWrapper(wrapper), true);
|
2010-09-23 15:56:28 -07:00
|
|
|
JSObject *holder = GetHolder(wrapper);
|
2012-03-27 16:31:37 -07:00
|
|
|
if (XPCWrappedNativeXrayTraits::isResolving(cx, holder, id)) {
|
2010-10-10 15:39:23 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
XPCWrappedNative *wn = XPCWrappedNativeXrayTraits::getWN(wrapper);
|
2010-07-02 14:09:48 -07:00
|
|
|
if (NATIVE_HAS_FLAG(wn, WantSetProperty)) {
|
2012-08-21 18:42:53 -07:00
|
|
|
JSAutoCompartment ac(cx, holder);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool retval = true;
|
2012-03-27 16:31:37 -07:00
|
|
|
nsresult rv = wn->GetScriptableCallback()->SetProperty(wn, cx, wrapper,
|
2012-07-30 04:19:09 -07:00
|
|
|
id, vp.address(), &retval);
|
2011-02-15 19:00:55 -08:00
|
|
|
if (NS_FAILED(rv) || !retval) {
|
2010-09-23 15:56:28 -07:00
|
|
|
if (retval)
|
2010-07-02 14:09:48 -07:00
|
|
|
XPCThrower::Throw(rv, cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-27 06:06:34 -07:00
|
|
|
class AutoSetWrapperNotShadowing
|
|
|
|
{
|
|
|
|
public:
|
2013-04-07 01:18:58 -07:00
|
|
|
AutoSetWrapperNotShadowing(ResolvingId *resolvingId MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-08-27 06:06:34 -07:00
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2013-04-07 01:18:58 -07:00
|
|
|
MOZ_ASSERT(resolvingId);
|
|
|
|
mResolvingId = resolvingId;
|
2012-08-27 06:06:34 -07:00
|
|
|
mResolvingId->mXrayShadowing = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSetWrapperNotShadowing()
|
|
|
|
{
|
|
|
|
mResolvingId->mXrayShadowing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
ResolvingId *mResolvingId;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This is called after the resolveNativeProperty could not find any property
|
|
|
|
// with the given id. At this point we can check for DOM specific collections
|
|
|
|
// like document["formName"] because we already know that it is not shadowing
|
|
|
|
// any native property.
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XPCWrappedNativeXrayTraits::resolveDOMCollectionProperty(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleObject holder, HandleId id,
|
2013-01-03 13:31:36 -08:00
|
|
|
PropertyDescriptor *desc, unsigned flags)
|
2012-08-27 06:06:34 -07:00
|
|
|
{
|
|
|
|
// If we are not currently resolving this id and resolveNative is called
|
|
|
|
// we don't do anything. (see defineProperty in case of shadowing is forbidden).
|
|
|
|
ResolvingId *rid = ResolvingId::getResolvingId(holder);
|
|
|
|
if (!rid || rid->mId != id)
|
|
|
|
return true;
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
XPCWrappedNative *wn = getWN(wrapper);
|
2013-04-07 01:18:58 -07:00
|
|
|
if (!wn) {
|
|
|
|
// This should NEVER happen, but let's be extra careful here
|
2013-04-12 20:04:51 -07:00
|
|
|
// because of the reported crashes (Bug 832091).
|
2013-04-07 01:18:58 -07:00
|
|
|
XPCThrower::Throw(NS_ERROR_UNEXPECTED, cx);
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-27 06:06:34 -07:00
|
|
|
if (!NATIVE_HAS_FLAG(wn, WantNewResolve))
|
|
|
|
return true;
|
|
|
|
|
2013-04-07 01:18:58 -07:00
|
|
|
ResolvingId *resolvingId = ResolvingId::getResolvingIdFromWrapper(wrapper);
|
|
|
|
if (!resolvingId) {
|
|
|
|
// This should NEVER happen, but let's be extra careful here
|
|
|
|
// becaue of the reported crashes (Bug 832091).
|
|
|
|
XPCThrower::Throw(NS_ERROR_UNEXPECTED, cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-27 06:06:34 -07:00
|
|
|
// Setting the current ResolvingId in non-shadowing mode. So for this id
|
|
|
|
// Xray won't ignore DOM specific collection properties temporarily.
|
2013-04-07 01:18:58 -07:00
|
|
|
AutoSetWrapperNotShadowing asw(resolvingId);
|
2012-08-27 06:06:34 -07:00
|
|
|
|
|
|
|
bool retval = true;
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject pobj(cx);
|
2012-08-27 06:06:34 -07:00
|
|
|
nsresult rv = wn->GetScriptableInfo()->GetCallback()->NewResolve(wn, cx, wrapper, id,
|
2013-03-27 04:33:30 -07:00
|
|
|
flags, pobj.address(), &retval);
|
2012-08-27 06:06:34 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (retval)
|
|
|
|
XPCThrower::Throw(rv, cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-15 11:19:55 -07:00
|
|
|
if (pobj && !JS_GetPropertyDescriptorById(cx, holder, id, 0, desc))
|
2012-08-27 06:06:34 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-27 06:15:20 -07:00
|
|
|
template <typename T>
|
2013-01-17 09:30:37 -08:00
|
|
|
static T*
|
|
|
|
As(JSObject *wrapper)
|
2012-08-27 06:15:20 -07:00
|
|
|
{
|
2012-10-05 09:59:23 -07:00
|
|
|
XPCWrappedNative *wn = XPCWrappedNativeXrayTraits::getWN(wrapper);
|
2012-08-27 06:15:20 -07:00
|
|
|
nsCOMPtr<T> native = do_QueryWrappedNative(wn);
|
2013-01-17 09:30:37 -08:00
|
|
|
return native;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static bool
|
|
|
|
Is(JSObject *wrapper)
|
|
|
|
{
|
|
|
|
return !!As<T>(wrapper);
|
2012-08-27 06:15:20 -07:00
|
|
|
}
|
|
|
|
|
2012-09-26 07:17:51 -07:00
|
|
|
static nsQueryInterface
|
2013-03-27 04:33:30 -07:00
|
|
|
do_QueryInterfaceNative(JSContext* cx, HandleObject wrapper);
|
2012-09-26 07:17:51 -07:00
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
// Helper function to work around some limitations of the current XPC
|
2012-08-27 06:15:20 -07:00
|
|
|
// calling mechanism. See: bug 763897.
|
|
|
|
// The idea is that we unwrap the 'this' object, and find the wrapped
|
|
|
|
// native that belongs to it. Then we simply make the call directly
|
|
|
|
// on it after a Query Interface.
|
|
|
|
static JSBool
|
|
|
|
mozMatchesSelectorStub(JSContext *cx, unsigned argc, jsval *vp)
|
|
|
|
{
|
2012-09-19 01:53:42 -07:00
|
|
|
if (argc < 1) {
|
2012-08-27 06:15:20 -07:00
|
|
|
JS_ReportError(cx, "Not enough arguments");
|
2012-09-19 01:53:42 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject wrapper(cx, JS_THIS_OBJECT(cx, vp));
|
|
|
|
RootedString selector(cx, JS_ValueToString(cx, JS_ARGV(cx, vp)[0]));
|
2012-10-06 09:06:24 -07:00
|
|
|
if (!selector) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-27 06:15:20 -07:00
|
|
|
nsDependentJSString selectorStr;
|
|
|
|
NS_ENSURE_TRUE(selectorStr.init(cx, selector), false);
|
|
|
|
|
2012-09-26 07:17:51 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterfaceNative(cx, wrapper);
|
2012-08-27 06:15:20 -07:00
|
|
|
if (!element) {
|
|
|
|
JS_ReportError(cx, "Unexpected object");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ret;
|
|
|
|
nsresult rv = element->MozMatchesSelector(selectorStr, &ret);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
XPCThrower::Throw(rv, cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
void
|
|
|
|
XPCWrappedNativeXrayTraits::preserveWrapper(JSObject *target)
|
|
|
|
{
|
|
|
|
XPCWrappedNative *wn =
|
|
|
|
static_cast<XPCWrappedNative *>(xpc_GetJSPrivate(target));
|
|
|
|
nsRefPtr<nsXPCClassInfo> ci;
|
|
|
|
CallQueryInterface(wn->Native(), getter_AddRefs(ci));
|
|
|
|
if (ci)
|
|
|
|
ci->PreserveWrapper(wn->Native());
|
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XPCWrappedNativeXrayTraits::resolveNativeProperty(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleObject holder, HandleId id,
|
2013-01-03 13:31:36 -08:00
|
|
|
JSPropertyDescriptor *desc, unsigned flags)
|
2010-07-02 14:09:48 -07:00
|
|
|
{
|
2012-08-27 06:15:20 -07:00
|
|
|
MOZ_ASSERT(js::GetObjectJSClass(holder) == &HolderClass);
|
|
|
|
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
|
2013-02-25 13:54:17 -08:00
|
|
|
if (id == rt->GetStringID(XPCJSRuntime::IDX_MOZMATCHESSELECTOR) &&
|
2012-08-27 06:15:20 -07:00
|
|
|
Is<nsIDOMElement>(wrapper))
|
|
|
|
{
|
|
|
|
// XPC calling mechanism cannot handle call/bind properly in some cases
|
2013-01-03 13:31:36 -08:00
|
|
|
// especially through xray wrappers. This is a temporary work around for
|
2012-08-27 06:15:20 -07:00
|
|
|
// this problem for mozMatchesSelector. See: bug 763897.
|
|
|
|
desc->obj = wrapper;
|
|
|
|
desc->attrs = JSPROP_ENUMERATE;
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject proto(cx);
|
|
|
|
if (!JS_GetPrototype(cx, wrapper, proto.address()))
|
2012-09-03 16:42:17 -07:00
|
|
|
return false;
|
2013-03-27 04:33:30 -07:00
|
|
|
JSFunction *fun = JS_NewFunction(cx, mozMatchesSelectorStub,
|
|
|
|
1, 0, proto,
|
2012-08-27 06:15:20 -07:00
|
|
|
"mozMatchesSelector");
|
|
|
|
NS_ENSURE_TRUE(fun, false);
|
|
|
|
desc->value = OBJECT_TO_JSVAL(JS_GetFunctionObject(fun));
|
|
|
|
desc->getter = NULL;
|
|
|
|
desc->setter = NULL;
|
|
|
|
desc->shortid = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-02 14:09:48 -07:00
|
|
|
desc->obj = NULL;
|
|
|
|
|
|
|
|
// This will do verification and the method lookup for us.
|
2012-10-05 09:59:23 -07:00
|
|
|
XPCCallContext ccx(JS_CALLER, cx, getTargetObject(wrapper), nullptr, id);
|
2010-07-02 14:09:48 -07:00
|
|
|
|
2012-08-27 06:06:34 -07:00
|
|
|
// There are no native numeric properties, so we can shortcut here. We will
|
|
|
|
// not find the property. However we want to support non shadowing dom
|
|
|
|
// specific collection properties like window.frames, so we still have to
|
|
|
|
// check for those.
|
2012-01-15 00:13:07 -08:00
|
|
|
if (!JSID_IS_STRING(id)) {
|
2010-07-02 14:09:48 -07:00
|
|
|
/* Not found */
|
2013-01-03 13:31:36 -08:00
|
|
|
return resolveDOMCollectionProperty(cx, wrapper, holder, id, desc, flags);
|
2010-07-02 14:09:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
XPCNativeInterface *iface;
|
|
|
|
XPCNativeMember *member;
|
2012-10-05 09:59:23 -07:00
|
|
|
XPCWrappedNative *wn = getWN(wrapper);
|
2013-04-07 01:18:58 -07:00
|
|
|
|
|
|
|
if (ccx.GetWrapper() != wn || !wn->IsValid()) {
|
|
|
|
// Something is wrong. If the wrapper is not even valid let's not risk
|
|
|
|
// calling resolveDOMCollectionProperty.
|
|
|
|
return true;
|
|
|
|
} else if (!(iface = ccx.GetInterface()) ||
|
|
|
|
!(member = ccx.GetMember())) {
|
2010-07-02 14:09:48 -07:00
|
|
|
/* Not found */
|
2013-01-03 13:31:36 -08:00
|
|
|
return resolveDOMCollectionProperty(cx, wrapper, holder, id, desc, flags);
|
2010-07-02 14:09:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
desc->obj = holder;
|
|
|
|
desc->attrs = JSPROP_ENUMERATE;
|
|
|
|
desc->getter = NULL;
|
|
|
|
desc->setter = NULL;
|
2010-11-17 12:39:37 -08:00
|
|
|
desc->shortid = 0;
|
2010-07-02 14:09:48 -07:00
|
|
|
desc->value = JSVAL_VOID;
|
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedValue fval(cx, JSVAL_VOID);
|
2010-07-02 14:09:48 -07:00
|
|
|
if (member->IsConstant()) {
|
|
|
|
if (!member->GetConstantValue(ccx, iface, &desc->value)) {
|
|
|
|
JS_ReportError(cx, "Failed to convert constant native property to JS value");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (member->IsAttribute()) {
|
|
|
|
// This is a getter/setter. Clone a function for it.
|
2013-03-27 04:33:30 -07:00
|
|
|
if (!member->NewFunctionObject(ccx, iface, wrapper, fval.address())) {
|
2010-07-02 14:09:48 -07:00
|
|
|
JS_ReportError(cx, "Failed to clone function object for native getter/setter");
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-20 14:48:01 -07:00
|
|
|
|
2010-07-02 14:09:48 -07:00
|
|
|
desc->attrs |= JSPROP_GETTER;
|
2010-09-20 14:48:01 -07:00
|
|
|
if (member->IsWritableAttribute())
|
2010-07-02 14:09:48 -07:00
|
|
|
desc->attrs |= JSPROP_SETTER;
|
|
|
|
|
|
|
|
// Make the property shared on the holder so no slot is allocated
|
|
|
|
// for it. This avoids keeping garbage alive through that slot.
|
|
|
|
desc->attrs |= JSPROP_SHARED;
|
|
|
|
} else {
|
|
|
|
// This is a method. Clone a function for it.
|
2011-01-25 15:06:45 -08:00
|
|
|
if (!member->NewFunctionObject(ccx, iface, wrapper, &desc->value)) {
|
2010-07-02 14:09:48 -07:00
|
|
|
JS_ReportError(cx, "Failed to clone function object for native function");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Without a wrapper the function would live on the prototype. Since we
|
|
|
|
// don't have one, we have to avoid calling the scriptable helper's
|
|
|
|
// GetProperty method for this property, so stub out the getter and
|
|
|
|
// setter here explicitly.
|
2011-02-09 11:31:40 -08:00
|
|
|
desc->getter = JS_PropertyStub;
|
|
|
|
desc->setter = JS_StrictPropertyStub;
|
2010-07-02 14:09:48 -07:00
|
|
|
}
|
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
if (!JS_WrapValue(cx, &desc->value) || !JS_WrapValue(cx, fval.address()))
|
2010-09-20 14:48:01 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (desc->attrs & JSPROP_GETTER)
|
2011-10-04 07:06:54 -07:00
|
|
|
desc->getter = js::CastAsJSPropertyOp(JSVAL_TO_OBJECT(fval));
|
2010-09-20 14:48:01 -07:00
|
|
|
if (desc->attrs & JSPROP_SETTER)
|
2011-10-04 07:06:54 -07:00
|
|
|
desc->setter = js::CastAsJSStrictPropertyOp(JSVAL_TO_OBJECT(fval));
|
2010-09-20 14:48:01 -07:00
|
|
|
|
2010-07-02 14:09:48 -07:00
|
|
|
// Define the property.
|
|
|
|
return JS_DefinePropertyById(cx, holder, id, desc->value,
|
|
|
|
desc->getter, desc->setter, desc->attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2013-03-27 04:33:30 -07:00
|
|
|
wrappedJSObject_getter(JSContext *cx, HandleObject wrapper, HandleId id, MutableHandleValue vp)
|
2010-07-02 14:09:48 -07:00
|
|
|
{
|
2011-10-04 07:06:54 -07:00
|
|
|
if (!IsWrapper(wrapper) || !WrapperFactory::IsXrayWrapper(wrapper)) {
|
2011-09-21 18:30:27 -07:00
|
|
|
JS_ReportError(cx, "Unexpected object");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-30 04:19:09 -07:00
|
|
|
vp.set(OBJECT_TO_JSVAL(wrapper));
|
2010-10-10 15:47:22 -07:00
|
|
|
|
2012-07-30 04:19:09 -07:00
|
|
|
return WrapperFactory::WaiveXrayAndWrap(cx, vp.address());
|
2010-07-02 14:09:48 -07:00
|
|
|
}
|
|
|
|
|
2011-09-21 18:30:27 -07:00
|
|
|
static JSBool
|
2013-03-27 04:33:30 -07:00
|
|
|
WrapURI(JSContext *cx, nsIURI *uri, MutableHandleValue vp)
|
2011-09-21 18:30:27 -07:00
|
|
|
{
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject scope(cx, JS_GetGlobalForScopeChain(cx));
|
2011-09-21 18:30:27 -07:00
|
|
|
nsresult rv =
|
2012-07-30 07:20:58 -07:00
|
|
|
nsXPConnect::FastGetXPConnect()->WrapNativeToJSVal(cx, scope, uri, nullptr,
|
2011-10-17 07:59:28 -07:00
|
|
|
&NS_GET_IID(nsIURI), true,
|
2013-03-27 04:33:30 -07:00
|
|
|
vp.address(), nullptr);
|
2011-09-21 18:30:27 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
XPCThrower::Throw(rv, cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2013-03-27 04:33:30 -07:00
|
|
|
documentURIObject_getter(JSContext *cx, HandleObject wrapper, HandleId id, MutableHandleValue vp)
|
2011-09-21 18:30:27 -07:00
|
|
|
{
|
2012-09-26 07:17:51 -07:00
|
|
|
nsCOMPtr<nsIDocument> native = do_QueryInterfaceNative(cx, wrapper);
|
2011-09-21 18:30:27 -07:00
|
|
|
if (!native) {
|
|
|
|
JS_ReportError(cx, "Unexpected object");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri = native->GetDocumentURI();
|
|
|
|
if (!uri) {
|
|
|
|
JS_ReportOutOfMemory(cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
return WrapURI(cx, uri, vp);
|
2011-09-21 18:30:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2013-03-27 04:33:30 -07:00
|
|
|
baseURIObject_getter(JSContext *cx, HandleObject wrapper, HandleId id, MutableHandleValue vp)
|
2011-09-21 18:30:27 -07:00
|
|
|
{
|
2012-09-26 07:17:51 -07:00
|
|
|
nsCOMPtr<nsINode> native = do_QueryInterfaceNative(cx, wrapper);
|
2011-09-21 18:30:27 -07:00
|
|
|
if (!native) {
|
|
|
|
JS_ReportError(cx, "Unexpected object");
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-26 07:17:51 -07:00
|
|
|
|
2011-09-21 18:30:27 -07:00
|
|
|
nsCOMPtr<nsIURI> uri = native->GetBaseURI();
|
|
|
|
if (!uri) {
|
|
|
|
JS_ReportOutOfMemory(cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
return WrapURI(cx, uri, vp);
|
2011-09-21 18:30:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool
|
2013-03-27 04:33:30 -07:00
|
|
|
nodePrincipal_getter(JSContext *cx, HandleObject wrapper, HandleId id, MutableHandleValue vp)
|
2011-09-21 18:30:27 -07:00
|
|
|
{
|
2012-09-26 07:17:51 -07:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterfaceNative(cx, wrapper);
|
2011-09-21 18:30:27 -07:00
|
|
|
if (!node) {
|
|
|
|
JS_ReportError(cx, "Unexpected object");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject scope(cx, JS_GetGlobalForScopeChain(cx));
|
2011-09-21 18:30:27 -07:00
|
|
|
nsresult rv =
|
2012-07-30 07:20:58 -07:00
|
|
|
nsXPConnect::FastGetXPConnect()->WrapNativeToJSVal(cx, scope, node->NodePrincipal(), nullptr,
|
2011-10-17 07:59:28 -07:00
|
|
|
&NS_GET_IID(nsIPrincipal), true,
|
2012-07-30 07:28:15 -07:00
|
|
|
vp.address(), nullptr);
|
2011-09-21 18:30:27 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
XPCThrower::Throw(rv, cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayTraits::resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper,
|
|
|
|
HandleObject wrapper, HandleObject holder, HandleId id,
|
2013-01-03 13:31:36 -08:00
|
|
|
PropertyDescriptor *desc, unsigned flags)
|
2012-10-05 09:59:23 -07:00
|
|
|
{
|
|
|
|
desc->obj = NULL;
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject target(cx, getTargetObject(wrapper));
|
|
|
|
RootedObject expando(cx, getExpandoObject(cx, target, wrapper));
|
2012-10-05 09:59:23 -07:00
|
|
|
|
|
|
|
// Check for expando properties first. Note that the expando object lives
|
|
|
|
// in the target compartment.
|
|
|
|
if (expando) {
|
|
|
|
JSAutoCompartment ac(cx, expando);
|
|
|
|
if (!JS_GetPropertyDescriptorById(cx, expando, id, 0, desc))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (desc->obj) {
|
|
|
|
if (!JS_WrapPropertyDescriptor(cx, desc))
|
|
|
|
return false;
|
|
|
|
// Pretend the property lives on the wrapper.
|
|
|
|
desc->obj = wrapper;
|
|
|
|
return true;
|
|
|
|
}
|
2012-10-05 09:59:24 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper,
|
|
|
|
HandleObject wrapper, HandleObject holder,
|
|
|
|
HandleId id, PropertyDescriptor *desc, unsigned flags)
|
2012-10-05 09:59:24 -07:00
|
|
|
{
|
|
|
|
// Call the common code.
|
|
|
|
bool ok = XrayTraits::resolveOwnProperty(cx, jsWrapper, wrapper, holder,
|
2013-01-03 13:31:36 -08:00
|
|
|
id, desc, flags);
|
2012-10-05 09:59:24 -07:00
|
|
|
if (!ok || desc->obj)
|
|
|
|
return ok;
|
2012-10-05 09:59:23 -07:00
|
|
|
|
2013-01-17 09:30:37 -08:00
|
|
|
// Check for indexed access on a window.
|
|
|
|
int32_t index = GetArrayIndexFromId(cx, id);
|
|
|
|
if (IsArrayIndex(index)) {
|
|
|
|
nsGlobalWindow* win =
|
2013-03-18 14:30:23 -07:00
|
|
|
static_cast<nsGlobalWindow*>(As<nsPIDOMWindow>(wrapper));
|
2013-01-17 09:30:37 -08:00
|
|
|
// Note: As() unwraps outer windows to get to the inner window.
|
|
|
|
if (win) {
|
|
|
|
bool unused;
|
|
|
|
nsCOMPtr<nsIDOMWindow> subframe = win->IndexedGetter(index, unused);
|
|
|
|
if (subframe) {
|
|
|
|
nsGlobalWindow* global = static_cast<nsGlobalWindow*>(subframe.get());
|
|
|
|
global->EnsureInnerWindow();
|
|
|
|
JSObject* obj = global->FastGetGlobalJSObject();
|
|
|
|
if (MOZ_UNLIKELY(!obj)) {
|
|
|
|
// It's gone?
|
|
|
|
return xpc::Throw(cx, NS_ERROR_FAILURE);
|
|
|
|
}
|
2013-03-27 04:33:30 -07:00
|
|
|
desc->value = ObjectValue(*obj);
|
2013-01-17 09:30:37 -08:00
|
|
|
mozilla::dom::FillPropertyDescriptor(desc, wrapper, true);
|
|
|
|
return JS_WrapPropertyDescriptor(cx, desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-18 06:47:09 -07:00
|
|
|
// Xray wrappers don't use the regular wrapper hierarchy, so we should be
|
|
|
|
// in the wrapper's compartment here, not the wrappee.
|
|
|
|
MOZ_ASSERT(js::IsObjectInContextCompartment(wrapper, cx));
|
2011-09-21 18:30:27 -07:00
|
|
|
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
|
2012-09-11 01:05:10 -07:00
|
|
|
if (AccessCheck::isChrome(wrapper) &&
|
2012-03-30 21:42:20 -07:00
|
|
|
(((id == rt->GetStringID(XPCJSRuntime::IDX_BASEURIOBJECT) ||
|
|
|
|
id == rt->GetStringID(XPCJSRuntime::IDX_NODEPRINCIPAL)) &&
|
|
|
|
Is<nsINode>(wrapper)) ||
|
|
|
|
(id == rt->GetStringID(XPCJSRuntime::IDX_DOCUMENTURIOBJECT) &&
|
2013-02-25 13:54:18 -08:00
|
|
|
Is<nsIDocument>(wrapper))))
|
|
|
|
{
|
2010-07-02 14:09:48 -07:00
|
|
|
desc->obj = wrapper;
|
|
|
|
desc->attrs = JSPROP_ENUMERATE|JSPROP_SHARED;
|
2012-03-30 21:42:20 -07:00
|
|
|
if (id == rt->GetStringID(XPCJSRuntime::IDX_BASEURIOBJECT))
|
2011-09-21 18:30:27 -07:00
|
|
|
desc->getter = baseURIObject_getter;
|
|
|
|
else if (id == rt->GetStringID(XPCJSRuntime::IDX_DOCUMENTURIOBJECT))
|
|
|
|
desc->getter = documentURIObject_getter;
|
|
|
|
else
|
|
|
|
desc->getter = nodePrincipal_getter;
|
2010-07-02 14:09:48 -07:00
|
|
|
desc->setter = NULL;
|
2010-10-10 15:36:32 -07:00
|
|
|
desc->shortid = 0;
|
2010-07-02 14:09:48 -07:00
|
|
|
desc->value = JSVAL_VOID;
|
|
|
|
return true;
|
|
|
|
}
|
2010-09-20 14:48:01 -07:00
|
|
|
|
2011-02-15 19:00:55 -08:00
|
|
|
JSBool hasProp;
|
|
|
|
if (!JS_HasPropertyById(cx, holder, id, &hasProp)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!hasProp) {
|
2012-10-05 09:59:23 -07:00
|
|
|
XPCWrappedNative *wn = getWN(wrapper);
|
2011-02-15 19:00:55 -08:00
|
|
|
|
|
|
|
// Run the resolve hook of the wrapped native.
|
|
|
|
if (!NATIVE_HAS_FLAG(wn, WantNewResolve)) {
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-10 14:08:44 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool retval = true;
|
2010-11-10 14:08:44 -08:00
|
|
|
JSObject *pobj = NULL;
|
|
|
|
nsresult rv = wn->GetScriptableInfo()->GetCallback()->NewResolve(wn, cx, wrapper, id,
|
|
|
|
flags, &pobj, &retval);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (retval)
|
|
|
|
XPCThrower::Throw(rv, cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-15 19:00:55 -08:00
|
|
|
#ifdef DEBUG
|
2012-08-27 06:15:20 -07:00
|
|
|
NS_ASSERTION(!pobj || (JS_HasPropertyById(cx, holder, id, &hasProp) &&
|
|
|
|
hasProp), "id got defined somewhere else?");
|
2011-02-15 19:00:55 -08:00
|
|
|
#endif
|
2010-11-10 14:08:44 -08:00
|
|
|
}
|
|
|
|
|
2010-10-10 15:49:13 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-03-21 15:23:47 -07:00
|
|
|
XPCWrappedNativeXrayTraits::defineProperty(JSContext *cx, HandleObject wrapper, HandleId id,
|
2013-01-14 02:29:48 -08:00
|
|
|
PropertyDescriptor *desc,
|
|
|
|
PropertyDescriptor &existingDesc,
|
|
|
|
bool *defined)
|
2010-10-10 15:49:13 -07:00
|
|
|
{
|
2012-10-05 09:59:24 -07:00
|
|
|
*defined = false;
|
2012-10-05 09:59:23 -07:00
|
|
|
JSObject *holder = singleton.ensureHolder(cx, wrapper);
|
2012-03-27 16:31:37 -07:00
|
|
|
if (isResolving(cx, holder, id)) {
|
|
|
|
if (!(desc->attrs & (JSPROP_GETTER | JSPROP_SETTER))) {
|
|
|
|
if (!desc->getter)
|
|
|
|
desc->getter = holder_get;
|
|
|
|
if (!desc->setter)
|
|
|
|
desc->setter = holder_set;
|
2010-10-10 15:41:24 -07:00
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:24 -07:00
|
|
|
*defined = true;
|
2012-03-27 16:31:37 -07:00
|
|
|
return JS_DefinePropertyById(cx, holder, id, desc->value, desc->getter, desc->setter,
|
|
|
|
desc->attrs);
|
2010-10-10 15:41:24 -07:00
|
|
|
}
|
2013-01-17 09:30:37 -08:00
|
|
|
|
|
|
|
// Check for an indexed property on a Window. If that's happening, do
|
|
|
|
// nothing but claim we defined it so it won't get added as an expando.
|
|
|
|
int32_t index = GetArrayIndexFromId(cx, id);
|
|
|
|
if (IsArrayIndex(index) && Is<nsIDOMWindow>(wrapper)) {
|
|
|
|
*defined = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:08:44 -08:00
|
|
|
return true;
|
2010-07-02 14:09:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XPCWrappedNativeXrayTraits::enumerateNames(JSContext *cx, HandleObject wrapper, unsigned flags,
|
|
|
|
AutoIdVector &props)
|
2010-07-02 14:09:48 -07:00
|
|
|
{
|
2010-11-10 14:08:44 -08:00
|
|
|
// Force all native properties to be materialized onto the wrapped native.
|
2013-03-27 04:33:30 -07:00
|
|
|
AutoIdVector wnProps(cx);
|
2010-11-10 14:08:44 -08:00
|
|
|
{
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject target(cx, singleton.getTargetObject(wrapper));
|
2012-10-05 09:59:23 -07:00
|
|
|
JSAutoCompartment ac(cx, target);
|
|
|
|
if (!js::GetPropertyNames(cx, target, flags, &wnProps))
|
2010-11-10 14:08:44 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go through the properties we got and enumerate all native ones.
|
|
|
|
for (size_t n = 0; n < wnProps.length(); ++n) {
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedId id(cx, wnProps[n]);
|
2010-11-10 14:08:44 -08:00
|
|
|
JSBool hasProp;
|
|
|
|
if (!JS_HasPropertyById(cx, wrapper, id, &hasProp))
|
|
|
|
return false;
|
|
|
|
if (hasProp)
|
|
|
|
props.append(id);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
JSObject *
|
|
|
|
XPCWrappedNativeXrayTraits::createHolder(JSContext *cx, JSObject *wrapper)
|
|
|
|
{
|
|
|
|
JSObject *global = JS_GetGlobalForObject(cx, wrapper);
|
|
|
|
JSObject *holder = JS_NewObjectWithGivenProto(cx, &HolderClass, nullptr,
|
|
|
|
global);
|
|
|
|
if (!holder)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
js::SetReservedSlot(holder, JSSLOT_RESOLVING, PrivateValue(NULL));
|
|
|
|
return holder;
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:22 -07:00
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XPCWrappedNativeXrayTraits::call(JSContext *cx, HandleObject wrapper,
|
2013-04-04 00:02:24 -07:00
|
|
|
const JS::CallArgs &args)
|
2012-10-05 09:59:22 -07:00
|
|
|
{
|
|
|
|
// Run the resolve hook of the wrapped native.
|
2012-10-05 09:59:23 -07:00
|
|
|
XPCWrappedNative *wn = getWN(wrapper);
|
2012-10-05 09:59:22 -07:00
|
|
|
if (NATIVE_HAS_FLAG(wn, WantCall)) {
|
2013-04-04 00:02:24 -07:00
|
|
|
XPCCallContext ccx(JS_CALLER, cx, wrapper, nullptr, JSID_VOID, args.length(), args.array(),
|
|
|
|
args.rval().address());
|
2012-10-05 09:59:22 -07:00
|
|
|
if (!ccx.IsValid())
|
|
|
|
return false;
|
|
|
|
bool ok = true;
|
2013-04-04 00:02:24 -07:00
|
|
|
nsresult rv = wn->GetScriptableInfo()->GetCallback()->Call(
|
|
|
|
wn, cx, wrapper, args.length(), args.array(), args.rval().address(), &ok);
|
2012-10-05 09:59:22 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (ok)
|
|
|
|
XPCThrower::Throw(rv, cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XPCWrappedNativeXrayTraits::construct(JSContext *cx, HandleObject wrapper,
|
2013-04-04 00:02:24 -07:00
|
|
|
const JS::CallArgs &args)
|
2012-10-05 09:59:22 -07:00
|
|
|
{
|
|
|
|
// Run the resolve hook of the wrapped native.
|
2012-10-05 09:59:23 -07:00
|
|
|
XPCWrappedNative *wn = getWN(wrapper);
|
2012-10-05 09:59:22 -07:00
|
|
|
if (NATIVE_HAS_FLAG(wn, WantConstruct)) {
|
2013-04-04 00:02:24 -07:00
|
|
|
XPCCallContext ccx(JS_CALLER, cx, wrapper, nullptr, JSID_VOID, args.length(), args.array(),
|
|
|
|
args.rval().address());
|
2012-10-05 09:59:22 -07:00
|
|
|
if (!ccx.IsValid())
|
|
|
|
return false;
|
|
|
|
bool ok = true;
|
2013-04-04 00:02:24 -07:00
|
|
|
nsresult rv = wn->GetScriptableInfo()->GetCallback()->Construct(
|
|
|
|
wn, cx, wrapper, args.length(), args.array(), args.rval().address(), &ok);
|
2012-10-05 09:59:22 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (ok)
|
|
|
|
XPCThrower::Throw(rv, cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
DOMXrayTraits::resolveNativeProperty(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleObject holder, HandleId id,
|
2013-01-03 13:31:36 -08:00
|
|
|
JSPropertyDescriptor *desc, unsigned flags)
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
2012-10-05 09:59:22 -07:00
|
|
|
JSObject *obj = getTargetObject(wrapper);
|
2012-10-09 11:50:27 -07:00
|
|
|
if (!XrayResolveNativeProperty(cx, wrapper, obj, id, desc))
|
|
|
|
return false;
|
2012-06-06 12:52:26 -07:00
|
|
|
|
2012-10-09 11:50:27 -07:00
|
|
|
NS_ASSERTION(!desc->obj || desc->obj == wrapper,
|
|
|
|
"What did we resolve this on?");
|
2012-03-30 21:42:20 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
DOMXrayTraits::resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper, HandleObject wrapper,
|
|
|
|
HandleObject holder, HandleId id,
|
|
|
|
JSPropertyDescriptor *desc, unsigned flags)
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
2012-10-05 09:59:23 -07:00
|
|
|
// Call the common code.
|
|
|
|
bool ok = XrayTraits::resolveOwnProperty(cx, jsWrapper, wrapper, holder,
|
2013-01-03 13:31:36 -08:00
|
|
|
id, desc, flags);
|
2012-10-05 09:59:23 -07:00
|
|
|
if (!ok || desc->obj)
|
|
|
|
return ok;
|
|
|
|
|
2012-10-05 09:59:22 -07:00
|
|
|
JSObject *obj = getTargetObject(wrapper);
|
2013-01-03 13:31:36 -08:00
|
|
|
if (!XrayResolveOwnProperty(cx, wrapper, obj, id, desc, flags))
|
2012-10-09 11:50:27 -07:00
|
|
|
return false;
|
2012-06-06 12:52:26 -07:00
|
|
|
|
2012-10-09 11:50:27 -07:00
|
|
|
NS_ASSERTION(!desc->obj || desc->obj == wrapper,
|
|
|
|
"What did we resolve this on?");
|
2012-06-06 12:52:26 -07:00
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-14 02:29:48 -08:00
|
|
|
bool
|
2013-03-21 15:23:47 -07:00
|
|
|
DOMXrayTraits::defineProperty(JSContext *cx, HandleObject wrapper, HandleId id,
|
2013-03-27 04:33:30 -07:00
|
|
|
PropertyDescriptor *desc, PropertyDescriptor &existingDesc,
|
2013-01-14 02:29:48 -08:00
|
|
|
bool *defined)
|
|
|
|
{
|
|
|
|
if (!existingDesc.obj)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
JSObject *obj= getTargetObject(wrapper);
|
|
|
|
if (!js::IsProxy(obj))
|
|
|
|
return true;
|
2013-03-21 15:23:47 -07:00
|
|
|
|
2013-01-14 02:29:48 -08:00
|
|
|
*defined = true;
|
|
|
|
return js::GetProxyHandler(obj)->defineProperty(cx, wrapper, id, desc);
|
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
DOMXrayTraits::enumerateNames(JSContext *cx, HandleObject wrapper, unsigned flags,
|
|
|
|
AutoIdVector &props)
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
2012-10-09 11:50:27 -07:00
|
|
|
return XrayEnumerateProperties(cx, wrapper, getTargetObject(wrapper),
|
2012-11-05 08:58:03 -08:00
|
|
|
flags, props);
|
2012-10-09 11:50:27 -07:00
|
|
|
}
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2012-10-09 11:50:27 -07:00
|
|
|
bool
|
2013-04-04 00:02:24 -07:00
|
|
|
DOMXrayTraits::call(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args)
|
2012-10-09 11:50:27 -07:00
|
|
|
{
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject obj(cx, getTargetObject(wrapper));
|
2012-10-09 11:50:27 -07:00
|
|
|
{
|
|
|
|
JSAutoCompartment ac(cx, obj);
|
2013-04-04 00:02:24 -07:00
|
|
|
Value thisv = args.thisv();
|
|
|
|
if (!JS_WrapValue(cx, &thisv))
|
2012-03-30 21:42:20 -07:00
|
|
|
return false;
|
2013-04-04 00:02:24 -07:00
|
|
|
args.setThis(thisv);
|
|
|
|
for (size_t i = 0; i < args.length(); ++i) {
|
|
|
|
if (!JS_WrapValue(cx, &args[i]))
|
2012-10-09 11:50:27 -07:00
|
|
|
return false;
|
2012-03-30 21:42:20 -07:00
|
|
|
}
|
2013-04-04 00:02:24 -07:00
|
|
|
if (!Call(cx, thisv, obj, args.length(), args.array(), args.rval().address()))
|
|
|
|
return false;
|
2012-10-09 11:50:27 -07:00
|
|
|
}
|
2013-04-04 00:02:24 -07:00
|
|
|
return JS_WrapValue(cx, args.rval().address());
|
2012-10-09 11:50:27 -07:00
|
|
|
}
|
2012-03-30 21:42:20 -07:00
|
|
|
|
2012-10-09 11:50:27 -07:00
|
|
|
bool
|
2013-04-04 00:02:24 -07:00
|
|
|
DOMXrayTraits::construct(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args)
|
2012-10-09 11:50:27 -07:00
|
|
|
{
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject obj(cx, getTargetObject(wrapper));
|
2012-10-09 11:50:27 -07:00
|
|
|
MOZ_ASSERT(mozilla::dom::HasConstructor(obj));
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject newObj(cx);
|
2012-10-09 11:50:27 -07:00
|
|
|
{
|
|
|
|
JSAutoCompartment ac(cx, obj);
|
2013-04-04 00:02:24 -07:00
|
|
|
for (size_t i = 0; i < args.length(); ++i) {
|
|
|
|
if (!JS_WrapValue(cx, &args[i]))
|
2012-10-09 11:50:27 -07:00
|
|
|
return false;
|
|
|
|
}
|
2013-04-04 00:02:24 -07:00
|
|
|
newObj = JS_New(cx, obj, args.length(), args.array());
|
2012-10-09 11:50:27 -07:00
|
|
|
}
|
2013-03-27 04:33:30 -07:00
|
|
|
if (!newObj || !JS_WrapObject(cx, newObj.address()))
|
2012-10-09 11:50:27 -07:00
|
|
|
return false;
|
2013-04-04 00:02:24 -07:00
|
|
|
args.rval().setObject(*newObj);
|
2012-03-30 21:42:20 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:23 -07:00
|
|
|
void
|
|
|
|
DOMXrayTraits::preserveWrapper(JSObject *target)
|
|
|
|
{
|
|
|
|
nsISupports *identity;
|
|
|
|
if (!mozilla::dom::UnwrapDOMObjectToISupports(target, identity))
|
|
|
|
return;
|
|
|
|
nsWrapperCache* cache = nullptr;
|
|
|
|
CallQueryInterface(identity, &cache);
|
|
|
|
if (cache)
|
|
|
|
nsContentUtils::PreserveWrapper(identity, cache);
|
|
|
|
}
|
|
|
|
|
2012-03-30 21:42:20 -07:00
|
|
|
JSObject*
|
2012-10-05 09:59:23 -07:00
|
|
|
DOMXrayTraits::createHolder(JSContext *cx, JSObject *wrapper)
|
2012-03-30 21:42:20 -07:00
|
|
|
{
|
2012-10-05 09:59:23 -07:00
|
|
|
return JS_NewObjectWithGivenProto(cx, nullptr, nullptr,
|
|
|
|
JS_GetGlobalForObject(cx, wrapper));
|
2012-03-30 21:42:20 -07:00
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
|
|
|
XrayWrapper<Base, Traits>::XrayWrapper(unsigned flags)
|
|
|
|
: Base(flags | WrapperFactory::IS_XRAY_WRAPPER_FLAG)
|
2010-07-02 14:09:48 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
|
|
|
XrayWrapper<Base, Traits>::~XrayWrapper()
|
2010-09-20 14:48:01 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
namespace XrayUtils {
|
|
|
|
|
2010-09-20 14:48:01 -07:00
|
|
|
bool
|
2013-04-03 11:41:23 -07:00
|
|
|
NeedsWaive(JSContext *cx, HandleObject wrapper, HandleId id)
|
2010-09-20 14:48:01 -07:00
|
|
|
{
|
2013-02-08 06:24:22 -08:00
|
|
|
// We dynamically waive Xray vision for XBL bindings accessing fields
|
|
|
|
// on bound elements, since there's no way to access such things sanely
|
|
|
|
// over Xray.
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
if (EnsureCompartmentPrivate(wrapper)->scope->IsXBLScope() &&
|
|
|
|
(content = do_QueryInterfaceNative(cx, wrapper)))
|
|
|
|
{
|
2013-03-27 04:33:30 -07:00
|
|
|
if (nsContentUtils::IsBindingField(cx, content, id))
|
2013-02-08 06:24:22 -08:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-22 21:04:39 -08:00
|
|
|
return false;
|
2010-09-20 14:48:01 -07:00
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
JSObject *
|
|
|
|
GetNativePropertiesObject(JSContext *cx, JSObject *wrapper)
|
2011-01-25 15:06:45 -08:00
|
|
|
{
|
2012-03-27 16:31:37 -07:00
|
|
|
NS_ASSERTION(js::IsWrapper(wrapper) && WrapperFactory::IsXrayWrapper(wrapper),
|
|
|
|
"bad object passed in");
|
2011-01-25 15:06:45 -08:00
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
JSObject *holder = GetHolder(wrapper);
|
|
|
|
NS_ASSERTION(holder, "uninitialized wrapper being used?");
|
|
|
|
return holder;
|
|
|
|
}
|
2011-01-25 15:06:45 -08:00
|
|
|
|
2013-02-25 13:54:17 -08:00
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
IsXrayResolving(JSContext *cx, HandleObject wrapper, HandleId id)
|
2013-02-25 13:54:17 -08:00
|
|
|
{
|
|
|
|
if (!WrapperFactory::IsXrayWrapper(wrapper) ||
|
|
|
|
GetXrayType(wrapper) != XrayForWrappedNative)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
JSObject *holder =
|
|
|
|
XPCWrappedNativeXrayTraits::singleton.ensureHolder(cx, wrapper);
|
|
|
|
return XPCWrappedNativeXrayTraits::isResolving(cx, holder, id);
|
|
|
|
}
|
|
|
|
|
2013-03-22 19:43:03 -07:00
|
|
|
} // namespace XrayUtils
|
2011-01-25 15:06:45 -08:00
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
static JSBool
|
|
|
|
XrayToString(JSContext *cx, unsigned argc, jsval *vp)
|
2011-01-25 15:06:45 -08:00
|
|
|
{
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject wrapper(cx, JS_THIS_OBJECT(cx, vp));
|
2012-04-27 03:47:00 -07:00
|
|
|
if (!wrapper)
|
|
|
|
return false;
|
2012-10-09 11:50:27 -07:00
|
|
|
if (IsWrapper(wrapper) &&
|
|
|
|
GetProxyHandler(wrapper) == &sandboxCallableProxyHandler) {
|
|
|
|
wrapper = xpc::SandboxCallableProxyHandler::wrappedObject(wrapper);
|
|
|
|
}
|
2012-04-27 03:47:00 -07:00
|
|
|
if (!IsWrapper(wrapper) || !WrapperFactory::IsXrayWrapper(wrapper)) {
|
2012-03-27 16:31:37 -07:00
|
|
|
JS_ReportError(cx, "XrayToString called on an incompatible object");
|
|
|
|
return false;
|
|
|
|
}
|
2011-01-25 15:06:45 -08:00
|
|
|
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject obj(cx, XrayTraits::getTargetObject(wrapper));
|
2012-10-09 11:50:27 -07:00
|
|
|
|
|
|
|
static const char start[] = "[object XrayWrapper ";
|
|
|
|
static const char end[] = "]";
|
|
|
|
if (UseDOMXray(obj))
|
|
|
|
return NativeToString(cx, wrapper, obj, start, end, vp);
|
|
|
|
|
|
|
|
nsAutoString result;
|
|
|
|
result.AppendASCII(start);
|
|
|
|
|
|
|
|
XPCCallContext ccx(JS_CALLER, cx, obj);
|
|
|
|
XPCWrappedNative *wn = XPCWrappedNativeXrayTraits::getWN(wrapper);
|
|
|
|
char *wrapperStr = wn->ToString(ccx);
|
|
|
|
if (!wrapperStr) {
|
|
|
|
JS_ReportOutOfMemory(cx);
|
|
|
|
return false;
|
2011-01-25 15:06:45 -08:00
|
|
|
}
|
2012-10-09 11:50:27 -07:00
|
|
|
result.AppendASCII(wrapperStr);
|
|
|
|
JS_smprintf_free(wrapperStr);
|
2011-01-25 15:06:45 -08:00
|
|
|
|
2012-10-09 11:50:27 -07:00
|
|
|
result.AppendASCII(end);
|
2011-05-25 08:30:50 -07:00
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
JSString *str = JS_NewUCStringCopyN(cx, reinterpret_cast<const jschar *>(result.get()),
|
|
|
|
result.Length());
|
|
|
|
if (!str)
|
|
|
|
return false;
|
2011-05-27 08:06:42 -07:00
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
*vp = STRING_TO_JSVAL(str);
|
|
|
|
return true;
|
2011-05-27 08:06:42 -07:00
|
|
|
}
|
|
|
|
|
2013-02-08 06:24:21 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
static void
|
|
|
|
DEBUG_CheckXBLCallable(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!js::IsCrossCompartmentWrapper(obj));
|
|
|
|
MOZ_ASSERT(JS_ObjectIsCallable(cx, obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DEBUG_CheckXBLLookup(JSContext *cx, JSPropertyDescriptor *desc)
|
|
|
|
{
|
|
|
|
if (!desc->obj)
|
|
|
|
return;
|
|
|
|
if (!desc->value.isUndefined()) {
|
|
|
|
MOZ_ASSERT(desc->value.isObject());
|
|
|
|
DEBUG_CheckXBLCallable(cx, &desc->value.toObject());
|
|
|
|
}
|
|
|
|
if (desc->getter) {
|
|
|
|
MOZ_ASSERT(desc->attrs & JSPROP_GETTER);
|
|
|
|
DEBUG_CheckXBLCallable(cx, JS_FUNC_TO_DATA_PTR(JSObject *, desc->getter));
|
|
|
|
}
|
|
|
|
if (desc->setter) {
|
|
|
|
MOZ_ASSERT(desc->attrs & JSPROP_SETTER);
|
|
|
|
DEBUG_CheckXBLCallable(cx, JS_FUNC_TO_DATA_PTR(JSObject *, desc->setter));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define DEBUG_CheckXBLLookup(a, b) {}
|
|
|
|
#endif
|
|
|
|
|
2013-03-22 19:43:03 -07:00
|
|
|
template <typename Base, typename Traits>
|
|
|
|
bool
|
|
|
|
XrayWrapper<Base, Traits>::isExtensible(JSObject *wrapper)
|
|
|
|
{
|
|
|
|
// Xray wrappers are supposed to provide a clean view of the target
|
|
|
|
// reflector, hiding any modifications by script in the target scope. So
|
|
|
|
// even if that script freezes the reflector, we don't want to make that
|
|
|
|
// visible to the caller. DOM reflectors are always extensible by default,
|
|
|
|
// so we can just return true here.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Base, typename Traits>
|
|
|
|
bool
|
|
|
|
XrayWrapper<Base, Traits>::preventExtensions(JSContext *cx, JS::Handle<JSObject*> wrapper)
|
|
|
|
{
|
|
|
|
// See above.
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_CHANGE_EXTENSIBILITY);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
2011-05-25 08:30:50 -07:00
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::getPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id,
|
|
|
|
PropertyDescriptor *desc, unsigned flags)
|
2011-05-25 08:30:50 -07:00
|
|
|
{
|
2013-02-25 13:54:18 -08:00
|
|
|
assertEnteredPolicy(cx, wrapper, id);
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject holder(cx, Traits::singleton.ensureHolder(cx, wrapper));
|
2012-03-27 16:31:37 -07:00
|
|
|
if (Traits::isResolving(cx, holder, id)) {
|
|
|
|
desc->obj = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
2011-05-27 08:06:42 -07:00
|
|
|
|
2012-08-27 06:06:34 -07:00
|
|
|
typename Traits::ResolvingIdImpl resolving(wrapper, id);
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2013-04-03 11:41:23 -07:00
|
|
|
if (XrayUtils::NeedsWaive(cx, wrapper, id)) {
|
|
|
|
RootedObject waived(cx, WrapperFactory::WaiveXray(cx, wrapper));
|
|
|
|
if (!waived || !JS_WrapObject(cx, waived.address()))
|
|
|
|
return false;
|
|
|
|
return JS_GetPropertyDescriptorById(cx, waived, id, flags, desc);
|
2011-08-20 06:53:32 -07:00
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
if (!holder)
|
2011-05-27 08:06:42 -07:00
|
|
|
return false;
|
2012-03-27 16:31:37 -07:00
|
|
|
|
2012-09-11 01:05:10 -07:00
|
|
|
// Only chrome wrappers and same-origin xrays (used by jetpack sandboxes)
|
|
|
|
// get .wrappedJSObject. We can check this by determining if the compartment
|
|
|
|
// of the wrapper subsumes that of the wrappee.
|
2012-03-30 21:42:20 -07:00
|
|
|
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
|
2012-09-11 01:05:10 -07:00
|
|
|
if (AccessCheck::wrapperSubsumes(wrapper) &&
|
2012-03-30 21:42:20 -07:00
|
|
|
id == rt->GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT)) {
|
|
|
|
desc->obj = wrapper;
|
|
|
|
desc->attrs = JSPROP_ENUMERATE|JSPROP_SHARED;
|
|
|
|
desc->getter = wrappedJSObject_getter;
|
|
|
|
desc->setter = NULL;
|
|
|
|
desc->shortid = 0;
|
|
|
|
desc->value = JSVAL_VOID;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-03 13:31:36 -08:00
|
|
|
if (!Traits::singleton.resolveOwnProperty(cx, *this, wrapper, holder, id, desc, flags))
|
2012-03-27 16:31:37 -07:00
|
|
|
return false;
|
|
|
|
|
2013-01-22 21:04:38 -08:00
|
|
|
if (desc->obj) {
|
|
|
|
desc->obj = wrapper;
|
2011-05-27 08:06:42 -07:00
|
|
|
return true;
|
2013-01-22 21:04:38 -08:00
|
|
|
}
|
2011-05-27 08:06:42 -07:00
|
|
|
|
2013-03-14 22:38:26 -07:00
|
|
|
// We need to handle named access on the Window somewhere other than
|
|
|
|
// Traits::resolveOwnProperty, because per spec it happens on the Global
|
|
|
|
// Scope Polluter and thus the resulting properties are non-|own|. However,
|
2013-04-17 09:00:20 -07:00
|
|
|
// we're set up (below) to cache (on the holder) anything that comes out of
|
2013-03-14 22:38:26 -07:00
|
|
|
// resolveNativeProperty, which we don't want for something dynamic like
|
2013-04-17 09:00:20 -07:00
|
|
|
// named access. So we just handle it here.
|
2013-03-14 22:38:26 -07:00
|
|
|
nsGlobalWindow *win;
|
2013-04-17 09:00:20 -07:00
|
|
|
if (Traits::Type == XrayForWrappedNative && JSID_IS_STRING(id) &&
|
2013-03-18 14:30:23 -07:00
|
|
|
(win = static_cast<nsGlobalWindow*>(As<nsPIDOMWindow>(wrapper))))
|
2013-03-14 22:38:26 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMWindow> childDOMWin = win->GetChildWindow(id);
|
|
|
|
if (childDOMWin) {
|
|
|
|
nsGlobalWindow *cwin = static_cast<nsGlobalWindow*>(childDOMWin.get());
|
|
|
|
JSObject *childObj = cwin->FastGetGlobalJSObject();
|
|
|
|
if (MOZ_UNLIKELY(!childObj))
|
|
|
|
return xpc::Throw(cx, NS_ERROR_FAILURE);
|
|
|
|
mozilla::dom::FillPropertyDescriptor(desc, wrapper,
|
|
|
|
ObjectValue(*childObj),
|
|
|
|
/* readOnly = */ true);
|
|
|
|
return JS_WrapPropertyDescriptor(cx, desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 09:00:20 -07:00
|
|
|
if (!JS_GetPropertyDescriptorById(cx, holder, id, 0, desc))
|
|
|
|
return false;
|
|
|
|
if (desc->obj) {
|
|
|
|
desc->obj = wrapper;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing in the cache. Call through, and cache the result.
|
|
|
|
if (!Traits::resolveNativeProperty(cx, wrapper, holder, id, desc, flags))
|
|
|
|
return false;
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2013-02-08 06:24:21 -08:00
|
|
|
if (!desc->obj &&
|
|
|
|
id == nsXPConnect::GetRuntimeInstance()->GetStringID(XPCJSRuntime::IDX_TO_STRING))
|
|
|
|
{
|
2011-08-20 06:53:32 -07:00
|
|
|
|
|
|
|
JSFunction *toString = JS_NewFunction(cx, XrayToString, 0, 0, holder, "toString");
|
|
|
|
if (!toString)
|
|
|
|
return false;
|
|
|
|
|
2013-02-08 06:24:21 -08:00
|
|
|
desc->obj = wrapper;
|
2011-08-20 06:53:32 -07:00
|
|
|
desc->attrs = 0;
|
|
|
|
desc->getter = NULL;
|
|
|
|
desc->setter = NULL;
|
|
|
|
desc->shortid = 0;
|
|
|
|
desc->value.setObject(*JS_GetFunctionObject(toString));
|
|
|
|
}
|
2011-05-27 08:06:42 -07:00
|
|
|
|
2013-02-08 06:24:21 -08:00
|
|
|
// If we're a special scope for in-content XBL, our script expects to see
|
|
|
|
// the bound XBL methods and attributes when accessing content. However,
|
|
|
|
// these members are implemented in content via custom-spliced prototypes,
|
|
|
|
// and thus aren't visible through Xray wrappers unless we handle them
|
|
|
|
// explicitly. So we check if we're running in such a scope, and if so,
|
|
|
|
// whether the wrappee is a bound element. If it is, we do a lookup via
|
|
|
|
// specialized XBL machinery.
|
|
|
|
//
|
|
|
|
// While we have to do some sketchy walking through content land, we should
|
|
|
|
// be protected by read-only/non-configurable properties, and any functions
|
|
|
|
// we end up with should _always_ be living in our own scope (the XBL scope).
|
|
|
|
// Make sure to assert that.
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
if (!desc->obj &&
|
|
|
|
EnsureCompartmentPrivate(wrapper)->scope->IsXBLScope() &&
|
|
|
|
(content = do_QueryInterfaceNative(cx, wrapper)))
|
|
|
|
{
|
2013-03-27 04:33:30 -07:00
|
|
|
if (!nsContentUtils::LookupBindingMember(cx, content, id, desc))
|
2013-02-08 06:24:21 -08:00
|
|
|
return false;
|
|
|
|
DEBUG_CheckXBLLookup(cx, desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we still have nothing, we're done.
|
|
|
|
if (!desc->obj)
|
|
|
|
return true;
|
|
|
|
|
2013-01-22 21:04:38 -08:00
|
|
|
if (!JS_DefinePropertyById(cx, holder, id, desc->value, desc->getter,
|
|
|
|
desc->setter, desc->attrs) ||
|
|
|
|
!JS_GetPropertyDescriptorById(cx, holder, id, flags, desc))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(desc->obj);
|
2011-05-27 08:06:42 -07:00
|
|
|
desc->obj = wrapper;
|
2013-01-22 21:04:38 -08:00
|
|
|
return true;
|
2011-05-25 08:30:50 -07:00
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
2011-05-25 08:30:50 -07:00
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, HandleId id,
|
2013-01-03 13:31:36 -08:00
|
|
|
PropertyDescriptor *desc, unsigned flags)
|
2011-05-25 08:30:50 -07:00
|
|
|
{
|
2013-02-25 13:54:18 -08:00
|
|
|
assertEnteredPolicy(cx, wrapper, id);
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject holder(cx, Traits::singleton.ensureHolder(cx, wrapper));
|
2012-03-27 16:31:37 -07:00
|
|
|
if (Traits::isResolving(cx, holder, id)) {
|
|
|
|
desc->obj = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2012-08-27 06:06:34 -07:00
|
|
|
typename Traits::ResolvingIdImpl resolving(wrapper, id);
|
2012-03-27 16:31:37 -07:00
|
|
|
|
|
|
|
// NB: Nothing we do here acts on the wrapped native itself, so we don't
|
|
|
|
// enter our policy.
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2013-04-03 11:41:23 -07:00
|
|
|
if (XrayUtils::NeedsWaive(cx, wrapper, id)) {
|
|
|
|
RootedObject waived(cx, WrapperFactory::WaiveXray(cx, wrapper));
|
|
|
|
if (!waived || !JS_WrapObject(cx, waived.address()))
|
|
|
|
return false;
|
|
|
|
if (!JS_GetPropertyDescriptorById(cx, waived, id, flags, desc))
|
|
|
|
return false;
|
|
|
|
if (desc->obj != waived)
|
|
|
|
desc->obj = nullptr;
|
|
|
|
return true;
|
2011-08-20 06:53:32 -07:00
|
|
|
}
|
|
|
|
|
2013-01-03 13:31:36 -08:00
|
|
|
if (!Traits::singleton.resolveOwnProperty(cx, *this, wrapper, holder, id, desc, flags))
|
2011-08-20 06:53:32 -07:00
|
|
|
return false;
|
2012-03-27 16:31:37 -07:00
|
|
|
|
2013-01-22 21:04:38 -08:00
|
|
|
if (desc->obj) {
|
|
|
|
desc->obj = wrapper;
|
2011-08-20 06:53:32 -07:00
|
|
|
return true;
|
2013-01-22 21:04:38 -08:00
|
|
|
}
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
if (!JS_GetPropertyDescriptorById(cx, holder, id, flags, desc))
|
2011-08-20 06:53:32 -07:00
|
|
|
return false;
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
// Pretend we found the property on the wrapper, not the holder.
|
2011-12-06 11:05:26 -08:00
|
|
|
if (desc->obj)
|
2012-03-27 16:31:37 -07:00
|
|
|
desc->obj = wrapper;
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2011-12-06 11:05:26 -08:00
|
|
|
return true;
|
2011-05-25 08:30:50 -07:00
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
2011-05-25 08:30:50 -07:00
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::defineProperty(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleId id, PropertyDescriptor *desc)
|
2011-05-25 08:30:50 -07:00
|
|
|
{
|
2013-02-25 13:54:18 -08:00
|
|
|
assertEnteredPolicy(cx, wrapper, id);
|
2013-04-03 11:41:23 -07:00
|
|
|
if (XrayUtils::NeedsWaive(cx, wrapper, id)) {
|
|
|
|
RootedObject waived(cx, WrapperFactory::WaiveXray(cx, wrapper));
|
|
|
|
if (!waived || !JS_WrapObject(cx, waived.address()))
|
2011-08-20 06:53:32 -07:00
|
|
|
return false;
|
2013-04-03 11:41:23 -07:00
|
|
|
return JS_DefinePropertyById(cx, waived, id, desc->value, desc->getter, desc->setter,
|
2011-08-20 06:53:32 -07:00
|
|
|
desc->attrs);
|
|
|
|
}
|
|
|
|
|
2013-02-25 13:54:17 -08:00
|
|
|
// NB: We still need JSRESOLVE_ASSIGNING here for the time being, because it
|
|
|
|
// tells things like nodelists whether they should create the property or not.
|
2011-08-20 06:53:32 -07:00
|
|
|
PropertyDescriptor existing_desc;
|
2013-01-03 13:31:36 -08:00
|
|
|
if (!getOwnPropertyDescriptor(cx, wrapper, id, &existing_desc, JSRESOLVE_ASSIGNING))
|
2011-08-20 06:53:32 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (existing_desc.obj && (existing_desc.attrs & JSPROP_PERMANENT))
|
|
|
|
return true; // silently ignore attempt to overwrite native property
|
|
|
|
|
2012-10-05 09:59:24 -07:00
|
|
|
bool defined = false;
|
2013-01-14 02:29:48 -08:00
|
|
|
if (!Traits::defineProperty(cx, wrapper, id, desc, existing_desc, &defined))
|
2012-10-05 09:59:24 -07:00
|
|
|
return false;
|
|
|
|
if (defined)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// We're placing an expando. The expando objects live in the target
|
|
|
|
// compartment, so we need to enter it.
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject target(cx, Traits::singleton.getTargetObject(wrapper));
|
2012-10-05 09:59:24 -07:00
|
|
|
JSAutoCompartment ac(cx, target);
|
|
|
|
|
|
|
|
// Grab the relevant expando object.
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject expandoObject(cx, Traits::singleton.ensureExpandoObject(cx, wrapper,
|
|
|
|
target));
|
2012-10-05 09:59:24 -07:00
|
|
|
if (!expandoObject)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Wrap the property descriptor for the target compartment.
|
|
|
|
PropertyDescriptor wrappedDesc = *desc;
|
|
|
|
if (!JS_WrapPropertyDescriptor(cx, &wrappedDesc))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return JS_DefinePropertyById(cx, expandoObject, id, wrappedDesc.value,
|
|
|
|
wrappedDesc.getter, wrappedDesc.setter,
|
|
|
|
wrappedDesc.attrs);
|
2011-08-20 06:53:32 -07:00
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::getOwnPropertyNames(JSContext *cx, HandleObject wrapper,
|
|
|
|
AutoIdVector &props)
|
2011-08-20 06:53:32 -07:00
|
|
|
{
|
2013-02-25 13:54:18 -08:00
|
|
|
assertEnteredPolicy(cx, wrapper, JSID_VOID);
|
2012-03-27 16:31:37 -07:00
|
|
|
return enumerate(cx, wrapper, JSITER_OWNONLY | JSITER_HIDDEN, props);
|
|
|
|
}
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::delete_(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleId id, bool *bp)
|
2012-03-27 16:31:37 -07:00
|
|
|
{
|
2013-02-25 13:54:18 -08:00
|
|
|
assertEnteredPolicy(cx, wrapper, id);
|
2012-03-27 16:31:37 -07:00
|
|
|
|
2012-10-05 09:59:24 -07:00
|
|
|
// Check the expando object.
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject target(cx, Traits::getTargetObject(wrapper));
|
|
|
|
RootedObject expando(cx, Traits::singleton.getExpandoObject(cx, target, wrapper));
|
2012-10-05 09:59:24 -07:00
|
|
|
JSBool b = true;
|
|
|
|
if (expando) {
|
|
|
|
JSAutoCompartment ac(cx, expando);
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedValue v(cx);
|
|
|
|
if (!JS_DeletePropertyById2(cx, expando, id, v.address()) ||
|
2012-10-05 09:59:24 -07:00
|
|
|
!JS_ValueToBoolean(cx, v, &b))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*bp = !!b;
|
2012-10-05 09:59:24 -07:00
|
|
|
return true;
|
2012-03-27 16:31:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Base, typename Traits>
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::enumerate(JSContext *cx, HandleObject wrapper, unsigned flags,
|
|
|
|
AutoIdVector &props)
|
2012-03-27 16:31:37 -07:00
|
|
|
{
|
2013-02-25 13:54:18 -08:00
|
|
|
assertEnteredPolicy(cx, wrapper, JSID_VOID);
|
2012-09-11 01:05:10 -07:00
|
|
|
if (!AccessCheck::wrapperSubsumes(wrapper)) {
|
2011-08-20 06:53:32 -07:00
|
|
|
JS_ReportError(cx, "Not allowed to enumerate cross origin objects");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:59:24 -07:00
|
|
|
// Enumerate expando properties first. Note that the expando object lives
|
|
|
|
// in the target compartment.
|
2013-03-27 04:33:30 -07:00
|
|
|
RootedObject target(cx, Traits::singleton.getTargetObject(wrapper));
|
|
|
|
RootedObject expando(cx, Traits::singleton.getExpandoObject(cx, target, wrapper));
|
2012-10-05 09:59:24 -07:00
|
|
|
if (expando) {
|
|
|
|
JSAutoCompartment ac(cx, expando);
|
|
|
|
if (!js::GetPropertyNames(cx, expando, flags, &props))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!JS_WrapAutoIdVector(cx, props))
|
|
|
|
return false;
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
return Traits::enumerateNames(cx, wrapper, flags, props);
|
|
|
|
}
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::enumerate(JSContext *cx, HandleObject wrapper,
|
|
|
|
AutoIdVector &props)
|
2012-03-27 16:31:37 -07:00
|
|
|
{
|
|
|
|
return enumerate(cx, wrapper, 0, props);
|
2011-05-25 08:30:50 -07:00
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
2011-05-25 08:30:50 -07:00
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::get(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleObject receiver, HandleId id,
|
|
|
|
MutableHandleValue vp)
|
2011-05-25 08:30:50 -07:00
|
|
|
{
|
2012-03-27 16:31:37 -07:00
|
|
|
// Skip our Base if it isn't already ProxyHandler.
|
|
|
|
// NB: None of the functions we call are prepared for the receiver not
|
|
|
|
// being the wrapper, so ignore the receiver here.
|
2013-03-27 04:33:30 -07:00
|
|
|
return js::BaseProxyHandler::get(cx, wrapper, wrapper, id, vp);
|
2012-03-27 16:31:37 -07:00
|
|
|
}
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::set(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleObject receiver, HandleId id,
|
|
|
|
bool strict, MutableHandleValue vp)
|
2012-03-27 16:31:37 -07:00
|
|
|
{
|
2012-05-17 04:19:37 -07:00
|
|
|
// Skip our Base if it isn't already BaseProxyHandler.
|
2012-03-27 16:31:37 -07:00
|
|
|
// NB: None of the functions we call are prepared for the receiver not
|
|
|
|
// being the wrapper, so ignore the receiver here.
|
2013-03-27 04:33:30 -07:00
|
|
|
return js::BaseProxyHandler::set(cx, wrapper, wrapper, id, strict, vp);
|
2012-03-27 16:31:37 -07:00
|
|
|
}
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::has(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleId id, bool *bp)
|
2012-03-27 16:31:37 -07:00
|
|
|
{
|
|
|
|
// Skip our Base if it isn't already ProxyHandler.
|
2013-03-27 04:33:30 -07:00
|
|
|
return js::BaseProxyHandler::has(cx, wrapper, id, bp);
|
2012-03-27 16:31:37 -07:00
|
|
|
}
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::hasOwn(JSContext *cx, HandleObject wrapper,
|
|
|
|
HandleId id, bool *bp)
|
2012-03-27 16:31:37 -07:00
|
|
|
{
|
|
|
|
// Skip our Base if it isn't already ProxyHandler.
|
2013-03-27 04:33:30 -07:00
|
|
|
return js::BaseProxyHandler::hasOwn(cx, wrapper, id, bp);
|
2012-03-27 16:31:37 -07:00
|
|
|
}
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::keys(JSContext *cx, HandleObject wrapper,
|
|
|
|
AutoIdVector &props)
|
2012-03-27 16:31:37 -07:00
|
|
|
{
|
|
|
|
// Skip our Base if it isn't already ProxyHandler.
|
2013-03-27 04:33:30 -07:00
|
|
|
return js::BaseProxyHandler::keys(cx, wrapper, props);
|
2012-03-27 16:31:37 -07:00
|
|
|
}
|
2011-08-20 06:53:32 -07:00
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
|
|
|
bool
|
2013-03-27 04:33:30 -07:00
|
|
|
XrayWrapper<Base, Traits>::iterate(JSContext *cx, HandleObject wrapper,
|
|
|
|
unsigned flags, MutableHandleValue vp)
|
2012-03-27 16:31:37 -07:00
|
|
|
{
|
|
|
|
// Skip our Base if it isn't already ProxyHandler.
|
2013-03-27 04:33:30 -07:00
|
|
|
return js::BaseProxyHandler::iterate(cx, wrapper, flags, vp);
|
2012-03-27 16:31:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Base, typename Traits>
|
|
|
|
bool
|
2013-04-04 00:02:24 -07:00
|
|
|
XrayWrapper<Base, Traits>::call(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args)
|
2012-03-27 16:31:37 -07:00
|
|
|
{
|
2013-02-25 13:54:18 -08:00
|
|
|
assertEnteredPolicy(cx, wrapper, JSID_VOID);
|
2013-04-04 00:02:24 -07:00
|
|
|
return Traits::call(cx, wrapper, args);
|
2011-05-25 08:30:50 -07:00
|
|
|
}
|
|
|
|
|
2012-03-27 16:31:37 -07:00
|
|
|
template <typename Base, typename Traits>
|
2011-05-25 08:30:50 -07:00
|
|
|
bool
|
2013-04-04 00:02:24 -07:00
|
|
|
XrayWrapper<Base, Traits>::construct(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args)
|
2011-05-25 08:30:50 -07:00
|
|
|
{
|
2013-02-25 13:54:18 -08:00
|
|
|
assertEnteredPolicy(cx, wrapper, JSID_VOID);
|
2013-04-04 00:02:24 -07:00
|
|
|
return Traits::construct(cx, wrapper, args);
|
2011-05-25 08:30:50 -07:00
|
|
|
}
|
|
|
|
|
2012-11-14 09:56:25 -08:00
|
|
|
/*
|
|
|
|
* The Permissive / Security variants should be used depending on whether the
|
|
|
|
* compartment of the wrapper is guranteed to subsume the compartment of the
|
|
|
|
* wrapped object (i.e. - whether it is safe from a security perspective to
|
|
|
|
* unwrap the wrapper).
|
|
|
|
*/
|
|
|
|
|
|
|
|
template<>
|
|
|
|
PermissiveXrayXPCWN PermissiveXrayXPCWN::singleton(0);
|
|
|
|
template class PermissiveXrayXPCWN;
|
|
|
|
|
|
|
|
template<>
|
|
|
|
SecurityXrayXPCWN SecurityXrayXPCWN::singleton(0);
|
|
|
|
template class SecurityXrayXPCWN;
|
|
|
|
|
|
|
|
template<>
|
|
|
|
PermissiveXrayDOM PermissiveXrayDOM::singleton(0);
|
|
|
|
template class PermissiveXrayDOM;
|
|
|
|
|
|
|
|
template<>
|
|
|
|
SecurityXrayDOM SecurityXrayDOM::singleton(0);
|
|
|
|
template class SecurityXrayDOM;
|
|
|
|
|
|
|
|
template<>
|
|
|
|
SCPermissiveXrayXPCWN SCPermissiveXrayXPCWN::singleton(0);
|
|
|
|
template class SCPermissiveXrayXPCWN;
|
|
|
|
|
|
|
|
template<>
|
|
|
|
SCSecurityXrayXPCWN SCSecurityXrayXPCWN::singleton(0);
|
|
|
|
template class SCSecurityXrayXPCWN;
|
2011-05-25 08:30:50 -07:00
|
|
|
|
2012-11-14 09:56:25 -08:00
|
|
|
template<>
|
|
|
|
SCPermissiveXrayDOM SCPermissiveXrayDOM::singleton(0);
|
|
|
|
template class SCPermissiveXrayDOM;
|
2012-07-18 04:51:28 -07:00
|
|
|
|
2012-09-26 07:17:51 -07:00
|
|
|
static nsQueryInterface
|
2013-03-27 04:33:30 -07:00
|
|
|
do_QueryInterfaceNative(JSContext* cx, HandleObject wrapper)
|
2012-09-26 07:17:51 -07:00
|
|
|
{
|
|
|
|
nsISupports* nativeSupports;
|
|
|
|
if (IsWrapper(wrapper) && WrapperFactory::IsXrayWrapper(wrapper)) {
|
|
|
|
JSObject* target = XrayTraits::getTargetObject(wrapper);
|
|
|
|
if (GetXrayType(target) == XrayForDOMObject) {
|
|
|
|
if (!UnwrapDOMObjectToISupports(target, nativeSupports)) {
|
|
|
|
nativeSupports = nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
XPCWrappedNative *wn = GetWrappedNative(target);
|
|
|
|
nativeSupports = wn->Native();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsIXPConnect *xpc = nsXPConnect::GetXPConnect();
|
|
|
|
nativeSupports = xpc->GetNativeOfWrapper(cx, wrapper);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsQueryInterface(nativeSupports);
|
|
|
|
}
|
|
|
|
|
2010-07-02 14:09:48 -07:00
|
|
|
}
|