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

Rename WeakRefInstance to JsWeakRef #1602

Merged
merged 1 commit into from
Jul 30, 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace Jint.Native.WeakRef;
/// <summary>
/// https://tc39.es/ecma262/#sec-properties-of-weak-ref-instances
/// </summary>
internal sealed class WeakRefInstance : ObjectInstance
internal sealed class JsWeakRef : ObjectInstance
{
private readonly WeakReference<JsValue> _weakRefTarget;

public WeakRefInstance(Engine engine, JsValue target) : base(engine)
public JsWeakRef(Engine engine, JsValue target) : base(engine)
{
_weakRefTarget = new WeakReference<JsValue>(target);
}
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/WeakRef/WeakRefConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget)
var weakRef = OrdinaryCreateFromConstructor(
newTarget,
static intrinsics => intrinsics.WeakRef.PrototypeObject,
static (engine, _, target) => new WeakRefInstance(engine, target!),
static (engine, _, target) => new JsWeakRef(engine, target!),
target);

_engine.AddToKeptObjects(target);
Expand Down
8 changes: 4 additions & 4 deletions Jint/Native/WeakRef/WeakRefPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ protected override void Initialize()

private JsValue Deref(JsValue thisObject, JsValue[] arguments)
{
var weakRef = thisObject as WeakRefInstance;
if (weakRef is null)
if (thisObject is JsWeakRef weakRef)
{
ExceptionHelper.ThrowTypeError(_realm, "object must be a WeakRef");
return weakRef.WeakRefDeref();
}

return weakRef.WeakRefDeref();
ExceptionHelper.ThrowTypeError(_realm, "object must be a WeakRef");
return default;
}
}