Skip to content

Commit d6124d8

Browse files
MesteeryBethGriggs
authored andcommitted
repl: fix top level await with surrogate characters
Fixes: #39929 PR-URL: #39931 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
1 parent edcfffe commit d6124d8

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎lib/internal/repl/await.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const{
4-
ArrayFrom,
54
ArrayPrototypeForEach,
65
ArrayPrototypeIncludes,
76
ArrayPrototypeJoin,
@@ -155,7 +154,7 @@ for (const nodeType of ObjectKeys(walk.base)) {
155154
functionprocessTopLevelAwait(src){
156155
constwrapPrefix='(async () => { ';
157156
constwrapped=`${wrapPrefix}${src} })()`;
158-
constwrappedArray=ArrayFrom(wrapped);
157+
constwrappedArray=StringPrototypeSplit(wrapped,'');
159158
letroot;
160159
try{
161160
root=parser.parse(wrapped,{ecmaVersion: 'latest'});

‎test/parallel/test-repl-preprocess-top-level-await.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,31 @@ const { processTopLevelAwait } = require('internal/repl/await');
99
// This test was created based on
1010
// https://cs.chromium.org/chromium/src/third_party/WebKit/LayoutTests/http/tests/inspector-unit/preprocess-top-level-awaits.js?rcl=358caaba5e763e71c4abb9ada2d9cd8b1188cac9
1111

12+
constsurrogate=(
13+
'"\u{1F601}\u{1f468}\u200d\u{1f469}\u200d\u{1f467}\u200d\u{1f466}"'
14+
);
15+
1216
consttestCases=[
1317
['0',
1418
null],
1519
['await 0',
1620
'(async () => { return (await 0) })()'],
21+
[`await ${surrogate}`,
22+
`(async () => { return (await ${surrogate}) })()`],
1723
['await 0;',
1824
'(async () => { return (await 0); })()'],
25+
[`await ${surrogate};`,
26+
`(async () => { return (await ${surrogate}); })()`],
27+
[`await ${surrogate};`,
28+
`(async () => { return (await ${surrogate}); })()`],
1929
['(await 0)',
2030
'(async () => { return ((await 0)) })()'],
31+
[`(await ${surrogate})`,
32+
`(async () => { return ((await ${surrogate})) })()`],
2133
['(await 0);',
2234
'(async () => { return ((await 0)); })()'],
35+
[`(await ${surrogate});`,
36+
`(async () => { return ((await ${surrogate})); })()`],
2337
['async function foo() { await 0; }',
2438
null],
2539
['async () => await 0',
@@ -28,8 +42,12 @@ const testCases = [
2842
null],
2943
['await 0; return 0;',
3044
null],
45+
[`await ${surrogate}; await ${surrogate};`,
46+
`(async () => { await ${surrogate}; return (await ${surrogate}); })()`],
3147
['var a = await 1',
3248
'var a; (async () => { void (a = await 1) })()'],
49+
[`var a = await ${surrogate}`,
50+
`var a; (async () => { void (a = await ${surrogate}) })()`],
3351
['let a = await 1',
3452
'let a; (async () => { void (a = await 1) })()'],
3553
['const a = await 1',

0 commit comments

Comments
 (0)