summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cjs_runtime.cpp16
-rw-r--r--fxjs/cjs_runtimestub.cpp70
-rw-r--r--fxjs/cjs_runtimestub.h42
-rw-r--r--fxjs/ijs_event_context.h5
-rw-r--r--fxjs/ijs_runtime.cpp38
5 files changed, 107 insertions, 64 deletions
diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp
index 6da52ad7ef..b9b9c03e1b 100644
--- a/fxjs/cjs_runtime.cpp
+++ b/fxjs/cjs_runtime.cpp
@@ -47,22 +47,6 @@
#endif // PDF_ENABLE_XFA
// static
-void IJS_Runtime::Initialize(unsigned int slot, void* isolate) {
- FXJS_Initialize(slot, reinterpret_cast<v8::Isolate*>(isolate));
-}
-
-// static
-void IJS_Runtime::Destroy() {
- FXJS_Release();
-}
-
-// static
-std::unique_ptr<IJS_Runtime> IJS_Runtime::Create(
- CPDFSDK_FormFillEnvironment* pFormFillEnv) {
- return pdfium::MakeUnique<CJS_Runtime>(pFormFillEnv);
-}
-
-// static
CJS_Runtime* CJS_Runtime::RuntimeFromIsolateCurrentContext(
v8::Isolate* pIsolate) {
return static_cast<CJS_Runtime*>(
diff --git a/fxjs/cjs_runtimestub.cpp b/fxjs/cjs_runtimestub.cpp
index 105bb6f114..98c7679a04 100644
--- a/fxjs/cjs_runtimestub.cpp
+++ b/fxjs/cjs_runtimestub.cpp
@@ -4,60 +4,40 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include <memory>
+#include "fxjs/cjs_runtimestub.h"
-#include "core/fxcrt/unowned_ptr.h"
#include "fxjs/cjs_event_context_stub.h"
-#include "fxjs/ijs_runtime.h"
#include "third_party/base/ptr_util.h"
-class CJS_RuntimeStub final : public IJS_Runtime {
- public:
- explicit CJS_RuntimeStub(CPDFSDK_FormFillEnvironment* pFormFillEnv)
- : m_pFormFillEnv(pFormFillEnv) {}
- ~CJS_RuntimeStub() override {}
+CJS_RuntimeStub::CJS_RuntimeStub(CPDFSDK_FormFillEnvironment* pFormFillEnv)
+ : m_pFormFillEnv(pFormFillEnv) {}
- IJS_EventContext* NewEventContext() override {
- if (!m_pContext)
- m_pContext = pdfium::MakeUnique<CJS_EventContextStub>();
- return m_pContext.get();
- }
+CJS_RuntimeStub::~CJS_RuntimeStub() = default;
- void ReleaseEventContext(IJS_EventContext* pContext) override {}
-
- CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override {
- return m_pFormFillEnv.Get();
- }
-
-#ifdef PDF_ENABLE_XFA
- bool GetValueByNameFromGlobalObject(const ByteStringView&,
- CFXJSE_Value*) override {
- return false;
- }
-
- bool SetValueByNameInGlobalObject(const ByteStringView&,
- CFXJSE_Value*) override {
- return false;
- }
-#endif // PDF_ENABLE_XFA
+IJS_EventContext* CJS_RuntimeStub::NewEventContext() {
+ if (!m_pContext)
+ m_pContext = pdfium::MakeUnique<CJS_EventContextStub>();
+ return m_pContext.get();
+}
- int ExecuteScript(const WideString& script, WideString* info) override {
- return 0;
- }
+void CJS_RuntimeStub::ReleaseEventContext(IJS_EventContext* pContext) {}
- protected:
- UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
- std::unique_ptr<CJS_EventContextStub> m_pContext;
-};
+CPDFSDK_FormFillEnvironment* CJS_RuntimeStub::GetFormFillEnv() const {
+ return m_pFormFillEnv.Get();
+}
-// static
-void IJS_Runtime::Initialize(unsigned int slot, void* isolate) {}
+#ifdef PDF_ENABLE_XFA
+bool CJS_RuntimeStub::GetValueByNameFromGlobalObject(const ByteStringView&,
+ CFXJSE_Value*) {
+ return false;
+}
-// static
-void IJS_Runtime::Destroy() {}
+bool CJS_RuntimeStub::SetValueByNameInGlobalObject(const ByteStringView&,
+ CFXJSE_Value*) {
+ return false;
+}
+#endif // PDF_ENABLE_XFA
-// static
-std::unique_ptr<IJS_Runtime> IJS_Runtime::Create(
- CPDFSDK_FormFillEnvironment* pFormFillEnv) {
- return pdfium::MakeUnique<CJS_RuntimeStub>(pFormFillEnv);
+int CJS_RuntimeStub::ExecuteScript(const WideString& script, WideString* info) {
+ return 0;
}
diff --git a/fxjs/cjs_runtimestub.h b/fxjs/cjs_runtimestub.h
new file mode 100644
index 0000000000..ecf3b4eb8a
--- /dev/null
+++ b/fxjs/cjs_runtimestub.h
@@ -0,0 +1,42 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef FXJS_CJS_RUNTIMESTUB_H_
+#define FXJS_CJS_RUNTIMESTUB_H_
+
+#include <memory>
+
+#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/unowned_ptr.h"
+#include "fxjs/ijs_runtime.h"
+
+class CPDFSDK_FormFillEnvironment;
+class IJS_EventContext;
+
+class CJS_RuntimeStub final : public IJS_Runtime {
+ public:
+ explicit CJS_RuntimeStub(CPDFSDK_FormFillEnvironment* pFormFillEnv);
+ ~CJS_RuntimeStub() override;
+
+ IJS_EventContext* NewEventContext() override;
+ void ReleaseEventContext(IJS_EventContext* pContext) override;
+ CPDFSDK_FormFillEnvironment* GetFormFillEnv() const override;
+
+#ifdef PDF_ENABLE_XFA
+ bool GetValueByNameFromGlobalObject(const ByteStringView&,
+ CFXJSE_Value*) override;
+ bool SetValueByNameInGlobalObject(const ByteStringView&,
+ CFXJSE_Value*) override;
+#endif // PDF_ENABLE_XFA
+
+ int ExecuteScript(const WideString& script, WideString* info) override;
+
+ protected:
+ UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
+ std::unique_ptr<IJS_EventContext> m_pContext;
+};
+
+#endif // FXJS_CJS_RUNTIMESTUB_H_
diff --git a/fxjs/ijs_event_context.h b/fxjs/ijs_event_context.h
index 9b8dd8eabe..6050d65eca 100644
--- a/fxjs/ijs_event_context.h
+++ b/fxjs/ijs_event_context.h
@@ -20,6 +20,8 @@ class CPDFSDK_FormFillEnvironment;
// may trigger new events on top of one another.
class IJS_EventContext {
public:
+ virtual ~IJS_EventContext() {}
+
virtual bool RunScript(const WideString& script, WideString* info) = 0;
virtual void OnApp_Init() = 0;
@@ -125,9 +127,6 @@ class IJS_EventContext {
virtual void OnBatchExec(CPDFSDK_FormFillEnvironment* pFormFillEnv) = 0;
virtual void OnConsole_Exec() = 0;
virtual void OnExternal_Exec() = 0;
-
- protected:
- virtual ~IJS_EventContext() {}
};
#endif // FXJS_IJS_EVENT_CONTEXT_H_
diff --git a/fxjs/ijs_runtime.cpp b/fxjs/ijs_runtime.cpp
new file mode 100644
index 0000000000..03538cd7b5
--- /dev/null
+++ b/fxjs/ijs_runtime.cpp
@@ -0,0 +1,38 @@
+// Copyright 2018 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "fxjs/ijs_runtime.h"
+
+#include "fpdfsdk/cpdfsdk_helpers.h"
+#include "fxjs/cjs_runtimestub.h"
+#include "third_party/base/ptr_util.h"
+
+#ifdef PDF_ENABLE_V8
+#include "fxjs/cfxjs_engine.h"
+#include "fxjs/cjs_runtime.h"
+#endif
+
+// static
+void IJS_Runtime::Initialize(unsigned int slot, void* isolate) {
+#ifdef PDF_ENABLE_V8
+ FXJS_Initialize(slot, reinterpret_cast<v8::Isolate*>(isolate));
+#endif
+}
+
+// static
+void IJS_Runtime::Destroy() {
+#ifdef PDF_ENABLE_V8
+ FXJS_Release();
+#endif
+}
+
+// static
+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);
+#endif
+}