From 53b12c3731a250909b050b1d724b196745bb6c9f Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Wed, 7 Nov 2018 07:50:51 +0100 Subject: [PATCH] test: fix NewFromUtf8 compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/24216 Reviewed-By: Michaƫl Zasso Reviewed-By: Anna Henningsen Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig --- doc/api/addons.md | 46 ++++++++++++++----- test/addons/dlopen-ping-pong/binding.cc | 4 +- test/addons/heap-profiler/binding.cc | 3 +- test/addons/hello-world-esm/binding.cc | 3 +- .../hello-world-function-export/binding.cc | 3 +- test/addons/hello-world/binding.cc | 3 +- test/addons/load-long-path/binding.cc | 3 +- test/addons/new-target/binding.cc | 3 +- test/addons/openssl-binding/binding.cc | 3 +- test/addons/symlinked-module/binding.cc | 3 +- test/addons/zlib-binding/binding.cc | 3 +- 11 files changed, 56 insertions(+), 21 deletions(-) diff --git a/doc/api/addons.md b/doc/api/addons.md index 757f24c5194271..e2530acb77d5e0 100644 --- a/doc/api/addons.md +++ b/doc/api/addons.md @@ -63,13 +63,15 @@ 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& args) { Isolate* isolate = args.GetIsolate(); - args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world")); + args.GetReturnValue().Set(String::NewFromUtf8( + isolate, "world", NewStringType::kNormal).ToLocalChecked()); } void Initialize(Local exports) { @@ -464,6 +466,7 @@ using v8::Exception; using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; +using v8::NewStringType; using v8::Number; using v8::Object; using v8::String; @@ -479,14 +482,18 @@ void Add(const FunctionCallbackInfo& args) { if (args.Length() < 2) { // Throw an Error that is passed back to JavaScript isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong number of arguments"))); + String::NewFromUtf8(isolate, + "Wrong number of arguments", + NewStringType::kNormal).ToLocalChecked())); return; } // Check the argument types if (!args[0]->IsNumber() || !args[1]->IsNumber()) { isolate->ThrowException(Exception::TypeError( - String::NewFromUtf8(isolate, "Wrong arguments"))); + String::NewFromUtf8(isolate, + "Wrong arguments", + NewStringType::kNormal).ToLocalChecked())); return; } @@ -534,6 +541,7 @@ using v8::Function; using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; +using v8::NewStringType; using v8::Null; using v8::Object; using v8::String; @@ -543,7 +551,10 @@ void RunCallback(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); Local cb = Local::Cast(args[0]); const unsigned argc = 1; - Local argv[argc] = { String::NewFromUtf8(isolate, "hello world") }; + Local argv[argc] = { + String::NewFromUtf8(isolate, + "hello world", + NewStringType::kNormal).ToLocalChecked() }; cb->Call(Null(isolate), argc, argv); } @@ -591,6 +602,7 @@ using v8::Context; using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; +using v8::NewStringType; using v8::Object; using v8::String; using v8::Value; @@ -600,7 +612,9 @@ void CreateObject(const FunctionCallbackInfo& args) { Local context = isolate->GetCurrentContext(); Local obj = Object::New(isolate); - obj->Set(String::NewFromUtf8(isolate, "msg"), + obj->Set(String::NewFromUtf8(isolate, + "msg", + NewStringType::kNormal).ToLocalChecked(), args[0]->ToString(context).ToLocalChecked()); args.GetReturnValue().Set(obj); @@ -644,13 +658,15 @@ 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& args) { Isolate* isolate = args.GetIsolate(); - args.GetReturnValue().Set(String::NewFromUtf8(isolate, "hello world")); + args.GetReturnValue().Set(String::NewFromUtf8( + isolate, "hello world", NewStringType::kNormal).ToLocalChecked()); } void CreateFunction(const FunctionCallbackInfo& args) { @@ -661,7 +677,8 @@ void CreateFunction(const FunctionCallbackInfo& args) { Local fn = tpl->GetFunction(context).ToLocalChecked(); // omit this to make it anonymous - fn->SetName(String::NewFromUtf8(isolate, "theFunction")); + fn->SetName(String::NewFromUtf8( + isolate, "theFunction", NewStringType::kNormal).ToLocalChecked()); args.GetReturnValue().Set(fn); } @@ -757,6 +774,7 @@ using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Isolate; using v8::Local; +using v8::NewStringType; using v8::Number; using v8::Object; using v8::Persistent; @@ -776,7 +794,8 @@ void MyObject::Init(Local exports) { // Prepare constructor template Local tpl = FunctionTemplate::New(isolate, New); - tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject")); + tpl->SetClassName(String::NewFromUtf8( + isolate, "MyObject", NewStringType::kNormal).ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); // Prototype @@ -784,7 +803,8 @@ void MyObject::Init(Local exports) { Local context = isolate->GetCurrentContext(); constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); - exports->Set(String::NewFromUtf8(isolate, "MyObject"), + exports->Set(String::NewFromUtf8( + isolate, "MyObject", NewStringType::kNormal).ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked()); } @@ -952,6 +972,7 @@ using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Isolate; using v8::Local; +using v8::NewStringType; using v8::Number; using v8::Object; using v8::Persistent; @@ -969,7 +990,8 @@ MyObject::~MyObject() { void MyObject::Init(Isolate* isolate) { // Prepare constructor template Local tpl = FunctionTemplate::New(isolate, New); - tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject")); + tpl->SetClassName(String::NewFromUtf8( + isolate, "MyObject", NewStringType::kNormal).ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); // Prototype @@ -1167,6 +1189,7 @@ using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Isolate; using v8::Local; +using v8::NewStringType; using v8::Object; using v8::Persistent; using v8::String; @@ -1183,7 +1206,8 @@ MyObject::~MyObject() { void MyObject::Init(Isolate* isolate) { // Prepare constructor template Local tpl = FunctionTemplate::New(isolate, New); - tpl->SetClassName(String::NewFromUtf8(isolate, "MyObject")); + tpl->SetClassName(String::NewFromUtf8( + isolate, "MyObject", NewStringType::kNormal).ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); Local context = isolate->GetCurrentContext(); diff --git a/test/addons/dlopen-ping-pong/binding.cc b/test/addons/dlopen-ping-pong/binding.cc index a3b9af1b8099a3..6a6c297b52fff9 100644 --- a/test/addons/dlopen-ping-pong/binding.cc +++ b/test/addons/dlopen-ping-pong/binding.cc @@ -15,6 +15,7 @@ using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Object; +using v8::NewStringType; using v8::String; using v8::Value; @@ -33,7 +34,8 @@ void LoadLibrary(const FunctionCallbackInfo& args) { void Ping(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); assert(ping_func != nullptr); - args.GetReturnValue().Set(String::NewFromUtf8(isolate, ping_func())); + args.GetReturnValue().Set(String::NewFromUtf8( + isolate, ping_func(), NewStringType::kNormal).ToLocalChecked()); } void init(Local exports) { diff --git a/test/addons/heap-profiler/binding.cc b/test/addons/heap-profiler/binding.cc index 861fb5a80c4651..29f58a5920825a 100644 --- a/test/addons/heap-profiler/binding.cc +++ b/test/addons/heap-profiler/binding.cc @@ -19,7 +19,8 @@ inline void Test(const v8::FunctionCallbackInfo& args) { inline void Initialize(v8::Local binding) { v8::Isolate* const isolate = binding->GetIsolate(); v8::Local context = isolate->GetCurrentContext(); - binding->Set(v8::String::NewFromUtf8(isolate, "test"), + binding->Set(v8::String::NewFromUtf8( + isolate, "test", v8::NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(isolate, Test) ->GetFunction(context) .ToLocalChecked()); diff --git a/test/addons/hello-world-esm/binding.cc b/test/addons/hello-world-esm/binding.cc index 944f5631956d15..02eecec099807a 100644 --- a/test/addons/hello-world-esm/binding.cc +++ b/test/addons/hello-world-esm/binding.cc @@ -3,7 +3,8 @@ void Method(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); - args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world")); + args.GetReturnValue().Set(v8::String::NewFromUtf8( + isolate, "world", v8::NewStringType::kNormal).ToLocalChecked()); } void init(v8::Local exports) { diff --git a/test/addons/hello-world-function-export/binding.cc b/test/addons/hello-world-function-export/binding.cc index 55d64b3d6c3513..e5476c4ee1e364 100644 --- a/test/addons/hello-world-function-export/binding.cc +++ b/test/addons/hello-world-function-export/binding.cc @@ -3,7 +3,8 @@ void Method(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); - args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world")); + args.GetReturnValue().Set(v8::String::NewFromUtf8( + isolate, "world", v8::NewStringType::kNormal).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 341b58f9a640d8..81bcbc29c78645 100644 --- a/test/addons/hello-world/binding.cc +++ b/test/addons/hello-world/binding.cc @@ -3,7 +3,8 @@ void Method(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); - args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world")); + args.GetReturnValue().Set(v8::String::NewFromUtf8( + isolate, "world", v8::NewStringType::kNormal).ToLocalChecked()); } // Not using the full NODE_MODULE_INIT() macro here because we want to test the diff --git a/test/addons/load-long-path/binding.cc b/test/addons/load-long-path/binding.cc index 944f5631956d15..02eecec099807a 100644 --- a/test/addons/load-long-path/binding.cc +++ b/test/addons/load-long-path/binding.cc @@ -3,7 +3,8 @@ void Method(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); - args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world")); + args.GetReturnValue().Set(v8::String::NewFromUtf8( + isolate, "world", v8::NewStringType::kNormal).ToLocalChecked()); } void init(v8::Local exports) { diff --git a/test/addons/new-target/binding.cc b/test/addons/new-target/binding.cc index 21b932ae018dfd..c2777c831e484a 100644 --- a/test/addons/new-target/binding.cc +++ b/test/addons/new-target/binding.cc @@ -12,7 +12,8 @@ inline void NewClass(const v8::FunctionCallbackInfo& args) { inline void Initialize(v8::Local binding) { auto isolate = binding->GetIsolate(); auto context = isolate->GetCurrentContext(); - binding->Set(v8::String::NewFromUtf8(isolate, "Class"), + binding->Set(v8::String::NewFromUtf8( + isolate, "Class", v8::NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(isolate, NewClass) ->GetFunction(context) .ToLocalChecked()); diff --git a/test/addons/openssl-binding/binding.cc b/test/addons/openssl-binding/binding.cc index bb00f1e176d7ce..122d420bc14e0b 100644 --- a/test/addons/openssl-binding/binding.cc +++ b/test/addons/openssl-binding/binding.cc @@ -22,7 +22,8 @@ inline void Initialize(v8::Local exports, v8::Local module, v8::Local context) { auto isolate = context->GetIsolate(); - auto key = v8::String::NewFromUtf8(isolate, "randomBytes"); + auto key = v8::String::NewFromUtf8( + isolate, "randomBytes", v8::NewStringType::kNormal).ToLocalChecked(); auto value = v8::FunctionTemplate::New(isolate, RandomBytes) ->GetFunction(context) .ToLocalChecked(); diff --git a/test/addons/symlinked-module/binding.cc b/test/addons/symlinked-module/binding.cc index 944f5631956d15..02eecec099807a 100644 --- a/test/addons/symlinked-module/binding.cc +++ b/test/addons/symlinked-module/binding.cc @@ -3,7 +3,8 @@ void Method(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); - args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world")); + args.GetReturnValue().Set(v8::String::NewFromUtf8( + isolate, "world", v8::NewStringType::kNormal).ToLocalChecked()); } void init(v8::Local exports) { diff --git a/test/addons/zlib-binding/binding.cc b/test/addons/zlib-binding/binding.cc index 1d0af911115359..0b82de211a8430 100644 --- a/test/addons/zlib-binding/binding.cc +++ b/test/addons/zlib-binding/binding.cc @@ -45,7 +45,8 @@ inline void Initialize(v8::Local exports, v8::Local module, v8::Local context) { auto isolate = context->GetIsolate(); - auto key = v8::String::NewFromUtf8(isolate, "compressBytes"); + auto key = v8::String::NewFromUtf8( + isolate, "compressBytes", v8::NewStringType::kNormal).ToLocalChecked(); auto value = v8::FunctionTemplate::New(isolate, CompressBytes) ->GetFunction(context) .ToLocalChecked();