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 <omerkatz@chromium.org>
Auto-Submit: Omer Katz <omerkatz@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79141}
This commit is contained in:
Omer Katz 2022-02-17 11:40:48 +01:00 committed by V8 LUCI CQ
parent 35fefc5976
commit 6f8b501c31
3 changed files with 12 additions and 3 deletions

View File

@ -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;

View File

@ -7,6 +7,7 @@
#include <memory>
#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

View File

@ -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<int>(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 {