From 458a9fd0fe931e50fd6477d55720b7ea8a5b517d Mon Sep 17 00:00:00 2001 From: Mestery Date: Sun, 29 Aug 2021 16:03:36 +0200 Subject: [PATCH 1/2] repl: fix top level await with surrogate characters Fixes: https://github.com/nodejs/node/issues/39929 --- lib/internal/repl/await.js | 2 +- .../test-repl-preprocess-top-level-await.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/internal/repl/await.js b/lib/internal/repl/await.js index f28a7ea412bc3f..6741d5f33d66f2 100644 --- a/lib/internal/repl/await.js +++ b/lib/internal/repl/await.js @@ -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' }); diff --git a/test/parallel/test-repl-preprocess-top-level-await.js b/test/parallel/test-repl-preprocess-top-level-await.js index 93d3d79a87bb08..b5b7c6589b17ba 100644 --- a/test/parallel/test-repl-preprocess-top-level-await.js +++ b/test/parallel/test-repl-preprocess-top-level-await.js @@ -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', @@ -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', From 62553091407c66372cf8c9759a18d66a21350541 Mon Sep 17 00:00:00 2001 From: Mestery Date: Mon, 30 Aug 2021 00:46:33 +0200 Subject: [PATCH 2/2] fixup --- lib/internal/repl/await.js | 1 - test/parallel/test-repl-preprocess-top-level-await.js | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/internal/repl/await.js b/lib/internal/repl/await.js index 6741d5f33d66f2..ba138fdfe8c8d9 100644 --- a/lib/internal/repl/await.js +++ b/lib/internal/repl/await.js @@ -1,7 +1,6 @@ 'use strict'; const { - ArrayFrom, ArrayPrototypeForEach, ArrayPrototypeIncludes, ArrayPrototypeJoin, diff --git a/test/parallel/test-repl-preprocess-top-level-await.js b/test/parallel/test-repl-preprocess-top-level-await.js index b5b7c6589b17ba..656b616b71d9e6 100644 --- a/test/parallel/test-repl-preprocess-top-level-await.js +++ b/test/parallel/test-repl-preprocess-top-level-await.js @@ -9,7 +9,9 @@ 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 surrogate = ( + '"\u{1F601}\u{1f468}\u200d\u{1f469}\u200d\u{1f467}\u200d\u{1f466}"' +); const testCases = [ [ '0',