Merge pull request #1514 from cxielarko/remove-issafeinteger

remove IsSafeInteger checks for BigInt
This commit is contained in:
Rick Waldron 2018-04-18 15:35:38 -04:00 committed by GitHub
commit 1155332c93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 62 deletions

View File

@ -0,0 +1,31 @@
// Copyright (C) 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt constructor called with integer argument
esid: sec-bigint-constructor
info: |
BigInt ( value )
...
3. If Type(prim) is Number, return ? NumberToBigInt(prim).
NumberToBigInt ( number )
...
3. Return a BigInt representing the mathematical value of number.
features: [BigInt]
---*/
assert.sameValue(BigInt(Number.MAX_SAFE_INTEGER), 9007199254740991n);
assert.sameValue(BigInt(-Number.MAX_SAFE_INTEGER), -9007199254740991n);
var pos = Math.pow(2, 53);
var neg = -pos;
assert.sameValue(BigInt(pos), 9007199254740992n,
"BigInt(2**53) === 9007199254740992n");
assert.sameValue(BigInt(neg), -9007199254740992n,
"BigInt(2**53) === -9007199254740992n");

View File

@ -1,20 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Throws a TypeError if BigInt is called with a new target
esid: sec-bigint-constructor
info: |
...
3. If Type(prim) is Number, return ? NumberToBigInt(prim).
...
NumberToBigInt ( number )
2. If IsSafeInteger(number) is false, throw a RangeError exception.
features: [BigInt]
---*/
assert.sameValue(BigInt(Number.MAX_SAFE_INTEGER), 9007199254740991n);
assert.sameValue(BigInt(-Number.MAX_SAFE_INTEGER), -9007199254740991n);

View File

@ -1,40 +0,0 @@
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt throws a RangeError if value is not a safe integer.
esid: sec-bigint-constructor
info: |
BigInt ( value )
...
2. Let prim be ? ToPrimitive(value, hint Number).
3. If Type(prim) is Number, return ? NumberToBigInt(prim).
...
NumberToBigInt ( number )
...
2. If IsSafeInteger(number) is false, throw a RangeError exception.
...
IsSafeInteger ( number )
...
3. Let integer be ToInteger(number).
4. If integer is not equal to number, return false.
5. If abs(integer) 2**53-1, return true.
6. Otherwise, return false.
features: [BigInt]
---*/
var pos = Math.pow(2, 53);
var neg = -pos;
assert.throws(RangeError, function() {
BigInt(pos);
});
assert.throws(RangeError, function() {
BigInt(neg);
});

View File

@ -1,4 +1,4 @@
// Copyright (C) 2017 Igalia, S.L. All rights reserved.
// Copyright (C) 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
@ -20,7 +20,7 @@ values.forEach(function(value, i) {
() => sample.setBigInt64(0, BigInt(value), false),
"value: " + value);
return;
} else if (!Number.isInteger(value) || value > 9007199254740991) {
} else if (!Number.isInteger(value)) {
assert.throws(RangeError,
() => sample.setBigInt64(0, BigInt(value), false),
"value " + value);