v8  9.0.257(node16.0.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 #include <vector>
10 
11 #include "cppgc/platform.h"
12 #include "libplatform/libplatform.h"
13 #include "v8config.h" // NOLINT(build/include_directory)
14 
15 namespace cppgc {
16 
17 /**
18  * Platform provided by cppgc. Uses V8's DefaultPlatform provided by
19  * libplatform internally. Exception: `GetForegroundTaskRunner()`, see below.
20  */
22  public:
23  /**
24  * Use this method instead of 'cppgc::InitializeProcess' when using
25  * 'cppgc::DefaultPlatform'. 'cppgc::DefaultPlatform::InitializeProcess'
26  * will initialize cppgc and v8 if needed (for non-standalone builds).
27  *
28  * \param platform DefaultPlatform instance used to initialize cppgc/v8.
29  */
30  static void InitializeProcess(DefaultPlatform* platform);
31 
32  using IdleTaskSupport = v8::platform::IdleTaskSupport;
33  explicit DefaultPlatform(
34  int thread_pool_size = 0,
35  IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
36  std::unique_ptr<TracingController> tracing_controller = {})
38  thread_pool_size, idle_task_support,
40  std::move(tracing_controller))) {}
41 
42  cppgc::PageAllocator* GetPageAllocator() override {
44  }
45 
46  double MonotonicallyIncreasingTime() override {
48  }
49 
50  std::shared_ptr<cppgc::TaskRunner> GetForegroundTaskRunner() override {
51  // V8's default platform creates a new task runner when passed the
52  // `v8::Isolate` pointer the first time. For non-default platforms this will
53  // require getting the appropriate task runner.
55  }
56 
57  std::unique_ptr<cppgc::JobHandle> PostJob(
58  cppgc::TaskPriority priority,
59  std::unique_ptr<cppgc::JobTask> job_task) override {
60  return v8_platform_->PostJob(priority, std::move(job_task));
61  }
62 
63  TracingController* GetTracingController() override {
65  }
66 
67  protected:
68  static constexpr v8::Isolate* kNoIsolate = nullptr;
69 
70  std::unique_ptr<v8::Platform> v8_platform_;
71 };
72 
73 } // namespace cppgc
74 
75 #endif // INCLUDE_CPPGC_DEFAULT_PLATFORM_H_
cppgc::DefaultPlatform::GetForegroundTaskRunner
std::shared_ptr< cppgc::TaskRunner > GetForegroundTaskRunner() override
Definition: default-platform.h:50
v8::platform::InProcessStackDumping::kDisabled
@ kDisabled
cppgc::DefaultPlatform
Definition: default-platform.h:21
cppgc::DefaultPlatform::GetTracingController
TracingController * GetTracingController() override
Definition: default-platform.h:63
v8::platform::IdleTaskSupport
IdleTaskSupport
Definition: libplatform.h:18
cppgc::DefaultPlatform::kNoIsolate
static constexpr v8::Isolate * kNoIsolate
Definition: default-platform.h:68
v8::platform
Definition: libplatform.h:16
cppgc::DefaultPlatform::InitializeProcess
static void InitializeProcess(DefaultPlatform *platform)
cppgc
Definition: allocation.h:17
cppgc::DefaultPlatform::PostJob
std::unique_ptr< cppgc::JobHandle > PostJob(cppgc::TaskPriority priority, std::unique_ptr< cppgc::JobTask > job_task) override
Definition: default-platform.h:57
V8_EXPORT
#define V8_EXPORT
Definition: v8config.h:512
v8::Isolate
Definition: v8.h:8450
cppgc::DefaultPlatform::DefaultPlatform
DefaultPlatform(int thread_pool_size=0, IdleTaskSupport idle_task_support=IdleTaskSupport::kDisabled, std::unique_ptr< TracingController > tracing_controller={})
Definition: default-platform.h:33
v8
Definition: libplatform.h:15
cppgc::DefaultPlatform::GetPageAllocator
cppgc::PageAllocator * GetPageAllocator() override
Definition: default-platform.h:42
v8::Platform
Definition: v8-platform.h:522
v8::Platform::GetTracingController
virtual TracingController * GetTracingController()=0
v8::Platform::GetForegroundTaskRunner
virtual std::shared_ptr< v8::TaskRunner > GetForegroundTaskRunner(Isolate *isolate)=0
cppgc::Platform
Definition: platform.h:28
v8::Platform::PostJob
virtual std::unique_ptr< JobHandle > PostJob(TaskPriority priority, std::unique_ptr< JobTask > job_task)=0
cppgc::DefaultPlatform::v8_platform_
std::unique_ptr< v8::Platform > v8_platform_
Definition: default-platform.h:70
v8::platform::IdleTaskSupport::kDisabled
@ kDisabled
v8::platform::InProcessStackDumping
InProcessStackDumping
Definition: libplatform.h:19
v8::Platform::GetPageAllocator
virtual PageAllocator * GetPageAllocator()
Definition: v8-platform.h:529
v8::Platform::MonotonicallyIncreasingTime
virtual double MonotonicallyIncreasingTime()=0
v8::platform::NewDefaultPlatform
V8_PLATFORM_EXPORT std::unique_ptr< v8::Platform > NewDefaultPlatform(int thread_pool_size=0, IdleTaskSupport idle_task_support=IdleTaskSupport::kDisabled, InProcessStackDumping in_process_stack_dumping=InProcessStackDumping::kDisabled, std::unique_ptr< v8::TracingController > tracing_controller={})
cppgc::DefaultPlatform::MonotonicallyIncreasingTime
double MonotonicallyIncreasingTime() override
Definition: default-platform.h:46