Bug 1252565 part 1. Push the script environment preparer bits up from XPCJSRuntime to CycleCollectedJSRuntime, because we need them on workers to do ctypes on workers properly. r=bholley

This commit is contained in:
Boris Zbarsky 2016-03-02 12:38:24 -05:00
Родитель 4d888c1249
Коммит 3baae07268
4 изменённых файлов: 32 добавлений и 27 удалений

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

@ -1343,27 +1343,6 @@ xpc::SimulateActivityCallback(bool aActive)
XPCJSRuntime::ActivityCallback(XPCJSRuntime::Get(), aActive);
}
void
XPCJSRuntime::EnvironmentPreparer::invoke(HandleObject scope, js::ScriptEnvironmentPreparer::Closure& closure)
{
MOZ_ASSERT(NS_IsMainThread());
nsIGlobalObject* global = NativeGlobal(scope);
// Not much we can do if we simply don't have a usable global here...
NS_ENSURE_TRUE_VOID(global && global->GetGlobalJSObject());
AutoEntryScript aes(global, "JS-engine-initiated execution");
aes.TakeOwnershipOfErrorReporting();
MOZ_ASSERT(!JS_IsExceptionPending(aes.cx()));
DebugOnly<bool> ok = closure(aes.cx());
MOZ_ASSERT_IF(ok, !JS_IsExceptionPending(aes.cx()));
// The AutoEntryScript will check for JS_IsExceptionPending on the
// JSContext and report it as needed as it comes off the stack.
}
// static
void
XPCJSRuntime::ActivityCallback(void* arg, bool active)
@ -3505,7 +3484,6 @@ XPCJSRuntime::Initialize()
stack->sampleRuntime(runtime);
#endif
JS_SetAccumulateTelemetryCallback(runtime, AccumulateTelemetryCallback);
js::SetScriptEnvironmentPreparer(runtime, &mEnvironmentPreparer);
js::SetActivityCallback(runtime, ActivityCallback, this);
JS_SetInterruptCallback(runtime, InterruptCallback);
js::SetWindowProxyClass(runtime, &OuterWindowProxyClass);

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

@ -592,11 +592,6 @@ public:
void AddGCCallback(xpcGCCallback cb);
void RemoveGCCallback(xpcGCCallback cb);
struct EnvironmentPreparer : public js::ScriptEnvironmentPreparer {
void invoke(JS::HandleObject scope, Closure& closure) override;
};
EnvironmentPreparer mEnvironmentPreparer;
static void ActivityCallback(void* arg, bool active);
static bool InterruptCallback(JSContext* cx);

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

@ -502,6 +502,7 @@ CycleCollectedJSRuntime::Initialize(JSRuntime* aParentRuntime,
InstanceClassHasProtoAtDepth
};
SetDOMCallbacks(mJSRuntime, &DOMcallbacks);
js::SetScriptEnvironmentPreparer(mJSRuntime, &mEnvironmentPreparer);
#ifdef SPIDERMONKEY_PROMISE
JS::SetEnqueuePromiseJobCallback(mJSRuntime, EnqueuePromiseJobCallback, this);
@ -1613,3 +1614,28 @@ CycleCollectedJSRuntime::PrepareWaitingZonesForGC()
mZonesWaitingForGC.Clear();
}
}
void
CycleCollectedJSRuntime::EnvironmentPreparer::invoke(JS::HandleObject scope,
js::ScriptEnvironmentPreparer::Closure& closure)
{
nsIGlobalObject* global = xpc::NativeGlobal(scope);
// Not much we can do if we simply don't have a usable global here...
NS_ENSURE_TRUE_VOID(global && global->GetGlobalJSObject());
bool mainThread = NS_IsMainThread();
JSContext* cx =
mainThread ? nullptr : nsContentUtils::GetDefaultJSContextForThread();
AutoEntryScript aes(global, "JS-engine-initiated execution", mainThread, cx);
aes.TakeOwnershipOfErrorReporting();
MOZ_ASSERT(!JS_IsExceptionPending(aes.cx()));
DebugOnly<bool> ok = closure(aes.cx());
MOZ_ASSERT_IF(ok, !JS_IsExceptionPending(aes.cx()));
// The AutoEntryScript will check for JS_IsExceptionPending on the
// JSContext and report it as needed as it comes off the stack.
}

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

@ -14,6 +14,7 @@
#include "mozilla/MemoryReporting.h"
#include "mozilla/SegmentedVector.h"
#include "jsapi.h"
#include "jsfriendapi.h"
#include "nsCycleCollectionParticipant.h"
#include "nsDataHashtable.h"
@ -401,6 +402,11 @@ private:
mPreservedNurseryObjects;
nsTHashtable<nsPtrHashKey<JS::Zone>> mZonesWaitingForGC;
struct EnvironmentPreparer : public js::ScriptEnvironmentPreparer {
void invoke(JS::HandleObject scope, Closure& closure) override;
};
EnvironmentPreparer mEnvironmentPreparer;
};
void TraceScriptHolder(nsISupports* aHolder, JSTracer* aTracer);