Skip to content

Commit

Permalink
[Fix] ES2020+: SameValueNonNumeric: properly throw on BigInt values
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Sep 1, 2022
1 parent b121e4c commit 73ba74c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 2020/SameValueNonNumeric.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var Type = require('./Type');

module.exports = function SameValueNonNumeric(x, y) {
var xType = Type(x);
if (xType === 'Number' || xType === 'Bigint') {
if (xType === 'Number' || xType === 'BigInt') {
throw new $TypeError('Assertion failed: SameValueNonNumeric does not accept Number or BigInt values');
}
if (xType !== Type(y)) {
Expand Down
2 changes: 1 addition & 1 deletion 2021/SameValueNonNumeric.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 2022/SameValueNonNumeric.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"devDependencies": {
"@ljharb/eslint-config": "^21.0.0",
"array.prototype.filter": "^1.0.1",
"array.prototype.flatmap": "^1.3.0",
"array.prototype.indexof": "^1.0.4",
"aud": "^2.0.0",
"available-regexp-flags": "^1.0.0",
Expand Down
15 changes: 13 additions & 2 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var forEach = require('for-each');
var debug = require('object-inspect');
var assign = require('object.assign');
var keys = require('object-keys');
var flatMap = require('array.prototype.flatmap');
var has = require('has');
var arrowFns = require('make-arrow-function').list();
var hasStrictMode = require('has-strict-mode')();
Expand Down Expand Up @@ -7444,9 +7445,19 @@ var es2020 = function ES2020(ES, ops, expectedMissing, skips) {
[4, ''],
['abc', true],
[{}, false]
];
].concat(flatMap(v.bigints, function (bigint) {
return [
[bigint, bigint],
[bigint, {}],
[{}, bigint],
[3, bigint],
[bigint, 3],
['', bigint],
[bigint, '']
];
}));
forEach(willThrow, function (nums) {
t['throws'](function () { return ES.SameValueNonNumeric.apply(ES, nums); }, TypeError, 'value must be same type and non-number');
t['throws'](function () { return ES.SameValueNonNumeric.apply(ES, nums); }, TypeError, 'value must be same type and non-number/bigint: got ' + debug(nums[0]) + ' and ' + debug(nums[1]));
});

forEach(v.objects.concat(v.nonNumberPrimitives), function (val) {
Expand Down

0 comments on commit 73ba74c

Please sign in to comment.