GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bootstrap: store internal loaders in C++ via a binding · nodejs/node@d668738

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/bootstrap
    • loaders.js
  • src
    • node_builtins.cc
    • node_realm.cc
    • node_realm.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/bootstrap/loaders.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/loaders.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ const loaderId = 'internal/bootstrap/loaders';
185185
const {
186186
builtinIds,
187187
compileFunction,
188+
setInternalLoaders,
188189
} = internalBinding('builtins');
189190

190191
const getOwn = (target, property, receiver) => {
@@ -378,5 +379,5 @@ function requireWithFallbackInDeps(request) {
378379
return requireBuiltin(request);
379380
}
380381

381-
// Pass the exports back to C++ land for C++ internals to use.
382-
return loaderExports;
382+
// Store the internal loaders in C++.
383+
setInternalLoaders(internalBinding, requireBuiltin);
Collapse file

‎src/node_builtins.cc‎

Copy file name to clipboardExpand all lines: src/node_builtins.cc
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,16 @@ void BuiltinLoader::HasCachedBuiltins(const FunctionCallbackInfo<Value>& args) {
666666
args.GetIsolate(), instance->code_cache_->has_code_cache));
667667
}
668668

669+
void SetInternalLoaders(const FunctionCallbackInfo<Value>& args) {
670+
Realm* realm = Realm::GetCurrent(args);
671+
CHECK(args[0]->IsFunction());
672+
CHECK(args[1]->IsFunction());
673+
DCHECK(realm->internal_binding_loader().IsEmpty());
674+
DCHECK(realm->builtin_module_require().IsEmpty());
675+
realm->set_internal_binding_loader(args[0].As<Function>());
676+
realm->set_builtin_module_require(args[1].As<Function>());
677+
}
678+
669679
void BuiltinLoader::CopySourceAndCodeCacheReferenceFrom(
670680
const BuiltinLoader* other) {
671681
code_cache_ = other->code_cache_;
@@ -704,6 +714,7 @@ void BuiltinLoader::CreatePerIsolateProperties(IsolateData* isolate_data,
704714
SetMethod(isolate, proto, "getCacheUsage", BuiltinLoader::GetCacheUsage);
705715
SetMethod(isolate, proto, "compileFunction", BuiltinLoader::CompileFunction);
706716
SetMethod(isolate, proto, "hasCachedBuiltins", HasCachedBuiltins);
717+
SetMethod(isolate, proto, "setInternalLoaders", SetInternalLoaders);
707718
}
708719

709720
void BuiltinLoader::CreatePerContextProperties(Local<Object> target,
@@ -722,6 +733,7 @@ void BuiltinLoader::RegisterExternalReferences(
722733
registry->Register(GetCacheUsage);
723734
registry->Register(CompileFunction);
724735
registry->Register(HasCachedBuiltins);
736+
registry->Register(SetInternalLoaders);
725737
}
726738

727739
} // namespace builtins
Collapse file

‎src/node_realm.cc‎

Copy file name to clipboardExpand all lines: src/node_realm.cc
+2-28Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace node {
1010

1111
using v8::Context;
1212
using v8::EscapableHandleScope;
13-
using v8::Function;
1413
using v8::HandleScope;
1514
using v8::Local;
1615
using v8::MaybeLocal;
@@ -183,31 +182,6 @@ MaybeLocal<Value> Realm::ExecuteBootstrapper(const char* id) {
183182
return scope.EscapeMaybe(result);
184183
}
185184

186-
MaybeLocal<Value> Realm::BootstrapInternalLoaders() {
187-
EscapableHandleScope scope(isolate_);
188-
189-
// Bootstrap internal loaders
190-
Local<Value> loader_exports;
191-
if (!ExecuteBootstrapper("internal/bootstrap/loaders")
192-
.ToLocal(&loader_exports)) {
193-
return MaybeLocal<Value>();
194-
}
195-
CHECK(loader_exports->IsObject());
196-
Local<Object> loader_exports_obj = loader_exports.As<Object>();
197-
Local<Value> internal_binding_loader =
198-
loader_exports_obj->Get(context(), env_->internal_binding_string())
199-
.ToLocalChecked();
200-
CHECK(internal_binding_loader->IsFunction());
201-
set_internal_binding_loader(internal_binding_loader.As<Function>());
202-
Local<Value> require =
203-
loader_exports_obj->Get(context(), env_->require_string())
204-
.ToLocalChecked();
205-
CHECK(require->IsFunction());
206-
set_builtin_module_require(require.As<Function>());
207-
208-
return scope.Escape(loader_exports);
209-
}
210-
211185
MaybeLocal<Value> Realm::BootstrapNode() {
212186
EscapableHandleScope scope(isolate_);
213187

@@ -261,11 +235,11 @@ MaybeLocal<Value> Realm::RunBootstrapping() {
261235

262236
CHECK(!has_run_bootstrapping_code());
263237

264-
if (BootstrapInternalLoaders().IsEmpty()) {
238+
Local<Value> result;
239+
if (!ExecuteBootstrapper("internal/bootstrap/loaders").ToLocal(&result)) {
265240
return MaybeLocal<Value>();
266241
}
267242

268-
Local<Value> result;
269243
if (!BootstrapNode().ToLocal(&result)) {
270244
return MaybeLocal<Value>();
271245
}
Collapse file

‎src/node_realm.h‎

Copy file name to clipboardExpand all lines: src/node_realm.h
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class Realm : public MemoryRetainer {
6969
void DeserializeProperties(const RealmSerializeInfo* info);
7070

7171
v8::MaybeLocal<v8::Value> ExecuteBootstrapper(const char* id);
72-
v8::MaybeLocal<v8::Value> BootstrapInternalLoaders();
7372
v8::MaybeLocal<v8::Value> BootstrapNode();
7473
v8::MaybeLocal<v8::Value> RunBootstrapping();
7574

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.