| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
LGTM with a few nits. Are we sure we want to put this on util as opposed to a new module?
I would lean more towards a types module, but am fine either way. Thanks for doing this!!
Sorry, something went wrong.
There was a problem hiding this comment.
should this be isGeneratorFunction
Sorry, something went wrong.
There was a problem hiding this comment.
isMap()
Sorry, something went wrong.
|
@evanlucas Introducing a new module is a semver-major, as it would break npmjs.com/types module. |
Sorry, something went wrong.
There was a problem hiding this comment.
If a new deprecation is introduced, it should be recorded in doc/api/deprecations.md.
Sorry, something went wrong.
There was a problem hiding this comment.
We no longer need this with isTypedArray being present in lib/internal/types.js.
Sorry, something went wrong.
There was a problem hiding this comment.
Four-space indentation. Ditto elsewhere.
Sorry, something went wrong.
There was a problem hiding this comment.
@TimothyGu All other macro lists I can find use 2 spaces for indentation?
Sorry, something went wrong.
There was a problem hiding this comment.
Heh. Never mind then, I guess.
Sorry, something went wrong.
|
@evanlucas Like @ChALkeR said, I couldn’t find a suitable name, that’s all. I don’t think util is a terrible home for this, though. @evanlucas @ChALkeR @TimothyGu Addressed your nits :) |
Sorry, something went wrong.
There was a problem hiding this comment.
Maybe Array.isArray() as per our style guide note about parentheses after methods (+ below and in the bottom reference).
Sorry, something went wrong.
There was a problem hiding this comment.
@vsemozhetbyt Yup, done!
Sorry, something went wrong.
There was a problem hiding this comment.
util.types.isDate() seems undocumented.
Sorry, something went wrong.
There was a problem hiding this comment.
@vsemozhetbyt Oops, thanks for catching this!
Sorry, something went wrong.
There was a problem hiding this comment.
&& value !== null?
Sorry, something went wrong.
There was a problem hiding this comment.
+ Is not typeof value can be either'object' or 'function'?
> const v = ()=>{}
undefined
> typeof v === 'object'
false
> typeof v
'function'
Sorry, something went wrong.
There was a problem hiding this comment.
|| value === null ?
Sorry, something went wrong.
There was a problem hiding this comment.
Would be good to have TypeError (and/or some other built-in Errors) here too.
Sorry, something went wrong.
There was a problem hiding this comment.
Something that may be surprising to JavaScript developers unfamiliar with iterators is that the iterators returned from .keys(), .values(), .entries(), and [@@iterator]() in fact look the same from the outside. Maybe have them here as well would aid comprehension? (Ditto for Set.)
Sorry, something went wrong.
There was a problem hiding this comment.
Alphabetically (what other API docs do), Uint16 would sort earlier than Uint8. This is certainly as good of a place for exception as any, but I'd like to keep it consistent for now.
Sorry, something went wrong.
There was a problem hiding this comment.
The same for util.types.isInt8Array(value).
Sorry, something went wrong.
There was a problem hiding this comment.
I do think this sorting order is a little less weird, tbh … 😄
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
Seems like you used compile here but instantiate in the test. Instantiate does indeed return { module, instance }.
Sorry, something went wrong.
There was a problem hiding this comment.
This function is implemented as value !== null && typeof value === 'object'.
Maybe also mention that even though functions are also objects, isObject historically returned false even for functions, because it's broken.
The doc as-is doesn't make much sense.
Sorry, something went wrong.
There was a problem hiding this comment.
s/string/symbol/
Also, no need for e.g. as Object() is the only way to get symbol objects in JavaScript (new Symbol() always throws an error).
Sorry, something went wrong.
There was a problem hiding this comment.
Ditto as the documentation change. You could use WebAssembly.Module's constructor to avoid the async-ness. If not, we don't really need to instantiate it. WebAssembly.compile should be sufficient.
Sorry, something went wrong.
There was a problem hiding this comment.
Yeah, I simply didn’t know you could just, you know, use new to construct a Module. ;)
Sorry, something went wrong.
There was a problem hiding this comment.
Do we have an existing check for Generator objects? In any case, I am interested in seeing a reliable JS equivalent for isGeneratorObject.
Sorry, something went wrong.
There was a problem hiding this comment.
@TimothyGu I’d guess you’d usually just check for presence of the methods? It’s not “reliable” in the sense that the V8 method is, but I didn’t see much benefit in including this, plus (and I could be completely wrong about that) I’d guess that this doesn’t work on transpiled generator functions anyway?
I’m happy to include it if you think it makes sense.
Sorry, something went wrong.
There was a problem hiding this comment.
I’d guess you’d usually just check for presence of the methods?
Doesn't this kind of defeats the whole point of having these functions available?
I’d guess that this doesn’t work on transpiled generator functions anyway?
True, but this wouldn't be the first function that doesn't either.
Sorry, something went wrong.
There was a problem hiding this comment.
I really like this test!
Sorry, something went wrong.
There was a problem hiding this comment.
process.on('exit') wouldn't be necessary if the WebAssembly.Module is created synchronously.
Sorry, something went wrong.
There was a problem hiding this comment.
Out of ABC-order?
Sorry, something went wrong.
There was a problem hiding this comment.
Is --pending-deprecation the correct type here? It's the first such one, afaik.
DEP0005 is also a --pending-deprecation, but does not mention that explicitly.
/cc @jasnell, I suppose.
Also, --pending-deprecation (and it being a semver-minor) is not mentioned in COLLABORATOR_GUIDE.md#deprecations, but that's probably a separate issue.
As I understand, currently --pending-deprecation is just a subclass of doc-only deprecations.
Sorry, something went wrong.
There was a problem hiding this comment.
I opened #18417 for that.
Sorry, something went wrong.
There was a problem hiding this comment.
As I understand, currently --pending-deprecation is just a subclass of doc-only deprecations.
I’m okay with seeing it that way, yeah. And I don’t mind being explicit about this here.
Sorry, something went wrong.
There was a problem hiding this comment.
#18433 landed, so could you change this line to
Type: Documentation-only (supports [`--pending-deprecation`][])
for consistency?
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM with the wasm example/test changed to sync version
Sorry, something went wrong.
There was a problem hiding this comment.
This should be util.types.isDate(new Date())
Sorry, something went wrong.
There was a problem hiding this comment.
a async ->an async?
Sorry, something went wrong.
There was a problem hiding this comment.
ArrayBuffer.isView -> ArrayBuffer.isView() (+ everywhere including bottom reference)?
Sorry, something went wrong.
There was a problem hiding this comment.
Maybe const proxy = new Proxy(target, {}); to make target more target?)
Sorry, something went wrong.
There was a problem hiding this comment.
The same for util.types.isInt8Array(value).
Sorry, something went wrong.
There was a problem hiding this comment.
Should be after WeakMap.
Sorry, something went wrong.
|
Maybe it is due to big diff, but some old review comments are not hidden now and are associated with the wrong lines, so do not be confused: #18415 (comment) (or https://github.com/nodejs/node/pull/18415/files#r164285093) #18415 (comment) (or https://github.com/nodejs/node/pull/18415/files#r164287166) |
Sorry, something went wrong.
There was a problem hiding this comment.
Just noting that this will have a named-import-in-ESM issue just like the fs.promises addition.
Sorry, something went wrong.
There was a problem hiding this comment.
We should likely note in the documentation how these checks are performed because types can lie about what they are if the user overrides Symbol.toStringTag.
Sorry, something went wrong.
There was a problem hiding this comment.
This function is cached at Node.js startup and thus immune to userland overrides.
Sorry, something went wrong.
There was a problem hiding this comment.
Ah right right... completely zoned on the caching. Just verified locally that even preload script can't lie about this. Dismiss this comment then :-)
Sorry, something went wrong.
There was a problem hiding this comment.
Actually... @addaleax ... this would be something worth adding to the tests... specifically, ensuring that a user-provided class overriding a built-in set within a preload module cannot lie and that the checks will come up as false.
Sorry, something went wrong.
There was a problem hiding this comment.
a user-provided class overriding a built-in set within a preload module cannot lie
I’m not sure what you mean by that. I have added a test that checks that overriding Symbol.toStringTag doesn’t fool this.
Sorry, something went wrong.
There was a problem hiding this comment.
The test should also likely verify that the result is consistent across vm contexts... e.g. check that vm.runInNewContext('new Map()') passes the type check.
Sorry, something went wrong.
There was a problem hiding this comment.
add:
util.types.isBooleanObject(Boolean(false)); // Returns false util.types.isBooleanObject(Boolean(true)); // Returns false
Sorry, something went wrong.
There was a problem hiding this comment.
Not sure if we should assert that it is 'built-in' in these. The objects can lie, and user code can create their own objects (polyfills) that are not actually built-ins.
Sorry, something went wrong.
There was a problem hiding this comment.
async function here could be a link to more documentation about async functions... perhaps a link over the MDN documentation?
Sorry, something went wrong.
There was a problem hiding this comment.
hmm... this last sentence is a bit content free. why would developers prefer to do type checking in JavaScript :-) ... I think it's better to say something about specific use cases such as "These are primarily useful for debugging" or something similar
Sorry, something went wrong.
There was a problem hiding this comment.
@jasnell I can’t really agree … the “why” is, it’s a preference. I personally don’t think it’s a good idea, but it’s what Node decided to migrate to?
Saying “these are primarily useful for debugging” doesn’t really seem more helpful, because it doesn’t even say how you’d use these methods for debugging…
Sorry, something went wrong.
There was a problem hiding this comment.
There's already https://github.com/nodejs/node/blob/master/test/parallel/test-types.js. You might want to look into combining these two files.
Sorry, something went wrong.
There was a problem hiding this comment.
@TimothyGu I’ve just copied the contents into a block in this file, let me know if that doesn’t sound good to you. The tests have somewhat different structures, but I think that’s fine?
Sorry, something went wrong.
PR-URL: #18415 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Provide public APIs for native typechecking that is actually useful.
The motivation for this is providing alternatives to userland
modules that would currently rely on `process.binding('util')`.
PR-URL: #18415
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
|
Should this be backported to v9.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label. |
Sorry, something went wrong.
|
this would need to come with #19149 |
Sorry, something went wrong.
- Use require('util').types instead of using process.binding('util')
to get the type checking helpers
- Rename nodeUtil to nodeTypes since that is what it is for
Refs: nodejs/node#18415
- Use require('util').types instead of using process.binding('util')
to get the type checking helpers
- Rename nodeUtil to nodeTypes since that is what it is for
Refs: nodejs/node#18415
The old variants have been deprecated since b20af80. Refs: nodejs#18415
The old variants have been deprecated since b20af80. Refs: #18415 PR-URL: #19602 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#18415 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Provide public APIs for native typechecking that is actually useful.
The motivation for this is providing alternatives to userland
modules that would currently rely on `process.binding('util')`.
PR-URL: nodejs#18415
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Refs: nodejs#18415 PR-URL: nodejs#19149 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
The old variants have been deprecated since b20af80. Refs: nodejs#18415 PR-URL: nodejs#19602 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: nodejs#18415 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Provide public APIs for native typechecking that is actually useful.
The motivation for this is providing alternatives to userland
modules that would currently rely on `process.binding('util')`.
PR-URL: nodejs#18415
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Refs: nodejs#18415 PR-URL: nodejs#19149 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
|
Is this something we would want to backport to v8.x? Seems like a bunch of moving parts |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Provide public APIs for native typechecking that is actually useful. The motivation for this is providing alternatives to userland modules that would currently rely on process.binding('util').
This is based off the list in v8.h, with things that have better JS equivalents removed; I’m happy to bikeshed this list.
Also, for context, previous efforts:
Checklist
Affected core subsystem(s)
util