0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-10-18 10:18:40 +00:00

use v8::Global instead of v8::Persistent

This commit is contained in:
Stefan Siegl 2024-09-27 23:27:59 +02:00
parent 73e684f4a8
commit 888684b483
5 changed files with 20 additions and 20 deletions

View File

@ -53,7 +53,7 @@ extern const zend_function_entry v8js_methods[];
typedef struct _v8js_script {
char *name;
v8js_ctx *ctx;
v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script>> *script;
v8::Global<v8::Script> *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<v8js_function_tmpl_t *, v8js_function_tmpl_t>::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<zend_object *, v8js_persistent_obj_t>::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<v8::String>();
new(&c->context) v8::Persistent<v8::Context>();
new(&c->global_template) v8::Persistent<v8::FunctionTemplate>();
new(&c->array_tmpl) v8::Persistent<v8::FunctionTemplate>();
new(&c->object_name) v8::Global<v8::String>();
new(&c->context) v8::Global<v8::Context>();
new(&c->global_template) v8::Global<v8::FunctionTemplate>();
new(&c->array_tmpl) v8::Global<v8::FunctionTemplate>();
new(&c->modules_stack) std::vector<char*>();
new(&c->modules_loaded) std::map<char *, v8js_persistent_value_t, cmp_str>;
@ -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<v8::Script, v8::CopyablePersistentTraits<v8::Script>>(c->isolate, script.ToLocalChecked());
res->script = new v8::Global<v8::Script>(c->isolate, script.ToLocalChecked());
v8::String::Utf8Value _sname(isolate, sname);
res->name = estrndup(ToCString(_sname), _sname.length());

View File

@ -17,10 +17,10 @@
/* Abbreviate long type names */
typedef v8::Persistent<v8::FunctionTemplate, v8::CopyablePersistentTraits<v8::FunctionTemplate> > v8js_function_tmpl_t;
typedef v8::Persistent<v8::ObjectTemplate, v8::CopyablePersistentTraits<v8::ObjectTemplate> > v8js_object_tmpl_t;
typedef v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object> > v8js_persistent_obj_t;
typedef v8::Persistent<v8::Value, v8::CopyablePersistentTraits<v8::Value> > v8js_persistent_value_t;
typedef v8::Global<v8::FunctionTemplate> v8js_function_tmpl_t;
typedef v8::Global<v8::ObjectTemplate> v8js_object_tmpl_t;
typedef v8::Global<v8::Object> v8js_persistent_obj_t;
typedef v8::Global<v8::Value> v8js_persistent_value_t;
/* Forward declarations */
struct v8js_v8object;
@ -35,8 +35,8 @@ struct cmp_str {
/* {{{ Context container */
struct v8js_ctx {
v8::Persistent<v8::String> object_name;
v8::Persistent<v8::Context> context;
v8::Global<v8::String> object_name;
v8::Global<v8::Context> context;
int in_execution;
v8::Isolate *isolate;

View File

@ -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<v8::Value> newobj;
v8::Global<v8::Value> newobj;
newobj.Reset(isolate, c->modules_loaded[normalised_module_id]);
// TODO store v8::Global in c->modules_loaded directly!?

View File

@ -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<v8::Value>();
new (&c->v8obj) v8::Global<v8::Value>();
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<v8::Value>();
new (&c->v8obj.v8obj) v8::Global<v8::Value>();
return &c->v8obj.std;
}

View File

@ -16,7 +16,7 @@
/* {{{ Object container */
struct v8js_v8object {
v8::Persistent<v8::Value> v8obj;
v8::Global<v8::Value> v8obj;
int flags;
struct v8js_ctx *ctx;
HashTable *properties;