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