Skip to content

Commit e207bc3

Browse files
committed
[Breaking] boxed primitives are not silently unboxed
1 parent 43b1eef commit e207bc3

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

index.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ var isRegex = require('is-regex');
55
var flags = require('regexp.prototype.flags');
66
var isArray = require('isarray');
77
var isDate = require('is-date-object');
8-
var isBoxedPrimitive = require('is-boxed-primitive');
9-
var unboxPrimitive = require('unbox-primitive');
8+
var whichBoxedPrimitive = require('which-boxed-primitive');
109
var callBound = require('es-abstract/helpers/callBound');
1110

1211
var $getTime = callBound('Date.prototype.getTime');
@@ -21,14 +20,10 @@ function deepEqual(actual, expected, options) {
2120
return true;
2221
}
2322

24-
var actualBoxed = isBoxedPrimitive(actual);
25-
var expectedBoxed = isBoxedPrimitive(expected);
26-
if (actualBoxed || expectedBoxed) {
27-
return deepEqual(
28-
actualBoxed ? unboxPrimitive(actual) : actual,
29-
expectedBoxed ? unboxPrimitive(expected) : expected,
30-
opts
31-
);
23+
var actualBoxed = whichBoxedPrimitive(actual);
24+
var expectedBoxed = whichBoxedPrimitive(expected);
25+
if (actualBoxed !== expectedBoxed) {
26+
return false;
3227
}
3328

3429
// 7.3. Other pairs that do not both pass typeof value == 'object', equivalence is determined by ==.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
"dependencies": {
2222
"es-abstract": "^1.16.2",
2323
"is-arguments": "^1.0.4",
24-
"is-boxed-primitive": "^1.0.0",
2524
"is-date-object": "^1.0.1",
2625
"is-regex": "^1.0.4",
2726
"isarray": "^2.0.5",
2827
"object-is": "^1.0.1",
2928
"object-keys": "^1.1.1",
3029
"regexp.prototype.flags": "^1.2.0",
31-
"unbox-primitive": "^1.0.0"
30+
"which-boxed-primitive": "^1.0.1"
3231
},
3332
"devDependencies": {
3433
"@ljharb/eslint-config": "^15.0.2",

test/cmp.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,32 +461,32 @@ test('toStringTag', { skip: !hasSymbols || !Symbol.toStringTag }, function (t) {
461461
});
462462

463463
test('boxed primitives', function (t) {
464-
t.deepEqualTest(Object(false), false, 'boxed and primitive `false`', true, true);
465-
t.deepEqualTest(Object(true), true, 'boxed and primitive `true`', true, true);
466-
t.deepEqualTest(Object(3), 3, 'boxed and primitive `3`', true, true);
467-
t.deepEqualTest(Object(NaN), NaN, 'boxed and primitive `NaN`', false, true);
468-
t.deepEqualTest(Object(''), '', 'boxed and primitive `""`', true, true);
469-
t.deepEqualTest(Object('str'), 'str', 'boxed and primitive `"str"`', true, true);
464+
t.deepEqualTest(Object(false), false, 'boxed and primitive `false`', false, false);
465+
t.deepEqualTest(Object(true), true, 'boxed and primitive `true`', false, false);
466+
t.deepEqualTest(Object(3), 3, 'boxed and primitive `3`', false, false);
467+
t.deepEqualTest(Object(NaN), NaN, 'boxed and primitive `NaN`', false, false);
468+
t.deepEqualTest(Object(''), '', 'boxed and primitive `""`', false, false);
469+
t.deepEqualTest(Object('str'), 'str', 'boxed and primitive `"str"`', false, false);
470470

471471
t.test('symbol', { skip: !hasSymbols }, function (st) {
472472
var s = Symbol('');
473-
st.deepEqualTest(Object(s), s, 'boxed and primitive `Symbol()`', true, true);
473+
st.deepEqualTest(Object(s), s, 'boxed and primitive `Symbol()`', false, false);
474474
st.end();
475475
});
476476

477477
t.test('bigint', { skip: typeof BigInt !== 'function' }, function (st) {
478478
var hhgtg = BigInt(42);
479-
st.deepEqualTest(Object(hhgtg), hhgtg, 'boxed and primitive `BigInt(42)`', true, true);
479+
st.deepEqualTest(Object(hhgtg), hhgtg, 'boxed and primitive `BigInt(42)`', false, false);
480480
st.end();
481481
});
482482

483-
t.test('`valueOf` is not called for boxed primitives', function (st) {
483+
t.test('`valueOf` is called for boxed primitives', function (st) {
484484
var a = Object(5);
485485
a.valueOf = function () { throw new Error('failed'); };
486486
var b = Object(5);
487487
b.valueOf = function () { throw new Error('failed'); };
488488

489-
st.deepEqualTest(a, b, 'two boxed numbers with a thrower valueOf', true, true);
489+
st.deepEqualTest(a, b, 'two boxed numbers with a thrower valueOf', false, false);
490490

491491
st.end();
492492
});

0 commit comments

Comments
 (0)