Browse Source

ensure that deepEqual does not depend on arguments order

from aae51ecf7d
deapstrictequal
teppeis 10 years ago
parent
commit
ae6abd7a9e
  1. 9
      assert.js
  2. 5
      test.js

9
assert.js

@ -227,10 +227,11 @@ function objEquiv(a, b) {
if (a.prototype !== b.prototype) return false;
//~~~I've managed to break Object.keys through screwy arguments passing.
// Converting to array solves the problem.
if (isArguments(a)) {
if (!isArguments(b)) {
return false;
}
var aIsArgs = isArguments(a),
bIsArgs = isArguments(b);
if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
return false;
if (aIsArgs) {
a = pSlice.call(a);
b = pSlice.call(b);
return _deepEqual(a, b);

5
test.js

@ -264,6 +264,11 @@ test('assert - Make sure deepEqual doesn\'t loop forever on circular refs', func
assert.ok(gotError);
});
test('assert - Ensure reflexivity of deepEqual with `arguments` objects', function() {
var args = (function() { return arguments; })();
assert.throws(makeBlock(assert.deepEqual, [], args), assert.AssertionError);
assert.throws(makeBlock(assert.deepEqual, args, []), assert.AssertionError);
});
test('assert - test assertion message', function () {
function testAssertionMessage(actual, expected) {

Loading…
Cancel
Save