mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-11 14:28:42 +00:00
Create implicit XPCNativeWrappers in fewer situations. bug 441087, r=jst sr=bzbarsky
This commit is contained in:
parent
644b86b987
commit
bf32265aa7
@ -401,7 +401,8 @@ XPC_NW_RewrapIfDeepWrapper(JSContext *cx, JSObject *obj, jsval v, jsval *rval)
|
||||
// Just using GetNewOrUsed on the return value of
|
||||
// GetWrappedNativeOfJSObject will give the right thing -- the unique deep
|
||||
// implicit wrapper associated with wrappedNative.
|
||||
JSObject* wrapperObj = XPCNativeWrapper::GetNewOrUsed(cx, wrappedNative);
|
||||
JSObject* wrapperObj = XPCNativeWrapper::GetNewOrUsed(cx, wrappedNative,
|
||||
nsnull);
|
||||
if (!wrapperObj) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
@ -776,7 +777,7 @@ MirrorWrappedNativeParent(JSContext *cx, XPCWrappedNative *wrapper,
|
||||
XPCWrappedNative *parent_wrapper =
|
||||
XPCWrappedNative::GetWrappedNativeOfJSObject(cx, wn_parent);
|
||||
|
||||
*result = XPCNativeWrapper::GetNewOrUsed(cx, parent_wrapper);
|
||||
*result = XPCNativeWrapper::GetNewOrUsed(cx, parent_wrapper, nsnull);
|
||||
if (!*result)
|
||||
return JS_FALSE;
|
||||
}
|
||||
@ -794,7 +795,7 @@ XPCNativeWrapperCtor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
// |obj| almost always has the wrong proto and parent so we have to create
|
||||
// our own object anyway. Set |obj| to null so we don't use it by accident.
|
||||
obj = nsnull;
|
||||
|
||||
|
||||
jsval native = argv[0];
|
||||
|
||||
if (JSVAL_IS_PRIMITIVE(native)) {
|
||||
@ -822,7 +823,6 @@ XPCNativeWrapperCtor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
XPCWrappedNative *wrappedNative;
|
||||
|
||||
if (XPCNativeWrapper::IsNativeWrapper(nativeObj)) {
|
||||
@ -1083,8 +1083,26 @@ XPCNativeWrapper::AttachNewConstructorObject(XPCCallContext &ccx,
|
||||
|
||||
// static
|
||||
JSObject *
|
||||
XPCNativeWrapper::GetNewOrUsed(JSContext *cx, XPCWrappedNative *wrapper)
|
||||
XPCNativeWrapper::GetNewOrUsed(JSContext *cx, XPCWrappedNative *wrapper,
|
||||
JSObject *callee)
|
||||
{
|
||||
if (callee) {
|
||||
nsCOMPtr<nsIPrincipal> prin;
|
||||
|
||||
nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
|
||||
nsresult rv = ssm->GetObjectPrincipal(cx, callee, getter_AddRefs(prin));
|
||||
if (NS_SUCCEEDED(rv) && prin) {
|
||||
PRBool isSystem;
|
||||
rv = ssm->IsSystemPrincipal(prin, &isSystem);
|
||||
if (NS_SUCCEEDED(rv) && !isSystem) {
|
||||
jsval v = OBJECT_TO_JSVAL(wrapper->GetFlatJSObject());
|
||||
if (!XPCNativeWrapperCtor(cx, JSVAL_TO_OBJECT(v), 1, &v, &v))
|
||||
return nsnull;
|
||||
return JSVAL_TO_OBJECT(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent wrapping a double-wrapped JS object in an
|
||||
// XPCNativeWrapper!
|
||||
nsCOMPtr<nsIXPConnectWrappedJS> xpcwrappedjs(do_QueryWrappedNative(wrapper));
|
||||
|
@ -46,7 +46,8 @@ public:
|
||||
static PRBool AttachNewConstructorObject(XPCCallContext &ccx,
|
||||
JSObject *aGlobalObject);
|
||||
|
||||
static JSObject *GetNewOrUsed(JSContext *cx, XPCWrappedNative *wrapper);
|
||||
static JSObject *GetNewOrUsed(JSContext *cx, XPCWrappedNative *wrapper,
|
||||
JSObject *callee);
|
||||
|
||||
static PRBool IsNativeWrapperClass(JSClass *clazz)
|
||||
{
|
||||
|
@ -1120,6 +1120,7 @@ XPCConvert::NativeInterface2JSObject(XPCCallContext& ccx,
|
||||
// printf("Wrapped native accessed across scope boundary\n");
|
||||
|
||||
JSScript* script = nsnull;
|
||||
JSObject* callee = nsnull;
|
||||
if(ccx.GetXPCContext()->CallerTypeIsJavaScript())
|
||||
{
|
||||
// Called from JS. We're going to hand the resulting
|
||||
@ -1127,15 +1128,20 @@ XPCConvert::NativeInterface2JSObject(XPCCallContext& ccx,
|
||||
// the stack.
|
||||
JSContext* cx = ccx;
|
||||
JSStackFrame* fp = cx->fp;
|
||||
while(!script && fp)
|
||||
while(fp)
|
||||
{
|
||||
script = fp->script;
|
||||
if(script)
|
||||
{
|
||||
callee = fp->callee;
|
||||
break;
|
||||
}
|
||||
fp = fp->down;
|
||||
}
|
||||
}
|
||||
else if(ccx.GetXPCContext()->CallerTypeIsNative())
|
||||
{
|
||||
JSObject* callee = ccx.GetCallee();
|
||||
callee = ccx.GetCallee();
|
||||
if(callee && JS_ObjectIsFunction(ccx, callee))
|
||||
{
|
||||
// Called from c++, and calling out to |callee|, which
|
||||
@ -1148,8 +1154,12 @@ XPCConvert::NativeInterface2JSObject(XPCCallContext& ccx,
|
||||
"object");
|
||||
script = JS_GetFunctionScript(ccx, fun);
|
||||
}
|
||||
// Else we don't know whom we're calling, so don't create
|
||||
// XPCNativeWrappers.
|
||||
else
|
||||
{
|
||||
// Else we don't know whom we're calling, so don't
|
||||
// create XPCNativeWrappers.
|
||||
callee = nsnull;
|
||||
}
|
||||
}
|
||||
// else don't create XPCNativeWrappers, since we have
|
||||
// no idea what's calling what here.
|
||||
@ -1173,7 +1183,8 @@ XPCConvert::NativeInterface2JSObject(XPCCallContext& ccx,
|
||||
#endif
|
||||
|
||||
JSObject *nativeWrapper =
|
||||
XPCNativeWrapper::GetNewOrUsed(ccx, wrapper);
|
||||
XPCNativeWrapper::GetNewOrUsed(ccx, wrapper,
|
||||
callee);
|
||||
|
||||
if (nativeWrapper)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user