Skip to content

Commit 45431b6

Browse files
committed
[Breaking] two objects with different Symbol.toStringTags are not equal
1 parent 5f2f2e5 commit 45431b6

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var isDate = require('is-date-object');
88

99
var getTime = Date.prototype.getTime;
1010
var gPO = Object.getPrototypeOf;
11+
var objToString = Object.prototype.toString;
1112

1213
function deepEqual(actual, expected, options) {
1314
var opts = options || {};
@@ -60,6 +61,8 @@ function objEquiv(a, b, opts) {
6061
// an identical 'prototype' property.
6162
if (a.prototype !== b.prototype) { return false; }
6263

64+
if (objToString.call(a) !== objToString.call(b)) { return false; }
65+
6366
if (isArguments(a) !== isArguments(b)) { return false; }
6467

6568
var aIsArray = isArray(a);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"devDependencies": {
2727
"@ljharb/eslint-config": "^13.1.1",
2828
"eslint": "^5.16.0",
29+
"has-symbols": "^1.0.0",
2930
"object.assign": "^4.1.0",
3031
"tape": "^4.11.0"
3132
},

test/cmp.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var test = require('tape');
22
require('./_tape');
33
var assign = require('object.assign');
4+
var hasSymbols = require('has-symbols')();
45

56
var equal = require('../');
67

@@ -401,3 +402,20 @@ test('[[Prototypes]]', { skip: !Object.getPrototypeOf }, function (t) {
401402

402403
t.end();
403404
});
405+
406+
test('toStringTag', { skip: !hasSymbols || !Symbol.toStringTag }, function (t) {
407+
var o1 = {};
408+
t.equal(Object.prototype.toString.call(o1), '[object Object]', 'o1: Symbol.toStringTag works');
409+
410+
var o2 = {};
411+
t.equal(Object.prototype.toString.call(o2), '[object Object]', 'o2: original Symbol.toStringTag works');
412+
413+
t.deepEqualTest(o1, o2, 'two normal empty objects', true, true);
414+
415+
o2[Symbol.toStringTag] = 'jifasnif';
416+
t.equal(Object.prototype.toString.call(o2), '[object jifasnif]', 'o2: modified Symbol.toStringTag works');
417+
418+
t.deepEqualTest(o1, o2, 'two normal empty objects with different toStringTags', false, false);
419+
420+
t.end();
421+
});

0 commit comments

Comments
 (0)