xref: /aosp_15_r20/external/pdfium/testing/fuzzers/xfa_process_state.cc (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1*3ac0a46fSAndroid Build Coastguard Worker // Copyright 2020 The PDFium Authors
2*3ac0a46fSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*3ac0a46fSAndroid Build Coastguard Worker // found in the LICENSE file.
4*3ac0a46fSAndroid Build Coastguard Worker 
5*3ac0a46fSAndroid Build Coastguard Worker #include "testing/fuzzers/xfa_process_state.h"
6*3ac0a46fSAndroid Build Coastguard Worker 
7*3ac0a46fSAndroid Build Coastguard Worker #include "fxjs/gc/heap.h"
8*3ac0a46fSAndroid Build Coastguard Worker #include "v8/include/libplatform/libplatform.h"
9*3ac0a46fSAndroid Build Coastguard Worker 
XFAProcessState(v8::Platform * platform,v8::Isolate * isolate)10*3ac0a46fSAndroid Build Coastguard Worker XFAProcessState::XFAProcessState(v8::Platform* platform, v8::Isolate* isolate)
11*3ac0a46fSAndroid Build Coastguard Worker     : platform_(platform), isolate_(isolate), heap_(FXGC_CreateHeap()) {}
12*3ac0a46fSAndroid Build Coastguard Worker 
~XFAProcessState()13*3ac0a46fSAndroid Build Coastguard Worker XFAProcessState::~XFAProcessState() {
14*3ac0a46fSAndroid Build Coastguard Worker   FXGC_ForceGarbageCollection(heap_.get());
15*3ac0a46fSAndroid Build Coastguard Worker }
16*3ac0a46fSAndroid Build Coastguard Worker 
GetHeap() const17*3ac0a46fSAndroid Build Coastguard Worker cppgc::Heap* XFAProcessState::GetHeap() const {
18*3ac0a46fSAndroid Build Coastguard Worker   return heap_.get();
19*3ac0a46fSAndroid Build Coastguard Worker }
20*3ac0a46fSAndroid Build Coastguard Worker 
ForceGCAndPump()21*3ac0a46fSAndroid Build Coastguard Worker void XFAProcessState::ForceGCAndPump() {
22*3ac0a46fSAndroid Build Coastguard Worker   FXGC_ForceGarbageCollection(heap_.get());
23*3ac0a46fSAndroid Build Coastguard Worker   while (v8::platform::PumpMessageLoop(platform_, isolate_))
24*3ac0a46fSAndroid Build Coastguard Worker     continue;
25*3ac0a46fSAndroid Build Coastguard Worker }
26