Bug 778085 - Add simple withPrototype versions of DirectWrapper and CrossCompartmentWrapper. r=ejpbruel

These are helpful for testing, and will also be useful in XPConnect. Note that the Wrapper
and Proxy hierarchy will soon be merged.

--HG--
extra : rebase_source : c9c846871a0bba4c9574eb5274dfe22f24d183b0
This commit is contained in:
Bobby Holley 2012-08-10 13:55:55 +02:00
parent c623bc5cfa
commit 3ad4456011
2 changed files with 13 additions and 5 deletions

View File

@ -202,9 +202,10 @@ IndirectWrapper::enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props
GET(IndirectProxyHandler::enumerate(cx, wrapper, props));
}
DirectWrapper::DirectWrapper(unsigned flags) : Wrapper(flags),
DirectWrapper::DirectWrapper(unsigned flags, bool hasPrototype) : Wrapper(flags),
DirectProxyHandler(&sWrapperFamily)
{
setHasPrototype(hasPrototype);
}
DirectWrapper::~DirectWrapper()
@ -216,6 +217,7 @@ DirectWrapper::getPropertyDescriptor(JSContext *cx, JSObject *wrapper,
jsid id, bool set,
PropertyDescriptor *desc)
{
JS_ASSERT(!hasPrototype()); // Should never be called when there's a prototype.
desc->obj = NULL; // default result if we refuse to perform this action
CHECKED(DirectProxyHandler::getPropertyDescriptor(cx, wrapper, id, set, desc),
set ? SET : GET);
@ -256,6 +258,7 @@ DirectWrapper::delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
bool
DirectWrapper::enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props)
{
JS_ASSERT(!hasPrototype()); // Should never be called when there's a prototype.
// if we refuse to perform this action, props remains empty
static jsid id = JSID_VOID;
GET(DirectProxyHandler::enumerate(cx, wrapper, props));
@ -264,6 +267,7 @@ DirectWrapper::enumerate(JSContext *cx, JSObject *wrapper, AutoIdVector &props)
bool
DirectWrapper::has(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
{
JS_ASSERT(!hasPrototype()); // Should never be called when there's a prototype.
*bp = false; // default result if we refuse to perform this action
GET(DirectProxyHandler::has(cx, wrapper, id, bp));
}
@ -300,6 +304,7 @@ DirectWrapper::keys(JSContext *cx, JSObject *wrapper, AutoIdVector &props)
bool
DirectWrapper::iterate(JSContext *cx, JSObject *wrapper, unsigned flags, Value *vp)
{
JS_ASSERT(!hasPrototype()); // Should never be called when there's a prototype.
vp->setUndefined(); // default result if we refuse to perform this action
const jsid id = JSID_VOID;
GET(DirectProxyHandler::iterate(cx, wrapper, flags, vp));
@ -371,6 +376,7 @@ DirectWrapper::fun_toString(JSContext *cx, JSObject *wrapper, unsigned indent)
}
DirectWrapper DirectWrapper::singleton((unsigned)0);
DirectWrapper DirectWrapper::singletonWithPrototype((unsigned)0, true);
/* Compartments. */
@ -484,8 +490,8 @@ ErrorCopier::~ErrorCopier()
/* Cross compartment wrappers. */
CrossCompartmentWrapper::CrossCompartmentWrapper(unsigned flags)
: DirectWrapper(CROSS_COMPARTMENT | flags)
CrossCompartmentWrapper::CrossCompartmentWrapper(unsigned flags, bool hasPrototype)
: DirectWrapper(CROSS_COMPARTMENT | flags, hasPrototype)
{
}

View File

@ -162,7 +162,7 @@ class JS_FRIEND_API(IndirectWrapper) : public Wrapper,
class JS_FRIEND_API(DirectWrapper) : public Wrapper, public DirectProxyHandler
{
public:
explicit DirectWrapper(unsigned flags);
explicit DirectWrapper(unsigned flags, bool hasPrototype = false);
virtual ~DirectWrapper();
@ -209,6 +209,7 @@ class JS_FRIEND_API(DirectWrapper) : public Wrapper, public DirectProxyHandler
virtual JSString *fun_toString(JSContext *cx, JSObject *wrapper, unsigned indent) MOZ_OVERRIDE;
static DirectWrapper singleton;
static DirectWrapper singletonWithPrototype;
static void *getWrapperFamily();
};
@ -217,7 +218,7 @@ class JS_FRIEND_API(DirectWrapper) : public Wrapper, public DirectProxyHandler
class JS_FRIEND_API(CrossCompartmentWrapper) : public DirectWrapper
{
public:
CrossCompartmentWrapper(unsigned flags);
CrossCompartmentWrapper(unsigned flags, bool hasPrototype = false);
virtual ~CrossCompartmentWrapper();
@ -254,6 +255,7 @@ class JS_FRIEND_API(CrossCompartmentWrapper) : public DirectWrapper
virtual bool iteratorNext(JSContext *cx, JSObject *wrapper, Value *vp);
static CrossCompartmentWrapper singleton;
static CrossCompartmentWrapper singletonWithPrototype;
};
/*