Bug 1539132 - Part 4: Remove unused return-value parameter from promise-reaction job functions. r=arai
authorAndré Bargull <andre.bargull@gmail.com>
Wed, 03 Apr 2019 20:02:30 +0000
changeset 467944 ef5b0d01d900190f3fcad092cba34c7d1e0dda5b
parent 467943 33a0651129668ca0ef3749cb66e68560d6555c32
child 467945 201c7691d719efc9b544018197c7b43b3a49ca1f
push id35813
push useraiakab@mozilla.com
push dateThu, 04 Apr 2019 16:07:30 +0000
treeherdermozilla-central@aa623df2ae8f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1539132
milestone68.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 1539132 - Part 4: Remove unused return-value parameter from promise-reaction job functions. r=arai Differential Revision: https://phabricator.services.mozilla.com/D25572
js/src/builtin/Promise.cpp
--- a/js/src/builtin/Promise.cpp
+++ b/js/src/builtin/Promise.cpp
@@ -1429,18 +1429,17 @@ static MOZ_MUST_USE bool TriggerPromiseR
 
   return true;
 }
 
 // Implements PromiseReactionJob optimized for the case when the reaction
 // handler is one of the default resolving functions as created by the
 // CreateResolvingFunctions abstract operation.
 static MOZ_MUST_USE bool DefaultResolvingPromiseReactionJob(
-    JSContext* cx, Handle<PromiseReactionRecord*> reaction,
-    MutableHandleValue rval) {
+    JSContext* cx, Handle<PromiseReactionRecord*> reaction) {
   MOZ_ASSERT(reaction->targetState() != JS::PromiseState::Pending);
 
   Rooted<PromiseObject*> promiseToResolve(cx,
                                           reaction->defaultResolvingPromise());
 
   // Testing functions allow to directly settle a promise without going
   // through the resolving functions. In that case the normal bookkeeping to
   // ensure only pending promises can be resolved doesn't apply and we need
@@ -1467,110 +1466,107 @@ static MOZ_MUST_USE bool DefaultResolvin
     }
   }
 
   // Steps 7-9.
   uint32_t hookSlot = resolutionMode == RejectMode ? ReactionRecordSlot_Reject
                                                    : ReactionRecordSlot_Resolve;
   RootedObject callee(cx, reaction->getFixedSlot(hookSlot).toObjectOrNull());
   RootedObject promiseObj(cx, reaction->promise());
-  if (!RunResolutionFunction(cx, callee, handlerResult, resolutionMode,
-                             promiseObj)) {
-    return false;
-  }
-
-  rval.setUndefined();
-  return true;
+  return RunResolutionFunction(cx, callee, handlerResult, resolutionMode,
+                               promiseObj);
 }
 
 static MOZ_MUST_USE bool AsyncFunctionPromiseReactionJob(
-    JSContext* cx, Handle<PromiseReactionRecord*> reaction,
-    MutableHandleValue rval) {
+    JSContext* cx, Handle<PromiseReactionRecord*> reaction) {
   MOZ_ASSERT(reaction->isAsyncFunction());
 
-  RootedValue handlerVal(cx, reaction->handler());
+  int32_t handler = reaction->handler().toInt32();
   RootedValue argument(cx, reaction->handlerArg());
   Rooted<AsyncFunctionGeneratorObject*> generator(
       cx, reaction->asyncFunctionGenerator());
 
-  int32_t handlerNum = handlerVal.toInt32();
-
-  // Await's handlers don't return a value, nor throw an exception.
+  // Await's handlers don't return a value, nor throw any exceptions.
   // They fail only on OOM.
-  if (handlerNum == PromiseHandlerAsyncFunctionAwaitedFulfilled) {
-    if (!AsyncFunctionAwaitedFulfilled(cx, generator, argument)) {
-      return false;
-    }
-  } else {
-    MOZ_ASSERT(handlerNum == PromiseHandlerAsyncFunctionAwaitedRejected);
-    if (!AsyncFunctionAwaitedRejected(cx, generator, argument)) {
-      return false;
-    }
-  }
-
-  rval.setUndefined();
-  return true;
+
+  if (handler == PromiseHandlerAsyncFunctionAwaitedFulfilled) {
+    return AsyncFunctionAwaitedFulfilled(cx, generator, argument);
+  }
+
+  MOZ_ASSERT(handler == PromiseHandlerAsyncFunctionAwaitedRejected);
+  return AsyncFunctionAwaitedRejected(cx, generator, argument);
 }
 
 static MOZ_MUST_USE bool AsyncGeneratorPromiseReactionJob(
-    JSContext* cx, Handle<PromiseReactionRecord*> reaction,
-    MutableHandleValue rval) {
+    JSContext* cx, Handle<PromiseReactionRecord*> reaction) {
   MOZ_ASSERT(reaction->isAsyncGenerator());
 
-  RootedValue handlerVal(cx, reaction->handler());
+  int32_t handler = reaction->handler().toInt32();
   RootedValue argument(cx, reaction->handlerArg());
   Rooted<AsyncGeneratorObject*> asyncGenObj(cx, reaction->asyncGenerator());
 
-  int32_t handlerNum = handlerVal.toInt32();
-
-  // Await's handlers don't return a value, nor throw exception.
+  // Await's handlers don't return a value, nor throw any exceptions.
   // They fail only on OOM.
-  if (handlerNum == PromiseHandlerAsyncGeneratorAwaitedFulfilled) {
-    // 4.1.1.
-    if (!AsyncGeneratorAwaitedFulfilled(cx, asyncGenObj, argument)) {
-      return false;
+
+  switch (handler) {
+    // ES2020 draft rev a09fc232c137800dbf51b6204f37fdede4ba1646
+    // 6.2.3.1.1 Await Fulfilled Functions
+    case PromiseHandlerAsyncGeneratorAwaitedFulfilled: {
+      return AsyncGeneratorAwaitedFulfilled(cx, asyncGenObj, argument);
     }
-  } else if (handlerNum == PromiseHandlerAsyncGeneratorAwaitedRejected) {
-    // 4.1.2.
-    if (!AsyncGeneratorAwaitedRejected(cx, asyncGenObj, argument)) {
-      return false;
+
+    // ES2020 draft rev a09fc232c137800dbf51b6204f37fdede4ba1646
+    // 6.2.3.1.2 Await Rejected Functions
+    case PromiseHandlerAsyncGeneratorAwaitedRejected: {
+      return AsyncGeneratorAwaitedRejected(cx, asyncGenObj, argument);
     }
-  } else if (handlerNum ==
-             PromiseHandlerAsyncGeneratorResumeNextReturnFulfilled) {
-    asyncGenObj->setCompleted();
-    // 11.4.3.5.1 step 1.
-    if (!AsyncGeneratorResolve(cx, asyncGenObj, argument, true)) {
-      return false;
+
+    // ES2020 draft rev a09fc232c137800dbf51b6204f37fdede4ba1646
+    // 25.5.3.5.1 AsyncGeneratorResumeNext Return Processor Fulfilled Functions
+    case PromiseHandlerAsyncGeneratorResumeNextReturnFulfilled: {
+      // Steps 1-2.
+      asyncGenObj->setCompleted();
+
+      // Step 3.
+      return AsyncGeneratorResolve(cx, asyncGenObj, argument, true);
     }
-  } else if (handlerNum ==
-             PromiseHandlerAsyncGeneratorResumeNextReturnRejected) {
-    asyncGenObj->setCompleted();
-    // 11.4.3.5.2 step 1.
-    if (!AsyncGeneratorReject(cx, asyncGenObj, argument)) {
-      return false;
+
+    // ES2020 draft rev a09fc232c137800dbf51b6204f37fdede4ba1646
+    // 25.5.3.5.2 AsyncGeneratorResumeNext Return Processor Rejected Functions
+    case PromiseHandlerAsyncGeneratorResumeNextReturnRejected: {
+      // Steps 1-2.
+      asyncGenObj->setCompleted();
+
+      // Step 3.
+      return AsyncGeneratorReject(cx, asyncGenObj, argument);
     }
-  } else if (handlerNum ==
-             PromiseHandlerAsyncGeneratorYieldReturnAwaitedFulfilled) {
-    asyncGenObj->setExecuting();
-    // 11.4.3.7 steps 8.d-e.
-    if (!AsyncGeneratorYieldReturnAwaitedFulfilled(cx, asyncGenObj, argument)) {
-      return false;
+
+    // ES2020 draft rev a09fc232c137800dbf51b6204f37fdede4ba1646
+    // 25.5.3.7 AsyncGeneratorYield
+    case PromiseHandlerAsyncGeneratorYieldReturnAwaitedFulfilled: {
+      asyncGenObj->setExecuting();
+
+      // Steps 8.d-e.
+      return AsyncGeneratorYieldReturnAwaitedFulfilled(cx, asyncGenObj,
+                                                       argument);
     }
-  } else {
-    MOZ_ASSERT(handlerNum ==
-               PromiseHandlerAsyncGeneratorYieldReturnAwaitedRejected);
-    asyncGenObj->setExecuting();
-    // 11.4.3.7 step 8.c.
-    if (!AsyncGeneratorYieldReturnAwaitedRejected(cx, asyncGenObj, argument)) {
-      return false;
+
+    // ES2020 draft rev a09fc232c137800dbf51b6204f37fdede4ba1646
+    // 25.5.3.7 AsyncGeneratorYield
+    case PromiseHandlerAsyncGeneratorYieldReturnAwaitedRejected: {
+      asyncGenObj->setExecuting();
+
+      // Step 8.c.
+      return AsyncGeneratorYieldReturnAwaitedRejected(cx, asyncGenObj,
+                                                      argument);
     }
-  }
-
-  rval.setUndefined();
-  return true;
+
+    default:
+      MOZ_CRASH("Bad handler in AsyncGeneratorPromiseReactionJob");
+  }
 }
 
 // ES2016, 25.4.2.1.
 /**
  * Callback triggering the fulfill/reject reaction for a resolved Promise,
  * to be invoked by the embedding during its processing of the Promise job
  * queue.
  *
@@ -1581,16 +1577,19 @@ static MOZ_MUST_USE bool AsyncGeneratorP
  * JSFunction object, with all information required for the job's
  * execution stored in in a reaction record in its first extended slot.
  */
 static bool PromiseReactionJob(JSContext* cx, unsigned argc, Value* vp) {
   CallArgs args = CallArgsFromVp(argc, vp);
 
   RootedFunction job(cx, &args.callee().as<JSFunction>());
 
+  // Promise reactions don't return any value.
+  args.rval().setUndefined();
+
   RootedObject reactionObj(
       cx, &job->getExtendedSlot(ReactionJobSlot_ReactionRecord).toObject());
 
   // To ensure that the embedding ends up with the right entry global, we're
   // guaranteeing that the reaction job function gets created in the same
   // compartment as the handler function. That's not necessarily the global
   // that the job was triggered from, though.
   // We can find the triggering global via the job's reaction record. To go
@@ -1609,23 +1608,23 @@ static bool PromiseReactionJob(JSContext
     MOZ_RELEASE_ASSERT(reactionObj->is<PromiseReactionRecord>());
     ar.emplace(cx, reactionObj);
   }
 
   // Steps 1-2.
   Handle<PromiseReactionRecord*> reaction =
       reactionObj.as<PromiseReactionRecord>();
   if (reaction->isDefaultResolvingHandler()) {
-    return DefaultResolvingPromiseReactionJob(cx, reaction, args.rval());
+    return DefaultResolvingPromiseReactionJob(cx, reaction);
   }
   if (reaction->isAsyncFunction()) {
-    return AsyncFunctionPromiseReactionJob(cx, reaction, args.rval());
+    return AsyncFunctionPromiseReactionJob(cx, reaction);
   }
   if (reaction->isAsyncGenerator()) {
-    return AsyncGeneratorPromiseReactionJob(cx, reaction, args.rval());
+    return AsyncGeneratorPromiseReactionJob(cx, reaction);
   }
   if (reaction->isDebuggerDummy()) {
     return true;
   }
 
   // Step 3.
   RootedValue handlerVal(cx, reaction->handler());
 
@@ -1673,23 +1672,18 @@ static bool PromiseReactionJob(JSContext
     }
   }
 
   // Steps 7-9.
   uint32_t hookSlot = resolutionMode == RejectMode ? ReactionRecordSlot_Reject
                                                    : ReactionRecordSlot_Resolve;
   RootedObject callee(cx, reaction->getFixedSlot(hookSlot).toObjectOrNull());
   RootedObject promiseObj(cx, reaction->promise());
-  if (!RunResolutionFunction(cx, callee, handlerResult, resolutionMode,
-                             promiseObj)) {
-    return false;
-  }
-
-  args.rval().setUndefined();
-  return true;
+  return RunResolutionFunction(cx, callee, handlerResult, resolutionMode,
+                               promiseObj);
 }
 
 // ES2016, 25.4.2.2.
 /**
  * Callback for resolving a thenable, to be invoked by the embedding during
  * its processing of the Promise job queue.
  *
  * See https://tc39.github.io/ecma262/#sec-jobs-and-job-queues