From b3a0e1f2989b17054801f5a10473723e8f52f287 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sat, 24 Nov 2018 16:38:22 +0900 Subject: [PATCH 1/3] src: migrate to new V8 array API This change migrates the deprecated V8 Array API to new APIs. --- src/node_util.cc | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/node_util.cc b/src/node_util.cc index 1a08c0e255f8d3..7230399460fb41 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -64,13 +64,15 @@ static void GetPromiseDetails(const FunctionCallbackInfo& args) { auto isolate = args.GetIsolate(); Local promise = args[0].As(); - Local ret = Array::New(isolate, 2); int state = promise->State(); - ret->Set(env->context(), 0, Integer::New(isolate, state)).FromJust(); + std::vector> values; + values.push_back(Integer::New(isolate, state)); if (state != Promise::PromiseState::kPending) - ret->Set(env->context(), 1, promise->Result()).FromJust(); + values.push_back(promise->Result()); + Local ret = Array::New( + isolate, values.data(), values.size()); args.GetReturnValue().Set(ret); } @@ -82,11 +84,13 @@ static void GetProxyDetails(const FunctionCallbackInfo& args) { Local proxy = args[0].As(); - Local ret = Array::New(args.GetIsolate(), 2); - ret->Set(env->context(), 0, proxy->GetTarget()).FromJust(); - ret->Set(env->context(), 1, proxy->GetHandler()).FromJust(); + Local ret[] = { + proxy->GetTarget(), + proxy->GetHandler() + }; - args.GetReturnValue().Set(ret); + args.GetReturnValue().Set( + Array::New(args.GetIsolate(), ret, arraysize(ret))); } static void PreviewEntries(const FunctionCallbackInfo& args) { @@ -101,11 +105,13 @@ static void PreviewEntries(const FunctionCallbackInfo& args) { // Fast path for WeakMap, WeakSet and Set iterators. if (args.Length() == 1) return args.GetReturnValue().Set(entries); - Local ret = Array::New(env->isolate(), 2); - ret->Set(env->context(), 0, entries).FromJust(); - ret->Set(env->context(), 1, Boolean::New(env->isolate(), is_key_value)) - .FromJust(); - return args.GetReturnValue().Set(ret); + + Local ret[] = { + entries, + Boolean::New(env->isolate(), is_key_value) + }; + return args.GetReturnValue().Set( + Array::New(env->isolate(), ret, arraysize(ret))); } // Side effect-free stringification that will never throw exceptions. From 11230d28d22a126151c4f480c830b645c82c531f Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Tue, 27 Nov 2018 10:55:42 +0900 Subject: [PATCH 2/3] src: set maximum of vector This addresses the comment in #24613 --- src/node_util.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_util.cc b/src/node_util.cc index 7230399460fb41..20e3ff0ead3211 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -66,7 +66,7 @@ static void GetPromiseDetails(const FunctionCallbackInfo& args) { Local promise = args[0].As(); int state = promise->State(); - std::vector> values; + std::vector> values(2); values.push_back(Integer::New(isolate, state)); if (state != Promise::PromiseState::kPending) values.push_back(promise->Result()); From 3729328ffe25f767b5e69d4393d06ef5142d2176 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 28 Nov 2018 10:48:13 +0900 Subject: [PATCH 3/3] src: refactor src/node_util.cc Use static sized data structure --- src/node_util.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/node_util.cc b/src/node_util.cc index 20e3ff0ead3211..496b6cbbcb1573 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -66,13 +66,11 @@ static void GetPromiseDetails(const FunctionCallbackInfo& args) { Local promise = args[0].As(); int state = promise->State(); - std::vector> values(2); - values.push_back(Integer::New(isolate, state)); + Local values[2] = { Integer::New(isolate, state) }; + size_t number_of_values = 1; if (state != Promise::PromiseState::kPending) - values.push_back(promise->Result()); - - Local ret = Array::New( - isolate, values.data(), values.size()); + values[number_of_values++] = promise->Result(); + Local ret = Array::New(isolate, values, number_of_values); args.GetReturnValue().Set(ret); }