mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 08:11:52 +00:00
Merge pull request #509 from chrisbckr/php8-propagate_exception_magic_methods
Php8 propagate exception magic methods
This commit is contained in:
commit
752cfa1d50
54
tests/php_exceptions_007.phpt
Normal file
54
tests/php_exceptions_007.phpt
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
--TEST--
|
||||||
|
Test V8::executeString() : PHP Exception handling (throwed inside magic method)
|
||||||
|
--SKIPIF--
|
||||||
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
class SomeClass {
|
||||||
|
function someMethod($someVariable) {
|
||||||
|
return $someVariable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function triggerException() {
|
||||||
|
throw new Exception("Some exception");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __get($key) {
|
||||||
|
$this->triggerException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function execute($code, $flags = V8Js::FLAG_NONE) {
|
||||||
|
$js = new V8Js();
|
||||||
|
$js->output = new stdClass();
|
||||||
|
$js->SomeClassInstance = new SomeClass();
|
||||||
|
try {
|
||||||
|
$js->executeString("
|
||||||
|
try {
|
||||||
|
$code
|
||||||
|
} catch(e) {
|
||||||
|
PHP.output.result = 'Caught exception at javascript level : ' + e.getMessage();
|
||||||
|
}
|
||||||
|
", '', $flags);
|
||||||
|
print($js->output->result.PHP_EOL);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
print( "Caught exception at php level : ".$e->getMessage().PHP_EOL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
execute("PHP.SomeClassInstance.triggerException();");
|
||||||
|
execute("PHP.SomeClassInstance.someMethod(PHP.SomeClassInstance.TriggerMagicMethod);");
|
||||||
|
execute("PHP.SomeClassInstance.TriggerMagicMethod;");
|
||||||
|
execute("PHP.SomeClassInstance.triggerException();", V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
|
||||||
|
execute("PHP.SomeClassInstance.someMethod(PHP.SomeClassInstance.TriggerMagicMethod);", V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
|
||||||
|
execute("PHP.SomeClassInstance.TriggerMagicMethod;", V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
|
||||||
|
?>
|
||||||
|
===EOF===
|
||||||
|
--EXPECTF--
|
||||||
|
Caught exception at php level : Some exception
|
||||||
|
Caught exception at php level : Some exception
|
||||||
|
Caught exception at php level : Some exception
|
||||||
|
Caught exception at javascript level : Some exception
|
||||||
|
Caught exception at javascript level : Some exception
|
||||||
|
Caught exception at javascript level : Some exception
|
||||||
|
===EOF===
|
@ -765,10 +765,12 @@ v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::Name> property_n
|
|||||||
(property_info != ZEND_WRONG_PROPERTY_INFO &&
|
(property_info != ZEND_WRONG_PROPERTY_INFO &&
|
||||||
property_info->flags & ZEND_ACC_PUBLIC)) {
|
property_info->flags & ZEND_ACC_PUBLIC)) {
|
||||||
zval *property_val = zend_read_property(NULL, &zobject, name, name_len, true, &php_value);
|
zval *property_val = zend_read_property(NULL, &zobject, name, name_len, true, &php_value);
|
||||||
// special case uninitialized_zval_ptr and return an empty value
|
if(EG(exception)) {
|
||||||
// (indicating that we don't intercept this property) if the
|
ret_value = v8js_propagate_exception(ctx);
|
||||||
// property doesn't exist.
|
} else if (property_val == &EG(uninitialized_zval)) {
|
||||||
if (property_val == &EG(uninitialized_zval)) {
|
// special case uninitialized_zval_ptr and return an empty value
|
||||||
|
// (indicating that we don't intercept this property) if the
|
||||||
|
// property doesn't exist.
|
||||||
ret_value = v8::Local<v8::Value>();
|
ret_value = v8::Local<v8::Value>();
|
||||||
} else {
|
} else {
|
||||||
// wrap it
|
// wrap it
|
||||||
|
Loading…
Reference in New Issue
Block a user