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

Side by Side Diff: src/isolate.cc

Issue 2325813002: Async/await catch prediction for "the synchronous case" (Closed)
Patch Set: TryCall 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
« no previous file with comments | « src/isolate.h ('k') | src/runtime/runtime-internal.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 if (Execution::TryCall(this, fun, promise, 0, NULL)
1710 .ToHandle(&has_reject_handler)) {
1711 return has_reject_handler->IsTrue(this);
1712 }
1713 // If an exception is thrown in the course of execution of this built-in
1714 // function, it indicates either a bug, or a synthetic uncatchable
1715 // exception in the shutdown path. In either case, it's OK to predict either
1716 // way in DevTools.
1717 return false;
1718 }
1706 1719
1707 Handle<Object> Isolate::GetPromiseOnStackOnThrow() { 1720 Handle<Object> Isolate::GetPromiseOnStackOnThrow() {
1708 Handle<Object> undefined = factory()->undefined_value(); 1721 Handle<Object> undefined = factory()->undefined_value();
1709 ThreadLocalTop* tltop = thread_local_top(); 1722 ThreadLocalTop* tltop = thread_local_top();
1710 if (tltop->promise_on_stack_ == NULL) return undefined; 1723 if (tltop->promise_on_stack_ == NULL) return undefined;
1711 // Find the top-most try-catch or try-finally handler. 1724 // Find the top-most try-catch or try-finally handler.
1712 CatchType prediction = PredictExceptionCatcher(); 1725 CatchType prediction = PredictExceptionCatcher();
1713 if (prediction == NOT_CAUGHT || prediction == CAUGHT_BY_EXTERNAL) { 1726 if (prediction == NOT_CAUGHT || prediction == CAUGHT_BY_EXTERNAL) {
1714 return undefined; 1727 return undefined;
1715 } 1728 }
1729 Handle<Object> retval = undefined;
1730 PromiseOnStack* promise_on_stack = tltop->promise_on_stack_;
1716 for (JavaScriptFrameIterator it(this); !it.done(); it.Advance()) { 1731 for (JavaScriptFrameIterator it(this); !it.done(); it.Advance()) {
1717 switch (PredictException(it.frame())) { 1732 switch (PredictException(it.frame())) {
1718 case HandlerTable::UNCAUGHT: 1733 case HandlerTable::UNCAUGHT:
1719 case HandlerTable::ASYNC_AWAIT: 1734 continue;
1720 break;
1721 case HandlerTable::CAUGHT: 1735 case HandlerTable::CAUGHT:
1722 case HandlerTable::DESUGARING: 1736 case HandlerTable::DESUGARING:
1723 return undefined; 1737 if (retval->IsJSObject()) {
1738 // Caught the result of an inner async/await invocation.
1739 // Mark the inner promise as caught in the "synchronous case" so
1740 // that Debug::OnException will see. In the synchronous case,
1741 // namely in the code in an async function before the first
1742 // await, the function which has this exception event has not yet
1743 // returned, so the generated Promise has not yet been marked
1744 // by AsyncFunctionAwaitCaught with promiseHandledHintSymbol.
1745 Handle<Symbol> key = factory()->promise_handled_hint_symbol();
1746 JSObject::SetProperty(Handle<JSObject>::cast(retval), key,
1747 factory()->true_value(), STRICT)
1748 .Assert();
1749 }
1750 return retval;
1724 case HandlerTable::PROMISE: 1751 case HandlerTable::PROMISE:
1725 return tltop->promise_on_stack_->promise(); 1752 return promise_on_stack->promise();
1753 case HandlerTable::ASYNC_AWAIT: {
1754 // If in the initial portion of async/await, continue the loop to pop up
1755 // successive async/await stack frames until an asynchronous one with
1756 // dependents is found, or a non-async stack frame is encountered, in
1757 // order to handle the synchronous async/await catch prediction case:
1758 // assume that async function calls are awaited.
1759 retval = promise_on_stack->promise();
1760 if (PromiseHasUserDefinedRejectHandler(retval)) {
1761 return retval;
1762 }
1763 promise_on_stack = promise_on_stack->prev();
1764 continue;
1765 }
1726 } 1766 }
1727 } 1767 }
1728 return undefined; 1768 return retval;
1729 } 1769 }
1730 1770
1731 1771
1732 void Isolate::SetCaptureStackTraceForUncaughtExceptions( 1772 void Isolate::SetCaptureStackTraceForUncaughtExceptions(
1733 bool capture, 1773 bool capture,
1734 int frame_limit, 1774 int frame_limit,
1735 StackTrace::StackTraceOptions options) { 1775 StackTrace::StackTraceOptions options) {
1736 capture_stack_trace_for_uncaught_exceptions_ = capture; 1776 capture_stack_trace_for_uncaught_exceptions_ = capture;
1737 stack_trace_for_uncaught_exceptions_frame_limit_ = frame_limit; 1777 stack_trace_for_uncaught_exceptions_frame_limit_ = frame_limit;
1738 stack_trace_for_uncaught_exceptions_options_ = options; 1778 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. 3206 // Then check whether this scope intercepts.
3167 if ((flag & intercept_mask_)) { 3207 if ((flag & intercept_mask_)) {
3168 intercepted_flags_ |= flag; 3208 intercepted_flags_ |= flag;
3169 return true; 3209 return true;
3170 } 3210 }
3171 return false; 3211 return false;
3172 } 3212 }
3173 3213
3174 } // namespace internal 3214 } // namespace internal
3175 } // namespace v8 3215 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/runtime/runtime-internal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698