From b2cd87e6115ec2c42af39eb62bbb603f1127bdc6 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 7 Jul 2020 22:03:17 +0200 Subject: [PATCH] src,doc,test: remove String::New default parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `kNormal` has been the implicit default for a while now (since V8 7.6). Refs: https://github.com/v8/v8/commit/e0d7f816990ada28ebe1281ca9431236ef8c6e4f Backport-PR-URL: https://github.com/nodejs/node/pull/34358 PR-URL: https://github.com/nodejs/node/pull/34248 Reviewed-By: Ben Noordhuis Reviewed-By: Tobias Nießen Reviewed-By: James M Snell --- doc/api/addons.md | 42 ++++++------------- src/README.md | 4 +- src/api/callback.cc | 4 +- src/api/environment.cc | 3 +- src/api/exceptions.cc | 19 +++------ src/cares_wrap.cc | 5 +-- src/heap_utils.cc | 11 ++--- src/node_credentials.cc | 4 +- src/node_crypto.cc | 7 ++-- src/node_env_var.cc | 3 +- src/node_i18n.cc | 3 +- src/node_os.cc | 6 +-- src/node_perf.cc | 7 +--- src/node_process_events.cc | 12 ++---- src/node_report_module.cc | 21 +++------- src/node_url.cc | 16 ++----- src/node_v8.cc | 5 +-- src/spawn_sync.cc | 3 +- src/tls_wrap.cc | 2 +- src/util.h | 6 +-- test/addons/async-hooks-promise/binding.cc | 3 +- test/addons/async-resource/binding.cc | 6 +-- test/addons/dlopen-ping-pong/binding.cc | 2 +- test/addons/heap-profiler/binding.cc | 2 +- .../hello-world-function-export/binding.cc | 2 +- test/addons/hello-world/binding.cc | 5 +-- test/addons/load-long-path/binding.cc | 2 +- test/addons/new-target/binding.cc | 2 +- test/addons/non-node-context/binding.cc | 3 +- test/addons/openssl-binding/binding.cc | 2 +- test/addons/parse-encoding/binding.cc | 3 +- test/addons/symlinked-module/binding.cc | 2 +- test/addons/worker-buffer-callback/binding.cc | 3 +- test/addons/zlib-binding/binding.cc | 2 +- test/cctest/test_environment.cc | 20 ++++----- test/cctest/test_linked_binding.cc | 24 +++++------ 36 files changed, 95 insertions(+), 171 deletions(-) diff --git a/doc/api/addons.md b/doc/api/addons.md index 9a2b6d1a536359..fca5d2a154db4f 100644 --- a/doc/api/addons.md +++ b/doc/api/addons.md @@ -65,7 +65,6 @@ namespace demo { using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; -using v8::NewStringType; using v8::Object; using v8::String; using v8::Value; @@ -73,7 +72,7 @@ using v8::Value; void Method(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); args.GetReturnValue().Set(String::NewFromUtf8( - isolate, "world", NewStringType::kNormal).ToLocalChecked()); + isolate, "world").ToLocalChecked()); } void Initialize(Local exports) { @@ -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(); } @@ -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; @@ -555,8 +552,7 @@ void Add(const FunctionCallbackInfo& 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; } @@ -564,8 +560,7 @@ void Add(const FunctionCallbackInfo& args) { if (!args[0]->IsNumber() || !args[1]->IsNumber()) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, - "Wrong arguments", - NewStringType::kNormal).ToLocalChecked())); + "Wrong arguments").ToLocalChecked())); return; } @@ -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; @@ -627,8 +621,7 @@ void RunCallback(const FunctionCallbackInfo& args) { const unsigned argc = 1; Local argv[argc] = { String::NewFromUtf8(isolate, - "hello world", - NewStringType::kNormal).ToLocalChecked() }; + "hello world").ToLocalChecked() }; cb->Call(context, Null(isolate), argc, argv).ToLocalChecked(); } @@ -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; @@ -688,8 +680,7 @@ void CreateObject(const FunctionCallbackInfo& args) { Local obj = Object::New(isolate); obj->Set(context, String::NewFromUtf8(isolate, - "msg", - NewStringType::kNormal).ToLocalChecked(), + "msg").ToLocalChecked(), args[0]->ToString(context).ToLocalChecked()) .FromJust(); @@ -734,7 +725,6 @@ using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Isolate; using v8::Local; -using v8::NewStringType; using v8::Object; using v8::String; using v8::Value; @@ -742,7 +732,7 @@ using v8::Value; void MyFunction(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); args.GetReturnValue().Set(String::NewFromUtf8( - isolate, "hello world", NewStringType::kNormal).ToLocalChecked()); + isolate, "hello world").ToLocalChecked()); } void CreateFunction(const FunctionCallbackInfo& args) { @@ -754,7 +744,7 @@ void CreateFunction(const FunctionCallbackInfo& args) { // omit this to make it anonymous fn->SetName(String::NewFromUtf8( - isolate, "theFunction", NewStringType::kNormal).ToLocalChecked()); + isolate, "theFunction").ToLocalChecked()); args.GetReturnValue().Set(fn); } @@ -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; @@ -874,8 +863,7 @@ void MyObject::Init(Local exports) { // Prepare constructor template Local 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 @@ -884,8 +872,8 @@ void MyObject::Init(Local exports) { Local 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& args) { @@ -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; @@ -1074,8 +1061,7 @@ MyObject::~MyObject() { void MyObject::Init(Isolate* isolate) { // Prepare constructor template Local 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 @@ -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; @@ -1297,8 +1282,7 @@ MyObject::~MyObject() { void MyObject::Init(Isolate* isolate) { // Prepare constructor template Local 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 = isolate->GetCurrentContext(); diff --git a/src/README.md b/src/README.md index a3a6a71aa55544..079326cd200a49 100644 --- a/src/README.md +++ b/src/README.md @@ -146,9 +146,7 @@ v8::Local GetFoo(v8::Local context, // The 'foo_string' handle cannot be returned from this function because // it is not “escaped” with `.Escape()`. v8::Local foo_string = - v8::String::NewFromUtf8(isolate, - "foo", - v8::NewStringType::kNormal).ToLocalChecked(); + v8::String::NewFromUtf8(isolate, "foo").ToLocalChecked(); v8::Local return_value; if (obj->Get(context, foo_string).ToLocal(&return_value)) { diff --git a/src/api/callback.cc b/src/api/callback.cc index 2bb34b088f74e1..84664c089594eb 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -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; @@ -214,8 +213,7 @@ MaybeLocal MakeCallback(Isolate* isolate, Local argv[], async_context asyncContext) { Local method_string = - String::NewFromUtf8(isolate, method, NewStringType::kNormal) - .ToLocalChecked(); + String::NewFromUtf8(isolate, method).ToLocalChecked(); return MakeCallback(isolate, recv, method_string, argc, argv, asyncContext); } diff --git a/src/api/environment.cc b/src/api/environment.cc index 90cb2be2e6edc8..fdfd257aec12f5 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -437,8 +437,7 @@ MaybeLocal LoadEnvironment( // This is a slightly hacky way to convert UTF-8 to UTF-16. Local str = String::NewFromUtf8(env->isolate(), - main_script_source_utf8, - v8::NewStringType::kNormal).ToLocalChecked(); + main_script_source_utf8).ToLocalChecked(); auto main_utf16 = std::make_unique(env->isolate(), str); // TODO(addaleax): Avoid having a global table for all scripts. diff --git a/src/api/exceptions.cc b/src/api/exceptions.cc index 998d370d3b5fd6..310b2acc4073d6 100644 --- a/src/api/exceptions.cc +++ b/src/api/exceptions.cc @@ -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; @@ -42,8 +41,7 @@ Local ErrnoException(Isolate* isolate, Local 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) { @@ -78,16 +76,13 @@ static Local 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(); } @@ -206,8 +201,7 @@ Local WinapiErrnoException(Isolate* isolate, Local cons2 = String::Concat( isolate, cons1, - String::NewFromUtf8(isolate, path, NewStringType::kNormal) - .ToLocalChecked()); + String::NewFromUtf8(isolate, path).ToLocalChecked()); Local cons3 = String::Concat(isolate, cons2, FIXED_ONE_BYTE_STRING(isolate, "'")); e = Exception::Error(cons3); @@ -222,8 +216,7 @@ Local 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(); } diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 4a332db71279a4..73a0ac6b334345 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -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; @@ -1937,8 +1936,8 @@ void CanonicalizeIP(const FunctionCallbackInfo& 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 val = String::NewFromUtf8(isolate, canonical_ip, - NewStringType::kNormal).ToLocalChecked(); + Local val = String::NewFromUtf8(isolate, canonical_ip) + .ToLocalChecked(); args.GetReturnValue().Set(val); } diff --git a/src/heap_utils.cc b/src/heap_utils.cc index 386bf61e4eca00..449feb9e78d0e1 100644 --- a/src/heap_utils.cc +++ b/src/heap_utils.cc @@ -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, @@ -168,9 +167,8 @@ class JSGraph : public EmbedderGraph { Local 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(); } } else { @@ -377,8 +375,7 @@ void TriggerHeapSnapshot(const FunctionCallbackInfo& 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; diff --git a/src/node_credentials.cc b/src/node_credentials.cc index d552a501726396..83db705e10df4f 100644 --- a/src/node_credentials.cc +++ b/src/node_credentials.cc @@ -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; @@ -46,8 +45,7 @@ bool SafeGetenv(const char* key, std::string* text, Environment* env) { TryCatch ignore_errors(env->isolate()); MaybeLocal maybe_value = env->env_vars()->Get( env->isolate(), - String::NewFromUtf8(env->isolate(), key, NewStringType::kNormal) - .ToLocalChecked()); + String::NewFromUtf8(env->isolate(), key).ToLocalChecked()); Local value; if (!maybe_value.ToLocal(&value)) goto fail; String::Utf8Value utf8_value(env->isolate(), value); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index eae0f2e49d3c86..dfc21ae6876105 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -392,8 +392,7 @@ void ThrowCryptoError(Environment* env, } HandleScope scope(env->isolate()); Local exception_string = - String::NewFromUtf8(env->isolate(), message, NewStringType::kNormal) - .ToLocalChecked(); + String::NewFromUtf8(env->isolate(), message).ToLocalChecked(); CryptoErrorVector errors; errors.Capture(); Local exception; @@ -1017,8 +1016,8 @@ void GetRootCertificates(const FunctionCallbackInfo& args) { for (size_t i = 0; i < arraysize(root_certs); i++) { if (!String::NewFromOneByte( env->isolate(), - reinterpret_cast(root_certs[i]), - NewStringType::kNormal).ToLocal(&result[i])) { + reinterpret_cast(root_certs[i])) + .ToLocal(&result[i])) { return; } } diff --git a/src/node_env_var.cc b/src/node_env_var.cc index 23eaad48586130..1a162888fd37a7 100644 --- a/src/node_env_var.cc +++ b/src/node_env_var.cc @@ -179,8 +179,7 @@ Local 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 str = String::NewFromUtf8( - isolate, items[i].name, NewStringType::kNormal); + MaybeLocal str = String::NewFromUtf8(isolate, items[i].name); if (str.IsEmpty()) { isolate->ThrowException(ERR_STRING_TOO_LONG(isolate)); return Local(); diff --git a/src/node_i18n.cc b/src/node_i18n.cc index 5382e469a4087c..cc2d245b8a77d9 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -338,8 +338,7 @@ void ICUErrorName(const FunctionCallbackInfo& args) { UErrorCode status = static_cast(args[0].As()->Value()); args.GetReturnValue().Set( String::NewFromUtf8(env->isolate(), - u_errorName(status), - NewStringType::kNormal).ToLocalChecked()); + u_errorName(status)).ToLocalChecked()); } } // anonymous namespace diff --git a/src/node_os.cc b/src/node_os.cc index 085fb1aef01c32..2e151ac4f89213 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -71,8 +71,7 @@ static void GetHostname(const FunctionCallbackInfo& args) { } args.GetReturnValue().Set( - String::NewFromUtf8(env->isolate(), buf, NewStringType::kNormal) - .ToLocalChecked()); + String::NewFromUtf8(env->isolate(), buf).ToLocalChecked()); } static void GetOSInformation(const FunctionCallbackInfo& args) { @@ -192,8 +191,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo& args) { // to assume UTF8 as the default as well. It’s what people will expect if // they name the interface from any input that uses UTF-8, which should be // the most frequent case by far these days.) - name = String::NewFromUtf8(isolate, raw_name, - NewStringType::kNormal).ToLocalChecked(); + name = String::NewFromUtf8(isolate, raw_name).ToLocalChecked(); snprintf(mac.data(), mac.size(), diff --git a/src/node_perf.cc b/src/node_perf.cc index 916a9974d5d6f9..b5efc05689f20c 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -24,7 +24,6 @@ using v8::Isolate; using v8::Local; using v8::Map; using v8::MaybeLocal; -using v8::NewStringType; using v8::Number; using v8::Object; using v8::PropertyAttribute; @@ -60,16 +59,14 @@ inline void InitObject(const PerformanceEntry& entry, Local obj) { obj->DefineOwnProperty(context, env->name_string(), String::NewFromUtf8(isolate, - entry.name().c_str(), - NewStringType::kNormal) + entry.name().c_str()) .ToLocalChecked(), attr) .Check(); obj->DefineOwnProperty(context, env->entry_type_string(), String::NewFromUtf8(isolate, - entry.type().c_str(), - NewStringType::kNormal) + entry.type().c_str()) .ToLocalChecked(), attr) .Check(); diff --git a/src/node_process_events.cc b/src/node_process_events.cc index 1b902949e264e0..0c149b26e334b0 100644 --- a/src/node_process_events.cc +++ b/src/node_process_events.cc @@ -14,7 +14,6 @@ using v8::Just; using v8::Local; using v8::Maybe; using v8::MaybeLocal; -using v8::NewStringType; using v8::Nothing; using v8::Object; using v8::String; @@ -58,21 +57,18 @@ Maybe ProcessEmitWarningGeneric(Environment* env, // The caller has to be able to handle a failure anyway, so we might as well // do proper error checking for string creation. - if (!String::NewFromUtf8(env->isolate(), warning, NewStringType::kNormal) - .ToLocal(&args[argc++])) { + if (!String::NewFromUtf8(env->isolate(), warning).ToLocal(&args[argc++])) return Nothing(); - } + if (type != nullptr) { if (!String::NewFromOneByte(env->isolate(), - reinterpret_cast(type), - NewStringType::kNormal) + reinterpret_cast(type)) .ToLocal(&args[argc++])) { return Nothing(); } if (code != nullptr && !String::NewFromOneByte(env->isolate(), - reinterpret_cast(code), - NewStringType::kNormal) + reinterpret_cast(code)) .ToLocal(&args[argc++])) { return Nothing(); } diff --git a/src/node_report_module.cc b/src/node_report_module.cc index d9dad28221a5cf..97c6bea3ad5ec5 100644 --- a/src/node_report_module.cc +++ b/src/node_report_module.cc @@ -49,8 +49,7 @@ void WriteReport(const FunctionCallbackInfo& info) { isolate, env, *message, *trigger, filename, error); // Return value is the report filename info.GetReturnValue().Set( - String::NewFromUtf8(isolate, filename.c_str(), v8::NewStringType::kNormal) - .ToLocalChecked()); + String::NewFromUtf8(isolate, filename.c_str()).ToLocalChecked()); } // External JavaScript API for returning a report @@ -71,10 +70,8 @@ void GetReport(const FunctionCallbackInfo& info) { isolate, env, "JavaScript API", __func__, error, out); // Return value is the contents of a report as a string. - info.GetReturnValue().Set(String::NewFromUtf8(isolate, - out.str().c_str(), - v8::NewStringType::kNormal) - .ToLocalChecked()); + info.GetReturnValue().Set( + String::NewFromUtf8(isolate, out.str().c_str()).ToLocalChecked()); } static void GetCompact(const FunctionCallbackInfo& info) { @@ -94,9 +91,7 @@ static void GetDirectory(const FunctionCallbackInfo& info) { node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex); Environment* env = Environment::GetCurrent(info); std::string directory = node::per_process::cli_options->report_directory; - auto result = String::NewFromUtf8(env->isolate(), - directory.c_str(), - v8::NewStringType::kNormal); + auto result = String::NewFromUtf8(env->isolate(), directory.c_str()); info.GetReturnValue().Set(result.ToLocalChecked()); } @@ -112,9 +107,7 @@ static void GetFilename(const FunctionCallbackInfo& info) { node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex); Environment* env = Environment::GetCurrent(info); std::string filename = node::per_process::cli_options->report_filename; - auto result = String::NewFromUtf8(env->isolate(), - filename.c_str(), - v8::NewStringType::kNormal); + auto result = String::NewFromUtf8(env->isolate(), filename.c_str()); info.GetReturnValue().Set(result.ToLocalChecked()); } @@ -129,9 +122,7 @@ static void SetFilename(const FunctionCallbackInfo& info) { static void GetSignal(const FunctionCallbackInfo& info) { Environment* env = Environment::GetCurrent(info); std::string signal = env->isolate_data()->options()->report_signal; - auto result = String::NewFromUtf8(env->isolate(), - signal.c_str(), - v8::NewStringType::kNormal); + auto result = String::NewFromUtf8(env->isolate(), signal.c_str()); info.GetReturnValue().Set(result.ToLocalChecked()); } diff --git a/src/node_url.cc b/src/node_url.cc index 029a04a429b7a5..4f0d5f284b14dd 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -2175,9 +2175,7 @@ void Parse(Environment* env, Local argv[2] = { undef, undef }; argv[ERR_ARG_FLAGS] = Integer::NewFromUnsigned(isolate, url.flags); argv[ERR_ARG_INPUT] = - String::NewFromUtf8(env->isolate(), - input, - NewStringType::kNormal).ToLocalChecked(); + String::NewFromUtf8(env->isolate(), input).ToLocalChecked(); error_cb.As()->Call(context, recv, arraysize(argv), argv) .FromMaybe(Local()); } @@ -2225,9 +2223,7 @@ void EncodeAuthSet(const FunctionCallbackInfo& args) { AppendOrEscape(&output, ch, USERINFO_ENCODE_SET); } args.GetReturnValue().Set( - String::NewFromUtf8(env->isolate(), - output.c_str(), - NewStringType::kNormal).ToLocalChecked()); + String::NewFromUtf8(env->isolate(), output.c_str()).ToLocalChecked()); } void ToUSVString(const FunctionCallbackInfo& args) { @@ -2279,9 +2275,7 @@ void DomainToASCII(const FunctionCallbackInfo& args) { } std::string out = host.ToStringMove(); args.GetReturnValue().Set( - String::NewFromUtf8(env->isolate(), - out.c_str(), - NewStringType::kNormal).ToLocalChecked()); + String::NewFromUtf8(env->isolate(), out.c_str()).ToLocalChecked()); } void DomainToUnicode(const FunctionCallbackInfo& args) { @@ -2299,9 +2293,7 @@ void DomainToUnicode(const FunctionCallbackInfo& args) { } std::string out = host.ToStringMove(); args.GetReturnValue().Set( - String::NewFromUtf8(env->isolate(), - out.c_str(), - NewStringType::kNormal).ToLocalChecked()); + String::NewFromUtf8(env->isolate(), out.c_str()).ToLocalChecked()); } void SetURLConstructor(const FunctionCallbackInfo& args) { diff --git a/src/node_v8.cc b/src/node_v8.cc index 047ca594095d16..f34125d5f49e16 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -37,7 +37,6 @@ using v8::HeapStatistics; using v8::Integer; using v8::Isolate; using v8::Local; -using v8::NewStringType; using v8::Object; using v8::ScriptCompiler; using v8::String; @@ -225,9 +224,7 @@ void Initialize(Local target, MaybeStackBuffer, 16> heap_spaces(number_of_heap_spaces); for (size_t i = 0; i < number_of_heap_spaces; i++) { env->isolate()->GetHeapSpaceStatistics(&s, i); - heap_spaces[i] = String::NewFromUtf8(env->isolate(), - s.space_name(), - NewStringType::kNormal) + heap_spaces[i] = String::NewFromUtf8(env->isolate(), s.space_name()) .ToLocalChecked(); } target->Set(env->context(), diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 11126c478f76f7..d7d06be34bdb10 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -695,8 +695,7 @@ Local SyncProcessRunner::BuildResultObject() { if (term_signal_ > 0) js_result->Set(context, env()->signal_string(), String::NewFromUtf8(env()->isolate(), - signo_string(term_signal_), - v8::NewStringType::kNormal) + signo_string(term_signal_)) .ToLocalChecked()) .Check(); else diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 792d3ea79ceea9..04c035a1e8f3e5 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -1143,7 +1143,7 @@ unsigned int TLSWrap::PskServerCallback(SSL* s, HandleScope scope(isolate); MaybeLocal maybe_identity_str = - v8::String::NewFromUtf8(isolate, identity, v8::NewStringType::kNormal); + String::NewFromUtf8(isolate, identity); v8::Local identity_str; if (!maybe_identity_str.ToLocal(&identity_str)) return 0; diff --git a/src/util.h b/src/util.h index f817eac1298d61..dc0d97f1df7dd2 100644 --- a/src/util.h +++ b/src/util.h @@ -676,11 +676,9 @@ inline v8::MaybeLocal ToV8Value(v8::Local context, do { \ v8::Isolate* isolate = target->GetIsolate(); \ v8::Local constant_name = \ - v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kNormal) \ - .ToLocalChecked(); \ + v8::String::NewFromUtf8(isolate, name).ToLocalChecked(); \ v8::Local constant_value = \ - v8::String::NewFromUtf8(isolate, constant, v8::NewStringType::kNormal) \ - .ToLocalChecked(); \ + v8::String::NewFromUtf8(isolate, constant).ToLocalChecked(); \ v8::PropertyAttribute constant_attributes = \ static_cast(v8::ReadOnly | v8::DontDelete); \ target \ diff --git a/test/addons/async-hooks-promise/binding.cc b/test/addons/async-hooks-promise/binding.cc index 1571690edead24..452cbda8793aa1 100644 --- a/test/addons/async-hooks-promise/binding.cc +++ b/test/addons/async-hooks-promise/binding.cc @@ -15,8 +15,7 @@ using v8::Value; static void ThrowError(Isolate* isolate, const char* err_msg) { Local str = String::NewFromOneByte( isolate, - reinterpret_cast(err_msg), - NewStringType::kNormal).ToLocalChecked(); + reinterpret_cast(err_msg)).ToLocalChecked(); isolate->ThrowException(str); } diff --git a/test/addons/async-resource/binding.cc b/test/addons/async-resource/binding.cc index ab33858c233dd0..6fd9b37cbeda40 100644 --- a/test/addons/async-resource/binding.cc +++ b/test/addons/async-resource/binding.cc @@ -55,8 +55,7 @@ void CallViaFunction(const FunctionCallbackInfo& args) { auto r = static_cast(args[0].As()->Value()); Local name = - String::NewFromUtf8(isolate, "methöd", v8::NewStringType::kNormal) - .ToLocalChecked(); + String::NewFromUtf8(isolate, "methöd").ToLocalChecked(); Local fn = r->get_resource()->Get(isolate->GetCurrentContext(), name) .ToLocalChecked(); @@ -73,8 +72,7 @@ void CallViaString(const FunctionCallbackInfo& args) { auto r = static_cast(args[0].As()->Value()); Local name = - String::NewFromUtf8(isolate, "methöd", v8::NewStringType::kNormal) - .ToLocalChecked(); + String::NewFromUtf8(isolate, "methöd").ToLocalChecked(); Local arg = Integer::New(isolate, 42); MaybeLocal ret = r->MakeCallback(name, 1, &arg); diff --git a/test/addons/dlopen-ping-pong/binding.cc b/test/addons/dlopen-ping-pong/binding.cc index 7b211be1195bf7..c8711f09aedac6 100644 --- a/test/addons/dlopen-ping-pong/binding.cc +++ b/test/addons/dlopen-ping-pong/binding.cc @@ -38,7 +38,7 @@ void Ping(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); assert(ping_func != nullptr); args.GetReturnValue().Set(String::NewFromUtf8( - isolate, ping_func(), NewStringType::kNormal).ToLocalChecked()); + isolate, ping_func()).ToLocalChecked()); } void init(Local exports) { diff --git a/test/addons/heap-profiler/binding.cc b/test/addons/heap-profiler/binding.cc index 9e1e97e9fc2afc..98156d5548960e 100644 --- a/test/addons/heap-profiler/binding.cc +++ b/test/addons/heap-profiler/binding.cc @@ -20,7 +20,7 @@ inline void Initialize(v8::Local binding) { v8::Isolate* const isolate = binding->GetIsolate(); v8::Local context = isolate->GetCurrentContext(); binding->Set(context, v8::String::NewFromUtf8( - isolate, "test", v8::NewStringType::kNormal).ToLocalChecked(), + isolate, "test").ToLocalChecked(), v8::FunctionTemplate::New(isolate, Test) ->GetFunction(context) .ToLocalChecked()).FromJust(); diff --git a/test/addons/hello-world-function-export/binding.cc b/test/addons/hello-world-function-export/binding.cc index e5476c4ee1e364..525b8cc732b4b1 100644 --- a/test/addons/hello-world-function-export/binding.cc +++ b/test/addons/hello-world-function-export/binding.cc @@ -4,7 +4,7 @@ void Method(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); args.GetReturnValue().Set(v8::String::NewFromUtf8( - isolate, "world", v8::NewStringType::kNormal).ToLocalChecked()); + isolate, "world").ToLocalChecked()); } void init(v8::Local exports, v8::Local module) { diff --git a/test/addons/hello-world/binding.cc b/test/addons/hello-world/binding.cc index f2d26b53e985cf..77de6c45a3a8f1 100644 --- a/test/addons/hello-world/binding.cc +++ b/test/addons/hello-world/binding.cc @@ -4,7 +4,7 @@ static void Method(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); args.GetReturnValue().Set(v8::String::NewFromUtf8( - isolate, "world", v8::NewStringType::kNormal).ToLocalChecked()); + isolate, "world").ToLocalChecked()); } // Not using the full NODE_MODULE_INIT() macro here because we want to test the @@ -21,8 +21,7 @@ static void FakeInit(v8::Local exports, v8::Local context) { auto isolate = context->GetIsolate(); auto exception = v8::Exception::Error(v8::String::NewFromUtf8(isolate, - "FakeInit should never run!", v8::NewStringType::kNormal) - .ToLocalChecked()); + "FakeInit should never run!").ToLocalChecked()); isolate->ThrowException(exception); } diff --git a/test/addons/load-long-path/binding.cc b/test/addons/load-long-path/binding.cc index 02eecec099807a..cd9fdf7f406c66 100644 --- a/test/addons/load-long-path/binding.cc +++ b/test/addons/load-long-path/binding.cc @@ -4,7 +4,7 @@ void Method(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); args.GetReturnValue().Set(v8::String::NewFromUtf8( - isolate, "world", v8::NewStringType::kNormal).ToLocalChecked()); + isolate, "world").ToLocalChecked()); } void init(v8::Local exports) { diff --git a/test/addons/new-target/binding.cc b/test/addons/new-target/binding.cc index 48ceeb55ca1aae..ba747fbbe87ea7 100644 --- a/test/addons/new-target/binding.cc +++ b/test/addons/new-target/binding.cc @@ -13,7 +13,7 @@ inline void Initialize(v8::Local binding) { auto isolate = binding->GetIsolate(); auto context = isolate->GetCurrentContext(); binding->Set(context, v8::String::NewFromUtf8( - isolate, "Class", v8::NewStringType::kNormal).ToLocalChecked(), + isolate, "Class").ToLocalChecked(), v8::FunctionTemplate::New(isolate, NewClass) ->GetFunction(context) .ToLocalChecked()).FromJust(); diff --git a/test/addons/non-node-context/binding.cc b/test/addons/non-node-context/binding.cc index 776786cef5180f..6fe776b7c60c3d 100644 --- a/test/addons/non-node-context/binding.cc +++ b/test/addons/non-node-context/binding.cc @@ -35,8 +35,7 @@ inline void RunInNewContext( context->Global()->Set( context, - String::NewFromUtf8(isolate, "data", NewStringType::kNormal) - .ToLocalChecked(), + String::NewFromUtf8(isolate, "data").ToLocalChecked(), args[1]).FromJust(); assert(args[0]->IsString()); // source code diff --git a/test/addons/openssl-binding/binding.cc b/test/addons/openssl-binding/binding.cc index 6cfecc4505421e..05849b6c14fe31 100644 --- a/test/addons/openssl-binding/binding.cc +++ b/test/addons/openssl-binding/binding.cc @@ -24,7 +24,7 @@ inline void Initialize(v8::Local exports, v8::Local context) { auto isolate = context->GetIsolate(); auto key = v8::String::NewFromUtf8( - isolate, "randomBytes", v8::NewStringType::kNormal).ToLocalChecked(); + isolate, "randomBytes").ToLocalChecked(); auto value = v8::FunctionTemplate::New(isolate, RandomBytes) ->GetFunction(context) .ToLocalChecked(); diff --git a/test/addons/parse-encoding/binding.cc b/test/addons/parse-encoding/binding.cc index 1501544153ad62..cdbd8e44466db8 100644 --- a/test/addons/parse-encoding/binding.cc +++ b/test/addons/parse-encoding/binding.cc @@ -23,8 +23,7 @@ void ParseEncoding(const v8::FunctionCallbackInfo& args) { ENCODING_MAP(V) #undef V auto encoding_string = - v8::String::NewFromUtf8(args.GetIsolate(), encoding_name, - v8::NewStringType::kNormal) + v8::String::NewFromUtf8(args.GetIsolate(), encoding_name) .ToLocalChecked(); args.GetReturnValue().Set(encoding_string); } diff --git a/test/addons/symlinked-module/binding.cc b/test/addons/symlinked-module/binding.cc index 02eecec099807a..cd9fdf7f406c66 100644 --- a/test/addons/symlinked-module/binding.cc +++ b/test/addons/symlinked-module/binding.cc @@ -4,7 +4,7 @@ void Method(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); args.GetReturnValue().Set(v8::String::NewFromUtf8( - isolate, "world", v8::NewStringType::kNormal).ToLocalChecked()); + isolate, "world").ToLocalChecked()); } void init(v8::Local exports) { diff --git a/test/addons/worker-buffer-callback/binding.cc b/test/addons/worker-buffer-callback/binding.cc index ac4c0cb498b7c7..9cacc6996243bd 100644 --- a/test/addons/worker-buffer-callback/binding.cc +++ b/test/addons/worker-buffer-callback/binding.cc @@ -25,8 +25,7 @@ void Initialize(Local exports, exports->Set(context, v8::String::NewFromUtf8( - isolate, "buffer", v8::NewStringType::kNormal) - .ToLocalChecked(), + isolate, "buffer").ToLocalChecked(), node::Buffer::New( isolate, data, diff --git a/test/addons/zlib-binding/binding.cc b/test/addons/zlib-binding/binding.cc index abfb0615842594..53d25642f0d563 100644 --- a/test/addons/zlib-binding/binding.cc +++ b/test/addons/zlib-binding/binding.cc @@ -46,7 +46,7 @@ inline void Initialize(v8::Local exports, v8::Local context) { auto isolate = context->GetIsolate(); auto key = v8::String::NewFromUtf8( - isolate, "compressBytes", v8::NewStringType::kNormal).ToLocalChecked(); + isolate, "compressBytes").ToLocalChecked(); auto value = v8::FunctionTemplate::New(isolate, CompressBytes) ->GetFunction(context) .ToLocalChecked(); diff --git a/test/cctest/test_environment.cc b/test/cctest/test_environment.cc index 11fc99a73bc5bb..6de332b59b2fe5 100644 --- a/test/cctest/test_environment.cc +++ b/test/cctest/test_environment.cc @@ -114,8 +114,8 @@ TEST_F(EnvironmentTest, PreExecutionPreparation) { v8::Local script = v8::Script::Compile( context, v8::String::NewFromOneByte(isolate_, - reinterpret_cast(run_script), - v8::NewStringType::kNormal).ToLocalChecked()) + reinterpret_cast(run_script)) + .ToLocalChecked()) .ToLocalChecked(); v8::Local result = script->Run(context).ToLocalChecked(); CHECK(result->IsString()); @@ -140,8 +140,8 @@ TEST_F(EnvironmentTest, LoadEnvironmentWithCallback) { context, v8::String::NewFromOneByte( isolate_, - reinterpret_cast("argv0"), - v8::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked(); + reinterpret_cast("argv0")) + .ToLocalChecked()).ToLocalChecked(); CHECK(argv0->IsString()); return info.process_object; @@ -165,15 +165,15 @@ TEST_F(EnvironmentTest, LoadEnvironmentWithSource) { context, v8::String::NewFromOneByte( isolate_, - reinterpret_cast("process"), - v8::NewStringType::kNormal).ToLocalChecked()) + reinterpret_cast("process")) + .ToLocalChecked()) .ToLocalChecked()->IsObject()); CHECK(main_ret.As()->Get( context, v8::String::NewFromOneByte( isolate_, - reinterpret_cast("require"), - v8::NewStringType::kNormal).ToLocalChecked()) + reinterpret_cast("require")) + .ToLocalChecked()) .ToLocalChecked()->IsFunction()); } @@ -509,8 +509,8 @@ TEST_F(EnvironmentTest, InspectorMultipleEmbeddedEnvironments) { context, v8::String::NewFromOneByte( isolate_, - reinterpret_cast("messageFromWorker"), - v8::NewStringType::kNormal).ToLocalChecked()) + reinterpret_cast("messageFromWorker")) + .ToLocalChecked()) .ToLocalChecked(); CHECK_EQ(data.extracted_value, 42); CHECK_EQ(from_inspector->IntegerValue(context).FromJust(), 42); diff --git a/test/cctest/test_linked_binding.cc b/test/cctest/test_linked_binding.cc index 6724402c55aef1..523acc86c63e2a 100644 --- a/test/cctest/test_linked_binding.cc +++ b/test/cctest/test_linked_binding.cc @@ -9,11 +9,11 @@ void InitializeBinding(v8::Local exports, exports->Set( context, v8::String::NewFromOneByte(isolate, - reinterpret_cast("key"), - v8::NewStringType::kNormal).ToLocalChecked(), + reinterpret_cast("key")) + .ToLocalChecked(), v8::String::NewFromOneByte(isolate, - reinterpret_cast("value"), - v8::NewStringType::kNormal).ToLocalChecked()) + reinterpret_cast("value")) + .ToLocalChecked()) .FromJust(); } @@ -33,8 +33,8 @@ TEST_F(LinkedBindingTest, SimpleTest) { v8::Local script = v8::Script::Compile( context, v8::String::NewFromOneByte(isolate_, - reinterpret_cast(run_script), - v8::NewStringType::kNormal).ToLocalChecked()) + reinterpret_cast(run_script)) + .ToLocalChecked()) .ToLocalChecked(); v8::Local completion_value = script->Run(context).ToLocalChecked(); v8::String::Utf8Value utf8val(isolate_, completion_value); @@ -51,11 +51,11 @@ void InitializeLocalBinding(v8::Local exports, exports->Set( context, v8::String::NewFromOneByte(isolate, - reinterpret_cast("key"), - v8::NewStringType::kNormal).ToLocalChecked(), + reinterpret_cast("key")) + .ToLocalChecked(), v8::String::NewFromOneByte(isolate, - reinterpret_cast("value"), - v8::NewStringType::kNormal).ToLocalChecked()) + reinterpret_cast("value")) + .ToLocalChecked()) .FromJust(); } @@ -74,8 +74,8 @@ TEST_F(LinkedBindingTest, LocallyDefinedLinkedBindingTest) { v8::Local script = v8::Script::Compile( context, v8::String::NewFromOneByte(isolate_, - reinterpret_cast(run_script), - v8::NewStringType::kNormal).ToLocalChecked()) + reinterpret_cast(run_script)) + .ToLocalChecked()) .ToLocalChecked(); v8::Local completion_value = script->Run(context).ToLocalChecked(); v8::String::Utf8Value utf8val(isolate_, completion_value);