Skip to content

Commit fdf8d17

Browse files
targosnodejs-github-bot
authored andcommitted
doc,src,test: replace use of deprecated GetIsolate
`Isolate::GetCurrent()` should be used instead as it returns the same thing. Refs: v8/v8@5c4a937
1 parent fc36918 commit fdf8d17

Some content is hidden

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

48 files changed

+130
-135
lines changed

doc/api/addons.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static void Method(const v8::FunctionCallbackInfo<v8::Value>& info) {
223223

224224
// Initialize this addon to be context-aware.
225225
NODE_MODULE_INIT(/* exports, module, context */) {
226-
Isolate* isolate = context->GetIsolate();
226+
Isolate* isolate = Isolate::GetCurrent();
227227

228228
// Create a new instance of `AddonData` for this instance of the addon and
229229
// tie its life cycle to that of the Node.js environment.
@@ -320,7 +320,7 @@ static void sanity_check(void*) {
320320

321321
// Initialize this addon to be context-aware.
322322
NODE_MODULE_INIT(/* exports, module, context */) {
323-
Isolate* isolate = context->GetIsolate();
323+
Isolate* isolate = Isolate::GetCurrent();
324324

325325
AddEnvironmentCleanupHook(isolate, sanity_check, nullptr);
326326
AddEnvironmentCleanupHook(isolate, cleanup_cb2, cookie);
@@ -879,7 +879,7 @@ MyObject::~MyObject() {
879879
}
880880

881881
void MyObject::Init(Local<Object> exports) {
882-
Isolate* isolate = exports->GetIsolate();
882+
Isolate* isolate = Isolate::GetCurrent();
883883
Local<Context> context = isolate->GetCurrentContext();
884884

885885
Local<ObjectTemplate> addon_data_tpl = ObjectTemplate::New(isolate);
@@ -1013,7 +1013,7 @@ void CreateObject(const FunctionCallbackInfo<Value>& args) {
10131013
}
10141014

10151015
void InitAll(Local<Object> exports, Local<Object> module) {
1016-
MyObject::Init(exports->GetIsolate());
1016+
MyObject::Init();
10171017

10181018
NODE_SET_METHOD(module, "exports", CreateObject);
10191019
}
@@ -1039,7 +1039,7 @@ namespace demo {
10391039
10401040
class MyObject : public node::ObjectWrap {
10411041
public:
1042-
static void Init(v8::Isolate* isolate);
1042+
static void Init();
10431043
static void NewInstance(const v8::FunctionCallbackInfo<v8::Value>& args);
10441044
10451045
private:
@@ -1089,7 +1089,8 @@ MyObject::MyObject(double value) : value_(value) {
10891089
MyObject::~MyObject() {
10901090
}
10911091

1092-
void MyObject::Init(Isolate* isolate) {
1092+
void MyObject::Init() {
1093+
Isolate* isolate = Isolate::GetCurrent();
10931094
// Prepare constructor template
10941095
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
10951096
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked());
@@ -1235,7 +1236,7 @@ void Add(const FunctionCallbackInfo<Value>& args) {
12351236
}
12361237

12371238
void InitAll(Local<Object> exports) {
1238-
MyObject::Init(exports->GetIsolate());
1239+
MyObject::Init();
12391240

12401241
NODE_SET_METHOD(exports, "createObject", CreateObject);
12411242
NODE_SET_METHOD(exports, "add", Add);
@@ -1261,7 +1262,7 @@ namespace demo {
12611262
12621263
class MyObject : public node::ObjectWrap {
12631264
public:
1264-
static void Init(v8::Isolate* isolate);
1265+
static void Init();
12651266
static void NewInstance(const v8::FunctionCallbackInfo<v8::Value>& args);
12661267
inline double value() const { return value_; }
12671268
@@ -1310,7 +1311,8 @@ MyObject::MyObject(double value) : value_(value) {
13101311
MyObject::~MyObject() {
13111312
}
13121313

1313-
void MyObject::Init(Isolate* isolate) {
1314+
void MyObject::Init() {
1315+
Isolate* isolate = Isolate::GetCurrent();
13141316
// Prepare constructor template
13151317
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
13161318
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked());

src/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ Typical ways of accessing the current `Isolate` in the Node.js code are:
9494

9595
* Given a `FunctionCallbackInfo` for a [binding function][],
9696
using `args.GetIsolate()`.
97-
* Given a [`Context`][], using `context->GetIsolate()`.
9897
* Given a [`Environment`][], using `env->isolate()`.
9998
* Given a [`Realm`][], using `realm->isolate()`.
99+
* Calling `Isolate::GetCurrent()`.
100100

101101
### V8 JavaScript values
102102

@@ -191,7 +191,7 @@ function getFoo(obj) {
191191
```cpp
192192
v8::Local<v8::Value> GetFoo(v8::Local<v8::Context> context,
193193
v8::Local<v8::Object> obj) {
194-
v8::Isolate* isolate = context->GetIsolate();
194+
v8::Isolate* isolate = Isolate::GetCurrent();
195195
v8::EscapableHandleScope handle_scope(isolate);
196196

197197
// The 'foo_string' handle cannot be returned from this function because
@@ -753,7 +753,7 @@ using `.ToLocal()` and `.To()` and returning early in case there is an error:
753753
// This could also return a v8::MaybeLocal<v8::Number>, for example.
754754
v8::Maybe<double> SumNumbers(v8::Local<v8::Context> context,
755755
v8::Local<v8::Array> array_of_integers) {
756-
v8::Isolate* isolate = context->GetIsolate();
756+
v8::Isolate* isolate = Isolate::GetCurrent();
757757
v8::HandleScope handle_scope(isolate);
758758

759759
double sum = 0;

src/api/environment.cc

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

626626
MaybeLocal<Object> GetPerContextExports(Local<Context> context,
627627
IsolateData* isolate_data) {
628-
Isolate* isolate = context->GetIsolate();
628+
Isolate* isolate = Isolate::GetCurrent();
629629
EscapableHandleScope handle_scope(isolate);
630630

631631
Local<Object> global = context->Global();
@@ -671,7 +671,7 @@ void ProtoThrower(const FunctionCallbackInfo<Value>& info) {
671671
// This runs at runtime, regardless of whether the context
672672
// is created from a snapshot.
673673
Maybe<void> InitializeContextRuntime(Local<Context> context) {
674-
Isolate* isolate = context->GetIsolate();
674+
Isolate* isolate = Isolate::GetCurrent();
675675
HandleScope handle_scope(isolate);
676676

677677
// When `IsCodeGenerationFromStringsAllowed` is true, V8 takes the fast path
@@ -750,7 +750,7 @@ Maybe<void> InitializeContextRuntime(Local<Context> context) {
750750
}
751751

752752
Maybe<void> InitializeBaseContextForSnapshot(Local<Context> context) {
753-
Isolate* isolate = context->GetIsolate();
753+
Isolate* isolate = Isolate::GetCurrent();
754754
HandleScope handle_scope(isolate);
755755

756756
// Delete `Intl.v8BreakIterator`
@@ -775,7 +775,7 @@ Maybe<void> InitializeBaseContextForSnapshot(Local<Context> context) {
775775
}
776776

777777
Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) {
778-
Isolate* isolate = context->GetIsolate();
778+
Isolate* isolate = Isolate::GetCurrent();
779779
HandleScope handle_scope(isolate);
780780

781781
// Initialize the default values.
@@ -793,7 +793,7 @@ Maybe<void> InitializeMainContextForSnapshot(Local<Context> context) {
793793
MaybeLocal<Object> InitializePrivateSymbols(Local<Context> context,
794794
IsolateData* isolate_data) {
795795
CHECK(isolate_data);
796-
Isolate* isolate = context->GetIsolate();
796+
Isolate* isolate = Isolate::GetCurrent();
797797
EscapableHandleScope scope(isolate);
798798
Context::Scope context_scope(context);
799799

@@ -817,7 +817,7 @@ MaybeLocal<Object> InitializePrivateSymbols(Local<Context> context,
817817
MaybeLocal<Object> InitializePerIsolateSymbols(Local<Context> context,
818818
IsolateData* isolate_data) {
819819
CHECK(isolate_data);
820-
Isolate* isolate = context->GetIsolate();
820+
Isolate* isolate = Isolate::GetCurrent();
821821
EscapableHandleScope scope(isolate);
822822
Context::Scope context_scope(context);
823823

@@ -843,7 +843,7 @@ MaybeLocal<Object> InitializePerIsolateSymbols(Local<Context> context,
843843
Maybe<void> InitializePrimordials(Local<Context> context,
844844
IsolateData* isolate_data) {
845845
// Run per-context JS files.
846-
Isolate* isolate = context->GetIsolate();
846+
Isolate* isolate = Isolate::GetCurrent();
847847
Context::Scope context_scope(context);
848848
Local<Object> exports;
849849

src/base_object-inl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ v8::Local<v8::Object> BaseObject::object() const {
5555
v8::Local<v8::Object> BaseObject::object(v8::Isolate* isolate) const {
5656
v8::Local<v8::Object> handle = object();
5757

58-
DCHECK_EQ(handle->GetCreationContextChecked()->GetIsolate(), isolate);
5958
DCHECK_EQ(env()->isolate(), isolate);
6059

6160
return handle;

src/crypto/crypto_context.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ bool ArrayOfStringsToX509s(Local<Context> context,
969969
Local<Array> cert_array,
970970
std::vector<X509*>* certs) {
971971
ClearErrorOnReturn clear_error_on_return;
972-
Isolate* isolate = context->GetIsolate();
972+
Isolate* isolate = Isolate::GetCurrent();
973973
Environment* env = Environment::GetCurrent(context);
974974
uint32_t array_length = cert_array->Length();
975975

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,10 +1757,10 @@ void AsyncHooks::Deserialize(Local<Context> context) {
17571757
context->GetDataFromSnapshotOnce<Array>(
17581758
info_->js_execution_async_resources).ToLocalChecked();
17591759
} else {
1760-
js_execution_async_resources = Array::New(context->GetIsolate());
1760+
js_execution_async_resources = Array::New(Isolate::GetCurrent());
17611761
}
1762-
js_execution_async_resources_.Reset(
1763-
context->GetIsolate(), js_execution_async_resources);
1762+
js_execution_async_resources_.Reset(Isolate::GetCurrent(),
1763+
js_execution_async_resources);
17641764

17651765
// The native_execution_async_resources_ field requires v8::Local<> instances
17661766
// for async calls whose resources were on the stack as JS objects when they
@@ -1800,7 +1800,7 @@ AsyncHooks::SerializeInfo AsyncHooks::Serialize(Local<Context> context,
18001800
info.async_id_fields = async_id_fields_.Serialize(context, creator);
18011801
if (!js_execution_async_resources_.IsEmpty()) {
18021802
info.js_execution_async_resources = creator->AddData(
1803-
context, js_execution_async_resources_.Get(context->GetIsolate()));
1803+
context, js_execution_async_resources_.Get(Isolate::GetCurrent()));
18041804
CHECK_NE(info.js_execution_async_resources, 0);
18051805
} else {
18061806
info.js_execution_async_resources = 0;

src/inspector/network_agent.cc

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace inspector {
1616

1717
using v8::EscapableHandleScope;
1818
using v8::HandleScope;
19+
using v8::Isolate;
1920
using v8::Just;
2021
using v8::Local;
2122
using v8::Maybe;
@@ -29,31 +30,31 @@ using v8::Value;
2930
Maybe<protocol::String> ObjectGetProtocolString(v8::Local<v8::Context> context,
3031
Local<Object> object,
3132
Local<v8::String> property) {
32-
HandleScope handle_scope(context->GetIsolate());
33+
HandleScope handle_scope(Isolate::GetCurrent());
3334
Local<Value> value;
3435
if (!object->Get(context, property).ToLocal(&value) || !value->IsString()) {
3536
return Nothing<protocol::String>();
3637
}
3738
Local<v8::String> str = value.As<v8::String>();
38-
return Just(ToProtocolString(context->GetIsolate(), str));
39+
return Just(ToProtocolString(Isolate::GetCurrent(), str));
3940
}
4041

4142
// Get a protocol string property from the object.
4243
Maybe<protocol::String> ObjectGetProtocolString(v8::Local<v8::Context> context,
4344
Local<Object> object,
4445
const char* property) {
45-
HandleScope handle_scope(context->GetIsolate());
46+
HandleScope handle_scope(Isolate::GetCurrent());
4647
return ObjectGetProtocolString(
47-
context, object, OneByteString(context->GetIsolate(), property));
48+
context, object, OneByteString(Isolate::GetCurrent(), property));
4849
}
4950

5051
// Get a protocol double property from the object.
5152
Maybe<double> ObjectGetDouble(v8::Local<v8::Context> context,
5253
Local<Object> object,
5354
const char* property) {
54-
HandleScope handle_scope(context->GetIsolate());
55+
HandleScope handle_scope(Isolate::GetCurrent());
5556
Local<Value> value;
56-
if (!object->Get(context, OneByteString(context->GetIsolate(), property))
57+
if (!object->Get(context, OneByteString(Isolate::GetCurrent(), property))
5758
.ToLocal(&value) ||
5859
!value->IsNumber()) {
5960
return Nothing<double>();
@@ -65,9 +66,9 @@ Maybe<double> ObjectGetDouble(v8::Local<v8::Context> context,
6566
Maybe<int> ObjectGetInt(v8::Local<v8::Context> context,
6667
Local<Object> object,
6768
const char* property) {
68-
HandleScope handle_scope(context->GetIsolate());
69+
HandleScope handle_scope(Isolate::GetCurrent());
6970
Local<Value> value;
70-
if (!object->Get(context, OneByteString(context->GetIsolate(), property))
71+
if (!object->Get(context, OneByteString(Isolate::GetCurrent(), property))
7172
.ToLocal(&value) ||
7273
!value->IsInt32()) {
7374
return Nothing<int>();
@@ -79,9 +80,9 @@ Maybe<int> ObjectGetInt(v8::Local<v8::Context> context,
7980
Maybe<bool> ObjectGetBool(v8::Local<v8::Context> context,
8081
Local<Object> object,
8182
const char* property) {
82-
HandleScope handle_scope(context->GetIsolate());
83+
HandleScope handle_scope(Isolate::GetCurrent());
8384
Local<Value> value;
84-
if (!object->Get(context, OneByteString(context->GetIsolate(), property))
85+
if (!object->Get(context, OneByteString(Isolate::GetCurrent(), property))
8586
.ToLocal(&value) ||
8687
!value->IsBoolean()) {
8788
return Nothing<bool>();
@@ -93,9 +94,9 @@ Maybe<bool> ObjectGetBool(v8::Local<v8::Context> context,
9394
MaybeLocal<v8::Object> ObjectGetObject(v8::Local<v8::Context> context,
9495
Local<Object> object,
9596
const char* property) {
96-
EscapableHandleScope handle_scope(context->GetIsolate());
97+
EscapableHandleScope handle_scope(Isolate::GetCurrent());
9798
Local<Value> value;
98-
if (!object->Get(context, OneByteString(context->GetIsolate(), property))
99+
if (!object->Get(context, OneByteString(Isolate::GetCurrent(), property))
99100
.ToLocal(&value) ||
100101
!value->IsObject()) {
101102
return {};
@@ -106,7 +107,7 @@ MaybeLocal<v8::Object> ObjectGetObject(v8::Local<v8::Context> context,
106107
// Create a protocol::Network::Headers from the v8 object.
107108
std::unique_ptr<protocol::Network::Headers> createHeadersFromObject(
108109
v8::Local<v8::Context> context, Local<Object> headers_obj) {
109-
HandleScope handle_scope(context->GetIsolate());
110+
HandleScope handle_scope(Isolate::GetCurrent());
110111

111112
std::unique_ptr<protocol::DictionaryValue> dict =
112113
protocol::DictionaryValue::create();
@@ -127,7 +128,7 @@ std::unique_ptr<protocol::Network::Headers> createHeadersFromObject(
127128
.To(&property_value)) {
128129
return {};
129130
}
130-
dict->setString(ToProtocolString(context->GetIsolate(), property_name),
131+
dict->setString(ToProtocolString(Isolate::GetCurrent(), property_name),
131132
property_value);
132133
}
133134

@@ -137,7 +138,7 @@ std::unique_ptr<protocol::Network::Headers> createHeadersFromObject(
137138
// Create a protocol::Network::Request from the v8 object.
138139
std::unique_ptr<protocol::Network::Request> createRequestFromObject(
139140
v8::Local<v8::Context> context, Local<Object> request) {
140-
HandleScope handle_scope(context->GetIsolate());
141+
HandleScope handle_scope(Isolate::GetCurrent());
141142
protocol::String url;
142143
if (!ObjectGetProtocolString(context, request, "url").To(&url)) {
143144
return {};
@@ -169,7 +170,7 @@ std::unique_ptr<protocol::Network::Request> createRequestFromObject(
169170
// Create a protocol::Network::Response from the v8 object.
170171
std::unique_ptr<protocol::Network::Response> createResponseFromObject(
171172
v8::Local<v8::Context> context, Local<Object> response) {
172-
HandleScope handle_scope(context->GetIsolate());
173+
HandleScope handle_scope(Isolate::GetCurrent());
173174
protocol::String url;
174175
if (!ObjectGetProtocolString(context, response, "url").To(&url)) {
175176
return {};
@@ -210,7 +211,7 @@ std::unique_ptr<protocol::Network::Response> createResponseFromObject(
210211

211212
std::unique_ptr<protocol::Network::WebSocketResponse> createWebSocketResponse(
212213
v8::Local<v8::Context> context, Local<Object> response) {
213-
HandleScope handle_scope(context->GetIsolate());
214+
HandleScope handle_scope(Isolate::GetCurrent());
214215
int status;
215216
if (!ObjectGetInt(context, response, "status").To(&status)) {
216217
return {};

src/js_native_api_v8.h

Lines changed: 2 additions & 2 deletions
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);
@@ -142,7 +142,7 @@ struct napi_env__ {
142142
}
143143
}
144144

145-
v8::Isolate* const isolate; // Shortcut for context()->GetIsolate()
145+
v8::Isolate* const isolate; // Shortcut for Isolate::GetCurrent()
146146
v8impl::Persistent<v8::Context> context_persistent;
147147

148148
v8impl::Persistent<v8::Value> last_exception;

0 commit comments

Comments
 (0)