bug 724310 - drop cx argument from JSObject field and fixed slots infallible API. r=:Waldo
This commit is contained in:
@@ -59,47 +59,38 @@ namespace {
|
||||
|
||||
class AutoResolveFlag
|
||||
{
|
||||
JSContext* mContext;
|
||||
JSObject* mObj;
|
||||
uintN mOldFlags;
|
||||
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
|
||||
static uintN GetFlags(JSContext* cx, JSObject* obj) {
|
||||
jsval v;
|
||||
#ifdef DEBUG
|
||||
JSBool ok =
|
||||
#endif
|
||||
JS_GetReservedSlot(cx, obj, sFlagsSlot, &v);
|
||||
NS_ASSERTION(ok, "Failed to get CPOW flags");
|
||||
static uintN GetFlags(JSObject* obj) {
|
||||
jsval v = JS_GetReservedSlot(obj, sFlagsSlot);
|
||||
return JSVAL_TO_INT(v);
|
||||
}
|
||||
|
||||
static uintN SetFlags(JSContext* cx, JSObject* obj, uintN flags) {
|
||||
uintN oldFlags = GetFlags(cx, obj);
|
||||
static uintN SetFlags(JSObject* obj, uintN flags) {
|
||||
uintN oldFlags = GetFlags(obj);
|
||||
if (oldFlags != flags)
|
||||
JS_SetReservedSlot(cx, obj, sFlagsSlot, INT_TO_JSVAL(flags));
|
||||
JS_SetReservedSlot(obj, sFlagsSlot, INT_TO_JSVAL(flags));
|
||||
return oldFlags;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
AutoResolveFlag(JSContext* cx,
|
||||
JSObject* obj
|
||||
AutoResolveFlag(JSObject* obj
|
||||
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: mContext(cx)
|
||||
, mObj(obj)
|
||||
, mOldFlags(SetFlags(cx, obj,
|
||||
GetFlags(cx, obj) | CPOW_FLAG_RESOLVING))
|
||||
: mObj(obj)
|
||||
, mOldFlags(SetFlags(obj, GetFlags(obj) | CPOW_FLAG_RESOLVING))
|
||||
{
|
||||
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
}
|
||||
|
||||
~AutoResolveFlag() {
|
||||
SetFlags(mContext, mObj, mOldFlags);
|
||||
SetFlags(mObj, mOldFlags);
|
||||
}
|
||||
|
||||
static JSBool IsSet(JSContext* cx, JSObject* obj) {
|
||||
return GetFlags(cx, obj) & CPOW_FLAG_RESOLVING;
|
||||
static JSBool IsSet(JSObject* obj) {
|
||||
return GetFlags(obj) & CPOW_FLAG_RESOLVING;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -201,7 +192,7 @@ void
|
||||
ObjectWrapperParent::ActorDestroy(ActorDestroyReason)
|
||||
{
|
||||
if (mObj) {
|
||||
JS_SetPrivate(NULL, mObj, NULL);
|
||||
JS_SetPrivate(mObj, NULL);
|
||||
mObj = NULL;
|
||||
}
|
||||
}
|
||||
@@ -216,25 +207,28 @@ ObjectWrapperParent::Manager()
|
||||
JSObject*
|
||||
ObjectWrapperParent::GetJSObject(JSContext* cx) const
|
||||
{
|
||||
js::Class *clasp = const_cast<js::Class *>(&ObjectWrapperParent::sCPOW_JSClass);
|
||||
if (!mObj && (mObj = JS_NewObject(cx, js::Jsvalify(clasp), NULL, NULL))) {
|
||||
JS_SetPrivate(cx, mObj, (void*)this);
|
||||
JS_SetReservedSlot(cx, mObj, sFlagsSlot, JSVAL_ZERO);
|
||||
if (!mObj) {
|
||||
js::Class *clasp = const_cast<js::Class *>(&ObjectWrapperParent::sCPOW_JSClass);
|
||||
mObj = JS_NewObject(cx, js::Jsvalify(clasp), NULL, NULL);
|
||||
if (mObj) {
|
||||
JS_SetPrivate(mObj, (void*)this);
|
||||
JS_SetReservedSlot(mObj, sFlagsSlot, JSVAL_ZERO);
|
||||
}
|
||||
}
|
||||
return mObj;
|
||||
}
|
||||
|
||||
static ObjectWrapperParent*
|
||||
Unwrap(JSContext* cx, JSObject* obj)
|
||||
Unwrap(JSObject* obj)
|
||||
{
|
||||
while (js::GetObjectClass(obj) != &ObjectWrapperParent::sCPOW_JSClass)
|
||||
if (!(obj = js::GetObjectProto(obj)))
|
||||
return NULL;
|
||||
|
||||
ObjectWrapperParent* self =
|
||||
static_cast<ObjectWrapperParent*>(JS_GetPrivate(cx, obj));
|
||||
static_cast<ObjectWrapperParent*>(JS_GetPrivate(obj));
|
||||
|
||||
NS_ASSERTION(!self || self->GetJSObject(cx) == obj,
|
||||
NS_ASSERTION(!self || self->GetJSObjectOrNull() == obj,
|
||||
"Wrapper and wrapped object disagree?");
|
||||
|
||||
return self;
|
||||
@@ -259,7 +253,7 @@ ObjectWrapperParent::jsval_to_JSVariant(JSContext* cx, jsval from,
|
||||
case JSTYPE_OBJECT:
|
||||
{
|
||||
PObjectWrapperParent* powp;
|
||||
if (!JSObject_to_PObjectWrapperParent(cx, JSVAL_TO_OBJECT(from), &powp))
|
||||
if (!JSObject_to_PObjectWrapperParent(JSVAL_TO_OBJECT(from), &powp))
|
||||
return with_error(cx, false, "Cannot pass parent-created object to child");
|
||||
*to = powp;
|
||||
}
|
||||
@@ -322,14 +316,13 @@ ObjectWrapperParent::jsval_from_JSVariant(JSContext* cx, const JSVariant& from,
|
||||
|
||||
/*static*/ bool
|
||||
ObjectWrapperParent::
|
||||
JSObject_to_PObjectWrapperParent(JSContext* cx, JSObject* from,
|
||||
PObjectWrapperParent** to)
|
||||
JSObject_to_PObjectWrapperParent(JSObject* from, PObjectWrapperParent** to)
|
||||
{
|
||||
if (!from) {
|
||||
*to = NULL;
|
||||
return true;
|
||||
}
|
||||
ObjectWrapperParent* owp = Unwrap(cx, from);
|
||||
ObjectWrapperParent* owp = Unwrap(from);
|
||||
if (!owp)
|
||||
return false;
|
||||
*to = owp;
|
||||
@@ -401,11 +394,11 @@ ObjectWrapperParent::CPOW_AddProperty(JSContext *cx, JSObject *obj, jsid id,
|
||||
CPOW_LOG(("Calling CPOW_AddProperty (%s)...",
|
||||
JSVAL_TO_CSTR(cx, id)));
|
||||
|
||||
ObjectWrapperParent* self = Unwrap(cx, obj);
|
||||
ObjectWrapperParent* self = Unwrap(obj);
|
||||
if (!self)
|
||||
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_AddProperty");
|
||||
|
||||
if (AutoResolveFlag::IsSet(cx, obj))
|
||||
if (AutoResolveFlag::IsSet(obj))
|
||||
return JS_TRUE;
|
||||
|
||||
AutoCheckOperation aco(cx, self);
|
||||
@@ -428,7 +421,7 @@ ObjectWrapperParent::CPOW_GetProperty(JSContext *cx, JSObject *obj, jsid id,
|
||||
CPOW_LOG(("Calling CPOW_GetProperty (%s)...",
|
||||
JSVAL_TO_CSTR(cx, id)));
|
||||
|
||||
ObjectWrapperParent* self = Unwrap(cx, obj);
|
||||
ObjectWrapperParent* self = Unwrap(obj);
|
||||
if (!self)
|
||||
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_GetProperty");
|
||||
|
||||
@@ -455,7 +448,7 @@ ObjectWrapperParent::CPOW_SetProperty(JSContext *cx, JSObject *obj, jsid id,
|
||||
CPOW_LOG(("Calling CPOW_SetProperty (%s)...",
|
||||
JSVAL_TO_CSTR(cx, id)));
|
||||
|
||||
ObjectWrapperParent* self = Unwrap(cx, obj);
|
||||
ObjectWrapperParent* self = Unwrap(obj);
|
||||
if (!self)
|
||||
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_SetProperty");
|
||||
|
||||
@@ -484,7 +477,7 @@ ObjectWrapperParent::CPOW_DelProperty(JSContext *cx, JSObject *obj, jsid id,
|
||||
CPOW_LOG(("Calling CPOW_DelProperty (%s)...",
|
||||
JSVAL_TO_CSTR(cx, id)));
|
||||
|
||||
ObjectWrapperParent* self = Unwrap(cx, obj);
|
||||
ObjectWrapperParent* self = Unwrap(obj);
|
||||
if (!self)
|
||||
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_DelProperty");
|
||||
|
||||
@@ -538,7 +531,7 @@ ObjectWrapperParent::NewEnumerateNext(JSContext* cx, jsval* statep, jsid* idp)
|
||||
jsid_from_nsString(cx, out_id, idp))
|
||||
{
|
||||
JSObject* obj = GetJSObject(cx);
|
||||
AutoResolveFlag arf(cx, obj);
|
||||
AutoResolveFlag arf(obj);
|
||||
return JS_DefinePropertyById(cx, obj, *idp, JSVAL_VOID, NULL, NULL,
|
||||
JSPROP_ENUMERATE);
|
||||
}
|
||||
@@ -565,7 +558,7 @@ ObjectWrapperParent::CPOW_NewEnumerate(JSContext *cx, JSObject *obj,
|
||||
{
|
||||
CPOW_LOG(("Calling CPOW_NewEnumerate..."));
|
||||
|
||||
ObjectWrapperParent* self = Unwrap(cx, obj);
|
||||
ObjectWrapperParent* self = Unwrap(obj);
|
||||
if (!self)
|
||||
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_NewEnumerate");
|
||||
|
||||
@@ -591,7 +584,7 @@ ObjectWrapperParent::CPOW_NewResolve(JSContext *cx, JSObject *obj, jsid id,
|
||||
CPOW_LOG(("Calling CPOW_NewResolve (%s)...",
|
||||
JSVAL_TO_CSTR(cx, id)));
|
||||
|
||||
ObjectWrapperParent* self = Unwrap(cx, obj);
|
||||
ObjectWrapperParent* self = Unwrap(obj);
|
||||
if (!self)
|
||||
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_NewResolve");
|
||||
|
||||
@@ -612,7 +605,7 @@ ObjectWrapperParent::CPOW_NewResolve(JSContext *cx, JSObject *obj, jsid id,
|
||||
return JS_FALSE;
|
||||
|
||||
if (*objp) {
|
||||
AutoResolveFlag arf(cx, *objp);
|
||||
AutoResolveFlag arf(*objp);
|
||||
JS_DefinePropertyById(cx, *objp, id, JSVAL_VOID, NULL, NULL,
|
||||
JSPROP_ENUMERATE);
|
||||
}
|
||||
@@ -626,7 +619,7 @@ ObjectWrapperParent::CPOW_Convert(JSContext *cx, JSObject *obj, JSType type,
|
||||
CPOW_LOG(("Calling CPOW_Convert (to %s)...",
|
||||
JS_GetTypeName(cx, type)));
|
||||
|
||||
ObjectWrapperParent* self = Unwrap(cx, obj);
|
||||
ObjectWrapperParent* self = Unwrap(obj);
|
||||
if (!self)
|
||||
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_Convert");
|
||||
|
||||
@@ -640,7 +633,7 @@ ObjectWrapperParent::CPOW_Finalize(JSContext* cx, JSObject* obj)
|
||||
{
|
||||
CPOW_LOG(("Calling CPOW_Finalize..."));
|
||||
|
||||
ObjectWrapperParent* self = Unwrap(cx, obj);
|
||||
ObjectWrapperParent* self = Unwrap(obj);
|
||||
if (self) {
|
||||
self->mObj = NULL;
|
||||
unused << ObjectWrapperParent::Send__delete__(self);
|
||||
@@ -657,13 +650,13 @@ ObjectWrapperParent::CPOW_Call(JSContext* cx, uintN argc, jsval* vp)
|
||||
return JS_FALSE;
|
||||
|
||||
ObjectWrapperParent* function =
|
||||
Unwrap(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
|
||||
Unwrap(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
|
||||
if (!function)
|
||||
return with_error(cx, JS_FALSE, "Could not unwrap CPOW function");
|
||||
|
||||
AutoCheckOperation aco(cx, function);
|
||||
|
||||
ObjectWrapperParent* receiver = Unwrap(cx, thisobj);
|
||||
ObjectWrapperParent* receiver = Unwrap(thisobj);
|
||||
if (!receiver) {
|
||||
// Substitute child global for parent global object.
|
||||
// TODO First make sure we're really replacing the global object?
|
||||
@@ -692,7 +685,7 @@ ObjectWrapperParent::CPOW_Construct(JSContext* cx, uintN argc, jsval* vp)
|
||||
{
|
||||
CPOW_LOG(("Calling CPOW_Construct..."));
|
||||
|
||||
ObjectWrapperParent* constructor = Unwrap(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
|
||||
ObjectWrapperParent* constructor = Unwrap(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)));
|
||||
if (!constructor)
|
||||
return with_error(cx, JS_FALSE, "Could not unwrap CPOW constructor function");
|
||||
|
||||
@@ -720,7 +713,7 @@ ObjectWrapperParent::CPOW_HasInstance(JSContext *cx, JSObject *obj, const jsval
|
||||
|
||||
*bp = JS_FALSE;
|
||||
|
||||
ObjectWrapperParent* self = Unwrap(cx, obj);
|
||||
ObjectWrapperParent* self = Unwrap(obj);
|
||||
if (!self)
|
||||
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_HasInstance");
|
||||
|
||||
@@ -745,14 +738,14 @@ ObjectWrapperParent::CPOW_Equality(JSContext *cx, JSObject *obj, const jsval *v,
|
||||
|
||||
*bp = JS_FALSE;
|
||||
|
||||
ObjectWrapperParent* self = Unwrap(cx, obj);
|
||||
ObjectWrapperParent* self = Unwrap(obj);
|
||||
if (!self)
|
||||
return with_error(cx, JS_FALSE, "Unwrapping failed in CPOW_Equality");
|
||||
|
||||
if (JSVAL_IS_PRIMITIVE(*v))
|
||||
return JS_TRUE;
|
||||
|
||||
ObjectWrapperParent* other = Unwrap(cx, JSVAL_TO_OBJECT(*v));
|
||||
ObjectWrapperParent* other = Unwrap(JSVAL_TO_OBJECT(*v));
|
||||
if (!other)
|
||||
return JS_TRUE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user