0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-23 00:51:51 +00:00
phpv8/tests/object_passback.phpt
2013-10-21 20:00:58 +02:00

75 lines
1.0 KiB
PHP

--TEST--
Test V8::executeString() : Object passing PHP > JS > PHP
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
class Bar {
function sayHello() {
echo "Hello\n";
}
}
class Foo {
function getBar() {
return new Bar();
}
function callMulti($list) {
foreach($list as $x) {
echo get_class($x)."\n"; // V8Object vs. Bar
$x->sayHello();
}
}
function callSingle($inst) {
echo get_class($inst)."\n";
$inst->sayHello();
}
}
$v8 = new V8Js();
$v8->foo = new Foo();
$JS = <<< EOF
var obj = PHP.foo.getBar();
PHP.foo.callMulti([obj]);
PHP.foo.callMulti([obj]);
PHP.foo.callSingle(obj);
PHP.foo.callSingle(obj);
obj = {};
obj.sayHello = function() {
print("JavaScript Hello\\n");
};
PHP.foo.callMulti([obj]);
PHP.foo.callMulti([obj]);
PHP.foo.callSingle(obj);
PHP.foo.callSingle(obj);
EOF;
$v8->executeString($JS);
?>
===EOF===
--EXPECT--
Bar
Hello
Bar
Hello
Bar
Hello
Bar
Hello
V8Object
JavaScript Hello
V8Object
JavaScript Hello
V8Object
JavaScript Hello
V8Object
JavaScript Hello
===EOF===