-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
module: use isURLInstance instead of instanceof #34951
Conversation
Review requested:
|
this is a good change - instanceof should be avoided - but perhaps this should have a test using the |
@ljharb can you elaborate on what you have in mind? $ node -p "require('vm').runInContext('URL', require('vm').createContext({})) === URL"
evalmachine.<anonymous>:1
URL
^
ReferenceError: URL is not defined
at evalmachine.<anonymous>:1:1
at Script.runInContext (vm.js:141:18)
at Object.runInContext (vm.js:279:6)
at [eval]:1:15
at Script.runInThisContext (vm.js:131:18)
at Object.runInThisContext (vm.js:295:38)
at Object.<anonymous> ([eval]-wrapper:10:26)
at Module._compile (internal/modules/cjs/loader.js:1200:30)
at evalScript (internal/process/execution.js:98:25)
at internal/main/eval_string.js:23:3
$ node -p "require('vm').runInContext('URL', require('vm').createContext({ URL })) === URL"
true We'd need a whole new implementation of |
ahhh, hm. what's the implementation of |
More info on that on #34622, I have actually very little knowledge myself on that topic 🙈 |
Looking at that implementation, that's not "is URL instance", that's "has truthy href and origin properties", which is more like "is URL-like". Is the intention to allow |
@ljharb I'd say it's probably OK, using such an object would fail anyway when converted to string. Hopefully the |
I think this should be labeled |
In case anyone is curious as to what Lines 1420 to 1422 in 22c52aa
|
Landed in d24eecd |
PR-URL: #34951 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Derek Lewis <[email protected]>
PR-URL: #34951 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Derek Lewis <[email protected]>
PR-URL: nodejs#34951 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Derek Lewis <[email protected]>
PR-URL: #34951 Backport-PR-URL: #35385 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Derek Lewis <[email protected]>
PR-URL: nodejs#34951 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Derek Lewis <[email protected]>
Related to #34622, in case there are several WHATWG URL implementations available,
isURLInstance
would work better thaninstanceof URL
. Might also be more efficient, but I haven't run any benchmarks :)Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes