0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-09-16 18:05:18 +00:00

Correctly force to array on property writing, closes #137

This commit is contained in:
Stefan Siegl 2015-04-26 13:49:13 +02:00
parent 5c43a471b4
commit b350871795
4 changed files with 46 additions and 3 deletions

View File

@ -1,5 +1,5 @@
--TEST--
Test V8::executeString() : Forcing to arrays
Test V8::executeString() : Forcing to arrays (return value conversion)
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--

View File

@ -1,5 +1,5 @@
--TEST--
Test V8::executeString() : Forcing to arrays
Test V8::executeString() : Forcing to arrays (argument passing)
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--

View File

@ -0,0 +1,42 @@
--TEST--
Test V8::executeString() : Forcing to arrays (property writing)
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$js = <<<'EOT'
PHP.test.foo = { "hello": "world" };
EOT;
$v8 = new V8Js();
$v8->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===

View File

@ -648,8 +648,9 @@ inline v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::String> 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<v8::Value>();
}
else {