unified-heap: Switch embedder snapshot type via GN flag

Instead of relying on OFFICIAL_BUILD, rely on a specific GN flag that can be
toggled.

V8 CL: http://crrev.com/c/1505372

Bug: 936797
Change-Id: I4e02e10be3b914c1c75f84b4d01d9d0b1b1d5ca1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1504573
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#639432}
diff --git a/third_party/blink/renderer/platform/BUILD.gn b/third_party/blink/renderer/platform/BUILD.gn
index 37ebc7e..c09297c 100644
--- a/third_party/blink/renderer/platform/BUILD.gn
+++ b/third_party/blink/renderer/platform/BUILD.gn
@@ -13,6 +13,7 @@
 import("//third_party/blink/renderer/build/scripts/scripts.gni")
 import("//third_party/blink/renderer/config.gni")
 import("//third_party/blink/renderer/platform/platform_generated.gni")
+import("//v8/gni/v8.gni")
 
 # Most targets in this file are private actions so use that as the default.
 visibility = [ ":*" ]
@@ -164,8 +165,8 @@
   visibility = []  # Allow re-assignment of list.
   visibility = [ "//third_party/blink/renderer/platform/*" ]
   public_deps = [
+    ":bindings_buildflags",
     ":make_platform_generated",
-    ":rcs_count_everything_buildflags",
     "//base",
     "//cc",
     "//cc/animation",
@@ -210,12 +211,14 @@
   runtime_call_stats_count_everything = false
 }
 
-buildflag_header("rcs_count_everything_buildflags") {
-  header = "runtime_call_stats_count_everything_buildflags.h"
-
+buildflag_header("bindings_buildflags") {
+  header = "buildflags.h"
   header_dir = "third_party/blink/renderer/platform/bindings"
 
-  flags = [ "RCS_COUNT_EVERYTHING=$runtime_call_stats_count_everything" ]
+  flags = [
+    "FULL_HEAP_SNAPSHOTS=$v8_enable_full_heap_snapshots",
+    "RCS_COUNT_EVERYTHING=$runtime_call_stats_count_everything",
+  ]
 }
 
 config("blink_platform_implementation") {
diff --git a/third_party/blink/renderer/platform/bindings/name_client.h b/third_party/blink/renderer/platform/bindings/name_client.h
index 97f220a..5d9cb55 100644
--- a/third_party/blink/renderer/platform/bindings/name_client.h
+++ b/third_party/blink/renderer/platform/bindings/name_client.h
@@ -6,6 +6,7 @@
 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_NAME_CLIENT_H_
 
 #include "base/macros.h"
+#include "third_party/blink/renderer/platform/bindings/buildflags.h"
 #include "third_party/blink/renderer/platform/platform_export.h"
 
 namespace blink {
@@ -14,6 +15,15 @@
 // the object graph.
 class PLATFORM_EXPORT NameClient {
  public:
+  static constexpr bool HideInternalName() {
+#if BUILDFLAG(FULL_HEAP_SNAPSHOTS) && \
+    (defined(COMPILER_GCC) || defined(__clang__))
+    return false;
+#else
+    return true;
+#endif  // BUILDFLAG(FULL_HEAP_SNAPSHOTS)
+  }
+
   NameClient() = default;
   ~NameClient() = default;
 
diff --git a/third_party/blink/renderer/platform/bindings/runtime_call_stats.h b/third_party/blink/renderer/platform/bindings/runtime_call_stats.h
index 8af5ea3..2716de4 100644
--- a/third_party/blink/renderer/platform/bindings/runtime_call_stats.h
+++ b/third_party/blink/renderer/platform/bindings/runtime_call_stats.h
@@ -9,7 +9,7 @@
 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_RUNTIME_CALL_STATS_H_
 
 #include "base/optional.h"
-#include "third_party/blink/renderer/platform/bindings/runtime_call_stats_count_everything_buildflags.h"
+#include "third_party/blink/renderer/platform/bindings/buildflags.h"
 #include "third_party/blink/renderer/platform/platform_export.h"
 #include "third_party/blink/renderer/platform/runtime_enabled_features.h"
 #include "third_party/blink/renderer/platform/wtf/allocator.h"
diff --git a/third_party/blink/renderer/platform/heap/name_trait_test.cc b/third_party/blink/renderer/platform/heap/name_trait_test.cc
index 44fb5e3..a7d5ac3 100644
--- a/third_party/blink/renderer/platform/heap/name_trait_test.cc
+++ b/third_party/blink/renderer/platform/heap/name_trait_test.cc
@@ -6,20 +6,21 @@
 
 #include "build/build_config.h"
 #include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/blink/renderer/platform/bindings/name_client.h"
 #include "third_party/blink/renderer/platform/heap/name_traits.h"
 
 namespace blink {
 
 namespace {
 
-class ClassWithoutName {
+class ClassWithoutName final {
  public:
   ClassWithoutName() = default;
 };
 
-class ClassWithName : public NameClient {
+class ClassWithName final : public NameClient {
  public:
-  ClassWithName(const char* name) : name_(name) {}
+  explicit ClassWithName(const char* name) : name_(name) {}
 
   const char* NameInHeapSnapshot() const final { return name_; }
 
@@ -30,15 +31,28 @@
 }  // namespace
 
 TEST(NameTraitTest, InternalNamesHiddenInOfficialBuild) {
+  // Use a test instead of static_assert to allow local builds but block
+  // enabling the feature accidentally through the waterfall.
+  //
+  // Do not include such type information in official builds to
+  // (a) safe binary size on string literals, and
+  // (b) avoid exposing internal types until it has been clarified whether
+  //     exposing internals in DevTools is fine.
 #if defined(OFFICIAL_BUILD)
-  EXPECT_TRUE(NameTrait<ClassWithoutName>::HideInternalName());
+  EXPECT_TRUE(NameClient::HideInternalName());
 #endif
 }
 
+TEST(NameTraitTest, InternalNamesHiddenWhenFlagIsTurnedOff) {
+#if !BUILDFLAG(FULL_HEAP_SNAPSHOTS)
+  EXPECT_TRUE(NameClient::HideInternalName());
+#endif  // BUILDFLAG(FULL_HEAP_SNAPSHOTS)
+}
+
 TEST(NameTraitTest, DefaultName) {
   ClassWithoutName no_name;
   const char* name = NameTrait<ClassWithoutName>::GetName(&no_name).value;
-  if (NameTrait<ClassWithoutName>::HideInternalName()) {
+  if (NameClient::HideInternalName()) {
     EXPECT_EQ(0, strcmp(name, "InternalNode"));
   } else {
     EXPECT_NE(nullptr, strstr(name, "ClassWithoutName"));
diff --git a/third_party/blink/renderer/platform/heap/name_traits.h b/third_party/blink/renderer/platform/heap/name_traits.h
index c994d5e..eda1cc1 100644
--- a/third_party/blink/renderer/platform/heap/name_traits.h
+++ b/third_party/blink/renderer/platform/heap/name_traits.h
@@ -24,14 +24,6 @@
   STATIC_ONLY(NameTrait);
 
  public:
-  static constexpr bool HideInternalName() {
-#if defined(OFFICIAL_BUILD) || !(defined(COMPILER_GCC) || defined(__clang__))
-    return true;
-#else
-    return false;
-#endif
-  }
-
   static HeapObjectName GetName(const void* obj) {
     return GetNameFor(static_cast<const T*>(obj));
   }
@@ -42,17 +34,10 @@
   }
 
   static HeapObjectName GetNameFor(...) {
-    // For non-official builds construct the name of a type from a compiler
-    // intrinsic.
-    //
-    // Do not include such type information in official builds to
-    // (a) safe binary size on string literals, and
-    // (b) avoid exposing internal types until a proper DevTools frontend
-    //     implementation is present.
-#if defined(OFFICIAL_BUILD) || !(defined(COMPILER_GCC) || defined(__clang__))
-    return {"InternalNode", true};
-#else
-    DCHECK(!HideInternalName());
+    if (NameClient::HideInternalName())
+      return {"InternalNode", true};
+
+    DCHECK(!NameClient::HideInternalName());
     static const char* leaky_class_name = nullptr;
     if (leaky_class_name)
       return {leaky_class_name, false};
@@ -67,7 +52,6 @@
     const std::string name = raw.substr(start_pos, len).c_str();
     leaky_class_name = strcpy(new char[name.length() + 1], name.c_str());
     return {leaky_class_name, false};
-#endif
   }
 };