Skip to content

Commit

Permalink
test the arguments shim and properly factor out the arguments handling
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Dec 21, 2013
1 parent abd3358 commit cf88b9c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
20 changes: 1 addition & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var Object_keys = typeof Object.keys === 'function'
return keys;
}
;
var isArguments = require('./lib/is_arguments.js');

var deepEqual = module.exports = function (actual, expected, opts) {
if (!opts) opts = {};
Expand Down Expand Up @@ -37,25 +38,6 @@ function isUndefinedOrNull(value) {
return value === null || value === undefined;
}

var supportsArgumentsClass = (function(){
return Object.prototype.toString.call(arguments)
}) == '[object Arguments]';

if(supportsArgumentsClass) {
var isArguments = function(object) {
return Object.prototype.toString.call(object) == '[object Arguments]';
}
} else {
var isArguments = function(object){
return object &&
typeof object == 'object' &&
typeof object.length == 'number' &&
Object.prototype.hasOwnProperty.call(object, 'callee') &&
!Object.prototype.propertyIsEnumerable.call(object, 'callee') ||
false;
}
}

function objEquiv(a, b, opts) {
if (!opts) opts = {};
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
Expand Down
20 changes: 20 additions & 0 deletions lib/is_arguments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var supportsArgumentsClass = (function(){
return Object.prototype.toString.call(arguments)
})() == '[object Arguments]';

exports = module.exports = supportsArgumentsClass ? supported : unsupported;

exports.supported = supported;
function supported(object) {
return Object.prototype.toString.call(object) == '[object Arguments]';
};

exports.unsupported = unsupported;
function unsupported(object){
return object &&
typeof object == 'object' &&
typeof object.length == 'number' &&
Object.prototype.hasOwnProperty.call(object, 'callee') &&
!Object.prototype.propertyIsEnumerable.call(object, 'callee') ||
false;
};
11 changes: 11 additions & 0 deletions test/cmp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var test = require('tape');
var equal = require('../');
var isArguments = require('../lib/is_arguments.js');

test('equal', function (t) {
t.ok(equal(
Expand Down Expand Up @@ -54,6 +55,16 @@ test('arguments class', function (t) {
t.end();
});

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]));

t.end();
});

test('dates', function (t) {
var d0 = new Date(1387585278000);
var d1 = new Date('Fri Dec 20 2013 16:21:18 GMT-0800 (PST)');
Expand Down

0 comments on commit cf88b9c

Please sign in to comment.