@@ -137,7 +137,7 @@ auto ObjectManipulator::Splice(v8::Isolate* isolate,
137137 }
138138
139139 if (!splice_val->IsFunction ()) {
140- return bv_factory_->New (" splice method is not a function" ,
140+ return bv_factory_->New (" splice member is not a function" ,
141141 type_execute_exception);
142142 }
143143
@@ -163,6 +163,49 @@ auto ObjectManipulator::Splice(v8::Isolate* isolate,
163163 return bv_factory_->New (local_context, maybe_value.ToLocalChecked ());
164164}
165165
166+ auto ObjectManipulator::Push (v8::Isolate* isolate,
167+ BinaryValue* obj_ptr,
168+ BinaryValue* new_val_ptr) -> BinaryValue::Ptr {
169+ const v8::Isolate::Scope isolate_scope (isolate);
170+ const v8::HandleScope handle_scope (isolate);
171+ const v8::Local<v8::Context> local_context = context_->Get ()->Get (isolate);
172+ const v8::Context::Scope context_scope (local_context);
173+
174+ const v8::Local<v8::Value> local_obj_val = obj_ptr->ToValue (local_context);
175+ const v8::Local<v8::Object> local_obj = local_obj_val.As <v8::Object>();
176+
177+ // Array.prototype.push doesn't exist in C++ in V8. We have to find the JS
178+ // function and call it:
179+ const v8::Local<v8::String> push_name =
180+ v8::String::NewFromUtf8Literal (isolate, " push" );
181+
182+ v8::Local<v8::Value> push_val;
183+ if (!local_obj->Get (local_context, push_name).ToLocal (&push_val)) {
184+ return bv_factory_->New (" no push method on object" , type_execute_exception);
185+ }
186+
187+ if (!push_val->IsFunction ()) {
188+ return bv_factory_->New (" push member is not a function" ,
189+ type_execute_exception);
190+ }
191+
192+ const v8::Local<v8::Function> push_func = push_val.As <v8::Function>();
193+
194+ const v8::TryCatch trycatch (isolate);
195+
196+ std::vector<v8::Local<v8::Value>> argv = {
197+ new_val_ptr->ToValue (local_context)};
198+
199+ v8::MaybeLocal<v8::Value> maybe_value = push_func->Call (
200+ local_context, local_obj, static_cast <int >(argv.size ()), argv.data ());
201+ if (maybe_value.IsEmpty ()) {
202+ return bv_factory_->New (local_context, trycatch.Message (),
203+ trycatch.Exception (), type_execute_exception);
204+ }
205+
206+ return bv_factory_->New (local_context, maybe_value.ToLocalChecked ());
207+ }
208+
166209auto ObjectManipulator::Call (v8::Isolate* isolate,
167210 BinaryValue* func_ptr,
168211 BinaryValue* this_ptr,
0 commit comments