Skip to content

Commit 4d12e23

Browse files
linkeoljharb
authored andcommitted
[Fix] Fix errors about in operator.
The in operator can only be used to check if a property is in an object. You can't search in strings, or in numbers, or other primitive types. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/in_operator_no_object#What_went_wrong
1 parent 1c7ccba commit 4d12e23

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag =
44
var toStr = Object.prototype.toString;
55

66
var isStandardArguments = function isArguments(value) {
7-
if (hasToStringTag && value && Symbol.toStringTag in value) {
7+
if (hasToStringTag && value && typeof value === 'object' && Symbol.toStringTag in value) {
88
return false;
99
}
1010
return toStr.call(value) === '[object Arguments]';

test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag =
77
test('primitives', function (t) {
88
t.notOk(isArguments([]), 'array is not arguments');
99
t.notOk(isArguments({}), 'object is not arguments');
10-
t.notOk(isArguments(''), 'string is not arguments');
10+
t.notOk(isArguments(''), 'empty string is not arguments');
11+
t.notOk(isArguments('foo'), 'string is not arguments');
1112
t.notOk(isArguments({ length: 2 }), 'naive array-like is not arguments');
1213
t.end();
1314
});

0 commit comments

Comments
 (0)