Skip to content

Commit

Permalink
repl: fix top level await with surrogate characters
Browse files Browse the repository at this point in the history
Fixes: #39929
  • Loading branch information
Mesteery committed Aug 29, 2021
1 parent 449147e commit 458a9fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/repl/await.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ for (const nodeType of ObjectKeys(walk.base)) {
function processTopLevelAwait(src) {
const wrapPrefix = '(async () => { ';
const wrapped = `${wrapPrefix}${src} })()`;
const wrappedArray = ArrayFrom(wrapped);
const wrappedArray = StringPrototypeSplit(wrapped, '');
let root;
try {
root = parser.parse(wrapped, { ecmaVersion: 'latest' });
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-repl-preprocess-top-level-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@ const { processTopLevelAwait } = require('internal/repl/await');
// This test was created based on
// https://cs.chromium.org/chromium/src/third_party/WebKit/LayoutTests/http/tests/inspector-unit/preprocess-top-level-awaits.js?rcl=358caaba5e763e71c4abb9ada2d9cd8b1188cac9

const surrogate = '"\u{1F601}\u{1f468}\u200d\u{1f469}\u200d\u{1f467}\u200d\u{1f466}"';

const testCases = [
[ '0',
null ],
[ 'await 0',
'(async () => { return (await 0) })()' ],
[ `await ${surrogate}`,
`(async () => { return (await ${surrogate}) })()` ],
[ 'await 0;',
'(async () => { return (await 0); })()' ],
[ `await ${surrogate};`,
`(async () => { return (await ${surrogate}); })()` ],
[ `await ${surrogate};`,
`(async () => { return (await ${surrogate}); })()` ],
[ '(await 0)',
'(async () => { return ((await 0)) })()' ],
[ `(await ${surrogate})`,
`(async () => { return ((await ${surrogate})) })()` ],
[ '(await 0);',
'(async () => { return ((await 0)); })()' ],
[ `(await ${surrogate});`,
`(async () => { return ((await ${surrogate})); })()` ],
[ 'async function foo() { await 0; }',
null ],
[ 'async () => await 0',
Expand All @@ -28,8 +40,12 @@ const testCases = [
null ],
[ 'await 0; return 0;',
null ],
[ `await ${surrogate}; await ${surrogate};`,
`(async () => { await ${surrogate}; return (await ${surrogate}); })()` ],
[ 'var a = await 1',
'var a; (async () => { void (a = await 1) })()' ],
[ `var a = await ${surrogate}`,
`var a; (async () => { void (a = await ${surrogate}) })()` ],
[ 'let a = await 1',
'let a; (async () => { void (a = await 1) })()' ],
[ 'const a = await 1',
Expand Down

0 comments on commit 458a9fd

Please sign in to comment.