diff options
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cfxjse_engine.cpp | 24 | ||||
-rw-r--r-- | fxjs/cfxjse_engine.h | 5 | ||||
-rw-r--r-- | fxjs/cjs_v8.cpp | 31 | ||||
-rw-r--r-- | fxjs/cjs_v8.h | 10 | ||||
-rw-r--r-- | fxjs/xfa/cjx_container.cpp | 2 | ||||
-rw-r--r-- | fxjs/xfa/cjx_form.cpp | 3 | ||||
-rw-r--r-- | fxjs/xfa/cjx_hostpseudomodel.cpp | 6 | ||||
-rw-r--r-- | fxjs/xfa/cjx_layoutpseudomodel.cpp | 11 | ||||
-rw-r--r-- | fxjs/xfa/cjx_list.cpp | 14 |
9 files changed, 52 insertions, 54 deletions
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp index 84981666df..1c07a949b0 100644 --- a/fxjs/cfxjse_engine.cpp +++ b/fxjs/cfxjse_engine.cpp @@ -756,3 +756,27 @@ void CFXJSE_Engine::AddNodesOfRunScript(CXFA_Node* pNode) { if (m_pScriptNodeArray && !pdfium::ContainsValue(*m_pScriptNodeArray, pNode)) m_pScriptNodeArray->push_back(pNode); } + +CXFA_Object* CFXJSE_Engine::ToXFAObject(v8::Local<v8::Value> obj) { + ASSERT(!obj.IsEmpty()); + + if (!obj->IsObject()) + return nullptr; + + CFXJSE_HostObject* hostObj = + FXJSE_RetrieveObjectBinding(obj.As<v8::Object>(), nullptr); + if (!hostObj || hostObj->type() != CFXJSE_HostObject::kXFA) + return nullptr; + return static_cast<CXFA_Object*>(hostObj); +} + +v8::Local<v8::Value> CFXJSE_Engine::NewXFAObject( + CXFA_Object* obj, + v8::Global<v8::FunctionTemplate>& tmpl) { + v8::EscapableHandleScope scope(GetIsolate()); + v8::Local<v8::FunctionTemplate> klass = + v8::Local<v8::FunctionTemplate>::New(GetIsolate(), tmpl); + v8::Local<v8::Object> object = klass->InstanceTemplate()->NewInstance(); + FXJSE_UpdateObjectBinding(object, obj); + return scope.Escape(object); +} diff --git a/fxjs/cfxjse_engine.h b/fxjs/cfxjse_engine.h index 1fcbc5eacb..2e44decd8f 100644 --- a/fxjs/cfxjse_engine.h +++ b/fxjs/cfxjse_engine.h @@ -13,6 +13,7 @@ #include "fxjs/cfxjse_formcalc_context.h" #include "fxjs/cjs_v8.h" +#include "v8/include/v8.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_script.h" @@ -84,6 +85,10 @@ class CFXJSE_Engine : public CJS_V8 { std::vector<CXFA_Node*>* GetUpObjectArray() { return &m_upObjectArray; } CXFA_Document* GetDocument() const { return m_pDocument.Get(); } + CXFA_Object* ToXFAObject(v8::Local<v8::Value> obj); + v8::Local<v8::Value> NewXFAObject(CXFA_Object* obj, + v8::Global<v8::FunctionTemplate>& tmpl); + private: CFXJSE_Context* CreateVariablesContext(CXFA_Node* pScriptNode, CXFA_Node* pSubform); diff --git a/fxjs/cjs_v8.cpp b/fxjs/cjs_v8.cpp index 0a1674076d..e6948a37cf 100644 --- a/fxjs/cjs_v8.cpp +++ b/fxjs/cjs_v8.cpp @@ -6,11 +6,6 @@ #include "fxjs/cjs_v8.h" -#ifdef PDF_ENABLE_XFA -#include "fxjs/cfxjse_context.h" -#include "xfa/fxfa/parser/cxfa_object.h" -#endif // PDF_ENABLE_XFA - CJS_V8::CJS_V8(v8::Isolate* isolate) : m_isolate(isolate) {} CJS_V8::~CJS_V8() = default; @@ -199,29 +194,3 @@ v8::Local<v8::Array> CJS_V8::ToArray(v8::Local<v8::Value> pValue) { v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); } - -#ifdef PDF_ENABLE_XFA -CXFA_Object* CJS_V8::ToXFAObject(v8::Local<v8::Value> obj) { - ASSERT(!obj.IsEmpty()); - - if (!obj->IsObject()) - return nullptr; - - CFXJSE_HostObject* hostObj = - FXJSE_RetrieveObjectBinding(obj.As<v8::Object>(), nullptr); - if (!hostObj || hostObj->type() != CFXJSE_HostObject::kXFA) - return nullptr; - return static_cast<CXFA_Object*>(hostObj); -} - -v8::Local<v8::Value> CJS_V8::NewXFAObject( - CXFA_Object* obj, - v8::Global<v8::FunctionTemplate>& tmpl) { - v8::EscapableHandleScope scope(m_isolate); - v8::Local<v8::FunctionTemplate> klass = - v8::Local<v8::FunctionTemplate>::New(m_isolate, tmpl); - v8::Local<v8::Object> object = klass->InstanceTemplate()->NewInstance(); - FXJSE_UpdateObjectBinding(object, obj); - return scope.Escape(object); -} -#endif // PDF_ENABLE_XFA diff --git a/fxjs/cjs_v8.h b/fxjs/cjs_v8.h index b8a1e13881..4599da3e36 100644 --- a/fxjs/cjs_v8.h +++ b/fxjs/cjs_v8.h @@ -16,10 +16,6 @@ #include "v8/include/v8-util.h" #include "v8/include/v8.h" -#ifdef PDF_ENABLE_XFA -class CXFA_Object; -#endif // PDF_ENABLE_XFA - class CJS_V8 { public: explicit CJS_V8(v8::Isolate* pIsolate); @@ -47,12 +43,6 @@ class CJS_V8 { v8::Local<v8::Object> ToObject(v8::Local<v8::Value> pValue); v8::Local<v8::Array> ToArray(v8::Local<v8::Value> pValue); -#ifdef PDF_ENABLE_XFA - CXFA_Object* ToXFAObject(v8::Local<v8::Value> obj); - v8::Local<v8::Value> NewXFAObject(CXFA_Object* obj, - v8::Global<v8::FunctionTemplate>& tmpl); -#endif // PDF_ENABLE_XFA - // Arrays. unsigned GetArrayLength(v8::Local<v8::Array> pArray); v8::Local<v8::Value> GetArrayElement(v8::Local<v8::Array> pArray, diff --git a/fxjs/xfa/cjx_container.cpp b/fxjs/xfa/cjx_container.cpp index cf0aca0cbb..b7577da204 100644 --- a/fxjs/xfa/cjx_container.cpp +++ b/fxjs/xfa/cjx_container.cpp @@ -34,7 +34,7 @@ CJS_Return CJX_Container::getDeltas( CJS_V8* runtime, const std::vector<v8::Local<v8::Value>>& params) { CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(GetDocument()); - return CJS_Return(runtime->NewXFAObject( + return CJS_Return(static_cast<CFXJSE_Engine*>(runtime)->NewXFAObject( pFormNodes, GetDocument()->GetScriptContext()->GetJseNormalClass()->GetTemplate())); } diff --git a/fxjs/xfa/cjx_form.cpp b/fxjs/xfa/cjx_form.cpp index 6576df88d2..32de9f5902 100644 --- a/fxjs/xfa/cjx_form.cpp +++ b/fxjs/xfa/cjx_form.cpp @@ -37,7 +37,8 @@ CJS_Return CJX_Form::formNodes( if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_Node* pDataNode = ToNode(runtime->ToXFAObject(params[0])); + CXFA_Node* pDataNode = + ToNode(static_cast<CFXJSE_Engine*>(runtime)->ToXFAObject(params[0])); if (!pDataNode) return CJS_Return(JSGetStringFromID(JSMessage::kValueError)); diff --git a/fxjs/xfa/cjx_hostpseudomodel.cpp b/fxjs/xfa/cjx_hostpseudomodel.cpp index 319761d19a..fd570990bc 100644 --- a/fxjs/xfa/cjx_hostpseudomodel.cpp +++ b/fxjs/xfa/cjx_hostpseudomodel.cpp @@ -279,7 +279,8 @@ CJS_Return CJX_HostPseudoModel::openList( CXFA_Node* pNode = nullptr; if (params[0]->IsObject()) { - pNode = ToNode(runtime->ToXFAObject(params[0])); + pNode = + ToNode(static_cast<CFXJSE_Engine*>(runtime)->ToXFAObject(params[0])); } else if (params[0]->IsString()) { CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext(); if (!pScriptContext) @@ -439,7 +440,8 @@ CJS_Return CJX_HostPseudoModel::setFocus( CXFA_Node* pNode = nullptr; if (params.size() >= 1) { if (params[0]->IsObject()) { - pNode = ToNode(runtime->ToXFAObject(params[0])); + pNode = + ToNode(static_cast<CFXJSE_Engine*>(runtime)->ToXFAObject(params[0])); } else if (params[0]->IsString()) { CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext(); if (!pScriptContext) diff --git a/fxjs/xfa/cjx_layoutpseudomodel.cpp b/fxjs/xfa/cjx_layoutpseudomodel.cpp index 384bd09d63..ba17ed8b8b 100644 --- a/fxjs/xfa/cjx_layoutpseudomodel.cpp +++ b/fxjs/xfa/cjx_layoutpseudomodel.cpp @@ -75,7 +75,8 @@ CJS_Return CJX_LayoutPseudoModel::HWXY( if (params.empty() || params.size() > 3) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_Node* pNode = ToNode(runtime->ToXFAObject(params[0])); + CXFA_Node* pNode = + ToNode(static_cast<CFXJSE_Engine*>(runtime)->ToXFAObject(params[0])); if (!pNode) return CJS_Return(true); @@ -185,7 +186,8 @@ CJS_Return CJX_LayoutPseudoModel::pageSpan( if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_Node* pNode = ToNode(runtime->ToXFAObject(params[0])); + CXFA_Node* pNode = + ToNode(static_cast<CFXJSE_Engine*>(runtime)->ToXFAObject(params[0])); if (!pNode) return CJS_Return(true); @@ -374,7 +376,7 @@ CJS_Return CJX_LayoutPseudoModel::pageContent( GetObjArray(pDocLayout, iIndex, wsType, bOnPageArea)); // TODO(dsinclair): Who owns the array once we release it? Won't this leak? - return CJS_Return(runtime->NewXFAObject( + return CJS_Return(static_cast<CFXJSE_Engine*>(runtime)->NewXFAObject( pArrayNodeList.release(), GetDocument()->GetScriptContext()->GetJseNormalClass()->GetTemplate())); } @@ -465,7 +467,8 @@ CJS_Return CJX_LayoutPseudoModel::PageInternals( if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_Node* pNode = ToNode(runtime->ToXFAObject(params[0])); + CXFA_Node* pNode = + ToNode(static_cast<CFXJSE_Engine*>(runtime)->ToXFAObject(params[0])); if (!pNode) return CJS_Return(runtime->NewNumber(0)); diff --git a/fxjs/xfa/cjx_list.cpp b/fxjs/xfa/cjx_list.cpp index 9cbd32d352..27a4315d5f 100644 --- a/fxjs/xfa/cjx_list.cpp +++ b/fxjs/xfa/cjx_list.cpp @@ -36,7 +36,8 @@ CJS_Return CJX_List::append(CJS_V8* runtime, if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - auto* pNode = ToNode(runtime->ToXFAObject(params[0])); + auto* pNode = + ToNode(static_cast<CFXJSE_Engine*>(runtime)->ToXFAObject(params[0])); if (!pNode) return CJS_Return(JSGetStringFromID(JSMessage::kValueError)); @@ -49,11 +50,13 @@ CJS_Return CJX_List::insert(CJS_V8* runtime, if (params.size() != 2) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - auto* pNewNode = ToNode(runtime->ToXFAObject(params[0])); + auto* pNewNode = + ToNode(static_cast<CFXJSE_Engine*>(runtime)->ToXFAObject(params[0])); if (!pNewNode) return CJS_Return(JSGetStringFromID(JSMessage::kValueError)); - auto* pBeforeNode = ToNode(runtime->ToXFAObject(params[1])); + auto* pBeforeNode = + ToNode(static_cast<CFXJSE_Engine*>(runtime)->ToXFAObject(params[1])); GetXFAList()->Insert(pNewNode, pBeforeNode); return CJS_Return(true); } @@ -63,7 +66,8 @@ CJS_Return CJX_List::remove(CJS_V8* runtime, if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - auto* pNode = ToNode(runtime->ToXFAObject(params[0])); + auto* pNode = + ToNode(static_cast<CFXJSE_Engine*>(runtime)->ToXFAObject(params[0])); if (!pNode) return CJS_Return(JSGetStringFromID(JSMessage::kValueError)); @@ -81,7 +85,7 @@ CJS_Return CJX_List::item(CJS_V8* runtime, if (index < 0 || cast_index >= GetXFAList()->GetLength()) return CJS_Return(JSGetStringFromID(JSMessage::kInvalidInputError)); - return CJS_Return(runtime->NewXFAObject( + return CJS_Return(static_cast<CFXJSE_Engine*>(runtime)->NewXFAObject( GetXFAList()->Item(cast_index), GetDocument()->GetScriptContext()->GetJseNormalClass()->GetTemplate())); } |