Skip to content

Commit d749bd2

Browse files
backesvictorgomes
authored andcommitted
Replace GetIsolate() by Isolate::GetCurrent() (#224)
* via gemini: Replace GetIsolate by Isolate::GetCurrent() * Manual fixes
1 parent 51d2f75 commit d749bd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+101
-101
lines changed

src/api/environment.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create(
639639

640640
MaybeLocal<Object> GetPerContextExports(Local<Context> context,
641641
IsolateData* isolate_data) {
642-
Isolate* isolate = context->GetIsolate();
642+
Isolate* isolate = Isolate::GetCurrent();
643643
EscapableHandleScope handle_scope(isolate);
644644

645645
Local<Object> global = context->Global();
@@ -685,7 +685,7 @@ void ProtoThrower(const FunctionCallbackInfo<Value>& info) {
685685
// This runs at runtime, regardless of whether the context
686686
// is created from a snapshot.
687687
Maybe<void> InitializeContextRuntime(Local<Context> context) {
688-
Isolate* isolate = context->GetIsolate();
688+
Isolate* isolate = Isolate::GetCurrent();
689689
HandleScope handle_scope(isolate);
690690

691691
// When `IsCodeGenerationFromStringsAllowed` is true, V8 takes the fast path
@@ -764,7 +764,7 @@ Maybe<void> InitializeContextRuntime(Local<Context> context) {
764764
}
765765

766766
Maybe<void> InitializeBaseContextForSnapshot(Local<Context> context) {
767-
Isolate* isolate = context->GetIsolate();
767+
Isolate* isolate = Isolate::GetCurrent();
768768
HandleScope handle_scope(isolate);
769769

770770
// Delete `Intl.v8BreakIterator`
@@ -789,7 +789,7 @@ Maybe<void> InitializeBaseContextForSnapshot(Local<Context> context) {
789789
}
790790

791791
Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) {
792-
Isolate* isolate = context->GetIsolate();
792+
Isolate* isolate = Isolate::GetCurrent();
793793
HandleScope handle_scope(isolate);
794794

795795
// Initialize the default values.
@@ -807,7 +807,7 @@ Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) {
807807
MaybeLocal<Object> InitializePrivateSymbols(Local<Context> context,
808808
IsolateData* isolate_data) {
809809
CHECK(isolate_data);
810-
Isolate* isolate = context->GetIsolate();
810+
Isolate* isolate = Isolate::GetCurrent();
811811
EscapableHandleScope scope(isolate);
812812
Context::Scope context_scope(context);
813813

@@ -831,7 +831,7 @@ MaybeLocal<Object> InitializePrivateSymbols(Local<Context> context,
831831
MaybeLocal<Object> InitializePerIsolateSymbols(Local<Context> context,
832832
IsolateData* isolate_data) {
833833
CHECK(isolate_data);
834-
Isolate* isolate = context->GetIsolate();
834+
Isolate* isolate = Isolate::GetCurrent();
835835
EscapableHandleScope scope(isolate);
836836
Context::Scope context_scope(context);
837837

@@ -857,7 +857,7 @@ MaybeLocal<Object> InitializePerIsolateSymbols(Local<Context> context,
857857
Maybe<void> InitializePrimordials(Local<Context> context,
858858
IsolateData* isolate_data) {
859859
// Run per-context JS files.
860-
Isolate* isolate = context->GetIsolate();
860+
Isolate* isolate = Isolate::GetCurrent();
861861
Context::Scope context_scope(context);
862862
Local<Object> exports;
863863

src/crypto/crypto_context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ bool ArrayOfStringsToX509s(Local<Context> context,
10221022
Local<Array> cert_array,
10231023
std::vector<X509*>* certs) {
10241024
ClearErrorOnReturn clear_error_on_return;
1025-
Isolate* isolate = context->GetIsolate();
1025+
Isolate* isolate = Isolate::GetCurrent();
10261026
Environment* env = Environment::GetCurrent(context);
10271027
uint32_t array_length = cert_array->Length();
10281028

src/crypto/crypto_x509.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ MaybeLocal<Value> ToV8Value(Local<Context> context, BIOPointer&& bio) {
107107
return {};
108108
BUF_MEM* mem = bio;
109109
Local<Value> ret;
110-
if (!String::NewFromUtf8(context->GetIsolate(),
110+
if (!String::NewFromUtf8(Isolate::GetCurrent(),
111111
mem->data,
112112
NewStringType::kNormal,
113113
mem->length)
@@ -121,7 +121,7 @@ MaybeLocal<Value> ToV8Value(Local<Context> context, const BIOPointer& bio) {
121121
return {};
122122
BUF_MEM* mem = bio;
123123
Local<Value> ret;
124-
if (!String::NewFromUtf8(context->GetIsolate(),
124+
if (!String::NewFromUtf8(Isolate::GetCurrent(),
125125
mem->data,
126126
NewStringType::kNormal,
127127
mem->length)

src/encoding_binding.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void BindingData::Deserialize(Local<Context> context,
7676
int index,
7777
InternalFieldInfoBase* info) {
7878
DCHECK_IS_SNAPSHOT_SLOT(index);
79-
HandleScope scope(context->GetIsolate());
79+
HandleScope scope(Isolate::GetCurrent());
8080
Realm* realm = Realm::GetCurrent(context);
8181
// Recreate the buffer in the constructor.
8282
InternalFieldInfo* casted_info = static_cast<InternalFieldInfo*>(info);

src/env.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,10 +1775,10 @@ void AsyncHooks::Deserialize(Local<Context> context) {
17751775
context->GetDataFromSnapshotOnce<Array>(
17761776
info_->js_execution_async_resources).ToLocalChecked();
17771777
} else {
1778-
js_execution_async_resources = Array::New(context->GetIsolate());
1778+
js_execution_async_resources = Array::New(Isolate::GetCurrent());
17791779
}
17801780
js_execution_async_resources_.Reset(
1781-
context->GetIsolate(), js_execution_async_resources);
1781+
Isolate::GetCurrent(), js_execution_async_resources);
17821782

17831783
// The native_execution_async_resources_ field requires v8::Local<> instances
17841784
// for async calls whose resources were on the stack as JS objects when they
@@ -1818,7 +1818,7 @@ AsyncHooks::SerializeInfo AsyncHooks::Serialize(Local<Context> context,
18181818
info.async_id_fields = async_id_fields_.Serialize(context, creator);
18191819
if (!js_execution_async_resources_.IsEmpty()) {
18201820
info.js_execution_async_resources = creator->AddData(
1821-
context, js_execution_async_resources_.Get(context->GetIsolate()));
1821+
context, js_execution_async_resources_.Get(Isolate::GetCurrent()));
18221822
CHECK_NE(info.js_execution_async_resources, 0);
18231823
} else {
18241824
info.js_execution_async_resources = 0;

src/inspector/network_agent.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,31 @@ using v8::Value;
2929
Maybe<protocol::String> ObjectGetProtocolString(v8::Local<v8::Context> context,
3030
Local<Object> object,
3131
Local<v8::String> property) {
32-
HandleScope handle_scope(context->GetIsolate());
32+
HandleScope handle_scope(v8::Isolate::GetCurrent());
3333
Local<Value> value;
3434
if (!object->Get(context, property).ToLocal(&value) || !value->IsString()) {
3535
return Nothing<protocol::String>();
3636
}
3737
Local<v8::String> str = value.As<v8::String>();
38-
return Just(ToProtocolString(context->GetIsolate(), str));
38+
return Just(ToProtocolString(v8::Isolate::GetCurrent(), str));
3939
}
4040

4141
// Get a protocol string property from the object.
4242
Maybe<protocol::String> ObjectGetProtocolString(v8::Local<v8::Context> context,
4343
Local<Object> object,
4444
const char* property) {
45-
HandleScope handle_scope(context->GetIsolate());
45+
HandleScope handle_scope(v8::Isolate::GetCurrent());
4646
return ObjectGetProtocolString(
47-
context, object, OneByteString(context->GetIsolate(), property));
47+
context, object, OneByteString(v8::Isolate::GetCurrent(), property));
4848
}
4949

5050
// Get a protocol double property from the object.
5151
Maybe<double> ObjectGetDouble(v8::Local<v8::Context> context,
5252
Local<Object> object,
5353
const char* property) {
54-
HandleScope handle_scope(context->GetIsolate());
54+
HandleScope handle_scope(v8::Isolate::GetCurrent());
5555
Local<Value> value;
56-
if (!object->Get(context, OneByteString(context->GetIsolate(), property))
56+
if (!object->Get(context, OneByteString(v8::Isolate::GetCurrent(), property))
5757
.ToLocal(&value) ||
5858
!value->IsNumber()) {
5959
return Nothing<double>();
@@ -65,9 +65,9 @@ Maybe<double> ObjectGetDouble(v8::Local<v8::Context> context,
6565
Maybe<int> ObjectGetInt(v8::Local<v8::Context> context,
6666
Local<Object> object,
6767
const char* property) {
68-
HandleScope handle_scope(context->GetIsolate());
68+
HandleScope handle_scope(v8::Isolate::GetCurrent());
6969
Local<Value> value;
70-
if (!object->Get(context, OneByteString(context->GetIsolate(), property))
70+
if (!object->Get(context, OneByteString(v8::Isolate::GetCurrent(), property))
7171
.ToLocal(&value) ||
7272
!value->IsInt32()) {
7373
return Nothing<int>();
@@ -79,9 +79,9 @@ Maybe<int> ObjectGetInt(v8::Local<v8::Context> context,
7979
Maybe<bool> ObjectGetBool(v8::Local<v8::Context> context,
8080
Local<Object> object,
8181
const char* property) {
82-
HandleScope handle_scope(context->GetIsolate());
82+
HandleScope handle_scope(v8::Isolate::GetCurrent());
8383
Local<Value> value;
84-
if (!object->Get(context, OneByteString(context->GetIsolate(), property))
84+
if (!object->Get(context, OneByteString(v8::Isolate::GetCurrent(), property))
8585
.ToLocal(&value) ||
8686
!value->IsBoolean()) {
8787
return Nothing<bool>();
@@ -93,9 +93,9 @@ Maybe<bool> ObjectGetBool(v8::Local<v8::Context> context,
9393
MaybeLocal<v8::Object> ObjectGetObject(v8::Local<v8::Context> context,
9494
Local<Object> object,
9595
const char* property) {
96-
EscapableHandleScope handle_scope(context->GetIsolate());
96+
EscapableHandleScope handle_scope(v8::Isolate::GetCurrent());
9797
Local<Value> value;
98-
if (!object->Get(context, OneByteString(context->GetIsolate(), property))
98+
if (!object->Get(context, OneByteString(v8::Isolate::GetCurrent(), property))
9999
.ToLocal(&value) ||
100100
!value->IsObject()) {
101101
return {};
@@ -106,7 +106,7 @@ MaybeLocal<v8::Object> ObjectGetObject(v8::Local<v8::Context> context,
106106
// Create a protocol::Network::Headers from the v8 object.
107107
std::unique_ptr<protocol::Network::Headers> createHeadersFromObject(
108108
v8::Local<v8::Context> context, Local<Object> headers_obj) {
109-
HandleScope handle_scope(context->GetIsolate());
109+
HandleScope handle_scope(v8::Isolate::GetCurrent());
110110

111111
std::unique_ptr<protocol::DictionaryValue> dict =
112112
protocol::DictionaryValue::create();
@@ -127,7 +127,7 @@ std::unique_ptr<protocol::Network::Headers> createHeadersFromObject(
127127
.To(&property_value)) {
128128
return {};
129129
}
130-
dict->setString(ToProtocolString(context->GetIsolate(), property_name),
130+
dict->setString(ToProtocolString(v8::Isolate::GetCurrent(), property_name),
131131
property_value);
132132
}
133133

@@ -137,7 +137,7 @@ std::unique_ptr<protocol::Network::Headers> createHeadersFromObject(
137137
// Create a protocol::Network::Request from the v8 object.
138138
std::unique_ptr<protocol::Network::Request> createRequestFromObject(
139139
v8::Local<v8::Context> context, Local<Object> request) {
140-
HandleScope handle_scope(context->GetIsolate());
140+
HandleScope handle_scope(v8::Isolate::GetCurrent());
141141
protocol::String url;
142142
if (!ObjectGetProtocolString(context, request, "url").To(&url)) {
143143
return {};
@@ -169,7 +169,7 @@ std::unique_ptr<protocol::Network::Request> createRequestFromObject(
169169
// Create a protocol::Network::Response from the v8 object.
170170
std::unique_ptr<protocol::Network::Response> createResponseFromObject(
171171
v8::Local<v8::Context> context, Local<Object> response) {
172-
HandleScope handle_scope(context->GetIsolate());
172+
HandleScope handle_scope(v8::Isolate::GetCurrent());
173173
protocol::String url;
174174
if (!ObjectGetProtocolString(context, response, "url").To(&url)) {
175175
return {};
@@ -210,7 +210,7 @@ std::unique_ptr<protocol::Network::Response> createResponseFromObject(
210210

211211
std::unique_ptr<protocol::Network::WebSocketResponse> createWebSocketResponse(
212212
v8::Local<v8::Context> context, Local<Object> response) {
213-
HandleScope handle_scope(context->GetIsolate());
213+
HandleScope handle_scope(v8::Isolate::GetCurrent());
214214
int status;
215215
if (!ObjectGetInt(context, response, "status").To(&status)) {
216216
return {};

src/js_native_api_v8.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class RefTracker {
5353
struct napi_env__ {
5454
explicit napi_env__(v8::Local<v8::Context> context,
5555
int32_t module_api_version)
56-
: isolate(context->GetIsolate()),
56+
: isolate(v8::Isolate::GetCurrent()),
5757
context_persistent(isolate, context),
5858
module_api_version(module_api_version) {
5959
napi_clear_last_error(this);

src/module_wrap.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ModuleCacheKey ModuleCacheKey::From(Local<Context> context,
9999
Local<String> specifier,
100100
Local<FixedArray> import_attributes) {
101101
CHECK_EQ(import_attributes->Length() % elements_per_attribute, 0);
102-
Isolate* isolate = context->GetIsolate();
102+
Isolate* isolate = Isolate::GetCurrent();
103103
std::size_t h1 = specifier->GetIdentityHash();
104104
size_t num_attributes = import_attributes->Length() / elements_per_attribute;
105105
ImportAttributeVector attributes;
@@ -202,7 +202,7 @@ ModuleWrap* ModuleWrap::GetLinkedRequest(uint32_t index) {
202202
object()->GetInternalField(kLinkedRequestsSlot);
203203
DCHECK(linked_requests_data->IsValue() &&
204204
linked_requests_data.As<Value>()->IsArray());
205-
Local<Array> requests = linked_requests_data.As<Array>();
205+
Local<Array> requests = linked_requests_data.As<Value>().As<Array>();
206206

207207
CHECK_LT(index, requests->Length());
208208

@@ -1022,7 +1022,7 @@ MaybeLocal<Module> ModuleWrap::ResolveModuleCallback(
10221022
return {};
10231023
}
10241024
DCHECK_NOT_NULL(resolved_module);
1025-
return resolved_module->module_.Get(context->GetIsolate());
1025+
return resolved_module->module_.Get(Isolate::GetCurrent());
10261026
}
10271027

10281028
// static
@@ -1046,7 +1046,7 @@ MaybeLocal<Object> ModuleWrap::ResolveSourceCallback(
10461046
Local<String> url = resolved_module->object()
10471047
->GetInternalField(ModuleWrap::kURLSlot)
10481048
.As<String>();
1049-
THROW_ERR_SOURCE_PHASE_NOT_DEFINED(context->GetIsolate(), url);
1049+
THROW_ERR_SOURCE_PHASE_NOT_DEFINED(Isolate::GetCurrent(), url);
10501050
return {};
10511051
}
10521052
CHECK(module_source_object->IsObject());
@@ -1059,7 +1059,7 @@ Maybe<ModuleWrap*> ModuleWrap::ResolveModule(
10591059
Local<String> specifier,
10601060
Local<FixedArray> import_attributes,
10611061
Local<Module> referrer) {
1062-
Isolate* isolate = context->GetIsolate();
1062+
Isolate* isolate = Isolate::GetCurrent();
10631063
Environment* env = Environment::GetCurrent(context);
10641064
if (env == nullptr) {
10651065
THROW_ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE(isolate);
@@ -1104,7 +1104,7 @@ static MaybeLocal<Promise> ImportModuleDynamicallyWithPhase(
11041104
Local<String> specifier,
11051105
ModuleImportPhase phase,
11061106
Local<FixedArray> import_attributes) {
1107-
Isolate* isolate = context->GetIsolate();
1107+
Isolate* isolate = Isolate::GetCurrent();
11081108
Environment* env = Environment::GetCurrent(context);
11091109
if (env == nullptr) {
11101110
THROW_ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE(isolate);
@@ -1343,7 +1343,7 @@ MaybeLocal<Module> LinkRequireFacadeWithOriginal(
13431343
Local<FixedArray> import_attributes,
13441344
Local<Module> referrer) {
13451345
Environment* env = Environment::GetCurrent(context);
1346-
Isolate* isolate = context->GetIsolate();
1346+
Isolate* isolate = Isolate::GetCurrent();
13471347
CHECK(specifier->Equals(context, env->original_string()).ToChecked());
13481348
CHECK(!env->temporary_required_module_facade_original.IsEmpty());
13491349
return env->temporary_required_module_facade_original.Get(isolate);

src/node.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ NODE_DEPRECATED("Use v8::Date::ValueOf() directly",
10021002

10031003
#define NODE_DEFINE_CONSTANT(target, constant) \
10041004
do { \
1005-
v8::Isolate* isolate = target->GetIsolate(); \
1005+
v8::Isolate* isolate = v8::Isolate::GetCurrent(); \
10061006
v8::Local<v8::Context> context = isolate->GetCurrentContext(); \
10071007
v8::Local<v8::String> constant_name = v8::String::NewFromUtf8Literal( \
10081008
isolate, #constant, v8::NewStringType::kInternalized); \
@@ -1018,7 +1018,7 @@ NODE_DEPRECATED("Use v8::Date::ValueOf() directly",
10181018

10191019
#define NODE_DEFINE_HIDDEN_CONSTANT(target, constant) \
10201020
do { \
1021-
v8::Isolate* isolate = target->GetIsolate(); \
1021+
v8::Isolate* isolate = v8::Isolate::GetCurrent(); \
10221022
v8::Local<v8::Context> context = isolate->GetCurrentContext(); \
10231023
v8::Local<v8::String> constant_name = v8::String::NewFromUtf8Literal( \
10241024
isolate, #constant, v8::NewStringType::kInternalized); \

src/node_blob.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ void BlobBindingData::Deserialize(Local<Context> context,
556556
int index,
557557
InternalFieldInfoBase* info) {
558558
DCHECK_IS_SNAPSHOT_SLOT(index);
559-
HandleScope scope(context->GetIsolate());
559+
HandleScope scope(Isolate::GetCurrent());
560560
Realm* realm = Realm::GetCurrent(context);
561561
BlobBindingData* binding = realm->AddBindingData<BlobBindingData>(holder);
562562
CHECK_NOT_NULL(binding);

0 commit comments

Comments
 (0)