From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 1 Sep 2025 03:13:53 +0900 Subject: Remove deprecated `GetIsolate` https://chromium-review.googlesource.com/c/v8/v8/+/6905244 diff --git a/src/api/environment.cc b/src/api/environment.cc index d753ad6c6b49b26b86920124f7ac90c1e052638e..cfc9b3157d08d62f43e2e5bb01229fe663f3ca61 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -668,7 +668,7 @@ std::unique_ptr MultiIsolatePlatform::Create( MaybeLocal GetPerContextExports(Local context, IsolateData* isolate_data) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); EscapableHandleScope handle_scope(isolate); Local global = context->Global(); @@ -714,7 +714,7 @@ void ProtoThrower(const FunctionCallbackInfo& info) { // This runs at runtime, regardless of whether the context // is created from a snapshot. Maybe InitializeContextRuntime(Local context) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); HandleScope handle_scope(isolate); // When `IsCodeGenerationFromStringsAllowed` is true, V8 takes the fast path @@ -793,7 +793,7 @@ Maybe InitializeContextRuntime(Local context) { } Maybe InitializeBaseContextForSnapshot(Local context) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); HandleScope handle_scope(isolate); // Delete `Intl.v8BreakIterator` @@ -818,7 +818,7 @@ Maybe InitializeBaseContextForSnapshot(Local context) { } Maybe InitializeMainContextForSnapshot(Local context) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); HandleScope handle_scope(isolate); // Initialize the default values. @@ -836,7 +836,7 @@ Maybe InitializeMainContextForSnapshot(Local context) { MaybeLocal InitializePrivateSymbols(Local context, IsolateData* isolate_data) { CHECK(isolate_data); - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); EscapableHandleScope scope(isolate); Context::Scope context_scope(context); @@ -860,7 +860,7 @@ MaybeLocal InitializePrivateSymbols(Local context, MaybeLocal InitializePerIsolateSymbols(Local context, IsolateData* isolate_data) { CHECK(isolate_data); - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); EscapableHandleScope scope(isolate); Context::Scope context_scope(context); @@ -886,7 +886,7 @@ MaybeLocal InitializePerIsolateSymbols(Local context, Maybe InitializePrimordials(Local context, IsolateData* isolate_data) { // Run per-context JS files. - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Context::Scope context_scope(context); Local exports; diff --git a/src/base_object-inl.h b/src/base_object-inl.h index cc60ddddb037e0279615bbe24821eb20fd8da677..37d83e41b618a07aca98118260abe9618f11256d 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -55,7 +55,6 @@ v8::Local BaseObject::object() const { v8::Local BaseObject::object(v8::Isolate* isolate) const { v8::Local handle = object(); - DCHECK_EQ(handle->GetCreationContextChecked()->GetIsolate(), isolate); DCHECK_EQ(env()->isolate(), isolate); return handle; diff --git a/src/crypto/crypto_context.cc b/src/crypto/crypto_context.cc index 2e3f31e1765024373c3fc2acd33fc3bfb352a906..ca62d3001bf51193d78caac0cccd93c188a8410c 100644 --- a/src/crypto/crypto_context.cc +++ b/src/crypto/crypto_context.cc @@ -1045,7 +1045,7 @@ bool ArrayOfStringsToX509s(Local context, Local cert_array, std::vector* certs) { ClearErrorOnReturn clear_error_on_return; - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Environment* env = Environment::GetCurrent(context); uint32_t array_length = cert_array->Length(); diff --git a/src/crypto/crypto_x509.cc b/src/crypto/crypto_x509.cc index 4c5427596d1c90d3a413cdd9ff4f1151e657073d..70135a6be65e41fcb3564ddf6d1e8083a59ef8bb 100644 --- a/src/crypto/crypto_x509.cc +++ b/src/crypto/crypto_x509.cc @@ -107,7 +107,7 @@ MaybeLocal ToV8Value(Local context, BIOPointer&& bio) { return {}; BUF_MEM* mem = bio; Local ret; - if (!String::NewFromUtf8(context->GetIsolate(), + if (!String::NewFromUtf8(Isolate::GetCurrent(), mem->data, NewStringType::kNormal, mem->length) @@ -121,7 +121,7 @@ MaybeLocal ToV8Value(Local context, const BIOPointer& bio) { return {}; BUF_MEM* mem = bio; Local ret; - if (!String::NewFromUtf8(context->GetIsolate(), + if (!String::NewFromUtf8(Isolate::GetCurrent(), mem->data, NewStringType::kNormal, mem->length) diff --git a/src/encoding_binding.cc b/src/encoding_binding.cc index a913e34c73db3fb62aedcf28bee1bf1c4d59de7a..9de38eb9907269e99fdf0907aa35862572a2c643 100644 --- a/src/encoding_binding.cc +++ b/src/encoding_binding.cc @@ -75,7 +75,7 @@ void BindingData::Deserialize(Local context, int index, InternalFieldInfoBase* info) { DCHECK_IS_SNAPSHOT_SLOT(index); - HandleScope scope(context->GetIsolate()); + HandleScope scope(Isolate::GetCurrent()); Realm* realm = Realm::GetCurrent(context); // Recreate the buffer in the constructor. InternalFieldInfo* casted_info = static_cast(info); diff --git a/src/env.cc b/src/env.cc index b5cf58cc953590493beb52abf249e33e486ffc46..347ec5c42e098186ff489dff199ac5989961f6e3 100644 --- a/src/env.cc +++ b/src/env.cc @@ -1765,10 +1765,10 @@ void AsyncHooks::Deserialize(Local context) { context->GetDataFromSnapshotOnce( info_->js_execution_async_resources).ToLocalChecked(); } else { - js_execution_async_resources = Array::New(context->GetIsolate()); + js_execution_async_resources = Array::New(Isolate::GetCurrent()); } js_execution_async_resources_.Reset( - context->GetIsolate(), js_execution_async_resources); + Isolate::GetCurrent(), js_execution_async_resources); // The native_execution_async_resources_ field requires v8::Local<> instances // for async calls whose resources were on the stack as JS objects when they @@ -1808,7 +1808,7 @@ AsyncHooks::SerializeInfo AsyncHooks::Serialize(Local context, info.async_id_fields = async_id_fields_.Serialize(context, creator); if (!js_execution_async_resources_.IsEmpty()) { info.js_execution_async_resources = creator->AddData( - context, js_execution_async_resources_.Get(context->GetIsolate())); + context, js_execution_async_resources_.Get(Isolate::GetCurrent())); CHECK_NE(info.js_execution_async_resources, 0); } else { info.js_execution_async_resources = 0; diff --git a/src/inspector/network_agent.cc b/src/inspector/network_agent.cc index aacd4e8cb83c88649537ab5d9e1ce752ea5b87a8..a47ea86adb9da081a125b6590bcd96f43053d44b 100644 --- a/src/inspector/network_agent.cc +++ b/src/inspector/network_agent.cc @@ -31,31 +31,31 @@ constexpr size_t kDefaultMaxTotalBufferSize = 100 * 1024 * 1024; // 100MB Maybe ObjectGetProtocolString(v8::Local context, Local object, Local property) { - HandleScope handle_scope(context->GetIsolate()); + HandleScope handle_scope(v8::Isolate::GetCurrent()); Local value; if (!object->Get(context, property).ToLocal(&value) || !value->IsString()) { return Nothing(); } Local str = value.As(); - return Just(ToProtocolString(context->GetIsolate(), str)); + return Just(ToProtocolString(v8::Isolate::GetCurrent(), str)); } // Get a protocol string property from the object. Maybe ObjectGetProtocolString(v8::Local context, Local object, const char* property) { - HandleScope handle_scope(context->GetIsolate()); + HandleScope handle_scope(v8::Isolate::GetCurrent()); return ObjectGetProtocolString( - context, object, OneByteString(context->GetIsolate(), property)); + context, object, OneByteString(v8::Isolate::GetCurrent(), property)); } // Get a protocol double property from the object. Maybe ObjectGetDouble(v8::Local context, Local object, const char* property) { - HandleScope handle_scope(context->GetIsolate()); + HandleScope handle_scope(v8::Isolate::GetCurrent()); Local value; - if (!object->Get(context, OneByteString(context->GetIsolate(), property)) + if (!object->Get(context, OneByteString(v8::Isolate::GetCurrent(), property)) .ToLocal(&value) || !value->IsNumber()) { return Nothing(); @@ -67,9 +67,9 @@ Maybe ObjectGetDouble(v8::Local context, Maybe ObjectGetInt(v8::Local context, Local object, const char* property) { - HandleScope handle_scope(context->GetIsolate()); + HandleScope handle_scope(v8::Isolate::GetCurrent()); Local value; - if (!object->Get(context, OneByteString(context->GetIsolate(), property)) + if (!object->Get(context, OneByteString(v8::Isolate::GetCurrent(), property)) .ToLocal(&value) || !value->IsInt32()) { return Nothing(); @@ -81,9 +81,9 @@ Maybe ObjectGetInt(v8::Local context, Maybe ObjectGetBool(v8::Local context, Local object, const char* property) { - HandleScope handle_scope(context->GetIsolate()); + HandleScope handle_scope(v8::Isolate::GetCurrent()); Local value; - if (!object->Get(context, OneByteString(context->GetIsolate(), property)) + if (!object->Get(context, OneByteString(v8::Isolate::GetCurrent(), property)) .ToLocal(&value) || !value->IsBoolean()) { return Nothing(); @@ -95,9 +95,9 @@ Maybe ObjectGetBool(v8::Local context, MaybeLocal ObjectGetObject(v8::Local context, Local object, const char* property) { - EscapableHandleScope handle_scope(context->GetIsolate()); + EscapableHandleScope handle_scope(v8::Isolate::GetCurrent()); Local value; - if (!object->Get(context, OneByteString(context->GetIsolate(), property)) + if (!object->Get(context, OneByteString(v8::Isolate::GetCurrent(), property)) .ToLocal(&value) || !value->IsObject()) { return {}; @@ -108,7 +108,7 @@ MaybeLocal ObjectGetObject(v8::Local context, // Create a protocol::Network::Headers from the v8 object. std::unique_ptr createHeadersFromObject( v8::Local context, Local headers_obj) { - HandleScope handle_scope(context->GetIsolate()); + HandleScope handle_scope(v8::Isolate::GetCurrent()); std::unique_ptr dict = protocol::DictionaryValue::create(); @@ -129,7 +129,7 @@ std::unique_ptr createHeadersFromObject( .To(&property_value)) { return {}; } - dict->setString(ToProtocolString(context->GetIsolate(), property_name), + dict->setString(ToProtocolString(v8::Isolate::GetCurrent(), property_name), property_value); } @@ -139,7 +139,7 @@ std::unique_ptr createHeadersFromObject( // Create a protocol::Network::Request from the v8 object. std::unique_ptr createRequestFromObject( v8::Local context, Local request) { - HandleScope handle_scope(context->GetIsolate()); + HandleScope handle_scope(v8::Isolate::GetCurrent()); protocol::String url; if (!ObjectGetProtocolString(context, request, "url").To(&url)) { return {}; @@ -171,7 +171,7 @@ std::unique_ptr createRequestFromObject( // Create a protocol::Network::Response from the v8 object. std::unique_ptr createResponseFromObject( v8::Local context, Local response) { - HandleScope handle_scope(context->GetIsolate()); + HandleScope handle_scope(v8::Isolate::GetCurrent()); protocol::String url; if (!ObjectGetProtocolString(context, response, "url").To(&url)) { return {}; @@ -212,7 +212,7 @@ std::unique_ptr createResponseFromObject( std::unique_ptr createWebSocketResponse( v8::Local context, Local response) { - HandleScope handle_scope(context->GetIsolate()); + HandleScope handle_scope(v8::Isolate::GetCurrent()); int status; if (!ObjectGetInt(context, response, "status").To(&status)) { return {}; diff --git a/src/js_native_api_v8.h b/src/js_native_api_v8.h index 27aeac589b19cd681923fb848ce5f36c66fc05e2..5f2900869763f40cac54e3cb3fe2e24eda615410 100644 --- a/src/js_native_api_v8.h +++ b/src/js_native_api_v8.h @@ -53,7 +53,7 @@ class RefTracker { struct napi_env__ { explicit napi_env__(v8::Local context, int32_t module_api_version) - : isolate(context->GetIsolate()), + : isolate(v8::Isolate::GetCurrent()), context_persistent(isolate, context), module_api_version(module_api_version) { napi_clear_last_error(this); diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 52483740bb377a2bc2a16af701615d9a4e448eae..84d17a46efe146c1794a43963c41a4461eacfca2 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -99,7 +99,7 @@ ModuleCacheKey ModuleCacheKey::From(Local context, Local specifier, Local import_attributes) { CHECK_EQ(import_attributes->Length() % elements_per_attribute, 0); - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); std::size_t h1 = specifier->GetIdentityHash(); size_t num_attributes = import_attributes->Length() / elements_per_attribute; ImportAttributeVector attributes; @@ -1022,7 +1022,7 @@ MaybeLocal ModuleWrap::ResolveModuleCallback( return {}; } DCHECK_NOT_NULL(resolved_module); - return resolved_module->module_.Get(context->GetIsolate()); + return resolved_module->module_.Get(Isolate::GetCurrent()); } // static @@ -1043,7 +1043,7 @@ MaybeLocal ModuleWrap::ResolveSourceCallback( ->GetInternalField(ModuleWrap::kModuleSourceObjectSlot) .As(); if (module_source_object->IsUndefined()) { - THROW_ERR_SOURCE_PHASE_NOT_DEFINED(context->GetIsolate(), + THROW_ERR_SOURCE_PHASE_NOT_DEFINED(Isolate::GetCurrent(), resolved_module->url_); return {}; } @@ -1057,7 +1057,7 @@ Maybe ModuleWrap::ResolveModule( Local specifier, Local import_attributes, Local referrer) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Environment* env = Environment::GetCurrent(context); if (env == nullptr) { THROW_ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE(isolate); @@ -1106,7 +1106,7 @@ MaybeLocal ImportModuleDynamicallyWithPhase( Local specifier, ModuleImportPhase phase, Local import_attributes) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Environment* env = Environment::GetCurrent(context); if (env == nullptr) { THROW_ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE(isolate); @@ -1348,7 +1348,7 @@ MaybeLocal LinkRequireFacadeWithOriginal( Local import_attributes, Local referrer) { Environment* env = Environment::GetCurrent(context); - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); CHECK(specifier->Equals(context, env->original_string()).ToChecked()); CHECK(!env->temporary_required_module_facade_original.IsEmpty()); return env->temporary_required_module_facade_original.Get(isolate); diff --git a/src/node.h b/src/node.h index 154fb15e6c8fe985e92378cc8471aa6a9d579b07..6252c41a14f4bd092cb424858be58d525b235625 100644 --- a/src/node.h +++ b/src/node.h @@ -1063,7 +1063,7 @@ NODE_DEPRECATED("Use v8::Date::ValueOf() directly", #define NODE_DEFINE_CONSTANT(target, constant) \ do { \ - v8::Isolate* isolate = target->GetIsolate(); \ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); \ v8::Local context = isolate->GetCurrentContext(); \ v8::Local constant_name = v8::String::NewFromUtf8Literal( \ isolate, #constant, v8::NewStringType::kInternalized); \ @@ -1079,7 +1079,7 @@ NODE_DEPRECATED("Use v8::Date::ValueOf() directly", #define NODE_DEFINE_HIDDEN_CONSTANT(target, constant) \ do { \ - v8::Isolate* isolate = target->GetIsolate(); \ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); \ v8::Local context = isolate->GetCurrentContext(); \ v8::Local constant_name = v8::String::NewFromUtf8Literal( \ isolate, #constant, v8::NewStringType::kInternalized); \ diff --git a/src/node_blob.cc b/src/node_blob.cc index d278a32c9934c15bc721da164efccca7bc7e7111..ab862bf93a411e6ae6da7c9f9706cee279a0ad70 100644 --- a/src/node_blob.cc +++ b/src/node_blob.cc @@ -554,7 +554,7 @@ void BlobBindingData::Deserialize(Local context, int index, InternalFieldInfoBase* info) { DCHECK_IS_SNAPSHOT_SLOT(index); - HandleScope scope(context->GetIsolate()); + HandleScope scope(Isolate::GetCurrent()); Realm* realm = Realm::GetCurrent(context); BlobBindingData* binding = realm->AddBindingData(holder); CHECK_NOT_NULL(binding); diff --git a/src/node_builtins.cc b/src/node_builtins.cc index 703ac1be06249736073f797058d170576a0db1bf..f0607ec9fd1983386166d0f4782adac99ace943e 100644 --- a/src/node_builtins.cc +++ b/src/node_builtins.cc @@ -275,7 +275,7 @@ MaybeLocal BuiltinLoader::LookupAndCompileInternal( const char* id, LocalVector* parameters, Realm* optional_realm) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); EscapableHandleScope scope(isolate); Local source; @@ -397,7 +397,7 @@ void BuiltinLoader::SaveCodeCache(const char* id, Local fun) { MaybeLocal BuiltinLoader::LookupAndCompile(Local context, const char* id, Realm* optional_realm) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); LocalVector parameters(isolate); // Detects parameters of the scripts based on module ids. // internal/bootstrap/realm: process, getLinkedBinding, @@ -451,7 +451,7 @@ MaybeLocal BuiltinLoader::LookupAndCompile(Local context, MaybeLocal BuiltinLoader::CompileAndCall(Local context, const char* id, Realm* realm) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); // Detects parameters of the scripts based on module ids. // internal/bootstrap/realm: process, getLinkedBinding, // getInternalBinding, primordials @@ -507,7 +507,7 @@ MaybeLocal BuiltinLoader::CompileAndCall(Local context, if (!maybe_fn.ToLocal(&fn)) { return MaybeLocal(); } - Local undefined = Undefined(context->GetIsolate()); + Local undefined = Undefined(Isolate::GetCurrent()); return fn->Call(context, undefined, argc, argv); } @@ -545,14 +545,14 @@ bool BuiltinLoader::CompileAllBuiltinsAndCopyCodeCache( to_eager_compile_.emplace(id); } - TryCatch bootstrapCatch(context->GetIsolate()); + TryCatch bootstrapCatch(Isolate::GetCurrent()); auto fn = LookupAndCompile(context, id.data(), nullptr); if (bootstrapCatch.HasCaught()) { per_process::Debug(DebugCategory::CODE_CACHE, "Failed to compile code cache for %s\n", id.data()); all_succeeded = false; - PrintCaughtException(context->GetIsolate(), context, bootstrapCatch); + PrintCaughtException(Isolate::GetCurrent(), context, bootstrapCatch); } else { // This is used by the snapshot builder, so save the code cache // unconditionally. diff --git a/src/node_constants.cc b/src/node_constants.cc index fea0426496978c0003fe1481afcf93fc9c23edca..c9588880d05435ab9f4e23fcff74c93309664270 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -1265,7 +1265,7 @@ void CreatePerContextProperties(Local target, Local unused, Local context, void* priv) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Environment* env = Environment::GetCurrent(context); CHECK( diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 3c234205e89be7e976dae5c3fcc73ca67953e034..e66d4fcb0c064f96cdb819c783027d864fe88d12 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -113,7 +113,7 @@ namespace { // Convert an int to a V8 Name (String or Symbol). MaybeLocal Uint32ToName(Local context, uint32_t index) { - return Uint32::New(context->GetIsolate(), index)->ToString(context); + return Uint32::New(Isolate::GetCurrent(), index)->ToString(context); } } // anonymous namespace @@ -677,7 +677,7 @@ Intercepted ContextifyContext::PropertyDefinerCallback( } Local context = ctx->context(); - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); PropertyAttribute attributes = PropertyAttribute::None; bool is_declared = @@ -1666,7 +1666,7 @@ static MaybeLocal CompileFunctionForCJSLoader( bool* cache_rejected, bool is_cjs_scope, ScriptCompiler::CachedData* cached_data) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); EscapableHandleScope scope(isolate); Local symbol = env->vm_dynamic_import_default_internal(); diff --git a/src/node_env_var.cc b/src/node_env_var.cc index 6aad252eb5681bb9ab9890812602b43c418e7a7f..5f7ef8cc58f589ba30a44abaaaaaf1514458c3f0 100644 --- a/src/node_env_var.cc +++ b/src/node_env_var.cc @@ -311,7 +311,7 @@ std::shared_ptr KVStore::CreateMapKVStore() { Maybe KVStore::AssignFromObject(Local context, Local entries) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); HandleScope handle_scope(isolate); Local keys; if (!entries->GetOwnPropertyNames(context).ToLocal(&keys)) diff --git a/src/node_errors.cc b/src/node_errors.cc index 55a0c986c5b6989ee9ce277bb6a9778abb2ad2ee..809d88f21e5572807e38132d40ee75870ab8de07 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -631,7 +631,7 @@ v8::ModifyCodeGenerationFromStringsResult ModifyCodeGenerationFromStrings( v8::Local context, v8::Local source, bool is_code_like) { - HandleScope scope(context->GetIsolate()); + HandleScope scope(Isolate::GetCurrent()); if (context->GetNumberOfEmbedderDataFields() <= ContextEmbedderIndex::kAllowCodeGenerationFromStrings) { @@ -1037,7 +1037,7 @@ const char* errno_string(int errorno) { } void PerIsolateMessageListener(Local message, Local error) { - Isolate* isolate = message->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); switch (message->ErrorLevel()) { case Isolate::MessageErrorLevel::kMessageWarning: { Environment* env = Environment::GetCurrent(isolate); @@ -1197,7 +1197,7 @@ void Initialize(Local target, SetMethod( context, target, "getErrorSourcePositions", GetErrorSourcePositions); - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Local exit_codes = Object::New(isolate); READONLY_PROPERTY(target, "exitCodes", exit_codes); diff --git a/src/node_file.cc b/src/node_file.cc index ba6ffc2b6565dea500bc8dd4818c8fcb7648694a..e834325a763f7ea8f53210145b5edd134d6b67e6 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -3843,7 +3843,7 @@ void BindingData::Deserialize(Local context, int index, InternalFieldInfoBase* info) { DCHECK_IS_SNAPSHOT_SLOT(index); - HandleScope scope(context->GetIsolate()); + HandleScope scope(Isolate::GetCurrent()); Realm* realm = Realm::GetCurrent(context); InternalFieldInfo* casted_info = static_cast(info); BindingData* binding = diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 57e068ae249d618c2658638f9f3b03e1fedb6524..8c51ae4e0a435971c6d0288af87810877dd31a49 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -254,7 +254,7 @@ namespace { MaybeLocal GetEmitMessageFunction(Local context, IsolateData* isolate_data) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Local per_context_bindings; Local emit_message_val; if (!GetPerContextExports(context, isolate_data) @@ -269,7 +269,7 @@ MaybeLocal GetEmitMessageFunction(Local context, } MaybeLocal GetDOMException(Local context) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Local per_context_bindings; Local domexception_ctor_val; if (!GetPerContextExports(context).ToLocal(&per_context_bindings) || @@ -284,7 +284,7 @@ MaybeLocal GetDOMException(Local context) { } void ThrowDataCloneException(Local context, Local message) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Local argv[] = {message, FIXED_ONE_BYTE_STRING(isolate, "DataCloneError")}; Local exception; @@ -1477,7 +1477,7 @@ BaseObjectPtr JSTransferable::Data::Deserialize( Maybe JSTransferable::Data::FinalizeTransferWrite( Local context, ValueSerializer* serializer) { - HandleScope handle_scope(context->GetIsolate()); + HandleScope handle_scope(Isolate::GetCurrent()); auto ret = serializer->WriteValue(context, PersistentToLocal::Strong(data_)); data_.Reset(); return ret; diff --git a/src/node_modules.cc b/src/node_modules.cc index cecdda74847801fd5821bc0afdf0dfc9f131c44a..04ebecc5d924f6c2fddd9992462d1ff692e1cee5 100644 --- a/src/node_modules.cc +++ b/src/node_modules.cc @@ -70,7 +70,7 @@ void BindingData::Deserialize(v8::Local context, int index, InternalFieldInfoBase* info) { DCHECK_IS_SNAPSHOT_SLOT(index); - HandleScope scope(context->GetIsolate()); + HandleScope scope(Isolate::GetCurrent()); Realm* realm = Realm::GetCurrent(context); BindingData* binding = realm->AddBindingData(holder); CHECK_NOT_NULL(binding); @@ -750,7 +750,7 @@ void BindingData::CreatePerContextProperties(Local target, Realm* realm = Realm::GetCurrent(context); realm->AddBindingData(target); - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); LocalVector compile_cache_status_values(isolate); #define V(status) \ diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 4a258e5f140994536386492059d64c9cf94ea0a6..67278974199db46fed85b443e7cdd30accd7687f 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -745,7 +745,7 @@ void BindingData::Deserialize(Local context, int index, InternalFieldInfoBase* info) { DCHECK_IS_SNAPSHOT_SLOT(index); - v8::HandleScope scope(context->GetIsolate()); + v8::HandleScope scope(Isolate::GetCurrent()); Realm* realm = Realm::GetCurrent(context); // Recreate the buffer in the constructor. InternalFieldInfo* casted_info = static_cast(info); diff --git a/src/node_realm.cc b/src/node_realm.cc index 6d2e4eb641a8ffaacf4aebd3522008a285387a30..47bd7d9f19077ac7a558c73db5f51bdf8da291e7 100644 --- a/src/node_realm.cc +++ b/src/node_realm.cc @@ -22,7 +22,7 @@ using v8::String; using v8::Value; Realm::Realm(Environment* env, v8::Local context, Kind kind) - : env_(env), isolate_(context->GetIsolate()), kind_(kind) { + : env_(env), isolate_(v8::Isolate::GetCurrent()), kind_(kind) { context_.Reset(isolate_, context); env->AssignToContext(context, this, ContextInfo("")); // The environment can also purge empty wrappers in the check callback, diff --git a/src/node_report.cc b/src/node_report.cc index ba2dd7e676bfdfe7da66a4a79db3c791a505c9a8..28e6cfac682e301b605c00c4ef2eaf01431f04e4 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -400,7 +400,7 @@ static void PrintJavaScriptErrorProperties(JSONWriter* writer, if (!error.IsEmpty() && error->IsObject()) { TryCatch try_catch(isolate); Local error_obj = error.As(); - Local context = error_obj->GetIsolate()->GetCurrentContext(); + Local context = Isolate::GetCurrent()->GetCurrentContext(); Local keys; if (!error_obj->GetOwnPropertyNames(context).ToLocal(&keys)) { return writer->json_objectend(); // the end of 'errorProperties' diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc index c2e24b4645e7903e08c80aead1c18c7bcff1bd89..e34d24d51d5c090b560d06f727043f20924e6f46 100644 --- a/src/node_snapshotable.cc +++ b/src/node_snapshotable.cc @@ -1614,7 +1614,7 @@ void BindingData::Deserialize(Local context, int index, InternalFieldInfoBase* info) { DCHECK_IS_SNAPSHOT_SLOT(index); - v8::HandleScope scope(context->GetIsolate()); + v8::HandleScope scope(Isolate::GetCurrent()); Realm* realm = Realm::GetCurrent(context); // Recreate the buffer in the constructor. InternalFieldInfo* casted_info = static_cast(info); diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 6bfc54dd81446545ebbb0faedb55a5383b81de49..2e52fb801684feb22800d4809daab006fc7cae9c 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -2061,7 +2061,7 @@ bool StatementSync::BindParams(const FunctionCallbackInfo& args) { if (args[0]->IsObject() && !args[0]->IsArrayBufferView()) { Local obj = args[0].As(); - Local context = obj->GetIsolate()->GetCurrentContext(); + Local context = Isolate::GetCurrent()->GetCurrentContext(); Local keys; if (!obj->GetOwnPropertyNames(context).ToLocal(&keys)) { return false; diff --git a/src/node_task_queue.cc b/src/node_task_queue.cc index d33ee3c26c111e53edf27e6368ca8f64ff30a349..f1c53c44f201b295888e7932c5e3e2b19cb9c319 100644 --- a/src/node_task_queue.cc +++ b/src/node_task_queue.cc @@ -48,7 +48,7 @@ void PromiseRejectCallback(PromiseRejectMessage message) { static std::atomic rejectionsHandledAfter{0}; Local promise = message.GetPromise(); - Isolate* isolate = promise->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); PromiseRejectEvent event = message.GetEvent(); Environment* env = Environment::GetCurrent(isolate); diff --git a/src/node_url.cc b/src/node_url.cc index 9d1e8ec05161570db11f7b662395509774668d78..9b91f83d879ea02fd3d61913c8dfd35b3bf1ac31 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -70,7 +70,7 @@ void BindingData::Deserialize(Local context, int index, InternalFieldInfoBase* info) { DCHECK_IS_SNAPSHOT_SLOT(index); - HandleScope scope(context->GetIsolate()); + HandleScope scope(Isolate::GetCurrent()); Realm* realm = Realm::GetCurrent(context); BindingData* binding = realm->AddBindingData(holder); CHECK_NOT_NULL(binding); diff --git a/src/node_v8.cc b/src/node_v8.cc index 8dd32dad262679444c10878299eb6bb8fb04e120..935ea2cf5157c3a2fbdf142fc7024ec6b6d5de26 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -163,7 +163,7 @@ void BindingData::Deserialize(Local context, int index, InternalFieldInfoBase* info) { DCHECK_IS_SNAPSHOT_SLOT(index); - HandleScope scope(context->GetIsolate()); + HandleScope scope(Isolate::GetCurrent()); Realm* realm = Realm::GetCurrent(context); // Recreate the buffer in the constructor. InternalFieldInfo* casted_info = static_cast(info); diff --git a/src/node_wasi.cc b/src/node_wasi.cc index 370221d3cddc201180260ecb3a222bc831c91093..f5aff2f65fe6b9f48cf970ab3e7c57cfe4885f85 100644 --- a/src/node_wasi.cc +++ b/src/node_wasi.cc @@ -50,7 +50,7 @@ using v8::WasmMemoryObject; static MaybeLocal WASIException(Local context, int errorno, const char* syscall) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Environment* env = Environment::GetCurrent(context); CHECK_NOT_NULL(env); const char* err_name = uvwasi_embedder_err_code_to_string(errorno); @@ -275,8 +275,8 @@ R WASI::WasiFunction::FastCallback( return EinvalError(); } - Isolate* isolate = receiver->GetIsolate(); - HandleScope scope(isolate); + Isolate* isolate = Isolate::GetCurrent(); + HandleScope handle_scope(isolate); if (wasi->memory_.IsEmpty()) { THROW_ERR_WASI_NOT_STARTED(isolate); return EinvalError(); diff --git a/src/node_webstorage.cc b/src/node_webstorage.cc index 5c7d268d38ff55ce4db07463b1ea0bcb2f4e63ea..bd83654012442195866e57173b6e5d4d25fecf0f 100644 --- a/src/node_webstorage.cc +++ b/src/node_webstorage.cc @@ -57,7 +57,7 @@ using v8::Value; } while (0) static void ThrowQuotaExceededException(Local context) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); auto dom_exception_str = FIXED_ONE_BYTE_STRING(isolate, "DOMException"); auto err_name = FIXED_ONE_BYTE_STRING(isolate, "QuotaExceededError"); auto err_message = @@ -437,7 +437,7 @@ Maybe Storage::Store(Local key, Local value) { } static MaybeLocal Uint32ToName(Local context, uint32_t index) { - return Uint32::New(context->GetIsolate(), index)->ToString(context); + return Uint32::New(Isolate::GetCurrent(), index)->ToString(context); } static void Clear(const FunctionCallbackInfo& info) { diff --git a/src/node_worker.cc b/src/node_worker.cc index e7d26b4c8cbb08a175084ceac51395860dc60598..fa4ec53ee556a23c8fd018caa1eee51bc5e004fe 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -1465,8 +1465,6 @@ void GetEnvMessagePort(const FunctionCallbackInfo& args) { Local port = env->message_port(); CHECK_IMPLIES(!env->is_main_thread(), !port.IsEmpty()); if (!port.IsEmpty()) { - CHECK_EQ(port->GetCreationContextChecked()->GetIsolate(), - args.GetIsolate()); args.GetReturnValue().Set(port); } } diff --git a/src/timers.cc b/src/timers.cc index da4206187f7c7d2becb8a101c1ff5346a10e13f4..03f0910926f3d403121e227cee32a546b2394e04 100644 --- a/src/timers.cc +++ b/src/timers.cc @@ -114,7 +114,7 @@ void BindingData::Deserialize(Local context, int index, InternalFieldInfoBase* info) { DCHECK_IS_SNAPSHOT_SLOT(index); - v8::HandleScope scope(context->GetIsolate()); + v8::HandleScope scope(Isolate::GetCurrent()); Realm* realm = Realm::GetCurrent(context); // Recreate the buffer in the constructor. BindingData* binding = realm->AddBindingData(holder); diff --git a/src/util-inl.h b/src/util-inl.h index aae5956742f195279ab6af04029d76dee6af2e84..6898e8ea794675e903e13e2b45524d572a3f68bb 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -336,14 +336,14 @@ v8::Maybe FromV8Array(v8::Local context, std::vector>* out) { uint32_t count = js_array->Length(); out->reserve(count); - ArrayIterationData data{out, context->GetIsolate()}; + ArrayIterationData data{out, v8::Isolate::GetCurrent()}; return js_array->Iterate(context, PushItemToVector, &data); } v8::MaybeLocal ToV8Value(v8::Local context, std::string_view str, v8::Isolate* isolate) { - if (isolate == nullptr) isolate = context->GetIsolate(); + if (isolate == nullptr) isolate = v8::Isolate::GetCurrent(); if (str.size() >= static_cast(v8::String::kMaxLength)) [[unlikely]] { // V8 only has a TODO comment about adding an exception when the maximum // string size is exceeded. @@ -359,7 +359,7 @@ v8::MaybeLocal ToV8Value(v8::Local context, v8::MaybeLocal ToV8Value(v8::Local context, std::u16string_view str, v8::Isolate* isolate) { - if (isolate == nullptr) isolate = context->GetIsolate(); + if (isolate == nullptr) isolate = v8::Isolate::GetCurrent(); if (str.length() >= static_cast(v8::String::kMaxLength)) [[unlikely]] { // V8 only has a TODO comment about adding an exception when the maximum @@ -379,7 +379,7 @@ v8::MaybeLocal ToV8Value(v8::Local context, v8::MaybeLocal ToV8Value(v8::Local context, v8_inspector::StringView str, v8::Isolate* isolate) { - if (isolate == nullptr) isolate = context->GetIsolate(); + if (isolate == nullptr) isolate = v8::Isolate::GetCurrent(); if (str.length() >= static_cast(v8::String::kMaxLength)) [[unlikely]] { // V8 only has a TODO comment about adding an exception when the maximum @@ -406,7 +406,7 @@ template v8::MaybeLocal ToV8Value(v8::Local context, const std::vector& vec, v8::Isolate* isolate) { - if (isolate == nullptr) isolate = context->GetIsolate(); + if (isolate == nullptr) isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope handle_scope(isolate); MaybeStackBuffer, 128> arr(vec.size()); @@ -423,7 +423,7 @@ template v8::MaybeLocal ToV8Value(v8::Local context, const std::set& set, v8::Isolate* isolate) { - if (isolate == nullptr) isolate = context->GetIsolate(); + if (isolate == nullptr) isolate = v8::Isolate::GetCurrent(); v8::Local set_js = v8::Set::New(isolate); v8::HandleScope handle_scope(isolate); @@ -442,7 +442,7 @@ template v8::MaybeLocal ToV8Value(v8::Local context, const std::ranges::elements_view& vec, v8::Isolate* isolate) { - if (isolate == nullptr) isolate = context->GetIsolate(); + if (isolate == nullptr) isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope handle_scope(isolate); MaybeStackBuffer, 128> arr(vec.size()); @@ -461,7 +461,7 @@ template v8::MaybeLocal ToV8Value(v8::Local context, const std::unordered_map& map, v8::Isolate* isolate) { - if (isolate == nullptr) isolate = context->GetIsolate(); + if (isolate == nullptr) isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope handle_scope(isolate); v8::Local ret = v8::Map::New(isolate); @@ -504,7 +504,7 @@ template v8::MaybeLocal ToV8Value(v8::Local context, const T& number, v8::Isolate* isolate) { - if (isolate == nullptr) isolate = context->GetIsolate(); + if (isolate == nullptr) isolate = v8::Isolate::GetCurrent(); return ConvertNumberToV8Value(isolate, number); } @@ -517,7 +517,7 @@ v8::Local ToV8ValuePrimitiveArray(v8::Local context, std::is_floating_point_v, "Only primitive types (bool, integral, floating-point) are supported."); - if (isolate == nullptr) isolate = context->GetIsolate(); + if (isolate == nullptr) isolate = v8::Isolate::GetCurrent(); v8::EscapableHandleScope handle_scope(isolate); v8::LocalVector elements(isolate); @@ -803,7 +803,7 @@ inline v8::MaybeLocal NewDictionaryInstanceNullProto( if (value.IsEmpty()) return v8::MaybeLocal(); } v8::Local obj = tmpl->NewInstance(context, property_values); - if (obj->SetPrototypeV2(context, v8::Null(context->GetIsolate())) + if (obj->SetPrototypeV2(context, v8::Null(v8::Isolate::GetCurrent())) .IsNothing()) { return v8::MaybeLocal(); } diff --git a/src/util.cc b/src/util.cc index 660cfff6b8a0c583be843e555e7a06cd09e0d279..c4b39450c5b7f91c46f7027db367c30db34927bb 100644 --- a/src/util.cc +++ b/src/util.cc @@ -391,7 +391,7 @@ void SetMethod(Local context, Local that, const std::string_view name, v8::FunctionCallback callback) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Local function = NewFunctionTemplate(isolate, callback, @@ -452,7 +452,7 @@ void SetFastMethod(Local context, const std::string_view name, v8::FunctionCallback slow_callback, const v8::CFunction* c_function) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Local function = NewFunctionTemplate(isolate, slow_callback, @@ -474,7 +474,7 @@ void SetFastMethodNoSideEffect(Local context, const std::string_view name, v8::FunctionCallback slow_callback, const v8::CFunction* c_function) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Local function = NewFunctionTemplate(isolate, slow_callback, @@ -562,7 +562,7 @@ void SetMethodNoSideEffect(Local context, Local that, const std::string_view name, v8::FunctionCallback callback) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); Local function = NewFunctionTemplate(isolate, callback, @@ -689,7 +689,7 @@ void SetConstructorFunction(Local context, const char* name, Local tmpl, SetConstructorFunctionFlag flag) { - Isolate* isolate = context->GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); SetConstructorFunction( context, that, OneByteString(isolate, name), tmpl, flag); } diff --git a/src/util.h b/src/util.h index 81d08c27fb7037d16e12843dc03c3d8f9caee723..52e6a149d6760640d93c56ce91a759ae9207a8c7 100644 --- a/src/util.h +++ b/src/util.h @@ -753,7 +753,7 @@ inline v8::MaybeLocal ToV8Value( // Variation on NODE_DEFINE_CONSTANT that sets a String value. #define NODE_DEFINE_STRING_CONSTANT(target, name, constant) \ do { \ - v8::Isolate* isolate = target->GetIsolate(); \ + v8::Isolate* isolate = v8::Isolate::GetCurrent(); \ v8::Local constant_name = \ v8::String::NewFromUtf8(isolate, name).ToLocalChecked(); \ v8::Local constant_value = \