mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 10:31:53 +00:00
Don't unset non-public properties, just hide them.
Before non-public properties were not reset also, trying to unset them just caused a fatal php error, effectively crashing the whole script.
This commit is contained in:
parent
c866e67313
commit
48feb0bf35
75
tests/property_visibility-delete.phpt
Normal file
75
tests/property_visibility-delete.phpt
Normal file
@ -0,0 +1,75 @@
|
||||
--TEST--
|
||||
Test V8::executeString() : Property visibility - delete
|
||||
--SKIPIF--
|
||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class Foo {
|
||||
private $privBar = "privBar";
|
||||
protected $protBar = "protBar";
|
||||
public $pubBar = "pubBar";
|
||||
|
||||
public function dump($a)
|
||||
{
|
||||
var_dump(@$this->$a);
|
||||
}
|
||||
}
|
||||
|
||||
$js = new V8Js();
|
||||
$js->foo = new Foo();
|
||||
|
||||
$script = <<<END
|
||||
|
||||
var_dump(PHP.foo.privBar);
|
||||
delete PHP.foo.privBar;
|
||||
var_dump(PHP.foo.privBar);
|
||||
|
||||
PHP.foo.privBar = 42;
|
||||
|
||||
var_dump(PHP.foo.privBar);
|
||||
delete PHP.foo.privBar;
|
||||
var_dump(PHP.foo.privBar);
|
||||
|
||||
var_dump(PHP.foo.protBar);
|
||||
delete PHP.foo.protBar;
|
||||
var_dump(PHP.foo.protBar);
|
||||
|
||||
var_dump(PHP.foo.pubBar);
|
||||
delete PHP.foo.pubBar;
|
||||
var_dump(PHP.foo.pubBar);
|
||||
|
||||
END;
|
||||
|
||||
$js->foo->dump('privBar');
|
||||
$js->foo->dump('protBar');
|
||||
$js->foo->dump('pubBar');
|
||||
|
||||
echo "--- JS ---\n";
|
||||
$js->executeString($script);
|
||||
|
||||
echo "--- PHP ---\n";
|
||||
$js->foo->dump('privBar');
|
||||
$js->foo->dump('protBar');
|
||||
$js->foo->dump('pubBar');
|
||||
|
||||
?>
|
||||
===EOF===
|
||||
--EXPECT--
|
||||
string(7) "privBar"
|
||||
string(7) "protBar"
|
||||
string(6) "pubBar"
|
||||
--- JS ---
|
||||
NULL
|
||||
NULL
|
||||
int(42)
|
||||
NULL
|
||||
NULL
|
||||
NULL
|
||||
string(6) "pubBar"
|
||||
NULL
|
||||
--- PHP ---
|
||||
string(7) "privBar"
|
||||
string(7) "protBar"
|
||||
NULL
|
||||
===EOF===
|
@ -725,6 +725,7 @@ static inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8
|
||||
zval *prop;
|
||||
MAKE_STD_ZVAL(prop);
|
||||
ZVAL_STRINGL(prop, name, name_len, 1);
|
||||
|
||||
if (callback_type == V8JS_PROP_QUERY) {
|
||||
if (h->has_property(object, prop, 0 ZEND_HASH_KEY_NULL TSRMLS_CC)) {
|
||||
ret_value = V8JS_UINT(v8::None);
|
||||
@ -732,9 +733,16 @@ static inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8
|
||||
ret_value = v8::Handle<v8::Value>(); // empty handle
|
||||
}
|
||||
} else {
|
||||
zend_property_info *property_info = zend_get_property_info(ce, prop, 1 TSRMLS_CC);
|
||||
|
||||
if(property_info && property_info->flags & ZEND_ACC_PUBLIC) {
|
||||
h->unset_property(object, prop ZEND_HASH_KEY_NULL TSRMLS_CC);
|
||||
ret_value = V8JS_BOOL(true);
|
||||
}
|
||||
else {
|
||||
ret_value = v8::Handle<v8::Value>(); // empty handle
|
||||
}
|
||||
}
|
||||
zval_ptr_dtor(&prop);
|
||||
} else {
|
||||
/* shouldn't reach here! but bail safely */
|
||||
|
Loading…
Reference in New Issue
Block a user