From a1fe73272892b668bd5928a836ecc6303c81e2fd Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 18 Apr 2018 22:48:22 +0000 Subject: Always build JS Runtime stubs even if V8 present. Prerequisite for switching V8 off at run-time. Change-Id: I4b9f867185758350f5de3f57e771f63020df6e65 Reviewed-on: https://pdfium-review.googlesource.com/30994 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- BUILD.gn | 11 ++++---- fxjs/cjs_runtime.cpp | 16 ----------- fxjs/cjs_runtimestub.cpp | 70 +++++++++++++++++------------------------------- fxjs/cjs_runtimestub.h | 42 +++++++++++++++++++++++++++++ fxjs/ijs_event_context.h | 5 ++-- fxjs/ijs_runtime.cpp | 38 ++++++++++++++++++++++++++ 6 files changed, 112 insertions(+), 70 deletions(-) create mode 100644 fxjs/cjs_runtimestub.h create mode 100644 fxjs/ijs_runtime.cpp diff --git a/BUILD.gn b/BUILD.gn index c00557594b..01e40f5102 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1172,7 +1172,12 @@ jumbo_static_library("pwl") { jumbo_static_library("fxjs") { sources = [ + "fxjs/cjs_event_context_stub.cpp", + "fxjs/cjs_event_context_stub.h", + "fxjs/cjs_runtimestub.cpp", + "fxjs/cjs_runtimestub.h", "fxjs/ijs_event_context.h", + "fxjs/ijs_runtime.cpp", "fxjs/ijs_runtime.h", ] configs += [ ":pdfium_core_config" ] @@ -1595,12 +1600,6 @@ jumbo_static_library("fxjs") { "fxjs/xfa/cjx_xsdconnection.h", ] } - } else { - sources += [ - "fxjs/cjs_event_context_stub.cpp", - "fxjs/cjs_event_context_stub.h", - "fxjs/cjs_runtimestub.cpp", - ] } } 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 @@ -46,22 +46,6 @@ #include "fxjs/cfxjse_value.h" #endif // PDF_ENABLE_XFA -// static -void IJS_Runtime::Initialize(unsigned int slot, void* isolate) { - FXJS_Initialize(slot, reinterpret_cast(isolate)); -} - -// static -void IJS_Runtime::Destroy() { - FXJS_Release(); -} - -// static -std::unique_ptr IJS_Runtime::Create( - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - return pdfium::MakeUnique(pFormFillEnv); -} - // static CJS_Runtime* CJS_Runtime::RuntimeFromIsolateCurrentContext( v8::Isolate* pIsolate) { 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 +#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(); - 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(); + return m_pContext.get(); +} - int ExecuteScript(const WideString& script, WideString* info) override { - return 0; - } +void CJS_RuntimeStub::ReleaseEventContext(IJS_EventContext* pContext) {} - protected: - UnownedPtr const m_pFormFillEnv; - std::unique_ptr 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::Create( - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - return pdfium::MakeUnique(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 + +#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 const m_pFormFillEnv; + std::unique_ptr 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(isolate)); +#endif +} + +// static +void IJS_Runtime::Destroy() { +#ifdef PDF_ENABLE_V8 + FXJS_Release(); +#endif +} + +// static +std::unique_ptr IJS_Runtime::Create( + CPDFSDK_FormFillEnvironment* pFormFillEnv) { +#ifdef PDF_ENABLE_V8 + return pdfium::MakeUnique(pFormFillEnv); +#else + return pdfium::MakeUnique(pFormFillEnv); +#endif +} -- cgit v1.2.3