From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cheng Zhao <zcbenz@gmail.com>
Date: Thu, 11 Apr 2019 17:16:13 +0900
Subject: build: modify js2c.py to allow injection of original-fs and custom
 embedder JS

This patch ensures that internal/fs/watchers can be loaded twice without
JS errors and ensures embedder JS is loaded via LoadEmbedderJavaScriptSource.

That method is generated by our modifications to js2c.cc in the BUILD.gn patch

diff --git a/lib/internal/fs/watchers.js b/lib/internal/fs/watchers.js
index 99212fa713bf3f767d4604906e41d9b279447239..4e32a274a63c8244ce3168d0c5cc56203cfe5473 100644
--- a/lib/internal/fs/watchers.js
+++ b/lib/internal/fs/watchers.js
@@ -292,12 +292,13 @@ function emitCloseNT(self) {
 }
 
 // Legacy alias on the C++ wrapper object. This is not public API, so we may
-// want to runtime-deprecate it at some point. There's no hurry, though.
-ObjectDefineProperty(FSEvent.prototype, 'owner', {
-  __proto__: null,
-  get() { return this[owner_symbol]; },
-  set(v) { return this[owner_symbol] = v; },
-});
+if (!'owner' in FSEvent.prototype) {
+  ObjectDefineProperty(FSEvent.prototype, 'owner', {
+ __proto__: null,
+    get() { return this[owner_symbol]; },
+    set(v) { return this[owner_symbol] = v; }
+  });
+}
 
 let kResistStopPropagation;
 
diff --git a/src/node_builtins.cc b/src/node_builtins.cc
index 80b36dc1aefca4d5d4124d7f84b12b9762a8de2c..f3cda64beaa1403cb33f1b0bd8089f3dfcbfc8b9 100644
--- a/src/node_builtins.cc
+++ b/src/node_builtins.cc
@@ -35,6 +35,7 @@ using v8::Value;
 BuiltinLoader::BuiltinLoader()
     : config_(GetConfig()), code_cache_(std::make_shared<BuiltinCodeCache>()) {
   LoadJavaScriptSource();
+  LoadEmbedderJavaScriptSource();
 #ifdef NODE_SHARED_BUILTIN_CJS_MODULE_LEXER_LEXER_PATH
   AddExternalizedBuiltin(
       "internal/deps/cjs-module-lexer/lexer",
diff --git a/src/node_builtins.h b/src/node_builtins.h
index ea77c7598153bb8a9ba20c89a4ece2c1580b9a25..11d10f52b7c492bfae4bc58b39c20a693762a72d 100644
--- a/src/node_builtins.h
+++ b/src/node_builtins.h
@@ -126,6 +126,7 @@ class NODE_EXTERN_PRIVATE BuiltinLoader {
 
   // Generated by tools/js2c.py as node_javascript.cc
   void LoadJavaScriptSource();  // Loads data into source_
+  void LoadEmbedderJavaScriptSource();  // Loads embedder data into source_
   UnionBytes GetConfig();       // Return data for config.gypi
 
   std::vector<std::string_view> GetBuiltinIds() const;
