-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add methods to detect arrays #282
Conversation
I have a use case where a user can hand me many different kinds of types, array buffer, uint8array, or a string, and I need to be able to distingush between them. Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
Instead of adding numerous APIs like this, we should consider exporting the |
I am happy to do that instead. What is the best way folks see to do that? Add a bunch of #define constants to the header for builtin classes, add a new enum in the header, or actually move the existing enum into the header |
I was thinking the same thing! |
IMHO moving the enum to the header would be best. |
I am not sure about moving the whole enum to keep some flexibility in the implementation for internal classes. We should move the standard class ids to the beginning of the enum and publish that enum, then use a separate private enum starting at the end of the public one for internal classes. |
Makes sense! |
As a counterargument: both V8 and JavaScriptCore have a plethora of "is foo" functions. It gives them the flexibility to change object representation at a whim without breaking downstream users. Exporting an enum means you can't ever change it (only add to it) without breaking source or binary compatibility. |
Good point! It also aligns well with isundefined and so on... |
The "is foo" functions could be defined in quickjs.h as simple inline functions comparing the return value of So source code compatibility should be sought and more likely achieved than binary API compatibility. |
I agree source code compatibility will be easier but binary compatibility is a conversation worth having if we want distros to start packaging libquickjs. They're virulently allergic to libraries without a stable API/ABI. That's more of a roadmap thing and doesn't need to hold up this pull request though. I believe we're in agreement that |
Actually, it is a little more complicated: in QuickJS, Should other "is foo" API functions function this way ? For the sake of the principle of least surprise, equivalent calls on different engines should behave in a consistent way. PS: I have never looked at the Node.js source code :) |
Yes, node.js / V8 behaves the same way w.r.t. proxies. They're transparent unless you specifically ask "is this a proxy?" |
https://github.com/v8/v8/blob/main/include/v8-value.h It looks like v8 has a bunch of these checks |
Is there anything I can do to get this merged? I am currently hardcoding the constants in my app for these classes. |
After some back and forth looks like this is the way we want to go, right folks? |
It seems inconsistent that Should we have a flag to specify whether to follow proxy chains and still return a boolean for native objects and safe proxies with just a limited chain depth? |
I guess one difference here is that when So maybe it should be the other way around? |
I have a use case where a user can hand me many different kinds of
types, array buffer, uint8array, or a string, and I need to be able to
distingush between them.