Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* Added AllowDynamicPropertis on V8Js, V8Object and V8Function #505

Merged
merged 1 commit into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/has_property_after_dispose.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Test V8::executeString() : has_property after dispose
--FILE--
<?php

#[AllowDynamicProperties]
class Foo {
function callMe($x) {
var_dump(property_exists($x, 'bla'));
Expand Down
7 changes: 4 additions & 3 deletions tests/issue_250_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Test V8::executeString() : Issue #250 (early free of array)
--FILE--
<?php

#[AllowDynamicProperties]
class TestObject {

private $data = [];
Expand Down Expand Up @@ -55,9 +56,9 @@ try {
?>
===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
1 change: 1 addition & 0 deletions tests/property_visibility-has-property.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Test V8::executeString() : Property visibility - has property
--FILE--
<?php

#[AllowDynamicProperties]
class Foo {
private $privBar = "privBar";
protected $protBar = "protBar";
Expand Down
1 change: 1 addition & 0 deletions tests/property_visibility-set.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Test V8::executeString() : Property visibility - set
--FILE--
<?php

#[AllowDynamicProperties]
class Foo {
private $privBar = "privBar";
protected $protBar = "protBar";
Expand Down
1 change: 1 addition & 0 deletions tests/use_after_dispose.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Test V8::executeString() : Use after dispose
--FILE--
<?php

#[AllowDynamicProperties]
class Foo {
function callMe($x) {
var_dump($x);
Expand Down
9 changes: 9 additions & 0 deletions v8js_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern "C" {
#include "zend_closures.h"
#include "ext/spl/spl_exceptions.h"
#include "zend_exceptions.h"
#include "zend_attributes.h"
}

#define PHP_V8JS_SCRIPT_RES_NAME "V8Js script"
Expand Down Expand Up @@ -1059,6 +1060,14 @@ PHP_MINIT_FUNCTION(v8js_class) /* {{{ */
php_ce_v8js = zend_register_internal_class(&ce);
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 */
memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
v8js_object_handlers.clone_obj = NULL;
Expand Down
17 changes: 17 additions & 0 deletions v8js_v8object_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down