Skip to content

Commit

Permalink
sea: warn if code cache is rejected
Browse files Browse the repository at this point in the history
Refs: nodejs#48191 (comment)
Signed-off-by: Darshan Sen <[email protected]>
  • Loading branch information
RaisinTen committed Jun 2, 2023
1 parent 5dfdbd1 commit 1610dd6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const {
require_private_symbol,
},
} = internalBinding('util');
const { isSea } = internalBinding('sea');
const {
getCjsConditions,
initializeCjsConditions,
Expand Down Expand Up @@ -127,7 +128,6 @@ let hasLoadedAnyUserCJSModule = false;

const {
codes: {
ERR_INTERNAL_ASSERTION,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_MODULE_SPECIFIER,
ERR_REQUIRE_ESM,
Expand Down Expand Up @@ -1189,8 +1189,9 @@ function wrapSafe(filename, content, cjsModuleInstance, codeCache) {
},
});

if (codeCache && result.cachedDataRejected !== false) {
throw new ERR_INTERNAL_ASSERTION('Code cache data rejected.');
// The code cache is used for SEAs only.
if (codeCache && result.cachedDataRejected !== false && isSea()) {
process.emitWarning('Code cache data rejected.');
}

// Cache the source map for the module if present.
Expand Down
6 changes: 6 additions & 0 deletions src/node_sea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ bool IsSingleExecutable() {
return postject_has_resource();
}

void IsSea(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(IsSingleExecutable());
}

void IsExperimentalSeaWarningNeeded(const FunctionCallbackInfo<Value>& args) {
if (!IsSingleExecutable()) {
args.GetReturnValue().Set(false);
Expand Down Expand Up @@ -415,6 +419,7 @@ void Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context,
void* priv) {
SetMethod(context, target, "isSea", IsSea);
SetMethod(context,
target,
"isExperimentalSeaWarningNeeded",
Expand All @@ -424,6 +429,7 @@ void Initialize(Local<Object> target,
}

void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(IsSea);
registry->Register(IsExperimentalSeaWarningNeeded);
registry->Register(GetCodePath);
registry->Register(GetCodeCache);
Expand Down

0 comments on commit 1610dd6

Please sign in to comment.