Skip to content

Commit

Permalink
src: merge NativeModuleEnv into NativeModuleLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Oct 17, 2022
1 parent b25a71a commit f67af84
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
3 changes: 3 additions & 0 deletions patches/node/.patches
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ fixup_for_wc_98-compat-extra-semi.patch
drop_deserializerequest_move_constructor_for_c_20_compat.patch
fix_parallel_test-v8-stats.patch
fix_expose_the_built-in_electron_module_via_the_esm_loader.patch
api_pass_oomdetails_to_oomerrorcallback.patch
src_iwyu_in_cleanup_queue_cc.patch
fix_expose_lookupandcompile_with_parameters.patch
54 changes: 54 additions & 0 deletions patches/node/fix_expose_lookupandcompile_with_parameters.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Thu, 13 Oct 2022 17:10:01 +0200
Subject: fix: expose LookupAndCompile with parameters

Node.js removed custom parameters from the public version of LookupAndCompile,
which we use in Electron. This patch re-exposes a wrapper to allow custom
parameters.

This should be upstreamed.

diff --git a/src/node_builtins.cc b/src/node_builtins.cc
index 3bc9d113b6b818dcda332966f09f17248b421263..549339b5b677fa242a7b60ae716789c2a11ab18d 100644
--- a/src/node_builtins.cc
+++ b/src/node_builtins.cc
@@ -397,6 +397,22 @@ MaybeLocal<Function> BuiltinLoader::LookupAndCompile(
return maybe;
}

+MaybeLocal<Function> BuiltinLoader::LookupAndCompile(
+ Local<Context> context,
+ const char* id,
+ std::vector<Local<String>>* parameters,
+ Environment* optional_env) {
+ Result result;
+ Isolate* isolate = context->GetIsolate();
+
+ MaybeLocal<Function> maybe = GetInstance()->LookupAndCompileInternal(
+ context, id, parameters, &result);
+ if (optional_env != nullptr) {
+ RecordResult(id, result, optional_env);
+ }
+ return maybe;
+}
+
bool BuiltinLoader::CompileAllBuiltins(Local<Context> context) {
BuiltinLoader* loader = GetInstance();
std::vector<std::string> ids = loader->GetBuiltinIds();
diff --git a/src/node_builtins.h b/src/node_builtins.h
index 7f0a25af306ffefbc51ac43689ed208d4cd94f0b..a32a7a990082ea3dad73511f91a9c70c72f6fe31 100644
--- a/src/node_builtins.h
+++ b/src/node_builtins.h
@@ -49,6 +49,11 @@ class NODE_EXTERN_PRIVATE BuiltinLoader {
v8::Local<v8::Context> context,
const char* id,
Environment* optional_env);
+ static v8::MaybeLocal<v8::Function> LookupAndCompile(
+ v8::Local<v8::Context> context,
+ const char* id,
+ std::vector<v8::Local<v8::String>>* parameters,
+ Environment* optional_env);

static v8::Local<v8::Object> GetSourceObject(v8::Local<v8::Context> context);
// Returns config.gypi as a JSON string
2 changes: 1 addition & 1 deletion shell/common/node_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "env.h"
#include "node.h"
#include "node_buffer.h"
#include "node_builtins.h"
#include "node_errors.h"
#include "node_internals.h"
#include "node_native_module_env.h"
#include "node_object_wrap.h"
#include "node_options-inl.h"
#include "node_options.h"
Expand Down
4 changes: 2 additions & 2 deletions shell/common/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ v8::MaybeLocal<v8::Value> CompileAndCall(
v8::Isolate* isolate = context->GetIsolate();
v8::TryCatch try_catch(isolate);
v8::MaybeLocal<v8::Function> compiled =
node::native_module::NativeModuleEnv::LookupAndCompile(
context, id, parameters, optional_env);
node::builtins::BuiltinLoader::LookupAndCompile(context, id, parameters,
optional_env);
if (compiled.IsEmpty()) {
return v8::MaybeLocal<v8::Value>();
}
Expand Down

0 comments on commit f67af84

Please sign in to comment.