Skip to content

Commit 37bbad2

Browse files
committed
[JSC] Implement BigInt.asIntN and BigInt.asUintN
https://bugs.webkit.org/show_bug.cgi?id=181144 Reviewed by Darin Adler. JSTests: * stress/bigint-asintn.js: Added. (shouldBe): (shouldThrow): (BigInt.asIntN): * stress/bigint-asuintn.js: Added. (shouldBe): (shouldThrow): (BigInt.asUintN): * test262/expectations.yaml: Source/JavaScriptCore: This patch implements BigInt.asIntN[1] and BigInt.asUintN[2] features. As the same to the other BigInt runtime C++ code, we port V8 code to JSC to implement both. BigInt.asIntN is `static_cast<intN_t>(BigInt value)` and BigInt.asUintN is `static_cast<uintN_t>(BigInt value)`. They are getting slice of N bits from two's complement representation of the given BigInt. The difference between asIntN and asUintN is asIntN renders MSB as a sign. This patch is once rolled out due to ARM64_32 build failure, which is caused by the existing bug[3]. Relanding it since it is now fixed. [1]: https://tc39.es/ecma262/#sec-bigint.asintn [2]: https://tc39.es/ecma262/#sec-bigint.asuintn [3]: https://trac.webkit.org/changeset/261174/webkit * runtime/BigIntConstructor.cpp: (JSC::toBigInt): (JSC::bigIntConstructorFuncAsUintN): (JSC::bigIntConstructorFuncAsIntN): * runtime/JSBigInt.cpp: (JSC::zeroImpl): (JSC::JSBigInt::divideImpl): (JSC::JSBigInt::unaryMinusImpl): (JSC::JSBigInt::remainderImpl): (JSC::JSBigInt::digitDiv): (JSC::JSBigInt::absoluteSub): (JSC::JSBigInt::asIntNImpl): (JSC::JSBigInt::asUintNImpl): (JSC::JSBigInt::truncateToNBits): (JSC::JSBigInt::truncateAndSubFromPowerOfTwo): (JSC::JSBigInt::asIntN): (JSC::JSBigInt::asUintN): * runtime/JSBigInt.h: Canonical link: https://commits.webkit.org/224372@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261199 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 323a93c commit 37bbad2

8 files changed

Lines changed: 578 additions & 109 deletions

File tree

‎JSTests/ChangeLog‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2020-05-05 Yusuke Suzuki <ysuzuki@apple.com>
2+
3+
[JSC] Implement BigInt.asIntN and BigInt.asUintN
4+
https://bugs.webkit.org/show_bug.cgi?id=181144
5+
6+
Reviewed by Darin Adler.
7+
8+
* stress/bigint-asintn.js: Added.
9+
(shouldBe):
10+
(shouldThrow):
11+
(BigInt.asIntN):
12+
* stress/bigint-asuintn.js: Added.
13+
(shouldBe):
14+
(shouldThrow):
15+
(BigInt.asUintN):
16+
* test262/expectations.yaml:
17+
118
2020-05-05 Ross Kirsling <ross.kirsling@sony.com>
219

320
[Intl] Alphabetize extension keys and correctly mark const methods

‎JSTests/stress/bigint-asintn.js‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
function shouldBe(actual, expected) {
2+
if (actual !== expected)
3+
throw new Error('bad value: ' + actual);
4+
}
5+
6+
function shouldThrow(func, errorMessage) {
7+
var errorThrown = false;
8+
var error = null;
9+
try {
10+
func();
11+
} catch (e) {
12+
errorThrown = true;
13+
error = e;
14+
}
15+
if (!errorThrown)
16+
throw new Error('not thrown');
17+
if (String(error) !== errorMessage)
18+
throw new Error(`bad error: ${String(error)}`);
19+
}
20+
21+
shouldThrow(() => {
22+
BigInt.asIntN(-1, 0n)
23+
}, `RangeError: number of bits cannot be negative`);
24+
25+
{
26+
let toIndex = false;
27+
let toBigInt = false;
28+
let index = {
29+
[Symbol.toPrimitive]() {
30+
shouldBe(toIndex, false);
31+
shouldBe(toBigInt, false);
32+
toIndex = true;
33+
return 32;
34+
}
35+
};
36+
let bigint = {
37+
[Symbol.toPrimitive]() {
38+
shouldBe(toIndex, true);
39+
shouldBe(toBigInt, false);
40+
toBigInt = true;
41+
return 10n;
42+
}
43+
}
44+
shouldBe(BigInt.asIntN(index, bigint), 10n);
45+
shouldBe(toIndex, true);
46+
shouldBe(toBigInt, true);
47+
}
48+
49+
shouldBe(BigInt.asIntN(-0, 0n), 0n);
50+
51+
shouldBe(BigInt.asIntN(0, 0n), 0n);
52+
shouldBe(BigInt.asIntN(1, 0n), 0n);
53+
shouldBe(BigInt.asIntN(2, 0n), 0n);
54+
shouldBe(BigInt.asIntN(3, 0n), 0n);
55+
56+
shouldBe(BigInt.asIntN(0, 1n), 0n);
57+
shouldBe(BigInt.asIntN(1, 1n), -1n);
58+
shouldBe(BigInt.asIntN(2, 1n), 1n);
59+
shouldBe(BigInt.asIntN(3, 1n), 1n);
60+
61+
shouldBe(BigInt.asIntN(30, 0x7fffffffn), -1n);
62+
shouldBe(BigInt.asIntN(31, 0x7fffffffn), -1n);
63+
shouldBe(BigInt.asIntN(32, 0x7fffffffn), 2147483647n);
64+
shouldBe(BigInt.asIntN(33, 0x7fffffffn), 2147483647n);
65+
shouldBe(BigInt.asIntN(34, 0x7fffffffn), 2147483647n);
66+
67+
shouldBe(BigInt.asIntN(30, 0x80000000n), 0n);
68+
shouldBe(BigInt.asIntN(31, 0x80000000n), 0n);
69+
shouldBe(BigInt.asIntN(32, 0x80000000n), -2147483648n);
70+
shouldBe(BigInt.asIntN(33, 0x80000000n), 2147483648n);
71+
shouldBe(BigInt.asIntN(34, 0x80000000n), 2147483648n);
72+
73+
shouldBe(BigInt.asIntN(30, -0x80000000n), 0n);
74+
shouldBe(BigInt.asIntN(31, -0x80000000n), 0n);
75+
shouldBe(BigInt.asIntN(32, -0x80000000n), -2147483648n);
76+
shouldBe(BigInt.asIntN(33, -0x80000000n), -2147483648n);
77+
shouldBe(BigInt.asIntN(34, -0x80000000n), -2147483648n);
78+
79+
shouldBe(BigInt.asIntN(30, -0x80000001n), -1n);
80+
shouldBe(BigInt.asIntN(31, -0x80000001n), -1n);
81+
shouldBe(BigInt.asIntN(32, -0x80000001n), 2147483647n);
82+
shouldBe(BigInt.asIntN(33, -0x80000001n), -2147483649n);
83+
shouldBe(BigInt.asIntN(34, -0x80000001n), -2147483649n);
84+
85+
shouldBe(BigInt.asIntN(62, 0x7fffffffffffffffn), -1n);
86+
shouldBe(BigInt.asIntN(63, 0x7fffffffffffffffn), -1n);
87+
shouldBe(BigInt.asIntN(64, 0x7fffffffffffffffn), 9223372036854775807n);
88+
shouldBe(BigInt.asIntN(65, 0x7fffffffffffffffn), 9223372036854775807n);
89+
shouldBe(BigInt.asIntN(66, 0x7fffffffffffffffn), 9223372036854775807n);
90+
91+
shouldBe(BigInt.asIntN(62, 0x8000000000000000n), 0n);
92+
shouldBe(BigInt.asIntN(63, 0x8000000000000000n), 0n);
93+
shouldBe(BigInt.asIntN(64, 0x8000000000000000n), -9223372036854775808n);
94+
shouldBe(BigInt.asIntN(65, 0x8000000000000000n), 9223372036854775808n);
95+
shouldBe(BigInt.asIntN(66, 0x8000000000000000n), 9223372036854775808n);
96+
97+
shouldBe(BigInt.asIntN(62, -0x800000000000000n), -576460752303423488n);
98+
shouldBe(BigInt.asIntN(63, -0x800000000000000n), -576460752303423488n);
99+
shouldBe(BigInt.asIntN(64, -0x800000000000000n), -576460752303423488n);
100+
shouldBe(BigInt.asIntN(65, -0x800000000000000n), -576460752303423488n);
101+
shouldBe(BigInt.asIntN(66, -0x800000000000000n), -576460752303423488n);
102+
103+
shouldBe(BigInt.asIntN(62, -0x800000000000001n), -576460752303423489n);
104+
shouldBe(BigInt.asIntN(63, -0x800000000000001n), -576460752303423489n);
105+
shouldBe(BigInt.asIntN(64, -0x800000000000001n), -576460752303423489n);
106+
shouldBe(BigInt.asIntN(65, -0x800000000000001n), -576460752303423489n);
107+
shouldBe(BigInt.asIntN(66, -0x800000000000001n), -576460752303423489n);

‎JSTests/stress/bigint-asuintn.js‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
function shouldBe(actual, expected) {
2+
if (actual !== expected)
3+
throw new Error('bad value: ' + actual);
4+
}
5+
6+
function shouldThrow(func, errorMessage) {
7+
var errorThrown = false;
8+
var error = null;
9+
try {
10+
func();
11+
} catch (e) {
12+
errorThrown = true;
13+
error = e;
14+
}
15+
if (!errorThrown)
16+
throw new Error('not thrown');
17+
if (String(error) !== errorMessage)
18+
throw new Error(`bad error: ${String(error)}`);
19+
}
20+
21+
shouldThrow(() => {
22+
BigInt.asUintN(-1, 0n)
23+
}, `RangeError: number of bits cannot be negative`);
24+
25+
{
26+
let toIndex = false;
27+
let toBigInt = false;
28+
let index = {
29+
[Symbol.toPrimitive]() {
30+
shouldBe(toIndex, false);
31+
shouldBe(toBigInt, false);
32+
toIndex = true;
33+
return 32;
34+
}
35+
};
36+
let bigint = {
37+
[Symbol.toPrimitive]() {
38+
shouldBe(toIndex, true);
39+
shouldBe(toBigInt, false);
40+
toBigInt = true;
41+
return 10n;
42+
}
43+
}
44+
shouldBe(BigInt.asUintN(index, bigint), 10n);
45+
shouldBe(toIndex, true);
46+
shouldBe(toBigInt, true);
47+
}
48+
49+
shouldBe(BigInt.asUintN(-0, 0n), 0n);
50+
shouldBe(BigInt.asUintN(0, 0n), 0n);
51+
shouldBe(BigInt.asUintN(1, 0n), 0n);
52+
shouldBe(BigInt.asUintN(2, 0n), 0n);
53+
shouldBe(BigInt.asUintN(3, 0n), 0n);
54+
55+
shouldBe(BigInt.asUintN(0, 1n), 0n);
56+
shouldBe(BigInt.asUintN(1, 1n), 1n);
57+
shouldBe(BigInt.asUintN(2, 1n), 1n);
58+
shouldBe(BigInt.asUintN(3, 1n), 1n);
59+
60+
shouldBe(BigInt.asUintN(30, 0x7fffffffn), 1073741823n);
61+
shouldBe(BigInt.asUintN(31, 0x7fffffffn), 2147483647n);
62+
shouldBe(BigInt.asUintN(32, 0x7fffffffn), 2147483647n);
63+
shouldBe(BigInt.asUintN(33, 0x7fffffffn), 2147483647n);
64+
shouldBe(BigInt.asUintN(34, 0x7fffffffn), 2147483647n);
65+
66+
shouldBe(BigInt.asUintN(30, 0x80000000n), 0n);
67+
shouldBe(BigInt.asUintN(31, 0x80000000n), 0n);
68+
shouldBe(BigInt.asUintN(32, 0x80000000n), 2147483648n);
69+
shouldBe(BigInt.asUintN(33, 0x80000000n), 2147483648n);
70+
shouldBe(BigInt.asUintN(34, 0x80000000n), 2147483648n);
71+
72+
shouldBe(BigInt.asUintN(30, 0xffffffffn), 1073741823n);
73+
shouldBe(BigInt.asUintN(31, 0xffffffffn), 2147483647n);
74+
shouldBe(BigInt.asUintN(32, 0xffffffffn), 4294967295n);
75+
shouldBe(BigInt.asUintN(33, 0xffffffffn), 4294967295n);
76+
shouldBe(BigInt.asUintN(34, 0xffffffffn), 4294967295n);
77+
78+
shouldBe(BigInt.asUintN(30, -0x80000000n), 0n);
79+
shouldBe(BigInt.asUintN(31, -0x80000000n), 0n);
80+
shouldBe(BigInt.asUintN(32, -0x80000000n), 2147483648n);
81+
shouldBe(BigInt.asUintN(33, -0x80000000n), 6442450944n);
82+
shouldBe(BigInt.asUintN(34, -0x80000000n), 15032385536n);
83+
84+
shouldBe(BigInt.asUintN(30, -0x80000001n), 1073741823n);
85+
shouldBe(BigInt.asUintN(31, -0x80000001n), 2147483647n);
86+
shouldBe(BigInt.asUintN(32, -0x80000001n), 2147483647n);
87+
shouldBe(BigInt.asUintN(33, -0x80000001n), 6442450943n);
88+
shouldBe(BigInt.asUintN(34, -0x80000001n), 15032385535n);
89+
90+
shouldBe(BigInt.asUintN(30, -0xffffffffn), 1n);
91+
shouldBe(BigInt.asUintN(31, -0xffffffffn), 1n);
92+
shouldBe(BigInt.asUintN(32, -0xffffffffn), 1n);
93+
shouldBe(BigInt.asUintN(33, -0xffffffffn), 4294967297n);
94+
shouldBe(BigInt.asUintN(34, -0xffffffffn), 12884901889n);
95+
96+
shouldBe(BigInt.asUintN(62, 0x7fffffffffffffffn), 4611686018427387903n);
97+
shouldBe(BigInt.asUintN(63, 0x7fffffffffffffffn), 9223372036854775807n);
98+
shouldBe(BigInt.asUintN(64, 0x7fffffffffffffffn), 9223372036854775807n);
99+
shouldBe(BigInt.asUintN(65, 0x7fffffffffffffffn), 9223372036854775807n);
100+
shouldBe(BigInt.asUintN(66, 0x7fffffffffffffffn), 9223372036854775807n);
101+
102+
shouldBe(BigInt.asUintN(62, 0x8000000000000000n), 0n);
103+
shouldBe(BigInt.asUintN(63, 0x8000000000000000n), 0n);
104+
shouldBe(BigInt.asUintN(64, 0x8000000000000000n), 9223372036854775808n);
105+
shouldBe(BigInt.asUintN(65, 0x8000000000000000n), 9223372036854775808n);
106+
shouldBe(BigInt.asUintN(66, 0x8000000000000000n), 9223372036854775808n);
107+
108+
shouldBe(BigInt.asUintN(62, 0xffffffffffffffffn), 4611686018427387903n);
109+
shouldBe(BigInt.asUintN(63, 0xffffffffffffffffn), 9223372036854775807n);
110+
shouldBe(BigInt.asUintN(64, 0xffffffffffffffffn), 18446744073709551615n);
111+
shouldBe(BigInt.asUintN(65, 0xffffffffffffffffn), 18446744073709551615n);
112+
shouldBe(BigInt.asUintN(66, 0xffffffffffffffffn), 18446744073709551615n);
113+
114+
shouldBe(BigInt.asUintN(62, -0x800000000000000n), 4035225266123964416n);
115+
shouldBe(BigInt.asUintN(63, -0x800000000000000n), 8646911284551352320n);
116+
shouldBe(BigInt.asUintN(64, -0x800000000000000n), 17870283321406128128n);
117+
shouldBe(BigInt.asUintN(65, -0x800000000000000n), 36317027395115679744n);
118+
shouldBe(BigInt.asUintN(66, -0x800000000000000n), 73210515542534782976n);
119+
120+
shouldBe(BigInt.asUintN(62, -0x800000000000001n), 4035225266123964415n);
121+
shouldBe(BigInt.asUintN(63, -0x800000000000001n), 8646911284551352319n);
122+
shouldBe(BigInt.asUintN(64, -0x800000000000001n), 17870283321406128127n);
123+
shouldBe(BigInt.asUintN(65, -0x800000000000001n), 36317027395115679743n);
124+
shouldBe(BigInt.asUintN(66, -0x800000000000001n), 73210515542534782975n);
125+
126+
shouldBe(BigInt.asUintN(62, -0xffffffffffffffffn), 1n);
127+
shouldBe(BigInt.asUintN(63, -0xffffffffffffffffn), 1n);
128+
shouldBe(BigInt.asUintN(64, -0xffffffffffffffffn), 1n);
129+
shouldBe(BigInt.asUintN(65, -0xffffffffffffffffn), 18446744073709551617n);
130+
shouldBe(BigInt.asUintN(66, -0xffffffffffffffffn), 55340232221128654849n);
131+
shouldBe(BigInt.asUintN(67, -0xffffffffffffffffn), 129127208515966861313n);

‎JSTests/test262/expectations.yaml‎

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -678,66 +678,6 @@ test/built-ins/ArrayIteratorPrototype/next/detach-typedarray-in-progress.js:
678678
test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-promise.js:
679679
default: 'Test262:AsyncTestFailure:Test262Error: Test262Error: AsyncGeneratorResolve(generator, resultValue, true) Expected SameValue(«[object Promise]», «unwrapped-value») to be true'
680680
strict mode: 'Test262:AsyncTestFailure:Test262Error: Test262Error: AsyncGeneratorResolve(generator, resultValue, true) Expected SameValue(«[object Promise]», «unwrapped-value») to be true'
681-
test/built-ins/BigInt/asIntN/arithmetic.js:
682-
default: 'Test262Error: Expected SameValue(«undefined», «0») to be true'
683-
strict mode: 'Test262Error: Expected SameValue(«undefined», «0») to be true'
684-
test/built-ins/BigInt/asIntN/bigint-tobigint-errors.js:
685-
default: 'Test262Error: ToBigInt: no argument => undefined => TypeError Expected a TypeError to be thrown but no exception was thrown at all'
686-
strict mode: 'Test262Error: ToBigInt: no argument => undefined => TypeError Expected a TypeError to be thrown but no exception was thrown at all'
687-
test/built-ins/BigInt/asIntN/bigint-tobigint-toprimitive.js:
688-
default: 'Test262Error: ToPrimitive: @@toPrimitive takes precedence Expected SameValue(«undefined», «1») to be true'
689-
strict mode: 'Test262Error: ToPrimitive: @@toPrimitive takes precedence Expected SameValue(«undefined», «1») to be true'
690-
test/built-ins/BigInt/asIntN/bigint-tobigint-wrapped-values.js:
691-
default: 'Test262Error: ToPrimitive: unbox object with internal slot Expected SameValue(«undefined», «0») to be true'
692-
strict mode: 'Test262Error: ToPrimitive: unbox object with internal slot Expected SameValue(«undefined», «0») to be true'
693-
test/built-ins/BigInt/asIntN/bigint-tobigint.js:
694-
default: 'Test262Error: Expected SameValue(«undefined», «0») to be true'
695-
strict mode: 'Test262Error: Expected SameValue(«undefined», «0») to be true'
696-
test/built-ins/BigInt/asIntN/bits-toindex-errors.js:
697-
default: 'Test262Error: ToIndex: throw when integerIndex < 0 Expected a RangeError to be thrown but no exception was thrown at all'
698-
strict mode: 'Test262Error: ToIndex: throw when integerIndex < 0 Expected a RangeError to be thrown but no exception was thrown at all'
699-
test/built-ins/BigInt/asIntN/bits-toindex-toprimitive.js:
700-
default: 'Test262Error: ToPrimitive: @@toPrimitive takes precedence Expected SameValue(«undefined», «-1») to be true'
701-
strict mode: 'Test262Error: ToPrimitive: @@toPrimitive takes precedence Expected SameValue(«undefined», «-1») to be true'
702-
test/built-ins/BigInt/asIntN/bits-toindex-wrapped-values.js:
703-
default: 'Test262Error: ToPrimitive: unbox object with internal slot Expected SameValue(«undefined», «0») to be true'
704-
strict mode: 'Test262Error: ToPrimitive: unbox object with internal slot Expected SameValue(«undefined», «0») to be true'
705-
test/built-ins/BigInt/asIntN/bits-toindex.js:
706-
default: 'Test262Error: Expected SameValue(«undefined», «0») to be true'
707-
strict mode: 'Test262Error: Expected SameValue(«undefined», «0») to be true'
708-
test/built-ins/BigInt/asIntN/order-of-steps.js:
709-
default: 'Test262Error: Expected SameValue(«0», «2») to be true'
710-
strict mode: 'Test262Error: Expected SameValue(«0», «2») to be true'
711-
test/built-ins/BigInt/asUintN/arithmetic.js:
712-
default: 'Test262Error: Expected SameValue(«undefined», «0») to be true'
713-
strict mode: 'Test262Error: Expected SameValue(«undefined», «0») to be true'
714-
test/built-ins/BigInt/asUintN/bigint-tobigint-errors.js:
715-
default: 'Test262Error: ToBigInt: no argument => undefined => TypeError Expected a TypeError to be thrown but no exception was thrown at all'
716-
strict mode: 'Test262Error: ToBigInt: no argument => undefined => TypeError Expected a TypeError to be thrown but no exception was thrown at all'
717-
test/built-ins/BigInt/asUintN/bigint-tobigint-toprimitive.js:
718-
default: 'Test262Error: ToPrimitive: @@toPrimitive takes precedence Expected SameValue(«undefined», «1») to be true'
719-
strict mode: 'Test262Error: ToPrimitive: @@toPrimitive takes precedence Expected SameValue(«undefined», «1») to be true'
720-
test/built-ins/BigInt/asUintN/bigint-tobigint-wrapped-values.js:
721-
default: 'Test262Error: ToPrimitive: unbox object with internal slot Expected SameValue(«undefined», «0») to be true'
722-
strict mode: 'Test262Error: ToPrimitive: unbox object with internal slot Expected SameValue(«undefined», «0») to be true'
723-
test/built-ins/BigInt/asUintN/bigint-tobigint.js:
724-
default: 'Test262Error: Expected SameValue(«undefined», «0») to be true'
725-
strict mode: 'Test262Error: Expected SameValue(«undefined», «0») to be true'
726-
test/built-ins/BigInt/asUintN/bits-toindex-errors.js:
727-
default: 'Test262Error: ToIndex: throw when integerIndex < 0 Expected a RangeError to be thrown but no exception was thrown at all'
728-
strict mode: 'Test262Error: ToIndex: throw when integerIndex < 0 Expected a RangeError to be thrown but no exception was thrown at all'
729-
test/built-ins/BigInt/asUintN/bits-toindex-toprimitive.js:
730-
default: 'Test262Error: ToPrimitive: @@toPrimitive takes precedence Expected SameValue(«undefined», «1») to be true'
731-
strict mode: 'Test262Error: ToPrimitive: @@toPrimitive takes precedence Expected SameValue(«undefined», «1») to be true'
732-
test/built-ins/BigInt/asUintN/bits-toindex-wrapped-values.js:
733-
default: 'Test262Error: ToPrimitive: unbox object with internal slot Expected SameValue(«undefined», «0») to be true'
734-
strict mode: 'Test262Error: ToPrimitive: unbox object with internal slot Expected SameValue(«undefined», «0») to be true'
735-
test/built-ins/BigInt/asUintN/bits-toindex.js:
736-
default: 'Test262Error: Expected SameValue(«undefined», «0») to be true'
737-
strict mode: 'Test262Error: Expected SameValue(«undefined», «0») to be true'
738-
test/built-ins/BigInt/asUintN/order-of-steps.js:
739-
default: 'Test262Error: Expected SameValue(«0», «2») to be true'
740-
strict mode: 'Test262Error: Expected SameValue(«0», «2») to be true'
741681
test/built-ins/DataView/custom-proto-access-detaches-buffer.js:
742682
default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
743683
strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'

‎Source/JavaScriptCore/ChangeLog‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
2020-05-05 Yusuke Suzuki <ysuzuki@apple.com>
2+
3+
[JSC] Implement BigInt.asIntN and BigInt.asUintN
4+
https://bugs.webkit.org/show_bug.cgi?id=181144
5+
6+
Reviewed by Darin Adler.
7+
8+
This patch implements BigInt.asIntN[1] and BigInt.asUintN[2] features.
9+
As the same to the other BigInt runtime C++ code, we port V8 code to JSC to implement both.
10+
11+
BigInt.asIntN is `static_cast<intN_t>(BigInt value)` and BigInt.asUintN is `static_cast<uintN_t>(BigInt value)`.
12+
They are getting slice of N bits from two's complement representation of the given BigInt. The difference between
13+
asIntN and asUintN is asIntN renders MSB as a sign.
14+
15+
This patch is once rolled out due to ARM64_32 build failure, which is caused by the existing bug[3]. Relanding it
16+
since it is now fixed.
17+
18+
[1]: https://tc39.es/ecma262/#sec-bigint.asintn
19+
[2]: https://tc39.es/ecma262/#sec-bigint.asuintn
20+
[3]: https://trac.webkit.org/changeset/261174/webkit
21+
22+
* runtime/BigIntConstructor.cpp:
23+
(JSC::toBigInt):
24+
(JSC::bigIntConstructorFuncAsUintN):
25+
(JSC::bigIntConstructorFuncAsIntN):
26+
* runtime/JSBigInt.cpp:
27+
(JSC::zeroImpl):
28+
(JSC::JSBigInt::divideImpl):
29+
(JSC::JSBigInt::unaryMinusImpl):
30+
(JSC::JSBigInt::remainderImpl):
31+
(JSC::JSBigInt::digitDiv):
32+
(JSC::JSBigInt::absoluteSub):
33+
(JSC::JSBigInt::asIntNImpl):
34+
(JSC::JSBigInt::asUintNImpl):
35+
(JSC::JSBigInt::truncateToNBits):
36+
(JSC::JSBigInt::truncateAndSubFromPowerOfTwo):
37+
(JSC::JSBigInt::asIntN):
38+
(JSC::JSBigInt::asUintN):
39+
* runtime/JSBigInt.h:
40+
141
2020-05-05 Ross Kirsling <ross.kirsling@sony.com>
242

343
[Intl] Alphabetize extension keys and correctly mark const methods

0 commit comments

Comments
 (0)