blob: 1ca957b44fe58e13d749e3cba5443048d52d6511 [file] [log] [blame]
Lei Zhang1ac47eb2015-12-21 11:04:44 -08001// Copyright 2015 PDFium 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#include "testing/js_embedder_test.h"
Lei Zhange75538b2017-12-20 19:33:20 +00006
tsepez36eb4bd2016-10-03 15:24:27 -07007#include "third_party/base/ptr_util.h"
Lei Zhang1ac47eb2015-12-21 11:04:44 -08008
9JSEmbedderTest::JSEmbedderTest()
Tom Sepez3f8ee5e2018-02-09 18:26:09 +000010 : m_pArrayBufferAllocator(
11 pdfium::MakeUnique<CFX_V8ArrayBufferAllocator>()) {}
jochen38a1f0a2016-05-31 12:07:40 -070012
13JSEmbedderTest::~JSEmbedderTest() {}
14
15void JSEmbedderTest::SetUp() {
Lei Zhang1ac47eb2015-12-21 11:04:44 -080016 v8::Isolate::CreateParams params;
17 params.array_buffer_allocator = m_pArrayBufferAllocator.get();
18 m_pIsolate = v8::Isolate::New(params);
Lei Zhang1ac47eb2015-12-21 11:04:44 -080019
Lei Zhang1ac47eb2015-12-21 11:04:44 -080020 EmbedderTest::SetExternalIsolate(m_pIsolate);
21 EmbedderTest::SetUp();
22
23 v8::Isolate::Scope isolate_scope(m_pIsolate);
Lei Zhang1ac47eb2015-12-21 11:04:44 -080024 v8::HandleScope handle_scope(m_pIsolate);
25 FXJS_PerIsolateData::SetUp(m_pIsolate);
tsepez36eb4bd2016-10-03 15:24:27 -070026 m_Engine = pdfium::MakeUnique<CFXJS_Engine>(m_pIsolate);
tsepezb4694242016-08-15 16:44:55 -070027 m_Engine->InitializeEngine();
Lei Zhang1ac47eb2015-12-21 11:04:44 -080028}
29
30void JSEmbedderTest::TearDown() {
tsepezb4694242016-08-15 16:44:55 -070031 m_Engine->ReleaseEngine();
32 m_Engine.reset();
Lei Zhang1ac47eb2015-12-21 11:04:44 -080033 EmbedderTest::TearDown();
jochen38a1f0a2016-05-31 12:07:40 -070034 m_pIsolate->Dispose();
35 m_pIsolate = nullptr;
Lei Zhang1ac47eb2015-12-21 11:04:44 -080036}
37
38v8::Isolate* JSEmbedderTest::isolate() {
39 return m_pIsolate;
40}
41
42v8::Local<v8::Context> JSEmbedderTest::GetV8Context() {
Tom Sepez1258f7f2018-02-02 17:37:37 +000043 return m_Engine->GetV8Context();
Lei Zhang1ac47eb2015-12-21 11:04:44 -080044}