• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 namespace cppgc {
14 namespace internal {
15 
16 class HeapBase;
17 
18 class V8_EXPORT_PRIVATE FatalOutOfMemoryHandler final {
19  public:
20   using Callback = void(const std::string&, const SourceLocation&, HeapBase*);
21 
22   FatalOutOfMemoryHandler() = default;
FatalOutOfMemoryHandler(HeapBase * heap)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