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

Side by Side Diff: src/isolate.cc

Issue 2161263003: [debug] use catch prediction flag for promise rejections. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 entry_handler = frame->top_handler()->next()->address(); 1271 entry_handler = frame->top_handler()->next()->address();
1272 } 1272 }
1273 1273
1274 // For JavaScript frames we perform a lookup in the handler table. 1274 // For JavaScript frames we perform a lookup in the handler table.
1275 if (frame->is_java_script()) { 1275 if (frame->is_java_script()) {
1276 JavaScriptFrame* js_frame = static_cast<JavaScriptFrame*>(frame); 1276 JavaScriptFrame* js_frame = static_cast<JavaScriptFrame*>(frame);
1277 HandlerTable::CatchPrediction prediction; 1277 HandlerTable::CatchPrediction prediction;
1278 if (js_frame->LookupExceptionHandlerInTable(nullptr, &prediction) > 0) { 1278 if (js_frame->LookupExceptionHandlerInTable(nullptr, &prediction) > 0) {
1279 // We are conservative with our prediction: try-finally is considered 1279 // We are conservative with our prediction: try-finally is considered
1280 // to always rethrow, to meet the expectation of the debugger. 1280 // to always rethrow, to meet the expectation of the debugger.
1281 if (prediction == HandlerTable::CAUGHT) return CAUGHT_BY_JAVASCRIPT; 1281 if (prediction != HandlerTable::UNCAUGHT) return CAUGHT_BY_JAVASCRIPT;
Dan Ehrenberg 2016/07/21 21:07:33 This is big--it deserves a comment mentioning the
Dan Ehrenberg 2016/07/21 21:08:51 Sorry, please ignore this comment; I wrote it whil
1282 } 1282 }
1283 } 1283 }
1284 1284
1285 // The exception has been externally caught if and only if there is an 1285 // The exception has been externally caught if and only if there is an
1286 // external handler which is on top of the top-most JS_ENTRY handler. 1286 // external handler which is on top of the top-most JS_ENTRY handler.
1287 if (external_handler != nullptr && !try_catch_handler()->is_verbose_) { 1287 if (external_handler != nullptr && !try_catch_handler()->is_verbose_) {
1288 if (entry_handler == nullptr || entry_handler > external_handler) { 1288 if (entry_handler == nullptr || entry_handler > external_handler) {
1289 return CAUGHT_BY_EXTERNAL; 1289 return CAUGHT_BY_EXTERNAL;
1290 } 1290 }
1291 } 1291 }
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 clear_pending_exception(); 1656 clear_pending_exception();
1657 return false; 1657 return false;
1658 } 1658 }
1659 1659
1660 // Reschedule the exception. 1660 // Reschedule the exception.
1661 thread_local_top()->scheduled_exception_ = pending_exception(); 1661 thread_local_top()->scheduled_exception_ = pending_exception();
1662 clear_pending_exception(); 1662 clear_pending_exception();
1663 return true; 1663 return true;
1664 } 1664 }
1665 1665
1666 1666 void Isolate::PushPromise(Handle<JSObject> promise) {
1667 void Isolate::PushPromise(Handle<JSObject> promise,
1668 Handle<JSFunction> function) {
1669 ThreadLocalTop* tltop = thread_local_top(); 1667 ThreadLocalTop* tltop = thread_local_top();
1670 PromiseOnStack* prev = tltop->promise_on_stack_; 1668 PromiseOnStack* prev = tltop->promise_on_stack_;
1671 Handle<JSObject> global_promise = 1669 Handle<JSObject> global_promise =
1672 Handle<JSObject>::cast(global_handles()->Create(*promise)); 1670 Handle<JSObject>::cast(global_handles()->Create(*promise));
1673 Handle<JSFunction> global_function = 1671 tltop->promise_on_stack_ = new PromiseOnStack(global_promise, prev);
1674 Handle<JSFunction>::cast(global_handles()->Create(*function));
1675 tltop->promise_on_stack_ =
1676 new PromiseOnStack(global_function, global_promise, prev);
1677 } 1672 }
1678 1673
1679 1674
1680 void Isolate::PopPromise() { 1675 void Isolate::PopPromise() {
1681 ThreadLocalTop* tltop = thread_local_top(); 1676 ThreadLocalTop* tltop = thread_local_top();
1682 if (tltop->promise_on_stack_ == NULL) return; 1677 if (tltop->promise_on_stack_ == NULL) return;
1683 PromiseOnStack* prev = tltop->promise_on_stack_->prev(); 1678 PromiseOnStack* prev = tltop->promise_on_stack_->prev();
1684 Handle<Object> global_function = tltop->promise_on_stack_->function();
1685 Handle<Object> global_promise = tltop->promise_on_stack_->promise(); 1679 Handle<Object> global_promise = tltop->promise_on_stack_->promise();
1686 delete tltop->promise_on_stack_; 1680 delete tltop->promise_on_stack_;
1687 tltop->promise_on_stack_ = prev; 1681 tltop->promise_on_stack_ = prev;
1688 global_handles()->Destroy(global_function.location());
1689 global_handles()->Destroy(global_promise.location()); 1682 global_handles()->Destroy(global_promise.location());
1690 } 1683 }
1691 1684
1692 1685
1693 Handle<Object> Isolate::GetPromiseOnStackOnThrow() { 1686 Handle<Object> Isolate::GetPromiseOnStackOnThrow() {
1694 Handle<Object> undefined = factory()->undefined_value(); 1687 Handle<Object> undefined = factory()->undefined_value();
1695 ThreadLocalTop* tltop = thread_local_top(); 1688 ThreadLocalTop* tltop = thread_local_top();
1696 if (tltop->promise_on_stack_ == NULL) return undefined; 1689 if (tltop->promise_on_stack_ == NULL) return undefined;
1697 Handle<JSFunction> promise_function = tltop->promise_on_stack_->function();
1698 // Find the top-most try-catch or try-finally handler. 1690 // Find the top-most try-catch or try-finally handler.
1699 if (PredictExceptionCatcher() != CAUGHT_BY_JAVASCRIPT) return undefined; 1691 if (PredictExceptionCatcher() != CAUGHT_BY_JAVASCRIPT) return undefined;
1700 for (JavaScriptFrameIterator it(this); !it.done(); it.Advance()) { 1692 for (JavaScriptFrameIterator it(this); !it.done(); it.Advance()) {
1701 JavaScriptFrame* frame = it.frame(); 1693 JavaScriptFrame* frame = it.frame();
1702 if (frame->LookupExceptionHandlerInTable(nullptr, nullptr) > 0) { 1694 HandlerTable::CatchPrediction prediction;
1695 if (frame->LookupExceptionHandlerInTable(nullptr, &prediction) > 0) {
1703 // Throwing inside a Promise only leads to a reject if not caught by an 1696 // Throwing inside a Promise only leads to a reject if not caught by an
1704 // inner try-catch or try-finally. 1697 // inner try-catch or try-finally.
1705 if (frame->function() == *promise_function) { 1698 if (prediction == HandlerTable::PROMISE) {
Dan Ehrenberg 2016/07/21 21:07:33 Beautiful
1706 return tltop->promise_on_stack_->promise(); 1699 return tltop->promise_on_stack_->promise();
1707 } 1700 }
1708 return undefined; 1701 return undefined;
1709 } 1702 }
1710 } 1703 }
1711 return undefined; 1704 return undefined;
1712 } 1705 }
1713 1706
1714 1707
1715 void Isolate::SetCaptureStackTraceForUncaughtExceptions( 1708 void Isolate::SetCaptureStackTraceForUncaughtExceptions(
(...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after
3095 // Then check whether this scope intercepts. 3088 // Then check whether this scope intercepts.
3096 if ((flag & intercept_mask_)) { 3089 if ((flag & intercept_mask_)) {
3097 intercepted_flags_ |= flag; 3090 intercepted_flags_ |= flag;
3098 return true; 3091 return true;
3099 } 3092 }
3100 return false; 3093 return false;
3101 } 3094 }
3102 3095
3103 } // namespace internal 3096 } // namespace internal
3104 } // namespace v8 3097 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698