Skip to content

Commit a3c7444

Browse files
authoredJan 18, 2025··
Implement Error.isError (#2030)
1 parent dd77948 commit a3c7444

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed
 

‎Jint.Tests.Test262/Test262Harness.settings.json

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"async-iteration",
1010
"Atomics",
1111
"decorators",
12-
"Error.isError",
1312
"explicit-resource-management",
1413
"import-defer",
1514
"iterator-helpers",

‎Jint/Native/Error/ErrorConstructor.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using Jint.Collections;
12
using Jint.Native.Object;
23
using Jint.Runtime;
34
using Jint.Runtime.Descriptors;
5+
using Jint.Runtime.Interop;
46

57
namespace Jint.Native.Error;
68

@@ -25,14 +27,23 @@ internal ErrorConstructor(
2527

2628
internal ErrorPrototype PrototypeObject { get; }
2729

30+
protected override void Initialize()
31+
{
32+
var properties = new PropertyDictionary(3, checkExistingKeys: false)
33+
{
34+
["isError"] = new PropertyDescriptor(new PropertyDescriptor(new ClrFunction(Engine, "isError", IsError, 1), PropertyFlag.NonEnumerable)),
35+
};
36+
SetProperties(properties);
37+
}
38+
2839
protected internal override JsValue Call(JsValue thisObject, JsValue[] arguments)
2940
{
3041
return Construct(arguments, this);
3142
}
3243

3344
public ObjectInstance Construct(string? message = null)
3445
{
35-
return Construct(message != null ? new JsValue[]{ message } : System.Array.Empty<JsValue>(), this);
46+
return Construct(message != null ? new JsValue[] { message } : System.Array.Empty<JsValue>(), this);
3647
}
3748

3849
/// <summary>
@@ -83,4 +94,12 @@ public override ObjectInstance Construct(JsValue[] arguments, JsValue newTarget)
8394
return callStack.BuildCallStackString(_engine, lastSyntaxNode.Location, currentFunction == this ? 1 : 0);
8495
}
8596
}
97+
98+
/// <summary>
99+
/// https://tc39.es/proposal-is-error/
100+
/// </summary>
101+
private static JsValue IsError(JsValue? thisObj, JsValue[] arguments)
102+
{
103+
return arguments.At(0) is JsError;
104+
}
86105
}

‎README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,15 @@ and many more.
130130

131131
#### ECMAScript Stage 3 (no version yet)
132132

133-
- ✔ Float16Array (Requires NET 6 or higher)
133+
-`Error.isError`
134+
-`Float16Array` (Requires NET 6 or higher)
134135
- ✔ Import attributes
135136
- ✔ JSON modules
136-
- ✔ Math.sumPrecise
137+
-`Math.sumPrecise`
137138
-`Promise.try`
138139
- ✔ Set methods (`intersection`, `union`, `difference`, `symmetricDifference`, `isSubsetOf`, `isSupersetOf`, `isDisjointFrom`)
139-
- ✔ ShadowRealm
140-
- ✔ Uint8Array to/from base64
140+
-`ShadowRealm`
141+
-`Uint8Array` to/from base64
141142

142143
#### Other
143144

0 commit comments

Comments
 (0)
Please sign in to comment.