1 // Copyright 2018 The PDFium Authors
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
9 #ifdef PDF_ENABLE_V8
10 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
11 #include "fxjs/cfxjs_engine.h"
12 #include "fxjs/cjs_runtime.h"
13 #ifdef PDF_ENABLE_XFA
14 #include "fxjs/gc/heap.h"
15 #endif // PDF_ENABLE_XFA
16 #endif // PDF_ENABLE_V8
17
ScopedEventContext(IJS_Runtime * pRuntime)18 IJS_Runtime::ScopedEventContext::ScopedEventContext(IJS_Runtime* pRuntime)
19 : m_pRuntime(pRuntime), m_pContext(pRuntime->NewEventContext()) {}
20
~ScopedEventContext()21 IJS_Runtime::ScopedEventContext::~ScopedEventContext() {
22 m_pRuntime->ReleaseEventContext(m_pContext.ExtractAsDangling());
23 }
24
25 // static
Initialize(unsigned int slot,void * isolate,void * platform)26 void IJS_Runtime::Initialize(unsigned int slot, void* isolate, void* platform) {
27 #ifdef PDF_ENABLE_V8
28 FXJS_Initialize(slot, static_cast<v8::Isolate*>(isolate));
29 #ifdef PDF_ENABLE_XFA
30 FXGC_Initialize(static_cast<v8::Platform*>(platform),
31 static_cast<v8::Isolate*>(isolate));
32 #endif // PDF_ENABLE_XFA
33 #endif // PDF_ENABLE_V8
34 }
35
36 // static
Destroy()37 void IJS_Runtime::Destroy() {
38 #ifdef PDF_ENABLE_V8
39 #ifdef PDF_ENABLE_XFA
40 FXGC_Release();
41 #endif // PDF_ENABLE_XFA
42 FXJS_Release();
43 #endif // PDF_ENABLE_V8
44 }
45
46 // static
Create(CPDFSDK_FormFillEnvironment * pFormFillEnv)47 std::unique_ptr<IJS_Runtime> IJS_Runtime::Create(
48 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
49 #ifdef PDF_ENABLE_V8
50 if (pFormFillEnv->IsJSPlatformPresent())
51 return std::make_unique<CJS_Runtime>(pFormFillEnv);
52 #endif
53 return std::make_unique<CJS_RuntimeStub>(pFormFillEnv);
54 }
55
56 IJS_Runtime::~IJS_Runtime() = default;
57
JS_Error(int line,int column,const WideString & exception)58 IJS_Runtime::JS_Error::JS_Error(int line,
59 int column,
60 const WideString& exception)
61 : line(line), column(column), exception(exception) {}
62