Skip to content

Commit

Permalink
src: fix upcoming V8 deprecation warnings
Browse files Browse the repository at this point in the history
PR-URL: nodejs#19490
Fixes: nodejs#18909
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
SirR4T authored and blattersturm committed Nov 2, 2018
1 parent a14e56b commit af07964
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/inspector_js_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static void AsyncTaskScheduledWrapper(const FunctionCallbackInfo<Value>& args) {

CHECK(args[0]->IsString());
Local<String> task_name = args[0].As<String>();
String::Value task_name_value(task_name);
String::Value task_name_value(args.GetIsolate(), task_name);
StringView task_name_view(*task_name_value, task_name_value.length());

CHECK(args[1]->IsNumber());
Expand Down
12 changes: 7 additions & 5 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1606,9 +1606,11 @@ void AppendExceptionLine(Environment* env,
ScriptOrigin origin = message->GetScriptOrigin();
node::Utf8Value filename(env->isolate(), message->GetScriptResourceName());
const char* filename_string = *filename;
int linenum = message->GetLineNumber();
int linenum = message->GetLineNumber(env->context()).FromJust();
// Print line of source code.
node::Utf8Value sourceline(env->isolate(), message->GetSourceLine());
MaybeLocal<String> source_line_maybe = message->GetSourceLine(env->context());
node::Utf8Value sourceline(env->isolate(),
source_line_maybe.ToLocalChecked());
const char* sourceline_string = *sourceline;

// Because of how node modules work, all scripts are wrapped with a
Expand Down Expand Up @@ -1752,7 +1754,7 @@ static void ReportException(Environment* env,
name.IsEmpty() ||
name->IsUndefined()) {
// Not an error object. Just print as-is.
String::Utf8Value message(er);
String::Utf8Value message(env->isolate(), er);

PrintErrorString("%s\n", *message ? *message :
"<toString() threw exception>");
Expand Down Expand Up @@ -1800,13 +1802,13 @@ static Local<Value> ExecuteString(Environment* env,
exit(3);
}

Local<Value> result = script.ToLocalChecked()->Run();
MaybeLocal<Value> result = script.ToLocalChecked()->Run(env->context());
if (result.IsEmpty()) {
ReportException(env, try_catch);
exit(4);
}

return scope.Escape(result);
return scope.Escape(result.ToLocalChecked());
}


Expand Down
2 changes: 1 addition & 1 deletion src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3359,7 +3359,7 @@ class Work : public node::AsyncResource {
void* data = nullptr)
: AsyncResource(env->isolate,
async_resource,
*v8::String::Utf8Value(async_resource_name)),
*v8::String::Utf8Value(env->isolate, async_resource_name)),
_env(env),
_data(data),
_execute(execute),
Expand Down
4 changes: 2 additions & 2 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
size_t result = haystack_length;

if (enc == UCS2) {
String::Value needle_value(needle);
String::Value needle_value(args.GetIsolate(), needle);
if (*needle_value == nullptr)
return args.GetReturnValue().Set(-1);

Expand Down Expand Up @@ -1035,7 +1035,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
}
result *= 2;
} else if (enc == UTF8) {
String::Utf8Value needle_value(needle);
String::Utf8Value needle_value(args.GetIsolate(), needle);
if (*needle_value == nullptr)
return args.GetReturnValue().Set(-1);

Expand Down
12 changes: 6 additions & 6 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -979,21 +979,21 @@ class ContextifyScript : public BaseObject {
PersistentToLocal(env->isolate(), wrapped_script->script_);
Local<Script> script = unbound_script->BindToCurrentContext();

Local<Value> result;
MaybeLocal<Value> result;
bool timed_out = false;
bool received_signal = false;
if (break_on_sigint && timeout != -1) {
Watchdog wd(env->isolate(), timeout, &timed_out);
SigintWatchdog swd(env->isolate(), &received_signal);
result = script->Run();
result = script->Run(env->context());
} else if (break_on_sigint) {
SigintWatchdog swd(env->isolate(), &received_signal);
result = script->Run();
result = script->Run(env->context());
} else if (timeout != -1) {
Watchdog wd(env->isolate(), timeout, &timed_out);
result = script->Run();
result = script->Run(env->context());
} else {
result = script->Run();
result = script->Run(env->context());
}

if (timed_out || received_signal) {
Expand Down Expand Up @@ -1024,7 +1024,7 @@ class ContextifyScript : public BaseObject {
return false;
}

args.GetReturnValue().Set(result);
args.GetReturnValue().Set(result.ToLocalChecked());
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4741,7 +4741,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {

int padding = args[2]->Uint32Value();

String::Utf8Value passphrase(args[3]);
String::Utf8Value passphrase(args.GetIsolate(), args[3]);

unsigned char* out_value = nullptr;
size_t out_len = 0;
Expand Down
10 changes: 2 additions & 8 deletions src/node_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,8 @@ void UpdateHeapSpaceStatisticsBuffer(const FunctionCallbackInfo<Value>& args) {


void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

if (args.Length() < 1)
return env->ThrowTypeError("v8 flag is required");
if (!args[0]->IsString())
return env->ThrowTypeError("v8 flag must be a string");

String::Utf8Value flags(args[0]);
CHECK(args[0]->IsString());
String::Utf8Value flags(args.GetIsolate(), args[0]);
V8::SetFlagsFromString(*flags, flags.length());
}

Expand Down
6 changes: 3 additions & 3 deletions src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ size_t StringBytes::Write(Isolate* isolate,
if (is_extern) {
nbytes = base64_decode(buf, buflen, data, external_nbytes);
} else {
String::Value value(str);
String::Value value(isolate, str);
nbytes = base64_decode(buf, buflen, *value, value.length());
}
if (chars_written != nullptr) {
Expand All @@ -422,7 +422,7 @@ size_t StringBytes::Write(Isolate* isolate,
if (is_extern) {
nbytes = hex_decode(buf, buflen, data, external_nbytes);
} else {
String::Value value(str);
String::Value value(isolate, str);
nbytes = hex_decode(buf, buflen, *value, value.length());
}
if (chars_written != nullptr) {
Expand Down Expand Up @@ -532,7 +532,7 @@ size_t StringBytes::Size(Isolate* isolate,
break;

case BASE64: {
String::Value value(str);
String::Value value(isolate, str);
data_size = base64_decoded_size(*value, value.length());
break;
}
Expand Down

0 comments on commit af07964

Please sign in to comment.