summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cjs_document.cpp3
-rw-r--r--fxjs/cjs_global.cpp3
-rw-r--r--fxjs/cjs_runtime.cpp4
-rw-r--r--fxjs/cjs_runtime.h1
-rw-r--r--fxjs/cjs_runtimestub.cpp4
-rw-r--r--fxjs/cjs_runtimestub.h1
-rw-r--r--fxjs/ijs_runtime.cpp8
-rw-r--r--fxjs/ijs_runtime.h8
8 files changed, 23 insertions, 9 deletions
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 248116b69a..9cfcad313e 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -132,8 +132,7 @@ CJS_Document::CJS_Document(v8::Local<v8::Object> pObject)
CJS_Document::~CJS_Document() = default;
void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) {
- CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
- SetFormFillEnv(pRuntime->GetFormFillEnv());
+ SetFormFillEnv(pIRuntime->GetFormFillEnv());
}
// The total number of fields in document.
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index c8deadf5d5..282b26210f 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -214,8 +214,7 @@ CJS_Global::~CJS_Global() {
}
void CJS_Global::InitInstance(IJS_Runtime* pIRuntime) {
- CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
- Initial(pRuntime->GetFormFillEnv());
+ Initial(pIRuntime->GetFormFillEnv());
}
void CJS_Global::Initial(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp
index b9b9c03e1b..3a607f1aae 100644
--- a/fxjs/cjs_runtime.cpp
+++ b/fxjs/cjs_runtime.cpp
@@ -143,6 +143,10 @@ void CJS_Runtime::DefineJSObjects() {
CJS_Annot::DefineJSObjects(this);
}
+CJS_Runtime* CJS_Runtime::AsCJSRuntime() {
+ return this;
+}
+
IJS_EventContext* CJS_Runtime::NewEventContext() {
m_EventContextArray.push_back(pdfium::MakeUnique<CJS_EventContext>(this));
return m_EventContextArray.back().get();
diff --git a/fxjs/cjs_runtime.h b/fxjs/cjs_runtime.h
index 0aab84828f..c5e69fbdc8 100644
--- a/fxjs/cjs_runtime.h
+++ b/fxjs/cjs_runtime.h
@@ -33,6 +33,7 @@ class CJS_Runtime : public IJS_Runtime,
~CJS_Runtime() override;
// IJS_Runtime
+ CJS_Runtime* AsCJSRuntime() override;
IJS_EventContext* NewEventContext() override;
void ReleaseEventContext(IJS_EventContext* pContext) override;
CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override;
diff --git a/fxjs/cjs_runtimestub.cpp b/fxjs/cjs_runtimestub.cpp
index 98c7679a04..c1e680e5d5 100644
--- a/fxjs/cjs_runtimestub.cpp
+++ b/fxjs/cjs_runtimestub.cpp
@@ -14,6 +14,10 @@ CJS_RuntimeStub::CJS_RuntimeStub(CPDFSDK_FormFillEnvironment* pFormFillEnv)
CJS_RuntimeStub::~CJS_RuntimeStub() = default;
+CJS_Runtime* CJS_RuntimeStub::AsCJSRuntime() {
+ return nullptr;
+}
+
IJS_EventContext* CJS_RuntimeStub::NewEventContext() {
if (!m_pContext)
m_pContext = pdfium::MakeUnique<CJS_EventContextStub>();
diff --git a/fxjs/cjs_runtimestub.h b/fxjs/cjs_runtimestub.h
index ecf3b4eb8a..a9e85fdf03 100644
--- a/fxjs/cjs_runtimestub.h
+++ b/fxjs/cjs_runtimestub.h
@@ -21,6 +21,7 @@ class CJS_RuntimeStub final : public IJS_Runtime {
explicit CJS_RuntimeStub(CPDFSDK_FormFillEnvironment* pFormFillEnv);
~CJS_RuntimeStub() override;
+ CJS_Runtime* AsCJSRuntime() override;
IJS_EventContext* NewEventContext() override;
void ReleaseEventContext(IJS_EventContext* pContext) override;
CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override;
diff --git a/fxjs/ijs_runtime.cpp b/fxjs/ijs_runtime.cpp
index 03538cd7b5..79238bfe11 100644
--- a/fxjs/ijs_runtime.cpp
+++ b/fxjs/ijs_runtime.cpp
@@ -31,8 +31,10 @@ void IJS_Runtime::Destroy() {
std::unique_ptr<IJS_Runtime> IJS_Runtime::Create(
CPDFSDK_FormFillEnvironment* pFormFillEnv) {
#ifdef PDF_ENABLE_V8
- return pdfium::MakeUnique<CJS_Runtime>(pFormFillEnv);
-#else
- return pdfium::MakeUnique<CJS_RuntimeStub>(pFormFillEnv);
+ if (pFormFillEnv->IsJSPlatformPresent())
+ return pdfium::MakeUnique<CJS_Runtime>(pFormFillEnv);
#endif
+ return pdfium::MakeUnique<CJS_RuntimeStub>(pFormFillEnv);
}
+
+IJS_Runtime::~IJS_Runtime() = default;
diff --git a/fxjs/ijs_runtime.h b/fxjs/ijs_runtime.h
index b97c65ef90..cde31c6e52 100644
--- a/fxjs/ijs_runtime.h
+++ b/fxjs/ijs_runtime.h
@@ -16,18 +16,22 @@
#include "fxjs/fxjse.h"
#endif // PDF_ENABLE_XFA
+class CJS_Runtime;
class CPDFSDK_FormFillEnvironment;
class IJS_EventContext;
-// Owns the FJXS objects needed to actually execute JS.
+// Owns the FJXS objects needed to actually execute JS, if possible. This
+// virtual interface is backed by either an actual JS runtime, or a stub,
+// when JS is not present.
class IJS_Runtime {
public:
static void Initialize(unsigned int slot, void* isolate);
static void Destroy();
static std::unique_ptr<IJS_Runtime> Create(
CPDFSDK_FormFillEnvironment* pFormFillEnv);
- virtual ~IJS_Runtime() {}
+ virtual ~IJS_Runtime();
+ virtual CJS_Runtime* AsCJSRuntime() = 0;
virtual IJS_EventContext* NewEventContext() = 0;
virtual void ReleaseEventContext(IJS_EventContext* pContext) = 0;
virtual CPDFSDK_FormFillEnvironment* GetFormFillEnv() const = 0;