From 27139fc37c58bb9c344158bfb7276df5bfadae27 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sat, 24 Nov 2018 16:38:22 +0900 Subject: [PATCH] src: migrate to new V8 array API This change migrates the deprecated V8 Array API to new APIs. PR-URL: https://github.com/nodejs/node/pull/24613 Reviewed-By: Anna Henningsen Reviewed-By: Joyee Cheung Reviewed-By: Colin Ihrig Reviewed-By: Gireesh Punathil Reviewed-By: Gus Caplan Reviewed-By: Tiancheng "Timothy" Gu --- src/node_util.cc | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/node_util.cc b/src/node_util.cc index 1a08c0e255f8d3..496b6cbbcb1573 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -64,13 +64,13 @@ 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(); + Local values[2] = { Integer::New(isolate, state) }; + size_t number_of_values = 1; if (state != Promise::PromiseState::kPending) - ret->Set(env->context(), 1, promise->Result()).FromJust(); - + values[number_of_values++] = promise->Result(); + Local ret = Array::New(isolate, values, number_of_values); args.GetReturnValue().Set(ret); } @@ -82,11 +82,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 +103,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.