xref: /third_party/node/deps/v8/src/heap/cppgc/platform.h (revision 1cb0ef41)
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_HEAP_CPPGC_PLATFORM_H_
6#define V8_HEAP_CPPGC_PLATFORM_H_
7
8#include <string>
9
10#include "include/cppgc/source-location.h"
11#include "src/base/macros.h"
12
13namespace cppgc {
14namespace internal {
15
16class HeapBase;
17
18class V8_EXPORT_PRIVATE FatalOutOfMemoryHandler final {
19 public:
20  using Callback = void(const std::string&, const SourceLocation&, HeapBase*);
21
22  FatalOutOfMemoryHandler() = default;
23  explicit FatalOutOfMemoryHandler(HeapBase* heap) : heap_(heap) {}
24
25  [[noreturn]] void operator()(
26      const std::string& reason = std::string(),
27      const SourceLocation& = SourceLocation::Current()) const;
28
29  void SetCustomHandler(Callback*);
30
31  // Disallow copy/move.
32  FatalOutOfMemoryHandler(const FatalOutOfMemoryHandler&) = delete;
33  FatalOutOfMemoryHandler& operator=(const FatalOutOfMemoryHandler&) = delete;
34
35 private:
36  HeapBase* heap_ = nullptr;
37  Callback* custom_handler_ = nullptr;
38};
39
40}  // namespace internal
41}  // namespace cppgc
42
43#endif  // V8_HEAP_CPPGC_PLATFORM_H_
44