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
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
ScopedEventContext(IJS_Runtime * pRuntime)15 IJS_Runtime::ScopedEventContext::ScopedEventContext(IJS_Runtime* pRuntime)
16 : m_pRuntime(pRuntime), m_pContext(pRuntime->NewEventContext()) {}
17
~ScopedEventContext()18 IJS_Runtime::ScopedEventContext::~ScopedEventContext() {
19 m_pRuntime->ReleaseEventContext(m_pContext.Release());
20 }
21
22 // static
Initialize(unsigned int slot,void * isolate)23 void IJS_Runtime::Initialize(unsigned int slot, void* isolate) {
24 #ifdef PDF_ENABLE_V8
25 FXJS_Initialize(slot, static_cast<v8::Isolate*>(isolate));
26 #endif
27 }
28
29 // static
Destroy()30 void IJS_Runtime::Destroy() {
31 #ifdef PDF_ENABLE_V8
32 FXJS_Release();
33 #endif
34 }
35
36 // static
Create(CPDFSDK_FormFillEnvironment * pFormFillEnv)37 std::unique_ptr<IJS_Runtime> IJS_Runtime::Create(
38 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
39 #ifdef PDF_ENABLE_V8
40 if (pFormFillEnv->IsJSPlatformPresent())
41 return pdfium::MakeUnique<CJS_Runtime>(pFormFillEnv);
42 #endif
43 return pdfium::MakeUnique<CJS_RuntimeStub>(pFormFillEnv);
44 }
45
46 IJS_Runtime::~IJS_Runtime() = default;
47
JS_Error(int line,int column,const WideString & exception)48 IJS_Runtime::JS_Error::JS_Error(int line,
49 int column,
50 const WideString& exception)
51 : line(line), column(column), exception(exception) {}
52