v8
9.4.146 (node 16.13.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
*/
21
class
V8_EXPORT
DefaultPlatform
:
public
Platform
{
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 = {})
37
:
v8_platform_
(
v8
::
platform
::
NewDefaultPlatform
(
38
thread_pool_size
,
idle_task_support
,
39
v8
::
platform
::
InProcessStackDumping
::
kDisabled
,
40
std::move(tracing_controller)
)
) {}
41
42
cppgc
::PageAllocator*
GetPageAllocator
()
override
{
43
return
v8_platform_
->
GetPageAllocator
(
)
;
44
}
45
46
double
MonotonicallyIncreasingTime
()
override
{
47
return
v8_platform_
->
MonotonicallyIncreasingTime
(
)
;
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.
54
return
v8_platform_
->
GetForegroundTaskRunner
(
kNoIsolate
)
;
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
{
64
return
v8_platform_
->
GetTracingController
(
)
;
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_
include
cppgc
default-platform.h
Generated on Fri Oct 29 2021 20:27:42 for v8 by
1.9.1