Bug 1120235. Various promise resolve/reject functions should actually return undefined instead of ending up accidentally returning their callee. r=nsm
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 12 Jan 2015 22:35:33 -0500
changeset 223467 02fb8f978e91aee84765ab33d863b320e25764f8
parent 223466 06f5318758ae2eeb501d57f6c501a497921595c1
child 223468 b5c6dd9423cf8830adf266c672ef550e83dc43f6
push id28095
push usercbook@mozilla.com
push dateTue, 13 Jan 2015 13:24:48 +0000
treeherdermozilla-central@a5700bec72e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnsm
bugs1120235
milestone38.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 1120235. Various promise resolve/reject functions should actually return undefined instead of ending up accidentally returning their callee. r=nsm
dom/promise/Promise.cpp
dom/promise/tests/mochitest.ini
dom/promise/tests/test_resolver_return_value.html
--- a/dom/promise/Promise.cpp
+++ b/dom/promise/Promise.cpp
@@ -413,43 +413,47 @@ Promise::JSCallback(JSContext* aCx, unsi
     }
   } else {
     promise->MaybeRejectInternal(aCx, args.get(0));
     if (!promise->CaptureStack(aCx, promise->mRejectionStack)) {
       return false;
     }
   }
 
+  args.rval().setUndefined();
   return true;
 }
 
 /*
  * Common bits of (JSCallbackThenableResolver/JSCallbackThenableRejecter).
  * Resolves/rejects the Promise if it is ok to do so, based on whether either of
  * the callbacks have been called before or not.
  */
 /* static */ bool
 Promise::ThenableResolverCommon(JSContext* aCx, uint32_t aTask,
                                 unsigned aArgc, JS::Value* aVp)
 {
   JS::CallArgs args = CallArgsFromVp(aArgc, aVp);
   JS::Rooted<JSObject*> thisFunc(aCx, &args.callee());
   if (!MarkAsCalledIfNotCalledBefore(aCx, thisFunc)) {
     // A function from this pair has been called before.
+    args.rval().setUndefined();
     return true;
   }
 
   Promise* promise = GetPromise(aCx, thisFunc);
   MOZ_ASSERT(promise);
 
   if (aTask == PromiseCallback::Resolve) {
     promise->ResolveInternal(aCx, args.get(0));
   } else {
     promise->RejectInternal(aCx, args.get(0));
   }
+
+  args.rval().setUndefined();
   return true;
 }
 
 /* static */ bool
 Promise::JSCallbackThenableResolver(JSContext* aCx,
                                     unsigned aArgc, JS::Value* aVp)
 {
   return ThenableResolverCommon(aCx, PromiseCallback::Resolve, aArgc, aVp);
--- a/dom/promise/tests/mochitest.ini
+++ b/dom/promise/tests/mochitest.ini
@@ -1,7 +1,8 @@
 [DEFAULT]
 
+[test_abortable_promise.html]
 [test_bug883683.html]
 [test_promise.html]
 [test_promise_utils.html]
 [test_resolve.html]
-[test_abortable_promise.html]
+[test_resolver_return_value.html]
new file mode 100644
--- /dev/null
+++ b/dom/promise/tests/test_resolver_return_value.html
@@ -0,0 +1,40 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1120235
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1120235</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 1120235 **/
+  var res, rej;
+  var p = new Promise(function(resolve, reject) { res = resolve; rej = reject; });
+  ise(res(1), undefined, "Resolve function should return undefined");
+  ise(rej(2), undefined, "Reject function should return undefined");
+
+  var thenable = {
+    then: function(resolve, reject) {
+      ise(resolve(3), undefined, "Thenable resolve argument should return undefined");
+      ise(reject(4), undefined, "Thenable reject argument should return undefined");
+      SimpleTest.finish();
+    }
+  };
+
+  SimpleTest.waitForExplicitFinish();
+  p = Promise.resolve(thenable);
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1120235">Mozilla Bug 1120235</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>