Skip to content

Array<RegExp>.toString() doesn't work properly on Node.js CLI #44417

Closed
@yukha-dw

Description

@yukha-dw

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.

const arr = [/asd/,/cvb/];

first=`${arr.toString()}`;
console.log({first});

arr.toString();

second=`${arr.toString()}`;
console.log({second});

After running arr.toString(); without assigning to a variable, the arr variable will broke and failed to return correct string.

Output

Scenario: node index.js

{ first: '/asd/,/cvb/' }
{ second: '/asd/,/cvb/' }

Scenario: Copy to Node.js CLI simultaneously

Welcome to Node.js v16.13.1.
Type ".help" for more information.
> const arr = [/asd/,/cvb/];
undefined
>
> first=`${arr.toString()}`;
'/asd/,/cvb/'
> console.log({first});
{ first: '/asd/,/cvb/' }
undefined
>
> arr.toString();
'/asd/,/cvb/'
>
> second=`${arr.toString()}`;
'/asd/,/cvb/'
> console.log({second});
{ second: '/asd/,/cvb/' }
undefined
>

Bugged Scenario: Run Line by Line on Node.js CLI

Welcome to Node.js v16.13.1.
Type ".help" for more information.
> const arr = [/asd/,/cvb/];
undefined
> first=`${arr.toString()}`;
'/asd/,/cvb/'
> console.log({first});
{ first: '/asd/,/cvb/' }
undefined
>
> arr.toString();
''
>
> second=`${arr.toString()}`;
''
> console.log({second});
{ second: '' }
undefined
>

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.replIssues and PRs related to the REPL subsystem.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions