-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Array<RegExp>.toString() doesn't work properly on Node.js CLI #44417
Comments
Thank you for reporting! I can reproduce this issue on v18.8.0. |
A minimum code to reproduce $ node -p "const a = [/a/]; a.toString();"
/a/
$ node
> const a = [/a/]; a.toString();
'/a/'
> a.toString();
'' |
Do you think this issue could be suitable for a new contributor? If so, I would like to be assigned to it and give it a try. |
From my brief investigation, this is seemingly caused by V8 issue, not Node.js. (Node.js just calls V8's APIs to execute scripts line by line, and ChromeDevTools has the same issue too.) I don't know this issue is suitable for you but it is definitely worthwhile to look into the code to find out the cause! |
A more minimum code to reproduce: $ node
Welcome to Node.js v18.2.0.
Type ".help" for more information.
> const a = [/a/];
undefined
> a.toString()
'' |
I am able to reproduce this with the Chrome DevTools. I just reported it to the @nodejs/v8 team. https://bugs.chromium.org/p/v8/issues/detail?id=13259 |
It seems this is not even specific to regex. PS C:\Users\mmis1> node
Welcome to Node.js v16.13.2.
Type ".help" for more information.
> const b = [{ toString() { console.log(1); return '1' } }]
undefined
> b + ''
'' |
Original commit message: [runtime] Clear array join stack when throwing uncatchable ... exception. Array#join depends array_join_stack to avoid infinite loop and ensures symmetric pushes/pops through catch blocks to correctly maintain the elements in the join stack. However, the stack does not pop the elements and leaves in an invalid state when throwing the uncatchable termination exception. And the invalid join stack state will affect subsequent Array#join calls. Because all the terminate exception will be handled by Isolate::UnwindAndFindHandler, we could clear the array join stack when unwinding the terminate exception. Bug: v8:13259 Change-Id: I23823e823c5fe0b089528c5cf654864cea78ebeb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3878451 Reviewed-by: Jakob Linke <[email protected]> Commit-Queue: 王澳 <[email protected]> Cr-Commit-Position: refs/heads/main@{#83465} Refs: v8/v8@031b98b Closes: nodejs#44417
Original commit message: [runtime] Clear array join stack when throwing uncatchable ... exception. Array#join depends array_join_stack to avoid infinite loop and ensures symmetric pushes/pops through catch blocks to correctly maintain the elements in the join stack. However, the stack does not pop the elements and leaves in an invalid state when throwing the uncatchable termination exception. And the invalid join stack state will affect subsequent Array#join calls. Because all the terminate exception will be handled by Isolate::UnwindAndFindHandler, we could clear the array join stack when unwinding the terminate exception. Bug: v8:13259 Change-Id: I23823e823c5fe0b089528c5cf654864cea78ebeb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3878451 Reviewed-by: Jakob Linke <[email protected]> Commit-Queue: 王澳 <[email protected]> Cr-Commit-Position: refs/heads/main@{#83465} Refs: v8/v8@031b98b Closes: #44417 PR-URL: #45375 Fixes: #44417 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Kohei Ueno <[email protected]>
Original commit message: [runtime] Clear array join stack when throwing uncatchable ... exception. Array#join depends array_join_stack to avoid infinite loop and ensures symmetric pushes/pops through catch blocks to correctly maintain the elements in the join stack. However, the stack does not pop the elements and leaves in an invalid state when throwing the uncatchable termination exception. And the invalid join stack state will affect subsequent Array#join calls. Because all the terminate exception will be handled by Isolate::UnwindAndFindHandler, we could clear the array join stack when unwinding the terminate exception. Bug: v8:13259 Change-Id: I23823e823c5fe0b089528c5cf654864cea78ebeb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3878451 Reviewed-by: Jakob Linke <[email protected]> Commit-Queue: 王澳 <[email protected]> Cr-Commit-Position: refs/heads/main@{#83465} Refs: v8/v8@031b98b Closes: #44417 PR-URL: #45375 Fixes: #44417 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Kohei Ueno <[email protected]>
Original commit message: [runtime] Clear array join stack when throwing uncatchable ... exception. Array#join depends array_join_stack to avoid infinite loop and ensures symmetric pushes/pops through catch blocks to correctly maintain the elements in the join stack. However, the stack does not pop the elements and leaves in an invalid state when throwing the uncatchable termination exception. And the invalid join stack state will affect subsequent Array#join calls. Because all the terminate exception will be handled by Isolate::UnwindAndFindHandler, we could clear the array join stack when unwinding the terminate exception. Bug: v8:13259 Change-Id: I23823e823c5fe0b089528c5cf654864cea78ebeb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3878451 Reviewed-by: Jakob Linke <[email protected]> Commit-Queue: 王澳 <[email protected]> Cr-Commit-Position: refs/heads/main@{#83465} Refs: v8/v8@031b98b Closes: #44417 PR-URL: #45375 Fixes: #44417 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Kohei Ueno <[email protected]>
Original commit message: [runtime] Clear array join stack when throwing uncatchable ... exception. Array#join depends array_join_stack to avoid infinite loop and ensures symmetric pushes/pops through catch blocks to correctly maintain the elements in the join stack. However, the stack does not pop the elements and leaves in an invalid state when throwing the uncatchable termination exception. And the invalid join stack state will affect subsequent Array#join calls. Because all the terminate exception will be handled by Isolate::UnwindAndFindHandler, we could clear the array join stack when unwinding the terminate exception. Bug: v8:13259 Change-Id: I23823e823c5fe0b089528c5cf654864cea78ebeb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3878451 Reviewed-by: Jakob Linke <[email protected]> Commit-Queue: 王澳 <[email protected]> Cr-Commit-Position: refs/heads/main@{#83465} Refs: v8/v8@031b98b Closes: #44417 PR-URL: #45375 Fixes: #44417 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Kohei Ueno <[email protected]>
Original commit message: [runtime] Clear array join stack when throwing uncatchable ... exception. Array#join depends array_join_stack to avoid infinite loop and ensures symmetric pushes/pops through catch blocks to correctly maintain the elements in the join stack. However, the stack does not pop the elements and leaves in an invalid state when throwing the uncatchable termination exception. And the invalid join stack state will affect subsequent Array#join calls. Because all the terminate exception will be handled by Isolate::UnwindAndFindHandler, we could clear the array join stack when unwinding the terminate exception. Bug: v8:13259 Change-Id: I23823e823c5fe0b089528c5cf654864cea78ebeb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3878451 Reviewed-by: Jakob Linke <[email protected]> Commit-Queue: 王澳 <[email protected]> Cr-Commit-Position: refs/heads/main@{#83465} Refs: v8/v8@031b98b Closes: #44417 PR-URL: #45375 Fixes: #44417 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Kohei Ueno <[email protected]>
Original commit message: [runtime] Clear array join stack when throwing uncatchable ... exception. Array#join depends array_join_stack to avoid infinite loop and ensures symmetric pushes/pops through catch blocks to correctly maintain the elements in the join stack. However, the stack does not pop the elements and leaves in an invalid state when throwing the uncatchable termination exception. And the invalid join stack state will affect subsequent Array#join calls. Because all the terminate exception will be handled by Isolate::UnwindAndFindHandler, we could clear the array join stack when unwinding the terminate exception. Bug: v8:13259 Change-Id: I23823e823c5fe0b089528c5cf654864cea78ebeb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3878451 Reviewed-by: Jakob Linke <[email protected]> Commit-Queue: 王澳 <[email protected]> Cr-Commit-Position: refs/heads/main@{#83465} Refs: v8/v8@031b98b Closes: #44417 PR-URL: #45375 Fixes: #44417 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Kohei Ueno <[email protected]>
Version
v16.13.1
Platform
Microsoft Windows NT 10.0.19044.0 x64
Subsystem
No response
What steps will reproduce the bug?
Hello, I've found interesting bug on Node.js CLI on Windows Console and also on WSL.
These code will work as intended when being run inside a file (
node index.js
) or copy to CLI simultaneously, but won't work if we run it line by line.After running
arr.toString();
without assigning to a variable, thearr
variable will broke and failed to return correct string.Output
Scenario:
node index.js
Scenario: Copy to Node.js CLI simultaneously
Bugged Scenario: Run Line by Line on Node.js CLI
How often does it reproduce? Is there a required condition?
On right condition, it happens all the time.
What is the expected behavior?
arr
variable does not change internally and able to return correct string using.toString()
method.What do you see instead?
arr.toString()
returns blank string and becomes broken.Additional information
No response
The text was updated successfully, but these errors were encountered: