Skip to content

Commit 2c95b96

Browse files
ryzokukentargos
authored andcommitted
src: remove calls to deprecated v8 functions (NewFromUtf8)
Remove all calls to deprecated v8 functions (here: String::NewFromUtf8) inside the code (src directory only). PR-URL: #21926 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0151486 commit 2c95b96

12 files changed

+89
-54
lines changed

src/cares_wrap.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,9 @@ void CanonicalizeIP(const FunctionCallbackInfo<Value>& args) {
19421942
char canonical_ip[INET6_ADDRSTRLEN];
19431943
const int af = (rc == 4 ? AF_INET : AF_INET6);
19441944
CHECK_EQ(0, uv_inet_ntop(af, &result, canonical_ip, sizeof(canonical_ip)));
1945-
args.GetReturnValue().Set(String::NewFromUtf8(isolate, canonical_ip));
1945+
v8::Local<String> val = String::NewFromUtf8(isolate, canonical_ip,
1946+
v8::NewStringType::kNormal).ToLocalChecked();
1947+
args.GetReturnValue().Set(val);
19461948
}
19471949

19481950
void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {

src/exceptions.cc

+15-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Local<Value> ErrnoException(Isolate* isolate,
3939
Local<String> path_string;
4040
if (path != nullptr) {
4141
// FIXME(bnoordhuis) It's questionable to interpret the file path as UTF-8.
42-
path_string = String::NewFromUtf8(env->isolate(), path);
42+
path_string = String::NewFromUtf8(env->isolate(), path,
43+
v8::NewStringType::kNormal).ToLocalChecked();
4344
}
4445

4546
if (path_string.IsEmpty() == false) {
@@ -68,13 +69,17 @@ static Local<String> StringFromPath(Isolate* isolate, const char* path) {
6869
#ifdef _WIN32
6970
if (strncmp(path, "\\\\?\\UNC\\", 8) == 0) {
7071
return String::Concat(FIXED_ONE_BYTE_STRING(isolate, "\\\\"),
71-
String::NewFromUtf8(isolate, path + 8));
72+
String::NewFromUtf8(isolate, path + 8,
73+
v8::NewStringType::kNormal)
74+
.ToLocalChecked());
7275
} else if (strncmp(path, "\\\\?\\", 4) == 0) {
73-
return String::NewFromUtf8(isolate, path + 4);
76+
return String::NewFromUtf8(isolate, path + 4, v8::NewStringType::kNormal)
77+
.ToLocalChecked();
7478
}
7579
#endif
7680

77-
return String::NewFromUtf8(isolate, path);
81+
return String::NewFromUtf8(isolate, path, v8::NewStringType::kNormal)
82+
.ToLocalChecked();
7883
}
7984

8085

@@ -183,7 +188,9 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
183188
Local<String> cons1 =
184189
String::Concat(message, FIXED_ONE_BYTE_STRING(isolate, " '"));
185190
Local<String> cons2 =
186-
String::Concat(cons1, String::NewFromUtf8(isolate, path));
191+
String::Concat(cons1,
192+
String::NewFromUtf8(isolate, path, v8::NewStringType::kNormal)
193+
.ToLocalChecked());
187194
Local<String> cons3 =
188195
String::Concat(cons2, FIXED_ONE_BYTE_STRING(isolate, "'"));
189196
e = Exception::Error(cons3);
@@ -195,7 +202,9 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
195202
obj->Set(env->errno_string(), Integer::New(isolate, errorno));
196203

197204
if (path != nullptr) {
198-
obj->Set(env->path_string(), String::NewFromUtf8(isolate, path));
205+
obj->Set(env->path_string(),
206+
String::NewFromUtf8(isolate, path, v8::NewStringType::kNormal)
207+
.ToLocalChecked());
199208
}
200209

201210
if (syscall != nullptr) {

src/node.cc

+23-13
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,8 @@ void AppendExceptionLine(Environment* env,
965965
arrow[off] = '\n';
966966
arrow[off + 1] = '\0';
967967

968-
Local<String> arrow_str = String::NewFromUtf8(env->isolate(), arrow);
968+
Local<String> arrow_str = String::NewFromUtf8(env->isolate(), arrow,
969+
v8::NewStringType::kNormal).ToLocalChecked();
969970

970971
const bool can_set_arrow = !arrow_str.IsEmpty() && !err_obj.IsEmpty();
971972
// If allocating arrow_str failed, print it out. There's not much else to do.
@@ -1741,7 +1742,8 @@ static void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
17411742

17421743
Local<Object> module = Object::New(env->isolate());
17431744
Local<Object> exports = Object::New(env->isolate());
1744-
Local<String> exports_prop = String::NewFromUtf8(env->isolate(), "exports");
1745+
Local<String> exports_prop = String::NewFromUtf8(env->isolate(), "exports",
1746+
v8::NewStringType::kNormal).ToLocalChecked();
17451747
module->Set(exports_prop, exports);
17461748

17471749
if (mod->nm_context_register_func != nullptr) {
@@ -1764,7 +1766,8 @@ static void ProcessTitleGetter(Local<Name> property,
17641766
const PropertyCallbackInfo<Value>& info) {
17651767
char buffer[512];
17661768
uv_get_process_title(buffer, sizeof(buffer));
1767-
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), buffer));
1769+
info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), buffer,
1770+
v8::NewStringType::kNormal).ToLocalChecked());
17681771
}
17691772

17701773

@@ -1789,7 +1792,8 @@ static void EnvGetter(Local<Name> property,
17891792
node::Utf8Value key(isolate, property);
17901793
const char* val = getenv(*key);
17911794
if (val) {
1792-
return info.GetReturnValue().Set(String::NewFromUtf8(isolate, val));
1795+
return info.GetReturnValue().Set(String::NewFromUtf8(isolate, val,
1796+
v8::NewStringType::kNormal).ToLocalChecked());
17931797
}
17941798
#else // _WIN32
17951799
node::TwoByteValue key(isolate, property);
@@ -1917,8 +1921,8 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
19171921
const int length = s ? s - var : strlen(var);
19181922
argv[idx] = String::NewFromUtf8(isolate,
19191923
var,
1920-
String::kNormalString,
1921-
length);
1924+
v8::NewStringType::kNormal,
1925+
length).ToLocalChecked();
19221926
if (++idx >= arraysize(argv)) {
19231927
fn->Call(ctx, envarr, idx, argv).ToLocalChecked();
19241928
idx = 0;
@@ -2195,14 +2199,16 @@ void SetupProcessObject(Environment* env,
21952199
// process.argv
21962200
Local<Array> arguments = Array::New(env->isolate(), argc);
21972201
for (int i = 0; i < argc; ++i) {
2198-
arguments->Set(i, String::NewFromUtf8(env->isolate(), argv[i]));
2202+
arguments->Set(i, String::NewFromUtf8(env->isolate(), argv[i],
2203+
v8::NewStringType::kNormal).ToLocalChecked());
21992204
}
22002205
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "argv"), arguments);
22012206

22022207
// process.execArgv
22032208
Local<Array> exec_arguments = Array::New(env->isolate(), exec_argc);
22042209
for (int i = 0; i < exec_argc; ++i) {
2205-
exec_arguments->Set(i, String::NewFromUtf8(env->isolate(), exec_argv[i]));
2210+
exec_arguments->Set(i, String::NewFromUtf8(env->isolate(), exec_argv[i],
2211+
v8::NewStringType::kNormal).ToLocalChecked());
22062212
}
22072213
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execArgv"),
22082214
exec_arguments);
@@ -2234,7 +2240,8 @@ void SetupProcessObject(Environment* env,
22342240
if (eval_string) {
22352241
READONLY_PROPERTY(process,
22362242
"_eval",
2237-
String::NewFromUtf8(env->isolate(), eval_string));
2243+
String::NewFromUtf8(env->isolate(), eval_string,
2244+
v8::NewStringType::kNormal).ToLocalChecked());
22382245
}
22392246

22402247
// -p, --print
@@ -2257,7 +2264,9 @@ void SetupProcessObject(Environment* env,
22572264
Local<Array> array = Array::New(env->isolate());
22582265
for (unsigned int i = 0; i < preload_modules.size(); ++i) {
22592266
Local<String> module = String::NewFromUtf8(env->isolate(),
2260-
preload_modules[i].c_str());
2267+
preload_modules[i].c_str(),
2268+
v8::NewStringType::kNormal)
2269+
.ToLocalChecked();
22612270
array->Set(i, module);
22622271
}
22632272
READONLY_PROPERTY(process,
@@ -2342,10 +2351,11 @@ void SetupProcessObject(Environment* env,
23422351
if (uv_exepath(exec_path, &exec_path_len) == 0) {
23432352
exec_path_value = String::NewFromUtf8(env->isolate(),
23442353
exec_path,
2345-
String::kNormalString,
2346-
exec_path_len);
2354+
v8::NewStringType::kNormal,
2355+
exec_path_len).ToLocalChecked();
23472356
} else {
2348-
exec_path_value = String::NewFromUtf8(env->isolate(), argv[0]);
2357+
exec_path_value = String::NewFromUtf8(env->isolate(), argv[0],
2358+
v8::NewStringType::kNormal).ToLocalChecked();
23492359
}
23502360
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "execPath"),
23512361
exec_path_value);

src/node.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ NODE_EXTERN struct uv_loop_s* GetCurrentEventLoop(v8::Isolate* isolate);
303303
v8::Isolate* isolate = target->GetIsolate(); \
304304
v8::Local<v8::Context> context = isolate->GetCurrentContext(); \
305305
v8::Local<v8::String> constant_name = \
306-
v8::String::NewFromUtf8(isolate, #constant); \
306+
v8::String::NewFromUtf8(isolate, #constant, \
307+
v8::NewStringType::kNormal).ToLocalChecked(); \
307308
v8::Local<v8::Number> constant_value = \
308309
v8::Number::New(isolate, static_cast<double>(constant)); \
309310
v8::PropertyAttribute constant_attributes = \
@@ -344,7 +345,8 @@ inline void NODE_SET_METHOD(v8::Local<v8::Template> recv,
344345
v8::HandleScope handle_scope(isolate);
345346
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
346347
callback);
347-
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name);
348+
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
349+
v8::NewStringType::kNormal).ToLocalChecked();
348350
t->SetClassName(fn_name);
349351
recv->Set(fn_name, t);
350352
}
@@ -358,7 +360,8 @@ inline void NODE_SET_METHOD(v8::Local<v8::Object> recv,
358360
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
359361
callback);
360362
v8::Local<v8::Function> fn = t->GetFunction();
361-
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name);
363+
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
364+
v8::NewStringType::kNormal).ToLocalChecked();
362365
fn->SetName(fn_name);
363366
recv->Set(fn_name, fn);
364367
}
@@ -374,7 +377,8 @@ inline void NODE_SET_PROTOTYPE_METHOD(v8::Local<v8::FunctionTemplate> recv,
374377
v8::Local<v8::Signature> s = v8::Signature::New(isolate, recv);
375378
v8::Local<v8::FunctionTemplate> t =
376379
v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), s);
377-
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name);
380+
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
381+
v8::NewStringType::kNormal).ToLocalChecked();
378382
t->SetClassName(fn_name);
379383
recv->PrototypeTemplate()->Set(fn_name, t);
380384
}

src/node_crypto.cc

+14-14
Original file line numberDiff line numberDiff line change
@@ -1563,8 +1563,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
15631563
BIO_get_mem_ptr(bio.get(), &mem);
15641564
info->Set(context, env->subject_string(),
15651565
String::NewFromUtf8(env->isolate(), mem->data,
1566-
String::kNormalString,
1567-
mem->length)).FromJust();
1566+
NewStringType::kNormal,
1567+
mem->length).ToLocalChecked()).FromJust();
15681568
}
15691569
USE(BIO_reset(bio.get()));
15701570

@@ -1573,8 +1573,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
15731573
BIO_get_mem_ptr(bio.get(), &mem);
15741574
info->Set(context, env->issuer_string(),
15751575
String::NewFromUtf8(env->isolate(), mem->data,
1576-
String::kNormalString,
1577-
mem->length)).FromJust();
1576+
NewStringType::kNormal,
1577+
mem->length).ToLocalChecked()).FromJust();
15781578
}
15791579
USE(BIO_reset(bio.get()));
15801580

@@ -1601,8 +1601,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
16011601
BIO_get_mem_ptr(bio.get(), &mem);
16021602
info->Set(context, keys[i],
16031603
String::NewFromUtf8(env->isolate(), mem->data,
1604-
String::kNormalString,
1605-
mem->length)).FromJust();
1604+
NewStringType::kNormal,
1605+
mem->length).ToLocalChecked()).FromJust();
16061606

16071607
USE(BIO_reset(bio.get()));
16081608
}
@@ -1620,8 +1620,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
16201620
BIO_get_mem_ptr(bio.get(), &mem);
16211621
info->Set(context, env->modulus_string(),
16221622
String::NewFromUtf8(env->isolate(), mem->data,
1623-
String::kNormalString,
1624-
mem->length)).FromJust();
1623+
NewStringType::kNormal,
1624+
mem->length).ToLocalChecked()).FromJust();
16251625
USE(BIO_reset(bio.get()));
16261626

16271627
uint64_t exponent_word = static_cast<uint64_t>(BN_get_word(e));
@@ -1635,8 +1635,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
16351635
BIO_get_mem_ptr(bio.get(), &mem);
16361636
info->Set(context, env->exponent_string(),
16371637
String::NewFromUtf8(env->isolate(), mem->data,
1638-
String::kNormalString,
1639-
mem->length)).FromJust();
1638+
NewStringType::kNormal,
1639+
mem->length).ToLocalChecked()).FromJust();
16401640
USE(BIO_reset(bio.get()));
16411641

16421642
int size = i2d_RSA_PUBKEY(rsa.get(), nullptr);
@@ -1655,16 +1655,16 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
16551655
BIO_get_mem_ptr(bio.get(), &mem);
16561656
info->Set(context, env->valid_from_string(),
16571657
String::NewFromUtf8(env->isolate(), mem->data,
1658-
String::kNormalString,
1659-
mem->length)).FromJust();
1658+
NewStringType::kNormal,
1659+
mem->length).ToLocalChecked()).FromJust();
16601660
USE(BIO_reset(bio.get()));
16611661

16621662
ASN1_TIME_print(bio.get(), X509_get_notAfter(cert));
16631663
BIO_get_mem_ptr(bio.get(), &mem);
16641664
info->Set(context, env->valid_to_string(),
16651665
String::NewFromUtf8(env->isolate(), mem->data,
1666-
String::kNormalString,
1667-
mem->length)).FromJust();
1666+
NewStringType::kNormal,
1667+
mem->length).ToLocalChecked()).FromJust();
16681668
bio.reset();
16691669

16701670
unsigned char md[EVP_MAX_MD_SIZE];

src/node_file.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,8 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
794794
Local<String> chars_string =
795795
String::NewFromUtf8(env->isolate(),
796796
&chars[start],
797-
String::kNormalString,
798-
size);
797+
v8::NewStringType::kNormal,
798+
size).ToLocalChecked();
799799
args.GetReturnValue().Set(chars_string);
800800
}
801801
}

src/node_i18n.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ void GetVersion(const FunctionCallbackInfo<Value>& args) {
552552
TYPE_ICU ","
553553
TYPE_UNICODE ","
554554
TYPE_CLDR ","
555-
TYPE_TZ));
555+
TYPE_TZ, v8::NewStringType::kNormal).ToLocalChecked());
556556
} else {
557557
CHECK_GE(args.Length(), 1);
558558
CHECK(args[0]->IsString());
@@ -565,7 +565,7 @@ void GetVersion(const FunctionCallbackInfo<Value>& args) {
565565
// Success.
566566
args.GetReturnValue().Set(
567567
String::NewFromUtf8(env->isolate(),
568-
versionString));
568+
versionString, v8::NewStringType::kNormal).ToLocalChecked());
569569
}
570570
}
571571
}

src/node_internals.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ struct sockaddr;
7272
do { \
7373
v8::Isolate* isolate = target->GetIsolate(); \
7474
v8::Local<v8::String> constant_name = \
75-
v8::String::NewFromUtf8(isolate, name); \
75+
v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kNormal) \
76+
.ToLocalChecked(); \
7677
v8::Local<v8::String> constant_value = \
77-
v8::String::NewFromUtf8(isolate, constant); \
78+
v8::String::NewFromUtf8(isolate, constant, v8::NewStringType::kNormal)\
79+
.ToLocalChecked(); \
7880
v8::PropertyAttribute constant_attributes = \
7981
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete); \
8082
target->DefineOwnProperty(isolate->GetCurrentContext(), \

src/node_os.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
261261
// contain non-ASCII characters. On UNIX, it's just a binary string with
262262
// no particular encoding but we treat it as a one-byte Latin-1 string.
263263
#ifdef _WIN32
264-
name = String::NewFromUtf8(env->isolate(), raw_name);
264+
name = String::NewFromUtf8(env->isolate(), raw_name,
265+
v8::NewStringType::kNormal).ToLocalChecked();
265266
#else
266267
name = OneByteString(env->isolate(), raw_name);
267268
#endif
@@ -335,8 +336,8 @@ static void GetHomeDirectory(const FunctionCallbackInfo<Value>& args) {
335336

336337
Local<String> home = String::NewFromUtf8(env->isolate(),
337338
buf,
338-
String::kNormalString,
339-
len);
339+
v8::NewStringType::kNormal,
340+
len).ToLocalChecked();
340341
args.GetReturnValue().Set(home);
341342
}
342343

src/node_perf.cc

+8-4
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,18 @@ inline void InitObject(const PerformanceEntry& entry, Local<Object> obj) {
7575
env->name_string(),
7676
String::NewFromUtf8(isolate,
7777
entry.name().c_str(),
78-
String::kNormalString),
79-
attr).FromJust();
78+
v8::NewStringType::kNormal)
79+
.ToLocalChecked(),
80+
attr)
81+
.FromJust();
8082
obj->DefineOwnProperty(context,
8183
FIXED_ONE_BYTE_STRING(isolate, "entryType"),
8284
String::NewFromUtf8(isolate,
8385
entry.type().c_str(),
84-
String::kNormalString),
85-
attr).FromJust();
86+
v8::NewStringType::kNormal)
87+
.ToLocalChecked(),
88+
attr)
89+
.FromJust();
8690
obj->DefineOwnProperty(context,
8791
FIXED_ONE_BYTE_STRING(isolate, "startTime"),
8892
Number::New(isolate, entry.startTime()),

src/node_process.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ void Cwd(const FunctionCallbackInfo<Value>& args) {
108108

109109
Local<String> cwd = String::NewFromUtf8(env->isolate(),
110110
buf,
111-
String::kNormalString,
112-
cwd_len);
111+
v8::NewStringType::kNormal,
112+
cwd_len).ToLocalChecked();
113113
args.GetReturnValue().Set(cwd);
114114
}
115115

src/spawn_sync.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,10 @@ Local<Object> SyncProcessRunner::BuildResultObject() {
683683
if (term_signal_ > 0)
684684
js_result->Set(context, env()->signal_string(),
685685
String::NewFromUtf8(env()->isolate(),
686-
signo_string(term_signal_))).FromJust();
686+
signo_string(term_signal_),
687+
v8::NewStringType::kNormal)
688+
.ToLocalChecked())
689+
.FromJust();
687690
else
688691
js_result->Set(context, env()->signal_string(),
689692
Null(env()->isolate())).FromJust();

0 commit comments

Comments
 (0)