Tom Sepez | a1fe732 | 2018-04-18 22:48:22 +0000 | [diff] [blame] | 1 | // Copyright 2018 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 "fxjs/ijs_runtime.h" |
| 6 | |
Tom Sepez | a1fe732 | 2018-04-18 22:48:22 +0000 | [diff] [blame] | 7 | #include "fxjs/cjs_runtimestub.h" |
| 8 | #include "third_party/base/ptr_util.h" |
| 9 | |
| 10 | #ifdef PDF_ENABLE_V8 |
| 11 | #include "fxjs/cfxjs_engine.h" |
| 12 | #include "fxjs/cjs_runtime.h" |
| 13 | #endif |
| 14 | |
Tom Sepez | 0928bc5 | 2018-08-22 17:40:12 +0000 | [diff] [blame] | 15 | IJS_Runtime::ScopedEventContext::ScopedEventContext(IJS_Runtime* pRuntime) |
| 16 | : m_pRuntime(pRuntime), m_pContext(pRuntime->NewEventContext()) {} |
| 17 | |
| 18 | IJS_Runtime::ScopedEventContext::~ScopedEventContext() { |
| 19 | m_pRuntime->ReleaseEventContext(m_pContext.Release()); |
| 20 | } |
| 21 | |
Tom Sepez | a1fe732 | 2018-04-18 22:48:22 +0000 | [diff] [blame] | 22 | // static |
| 23 | void IJS_Runtime::Initialize(unsigned int slot, void* isolate) { |
| 24 | #ifdef PDF_ENABLE_V8 |
Tom Sepez | 9b8b217 | 2018-04-25 22:12:34 +0000 | [diff] [blame] | 25 | FXJS_Initialize(slot, static_cast<v8::Isolate*>(isolate)); |
Tom Sepez | a1fe732 | 2018-04-18 22:48:22 +0000 | [diff] [blame] | 26 | #endif |
| 27 | } |
| 28 | |
| 29 | // static |
| 30 | void IJS_Runtime::Destroy() { |
| 31 | #ifdef PDF_ENABLE_V8 |
| 32 | FXJS_Release(); |
| 33 | #endif |
| 34 | } |
| 35 | |
| 36 | // static |
| 37 | std::unique_ptr<IJS_Runtime> IJS_Runtime::Create( |
| 38 | CPDFSDK_FormFillEnvironment* pFormFillEnv) { |
| 39 | #ifdef PDF_ENABLE_V8 |
Tom Sepez | 0784c73 | 2018-04-23 18:02:57 +0000 | [diff] [blame] | 40 | if (pFormFillEnv->IsJSPlatformPresent()) |
| 41 | return pdfium::MakeUnique<CJS_Runtime>(pFormFillEnv); |
Tom Sepez | a1fe732 | 2018-04-18 22:48:22 +0000 | [diff] [blame] | 42 | #endif |
Tom Sepez | 0784c73 | 2018-04-23 18:02:57 +0000 | [diff] [blame] | 43 | return pdfium::MakeUnique<CJS_RuntimeStub>(pFormFillEnv); |
Tom Sepez | a1fe732 | 2018-04-18 22:48:22 +0000 | [diff] [blame] | 44 | } |
Tom Sepez | 0784c73 | 2018-04-23 18:02:57 +0000 | [diff] [blame] | 45 | |
| 46 | IJS_Runtime::~IJS_Runtime() = default; |
Dan Sinclair | dc5d88b | 2018-05-17 13:53:52 +0000 | [diff] [blame] | 47 | |
| 48 | IJS_Runtime::JS_Error::JS_Error(int line, |
| 49 | int column, |
| 50 | const WideString& exception) |
| 51 | : line(line), column(column), exception(exception) {} |