|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('node:assert'); |
| 5 | +const { spawnSync, spawn } = require('node:child_process'); |
| 6 | + |
| 7 | +assert.strictEqual(RegExp.$_, ''); |
| 8 | +assert.strictEqual(RegExp.$0, undefined); |
| 9 | +assert.strictEqual(RegExp.$1, ''); |
| 10 | +assert.strictEqual(RegExp.$2, ''); |
| 11 | +assert.strictEqual(RegExp.$3, ''); |
| 12 | +assert.strictEqual(RegExp.$4, ''); |
| 13 | +assert.strictEqual(RegExp.$5, ''); |
| 14 | +assert.strictEqual(RegExp.$6, ''); |
| 15 | +assert.strictEqual(RegExp.$7, ''); |
| 16 | +assert.strictEqual(RegExp.$8, ''); |
| 17 | +assert.strictEqual(RegExp.$9, ''); |
| 18 | +assert.strictEqual(RegExp.input, ''); |
| 19 | +assert.strictEqual(RegExp.lastMatch, ''); |
| 20 | +assert.strictEqual(RegExp.lastParen, ''); |
| 21 | +assert.strictEqual(RegExp.leftContext, ''); |
| 22 | +assert.strictEqual(RegExp.rightContext, ''); |
| 23 | +assert.strictEqual(RegExp['$&'], ''); |
| 24 | +assert.strictEqual(RegExp['$`'], ''); |
| 25 | +assert.strictEqual(RegExp['$+'], ''); |
| 26 | +assert.strictEqual(RegExp["$'"], ''); |
| 27 | + |
| 28 | +const allRegExpStatics = |
| 29 | + 'RegExp.$_ + RegExp["$&"] + RegExp["$`"] + RegExp["$+"] + RegExp["$\'"] + ' + |
| 30 | + 'RegExp.input + RegExp.lastMatch + RegExp.lastParen + ' + |
| 31 | + 'RegExp.leftContext + RegExp.rightContext + ' + |
| 32 | + Array.from({ length: 10 }, (_, i) => `RegExp.$${i}`).join(' + '); |
| 33 | + |
| 34 | +{ |
| 35 | + const child = spawnSync(process.execPath, |
| 36 | + [ '-p', allRegExpStatics ], |
| 37 | + { stdio: ['inherit', 'pipe', 'inherit'] }); |
| 38 | + assert.match(child.stdout.toString(), /^undefined\r?\n$/); |
| 39 | + assert.strictEqual(child.status, 0); |
| 40 | + assert.strictEqual(child.signal, null); |
| 41 | +} |
| 42 | + |
| 43 | +{ |
| 44 | + const child = spawnSync(process.execPath, |
| 45 | + [ '-e', `console.log(${allRegExpStatics})`, '--input-type=module' ], |
| 46 | + { stdio: ['inherit', 'pipe', 'inherit'] }); |
| 47 | + assert.match(child.stdout.toString(), /^undefined\r?\n$/); |
| 48 | + assert.strictEqual(child.status, 0); |
| 49 | + assert.strictEqual(child.signal, null); |
| 50 | +} |
| 51 | + |
| 52 | +{ |
| 53 | + const child = spawn(process.execPath, [], { stdio: ['pipe', 'pipe', 'inherit'], encoding: 'utf8' }); |
| 54 | + |
| 55 | + let stdout = ''; |
| 56 | + child.stdout.on('data', (chunk) => { |
| 57 | + stdout += chunk; |
| 58 | + }); |
| 59 | + |
| 60 | + child.on('exit', common.mustCall((status, signal) => { |
| 61 | + assert.match(stdout, /^undefined\r?\n$/); |
| 62 | + assert.strictEqual(status, 0); |
| 63 | + assert.strictEqual(signal, null); |
| 64 | + })); |
| 65 | + child.on('error', common.mustNotCall()); |
| 66 | + |
| 67 | + child.stdin.end(`console.log(${allRegExpStatics});\n`); |
| 68 | +} |
0 commit comments