GeezerVison is showing github.com — bootstrap: store internal loaders in C++ via a binding · nodejs/node@d668738
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/loaders.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -185,6 +185,7 @@ const loaderId = 'internal/bootstrap/loaders'; | 185 | 185 | const { | 186 | 186 | builtinIds, | 187 | 187 | compileFunction, | | 188 | + setInternalLoaders, | 188 | 189 | } = internalBinding('builtins'); | 189 | 190 |
| 190 | 191 | const getOwn = (target, property, receiver) => { | @@ -378,5 +379,5 @@ function requireWithFallbackInDeps(request) { | 378 | 379 | return requireBuiltin(request); | 379 | 380 | } | 380 | 381 |
| 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 Copy file name to clipboardExpand all lines: src/node_builtins.cc +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -666,6 +666,16 @@ void BuiltinLoader::HasCachedBuiltins(const FunctionCallbackInfo<Value>& args) { | 666 | 666 | args.GetIsolate(), instance->code_cache_->has_code_cache)); | 667 | 667 | } | 668 | 668 |
| | 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 | + | 669 | 679 | void BuiltinLoader::CopySourceAndCodeCacheReferenceFrom( | 670 | 680 | const BuiltinLoader* other) { | 671 | 681 | code_cache_ = other->code_cache_; | @@ -704,6 +714,7 @@ void BuiltinLoader::CreatePerIsolateProperties(IsolateData* isolate_data, | 704 | 714 | SetMethod(isolate, proto, "getCacheUsage", BuiltinLoader::GetCacheUsage); | 705 | 715 | SetMethod(isolate, proto, "compileFunction", BuiltinLoader::CompileFunction); | 706 | 716 | SetMethod(isolate, proto, "hasCachedBuiltins", HasCachedBuiltins); | | 717 | + SetMethod(isolate, proto, "setInternalLoaders", SetInternalLoaders); | 707 | 718 | } | 708 | 719 |
| 709 | 720 | void BuiltinLoader::CreatePerContextProperties(Local<Object> target, | @@ -722,6 +733,7 @@ void BuiltinLoader::RegisterExternalReferences( | 722 | 733 | registry->Register(GetCacheUsage); | 723 | 734 | registry->Register(CompileFunction); | 724 | 735 | registry->Register(HasCachedBuiltins); | | 736 | + registry->Register(SetInternalLoaders); | 725 | 737 | } | 726 | 738 |
| 727 | 739 | } // namespace builtins | |
Collapse file Copy file name to clipboardExpand all lines: src/node_realm.cc +2-28Lines changed: 2 additions & 28 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,7 +10,6 @@ namespace node { | 10 | 10 |
| 11 | 11 | using v8::Context; | 12 | 12 | using v8::EscapableHandleScope; | 13 | | -using v8::Function; | 14 | 13 | using v8::HandleScope; | 15 | 14 | using v8::Local; | 16 | 15 | using v8::MaybeLocal; | @@ -183,31 +182,6 @@ MaybeLocal<Value> Realm::ExecuteBootstrapper(const char* id) { | 183 | 182 | return scope.EscapeMaybe(result); | 184 | 183 | } | 185 | 184 |
| 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 | | - | 211 | 185 | MaybeLocal<Value> Realm::BootstrapNode() { | 212 | 186 | EscapableHandleScope scope(isolate_); | 213 | 187 |
| @@ -261,11 +235,11 @@ MaybeLocal<Value> Realm::RunBootstrapping() { | 261 | 235 |
| 262 | 236 | CHECK(!has_run_bootstrapping_code()); | 263 | 237 |
| 264 | | - if (BootstrapInternalLoaders().IsEmpty()) { | | 238 | + Local<Value> result; | | 239 | + if (!ExecuteBootstrapper("internal/bootstrap/loaders").ToLocal(&result)) { | 265 | 240 | return MaybeLocal<Value>(); | 266 | 241 | } | 267 | 242 |
| 268 | | - Local<Value> result; | 269 | 243 | if (!BootstrapNode().ToLocal(&result)) { | 270 | 244 | return MaybeLocal<Value>(); | 271 | 245 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/node_realm.h -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -69,7 +69,6 @@ class Realm : public MemoryRetainer { | 69 | 69 | void DeserializeProperties(const RealmSerializeInfo* info); | 70 | 70 |
| 71 | 71 | v8::MaybeLocal<v8::Value> ExecuteBootstrapper(const char* id); | 72 | | - v8::MaybeLocal<v8::Value> BootstrapInternalLoaders(); | 73 | 72 | v8::MaybeLocal<v8::Value> BootstrapNode(); | 74 | 73 | v8::MaybeLocal<v8::Value> RunBootstrapping(); | 75 | 74 |
| |
|