Skip to content

Commit b2cd87e

Browse files
addaleaxMylesBorins
authored andcommitted
src,doc,test: remove String::New default parameter
`kNormal` has been the implicit default for a while now (since V8 7.6). Refs: v8/v8@e0d7f81 Backport-PR-URL: #34358 PR-URL: #34248 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 73d6792 commit b2cd87e

File tree

36 files changed

+95
-171
lines changed

36 files changed

+95
-171
lines changed

doc/api/addons.md

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,14 @@ namespace demo {
6565
using v8::FunctionCallbackInfo;
6666
using v8::Isolate;
6767
using v8::Local;
68-
using v8::NewStringType;
6968
using v8::Object;
7069
using v8::String;
7170
using v8::Value;
7271

7372
void Method(const FunctionCallbackInfo<Value>& args) {
7473
Isolate* isolate = args.GetIsolate();
7574
args.GetReturnValue().Set(String::NewFromUtf8(
76-
isolate, "world", NewStringType::kNormal).ToLocalChecked());
75+
isolate, "world").ToLocalChecked());
7776
}
7877

7978
void Initialize(Local<Object> exports) {
@@ -226,8 +225,7 @@ NODE_MODULE_INIT(/* exports, module, context */) {
226225
// per-addon-instance data we created above by passing `external` as the
227226
// third parameter to the `FunctionTemplate` constructor.
228227
exports->Set(context,
229-
String::NewFromUtf8(isolate, "method", NewStringType::kNormal)
230-
.ToLocalChecked(),
228+
String::NewFromUtf8(isolate, "method").ToLocalChecked(),
231229
FunctionTemplate::New(isolate, Method, external)
232230
->GetFunction(context).ToLocalChecked()).FromJust();
233231
}
@@ -538,7 +536,6 @@ using v8::Exception;
538536
using v8::FunctionCallbackInfo;
539537
using v8::Isolate;
540538
using v8::Local;
541-
using v8::NewStringType;
542539
using v8::Number;
543540
using v8::Object;
544541
using v8::String;
@@ -555,17 +552,15 @@ void Add(const FunctionCallbackInfo<Value>& args) {
555552
// Throw an Error that is passed back to JavaScript
556553
isolate->ThrowException(Exception::TypeError(
557554
String::NewFromUtf8(isolate,
558-
"Wrong number of arguments",
559-
NewStringType::kNormal).ToLocalChecked()));
555+
"Wrong number of arguments").ToLocalChecked()));
560556
return;
561557
}
562558

563559
// Check the argument types
564560
if (!args[0]->IsNumber() || !args[1]->IsNumber()) {
565561
isolate->ThrowException(Exception::TypeError(
566562
String::NewFromUtf8(isolate,
567-
"Wrong arguments",
568-
NewStringType::kNormal).ToLocalChecked()));
563+
"Wrong arguments").ToLocalChecked()));
569564
return;
570565
}
571566

@@ -614,7 +609,6 @@ using v8::Function;
614609
using v8::FunctionCallbackInfo;
615610
using v8::Isolate;
616611
using v8::Local;
617-
using v8::NewStringType;
618612
using v8::Null;
619613
using v8::Object;
620614
using v8::String;
@@ -627,8 +621,7 @@ void RunCallback(const FunctionCallbackInfo<Value>& args) {
627621
const unsigned argc = 1;
628622
Local<Value> argv[argc] = {
629623
String::NewFromUtf8(isolate,
630-
"hello world",
631-
NewStringType::kNormal).ToLocalChecked() };
624+
"hello world").ToLocalChecked() };
632625
cb->Call(context, Null(isolate), argc, argv).ToLocalChecked();
633626
}
634627

@@ -676,7 +669,6 @@ using v8::Context;
676669
using v8::FunctionCallbackInfo;
677670
using v8::Isolate;
678671
using v8::Local;
679-
using v8::NewStringType;
680672
using v8::Object;
681673
using v8::String;
682674
using v8::Value;
@@ -688,8 +680,7 @@ void CreateObject(const FunctionCallbackInfo<Value>& args) {
688680
Local<Object> obj = Object::New(isolate);
689681
obj->Set(context,
690682
String::NewFromUtf8(isolate,
691-
"msg",
692-
NewStringType::kNormal).ToLocalChecked(),
683+
"msg").ToLocalChecked(),
693684
args[0]->ToString(context).ToLocalChecked())
694685
.FromJust();
695686

@@ -734,15 +725,14 @@ using v8::FunctionCallbackInfo;
734725
using v8::FunctionTemplate;
735726
using v8::Isolate;
736727
using v8::Local;
737-
using v8::NewStringType;
738728
using v8::Object;
739729
using v8::String;
740730
using v8::Value;
741731

742732
void MyFunction(const FunctionCallbackInfo<Value>& args) {
743733
Isolate* isolate = args.GetIsolate();
744734
args.GetReturnValue().Set(String::NewFromUtf8(
745-
isolate, "hello world", NewStringType::kNormal).ToLocalChecked());
735+
isolate, "hello world").ToLocalChecked());
746736
}
747737

748738
void CreateFunction(const FunctionCallbackInfo<Value>& args) {
@@ -754,7 +744,7 @@ void CreateFunction(const FunctionCallbackInfo<Value>& args) {
754744

755745
// omit this to make it anonymous
756746
fn->SetName(String::NewFromUtf8(
757-
isolate, "theFunction", NewStringType::kNormal).ToLocalChecked());
747+
isolate, "theFunction").ToLocalChecked());
758748

759749
args.GetReturnValue().Set(fn);
760750
}
@@ -850,7 +840,6 @@ using v8::FunctionCallbackInfo;
850840
using v8::FunctionTemplate;
851841
using v8::Isolate;
852842
using v8::Local;
853-
using v8::NewStringType;
854843
using v8::Number;
855844
using v8::Object;
856845
using v8::ObjectTemplate;
@@ -874,8 +863,7 @@ void MyObject::Init(Local<Object> exports) {
874863

875864
// Prepare constructor template
876865
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New, addon_data);
877-
tpl->SetClassName(String::NewFromUtf8(
878-
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked());
866+
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked());
879867
tpl->InstanceTemplate()->SetInternalFieldCount(1);
880868

881869
// Prototype
@@ -884,8 +872,8 @@ void MyObject::Init(Local<Object> exports) {
884872
Local<Function> constructor = tpl->GetFunction(context).ToLocalChecked();
885873
addon_data->SetInternalField(0, constructor);
886874
exports->Set(context, String::NewFromUtf8(
887-
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked(),
888-
constructor).FromJust();
875+
isolate, "MyObject").ToLocalChecked(),
876+
constructor).FromJust();
889877
}
890878

891879
void MyObject::New(const FunctionCallbackInfo<Value>& args) {
@@ -1055,7 +1043,6 @@ using v8::FunctionTemplate;
10551043
using v8::Global;
10561044
using v8::Isolate;
10571045
using v8::Local;
1058-
using v8::NewStringType;
10591046
using v8::Number;
10601047
using v8::Object;
10611048
using v8::String;
@@ -1074,8 +1061,7 @@ MyObject::~MyObject() {
10741061
void MyObject::Init(Isolate* isolate) {
10751062
// Prepare constructor template
10761063
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
1077-
tpl->SetClassName(String::NewFromUtf8(
1078-
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked());
1064+
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked());
10791065
tpl->InstanceTemplate()->SetInternalFieldCount(1);
10801066

10811067
// Prototype
@@ -1279,7 +1265,6 @@ using v8::FunctionTemplate;
12791265
using v8::Global;
12801266
using v8::Isolate;
12811267
using v8::Local;
1282-
using v8::NewStringType;
12831268
using v8::Object;
12841269
using v8::String;
12851270
using v8::Value;
@@ -1297,8 +1282,7 @@ MyObject::~MyObject() {
12971282
void MyObject::Init(Isolate* isolate) {
12981283
// Prepare constructor template
12991284
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
1300-
tpl->SetClassName(String::NewFromUtf8(
1301-
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked());
1285+
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked());
13021286
tpl->InstanceTemplate()->SetInternalFieldCount(1);
13031287

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

src/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ v8::Local<v8::Value> GetFoo(v8::Local<v8::Context> context,
146146
// The 'foo_string' handle cannot be returned from this function because
147147
// it is not “escaped” with `.Escape()`.
148148
v8::Local<v8::String> foo_string =
149-
v8::String::NewFromUtf8(isolate,
150-
"foo",
151-
v8::NewStringType::kNormal).ToLocalChecked();
149+
v8::String::NewFromUtf8(isolate, "foo").ToLocalChecked();
152150

153151
v8::Local<v8::Value> return_value;
154152
if (obj->Get(context, foo_string).ToLocal(&return_value)) {

src/api/callback.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ using v8::Isolate;
1313
using v8::Local;
1414
using v8::MaybeLocal;
1515
using v8::MicrotasksScope;
16-
using v8::NewStringType;
1716
using v8::Object;
1817
using v8::String;
1918
using v8::Value;
@@ -214,8 +213,7 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
214213
Local<Value> argv[],
215214
async_context asyncContext) {
216215
Local<String> method_string =
217-
String::NewFromUtf8(isolate, method, NewStringType::kNormal)
218-
.ToLocalChecked();
216+
String::NewFromUtf8(isolate, method).ToLocalChecked();
219217
return MakeCallback(isolate, recv, method_string, argc, argv, asyncContext);
220218
}
221219

src/api/environment.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ MaybeLocal<Value> LoadEnvironment(
437437
// This is a slightly hacky way to convert UTF-8 to UTF-16.
438438
Local<String> str =
439439
String::NewFromUtf8(env->isolate(),
440-
main_script_source_utf8,
441-
v8::NewStringType::kNormal).ToLocalChecked();
440+
main_script_source_utf8).ToLocalChecked();
442441
auto main_utf16 = std::make_unique<String::Value>(env->isolate(), str);
443442

444443
// TODO(addaleax): Avoid having a global table for all scripts.

src/api/exceptions.cc

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ using v8::Exception;
1515
using v8::Integer;
1616
using v8::Isolate;
1717
using v8::Local;
18-
using v8::NewStringType;
1918
using v8::Object;
2019
using v8::String;
2120
using v8::Value;
@@ -42,8 +41,7 @@ Local<Value> ErrnoException(Isolate* isolate,
4241
Local<String> path_string;
4342
if (path != nullptr) {
4443
// FIXME(bnoordhuis) It's questionable to interpret the file path as UTF-8.
45-
path_string = String::NewFromUtf8(isolate, path, NewStringType::kNormal)
46-
.ToLocalChecked();
44+
path_string = String::NewFromUtf8(isolate, path).ToLocalChecked();
4745
}
4846

4947
if (path_string.IsEmpty() == false) {
@@ -78,16 +76,13 @@ static Local<String> StringFromPath(Isolate* isolate, const char* path) {
7876
return String::Concat(
7977
isolate,
8078
FIXED_ONE_BYTE_STRING(isolate, "\\\\"),
81-
String::NewFromUtf8(isolate, path + 8, NewStringType::kNormal)
82-
.ToLocalChecked());
79+
String::NewFromUtf8(isolate, path + 8).ToLocalChecked());
8380
} else if (strncmp(path, "\\\\?\\", 4) == 0) {
84-
return String::NewFromUtf8(isolate, path + 4, NewStringType::kNormal)
85-
.ToLocalChecked();
81+
return String::NewFromUtf8(isolate, path + 4).ToLocalChecked();
8682
}
8783
#endif
8884

89-
return String::NewFromUtf8(isolate, path, NewStringType::kNormal)
90-
.ToLocalChecked();
85+
return String::NewFromUtf8(isolate, path).ToLocalChecked();
9186
}
9287

9388

@@ -206,8 +201,7 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
206201
Local<String> cons2 = String::Concat(
207202
isolate,
208203
cons1,
209-
String::NewFromUtf8(isolate, path, NewStringType::kNormal)
210-
.ToLocalChecked());
204+
String::NewFromUtf8(isolate, path).ToLocalChecked());
211205
Local<String> cons3 =
212206
String::Concat(isolate, cons2, FIXED_ONE_BYTE_STRING(isolate, "'"));
213207
e = Exception::Error(cons3);
@@ -222,8 +216,7 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
222216
if (path != nullptr) {
223217
obj->Set(env->context(),
224218
env->path_string(),
225-
String::NewFromUtf8(isolate, path, NewStringType::kNormal)
226-
.ToLocalChecked())
219+
String::NewFromUtf8(isolate, path).ToLocalChecked())
227220
.Check();
228221
}
229222

src/cares_wrap.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ using v8::Int32;
6666
using v8::Integer;
6767
using v8::Isolate;
6868
using v8::Local;
69-
using v8::NewStringType;
7069
using v8::Null;
7170
using v8::Object;
7271
using v8::String;
@@ -1937,8 +1936,8 @@ void CanonicalizeIP(const FunctionCallbackInfo<Value>& args) {
19371936
char canonical_ip[INET6_ADDRSTRLEN];
19381937
const int af = (rc == 4 ? AF_INET : AF_INET6);
19391938
CHECK_EQ(0, uv_inet_ntop(af, &result, canonical_ip, sizeof(canonical_ip)));
1940-
Local<String> val = String::NewFromUtf8(isolate, canonical_ip,
1941-
NewStringType::kNormal).ToLocalChecked();
1939+
Local<String> val = String::NewFromUtf8(isolate, canonical_ip)
1940+
.ToLocalChecked();
19421941
args.GetReturnValue().Set(val);
19431942
}
19441943

src/heap_utils.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ class JSGraph : public EmbedderGraph {
118118
name_str += " ";
119119
name_str += n->Name();
120120
}
121-
if (!String::NewFromUtf8(
122-
isolate_, name_str.c_str(), v8::NewStringType::kNormal)
121+
if (!String::NewFromUtf8(isolate_, name_str.c_str())
123122
.ToLocal(&value) ||
124123
obj->Set(context, name_string, value).IsNothing() ||
125124
obj->Set(context,
@@ -168,9 +167,8 @@ class JSGraph : public EmbedderGraph {
168167
Local<Value> edge_name_value;
169168
const char* edge_name = edge.first;
170169
if (edge_name != nullptr) {
171-
if (!String::NewFromUtf8(
172-
isolate_, edge_name, v8::NewStringType::kNormal)
173-
.ToLocal(&edge_name_value)) {
170+
if (!String::NewFromUtf8(isolate_, edge_name)
171+
.ToLocal(&edge_name_value)) {
174172
return MaybeLocal<Array>();
175173
}
176174
} else {
@@ -377,8 +375,7 @@ void TriggerHeapSnapshot(const FunctionCallbackInfo<Value>& args) {
377375
DiagnosticFilename name(env, "Heap", "heapsnapshot");
378376
if (!WriteSnapshot(isolate, *name))
379377
return;
380-
if (String::NewFromUtf8(isolate, *name, v8::NewStringType::kNormal)
381-
.ToLocal(&filename_v)) {
378+
if (String::NewFromUtf8(isolate, *name).ToLocal(&filename_v)) {
382379
args.GetReturnValue().Set(filename_v);
383380
}
384381
return;

src/node_credentials.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ using v8::HandleScope;
2020
using v8::Isolate;
2121
using v8::Local;
2222
using v8::MaybeLocal;
23-
using v8::NewStringType;
2423
using v8::Object;
2524
using v8::String;
2625
using v8::TryCatch;
@@ -46,8 +45,7 @@ bool SafeGetenv(const char* key, std::string* text, Environment* env) {
4645
TryCatch ignore_errors(env->isolate());
4746
MaybeLocal<String> maybe_value = env->env_vars()->Get(
4847
env->isolate(),
49-
String::NewFromUtf8(env->isolate(), key, NewStringType::kNormal)
50-
.ToLocalChecked());
48+
String::NewFromUtf8(env->isolate(), key).ToLocalChecked());
5149
Local<String> value;
5250
if (!maybe_value.ToLocal(&value)) goto fail;
5351
String::Utf8Value utf8_value(env->isolate(), value);

src/node_crypto.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ void ThrowCryptoError(Environment* env,
392392
}
393393
HandleScope scope(env->isolate());
394394
Local<String> exception_string =
395-
String::NewFromUtf8(env->isolate(), message, NewStringType::kNormal)
396-
.ToLocalChecked();
395+
String::NewFromUtf8(env->isolate(), message).ToLocalChecked();
397396
CryptoErrorVector errors;
398397
errors.Capture();
399398
Local<Value> exception;
@@ -1017,8 +1016,8 @@ void GetRootCertificates(const FunctionCallbackInfo<Value>& args) {
10171016
for (size_t i = 0; i < arraysize(root_certs); i++) {
10181017
if (!String::NewFromOneByte(
10191018
env->isolate(),
1020-
reinterpret_cast<const uint8_t*>(root_certs[i]),
1021-
NewStringType::kNormal).ToLocal(&result[i])) {
1019+
reinterpret_cast<const uint8_t*>(root_certs[i]))
1020+
.ToLocal(&result[i])) {
10221021
return;
10231022
}
10241023
}

src/node_env_var.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ Local<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
179179
// https://github.com/libuv/libuv/pull/2473 and can be removed later.
180180
if (items[i].name[0] == '=' || items[i].name[0] == '\0') continue;
181181
#endif
182-
MaybeLocal<String> str = String::NewFromUtf8(
183-
isolate, items[i].name, NewStringType::kNormal);
182+
MaybeLocal<String> str = String::NewFromUtf8(isolate, items[i].name);
184183
if (str.IsEmpty()) {
185184
isolate->ThrowException(ERR_STRING_TOO_LONG(isolate));
186185
return Local<Array>();

src/node_i18n.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ void ICUErrorName(const FunctionCallbackInfo<Value>& args) {
338338
UErrorCode status = static_cast<UErrorCode>(args[0].As<Int32>()->Value());
339339
args.GetReturnValue().Set(
340340
String::NewFromUtf8(env->isolate(),
341-
u_errorName(status),
342-
NewStringType::kNormal).ToLocalChecked());
341+
u_errorName(status)).ToLocalChecked());
343342
}
344343

345344
} // anonymous namespace

0 commit comments

Comments
 (0)