Bug 1274922 part 2 - Give the shell its own EnvironmentPreparer. r=jorendorff

This commit is contained in:
Jan de Mooij 2016-05-28 13:11:17 +02:00
parent 8164408c7e
commit 4cbcb1c8f0

View File

@ -178,6 +178,16 @@ struct ShellRuntime
bool quitting;
};
struct MOZ_STACK_CLASS EnvironmentPreparer : public js::ScriptEnvironmentPreparer {
JSContext* cx;
explicit EnvironmentPreparer(JSContext* cx)
: cx(cx)
{
js::SetScriptEnvironmentPreparer(JS_GetRuntime(cx), this);
}
void invoke(JS::HandleObject scope, Closure& closure) override;
};
// Shell state set once at startup.
static bool enableCodeCoverage = false;
static bool enableDisassemblyDumps = false;
@ -496,6 +506,18 @@ SkipUTF8BOM(FILE* file)
ungetc(ch1, file);
}
void
EnvironmentPreparer::invoke(HandleObject scope, Closure& closure)
{
MOZ_ASSERT(!JS_IsExceptionPending(cx));
AutoCompartment ac(cx, scope);
if (!closure(cx))
JS_ReportPendingException(cx);
MOZ_ASSERT(!JS_IsExceptionPending(cx));
}
static void
RunFile(JSContext* cx, const char* filename, FILE* file, bool compileOnly)
{
@ -2952,6 +2974,8 @@ WorkerMain(void* arg)
JS::SetEnqueuePromiseJobCallback(rt, ShellEnqueuePromiseJobCallback);
#endif // SPIDERMONKEY_PROMISE
EnvironmentPreparer environmentPreparer(cx);
JS::SetLargeAllocationFailureCallback(rt, my_LargeAllocFailCallback, (void*)cx);
do {
@ -7441,6 +7465,8 @@ main(int argc, char** argv, char** envp)
JS::SetEnqueuePromiseJobCallback(rt, ShellEnqueuePromiseJobCallback);
#endif // SPIDERMONKEY_PROMISE
EnvironmentPreparer environmentPreparer(cx);
JS_SetGCParameter(rt, JSGC_MODE, JSGC_MODE_INCREMENTAL);
JS::SetLargeAllocationFailureCallback(rt, my_LargeAllocFailCallback, (void*)cx);