From 8126fc49283414f43dd1a1ae312dd97f54b484e1 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Thu, 11 Aug 2016 18:54:38 +0200 Subject: [PATCH] Handle Z_TYPE == IS_REFERENCE well, fixes #246 --- tests/issue_246_001.phpt | 18 ++++++++++++++++++ v8js_convert.cc | 13 ++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 tests/issue_246_001.phpt diff --git a/tests/issue_246_001.phpt b/tests/issue_246_001.phpt new file mode 100644 index 0000000..e2b12ae --- /dev/null +++ b/tests/issue_246_001.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test V8::executeString() : Handle Z_TYPE == IS_REFERENCE (issue #246) +--SKIPIF-- + +--FILE-- + 'ipsum']; +array_walk_recursive($array, function (&$item) {}); +$v8->some_array = $array; +$v8->executeString('var_dump(PHP.some_array.lorem);'); +?> +===EOF=== +--EXPECT-- +string(5) "ipsum" +===EOF=== diff --git a/v8js_convert.cc b/v8js_convert.cc index cbfef2b..ed29b0e 100644 --- a/v8js_convert.cc +++ b/v8js_convert.cc @@ -104,11 +104,16 @@ v8::Handle zval_to_v8js(zval *value, v8::Isolate *isolate TSRMLS_DC) long v; zend_class_entry *ce; - if(Z_TYPE_P(value) == IS_INDIRECT) - value = Z_INDIRECT_P(value); - switch (Z_TYPE_P(value)) { + case IS_INDIRECT: + jsValue = zval_to_v8js(Z_INDIRECT_P(value), isolate); + break; + + case IS_REFERENCE: + jsValue = zval_to_v8js(Z_REFVAL_P(value), isolate); + break; + case IS_ARRAY: jsValue = v8js_hash_to_jsarr(value, isolate TSRMLS_CC); break; @@ -163,8 +168,10 @@ v8::Handle zval_to_v8js(zval *value, v8::Isolate *isolate TSRMLS_DC) case IS_UNDEF: default: /* undefined -> return v8::Value left empty */ + jsValue = v8::Undefined(isolate); break; } + return jsValue; } /* }}} */