From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tomas Rycl <torycl@microsoft.com>
Date: Mon, 13 May 2019 15:48:48 +0200
Subject: Do not export private V8 symbols on Windows

This change stops private V8 symbols and internal crt methods being exported.
It fixes an issue where native node modules can import
incorrect CRT methods and crash on Windows.
It also reduces size of node.lib by 75%.

This patch can be safely removed if, when it is removed, `node.lib` does not
contain any standard C++ library exports (e.g. `std::ostringstream`).

diff --git a/BUILD.gn b/BUILD.gn
index 0d34b2ebbe315b4cd1c4c2f5a0c95cc74b28d23d..1f8f89e1876ca7a02a8762c5e88d6fcf96037dc0 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -675,6 +675,10 @@ config("internal_config") {
     ":cppgc_header_features",
   ]
 
+  if (!is_component_build && is_electron_build) {
+    defines += [ "HIDE_PRIVATE_SYMBOLS" ]
+  }
+
   if (is_component_build || is_electron_build) {
     defines += [ "BUILDING_V8_SHARED" ]
   }
diff --git a/src/base/macros.h b/src/base/macros.h
index cd5b91f745a4532b6248d5504fd100cd9806fee4..00321c74d8b195b7024cfa778aa685410edd8dc0 100644
--- a/src/base/macros.h
+++ b/src/base/macros.h
@@ -388,13 +388,17 @@ bool is_inbounds(float_t v) {
 #ifdef V8_OS_WIN
 
 // Setup for Windows shared library export.
+#if defined(HIDE_PRIVATE_SYMBOLS)
+#define V8_EXPORT_PRIVATE
+#else //if !defined(HIDE_PRIVATE_SYMBOLS)
 #ifdef BUILDING_V8_SHARED
 #define V8_EXPORT_PRIVATE __declspec(dllexport)
 #elif USING_V8_SHARED
 #define V8_EXPORT_PRIVATE __declspec(dllimport)
-#else
+#else //!(BUILDING_V8_SHARED || USING_V8_SHARED)
 #define V8_EXPORT_PRIVATE
-#endif  // BUILDING_V8_SHARED
+#endif
+#endif
 
 #else  // V8_OS_WIN
 
