This commit is contained in:
2024-12-18 12:52:31 +08:00
parent 8cb187e395
commit 167fedb776
2 changed files with 3 additions and 12 deletions

View File

@@ -27,14 +27,9 @@ abstract class JSRef {
_refCount++; _refCount++;
} }
bool _released = false;
void free() { void free() {
_refCount--; _refCount--;
if (_refCount < 0 && !_released){ if (_refCount < 0) destroy();
_released = true;
destroy();
}
} }
void destroy(); void destroy();

View File

@@ -150,12 +150,8 @@ class _JSObject extends JSRef {
} }
/// JS function wrapper /// JS function wrapper
class _JSFunction extends _JSObject implements JSInvokable, _IsolateEncodable, Finalizable { class _JSFunction extends _JSObject implements JSInvokable, _IsolateEncodable {
_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]) {