blob: 064a96104917496a6eeb840d8eeb8c7bdd70ae5a [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"
tsepez36eb4bd2016-10-03 15:24:27 -07006#include "third_party/base/ptr_util.h"
Lei Zhang1ac47eb2015-12-21 11:04:44 -08007
8JSEmbedderTest::JSEmbedderTest()
jochen38a1f0a2016-05-31 12:07:40 -07009 : m_pArrayBufferAllocator(new FXJS_ArrayBufferAllocator),
10 m_pIsolate(nullptr) {}
11
12JSEmbedderTest::~JSEmbedderTest() {}
13
14void JSEmbedderTest::SetUp() {
Lei Zhang1ac47eb2015-12-21 11:04:44 -080015 v8::Isolate::CreateParams params;
16 params.array_buffer_allocator = m_pArrayBufferAllocator.get();
17 m_pIsolate = v8::Isolate::New(params);
Lei Zhang1ac47eb2015-12-21 11:04:44 -080018
Lei Zhang1ac47eb2015-12-21 11:04:44 -080019 EmbedderTest::SetExternalIsolate(m_pIsolate);
20 EmbedderTest::SetUp();
21
22 v8::Isolate::Scope isolate_scope(m_pIsolate);
Lei Zhang1ac47eb2015-12-21 11:04:44 -080023 v8::HandleScope handle_scope(m_pIsolate);
24 FXJS_PerIsolateData::SetUp(m_pIsolate);
tsepez36eb4bd2016-10-03 15:24:27 -070025 m_Engine = pdfium::MakeUnique<CFXJS_Engine>(m_pIsolate);
tsepezb4694242016-08-15 16:44:55 -070026 m_Engine->InitializeEngine();
Lei Zhang1ac47eb2015-12-21 11:04:44 -080027}
28
29void JSEmbedderTest::TearDown() {
tsepezb4694242016-08-15 16:44:55 -070030 m_Engine->ReleaseEngine();
31 m_Engine.reset();
Lei Zhang1ac47eb2015-12-21 11:04:44 -080032 EmbedderTest::TearDown();
jochen38a1f0a2016-05-31 12:07:40 -070033 m_pIsolate->Dispose();
34 m_pIsolate = nullptr;
Lei Zhang1ac47eb2015-12-21 11:04:44 -080035}
36
37v8::Isolate* JSEmbedderTest::isolate() {
38 return m_pIsolate;
39}
40
41v8::Local<v8::Context> JSEmbedderTest::GetV8Context() {
tsepezb4694242016-08-15 16:44:55 -070042 return m_Engine->GetPersistentContext();
Lei Zhang1ac47eb2015-12-21 11:04:44 -080043}