[api] Make JSStackComparableAddress private

This is an internal property that should not be used publicly.
The following methods are going to be deprecated:
- v8::TryCatch::JSStackComparableAddress
- v8::BackupIncumbentScope::JSStackComparableAddress

Change-Id: Iaecfdece4660eaf1aef88121ff0f0c501c0ced5b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3097451
Reviewed-by: Victor Gomes <victorgomes@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76363}
This commit is contained in:
Camillo Bruni 2021-08-17 10:15:29 +02:00 committed by V8 LUCI CQ
parent 810d34dfe6
commit e7f4c2a15a
4 changed files with 34 additions and 19 deletions

View File

@ -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<void*>(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<Context> backup_incumbent_context_;
uintptr_t js_stack_comparable_address_ = 0;
const BackupIncumbentScope* prev_ = nullptr;

View File

@ -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<void*>(
js_stack_comparable_address_ = static_cast<internal::Address>(
i::SimulatorStack::RegisterJSStackComparableAddress(isolate_));
isolate_->RegisterTryCatchHandler(this);
}

View File

@ -2625,7 +2625,7 @@ Handle<Context> 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)) {

View File

@ -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<Address>(
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