| Index: src/isolate.cc
|
| diff --git a/src/isolate.cc b/src/isolate.cc
|
| index 1b96583cb093cd44eb2022945e59b2a6bc185322..b9c35b7fae1abc8f9c874f604a5d547b1ace8b03 100644
|
| --- a/src/isolate.cc
|
| +++ b/src/isolate.cc
|
| @@ -1703,29 +1703,59 @@ void Isolate::PopPromise() {
|
| global_handles()->Destroy(global_promise.location());
|
| }
|
|
|
| +bool Isolate::PromiseHasUserDefinedRejectHandler(Handle<Object> promise) {
|
| + Handle<JSFunction> fun = promise_has_user_defined_reject_handler();
|
| + Handle<Object> has_reject_handler;
|
| + ASSIGN_RETURN_ON_EXCEPTION_VALUE(this, has_reject_handler,
|
| + Execution::Call(this, fun, promise, 0, NULL),
|
| + false);
|
| + return has_reject_handler->IsTrue(this);
|
| +}
|
|
|
| Handle<Object> Isolate::GetPromiseOnStackOnThrow() {
|
| - Handle<Object> undefined = factory()->undefined_value();
|
| + Handle<Object> retval = factory()->undefined_value();
|
| ThreadLocalTop* tltop = thread_local_top();
|
| - if (tltop->promise_on_stack_ == NULL) return undefined;
|
| + if (tltop->promise_on_stack_ == NULL) return retval;
|
| // Find the top-most try-catch or try-finally handler.
|
| CatchType prediction = PredictExceptionCatcher();
|
| if (prediction == NOT_CAUGHT || prediction == CAUGHT_BY_EXTERNAL) {
|
| - return undefined;
|
| + return retval;
|
| }
|
| + PromiseOnStack* promise_on_stack = tltop->promise_on_stack_;
|
| for (JavaScriptFrameIterator it(this); !it.done(); it.Advance()) {
|
| switch (PredictException(it.frame())) {
|
| case HandlerTable::UNCAUGHT:
|
| - case HandlerTable::ASYNC_AWAIT:
|
| - break;
|
| + continue;
|
| case HandlerTable::CAUGHT:
|
| case HandlerTable::DESUGARING:
|
| - return undefined;
|
| + if (retval->IsJSObject()) {
|
| + // Caught the result of an inner async/await invocation.
|
| + // Mark the inner promise as caught in the "synchronous case" so
|
| + // that Debug::OnException will see.
|
| + Handle<Symbol> key = factory()->promise_handled_hint_symbol();
|
| + JSObject::SetProperty(Handle<JSObject>::cast(retval), key,
|
| + factory()->true_value(), STRICT)
|
| + .Assert();
|
| + }
|
| + return retval;
|
| case HandlerTable::PROMISE:
|
| - return tltop->promise_on_stack_->promise();
|
| + return promise_on_stack->promise();
|
| + case HandlerTable::ASYNC_AWAIT: {
|
| + // If in the initial portion of async/await, continue the loop to pop up
|
| + // successive async/await stack frames until an asynchronous one with
|
| + // dependents is found, or a non-async stack frame is encountered, in
|
| + // order to handle the synchronous async/await catch prediction case:
|
| + // assume that async function calls are awaited.
|
| + retval = promise_on_stack->promise();
|
| + if (PromiseHasUserDefinedRejectHandler(retval)) {
|
| + return retval;
|
| + }
|
| + promise_on_stack = promise_on_stack->prev();
|
| + continue;
|
| + }
|
| }
|
| }
|
| - return undefined;
|
| + return retval;
|
| }
|
|
|
|
|
|
|