From 5ee71e78a3d2f1272ce8b57301bf157c6e1356a2 Mon Sep 17 00:00:00 2001 From: Marko Lahma Date: Sun, 30 Jul 2023 22:05:34 +0300 Subject: [PATCH] Rename WeakRefInstance to JsWeakRef --- Jint/Native/WeakRef/{WeakRefInstance.cs => JsWeakRef.cs} | 4 ++-- Jint/Native/WeakRef/WeakRefConstructor.cs | 2 +- Jint/Native/WeakRef/WeakRefPrototype.cs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) rename Jint/Native/WeakRef/{WeakRefInstance.cs => JsWeakRef.cs} (80%) diff --git a/Jint/Native/WeakRef/WeakRefInstance.cs b/Jint/Native/WeakRef/JsWeakRef.cs similarity index 80% rename from Jint/Native/WeakRef/WeakRefInstance.cs rename to Jint/Native/WeakRef/JsWeakRef.cs index 77ef081e93..6eaec58430 100644 --- a/Jint/Native/WeakRef/WeakRefInstance.cs +++ b/Jint/Native/WeakRef/JsWeakRef.cs @@ -5,11 +5,11 @@ namespace Jint.Native.WeakRef; /// /// https://tc39.es/ecma262/#sec-properties-of-weak-ref-instances /// -internal sealed class WeakRefInstance : ObjectInstance +internal sealed class JsWeakRef : ObjectInstance { private readonly WeakReference _weakRefTarget; - public WeakRefInstance(Engine engine, JsValue target) : base(engine) + public JsWeakRef(Engine engine, JsValue target) : base(engine) { _weakRefTarget = new WeakReference(target); } diff --git a/Jint/Native/WeakRef/WeakRefConstructor.cs b/Jint/Native/WeakRef/WeakRefConstructor.cs index bcfa74b9ac..913f45a141 100644 --- a/Jint/Native/WeakRef/WeakRefConstructor.cs +++ b/Jint/Native/WeakRef/WeakRefConstructor.cs @@ -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); diff --git a/Jint/Native/WeakRef/WeakRefPrototype.cs b/Jint/Native/WeakRef/WeakRefPrototype.cs index 7b1d4c3618..b0be7daefb 100644 --- a/Jint/Native/WeakRef/WeakRefPrototype.cs +++ b/Jint/Native/WeakRef/WeakRefPrototype.cs @@ -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; } }