Bladeren bron

Correctly force to array on property writing, closes #137

Stefan Siegl 10 jaren geleden
bovenliggende
commit
b350871795
4 gewijzigde bestanden met toevoegingen van 46 en 3 verwijderingen
  1. 1 1
      tests/execute_flags.phpt
  2. 1 1
      tests/execute_flags_args.phpt
  3. 42 0
      tests/execute_flags_property_writing.phpt
  4. 2 1
      v8js_object_export.cc

+ 1 - 1
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--
 <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
 --FILE--

+ 1 - 1
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--
 <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
 --FILE--

+ 42 - 0
tests/execute_flags_property_writing.phpt

@@ -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===

+ 2 - 1
v8js_object_export.cc

@@ -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 {