0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-22 14:01:53 +00:00

Merge pull request #505 from chrisbckr/php82-AllowDynamicProperties

* Added AllowDynamicPropertis on V8Js, V8Object and V8Function
This commit is contained in:
Stefan Siegl 2023-02-19 18:54:17 +01:00 committed by GitHub
commit eb66c66cff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 3 deletions

View File

@ -5,6 +5,7 @@ Test V8::executeString() : has_property after dispose
--FILE-- --FILE--
<?php <?php
#[AllowDynamicProperties]
class Foo { class Foo {
function callMe($x) { function callMe($x) {
var_dump(property_exists($x, 'bla')); var_dump(property_exists($x, 'bla'));

View File

@ -5,6 +5,7 @@ Test V8::executeString() : Issue #250 (early free of array)
--FILE-- --FILE--
<?php <?php
#[AllowDynamicProperties]
class TestObject { class TestObject {
private $data = []; private $data = [];
@ -55,9 +56,9 @@ try {
?> ?>
===EOF=== ===EOF===
--EXPECTF-- --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: Stack trace:
#0 [internal function]: TestObject->setTitle('ouch') #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} #2 {main}
thrown in %s%eissue_250_001.php on line 9 thrown in %s%eissue_250_001.php on line 10

View File

@ -5,6 +5,7 @@ Test V8::executeString() : Property visibility - has property
--FILE-- --FILE--
<?php <?php
#[AllowDynamicProperties]
class Foo { class Foo {
private $privBar = "privBar"; private $privBar = "privBar";
protected $protBar = "protBar"; protected $protBar = "protBar";

View File

@ -5,6 +5,7 @@ Test V8::executeString() : Property visibility - set
--FILE-- --FILE--
<?php <?php
#[AllowDynamicProperties]
class Foo { class Foo {
private $privBar = "privBar"; private $privBar = "privBar";
protected $protBar = "protBar"; protected $protBar = "protBar";

View File

@ -5,6 +5,7 @@ Test V8::executeString() : Use after dispose
--FILE-- --FILE--
<?php <?php
#[AllowDynamicProperties]
class Foo { class Foo {
function callMe($x) { function callMe($x) {
var_dump($x); var_dump($x);

View File

@ -34,6 +34,7 @@ extern "C" {
#include "zend_closures.h" #include "zend_closures.h"
#include "ext/spl/spl_exceptions.h" #include "ext/spl/spl_exceptions.h"
#include "zend_exceptions.h" #include "zend_exceptions.h"
#include "zend_attributes.h"
} }
#define PHP_V8JS_SCRIPT_RES_NAME "V8Js script" #define PHP_V8JS_SCRIPT_RES_NAME "V8Js script"
@ -1059,6 +1060,14 @@ PHP_MINIT_FUNCTION(v8js_class) /* {{{ */
php_ce_v8js = zend_register_internal_class(&ce); php_ce_v8js = zend_register_internal_class(&ce);
php_ce_v8js->create_object = v8js_new; php_ce_v8js->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 */ /* V8Js handlers */
memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
v8js_object_handlers.clone_obj = NULL; v8js_object_handlers.clone_obj = NULL;

View File

@ -29,6 +29,7 @@ extern "C"
#include "zend_closures.h" #include "zend_closures.h"
#include "ext/spl/spl_exceptions.h" #include "ext/spl/spl_exceptions.h"
#include "zend_exceptions.h" #include "zend_exceptions.h"
#include "zend_attributes.h"
} }
/* {{{ Class Entries */ /* {{{ Class Entries */
@ -899,12 +900,28 @@ PHP_MINIT_FUNCTION(v8js_v8object_class) /* {{{ */
php_ce_v8object->ce_flags |= ZEND_ACC_FINAL; php_ce_v8object->ce_flags |= ZEND_ACC_FINAL;
php_ce_v8object->create_object = v8js_v8object_new; 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 */ /* V8Function Class */
INIT_CLASS_ENTRY(ce, "V8Function", v8js_v8function_methods); INIT_CLASS_ENTRY(ce, "V8Function", v8js_v8function_methods);
php_ce_v8function = zend_register_internal_class(&ce); php_ce_v8function = zend_register_internal_class(&ce);
php_ce_v8function->ce_flags |= ZEND_ACC_FINAL; php_ce_v8function->ce_flags |= ZEND_ACC_FINAL;
php_ce_v8function->create_object = v8js_v8object_new; 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 */ /* V8Generator Class */
INIT_CLASS_ENTRY(ce, "V8Generator", v8js_v8generator_methods); INIT_CLASS_ENTRY(ce, "V8Generator", v8js_v8generator_methods);
php_ce_v8generator = zend_register_internal_class(&ce); php_ce_v8generator = zend_register_internal_class(&ce);