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 #include "third_party/base/ptr_util.h" 7 JSEmbedderTest()8JSEmbedderTest::JSEmbedderTest() 9 : m_pArrayBufferAllocator(new FXJS_ArrayBufferAllocator), 10 m_pIsolate(nullptr) {} 11 ~JSEmbedderTest()12JSEmbedderTest::~JSEmbedderTest() {} 13 SetUp()14void JSEmbedderTest::SetUp() { 15 v8::Isolate::CreateParams params; 16 params.array_buffer_allocator = m_pArrayBufferAllocator.get(); 17 m_pIsolate = v8::Isolate::New(params); 18 19 EmbedderTest::SetExternalIsolate(m_pIsolate); 20 EmbedderTest::SetUp(); 21 22 v8::Isolate::Scope isolate_scope(m_pIsolate); 23 v8::HandleScope handle_scope(m_pIsolate); 24 FXJS_PerIsolateData::SetUp(m_pIsolate); 25 m_Engine = pdfium::MakeUnique<CFXJS_Engine>(m_pIsolate); 26 m_Engine->InitializeEngine(); 27 } 28 TearDown()29void JSEmbedderTest::TearDown() { 30 m_Engine->ReleaseEngine(); 31 m_Engine.reset(); 32 EmbedderTest::TearDown(); 33 m_pIsolate->Dispose(); 34 m_pIsolate = nullptr; 35 } 36 isolate()37v8::Isolate* JSEmbedderTest::isolate() { 38 return m_pIsolate; 39 } 40 GetV8Context()41v8::Local<v8::Context> JSEmbedderTest::GetV8Context() { 42 return m_Engine->GetPersistentContext(); 43 } 44