bug 1250486 - get rid of the static ctor for XPCShellImpl.cpp r=bz

The dtor for PersistentRooted<> removes it from a linked list, which means we
need a static ctor to register that dtor with the atexit machinary.  So the
easiest thing to do is make sScriptedInterruptCallback a pointer that points to
a PersistentRootedValue we allocate on the heap.
This commit is contained in:
Trevor Saunders 2016-02-23 08:03:40 -05:00
Родитель fb15614836
Коммит 32fdac666f
1 изменённых файлов: 8 добавлений и 7 удалений

Просмотреть файл

@ -561,13 +561,13 @@ Btoa(JSContext* cx, unsigned argc, Value* vp)
return xpc::Base64Encode(cx, args[0], args.rval());
}
static PersistentRootedValue sScriptedInterruptCallback;
static PersistentRootedValue *sScriptedInterruptCallback = nullptr;
static bool
XPCShellInterruptCallback(JSContext* cx)
{
MOZ_ASSERT(sScriptedInterruptCallback.initialized());
RootedValue callback(cx, sScriptedInterruptCallback);
MOZ_ASSERT(sScriptedInterruptCallback->initialized());
RootedValue callback(cx, *sScriptedInterruptCallback);
// If no interrupt callback was set by script, no-op.
if (callback.isUndefined())
@ -589,7 +589,7 @@ XPCShellInterruptCallback(JSContext* cx)
static bool
SetInterruptCallback(JSContext* cx, unsigned argc, Value* vp)
{
MOZ_ASSERT(sScriptedInterruptCallback.initialized());
MOZ_ASSERT(sScriptedInterruptCallback->initialized());
// Sanity-check args.
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
@ -600,7 +600,7 @@ SetInterruptCallback(JSContext* cx, unsigned argc, Value* vp)
// Allow callers to remove the interrupt callback by passing undefined.
if (args[0].isUndefined()) {
sScriptedInterruptCallback = UndefinedValue();
*sScriptedInterruptCallback = UndefinedValue();
return true;
}
@ -610,7 +610,7 @@ SetInterruptCallback(JSContext* cx, unsigned argc, Value* vp)
return false;
}
sScriptedInterruptCallback = args[0];
*sScriptedInterruptCallback = args[0];
return true;
}
@ -1433,7 +1433,8 @@ XRE_XPCShellMain(int argc, char** argv, char** envp)
// Override the default XPConnect interrupt callback. We could store the
// old one and restore it before shutting down, but there's not really a
// reason to bother.
sScriptedInterruptCallback.init(rt, UndefinedValue());
sScriptedInterruptCallback = new PersistentRootedValue;
sScriptedInterruptCallback->init(rt, UndefinedValue());
JS_SetInterruptCallback(rt, XPCShellInterruptCallback);
AutoJSAPI jsapi;