Skip to content

Commit 80dc3b1

Browse files
committed
fixup
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent 83ca596 commit 80dc3b1

5 files changed

Lines changed: 52 additions & 27 deletions

File tree

‎deps/v8/src/flags/flag-definitions.h‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,8 @@ DEFINE_NEG_IMPLICATION(stress_snapshot, incremental_marking)
451451
#define V8_LITE_MODE_BOOL false
452452
#endif
453453

454-
// Node.js requires WebAssembly for built-in functionality, including fetch and
455-
// TypeScript. Retain the constants for V8 internals, but do not register these
456-
// unsupported modes with the flag parser.
457-
#if defined(FLAG_MODE_DECLARE)
458-
DEFINE_BOOL_READONLY(lite_mode, false,
459-
"enables trade-off of performance for memory savings")
460-
#endif
454+
DEFINE_BOOL(lite_mode, V8_LITE_MODE_BOOL,
455+
"enables trade-off of performance for memory savings")
461456

462457
// Lite mode implies other flags to trade-off performance for memory.
463458
DEFINE_IMPLICATION(lite_mode, jitless)
@@ -942,14 +937,15 @@ DEFINE_STRING(
942937
"Select which native code sequence to use for wasm trace instruction: "
943938
"default or cpuid")
944939

945-
#if defined(V8_JITLESS) || defined(V8_LITE_MODE)
946-
#error Node.js does not support interpreter-only V8 builds.
947-
#endif
948-
#define V8_JITLESS_BOOL false
949-
#if defined(FLAG_MODE_DECLARE)
950-
DEFINE_BOOL_READONLY(jitless, false,
940+
#ifdef V8_JITLESS
941+
#define V8_JITLESS_BOOL true
942+
DEFINE_BOOL_READONLY(jitless, true,
951943
"Disable runtime allocation of executable memory.")
952-
#endif
944+
#else
945+
#define V8_JITLESS_BOOL false
946+
DEFINE_BOOL(jitless, V8_LITE_MODE_BOOL,
947+
"Disable runtime allocation of executable memory.")
948+
#endif // V8_JITLESS
953949

954950
// Jitless V8 has a few implications:
955951
// Field type tracking is only used by TurboFan.

‎deps/v8/src/flags/flags.cc‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,10 +1042,6 @@ class ImplicationProcessor {
10421042
bool EnforceImplications() {
10431043
bool changed = false;
10441044

1045-
// Node.js retains these constants without exposing them as runtime flags.
1046-
const auto& jitless = v8_flags.jitless;
1047-
const auto& lite_mode = v8_flags.lite_mode;
1048-
10491045
// For each flag, alias with a mutable reference so that implications don't
10501046
// need the v8_flags prefix.
10511047
#define FLAG_MODE_APPLY_NAME(name) \

‎src/node.cc‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
#include "node_version.h"
4949
#include "permission/env_permission.h"
5050

51+
#if defined(V8_JITLESS) || defined(V8_LITE_MODE)
52+
#error Node.js does not support interpreter-only V8 builds.
53+
#endif
54+
5155
#if HAVE_OPENSSL
5256
#include "ncrypto.h"
5357
#if OPENSSL_VERSION_MAJOR >= 3
@@ -1108,6 +1112,12 @@ static ExitCode InitializeNodeWithArgsInternal(
11081112

11091113
allow_env_sources.Finish();
11101114

1115+
// Node.js requires WebAssembly for built-in functionality. Override these
1116+
// modes after all option sources, before V8 applies their implications.
1117+
// Explicitly allow overriding even when contradiction checks are enabled.
1118+
V8::SetFlagsFromString("--allow-overwriting-for-next-flag --no-lite-mode "
1119+
"--allow-overwriting-for-next-flag --no-jitless");
1120+
11111121
// Every option source has now been parsed, so cross-source option
11121122
// constraints can finally be validated.
11131123
CheckGlobalBenchOptions(errors);

‎src/node_v8.cc‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) {
272272
CHECK(args[0]->IsString());
273273
Utf8Value flags(args.GetIsolate(), args[0]);
274274
V8::SetFlagsFromString(flags.out(), flags.length());
275+
// Runtime flags must not re-enable modes that disable required WebAssembly
276+
// support, even when contradiction checks are enabled.
277+
V8::SetFlagsFromString("--allow-overwriting-for-next-flag --no-lite-mode "
278+
"--allow-overwriting-for-next-flag --no-jitless");
275279
}
276280

277281
void StartCpuProfile(const FunctionCallbackInfo<Value>& args) {

‎test/parallel/test-cli-no-jitless.js‎

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,48 @@ const common = require('../common');
44
const assert = require('assert');
55
const { 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+
916
for (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, /bad option:/);
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, /unrecognized flag/);
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

2745
const options = spawnSync(process.execPath, ['--v8-options'], { encoding: 'utf8' });
2846
assert.strictEqual(options.status, 0, options.stderr);
29-
assert.doesNotMatch(options.stdout, /--(?:jitless|lite[-_]mode)\b/);
47+
assert.match(options.stdout, /--jitless\b/);
48+
assert.match(options.stdout, /--lite-mode\b/);
3049

3150
for (const flag of ['--jitless', '--lite-mode', '--lite_mode']) {
3251
assert.strictEqual(process.allowedNodeEnvironmentFlags.has(flag), false);

0 commit comments

Comments
 (0)