mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 03:01:51 +00:00
adapt V8 12.8 interceptor signatures
This commit is contained in:
parent
888684b483
commit
d0c4a3614d
@ -56,7 +56,7 @@ static zval v8js_array_access_dispatch(zend_object *object, const char *method_n
|
||||
|
||||
|
||||
|
||||
void v8js_array_access_getter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
|
||||
v8::Intercepted v8js_array_access_getter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
|
||||
{
|
||||
v8::Isolate *isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> self = info.Holder();
|
||||
@ -70,12 +70,17 @@ void v8js_array_access_getter(uint32_t index, const v8::PropertyCallbackInfo<v8:
|
||||
v8::Local<v8::Value> ret_value = zval_to_v8js(&php_value, isolate);
|
||||
zval_ptr_dtor(&php_value);
|
||||
|
||||
info.GetReturnValue().Set(ret_value);
|
||||
if (ret_value.IsEmpty()) {
|
||||
return v8::Intercepted::kNo;
|
||||
} else {
|
||||
info.GetReturnValue().Set(ret_value);
|
||||
return v8::Intercepted::kYes;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
void v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> value,
|
||||
const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
|
||||
v8::Intercepted v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> value,
|
||||
const v8::PropertyCallbackInfo<void>& info) /* {{{ */
|
||||
{
|
||||
v8::Isolate *isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> self = info.Holder();
|
||||
@ -86,20 +91,16 @@ void v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> value,
|
||||
ZVAL_UNDEF(&zvalue);
|
||||
|
||||
if (v8js_to_zval(value, &zvalue, 0, isolate) != SUCCESS) {
|
||||
info.GetReturnValue().Set(v8::Local<v8::Value>());
|
||||
return;
|
||||
return v8::Intercepted::kNo;
|
||||
}
|
||||
|
||||
zval php_value = v8js_array_access_dispatch(object, "offsetSet", 2, index, zvalue);
|
||||
zval_ptr_dtor(&php_value);
|
||||
|
||||
/* simply pass back the value to tell we intercepted the call
|
||||
* as the offsetSet function returns void. */
|
||||
info.GetReturnValue().Set(value);
|
||||
|
||||
/* if PHP wanted to hold on to this value, zend_call_function would
|
||||
* have bumped the refcount. */
|
||||
zval_ptr_dtor(&zvalue);
|
||||
return v8::Intercepted::kYes;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -159,7 +160,7 @@ static void v8js_array_access_length(v8::Local<v8::String> property, const v8::P
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
void v8js_array_access_deleter(uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& info) /* {{{ */
|
||||
v8::Intercepted v8js_array_access_deleter(uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& info) /* {{{ */
|
||||
{
|
||||
v8::Isolate *isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> self = info.Holder();
|
||||
@ -173,10 +174,11 @@ void v8js_array_access_deleter(uint32_t index, const v8::PropertyCallbackInfo<v8
|
||||
zval_ptr_dtor(&php_value);
|
||||
|
||||
info.GetReturnValue().Set(V8JS_BOOL(true));
|
||||
return v8::Intercepted::kYes;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
void v8js_array_access_query(uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) /* {{{ */
|
||||
v8::Intercepted v8js_array_access_query(uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) /* {{{ */
|
||||
{
|
||||
v8::Isolate *isolate = info.GetIsolate();
|
||||
v8::Local<v8::Object> self = info.Holder();
|
||||
@ -187,7 +189,10 @@ void v8js_array_access_query(uint32_t index, const v8::PropertyCallbackInfo<v8::
|
||||
* otherwise we're expected to return an empty handle. */
|
||||
if(v8js_array_access_isset_p(object, index)) {
|
||||
info.GetReturnValue().Set(V8JS_UINT(v8::PropertyAttribute::None));
|
||||
return v8::Intercepted::kYes;
|
||||
}
|
||||
|
||||
return v8::Intercepted::kNo;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -217,7 +222,7 @@ void v8js_array_access_enumerator(const v8::PropertyCallbackInfo<v8::Array>& inf
|
||||
|
||||
|
||||
|
||||
void v8js_array_access_named_getter(v8::Local<v8::Name> property_name, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */
|
||||
v8::Intercepted v8js_array_access_named_getter(v8::Local<v8::Name> property_name, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */
|
||||
{
|
||||
v8::Local<v8::String> property = v8::Local<v8::String>::Cast(property_name);
|
||||
v8::Isolate *isolate = info.GetIsolate();
|
||||
@ -226,10 +231,10 @@ void v8js_array_access_named_getter(v8::Local<v8::Name> property_name, const v8:
|
||||
|
||||
if(strcmp(name, "length") == 0) {
|
||||
v8js_array_access_length(property, info);
|
||||
return;
|
||||
return v8::Intercepted::kYes;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> ret_value = v8js_named_property_callback(property, info, V8JS_PROP_GETTER);
|
||||
v8::Local<v8::Value> ret_value = v8js_named_property_callback(info.GetIsolate(), info.Holder(), property, V8JS_PROP_GETTER);
|
||||
|
||||
if(ret_value.IsEmpty()) {
|
||||
v8::Local<v8::Array> arr = v8::Array::New(isolate);
|
||||
@ -250,6 +255,7 @@ void v8js_array_access_named_getter(v8::Local<v8::Name> property_name, const v8:
|
||||
}
|
||||
|
||||
info.GetReturnValue().Set(ret_value);
|
||||
return v8::Intercepted::kYes;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
@ -14,18 +14,18 @@
|
||||
#define V8JS_ARRAY_ACCESS_H
|
||||
|
||||
/* Indexed Property Handlers */
|
||||
void v8js_array_access_getter(uint32_t index,
|
||||
const v8::PropertyCallbackInfo<v8::Value>& info);
|
||||
void v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> value,
|
||||
v8::Intercepted v8js_array_access_getter(uint32_t index,
|
||||
const v8::PropertyCallbackInfo<v8::Value>& info);
|
||||
v8::Intercepted v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> value,
|
||||
const v8::PropertyCallbackInfo<void>& info);
|
||||
void v8js_array_access_enumerator(const v8::PropertyCallbackInfo<v8::Array>& info);
|
||||
void v8js_array_access_deleter(uint32_t index,
|
||||
v8::Intercepted v8js_array_access_deleter(uint32_t index,
|
||||
const v8::PropertyCallbackInfo<v8::Boolean>& info);
|
||||
void v8js_array_access_query(uint32_t index,
|
||||
v8::Intercepted v8js_array_access_query(uint32_t index,
|
||||
const v8::PropertyCallbackInfo<v8::Integer>& info);
|
||||
|
||||
/* Named Property Handlers */
|
||||
void v8js_array_access_named_getter(v8::Local<v8::Name> property,
|
||||
v8::Intercepted v8js_array_access_named_getter(v8::Local<v8::Name> property,
|
||||
const v8::PropertyCallbackInfo<v8::Value> &info);
|
||||
|
||||
#endif /* V8JS_ARRAY_ACCESS_H */
|
||||
|
@ -524,7 +524,7 @@ static void v8js_compile_script(zval *this_ptr, const zend_string *str, const ze
|
||||
v8::Local<v8::String> sname = identifier
|
||||
? V8JS_ZSTR(identifier)
|
||||
: V8JS_SYM("V8Js::compileString()");
|
||||
v8::ScriptOrigin origin(isolate, sname);
|
||||
v8::ScriptOrigin origin(sname);
|
||||
|
||||
if (ZSTR_LEN(str) > std::numeric_limits<int>::max()) {
|
||||
zend_throw_exception(php_ce_v8js_exception,
|
||||
|
@ -502,7 +502,7 @@ V8JS_METHOD(require)
|
||||
|
||||
// Set script identifier
|
||||
v8::Local<v8::String> sname = V8JS_STR(normalised_module_id);
|
||||
v8::ScriptOrigin origin(isolate, sname);
|
||||
v8::ScriptOrigin origin(sname);
|
||||
|
||||
if (Z_STRLEN(module_code) > std::numeric_limits<int>::max()) {
|
||||
zend_throw_exception(php_ce_v8js_exception,
|
||||
|
@ -648,12 +648,10 @@ static void v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& info)
|
||||
/* }}} */
|
||||
|
||||
/* This method handles named property and method get/set/query/delete. */
|
||||
template<typename T>
|
||||
v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::Name> property_name, const v8::PropertyCallbackInfo<T> &info, property_op_t callback_type, v8::Local<v8::Value> set_value) /* {{{ */
|
||||
v8::Local<v8::Value> v8js_named_property_callback(v8::Isolate *isolate, v8::Local<v8::Object> self, v8::Local<v8::Name> property_name, property_op_t callback_type, v8::Local<v8::Value> set_value) /* {{{ */
|
||||
{
|
||||
v8::Local<v8::String> property = v8::Local<v8::String>::Cast(property_name);
|
||||
|
||||
v8::Isolate *isolate = info.GetIsolate();
|
||||
v8::Local<v8::Context> v8_context = isolate->GetEnteredOrMicrotaskContext();
|
||||
v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
|
||||
v8::String::Utf8Value cstr(isolate, property);
|
||||
@ -662,7 +660,6 @@ v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::Name> property_n
|
||||
char *lower = estrndup(name, name_len);
|
||||
zend_string *method_name;
|
||||
|
||||
v8::Local<v8::Object> self = info.Holder();
|
||||
v8::Local<v8::Value> ret_value;
|
||||
v8::Local<v8::Function> cb;
|
||||
|
||||
@ -860,44 +857,58 @@ v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::Name> property_n
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void v8js_named_property_getter(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */
|
||||
static v8::Intercepted v8js_named_property_getter(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */
|
||||
{
|
||||
info.GetReturnValue().Set(v8js_named_property_callback(property, info, V8JS_PROP_GETTER));
|
||||
}
|
||||
/* }}} */
|
||||
v8::Local<v8::Value> r = v8js_named_property_callback(info.GetIsolate(), info.Holder(), property, V8JS_PROP_GETTER);
|
||||
|
||||
static void v8js_named_property_setter(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */
|
||||
{
|
||||
info.GetReturnValue().Set(v8js_named_property_callback(property, info, V8JS_PROP_SETTER, value));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void v8js_named_property_query(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Integer> &info) /* {{{ */
|
||||
{
|
||||
v8::Local<v8::Value> r = v8js_named_property_callback(property, info, V8JS_PROP_QUERY);
|
||||
if (r.IsEmpty()) {
|
||||
return;
|
||||
return v8::Intercepted::kNo;
|
||||
} else {
|
||||
info.GetReturnValue().Set(r);
|
||||
return v8::Intercepted::kYes;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static v8::Intercepted v8js_named_property_setter(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void> &info) /* {{{ */
|
||||
{
|
||||
v8::Local<v8::Value> r = v8js_named_property_callback(info.GetIsolate(), info.Holder(), property, V8JS_PROP_SETTER, value);
|
||||
return r.IsEmpty() ? v8::Intercepted::kNo : v8::Intercepted::kYes;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static v8::Intercepted v8js_named_property_query(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Integer> &info) /* {{{ */
|
||||
{
|
||||
v8::Local<v8::Value> r = v8js_named_property_callback(info.GetIsolate(), info.Holder(), property, V8JS_PROP_QUERY);
|
||||
if (r.IsEmpty()) {
|
||||
return v8::Intercepted::kNo;
|
||||
}
|
||||
|
||||
v8::Isolate *isolate = info.GetIsolate();
|
||||
v8::MaybeLocal<v8::Integer> value = r->ToInteger(isolate->GetEnteredOrMicrotaskContext());
|
||||
if (!value.IsEmpty()) {
|
||||
if (value.IsEmpty()) {
|
||||
return v8::Intercepted::kNo;
|
||||
} else {
|
||||
info.GetReturnValue().Set(value.ToLocalChecked());
|
||||
return v8::Intercepted::kYes;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void v8js_named_property_deleter(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Boolean> &info) /* {{{ */
|
||||
static v8::Intercepted v8js_named_property_deleter(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Boolean> &info) /* {{{ */
|
||||
{
|
||||
v8::Local<v8::Value> r = v8js_named_property_callback(property, info, V8JS_PROP_DELETER);
|
||||
v8::Local<v8::Value> r = v8js_named_property_callback(info.GetIsolate(), info.Holder(), property, V8JS_PROP_DELETER);
|
||||
if (r.IsEmpty()) {
|
||||
return;
|
||||
return v8::Intercepted::kNo;
|
||||
}
|
||||
|
||||
v8::Isolate *isolate = info.GetIsolate();
|
||||
v8::Local<v8::Boolean> value = r->ToBoolean(isolate);
|
||||
if (!value.IsEmpty()) {
|
||||
if (value.IsEmpty()) {
|
||||
return v8::Intercepted::kNo;
|
||||
} else {
|
||||
info.GetReturnValue().Set(value);
|
||||
return v8::Intercepted::kYes;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
@ -940,7 +951,7 @@ static v8::MaybeLocal<v8::Object> v8js_wrap_object(v8::Isolate *isolate, zend_cl
|
||||
/* We'll free persist_tpl_ when template_cache is destroyed */
|
||||
|
||||
v8::Local<v8::ObjectTemplate> inst_tpl = new_tpl->InstanceTemplate();
|
||||
v8::GenericNamedPropertyGetterCallback getter = v8js_named_property_getter;
|
||||
v8::NamedPropertyGetterCallback getter = v8js_named_property_getter;
|
||||
v8::GenericNamedPropertyEnumeratorCallback enumerator = v8js_named_property_enumerator;
|
||||
|
||||
/* Check for ArrayAccess object */
|
||||
@ -958,11 +969,12 @@ static v8::MaybeLocal<v8::Object> v8js_wrap_object(v8::Isolate *isolate, zend_cl
|
||||
}
|
||||
|
||||
if(has_array_access && has_countable) {
|
||||
inst_tpl->SetIndexedPropertyHandler(v8js_array_access_getter,
|
||||
v8js_array_access_setter,
|
||||
v8js_array_access_query,
|
||||
v8js_array_access_deleter,
|
||||
v8js_array_access_enumerator);
|
||||
inst_tpl->SetHandler(
|
||||
v8::IndexedPropertyHandlerConfiguration(v8js_array_access_getter,
|
||||
v8js_array_access_setter,
|
||||
v8js_array_access_query,
|
||||
v8js_array_access_deleter,
|
||||
v8js_array_access_enumerator));
|
||||
|
||||
/* Switch to special ArrayAccess getter, which falls back to
|
||||
* v8js_named_property_getter, but possibly bridges the
|
||||
|
@ -25,11 +25,9 @@ typedef enum {
|
||||
V8JS_PROP_DELETER
|
||||
} property_op_t;
|
||||
|
||||
template<typename T>
|
||||
v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::Name> property,
|
||||
const v8::PropertyCallbackInfo<T> &info,
|
||||
property_op_t callback_type,
|
||||
v8::Local<v8::Value> set_value = v8::Local<v8::Value>());
|
||||
v8::Local<v8::Value> v8js_named_property_callback(v8::Isolate *isolate, v8::Local<v8::Object> self,
|
||||
v8::Local<v8::Name> property, property_op_t callback_type,
|
||||
v8::Local<v8::Value> set_value = v8::Local<v8::Value>());
|
||||
|
||||
void v8js_php_callback(const v8::FunctionCallbackInfo<v8::Value>& info);
|
||||
|
||||
|
@ -25,7 +25,7 @@ extern "C" {
|
||||
#include "zend_exceptions.h"
|
||||
}
|
||||
|
||||
static void v8js_fetch_php_variable(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
|
||||
static void v8js_fetch_php_variable(v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
|
||||
{
|
||||
v8::Local<v8::External> data = v8::Local<v8::External>::Cast(info.Data());
|
||||
v8js_accessor_ctx *ctx = static_cast<v8js_accessor_ctx *>(data->Value());
|
||||
@ -80,7 +80,7 @@ void v8js_register_accessors(std::vector<v8js_accessor_ctx*> *accessor_list, v8:
|
||||
ctx->isolate = isolate;
|
||||
|
||||
/* Set the variable fetch callback for given symbol on named property */
|
||||
php_obj->SetAccessor(V8JS_STRL(ZSTR_VAL(property_name), static_cast<int>(ZSTR_LEN(property_name))), v8js_fetch_php_variable, NULL, v8::External::New(isolate, ctx));
|
||||
php_obj->SetNativeDataProperty(V8JS_STRL(ZSTR_VAL(property_name), static_cast<int>(ZSTR_LEN(property_name))), v8js_fetch_php_variable, NULL, v8::External::New(isolate, ctx), v8::PropertyAttribute::ReadOnly);
|
||||
|
||||
/* record the context so we can free it later */
|
||||
accessor_list->push_back(ctx);
|
||||
|
Loading…
Reference in New Issue
Block a user