-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
repl: refactor to avoid unsafe array iteration #36444
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
Changes from 13 commits
b81f448
f5d6c33
b6b3c5b
0a167a1
3a9491e
846ac65
9367f9b
61cb3b7
10c1759
669f93e
dc678b0
ddfbfc4
77a6be5
6c19991
ccc860a
81776d6
a45f1ed
c61b0b9
71350bd
1ec7036
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,41 @@ | ||||
| 'use strict'; | ||||
| const common = require('../common'); | ||||
| const ArrayStream = require('../common/arraystream'); | ||||
| const assert = require('assert'); | ||||
| const repl = require('repl'); | ||||
|
|
||||
| function run(input, expectation) { | ||||
| const inputStream = new ArrayStream(); | ||||
| const outputStream = new ArrayStream(); | ||||
| let output = ''; | ||||
|
|
||||
| outputStream.write = (data) => { output += data.replace('\r', ''); }; | ||||
|
|
||||
| const r = repl.start({ | ||||
| input: inputStream, | ||||
| output: outputStream, | ||||
| terminal: true | ||||
| }); | ||||
|
|
||||
| r.on('exit', common.mustCall(() => { | ||||
| const actual = output.split('\n'); | ||||
|
|
||||
| // Validate that the for loop returns undefined | ||||
| assert.notStrictEqual(actual[actual.length - 2], expectation); | ||||
| })); | ||||
|
|
||||
| inputStream.run(input); | ||||
| r.close(); | ||||
| } | ||||
|
|
||||
| run([ | ||||
| 'delete Array.prototype[Symbol.iterator];', | ||||
| 'for(const x of [3, 2, 1]);' | ||||
|
||||
| 'for(const x of [3, 2, 1]);' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it just returns true if I remove the loop. Both the errors are thrown right after the loop is streamed in.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, you'll get TypeError: undefined is not a function.
| 'for(const x of [3, 2, 1]);' |
Uh oh!
There was an error while loading. Please reload this page.