Skip to content

Commit 92d2d79

Browse files
danbevBridgeAR
authored andcommitted
test: fix NewFromUtf8 compiler warning
Currently there are a number of compiler warnings like the following: ../binding.cc:6:41: warning: 'NewFromUtf8' is deprecated: Use maybe version [-Wdeprecated-declarations] args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world")); ^ /node/deps/v8/include/v8.h:2883:10: note: 'NewFromUtf8' has been explicitly marked deprecated here static V8_DEPRECATE_SOON( ^ /node/deps/v8/include/v8config.h:341:29: note: expanded from macro 'V8_DEPRECATE_SOON' declarator __attribute__((deprecated(message))) ^ This commit updates the code to use the maybe versions. PR-URL: #24216 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 0c4facf commit 92d2d79

File tree

11 files changed

+56
-21
lines changed

11 files changed

+56
-21
lines changed

doc/api/addons.md

+35-11
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ namespace demo {
6363
using v8::FunctionCallbackInfo;
6464
using v8::Isolate;
6565
using v8::Local;
66+
using v8::NewStringType;
6667
using v8::Object;
6768
using v8::String;
6869
using v8::Value;
6970

7071
void Method(const FunctionCallbackInfo<Value>& args) {
7172
Isolate* isolate = args.GetIsolate();
72-
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
73+
args.GetReturnValue().Set(String::NewFromUtf8(
74+
isolate, "world", NewStringType::kNormal).ToLocalChecked());
7375
}
7476

7577
void Initialize(Local<Object> exports) {
@@ -464,6 +466,7 @@ using v8::Exception;
464466
using v8::FunctionCallbackInfo;
465467
using v8::Isolate;
466468
using v8::Local;
469+
using v8::NewStringType;
467470
using v8::Number;
468471
using v8::Object;
469472
using v8::String;
@@ -479,14 +482,18 @@ void Add(const FunctionCallbackInfo<Value>& args) {
479482
if (args.Length() < 2) {
480483
// Throw an Error that is passed back to JavaScript
481484
isolate->ThrowException(Exception::TypeError(
482-
String::NewFromUtf8(isolate, "Wrong number of arguments")));
485+
String::NewFromUtf8(isolate,
486+
"Wrong number of arguments",
487+
NewStringType::kNormal).ToLocalChecked()));
483488
return;
484489
}
485490

486491
// Check the argument types
487492
if (!args[0]->IsNumber() || !args[1]->IsNumber()) {
488493
isolate->ThrowException(Exception::TypeError(
489-
String::NewFromUtf8(isolate, "Wrong arguments")));
494+
String::NewFromUtf8(isolate,
495+
"Wrong arguments",
496+
NewStringType::kNormal).ToLocalChecked()));
490497
return;
491498
}
492499

@@ -534,6 +541,7 @@ using v8::Function;
534541
using v8::FunctionCallbackInfo;
535542
using v8::Isolate;
536543
using v8::Local;
544+
using v8::NewStringType;
537545
using v8::Null;
538546
using v8::Object;
539547
using v8::String;
@@ -543,7 +551,10 @@ void RunCallback(const FunctionCallbackInfo<Value>& args) {
543551
Isolate* isolate = args.GetIsolate();
544552
Local<Function> cb = Local<Function>::Cast(args[0]);
545553
const unsigned argc = 1;
546-
Local<Value> argv[argc] = { String::NewFromUtf8(isolate, "hello world") };
554+
Local<Value> argv[argc] = {
555+
String::NewFromUtf8(isolate,
556+
"hello world",
557+
NewStringType::kNormal).ToLocalChecked() };
547558
cb->Call(Null(isolate), argc, argv);
548559
}
549560

@@ -591,6 +602,7 @@ using v8::Context;
591602
using v8::FunctionCallbackInfo;
592603
using v8::Isolate;
593604
using v8::Local;
605+
using v8::NewStringType;
594606
using v8::Object;
595607
using v8::String;
596608
using v8::Value;
@@ -600,7 +612,9 @@ void CreateObject(const FunctionCallbackInfo<Value>& args) {
600612
Local<Context> context = isolate->GetCurrentContext();
601613

602614
Local<Object> obj = Object::New(isolate);
603-
obj->Set(String::NewFromUtf8(isolate, "msg"),
615+
obj->Set(String::NewFromUtf8(isolate,
616+
"msg",
617+
NewStringType::kNormal).ToLocalChecked(),
604618
args[0]->ToString(context).ToLocalChecked());
605619

606620
args.GetReturnValue().Set(obj);
@@ -644,13 +658,15 @@ using v8::FunctionCallbackInfo;
644658
using v8::FunctionTemplate;
645659
using v8::Isolate;
646660
using v8::Local;
661+
using v8::NewStringType;
647662
using v8::Object;
648663
using v8::String;
649664
using v8::Value;
650665

651666
void MyFunction(const FunctionCallbackInfo<Value>& args) {
652667
Isolate* isolate = args.GetIsolate();
653-
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello world"));
668+
args.GetReturnValue().Set(String::NewFromUtf8(
669+
isolate, "hello world", NewStringType::kNormal).ToLocalChecked());
654670
}
655671

656672
void CreateFunction(const FunctionCallbackInfo<Value>& args) {
@@ -661,7 +677,8 @@ void CreateFunction(const FunctionCallbackInfo<Value>& args) {
661677
Local<Function> fn = tpl->GetFunction(context).ToLocalChecked();
662678

663679
// omit this to make it anonymous
664-
fn->SetName(String::NewFromUtf8(isolate, "theFunction"));
680+
fn->SetName(String::NewFromUtf8(
681+
isolate, "theFunction", NewStringType::kNormal).ToLocalChecked());
665682

666683
args.GetReturnValue().Set(fn);
667684
}
@@ -757,6 +774,7 @@ using v8::FunctionCallbackInfo;
757774
using v8::FunctionTemplate;
758775
using v8::Isolate;
759776
using v8::Local;
777+
using v8::NewStringType;
760778
using v8::Number;
761779
using v8::Object;
762780
using v8::Persistent;
@@ -776,15 +794,17 @@ void MyObject::Init(Local<Object> exports) {
776794

777795
// Prepare constructor template
778796
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
779-
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject"));
797+
tpl->SetClassName(String::NewFromUtf8(
798+
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked());
780799
tpl->InstanceTemplate()->SetInternalFieldCount(1);
781800

782801
// Prototype
783802
NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne);
784803

785804
Local<Context> context = isolate->GetCurrentContext();
786805
constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
787-
exports->Set(String::NewFromUtf8(isolate, "MyObject"),
806+
exports->Set(String::NewFromUtf8(
807+
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked(),
788808
tpl->GetFunction(context).ToLocalChecked());
789809
}
790810

@@ -952,6 +972,7 @@ using v8::FunctionCallbackInfo;
952972
using v8::FunctionTemplate;
953973
using v8::Isolate;
954974
using v8::Local;
975+
using v8::NewStringType;
955976
using v8::Number;
956977
using v8::Object;
957978
using v8::Persistent;
@@ -969,7 +990,8 @@ MyObject::~MyObject() {
969990
void MyObject::Init(Isolate* isolate) {
970991
// Prepare constructor template
971992
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
972-
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject"));
993+
tpl->SetClassName(String::NewFromUtf8(
994+
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked());
973995
tpl->InstanceTemplate()->SetInternalFieldCount(1);
974996

975997
// Prototype
@@ -1167,6 +1189,7 @@ using v8::FunctionCallbackInfo;
11671189
using v8::FunctionTemplate;
11681190
using v8::Isolate;
11691191
using v8::Local;
1192+
using v8::NewStringType;
11701193
using v8::Object;
11711194
using v8::Persistent;
11721195
using v8::String;
@@ -1183,7 +1206,8 @@ MyObject::~MyObject() {
11831206
void MyObject::Init(Isolate* isolate) {
11841207
// Prepare constructor template
11851208
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
1186-
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject"));
1209+
tpl->SetClassName(String::NewFromUtf8(
1210+
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked());
11871211
tpl->InstanceTemplate()->SetInternalFieldCount(1);
11881212

11891213
Local<Context> context = isolate->GetCurrentContext();

test/addons/dlopen-ping-pong/binding.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using v8::FunctionCallbackInfo;
1515
using v8::Isolate;
1616
using v8::Local;
1717
using v8::Object;
18+
using v8::NewStringType;
1819
using v8::String;
1920
using v8::Value;
2021

@@ -33,7 +34,8 @@ void LoadLibrary(const FunctionCallbackInfo<Value>& args) {
3334
void Ping(const FunctionCallbackInfo<Value>& args) {
3435
Isolate* isolate = args.GetIsolate();
3536
assert(ping_func != nullptr);
36-
args.GetReturnValue().Set(String::NewFromUtf8(isolate, ping_func()));
37+
args.GetReturnValue().Set(String::NewFromUtf8(
38+
isolate, ping_func(), NewStringType::kNormal).ToLocalChecked());
3739
}
3840

3941
void init(Local<Object> exports) {

test/addons/heap-profiler/binding.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ inline void Test(const v8::FunctionCallbackInfo<v8::Value>& args) {
1919
inline void Initialize(v8::Local<v8::Object> binding) {
2020
v8::Isolate* const isolate = binding->GetIsolate();
2121
v8::Local<v8::Context> context = isolate->GetCurrentContext();
22-
binding->Set(v8::String::NewFromUtf8(isolate, "test"),
22+
binding->Set(v8::String::NewFromUtf8(
23+
isolate, "test", v8::NewStringType::kNormal).ToLocalChecked(),
2324
v8::FunctionTemplate::New(isolate, Test)
2425
->GetFunction(context)
2526
.ToLocalChecked());

test/addons/hello-world-esm/binding.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
55
v8::Isolate* isolate = args.GetIsolate();
6-
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world"));
6+
args.GetReturnValue().Set(v8::String::NewFromUtf8(
7+
isolate, "world", v8::NewStringType::kNormal).ToLocalChecked());
78
}
89

910
void init(v8::Local<v8::Object> exports) {

test/addons/hello-world-function-export/binding.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
55
v8::Isolate* isolate = args.GetIsolate();
6-
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world"));
6+
args.GetReturnValue().Set(v8::String::NewFromUtf8(
7+
isolate, "world", v8::NewStringType::kNormal).ToLocalChecked());
78
}
89

910
void init(v8::Local<v8::Object> exports, v8::Local<v8::Object> module) {

test/addons/hello-world/binding.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
55
v8::Isolate* isolate = args.GetIsolate();
6-
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world"));
6+
args.GetReturnValue().Set(v8::String::NewFromUtf8(
7+
isolate, "world", v8::NewStringType::kNormal).ToLocalChecked());
78
}
89

910
// Not using the full NODE_MODULE_INIT() macro here because we want to test the

test/addons/load-long-path/binding.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
55
v8::Isolate* isolate = args.GetIsolate();
6-
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world"));
6+
args.GetReturnValue().Set(v8::String::NewFromUtf8(
7+
isolate, "world", v8::NewStringType::kNormal).ToLocalChecked());
78
}
89

910
void init(v8::Local<v8::Object> exports) {

test/addons/new-target/binding.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ inline void NewClass(const v8::FunctionCallbackInfo<v8::Value>& args) {
1212
inline void Initialize(v8::Local<v8::Object> binding) {
1313
auto isolate = binding->GetIsolate();
1414
auto context = isolate->GetCurrentContext();
15-
binding->Set(v8::String::NewFromUtf8(isolate, "Class"),
15+
binding->Set(v8::String::NewFromUtf8(
16+
isolate, "Class", v8::NewStringType::kNormal).ToLocalChecked(),
1617
v8::FunctionTemplate::New(isolate, NewClass)
1718
->GetFunction(context)
1819
.ToLocalChecked());

test/addons/openssl-binding/binding.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ inline void Initialize(v8::Local<v8::Object> exports,
2222
v8::Local<v8::Value> module,
2323
v8::Local<v8::Context> context) {
2424
auto isolate = context->GetIsolate();
25-
auto key = v8::String::NewFromUtf8(isolate, "randomBytes");
25+
auto key = v8::String::NewFromUtf8(
26+
isolate, "randomBytes", v8::NewStringType::kNormal).ToLocalChecked();
2627
auto value = v8::FunctionTemplate::New(isolate, RandomBytes)
2728
->GetFunction(context)
2829
.ToLocalChecked();

test/addons/symlinked-module/binding.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
55
v8::Isolate* isolate = args.GetIsolate();
6-
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world"));
6+
args.GetReturnValue().Set(v8::String::NewFromUtf8(
7+
isolate, "world", v8::NewStringType::kNormal).ToLocalChecked());
78
}
89

910
void init(v8::Local<v8::Object> exports) {

test/addons/zlib-binding/binding.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ inline void Initialize(v8::Local<v8::Object> exports,
4545
v8::Local<v8::Value> module,
4646
v8::Local<v8::Context> context) {
4747
auto isolate = context->GetIsolate();
48-
auto key = v8::String::NewFromUtf8(isolate, "compressBytes");
48+
auto key = v8::String::NewFromUtf8(
49+
isolate, "compressBytes", v8::NewStringType::kNormal).ToLocalChecked();
4950
auto value = v8::FunctionTemplate::New(isolate, CompressBytes)
5051
->GetFunction(context)
5152
.ToLocalChecked();

0 commit comments

Comments
 (0)