OLD | NEW |
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 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 // For JSEntryStub frames we update the JS_ENTRY handler. | 1304 // For JSEntryStub frames we update the JS_ENTRY handler. |
1305 if (frame->is_entry() || frame->is_entry_construct()) { | 1305 if (frame->is_entry() || frame->is_entry_construct()) { |
1306 entry_handler = frame->top_handler()->next()->address(); | 1306 entry_handler = frame->top_handler()->next()->address(); |
1307 } | 1307 } |
1308 | 1308 |
1309 // For JavaScript frames we perform a lookup in the handler table. | 1309 // For JavaScript frames we perform a lookup in the handler table. |
1310 if (frame->is_java_script()) { | 1310 if (frame->is_java_script()) { |
1311 JavaScriptFrame* js_frame = static_cast<JavaScriptFrame*>(frame); | 1311 JavaScriptFrame* js_frame = static_cast<JavaScriptFrame*>(frame); |
1312 HandlerTable::CatchPrediction prediction = PredictException(js_frame); | 1312 HandlerTable::CatchPrediction prediction = PredictException(js_frame); |
1313 if (prediction == HandlerTable::DESUGARING) return CAUGHT_BY_DESUGARING; | 1313 if (prediction == HandlerTable::DESUGARING) return CAUGHT_BY_DESUGARING; |
| 1314 if (prediction == HandlerTable::ASYNC_AWAIT) return CAUGHT_BY_ASYNC_AWAIT; |
| 1315 if (prediction == HandlerTable::PROMISE) return CAUGHT_BY_PROMISE; |
1314 if (prediction != HandlerTable::UNCAUGHT) return CAUGHT_BY_JAVASCRIPT; | 1316 if (prediction != HandlerTable::UNCAUGHT) return CAUGHT_BY_JAVASCRIPT; |
1315 } | 1317 } |
1316 | 1318 |
1317 // The exception has been externally caught if and only if there is an | 1319 // The exception has been externally caught if and only if there is an |
1318 // external handler which is on top of the top-most JS_ENTRY handler. | 1320 // external handler which is on top of the top-most JS_ENTRY handler. |
1319 if (external_handler != nullptr && !try_catch_handler()->is_verbose_) { | 1321 if (external_handler != nullptr && !try_catch_handler()->is_verbose_) { |
1320 if (entry_handler == nullptr || entry_handler > external_handler) { | 1322 if (entry_handler == nullptr || entry_handler > external_handler) { |
1321 return CAUGHT_BY_EXTERNAL; | 1323 return CAUGHT_BY_EXTERNAL; |
1322 } | 1324 } |
1323 } | 1325 } |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 void Isolate::PopPromise() { | 1696 void Isolate::PopPromise() { |
1695 ThreadLocalTop* tltop = thread_local_top(); | 1697 ThreadLocalTop* tltop = thread_local_top(); |
1696 if (tltop->promise_on_stack_ == NULL) return; | 1698 if (tltop->promise_on_stack_ == NULL) return; |
1697 PromiseOnStack* prev = tltop->promise_on_stack_->prev(); | 1699 PromiseOnStack* prev = tltop->promise_on_stack_->prev(); |
1698 Handle<Object> global_promise = tltop->promise_on_stack_->promise(); | 1700 Handle<Object> global_promise = tltop->promise_on_stack_->promise(); |
1699 delete tltop->promise_on_stack_; | 1701 delete tltop->promise_on_stack_; |
1700 tltop->promise_on_stack_ = prev; | 1702 tltop->promise_on_stack_ = prev; |
1701 global_handles()->Destroy(global_promise.location()); | 1703 global_handles()->Destroy(global_promise.location()); |
1702 } | 1704 } |
1703 | 1705 |
| 1706 bool Isolate::PromiseHasUserDefinedRejectHandler(Handle<JSObject> 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, |
| 1710 Execution::Call(this, fun, promise, 0, NULL), |
| 1711 false); |
| 1712 return has_reject_handler->IsTrue(this); |
| 1713 } |
1704 | 1714 |
1705 Handle<Object> Isolate::GetPromiseOnStackOnThrow() { | 1715 Handle<Object> Isolate::GetPromiseOnStackOnThrow() { |
1706 Handle<Object> undefined = factory()->undefined_value(); | 1716 Handle<Object> undefined = factory()->undefined_value(); |
1707 ThreadLocalTop* tltop = thread_local_top(); | 1717 ThreadLocalTop* tltop = thread_local_top(); |
1708 if (tltop->promise_on_stack_ == NULL) return undefined; | 1718 if (tltop->promise_on_stack_ == NULL) return undefined; |
1709 // Find the top-most try-catch or try-finally handler. | 1719 // Find the top-most try-catch or try-finally handler. |
1710 CatchType prediction = PredictExceptionCatcher(); | 1720 CatchType prediction = PredictExceptionCatcher(); |
1711 if (prediction == NOT_CAUGHT || prediction == CAUGHT_BY_EXTERNAL) { | 1721 if (prediction == NOT_CAUGHT || prediction == CAUGHT_BY_EXTERNAL) { |
1712 return undefined; | 1722 return undefined; |
1713 } | 1723 } |
1714 for (JavaScriptFrameIterator it(this); !it.done(); it.Advance()) { | 1724 for (JavaScriptFrameIterator it(this); !it.done(); it.Advance()) { |
1715 switch (PredictException(it.frame())) { | 1725 switch (PredictException(it.frame())) { |
1716 case HandlerTable::UNCAUGHT: | 1726 case HandlerTable::UNCAUGHT: |
1717 break; | 1727 break; |
1718 case HandlerTable::CAUGHT: | 1728 case HandlerTable::CAUGHT: |
1719 case HandlerTable::DESUGARING: | 1729 case HandlerTable::DESUGARING: |
1720 return undefined; | 1730 return undefined; |
1721 case HandlerTable::PROMISE: | 1731 case HandlerTable::PROMISE: |
1722 return tltop->promise_on_stack_->promise(); | 1732 return tltop->promise_on_stack_->promise(); |
| 1733 case HandlerTable::ASYNC_AWAIT: { |
| 1734 // If in an async/await, pop up successive async/await stack frames |
| 1735 // until an asynchronous one with dependents is found, or a non-async |
| 1736 // stack frame is encountered, in order to handle the synchronous |
| 1737 // async/await catch prediction case: assume that async function calls |
| 1738 // are awaited. |
| 1739 PromiseOnStack* promise_on_stack = tltop->promise_on_stack_; |
| 1740 for (it.Advance(); !it.done(); it.Advance()) { |
| 1741 if (PromiseHasUserDefinedRejectHandler(promise_on_stack->promise())) { |
| 1742 break; |
| 1743 } |
| 1744 JavaScriptFrame* frame = it.frame(); |
| 1745 if (!frame->function()->shared()->is_async()) { |
| 1746 // Keep searching up the stack until an async function stack frame |
| 1747 // is found, heuristically assuming that that will ultimately await |
| 1748 // whatever is going on here. |
| 1749 continue; |
| 1750 } |
| 1751 PromiseOnStack* next_promise_on_stack = promise_on_stack->prev(); |
| 1752 if (next_promise_on_stack == nullptr) break; |
| 1753 switch (PredictException(it.frame())) { |
| 1754 case HandlerTable::CAUGHT: |
| 1755 case HandlerTable::DESUGARING: { |
| 1756 // Mark the inner promise as caught in the "synchronous case" so |
| 1757 // that Debug::OnException will see. |
| 1758 Handle<Symbol> key = factory()->promise_handled_hint_symbol(); |
| 1759 JSObject::SetProperty(promise_on_stack->promise(), key, key, |
| 1760 STRICT) |
| 1761 .Assert(); |
| 1762 return promise_on_stack->promise(); |
| 1763 } |
| 1764 case HandlerTable::ASYNC_AWAIT: |
| 1765 promise_on_stack = next_promise_on_stack; |
| 1766 continue; |
| 1767 case HandlerTable::PROMISE: |
| 1768 case HandlerTable::UNCAUGHT: |
| 1769 UNREACHABLE(); |
| 1770 } |
| 1771 } |
| 1772 return promise_on_stack->promise(); |
| 1773 } |
1723 } | 1774 } |
1724 } | 1775 } |
1725 return undefined; | 1776 return undefined; |
1726 } | 1777 } |
1727 | 1778 |
1728 | 1779 |
1729 void Isolate::SetCaptureStackTraceForUncaughtExceptions( | 1780 void Isolate::SetCaptureStackTraceForUncaughtExceptions( |
1730 bool capture, | 1781 bool capture, |
1731 int frame_limit, | 1782 int frame_limit, |
1732 StackTrace::StackTraceOptions options) { | 1783 StackTrace::StackTraceOptions options) { |
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3162 // Then check whether this scope intercepts. | 3213 // Then check whether this scope intercepts. |
3163 if ((flag & intercept_mask_)) { | 3214 if ((flag & intercept_mask_)) { |
3164 intercepted_flags_ |= flag; | 3215 intercepted_flags_ |= flag; |
3165 return true; | 3216 return true; |
3166 } | 3217 } |
3167 return false; | 3218 return false; |
3168 } | 3219 } |
3169 | 3220 |
3170 } // namespace internal | 3221 } // namespace internal |
3171 } // namespace v8 | 3222 } // namespace v8 |
OLD | NEW |