From 80d3c118f460453c9aede58213354d6652db81cb Mon Sep 17 00:00:00 2001
From: Richard Lau <rlau@redhat.com>
Date: Wed, 24 Feb 2021 18:50:11 +0000
Subject: [PATCH] deps: V8: cherry-pick 373f4ae739ee
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Original commit message:

    [torque] Don't replace unmodified empty files

    To improve incremental builds.

    Bug: v8:7793
    Change-Id: I6990a97e058d22d34acd1f609167cd30ca7518ad
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2596789
    Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
    Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
    Cr-Commit-Position: refs/heads/master@{#72053}

Refs: https://github.com/v8/v8/commit/373f4ae739eeae0e4d2224b15002be35f1470312

PR-URL: https://github.com/nodejs/node/pull/37505
Fixes: https://github.com/nodejs/node/issues/37368
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
---
 common.gypi                 | 2 +-
 deps/v8/src/torque/utils.cc | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/common.gypi b/common.gypi
index 6d358895761ef3..0235880edf83bb 100644
--- a/common.gypi
+++ b/common.gypi
@@ -36,7 +36,7 @@
 
     # Reset this number to 0 on major V8 upgrades.
     # Increment by one for each non-official patch applied to deps/v8.
-    'v8_embedder_string': '-node.26',
+    'v8_embedder_string': '-node.27',
 
     ##### V8 defaults for Node.js #####
 
diff --git a/deps/v8/src/torque/utils.cc b/deps/v8/src/torque/utils.cc
index 312adcfb24a34b..6118341e1e0d41 100644
--- a/deps/v8/src/torque/utils.cc
+++ b/deps/v8/src/torque/utils.cc
@@ -317,13 +317,15 @@ void ReplaceFileContentsIfDifferent(const std::string& file_path,
                                     const std::string& contents) {
   std::ifstream old_contents_stream(file_path.c_str());
   std::string old_contents;
+  bool file_exists = false;
   if (old_contents_stream.good()) {
+    file_exists = true;
     std::istreambuf_iterator<char> eos;
     old_contents =
         std::string(std::istreambuf_iterator<char>(old_contents_stream), eos);
     old_contents_stream.close();
   }
-  if (old_contents.length() == 0 || old_contents != contents) {
+  if (!file_exists || old_contents != contents) {
     std::ofstream new_contents_stream;
     new_contents_stream.open(file_path.c_str());
     new_contents_stream << contents;