Implement BigInt asIntN and asUintN methods (#5165)
The following methods were implemented: - BigInt.asIntN - BigInt.asUintN Custom dispatcher also added to builtin_bigint. The implementation is based on PR #4736, only applied the requested changes. Co-authored-by: Daniel Batiz batizjob@gmail.com JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi gergocs@inf.u-szeged.hu
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
// Copyright JS Foundation and other contributors, http://js.foundation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
assert(BigInt.asIntN('1', 1n) === -1n)
|
||||
assert(BigInt.asIntN(1.1, 1n) === -1n)
|
||||
assert(BigInt.asIntN(2, 2n**2n) === 0n)
|
||||
assert(BigInt.asIntN(undefined, 1n) === 0n)
|
||||
|
||||
var array = [1, 1n, -1n]
|
||||
|
||||
assert(BigInt.asIntN(array[0], 1n) == -1n)
|
||||
assert(BigInt.asIntN(array[0], array[1]) == -1n)
|
||||
assert(BigInt.asIntN(array[0], array[2]) == -1n)
|
||||
|
||||
function f(param1, param2) {
|
||||
assert(BigInt.asIntN(param1, param2) === 0n)
|
||||
}
|
||||
f(0,10n)
|
||||
f(10,0n)
|
||||
|
||||
try {
|
||||
assert(f(1, "1n") === 1n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof SyntaxError)
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asIntN(Number.POSITIVE_INFINITY, 1n) === 1n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof RangeError)
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asIntN(Number.NEGATIVE_INFINITY, 1n) === 1n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof RangeError)
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asIntN(1, Number.POSITIVE_INFINITY) === 1n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError)
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asIntN(1, Number.NEGATIVE_INFINITY) === 1n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError)
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asIntN(1, 1 + 1n) === 1n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError)
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asIntN(2n, 2n**2n) === 0n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError)
|
||||
}
|
||||
|
||||
try {
|
||||
BigInt.asIntN().call(undefined,1n)
|
||||
assert (false);
|
||||
} catch(e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
BigInt.asIntN().call(1,undefined)
|
||||
assert (false);
|
||||
} catch(e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
BigInt.asIntN().call(undefined,undefined)
|
||||
assert (false);
|
||||
} catch(e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asIntN(Infinity, 2n) === RangeError)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof RangeError)
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
// Copyright JS Foundation and other contributors, http://js.foundation
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
assert(BigInt.asUintN('1', 1n) === 1n)
|
||||
assert(BigInt.asUintN(1.1, 1n) === 1n)
|
||||
assert(BigInt.asUintN(2, 2n**2n) === 0n)
|
||||
assert(BigInt.asUintN(undefined, 1n) === 0n)
|
||||
|
||||
var array = [1, 1n, -1n]
|
||||
|
||||
assert(BigInt.asUintN(array[0], 1n) == 1n)
|
||||
assert(BigInt.asUintN(array[0], array[1]) == 1n)
|
||||
assert(BigInt.asUintN(array[0], array[2]) == 1n)
|
||||
|
||||
function f(param1, param2) {
|
||||
assert(BigInt.asUintN(param1, param2) === 0n)
|
||||
}
|
||||
f(0,10n)
|
||||
f(10,0n)
|
||||
|
||||
try {
|
||||
assert(f(1, "1n") === 1n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof SyntaxError)
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asUintN(Number.POSITIVE_INFINITY, 1n) === 1n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof RangeError)
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asUintN(Number.NEGATIVE_INFINITY, 1n) === 1n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof RangeError)
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asUintN(1, Number.POSITIVE_INFINITY) === 1n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError)
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asUintN(1, Number.NEGATIVE_INFINITY) === 1n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError)
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asUintN(1, 1 + 1n) === 1n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError)
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asUintN(2n, 2n**2n) === 0n)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof TypeError)
|
||||
}
|
||||
|
||||
try {
|
||||
BigInt.asUintN().call(undefined,1n)
|
||||
assert (false);
|
||||
} catch(e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
BigInt.asUintN().call(1,undefined)
|
||||
assert (false);
|
||||
} catch(e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
BigInt.asUintN().call(undefined,undefined)
|
||||
assert (false);
|
||||
} catch(e) {
|
||||
assert(e instanceof TypeError);
|
||||
}
|
||||
|
||||
try {
|
||||
assert(BigInt.asUintN(Infinity, 2n) === RangeError)
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof RangeError)
|
||||
}
|
||||
@@ -4,6 +4,8 @@ tests/jerry/bigint6.js
|
||||
tests/jerry/bigint7.js
|
||||
tests/jerry/bigint8.js
|
||||
tests/jerry/bigint9.js
|
||||
tests/jerry/es.next/bigint-as-int-n.js
|
||||
tests/jerry/es.next/bigint-as-uint-n.js
|
||||
tests/jerry/logical-assignment.js
|
||||
tests/jerry/module-circular-01.mjs
|
||||
tests/jerry/module-circular-02.mjs
|
||||
|
||||
@@ -2,32 +2,6 @@
|
||||
<excludeList>
|
||||
<!-- Uncategorized failing tests -->
|
||||
<test id="built-ins/Array/prototype/splice/property-traps-order-with-species.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/arithmetic.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/asIntN.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/bigint-tobigint-errors.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/bigint-tobigint-toprimitive.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/bigint-tobigint-wrapped-values.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/bigint-tobigint.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/bits-toindex-errors.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/bits-toindex-toprimitive.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/bits-toindex-wrapped-values.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/bits-toindex.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/length.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/name.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asIntN/order-of-steps.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/arithmetic.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/asUintN.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/bigint-tobigint-errors.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/bigint-tobigint-toprimitive.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/bigint-tobigint-wrapped-values.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/bigint-tobigint.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/bits-toindex-errors.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/bits-toindex-toprimitive.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/bits-toindex-wrapped-values.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/bits-toindex.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/length.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/name.js"><reason></reason></test>
|
||||
<test id="built-ins/BigInt/asUintN/order-of-steps.js"><reason></reason></test>
|
||||
<test id="built-ins/Function/prototype/toString/class-declaration-explicit-ctor.js"><reason></reason></test>
|
||||
<test id="built-ins/Function/prototype/toString/class-expression-explicit-ctor.js"><reason></reason></test>
|
||||
<test id="built-ins/Function/prototype/toString/well-known-intrinsic-object-functions.js"><reason></reason></test>
|
||||
|
||||
Reference in New Issue
Block a user