blob: 1b21fe04db119fae2f2a06bca7f3bfceb9b7210d [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"
6
7JSEmbedderTest::JSEmbedderTest()
jochen38a1f0a2016-05-31 12:07:40 -07008 : m_pArrayBufferAllocator(new FXJS_ArrayBufferAllocator),
9 m_pIsolate(nullptr) {}
10
11JSEmbedderTest::~JSEmbedderTest() {}
12
13void JSEmbedderTest::SetUp() {
Lei Zhang1ac47eb2015-12-21 11:04:44 -080014 v8::Isolate::CreateParams params;
15 params.array_buffer_allocator = m_pArrayBufferAllocator.get();
16 m_pIsolate = v8::Isolate::New(params);
Lei Zhang1ac47eb2015-12-21 11:04:44 -080017
Lei Zhang1ac47eb2015-12-21 11:04:44 -080018 EmbedderTest::SetExternalIsolate(m_pIsolate);
19 EmbedderTest::SetUp();
20
21 v8::Isolate::Scope isolate_scope(m_pIsolate);
Lei Zhang1ac47eb2015-12-21 11:04:44 -080022 v8::HandleScope handle_scope(m_pIsolate);
23 FXJS_PerIsolateData::SetUp(m_pIsolate);
tsepeza4941912016-08-15 11:40:12 -070024 FXJS_InitializeEngine(m_pIsolate, nullptr, &m_pPersistentContext,
25 &m_StaticObjects);
Lei Zhang1ac47eb2015-12-21 11:04:44 -080026}
27
28void JSEmbedderTest::TearDown() {
tsepeza4941912016-08-15 11:40:12 -070029 FXJS_ReleaseEngine(m_pIsolate, &m_pPersistentContext, &m_StaticObjects);
Lei Zhang1ac47eb2015-12-21 11:04:44 -080030 m_pPersistentContext.Reset();
Lei Zhang1ac47eb2015-12-21 11:04:44 -080031 EmbedderTest::TearDown();
jochen38a1f0a2016-05-31 12:07:40 -070032 m_pIsolate->Dispose();
33 m_pIsolate = nullptr;
Lei Zhang1ac47eb2015-12-21 11:04:44 -080034}
35
36v8::Isolate* JSEmbedderTest::isolate() {
37 return m_pIsolate;
38}
39
40v8::Local<v8::Context> JSEmbedderTest::GetV8Context() {
41 return m_pPersistentContext.Get(m_pIsolate);
42}