1ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann// Copyright 2015 PDFium Authors. All rights reserved.
2ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann// Use of this source code is governed by a BSD-style license that can be
3ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann// found in the LICENSE file.
4ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
5ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann#include "testing/js_embedder_test.h"
64d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann#include "third_party/base/ptr_util.h"
7ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
8ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannJSEmbedderTest::JSEmbedderTest()
94d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann    : m_pArrayBufferAllocator(new FXJS_ArrayBufferAllocator),
104d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann      m_pIsolate(nullptr) {}
114d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
124d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. MoltmannJSEmbedderTest::~JSEmbedderTest() {}
134d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann
144d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmannvoid JSEmbedderTest::SetUp() {
15ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann  v8::Isolate::CreateParams params;
16ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann  params.array_buffer_allocator = m_pArrayBufferAllocator.get();
17ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann  m_pIsolate = v8::Isolate::New(params);
18ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
19ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann  EmbedderTest::SetExternalIsolate(m_pIsolate);
20ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann  EmbedderTest::SetUp();
21ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
22ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann  v8::Isolate::Scope isolate_scope(m_pIsolate);
23ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann  v8::HandleScope handle_scope(m_pIsolate);
24ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann  FXJS_PerIsolateData::SetUp(m_pIsolate);
254d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  m_Engine = pdfium::MakeUnique<CFXJS_Engine>(m_pIsolate);
264d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  m_Engine->InitializeEngine();
27ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
28ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
29ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannvoid JSEmbedderTest::TearDown() {
304d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  m_Engine->ReleaseEngine();
314d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  m_Engine.reset();
32ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann  EmbedderTest::TearDown();
334d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  m_pIsolate->Dispose();
344d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  m_pIsolate = nullptr;
35ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
36ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
37ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannv8::Isolate* JSEmbedderTest::isolate() {
38ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann  return m_pIsolate;
39ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
40ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
41ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannv8::Local<v8::Context> JSEmbedderTest::GetV8Context() {
424d3acf4ec42bf6e838f9060103aff98fbf170794Philip P. Moltmann  return m_Engine->GetPersistentContext();
43ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
44