Skip to content

Commit

Permalink
src: remove calls to deprecated v8 functions (ToString)
Browse files Browse the repository at this point in the history
Remove all calls to deprecated v8 functions (here: Value::ToString)
inside the code (src directory only).

PR-URL: #21935
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
ryzokuken authored and targos committed Sep 6, 2018
1 parent b9c0d5e commit ee237e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
10 changes: 8 additions & 2 deletions src/spawn_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,8 @@ int SyncProcessRunner::CopyJsString(Local<Value> js_value,
if (js_value->IsString())
js_string = js_value.As<String>();
else
js_string = js_value->ToString(env()->isolate());
js_string = js_value->ToString(env()->isolate()->GetCurrentContext())
.ToLocalChecked();

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

if (!value->IsString())
js_array->Set(context, i, value->ToString(env()->isolate())).FromJust();
js_array
->Set(context,
i,
value->ToString(env()->isolate()->GetCurrentContext())
.ToLocalChecked())
.FromJust();

data_size += StringBytes::StorageSize(isolate, value, UTF8) + 1;
data_size = ROUND_UP(data_size, sizeof(void*));
Expand Down
6 changes: 4 additions & 2 deletions src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ size_t StringBytes::StorageSize(Isolate* isolate,
return Buffer::Length(val);
}

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

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

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

switch (encoding) {
case ASCII:
Expand Down
10 changes: 4 additions & 6 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ template <typename T>
static void MakeUtf8String(Isolate* isolate,
Local<Value> value,
T* target) {
Local<String> string = value->ToString(isolate);
if (string.IsEmpty())
return;
Local<String> string;
if (!value->ToString(isolate->GetCurrentContext()).ToLocal(&string)) return;

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

Local<String> string = value->ToString(isolate);
if (string.IsEmpty())
return;
Local<String> string;
if (!value->ToString(isolate->GetCurrentContext()).ToLocal(&string)) return;

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

0 comments on commit ee237e3

Please sign in to comment.