Skip to content

Commit

Permalink
Rename WeakRefInstance to JsWeakRef (#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma authored Jul 30, 2023
1 parent 5c19933 commit 0b1ed1b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
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;
}
}

0 comments on commit 0b1ed1b

Please sign in to comment.