0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-22 12:51:52 +00:00
phpv8/tests/js-construct-protected-ctor.phpt
Christiano Becker fab7a68717 PHP 8.2 compatibility
* tests/array_access_002.phpt - added #[AllowDynamicProperties] to the class MyArray
* tests/js-construct-protected-ctor.phpt - some change on how pph8.2 Exepctions references the line that caused the exception, when some call have multiple lines (eg: the executeString in this test), now references the line where the command started (first line) instead of the last line.
* V8Js Object Export: added to not enumerate magic methods __serialize and __unserialize - this two methods was added to DateTime objects and was causing tests/var_dump.phpt failing.
2023-02-20 08:09:13 -03:00

101 lines
2.0 KiB
PHP

--TEST--
Test V8::executeString() : Test PHP object construction controlled by JavaScript (protected ctor)
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$v8 = new V8Js();
class Greeter {
protected $_name = null;
protected function __construct($name) {
echo "ctor called (php)\n";
$this->_name = $name;
}
static function getInstance($name) {
return new Greeter($name);
}
function sayHello() {
echo "Hello ".$this->_name."\n";
}
}
$v8->greeter = Greeter::getInstance("John");
try {
$v8->executeString('
PHP.greeter.sayHello();
var ngGreeter = new PHP.greeter.constructor("Ringo");
ngGreeter.sayHello();
', 'ctor-test');
} catch(V8JsScriptException $e) {
echo "caught js exception\n";
var_dump($e);
}
?>
===EOF===
--EXPECTF--
ctor called (php)
Hello John
caught js exception
object(V8JsScriptException)#%d (13) {
["message":protected]=>
string(56) "ctor-test:4: Call to protected __construct() not allowed"
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(%d) "%s"
["line":protected]=>
int(%d)
["trace":"Exception":private]=>
array(1) {
[0]=>
array(6) {
["file"]=>
string(%d) "%s"
["line"]=>
int(%d)
["function"]=>
string(13) "executeString"
["class"]=>
string(4) "V8Js"
["type"]=>
string(2) "->"
["args"]=>
array(2) {
[0]=>
string(%d) "
PHP.greeter.sayHello();
var ngGreeter = new PHP.greeter.constructor("Ringo");
ngGreeter.sayHello();
"
[1]=>
string(9) "ctor-test"
}
}
}
["previous":"Exception":private]=>
NULL
["JsFileName":protected]=>
string(9) "ctor-test"
["JsLineNumber":protected]=>
int(4)
["JsStartColumn":protected]=>
int(18)
["JsEndColumn":protected]=>
int(19)
["JsSourceLine":protected]=>
string(55) " var ngGreeter = new PHP.greeter.constructor("Ringo");"
["JsTrace":protected]=>
NULL
}
===EOF===