Bug 792036 - Refactor AttachComponentsObject API to allow an explicit target. r=mrbkap

The aGlobal API is currently unnecessary, since it should always be equal to the global obtained from the scope. But we'll want to manually specify the target object in subsequent patches, so make it an optional argument that's currently never passed.
This commit is contained in:
Bobby Holley 2012-09-24 14:46:27 +02:00
parent ed5dd572c2
commit ad2fb92189
3 changed files with 13 additions and 8 deletions

View File

@ -3327,7 +3327,7 @@ xpc_CreateSandboxObject(JSContext *cx, jsval *vp, nsISupports *prinOrSop, Sandbo
return NS_ERROR_XPC_UNEXPECTED;
if (options.wantComponents &&
!nsXPCComponents::AttachComponentsObject(ccx, scope, sandbox))
!nsXPCComponents::AttachComponentsObject(ccx, scope))
return NS_ERROR_XPC_UNEXPECTED;
if (!XPCNativeWrapper::AttachNewConstructorObject(ccx, sandbox))
@ -4762,10 +4762,12 @@ nsXPCComponents::SetProperty(nsIXPConnectWrappedNative *wrapper,
JSBool
nsXPCComponents::AttachComponentsObject(XPCCallContext& ccx,
XPCWrappedNativeScope* aScope,
JSObject* aGlobal)
JSObject* aTarget)
{
if (!aGlobal)
return false;
JSObject *global = aScope->GetGlobalJSObject();
MOZ_ASSERT(js::IsObjectInContextCompartment(global, ccx));
if (!aTarget)
aTarget = global;
nsXPCComponents* components = aScope->GetComponents();
if (!components) {
@ -4796,7 +4798,7 @@ nsXPCComponents::AttachComponentsObject(XPCCallContext& ccx,
return false;
jsid id = ccx.GetRuntime()->GetStringID(XPCJSRuntime::IDX_COMPONENTS);
return JS_DefinePropertyById(ccx, aGlobal, id, v, nullptr, nullptr,
return JS_DefinePropertyById(ccx, aTarget, id, v, nullptr, nullptr,
JSPROP_PERMANENT | JSPROP_READONLY);
}

View File

@ -990,7 +990,7 @@ nsXPConnect::InitClasses(JSContext * aJSContext, JSObject * aGlobalJSObj)
scope->RemoveWrappedNativeProtos();
if (!nsXPCComponents::AttachComponentsObject(ccx, scope, aGlobalJSObj))
if (!nsXPCComponents::AttachComponentsObject(ccx, scope))
return UnexpectedFailure(NS_ERROR_FAILURE);
if (!XPCNativeWrapper::AttachNewConstructorObject(ccx, aGlobalJSObj))
@ -1172,7 +1172,7 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
if (!(aFlags & nsIXPConnect::OMIT_COMPONENTS_OBJECT)) {
// XPCCallContext gives us an active request needed to save/restore.
if (!nsXPCComponents::AttachComponentsObject(ccx, wrappedGlobal->GetScope(), global))
if (!nsXPCComponents::AttachComponentsObject(ccx, wrappedGlobal->GetScope()))
return UnexpectedFailure(NS_ERROR_FAILURE);
if (!XPCNativeWrapper::AttachNewConstructorObject(ccx, global))

View File

@ -3747,10 +3747,13 @@ public:
NS_DECL_NSISECURITYCHECKEDCOMPONENT
public:
// The target is the object upon which |Components| will be defined. If
// aTarget is left null, a default object will be computed. This is usually
// the right thing to do.
static JSBool
AttachComponentsObject(XPCCallContext& ccx,
XPCWrappedNativeScope* aScope,
JSObject* aGlobal);
JSObject* aTarget = NULL);
void SystemIsBeingShutDown() {ClearMembers();}