1// 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()
8    : m_pArrayBufferAllocator(new FXJS_ArrayBufferAllocator) {
9  v8::Isolate::CreateParams params;
10  params.array_buffer_allocator = m_pArrayBufferAllocator.get();
11  m_pIsolate = v8::Isolate::New(params);
12}
13
14JSEmbedderTest::~JSEmbedderTest() {
15  m_pIsolate->Dispose();
16}
17
18void JSEmbedderTest::SetUp() {
19  EmbedderTest::SetExternalIsolate(m_pIsolate);
20  EmbedderTest::SetUp();
21
22  v8::Isolate::Scope isolate_scope(m_pIsolate);
23#ifdef PDF_ENABLE_XFA
24  v8::Locker locker(m_pIsolate);
25#endif  // PDF_ENABLE_XFA
26  v8::HandleScope handle_scope(m_pIsolate);
27  FXJS_PerIsolateData::SetUp(m_pIsolate);
28  FXJS_InitializeRuntime(m_pIsolate, nullptr, &m_pPersistentContext,
29                         &m_StaticObjects);
30}
31
32void JSEmbedderTest::TearDown() {
33  FXJS_ReleaseRuntime(m_pIsolate, &m_pPersistentContext, &m_StaticObjects);
34  m_pPersistentContext.Reset();
35  FXJS_Release();
36  EmbedderTest::TearDown();
37}
38
39v8::Isolate* JSEmbedderTest::isolate() {
40  return m_pIsolate;
41}
42
43v8::Local<v8::Context> JSEmbedderTest::GetV8Context() {
44  return m_pPersistentContext.Get(m_pIsolate);
45}
46