Skip to content

Commit 9d84326

Browse files
lahmasebastienros
andauthored
ES2020 BigInt (#1027)
Co-authored-by: Sébastien Ros <[email protected]>
1 parent d84af69 commit 9d84326

File tree

76 files changed

+2213
-550
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2213
-550
lines changed

Jint.Repl/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private static void Main(string[] args)
6666
try
6767
{
6868
var result = engine.Evaluate(input, parserOptions);
69-
if (!result.IsNull() && !result.IsUndefined())
69+
if (!result.IsPrimitive() && result is not IPrimitiveInstance)
7070
{
7171
var serializer = new JsonSerializer(engine);
7272
var str = serializer.Serialize(result, Undefined.Instance, " ");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Xunit;
2+
3+
namespace Jint.Tests.Test262.BuiltIns
4+
{
5+
public class BigIntTests : Test262Test
6+
{
7+
[Theory(DisplayName = "built-ins\\BigInt")]
8+
[MemberData(nameof(SourceFiles), "built-ins\\BigInt", false)]
9+
[MemberData(nameof(SourceFiles), "built-ins\\BigInt", true, Skip = "Skipped")]
10+
protected void RunTest(SourceFile sourceFile)
11+
{
12+
RunTestInternal(sourceFile);
13+
}
14+
}
15+
}

Jint.Tests.Test262/Test262Test.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static Test262Test()
7373
"detachArrayBuffer.js",
7474
"byteConversionValues.js",
7575
"hidden-constructors.js",
76+
"testBigIntTypedArray.js"
7677
};
7778

7879
Sources = new Dictionary<string, Script>(files.Length);
@@ -174,7 +175,7 @@ protected void RunTestCode(string fileName, string code, bool strict)
174175

175176
if (!negative && !string.IsNullOrWhiteSpace(lastError))
176177
{
177-
throw new XunitException(lastError);
178+
throw new XunitException($"{Environment.NewLine}{fileName}{Environment.NewLine}{Environment.NewLine}{lastError}");
178179
}
179180
}
180181

@@ -242,10 +243,6 @@ public static IEnumerable<object[]> SourceFiles(string pathPrefix, bool skipped)
242243
skip = true;
243244
reason = "tail-calls not implemented";
244245
break;
245-
case "BigInt":
246-
skip = true;
247-
reason = "BigInt not implemented";
248-
break;
249246
case "generators":
250247
skip = true;
251248
reason = "generators not implemented";

Jint.Tests.Test262/test/built-ins/BigInt/asIntN/bigint-tobigint-errors.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ info: |
99
2. Let bigint ? ToBigInt(bigint).
1010
features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive]
1111
---*/
12+
assert.sameValue(typeof BigInt, 'function');
13+
assert.sameValue(typeof BigInt.asIntN, 'function');
14+
15+
assert.throws(TypeError, function () {
16+
BigInt.asIntN();
17+
}, "ToBigInt: no argument => undefined => TypeError");
18+
assert.throws(TypeError, function () {
19+
BigInt.asIntN(0);
20+
}, "ToBigInt: no argument => undefined => TypeError");
1221

1322
assert.throws(TypeError, function() {
1423
BigInt.asIntN(0, undefined);

Jint.Tests.Test262/test/built-ins/BigInt/asIntN/bigint-tobigint-toprimitive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ info: |
99
2. Let bigint ? ToBigInt(bigint).
1010
features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive]
1111
---*/
12-
12+
assert.sameValue(typeof BigInt, 'function');
13+
assert.sameValue(typeof BigInt.asIntN, 'function');
1314
function err() {
1415
throw new Test262Error();
1516
}

Jint.Tests.Test262/test/built-ins/BigInt/asIntN/bits-toindex-errors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ info: |
99
1. Let bits be ? ToIndex(bits).
1010
features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive]
1111
---*/
12+
assert.sameValue(typeof BigInt, 'function');
13+
assert.sameValue(typeof BigInt.asIntN, 'function');
1214

1315
assert.throws(RangeError, function() {
1416
BigInt.asIntN(-1, 0n);

Jint.Tests.Test262/test/built-ins/BigInt/asIntN/bits-toindex-toprimitive.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ info: |
99
1. Let bits be ? ToIndex(bits).
1010
features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive]
1111
---*/
12+
assert.sameValue(typeof BigInt, 'function');
13+
assert.sameValue(typeof BigInt.asIntN, 'function');
1214

1315
function err() {
1416
throw new Test262Error();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (C) 2020 Rick Waldron. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
esid: sec-ecmascript-standard-built-in-objects
5+
description: >
6+
BigInt.asIntN does not implement [[Construct]], is not new-able
7+
info: |
8+
ECMAScript Function Objects
9+
10+
Built-in function objects that are not identified as constructors do not
11+
implement the [[Construct]] internal method unless otherwise specified in
12+
the description of a particular function.
13+
14+
sec-evaluatenew
15+
16+
...
17+
7. If IsConstructor(constructor) is false, throw a TypeError exception.
18+
...
19+
includes: [isConstructor.js]
20+
features: [Reflect.construct, BigInt, arrow-function]
21+
---*/
22+
assert.sameValue(isConstructor(BigInt.asIntN), false, 'isConstructor(BigInt.asIntN) must return false');
23+
24+
assert.throws(TypeError, () => {
25+
new BigInt.asIntN(64, 1n);
26+
}, '`new BigInt.asIntN(64, 1n)` throws TypeError');

Jint.Tests.Test262/test/built-ins/BigInt/asUintN/bigint-tobigint-errors.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ info: |
99
2. Let bigint ? ToBigInt(bigint).
1010
features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive]
1111
---*/
12+
assert.sameValue(typeof BigInt, 'function');
13+
assert.sameValue(typeof BigInt.asUintN, 'function');
14+
15+
assert.throws(TypeError, function () {
16+
BigInt.asUintN();
17+
}, "ToBigInt: no argument => undefined => TypeError");
18+
assert.throws(TypeError, function () {
19+
BigInt.asUintN(0);
20+
}, "ToBigInt: no argument => undefined => TypeError");
1221

1322
assert.throws(TypeError, function() {
1423
BigInt.asUintN(0, undefined);

Jint.Tests.Test262/test/built-ins/BigInt/asUintN/bigint-tobigint-toprimitive.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ info: |
99
2. Let bigint ? ToBigInt(bigint).
1010
features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive]
1111
---*/
12+
assert.sameValue(typeof BigInt, 'function');
13+
assert.sameValue(typeof BigInt.asUintN, 'function');
1214

1315
function err() {
1416
throw new Test262Error();

0 commit comments

Comments
 (0)