Bug 1152106, part 2 - Make the global Components property configurable in cases where EnableUniversalXPConnect may later need to redefine it. r=bholley.
authorJason Orendorff <jorendorff@mozilla.com>
Fri, 10 Apr 2015 18:04:05 -0500
changeset 240419 f84caefdf90db6545b0be3ebbcacb959f9121d09
parent 240418 693ab25e4c62d1131e8ad47691e150aa00c40052
child 240420 17aa3439663e66874a35eb91711edbc66994bdfa
push id28636
push userkwierso@gmail.com
push dateThu, 23 Apr 2015 00:16:12 +0000
treeherdermozilla-central@a5af73b32ac8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1152106
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1152106, part 2 - Make the global Components property configurable in cases where EnableUniversalXPConnect may later need to redefine it. r=bholley.
js/xpconnect/src/XPCWrappedNativeScope.cpp
--- a/js/xpconnect/src/XPCWrappedNativeScope.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp
@@ -192,19 +192,26 @@ XPCWrappedNativeScope::AttachComponentsO
 {
     RootedObject components(aCx);
     if (!GetComponentsJSObject(&components))
         return false;
 
     RootedObject global(aCx, GetGlobalJSObject());
     MOZ_ASSERT(js::IsObjectInContextCompartment(global, aCx));
 
+    // The global Components property is non-configurable if it's a full
+    // nsXPCComponents object. That way, if it's an nsXPCComponentsBase,
+    // enableUniversalXPConnect can upgrade it later.
+    unsigned attrs = JSPROP_READONLY;
+    nsCOMPtr<nsIXPCComponents> c = do_QueryInterface(mComponents);
+    if (c)
+        attrs |= JSPROP_PERMANENT;
+
     RootedId id(aCx, XPCJSRuntime::Get()->GetStringID(XPCJSRuntime::IDX_COMPONENTS));
-    return JS_DefinePropertyById(aCx, global, id, components,
-                                 JSPROP_PERMANENT | JSPROP_READONLY);
+    return JS_DefinePropertyById(aCx, global, id, components, attrs);
 }
 
 static bool
 CompartmentPerAddon()
 {
     static bool initialized = false;
     static bool pref = false;