v8  10.1.124 (node 18.2.0)
V8 is Google's open source JavaScript engine
default-platform.h
Go to the documentation of this file.
1 // Copyright 2020 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 INCLUDE_CPPGC_DEFAULT_PLATFORM_H_
6 #define INCLUDE_CPPGC_DEFAULT_PLATFORM_H_
7 
8 #include <memory>
9 
10 #include "cppgc/platform.h"
11 #include "libplatform/libplatform.h"
12 #include "v8config.h" // NOLINT(build/include_directory)
13 
14 namespace cppgc {
15 
16 /**
17  * Platform provided by cppgc. Uses V8's DefaultPlatform provided by
18  * libplatform internally. Exception: `GetForegroundTaskRunner()`, see below.
19  */
21  public:
22  /**
23  * Use this method instead of 'cppgc::InitializeProcess' when using
24  * 'cppgc::DefaultPlatform'. 'cppgc::DefaultPlatform::InitializeProcess'
25  * will initialize cppgc and v8 if needed (for non-standalone builds).
26  *
27  * \param platform DefaultPlatform instance used to initialize cppgc/v8.
28  */
29  static void InitializeProcess(DefaultPlatform* platform);
30 
31  using IdleTaskSupport = v8::platform::IdleTaskSupport;
32  explicit DefaultPlatform(
33  int thread_pool_size = 0,
34  IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
35  std::unique_ptr<TracingController> tracing_controller = {})
37  thread_pool_size, idle_task_support,
39  std::move(tracing_controller))) {}
40 
41  cppgc::PageAllocator* GetPageAllocator() override {
43  }
44 
45  double MonotonicallyIncreasingTime() override {
47  }
48 
49  std::shared_ptr<cppgc::TaskRunner> GetForegroundTaskRunner() override {
50  // V8's default platform creates a new task runner when passed the
51  // `v8::Isolate` pointer the first time. For non-default platforms this will
52  // require getting the appropriate task runner.
54  }
55 
56  std::unique_ptr<cppgc::JobHandle> PostJob(
57  cppgc::TaskPriority priority,
58  std::unique_ptr<cppgc::JobTask> job_task) override {
59  return v8_platform_->PostJob(priority, std::move(job_task));
60  }
61 
62  TracingController* GetTracingController() override {
64  }
65 
66  v8::Platform* GetV8Platform() const { return v8_platform_.get(); }
67 
68  protected:
69  static constexpr v8::Isolate* kNoIsolate = nullptr;
70 
71  std::unique_ptr<v8::Platform> v8_platform_;
72 };
73 
74 } // namespace cppgc
75 
76 #endif // INCLUDE_CPPGC_DEFAULT_PLATFORM_H_