diff --git a/Jint.Tests.Test262/Test262Harness.settings.json b/Jint.Tests.Test262/Test262Harness.settings.json index 75eed76e51..fcd82c74dd 100644 --- a/Jint.Tests.Test262/Test262Harness.settings.json +++ b/Jint.Tests.Test262/Test262Harness.settings.json @@ -9,7 +9,6 @@ "async-iteration", "Atomics", "decorators", - "Error.isError", "explicit-resource-management", "import-defer", "iterator-helpers", diff --git a/Jint/Native/Error/ErrorConstructor.cs b/Jint/Native/Error/ErrorConstructor.cs index 563d4dbc57..b5cb1986bc 100644 --- a/Jint/Native/Error/ErrorConstructor.cs +++ b/Jint/Native/Error/ErrorConstructor.cs @@ -1,6 +1,8 @@ +using Jint.Collections; using Jint.Native.Object; using Jint.Runtime; using Jint.Runtime.Descriptors; +using Jint.Runtime.Interop; namespace Jint.Native.Error; @@ -25,6 +27,15 @@ internal ErrorConstructor( internal ErrorPrototype PrototypeObject { get; } + protected override void Initialize() + { + var properties = new PropertyDictionary(3, checkExistingKeys: false) + { + ["isError"] = new PropertyDescriptor(new PropertyDescriptor(new ClrFunction(Engine, "isError", IsError, 1), PropertyFlag.NonEnumerable)), + }; + SetProperties(properties); + } + protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments) { return Construct(arguments, this); @@ -32,7 +43,7 @@ protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments public ObjectInstance Construct(string? message = null) { - return Construct(message != null ? new JsValue[]{ message } : System.Array.Empty(), this); + return Construct(message != null ? new JsValue[] { message } : System.Array.Empty(), this); } /// @@ -83,4 +94,12 @@ public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget) return callStack.BuildCallStackString(_engine, lastSyntaxNode.Location, currentFunction == this ? 1 : 0); } } + + /// + /// https://tc39.es/proposal-is-error/ + /// + private static JsValue IsError(JsValue? thisObj, JsValue[] arguments) + { + return arguments.At(0) is JsError; + } } diff --git a/README.md b/README.md index 2ef5267885..676e9abb41 100644 --- a/README.md +++ b/README.md @@ -130,14 +130,15 @@ and many more. #### ECMAScript Stage 3 (no version yet) -- ✔ Float16Array (Requires NET 6 or higher) +- ✔ `Error.isError` +- ✔ `Float16Array` (Requires NET 6 or higher) - ✔ Import attributes - ✔ JSON modules -- ✔ Math.sumPrecise +- ✔ `Math.sumPrecise` - ✔ `Promise.try` - ✔ Set methods (`intersection`, `union`, `difference`, `symmetricDifference`, `isSubsetOf`, `isSupersetOf`, `isDisjointFrom`) -- ✔ ShadowRealm -- ✔ Uint8Array to/from base64 +- ✔ `ShadowRealm` +- ✔ `Uint8Array` to/from base64 #### Other