Skip to content

Commit 56f2556

Browse files
committed
lib,src: fix process.features.cached_builtins when snapshotted
This value is not a constant, in the sense that its value when running `node_mksnapshot` and when running the default `node` binary are different.
1 parent 1ce19a5 commit 56f2556

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/internal/bootstrap/node.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,17 @@ ObjectDefineProperty(process, 'features', {
197197
tls_sni: hasOpenSSL,
198198
tls_ocsp: hasOpenSSL,
199199
tls: hasOpenSSL,
200-
cached_builtins: config.hasCachedBuiltins,
200+
}
201+
});
202+
ObjectDefineProperty(process.features, 'cached_builtins', {
203+
enumerable: true,
204+
configurable: true,
205+
get() {
206+
return config.hasCachedBuiltins();
207+
},
208+
set(v) {
209+
delete this.cached_builtins;
210+
this.cached_builtins = v;
201211
}
202212
});
203213

src/node_config.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@
44
#include "node_i18n.h"
55
#include "node_native_module_env.h"
66
#include "node_options.h"
7+
#include "snapshot_support-inl.h"
78
#include "util-inl.h"
89

910
namespace node {
1011

1112
using v8::Context;
13+
using v8::FunctionCallbackInfo;
1214
using v8::Isolate;
1315
using v8::Local;
1416
using v8::Number;
1517
using v8::Object;
1618
using v8::Value;
1719

20+
static void HasCachedBuiltins(const FunctionCallbackInfo<Value>& args) {
21+
args.GetReturnValue().Set(native_module::has_code_cache);
22+
}
23+
1824
// The config binding is used to provide an internal view of compile time
1925
// config options that are required internally by lib/*.js code. This is an
2026
// alternative to dropping additional properties onto the process object as
@@ -85,10 +91,16 @@ static void Initialize(Local<Object> target,
8591
READONLY_TRUE_PROPERTY(target, "hasDtrace");
8692
#endif
8793

88-
READONLY_PROPERTY(target, "hasCachedBuiltins",
89-
v8::Boolean::New(isolate, native_module::has_code_cache));
94+
// Make this a method instead of a constant in order for snapshotted builts
95+
// to correctly report this.
96+
env->SetMethodNoSideEffect(target, "hasCachedBuiltins", HasCachedBuiltins);
9097
} // InitConfig
9198

99+
static ExternalReferences external_references {
100+
__FILE__,
101+
HasCachedBuiltins
102+
};
103+
92104
} // namespace node
93105

94106
NODE_MODULE_CONTEXT_AWARE_INTERNAL(config, node::Initialize)

0 commit comments

Comments
 (0)