mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 07:01:52 +00:00
support php8
This commit is contained in:
parent
6a7753a43a
commit
97cc819ade
@ -50,7 +50,11 @@ static zval v8js_array_access_dispatch(zend_object *object, const char *method_n
|
||||
fci.params = params;
|
||||
|
||||
fci.object = object;
|
||||
#if (PHP_MAJOR_VERSION < 8)
|
||||
fci.no_separation = 0;
|
||||
#else
|
||||
fci.named_params = NULL;
|
||||
#endif
|
||||
|
||||
zend_call_function(&fci, NULL);
|
||||
zval_dtor(&fci.function_name);
|
||||
|
@ -506,7 +506,11 @@ static PHP_METHOD(V8Js, __construct)
|
||||
V8JS_GLOBAL(isolate)->DefineOwnProperty(context, object_name_js, php_obj, v8::ReadOnly);
|
||||
|
||||
/* Export public property values */
|
||||
#if (PHP_MAJOR_VERSION < 8)
|
||||
HashTable *properties = zend_std_get_properties(getThis());
|
||||
#else
|
||||
HashTable *properties = zend_std_get_properties(Z_OBJ_P(getThis()));
|
||||
#endif
|
||||
zval *value;
|
||||
zend_string *member;
|
||||
|
||||
@ -665,7 +669,6 @@ static void v8js_compile_script(zval *this_ptr, const zend_string *str, const ze
|
||||
static void v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, long time_limit, size_t memory_limit, zval **return_value)
|
||||
{
|
||||
v8js_ctx *c = Z_V8JS_CTX_OBJ_P(this_ptr);
|
||||
|
||||
if (res->ctx != c) {
|
||||
zend_error(E_WARNING, "Script resource from wrong V8Js object passed");
|
||||
ZVAL_BOOL(*return_value, 0);
|
||||
@ -1306,7 +1309,33 @@ 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) /* {{{ */
|
||||
{
|
||||
v8js_ctx *c = Z_V8JS_CTX_OBJ(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, member, 1);
|
||||
|
||||
if(!property_info ||
|
||||
(property_info != ZEND_WRONG_PROPERTY_INFO &&
|
||||
(property_info->flags & ZEND_ACC_PUBLIC))) {
|
||||
/* Global PHP JS object */
|
||||
v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
|
||||
v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(v8_context, object_name_js).ToLocalChecked()->ToObject(v8_context).ToLocalChecked();
|
||||
|
||||
if (ZSTR_LEN(member) > std::numeric_limits<int>::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<v8::Name> key = V8JS_SYML(ZSTR_VAL(member), static_cast<int>(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);
|
||||
@ -1314,6 +1343,7 @@ static SINCE74(zval*, void) v8js_write_property(zval *object, zval *member, zval
|
||||
|
||||
/* 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))) {
|
||||
@ -1331,12 +1361,31 @@ static SINCE74(zval*, void) v8js_write_property(zval *object, zval *member, zval
|
||||
v8::Local<v8::Name> key = V8JS_SYML(Z_STRVAL_P(member), static_cast<int>(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);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#if PHP_VERSION_ID >= 80000
|
||||
static void v8js_unset_property(zend_object *object, zend_string *member, void **cache_slot) /* {{{ */
|
||||
{
|
||||
V8JS_BEGIN_CTX_OBJ(c, object)
|
||||
|
||||
/* Global PHP JS object */
|
||||
v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
|
||||
v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(v8_context, object_name_js).ToLocalChecked()->ToObject(v8_context).ToLocalChecked();
|
||||
|
||||
if (ZSTR_LEN(member) > std::numeric_limits<int>::max()) {
|
||||
zend_throw_exception(php_ce_v8js_exception,
|
||||
"Property name exceeds maximum supported length", 0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Delete value from PHP JS object */
|
||||
v8::Local<v8::Value> key = V8JS_SYML(ZSTR_VAL(member), static_cast<int>(ZSTR_LEN(member)));
|
||||
#else
|
||||
static void v8js_unset_property(zval *object, zval *member, void **cache_slot) /* {{{ */
|
||||
{
|
||||
V8JS_BEGIN_CTX(c, object)
|
||||
@ -1346,13 +1395,15 @@ static void v8js_unset_property(zval *object, zval *member, void **cache_slot) /
|
||||
v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(v8_context, object_name_js).ToLocalChecked()->ToObject(v8_context).ToLocalChecked();
|
||||
|
||||
if (Z_STRLEN_P(member) > std::numeric_limits<int>::max()) {
|
||||
zend_throw_exception(php_ce_v8js_exception,
|
||||
zend_throw_exception(php_ce_v8js_exception,
|
||||
"Property name exceeds maximum supported length", 0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Delete value from PHP JS object */
|
||||
v8::Local<v8::Value> key = V8JS_SYML(Z_STRVAL_P(member), static_cast<int>(Z_STRLEN_P(member)));
|
||||
#endif
|
||||
|
||||
jsobj->Delete(v8_context, key);
|
||||
|
||||
/* Unset from PHP object */
|
||||
|
@ -84,8 +84,13 @@ static inline struct v8js_ctx *v8js_ctx_fetch_object(zend_object *obj) {
|
||||
}
|
||||
|
||||
#define Z_V8JS_CTX_OBJ_P(zv) v8js_ctx_fetch_object(Z_OBJ_P(zv));
|
||||
#define Z_V8JS_CTX_OBJ(zv) v8js_ctx_fetch_object(zv);
|
||||
|
||||
|
||||
#if PHP_VERSION_ID >= 80000
|
||||
#define ZEND_ACC_DTOR 0
|
||||
#endif
|
||||
|
||||
PHP_MINIT_FUNCTION(v8js_class);
|
||||
|
||||
#endif /* V8JS_CLASS_H */
|
||||
|
@ -148,7 +148,11 @@ v8::Local<v8::Value> zval_to_v8js(zval *value, v8::Isolate *isolate) /* {{{ */
|
||||
ce = php_date_get_date_ce();
|
||||
if (instanceof_function(Z_OBJCE_P(value), ce)) {
|
||||
zval dtval;
|
||||
#if PHP_VERSION_ID >= 80000
|
||||
zend_call_method_with_0_params(Z_OBJ_P(value), NULL, NULL, "getTimestamp", &dtval);
|
||||
#else
|
||||
zend_call_method_with_0_params(value, NULL, NULL, "getTimestamp", &dtval);
|
||||
#endif
|
||||
v8::Date::New(isolate->GetEnteredOrMicrotaskContext(), ((double)Z_LVAL(dtval) * 1000.0)).ToLocal(&jsValue);
|
||||
zval_dtor(&dtval);
|
||||
} else
|
||||
|
@ -50,8 +50,14 @@ void v8js_create_script_exception(zval *return_value, v8::Isolate *isolate, v8::
|
||||
|
||||
object_init_ex(return_value, php_ce_v8js_script_exception);
|
||||
|
||||
#if PHP_VERSION_ID >= 80000
|
||||
#define PHPV8_EXPROP(type, name, value) \
|
||||
zend_update_property##type(php_ce_v8js_script_exception, Z_OBJ_P(return_value), #name, sizeof(#name) - 1, value);
|
||||
#else
|
||||
#define PHPV8_EXPROP(type, name, value) \
|
||||
zend_update_property##type(php_ce_v8js_script_exception, return_value, #name, sizeof(#name) - 1, value);
|
||||
#endif
|
||||
|
||||
|
||||
if (tc_message.IsEmpty()) {
|
||||
spprintf(&message_string, 0, "%s", exception_string);
|
||||
@ -128,7 +134,19 @@ void v8js_throw_script_exception(v8::Isolate *isolate, v8::TryCatch *try_catch)
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#if PHP_VERSION_ID >= 80000
|
||||
#define V8JS_EXCEPTION_METHOD(property) \
|
||||
static PHP_METHOD(V8JsScriptException, get##property) \
|
||||
{ \
|
||||
zval *value, rv; \
|
||||
\
|
||||
if (zend_parse_parameters_none() == FAILURE) { \
|
||||
return; \
|
||||
} \
|
||||
value = zend_read_property(php_ce_v8js_script_exception, Z_OBJ_P(getThis()), #property, sizeof(#property) - 1, 0, &rv); \
|
||||
RETURN_ZVAL(value, 1, 0); \
|
||||
}
|
||||
#else
|
||||
#define V8JS_EXCEPTION_METHOD(property) \
|
||||
static PHP_METHOD(V8JsScriptException, get##property) \
|
||||
{ \
|
||||
@ -140,6 +158,8 @@ void v8js_throw_script_exception(v8::Isolate *isolate, v8::TryCatch *try_catch)
|
||||
value = zend_read_property(php_ce_v8js_script_exception, getThis(), #property, sizeof(#property) - 1, 0, &rv); \
|
||||
RETURN_ZVAL(value, 1, 0); \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* {{{ proto string V8JsEScriptxception::getJsFileName()
|
||||
*/
|
||||
|
@ -311,8 +311,13 @@ V8JS_METHOD(require)
|
||||
ZVAL_STRING(¶ms[0], module_base_cstr);
|
||||
ZVAL_STRING(¶ms[1], module_id);
|
||||
|
||||
#if (PHP_MAJOR_VERSION < 8)
|
||||
call_result = call_user_function_ex(EG(function_table), NULL, &c->module_normaliser,
|
||||
&normaliser_result, 2, params, 0, NULL);
|
||||
#else
|
||||
call_result = call_user_function(EG(function_table), NULL, &c->module_normaliser,
|
||||
&normaliser_result, 2, params);
|
||||
#endif
|
||||
}
|
||||
|
||||
isolate->Enter();
|
||||
@ -435,7 +440,11 @@ V8JS_METHOD(require)
|
||||
|
||||
zend_try {
|
||||
ZVAL_STRING(¶ms[0], normalised_module_id);
|
||||
#if (PHP_MAJOR_VERSION < 8)
|
||||
call_result = call_user_function_ex(EG(function_table), NULL, &c->module_loader, &module_code, 1, params, 0, NULL);
|
||||
#else
|
||||
call_result = call_user_function(EG(function_table), NULL, &c->module_loader, &module_code, 1, params);
|
||||
#endif
|
||||
}
|
||||
zend_catch {
|
||||
v8js_terminate_execution(isolate);
|
||||
|
@ -137,8 +137,11 @@ static void v8js_call_php_func(zend_object *object, zend_function *method_ptr, c
|
||||
} else {
|
||||
fci.params = NULL;
|
||||
}
|
||||
|
||||
#if (PHP_MAJOR_VERSION < 8)
|
||||
fci.no_separation = 1;
|
||||
#else
|
||||
fci.named_params = NULL;
|
||||
#endif
|
||||
info.GetReturnValue().Set(V8JS_NULL);
|
||||
|
||||
{
|
||||
@ -640,8 +643,12 @@ v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::Name> property_n
|
||||
zval php_value;
|
||||
|
||||
zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
|
||||
#if PHP_VERSION_ID >= 80000
|
||||
zend_object &zobject = *object;
|
||||
#else
|
||||
zval zobject;
|
||||
ZVAL_OBJ(&zobject, object);
|
||||
#endif
|
||||
|
||||
v8js_function_tmpl_t *tmpl_ptr = reinterpret_cast<v8js_function_tmpl_t *>(self->GetAlignedPointerFromInternalField(0));
|
||||
v8::Local<v8::FunctionTemplate> tmpl = v8::Local<v8::FunctionTemplate>::New(isolate, *tmpl_ptr);
|
||||
@ -796,7 +803,11 @@ v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::Name> property_n
|
||||
const zend_object_handlers *h = object->handlers;
|
||||
|
||||
if (callback_type == V8JS_PROP_QUERY) {
|
||||
#if PHP_VERSION_ID >= 80000
|
||||
if (h->has_property(&zobject, Z_STR_P(&zname), 0, NULL)) {
|
||||
#else
|
||||
if (h->has_property(&zobject, &zname, 0, NULL)) {
|
||||
#endif
|
||||
ret_value = V8JS_UINT(v8::None);
|
||||
} else {
|
||||
ret_value = v8::Local<v8::Value>(); // empty handle
|
||||
@ -807,7 +818,11 @@ v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::Name> property_n
|
||||
if(!property_info ||
|
||||
(property_info != ZEND_WRONG_PROPERTY_INFO &&
|
||||
property_info->flags & ZEND_ACC_PUBLIC)) {
|
||||
#if PHP_VERSION_ID >= 80000
|
||||
h->unset_property(&zobject, Z_STR_P(&zname), NULL);
|
||||
#else
|
||||
h->unset_property(&zobject, &zname, NULL);
|
||||
#endif
|
||||
ret_value = V8JS_TRUE();
|
||||
}
|
||||
else {
|
||||
|
@ -82,6 +82,11 @@ int v8js_get_properties_hash(v8::Local<v8::Value> jsValue, HashTable *retval, in
|
||||
(ctx) = Z_V8JS_CTX_OBJ_P(object); \
|
||||
V8JS_CTX_PROLOGUE(ctx);
|
||||
|
||||
#define V8JS_BEGIN_CTX_OBJ(ctx, object) \
|
||||
v8js_ctx *(ctx); \
|
||||
(ctx) = Z_V8JS_CTX_OBJ(object); \
|
||||
V8JS_CTX_PROLOGUE(ctx);
|
||||
|
||||
|
||||
#if PHP_VERSION_ID < 70400
|
||||
#define SINCE74(x,y) y
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -35,7 +35,7 @@ static inline v8js_v8object *v8js_v8object_fetch_object(zend_object *obj) {
|
||||
}
|
||||
|
||||
#define Z_V8JS_V8OBJECT_OBJ_P(zv) v8js_v8object_fetch_object(Z_OBJ_P(zv));
|
||||
|
||||
#define Z_V8JS_V8OBJECT_OBJ(zv) v8js_v8object_fetch_object(zv);
|
||||
|
||||
/* {{{ Generator container */
|
||||
struct v8js_v8generator {
|
||||
|
Loading…
Reference in New Issue
Block a user