From 6f8b501c31bd99f22334bd8fb04e835f9bf14fd4 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Thu, 17 Feb 2022 11:40:48 +0100 Subject: [PATCH] cppgc: Informative message in case of delete Outside of unittests, if someone tried to delete a GCed object manually they would get a silent crash without a stacktrace or any error messages. This CL replaces the silent crash with an informative message. Change-Id: Ied8895dab43ce7e3a9bf778b13e77d377d269fce Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3468346 Commit-Queue: Omer Katz Auto-Submit: Omer Katz Reviewed-by: Michael Lippautz Commit-Queue: Michael Lippautz Cr-Commit-Position: refs/heads/main@{#79141} --- include/cppgc/garbage-collected.h | 3 ++- include/cppgc/platform.h | 4 +++- src/heap/cppgc/platform.cc | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/cppgc/garbage-collected.h b/include/cppgc/garbage-collected.h index 75d127ee9c..6737c8be49 100644 --- a/include/cppgc/garbage-collected.h +++ b/include/cppgc/garbage-collected.h @@ -62,7 +62,8 @@ class GarbageCollected { // virtual destructor requires an unambiguous, accessible 'operator delete'. void operator delete(void*) { #ifdef V8_ENABLE_CHECKS - internal::Abort(); + internal::Fatal( + "Manually deleting a garbage collected object is not allowed"); #endif // V8_ENABLE_CHECKS } void operator delete[](void*) = delete; diff --git a/include/cppgc/platform.h b/include/cppgc/platform.h index 3276a26b65..5d5f8796ad 100644 --- a/include/cppgc/platform.h +++ b/include/cppgc/platform.h @@ -7,6 +7,7 @@ #include +#include "cppgc/source-location.h" #include "v8-platform.h" // NOLINT(build/include_directory) #include "v8config.h" // NOLINT(build/include_directory) @@ -145,7 +146,8 @@ V8_EXPORT void ShutdownProcess(); namespace internal { -V8_EXPORT void Abort(); +V8_EXPORT void Fatal(const std::string& reason = std::string(), + const SourceLocation& = SourceLocation::Current()); } // namespace internal diff --git a/src/heap/cppgc/platform.cc b/src/heap/cppgc/platform.cc index fd769ae469..ba5d2a18d0 100644 --- a/src/heap/cppgc/platform.cc +++ b/src/heap/cppgc/platform.cc @@ -16,7 +16,13 @@ namespace cppgc { namespace internal { -void Abort() { v8::base::OS::Abort(); } +void Fatal(const std::string& reason, const SourceLocation& loc) { +#ifdef DEBUG + V8_Fatal(loc.FileName(), static_cast(loc.Line()), "%s", reason.c_str()); +#else // !DEBUG + V8_Fatal("%s", reason.c_str()); +#endif // !DEBUG +} void FatalOutOfMemoryHandler::operator()(const std::string& reason, const SourceLocation& loc) const {