Skip to content

Commit 0a65727

Browse files
ryzokukentargos
authored andcommitted
src: remove calls to deprecated v8 functions (ToString)
Remove all calls to deprecated v8 functions (here: Value::ToString) inside the code (src directory only). PR-URL: #21935 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent eebcec7 commit 0a65727

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/spawn_sync.cc

+8-2
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,8 @@ int SyncProcessRunner::CopyJsString(Local<Value> js_value,
981981
if (js_value->IsString())
982982
js_string = js_value.As<String>();
983983
else
984-
js_string = js_value->ToString(env()->isolate());
984+
js_string = js_value->ToString(env()->isolate()->GetCurrentContext())
985+
.ToLocalChecked();
985986

986987
// Include space for null terminator byte.
987988
size = StringBytes::StorageSize(isolate, js_string, UTF8) + 1;
@@ -1025,7 +1026,12 @@ int SyncProcessRunner::CopyJsStringArray(Local<Value> js_value,
10251026
auto value = js_array->Get(context, i).ToLocalChecked();
10261027

10271028
if (!value->IsString())
1028-
js_array->Set(context, i, value->ToString(env()->isolate())).FromJust();
1029+
js_array
1030+
->Set(context,
1031+
i,
1032+
value->ToString(env()->isolate()->GetCurrentContext())
1033+
.ToLocalChecked())
1034+
.FromJust();
10291035

10301036
data_size += StringBytes::StorageSize(isolate, value, UTF8) + 1;
10311037
data_size = ROUND_UP(data_size, sizeof(void*));

src/string_bytes.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ size_t StringBytes::StorageSize(Isolate* isolate,
410410
return Buffer::Length(val);
411411
}
412412

413-
Local<String> str = val->ToString(isolate);
413+
Local<String> str =
414+
val->ToString(isolate->GetCurrentContext()).ToLocalChecked();
414415

415416
switch (encoding) {
416417
case ASCII:
@@ -456,7 +457,8 @@ size_t StringBytes::Size(Isolate* isolate,
456457
if (Buffer::HasInstance(val) && (encoding == BUFFER || encoding == LATIN1))
457458
return Buffer::Length(val);
458459

459-
Local<String> str = val->ToString(isolate);
460+
Local<String> str =
461+
val->ToString(isolate->GetCurrentContext()).ToLocalChecked();
460462

461463
switch (encoding) {
462464
case ASCII:

src/util.cc

+4-6
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ template <typename T>
3737
static void MakeUtf8String(Isolate* isolate,
3838
Local<Value> value,
3939
T* target) {
40-
Local<String> string = value->ToString(isolate);
41-
if (string.IsEmpty())
42-
return;
40+
Local<String> string;
41+
if (!value->ToString(isolate->GetCurrentContext()).ToLocal(&string)) return;
4342

4443
const size_t storage = StringBytes::StorageSize(isolate, string, UTF8) + 1;
4544
target->AllocateSufficientStorage(storage);
@@ -63,9 +62,8 @@ TwoByteValue::TwoByteValue(Isolate* isolate, Local<Value> value) {
6362
return;
6463
}
6564

66-
Local<String> string = value->ToString(isolate);
67-
if (string.IsEmpty())
68-
return;
65+
Local<String> string;
66+
if (!value->ToString(isolate->GetCurrentContext()).ToLocal(&string)) return;
6967

7068
// Allocate enough space to include the null terminator
7169
const size_t storage = string->Length() + 1;

0 commit comments

Comments
 (0)