diff --git a/index.js b/index.js index 0772f8c..3f7948d 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,16 @@ var deepEqual = module.exports = function (actual, expected, opts) { } else if (actual instanceof Date && expected instanceof Date) { return actual.getTime() === expected.getTime(); + // 7.3 If the expected value is a RegExp object, the actual value is + // equivalent if it is also a RegExp object with the same source and + // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). + } else if (actual instanceof RegExp && expected instanceof RegExp) { + return actual.source === expected.source && + actual.global === expected.global && + actual.multiline === expected.multiline && + actual.lastIndex === expected.lastIndex && + actual.ignoreCase === expected.ignoreCase; + // 7.3. Other pairs that do not both pass typeof value == 'object', // equivalence is determined by ==. } else if (!actual || !expected || typeof actual != 'object' && typeof expected != 'object') { @@ -42,10 +52,21 @@ function isBuffer (x) { function objEquiv(a, b, opts) { var i, key; + if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) return false; + + var abc = 5; + try { + Object.getPrototypeOf(abc); // all ok ES6 + } catch (e) { // error ES5 + Object.getPrototypeOf = function(obj) { + return obj.__proto__; + } + } + // an identical 'prototype' property. - if (a.prototype !== b.prototype) return false; + if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false; //~~~I've managed to break Object.keys through screwy arguments passing. // Converting to array solves the problem. if (isArguments(a)) { diff --git a/test/cmp.js b/test/cmp.js index 2aab5f9..1cb6b9a 100644 --- a/test/cmp.js +++ b/test/cmp.js @@ -59,7 +59,7 @@ test('arguments class', function (t) { test('test the arguments shim', function (t) { t.ok(isArguments.supported((function(){return arguments})())); t.notOk(isArguments.supported([1,2,3])); - + t.ok(isArguments.unsupported((function(){return arguments})())); t.notOk(isArguments.unsupported([1,2,3])); @@ -93,3 +93,20 @@ test('null == undefined', function (t) { t.notOk(equal(null, undefined, { strict: true })) t.end() }) + +test('test objects', function (t) { + var d = new Date(1387585278000); + var e = new RegExp("abc"); + t.notOk(equal(d, e)); + t.end(); +}); + +test('test RegExp !=', function (t) { + t.notOk(equal(/abc/, /xyz/)); + t.end(); +}); + +test('test RegExp ==', function (t) { + t.ok(equal(/abc/, /abc/)); + t.end(); +});