Bug 797821 - Stop passing wantXrays directly to CreateGlobalObject. r=mrbkap
authorBobby Holley <bobbyholley@gmail.com>
Thu, 25 Oct 2012 17:01:07 +0200
changeset 111521 2a49f864998f02764c6c4f85b30414226e191870
parent 111520 4bdc434c6d6eda66d19813aaf3439798bf397361
child 111522 ed27c3a1eca3be9c673adda61cf7f5882239bed7
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmrbkap
bugs797821
milestone19.0a1
Bug 797821 - Stop passing wantXrays directly to CreateGlobalObject. r=mrbkap This can happen after the fact where it needs to.
content/xbl/src/nsXBLDocumentInfo.cpp
content/xul/document/src/nsXULPrototypeDocument.cpp
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCJSContextStack.cpp
js/xpconnect/src/XPCWrappedNative.cpp
js/xpconnect/src/nsXPConnect.cpp
js/xpconnect/src/xpcprivate.h
js/xpconnect/src/xpcpublic.h
--- a/content/xbl/src/nsXBLDocumentInfo.cpp
+++ b/content/xbl/src/nsXBLDocumentInfo.cpp
@@ -276,18 +276,17 @@ nsXBLDocGlobalObject::EnsureScriptEnviro
   JSContext *cx = mScriptContext->GetNativeContext();
   JSAutoRequest ar(cx);
 
   // nsJSEnvironment set the error reporter to NS_ScriptErrorReporter so
   // we must apparently override that with our own (although it isn't clear 
   // why - see bug 339647)
   JS_SetErrorReporter(cx, XBL_ProtoErrorReporter);
 
-  mJSObject = xpc::CreateGlobalObject(cx, &gSharedGlobalClass,
-                                      GetPrincipal(), false);
+  mJSObject = xpc::CreateGlobalObject(cx, &gSharedGlobalClass, GetPrincipal());
   if (!mJSObject)
       return NS_OK;
 
   // Set the location information for the new global, so that tools like
   // about:memory may use that information
   nsIURI *ownerURI = mGlobalObjectOwner->DocumentURI();
   xpc::SetLocationForGlobal(mJSObject, ownerURI);
 
--- a/content/xul/document/src/nsXULPrototypeDocument.cpp
+++ b/content/xul/document/src/nsXULPrototypeDocument.cpp
@@ -748,17 +748,17 @@ nsXULPDGlobalObject::EnsureScriptEnviron
   // We have to setup a special global object.  We do this then
   // attach it as the global for this context.  Then, we
   // will re-fetch the global and set it up in our language globals array.
   {
     JSContext *cx = ctxNew->GetNativeContext();
     JSAutoRequest ar(cx);
 
     JSObject *newGlob = xpc::CreateGlobalObject(cx, &gSharedGlobalClass,
-                                                GetPrincipal(), false);
+                                                GetPrincipal());
     if (!newGlob)
         return NS_OK;;
 
     ::JS_SetGlobalObject(cx, newGlob);
 
     // Add an owning reference from JS back to us. This'll be
     // released when the JSObject is finalized.
     ::JS_SetPrivate(newGlob, this);
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -3253,20 +3253,21 @@ xpc_CreateSandboxObject(JSContext *cx, j
         if (!sop)
             return NS_ERROR_OUT_OF_MEMORY;
     }
 
     nsIPrincipal *principal = sop->GetPrincipal();
 
     JSObject *sandbox;
 
-    sandbox = xpc::CreateGlobalObject(cx, &SandboxClass, principal, options.wantXrays);
+    sandbox = xpc::CreateGlobalObject(cx, &SandboxClass, principal);
     if (!sandbox)
         return NS_ERROR_FAILURE;
     NS_ENSURE_SUCCESS(rv, rv);
+    xpc::GetCompartmentPrivate(sandbox)->wantXrays = options.wantXrays;
 
     JS::AutoObjectRooter tvr(cx, sandbox);
 
     {
         JSAutoCompartment ac(cx, sandbox);
 
         if (options.proto) {
             bool ok = JS_WrapObject(cx, &options.proto);
--- a/js/xpconnect/src/XPCJSContextStack.cpp
+++ b/js/xpconnect/src/XPCJSContextStack.cpp
@@ -176,18 +176,17 @@ XPCJSContextStack::GetSafeJSContext()
 
     JSObject *glob;
     {
         // scoped JS Request
         JSAutoRequest req(mSafeJSContext);
 
         JS_SetErrorReporter(mSafeJSContext, mozJSLoaderErrorReporter);
 
-        glob = xpc::CreateGlobalObject(mSafeJSContext, &global_class,
-                                       principal, false);
+        glob = xpc::CreateGlobalObject(mSafeJSContext, &global_class, principal);
 
         if (glob) {
             // Make sure the context is associated with a proper compartment
             // and not the default compartment.
             JS_SetGlobalObject(mSafeJSContext, glob);
 
             // Note: make sure to set the private before calling
             // InitClasses
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -307,17 +307,17 @@ XPCWrappedNative::WrapNewGlobal(XPCCallC
         si(ccx, XPCNativeScriptableInfo::Construct(ccx, &sciWrapper));
     MOZ_ASSERT(si.get());
 
     // Finally, we get to the JSClass.
     JSClass *clasp = si->GetJSClass();
     MOZ_ASSERT(clasp->flags & JSCLASS_IS_GLOBAL);
 
     // Create the global.
-    JSObject *global =  xpc::CreateGlobalObject(ccx, clasp, principal, false);
+    JSObject *global =  xpc::CreateGlobalObject(ccx, clasp, principal);
     if (!global)
         return NS_ERROR_FAILURE;
 
     // Immediately enter the global's compartment, so that everything else we
     // create ends up there.
     JSAutoCompartment ac(ccx, global);
 
     // If requested, immediately initialize the standard classes on the global.
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -1071,30 +1071,29 @@ CheckTypeInference(JSContext *cx, JSClas
 }
 #else
 #define CheckTypeInference(cx, clasp, principal) {}
 #endif
 
 namespace xpc {
 
 JSObject*
-CreateGlobalObject(JSContext *cx, JSClass *clasp, nsIPrincipal *principal,
-                   bool wantXrays)
+CreateGlobalObject(JSContext *cx, JSClass *clasp, nsIPrincipal *principal)
 {
     // Make sure that Type Inference is enabled for everything non-chrome.
     // Sandboxes and compilation scopes are exceptions. See bug 744034.
     CheckTypeInference(cx, clasp, principal);
 
     NS_ABORT_IF_FALSE(NS_IsMainThread(), "using a principal off the main thread?");
 
     JSObject *global = JS_NewGlobalObject(cx, clasp, nsJSPrincipals::get(principal));
     if (!global)
         return nullptr;
     JSCompartment *compartment = js::GetObjectCompartment(global);
-    JS_SetCompartmentPrivate(compartment, new xpc::CompartmentPrivate(wantXrays));
+    JS_SetCompartmentPrivate(compartment, new xpc::CompartmentPrivate());
 
     XPCCompartmentSet& set = nsXPConnect::GetRuntimeInstance()->GetCompartmentSet();
     if (!set.put(compartment))
         return nullptr;
 
 #ifdef DEBUG
     // Verify that the right trace hook is called. Note that this doesn't
     // work right for wrapped globals, since the tracing situation there is
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -4317,18 +4317,18 @@ XPC_GetIdentityObject(JSContext *cx, JSO
 
 namespace xpc {
 
 class CompartmentPrivate
 {
 public:
     typedef nsTHashtable<nsPtrHashKey<JSObject> > DOMExpandoMap;
 
-    CompartmentPrivate(bool wantXrays)
-        : wantXrays(wantXrays)
+    CompartmentPrivate()
+        : wantXrays(false)
         , universalXPConnectEnabled(false)
     {
         MOZ_COUNT_CTOR(xpc::CompartmentPrivate);
     }
 
     ~CompartmentPrivate();
 
     bool wantXrays;
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -37,18 +37,17 @@ JSObject *
 TransplantObject(JSContext *cx, JSObject *origobj, JSObject *target);
 
 JSObject *
 TransplantObjectWithWrapper(JSContext *cx,
                             JSObject *origobj, JSObject *origwrapper,
                             JSObject *targetobj, JSObject *targetwrapper);
 
 JSObject *
-CreateGlobalObject(JSContext *cx, JSClass *clasp, nsIPrincipal *principal,
-                   bool wantXrays);
+CreateGlobalObject(JSContext *cx, JSClass *clasp, nsIPrincipal *principal);
 } /* namespace xpc */
 
 #define XPCONNECT_GLOBAL_FLAGS                                                \
     JSCLASS_DOM_GLOBAL | JSCLASS_XPCONNECT_GLOBAL | JSCLASS_HAS_PRIVATE |     \
     JSCLASS_PRIVATE_IS_NSISUPPORTS | JSCLASS_IMPLEMENTS_BARRIERS |            \
     JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(3)
 
 void