Skip to content

Commit 9ca35ea

Browse files
committed
Add support for v8 v13
See v8/v8@8c53487
1 parent 7c3cd4a commit 9ca35ea

File tree

3 files changed

+103
-17
lines changed

3 files changed

+103
-17
lines changed

.github/workflows/build-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- 10.9.194
2727
# - 11.9.172
2828
- 12.9.203
29-
# - 13.1.104
29+
- 13.5.212
3030

3131
runs-on: ${{ matrix.operating-system }}
3232

@@ -122,7 +122,7 @@ jobs:
122122
- 10.9.194
123123
# - 11.9.172
124124
- 12.9.203
125-
# - 13.1.104
125+
- 13.5.212
126126
php-versions:
127127
# - '8.1'
128128
- '8.2'

v8js_array_access.cc

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ static zval v8js_array_access_dispatch(zend_object *object, const char *method_n
5959
V8JS_INTERCEPTED v8js_array_access_getter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
6060
{
6161
v8::Isolate *isolate = info.GetIsolate();
62-
v8::Local<v8::Object> self = info.Holder();
62+
v8::Local<v8::Object> self;
63+
#if PHP_V8_API_VERSION >= 13000000
64+
self = info.This();
65+
#else
66+
self = info.Holder();
67+
#endif
6368

6469
zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
6570

@@ -83,7 +88,12 @@ V8JS_INTERCEPTED v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> v
8388
const V8JS_SETTER_PROPERTY_CALLBACK_INFO &info) /* {{{ */
8489
{
8590
v8::Isolate *isolate = info.GetIsolate();
86-
v8::Local<v8::Object> self = info.Holder();
91+
v8::Local<v8::Object> self;
92+
#if PHP_V8_API_VERSION >= 13000000
93+
self = info.This();
94+
#else
95+
self = info.Holder();
96+
#endif
8797

8898
zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
8999

@@ -157,7 +167,12 @@ static bool v8js_array_access_isset_p(zend_object *object, int index) /* {{{ */
157167
static void v8js_array_access_length(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& info) /* {{{ */
158168
{
159169
v8::Isolate *isolate = info.GetIsolate();
160-
v8::Local<v8::Object> self = info.Holder();
170+
v8::Local<v8::Object> self;
171+
#if PHP_V8_API_VERSION >= 13000000
172+
self = info.This();
173+
#else
174+
self = info.Holder();
175+
#endif
161176

162177
zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
163178

@@ -169,7 +184,12 @@ static void v8js_array_access_length(v8::Local<v8::String> property, const v8::P
169184
V8JS_INTERCEPTED v8js_array_access_deleter(uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& info) /* {{{ */
170185
{
171186
v8::Isolate *isolate = info.GetIsolate();
172-
v8::Local<v8::Object> self = info.Holder();
187+
v8::Local<v8::Object> self;
188+
#if PHP_V8_API_VERSION >= 13000000
189+
self = info.This();
190+
#else
191+
self = info.Holder();
192+
#endif
173193

174194
zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
175195

@@ -187,7 +207,12 @@ V8JS_INTERCEPTED v8js_array_access_deleter(uint32_t index, const v8::PropertyCal
187207
V8JS_INTERCEPTED v8js_array_access_query(uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& info) /* {{{ */
188208
{
189209
v8::Isolate *isolate = info.GetIsolate();
190-
v8::Local<v8::Object> self = info.Holder();
210+
v8::Local<v8::Object> self;
211+
#if PHP_V8_API_VERSION >= 13000000
212+
self = info.This();
213+
#else
214+
self = info.Holder();
215+
#endif
191216

192217
zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
193218

@@ -206,7 +231,13 @@ V8JS_INTERCEPTED v8js_array_access_query(uint32_t index, const v8::PropertyCallb
206231
void v8js_array_access_enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) /* {{{ */
207232
{
208233
v8::Isolate *isolate = info.GetIsolate();
209-
v8::Local<v8::Object> self = info.Holder();
234+
v8::Local<v8::Object> self;
235+
236+
#if PHP_V8_API_VERSION >= 13000000
237+
self = info.This();
238+
#else
239+
self = info.Holder();
240+
#endif
210241

211242
zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
212243

@@ -240,7 +271,14 @@ V8JS_INTERCEPTED v8js_array_access_named_getter(v8::Local<v8::Name> property_nam
240271
return V8JS_INTERCEPTED_YES;
241272
}
242273

243-
v8::Local<v8::Value> ret_value = v8js_named_property_callback(info.GetIsolate(), info.Holder(), property, V8JS_PROP_GETTER);
274+
v8::Local<v8::Object> holder;
275+
#if PHP_V8_API_VERSION >= 13000000
276+
holder = info.This();
277+
#else
278+
holder = info.Holder();
279+
#endif
280+
281+
v8::Local<v8::Value> ret_value = v8js_named_property_callback(info.GetIsolate(), holder, property, V8JS_PROP_GETTER);
244282

245283
if(ret_value.IsEmpty()) {
246284
v8::Local<v8::Array> arr = v8::Array::New(isolate);

v8js_object_export.cc

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ static void v8js_call_php_func(zend_object *object, zend_function *method_ptr, c
212212
return_value = v8js_propagate_exception(ctx);
213213
} else if (Z_TYPE(retval) == IS_OBJECT && Z_OBJ(retval) == object) {
214214
// special case: "return $this"
215+
#if PHP_V8_API_VERSION >= 13000000
216+
return_value = info.This();
217+
#else
215218
return_value = info.Holder();
219+
#endif
216220
} else {
217221
return_value = zval_to_v8js(&retval, isolate);
218222
}
@@ -227,7 +231,12 @@ static void v8js_call_php_func(zend_object *object, zend_function *method_ptr, c
227231
/* Callback for PHP methods and functions */
228232
void v8js_php_callback(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */
229233
{
230-
v8::Local<v8::Object> self = info.Holder();
234+
v8::Local<v8::Object> self;
235+
#if PHP_V8_API_VERSION >= 13000000
236+
self = info.This();
237+
#else
238+
self = info.Holder();
239+
#endif
231240

232241
zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
233242
zend_function *method_ptr;
@@ -364,7 +373,12 @@ static void v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8::Ar
364373
v8::Isolate *isolate = info.GetIsolate();
365374
v8::Local<v8::Context> v8_context = isolate->GetEnteredOrMicrotaskContext();
366375

367-
v8::Local<v8::Object> self = info.Holder();
376+
v8::Local<v8::Object> self;
377+
#if PHP_V8_API_VERSION >= 13000000
378+
self = info.This();
379+
#else
380+
self = info.Holder();
381+
#endif
368382
v8::Local<v8::Array> result = v8::Array::New(isolate, 0);
369383
uint32_t result_len = 0;
370384

@@ -466,7 +480,12 @@ static void v8js_invoke_callback(const v8::FunctionCallbackInfo<v8::Value>& info
466480
v8::Isolate *isolate = info.GetIsolate();
467481
v8::Local<v8::Context> v8_context = isolate->GetEnteredOrMicrotaskContext();
468482

469-
v8::Local<v8::Object> self = info.Holder();
483+
v8::Local<v8::Object> self;
484+
#if PHP_V8_API_VERSION >= 13000000
485+
self = info.This();
486+
#else
487+
self = info.Holder();
488+
#endif
470489
v8::Local<v8::Function> cb = v8::Local<v8::Function>::Cast(info.Data());
471490
int argc = info.Length(), i;
472491
v8::Local<v8::Value> *argv = static_cast<v8::Local<v8::Value> *>(alloca(sizeof(v8::Local<v8::Value>) * argc));
@@ -511,7 +530,12 @@ static void v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& info)
511530
v8::Isolate *isolate = info.GetIsolate();
512531
v8::Local<v8::Context> v8_context = isolate->GetEnteredOrMicrotaskContext();
513532

514-
v8::Local<v8::Object> self = info.Holder();
533+
v8::Local<v8::Object> self;
534+
#if PHP_V8_API_VERSION >= 13000000
535+
self = info.This();
536+
#else
537+
self = info.Holder();
538+
#endif
515539
v8::Local<v8::Value> return_value = V8JS_NULL;
516540

517541
char *error;
@@ -859,7 +883,13 @@ v8::Local<v8::Value> v8js_named_property_callback(v8::Isolate *isolate, v8::Loca
859883

860884
static V8JS_INTERCEPTED v8js_named_property_getter(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */
861885
{
862-
v8::Local<v8::Value> r = v8js_named_property_callback(info.GetIsolate(), info.Holder(), property, V8JS_PROP_GETTER);
886+
v8::Local<v8::Object> self;
887+
#if PHP_V8_API_VERSION >= 13000000
888+
self = info.This();
889+
#else
890+
self = info.Holder();
891+
#endif
892+
v8::Local<v8::Value> r = v8js_named_property_callback(info.GetIsolate(), self, property, V8JS_PROP_GETTER);
863893

864894
if (r.IsEmpty()) {
865895
return V8JS_INTERCEPTED_NO;
@@ -872,7 +902,13 @@ static V8JS_INTERCEPTED v8js_named_property_getter(v8::Local<v8::Name> property,
872902

873903
static V8JS_INTERCEPTED v8js_named_property_setter(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const V8JS_SETTER_PROPERTY_CALLBACK_INFO &info) /* {{{ */
874904
{
875-
v8::Local<v8::Value> r = v8js_named_property_callback(info.GetIsolate(), info.Holder(), property, V8JS_PROP_SETTER, value);
905+
v8::Local<v8::Object> self;
906+
#if PHP_V8_API_VERSION >= 13000000
907+
self = info.This();
908+
#else
909+
self = info.Holder();
910+
#endif
911+
v8::Local<v8::Value> r = v8js_named_property_callback(info.GetIsolate(), self, property, V8JS_PROP_SETTER, value);
876912
#if PHP_V8_HAS_INTERCEPTED
877913
return r.IsEmpty() ? v8::Intercepted::kNo : v8::Intercepted::kYes;
878914
#else
@@ -883,7 +919,13 @@ static V8JS_INTERCEPTED v8js_named_property_setter(v8::Local<v8::Name> property,
883919

884920
static V8JS_INTERCEPTED v8js_named_property_query(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Integer> &info) /* {{{ */
885921
{
886-
v8::Local<v8::Value> r = v8js_named_property_callback(info.GetIsolate(), info.Holder(), property, V8JS_PROP_QUERY);
922+
v8::Local<v8::Object> self;
923+
#if PHP_V8_API_VERSION >= 13000000
924+
self = info.This();
925+
#else
926+
self = info.Holder();
927+
#endif
928+
v8::Local<v8::Value> r = v8js_named_property_callback(info.GetIsolate(), self, property, V8JS_PROP_QUERY);
887929
if (r.IsEmpty()) {
888930
return V8JS_INTERCEPTED_NO;
889931
}
@@ -901,7 +943,13 @@ static V8JS_INTERCEPTED v8js_named_property_query(v8::Local<v8::Name> property,
901943

902944
static V8JS_INTERCEPTED v8js_named_property_deleter(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Boolean> &info) /* {{{ */
903945
{
904-
v8::Local<v8::Value> r = v8js_named_property_callback(info.GetIsolate(), info.Holder(), property, V8JS_PROP_DELETER);
946+
v8::Local<v8::Object> self;
947+
#if PHP_V8_API_VERSION >= 13000000
948+
self = info.This();
949+
#else
950+
self = info.Holder();
951+
#endif
952+
v8::Local<v8::Value> r = v8js_named_property_callback(info.GetIsolate(), self, property, V8JS_PROP_DELETER);
905953
if (r.IsEmpty()) {
906954
return V8JS_INTERCEPTED_NO;
907955
}

0 commit comments

Comments
 (0)