Fixed V8 crash with Create App

This commit is contained in:
ksuprynowicz 2023-02-23 18:17:23 +01:00
parent b554fc70ea
commit d25e5491eb
2 changed files with 12 additions and 5 deletions

View file

@ -31,6 +31,7 @@ public:
void next(); void next();
V8ScriptValue value(); V8ScriptValue value();
private: private:
// V8TODO: maybe these should be WeakPersistent?
v8::UniquePersistent<v8::Array> _propertyNames; v8::UniquePersistent<v8::Array> _propertyNames;
v8::UniquePersistent<v8::Object> _object; v8::UniquePersistent<v8::Object> _object;
v8::UniquePersistent<v8::Context> _context; v8::UniquePersistent<v8::Context> _context;

View file

@ -31,7 +31,8 @@ public:
v8::Isolate::Scope isolateScope(_engine->getIsolate()); v8::Isolate::Scope isolateScope(_engine->getIsolate());
v8::HandleScope handleScope(_engine->getIsolate()); v8::HandleScope handleScope(_engine->getIsolate());
v8::Context::Scope(_engine->getContext()); v8::Context::Scope(_engine->getContext());
_value.reset(new v8::UniquePersistent<T>(_engine->getIsolate(), value)); _value.reset(new v8::Persistent<T>(_engine->getIsolate(), value));
//_value.reset(new v8::UniquePersistent<T>(_engine->getIsolate(), value));
}; };
V8ScriptValueTemplate& operator= (const V8ScriptValueTemplate &source) { V8ScriptValueTemplate& operator= (const V8ScriptValueTemplate &source) {
@ -40,7 +41,8 @@ public:
v8::HandleScope handleScope(_engine->getIsolate()); v8::HandleScope handleScope(_engine->getIsolate());
v8::Context::Scope(_engine->getContext()); v8::Context::Scope(_engine->getContext());
_engine = source.getEngine(); _engine = source.getEngine();
_value.reset(new v8::UniquePersistent<T>(_engine->getIsolate(), source.constGet())); _value.reset(new v8::Persistent<T>(_engine->getIsolate(), source.constGet()));
//_value.reset(new v8::UniquePersistent<T>(_engine->getIsolate(), source.constGet()));
return *this; return *this;
}; };
@ -49,7 +51,8 @@ public:
v8::Isolate::Scope isolateScope(_engine->getIsolate()); v8::Isolate::Scope isolateScope(_engine->getIsolate());
v8::HandleScope handleScope(_engine->getIsolate()); v8::HandleScope handleScope(_engine->getIsolate());
v8::Context::Scope(_engine->getContext()); v8::Context::Scope(_engine->getContext());
_value.reset(new v8::UniquePersistent<T>(_engine->getIsolate(), v8::Local<T>())); //_value.reset(new v8::UniquePersistent<T>(_engine->getIsolate(), v8::Local<T>()));
_value.reset(new v8::Persistent<T>(_engine->getIsolate(), v8::Local<T>()));
}; };
V8ScriptValueTemplate(const V8ScriptValueTemplate &copied) : _engine(copied.getEngine()) { V8ScriptValueTemplate(const V8ScriptValueTemplate &copied) : _engine(copied.getEngine()) {
@ -57,7 +60,8 @@ public:
v8::Isolate::Scope isolateScope(_engine->getIsolate()); v8::Isolate::Scope isolateScope(_engine->getIsolate());
v8::HandleScope handleScope(_engine->getIsolate()); v8::HandleScope handleScope(_engine->getIsolate());
v8::Context::Scope(_engine->getContext()); v8::Context::Scope(_engine->getContext());
_value.reset(new v8::UniquePersistent<T>(_engine->getIsolate(), copied.constGet())); //_value.reset(new v8::UniquePersistent<T>(_engine->getIsolate(), copied.constGet()));
_value.reset(new v8::Persistent<T>(_engine->getIsolate(), copied.constGet()));
} }
v8::Local<T> get() { v8::Local<T> get() {
@ -104,7 +108,9 @@ public:
}; };
private: private:
std::shared_ptr<v8::UniquePersistent<T>> _value; // std::shared_ptr<v8::UniquePersistent<T>> _value;
// V8TODO: Persistent needs reset to release object? It may cause memory leaks here
std::shared_ptr<v8::Persistent<T>> _value;
// V8TODO: maybe make it weak // V8TODO: maybe make it weak
// does it need , CopyablePersistentTraits<Value>? // does it need , CopyablePersistentTraits<Value>?
// V8TODO: is context needed at all? // V8TODO: is context needed at all?