Skip to content

Commit

Permalink
[Breaking] two objects with different Symbol.toStringTags are not e…
Browse files Browse the repository at this point in the history
…qual
  • Loading branch information
ljharb committed Aug 6, 2019
1 parent 77c430f commit b0e2c2c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var isDate = require('is-date-object');

var getTime = Date.prototype.getTime;
var gPO = Object.getPrototypeOf;
var objToString = Object.prototype.toString;

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

if (objToString.call(a) !== objToString.call(b)) { return false; }

if (isArguments(a) !== isArguments(b)) { return false; }

var aIsArray = isArray(a);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"devDependencies": {
"@ljharb/eslint-config": "^13.1.1",
"eslint": "^5.16.0",
"has-symbols": "^1.0.0",
"tape": "^4.11.0"
},
"repository": {
Expand Down
18 changes: 18 additions & 0 deletions test/cmp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var test = require('tape');
require('./_tape');
var hasSymbols = require('has-symbols')();

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

Expand Down Expand Up @@ -374,3 +375,20 @@ test('[[Prototypes]]', { skip: !Object.getPrototypeOf }, function (t) {

t.end();
});

test('toStringTag', { skip: !hasSymbols || !Symbol.toStringTag }, function (t) {
var o1 = {};
t.equal(Object.prototype.toString.call(o1), '[object Object]', 'o1: Symbol.toStringTag works');

var o2 = {};
t.equal(Object.prototype.toString.call(o2), '[object Object]', 'o2: original Symbol.toStringTag works');

t.deepEqualTest(o1, o2, 'two normal empty objects', true, true);

o2[Symbol.toStringTag] = 'jifasnif';
t.equal(Object.prototype.toString.call(o2), '[object jifasnif]', 'o2: modified Symbol.toStringTag works');

t.deepEqualTest(o1, o2, 'two normal empty objects with different toStringTags', false, false);

t.end();
});

0 comments on commit b0e2c2c

Please sign in to comment.