Skip to content

Commit f0d7b40

Browse files
committed
vfs: convert isVfsEnabled from property to method
Convert isVfsEnabled from a boolean property set during Initialize() to a SetMethod function, matching the isSea() pattern. This addresses review feedback requesting consistency in the C++ binding API.
1 parent 4c3c38f commit f0d7b40

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

lib/internal/main/embedding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
} = require('internal/process/pre_execution');
1515
const {
1616
isSea,
17-
isVfsEnabled: isVfsEnabledFlag,
17+
isVfsEnabled: isVfsEnabledFn,
1818
mainCodePath: seaMainCodePath,
1919
isExperimentalSeaWarningNeeded,
2020
} = internalBinding('sea');
@@ -113,7 +113,7 @@ function initSeaVfs() {
113113
if (seaVfsInitialized) return;
114114
seaVfsInitialized = true;
115115

116-
if (!isLoadingSea || !isVfsEnabledFlag) return;
116+
if (!isLoadingSea || !isVfsEnabledFn()) return;
117117

118118
const { getSeaVfs } = require('internal/vfs/sea');
119119
const seaVfs = getSeaVfs();

lib/internal/vfs/sea.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { isSea, isVfsEnabled, getAssetKeys } = internalBinding('sea');
3+
const { isSea, isVfsEnabled: isVfsEnabledFn, getAssetKeys } = internalBinding('sea');
44
const { kEmptyObject, getLazy } = require('internal/util');
55
const {
66
codes: {
@@ -30,7 +30,7 @@ const lazySEAProvider = getLazy(
3030
* @returns {VirtualFileSystem|null} The VFS instance, or null if not running as SEA or no assets
3131
*/
3232
function createSeaVfs(options = kEmptyObject) {
33-
if (!isSea || !isVfsEnabled) {
33+
if (!isSea || !isVfsEnabledFn()) {
3434
return null;
3535
}
3636

src/node_sea.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,15 @@ void IsSea(const FunctionCallbackInfo<Value>& args) {
266266
args.GetReturnValue().Set(IsSingleExecutable());
267267
}
268268

269+
void IsVfsEnabled(const FunctionCallbackInfo<Value>& args) {
270+
bool enabled = false;
271+
if (IsSingleExecutable()) {
272+
SeaResource sea_resource = FindSingleExecutableResource();
273+
enabled = static_cast<bool>(sea_resource.flags & SeaFlags::kEnableVfs);
274+
}
275+
args.GetReturnValue().Set(enabled);
276+
}
277+
269278
void IsExperimentalSeaWarningNeeded(const FunctionCallbackInfo<Value>& args) {
270279
bool is_building_sea =
271280
!per_process::cli_options->experimental_sea_config.empty();
@@ -952,11 +961,9 @@ void Initialize(Local<Object> target,
952961
Environment* env = Environment::GetCurrent(context);
953962
Isolate* isolate = env->isolate();
954963

955-
// isVfsEnabled is a boolean property (only used by embedding.js).
956-
bool is_vfs_enabled = false;
957964
if (IsSingleExecutable()) {
958965
SeaResource sea_resource = FindSingleExecutableResource();
959-
is_vfs_enabled =
966+
bool is_vfs_enabled =
960967
static_cast<bool>(sea_resource.flags & SeaFlags::kEnableVfs);
961968
// Expose the main code path so VFS can construct the correct entry point.
962969
if (is_vfs_enabled) {
@@ -974,13 +981,9 @@ void Initialize(Local<Object> target,
974981
}
975982
}
976983
}
977-
target
978-
->Set(context,
979-
FIXED_ONE_BYTE_STRING(isolate, "isVfsEnabled"),
980-
Boolean::New(isolate, is_vfs_enabled))
981-
.Check();
982984

983985
SetMethod(context, target, "isSea", IsSea);
986+
SetMethod(context, target, "isVfsEnabled", IsVfsEnabled);
984987
SetMethod(context,
985988
target,
986989
"isExperimentalSeaWarningNeeded",
@@ -991,6 +994,7 @@ void Initialize(Local<Object> target,
991994

992995
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
993996
registry->Register(IsSea);
997+
registry->Register(IsVfsEnabled);
994998
registry->Register(IsExperimentalSeaWarningNeeded);
995999
registry->Register(GetAsset);
9961000
registry->Register(GetAssetKeys);

0 commit comments

Comments
 (0)