Bug 899245 - Rename js::GetDefaultGlobalForContext to js::DefaultObjectForContextOrNull. r=luke

This is more correct, since the object very often is not a global.
This commit is contained in:
Bobby Holley 2013-07-29 16:45:25 -07:00
parent b853a768d6
commit acaaa3b1a2
13 changed files with 20 additions and 20 deletions

View File

@ -1649,10 +1649,10 @@ nsContentUtils::TraceSafeJSContext(JSTracer* aTrc)
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));
}
}

View File

@ -1604,7 +1604,7 @@ nsJSContext::GetGlobalObject()
JSObject*
nsJSContext::GetNativeGlobal()
{
return js::GetDefaultGlobalForContext(mContext);
return js::DefaultObjectForContextOrNull(mContext);
}
JSContext*

View File

@ -144,7 +144,7 @@ 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) {

View File

@ -1696,8 +1696,8 @@ WorkerRunnable::Run()
// 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;
@ -2867,8 +2867,8 @@ WorkerPrivate::DoRunLoop(JSContext* aCx)
// 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 &&

View File

@ -1695,7 +1695,7 @@ 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;

View File

@ -370,7 +370,7 @@ js::GetGlobalForObjectCrossCompartment(JSObject *obj)
}
JS_FRIEND_API(JSObject *)
js::GetDefaultGlobalForContext(JSContext *cx)
js::DefaultObjectForContextOrNull(JSContext *cx)
{
return cx->maybeDefaultCompartmentObject();
}

View File

@ -440,7 +440,7 @@ 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);

View File

@ -2635,7 +2635,7 @@ EvalInFrame(JSContext *cx, unsigned argc, jsval *vp)
if (saveCurrent) {
if (!sfc.save())
return false;
ac.construct(cx, GetDefaultGlobalForContext(cx));
ac.construct(cx, DefaultObjectForContextOrNull(cx));
}
size_t length;

View File

@ -687,7 +687,7 @@ 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_);

View File

@ -70,7 +70,7 @@ XPCJSContextStack::Push(JSContext *cx)
// 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);

View File

@ -137,8 +137,8 @@ AutoCxPusher::AutoCxPusher(JSContext* cx, bool allowNull) : mScriptIsRunning(fal
// 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);
}
}

View File

@ -159,7 +159,7 @@ 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);

View File

@ -308,7 +308,7 @@ public:
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);
}
@ -562,7 +562,7 @@ CycleCollectedJSRuntime::MaybeTraceGlobals(JSTracer* aTracer) const
continue;
}
if (JSObject* global = js::GetDefaultGlobalForContext(acx)) {
if (JSObject* global = js::DefaultObjectForContextOrNull(acx)) {
JS::AssertGCThingMustBeTenured(global);
JS_CallObjectTracer(aTracer, &global, "Global Object");
}
@ -760,7 +760,7 @@ CycleCollectedJSRuntime::MaybeTraverseGlobals(nsCycleCollectionNoteRootCallback&
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());
}