@@ -4,29 +4,48 @@ const common = require('../common');
44const assert = require ( 'assert' ) ;
55const { spawnSync } = require ( 'child_process' ) ;
66
7- // Interpreter-only modes must not bypass Node's WebAssembly requirement,
8- // including through V8's alternate flag spellings and runtime flag API.
7+ // Interpreter-only modes are overridden to preserve Node's WebAssembly
8+ // requirement, including alternate spellings and the runtime flag API.
9+ const wasm = `
10+ const assert = require('assert');
11+ assert.strictEqual(typeof WebAssembly, 'object');
12+ const bytes = Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0);
13+ new WebAssembly.Instance(new WebAssembly.Module(bytes));
14+ ` ;
15+
916for ( const flag of [
1017 '--jitless' , '--lite-mode' , '--lite_mode' , '-jitless' , '-lite_mode' ,
1118 '--jitless=true' , '--lite_mode=true' , '--no-jitless' , '--no-lite-mode' ,
1219] ) {
13- const result = spawnSync ( process . execPath , [ flag , '-e' , '' ] , { encoding : 'utf8' } ) ;
14- assert . strictEqual ( result . status , 9 , result . stderr ) ;
20+ const result = spawnSync ( process . execPath , [ flag , '-e' , wasm ] , { encoding : 'utf8' } ) ;
21+ assert . strictEqual ( result . status , 0 , result . stderr ) ;
1522 assert . strictEqual ( result . signal , null ) ;
16- assert . match ( result . stderr , / b a d o p t i o n : / ) ;
23+ assert . strictEqual ( result . stderr , '' ) ;
1724
1825 const runtime = spawnSync ( process . execPath , [ '-e' , `
1926 require('v8').setFlagsFromString(${ JSON . stringify ( flag ) } );
20- const bytes = Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0);
21- new WebAssembly.Instance(new WebAssembly.Module(bytes));
27+ ${ wasm }
28+ // A new isolate must also retain WebAssembly after changing runtime flags.
29+ new (require('worker_threads').Worker)(${ JSON . stringify ( wasm ) } , { eval: true });
2230 ` ] , { encoding : 'utf8' } ) ;
2331 assert . strictEqual ( runtime . status , 0 , runtime . stderr ) ;
24- assert . match ( runtime . stderr , / u n r e c o g n i z e d f l a g / ) ;
32+ assert . strictEqual ( runtime . stderr , '' ) ;
33+ }
34+
35+ // Node's overrides must not be treated as contradictory user-supplied flags.
36+ for ( const flag of [ '--jitless' , '--lite-mode' ] ) {
37+ const result = spawnSync ( process . execPath , [
38+ '--abort-on-contradictory-flags' , flag , '-e' , wasm ,
39+ ] , { encoding : 'utf8' } ) ;
40+ assert . strictEqual ( result . status , 0 , result . stderr ) ;
41+ assert . strictEqual ( result . signal , null ) ;
42+ assert . strictEqual ( result . stderr , '' ) ;
2543}
2644
2745const options = spawnSync ( process . execPath , [ '--v8-options' ] , { encoding : 'utf8' } ) ;
2846assert . strictEqual ( options . status , 0 , options . stderr ) ;
29- assert . doesNotMatch ( options . stdout , / - - (?: j i t l e s s | l i t e [ - _ ] m o d e ) \b / ) ;
47+ assert . match ( options . stdout , / - - j i t l e s s \b / ) ;
48+ assert . match ( options . stdout , / - - l i t e - m o d e \b / ) ;
3049
3150for ( const flag of [ '--jitless' , '--lite-mode' , '--lite_mode' ] ) {
3251 assert . strictEqual ( process . allowedNodeEnvironmentFlags . has ( flag ) , false ) ;
0 commit comments