From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <sattard@slack-corp.com>
Date: Fri, 28 Jun 2019 17:13:54 -0700
Subject: chore: re-add CompileAndCall, this should be added as a helper in
 electron

diff --git a/src/node_native_module_env.cc b/src/node_native_module_env.cc
index 31536000fc8d2f9ce9589ef8e31cb55439fbd28d..6cb49b3b6def15a38ce1ba51da11af2567cb84ec 100644
--- a/src/node_native_module_env.cc
+++ b/src/node_native_module_env.cc
@@ -151,6 +151,22 @@ MaybeLocal<Function> NativeModuleEnv::LookupAndCompile(
   return maybe;
 }
 
+MaybeLocal<Value> NativeModuleEnv::CompileAndCall(
+    Local<Context> context,
+    const char* id,
+    std::vector<Local<String>>* parameters,
+    std::vector<Local<Value>>* arguments,
+    Environment* optional_env) {
+  Isolate* isolate = context->GetIsolate();
+  MaybeLocal<Function> compiled = LookupAndCompile(context, id, parameters, optional_env);
+  if (compiled.IsEmpty()) {
+    return MaybeLocal<Value>();
+  }
+  Local<Function> fn = compiled.ToLocalChecked().As<Function>();
+  return fn->Call(
+      context, v8::Null(isolate), arguments->size(), arguments->data());
+}
+
 // TODO(joyeecheung): It is somewhat confusing that Class::Initialize
 // is used to initialize to the binding, but it is the current convention.
 // Rename this across the code base to something that makes more sense.
diff --git a/src/node_native_module_env.h b/src/node_native_module_env.h
index f662c67be50d404ee5b6cf6e2b8dd5991c59e723..b91a5059cd1f19d87e5876c372f3ded60681a5df 100644
--- a/src/node_native_module_env.h
+++ b/src/node_native_module_env.h
@@ -24,6 +24,17 @@ class NativeModuleEnv {
       const char* id,
       std::vector<v8::Local<v8::String>>* parameters,
       Environment* optional_env);
+  // Run a script with JS source bundled inside the binary as if it's wrapped
+  // in a function called with a null receiver and arguments specified in C++.
+  // The returned value is empty if an exception is encountered.
+  // JS code run with this method can assume that their top-level
+  // declarations won't affect the global scope.
+  static v8::MaybeLocal<v8::Value> CompileAndCall(
+      v8::Local<v8::Context> context,
+      const char* id,
+      std::vector<v8::Local<v8::String>>* parameters,
+      std::vector<v8::Local<v8::Value>>* arguments,
+      Environment* optional_env);
 
   static v8::Local<v8::Object> GetSourceObject(v8::Local<v8::Context> context);
   // Returns config.gypi as a JSON string
