Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static member fixed #74

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion YantraJS.Core.Tests/Core/GCTests/FinalizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void FinalizeTest()

private static void Register(JSFinalizationRegistry fr)
{
JSFinalizationRegistry.Register(new Arguments(fr, new JSObject(), new JSString("a")));
fr.Register(new Arguments(fr, new JSObject(), new JSString("a")));
}
}
}
18 changes: 6 additions & 12 deletions YantraJS.Core/Core/Weak/WeakRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,27 @@ private void FinalizeReference(JSValue token)
}

[JSExport]
public static JSValue Unregister(in Arguments a)
public JSValue Unregister(in Arguments a)
{
if (!(a.This is JSFinalizationRegistry @this))
throw JSContext.Current.NewTypeError($"Invalid receiver");
if (!(a[0] is JSObject obj))
throw JSContext.Current.NewTypeError($"Argument is not an object");
// var weakRef = obj[@this.finalizationSymbol] as WeakObject;
// GC.SuppressFinalize(weakRef);
@this.Unregister(a[0]);
this.Unregister(a[0]);
return JSUndefined.Value;
}


[JSExport]
public static JSValue Register(in Arguments a)
public JSValue Register(in Arguments a)
{
if (!(a.This is JSFinalizationRegistry @this))
throw JSContext.Current.NewTypeError($"Invalid receiver");
if (!(a[0] is JSObject obj))
throw JSContext.Current.NewTypeError($"Argument is not an object");
var token = a[1];
if (token?.IsNullOrUndefined ?? false)
throw JSContext.Current.NewTypeError($"Token is required");
// obj[@this.finalizationSymbol] = new WeakObject(@this, a[1]);
@this.Register(obj, token);
this.Register(obj, token);
return JSUndefined.Value;
}

Expand Down Expand Up @@ -106,11 +102,9 @@ public static JSValue Constructor(in Arguments a)
}

[JSExport]
public static JSValue Deref(in Arguments a)
public JSValue Deref(in Arguments a)
{
if (!(a.This is JSWeakRef wr))
throw JSContext.Current.NewTypeError("WeakRef.prototype.deref receiver is not WeakRef");
if (wr.weak.TryGetTarget(out var v))
if (weak.TryGetTarget(out var v))
return v;
return JSUndefined.Value;
}
Expand Down