@@ -63,13 +63,15 @@ namespace demo {
63
63
using v8::FunctionCallbackInfo;
64
64
using v8::Isolate;
65
65
using v8::Local;
66
+ using v8::NewStringType;
66
67
using v8::Object;
67
68
using v8::String;
68
69
using v8::Value;
69
70
70
71
void Method(const FunctionCallbackInfo<Value >& args) {
71
72
Isolate* isolate = args.GetIsolate();
72
- args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
73
+ args.GetReturnValue().Set(String::NewFromUtf8(
74
+ isolate, "world", NewStringType::kNormal).ToLocalChecked());
73
75
}
74
76
75
77
void Initialize(Local<Object > exports) {
@@ -464,6 +466,7 @@ using v8::Exception;
464
466
using v8::FunctionCallbackInfo;
465
467
using v8::Isolate;
466
468
using v8::Local;
469
+ using v8::NewStringType;
467
470
using v8::Number;
468
471
using v8::Object;
469
472
using v8::String;
@@ -479,14 +482,18 @@ void Add(const FunctionCallbackInfo<Value>& args) {
479
482
if (args.Length() < 2) {
480
483
// Throw an Error that is passed back to JavaScript
481
484
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()));
483
488
return;
484
489
}
485
490
486
491
// Check the argument types
487
492
if (!args[ 0] ->IsNumber() || !args[ 1] ->IsNumber()) {
488
493
isolate->ThrowException(Exception::TypeError(
489
- String::NewFromUtf8(isolate, "Wrong arguments")));
494
+ String::NewFromUtf8(isolate,
495
+ "Wrong arguments",
496
+ NewStringType::kNormal).ToLocalChecked()));
490
497
return;
491
498
}
492
499
@@ -534,6 +541,7 @@ using v8::Function;
534
541
using v8::FunctionCallbackInfo;
535
542
using v8::Isolate;
536
543
using v8::Local;
544
+ using v8::NewStringType;
537
545
using v8::Null;
538
546
using v8::Object;
539
547
using v8::String;
@@ -543,7 +551,10 @@ void RunCallback(const FunctionCallbackInfo<Value>& args) {
543
551
Isolate* isolate = args.GetIsolate();
544
552
Local<Function > cb = Local<Function >::Cast(args[ 0] );
545
553
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() };
547
558
cb->Call(Null(isolate), argc, argv);
548
559
}
549
560
@@ -591,6 +602,7 @@ using v8::Context;
591
602
using v8::FunctionCallbackInfo;
592
603
using v8::Isolate;
593
604
using v8::Local;
605
+ using v8::NewStringType;
594
606
using v8::Object;
595
607
using v8::String;
596
608
using v8::Value;
@@ -600,7 +612,9 @@ void CreateObject(const FunctionCallbackInfo<Value>& args) {
600
612
Local<Context > context = isolate->GetCurrentContext();
601
613
602
614
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(),
604
618
args[ 0] ->ToString(context).ToLocalChecked());
605
619
606
620
args.GetReturnValue().Set(obj);
@@ -644,13 +658,15 @@ using v8::FunctionCallbackInfo;
644
658
using v8::FunctionTemplate;
645
659
using v8::Isolate;
646
660
using v8::Local;
661
+ using v8::NewStringType;
647
662
using v8::Object;
648
663
using v8::String;
649
664
using v8::Value;
650
665
651
666
void MyFunction(const FunctionCallbackInfo<Value >& args) {
652
667
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());
654
670
}
655
671
656
672
void CreateFunction(const FunctionCallbackInfo<Value >& args) {
@@ -661,7 +677,8 @@ void CreateFunction(const FunctionCallbackInfo<Value>& args) {
661
677
Local<Function > fn = tpl->GetFunction(context).ToLocalChecked();
662
678
663
679
// omit this to make it anonymous
664
- fn->SetName(String::NewFromUtf8(isolate, "theFunction"));
680
+ fn->SetName(String::NewFromUtf8(
681
+ isolate, "theFunction", NewStringType::kNormal).ToLocalChecked());
665
682
666
683
args.GetReturnValue().Set(fn);
667
684
}
@@ -757,6 +774,7 @@ using v8::FunctionCallbackInfo;
757
774
using v8::FunctionTemplate;
758
775
using v8::Isolate;
759
776
using v8::Local;
777
+ using v8::NewStringType;
760
778
using v8::Number;
761
779
using v8::Object;
762
780
using v8::Persistent;
@@ -776,15 +794,17 @@ void MyObject::Init(Local<Object> exports) {
776
794
777
795
// Prepare constructor template
778
796
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());
780
799
tpl->InstanceTemplate()->SetInternalFieldCount(1);
781
800
782
801
// Prototype
783
802
NODE_SET_PROTOTYPE_METHOD(tpl, "plusOne", PlusOne);
784
803
785
804
Local<Context > context = isolate->GetCurrentContext();
786
805
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(),
788
808
tpl->GetFunction(context).ToLocalChecked());
789
809
}
790
810
@@ -952,6 +972,7 @@ using v8::FunctionCallbackInfo;
952
972
using v8::FunctionTemplate;
953
973
using v8::Isolate;
954
974
using v8::Local;
975
+ using v8::NewStringType;
955
976
using v8::Number;
956
977
using v8::Object;
957
978
using v8::Persistent;
@@ -969,7 +990,8 @@ MyObject::~MyObject() {
969
990
void MyObject::Init(Isolate* isolate) {
970
991
// Prepare constructor template
971
992
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());
973
995
tpl->InstanceTemplate()->SetInternalFieldCount(1);
974
996
975
997
// Prototype
@@ -1167,6 +1189,7 @@ using v8::FunctionCallbackInfo;
1167
1189
using v8::FunctionTemplate;
1168
1190
using v8::Isolate;
1169
1191
using v8::Local;
1192
+ using v8::NewStringType;
1170
1193
using v8::Object;
1171
1194
using v8::Persistent;
1172
1195
using v8::String;
@@ -1183,7 +1206,8 @@ MyObject::~MyObject() {
1183
1206
void MyObject::Init(Isolate* isolate) {
1184
1207
// Prepare constructor template
1185
1208
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());
1187
1211
tpl->InstanceTemplate()->SetInternalFieldCount(1);
1188
1212
1189
1213
Local<Context > context = isolate->GetCurrentContext();
0 commit comments