mirror of
https://github.com/wgh136/flutter_qjs.git
synced 2025-09-27 21:37:24 +00:00
make JSFunction Finalizable
This commit is contained in:
@@ -27,9 +27,14 @@ abstract class JSRef {
|
|||||||
_refCount++;
|
_refCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _released = false;
|
||||||
|
|
||||||
void free() {
|
void free() {
|
||||||
_refCount--;
|
_refCount--;
|
||||||
if (_refCount < 0) destroy();
|
if (_refCount < 0 && !_released){
|
||||||
|
_released = true;
|
||||||
|
destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
@@ -150,8 +150,12 @@ class _JSObject extends JSRef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// JS function wrapper
|
/// JS function wrapper
|
||||||
class _JSFunction extends _JSObject implements JSInvokable, _IsolateEncodable {
|
class _JSFunction extends _JSObject implements JSInvokable, _IsolateEncodable, Finalizable {
|
||||||
_JSFunction(Pointer<JSContext> ctx, Pointer<JSValue> val) : super(ctx, val);
|
_JSFunction(Pointer<JSContext> ctx, Pointer<JSValue> val) : super(ctx, val) {
|
||||||
|
_finalizer.attach(this, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static final _finalizer = Finalizer<_JSFunction>((f) => f.free());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
invoke(List<dynamic> arguments, [dynamic thisVal]) {
|
invoke(List<dynamic> arguments, [dynamic thisVal]) {
|
||||||
|
Reference in New Issue
Block a user