diff options
-rw-r--r-- | BUILD.gn | 1 | ||||
-rw-r--r-- | fxjs/cfxjse_engine.cpp | 20 | ||||
-rw-r--r-- | fxjs/cfxjse_formcalc_context.cpp | 14 | ||||
-rw-r--r-- | fxjs/cfxjse_formcalc_context.h | 3 | ||||
-rw-r--r-- | fxjs/fxjse.cpp | 19 | ||||
-rw-r--r-- | fxjs/fxjse.h | 15 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_object.cpp | 9 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_object.h | 3 |
8 files changed, 52 insertions, 32 deletions
@@ -1323,6 +1323,7 @@ jumbo_static_library("fxjs") { "fxjs/cfxjse_runtimedata.h", "fxjs/cfxjse_value.cpp", "fxjs/cfxjse_value.h", + "fxjs/fxjse.cpp", "fxjs/fxjse.h", "fxjs/xfa/cjx_arc.cpp", "fxjs/xfa/cjx_arc.h", diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp index 9b54555a21..62376dd822 100644 --- a/fxjs/cfxjse_engine.cpp +++ b/fxjs/cfxjse_engine.cpp @@ -77,20 +77,16 @@ CXFA_Object* CFXJSE_Engine::ToObject( if (!info.Holder()->IsObject()) return nullptr; - CFXJSE_HostObject* hostObj = + CFXJSE_HostObject* pHostObj = FXJSE_RetrieveObjectBinding(info.Holder().As<v8::Object>(), nullptr); - if (!hostObj || hostObj->type() != CFXJSE_HostObject::kXFA) - return nullptr; - return static_cast<CXFA_Object*>(hostObj); + return pHostObj ? pHostObj->AsCXFAObject() : nullptr; } // static. CXFA_Object* CFXJSE_Engine::ToObject(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { CFXJSE_HostObject* pHostObj = pValue->ToHostObject(pClass); - if (!pHostObj || pHostObj->type() != CFXJSE_HostObject::kXFA) - return nullptr; - return static_cast<CXFA_Object*>(pHostObj); + return pHostObj ? pHostObj->AsCXFAObject() : nullptr; } CFXJSE_Engine::CFXJSE_Engine(CXFA_Document* pDocument, @@ -791,16 +787,12 @@ void CFXJSE_Engine::AddNodesOfRunScript(CXFA_Node* pNode) { } CXFA_Object* CFXJSE_Engine::ToXFAObject(v8::Local<v8::Value> obj) { - ASSERT(!obj.IsEmpty()); - - if (!obj->IsObject()) + if (obj.IsEmpty() || !obj->IsObject()) return nullptr; - CFXJSE_HostObject* hostObj = + CFXJSE_HostObject* pHostObj = FXJSE_RetrieveObjectBinding(obj.As<v8::Object>(), nullptr); - if (!hostObj || hostObj->type() != CFXJSE_HostObject::kXFA) - return nullptr; - return static_cast<CXFA_Object*>(hostObj); + return pHostObj ? pHostObj->AsCXFAObject() : nullptr; } v8::Local<v8::Value> CFXJSE_Engine::NewXFAObject( diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp index c7433b4b2b..b0a26d86a4 100644 --- a/fxjs/cfxjse_formcalc_context.cpp +++ b/fxjs/cfxjse_formcalc_context.cpp @@ -450,9 +450,7 @@ bool PatternStringType(const ByteStringView& szPattern, uint32_t& patternType) { CFXJSE_FormCalcContext* ToFormCalcContext(CFXJSE_Value* pValue) { CFXJSE_HostObject* pHostObj = pValue->ToHostObject(nullptr); - if (!pHostObj || pHostObj->type() != CFXJSE_HostObject::kFM2JS) - return nullptr; - return static_cast<CFXJSE_FormCalcContext*>(pHostObj); + return pHostObj ? pHostObj->AsFormCalcContext() : nullptr; } bool IsWhitespace(char c) { @@ -6177,15 +6175,13 @@ bool CFXJSE_FormCalcContext::Translate(const WideStringView& wsFormcalc, return false; wsJavascript->AppendChar(0); - return !CXFA_IsTooBig(wsJavascript); } CFXJSE_FormCalcContext::CFXJSE_FormCalcContext(v8::Isolate* pScriptIsolate, CFXJSE_Context* pScriptContext, CXFA_Document* pDoc) - : CFXJSE_HostObject(kFM2JS), - m_pIsolate(pScriptIsolate), + : m_pIsolate(pScriptIsolate), m_pFMClass(CFXJSE_Class::Create(pScriptContext, &kFormCalcFM2JSDescriptor, false)), @@ -6194,7 +6190,11 @@ CFXJSE_FormCalcContext::CFXJSE_FormCalcContext(v8::Isolate* pScriptIsolate, m_pValue.get()->SetObject(this, m_pFMClass); } -CFXJSE_FormCalcContext::~CFXJSE_FormCalcContext() {} +CFXJSE_FormCalcContext::~CFXJSE_FormCalcContext() = default; + +CFXJSE_FormCalcContext* CFXJSE_FormCalcContext::AsFormCalcContext() { + return this; +} void CFXJSE_FormCalcContext::GlobalPropertyGetter(CFXJSE_Value* pValue) { pValue->Assign(m_pValue.get()); diff --git a/fxjs/cfxjse_formcalc_context.h b/fxjs/cfxjse_formcalc_context.h index 052bba394a..8a92d9b0f1 100644 --- a/fxjs/cfxjse_formcalc_context.h +++ b/fxjs/cfxjse_formcalc_context.h @@ -25,6 +25,9 @@ class CFXJSE_FormCalcContext : public CFXJSE_HostObject { CXFA_Document* pDoc); ~CFXJSE_FormCalcContext() override; + // CFXJSE_HostObject: + CFXJSE_FormCalcContext* AsFormCalcContext() override; + static void Abs(CFXJSE_Value* pThis, const ByteStringView& szFuncName, CFXJSE_Arguments& args); diff --git a/fxjs/fxjse.cpp b/fxjs/fxjse.cpp new file mode 100644 index 0000000000..68adaa5dd3 --- /dev/null +++ b/fxjs/fxjse.cpp @@ -0,0 +1,19 @@ +// 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 + +#include "fxjs/fxjse.h" + +CFXJSE_HostObject::CFXJSE_HostObject() = default; + +CFXJSE_HostObject::~CFXJSE_HostObject() = default; + +CFXJSE_FormCalcContext* CFXJSE_HostObject::AsFormCalcContext() { + return nullptr; +} + +CXFA_Object* CFXJSE_HostObject::AsCXFAObject() { + return nullptr; +} diff --git a/fxjs/fxjse.h b/fxjs/fxjse.h index addd148117..3f2eb1d836 100644 --- a/fxjs/fxjse.h +++ b/fxjs/fxjse.h @@ -12,23 +12,22 @@ #include "v8/include/v8.h" class CFXJSE_Arguments; +class CFXJSE_FormCalcContext; class CFXJSE_Value; class CJS_Return; +class CXFA_Object; // C++ object which is retrieved from v8 object's slot. class CFXJSE_HostObject { public: - virtual ~CFXJSE_HostObject() {} + virtual ~CFXJSE_HostObject(); - // Small layering violation here, but we need to distinguish between the - // two kinds of subclasses. - enum Type { kXFA, kFM2JS }; - Type type() const { return type_; } + // Two subclasses. + virtual CFXJSE_FormCalcContext* AsFormCalcContext(); + virtual CXFA_Object* AsCXFAObject(); protected: - explicit CFXJSE_HostObject(Type type) { type_ = type; } - - Type type_; + CFXJSE_HostObject(); }; typedef CJS_Return (*FXJSE_MethodCallback)( diff --git a/xfa/fxfa/parser/cxfa_object.cpp b/xfa/fxfa/parser/cxfa_object.cpp index a716c651f5..920e33860e 100644 --- a/xfa/fxfa/parser/cxfa_object.cpp +++ b/xfa/fxfa/parser/cxfa_object.cpp @@ -22,15 +22,18 @@ CXFA_Object::CXFA_Object(CXFA_Document* pDocument, XFA_Element elementType, const WideStringView& elementName, std::unique_ptr<CJX_Object> jsObject) - : CFXJSE_HostObject(kXFA), - m_pDocument(pDocument), + : m_pDocument(pDocument), m_objectType(objectType), m_elementType(elementType), m_elementNameHash(FX_HashCode_GetW(elementName, false)), m_elementName(elementName), m_pJSObject(std::move(jsObject)) {} -CXFA_Object::~CXFA_Object() {} +CXFA_Object::~CXFA_Object() = default; + +CXFA_Object* CXFA_Object::AsCXFAObject() { + return this; +} WideString CXFA_Object::GetSOMExpression() { CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext(); diff --git a/xfa/fxfa/parser/cxfa_object.h b/xfa/fxfa/parser/cxfa_object.h index 20412dcbf7..023516a05e 100644 --- a/xfa/fxfa/parser/cxfa_object.h +++ b/xfa/fxfa/parser/cxfa_object.h @@ -36,6 +36,9 @@ class CXFA_Object : public CFXJSE_HostObject { public: ~CXFA_Object() override; + // CFXJSE_HostObject: + CXFA_Object* AsCXFAObject() override; + CXFA_Document* GetDocument() const { return m_pDocument.Get(); } XFA_ObjectType GetObjectType() const { return m_objectType; } |