-
Notifications
You must be signed in to change notification settings - Fork 152
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
Add JS_IsPlainObject function #959
base: master
Are you sure you want to change the base?
Conversation
Perhaps this should be called IsPlainObject? |
I have changed the function name to JS_IsPlainObject now. |
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.
LGTM. @bnoordhuis WDYT?
@harumazzz what (or where) do you intend to use this? What you're doing here is very close to |
In my project, I used this check for my own JSON parse/stringify and nested deep clone. There is not much case we would need this API, however since we already got JS_IsArray, I think we should also have JS_IsPlainObject? |
What I'm trying to understand is under what conditions specifically you'd branch on The latter corresponds to the |
I think calling |
That's not a very compelling argument. In the balance, I think it's best if we don't merge this. On the one hand, this API is a minor addition that cannot do much harm. On the other hand, if, by your own admission, the primary use case is to skirt on writing a few extra lines of code that make for a more cohesive user experience, then it's definitely not a great API. |
Indeed it is a weaker predicate than |
Used to check if an object is actually a JS object, since JS_IsObject only checked if the tag of a JSValue is JS_TAG_OBJECT.