From 888684b4832109d2618b23d8fee7fcbba844a234 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Fri, 27 Sep 2024 23:27:59 +0200 Subject: [PATCH] use v8::Global instead of v8::Persistent --- v8js_class.cc | 20 ++++++++++---------- v8js_class.h | 12 ++++++------ v8js_methods.cc | 2 +- v8js_v8object_class.cc | 4 ++-- v8js_v8object_class.h | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/v8js_class.cc b/v8js_class.cc index 5b5ac51..26a5a29 100644 --- a/v8js_class.cc +++ b/v8js_class.cc @@ -53,7 +53,7 @@ extern const zend_function_entry v8js_methods[]; typedef struct _v8js_script { char *name; v8js_ctx *ctx; - v8::Persistent> *script; + v8::Global *script; } v8js_script; static void v8js_script_free(v8js_script *res); @@ -95,11 +95,11 @@ static void v8js_free_storage(zend_object *object) /* {{{ */ } c->object_name.Reset(); - c->object_name.~Persistent(); + c->object_name.~Global(); c->global_template.Reset(); - c->global_template.~Persistent(); + c->global_template.~Global(); c->array_tmpl.Reset(); - c->array_tmpl.~Persistent(); + c->array_tmpl.~Global(); /* Clear persistent call_impl & method_tmpls templates */ for (std::map::iterator it = c->call_impls.begin(); @@ -133,7 +133,7 @@ static void v8js_free_storage(zend_object *object) /* {{{ */ if (!c->context.IsEmpty()) { c->context.Reset(); } - c->context.~Persistent(); + c->context.~Global(); /* Dispose yet undisposed weak refs */ for (std::map::iterator it = c->weak_objects.begin(); @@ -208,10 +208,10 @@ static zend_object* v8js_new(zend_class_entry *ce) /* {{{ */ c->std.handlers = &v8js_object_handlers; - new(&c->object_name) v8::Persistent(); - new(&c->context) v8::Persistent(); - new(&c->global_template) v8::Persistent(); - new(&c->array_tmpl) v8::Persistent(); + new(&c->object_name) v8::Global(); + new(&c->context) v8::Global(); + new(&c->global_template) v8::Global(); + new(&c->array_tmpl) v8::Global(); new(&c->modules_stack) std::vector(); new(&c->modules_loaded) std::map; @@ -541,7 +541,7 @@ static void v8js_compile_script(zval *this_ptr, const zend_string *str, const ze return; } res = (v8js_script *)emalloc(sizeof(v8js_script)); - res->script = new v8::Persistent>(c->isolate, script.ToLocalChecked()); + res->script = new v8::Global(c->isolate, script.ToLocalChecked()); v8::String::Utf8Value _sname(isolate, sname); res->name = estrndup(ToCString(_sname), _sname.length()); diff --git a/v8js_class.h b/v8js_class.h index c69514d..cb89824 100644 --- a/v8js_class.h +++ b/v8js_class.h @@ -17,10 +17,10 @@ /* Abbreviate long type names */ -typedef v8::Persistent > v8js_function_tmpl_t; -typedef v8::Persistent > v8js_object_tmpl_t; -typedef v8::Persistent > v8js_persistent_obj_t; -typedef v8::Persistent > v8js_persistent_value_t; +typedef v8::Global v8js_function_tmpl_t; +typedef v8::Global v8js_object_tmpl_t; +typedef v8::Global v8js_persistent_obj_t; +typedef v8::Global v8js_persistent_value_t; /* Forward declarations */ struct v8js_v8object; @@ -35,8 +35,8 @@ struct cmp_str { /* {{{ Context container */ struct v8js_ctx { - v8::Persistent object_name; - v8::Persistent context; + v8::Global object_name; + v8::Global context; int in_execution; v8::Isolate *isolate; diff --git a/v8js_methods.cc b/v8js_methods.cc index 63a28db..1f69a7b 100644 --- a/v8js_methods.cc +++ b/v8js_methods.cc @@ -405,7 +405,7 @@ V8JS_METHOD(require) // If we have already loaded and cached this module then use it if (c->modules_loaded.count(normalised_module_id) > 0) { - v8::Persistent newobj; + v8::Global newobj; newobj.Reset(isolate, c->modules_loaded[normalised_module_id]); // TODO store v8::Global in c->modules_loaded directly!? diff --git a/v8js_v8object_class.cc b/v8js_v8object_class.cc index a27fd63..b0e8007 100644 --- a/v8js_v8object_class.cc +++ b/v8js_v8object_class.cc @@ -537,7 +537,7 @@ static zend_object *v8js_v8object_new(zend_class_entry *ce) /* {{{ */ zend_object_std_init(&c->std, ce); c->std.handlers = &v8js_v8object_handlers; - new (&c->v8obj) v8::Persistent(); + new (&c->v8obj) v8::Global(); return &c->std; } @@ -624,7 +624,7 @@ static zend_object *v8js_v8generator_new(zend_class_entry *ce) /* {{{ */ zend_object_std_init(&c->v8obj.std, ce); c->v8obj.std.handlers = &v8js_v8generator_handlers; - new (&c->v8obj.v8obj) v8::Persistent(); + new (&c->v8obj.v8obj) v8::Global(); return &c->v8obj.std; } diff --git a/v8js_v8object_class.h b/v8js_v8object_class.h index 0bb7ed0..f7c39a8 100644 --- a/v8js_v8object_class.h +++ b/v8js_v8object_class.h @@ -16,7 +16,7 @@ /* {{{ Object container */ struct v8js_v8object { - v8::Persistent v8obj; + v8::Global v8obj; int flags; struct v8js_ctx *ctx; HashTable *properties;