lib: use non-symbols in isURLInstance check#34622
lib: use non-symbols in isURLInstance check#34622codebytere wants to merge 1 commit intonodejs:masterfrom
Conversation
jasnell
left a comment
There was a problem hiding this comment.
Let's use this as part of the argument back to TC-39 that URL really ought to be added to the language ;-) ... LGTM!
|
Does this mean that in electron there are two different implementations of URL floating around? |
|
Sadly, yes, but I believe the blink one is the one that's actually global. The Node.js one would still be accessible via |
|
@devsnek heh well "floating around" is a bit nebulous, but two can exist depending on where/how you're invoking Renderer example: const fs = require('fs');
const path = require('path');
const url1 = new URL('file://' + path.resolve('index.html'));
const url = require('url')
const url2 = new url.URL('file://' + path.resolve('index.html'));
console.log(url1) // Blink impl
console.log(url2) // Node.js implwill show: |
604cdfd to
ab961ef
Compare
PR-URL: #34622 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
|
Landed in 8825eb4. |
PR-URL: #34622 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #34622 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #34622 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #34622 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

This slightly changes the conditional used to determine whether or not something is a URL instance. Since Node.js adds symbols to the URL not specified by the WHATWG, those symbols are not present in other implementations (like Blink's) and therefore can cause false negatives. In Electron's renderer process, running e.g. this code:
would cause the following error:
To remedy this, I think we should instead switch on properties guaranteed to be present in all URL instances as specified by the WHATWG.
cc @jasnell
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes