assert: fix deepEqual regression
Change of Object.keys in ES6 breaks assert.deepEqual about primitive values. V8: https://code.google.com/p/v8/issues/detail?id=3443 Previously deepEqual depends on Object.key that throws an error for a primitive value, but now Object.key does not throw. PR-URL: https://github.com/iojs/io.js/pull/193 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
ef10827c9f
commit
00a7456c19
@ -201,8 +201,9 @@ function objEquiv(a, b) {
|
|||||||
return false;
|
return false;
|
||||||
// an identical 'prototype' property.
|
// an identical 'prototype' property.
|
||||||
if (a.prototype !== b.prototype) return false;
|
if (a.prototype !== b.prototype) return false;
|
||||||
//~~~I've managed to break Object.keys through screwy arguments passing.
|
// if one is a primitive, the other must be same
|
||||||
// Converting to array solves the problem.
|
if (util.isPrimitive(a) || util.isPrimitive(b))
|
||||||
|
return a === b;
|
||||||
var aIsArgs = isArguments(a),
|
var aIsArgs = isArguments(a),
|
||||||
bIsArgs = isArguments(b);
|
bIsArgs = isArguments(b);
|
||||||
if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
|
if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
|
||||||
@ -212,13 +213,9 @@ function objEquiv(a, b) {
|
|||||||
b = pSlice.call(b);
|
b = pSlice.call(b);
|
||||||
return _deepEqual(a, b);
|
return _deepEqual(a, b);
|
||||||
}
|
}
|
||||||
try {
|
var ka = Object.keys(a),
|
||||||
var ka = Object.keys(a),
|
kb = Object.keys(b),
|
||||||
kb = Object.keys(b),
|
key, i;
|
||||||
key, i;
|
|
||||||
} catch (e) {//happens when one is a string literal and the other isn't
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// having the same number of owned properties (keys incorporates
|
// having the same number of owned properties (keys incorporates
|
||||||
// hasOwnProperty)
|
// hasOwnProperty)
|
||||||
if (ka.length != kb.length)
|
if (ka.length != kb.length)
|
||||||
|
@ -153,8 +153,22 @@ nameBuilder2.prototype = Object;
|
|||||||
nb2 = new nameBuilder2('Ryan', 'Dahl');
|
nb2 = new nameBuilder2('Ryan', 'Dahl');
|
||||||
assert.throws(makeBlock(a.deepEqual, nb1, nb2), a.AssertionError);
|
assert.throws(makeBlock(a.deepEqual, nb1, nb2), a.AssertionError);
|
||||||
|
|
||||||
// String literal + object blew up my implementation...
|
// primitives and object
|
||||||
assert.throws(makeBlock(a.deepEqual, 'a', {}), a.AssertionError);
|
assert.throws(makeBlock(a.deepEqual, null, {}), a.AssertionError);
|
||||||
|
assert.throws(makeBlock(a.deepEqual, undefined, {}), a.AssertionError);
|
||||||
|
assert.throws(makeBlock(a.deepEqual, 'a', ['a']), a.AssertionError);
|
||||||
|
assert.throws(makeBlock(a.deepEqual, 'a', {0: 'a'}), a.AssertionError);
|
||||||
|
assert.throws(makeBlock(a.deepEqual, 1, {}), a.AssertionError);
|
||||||
|
assert.throws(makeBlock(a.deepEqual, true, {}), a.AssertionError);
|
||||||
|
if (typeof Symbol === 'symbol') {
|
||||||
|
assert.throws(makeBlock(assert.deepEqual, Symbol(), {}), a.AssertionError);
|
||||||
|
}
|
||||||
|
|
||||||
|
// primitive wrappers and object
|
||||||
|
assert.doesNotThrow(makeBlock(a.deepEqual, new String('a'), ['a']), a.AssertionError);
|
||||||
|
assert.doesNotThrow(makeBlock(a.deepEqual, new String('a'), {0: 'a'}), a.AssertionError);
|
||||||
|
assert.doesNotThrow(makeBlock(a.deepEqual, new Number(1), {}), a.AssertionError);
|
||||||
|
assert.doesNotThrow(makeBlock(a.deepEqual, new Boolean(true), {}), a.AssertionError);
|
||||||
|
|
||||||
// Testing the throwing
|
// Testing the throwing
|
||||||
function thrower(errorConstructor) {
|
function thrower(errorConstructor) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user