| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
Hi! Thanks for sending the PR. Would it be possible to add tests to make sure this is fixing the issue?
Sorry, something went wrong.
How would you suggest to test this? run the same commands and check no error is printed to screen OR do more of unit test to the specific preview function? |
Sorry, something went wrong.
|
You can add a test case in test/parallel/test-repl-history-navigation.js: {
env: { NODE_REPL_HISTORY: defaultHistoryPath },
test: [ 'const util = {}', ENTER,
'ut', RIGHT, ENTER],
expected: [],
clean: false
},You need to also add a line to make sure the warning is gone at the top of the file: process.on('warning', common.mustNotCall());Make sure this fails on current Node.js version, and passes with your PR: $ ./tools/test.py test/parallel/test-repl-history-navigation.js
[00:00|% 100|+ 1|- 0]: Done
$ node test/parallel/test-repl-history-navigation.js || echo 'All good, we expect this to fail'
All good, we expect this to fail |
Sorry, something went wrong.
@aduh95 Done! Thanks for the guidance 😄 |
Sorry, something went wrong.
|
I... don't understand this fix? Doesn't this just fix the error being shown (cannot read property length) instead of the underlying cause (the repl assuming util is available in the global namespace)? I would strongly prefer a fix that fixes the underlying issue and not the "cosmetic" one. Namely changing code doing something like: session.post('Runtime.callFunctionOn', {
functionDeclaration: `(v) => util.inspect(v, ${inspectOptions})`,
objectId: result.objectId,
arguments: [result]
}To not rely on the global util (either by requireing it, "hiding" it as a non-completed global, or passing it to Runtime.evaluate) |
Sorry, something went wrong.
There was a problem hiding this comment.
Requesting changes to make sure this doesn't land before everyone is on the same page regarding the kind of fix this needs @nodejs/repl
(Thank you for working on this @EladKeyshawn !)
Sorry, something went wrong.
I think it makes sense to change that relevant code from util.inspect to require('util').inspect at least (in addition to the undefined fix, so that doing const require = {} won't break the code). The change would change the "bad" word to require, but I think that it's much less likely to be used. |
Sorry, something went wrong.
That shouldn't be an issue, require is not on the global scope. actually it is, the function still inherits from the REPL scope. |
Sorry, something went wrong.
|
@benjamingr I arrive at the same conclusion as @Linkgoron, we need to rely on either util or require being unchanged –unless there's a way to use dynamic import? Maybe what we can do is to use (v) => Reflect.getOwnPropertyDescriptor(globalThis, 'util').get().inspect(v, ${inspectOptions}), which would fail only if the global util property is re-defined, and wouldn't be "exploitable" unless the user goes all the way of defining a credible mock: > const util = {}
undefined
> util
{}
> globalThis.util = { inspect() { return console.log(arguments) } }
{ inspect: [Function: inspect] }
> util
{}
> Reflect.defineProperty(globalThis, 'util', { get() { return {inspect(){ console.log(arguments) }}}})
true
> ut[Arguments] {
'0': {},
'1': {
showHidden: false,
depth: 1,
colors: false,
customInspect: true,
showProxy: true,
maxArrayLength: 100,
maxStringLength: 10000,
breakLength: Infinity,
compact: true,
sorted: false,
getters: false
}
} |
Sorry, something went wrong.
|
@EladKeyshawn can you please update the code at node/lib/internal/repl/utils.js Lines 353 to 357 in 7216eb6 |
Sorry, something went wrong.
No problem :) I'm on it |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM with green CI
Sorry, something went wrong.
If globalThis is reassigned we're back with the same problem. Do we count on the fact that it's unlikely to happen? anyways my original patch solves the Cannot read property 'length' of undefined warning in this case anyways. |
Sorry, something went wrong.
|
@aduh95 Can you explain why the last tests pass the expected output but are not marked as called, I believe obviously repl.once('closed'... is not triggered but is that normal? |
Sorry, something went wrong.
Right, I think it's fine to fail when globalThis is overwritten, I don't think there is a way around it. I'd say it's possibly less likely to happen than util.
I'm not sure I understand what you mean, I'd expect the closed event to be emitted for each test case. What make you think it's not triggered? |
Sorry, something went wrong.
|
@benjamingr @aduh95 What's blocking this? |
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
|
test-repl-history-navigation is consistently failing on ubuntu1804_sharedlibs_withoutintl_x64 and ubuntu1804_sharedlibs_withoutssl_x64 jobs. |
Sorry, something went wrong.
Do you have any idea what could cause this? for me on OSx it works. |
Sorry, something went wrong.
There was a problem hiding this comment.
One way of working around this would be to disable the output checks when Intl or crypto is missing.
Sorry, something went wrong.
There was a problem hiding this comment.
| expected: [ | |
| expected: common.hasIntl && common.hasCrypto ? [ |
Sorry, something went wrong.
There was a problem hiding this comment.
Can I ask why do these requirements affect the console output? :)
Sorry, something went wrong.
There was a problem hiding this comment.
No clue! If you'd like to investigate that, you can compile node with ./configure --without-intl on your local machine.
Sorry, something went wrong.
Sorry, something went wrong.
|
Landed in b2baa3dd5100 🎉 |
Sorry, something went wrong.
|
I had to revert because of lint failures. I will land this manually. |
Sorry, something went wrong.
|
@benjamingr I have this ready to land on my local machine, do you want me to push? |
Sorry, something went wrong.
|
@aduh95 yes please, thanks :) I want to investigate what's went wrong and I don't want to hold this PR up just for my root-cause check |
Sorry, something went wrong.
The REPL no longer relies on `util` being a reference to the `util` core module. It still relies on `globalThis` refering to the global object, but no longer emits warnings when it's overwritten by the user. PR-URL: nodejs#38141 Fixes: nodejs#38139 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
|
Thanks 😊 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes: #38139