Bug 1341358 - Don't accidentally clear the incumbent global callback when finishing a cooperative thread, r=jandem.
authorBrian Hackett <bhackett1024@gmail.com>
Wed, 22 Feb 2017 05:16:50 -0700
changeset 344290 c6a89afa0c6b9c26cdba08a5d8e4115bc699d8d7
parent 344289 f2019fbd6f8c41163eb540d798558d44fcf176f4
child 344291 3c365d2e82021bff402507092a42b2b4c00ed297
push id31406
push userkwierso@gmail.com
push dateWed, 22 Feb 2017 23:01:18 +0000
treeherdermozilla-central@32dcdde1fc64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1341358
milestone54.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 1341358 - Don't accidentally clear the incumbent global callback when finishing a cooperative thread, r=jandem.
js/src/jit-test/tests/basic/bug1341358.js
js/src/shell/js.cpp
js/src/vm/Runtime.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/bug1341358.js
@@ -0,0 +1,8 @@
+if (helperThreadCount() == 0)
+    quit();
+evalInCooperativeThread("var x = 3");
+let PromiseCtor = Promise;
+let promises = [];
+let p = new PromiseCtor(function(res_, rej_) {});
+promises.push(p);
+let allPromise = getWaitForAllPromise(promises);
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -3538,20 +3538,23 @@ WorkerMain(void* arg)
         AutoReportException are(cx);
         RootedScript script(cx);
         if (!JS::Compile(cx, options, input->chars, input->length, &script))
             break;
         RootedValue result(cx);
         JS_ExecuteScript(cx, script, &result);
     } while (0);
 
-    JS::SetLargeAllocationFailureCallback(cx, nullptr, nullptr);
-
-    JS::SetGetIncumbentGlobalCallback(cx, nullptr);
-    JS::SetEnqueuePromiseJobCallback(cx, nullptr);
+    if (input->parentRuntime) {
+        JS::SetLargeAllocationFailureCallback(cx, nullptr, nullptr);
+
+        JS::SetGetIncumbentGlobalCallback(cx, nullptr);
+        JS::SetEnqueuePromiseJobCallback(cx, nullptr);
+    }
+
     sc->jobQueue.reset();
 
     KillWatchdog(cx);
 }
 
 // Workers can spawn other workers, so we need a lock to access workerThreads.
 static Mutex* workerThreadsLock = nullptr;
 static Vector<js::Thread*, 0, SystemAllocPolicy> workerThreads;
--- a/js/src/vm/Runtime.cpp
+++ b/js/src/vm/Runtime.cpp
@@ -627,17 +627,17 @@ FreeOp::isDefaultFreeOp() const
 {
     return runtime_ && runtime_->defaultFreeOp() == this;
 }
 
 JSObject*
 JSRuntime::getIncumbentGlobal(JSContext* cx)
 {
     MOZ_ASSERT(cx->runtime()->getIncumbentGlobalCallback,
-               "Must set a callback using JS_SetGetIncumbentGlobalCallback before using Promises");
+               "Must set a callback using SetGetIncumbentGlobalCallback before using Promises");
 
     return cx->runtime()->getIncumbentGlobalCallback(cx);
 }
 
 bool
 JSRuntime::enqueuePromiseJob(JSContext* cx, HandleFunction job, HandleObject promise,
                              HandleObject incumbentGlobal)
 {