11cb0ef41Sopenharmony_ci// Copyright Joyent, Inc. and other Node contributors. 21cb0ef41Sopenharmony_ci// 31cb0ef41Sopenharmony_ci// Permission is hereby granted, free of charge, to any person obtaining a 41cb0ef41Sopenharmony_ci// copy of this software and associated documentation files (the 51cb0ef41Sopenharmony_ci// "Software"), to deal in the Software without restriction, including 61cb0ef41Sopenharmony_ci// without limitation the rights to use, copy, modify, merge, publish, 71cb0ef41Sopenharmony_ci// distribute, sublicense, and/or sell copies of the Software, and to permit 81cb0ef41Sopenharmony_ci// persons to whom the Software is furnished to do so, subject to the 91cb0ef41Sopenharmony_ci// following conditions: 101cb0ef41Sopenharmony_ci// 111cb0ef41Sopenharmony_ci// The above copyright notice and this permission notice shall be included 121cb0ef41Sopenharmony_ci// in all copies or substantial portions of the Software. 131cb0ef41Sopenharmony_ci// 141cb0ef41Sopenharmony_ci// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 151cb0ef41Sopenharmony_ci// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 161cb0ef41Sopenharmony_ci// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 171cb0ef41Sopenharmony_ci// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 181cb0ef41Sopenharmony_ci// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 191cb0ef41Sopenharmony_ci// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 201cb0ef41Sopenharmony_ci// USE OR OTHER DEALINGS IN THE SOFTWARE. 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci'use strict'; 231cb0ef41Sopenharmony_ciconst common = require('../common'); 241cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 251cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 261cb0ef41Sopenharmony_ciconst assert = require('assert'); 271cb0ef41Sopenharmony_ciconst net = require('net'); 281cb0ef41Sopenharmony_ciconst repl = require('repl'); 291cb0ef41Sopenharmony_ciconst { inspect } = require('util'); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ciconst message = 'Read, Eval, Print Loop'; 321cb0ef41Sopenharmony_ciconst prompt_unix = 'node via Unix socket> '; 331cb0ef41Sopenharmony_ciconst prompt_tcp = 'node via TCP socket> '; 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci// Absolute path to test/fixtures/a.js 361cb0ef41Sopenharmony_ciconst moduleFilename = fixtures.path('a'); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci// Function for REPL to run 391cb0ef41Sopenharmony_ciglobal.invoke_me = function(arg) { 401cb0ef41Sopenharmony_ci return `invoked ${arg}`; 411cb0ef41Sopenharmony_ci}; 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci// Helpers for describing the expected output: 441cb0ef41Sopenharmony_ciconst kArrow = /^ *\^+ *$/; // Arrow of ^ pointing to syntax error location 451cb0ef41Sopenharmony_ciconst kSource = Symbol('kSource'); // Placeholder standing for input readback 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ciasync function runReplTests(socket, prompt, tests) { 481cb0ef41Sopenharmony_ci let lineBuffer = ''; 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci for (const { send, expect } of tests) { 511cb0ef41Sopenharmony_ci // Expect can be a single line or multiple lines 521cb0ef41Sopenharmony_ci const expectedLines = Array.isArray(expect) ? expect : [ expect ]; 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci console.error('out:', JSON.stringify(send)); 551cb0ef41Sopenharmony_ci socket.write(`${send}\n`); 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci for (let expectedLine of expectedLines) { 581cb0ef41Sopenharmony_ci // Special value: kSource refers to last sent source text 591cb0ef41Sopenharmony_ci if (expectedLine === kSource) 601cb0ef41Sopenharmony_ci expectedLine = send; 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci while (!lineBuffer.includes('\n')) { 631cb0ef41Sopenharmony_ci lineBuffer += await event(socket, expect); 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci // Cut away the initial prompt 661cb0ef41Sopenharmony_ci while (lineBuffer.startsWith(prompt)) 671cb0ef41Sopenharmony_ci lineBuffer = lineBuffer.substr(prompt.length); 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci // Allow to match partial text if no newline was received, because 701cb0ef41Sopenharmony_ci // sending newlines from the REPL itself would be redundant 711cb0ef41Sopenharmony_ci // (e.g. in the `... ` multiline prompt: The user already pressed 721cb0ef41Sopenharmony_ci // enter for that, so the REPL shouldn't do it again!). 731cb0ef41Sopenharmony_ci if (lineBuffer === expectedLine && !expectedLine.includes('\n')) 741cb0ef41Sopenharmony_ci lineBuffer += '\n'; 751cb0ef41Sopenharmony_ci } 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci // Split off the current line. 781cb0ef41Sopenharmony_ci const newlineOffset = lineBuffer.indexOf('\n'); 791cb0ef41Sopenharmony_ci let actualLine = lineBuffer.substr(0, newlineOffset); 801cb0ef41Sopenharmony_ci lineBuffer = lineBuffer.substr(newlineOffset + 1); 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ci // This might have been skipped in the loop above because the buffer 831cb0ef41Sopenharmony_ci // already contained a \n to begin with and the entire loop was skipped. 841cb0ef41Sopenharmony_ci while (actualLine.startsWith(prompt)) 851cb0ef41Sopenharmony_ci actualLine = actualLine.substr(prompt.length); 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci console.error('in:', JSON.stringify(actualLine)); 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci // Match a string directly, or a RegExp. 901cb0ef41Sopenharmony_ci if (typeof expectedLine === 'string') { 911cb0ef41Sopenharmony_ci assert.strictEqual(actualLine, expectedLine); 921cb0ef41Sopenharmony_ci } else { 931cb0ef41Sopenharmony_ci assert.match(actualLine, expectedLine); 941cb0ef41Sopenharmony_ci } 951cb0ef41Sopenharmony_ci } 961cb0ef41Sopenharmony_ci } 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_ci const remainder = socket.read(); 991cb0ef41Sopenharmony_ci assert(remainder === '' || remainder === null); 1001cb0ef41Sopenharmony_ci} 1011cb0ef41Sopenharmony_ci 1021cb0ef41Sopenharmony_ciconst unixTests = [ 1031cb0ef41Sopenharmony_ci { 1041cb0ef41Sopenharmony_ci send: '', 1051cb0ef41Sopenharmony_ci expect: '' 1061cb0ef41Sopenharmony_ci }, 1071cb0ef41Sopenharmony_ci { 1081cb0ef41Sopenharmony_ci send: 'message', 1091cb0ef41Sopenharmony_ci expect: `'${message}'` 1101cb0ef41Sopenharmony_ci }, 1111cb0ef41Sopenharmony_ci { 1121cb0ef41Sopenharmony_ci send: 'invoke_me(987)', 1131cb0ef41Sopenharmony_ci expect: '\'invoked 987\'' 1141cb0ef41Sopenharmony_ci }, 1151cb0ef41Sopenharmony_ci { 1161cb0ef41Sopenharmony_ci send: 'a = 12345', 1171cb0ef41Sopenharmony_ci expect: '12345' 1181cb0ef41Sopenharmony_ci }, 1191cb0ef41Sopenharmony_ci { 1201cb0ef41Sopenharmony_ci send: '{a:1}', 1211cb0ef41Sopenharmony_ci expect: '{ a: 1 }' 1221cb0ef41Sopenharmony_ci }, 1231cb0ef41Sopenharmony_ci]; 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_ciconst strictModeTests = [ 1261cb0ef41Sopenharmony_ci { 1271cb0ef41Sopenharmony_ci send: 'ref = 1', 1281cb0ef41Sopenharmony_ci expect: [/^Uncaught ReferenceError:\s/] 1291cb0ef41Sopenharmony_ci }, 1301cb0ef41Sopenharmony_ci]; 1311cb0ef41Sopenharmony_ci 1321cb0ef41Sopenharmony_ciconst errorTests = [ 1331cb0ef41Sopenharmony_ci // Uncaught error throws and prints out 1341cb0ef41Sopenharmony_ci { 1351cb0ef41Sopenharmony_ci send: 'throw new Error(\'test error\');', 1361cb0ef41Sopenharmony_ci expect: ['Uncaught Error: test error'] 1371cb0ef41Sopenharmony_ci }, 1381cb0ef41Sopenharmony_ci { 1391cb0ef41Sopenharmony_ci send: "throw { foo: 'bar' };", 1401cb0ef41Sopenharmony_ci expect: "Uncaught { foo: 'bar' }" 1411cb0ef41Sopenharmony_ci }, 1421cb0ef41Sopenharmony_ci // Common syntax error is treated as multiline command 1431cb0ef41Sopenharmony_ci { 1441cb0ef41Sopenharmony_ci send: 'function test_func() {', 1451cb0ef41Sopenharmony_ci expect: '... ' 1461cb0ef41Sopenharmony_ci }, 1471cb0ef41Sopenharmony_ci // You can recover with the .break command 1481cb0ef41Sopenharmony_ci { 1491cb0ef41Sopenharmony_ci send: '.break', 1501cb0ef41Sopenharmony_ci expect: '' 1511cb0ef41Sopenharmony_ci }, 1521cb0ef41Sopenharmony_ci // But passing the same string to eval() should throw 1531cb0ef41Sopenharmony_ci { 1541cb0ef41Sopenharmony_ci send: 'eval("function test_func() {")', 1551cb0ef41Sopenharmony_ci expect: [/^Uncaught SyntaxError: /] 1561cb0ef41Sopenharmony_ci }, 1571cb0ef41Sopenharmony_ci // Can handle multiline template literals 1581cb0ef41Sopenharmony_ci { 1591cb0ef41Sopenharmony_ci send: '`io.js', 1601cb0ef41Sopenharmony_ci expect: '... ' 1611cb0ef41Sopenharmony_ci }, 1621cb0ef41Sopenharmony_ci // Special REPL commands still available 1631cb0ef41Sopenharmony_ci { 1641cb0ef41Sopenharmony_ci send: '.break', 1651cb0ef41Sopenharmony_ci expect: '' 1661cb0ef41Sopenharmony_ci }, 1671cb0ef41Sopenharmony_ci // Template expressions 1681cb0ef41Sopenharmony_ci { 1691cb0ef41Sopenharmony_ci send: '`io.js ${"1.0"', 1701cb0ef41Sopenharmony_ci expect: '... ' 1711cb0ef41Sopenharmony_ci }, 1721cb0ef41Sopenharmony_ci { 1731cb0ef41Sopenharmony_ci send: '+ ".2"}`', 1741cb0ef41Sopenharmony_ci expect: '\'io.js 1.0.2\'' 1751cb0ef41Sopenharmony_ci }, 1761cb0ef41Sopenharmony_ci { 1771cb0ef41Sopenharmony_ci send: '`io.js ${', 1781cb0ef41Sopenharmony_ci expect: '... ' 1791cb0ef41Sopenharmony_ci }, 1801cb0ef41Sopenharmony_ci { 1811cb0ef41Sopenharmony_ci send: '"1.0" + ".2"}`', 1821cb0ef41Sopenharmony_ci expect: '\'io.js 1.0.2\'' 1831cb0ef41Sopenharmony_ci }, 1841cb0ef41Sopenharmony_ci // Dot prefix in multiline commands aren't treated as commands 1851cb0ef41Sopenharmony_ci { 1861cb0ef41Sopenharmony_ci send: '("a"', 1871cb0ef41Sopenharmony_ci expect: '... ' 1881cb0ef41Sopenharmony_ci }, 1891cb0ef41Sopenharmony_ci { 1901cb0ef41Sopenharmony_ci send: '.charAt(0))', 1911cb0ef41Sopenharmony_ci expect: '\'a\'' 1921cb0ef41Sopenharmony_ci }, 1931cb0ef41Sopenharmony_ci // Floating point numbers are not interpreted as REPL commands. 1941cb0ef41Sopenharmony_ci { 1951cb0ef41Sopenharmony_ci send: '.1234', 1961cb0ef41Sopenharmony_ci expect: '0.1234' 1971cb0ef41Sopenharmony_ci }, 1981cb0ef41Sopenharmony_ci // Floating point expressions are not interpreted as REPL commands 1991cb0ef41Sopenharmony_ci { 2001cb0ef41Sopenharmony_ci send: '.1+.1', 2011cb0ef41Sopenharmony_ci expect: '0.2' 2021cb0ef41Sopenharmony_ci }, 2031cb0ef41Sopenharmony_ci // Can parse valid JSON 2041cb0ef41Sopenharmony_ci { 2051cb0ef41Sopenharmony_ci send: 'JSON.parse(\'{"valid": "json"}\');', 2061cb0ef41Sopenharmony_ci expect: '{ valid: \'json\' }' 2071cb0ef41Sopenharmony_ci }, 2081cb0ef41Sopenharmony_ci // Invalid input to JSON.parse error is special case of syntax error, 2091cb0ef41Sopenharmony_ci // should throw 2101cb0ef41Sopenharmony_ci { 2111cb0ef41Sopenharmony_ci send: 'JSON.parse(\'{invalid: \\\'json\\\'}\');', 2121cb0ef41Sopenharmony_ci expect: [/^Uncaught SyntaxError: /] 2131cb0ef41Sopenharmony_ci }, 2141cb0ef41Sopenharmony_ci // End of input to JSON.parse error is special case of syntax error, 2151cb0ef41Sopenharmony_ci // should throw 2161cb0ef41Sopenharmony_ci { 2171cb0ef41Sopenharmony_ci send: 'JSON.parse(\'066\');', 2181cb0ef41Sopenharmony_ci expect: [/^Uncaught SyntaxError: /] 2191cb0ef41Sopenharmony_ci }, 2201cb0ef41Sopenharmony_ci // should throw 2211cb0ef41Sopenharmony_ci { 2221cb0ef41Sopenharmony_ci send: 'JSON.parse(\'{\');', 2231cb0ef41Sopenharmony_ci expect: [/^Uncaught SyntaxError: /] 2241cb0ef41Sopenharmony_ci }, 2251cb0ef41Sopenharmony_ci // invalid RegExps are a special case of syntax error, 2261cb0ef41Sopenharmony_ci // should throw 2271cb0ef41Sopenharmony_ci { 2281cb0ef41Sopenharmony_ci send: '/(/;', 2291cb0ef41Sopenharmony_ci expect: [ 2301cb0ef41Sopenharmony_ci kSource, 2311cb0ef41Sopenharmony_ci kArrow, 2321cb0ef41Sopenharmony_ci '', 2331cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 2341cb0ef41Sopenharmony_ci ] 2351cb0ef41Sopenharmony_ci }, 2361cb0ef41Sopenharmony_ci // invalid RegExp modifiers are a special case of syntax error, 2371cb0ef41Sopenharmony_ci // should throw (GH-4012) 2381cb0ef41Sopenharmony_ci { 2391cb0ef41Sopenharmony_ci send: 'new RegExp("foo", "wrong modifier");', 2401cb0ef41Sopenharmony_ci expect: [/^Uncaught SyntaxError: /] 2411cb0ef41Sopenharmony_ci }, 2421cb0ef41Sopenharmony_ci // Strict mode syntax errors should be caught (GH-5178) 2431cb0ef41Sopenharmony_ci { 2441cb0ef41Sopenharmony_ci send: '(function() { "use strict"; return 0755; })()', 2451cb0ef41Sopenharmony_ci expect: [ 2461cb0ef41Sopenharmony_ci kSource, 2471cb0ef41Sopenharmony_ci kArrow, 2481cb0ef41Sopenharmony_ci '', 2491cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 2501cb0ef41Sopenharmony_ci ] 2511cb0ef41Sopenharmony_ci }, 2521cb0ef41Sopenharmony_ci { 2531cb0ef41Sopenharmony_ci send: '(function(a, a, b) { "use strict"; return a + b + c; })()', 2541cb0ef41Sopenharmony_ci expect: [ 2551cb0ef41Sopenharmony_ci kSource, 2561cb0ef41Sopenharmony_ci kArrow, 2571cb0ef41Sopenharmony_ci '', 2581cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 2591cb0ef41Sopenharmony_ci ] 2601cb0ef41Sopenharmony_ci }, 2611cb0ef41Sopenharmony_ci { 2621cb0ef41Sopenharmony_ci send: '(function() { "use strict"; with (this) {} })()', 2631cb0ef41Sopenharmony_ci expect: [ 2641cb0ef41Sopenharmony_ci kSource, 2651cb0ef41Sopenharmony_ci kArrow, 2661cb0ef41Sopenharmony_ci '', 2671cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 2681cb0ef41Sopenharmony_ci ] 2691cb0ef41Sopenharmony_ci }, 2701cb0ef41Sopenharmony_ci { 2711cb0ef41Sopenharmony_ci send: '(function() { "use strict"; var x; delete x; })()', 2721cb0ef41Sopenharmony_ci expect: [ 2731cb0ef41Sopenharmony_ci kSource, 2741cb0ef41Sopenharmony_ci kArrow, 2751cb0ef41Sopenharmony_ci '', 2761cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 2771cb0ef41Sopenharmony_ci ] 2781cb0ef41Sopenharmony_ci }, 2791cb0ef41Sopenharmony_ci { 2801cb0ef41Sopenharmony_ci send: '(function() { "use strict"; eval = 17; })()', 2811cb0ef41Sopenharmony_ci expect: [ 2821cb0ef41Sopenharmony_ci kSource, 2831cb0ef41Sopenharmony_ci kArrow, 2841cb0ef41Sopenharmony_ci '', 2851cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 2861cb0ef41Sopenharmony_ci ] 2871cb0ef41Sopenharmony_ci }, 2881cb0ef41Sopenharmony_ci { 2891cb0ef41Sopenharmony_ci send: '(function() { "use strict"; if (true) function f() { } })()', 2901cb0ef41Sopenharmony_ci expect: [ 2911cb0ef41Sopenharmony_ci kSource, 2921cb0ef41Sopenharmony_ci kArrow, 2931cb0ef41Sopenharmony_ci '', 2941cb0ef41Sopenharmony_ci 'Uncaught:', 2951cb0ef41Sopenharmony_ci /^SyntaxError: /, 2961cb0ef41Sopenharmony_ci ] 2971cb0ef41Sopenharmony_ci }, 2981cb0ef41Sopenharmony_ci // Named functions can be used: 2991cb0ef41Sopenharmony_ci { 3001cb0ef41Sopenharmony_ci send: 'function blah() { return 1; }', 3011cb0ef41Sopenharmony_ci expect: 'undefined' 3021cb0ef41Sopenharmony_ci }, 3031cb0ef41Sopenharmony_ci { 3041cb0ef41Sopenharmony_ci send: 'blah()', 3051cb0ef41Sopenharmony_ci expect: '1' 3061cb0ef41Sopenharmony_ci }, 3071cb0ef41Sopenharmony_ci // Functions should not evaluate twice (#2773) 3081cb0ef41Sopenharmony_ci { 3091cb0ef41Sopenharmony_ci send: 'var I = [1,2,3,function() {}]; I.pop()', 3101cb0ef41Sopenharmony_ci expect: '[Function (anonymous)]' 3111cb0ef41Sopenharmony_ci }, 3121cb0ef41Sopenharmony_ci // Multiline object 3131cb0ef41Sopenharmony_ci { 3141cb0ef41Sopenharmony_ci send: '{ a: ', 3151cb0ef41Sopenharmony_ci expect: '... ' 3161cb0ef41Sopenharmony_ci }, 3171cb0ef41Sopenharmony_ci { 3181cb0ef41Sopenharmony_ci send: '1 }', 3191cb0ef41Sopenharmony_ci expect: '{ a: 1 }' 3201cb0ef41Sopenharmony_ci }, 3211cb0ef41Sopenharmony_ci // Multiline string-keyed object (e.g. JSON) 3221cb0ef41Sopenharmony_ci { 3231cb0ef41Sopenharmony_ci send: '{ "a": ', 3241cb0ef41Sopenharmony_ci expect: '... ' 3251cb0ef41Sopenharmony_ci }, 3261cb0ef41Sopenharmony_ci { 3271cb0ef41Sopenharmony_ci send: '1 }', 3281cb0ef41Sopenharmony_ci expect: '{ a: 1 }' 3291cb0ef41Sopenharmony_ci }, 3301cb0ef41Sopenharmony_ci // Multiline class with private member. 3311cb0ef41Sopenharmony_ci { 3321cb0ef41Sopenharmony_ci send: 'class Foo { #private = true ', 3331cb0ef41Sopenharmony_ci expect: '... ' 3341cb0ef41Sopenharmony_ci }, 3351cb0ef41Sopenharmony_ci // Class field with bigint. 3361cb0ef41Sopenharmony_ci { 3371cb0ef41Sopenharmony_ci send: 'num = 123456789n', 3381cb0ef41Sopenharmony_ci expect: '... ' 3391cb0ef41Sopenharmony_ci }, 3401cb0ef41Sopenharmony_ci // Static class features. 3411cb0ef41Sopenharmony_ci { 3421cb0ef41Sopenharmony_ci send: 'static foo = "bar" }', 3431cb0ef41Sopenharmony_ci expect: 'undefined' 3441cb0ef41Sopenharmony_ci }, 3451cb0ef41Sopenharmony_ci // Multiline anonymous function with comment 3461cb0ef41Sopenharmony_ci { 3471cb0ef41Sopenharmony_ci send: '(function() {', 3481cb0ef41Sopenharmony_ci expect: '... ' 3491cb0ef41Sopenharmony_ci }, 3501cb0ef41Sopenharmony_ci { 3511cb0ef41Sopenharmony_ci send: '// blah', 3521cb0ef41Sopenharmony_ci expect: '... ' 3531cb0ef41Sopenharmony_ci }, 3541cb0ef41Sopenharmony_ci { 3551cb0ef41Sopenharmony_ci send: 'return 1n;', 3561cb0ef41Sopenharmony_ci expect: '... ' 3571cb0ef41Sopenharmony_ci }, 3581cb0ef41Sopenharmony_ci { 3591cb0ef41Sopenharmony_ci send: '})()', 3601cb0ef41Sopenharmony_ci expect: '1n' 3611cb0ef41Sopenharmony_ci }, 3621cb0ef41Sopenharmony_ci // Multiline function call 3631cb0ef41Sopenharmony_ci { 3641cb0ef41Sopenharmony_ci send: 'function f(){}; f(f(1,', 3651cb0ef41Sopenharmony_ci expect: '... ' 3661cb0ef41Sopenharmony_ci }, 3671cb0ef41Sopenharmony_ci { 3681cb0ef41Sopenharmony_ci send: '2)', 3691cb0ef41Sopenharmony_ci expect: '... ' 3701cb0ef41Sopenharmony_ci }, 3711cb0ef41Sopenharmony_ci { 3721cb0ef41Sopenharmony_ci send: ')', 3731cb0ef41Sopenharmony_ci expect: 'undefined' 3741cb0ef41Sopenharmony_ci }, 3751cb0ef41Sopenharmony_ci // `npm` prompt error message. 3761cb0ef41Sopenharmony_ci { 3771cb0ef41Sopenharmony_ci send: 'npm install foobar', 3781cb0ef41Sopenharmony_ci expect: [ 3791cb0ef41Sopenharmony_ci 'npm should be run outside of the Node.js REPL, in your normal shell.', 3801cb0ef41Sopenharmony_ci '(Press Ctrl+D to exit.)', 3811cb0ef41Sopenharmony_ci ] 3821cb0ef41Sopenharmony_ci }, 3831cb0ef41Sopenharmony_ci { 3841cb0ef41Sopenharmony_ci send: '(function() {\n\nreturn 1;\n})()', 3851cb0ef41Sopenharmony_ci expect: '... ... ... 1' 3861cb0ef41Sopenharmony_ci }, 3871cb0ef41Sopenharmony_ci { 3881cb0ef41Sopenharmony_ci send: '{\n\na: 1\n}', 3891cb0ef41Sopenharmony_ci expect: '... ... ... { a: 1 }' 3901cb0ef41Sopenharmony_ci }, 3911cb0ef41Sopenharmony_ci { 3921cb0ef41Sopenharmony_ci send: 'url.format("http://google.com")', 3931cb0ef41Sopenharmony_ci expect: '\'http://google.com/\'' 3941cb0ef41Sopenharmony_ci }, 3951cb0ef41Sopenharmony_ci { 3961cb0ef41Sopenharmony_ci send: 'var path = 42; path', 3971cb0ef41Sopenharmony_ci expect: '42' 3981cb0ef41Sopenharmony_ci }, 3991cb0ef41Sopenharmony_ci // This makes sure that we don't print `undefined` when we actually print 4001cb0ef41Sopenharmony_ci // the error message 4011cb0ef41Sopenharmony_ci { 4021cb0ef41Sopenharmony_ci send: '.invalid_repl_command', 4031cb0ef41Sopenharmony_ci expect: 'Invalid REPL keyword' 4041cb0ef41Sopenharmony_ci }, 4051cb0ef41Sopenharmony_ci // This makes sure that we don't crash when we use an inherited property as 4061cb0ef41Sopenharmony_ci // a REPL command 4071cb0ef41Sopenharmony_ci { 4081cb0ef41Sopenharmony_ci send: '.toString', 4091cb0ef41Sopenharmony_ci expect: 'Invalid REPL keyword' 4101cb0ef41Sopenharmony_ci }, 4111cb0ef41Sopenharmony_ci // Fail when we are not inside a String and a line continuation is used 4121cb0ef41Sopenharmony_ci { 4131cb0ef41Sopenharmony_ci send: '[] \\', 4141cb0ef41Sopenharmony_ci expect: [ 4151cb0ef41Sopenharmony_ci kSource, 4161cb0ef41Sopenharmony_ci kArrow, 4171cb0ef41Sopenharmony_ci '', 4181cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 4191cb0ef41Sopenharmony_ci ] 4201cb0ef41Sopenharmony_ci }, 4211cb0ef41Sopenharmony_ci // Do not fail when a String is created with line continuation 4221cb0ef41Sopenharmony_ci { 4231cb0ef41Sopenharmony_ci send: '\'the\\\nfourth\\\neye\'', 4241cb0ef41Sopenharmony_ci expect: ['... ... \'thefourtheye\''] 4251cb0ef41Sopenharmony_ci }, 4261cb0ef41Sopenharmony_ci // Don't fail when a partial String is created and line continuation is used 4271cb0ef41Sopenharmony_ci // with whitespace characters at the end of the string. We are to ignore it. 4281cb0ef41Sopenharmony_ci // This test is to make sure that we properly remove the whitespace 4291cb0ef41Sopenharmony_ci // characters at the end of line, unlike the buggy `trimWhitespace` function 4301cb0ef41Sopenharmony_ci { 4311cb0ef41Sopenharmony_ci send: ' \t .break \t ', 4321cb0ef41Sopenharmony_ci expect: '' 4331cb0ef41Sopenharmony_ci }, 4341cb0ef41Sopenharmony_ci // Multiline strings preserve whitespace characters in them 4351cb0ef41Sopenharmony_ci { 4361cb0ef41Sopenharmony_ci send: '\'the \\\n fourth\t\t\\\n eye \'', 4371cb0ef41Sopenharmony_ci expect: '... ... \'the fourth\\t\\t eye \'' 4381cb0ef41Sopenharmony_ci }, 4391cb0ef41Sopenharmony_ci // More than one multiline strings also should preserve whitespace chars 4401cb0ef41Sopenharmony_ci { 4411cb0ef41Sopenharmony_ci send: '\'the \\\n fourth\' + \'\t\t\\\n eye \'', 4421cb0ef41Sopenharmony_ci expect: '... ... \'the fourth\\t\\t eye \'' 4431cb0ef41Sopenharmony_ci }, 4441cb0ef41Sopenharmony_ci // using REPL commands within a string literal should still work 4451cb0ef41Sopenharmony_ci { 4461cb0ef41Sopenharmony_ci send: '\'\\\n.break', 4471cb0ef41Sopenharmony_ci expect: '... ' + prompt_unix 4481cb0ef41Sopenharmony_ci }, 4491cb0ef41Sopenharmony_ci // Using REPL command "help" within a string literal should still work 4501cb0ef41Sopenharmony_ci { 4511cb0ef41Sopenharmony_ci send: '\'thefourth\\\n.help\neye\'', 4521cb0ef41Sopenharmony_ci expect: [ 4531cb0ef41Sopenharmony_ci /\.break/, 4541cb0ef41Sopenharmony_ci /\.clear/, 4551cb0ef41Sopenharmony_ci /\.exit/, 4561cb0ef41Sopenharmony_ci /\.help/, 4571cb0ef41Sopenharmony_ci /\.load/, 4581cb0ef41Sopenharmony_ci /\.save/, 4591cb0ef41Sopenharmony_ci '', 4601cb0ef41Sopenharmony_ci 'Press Ctrl+C to abort current expression, Ctrl+D to exit the REPL', 4611cb0ef41Sopenharmony_ci /'thefourtheye'/, 4621cb0ef41Sopenharmony_ci ] 4631cb0ef41Sopenharmony_ci }, 4641cb0ef41Sopenharmony_ci // Check for wrapped objects. 4651cb0ef41Sopenharmony_ci { 4661cb0ef41Sopenharmony_ci send: '{ a: 1 }.a', // ({ a: 1 }.a); 4671cb0ef41Sopenharmony_ci expect: '1' 4681cb0ef41Sopenharmony_ci }, 4691cb0ef41Sopenharmony_ci { 4701cb0ef41Sopenharmony_ci send: '{ a: 1 }.a;', // { a: 1 }.a; 4711cb0ef41Sopenharmony_ci expect: [ 4721cb0ef41Sopenharmony_ci kSource, 4731cb0ef41Sopenharmony_ci kArrow, 4741cb0ef41Sopenharmony_ci '', 4751cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 4761cb0ef41Sopenharmony_ci ] 4771cb0ef41Sopenharmony_ci }, 4781cb0ef41Sopenharmony_ci { 4791cb0ef41Sopenharmony_ci send: '{ a: 1 }["a"] === 1', // ({ a: 1 }['a'] === 1); 4801cb0ef41Sopenharmony_ci expect: 'true' 4811cb0ef41Sopenharmony_ci }, 4821cb0ef41Sopenharmony_ci { 4831cb0ef41Sopenharmony_ci send: '{ a: 1 }["a"] === 1;', // { a: 1 }; ['a'] === 1; 4841cb0ef41Sopenharmony_ci expect: 'false' 4851cb0ef41Sopenharmony_ci }, 4861cb0ef41Sopenharmony_ci // Empty lines in the REPL should be allowed 4871cb0ef41Sopenharmony_ci { 4881cb0ef41Sopenharmony_ci send: '\n\r\n\r\n', 4891cb0ef41Sopenharmony_ci expect: '' 4901cb0ef41Sopenharmony_ci }, 4911cb0ef41Sopenharmony_ci // Empty lines in the string literals should not affect the string 4921cb0ef41Sopenharmony_ci { 4931cb0ef41Sopenharmony_ci send: '\'the\\\n\\\nfourtheye\'\n', 4941cb0ef41Sopenharmony_ci expect: '... ... \'thefourtheye\'' 4951cb0ef41Sopenharmony_ci }, 4961cb0ef41Sopenharmony_ci // Regression test for https://github.com/nodejs/node/issues/597 4971cb0ef41Sopenharmony_ci { 4981cb0ef41Sopenharmony_ci send: '/(.)(.)(.)(.)(.)(.)(.)(.)(.)/.test(\'123456789\')\n', 4991cb0ef41Sopenharmony_ci expect: 'true' 5001cb0ef41Sopenharmony_ci }, 5011cb0ef41Sopenharmony_ci // The following test's result depends on the RegExp's match from the above 5021cb0ef41Sopenharmony_ci { 5031cb0ef41Sopenharmony_ci send: 'RegExp.$1\nRegExp.$2\nRegExp.$3\nRegExp.$4\nRegExp.$5\n' + 5041cb0ef41Sopenharmony_ci 'RegExp.$6\nRegExp.$7\nRegExp.$8\nRegExp.$9\n', 5051cb0ef41Sopenharmony_ci expect: ['\'1\'', '\'2\'', '\'3\'', '\'4\'', '\'5\'', '\'6\'', 5061cb0ef41Sopenharmony_ci '\'7\'', '\'8\'', '\'9\''] 5071cb0ef41Sopenharmony_ci }, 5081cb0ef41Sopenharmony_ci // Regression tests for https://github.com/nodejs/node/issues/2749 5091cb0ef41Sopenharmony_ci { 5101cb0ef41Sopenharmony_ci send: 'function x() {\nreturn \'\\n\';\n }', 5111cb0ef41Sopenharmony_ci expect: '... ... undefined' 5121cb0ef41Sopenharmony_ci }, 5131cb0ef41Sopenharmony_ci { 5141cb0ef41Sopenharmony_ci send: 'function x() {\nreturn \'\\\\\';\n }', 5151cb0ef41Sopenharmony_ci expect: '... ... undefined' 5161cb0ef41Sopenharmony_ci }, 5171cb0ef41Sopenharmony_ci // Regression tests for https://github.com/nodejs/node/issues/3421 5181cb0ef41Sopenharmony_ci { 5191cb0ef41Sopenharmony_ci send: 'function x() {\n//\'\n }', 5201cb0ef41Sopenharmony_ci expect: '... ... undefined' 5211cb0ef41Sopenharmony_ci }, 5221cb0ef41Sopenharmony_ci { 5231cb0ef41Sopenharmony_ci send: 'function x() {\n//"\n }', 5241cb0ef41Sopenharmony_ci expect: '... ... undefined' 5251cb0ef41Sopenharmony_ci }, 5261cb0ef41Sopenharmony_ci { 5271cb0ef41Sopenharmony_ci send: 'function x() {//\'\n }', 5281cb0ef41Sopenharmony_ci expect: '... undefined' 5291cb0ef41Sopenharmony_ci }, 5301cb0ef41Sopenharmony_ci { 5311cb0ef41Sopenharmony_ci send: 'function x() {//"\n }', 5321cb0ef41Sopenharmony_ci expect: '... undefined' 5331cb0ef41Sopenharmony_ci }, 5341cb0ef41Sopenharmony_ci { 5351cb0ef41Sopenharmony_ci send: 'function x() {\nvar i = "\'";\n }', 5361cb0ef41Sopenharmony_ci expect: '... ... undefined' 5371cb0ef41Sopenharmony_ci }, 5381cb0ef41Sopenharmony_ci { 5391cb0ef41Sopenharmony_ci send: 'function x(/*optional*/) {}', 5401cb0ef41Sopenharmony_ci expect: 'undefined' 5411cb0ef41Sopenharmony_ci }, 5421cb0ef41Sopenharmony_ci { 5431cb0ef41Sopenharmony_ci send: 'function x(/* // 5 */) {}', 5441cb0ef41Sopenharmony_ci expect: 'undefined' 5451cb0ef41Sopenharmony_ci }, 5461cb0ef41Sopenharmony_ci { 5471cb0ef41Sopenharmony_ci send: '// /* 5 */', 5481cb0ef41Sopenharmony_ci expect: 'undefined' 5491cb0ef41Sopenharmony_ci }, 5501cb0ef41Sopenharmony_ci { 5511cb0ef41Sopenharmony_ci send: '"//"', 5521cb0ef41Sopenharmony_ci expect: '\'//\'' 5531cb0ef41Sopenharmony_ci }, 5541cb0ef41Sopenharmony_ci { 5551cb0ef41Sopenharmony_ci send: '"data /*with*/ comment"', 5561cb0ef41Sopenharmony_ci expect: '\'data /*with*/ comment\'' 5571cb0ef41Sopenharmony_ci }, 5581cb0ef41Sopenharmony_ci { 5591cb0ef41Sopenharmony_ci send: 'function x(/*fn\'s optional params*/) {}', 5601cb0ef41Sopenharmony_ci expect: 'undefined' 5611cb0ef41Sopenharmony_ci }, 5621cb0ef41Sopenharmony_ci { 5631cb0ef41Sopenharmony_ci send: '/* \'\n"\n\'"\'\n*/', 5641cb0ef41Sopenharmony_ci expect: '... ... ... undefined' 5651cb0ef41Sopenharmony_ci }, 5661cb0ef41Sopenharmony_ci // REPL should get a normal require() function, not one that allows 5671cb0ef41Sopenharmony_ci // access to internal modules without the --expose-internals flag. 5681cb0ef41Sopenharmony_ci { 5691cb0ef41Sopenharmony_ci send: 'require("internal/repl")', 5701cb0ef41Sopenharmony_ci expect: [ 5711cb0ef41Sopenharmony_ci /^Uncaught Error: Cannot find module 'internal\/repl'/, 5721cb0ef41Sopenharmony_ci /^Require stack:/, 5731cb0ef41Sopenharmony_ci /^- <repl>/, 5741cb0ef41Sopenharmony_ci /^ {4}at .*/, 5751cb0ef41Sopenharmony_ci /^ {4}at .*/, 5761cb0ef41Sopenharmony_ci /^ {4}at .*/, 5771cb0ef41Sopenharmony_ci /^ {4}at .*/, 5781cb0ef41Sopenharmony_ci " code: 'MODULE_NOT_FOUND',", 5791cb0ef41Sopenharmony_ci " requireStack: [ '<repl>' ]", 5801cb0ef41Sopenharmony_ci '}', 5811cb0ef41Sopenharmony_ci ] 5821cb0ef41Sopenharmony_ci }, 5831cb0ef41Sopenharmony_ci // REPL should handle quotes within regexp literal in multiline mode 5841cb0ef41Sopenharmony_ci { 5851cb0ef41Sopenharmony_ci send: "function x(s) {\nreturn s.replace(/'/,'');\n}", 5861cb0ef41Sopenharmony_ci expect: '... ... undefined' 5871cb0ef41Sopenharmony_ci }, 5881cb0ef41Sopenharmony_ci { 5891cb0ef41Sopenharmony_ci send: "function x(s) {\nreturn s.replace(/'/,'');\n}", 5901cb0ef41Sopenharmony_ci expect: '... ... undefined' 5911cb0ef41Sopenharmony_ci }, 5921cb0ef41Sopenharmony_ci { 5931cb0ef41Sopenharmony_ci send: 'function x(s) {\nreturn s.replace(/"/,"");\n}', 5941cb0ef41Sopenharmony_ci expect: '... ... undefined' 5951cb0ef41Sopenharmony_ci }, 5961cb0ef41Sopenharmony_ci { 5971cb0ef41Sopenharmony_ci send: 'function x(s) {\nreturn s.replace(/.*/,"");\n}', 5981cb0ef41Sopenharmony_ci expect: '... ... undefined' 5991cb0ef41Sopenharmony_ci }, 6001cb0ef41Sopenharmony_ci { 6011cb0ef41Sopenharmony_ci send: '{ var x = 4; }', 6021cb0ef41Sopenharmony_ci expect: 'undefined' 6031cb0ef41Sopenharmony_ci }, 6041cb0ef41Sopenharmony_ci // Illegal token is not recoverable outside string literal, RegExp literal, 6051cb0ef41Sopenharmony_ci // or block comment. https://github.com/nodejs/node/issues/3611 6061cb0ef41Sopenharmony_ci { 6071cb0ef41Sopenharmony_ci send: 'a = 3.5e', 6081cb0ef41Sopenharmony_ci expect: [ 6091cb0ef41Sopenharmony_ci kSource, 6101cb0ef41Sopenharmony_ci kArrow, 6111cb0ef41Sopenharmony_ci '', 6121cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 6131cb0ef41Sopenharmony_ci ] 6141cb0ef41Sopenharmony_ci }, 6151cb0ef41Sopenharmony_ci // Mitigate https://github.com/nodejs/node/issues/548 6161cb0ef41Sopenharmony_ci { 6171cb0ef41Sopenharmony_ci send: 'function name(){ return "node"; };name()', 6181cb0ef41Sopenharmony_ci expect: '\'node\'' 6191cb0ef41Sopenharmony_ci }, 6201cb0ef41Sopenharmony_ci { 6211cb0ef41Sopenharmony_ci send: 'function name(){ return "nodejs"; };name()', 6221cb0ef41Sopenharmony_ci expect: '\'nodejs\'' 6231cb0ef41Sopenharmony_ci }, 6241cb0ef41Sopenharmony_ci // Avoid emitting repl:line-number for SyntaxError 6251cb0ef41Sopenharmony_ci { 6261cb0ef41Sopenharmony_ci send: 'a = 3.5e', 6271cb0ef41Sopenharmony_ci expect: [ 6281cb0ef41Sopenharmony_ci kSource, 6291cb0ef41Sopenharmony_ci kArrow, 6301cb0ef41Sopenharmony_ci '', 6311cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 6321cb0ef41Sopenharmony_ci ] 6331cb0ef41Sopenharmony_ci }, 6341cb0ef41Sopenharmony_ci // Avoid emitting stack trace 6351cb0ef41Sopenharmony_ci { 6361cb0ef41Sopenharmony_ci send: 'a = 3.5e', 6371cb0ef41Sopenharmony_ci expect: [ 6381cb0ef41Sopenharmony_ci kSource, 6391cb0ef41Sopenharmony_ci kArrow, 6401cb0ef41Sopenharmony_ci '', 6411cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 6421cb0ef41Sopenharmony_ci ] 6431cb0ef41Sopenharmony_ci }, 6441cb0ef41Sopenharmony_ci 6451cb0ef41Sopenharmony_ci // https://github.com/nodejs/node/issues/9850 6461cb0ef41Sopenharmony_ci { 6471cb0ef41Sopenharmony_ci send: 'function* foo() {}; foo().next();', 6481cb0ef41Sopenharmony_ci expect: '{ value: undefined, done: true }' 6491cb0ef41Sopenharmony_ci }, 6501cb0ef41Sopenharmony_ci 6511cb0ef41Sopenharmony_ci { 6521cb0ef41Sopenharmony_ci send: 'function *foo() {}; foo().next();', 6531cb0ef41Sopenharmony_ci expect: '{ value: undefined, done: true }' 6541cb0ef41Sopenharmony_ci }, 6551cb0ef41Sopenharmony_ci 6561cb0ef41Sopenharmony_ci { 6571cb0ef41Sopenharmony_ci send: 'function*foo() {}; foo().next();', 6581cb0ef41Sopenharmony_ci expect: '{ value: undefined, done: true }' 6591cb0ef41Sopenharmony_ci }, 6601cb0ef41Sopenharmony_ci 6611cb0ef41Sopenharmony_ci { 6621cb0ef41Sopenharmony_ci send: 'function * foo() {}; foo().next()', 6631cb0ef41Sopenharmony_ci expect: '{ value: undefined, done: true }' 6641cb0ef41Sopenharmony_ci }, 6651cb0ef41Sopenharmony_ci 6661cb0ef41Sopenharmony_ci // https://github.com/nodejs/node/issues/9300 6671cb0ef41Sopenharmony_ci { 6681cb0ef41Sopenharmony_ci send: 'function foo() {\nvar bar = 1 / 1; // "/"\n}', 6691cb0ef41Sopenharmony_ci expect: '... ... undefined' 6701cb0ef41Sopenharmony_ci }, 6711cb0ef41Sopenharmony_ci 6721cb0ef41Sopenharmony_ci { 6731cb0ef41Sopenharmony_ci send: '(function() {\nreturn /foo/ / /bar/;\n}())', 6741cb0ef41Sopenharmony_ci expect: '... ... NaN' 6751cb0ef41Sopenharmony_ci }, 6761cb0ef41Sopenharmony_ci 6771cb0ef41Sopenharmony_ci { 6781cb0ef41Sopenharmony_ci send: '(function() {\nif (false) {} /bar"/;\n}())', 6791cb0ef41Sopenharmony_ci expect: '... ... undefined' 6801cb0ef41Sopenharmony_ci }, 6811cb0ef41Sopenharmony_ci 6821cb0ef41Sopenharmony_ci // https://github.com/nodejs/node/issues/16483 6831cb0ef41Sopenharmony_ci { 6841cb0ef41Sopenharmony_ci send: 'new Proxy({x:42}, {get(){throw null}});', 6851cb0ef41Sopenharmony_ci expect: 'Proxy [ { x: 42 }, { get: [Function: get] } ]' 6861cb0ef41Sopenharmony_ci }, 6871cb0ef41Sopenharmony_ci { 6881cb0ef41Sopenharmony_ci send: 'repl.writer.options.showProxy = false, new Proxy({x:42}, {});', 6891cb0ef41Sopenharmony_ci expect: '{ x: 42 }' 6901cb0ef41Sopenharmony_ci }, 6911cb0ef41Sopenharmony_ci 6921cb0ef41Sopenharmony_ci // Newline within template string maintains whitespace. 6931cb0ef41Sopenharmony_ci { 6941cb0ef41Sopenharmony_ci send: '`foo \n`', 6951cb0ef41Sopenharmony_ci expect: '... \'foo \\n\'' 6961cb0ef41Sopenharmony_ci }, 6971cb0ef41Sopenharmony_ci // Whitespace is not evaluated. 6981cb0ef41Sopenharmony_ci { 6991cb0ef41Sopenharmony_ci send: ' \t \n', 7001cb0ef41Sopenharmony_ci expect: 'undefined' 7011cb0ef41Sopenharmony_ci }, 7021cb0ef41Sopenharmony_ci // Do not parse `...[]` as a REPL keyword 7031cb0ef41Sopenharmony_ci { 7041cb0ef41Sopenharmony_ci send: '...[]', 7051cb0ef41Sopenharmony_ci expect: [ 7061cb0ef41Sopenharmony_ci kSource, 7071cb0ef41Sopenharmony_ci kArrow, 7081cb0ef41Sopenharmony_ci '', 7091cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 7101cb0ef41Sopenharmony_ci ] 7111cb0ef41Sopenharmony_ci }, 7121cb0ef41Sopenharmony_ci // Bring back the repl to prompt 7131cb0ef41Sopenharmony_ci { 7141cb0ef41Sopenharmony_ci send: '.break', 7151cb0ef41Sopenharmony_ci expect: '' 7161cb0ef41Sopenharmony_ci }, 7171cb0ef41Sopenharmony_ci { 7181cb0ef41Sopenharmony_ci send: 'console.log("Missing comma in arg list" process.version)', 7191cb0ef41Sopenharmony_ci expect: [ 7201cb0ef41Sopenharmony_ci kSource, 7211cb0ef41Sopenharmony_ci kArrow, 7221cb0ef41Sopenharmony_ci '', 7231cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 7241cb0ef41Sopenharmony_ci ] 7251cb0ef41Sopenharmony_ci }, 7261cb0ef41Sopenharmony_ci { 7271cb0ef41Sopenharmony_ci send: 'x = {\nfield\n{', 7281cb0ef41Sopenharmony_ci expect: [ 7291cb0ef41Sopenharmony_ci '... ... {', 7301cb0ef41Sopenharmony_ci kArrow, 7311cb0ef41Sopenharmony_ci '', 7321cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 7331cb0ef41Sopenharmony_ci ] 7341cb0ef41Sopenharmony_ci }, 7351cb0ef41Sopenharmony_ci { 7361cb0ef41Sopenharmony_ci send: '(2 + 3))', 7371cb0ef41Sopenharmony_ci expect: [ 7381cb0ef41Sopenharmony_ci kSource, 7391cb0ef41Sopenharmony_ci kArrow, 7401cb0ef41Sopenharmony_ci '', 7411cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 7421cb0ef41Sopenharmony_ci ] 7431cb0ef41Sopenharmony_ci }, 7441cb0ef41Sopenharmony_ci { 7451cb0ef41Sopenharmony_ci send: 'if (typeof process === "object"); {', 7461cb0ef41Sopenharmony_ci expect: '... ' 7471cb0ef41Sopenharmony_ci }, 7481cb0ef41Sopenharmony_ci { 7491cb0ef41Sopenharmony_ci send: 'console.log("process is defined");', 7501cb0ef41Sopenharmony_ci expect: '... ' 7511cb0ef41Sopenharmony_ci }, 7521cb0ef41Sopenharmony_ci { 7531cb0ef41Sopenharmony_ci send: '} else {', 7541cb0ef41Sopenharmony_ci expect: [ 7551cb0ef41Sopenharmony_ci kSource, 7561cb0ef41Sopenharmony_ci kArrow, 7571cb0ef41Sopenharmony_ci '', 7581cb0ef41Sopenharmony_ci /^Uncaught SyntaxError: /, 7591cb0ef41Sopenharmony_ci ] 7601cb0ef41Sopenharmony_ci }, 7611cb0ef41Sopenharmony_ci { 7621cb0ef41Sopenharmony_ci send: 'console', 7631cb0ef41Sopenharmony_ci expect: [ 7641cb0ef41Sopenharmony_ci 'Object [console] {', 7651cb0ef41Sopenharmony_ci ' log: [Function: log],', 7661cb0ef41Sopenharmony_ci ' warn: [Function: warn],', 7671cb0ef41Sopenharmony_ci ' dir: [Function: dir],', 7681cb0ef41Sopenharmony_ci ' time: [Function: time],', 7691cb0ef41Sopenharmony_ci ' timeEnd: [Function: timeEnd],', 7701cb0ef41Sopenharmony_ci ' timeLog: [Function: timeLog],', 7711cb0ef41Sopenharmony_ci ' trace: [Function: trace],', 7721cb0ef41Sopenharmony_ci ' assert: [Function: assert],', 7731cb0ef41Sopenharmony_ci ' clear: [Function: clear],', 7741cb0ef41Sopenharmony_ci ' count: [Function: count],', 7751cb0ef41Sopenharmony_ci ' countReset: [Function: countReset],', 7761cb0ef41Sopenharmony_ci ' group: [Function: group],', 7771cb0ef41Sopenharmony_ci ' groupEnd: [Function: groupEnd],', 7781cb0ef41Sopenharmony_ci ' table: [Function: table],', 7791cb0ef41Sopenharmony_ci / {2}debug: \[Function: (debug|log)],/, 7801cb0ef41Sopenharmony_ci / {2}info: \[Function: (info|log)],/, 7811cb0ef41Sopenharmony_ci / {2}dirxml: \[Function: (dirxml|log)],/, 7821cb0ef41Sopenharmony_ci / {2}error: \[Function: (error|warn)],/, 7831cb0ef41Sopenharmony_ci / {2}groupCollapsed: \[Function: (groupCollapsed|group)],/, 7841cb0ef41Sopenharmony_ci / {2}Console: \[Function: Console],?/, 7851cb0ef41Sopenharmony_ci ...process.features.inspector ? [ 7861cb0ef41Sopenharmony_ci ' profile: [Function: profile],', 7871cb0ef41Sopenharmony_ci ' profileEnd: [Function: profileEnd],', 7881cb0ef41Sopenharmony_ci ' timeStamp: [Function: timeStamp],', 7891cb0ef41Sopenharmony_ci ' context: [Function: context]', 7901cb0ef41Sopenharmony_ci ] : [], 7911cb0ef41Sopenharmony_ci '}', 7921cb0ef41Sopenharmony_ci ] 7931cb0ef41Sopenharmony_ci }, 7941cb0ef41Sopenharmony_ci]; 7951cb0ef41Sopenharmony_ci 7961cb0ef41Sopenharmony_ciconst tcpTests = [ 7971cb0ef41Sopenharmony_ci { 7981cb0ef41Sopenharmony_ci send: '', 7991cb0ef41Sopenharmony_ci expect: '' 8001cb0ef41Sopenharmony_ci }, 8011cb0ef41Sopenharmony_ci { 8021cb0ef41Sopenharmony_ci send: 'invoke_me(333)', 8031cb0ef41Sopenharmony_ci expect: '\'invoked 333\'' 8041cb0ef41Sopenharmony_ci }, 8051cb0ef41Sopenharmony_ci { 8061cb0ef41Sopenharmony_ci send: 'a += 1', 8071cb0ef41Sopenharmony_ci expect: '12346' 8081cb0ef41Sopenharmony_ci }, 8091cb0ef41Sopenharmony_ci { 8101cb0ef41Sopenharmony_ci send: `require(${JSON.stringify(moduleFilename)}).number`, 8111cb0ef41Sopenharmony_ci expect: '42' 8121cb0ef41Sopenharmony_ci }, 8131cb0ef41Sopenharmony_ci { 8141cb0ef41Sopenharmony_ci send: 'import comeOn from \'fhqwhgads\'', 8151cb0ef41Sopenharmony_ci expect: [ 8161cb0ef41Sopenharmony_ci kSource, 8171cb0ef41Sopenharmony_ci kArrow, 8181cb0ef41Sopenharmony_ci '', 8191cb0ef41Sopenharmony_ci 'Uncaught:', 8201cb0ef41Sopenharmony_ci 'SyntaxError: Cannot use import statement inside the Node.js REPL, \ 8211cb0ef41Sopenharmony_cialternatively use dynamic import: const { default: comeOn } = await import("fhqwhgads");', 8221cb0ef41Sopenharmony_ci ] 8231cb0ef41Sopenharmony_ci }, 8241cb0ef41Sopenharmony_ci { 8251cb0ef41Sopenharmony_ci send: 'import { export1, export2 } from "module-name"', 8261cb0ef41Sopenharmony_ci expect: [ 8271cb0ef41Sopenharmony_ci kSource, 8281cb0ef41Sopenharmony_ci kArrow, 8291cb0ef41Sopenharmony_ci '', 8301cb0ef41Sopenharmony_ci 'Uncaught:', 8311cb0ef41Sopenharmony_ci 'SyntaxError: Cannot use import statement inside the Node.js REPL, \ 8321cb0ef41Sopenharmony_cialternatively use dynamic import: const { export1, export2 } = await import("module-name");', 8331cb0ef41Sopenharmony_ci ] 8341cb0ef41Sopenharmony_ci }, 8351cb0ef41Sopenharmony_ci { 8361cb0ef41Sopenharmony_ci send: 'import * as name from "module-name";', 8371cb0ef41Sopenharmony_ci expect: [ 8381cb0ef41Sopenharmony_ci kSource, 8391cb0ef41Sopenharmony_ci kArrow, 8401cb0ef41Sopenharmony_ci '', 8411cb0ef41Sopenharmony_ci 'Uncaught:', 8421cb0ef41Sopenharmony_ci 'SyntaxError: Cannot use import statement inside the Node.js REPL, \ 8431cb0ef41Sopenharmony_cialternatively use dynamic import: const name = await import("module-name");', 8441cb0ef41Sopenharmony_ci ] 8451cb0ef41Sopenharmony_ci }, 8461cb0ef41Sopenharmony_ci { 8471cb0ef41Sopenharmony_ci send: 'import "module-name";', 8481cb0ef41Sopenharmony_ci expect: [ 8491cb0ef41Sopenharmony_ci kSource, 8501cb0ef41Sopenharmony_ci kArrow, 8511cb0ef41Sopenharmony_ci '', 8521cb0ef41Sopenharmony_ci 'Uncaught:', 8531cb0ef41Sopenharmony_ci 'SyntaxError: Cannot use import statement inside the Node.js REPL, \ 8541cb0ef41Sopenharmony_cialternatively use dynamic import: await import("module-name");', 8551cb0ef41Sopenharmony_ci ] 8561cb0ef41Sopenharmony_ci }, 8571cb0ef41Sopenharmony_ci { 8581cb0ef41Sopenharmony_ci send: 'import { export1 as localName1, export2 } from "bar";', 8591cb0ef41Sopenharmony_ci expect: [ 8601cb0ef41Sopenharmony_ci kSource, 8611cb0ef41Sopenharmony_ci kArrow, 8621cb0ef41Sopenharmony_ci '', 8631cb0ef41Sopenharmony_ci 'Uncaught:', 8641cb0ef41Sopenharmony_ci 'SyntaxError: Cannot use import statement inside the Node.js REPL, \ 8651cb0ef41Sopenharmony_cialternatively use dynamic import: const { export1: localName1, export2 } = await import("bar");', 8661cb0ef41Sopenharmony_ci ] 8671cb0ef41Sopenharmony_ci }, 8681cb0ef41Sopenharmony_ci { 8691cb0ef41Sopenharmony_ci send: 'import alias from "bar";', 8701cb0ef41Sopenharmony_ci expect: [ 8711cb0ef41Sopenharmony_ci kSource, 8721cb0ef41Sopenharmony_ci kArrow, 8731cb0ef41Sopenharmony_ci '', 8741cb0ef41Sopenharmony_ci 'Uncaught:', 8751cb0ef41Sopenharmony_ci 'SyntaxError: Cannot use import statement inside the Node.js REPL, \ 8761cb0ef41Sopenharmony_cialternatively use dynamic import: const { default: alias } = await import("bar");', 8771cb0ef41Sopenharmony_ci ] 8781cb0ef41Sopenharmony_ci }, 8791cb0ef41Sopenharmony_ci { 8801cb0ef41Sopenharmony_ci send: 'import alias, {namedExport} from "bar";', 8811cb0ef41Sopenharmony_ci expect: [ 8821cb0ef41Sopenharmony_ci kSource, 8831cb0ef41Sopenharmony_ci kArrow, 8841cb0ef41Sopenharmony_ci '', 8851cb0ef41Sopenharmony_ci 'Uncaught:', 8861cb0ef41Sopenharmony_ci 'SyntaxError: Cannot use import statement inside the Node.js REPL, \ 8871cb0ef41Sopenharmony_cialternatively use dynamic import: const { default: alias, namedExport } = await import("bar");', 8881cb0ef41Sopenharmony_ci ] 8891cb0ef41Sopenharmony_ci }, 8901cb0ef41Sopenharmony_ci]; 8911cb0ef41Sopenharmony_ci 8921cb0ef41Sopenharmony_ci(async function() { 8931cb0ef41Sopenharmony_ci { 8941cb0ef41Sopenharmony_ci const [ socket, replServer ] = await startUnixRepl(); 8951cb0ef41Sopenharmony_ci 8961cb0ef41Sopenharmony_ci await runReplTests(socket, prompt_unix, unixTests); 8971cb0ef41Sopenharmony_ci await runReplTests(socket, prompt_unix, errorTests); 8981cb0ef41Sopenharmony_ci replServer.replMode = repl.REPL_MODE_STRICT; 8991cb0ef41Sopenharmony_ci await runReplTests(socket, prompt_unix, strictModeTests); 9001cb0ef41Sopenharmony_ci 9011cb0ef41Sopenharmony_ci socket.end(); 9021cb0ef41Sopenharmony_ci } 9031cb0ef41Sopenharmony_ci { 9041cb0ef41Sopenharmony_ci const [ socket ] = await startTCPRepl(); 9051cb0ef41Sopenharmony_ci 9061cb0ef41Sopenharmony_ci await runReplTests(socket, prompt_tcp, tcpTests); 9071cb0ef41Sopenharmony_ci 9081cb0ef41Sopenharmony_ci socket.end(); 9091cb0ef41Sopenharmony_ci } 9101cb0ef41Sopenharmony_ci common.allowGlobals(global.invoke_me, global.message, global.a, global.blah, 9111cb0ef41Sopenharmony_ci global.I, global.f, global.path, global.x, global.name, global.foo); 9121cb0ef41Sopenharmony_ci})().then(common.mustCall()); 9131cb0ef41Sopenharmony_ci 9141cb0ef41Sopenharmony_cifunction startTCPRepl() { 9151cb0ef41Sopenharmony_ci let resolveSocket, resolveReplServer; 9161cb0ef41Sopenharmony_ci 9171cb0ef41Sopenharmony_ci const server = net.createServer(common.mustCall((socket) => { 9181cb0ef41Sopenharmony_ci assert.strictEqual(server, socket.server); 9191cb0ef41Sopenharmony_ci 9201cb0ef41Sopenharmony_ci socket.on('end', common.mustCall(() => { 9211cb0ef41Sopenharmony_ci socket.end(); 9221cb0ef41Sopenharmony_ci })); 9231cb0ef41Sopenharmony_ci 9241cb0ef41Sopenharmony_ci resolveReplServer(repl.start(prompt_tcp, socket)); 9251cb0ef41Sopenharmony_ci })); 9261cb0ef41Sopenharmony_ci 9271cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 9281cb0ef41Sopenharmony_ci const client = net.createConnection(server.address().port); 9291cb0ef41Sopenharmony_ci 9301cb0ef41Sopenharmony_ci client.setEncoding('utf8'); 9311cb0ef41Sopenharmony_ci 9321cb0ef41Sopenharmony_ci client.on('connect', common.mustCall(() => { 9331cb0ef41Sopenharmony_ci assert.strictEqual(client.readable, true); 9341cb0ef41Sopenharmony_ci assert.strictEqual(client.writable, true); 9351cb0ef41Sopenharmony_ci 9361cb0ef41Sopenharmony_ci resolveSocket(client); 9371cb0ef41Sopenharmony_ci })); 9381cb0ef41Sopenharmony_ci 9391cb0ef41Sopenharmony_ci client.on('close', common.mustCall(() => { 9401cb0ef41Sopenharmony_ci server.close(); 9411cb0ef41Sopenharmony_ci })); 9421cb0ef41Sopenharmony_ci })); 9431cb0ef41Sopenharmony_ci 9441cb0ef41Sopenharmony_ci return Promise.all([ 9451cb0ef41Sopenharmony_ci new Promise((resolve) => resolveSocket = resolve), 9461cb0ef41Sopenharmony_ci new Promise((resolve) => resolveReplServer = resolve), 9471cb0ef41Sopenharmony_ci ]); 9481cb0ef41Sopenharmony_ci} 9491cb0ef41Sopenharmony_ci 9501cb0ef41Sopenharmony_cifunction startUnixRepl() { 9511cb0ef41Sopenharmony_ci let resolveSocket, resolveReplServer; 9521cb0ef41Sopenharmony_ci 9531cb0ef41Sopenharmony_ci const server = net.createServer(common.mustCall((socket) => { 9541cb0ef41Sopenharmony_ci assert.strictEqual(server, socket.server); 9551cb0ef41Sopenharmony_ci 9561cb0ef41Sopenharmony_ci socket.on('end', common.mustCall(() => { 9571cb0ef41Sopenharmony_ci socket.end(); 9581cb0ef41Sopenharmony_ci })); 9591cb0ef41Sopenharmony_ci 9601cb0ef41Sopenharmony_ci const replServer = repl.start({ 9611cb0ef41Sopenharmony_ci prompt: prompt_unix, 9621cb0ef41Sopenharmony_ci input: socket, 9631cb0ef41Sopenharmony_ci output: socket, 9641cb0ef41Sopenharmony_ci useGlobal: true 9651cb0ef41Sopenharmony_ci }); 9661cb0ef41Sopenharmony_ci replServer.context.message = message; 9671cb0ef41Sopenharmony_ci resolveReplServer(replServer); 9681cb0ef41Sopenharmony_ci })); 9691cb0ef41Sopenharmony_ci 9701cb0ef41Sopenharmony_ci tmpdir.refresh(); 9711cb0ef41Sopenharmony_ci 9721cb0ef41Sopenharmony_ci server.listen(common.PIPE, common.mustCall(() => { 9731cb0ef41Sopenharmony_ci const client = net.createConnection(common.PIPE); 9741cb0ef41Sopenharmony_ci 9751cb0ef41Sopenharmony_ci client.setEncoding('utf8'); 9761cb0ef41Sopenharmony_ci 9771cb0ef41Sopenharmony_ci client.on('connect', common.mustCall(() => { 9781cb0ef41Sopenharmony_ci assert.strictEqual(client.readable, true); 9791cb0ef41Sopenharmony_ci assert.strictEqual(client.writable, true); 9801cb0ef41Sopenharmony_ci 9811cb0ef41Sopenharmony_ci resolveSocket(client); 9821cb0ef41Sopenharmony_ci })); 9831cb0ef41Sopenharmony_ci 9841cb0ef41Sopenharmony_ci client.on('close', common.mustCall(() => { 9851cb0ef41Sopenharmony_ci server.close(); 9861cb0ef41Sopenharmony_ci })); 9871cb0ef41Sopenharmony_ci })); 9881cb0ef41Sopenharmony_ci 9891cb0ef41Sopenharmony_ci return Promise.all([ 9901cb0ef41Sopenharmony_ci new Promise((resolve) => resolveSocket = resolve), 9911cb0ef41Sopenharmony_ci new Promise((resolve) => resolveReplServer = resolve), 9921cb0ef41Sopenharmony_ci ]); 9931cb0ef41Sopenharmony_ci} 9941cb0ef41Sopenharmony_ci 9951cb0ef41Sopenharmony_cifunction event(ee, expected) { 9961cb0ef41Sopenharmony_ci return new Promise((resolve, reject) => { 9971cb0ef41Sopenharmony_ci const timeout = setTimeout(() => { 9981cb0ef41Sopenharmony_ci const data = inspect(expected, { compact: false }); 9991cb0ef41Sopenharmony_ci const msg = `The REPL did not reply as expected for:\n\n${data}`; 10001cb0ef41Sopenharmony_ci reject(new Error(msg)); 10011cb0ef41Sopenharmony_ci }, common.platformTimeout(9999)); 10021cb0ef41Sopenharmony_ci ee.once('data', common.mustCall((...args) => { 10031cb0ef41Sopenharmony_ci clearTimeout(timeout); 10041cb0ef41Sopenharmony_ci resolve(...args); 10051cb0ef41Sopenharmony_ci })); 10061cb0ef41Sopenharmony_ci }); 10071cb0ef41Sopenharmony_ci} 1008