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 b9a2e1ab4cef5b6fc5aeb90288e228dc337973bf..66dca114fb4797db9b62cf8343d58ab71c54b6a6 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -551,6 +551,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 fca0b2ebb2ccda35ed308155f436820f5a76b9a2..0f8fab3ab75943d7fb3a93cd6e59092ea19804f6 100644
--- a/src/base/macros.h
+++ b/src/base/macros.h
@@ -381,13 +381,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
 
