Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/isolate.cc

Issue 2325813002: Async/await catch prediction for "the synchronous case" (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/isolate.h" 5 #include "src/isolate.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <fstream> // NOLINT(readability/streams) 9 #include <fstream> // NOLINT(readability/streams)
10 #include <sstream> 10 #include <sstream>
(...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after
1696 void Isolate::PopPromise() { 1696 void Isolate::PopPromise() {
1697 ThreadLocalTop* tltop = thread_local_top(); 1697 ThreadLocalTop* tltop = thread_local_top();
1698 if (tltop->promise_on_stack_ == NULL) return; 1698 if (tltop->promise_on_stack_ == NULL) return;
1699 PromiseOnStack* prev = tltop->promise_on_stack_->prev(); 1699 PromiseOnStack* prev = tltop->promise_on_stack_->prev();
1700 Handle<Object> global_promise = tltop->promise_on_stack_->promise(); 1700 Handle<Object> global_promise = tltop->promise_on_stack_->promise();
1701 delete tltop->promise_on_stack_; 1701 delete tltop->promise_on_stack_;
1702 tltop->promise_on_stack_ = prev; 1702 tltop->promise_on_stack_ = prev;
1703 global_handles()->Destroy(global_promise.location()); 1703 global_handles()->Destroy(global_promise.location());
1704 } 1704 }
1705 1705
1706 bool Isolate::PromiseHasUserDefinedRejectHandler(Handle<Object> promise) {
1707 Handle<JSFunction> fun = promise_has_user_defined_reject_handler();
1708 Handle<Object> has_reject_handler;
1709 ASSIGN_RETURN_ON_EXCEPTION_VALUE(this, has_reject_handler,
jgruber 2016/09/12 10:27:31 We need to handle thrown exceptions, either by cle
Dan Ehrenberg 2016/09/12 22:12:11 I think it's OK to handle the exceptions like this
jgruber 2016/09/13 08:17:20 If we don't care about any thrown exceptions in pr
Dan Ehrenberg 2016/09/13 22:34:55 Done
adamk 2016/09/15 00:11:07 Would Execution::TryCall() work instead of calling
Dan Ehrenberg 2016/09/15 00:37:40 Done
1710 Execution::Call(this, fun, promise, 0, NULL),
1711 false);
1712 return has_reject_handler->IsTrue(this);
1713 }
1706 1714
1707 Handle<Object> Isolate::GetPromiseOnStackOnThrow() { 1715 Handle<Object> Isolate::GetPromiseOnStackOnThrow() {
1708 Handle<Object> undefined = factory()->undefined_value(); 1716 Handle<Object> retval = factory()->undefined_value();
1709 ThreadLocalTop* tltop = thread_local_top(); 1717 ThreadLocalTop* tltop = thread_local_top();
1710 if (tltop->promise_on_stack_ == NULL) return undefined; 1718 if (tltop->promise_on_stack_ == NULL) return retval;
kozy 2016/09/12 18:13:56 Can we return factory()->undefined_value() here..
Dan Ehrenberg 2016/09/12 22:12:11 Done
1711 // Find the top-most try-catch or try-finally handler. 1719 // Find the top-most try-catch or try-finally handler.
1712 CatchType prediction = PredictExceptionCatcher(); 1720 CatchType prediction = PredictExceptionCatcher();
1713 if (prediction == NOT_CAUGHT || prediction == CAUGHT_BY_EXTERNAL) { 1721 if (prediction == NOT_CAUGHT || prediction == CAUGHT_BY_EXTERNAL) {
1714 return undefined; 1722 return retval;
kozy 2016/09/12 18:13:56 ..and here, and then introduce retval variable.
Dan Ehrenberg 2016/09/12 22:12:11 Done
1715 } 1723 }
1724 PromiseOnStack* promise_on_stack = tltop->promise_on_stack_;
1716 for (JavaScriptFrameIterator it(this); !it.done(); it.Advance()) { 1725 for (JavaScriptFrameIterator it(this); !it.done(); it.Advance()) {
1717 switch (PredictException(it.frame())) { 1726 switch (PredictException(it.frame())) {
1718 case HandlerTable::UNCAUGHT: 1727 case HandlerTable::UNCAUGHT:
1719 case HandlerTable::ASYNC_AWAIT: 1728 continue;
1720 break;
1721 case HandlerTable::CAUGHT: 1729 case HandlerTable::CAUGHT:
1722 case HandlerTable::DESUGARING: 1730 case HandlerTable::DESUGARING:
1723 return undefined; 1731 if (retval->IsJSObject()) {
jgruber 2016/09/12 10:27:31 Would a DCHECK(retval->IsJSPromise()) work here?
Dan Ehrenberg 2016/09/12 22:12:11 No, as this may be occurring in a case that has no
jgruber 2016/09/13 08:17:20 I meant if (retval->IsJSObject()) { DCHECK(ret
Dan Ehrenberg 2016/09/13 22:34:55 Done
1732 // Caught the result of an inner async/await invocation.
1733 // Mark the inner promise as caught in the "synchronous case" so
1734 // that Debug::OnException will see.
1735 Handle<Symbol> key = factory()->promise_handled_hint_symbol();
jgruber 2016/09/12 10:27:31 Which case is this so that the promise isn't marke
Dan Ehrenberg 2016/09/12 22:12:11 I added more comment text to try to explain. This
1736 JSObject::SetProperty(Handle<JSObject>::cast(retval), key,
1737 factory()->true_value(), STRICT)
1738 .Assert();
1739 }
1740 return retval;
1724 case HandlerTable::PROMISE: 1741 case HandlerTable::PROMISE:
1725 return tltop->promise_on_stack_->promise(); 1742 return promise_on_stack->promise();
1743 case HandlerTable::ASYNC_AWAIT: {
1744 // If in the initial portion of async/await, continue the loop to pop up
1745 // successive async/await stack frames until an asynchronous one with
1746 // dependents is found, or a non-async stack frame is encountered, in
1747 // order to handle the synchronous async/await catch prediction case:
1748 // assume that async function calls are awaited.
1749 retval = promise_on_stack->promise();
1750 if (PromiseHasUserDefinedRejectHandler(retval)) {
1751 return retval;
1752 }
1753 promise_on_stack = promise_on_stack->prev();
1754 continue;
1755 }
1726 } 1756 }
1727 } 1757 }
1728 return undefined; 1758 return retval;
1729 } 1759 }
1730 1760
1731 1761
1732 void Isolate::SetCaptureStackTraceForUncaughtExceptions( 1762 void Isolate::SetCaptureStackTraceForUncaughtExceptions(
1733 bool capture, 1763 bool capture,
1734 int frame_limit, 1764 int frame_limit,
1735 StackTrace::StackTraceOptions options) { 1765 StackTrace::StackTraceOptions options) {
1736 capture_stack_trace_for_uncaught_exceptions_ = capture; 1766 capture_stack_trace_for_uncaught_exceptions_ = capture;
1737 stack_trace_for_uncaught_exceptions_frame_limit_ = frame_limit; 1767 stack_trace_for_uncaught_exceptions_frame_limit_ = frame_limit;
1738 stack_trace_for_uncaught_exceptions_options_ = options; 1768 stack_trace_for_uncaught_exceptions_options_ = options;
(...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after
3166 // Then check whether this scope intercepts. 3196 // Then check whether this scope intercepts.
3167 if ((flag & intercept_mask_)) { 3197 if ((flag & intercept_mask_)) {
3168 intercepted_flags_ |= flag; 3198 intercepted_flags_ |= flag;
3169 return true; 3199 return true;
3170 } 3200 }
3171 return false; 3201 return false;
3172 } 3202 }
3173 3203
3174 } // namespace internal 3204 } // namespace internal
3175 } // namespace v8 3205 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/runtime/runtime-internal.cc » ('j') | src/runtime/runtime-internal.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698