Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
v8_test_environment.cpp
Go to the documentation of this file.
1
// Copyright 2020 The PDFium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#
include
"testing/v8_test_environment.h"
6
7
#
include
<
memory
>
8
#
include
<
string
>
9
10
#
include
"core/fxcrt/check.h"
11
#
include
"core/fxcrt/fx_system.h"
12
#
include
"testing/v8_initializer.h"
13
#
include
"v8/include/libplatform/libplatform.h"
14
#
include
"v8/include/v8-isolate.h"
15
#
include
"v8/include/v8-platform.h"
16
#
include
"v8/include/v8-snapshot.h"
17
18
namespace
{
19
20
V8TestEnvironment
* g_environment =
nullptr
;
21
22
}
// namespace
23
24
V8TestEnvironment
::
V8TestEnvironment
(
const
char
* exe_name)
25
: exe_path_(exe_name),
26
array_buffer_allocator_
(
std
::
make_unique
<
CFX_V8ArrayBufferAllocator
>()) {
27
DCHECK
(!g_environment);
28
g_environment =
this
;
29
}
30
31
V8TestEnvironment
::~
V8TestEnvironment
() {
32
DCHECK
(g_environment);
33
34
#
ifdef
V8_USE_EXTERNAL_STARTUP_DATA
35
if
(startup_data_)
36
free(
const_cast
<
char
*>(startup_data_->data));
37
#
endif
// V8_USE_EXTERNAL_STARTUP_DATA
38
39
g_environment =
nullptr
;
40
}
41
42
// static
43
V8TestEnvironment
*
V8TestEnvironment
::
GetInstance
() {
44
return
g_environment;
45
}
46
47
// static
48
void
V8TestEnvironment
::
PumpPlatformMessageLoop
(
v8
::Isolate* isolate) {
49
v8
::Platform* platform =
GetInstance
(
)
->
platform
(
)
;
50
while
(v8::platform::PumpMessageLoop(platform, isolate))
51
continue
;
52
}
53
54
void
V8TestEnvironment
::
SetUp
() {
55
#
ifdef
V8_USE_EXTERNAL_STARTUP_DATA
56
if
(startup_data_) {
57
platform_ = InitializeV8ForPDFiumWithStartupData(exe_path_, std::string(),
58
std::string(),
nullptr
);
59
}
else
{
60
startup_data_ = std::make_unique<v8::StartupData>();
61
platform_ = InitializeV8ForPDFiumWithStartupData(
62
exe_path_, std::string(), std::string(), startup_data_.get());
63
}
64
#
else
65
platform_ = InitializeV8ForPDFium(std::string(), exe_path_);
66
#
endif
// V8_USE_EXTERNAL_STARTUP_DATA
67
68
v8::Isolate::CreateParams params;
69
params.array_buffer_allocator = array_buffer_allocator_.get();
70
isolate_.reset(v8::Isolate::New(params));
71
}
72
73
void
V8TestEnvironment
::
TearDown
() {
74
isolate_.reset();
75
ShutdownV8ForPDFium
(
)
;
76
}
DCHECK
#define DCHECK
Definition
check.h:33
V8TestEnvironment
Definition
v8_test_environment.h:26
V8TestEnvironment::platform
v8::Platform * platform() const
Definition
v8_test_environment.h:40
V8TestEnvironment::V8TestEnvironment
V8TestEnvironment(const char *exe_path)
Definition
v8_test_environment.cpp:24
V8TestEnvironment::~V8TestEnvironment
~V8TestEnvironment() override
Definition
v8_test_environment.cpp:31
V8TestEnvironment::SetUp
void SetUp() override
Definition
v8_test_environment.cpp:54
V8TestEnvironment::PumpPlatformMessageLoop
static void PumpPlatformMessageLoop(v8::Isolate *pIsolate)
Definition
v8_test_environment.cpp:48
V8TestEnvironment::TearDown
void TearDown() override
Definition
v8_test_environment.cpp:73
V8TestEnvironment::GetInstance
static V8TestEnvironment * GetInstance()
Definition
v8_test_environment.cpp:43
v8
Definition
fxv8_unittest.h:15
ShutdownV8ForPDFium
void ShutdownV8ForPDFium()
Definition
v8_initializer.cpp:119
qtwebengine
src
3rdparty
chromium
third_party
pdfium
testing
v8_test_environment.cpp
Generated on
for Qt by
1.18.0