diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-11-06 18:05:48 +0800 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2018-12-06 15:25:38 +0100 |
commit | 0e090768de1844c493013d5e99bd903928aff2ab (patch) | |
tree | dde246dd6e38b75366106600cff75d958b9d16cb /deps/v8/test | |
parent | 5620727f30e5867671d9ec03b77a36fb7ca7ff4f (diff) | |
download | android-node-v8-0e090768de1844c493013d5e99bd903928aff2ab.tar.gz android-node-v8-0e090768de1844c493013d5e99bd903928aff2ab.tar.bz2 android-node-v8-0e090768de1844c493013d5e99bd903928aff2ab.zip |
deps: cherry-pick 0483e9a from upstream V8
Original commit message:
[api] Allow embedder to construct an Array from Local<Value>*
Currently to obtain a v8::Array out of a C array or a std::vector,
one needs to loop through the elements and call array->Set() multiple
times, and these calls go into v8::Object::Set() which can be slow.
This patch adds a new Array::New overload that converts a
Local<Value>* with known size into a Local<Array>.
Change-Id: I0a768f0e18eec51e78d58be455482ec6425ca188
Reviewed-on: https://chromium-review.googlesource.com/c/1317049
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Adam Klein <adamk@chromium.org>
Commit-Queue: Joyee Cheung <joyee@igalia.com>
Cr-Commit-Position: refs/heads/master@{#57261}
Refs: https://github.com/v8/v8/commit/0483e9a9abe77a73632fd85b9c0cd608efa9aa0d
PR-URL: https://github.com/nodejs/node/pull/24125
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yang Guo <yangguo@chromium.org>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'deps/v8/test')
-rw-r--r-- | deps/v8/test/cctest/test-api.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/deps/v8/test/cctest/test-api.cc b/deps/v8/test/cctest/test-api.cc index 9eb73fab7e..0d92508d24 100644 --- a/deps/v8/test/cctest/test-api.cc +++ b/deps/v8/test/cctest/test-api.cc @@ -5225,6 +5225,22 @@ THREADED_TEST(Array) { CHECK_EQ(27u, array->Length()); array = v8::Array::New(context->GetIsolate(), -27); CHECK_EQ(0u, array->Length()); + + std::vector<Local<Value>> vector = {v8_num(1), v8_num(2), v8_num(3)}; + array = v8::Array::New(context->GetIsolate(), vector.data(), vector.size()); + CHECK_EQ(vector.size(), array->Length()); + CHECK_EQ(1, arr->Get(context.local(), 0) + .ToLocalChecked() + ->Int32Value(context.local()) + .FromJust()); + CHECK_EQ(2, arr->Get(context.local(), 1) + .ToLocalChecked() + ->Int32Value(context.local()) + .FromJust()); + CHECK_EQ(3, arr->Get(context.local(), 2) + .ToLocalChecked() + ->Int32Value(context.local()) + .FromJust()); } |