File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3030
3131 # Reset this number to 0 on major V8 upgrades.
3232 # Increment by one for each non-official patch applied to deps/v8.
33- 'v8_embedder_string' : '-node.9 ' ,
33+ 'v8_embedder_string' : '-node.10 ' ,
3434
3535 # Enable disassembler for `--print-code` v8 options
3636 'v8_enable_disassembler' : 1 ,
Original file line number Diff line number Diff line change @@ -3779,6 +3779,12 @@ class V8_EXPORT Array : public Object {
37793779 */
37803780 static Local<Array> New (Isolate* isolate, int length = 0 );
37813781
3782+ /* *
3783+ * Creates a JavaScript array out of a Local<Value> array in C++
3784+ * with a known length.
3785+ */
3786+ static Local<Array> New (Isolate* isolate, Local<Value>* elements,
3787+ size_t length);
37823788 V8_INLINE static Array* Cast (Value* obj);
37833789 private:
37843790 Array ();
Original file line number Diff line number Diff line change @@ -6981,6 +6981,23 @@ Local<v8::Array> v8::Array::New(Isolate* isolate, int length) {
69816981 return Utils::ToLocal (obj);
69826982}
69836983
6984+ Local<v8::Array> v8::Array::New (Isolate* isolate, Local<Value>* elements,
6985+ size_t length) {
6986+ i::Isolate* i_isolate = reinterpret_cast <i::Isolate*>(isolate);
6987+ i::Factory* factory = i_isolate->factory ();
6988+ LOG_API (i_isolate, Array, New);
6989+ ENTER_V8_NO_SCRIPT_NO_EXCEPTION (i_isolate);
6990+ int len = static_cast <int >(length);
6991+
6992+ i::Handle<i::FixedArray> result = factory->NewFixedArray (len);
6993+ for (int i = 0 ; i < len; i++) {
6994+ i::Handle<i::Object> element = Utils::OpenHandle (*elements[i]);
6995+ result->set (i, *element);
6996+ }
6997+
6998+ return Utils::ToLocal (
6999+ factory->NewJSArrayWithElements (result, i::PACKED_ELEMENTS, len));
7000+ }
69847001
69857002uint32_t v8::Array::Length () const {
69867003 i::Handle<i::JSArray> obj = Utils::OpenHandle (this );
Original file line number Diff line number Diff line change @@ -5247,6 +5247,22 @@ THREADED_TEST(Array) {
52475247 CHECK_EQ(27u, array->Length());
52485248 array = v8::Array::New(context->GetIsolate(), -27);
52495249 CHECK_EQ(0u, array->Length());
5250+
5251+ std::vector<Local<Value>> vector = {v8_num(1), v8_num(2), v8_num(3)};
5252+ array = v8::Array::New(context->GetIsolate(), vector.data(), vector.size());
5253+ CHECK_EQ(vector.size(), array->Length());
5254+ CHECK_EQ(1, arr->Get(context.local(), 0)
5255+ .ToLocalChecked()
5256+ ->Int32Value(context.local())
5257+ .FromJust());
5258+ CHECK_EQ(2, arr->Get(context.local(), 1)
5259+ .ToLocalChecked()
5260+ ->Int32Value(context.local())
5261+ .FromJust());
5262+ CHECK_EQ(3, arr->Get(context.local(), 2)
5263+ .ToLocalChecked()
5264+ ->Int32Value(context.local())
5265+ .FromJust());
52505266}
52515267
52525268
You can’t perform that action at this time.
0 commit comments