Skip to content

Commit

Permalink
src,doc,test: remove String::New default parameter
Browse files Browse the repository at this point in the history
`kNormal` has been the implicit default for a while now (since V8 7.6).

Refs: v8/v8@e0d7f81

PR-URL: nodejs#34248
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
addaleax committed Jul 14, 2020
1 parent d1912e0 commit 1ba6cf1
Show file tree
Hide file tree
Showing 35 changed files with 85 additions and 159 deletions.
42 changes: 13 additions & 29 deletions doc/api/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ namespace demo {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;

void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(
isolate, "world", NewStringType::kNormal).ToLocalChecked());
isolate, "world").ToLocalChecked());
}

void Initialize(Local<Object> exports) {
Expand Down Expand Up @@ -226,8 +225,7 @@ NODE_MODULE_INIT(/* exports, module, context */) {
// per-addon-instance data we created above by passing `external` as the
// third parameter to the `FunctionTemplate` constructor.
exports->Set(context,
String::NewFromUtf8(isolate, "method", NewStringType::kNormal)
.ToLocalChecked(),
String::NewFromUtf8(isolate, "method").ToLocalChecked(),
FunctionTemplate::New(isolate, Method, external)
->GetFunction(context).ToLocalChecked()).FromJust();
}
Expand Down Expand Up @@ -538,7 +536,6 @@ using v8::Exception;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Number;
using v8::Object;
using v8::String;
Expand All @@ -555,17 +552,15 @@ void Add(const FunctionCallbackInfo<Value>& args) {
// Throw an Error that is passed back to JavaScript
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate,
"Wrong number of arguments",
NewStringType::kNormal).ToLocalChecked()));
"Wrong number of arguments").ToLocalChecked()));
return;
}

// Check the argument types
if (!args[0]->IsNumber() || !args[1]->IsNumber()) {
isolate->ThrowException(Exception::TypeError(
String::NewFromUtf8(isolate,
"Wrong arguments",
NewStringType::kNormal).ToLocalChecked()));
"Wrong arguments").ToLocalChecked()));
return;
}

Expand Down Expand Up @@ -614,7 +609,6 @@ using v8::Function;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Null;
using v8::Object;
using v8::String;
Expand All @@ -627,8 +621,7 @@ void RunCallback(const FunctionCallbackInfo<Value>& args) {
const unsigned argc = 1;
Local<Value> argv[argc] = {
String::NewFromUtf8(isolate,
"hello world",
NewStringType::kNormal).ToLocalChecked() };
"hello world").ToLocalChecked() };
cb->Call(context, Null(isolate), argc, argv).ToLocalChecked();
}

Expand Down Expand Up @@ -676,7 +669,6 @@ using v8::Context;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;
Expand All @@ -688,8 +680,7 @@ void CreateObject(const FunctionCallbackInfo<Value>& args) {
Local<Object> obj = Object::New(isolate);
obj->Set(context,
String::NewFromUtf8(isolate,
"msg",
NewStringType::kNormal).ToLocalChecked(),
"msg").ToLocalChecked(),
args[0]->ToString(context).ToLocalChecked())
.FromJust();

Expand Down Expand Up @@ -734,15 +725,14 @@ using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;

void MyFunction(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(
isolate, "hello world", NewStringType::kNormal).ToLocalChecked());
isolate, "hello world").ToLocalChecked());
}

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

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

args.GetReturnValue().Set(fn);
}
Expand Down Expand Up @@ -850,7 +840,6 @@ using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Number;
using v8::Object;
using v8::ObjectTemplate;
Expand All @@ -874,8 +863,7 @@ void MyObject::Init(Local<Object> exports) {

// Prepare constructor template
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New, addon_data);
tpl->SetClassName(String::NewFromUtf8(
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked());
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);

// Prototype
Expand All @@ -884,8 +872,8 @@ void MyObject::Init(Local<Object> exports) {
Local<Function> constructor = tpl->GetFunction(context).ToLocalChecked();
addon_data->SetInternalField(0, constructor);
exports->Set(context, String::NewFromUtf8(
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked(),
constructor).FromJust();
isolate, "MyObject").ToLocalChecked(),
constructor).FromJust();
}

void MyObject::New(const FunctionCallbackInfo<Value>& args) {
Expand Down Expand Up @@ -1055,7 +1043,6 @@ using v8::FunctionTemplate;
using v8::Global;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Number;
using v8::Object;
using v8::String;
Expand All @@ -1074,8 +1061,7 @@ MyObject::~MyObject() {
void MyObject::Init(Isolate* isolate) {
// Prepare constructor template
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
tpl->SetClassName(String::NewFromUtf8(
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked());
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);

// Prototype
Expand Down Expand Up @@ -1279,7 +1265,6 @@ using v8::FunctionTemplate;
using v8::Global;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;
Expand All @@ -1297,8 +1282,7 @@ MyObject::~MyObject() {
void MyObject::Init(Isolate* isolate) {
// Prepare constructor template
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
tpl->SetClassName(String::NewFromUtf8(
isolate, "MyObject", NewStringType::kNormal).ToLocalChecked());
tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);

Local<Context> context = isolate->GetCurrentContext();
Expand Down
4 changes: 1 addition & 3 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ v8::Local<v8::Value> GetFoo(v8::Local<v8::Context> context,
// The 'foo_string' handle cannot be returned from this function because
// it is not “escaped” with `.Escape()`.
v8::Local<v8::String> foo_string =
v8::String::NewFromUtf8(isolate,
"foo",
v8::NewStringType::kNormal).ToLocalChecked();
v8::String::NewFromUtf8(isolate, "foo").ToLocalChecked();

v8::Local<v8::Value> return_value;
if (obj->Get(context, foo_string).ToLocal(&return_value)) {
Expand Down
4 changes: 1 addition & 3 deletions src/api/callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ using v8::Isolate;
using v8::Local;
using v8::MaybeLocal;
using v8::MicrotasksScope;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;
Expand Down Expand Up @@ -209,8 +208,7 @@ MaybeLocal<Value> MakeCallback(Isolate* isolate,
Local<Value> argv[],
async_context asyncContext) {
Local<String> method_string =
String::NewFromUtf8(isolate, method, NewStringType::kNormal)
.ToLocalChecked();
String::NewFromUtf8(isolate, method).ToLocalChecked();
return MakeCallback(isolate, recv, method_string, argc, argv, asyncContext);
}

Expand Down
1 change: 1 addition & 0 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ void FreeEnvironment(Environment* env) {
delete env;
}


Environment* GetCurrentEnvironment(Local<Context> context) {
return Environment::GetCurrent(context);
}
Expand Down
19 changes: 6 additions & 13 deletions src/api/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ using v8::Exception;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;
Expand All @@ -42,8 +41,7 @@ Local<Value> ErrnoException(Isolate* isolate,
Local<String> path_string;
if (path != nullptr) {
// FIXME(bnoordhuis) It's questionable to interpret the file path as UTF-8.
path_string = String::NewFromUtf8(isolate, path, NewStringType::kNormal)
.ToLocalChecked();
path_string = String::NewFromUtf8(isolate, path).ToLocalChecked();
}

if (path_string.IsEmpty() == false) {
Expand Down Expand Up @@ -78,16 +76,13 @@ static Local<String> StringFromPath(Isolate* isolate, const char* path) {
return String::Concat(
isolate,
FIXED_ONE_BYTE_STRING(isolate, "\\\\"),
String::NewFromUtf8(isolate, path + 8, NewStringType::kNormal)
.ToLocalChecked());
String::NewFromUtf8(isolate, path + 8).ToLocalChecked());
} else if (strncmp(path, "\\\\?\\", 4) == 0) {
return String::NewFromUtf8(isolate, path + 4, NewStringType::kNormal)
.ToLocalChecked();
return String::NewFromUtf8(isolate, path + 4).ToLocalChecked();
}
#endif

return String::NewFromUtf8(isolate, path, NewStringType::kNormal)
.ToLocalChecked();
return String::NewFromUtf8(isolate, path).ToLocalChecked();
}


Expand Down Expand Up @@ -206,8 +201,7 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
Local<String> cons2 = String::Concat(
isolate,
cons1,
String::NewFromUtf8(isolate, path, NewStringType::kNormal)
.ToLocalChecked());
String::NewFromUtf8(isolate, path).ToLocalChecked());
Local<String> cons3 =
String::Concat(isolate, cons2, FIXED_ONE_BYTE_STRING(isolate, "'"));
e = Exception::Error(cons3);
Expand All @@ -222,8 +216,7 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
if (path != nullptr) {
obj->Set(env->context(),
env->path_string(),
String::NewFromUtf8(isolate, path, NewStringType::kNormal)
.ToLocalChecked())
String::NewFromUtf8(isolate, path).ToLocalChecked())
.Check();
}

Expand Down
5 changes: 2 additions & 3 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ using v8::Int32;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Null;
using v8::Object;
using v8::String;
Expand Down Expand Up @@ -1937,8 +1936,8 @@ void CanonicalizeIP(const FunctionCallbackInfo<Value>& args) {
char canonical_ip[INET6_ADDRSTRLEN];
const int af = (rc == 4 ? AF_INET : AF_INET6);
CHECK_EQ(0, uv_inet_ntop(af, &result, canonical_ip, sizeof(canonical_ip)));
Local<String> val = String::NewFromUtf8(isolate, canonical_ip,
NewStringType::kNormal).ToLocalChecked();
Local<String> val = String::NewFromUtf8(isolate, canonical_ip)
.ToLocalChecked();
args.GetReturnValue().Set(val);
}

Expand Down
11 changes: 4 additions & 7 deletions src/heap_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ class JSGraph : public EmbedderGraph {
name_str += " ";
name_str += n->Name();
}
if (!String::NewFromUtf8(
isolate_, name_str.c_str(), v8::NewStringType::kNormal)
if (!String::NewFromUtf8(isolate_, name_str.c_str())
.ToLocal(&value) ||
obj->Set(context, name_string, value).IsNothing() ||
obj->Set(context,
Expand Down Expand Up @@ -168,9 +167,8 @@ class JSGraph : public EmbedderGraph {
Local<Value> edge_name_value;
const char* edge_name = edge.first;
if (edge_name != nullptr) {
if (!String::NewFromUtf8(
isolate_, edge_name, v8::NewStringType::kNormal)
.ToLocal(&edge_name_value)) {
if (!String::NewFromUtf8(isolate_, edge_name)
.ToLocal(&edge_name_value)) {
return MaybeLocal<Array>();
}
} else {
Expand Down Expand Up @@ -377,8 +375,7 @@ void TriggerHeapSnapshot(const FunctionCallbackInfo<Value>& args) {
DiagnosticFilename name(env, "Heap", "heapsnapshot");
if (!WriteSnapshot(isolate, *name))
return;
if (String::NewFromUtf8(isolate, *name, v8::NewStringType::kNormal)
.ToLocal(&filename_v)) {
if (String::NewFromUtf8(isolate, *name).ToLocal(&filename_v)) {
args.GetReturnValue().Set(filename_v);
}
return;
Expand Down
4 changes: 1 addition & 3 deletions src/node_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ using v8::HandleScope;
using v8::Isolate;
using v8::Local;
using v8::MaybeLocal;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::TryCatch;
Expand All @@ -46,8 +45,7 @@ bool SafeGetenv(const char* key, std::string* text, Environment* env) {
TryCatch ignore_errors(env->isolate());
MaybeLocal<String> maybe_value = env->env_vars()->Get(
env->isolate(),
String::NewFromUtf8(env->isolate(), key, NewStringType::kNormal)
.ToLocalChecked());
String::NewFromUtf8(env->isolate(), key).ToLocalChecked());
Local<String> value;
if (!maybe_value.ToLocal(&value)) goto fail;
String::Utf8Value utf8_value(env->isolate(), value);
Expand Down
7 changes: 3 additions & 4 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ void ThrowCryptoError(Environment* env,
}
HandleScope scope(env->isolate());
Local<String> exception_string =
String::NewFromUtf8(env->isolate(), message, NewStringType::kNormal)
.ToLocalChecked();
String::NewFromUtf8(env->isolate(), message).ToLocalChecked();
CryptoErrorVector errors;
errors.Capture();
Local<Value> exception;
Expand Down Expand Up @@ -995,8 +994,8 @@ void GetRootCertificates(const FunctionCallbackInfo<Value>& args) {
for (size_t i = 0; i < arraysize(root_certs); i++) {
if (!String::NewFromOneByte(
env->isolate(),
reinterpret_cast<const uint8_t*>(root_certs[i]),
NewStringType::kNormal).ToLocal(&result[i])) {
reinterpret_cast<const uint8_t*>(root_certs[i]))
.ToLocal(&result[i])) {
return;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/node_env_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ Local<Array> RealEnvStore::Enumerate(Isolate* isolate) const {
// https://github.com/libuv/libuv/pull/2473 and can be removed later.
if (items[i].name[0] == '=' || items[i].name[0] == '\0') continue;
#endif
MaybeLocal<String> str = String::NewFromUtf8(
isolate, items[i].name, NewStringType::kNormal);
MaybeLocal<String> str = String::NewFromUtf8(isolate, items[i].name);
if (str.IsEmpty()) {
isolate->ThrowException(ERR_STRING_TOO_LONG(isolate));
return Local<Array>();
Expand Down
3 changes: 1 addition & 2 deletions src/node_i18n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ void ICUErrorName(const FunctionCallbackInfo<Value>& args) {
UErrorCode status = static_cast<UErrorCode>(args[0].As<Int32>()->Value());
args.GetReturnValue().Set(
String::NewFromUtf8(env->isolate(),
u_errorName(status),
NewStringType::kNormal).ToLocalChecked());
u_errorName(status)).ToLocalChecked());
}

} // anonymous namespace
Expand Down
Loading

0 comments on commit 1ba6cf1

Please sign in to comment.