Skip to content

Commit f7c7a62

Browse files
committed
Replace uses of the old Value::NewArray method with new ArrayByValue type.
1 parent ff075a0 commit f7c7a62

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

src/node_php_phpobject_class.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,15 @@ class PhpObject::PhpInvokeMsg : public MessageToPhp {
645645
public:
646646
PhpInvokeMsg(ObjectMapper *m, Nan::Callback *callback, bool is_sync,
647647
objid_t obj, v8::Local<v8::String> method,
648-
const Nan::FunctionCallbackInfo<v8::Value> &info)
648+
const Nan::FunctionCallbackInfo<v8::Value> *info)
649649
: MessageToPhp(m, callback, is_sync), method_(m, method),
650-
argc_(info.Length()), argv_(Value::NewArray(m, info)),
650+
argc_(info->Length()), argv_(),
651651
should_convert_array_to_iterator_(false) {
652652
obj_.SetJsObject(obj);
653+
argv_.SetArrayByValue(argc_, [m, info](uint32_t idx, Value& v) {
654+
v.Set(m, (*info)[idx]);
655+
});
653656
}
654-
~PhpInvokeMsg() override { delete[] argv_; }
655657
inline bool should_convert_array_to_iterator() {
656658
return should_convert_array_to_iterator_;
657659
}
@@ -803,7 +805,7 @@ class PhpObject::PhpInvokeMsg : public MessageToPhp {
803805
Value obj_;
804806
Value method_;
805807
int argc_;
806-
Value *argv_;
808+
Value argv_;
807809
bool should_convert_array_to_iterator_;
808810
};
809811

@@ -824,7 +826,7 @@ void PhpObject::MethodThunk_(v8::Local<v8::String> method,
824826
return Nan::ThrowError("Invocation after PHP request has completed.");
825827
}
826828
PhpInvokeMsg msg(channel_, nullptr, true, // Sync call.
827-
id_, method, info);
829+
id_, method, &info);
828830
channel_->SendToPhp(&msg, MessageFlags::SYNC);
829831
THROW_IF_EXCEPTION("PHP exception thrown during method invocation", /* */);
830832
if (msg.retval().IsEmpty()) {

src/values.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -506,22 +506,6 @@ class Value {
506506
: type_(VALUE_EMPTY), empty_(0) {
507507
Set(m, v TSRMLS_CC);
508508
}
509-
template <typename T>
510-
static Value *NewArray(PhpObjectMapper *m, int argc, T* argv TSRMLS_DC) {
511-
Value *result = new Value[argc];
512-
for (int i = 0; i < argc; i++) {
513-
result[i].Set(m, argv[i] TSRMLS_CC);
514-
}
515-
return result;
516-
}
517-
static Value *NewArray(JsObjectMapper *m,
518-
const Nan::FunctionCallbackInfo<v8::Value> &info) {
519-
Value *result = new Value[info.Length()];
520-
for (int i = 0; i < info.Length(); i++) {
521-
result[i].Set(m, info[i]);
522-
}
523-
return result;
524-
}
525509
void Set(JsObjectMapper *m, v8::Local<v8::Value> v) {
526510
if (v->IsUndefined() || v->IsNull()) {
527511
/* Fall through to the default case. */

0 commit comments

Comments
 (0)