From 8b10c810492818a5651a093e27f95af16aeedfaf Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Thu, 5 Aug 2021 11:46:17 +0200 Subject: [PATCH] demo unification of PHP 8.0 code branch w/ old one --- v8js_class.cc | 33 ++++----------------------------- v8js_v8.h | 6 ++++++ 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/v8js_class.cc b/v8js_class.cc index 9576898..a9ba1f3 100644 --- a/v8js_class.cc +++ b/v8js_class.cc @@ -1309,9 +1309,11 @@ const zend_function_entry v8js_methods[] = { /* {{{ */ /* V8Js object handlers */ -#if PHP_VERSION_ID >= 80000 -static SINCE74(zval*, void) v8js_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot) /* {{{ */ +static SINCE74(zval*, void) v8js_write_property(SINCE80(zend_object, zval) *_object, SINCE80(zend_string, zval) *_member, zval *value, void **cache_slot) /* {{{ */ { + zend_object *object = SINCE80(_object, Z_OBJ_P(_object)); + zend_string *member = SINCE80(_member, Z_STR_P(_member)); + v8js_ctx *c = Z_V8JS_CTX_OBJ(object); V8JS_CTX_PROLOGUE_EX(c, SINCE74(value,)); @@ -1335,33 +1337,6 @@ static SINCE74(zval*, void) v8js_write_property(zend_object *object, zend_string v8::Local key = V8JS_SYML(ZSTR_VAL(member), static_cast(ZSTR_LEN(member))); jsobj->DefineOwnProperty(v8_context, key, zval_to_v8js(value, isolate), v8::ReadOnly); } -#else -static SINCE74(zval*, void) v8js_write_property(zval *object, zval *member, zval *value, void **cache_slot) /* {{{ */ -{ - v8js_ctx *c = Z_V8JS_CTX_OBJ_P(object); - V8JS_CTX_PROLOGUE_EX(c, SINCE74(value,)); - - /* Check whether member is public, if so, export to V8. */ - zend_property_info *property_info = zend_get_property_info(c->std.ce, Z_STR_P(member), 1); - - if(!property_info || - (property_info != ZEND_WRONG_PROPERTY_INFO && - (property_info->flags & ZEND_ACC_PUBLIC))) { - /* Global PHP JS object */ - v8::Local object_name_js = v8::Local::New(isolate, c->object_name); - v8::Local jsobj = V8JS_GLOBAL(isolate)->Get(v8_context, object_name_js).ToLocalChecked()->ToObject(v8_context).ToLocalChecked(); - - if (Z_STRLEN_P(member) > std::numeric_limits::max()) { - zend_throw_exception(php_ce_v8js_exception, - "Property name exceeds maximum supported length", 0); - return SINCE74(value,); - } - - /* Write value to PHP JS object */ - v8::Local key = V8JS_SYML(Z_STRVAL_P(member), static_cast(Z_STRLEN_P(member))); - jsobj->DefineOwnProperty(v8_context, key, zval_to_v8js(value, isolate), v8::ReadOnly); - } -#endif /* Write value to PHP object */ SINCE74(return,) std_object_handlers.write_property(object, member, value, NULL); diff --git a/v8js_v8.h b/v8js_v8.h index 67c9d7b..7adc67d 100644 --- a/v8js_v8.h +++ b/v8js_v8.h @@ -94,6 +94,12 @@ int v8js_get_properties_hash(v8::Local jsValue, HashTable *retval, in #define SINCE74(x,y) x #endif +#if PHP_VERSION_ID < 80000 +#define SINCE80(x,y) y +#else +#define SINCE80(x,y) x +#endif + #endif /* V8JS_V8_H */