Skip to content

Commit e0301a9

Browse files
committed
src: fix upcoming v8 deprecation warnings
Fixes: nodejs#18909
1 parent 4e1f090 commit e0301a9

8 files changed

+23
-20
lines changed

src/inspector_js_api.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static void AsyncTaskScheduledWrapper(const FunctionCallbackInfo<Value>& args) {
230230

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

236236
CHECK(args[1]->IsNumber());

src/node.cc

+8-5
Original file line numberDiff line numberDiff line change
@@ -1269,9 +1269,12 @@ void AppendExceptionLine(Environment* env,
12691269
ScriptOrigin origin = message->GetScriptOrigin();
12701270
node::Utf8Value filename(env->isolate(), message->GetScriptResourceName());
12711271
const char* filename_string = *filename;
1272-
int linenum = message->GetLineNumber();
1272+
Maybe<int> line_number_maybe = message->GetLineNumber(env->context());
1273+
int linenum = line_number_maybe.FromJust();
12731274
// Print line of source code.
1274-
node::Utf8Value sourceline(env->isolate(), message->GetSourceLine());
1275+
MaybeLocal<String> source_line_maybe = message->GetSourceLine(env->context());
1276+
node::Utf8Value sourceline(env->isolate(),
1277+
source_line_maybe.ToLocalChecked());
12751278
const char* sourceline_string = *sourceline;
12761279
if (strstr(sourceline_string, "node-do-not-add-exception-line") != nullptr)
12771280
return;
@@ -1419,7 +1422,7 @@ static void ReportException(Environment* env,
14191422
name.IsEmpty() ||
14201423
name->IsUndefined()) {
14211424
// Not an error object. Just print as-is.
1422-
String::Utf8Value message(er);
1425+
String::Utf8Value message(env->isolate(), er);
14231426

14241427
PrintErrorString("%s\n", *message ? *message :
14251428
"<toString() threw exception>");
@@ -1471,13 +1474,13 @@ static Local<Value> ExecuteString(Environment* env,
14711474
exit(3);
14721475
}
14731476

1474-
Local<Value> result = script.ToLocalChecked()->Run();
1477+
MaybeLocal<Value> result = script.ToLocalChecked()->Run(env->context());
14751478
if (result.IsEmpty()) {
14761479
ReportException(env, try_catch);
14771480
exit(4);
14781481
}
14791482

1480-
return scope.Escape(result);
1483+
return scope.Escape(result.ToLocalChecked());
14811484
}
14821485

14831486

src/node_api.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3315,7 +3315,7 @@ class Work : public node::AsyncResource {
33153315
void* data = nullptr)
33163316
: AsyncResource(env->isolate,
33173317
async_resource,
3318-
*v8::String::Utf8Value(async_resource_name)),
3318+
*v8::String::Utf8Value(env->isolate, async_resource_name)),
33193319
_env(env),
33203320
_data(data),
33213321
_execute(execute),

src/node_buffer.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
854854
size_t result = haystack_length;
855855

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

@@ -887,7 +887,7 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
887887
}
888888
result *= 2;
889889
} else if (enc == UTF8) {
890-
String::Utf8Value needle_value(needle);
890+
String::Utf8Value needle_value(args.GetIsolate(), needle);
891891
if (*needle_value == nullptr)
892892
return args.GetReturnValue().Set(-1);
893893

src/node_contextify.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -1088,21 +1088,21 @@ class ContextifyScript : public BaseObject {
10881088
PersistentToLocal(env->isolate(), wrapped_script->script_);
10891089
Local<Script> script = unbound_script->BindToCurrentContext();
10901090

1091-
Local<Value> result;
1091+
MaybeLocal<Value> result;
10921092
bool timed_out = false;
10931093
bool received_signal = false;
10941094
if (break_on_sigint && timeout != -1) {
10951095
Watchdog wd(env->isolate(), timeout, &timed_out);
10961096
SigintWatchdog swd(env->isolate(), &received_signal);
1097-
result = script->Run();
1097+
result = script->Run(env->context());
10981098
} else if (break_on_sigint) {
10991099
SigintWatchdog swd(env->isolate(), &received_signal);
1100-
result = script->Run();
1100+
result = script->Run(env->context());
11011101
} else if (timeout != -1) {
11021102
Watchdog wd(env->isolate(), timeout, &timed_out);
1103-
result = script->Run();
1103+
result = script->Run(env->context());
11041104
} else {
1105-
result = script->Run();
1105+
result = script->Run(env->context());
11061106
}
11071107

11081108
if (timed_out || received_signal) {
@@ -1133,7 +1133,7 @@ class ContextifyScript : public BaseObject {
11331133
return false;
11341134
}
11351135

1136-
args.GetReturnValue().Set(result);
1136+
args.GetReturnValue().Set(result.ToLocalChecked());
11371137
return true;
11381138
}
11391139

src/node_crypto.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -4255,7 +4255,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
42554255

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

4258-
String::Utf8Value passphrase(args[3]);
4258+
String::Utf8Value passphrase(args.GetIsolate(), args[3]);
42594259

42604260
unsigned char* out_value = nullptr;
42614261
size_t out_len = 0;

src/node_v8.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void UpdateHeapSpaceStatisticsBuffer(const FunctionCallbackInfo<Value>& args) {
114114

115115
void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) {
116116
CHECK(args[0]->IsString());
117-
String::Utf8Value flags(args[0]);
117+
String::Utf8Value flags(args.GetIsolate(), args[0]);
118118
V8::SetFlagsFromString(*flags, flags.length());
119119
}
120120

src/string_bytes.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ size_t StringBytes::Write(Isolate* isolate,
369369
auto ext = str->GetExternalOneByteStringResource();
370370
nbytes = base64_decode(buf, buflen, ext->data(), ext->length());
371371
} else {
372-
String::Value value(str);
372+
String::Value value(isolate, str);
373373
nbytes = base64_decode(buf, buflen, *value, value.length());
374374
}
375375
*chars_written = nbytes;
@@ -380,7 +380,7 @@ size_t StringBytes::Write(Isolate* isolate,
380380
auto ext = str->GetExternalOneByteStringResource();
381381
nbytes = hex_decode(buf, buflen, ext->data(), ext->length());
382382
} else {
383-
String::Value value(str);
383+
String::Value value(isolate, str);
384384
nbytes = hex_decode(buf, buflen, *value, value.length());
385385
}
386386
*chars_written = nbytes;
@@ -479,7 +479,7 @@ size_t StringBytes::Size(Isolate* isolate,
479479
return str->Length() * sizeof(uint16_t);
480480

481481
case BASE64: {
482-
String::Value value(str);
482+
String::Value value(isolate, str);
483483
return base64_decoded_size(*value, value.length());
484484
}
485485

0 commit comments

Comments
 (0)