-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: simplify isPrimitve
#739
Conversation
How about something simpler still: return Object(arg) !== arg; |
Or return arg === null || typeof arg !== 'object'; |
@micnic that would return true for functions. |
@seishun, oops, I read in the commit description |
@seishun looks neat, but probably involves unnecessary allocation |
@seishun Here is how it's implemented in v8: function ToObject(x) {
if (IS_STRING(x)) return new $String(x);
if (IS_NUMBER(x)) return new $Number(x);
if (IS_BOOLEAN(x)) return new $Boolean(x);
if (IS_SYMBOL(x)) return %NewSymbolWrapper(x);
if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) {
throw %MakeTypeError('undefined_or_null_to_object', []);
}
return x;
} |
I can't find any failures for edge cases. LGTM |
typeof arg === 'symbol' || // ES6 symbol | ||
typeof arg === 'undefined'; | ||
typeof arg !== 'object' && | ||
typeof arg !== 'function'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it fits on one line now?
LGTM but there's a typo in the commit log: s/isPrimitve/isPrimitive/ |
Everything that is not an object should be a primitive.
b40a19a
to
0172bb4
Compare
Everything that is not an object should be a primitive. PR-URL: #739 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Fixed everything and landed b9d3928 |
Everything that is not an object should be a primitive.
R=@trevnorris