зеркало из https://github.com/mozilla/gecko-dev.git
Fixing bug 413559. Make XPConnect use faster accessors for JS class/parent/private/proto. r=mrbkap@gmail.com, sr=brendan@mozilla.org
This commit is contained in:
Родитель
ede517d088
Коммит
e6a7385bbe
|
@ -1379,10 +1379,8 @@ mozJSComponentLoader::Import(const nsACString & registryLocation)
|
|||
NS_ERROR("null calling object");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSObject *parent;
|
||||
while ((parent = JS_GetParent(cx, targetObject)))
|
||||
targetObject = parent;
|
||||
|
||||
targetObject = JS_GetGlobalForObject(cx, targetObject);
|
||||
}
|
||||
|
||||
JSObject *globalObj = nsnull;
|
||||
|
|
|
@ -149,10 +149,10 @@ ThrowException(nsresult ex, JSContext *cx)
|
|||
// Get the (possibly non-existant) XOW off of an object
|
||||
static inline
|
||||
JSObject *
|
||||
GetWrapper(JSContext *cx, JSObject *obj)
|
||||
GetWrapper(JSObject *obj)
|
||||
{
|
||||
while (JS_GET_CLASS(cx, obj) != &sXPC_XOW_JSClass.base) {
|
||||
obj = JS_GetPrototype(cx, obj);
|
||||
while (STOBJ_GET_CLASS(obj) != &sXPC_XOW_JSClass.base) {
|
||||
obj = STOBJ_GET_PROTO(obj);
|
||||
if (!obj) {
|
||||
break;
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ static inline
|
|||
JSObject *
|
||||
GetWrappedObject(JSContext *cx, JSObject *wrapper)
|
||||
{
|
||||
if (JS_GET_CLASS(cx, wrapper) != &sXPC_XOW_JSClass.base) {
|
||||
if (STOBJ_GET_CLASS(wrapper) != &sXPC_XOW_JSClass.base) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
@ -230,10 +230,10 @@ XPC_XOW_WrapperMoved(JSContext *cx, XPCWrappedNative *innerObj,
|
|||
}
|
||||
|
||||
static JSBool
|
||||
IsValFrame(JSContext *cx, JSObject *obj, jsval v, XPCWrappedNative *wn)
|
||||
IsValFrame(JSObject *obj, jsval v, XPCWrappedNative *wn)
|
||||
{
|
||||
// Fast path for the common case.
|
||||
if (JS_GET_CLASS(cx, obj)->name[0] != 'W') {
|
||||
if (STOBJ_GET_CLASS(obj)->name[0] != 'W') {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -321,7 +321,7 @@ XPC_XOW_FunctionWrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
// We disallow invalid XOWs that have no wrapped object. Otherwise,
|
||||
// if it isn't an XOW, then pass it through as-is.
|
||||
|
||||
wrappedObj = GetWrapper(cx, obj);
|
||||
wrappedObj = GetWrapper(obj);
|
||||
if (wrappedObj) {
|
||||
wrappedObj = GetWrappedObject(cx, wrappedObj);
|
||||
if (!wrappedObj) {
|
||||
|
@ -377,7 +377,7 @@ WrapSameOriginProp(JSContext *cx, JSObject *outerObj, jsval *vp)
|
|||
}
|
||||
|
||||
JSObject *wrappedObj = JSVAL_TO_OBJECT(*vp);
|
||||
JSClass *clasp = JS_GET_CLASS(cx, wrappedObj);
|
||||
JSClass *clasp = STOBJ_GET_CLASS(wrappedObj);
|
||||
if (XPC_XOW_ClassNeedsXOW(clasp->name)) {
|
||||
return XPC_XOW_WrapObject(cx, JS_GetGlobalForObject(cx, outerObj), vp);
|
||||
}
|
||||
|
@ -385,14 +385,14 @@ WrapSameOriginProp(JSContext *cx, JSObject *outerObj, jsval *vp)
|
|||
// Check if wrappedObj is an XOW. If so, verify that it's from the
|
||||
// right scope.
|
||||
if (clasp == &sXPC_XOW_JSClass.base &&
|
||||
JS_GetParent(cx, wrappedObj) != JS_GetParent(cx, outerObj)) {
|
||||
STOBJ_GET_PARENT(wrappedObj) != STOBJ_GET_PARENT(outerObj)) {
|
||||
*vp = OBJECT_TO_JSVAL(GetWrappedObject(cx, wrappedObj));
|
||||
return XPC_XOW_WrapObject(cx, JS_GetParent(cx, outerObj), vp);
|
||||
return XPC_XOW_WrapObject(cx, STOBJ_GET_PARENT(outerObj), vp);
|
||||
}
|
||||
|
||||
if (JS_ObjectIsFunction(cx, wrappedObj) &&
|
||||
JS_GetFunctionNative(cx, reinterpret_cast<JSFunction *>
|
||||
(JS_GetPrivate(cx, wrappedObj))) ==
|
||||
(xpc_GetJSPrivate(wrappedObj))) ==
|
||||
XPCWrapper::sEvalNative) {
|
||||
return XPC_XOW_WrapFunction(cx, outerObj, wrappedObj, vp);
|
||||
}
|
||||
|
@ -405,7 +405,8 @@ XPC_XOW_WrapFunction(JSContext *cx, JSObject *outerObj, JSObject *funobj,
|
|||
jsval *rval)
|
||||
{
|
||||
jsval funobjVal = OBJECT_TO_JSVAL(funobj);
|
||||
JSFunction *wrappedFun = reinterpret_cast<JSFunction *>(JS_GetPrivate(cx, funobj));
|
||||
JSFunction *wrappedFun =
|
||||
reinterpret_cast<JSFunction *>(xpc_GetJSPrivate(funobj));
|
||||
JSNative native = JS_GetFunctionNative(cx, wrappedFun);
|
||||
if (!native || native == XPC_XOW_FunctionWrapper) {
|
||||
*rval = funobjVal;
|
||||
|
@ -444,8 +445,8 @@ XPC_XOW_RewrapIfNeeded(JSContext *cx, JSObject *outerObj, jsval *vp)
|
|||
return XPC_XOW_WrapFunction(cx, outerObj, obj, vp);
|
||||
}
|
||||
|
||||
if (JS_GET_CLASS(cx, obj) == &sXPC_XOW_JSClass.base &&
|
||||
JS_GetParent(cx, outerObj) != JS_GetParent(cx, obj)) {
|
||||
if (STOBJ_GET_CLASS(obj) == &sXPC_XOW_JSClass.base &&
|
||||
STOBJ_GET_PARENT(outerObj) != STOBJ_GET_PARENT(obj)) {
|
||||
*vp = OBJECT_TO_JSVAL(GetWrappedObject(cx, obj));
|
||||
} else if (!XPCWrappedNative::GetWrappedNativeOfJSObject(cx, obj)) {
|
||||
return JS_TRUE;
|
||||
|
@ -462,7 +463,7 @@ XPC_XOW_WrapObject(JSContext *cx, JSObject *parent, jsval *vp)
|
|||
XPCWrappedNative *wn;
|
||||
if (!JSVAL_IS_OBJECT(*vp) ||
|
||||
!(wrappedObj = JSVAL_TO_OBJECT(*vp)) ||
|
||||
JS_GET_CLASS(cx, wrappedObj) == &sXPC_XOW_JSClass.base ||
|
||||
STOBJ_GET_CLASS(wrappedObj) == &sXPC_XOW_JSClass.base ||
|
||||
!(wn = XPCWrappedNative::GetWrappedNativeOfJSObject(cx, wrappedObj))) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -473,7 +474,7 @@ XPC_XOW_WrapObject(JSContext *cx, JSObject *parent, jsval *vp)
|
|||
|
||||
// The parent must be the inner global object for its scope.
|
||||
parent = JS_GetGlobalForObject(cx, parent);
|
||||
JSClass *clasp = JS_GET_CLASS(cx, parent);
|
||||
JSClass *clasp = STOBJ_GET_CLASS(parent);
|
||||
if (clasp->flags & JSCLASS_IS_EXTENDED) {
|
||||
JSExtendedClass *xclasp = reinterpret_cast<JSExtendedClass *>(clasp);
|
||||
if (xclasp->innerObject) {
|
||||
|
@ -489,7 +490,7 @@ XPC_XOW_WrapObject(JSContext *cx, JSObject *parent, jsval *vp)
|
|||
|
||||
#ifdef DEBUG_mrbkap
|
||||
printf("Wrapping object at %p (%s) [%p]\n",
|
||||
(void *)wrappedObj, JS_GET_CLASS(cx, wrappedObj)->name,
|
||||
(void *)wrappedObj, STOBJ_GET_CLASS(wrappedObj)->name,
|
||||
(void *)parentScope);
|
||||
#endif
|
||||
|
||||
|
@ -502,7 +503,7 @@ XPC_XOW_WrapObject(JSContext *cx, JSObject *parent, jsval *vp)
|
|||
}
|
||||
|
||||
if (outerObj) {
|
||||
NS_ASSERTION(JS_GET_CLASS(cx, outerObj) == &sXPC_XOW_JSClass.base,
|
||||
NS_ASSERTION(STOBJ_GET_CLASS(outerObj) == &sXPC_XOW_JSClass.base,
|
||||
"What crazy object are we getting here?");
|
||||
#ifdef DEBUG_mrbkap
|
||||
printf("But found a wrapper in the map %p!\n", (void *)outerObj);
|
||||
|
@ -550,7 +551,7 @@ XPC_XOW_AddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
// All AddProperty needs to do is pass on addProperty requests to
|
||||
// same-origin objects, and throw for all else.
|
||||
|
||||
obj = GetWrapper(cx, obj);
|
||||
obj = GetWrapper(obj);
|
||||
jsval resolving;
|
||||
if (!JS_GetReservedSlot(cx, obj, XPCWrapper::sResolvingSlot, &resolving)) {
|
||||
return JS_FALSE;
|
||||
|
@ -618,7 +619,7 @@ XPC_XOW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
|
|||
}
|
||||
|
||||
JSObject *origObj = obj;
|
||||
obj = GetWrapper(cx, obj);
|
||||
obj = GetWrapper(obj);
|
||||
if (!obj) {
|
||||
return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx);
|
||||
}
|
||||
|
@ -648,7 +649,7 @@ XPC_XOW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
|
|||
XPCWrappedNative *wn =
|
||||
XPCWrappedNative::GetWrappedNativeOfJSObject(cx, wrappedObj);
|
||||
NS_ASSERTION(wn, "How did we wrap a non-WrappedNative?");
|
||||
if (!IsValFrame(cx, wrappedObj, id, wn)) {
|
||||
if (!IsValFrame(wrappedObj, id, wn)) {
|
||||
nsIScriptSecurityManager *ssm = GetSecurityManager();
|
||||
if (!ssm) {
|
||||
return ThrowException(NS_ERROR_NOT_INITIALIZED, cx);
|
||||
|
@ -658,7 +659,7 @@ XPC_XOW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
|
|||
? (PRUint32)nsIXPCSecurityManager::ACCESS_SET_PROPERTY
|
||||
: (PRUint32)nsIXPCSecurityManager::ACCESS_GET_PROPERTY;
|
||||
rv = ssm->CheckPropertyAccess(cx, wrappedObj,
|
||||
JS_GET_CLASS(cx, wrappedObj)->name,
|
||||
STOBJ_GET_CLASS(wrappedObj)->name,
|
||||
id, check);
|
||||
if (NS_FAILED(rv)) {
|
||||
// The security manager threw an exception for us.
|
||||
|
@ -678,7 +679,7 @@ XPC_XOW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
|
|||
JSBool checkProto =
|
||||
(isSet && id == GetRTStringByIndex(cx, XPCJSRuntime::IDX_PROTO));
|
||||
if (checkProto) {
|
||||
proto = JS_GetPrototype(cx, wrappedObj);
|
||||
proto = STOBJ_GET_PROTO(wrappedObj);
|
||||
}
|
||||
|
||||
// Same origin, pass this request along as though nothing interesting
|
||||
|
@ -697,7 +698,7 @@ XPC_XOW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
|
|||
}
|
||||
|
||||
if (checkProto) {
|
||||
JSObject *newProto = JS_GetPrototype(cx, wrappedObj);
|
||||
JSObject *newProto = STOBJ_GET_PROTO(wrappedObj);
|
||||
|
||||
// If code is trying to set obj.__proto__ and we're on obj's
|
||||
// prototype chain, then the OBJ_SET_PROPERTY above will do the
|
||||
|
@ -742,7 +743,7 @@ XPC_XOW_SetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
XPC_XOW_Enumerate(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
obj = GetWrapper(cx, obj);
|
||||
obj = GetWrapper(obj);
|
||||
JSObject *wrappedObj = GetWrappedObject(cx, obj);
|
||||
if (!wrappedObj) {
|
||||
// Nothing to enumerate.
|
||||
|
@ -765,7 +766,7 @@ JS_STATIC_DLL_CALLBACK(JSBool)
|
|||
XPC_XOW_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
|
||||
JSObject **objp)
|
||||
{
|
||||
obj = GetWrapper(cx, obj);
|
||||
obj = GetWrapper(obj);
|
||||
|
||||
JSObject *wrappedObj = GetWrappedObject(cx, obj);
|
||||
if (!wrappedObj) {
|
||||
|
@ -788,7 +789,7 @@ XPC_XOW_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
|
|||
XPCWrappedNative *wn =
|
||||
XPCWrappedNative::GetWrappedNativeOfJSObject(cx, wrappedObj);
|
||||
NS_ASSERTION(wn, "How did we wrap a non-WrappedNative?");
|
||||
if (!IsValFrame(cx, wrappedObj, id, wn)) {
|
||||
if (!IsValFrame(wrappedObj, id, wn)) {
|
||||
nsIScriptSecurityManager *ssm = GetSecurityManager();
|
||||
if (!ssm) {
|
||||
return ThrowException(NS_ERROR_NOT_INITIALIZED, cx);
|
||||
|
@ -797,7 +798,7 @@ XPC_XOW_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
|
|||
? (PRUint32)nsIXPCSecurityManager::ACCESS_SET_PROPERTY
|
||||
: (PRUint32)nsIXPCSecurityManager::ACCESS_GET_PROPERTY;
|
||||
rv = ssm->CheckPropertyAccess(cx, wrappedObj,
|
||||
JS_GET_CLASS(cx, wrappedObj)->name,
|
||||
STOBJ_GET_CLASS(wrappedObj)->name,
|
||||
id, action);
|
||||
if (NS_FAILED(rv)) {
|
||||
// The security manager threw an exception for us.
|
||||
|
@ -865,7 +866,7 @@ XPC_XOW_Convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
if (!JS_GET_CLASS(cx, wrappedObj)->convert(cx, wrappedObj, type, vp)) {
|
||||
if (!STOBJ_GET_CLASS(wrappedObj)->convert(cx, wrappedObj, type, vp)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -947,7 +948,7 @@ JS_STATIC_DLL_CALLBACK(JSBool)
|
|||
XPC_XOW_Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
{
|
||||
JSObject *realObj = GetWrapper(cx, JSVAL_TO_OBJECT(argv[-2]));
|
||||
JSObject *realObj = GetWrapper(JSVAL_TO_OBJECT(argv[-2]));
|
||||
JSObject *wrappedObj = GetWrappedObject(cx, realObj);
|
||||
if (!wrappedObj) {
|
||||
// Nothing to construct.
|
||||
|
@ -986,7 +987,7 @@ XPC_XOW_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JSClass *clasp = JS_GET_CLASS(cx, iface);
|
||||
JSClass *clasp = STOBJ_GET_CLASS(iface);
|
||||
|
||||
*bp = JS_FALSE;
|
||||
if (!clasp->hasInstance) {
|
||||
|
@ -1017,7 +1018,7 @@ XPC_XOW_Equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
|
|||
}
|
||||
|
||||
JSObject *test = JSVAL_TO_OBJECT(v);
|
||||
if (JS_GET_CLASS(cx, test) == &sXPC_XOW_JSClass.base) {
|
||||
if (STOBJ_GET_CLASS(test) == &sXPC_XOW_JSClass.base) {
|
||||
if (!JS_GetReservedSlot(cx, test, XPCWrapper::sWrappedObjSlot, &v)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
@ -1044,7 +1045,7 @@ XPC_XOW_Equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
|
|||
XPCWrappedNative *me = XPCWrappedNative::GetWrappedNativeOfJSObject(cx, obj);
|
||||
obj = me->GetFlatJSObject();
|
||||
test = other->GetFlatJSObject();
|
||||
return ((JSExtendedClass *)JS_GET_CLASS(cx, obj))->
|
||||
return ((JSExtendedClass *)STOBJ_GET_CLASS(obj))->
|
||||
equality(cx, obj, OBJECT_TO_JSVAL(test), bp);
|
||||
}
|
||||
|
||||
|
@ -1089,7 +1090,7 @@ JS_STATIC_DLL_CALLBACK(JSBool)
|
|||
XPC_XOW_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
{
|
||||
obj = GetWrapper(cx, obj);
|
||||
obj = GetWrapper(obj);
|
||||
if (!obj) {
|
||||
return ThrowException(NS_ERROR_UNEXPECTED, cx);
|
||||
}
|
||||
|
@ -1114,7 +1115,7 @@ XPC_XOW_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
return ThrowException(NS_ERROR_NOT_INITIALIZED, cx);
|
||||
}
|
||||
rv = ssm->CheckPropertyAccess(cx, wrappedObj,
|
||||
JS_GET_CLASS(cx, wrappedObj)->name,
|
||||
STOBJ_GET_CLASS(wrappedObj)->name,
|
||||
GetRTStringByIndex(cx, XPCJSRuntime::IDX_TO_STRING),
|
||||
nsIXPCSecurityManager::ACCESS_GET_PROPERTY);
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
inline
|
||||
XPCDispParamPropJSClass* GetParamProp(JSContext* cx, JSObject* obj)
|
||||
{
|
||||
return reinterpret_cast<XPCDispParamPropJSClass*>(JS_GetPrivate(cx, obj));
|
||||
return reinterpret_cast<XPCDispParamPropJSClass*>(xpc_GetJSPrivate(cx, obj));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -125,16 +125,16 @@ JSExtendedClass XPCNativeWrapper::sXPC_NW_JSClass = {
|
|||
//
|
||||
// in the call from XPC_NW_Convert, for example.
|
||||
|
||||
#define XPC_NW_CALL_HOOK(cx, obj, hook, args) \
|
||||
return JS_GET_CLASS(cx, obj)->hook args;
|
||||
#define XPC_NW_CALL_HOOK(obj, hook, args) \
|
||||
return STOBJ_GET_CLASS(obj)->hook args;
|
||||
|
||||
#define XPC_NW_CAST_HOOK(cx, obj, type, hook, args) \
|
||||
return ((type) JS_GET_CLASS(cx, obj)->hook) args;
|
||||
#define XPC_NW_CAST_HOOK(obj, type, hook, args) \
|
||||
return ((type) STOBJ_GET_CLASS(obj)->hook) args;
|
||||
|
||||
static JSBool
|
||||
ShouldBypassNativeWrapper(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
NS_ASSERTION(XPCNativeWrapper::IsNativeWrapper(cx, obj),
|
||||
NS_ASSERTION(XPCNativeWrapper::IsNativeWrapper(obj),
|
||||
"Unexpected object");
|
||||
jsval flags;
|
||||
|
||||
|
@ -158,7 +158,7 @@ ShouldBypassNativeWrapper(JSContext *cx, JSObject *obj)
|
|||
#define XPC_NW_BYPASS_BASE(cx, obj, code) \
|
||||
JS_BEGIN_MACRO \
|
||||
if (ShouldBypassNativeWrapper(cx, obj)) { \
|
||||
XPCWrappedNative *wn_ = XPCNativeWrapper::GetWrappedNative(cx, obj); \
|
||||
XPCWrappedNative *wn_ = XPCNativeWrapper::GetWrappedNative(obj); \
|
||||
if (!wn_) { \
|
||||
return JS_TRUE; \
|
||||
} \
|
||||
|
@ -168,14 +168,14 @@ ShouldBypassNativeWrapper(JSContext *cx, JSObject *obj)
|
|||
JS_END_MACRO
|
||||
|
||||
#define XPC_NW_BYPASS(cx, obj, hook, args) \
|
||||
XPC_NW_BYPASS_BASE(cx, obj, XPC_NW_CALL_HOOK(cx, obj, hook, args))
|
||||
XPC_NW_BYPASS_BASE(cx, obj, XPC_NW_CALL_HOOK(obj, hook, args))
|
||||
|
||||
#define XPC_NW_BYPASS_CAST(cx, obj, type, hook, args) \
|
||||
XPC_NW_BYPASS_BASE(cx, obj, XPC_NW_CAST_HOOK(cx, obj, type, hook, args))
|
||||
XPC_NW_BYPASS_BASE(cx, obj, XPC_NW_CAST_HOOK(obj, type, hook, args))
|
||||
|
||||
#define XPC_NW_BYPASS_TEST(cx, obj, hook, args) \
|
||||
XPC_NW_BYPASS_BASE(cx, obj, \
|
||||
JSClass *clasp_ = JS_GET_CLASS(cx, obj); \
|
||||
JSClass *clasp_ = STOBJ_GET_CLASS(obj); \
|
||||
return !clasp_->hook || clasp_->hook args; \
|
||||
)
|
||||
|
||||
|
@ -335,7 +335,7 @@ XPC_NW_DelProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
JSBool
|
||||
XPC_NW_RewrapIfDeepWrapper(JSContext *cx, JSObject *obj, jsval v, jsval *rval)
|
||||
{
|
||||
NS_ASSERTION(XPCNativeWrapper::IsNativeWrapper(cx, obj),
|
||||
NS_ASSERTION(XPCNativeWrapper::IsNativeWrapper(obj),
|
||||
"Unexpected object");
|
||||
|
||||
JSBool primitive = JSVAL_IS_PRIMITIVE(v);
|
||||
|
@ -353,7 +353,7 @@ XPC_NW_RewrapIfDeepWrapper(JSContext *cx, JSObject *obj, jsval v, jsval *rval)
|
|||
// if (HAS_FLAGS(flags, FLAG_DEEP).
|
||||
if (HAS_FLAGS(flags, FLAG_DEEP) && !primitive) {
|
||||
// Unwrap a cross origin wrapper, since we're more restrictive.
|
||||
if (JS_GET_CLASS(cx, nativeObj) == &sXPC_XOW_JSClass.base) {
|
||||
if (STOBJ_GET_CLASS(nativeObj) == &sXPC_XOW_JSClass.base) {
|
||||
if (!::JS_GetReservedSlot(cx, nativeObj, XPCWrapper::sWrappedObjSlot,
|
||||
&v)) {
|
||||
return JS_FALSE;
|
||||
|
@ -378,7 +378,7 @@ XPC_NW_RewrapIfDeepWrapper(JSContext *cx, JSObject *obj, jsval v, jsval *rval)
|
|||
#ifdef DEBUG_XPCNativeWrapper
|
||||
printf("Rewrapping for deep explicit wrapper\n");
|
||||
#endif
|
||||
if (wrappedNative == XPCNativeWrapper::GetWrappedNative(cx, obj)) {
|
||||
if (wrappedNative == XPCNativeWrapper::GetWrappedNative(obj)) {
|
||||
// Already wrapped, return the wrapper.
|
||||
*rval = OBJECT_TO_JSVAL(obj);
|
||||
return JS_TRUE;
|
||||
|
@ -420,8 +420,8 @@ XPC_NW_FunctionWrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
obj = nsnull;
|
||||
}
|
||||
|
||||
while (obj && !XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
|
||||
obj = ::JS_GetPrototype(cx, obj);
|
||||
while (obj && !XPCNativeWrapper::IsNativeWrapper(obj)) {
|
||||
obj = STOBJ_GET_PROTO(obj);
|
||||
}
|
||||
|
||||
if (!obj) {
|
||||
|
@ -430,9 +430,8 @@ XPC_NW_FunctionWrapper(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
|
||||
// The real method we're going to call is the parent of this
|
||||
// function's JSObject.
|
||||
JSObject *methodToCallObj = ::JS_GetParent(cx, funObj);
|
||||
XPCWrappedNative *wrappedNative =
|
||||
XPCNativeWrapper::GetWrappedNative(cx, obj);
|
||||
JSObject *methodToCallObj = STOBJ_GET_PARENT(funObj);
|
||||
XPCWrappedNative *wrappedNative = XPCNativeWrapper::GetWrappedNative(obj);
|
||||
|
||||
if (!::JS_ObjectIsFunction(cx, methodToCallObj) || !wrappedNative) {
|
||||
return ThrowException(NS_ERROR_UNEXPECTED, cx);
|
||||
|
@ -463,8 +462,8 @@ XPC_NW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
while (!XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
|
||||
obj = ::JS_GetPrototype(cx, obj);
|
||||
while (!XPCNativeWrapper::IsNativeWrapper(obj)) {
|
||||
obj = STOBJ_GET_PROTO(obj);
|
||||
if (!obj) {
|
||||
return ThrowException(NS_ERROR_UNEXPECTED, cx);
|
||||
}
|
||||
|
@ -474,8 +473,7 @@ XPC_NW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
XPCWrappedNative *wrappedNative =
|
||||
XPCNativeWrapper::GetWrappedNative(cx, obj);
|
||||
XPCWrappedNative *wrappedNative = XPCNativeWrapper::GetWrappedNative(obj);
|
||||
|
||||
if (!wrappedNative) {
|
||||
return ThrowException(NS_ERROR_INVALID_ARG, cx);
|
||||
|
@ -539,7 +537,7 @@ XPC_NW_Enumerate(JSContext *cx, JSObject *obj)
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
XPCWrappedNative *wn = XPCNativeWrapper::GetWrappedNative(cx, obj);
|
||||
XPCWrappedNative *wn = XPCNativeWrapper::GetWrappedNative(obj);
|
||||
if (!wn) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -576,7 +574,7 @@ XPC_NW_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
|
|||
// the wrapped native's object.
|
||||
|
||||
if (ShouldBypassNativeWrapper(cx, obj)) {
|
||||
XPCWrappedNative *wn = XPCNativeWrapper::GetWrappedNative(cx, obj);
|
||||
XPCWrappedNative *wn = XPCNativeWrapper::GetWrappedNative(obj);
|
||||
if (!wn) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -606,15 +604,14 @@ XPC_NW_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
while (!XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
|
||||
obj = ::JS_GetPrototype(cx, obj);
|
||||
while (!XPCNativeWrapper::IsNativeWrapper(obj)) {
|
||||
obj = STOBJ_GET_PROTO(obj);
|
||||
if (!obj) {
|
||||
return ThrowException(NS_ERROR_UNEXPECTED, cx);
|
||||
}
|
||||
}
|
||||
|
||||
XPCWrappedNative *wrappedNative =
|
||||
XPCNativeWrapper::GetWrappedNative(cx, obj);
|
||||
XPCWrappedNative *wrappedNative = XPCNativeWrapper::GetWrappedNative(obj);
|
||||
|
||||
if (!wrappedNative) {
|
||||
// No wrapped native, no properties.
|
||||
|
@ -668,15 +665,14 @@ XPC_NW_CheckAccess(JSContext *cx, JSObject *obj, jsval id,
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
XPCWrappedNative *wrappedNative =
|
||||
XPCNativeWrapper::GetWrappedNative(cx, obj);
|
||||
XPCWrappedNative *wrappedNative = XPCNativeWrapper::GetWrappedNative(obj);
|
||||
if (!wrappedNative) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSObject *wrapperJSObject = wrappedNative->GetFlatJSObject();
|
||||
|
||||
JSClass *clazz = JS_GET_CLASS(cx, wrapperJSObject);
|
||||
JSClass *clazz = STOBJ_GET_CLASS(wrapperJSObject);
|
||||
return !clazz->checkAccess ||
|
||||
clazz->checkAccess(cx, wrapperJSObject, id, mode, vp);
|
||||
}
|
||||
|
@ -684,7 +680,7 @@ XPC_NW_CheckAccess(JSContext *cx, JSObject *obj, jsval id,
|
|||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
XPC_NW_Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
if (!XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
|
||||
if (!XPCNativeWrapper::IsNativeWrapper(obj)) {
|
||||
// If obj is not an XPCNativeWrapper, then someone's probably trying to call
|
||||
// our prototype (i.e., XPCNativeWrapper.prototype()). In this case, it is
|
||||
// safe to simply ignore the call, since that's what would happen anyway.
|
||||
|
@ -714,8 +710,7 @@ XPC_NW_Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
|
||||
XPC_NW_BYPASS_TEST(cx, obj, construct, (cx, obj, argc, argv, rval));
|
||||
|
||||
XPCWrappedNative *wrappedNative =
|
||||
XPCNativeWrapper::GetWrappedNative(cx, obj);
|
||||
XPCWrappedNative *wrappedNative = XPCNativeWrapper::GetWrappedNative(obj);
|
||||
if (!wrappedNative) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -756,7 +751,7 @@ static JSBool
|
|||
MirrorWrappedNativeParent(JSContext *cx, XPCWrappedNative *wrapper,
|
||||
JSObject **result)
|
||||
{
|
||||
JSObject *wn_parent = ::JS_GetParent(cx, wrapper->GetFlatJSObject());
|
||||
JSObject *wn_parent = STOBJ_GET_PARENT(wrapper->GetFlatJSObject());
|
||||
if (!wn_parent) {
|
||||
*result = nsnull;
|
||||
} else {
|
||||
|
@ -791,7 +786,7 @@ XPCNativeWrapperCtor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
JSObject *nativeObj = JSVAL_TO_OBJECT(native);
|
||||
|
||||
// Unwrap a cross origin wrapper, since we're more restrictive than it is.
|
||||
if (JS_GET_CLASS(cx, nativeObj) == &sXPC_XOW_JSClass.base) {
|
||||
if (STOBJ_GET_CLASS(nativeObj) == &sXPC_XOW_JSClass.base) {
|
||||
jsval v;
|
||||
if (!::JS_GetReservedSlot(cx, nativeObj, XPCWrapper::sWrappedObjSlot, &v)) {
|
||||
return JS_FALSE;
|
||||
|
@ -805,7 +800,7 @@ XPCNativeWrapperCtor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
|
||||
XPCWrappedNative *wrappedNative;
|
||||
|
||||
if (XPCNativeWrapper::IsNativeWrapper(cx, nativeObj)) {
|
||||
if (XPCNativeWrapper::IsNativeWrapper(nativeObj)) {
|
||||
// We're asked to wrap an already wrapped object. Re-wrap the
|
||||
// object wrapped by the given wrapper.
|
||||
|
||||
|
@ -813,7 +808,7 @@ XPCNativeWrapperCtor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
printf("Wrapping already wrapped object\n");
|
||||
#endif
|
||||
|
||||
wrappedNative = XPCNativeWrapper::GetWrappedNative(cx, nativeObj);
|
||||
wrappedNative = XPCNativeWrapper::GetWrappedNative(nativeObj);
|
||||
|
||||
if (!wrappedNative) {
|
||||
return ThrowException(NS_ERROR_INVALID_ARG, cx);
|
||||
|
@ -958,8 +953,7 @@ XPCNativeWrapperCtor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
JS_STATIC_DLL_CALLBACK(void)
|
||||
XPC_NW_Trace(JSTracer *trc, JSObject *obj)
|
||||
{
|
||||
XPCWrappedNative *wrappedNative =
|
||||
XPCNativeWrapper::GetWrappedNative(trc->context, obj);
|
||||
XPCWrappedNative *wrappedNative = XPCNativeWrapper::GetWrappedNative(obj);
|
||||
|
||||
if (wrappedNative && wrappedNative->IsValid()) {
|
||||
JS_CALL_OBJECT_TRACER(trc, wrappedNative->GetFlatJSObject(),
|
||||
|
@ -970,7 +964,7 @@ XPC_NW_Trace(JSTracer *trc, JSObject *obj)
|
|||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
XPC_NW_Equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
|
||||
{
|
||||
NS_ASSERTION(XPCNativeWrapper::IsNativeWrapper(cx, obj),
|
||||
NS_ASSERTION(XPCNativeWrapper::IsNativeWrapper(obj),
|
||||
"Uh, we should only ever be called for XPCNativeWrapper "
|
||||
"objects!");
|
||||
|
||||
|
@ -980,8 +974,7 @@ XPC_NW_Equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
XPCWrappedNative *wrappedNative =
|
||||
XPCNativeWrapper::GetWrappedNative(cx, obj);
|
||||
XPCWrappedNative *wrappedNative = XPCNativeWrapper::GetWrappedNative(obj);
|
||||
|
||||
if (wrappedNative && wrappedNative->IsValid() &&
|
||||
NATIVE_HAS_FLAG(wrappedNative, WantEquality)) {
|
||||
|
@ -1006,8 +999,8 @@ JS_STATIC_DLL_CALLBACK(JSBool)
|
|||
XPC_NW_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
{
|
||||
while (!XPCNativeWrapper::IsNativeWrapper(cx, obj)) {
|
||||
obj = ::JS_GetPrototype(cx, obj);
|
||||
while (!XPCNativeWrapper::IsNativeWrapper(obj)) {
|
||||
obj = STOBJ_GET_PROTO(obj);
|
||||
if (!obj) {
|
||||
return ThrowException(NS_ERROR_UNEXPECTED, cx);
|
||||
}
|
||||
|
@ -1017,8 +1010,7 @@ XPC_NW_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
XPCWrappedNative *wrappedNative =
|
||||
XPCNativeWrapper::GetWrappedNative(cx, obj);
|
||||
XPCWrappedNative *wrappedNative = XPCNativeWrapper::GetWrappedNative(obj);
|
||||
|
||||
if (!wrappedNative) {
|
||||
// toString() called on XPCNativeWrapper.prototype
|
||||
|
|
|
@ -53,14 +53,14 @@ public:
|
|||
return clazz == &sXPC_NW_JSClass.base;
|
||||
}
|
||||
|
||||
static PRBool IsNativeWrapper(JSContext *cx, JSObject *obj)
|
||||
static PRBool IsNativeWrapper(JSObject *obj)
|
||||
{
|
||||
return JS_GET_CLASS(cx, obj) == &sXPC_NW_JSClass.base;
|
||||
return STOBJ_GET_CLASS(obj) == &sXPC_NW_JSClass.base;
|
||||
}
|
||||
|
||||
static XPCWrappedNative *GetWrappedNative(JSContext *cx, JSObject *obj)
|
||||
static XPCWrappedNative *GetWrappedNative(JSObject *obj)
|
||||
{
|
||||
return (XPCWrappedNative *)::JS_GetPrivate(cx, obj);
|
||||
return (XPCWrappedNative *)xpc_GetJSPrivate(obj);
|
||||
}
|
||||
|
||||
static JSClass *GetJSClass()
|
||||
|
|
|
@ -343,10 +343,10 @@ WrapJSValue(JSContext *cx, JSObject *obj, jsval val, jsval *rval)
|
|||
}
|
||||
|
||||
static inline JSObject *
|
||||
FindSafeObject(JSContext *cx, JSObject *obj)
|
||||
FindSafeObject(JSObject *obj)
|
||||
{
|
||||
while (JS_GET_CLASS(cx, obj) != &sXPC_SJOW_JSClass.base) {
|
||||
obj = ::JS_GetPrototype(cx, obj);
|
||||
while (STOBJ_GET_CLASS(obj) != &sXPC_SJOW_JSClass.base) {
|
||||
obj = STOBJ_GET_PROTO(obj);
|
||||
|
||||
if (!obj) {
|
||||
break;
|
||||
|
@ -356,12 +356,6 @@ FindSafeObject(JSContext *cx, JSObject *obj)
|
|||
return obj;
|
||||
}
|
||||
|
||||
PRBool
|
||||
IsXPCSafeJSObjectWrapper(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
return FindSafeObject(cx, obj) != nsnull;
|
||||
}
|
||||
|
||||
PRBool
|
||||
IsXPCSafeJSObjectWrapperClass(JSClass *clazz)
|
||||
{
|
||||
|
@ -369,31 +363,31 @@ IsXPCSafeJSObjectWrapperClass(JSClass *clazz)
|
|||
}
|
||||
|
||||
static inline JSObject *
|
||||
GetUnsafeObject(JSContext *cx, JSObject *obj)
|
||||
GetUnsafeObject(JSObject *obj)
|
||||
{
|
||||
obj = FindSafeObject(cx, obj);
|
||||
obj = FindSafeObject(obj);
|
||||
|
||||
if (!obj) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
return ::JS_GetParent(cx, obj);
|
||||
return STOBJ_GET_PARENT(obj);
|
||||
}
|
||||
|
||||
JSObject *
|
||||
XPC_SJOW_GetUnsafeObject(JSContext *cx, JSObject *obj)
|
||||
XPC_SJOW_GetUnsafeObject(JSObject *obj)
|
||||
{
|
||||
return GetUnsafeObject(cx, obj);
|
||||
return GetUnsafeObject(obj);
|
||||
}
|
||||
|
||||
static jsval
|
||||
UnwrapJSValue(JSContext *cx, jsval val)
|
||||
UnwrapJSValue(jsval val)
|
||||
{
|
||||
if (JSVAL_IS_PRIMITIVE(val)) {
|
||||
return val;
|
||||
}
|
||||
|
||||
JSObject *unsafeObj = GetUnsafeObject(cx, JSVAL_TO_OBJECT(val));
|
||||
JSObject *unsafeObj = GetUnsafeObject(JSVAL_TO_OBJECT(val));
|
||||
if (unsafeObj) {
|
||||
return OBJECT_TO_JSVAL(unsafeObj);
|
||||
}
|
||||
|
@ -483,7 +477,7 @@ XPC_SJOW_AddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
obj = FindSafeObject(cx, obj);
|
||||
obj = FindSafeObject(obj);
|
||||
NS_ASSERTION(obj != nsnull, "FindSafeObject() returned null in class hook!");
|
||||
|
||||
// Do nothing here if we're in the middle of resolving a property on
|
||||
|
@ -495,7 +489,7 @@ XPC_SJOW_AddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
return ok;
|
||||
}
|
||||
|
||||
JSObject *unsafeObj = GetUnsafeObject(cx, obj);
|
||||
JSObject *unsafeObj = GetUnsafeObject(obj);
|
||||
if (!unsafeObj) {
|
||||
return ThrowException(NS_ERROR_UNEXPECTED, cx);
|
||||
}
|
||||
|
@ -512,7 +506,7 @@ XPC_SJOW_AddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
XPC_SJOW_DelProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
JSObject *unsafeObj = GetUnsafeObject(cx, obj);
|
||||
JSObject *unsafeObj = GetUnsafeObject(obj);
|
||||
if (!unsafeObj) {
|
||||
return ThrowException(NS_ERROR_UNEXPECTED, cx);
|
||||
}
|
||||
|
@ -553,10 +547,10 @@ XPC_SJOW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
obj = FindSafeObject(cx, obj);
|
||||
obj = FindSafeObject(obj);
|
||||
NS_ASSERTION(obj != nsnull, "FindSafeObject() returned null in class hook!");
|
||||
|
||||
JSObject *unsafeObj = GetUnsafeObject(cx, obj);
|
||||
JSObject *unsafeObj = GetUnsafeObject(obj);
|
||||
if (!unsafeObj) {
|
||||
return ThrowException(NS_ERROR_UNEXPECTED, cx);
|
||||
}
|
||||
|
@ -589,7 +583,7 @@ XPC_SJOW_GetOrSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp,
|
|||
args[0] = id;
|
||||
|
||||
if (aIsSet) {
|
||||
args[1] = UnwrapJSValue(cx, *vp);
|
||||
args[1] = UnwrapJSValue(*vp);
|
||||
}
|
||||
|
||||
jsval val;
|
||||
|
@ -614,7 +608,7 @@ XPC_SJOW_SetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
XPC_SJOW_Enumerate(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
obj = FindSafeObject(cx, obj);
|
||||
obj = FindSafeObject(obj);
|
||||
NS_ASSERTION(obj != nsnull, "FindSafeObject() returned null in class hook!");
|
||||
|
||||
// We are being notified of a for-in loop or similar operation on
|
||||
|
@ -624,7 +618,7 @@ XPC_SJOW_Enumerate(JSContext *cx, JSObject *obj)
|
|||
// enumerated identifiers from the unsafe object to the safe
|
||||
// wrapper.
|
||||
|
||||
JSObject *unsafeObj = GetUnsafeObject(cx, obj);
|
||||
JSObject *unsafeObj = GetUnsafeObject(obj);
|
||||
if (!unsafeObj) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -641,10 +635,10 @@ JS_STATIC_DLL_CALLBACK(JSBool)
|
|||
XPC_SJOW_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
|
||||
JSObject **objp)
|
||||
{
|
||||
obj = FindSafeObject(cx, obj);
|
||||
obj = FindSafeObject(obj);
|
||||
NS_ASSERTION(obj != nsnull, "FindSafeObject() returned null in class hook!");
|
||||
|
||||
JSObject *unsafeObj = GetUnsafeObject(cx, obj);
|
||||
JSObject *unsafeObj = GetUnsafeObject(obj);
|
||||
if (!unsafeObj) {
|
||||
// No unsafe object, nothing to resolve here.
|
||||
|
||||
|
@ -702,7 +696,7 @@ XPC_SJOW_CheckAccess(JSContext *cx, JSObject *obj, jsval id,
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JSObject *unsafeObj = GetUnsafeObject(cx, obj);
|
||||
JSObject *unsafeObj = GetUnsafeObject(obj);
|
||||
if (!unsafeObj) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -714,7 +708,7 @@ XPC_SJOW_CheckAccess(JSContext *cx, JSObject *obj, jsval id,
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JSClass *clazz = JS_GET_CLASS(cx, unsafeObj);
|
||||
JSClass *clazz = STOBJ_GET_CLASS(unsafeObj);
|
||||
return !clazz->checkAccess ||
|
||||
clazz->checkAccess(cx, unsafeObj, id, mode, vp);
|
||||
}
|
||||
|
@ -723,7 +717,7 @@ JS_STATIC_DLL_CALLBACK(JSBool)
|
|||
XPC_SJOW_Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
{
|
||||
JSObject *tmp = FindSafeObject(cx, obj);
|
||||
JSObject *tmp = FindSafeObject(obj);
|
||||
JSObject *unsafeObj, *callThisObj = nsnull;
|
||||
|
||||
if (tmp) {
|
||||
|
@ -748,14 +742,14 @@ XPC_SJOW_Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
obj = FindSafeObject(cx, JSVAL_TO_OBJECT(argv[-2]));
|
||||
obj = FindSafeObject(JSVAL_TO_OBJECT(argv[-2]));
|
||||
|
||||
if (!obj) {
|
||||
return ThrowException(NS_ERROR_INVALID_ARG, cx);
|
||||
}
|
||||
}
|
||||
|
||||
unsafeObj = GetUnsafeObject(cx, obj);
|
||||
unsafeObj = GetUnsafeObject(obj);
|
||||
if (!unsafeObj) {
|
||||
return ThrowException(NS_ERROR_UNEXPECTED, cx);
|
||||
}
|
||||
|
@ -764,7 +758,7 @@ XPC_SJOW_Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
callThisObj = unsafeObj;
|
||||
}
|
||||
|
||||
JSObject *funToCall = GetUnsafeObject(cx, JSVAL_TO_OBJECT(argv[-2]));
|
||||
JSObject *funToCall = GetUnsafeObject(JSVAL_TO_OBJECT(argv[-2]));
|
||||
|
||||
if (!funToCall) {
|
||||
// Someone has called XPCSafeJSObjectWrapper.prototype() causing
|
||||
|
@ -854,7 +848,7 @@ XPC_SJOW_Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
}
|
||||
|
||||
for (uintN i = 0; i < argc; ++i) {
|
||||
args[i + 2] = UnwrapJSValue(cx, argv[i]);
|
||||
args[i + 2] = UnwrapJSValue(argv[i]);
|
||||
}
|
||||
|
||||
jsval val;
|
||||
|
@ -896,14 +890,14 @@ XPC_SJOW_Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
// with XPCSafeJSObjectWrapper, and never let the eval function
|
||||
// object be directly wrapped.
|
||||
|
||||
if (JS_GET_CLASS(cx, objToWrap) == &js_ScriptClass ||
|
||||
if (STOBJ_GET_CLASS(objToWrap) == &js_ScriptClass ||
|
||||
(::JS_ObjectIsFunction(cx, objToWrap) &&
|
||||
::JS_GetFunctionNative(cx, ::JS_ValueToFunction(cx, argv[0])) ==
|
||||
XPCWrapper::sEvalNative)) {
|
||||
return ThrowException(NS_ERROR_INVALID_ARG, cx);
|
||||
}
|
||||
|
||||
if (JS_GET_CLASS(cx, objToWrap) == &sXPC_XOW_JSClass.base) {
|
||||
if (STOBJ_GET_CLASS(objToWrap) == &sXPC_XOW_JSClass.base) {
|
||||
// We're being asked to wrap a XOW. By using XPCWrapper::Unwrap,
|
||||
// we guarantee that the wrapped object is same-origin to us. If
|
||||
// it isn't, then just wrap the XOW for an added layer of wrapping.
|
||||
|
@ -920,7 +914,7 @@ XPC_SJOW_Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JSObject *unsafeObj = GetUnsafeObject(cx, objToWrap);
|
||||
JSObject *unsafeObj = GetUnsafeObject(objToWrap);
|
||||
|
||||
if (unsafeObj) {
|
||||
// We're asked to wrap an already wrapped object. Re-wrap the
|
||||
|
@ -957,10 +951,10 @@ XPC_SJOW_Equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
|
|||
if (JSVAL_IS_PRIMITIVE(v)) {
|
||||
*bp = JS_FALSE;
|
||||
} else {
|
||||
JSObject *unsafeObj = GetUnsafeObject(cx, obj);
|
||||
JSObject *unsafeObj = GetUnsafeObject(obj);
|
||||
|
||||
JSObject *other = JSVAL_TO_OBJECT(v);
|
||||
JSObject *otherUnsafe = GetUnsafeObject(cx, other);
|
||||
JSObject *otherUnsafe = GetUnsafeObject(other);
|
||||
|
||||
*bp = (obj == other || unsafeObj == other ||
|
||||
(unsafeObj && unsafeObj == otherUnsafe) ||
|
||||
|
@ -973,7 +967,7 @@ XPC_SJOW_Equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
|
|||
JS_STATIC_DLL_CALLBACK(JSObject *)
|
||||
XPC_SJOW_Iterator(JSContext *cx, JSObject *obj, JSBool keysonly)
|
||||
{
|
||||
JSObject *innerObj = GetUnsafeObject(cx, obj);
|
||||
JSObject *innerObj = GetUnsafeObject(obj);
|
||||
if (!innerObj) {
|
||||
ThrowException(NS_ERROR_INVALID_ARG, cx);
|
||||
return nsnull;
|
||||
|
@ -1003,19 +997,19 @@ XPC_SJOW_Iterator(JSContext *cx, JSObject *obj, JSBool keysonly)
|
|||
JS_STATIC_DLL_CALLBACK(JSObject *)
|
||||
XPC_SJOW_WrappedObject(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
return GetUnsafeObject(cx, obj);
|
||||
return GetUnsafeObject(obj);
|
||||
}
|
||||
|
||||
JS_STATIC_DLL_CALLBACK(JSBool)
|
||||
XPC_SJOW_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
{
|
||||
obj = FindSafeObject(cx, obj);
|
||||
obj = FindSafeObject(obj);
|
||||
if (!obj) {
|
||||
return ThrowException(NS_ERROR_INVALID_ARG, cx);
|
||||
}
|
||||
|
||||
JSObject *unsafeObj = GetUnsafeObject(cx, obj);
|
||||
JSObject *unsafeObj = GetUnsafeObject(obj);
|
||||
|
||||
if (!unsafeObj) {
|
||||
// No unsafe object, nothing to stringify here, return "[object
|
||||
|
|
|
@ -92,7 +92,7 @@ IteratorNext(JSContext *cx, uintN argc, jsval *vp)
|
|||
*vp = v;
|
||||
} else {
|
||||
// We need to return an [id, value] pair.
|
||||
if (!OBJ_GET_PROPERTY(cx, JS_GetParent(cx, obj), id, &v)) {
|
||||
if (!OBJ_GET_PROPERTY(cx, STOBJ_GET_PARENT(obj), id, &v)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ XPCWrapper::CreateIteratorObj(JSContext *cx, JSObject *tempWrapper,
|
|||
if (!XPCWrapper::Enumerate(cx, iterObj, innerObj)) {
|
||||
return nsnull;
|
||||
}
|
||||
} while ((innerObj = JS_GetPrototype(cx, innerObj)) != nsnull);
|
||||
} while ((innerObj = STOBJ_GET_PROTO(innerObj)) != nsnull);
|
||||
|
||||
JSIdArray *ida = JS_Enumerate(cx, iterObj);
|
||||
if (!ida) {
|
||||
|
@ -293,7 +293,7 @@ XPCWrapper::NewResolve(JSContext *cx, JSObject *wrapperObj,
|
|||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool isXOW = (JS_GET_CLASS(cx, wrapperObj) == &sXPC_XOW_JSClass.base);
|
||||
JSBool isXOW = (STOBJ_GET_CLASS(wrapperObj) == &sXPC_XOW_JSClass.base);
|
||||
uintN attrs = JSPROP_ENUMERATE;
|
||||
if (OBJ_IS_NATIVE(innerObjp)) {
|
||||
JSScopeProperty *sprop = reinterpret_cast<JSScopeProperty *>(prop);
|
||||
|
@ -312,7 +312,7 @@ XPCWrapper::NewResolve(JSContext *cx, JSObject *wrapperObj,
|
|||
if (!preserveVal && isXOW && !JSVAL_IS_PRIMITIVE(v)) {
|
||||
JSObject *obj = JSVAL_TO_OBJECT(v);
|
||||
if (JS_ObjectIsFunction(cx, obj)) {
|
||||
JSFunction *fun = reinterpret_cast<JSFunction *>(JS_GetPrivate(cx, obj));
|
||||
JSFunction *fun = reinterpret_cast<JSFunction *>(xpc_GetJSPrivate(obj));
|
||||
if (JS_GetFunctionNative(cx, fun) == sEvalNative &&
|
||||
!WrapFunction(cx, wrapperObj, obj, &v, JS_FALSE)) {
|
||||
return JS_FALSE;
|
||||
|
|
|
@ -767,7 +767,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
|
|||
char name[72];
|
||||
if(XPCNativeWrapper::IsNativeWrapperClass(clazz))
|
||||
{
|
||||
XPCWrappedNative* wn = XPCNativeWrapper::GetWrappedNative(cx, obj);
|
||||
XPCWrappedNative* wn = XPCNativeWrapper::GetWrappedNative(obj);
|
||||
if(wn)
|
||||
{
|
||||
XPCNativeScriptableInfo* si = wn->GetScriptableInfo();
|
||||
|
@ -814,7 +814,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
|
|||
if(IS_PROTO_CLASS(clazz))
|
||||
{
|
||||
XPCWrappedNativeProto* p =
|
||||
(XPCWrappedNativeProto*) JS_GetPrivate(cx, obj);
|
||||
(XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
si = p->GetScriptableInfo();
|
||||
}
|
||||
if(si)
|
||||
|
@ -824,7 +824,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
|
|||
}
|
||||
else if(clazz == &js_ScriptClass)
|
||||
{
|
||||
JSScript* script = (JSScript*) JS_GetPrivate(cx, obj);
|
||||
JSScript* script = (JSScript*) xpc_GetJSPrivate(obj);
|
||||
if(script->filename)
|
||||
{
|
||||
JS_snprintf(name, sizeof(name), "JS Object (Script - %s)",
|
||||
|
@ -837,7 +837,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
|
|||
}
|
||||
else if(clazz == &js_FunctionClass)
|
||||
{
|
||||
JSFunction* fun = (JSFunction*) JS_GetPrivate(cx, obj);
|
||||
JSFunction* fun = (JSFunction*) xpc_GetJSPrivate(obj);
|
||||
if(fun->atom && ATOM_IS_STRING(fun->atom))
|
||||
{
|
||||
NS_ConvertUTF16toUTF8
|
||||
|
@ -896,7 +896,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
|
|||
// (see XPCWrappedNative::FlatJSObjectFinalized). Its XPCWrappedNative
|
||||
// will be held alive through the parent of the JSObject of the tearoff.
|
||||
XPCWrappedNativeTearOff *to =
|
||||
(XPCWrappedNativeTearOff*) JS_GetPrivate(cx, obj);
|
||||
(XPCWrappedNativeTearOff*) xpc_GetJSPrivate(obj);
|
||||
cb.NoteXPCOMChild(to->GetNative());
|
||||
}
|
||||
// XXX XPCNativeWrapper seems to be the only class that doesn't hold a
|
||||
|
@ -907,7 +907,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
|
|||
clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS &&
|
||||
!XPCNativeWrapper::IsNativeWrapperClass(clazz))
|
||||
{
|
||||
cb.NoteXPCOMChild(static_cast<nsISupports*>(JS_GetPrivate(cx, obj)));
|
||||
cb.NoteXPCOMChild(static_cast<nsISupports*>(xpc_GetJSPrivate(obj)));
|
||||
}
|
||||
|
||||
#ifndef XPCONNECT_STANDALONE
|
||||
|
@ -1210,7 +1210,7 @@ nsXPConnect::WrapNative(JSContext * aJSContext,
|
|||
#ifdef DEBUG
|
||||
JSObject* returnObj;
|
||||
(*_retval)->GetJSObject(&returnObj);
|
||||
NS_ASSERTION(!XPCNativeWrapper::IsNativeWrapper(aJSContext, returnObj),
|
||||
NS_ASSERTION(!XPCNativeWrapper::IsNativeWrapper(returnObj),
|
||||
"Shouldn't be returning a native wrapper here");
|
||||
#endif
|
||||
|
||||
|
@ -1748,7 +1748,7 @@ nsXPConnect::RestoreWrappedNativePrototype(JSContext * aJSContext,
|
|||
if(NS_FAILED(rv))
|
||||
return UnexpectedFailure(rv);
|
||||
|
||||
if(!IS_PROTO_CLASS(JS_GET_CLASS(ccx, protoJSObject)))
|
||||
if(!IS_PROTO_CLASS(STOBJ_GET_CLASS(protoJSObject)))
|
||||
return UnexpectedFailure(NS_ERROR_INVALID_ARG);
|
||||
|
||||
XPCWrappedNativeScope* scope =
|
||||
|
@ -1757,7 +1757,7 @@ nsXPConnect::RestoreWrappedNativePrototype(JSContext * aJSContext,
|
|||
return UnexpectedFailure(NS_ERROR_FAILURE);
|
||||
|
||||
XPCWrappedNativeProto *proto =
|
||||
(XPCWrappedNativeProto*)JS_GetPrivate(ccx, protoJSObject);
|
||||
(XPCWrappedNativeProto*)xpc_GetJSPrivate(protoJSObject);
|
||||
if(!proto)
|
||||
return UnexpectedFailure(NS_ERROR_FAILURE);
|
||||
|
||||
|
|
|
@ -3098,7 +3098,7 @@ JS_STATIC_DLL_CALLBACK(void)
|
|||
sandbox_finalize(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
nsIScriptObjectPrincipal *sop =
|
||||
(nsIScriptObjectPrincipal *)JS_GetPrivate(cx, obj);
|
||||
(nsIScriptObjectPrincipal *)xpc_GetJSPrivate(obj);
|
||||
NS_IF_RELEASE(sop);
|
||||
}
|
||||
|
||||
|
@ -3483,11 +3483,11 @@ xpc_EvalInSandbox(JSContext *cx, JSObject *sandbox, const nsAString& source,
|
|||
const char *filename, PRInt32 lineNo,
|
||||
PRBool returnStringOnly, jsval *rval)
|
||||
{
|
||||
if (JS_GetClass(cx, sandbox) != &SandboxClass)
|
||||
if (STOBJ_GET_CLASS(sandbox) != &SandboxClass)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
nsIScriptObjectPrincipal *sop =
|
||||
(nsIScriptObjectPrincipal*)JS_GetPrivate(cx, sandbox);
|
||||
(nsIScriptObjectPrincipal*)xpc_GetJSPrivate(sandbox);
|
||||
NS_ASSERTION(sop, "Invalid sandbox passed");
|
||||
nsCOMPtr<nsIPrincipal> prin = sop->GetPrincipal();
|
||||
|
||||
|
|
|
@ -148,15 +148,15 @@ XPCConvert::IsMethodReflectable(const XPTMethodDescriptor& info)
|
|||
/***************************************************************************/
|
||||
|
||||
static JSBool
|
||||
GetISupportsFromJSObject(JSContext* cx, JSObject* obj, nsISupports** iface)
|
||||
GetISupportsFromJSObject(JSObject* obj, nsISupports** iface)
|
||||
{
|
||||
JSClass* jsclass = JS_GET_CLASS(cx, obj);
|
||||
JSClass* jsclass = STOBJ_GET_CLASS(obj);
|
||||
NS_ASSERTION(jsclass, "obj has no class");
|
||||
if(jsclass &&
|
||||
(jsclass->flags & JSCLASS_HAS_PRIVATE) &&
|
||||
(jsclass->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS))
|
||||
{
|
||||
*iface = (nsISupports*) JS_GetPrivate(cx, obj);
|
||||
*iface = (nsISupports*) xpc_GetJSPrivate(obj);
|
||||
return JS_TRUE;
|
||||
}
|
||||
return JS_FALSE;
|
||||
|
@ -487,8 +487,8 @@ XPCConvert::NativeData2JS(XPCCallContext& ccx, jsval* d, const void* s,
|
|||
if(NS_FAILED(holder->GetJSObject(&jsobj)))
|
||||
return JS_FALSE;
|
||||
#ifdef DEBUG
|
||||
if(!JS_GetParent(ccx, jsobj))
|
||||
NS_ASSERTION(JS_GET_CLASS(ccx, jsobj)->flags & JSCLASS_IS_GLOBAL,
|
||||
if(!STOBJ_GET_PARENT(jsobj))
|
||||
NS_ASSERTION(STOBJ_GET_CLASS(jsobj)->flags & JSCLASS_IS_GLOBAL,
|
||||
"Why did we recreate this wrapper?");
|
||||
#endif
|
||||
*d = OBJECT_TO_JSVAL(jsobj);
|
||||
|
@ -1141,7 +1141,7 @@ XPCConvert::NativeInterface2JSObject(XPCCallContext& ccx,
|
|||
// is a JS function object. Look for the script for
|
||||
// this function.
|
||||
JSFunction* fun =
|
||||
(JSFunction*) JS_GetPrivate(ccx, callee);
|
||||
(JSFunction*) xpc_GetJSPrivate(callee);
|
||||
NS_ASSERTION(fun,
|
||||
"Must have JSFunction for a Function "
|
||||
"object");
|
||||
|
@ -1194,7 +1194,7 @@ XPCConvert::NativeInterface2JSObject(XPCCallContext& ccx,
|
|||
}
|
||||
|
||||
JSObject *flat = wrapper->GetFlatJSObject();
|
||||
const char *name = JS_GET_CLASS(ccx, flat)->name;
|
||||
const char *name = STOBJ_GET_CLASS(flat)->name;
|
||||
uint32 flags = JS_GetTopScriptFilenameFlags(ccx, nsnull);
|
||||
if(allowNativeWrapper &&
|
||||
!(flags & JSFILENAME_SYSTEM) &&
|
||||
|
@ -1278,7 +1278,7 @@ XPCConvert::JSObject2NativeInterface(XPCCallContext& ccx,
|
|||
// Does the JSObject have 'nsISupportness'?
|
||||
// XXX hmm, I wonder if this matters anymore with no
|
||||
// oldstyle DOM objects around.
|
||||
if(GetISupportsFromJSObject(cx, src, &iface))
|
||||
if(GetISupportsFromJSObject(src, &iface))
|
||||
{
|
||||
if(iface)
|
||||
return NS_SUCCEEDED(iface->QueryInterface(*iid, dest));
|
||||
|
|
|
@ -3906,6 +3906,18 @@ NS_DEFINE_STATIC_IID_ACCESSOR(PrincipalHolder, PRINCIPALHOLDER_IID)
|
|||
|
||||
JSBool xpc_IsReportableErrorCode(nsresult code);
|
||||
|
||||
inline void *
|
||||
xpc_GetJSPrivate(JSObject *obj)
|
||||
{
|
||||
jsval v;
|
||||
|
||||
JS_ASSERT(STOBJ_GET_CLASS(obj)->flags & JSCLASS_HAS_PRIVATE);
|
||||
v = obj->fslots[JSSLOT_PRIVATE];
|
||||
if (!JSVAL_IS_INT(v))
|
||||
return NULL;
|
||||
return JSVAL_TO_PRIVATE(v);
|
||||
}
|
||||
|
||||
#ifndef XPCONNECT_STANDALONE
|
||||
|
||||
// Helper for creating a sandbox object to use for evaluating
|
||||
|
@ -3958,7 +3970,7 @@ PRBool
|
|||
IsXPCSafeJSObjectWrapperClass(JSClass *clazz);
|
||||
|
||||
JSObject *
|
||||
XPC_SJOW_GetUnsafeObject(JSContext *cx, JSObject *obj);
|
||||
XPC_SJOW_GetUnsafeObject(JSObject *obj);
|
||||
|
||||
JSBool
|
||||
XPC_SJOW_Construct(JSContext *cx, JSObject *obj, uintN, jsval *argv,
|
||||
|
|
|
@ -155,7 +155,7 @@ SafeFinalize(JSContext* cx, JSObject* obj)
|
|||
{
|
||||
#ifndef XPCONNECT_STANDALONE
|
||||
nsIScriptObjectPrincipal* sop =
|
||||
static_cast<nsIScriptObjectPrincipal*>(JS_GetPrivate(cx, obj));
|
||||
static_cast<nsIScriptObjectPrincipal*>(xpc_GetJSPrivate(obj));
|
||||
NS_IF_RELEASE(sop);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -259,16 +259,6 @@ XPCThrower::BuildAndThrowException(JSContext* cx, nsresult rv, const char* sz)
|
|||
JS_ReportOutOfMemory(cx);
|
||||
}
|
||||
|
||||
static JSObject*
|
||||
GetGlobalObject(JSContext* cx, JSObject* start)
|
||||
{
|
||||
JSObject* parent;
|
||||
|
||||
while((parent = JS_GetParent(cx, start)) != nsnull)
|
||||
start = parent;
|
||||
return start;
|
||||
}
|
||||
|
||||
// static
|
||||
JSBool
|
||||
XPCThrower::ThrowExceptionObject(JSContext* cx, nsIException* e)
|
||||
|
@ -282,7 +272,7 @@ XPCThrower::ThrowExceptionObject(JSContext* cx, nsIException* e)
|
|||
JSObject* glob = JS_GetScopeChain(cx);
|
||||
if(!glob)
|
||||
return JS_FALSE;
|
||||
glob = GetGlobalObject(cx, glob);
|
||||
glob = JS_GetGlobalForObject(cx, glob);
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
nsresult rv = xpc->WrapNative(cx, glob, e,
|
||||
|
|
|
@ -395,7 +395,7 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
|
|||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
NS_ASSERTION(!XPCNativeWrapper::IsNativeWrapper(ccx, parent),
|
||||
NS_ASSERTION(!XPCNativeWrapper::IsNativeWrapper(parent),
|
||||
"Parent should never be an XPCNativeWrapper here");
|
||||
|
||||
if(parent != plannedParent)
|
||||
|
@ -470,7 +470,7 @@ XPCWrappedNative::GetNewOrUsed(XPCCallContext& ccx,
|
|||
|
||||
NS_ADDREF(wrapper);
|
||||
|
||||
NS_ASSERTION(!XPCNativeWrapper::IsNativeWrapper(ccx, parent),
|
||||
NS_ASSERTION(!XPCNativeWrapper::IsNativeWrapper(parent),
|
||||
"XPCNativeWrapper being used to parent XPCWrappedNative?");
|
||||
|
||||
if(!wrapper->Init(ccx, parent, isGlobal, &sciWrapper))
|
||||
|
@ -1197,7 +1197,7 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
|
|||
// is directly using that of its XPCWrappedNativeProto.
|
||||
|
||||
if(wrapper->HasProto() &&
|
||||
JS_GetPrototype(ccx, wrapper->GetFlatJSObject()) ==
|
||||
STOBJ_GET_PROTO(wrapper->GetFlatJSObject()) ==
|
||||
oldProto->GetJSProtoObject())
|
||||
{
|
||||
if(!JS_SetPrototype(ccx, wrapper->GetFlatJSObject(),
|
||||
|
@ -1283,15 +1283,15 @@ XPCWrappedNative::GetWrappedNativeOfJSObject(JSContext* cx,
|
|||
|
||||
if(funobj)
|
||||
{
|
||||
JSObject* funObjParent = JS_GetParent(cx, funobj);
|
||||
JSObject* funObjParent = STOBJ_GET_PARENT(funobj);
|
||||
NS_ASSERTION(funObjParent, "funobj has no parent");
|
||||
|
||||
JSClass* funObjParentClass = JS_GET_CLASS(cx, funObjParent);
|
||||
JSClass* funObjParentClass = STOBJ_GET_CLASS(funObjParent);
|
||||
|
||||
if(IS_PROTO_CLASS(funObjParentClass))
|
||||
{
|
||||
NS_ASSERTION(JS_GetParent(cx, funObjParent), "funobj's parent (proto) is global");
|
||||
proto = (XPCWrappedNativeProto*) JS_GetPrivate(cx, funObjParent);
|
||||
NS_ASSERTION(STOBJ_GET_PARENT(funObjParent), "funobj's parent (proto) is global");
|
||||
proto = (XPCWrappedNativeProto*) xpc_GetJSPrivate(funObjParent);
|
||||
if(proto)
|
||||
protoClassInfo = proto->GetClassInfo();
|
||||
}
|
||||
|
@ -1302,7 +1302,7 @@ XPCWrappedNative::GetWrappedNativeOfJSObject(JSContext* cx,
|
|||
}
|
||||
else if(IS_TEAROFF_CLASS(funObjParentClass))
|
||||
{
|
||||
NS_ASSERTION(JS_GetParent(cx, funObjParent), "funobj's parent (tearoff) is global");
|
||||
NS_ASSERTION(STOBJ_GET_PARENT(funObjParent), "funobj's parent (tearoff) is global");
|
||||
cur = funObjParent;
|
||||
goto return_tearoff;
|
||||
}
|
||||
|
@ -1313,17 +1313,17 @@ XPCWrappedNative::GetWrappedNativeOfJSObject(JSContext* cx,
|
|||
}
|
||||
}
|
||||
|
||||
for(cur = obj; cur; cur = JS_GetPrototype(cx, cur))
|
||||
for(cur = obj; cur; cur = STOBJ_GET_PROTO(cur))
|
||||
{
|
||||
// this is on two lines to make the compiler happy given the goto.
|
||||
JSClass* clazz;
|
||||
clazz = JS_GET_CLASS(cx, cur);
|
||||
clazz = STOBJ_GET_CLASS(cur);
|
||||
|
||||
if(IS_WRAPPER_CLASS(clazz))
|
||||
{
|
||||
return_wrapper:
|
||||
XPCWrappedNative* wrapper =
|
||||
(XPCWrappedNative*) JS_GetPrivate(cx, cur);
|
||||
(XPCWrappedNative*) xpc_GetJSPrivate(cur);
|
||||
if(proto && proto != wrapper->GetProto() &&
|
||||
(proto->GetScope() != wrapper->GetScope() ||
|
||||
!protoClassInfo || !wrapper->GetProto() ||
|
||||
|
@ -1338,7 +1338,7 @@ return_wrapper:
|
|||
{
|
||||
return_tearoff:
|
||||
XPCWrappedNative* wrapper =
|
||||
(XPCWrappedNative*) JS_GetPrivate(cx, JS_GetParent(cx,cur));
|
||||
(XPCWrappedNative*) xpc_GetJSPrivate(STOBJ_GET_PARENT(cur));
|
||||
if(proto && proto != wrapper->GetProto() &&
|
||||
(proto->GetScope() != wrapper->GetScope() ||
|
||||
!protoClassInfo || !wrapper->GetProto() ||
|
||||
|
@ -1347,7 +1347,7 @@ return_tearoff:
|
|||
if(pobj2)
|
||||
*pobj2 = cur;
|
||||
XPCWrappedNativeTearOff* to =
|
||||
(XPCWrappedNativeTearOff*) JS_GetPrivate(cx, cur);
|
||||
(XPCWrappedNativeTearOff*) xpc_GetJSPrivate(cur);
|
||||
if(!to)
|
||||
return nsnull;
|
||||
if(pTearOff)
|
||||
|
@ -1367,11 +1367,11 @@ return_tearoff:
|
|||
if(pobj2)
|
||||
*pobj2 = cur;
|
||||
|
||||
return XPCNativeWrapper::GetWrappedNative(cx, cur);
|
||||
return XPCNativeWrapper::GetWrappedNative(cur);
|
||||
}
|
||||
|
||||
if(IsXPCSafeJSObjectWrapperClass(clazz) &&
|
||||
(unsafeObj = JS_GetParent(cx, cur)))
|
||||
(unsafeObj = STOBJ_GET_PARENT(cur)))
|
||||
return GetWrappedNativeOfJSObject(cx, unsafeObj, funobj, pobj2,
|
||||
pTearOff);
|
||||
}
|
||||
|
@ -1379,7 +1379,7 @@ return_tearoff:
|
|||
// If we didn't find a wrapper using the given funobj and obj, try
|
||||
// again with obj's outer object, if it's got one.
|
||||
|
||||
JSClass *clazz = JS_GET_CLASS(cx, obj);
|
||||
JSClass *clazz = STOBJ_GET_CLASS(obj);
|
||||
|
||||
if((clazz->flags & JSCLASS_IS_EXTENDED) &&
|
||||
((JSExtendedClass*)clazz)->outerObject)
|
||||
|
@ -1388,7 +1388,7 @@ return_tearoff:
|
|||
|
||||
// Protect against infinite recursion through XOWs.
|
||||
JSObject *unsafeObj;
|
||||
clazz = JS_GET_CLASS(cx, outer);
|
||||
clazz = STOBJ_GET_CLASS(outer);
|
||||
if(clazz == &sXPC_XOW_JSClass.base &&
|
||||
(unsafeObj = XPCWrapper::Unwrap(cx, outer)))
|
||||
{
|
||||
|
@ -1631,14 +1631,14 @@ XPCWrappedNative::InitTearOff(XPCCallContext& ccx,
|
|||
JSObject* proto = nsnull;
|
||||
JSObject* our_proto = GetProto()->GetJSProtoObject();
|
||||
|
||||
proto = JS_GetPrototype(ccx, jso);
|
||||
proto = STOBJ_GET_PROTO(jso);
|
||||
|
||||
NS_ASSERTION(proto && proto != our_proto,
|
||||
"!!! xpconnect/xbl check - wrapper has no special proto");
|
||||
|
||||
PRBool found_our_proto = PR_FALSE;
|
||||
while(proto && !found_our_proto) {
|
||||
proto = JS_GetPrototype(ccx, proto);
|
||||
proto = STOBJ_GET_PROTO(proto);
|
||||
|
||||
found_our_proto = proto == our_proto;
|
||||
}
|
||||
|
|
|
@ -634,7 +634,7 @@ XPC_WN_Shared_Enumerate(JSContext *cx, JSObject *obj)
|
|||
JS_STATIC_DLL_CALLBACK(void)
|
||||
XPC_WN_NoHelper_Finalize(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
XPCWrappedNative* p = (XPCWrappedNative*) JS_GetPrivate(cx, obj);
|
||||
XPCWrappedNative* p = (XPCWrappedNative*) xpc_GetJSPrivate(obj);
|
||||
if(!p)
|
||||
return;
|
||||
p->FlatJSObjectFinalized(cx);
|
||||
|
@ -735,13 +735,13 @@ XPC_GetIdentityObject(JSContext *cx, JSObject *obj)
|
|||
{
|
||||
XPCWrappedNative *wrapper;
|
||||
|
||||
if(XPCNativeWrapper::IsNativeWrapper(cx, obj))
|
||||
wrapper = XPCNativeWrapper::GetWrappedNative(cx, obj);
|
||||
if(XPCNativeWrapper::IsNativeWrapper(obj))
|
||||
wrapper = XPCNativeWrapper::GetWrappedNative(obj);
|
||||
else
|
||||
wrapper = XPCWrappedNative::GetWrappedNativeOfJSObject(cx, obj);
|
||||
|
||||
if(!wrapper) {
|
||||
JSObject *unsafeObj = XPC_SJOW_GetUnsafeObject(cx, obj);
|
||||
JSObject *unsafeObj = XPC_SJOW_GetUnsafeObject(obj);
|
||||
if(unsafeObj)
|
||||
return XPC_GetIdentityObject(cx, unsafeObj);
|
||||
|
||||
|
@ -768,11 +768,9 @@ XPC_WN_Equality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
|
|||
return Throw(rv, cx);
|
||||
|
||||
if(!*bp && !JSVAL_IS_PRIMITIVE(v) &&
|
||||
IsXPCSafeJSObjectWrapperClass(JS_GET_CLASS(cx,
|
||||
JSVAL_TO_OBJECT(v))))
|
||||
IsXPCSafeJSObjectWrapperClass(STOBJ_GET_CLASS(JSVAL_TO_OBJECT(v))))
|
||||
{
|
||||
v = OBJECT_TO_JSVAL(XPC_SJOW_GetUnsafeObject(cx,
|
||||
JSVAL_TO_OBJECT(v)));
|
||||
v = OBJECT_TO_JSVAL(XPC_SJOW_GetUnsafeObject(JSVAL_TO_OBJECT(v)));
|
||||
|
||||
rv = si->GetCallback()->Equality(wrapper, cx, obj, v, bp);
|
||||
if(NS_FAILED(rv))
|
||||
|
@ -1022,7 +1020,7 @@ XPC_WN_Helper_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
|
|||
JS_STATIC_DLL_CALLBACK(void)
|
||||
XPC_WN_Helper_Finalize(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
XPCWrappedNative* wrapper = (XPCWrappedNative*) JS_GetPrivate(cx, obj);
|
||||
XPCWrappedNative* wrapper = (XPCWrappedNative*) xpc_GetJSPrivate(obj);
|
||||
if(!wrapper)
|
||||
return;
|
||||
wrapper->GetScriptableCallback()->Finalize(wrapper, cx, obj);
|
||||
|
@ -1176,7 +1174,7 @@ JS_STATIC_DLL_CALLBACK(JSBool)
|
|||
XPC_WN_JSOp_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
jsval *statep, jsid *idp)
|
||||
{
|
||||
JSClass *clazz = JS_GET_CLASS(cx, obj);
|
||||
JSClass *clazz = STOBJ_GET_CLASS(obj);
|
||||
if(!IS_WRAPPER_CLASS(clazz) || clazz == &XPC_WN_NoHelper_JSClass.base)
|
||||
{
|
||||
// obj must be a prototype object or a wrapper w/o a
|
||||
|
@ -1517,7 +1515,8 @@ XPC_WN_Shared_Proto_Enumerate(JSContext *cx, JSObject *obj)
|
|||
JS_InstanceOf(cx, obj, &XPC_WN_NoMods_WithCall_Proto_JSClass, nsnull) ||
|
||||
JS_InstanceOf(cx, obj, &XPC_WN_NoMods_NoCall_Proto_JSClass, nsnull),
|
||||
"bad proto");
|
||||
XPCWrappedNativeProto* self = (XPCWrappedNativeProto*) JS_GetPrivate(cx, obj);
|
||||
XPCWrappedNativeProto* self =
|
||||
(XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
if(!self)
|
||||
return JS_FALSE;
|
||||
|
||||
|
@ -1561,7 +1560,7 @@ JS_STATIC_DLL_CALLBACK(void)
|
|||
XPC_WN_Shared_Proto_Finalize(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
// This can be null if xpc shutdown has already happened
|
||||
XPCWrappedNativeProto* p = (XPCWrappedNativeProto*) JS_GetPrivate(cx, obj);
|
||||
XPCWrappedNativeProto* p = (XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
if(p)
|
||||
p->JSProtoObjectFinalized(cx, obj);
|
||||
}
|
||||
|
@ -1571,7 +1570,7 @@ XPC_WN_Shared_Proto_Trace(JSTracer *trc, JSObject *obj)
|
|||
{
|
||||
// This can be null if xpc shutdown has already happened
|
||||
XPCWrappedNativeProto* p =
|
||||
(XPCWrappedNativeProto*) JS_GetPrivate(trc->context, obj);
|
||||
(XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
if(p)
|
||||
TraceScopeJSObjects(trc, p->GetScope());
|
||||
}
|
||||
|
@ -1590,7 +1589,8 @@ XPC_WN_ModsAllowed_Proto_Resolve(JSContext *cx, JSObject *obj, jsval idval)
|
|||
nsnull),
|
||||
"bad proto");
|
||||
|
||||
XPCWrappedNativeProto* self = (XPCWrappedNativeProto*) JS_GetPrivate(cx, obj);
|
||||
XPCWrappedNativeProto* self =
|
||||
(XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
if(!self)
|
||||
return JS_FALSE;
|
||||
|
||||
|
@ -1700,7 +1700,8 @@ XPC_WN_OnlyIWrite_Proto_PropertyStub(JSContext *cx, JSObject *obj, jsval idval,
|
|||
JS_InstanceOf(cx, obj, &XPC_WN_NoMods_NoCall_Proto_JSClass, nsnull),
|
||||
"bad proto");
|
||||
|
||||
XPCWrappedNativeProto* self = (XPCWrappedNativeProto*) JS_GetPrivate(cx, obj);
|
||||
XPCWrappedNativeProto* self =
|
||||
(XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
if(!self)
|
||||
return JS_FALSE;
|
||||
|
||||
|
@ -1725,7 +1726,8 @@ XPC_WN_NoMods_Proto_Resolve(JSContext *cx, JSObject *obj, jsval idval)
|
|||
JS_InstanceOf(cx, obj, &XPC_WN_NoMods_NoCall_Proto_JSClass, nsnull),
|
||||
"bad proto");
|
||||
|
||||
XPCWrappedNativeProto* self = (XPCWrappedNativeProto*) JS_GetPrivate(cx, obj);
|
||||
XPCWrappedNativeProto* self =
|
||||
(XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
|
||||
if(!self)
|
||||
return JS_FALSE;
|
||||
|
||||
|
@ -1848,7 +1850,7 @@ JS_STATIC_DLL_CALLBACK(void)
|
|||
XPC_WN_TearOff_Finalize(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
XPCWrappedNativeTearOff* p = (XPCWrappedNativeTearOff*)
|
||||
JS_GetPrivate(cx, obj);
|
||||
xpc_GetJSPrivate(obj);
|
||||
if(!p)
|
||||
return;
|
||||
p->JSObjectFinalized();
|
||||
|
|
|
@ -236,13 +236,13 @@ XPCWrappedNativeScope::SetGlobal(XPCCallContext& ccx, JSObject* aGlobal)
|
|||
// Now init our script object principal, if the new global has one
|
||||
|
||||
JSContext* cx = ccx.GetJSContext();
|
||||
const JSClass* jsClass = JS_GetClass(cx, aGlobal);
|
||||
const JSClass* jsClass = STOBJ_GET_CLASS(aGlobal);
|
||||
if(!(~jsClass->flags & (JSCLASS_HAS_PRIVATE |
|
||||
JSCLASS_PRIVATE_IS_NSISUPPORTS)))
|
||||
{
|
||||
// Our global has an nsISupports native pointer. Let's
|
||||
// see whether it's what we want.
|
||||
nsISupports* priv = (nsISupports*)JS_GetPrivate(cx, aGlobal);
|
||||
nsISupports* priv = (nsISupports*)xpc_GetJSPrivate(aGlobal);
|
||||
nsCOMPtr<nsIXPConnectWrappedNative> native =
|
||||
do_QueryInterface(priv);
|
||||
if(native)
|
||||
|
@ -700,19 +700,19 @@ XPCWrappedNativeScope::SystemIsBeingShutDown(JSContext* cx)
|
|||
|
||||
static
|
||||
XPCWrappedNativeScope*
|
||||
GetScopeOfObject(JSContext* cx, JSObject* obj)
|
||||
GetScopeOfObject(JSObject* obj)
|
||||
{
|
||||
nsISupports* supports;
|
||||
JSClass* clazz = JS_GET_CLASS(cx, obj);
|
||||
JSClass* clazz = STOBJ_GET_CLASS(obj);
|
||||
|
||||
if(!IS_WRAPPER_CLASS(clazz) ||
|
||||
!(supports = (nsISupports*) JS_GetPrivate(cx, obj)))
|
||||
!(supports = (nsISupports*) xpc_GetJSPrivate(obj)))
|
||||
{
|
||||
#ifdef DEBUG
|
||||
{
|
||||
if(!(~clazz->flags & (JSCLASS_HAS_PRIVATE |
|
||||
JSCLASS_PRIVATE_IS_NSISUPPORTS)) &&
|
||||
(supports = (nsISupports*) JS_GetPrivate(cx, obj)))
|
||||
(supports = (nsISupports*) xpc_GetJSPrivate(obj)))
|
||||
{
|
||||
nsCOMPtr<nsIXPConnectWrappedNative> iface =
|
||||
do_QueryInterface(supports);
|
||||
|
@ -784,7 +784,7 @@ XPCWrappedNativeScope::FindInJSObjectScope(XPCCallContext& ccx, JSObject* obj,
|
|||
// If this object is itself a wrapped native then we can get the
|
||||
// scope directly.
|
||||
|
||||
scope = GetScopeOfObject(ccx, obj);
|
||||
scope = GetScopeOfObject(obj);
|
||||
if(scope)
|
||||
return scope;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче