From 624fdf80e0dc72d537015b8d9e55ccc07a46779b Mon Sep 17 00:00:00 2001 From: Meir Shpilraien Date: Sun, 10 Sep 2023 11:27:13 +0300 Subject: [PATCH 1/3] Fix compilation with V8 version >= 11.9. --- v8_c_api/src/v8_c_api.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/v8_c_api/src/v8_c_api.cpp b/v8_c_api/src/v8_c_api.cpp index e3bcf38..c0176c9 100644 --- a/v8_c_api/src/v8_c_api.cpp +++ b/v8_c_api/src/v8_c_api.cpp @@ -1299,7 +1299,19 @@ void v8_ObjectSetInternalField(v8_local_object *obj, size_t index, v8_local_valu } v8_local_value* v8_ObjectGetInternalField(v8_local_object *obj, size_t index) { + // On v8 version 11.9, the API was changed to allow setting any V8 and not just + // Local. This is why we need to check the V8 version to decide which code + // flow to take. +#if (V8_MAJOR_VERSION > 11) || (V8_MAJOR_VERSION == 11 && V8_MINOR_VERSION >= 9) + v8::Local data = obj->obj->GetInternalField(index); + if (!data->IsValue()) + { + return NULL; + } + v8::Local val = data.As(); +#else v8::Local val = obj->obj->GetInternalField(index); +#endif v8_local_value *res = (v8_local_value*) V8_ALLOC(sizeof(*res)); res = new (res) v8_local_value(val); return res; From 9868a113d287f341b4e0d44bfee1062018bd8c0a Mon Sep 17 00:00:00 2001 From: Meir Shpilraien Date: Sun, 10 Sep 2023 11:29:21 +0300 Subject: [PATCH 2/3] Fix comment typo --- v8_c_api/src/v8_c_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v8_c_api/src/v8_c_api.cpp b/v8_c_api/src/v8_c_api.cpp index c0176c9..8472bb2 100644 --- a/v8_c_api/src/v8_c_api.cpp +++ b/v8_c_api/src/v8_c_api.cpp @@ -1299,7 +1299,7 @@ void v8_ObjectSetInternalField(v8_local_object *obj, size_t index, v8_local_valu } v8_local_value* v8_ObjectGetInternalField(v8_local_object *obj, size_t index) { - // On v8 version 11.9, the API was changed to allow setting any V8 and not just + // On v8 version 11.9, the API was changed to allow setting any V8 data and not just // Local. This is why we need to check the V8 version to decide which code // flow to take. #if (V8_MAJOR_VERSION > 11) || (V8_MAJOR_VERSION == 11 && V8_MINOR_VERSION >= 9) From 25d0a9f275e0351c91b6aded3cc8d61c2eadd69e Mon Sep 17 00:00:00 2001 From: Meir Shpilraien Date: Tue, 12 Sep 2023 10:06:46 +0300 Subject: [PATCH 3/3] Review fixes --- v8_c_api/src/v8_c_api.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/v8_c_api/src/v8_c_api.cpp b/v8_c_api/src/v8_c_api.cpp index 8472bb2..3d94c68 100644 --- a/v8_c_api/src/v8_c_api.cpp +++ b/v8_c_api/src/v8_c_api.cpp @@ -1299,19 +1299,7 @@ void v8_ObjectSetInternalField(v8_local_object *obj, size_t index, v8_local_valu } v8_local_value* v8_ObjectGetInternalField(v8_local_object *obj, size_t index) { - // On v8 version 11.9, the API was changed to allow setting any V8 data and not just - // Local. This is why we need to check the V8 version to decide which code - // flow to take. -#if (V8_MAJOR_VERSION > 11) || (V8_MAJOR_VERSION == 11 && V8_MINOR_VERSION >= 9) - v8::Local data = obj->obj->GetInternalField(index); - if (!data->IsValue()) - { - return NULL; - } - v8::Local val = data.As(); -#else - v8::Local val = obj->obj->GetInternalField(index); -#endif + v8::Local val = obj->obj->GetInternalField(index).As(); v8_local_value *res = (v8_local_value*) V8_ALLOC(sizeof(*res)); res = new (res) v8_local_value(val); return res;