mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 09:21:52 +00:00
optimize redundancy code and fix some unit test
This commit is contained in:
parent
8b10c81049
commit
3d64f08536
@ -16,9 +16,9 @@ try {
|
|||||||
?>
|
?>
|
||||||
===EOF===
|
===EOF===
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Deprecated: Function V8Js::checkString() is deprecated in %s on line %d
|
Deprecated: %s V8Js::checkString() is deprecated in %s on line %d
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
||||||
Deprecated: Function V8Js::checkString() is deprecated in %s on line %d
|
Deprecated: %s V8Js::checkString() is deprecated in %s on line %d
|
||||||
string(%d) "V8Js::checkString():1: SyntaxError: %s"
|
string(%d) "V8Js::checkString():1: SyntaxError: %s"
|
||||||
===EOF===
|
===EOF===
|
||||||
|
@ -23,15 +23,15 @@ var_dump($v8->getPendingException());
|
|||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Deprecated: V8Js::__construct(): Disabling exception reporting is deprecated, $report_uncaught_exceptions != true in %s%eexception_clearing.php on line 3
|
Deprecated: V8Js::__construct(): Disabling exception reporting is deprecated, $report_uncaught_exceptions != true in %s%eexception_clearing.php on line 3
|
||||||
|
|
||||||
Deprecated: Function V8Js::getPendingException() is deprecated in %s%eexception_clearing.php on line 5
|
Deprecated: %s V8Js::getPendingException() is deprecated in %s%eexception_clearing.php on line 5
|
||||||
NULL
|
NULL
|
||||||
|
|
||||||
Deprecated: Function V8Js::clearPendingException() is deprecated in %s%eexception_clearing.php on line 7
|
Deprecated: %s V8Js::clearPendingException() is deprecated in %s%eexception_clearing.php on line 7
|
||||||
|
|
||||||
Deprecated: Function V8Js::getPendingException() is deprecated in %s%eexception_clearing.php on line 8
|
Deprecated: %s V8Js::getPendingException() is deprecated in %s%eexception_clearing.php on line 8
|
||||||
NULL
|
NULL
|
||||||
|
|
||||||
Deprecated: Function V8Js::getPendingException() is deprecated in %s%eexception_clearing.php on line 11
|
Deprecated: %s V8Js::getPendingException() is deprecated in %s%eexception_clearing.php on line 11
|
||||||
object(V8JsScriptException)#%d (13) {
|
object(V8JsScriptException)#%d (13) {
|
||||||
["message":protected]=>
|
["message":protected]=>
|
||||||
string(49) "throw_0:1: ReferenceError: fooobar is not defined"
|
string(49) "throw_0:1: ReferenceError: fooobar is not defined"
|
||||||
@ -83,8 +83,8 @@ object(V8JsScriptException)#%d (13) {
|
|||||||
at throw_0:1:1"
|
at throw_0:1:1"
|
||||||
}
|
}
|
||||||
|
|
||||||
Deprecated: Function V8Js::clearPendingException() is deprecated in %s%eexception_clearing.php on line 13
|
Deprecated: %s V8Js::clearPendingException() is deprecated in %s%eexception_clearing.php on line 13
|
||||||
|
|
||||||
Deprecated: Function V8Js::getPendingException() is deprecated in %s%eexception_clearing.php on line 14
|
Deprecated: %s V8Js::getPendingException() is deprecated in %s%eexception_clearing.php on line 14
|
||||||
NULL
|
NULL
|
||||||
===EOF===
|
===EOF===
|
||||||
|
@ -40,7 +40,7 @@ try {
|
|||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Deprecated: V8Js::__construct(): Disabling exception reporting is deprecated, $report_uncaught_exceptions != true in %s%eexception_propagation_2.php on line 8
|
Deprecated: V8Js::__construct(): Disabling exception reporting is deprecated, $report_uncaught_exceptions != true in %s%eexception_propagation_2.php on line 8
|
||||||
|
|
||||||
Deprecated: Function V8Js::getPendingException() is deprecated in %s%eexception_propagation_2.php on line 11
|
Deprecated: %s V8Js::getPendingException() is deprecated in %s%eexception_propagation_2.php on line 11
|
||||||
object(V8JsScriptException)#%d (13) {
|
object(V8JsScriptException)#%d (13) {
|
||||||
["message":protected]=>
|
["message":protected]=>
|
||||||
string(49) "throw_0:1: ReferenceError: fooobar is not defined"
|
string(49) "throw_0:1: ReferenceError: fooobar is not defined"
|
||||||
|
@ -14,11 +14,11 @@ $a = new V8Js('myobj', array(), array('a'));
|
|||||||
?>
|
?>
|
||||||
===EOF===
|
===EOF===
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Deprecated: Function V8Js::registerExtension() is deprecated in %s%eextensions_basic.php on line 3
|
Deprecated: %s V8Js::registerExtension() is deprecated in %s%eextensions_basic.php on line 3
|
||||||
|
|
||||||
Deprecated: Function V8Js::registerExtension() is deprecated in %s%eextensions_basic.php on line 4
|
Deprecated: %s V8Js::registerExtension() is deprecated in %s%eextensions_basic.php on line 4
|
||||||
|
|
||||||
Deprecated: Function V8Js::getExtensions() is deprecated in %s%eextensions_basic.php on line 6
|
Deprecated: %s V8Js::getExtensions() is deprecated in %s%eextensions_basic.php on line 6
|
||||||
array(2) {
|
array(2) {
|
||||||
["a"]=>
|
["a"]=>
|
||||||
array(2) {
|
array(2) {
|
||||||
|
@ -13,11 +13,11 @@ var_dump(V8JS::getExtensions());
|
|||||||
$a = new V8Js('myobj', array(), array('a'));
|
$a = new V8Js('myobj', array(), array('a'));
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Deprecated: Function V8Js::registerExtension() is deprecated in %s%eextensions_circular_dependency.php on line 3
|
Deprecated: %s V8Js::registerExtension() is deprecated in %s%eextensions_circular_dependency.php on line 3
|
||||||
|
|
||||||
Deprecated: Function V8Js::registerExtension() is deprecated in %s%eextensions_circular_dependency.php on line 4
|
Deprecated: %s V8Js::registerExtension() is deprecated in %s%eextensions_circular_dependency.php on line 4
|
||||||
|
|
||||||
Deprecated: Function V8Js::getExtensions() is deprecated in %s%eextensions_circular_dependency.php on line 6
|
Deprecated: %s V8Js::getExtensions() is deprecated in %s%eextensions_circular_dependency.php on line 6
|
||||||
array(2) {
|
array(2) {
|
||||||
["a"]=>
|
["a"]=>
|
||||||
array(2) {
|
array(2) {
|
||||||
|
@ -33,7 +33,7 @@ var_dump($v8);
|
|||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
-- registerExtension --
|
-- registerExtension --
|
||||||
|
|
||||||
Deprecated: Function V8Js::registerExtension() is deprecated in %s%eextensions_error.php on line 5
|
Deprecated: %s V8Js::registerExtension() is deprecated in %s%eextensions_error.php on line 5
|
||||||
-- creating V8Js object --
|
-- creating V8Js object --
|
||||||
Error installing extension 'handlebars'.
|
Error installing extension 'handlebars'.
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ $js->executeString($script);
|
|||||||
?>
|
?>
|
||||||
===EOF===
|
===EOF===
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Notice: Undefined variable: bar in %s%efatal_error_ignore_non_fatals.php on line 6
|
%s: Undefined variable%sbar in %s%efatal_error_ignore_non_fatals.php on line 6
|
||||||
|
|
||||||
Warning: Foo Bar! in %s%efatal_error_ignore_non_fatals.php on line 7
|
Warning: Foo Bar! in %s%efatal_error_ignore_non_fatals.php on line 7
|
||||||
blar foo
|
blar foo
|
||||||
|
@ -25,7 +25,7 @@ goodbye cruel world!
|
|||||||
|
|
||||||
Fatal error: Uncaught Error: Call to undefined method Foo::bar() in %s%efatal_error_v8function.php:6
|
Fatal error: Uncaught Error: Call to undefined method Foo::bar() in %s%efatal_error_v8function.php:6
|
||||||
Stack trace:
|
Stack trace:
|
||||||
#0 [internal function]: Foo->callback()
|
#0 %s: Foo->callback()
|
||||||
#1 %s%efatal_error_v8function.php(14): V8Function->V8Js::V8::Invoke()
|
#1 %s%efatal_error_v8function.php(14): V8Function->V8Js::V8::Invoke()
|
||||||
#2 {main}
|
#2 {main}
|
||||||
thrown in %s%efatal_error_v8function.php on line 6
|
thrown in %s%efatal_error_v8function.php on line 6
|
||||||
|
@ -506,11 +506,7 @@ static PHP_METHOD(V8Js, __construct)
|
|||||||
V8JS_GLOBAL(isolate)->DefineOwnProperty(context, object_name_js, php_obj, v8::ReadOnly);
|
V8JS_GLOBAL(isolate)->DefineOwnProperty(context, object_name_js, php_obj, v8::ReadOnly);
|
||||||
|
|
||||||
/* Export public property values */
|
/* Export public property values */
|
||||||
#if (PHP_MAJOR_VERSION < 8)
|
HashTable *properties = zend_std_get_properties(SINCE80(Z_OBJ_P(getThis()), getThis()));
|
||||||
HashTable *properties = zend_std_get_properties(getThis());
|
|
||||||
#else
|
|
||||||
HashTable *properties = zend_std_get_properties(Z_OBJ_P(getThis()));
|
|
||||||
#endif
|
|
||||||
zval *value;
|
zval *value;
|
||||||
zend_string *member;
|
zend_string *member;
|
||||||
|
|
||||||
@ -1339,15 +1335,16 @@ static SINCE74(zval*, void) v8js_write_property(SINCE80(zend_object, zval) *_obj
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Write value to PHP object */
|
/* Write value to PHP object */
|
||||||
SINCE74(return,) std_object_handlers.write_property(object, member, value, NULL);
|
SINCE74(return,) std_object_handlers.write_property(SINCE80(object, _object), SINCE80(member, _member), value, NULL);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
#if PHP_VERSION_ID >= 80000
|
static void v8js_unset_property(SINCE80(zend_object, zval) *_object, SINCE80(zend_string, zval) *_member, void **cache_slot) /* {{{ */
|
||||||
static void v8js_unset_property(zend_object *object, zend_string *member, void **cache_slot) /* {{{ */
|
|
||||||
{
|
{
|
||||||
V8JS_BEGIN_CTX_OBJ(c, object)
|
zend_object *object = SINCE80(_object, Z_OBJ_P(_object));
|
||||||
|
zend_string *member = SINCE80(_member, Z_STR_P(_member));
|
||||||
|
|
||||||
|
V8JS_BEGIN_CTX_OBJ(c, object);
|
||||||
/* Global PHP JS object */
|
/* Global PHP JS object */
|
||||||
v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
|
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();
|
v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(v8_context, object_name_js).ToLocalChecked()->ToObject(v8_context).ToLocalChecked();
|
||||||
@ -1360,29 +1357,11 @@ static void v8js_unset_property(zend_object *object, zend_string *member, void *
|
|||||||
|
|
||||||
/* Delete value from PHP JS object */
|
/* Delete value from PHP JS object */
|
||||||
v8::Local<v8::Value> key = V8JS_SYML(ZSTR_VAL(member), static_cast<int>(ZSTR_LEN(member)));
|
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)
|
|
||||||
|
|
||||||
/* 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 (Z_STRLEN_P(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(Z_STRVAL_P(member), static_cast<int>(Z_STRLEN_P(member)));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
jsobj->Delete(v8_context, key);
|
jsobj->Delete(v8_context, key);
|
||||||
|
|
||||||
/* Unset from PHP object */
|
/* Unset from PHP object */
|
||||||
std_object_handlers.unset_property(object, member, NULL);
|
std_object_handlers.unset_property(SINCE80(object, _object), SINCE80(member, _member), NULL);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -148,11 +148,7 @@ v8::Local<v8::Value> zval_to_v8js(zval *value, v8::Isolate *isolate) /* {{{ */
|
|||||||
ce = php_date_get_date_ce();
|
ce = php_date_get_date_ce();
|
||||||
if (instanceof_function(Z_OBJCE_P(value), ce)) {
|
if (instanceof_function(Z_OBJCE_P(value), ce)) {
|
||||||
zval dtval;
|
zval dtval;
|
||||||
#if PHP_VERSION_ID >= 80000
|
zend_call_method_with_0_params(SINCE80(Z_OBJ_P(value), value), NULL, NULL, "getTimestamp", &dtval);
|
||||||
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);
|
v8::Date::New(isolate->GetEnteredOrMicrotaskContext(), ((double)Z_LVAL(dtval) * 1000.0)).ToLocal(&jsValue);
|
||||||
zval_dtor(&dtval);
|
zval_dtor(&dtval);
|
||||||
} else
|
} else
|
||||||
|
@ -50,13 +50,8 @@ void v8js_create_script_exception(zval *return_value, v8::Isolate *isolate, v8::
|
|||||||
|
|
||||||
object_init_ex(return_value, php_ce_v8js_script_exception);
|
object_init_ex(return_value, php_ce_v8js_script_exception);
|
||||||
|
|
||||||
#if PHP_VERSION_ID >= 80000
|
|
||||||
#define PHPV8_EXPROP(type, name, value) \
|
#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);
|
zend_update_property##type(php_ce_v8js_script_exception, SINCE80(Z_OBJ_P(return_value), 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()) {
|
if (tc_message.IsEmpty()) {
|
||||||
@ -134,7 +129,6 @@ void v8js_throw_script_exception(v8::Isolate *isolate, v8::TryCatch *try_catch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
#if PHP_VERSION_ID >= 80000
|
|
||||||
#define V8JS_EXCEPTION_METHOD(property) \
|
#define V8JS_EXCEPTION_METHOD(property) \
|
||||||
static PHP_METHOD(V8JsScriptException, get##property) \
|
static PHP_METHOD(V8JsScriptException, get##property) \
|
||||||
{ \
|
{ \
|
||||||
@ -143,22 +137,9 @@ void v8js_throw_script_exception(v8::Isolate *isolate, v8::TryCatch *try_catch)
|
|||||||
if (zend_parse_parameters_none() == FAILURE) { \
|
if (zend_parse_parameters_none() == FAILURE) { \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
value = zend_read_property(php_ce_v8js_script_exception, Z_OBJ_P(getThis()), #property, sizeof(#property) - 1, 0, &rv); \
|
value = zend_read_property(php_ce_v8js_script_exception, SINCE80(Z_OBJ_P(getThis()), getThis()), #property, sizeof(#property) - 1, 0, &rv); \
|
||||||
RETURN_ZVAL(value, 1, 0); \
|
RETURN_ZVAL(value, 1, 0); \
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#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, getThis(), #property, sizeof(#property) - 1, 0, &rv); \
|
|
||||||
RETURN_ZVAL(value, 1, 0); \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* {{{ proto string V8JsEScriptxception::getJsFileName()
|
/* {{{ proto string V8JsEScriptxception::getJsFileName()
|
||||||
|
@ -643,11 +643,11 @@ v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::Name> property_n
|
|||||||
zval php_value;
|
zval php_value;
|
||||||
|
|
||||||
zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
|
zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
|
||||||
#if PHP_VERSION_ID >= 80000
|
#if PHP_VERSION_ID < 80000
|
||||||
zend_object &zobject = *object;
|
|
||||||
#else
|
|
||||||
zval zobject;
|
zval zobject;
|
||||||
ZVAL_OBJ(&zobject, object);
|
ZVAL_OBJ(&zobject, object);
|
||||||
|
#else
|
||||||
|
zend_object &zobject = *object;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
v8js_function_tmpl_t *tmpl_ptr = reinterpret_cast<v8js_function_tmpl_t *>(self->GetAlignedPointerFromInternalField(0));
|
v8js_function_tmpl_t *tmpl_ptr = reinterpret_cast<v8js_function_tmpl_t *>(self->GetAlignedPointerFromInternalField(0));
|
||||||
@ -803,11 +803,7 @@ v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::Name> property_n
|
|||||||
const zend_object_handlers *h = object->handlers;
|
const zend_object_handlers *h = object->handlers;
|
||||||
|
|
||||||
if (callback_type == V8JS_PROP_QUERY) {
|
if (callback_type == V8JS_PROP_QUERY) {
|
||||||
#if PHP_VERSION_ID >= 80000
|
if (h->has_property(&zobject, SINCE80(Z_STR_P(&zname), &zname), 0, NULL)) {
|
||||||
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);
|
ret_value = V8JS_UINT(v8::None);
|
||||||
} else {
|
} else {
|
||||||
ret_value = v8::Local<v8::Value>(); // empty handle
|
ret_value = v8::Local<v8::Value>(); // empty handle
|
||||||
@ -818,11 +814,7 @@ v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::Name> property_n
|
|||||||
if(!property_info ||
|
if(!property_info ||
|
||||||
(property_info != ZEND_WRONG_PROPERTY_INFO &&
|
(property_info != ZEND_WRONG_PROPERTY_INFO &&
|
||||||
property_info->flags & ZEND_ACC_PUBLIC)) {
|
property_info->flags & ZEND_ACC_PUBLIC)) {
|
||||||
#if PHP_VERSION_ID >= 80000
|
h->unset_property(&zobject, SINCE80(Z_STR_P(&zname), &zname), NULL);
|
||||||
h->unset_property(&zobject, Z_STR_P(&zname), NULL);
|
|
||||||
#else
|
|
||||||
h->unset_property(&zobject, &zname, NULL);
|
|
||||||
#endif
|
|
||||||
ret_value = V8JS_TRUE();
|
ret_value = V8JS_TRUE();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -45,9 +45,15 @@ static zend_object_handlers v8js_v8generator_handlers;
|
|||||||
#define V8JS_V8_INVOKE_FUNC_NAME "V8Js::V8::Invoke"
|
#define V8JS_V8_INVOKE_FUNC_NAME "V8Js::V8::Invoke"
|
||||||
|
|
||||||
/* V8 Object handlers */
|
/* V8 Object handlers */
|
||||||
#if PHP_VERSION_ID >= 80000
|
static int v8js_v8object_has_property(SINCE80(zend_object, zval) *_object, SINCE80(zend_string, zval) *_member, int has_set_exists, void **cache_slot) /* {{{ */
|
||||||
static int v8js_v8object_has_property(zend_object *object, zend_string *member, int has_set_exists, void **cache_slot) /* {{{ */
|
|
||||||
{
|
{
|
||||||
|
zend_object *object = SINCE80(_object, Z_OBJ_P(_object));
|
||||||
|
zend_string *member = SINCE80(_member, Z_STR_P(_member));
|
||||||
|
/* param has_set_exists:
|
||||||
|
* 0 (has) whether property exists and is not NULL - isset()
|
||||||
|
* 1 (set) whether property exists and is true-ish - empty()
|
||||||
|
* 2 (exists) whether property exists - property_exists()
|
||||||
|
*/
|
||||||
int retval = false;
|
int retval = false;
|
||||||
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ(object);
|
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ(object);
|
||||||
|
|
||||||
@ -75,42 +81,6 @@ static int v8js_v8object_has_property(zend_object *object, zend_string *member,
|
|||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::String> jsKey = V8JS_ZSYM(member);
|
v8::Local<v8::String> jsKey = V8JS_ZSYM(member);
|
||||||
#else
|
|
||||||
static int v8js_v8object_has_property(zval *object, zval *member, int has_set_exists, void **cache_slot) /* {{{ */
|
|
||||||
{
|
|
||||||
/* param has_set_exists:
|
|
||||||
* 0 (has) whether property exists and is not NULL - isset()
|
|
||||||
* 1 (set) whether property exists and is true-ish - empty()
|
|
||||||
* 2 (exists) whether property exists - property_exists()
|
|
||||||
*/
|
|
||||||
int retval = false;
|
|
||||||
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
|
|
||||||
|
|
||||||
if (!obj->ctx)
|
|
||||||
{
|
|
||||||
zend_throw_exception(php_ce_v8js_exception,
|
|
||||||
"Can't access V8Object after V8Js instance is destroyed!", 0);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
V8JS_CTX_PROLOGUE_EX(obj->ctx, false);
|
|
||||||
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
|
||||||
v8::Local<v8::Object> jsObj;
|
|
||||||
|
|
||||||
if (Z_TYPE_P(member) != IS_STRING || !v8obj->IsObject() || !v8obj->ToObject(v8_context).ToLocal(&jsObj))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Z_STRLEN_P(member) > std::numeric_limits<int>::max())
|
|
||||||
{
|
|
||||||
zend_throw_exception(php_ce_v8js_exception,
|
|
||||||
"Member name length exceeds maximum supported length", 0);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
v8::Local<v8::String> jsKey = V8JS_ZSYM(Z_STR_P(member));
|
|
||||||
#endif
|
|
||||||
/* Skip any prototype properties */
|
/* Skip any prototype properties */
|
||||||
if (!jsObj->HasRealNamedProperty(v8_context, jsKey).FromMaybe(false) && !jsObj->HasRealNamedCallbackProperty(v8_context, jsKey).FromMaybe(false))
|
if (!jsObj->HasRealNamedProperty(v8_context, jsKey).FromMaybe(false) && !jsObj->HasRealNamedCallbackProperty(v8_context, jsKey).FromMaybe(false))
|
||||||
{
|
{
|
||||||
@ -158,9 +128,11 @@ static int v8js_v8object_has_property(zval *object, zval *member, int has_set_ex
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
#if PHP_VERSION_ID >= 80000
|
static zval *v8js_v8object_read_property(SINCE80(zend_object, zval) *_object, SINCE80(zend_string, zval) *_member, int type, void **cache_slot, zval *rv) /* {{{ */
|
||||||
static zval *v8js_v8object_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv) /* {{{ */
|
|
||||||
{
|
{
|
||||||
|
zend_object *object = SINCE80(_object, Z_OBJ_P(_object));
|
||||||
|
zend_string *member = SINCE80(_member, Z_STR_P(_member));
|
||||||
|
|
||||||
zval *retval = rv;
|
zval *retval = rv;
|
||||||
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ(object);
|
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ(object);
|
||||||
|
|
||||||
@ -185,34 +157,7 @@ static zval *v8js_v8object_read_property(zend_object *object, zend_string *membe
|
|||||||
|
|
||||||
v8::Local<v8::String> jsKey = V8JS_ZSYM(member);
|
v8::Local<v8::String> jsKey = V8JS_ZSYM(member);
|
||||||
v8::Local<v8::Object> jsObj = v8obj->ToObject(v8_context).ToLocalChecked();
|
v8::Local<v8::Object> jsObj = v8obj->ToObject(v8_context).ToLocalChecked();
|
||||||
#else
|
|
||||||
static zval *v8js_v8object_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv) /* {{{ */
|
|
||||||
{
|
|
||||||
zval *retval = rv;
|
|
||||||
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
|
|
||||||
|
|
||||||
if (!obj->ctx)
|
|
||||||
{
|
|
||||||
zend_throw_exception(php_ce_v8js_exception,
|
|
||||||
"Can't access V8Object after V8Js instance is destroyed!", 0);
|
|
||||||
return SINCE74(object, retval);
|
|
||||||
}
|
|
||||||
|
|
||||||
V8JS_CTX_PROLOGUE_EX(obj->ctx, retval);
|
|
||||||
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
|
||||||
|
|
||||||
if (Z_TYPE_P(member) == IS_STRING && v8obj->IsObject())
|
|
||||||
{
|
|
||||||
if (Z_STRLEN_P(member) > std::numeric_limits<int>::max())
|
|
||||||
{
|
|
||||||
zend_throw_exception(php_ce_v8js_exception,
|
|
||||||
"Member name length exceeds maximum supported length", 0);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
v8::Local<v8::String> jsKey = V8JS_ZSYM(Z_STR_P(member));
|
|
||||||
v8::Local<v8::Object> jsObj = v8obj->ToObject(v8_context).ToLocalChecked();
|
|
||||||
#endif
|
|
||||||
/* Skip any prototype properties */
|
/* Skip any prototype properties */
|
||||||
if (jsObj->HasRealNamedProperty(v8_context, jsKey).FromMaybe(false) || jsObj->HasRealNamedCallbackProperty(v8_context, jsKey).FromMaybe(false))
|
if (jsObj->HasRealNamedProperty(v8_context, jsKey).FromMaybe(false) || jsObj->HasRealNamedCallbackProperty(v8_context, jsKey).FromMaybe(false))
|
||||||
{
|
{
|
||||||
@ -229,19 +174,17 @@ static zval *v8js_v8object_read_property(zval *object, zval *member, int type, v
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
#if PHP_VERSION_ID >= 80000
|
static zval *v8js_v8object_get_property_ptr_ptr(SINCE80(zend_object, zval) *object, SINCE80(zend_string, zval) *member, int type, void **cache_slot) /* {{{ */
|
||||||
static zval *v8js_v8object_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot) /* {{{ */
|
|
||||||
#else
|
|
||||||
static zval *v8js_v8object_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot) /* {{{ */
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
#if PHP_VERSION_ID >= 80000
|
static SINCE74(zval *, void) v8js_v8object_write_property(SINCE80(zend_object, zval) *_object, SINCE80(zend_string, zval) *_member, zval *value, void **cache_slot) /* {{{ */
|
||||||
static SINCE74(zval *, void) v8js_v8object_write_property(zend_object *object, zend_string *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_v8object *obj = Z_V8JS_V8OBJECT_OBJ(object);
|
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ(object);
|
||||||
|
|
||||||
if (!obj->ctx)
|
if (!obj->ctx)
|
||||||
@ -266,41 +209,16 @@ static SINCE74(zval *, void) v8js_v8object_write_property(zend_object *object, z
|
|||||||
{
|
{
|
||||||
v8obj->CreateDataProperty(v8_context, V8JS_ZSYM(member), zval_to_v8js(value, isolate));
|
v8obj->CreateDataProperty(v8_context, V8JS_ZSYM(member), zval_to_v8js(value, isolate));
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
static SINCE74(zval *, void) v8js_v8object_write_property(zval *object, zval *member, zval *value, void **cache_slot) /* {{{ */
|
|
||||||
{
|
|
||||||
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
|
|
||||||
|
|
||||||
if (!obj->ctx)
|
|
||||||
{
|
|
||||||
zend_throw_exception(php_ce_v8js_exception,
|
|
||||||
"Can't access V8Object after V8Js instance is destroyed!", 0);
|
|
||||||
return SINCE74(value, );
|
|
||||||
}
|
|
||||||
|
|
||||||
V8JS_CTX_PROLOGUE_EX(obj->ctx, SINCE74(value, ));
|
|
||||||
v8::Local<v8::Value> v8objHandle = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
|
||||||
|
|
||||||
if (Z_STRLEN_P(member) > std::numeric_limits<int>::max())
|
|
||||||
{
|
|
||||||
zend_throw_exception(php_ce_v8js_exception,
|
|
||||||
"Member name length exceeds maximum supported length", 0);
|
|
||||||
return SINCE74(value, );
|
|
||||||
}
|
|
||||||
|
|
||||||
v8::Local<v8::Object> v8obj;
|
|
||||||
if (v8objHandle->IsObject() && v8objHandle->ToObject(v8_context).ToLocal(&v8obj))
|
|
||||||
{
|
|
||||||
v8obj->CreateDataProperty(v8_context, V8JS_ZSYM(Z_STR_P(member)), zval_to_v8js(value, isolate));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return SINCE74(value, );
|
return SINCE74(value, );
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
#if PHP_VERSION_ID >= 80000
|
static void v8js_v8object_unset_property(SINCE80(zend_object, zval) *_object, SINCE80(zend_string, zval) *_member, void **cache_slot) /* {{{ */
|
||||||
static void v8js_v8object_unset_property(zend_object *object, zend_string *member, void **cache_slot) /* {{{ */
|
|
||||||
{
|
{
|
||||||
|
zend_object *object = SINCE80(_object, Z_OBJ_P(_object));
|
||||||
|
zend_string *member = SINCE80(_member, Z_STR_P(_member));
|
||||||
|
|
||||||
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ(object);
|
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ(object);
|
||||||
|
|
||||||
if (!obj->ctx)
|
if (!obj->ctx)
|
||||||
@ -326,46 +244,12 @@ static void v8js_v8object_unset_property(zend_object *object, zend_string *membe
|
|||||||
v8obj->Delete(v8_context, V8JS_ZSYM(member));
|
v8obj->Delete(v8_context, V8JS_ZSYM(member));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
static void v8js_v8object_unset_property(zval *object, zval *member, void **cache_slot) /* {{{ */
|
|
||||||
{
|
|
||||||
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
|
|
||||||
|
|
||||||
if (!obj->ctx)
|
|
||||||
{
|
|
||||||
zend_throw_exception(php_ce_v8js_exception,
|
|
||||||
"Can't access V8Object after V8Js instance is destroyed!", 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
V8JS_CTX_PROLOGUE(obj->ctx);
|
|
||||||
v8::Local<v8::Value> v8objHandle = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
|
||||||
|
|
||||||
if (Z_STRLEN_P(member) > std::numeric_limits<int>::max())
|
|
||||||
{
|
|
||||||
zend_throw_exception(php_ce_v8js_exception,
|
|
||||||
"Member name length exceeds maximum supported length", 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
v8::Local<v8::Object> v8obj;
|
|
||||||
if (v8objHandle->IsObject() && v8objHandle->ToObject(v8_context).ToLocal(&v8obj))
|
|
||||||
{
|
|
||||||
v8obj->Delete(v8_context, V8JS_ZSYM(Z_STR_P(member)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
#if PHP_VERSION_ID >= 80000
|
static HashTable *v8js_v8object_get_properties(SINCE80(zend_object, zval) *object) /* {{{ */
|
||||||
static HashTable *v8js_v8object_get_properties(zend_object *object) /* {{{ */
|
|
||||||
{
|
{
|
||||||
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ(object);
|
v8js_v8object *obj = SINCE80(Z_V8JS_V8OBJECT_OBJ, Z_V8JS_V8OBJECT_OBJ_P)(object);
|
||||||
#else
|
|
||||||
static HashTable *v8js_v8object_get_properties(zval *object) /* {{{ */
|
|
||||||
{
|
|
||||||
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
|
|
||||||
#endif
|
|
||||||
if (obj->properties == NULL)
|
if (obj->properties == NULL)
|
||||||
{
|
{
|
||||||
#if PHP_VERSION_ID < 70300
|
#if PHP_VERSION_ID < 70300
|
||||||
@ -411,11 +295,7 @@ static HashTable *v8js_v8object_get_properties(zval *object) /* {{{ */
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
#if PHP_VERSION_ID >= 80000
|
static HashTable *v8js_v8object_get_debug_info(SINCE80(zend_object, zval) *object, int *is_temp) /* {{{ */
|
||||||
static HashTable *v8js_v8object_get_debug_info(zend_object *object, int *is_temp) /* {{{ */
|
|
||||||
#else
|
|
||||||
static HashTable *v8js_v8object_get_debug_info(zval *object, int *is_temp) /* {{{ */
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
*is_temp = 0;
|
*is_temp = 0;
|
||||||
return v8js_v8object_get_properties(object);
|
return v8js_v8object_get_properties(object);
|
||||||
@ -544,11 +424,7 @@ static ZEND_FUNCTION(zend_v8object_func)
|
|||||||
static zend_function *v8js_v8object_get_method(zend_object **object_ptr, zend_string *method, const zval *key) /* {{{ */
|
static zend_function *v8js_v8object_get_method(zend_object **object_ptr, zend_string *method, const zval *key) /* {{{ */
|
||||||
{
|
{
|
||||||
v8js_v8object *obj = v8js_v8object_fetch_object(*object_ptr);
|
v8js_v8object *obj = v8js_v8object_fetch_object(*object_ptr);
|
||||||
#if PHP_VERSION_ID < 80000
|
SINCE80(zend_internal_function, zend_function) *f;
|
||||||
zend_function *f;
|
|
||||||
#else
|
|
||||||
zend_internal_function *f;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!obj->ctx)
|
if (!obj->ctx)
|
||||||
{
|
{
|
||||||
@ -708,15 +584,13 @@ static int v8js_v8object_call_method(zend_string *method, zend_object *object, I
|
|||||||
|
|
||||||
#if PHP_VERSION_ID >= 80000
|
#if PHP_VERSION_ID >= 80000
|
||||||
static int v8js_v8object_get_closure(zend_object *object, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **zobj_ptr, bool call) /* {{{ */
|
static int v8js_v8object_get_closure(zend_object *object, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **zobj_ptr, bool call) /* {{{ */
|
||||||
{
|
|
||||||
zend_internal_function *invoke;
|
|
||||||
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ(object);
|
|
||||||
#else
|
#else
|
||||||
static int v8js_v8object_get_closure(zval *object, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **zobj_ptr) /* {{{ */
|
static int v8js_v8object_get_closure(zval *object, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **zobj_ptr) /* {{{ */
|
||||||
{
|
|
||||||
zend_function *invoke;
|
|
||||||
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
|
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
SINCE80(zend_internal_function, zend_function) *invoke;
|
||||||
|
v8js_v8object *obj = SINCE80(Z_V8JS_V8OBJECT_OBJ, Z_V8JS_V8OBJECT_OBJ_P)(object);
|
||||||
|
|
||||||
if (!obj->ctx)
|
if (!obj->ctx)
|
||||||
{
|
{
|
||||||
zend_throw_exception(php_ce_v8js_exception,
|
zend_throw_exception(php_ce_v8js_exception,
|
||||||
@ -747,11 +621,7 @@ static int v8js_v8object_get_closure(zval *object, zend_class_entry **ce_ptr, ze
|
|||||||
|
|
||||||
if (zobj_ptr)
|
if (zobj_ptr)
|
||||||
{
|
{
|
||||||
#if PHP_VERSION_ID >= 80000
|
*zobj_ptr = SINCE80(object, Z_OBJ_P(object));
|
||||||
*zobj_ptr = object;
|
|
||||||
#else
|
|
||||||
*zobj_ptr = Z_OBJ_P(object);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*ce_ptr = NULL;
|
*ce_ptr = NULL;
|
||||||
@ -1176,9 +1046,7 @@ PHP_MINIT_FUNCTION(v8js_v8object_class) /* {{{ */
|
|||||||
v8js_v8object_handlers.unset_property = v8js_v8object_unset_property;
|
v8js_v8object_handlers.unset_property = v8js_v8object_unset_property;
|
||||||
v8js_v8object_handlers.get_properties = v8js_v8object_get_properties;
|
v8js_v8object_handlers.get_properties = v8js_v8object_get_properties;
|
||||||
v8js_v8object_handlers.get_method = v8js_v8object_get_method;
|
v8js_v8object_handlers.get_method = v8js_v8object_get_method;
|
||||||
#if PHP_VERSION_ID < 80000
|
SINCE80(, v8js_v8object_handlers.call_method = v8js_v8object_call_method);
|
||||||
v8js_v8object_handlers.call_method = v8js_v8object_call_method;
|
|
||||||
#endif
|
|
||||||
v8js_v8object_handlers.get_debug_info = v8js_v8object_get_debug_info;
|
v8js_v8object_handlers.get_debug_info = v8js_v8object_get_debug_info;
|
||||||
v8js_v8object_handlers.get_closure = v8js_v8object_get_closure;
|
v8js_v8object_handlers.get_closure = v8js_v8object_get_closure;
|
||||||
v8js_v8object_handlers.offset = XtOffsetOf(struct v8js_v8object, std);
|
v8js_v8object_handlers.offset = XtOffsetOf(struct v8js_v8object, std);
|
||||||
|
Loading…
Reference in New Issue
Block a user