Skip to content

Commit 2a07c92

Browse files
backesvictorgomes
authored andcommitted
Avoid deprecated GetIsolate methods (#219)
These methods already return the value read from TLS. They will be deprecated and removed soon, so switch to using TLS directly.
1 parent 9ca8ace commit 2a07c92

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/util-inl.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,14 @@ v8::Maybe<void> FromV8Array(v8::Local<v8::Context> context,
328328
std::vector<v8::Global<v8::Value>>* out) {
329329
uint32_t count = js_array->Length();
330330
out->reserve(count);
331-
ArrayIterationData data{out, context->GetIsolate()};
331+
ArrayIterationData data{out, v8::Isolate::GetCurrent()};
332332
return js_array->Iterate(context, PushItemToVector, &data);
333333
}
334334

335335
v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
336336
std::string_view str,
337337
v8::Isolate* isolate) {
338-
if (isolate == nullptr) isolate = context->GetIsolate();
338+
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
339339
if (str.size() >= static_cast<size_t>(v8::String::kMaxLength)) [[unlikely]] {
340340
// V8 only has a TODO comment about adding an exception when the maximum
341341
// string size is exceeded.
@@ -351,7 +351,7 @@ v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
351351
v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
352352
v8_inspector::StringView str,
353353
v8::Isolate* isolate) {
354-
if (isolate == nullptr) isolate = context->GetIsolate();
354+
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
355355
if (str.length() >= static_cast<size_t>(v8::String::kMaxLength))
356356
[[unlikely]] {
357357
// V8 only has a TODO comment about adding an exception when the maximum
@@ -378,7 +378,7 @@ template <typename T>
378378
v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
379379
const std::vector<T>& vec,
380380
v8::Isolate* isolate) {
381-
if (isolate == nullptr) isolate = context->GetIsolate();
381+
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
382382
v8::EscapableHandleScope handle_scope(isolate);
383383

384384
MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
@@ -395,7 +395,7 @@ template <typename T>
395395
v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
396396
const std::set<T>& set,
397397
v8::Isolate* isolate) {
398-
if (isolate == nullptr) isolate = context->GetIsolate();
398+
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
399399
v8::Local<v8::Set> set_js = v8::Set::New(isolate);
400400
v8::HandleScope handle_scope(isolate);
401401

@@ -414,7 +414,7 @@ template <typename T, std::size_t U>
414414
v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
415415
const std::ranges::elements_view<T, U>& vec,
416416
v8::Isolate* isolate) {
417-
if (isolate == nullptr) isolate = context->GetIsolate();
417+
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
418418
v8::EscapableHandleScope handle_scope(isolate);
419419

420420
MaybeStackBuffer<v8::Local<v8::Value>, 128> arr(vec.size());
@@ -433,7 +433,7 @@ template <typename T, typename U>
433433
v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
434434
const std::unordered_map<T, U>& map,
435435
v8::Isolate* isolate) {
436-
if (isolate == nullptr) isolate = context->GetIsolate();
436+
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
437437
v8::EscapableHandleScope handle_scope(isolate);
438438

439439
v8::Local<v8::Map> ret = v8::Map::New(isolate);
@@ -476,7 +476,7 @@ template <typename T, typename>
476476
v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
477477
const T& number,
478478
v8::Isolate* isolate) {
479-
if (isolate == nullptr) isolate = context->GetIsolate();
479+
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
480480
return ConvertNumberToV8Value(isolate, number);
481481
}
482482

@@ -489,7 +489,7 @@ v8::Local<v8::Array> ToV8ValuePrimitiveArray(v8::Local<v8::Context> context,
489489
std::is_floating_point_v<T>,
490490
"Only primitive types (bool, integral, floating-point) are supported.");
491491

492-
if (isolate == nullptr) isolate = context->GetIsolate();
492+
if (isolate == nullptr) isolate = v8::Isolate::GetCurrent();
493493
v8::EscapableHandleScope handle_scope(isolate);
494494

495495
v8::LocalVector<v8::Value> elements(isolate);

0 commit comments

Comments
 (0)