Skip to content

Commit 866bc4a

Browse files
authored
Replace GetIsolate() by Isolate::GetCurrent() (#224)
* via gemini: Replace GetIsolate by Isolate::GetCurrent() * Manual fixes
1 parent 16dcce7 commit 866bc4a

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
@@ -636,7 +636,7 @@ std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create(
636636

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

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

688688
// When `IsCodeGenerationFromStringsAllowed` is true, V8 takes the fast path
@@ -761,7 +761,7 @@ Maybe<void> InitializeContextRuntime(Local<Context> context) {
761761
}
762762

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

767767
// Delete `Intl.v8BreakIterator`
@@ -786,7 +786,7 @@ Maybe<void> InitializeBaseContextForSnapshot(Local<Context> context) {
786786
}
787787

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

792792
// Initialize the default values.
@@ -804,7 +804,7 @@ Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) {
804804
MaybeLocal<Object> InitializePrivateSymbols(Local<Context> context,
805805
IsolateData* isolate_data) {
806806
CHECK(isolate_data);
807-
Isolate* isolate = context->GetIsolate();
807+
Isolate* isolate = Isolate::GetCurrent();
808808
EscapableHandleScope scope(isolate);
809809
Context::Scope context_scope(context);
810810

@@ -828,7 +828,7 @@ MaybeLocal<Object> InitializePrivateSymbols(Local<Context> context,
828828
MaybeLocal<Object> InitializePerIsolateSymbols(Local<Context> context,
829829
IsolateData* isolate_data) {
830830
CHECK(isolate_data);
831-
Isolate* isolate = context->GetIsolate();
831+
Isolate* isolate = Isolate::GetCurrent();
832832
EscapableHandleScope scope(isolate);
833833
Context::Scope context_scope(context);
834834

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

src/crypto/crypto_context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ bool ArrayOfStringsToX509s(Local<Context> context,
948948
Local<Array> cert_array,
949949
std::vector<X509*>* certs) {
950950
ClearErrorOnReturn clear_error_on_return;
951-
Isolate* isolate = context->GetIsolate();
951+
Isolate* isolate = Isolate::GetCurrent();
952952
Environment* env = Environment::GetCurrent(context);
953953
uint32_t array_length = cert_array->Length();
954954

src/crypto/crypto_x509.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ MaybeLocal<Value> ToV8Value(Local<Context> context, BIOPointer&& bio) {
105105
return {};
106106
BUF_MEM* mem = bio;
107107
Local<Value> ret;
108-
if (!String::NewFromUtf8(context->GetIsolate(),
108+
if (!String::NewFromUtf8(Isolate::GetCurrent(),
109109
mem->data,
110110
NewStringType::kNormal,
111111
mem->length)
@@ -119,7 +119,7 @@ MaybeLocal<Value> ToV8Value(Local<Context> context, const BIOPointer& bio) {
119119
return {};
120120
BUF_MEM* mem = bio;
121121
Local<Value> ret;
122-
if (!String::NewFromUtf8(context->GetIsolate(),
122+
if (!String::NewFromUtf8(Isolate::GetCurrent(),
123123
mem->data,
124124
NewStringType::kNormal,
125125
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
@@ -1750,10 +1750,10 @@ void AsyncHooks::Deserialize(Local<Context> context) {
17501750
context->GetDataFromSnapshotOnce<Array>(
17511751
info_->js_execution_async_resources).ToLocalChecked();
17521752
} else {
1753-
js_execution_async_resources = Array::New(context->GetIsolate());
1753+
js_execution_async_resources = Array::New(Isolate::GetCurrent());
17541754
}
17551755
js_execution_async_resources_.Reset(
1756-
context->GetIsolate(), js_execution_async_resources);
1756+
Isolate::GetCurrent(), js_execution_async_resources);
17571757

17581758
// The native_execution_async_resources_ field requires v8::Local<> instances
17591759
// for async calls whose resources were on the stack as JS objects when they
@@ -1793,7 +1793,7 @@ AsyncHooks::SerializeInfo AsyncHooks::Serialize(Local<Context> context,
17931793
info.async_id_fields = async_id_fields_.Serialize(context, creator);
17941794
if (!js_execution_async_resources_.IsEmpty()) {
17951795
info.js_execution_async_resources = creator->AddData(
1796-
context, js_execution_async_resources_.Get(context->GetIsolate()));
1796+
context, js_execution_async_resources_.Get(Isolate::GetCurrent()));
17971797
CHECK_NE(info.js_execution_async_resources, 0);
17981798
} else {
17991799
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
@@ -77,7 +77,7 @@ ModuleCacheKey ModuleCacheKey::From(Local<Context> context,
7777
Local<String> specifier,
7878
Local<FixedArray> import_attributes) {
7979
CHECK_EQ(import_attributes->Length() % elements_per_attribute, 0);
80-
Isolate* isolate = context->GetIsolate();
80+
Isolate* isolate = Isolate::GetCurrent();
8181
std::size_t h1 = specifier->GetIdentityHash();
8282
size_t num_attributes = import_attributes->Length() / elements_per_attribute;
8383
ImportAttributeVector attributes;
@@ -178,7 +178,7 @@ ModuleWrap* ModuleWrap::GetLinkedRequest(uint32_t index) {
178178
object()->GetInternalField(kLinkedRequestsSlot);
179179
DCHECK(linked_requests_data->IsValue() &&
180180
linked_requests_data.As<Value>()->IsArray());
181-
Local<Array> requests = linked_requests_data.As<Array>();
181+
Local<Array> requests = linked_requests_data.As<Value>().As<Array>();
182182

183183
CHECK_LT(index, requests->Length());
184184

@@ -1000,7 +1000,7 @@ MaybeLocal<Module> ModuleWrap::ResolveModuleCallback(
10001000
return {};
10011001
}
10021002
DCHECK_NOT_NULL(resolved_module);
1003-
return resolved_module->module_.Get(context->GetIsolate());
1003+
return resolved_module->module_.Get(Isolate::GetCurrent());
10041004
}
10051005

10061006
// static
@@ -1024,7 +1024,7 @@ MaybeLocal<Object> ModuleWrap::ResolveSourceCallback(
10241024
Local<String> url = resolved_module->object()
10251025
->GetInternalField(ModuleWrap::kURLSlot)
10261026
.As<String>();
1027-
THROW_ERR_SOURCE_PHASE_NOT_DEFINED(context->GetIsolate(), url);
1027+
THROW_ERR_SOURCE_PHASE_NOT_DEFINED(Isolate::GetCurrent(), url);
10281028
return {};
10291029
}
10301030
CHECK(module_source_object->IsObject());
@@ -1037,7 +1037,7 @@ Maybe<ModuleWrap*> ModuleWrap::ResolveModule(
10371037
Local<String> specifier,
10381038
Local<FixedArray> import_attributes,
10391039
Local<Module> referrer) {
1040-
Isolate* isolate = context->GetIsolate();
1040+
Isolate* isolate = Isolate::GetCurrent();
10411041
Environment* env = Environment::GetCurrent(context);
10421042
if (env == nullptr) {
10431043
THROW_ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE(isolate);
@@ -1082,7 +1082,7 @@ static MaybeLocal<Promise> ImportModuleDynamicallyWithPhase(
10821082
Local<String> specifier,
10831083
ModuleImportPhase phase,
10841084
Local<FixedArray> import_attributes) {
1085-
Isolate* isolate = context->GetIsolate();
1085+
Isolate* isolate = Isolate::GetCurrent();
10861086
Environment* env = Environment::GetCurrent(context);
10871087
if (env == nullptr) {
10881088
THROW_ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE(isolate);
@@ -1321,7 +1321,7 @@ MaybeLocal<Module> LinkRequireFacadeWithOriginal(
13211321
Local<FixedArray> import_attributes,
13221322
Local<Module> referrer) {
13231323
Environment* env = Environment::GetCurrent(context);
1324-
Isolate* isolate = context->GetIsolate();
1324+
Isolate* isolate = Isolate::GetCurrent();
13251325
CHECK(specifier->Equals(context, env->original_string()).ToChecked());
13261326
CHECK(!env->temporary_required_module_facade_original.IsEmpty());
13271327
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
@@ -557,7 +557,7 @@ void BlobBindingData::Deserialize(Local<Context> context,
557557
int index,
558558
InternalFieldInfoBase* info) {
559559
DCHECK_IS_SNAPSHOT_SLOT(index);
560-
HandleScope scope(context->GetIsolate());
560+
HandleScope scope(Isolate::GetCurrent());
561561
Realm* realm = Realm::GetCurrent(context);
562562
BlobBindingData* binding = realm->AddBindingData<BlobBindingData>(holder);
563563
CHECK_NOT_NULL(binding);

0 commit comments

Comments
 (0)