From 48feb0bf35c1eb32e0b69417dc1d09e7eb9342dd Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Fri, 11 Apr 2014 20:42:55 +0200 Subject: [PATCH] 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. --- tests/property_visibility-delete.phpt | 75 +++++++++++++++++++++++++++ v8js_convert.cc | 12 ++++- 2 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 tests/property_visibility-delete.phpt diff --git a/tests/property_visibility-delete.phpt b/tests/property_visibility-delete.phpt new file mode 100644 index 0000000..73a484a --- /dev/null +++ b/tests/property_visibility-delete.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test V8::executeString() : Property visibility - delete +--SKIPIF-- + +--FILE-- +$a); + } +} + +$js = new V8Js(); +$js->foo = new Foo(); + +$script = <<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=== diff --git a/v8js_convert.cc b/v8js_convert.cc index ef34f3f..227ae2f 100644 --- a/v8js_convert.cc +++ b/v8js_convert.cc @@ -725,6 +725,7 @@ static inline v8::Local php_v8js_named_property_callback(v8::Localhas_property(object, prop, 0 ZEND_HASH_KEY_NULL TSRMLS_CC)) { ret_value = V8JS_UINT(v8::None); @@ -732,8 +733,15 @@ static inline v8::Local php_v8js_named_property_callback(v8::Local(); // empty handle } } else { - h->unset_property(object, prop ZEND_HASH_KEY_NULL TSRMLS_CC); - ret_value = V8JS_BOOL(true); + 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(); // empty handle + } } zval_ptr_dtor(&prop); } else {