From b35087179566fea487dfd4c6ea23a4cdf433ef31 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sun, 26 Apr 2015 13:49:13 +0200 Subject: [PATCH] Correctly force to array on property writing, closes #137 --- tests/execute_flags.phpt | 2 +- tests/execute_flags_args.phpt | 2 +- tests/execute_flags_property_writing.phpt | 42 +++++++++++++++++++++++ v8js_object_export.cc | 3 +- 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 tests/execute_flags_property_writing.phpt diff --git a/tests/execute_flags.phpt b/tests/execute_flags.phpt index 642b3eb..0ef6b19 100644 --- a/tests/execute_flags.phpt +++ b/tests/execute_flags.phpt @@ -1,5 +1,5 @@ --TEST-- -Test V8::executeString() : Forcing to arrays +Test V8::executeString() : Forcing to arrays (return value conversion) --SKIPIF-- --FILE-- diff --git a/tests/execute_flags_args.phpt b/tests/execute_flags_args.phpt index b839ee4..1275110 100644 --- a/tests/execute_flags_args.phpt +++ b/tests/execute_flags_args.phpt @@ -1,5 +1,5 @@ --TEST-- -Test V8::executeString() : Forcing to arrays +Test V8::executeString() : Forcing to arrays (argument passing) --SKIPIF-- --FILE-- diff --git a/tests/execute_flags_property_writing.phpt b/tests/execute_flags_property_writing.phpt new file mode 100644 index 0000000..55d74ab --- /dev/null +++ b/tests/execute_flags_property_writing.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test V8::executeString() : Forcing to arrays (property writing) +--SKIPIF-- + +--FILE-- +test = new stdClass(); + +try { + $v8->executeString($js, 'no_flags.js'); + var_dump($v8->test); + echo "---\n"; + $v8->executeString($js, 'force_to_array.js', V8Js::FLAG_FORCE_ARRAY); + var_dump($v8->test); +} catch (V8JsScriptException $e) { + var_dump($e); +} +?> +===EOF=== +--EXPECTF-- +object(stdClass)#%d (1) { + ["foo"]=> + object(V8Object)#%d (1) { + ["hello"]=> + string(5) "world" + } +} +--- +object(stdClass)#%d (1) { + ["foo"]=> + array(1) { + ["hello"]=> + string(5) "world" + } +} +===EOF=== diff --git a/v8js_object_export.cc b/v8js_object_export.cc index 6581061..e108740 100644 --- a/v8js_object_export.cc +++ b/v8js_object_export.cc @@ -648,8 +648,9 @@ inline v8::Local v8js_named_property_callback(v8::Local p zval_ptr_dtor(&php_value); } } else if (callback_type == V8JS_PROP_SETTER) { + int flags = V8JS_GLOBAL_GET_FLAGS(isolate); MAKE_STD_ZVAL(php_value); - if (v8js_to_zval(set_value, php_value, 0, isolate TSRMLS_CC) != SUCCESS) { + if (v8js_to_zval(set_value, php_value, flags, isolate TSRMLS_CC) != SUCCESS) { ret_value = v8::Handle(); } else {