diff --git a/include/v8.h b/include/v8.h index f2280dc40f..73bb0ab103 100644 --- a/include/v8.h +++ b/include/v8.h @@ -10389,20 +10389,11 @@ class V8_EXPORT TryCatch { */ void SetCaptureMessage(bool value); - /** - * There are cases when the raw address of C++ TryCatch object cannot be - * used for comparisons with addresses into the JS stack. The cases are: - * 1) ARM, ARM64 and MIPS simulators which have separate JS stack. - * 2) Address sanitizer allocates local C++ object in the heap when - * UseAfterReturn mode is enabled. - * This method returns address that can be used for comparisons with - * addresses into the JS stack. When neither simulator nor ASAN's - * UseAfterReturn is enabled, then the address returned will be the address - * of the C++ try catch handler itself. - */ + V8_DEPRECATE_SOON( + "This is private information that should not be exposed by the API") static void* JSStackComparableAddress(TryCatch* handler) { if (handler == nullptr) return nullptr; - return handler->js_stack_comparable_address_; + return reinterpret_cast(handler->JSStackComparableAddressPrivate()); } TryCatch(const TryCatch&) = delete; @@ -10416,13 +10407,28 @@ class V8_EXPORT TryCatch { void operator delete(void*, size_t); void operator delete[](void*, size_t); + /** + * There are cases when the raw address of C++ TryCatch object cannot be + * used for comparisons with addresses into the JS stack. The cases are: + * 1) ARM, ARM64 and MIPS simulators which have separate JS stack. + * 2) Address sanitizer allocates local C++ object in the heap when + * UseAfterReturn mode is enabled. + * This method returns address that can be used for comparisons with + * addresses into the JS stack. When neither simulator nor ASAN's + * UseAfterReturn is enabled, then the address returned will be the address + * of the C++ try catch handler itself. + */ + internal::Address JSStackComparableAddressPrivate() { + return js_stack_comparable_address_; + } + void ResetInternal(); internal::Isolate* isolate_; TryCatch* next_; void* exception_; void* message_obj_; - void* js_stack_comparable_address_; + internal::Address js_stack_comparable_address_; bool is_verbose_ : 1; bool can_continue_ : 1; bool capture_message_ : 1; @@ -10430,6 +10436,7 @@ class V8_EXPORT TryCatch { bool has_terminated_ : 1; friend class internal::Isolate; + friend class internal::ThreadLocalTop; }; @@ -10732,15 +10739,21 @@ class V8_EXPORT Context : public Data { /** * Returns address that is comparable with JS stack address. Note that JS * stack may be allocated separately from the native stack. See also - * |TryCatch::JSStackComparableAddress| for details. + * |TryCatch::JSStackComparableAddressPrivate| for details. */ + V8_DEPRECATE_SOON( + "This is private V8 information that should not be exposed in the API.") uintptr_t JSStackComparableAddress() const { - return js_stack_comparable_address_; + return JSStackComparableAddressPrivate(); } private: friend class internal::Isolate; + uintptr_t JSStackComparableAddressPrivate() const { + return js_stack_comparable_address_; + } + Local backup_incumbent_context_; uintptr_t js_stack_comparable_address_ = 0; const BackupIncumbentScope* prev_ = nullptr; diff --git a/src/api/api.cc b/src/api/api.cc index 32e7a35c87..a67ae04e73 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -2761,7 +2761,7 @@ v8::TryCatch::TryCatch(v8::Isolate* isolate) has_terminated_(false) { ResetInternal(); // Special handling for simulators which have a separate JS stack. - js_stack_comparable_address_ = reinterpret_cast( + js_stack_comparable_address_ = static_cast( i::SimulatorStack::RegisterJSStackComparableAddress(isolate_)); isolate_->RegisterTryCatchHandler(this); } diff --git a/src/execution/isolate.cc b/src/execution/isolate.cc index f35806b24e..daaa474b3b 100644 --- a/src/execution/isolate.cc +++ b/src/execution/isolate.cc @@ -2625,7 +2625,7 @@ Handle Isolate::GetIncumbentContext() { // NOTE: This code assumes that the stack grows downward. Address top_backup_incumbent = top_backup_incumbent_scope() - ? top_backup_incumbent_scope()->JSStackComparableAddress() + ? top_backup_incumbent_scope()->JSStackComparableAddressPrivate() : 0; if (!it.done() && (!top_backup_incumbent || it.frame()->sp() < top_backup_incumbent)) { diff --git a/src/execution/thread-local-top.h b/src/execution/thread-local-top.h index f903747aeb..83c3903ad4 100644 --- a/src/execution/thread-local-top.h +++ b/src/execution/thread-local-top.h @@ -63,8 +63,10 @@ class ThreadLocalTop { // corresponds to the place on the JS stack where the C++ handler // would have been if the stack were not separate. Address try_catch_handler_address() { - return reinterpret_cast
( - v8::TryCatch::JSStackComparableAddress(try_catch_handler_)); + if (try_catch_handler_) { + return try_catch_handler_->JSStackComparableAddressPrivate(); + } + return kNullAddress; } // Call depth represents nested v8 api calls. Instead of storing the nesting