From 83431fbd52fc9cb578bcbcfc0bebc23c4f05e1bb Mon Sep 17 00:00:00 2001 From: Christiano Becker Date: Sat, 18 Feb 2023 10:18:36 -0300 Subject: [PATCH] * Added AllowDynamicPropertis on V8Js, V8Object and V8Function * Added #[AllowDynamicProperties] on test classes that uses Dynamic Properties --- tests/has_property_after_dispose.phpt | 1 + tests/issue_250_001.phpt | 7 ++++--- tests/property_visibility-has-property.phpt | 1 + tests/property_visibility-set.phpt | 1 + tests/use_after_dispose.phpt | 1 + v8js_class.cc | 9 +++++++++ v8js_v8object_class.cc | 17 +++++++++++++++++ 7 files changed, 34 insertions(+), 3 deletions(-) diff --git a/tests/has_property_after_dispose.phpt b/tests/has_property_after_dispose.phpt index 02ee623..4f84725 100644 --- a/tests/has_property_after_dispose.phpt +++ b/tests/has_property_after_dispose.phpt @@ -5,6 +5,7 @@ Test V8::executeString() : has_property after dispose --FILE-- ===EOF=== --EXPECTF-- -Fatal error: Uncaught Error: Attempt to modify property "b" on null in %s%eissue_250_001.php:9 +Fatal error: Uncaught Error: Attempt to modify property "b" on null in %s%eissue_250_001.php:10 Stack trace: #0 [internal function]: TestObject->setTitle('ouch') -#1 %s%eissue_250_001.php(44): V8Js->executeString(' var v1 = se...') +#1 %s%eissue_250_001.php(45): V8Js->executeString(' var v1 = se...') #2 {main} - thrown in %s%eissue_250_001.php on line 9 + thrown in %s%eissue_250_001.php on line 10 diff --git a/tests/property_visibility-has-property.phpt b/tests/property_visibility-has-property.phpt index 1fdb5df..06b7f11 100644 --- a/tests/property_visibility-has-property.phpt +++ b/tests/property_visibility-has-property.phpt @@ -5,6 +5,7 @@ Test V8::executeString() : Property visibility - has property --FILE-- create_object = v8js_new; +#if PHP_VERSION_ID >= 80200 + php_ce_v8js->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES; + + zend_string *attribute_name_AllowDynamicProperties_class_V8Js = zend_string_init_interned("AllowDynamicProperties", sizeof("AllowDynamicProperties") - 1, 1); + zend_add_class_attribute(php_ce_v8js, attribute_name_AllowDynamicProperties_class_V8Js, 0); + zend_string_release(attribute_name_AllowDynamicProperties_class_V8Js); +#endif + /* V8Js handlers */ memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); v8js_object_handlers.clone_obj = NULL; diff --git a/v8js_v8object_class.cc b/v8js_v8object_class.cc index ff1495c..7bc4b4f 100644 --- a/v8js_v8object_class.cc +++ b/v8js_v8object_class.cc @@ -29,6 +29,7 @@ extern "C" #include "zend_closures.h" #include "ext/spl/spl_exceptions.h" #include "zend_exceptions.h" +#include "zend_attributes.h" } /* {{{ Class Entries */ @@ -899,11 +900,27 @@ PHP_MINIT_FUNCTION(v8js_v8object_class) /* {{{ */ php_ce_v8object->ce_flags |= ZEND_ACC_FINAL; php_ce_v8object->create_object = v8js_v8object_new; +#if PHP_VERSION_ID >= 80200 + php_ce_v8object->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES; + + zend_string *attribute_name_AllowDynamicProperties_class_v8object = zend_string_init_interned("AllowDynamicProperties", sizeof("AllowDynamicProperties") - 1, 1); + zend_add_class_attribute(php_ce_v8object, attribute_name_AllowDynamicProperties_class_v8object, 0); + zend_string_release(attribute_name_AllowDynamicProperties_class_v8object); +#endif + /* V8Function Class */ INIT_CLASS_ENTRY(ce, "V8Function", v8js_v8function_methods); php_ce_v8function = zend_register_internal_class(&ce); php_ce_v8function->ce_flags |= ZEND_ACC_FINAL; php_ce_v8function->create_object = v8js_v8object_new; + +#if PHP_VERSION_ID >= 80200 + php_ce_v8function->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES; + + zend_string *attribute_name_AllowDynamicProperties_class_v8function = zend_string_init_interned("AllowDynamicProperties", sizeof("AllowDynamicProperties") - 1, 1); + zend_add_class_attribute(php_ce_v8function, attribute_name_AllowDynamicProperties_class_v8function, 0); + zend_string_release(attribute_name_AllowDynamicProperties_class_v8function); +#endif /* V8Generator Class */ INIT_CLASS_ENTRY(ce, "V8Generator", v8js_v8generator_methods);