Bug 899245 - Rename js::GetDefaultGlobalForContext to js::DefaultObjectForContextOrNull. r=luke
authorBobby Holley <bobbyholley@gmail.com>
Mon, 29 Jul 2013 16:45:25 -0700
changeset 152750 e5305a6fba38e7607addecf33f3078855b90adbc
parent 152749 770b97caaababc0feb961b4cc8d9812f15b88dc6
child 152751 829fcfef081051c4be5fca1f5e4c6e3a72e4293f
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs899245
milestone25.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 899245 - Rename js::GetDefaultGlobalForContext to js::DefaultObjectForContextOrNull. r=luke This is more correct, since the object very often is not a global.
content/base/src/nsContentUtils.cpp
dom/base/nsJSEnvironment.cpp
dom/base/nsJSUtils.cpp
dom/workers/WorkerPrivate.cpp
js/jsd/jsd_xpc.cpp
js/src/jsfriendapi.cpp
js/src/jsfriendapi.h
js/src/shell/js.cpp
js/src/vm/SelfHosting.cpp
js/xpconnect/src/XPCJSContextStack.cpp
js/xpconnect/src/nsCxPusher.cpp
js/xpconnect/src/xpcpublic.h
xpcom/base/CycleCollectedJSRuntime.cpp
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -1644,20 +1644,20 @@ nsContentUtils::GetContextFromDocument(n
 //static
 void
 nsContentUtils::TraceSafeJSContext(JSTracer* aTrc)
 {
   JSContext* cx = GetSafeJSContext();
   if (!cx) {
     return;
   }
-  if (JSObject* global = js::GetDefaultGlobalForContext(cx)) {
+  if (JSObject* global = js::DefaultObjectForContextOrNull(cx)) {
     JS::AssertGCThingMustBeTenured(global);
     JS_CallObjectTracer(aTrc, &global, "safe context");
-    MOZ_ASSERT(global == js::GetDefaultGlobalForContext(cx));
+    MOZ_ASSERT(global == js::DefaultObjectForContextOrNull(cx));
   }
 }
 
 nsPIDOMWindow *
 nsContentUtils::GetWindowFromCaller()
 {
   JSContext *cx = GetCurrentJSContext();
   if (cx) {
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -1599,17 +1599,17 @@ nsJSContext::GetGlobalObject()
   // This'll return a pointer to something we're about to release, but
   // that's ok, the JS object will hold it alive long enough.
   return sgo;
 }
 
 JSObject*
 nsJSContext::GetNativeGlobal()
 {
-    return js::GetDefaultGlobalForContext(mContext);
+    return js::DefaultObjectForContextOrNull(mContext);
 }
 
 JSContext*
 nsJSContext::GetNativeContext()
 {
   return xpc_UnmarkGrayContext(mContext);
 }
 
--- a/dom/base/nsJSUtils.cpp
+++ b/dom/base/nsJSUtils.cpp
@@ -139,17 +139,17 @@ nsJSUtils::GetCurrentlyRunningCodeInnerW
 }
 
 void
 nsJSUtils::ReportPendingException(JSContext *aContext)
 {
   if (JS_IsExceptionPending(aContext)) {
     bool saved = JS_SaveFrameChain(aContext);
     {
-      JSAutoCompartment ac(aContext, js::GetDefaultGlobalForContext(aContext));
+      JSAutoCompartment ac(aContext, js::DefaultObjectForContextOrNull(aContext));
       JS_ReportPendingException(aContext);
     }
     if (saved) {
       JS_RestoreFrameChain(aContext);
     }
   }
 }
 
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -1691,18 +1691,18 @@ WorkerRunnable::Run()
     ac.construct(cx, targetCompartmentObject);
   }
 
   bool result = WorkerRun(cx, mWorkerPrivate);
   // In the case of CompileScriptRunnnable, WorkerRun above can cause us to
   // lazily create a global, in which case we need to be in its compartment
   // when calling PostRun() below. Maybe<> this time...
   if (mTarget == WorkerThread && ac.empty() &&
-      js::GetDefaultGlobalForContext(cx)) {
-    ac.construct(cx, js::GetDefaultGlobalForContext(cx));
+      js::DefaultObjectForContextOrNull(cx)) {
+    ac.construct(cx, js::DefaultObjectForContextOrNull(cx));
   }
   PostRun(cx, mWorkerPrivate, result);
   return result ? NS_OK : NS_ERROR_FAILURE;
 }
 
 void
 WorkerRunnable::PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
                         bool aRunResult)
@@ -2862,18 +2862,18 @@ WorkerPrivate::DoRunLoop(JSContext* aCx)
 
         // Workers lazily create a global object in CompileScriptRunnable. In
         // the old world, creating the global would implicitly set it as the
         // default compartment object on mJSContext, meaning that subsequent
         // runnables would be able to operate in that compartment without
         // explicitly entering it. That no longer works, so we mimic the
         // "operate in the compartment of the worker global once it exists"
         // behavior here. This could probably be improved with some refactoring.
-        if (maybeAC.empty() && js::GetDefaultGlobalForContext(aCx)) {
-          maybeAC.construct(aCx, js::GetDefaultGlobalForContext(aCx));
+        if (maybeAC.empty() && js::DefaultObjectForContextOrNull(aCx)) {
+          maybeAC.construct(aCx, js::DefaultObjectForContextOrNull(aCx));
         }
 
         if (!normalGCTimerRunning &&
             event != idleGCEvent &&
             currentStatus <= Terminating) {
           // Must always cancel before changing the timer's target.
           if (NS_FAILED(gcTimer->Cancel())) {
             NS_WARNING("Failed to cancel GC timer!");
--- a/js/jsd/jsd_xpc.cpp
+++ b/js/jsd/jsd_xpc.cpp
@@ -1690,17 +1690,17 @@ jsdContext::GetTag(uint32_t *_rval)
     *_rval = mTag;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 jsdContext::GetGlobalObject (jsdIValue **_rval)
 {
     ASSERT_VALID_EPHEMERAL;
-    JSObject *glob = js::GetDefaultGlobalForContext(mJSCx);
+    JSObject *glob = js::DefaultObjectForContextOrNull(mJSCx);
     JSDValue *jsdv = JSD_NewValue (mJSDCx, OBJECT_TO_JSVAL(glob));
     if (!jsdv)
         return NS_ERROR_FAILURE;
     *_rval = jsdValue::FromPtr (mJSDCx, jsdv);
     if (!*_rval)
         return NS_ERROR_FAILURE;
     return NS_OK;
 }
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -365,17 +365,17 @@ js::GetObjectParentMaybeScope(JSObject *
 
 JS_FRIEND_API(JSObject *)
 js::GetGlobalForObjectCrossCompartment(JSObject *obj)
 {
     return &obj->global();
 }
 
 JS_FRIEND_API(JSObject *)
-js::GetDefaultGlobalForContext(JSContext *cx)
+js::DefaultObjectForContextOrNull(JSContext *cx)
 {
     return cx->maybeDefaultCompartmentObject();
 }
 
 JS_FRIEND_API(void)
 js::NotifyAnimationActivity(JSObject *obj)
 {
     obj->compartment()->lastAnimationTime = PRMJ_Now();
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -435,17 +435,17 @@ GetObjectCompartment(JSObject *obj)
 JS_FRIEND_API(JSObject *)
 GetObjectParentMaybeScope(JSObject *obj);
 
 JS_FRIEND_API(JSObject *)
 GetGlobalForObjectCrossCompartment(JSObject *obj);
 
 // For legacy consumers only. This whole concept is going away soon.
 JS_FRIEND_API(JSObject *)
-GetDefaultGlobalForContext(JSContext *cx);
+DefaultObjectForContextOrNull(JSContext *cx);
 
 JS_FRIEND_API(void)
 NotifyAnimationActivity(JSObject *obj);
 
 JS_FRIEND_API(bool)
 IsOriginalScriptFunction(JSFunction *fun);
 
 /*
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2630,17 +2630,17 @@ EvalInFrame(JSContext *cx, unsigned argc
             break;
     }
 
     AutoSaveFrameChain sfc(cx);
     mozilla::Maybe<AutoCompartment> ac;
     if (saveCurrent) {
         if (!sfc.save())
             return false;
-        ac.construct(cx, GetDefaultGlobalForContext(cx));
+        ac.construct(cx, DefaultObjectForContextOrNull(cx));
     }
 
     size_t length;
     const jschar *chars = JS_GetStringCharsAndLength(cx, str, &length);
     if (!chars)
         return false;
 
     JSAbstractFramePtr frame(Jsvalify(fi.abstractFramePtr()));
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -682,17 +682,17 @@ const JSFunctionSpec intrinsic_functions
 
     JS_FS_END
 };
 
 bool
 JSRuntime::initSelfHosting(JSContext *cx)
 {
     JS_ASSERT(!selfHostingGlobal_);
-    RootedObject savedGlobal(cx, js::GetDefaultGlobalForContext(cx));
+    RootedObject savedGlobal(cx, js::DefaultObjectForContextOrNull(cx));
     if (!(selfHostingGlobal_ = JS_NewGlobalObject(cx, &self_hosting_global_class, NULL)))
         return false;
     JSAutoCompartment ac(cx, selfHostingGlobal_);
     JS_SetGlobalObject(cx, selfHostingGlobal_);
     Rooted<GlobalObject*> shg(cx, &selfHostingGlobal_->as<GlobalObject>());
     /*
      * During initialization of standard classes for the self-hosting global,
      * all self-hosted functions are ignored. Thus, we don't create cyclic
--- a/js/xpconnect/src/XPCJSContextStack.cpp
+++ b/js/xpconnect/src/XPCJSContextStack.cpp
@@ -65,17 +65,17 @@ XPCJSContextStack::Push(JSContext *cx)
 
     XPCJSContextInfo &e = mStack[mStack.Length() - 1];
     if (e.cx) {
         // The cx we're pushing is also stack-top. In general we still need to
         // call JS_SaveFrameChain here. But if that would put us in a
         // compartment that's same-origin with the current one, we can skip it.
         nsIScriptSecurityManager* ssm = XPCWrapper::GetSecurityManager();
         if ((e.cx == cx) && ssm) {
-            RootedObject defaultGlobal(cx, js::GetDefaultGlobalForContext(cx));
+            RootedObject defaultGlobal(cx, js::DefaultObjectForContextOrNull(cx));
             nsIPrincipal *currentPrincipal =
               GetCompartmentPrincipal(js::GetContextCompartment(cx));
             nsIPrincipal *defaultPrincipal = GetObjectPrincipal(defaultGlobal);
             bool equal = false;
             currentPrincipal->Equals(defaultPrincipal, &equal);
             if (equal) {
                 mStack.AppendElement(cx);
                 return true;
--- a/js/xpconnect/src/nsCxPusher.cpp
+++ b/js/xpconnect/src/nsCxPusher.cpp
@@ -132,18 +132,18 @@ AutoCxPusher::AutoCxPusher(JSContext* cx
 
   // Enter a request and a compartment for the duration that the cx is on the
   // stack if non-null.
   //
   // NB: We call UnmarkGrayContext so that this can obsolete the need for the
   // old XPCAutoRequest as well.
   if (cx) {
     mAutoRequest.construct(cx);
-    if (js::GetDefaultGlobalForContext(cx))
-      mAutoCompartment.construct(cx, js::GetDefaultGlobalForContext(cx));
+    if (js::DefaultObjectForContextOrNull(cx))
+      mAutoCompartment.construct(cx, js::DefaultObjectForContextOrNull(cx));
     xpc_UnmarkGrayContext(cx);
   }
 }
 
 NS_EXPORT
 AutoCxPusher::~AutoCxPusher()
 {
   // Leave the compartment and request before popping.
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -154,17 +154,17 @@ xpc_UnmarkGrayScript(JSScript *script)
 
     return script;
 }
 
 inline JSContext *
 xpc_UnmarkGrayContext(JSContext *cx)
 {
     if (cx) {
-        JSObject *global = js::GetDefaultGlobalForContext(cx);
+        JSObject *global = js::DefaultObjectForContextOrNull(cx);
         xpc_UnmarkGrayObject(global);
         if (global && JS_IsInRequest(JS_GetRuntime(cx))) {
             JSObject *scope = JS_GetGlobalForScopeChain(cx);
             if (scope != global)
                 xpc_UnmarkGrayObject(scope);
         }
     }
     return cx;
--- a/xpcom/base/CycleCollectedJSRuntime.cpp
+++ b/xpcom/base/CycleCollectedJSRuntime.cpp
@@ -303,17 +303,17 @@ public:
     // JSContexts do not have an internal refcount and always have a single
     // owner (e.g., nsJSContext). Thus, the default refcount is 1. However,
     // in the (abnormal) case of synchronous cycle-collection, the context
     // may be actively executing code in which case we want to treat it as
     // rooted by adding an extra refcount.
     unsigned refCount = js::ContextHasOutstandingRequests(cx) ? 2 : 1;
 
     cb.DescribeRefCountedNode(refCount, "JSContext");
-    if (JSObject *global = js::GetDefaultGlobalForContext(cx)) {
+    if (JSObject *global = js::DefaultObjectForContextOrNull(cx)) {
       NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[global object]");
       cb.NoteJSChild(global);
     }
 
     return NS_OK;
   }
 };
 
@@ -557,17 +557,17 @@ CycleCollectedJSRuntime::MaybeTraceGloba
 {
   JSContext* iter = nullptr;
   while (JSContext* acx = JS_ContextIterator(Runtime(), &iter)) {
     MOZ_ASSERT(js::HasUnrootedGlobal(acx) == mExpectUnrootedGlobals);
     if (!js::HasUnrootedGlobal(acx)) {
       continue;
     }
 
-    if (JSObject* global = js::GetDefaultGlobalForContext(acx)) {
+    if (JSObject* global = js::DefaultObjectForContextOrNull(acx)) {
       JS::AssertGCThingMustBeTenured(global);
       JS_CallObjectTracer(aTracer, &global, "Global Object");
     }
   }
 }
 
 void
 CycleCollectedJSRuntime::DescribeGCThing(bool aIsMarked, void* aThing,
@@ -755,17 +755,17 @@ CycleCollectedJSRuntime::TraverseObjectS
 // collector.
 void
 CycleCollectedJSRuntime::MaybeTraverseGlobals(nsCycleCollectionNoteRootCallback& aCb) const
 {
   JSContext *iter = nullptr, *acx;
   while ((acx = JS_ContextIterator(Runtime(), &iter))) {
     // Add the context to the CC graph only if traversing it would
     // end up doing something.
-    JSObject* global = js::GetDefaultGlobalForContext(acx);
+    JSObject* global = js::DefaultObjectForContextOrNull(acx);
     if (global && xpc_IsGrayGCThing(global)) {
       aCb.NoteNativeRoot(acx, JSContextParticipant());
     }
   }
 }
 
 void
 CycleCollectedJSRuntime::TraverseNativeRoots(nsCycleCollectionNoteRootCallback& aCb)