| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef XFA_FXFA_PARSER_XFA_SCRIPT_H_ | 7 #ifndef XFA_FXFA_PARSER_XFA_SCRIPT_H_ |
| 8 #define XFA_FXFA_PARSER_XFA_SCRIPT_H_ | 8 #define XFA_FXFA_PARSER_XFA_SCRIPT_H_ |
| 9 | 9 |
| 10 #include "xfa/fxfa/include/fxfa.h" | 10 #include "xfa/fxfa/include/fxfa.h" |
| 11 #include "xfa/fxfa/parser/cxfa_valuearray.h" |
| 11 #include "xfa/fxjse/value.h" | 12 #include "xfa/fxjse/value.h" |
| 12 | 13 |
| 13 #define XFA_RESOLVENODE_Children 0x0001 | 14 #define XFA_RESOLVENODE_Children 0x0001 |
| 14 #define XFA_RESOLVENODE_Attributes 0x0004 | 15 #define XFA_RESOLVENODE_Attributes 0x0004 |
| 15 #define XFA_RESOLVENODE_Properties 0x0008 | 16 #define XFA_RESOLVENODE_Properties 0x0008 |
| 16 #define XFA_RESOLVENODE_Siblings 0x0020 | 17 #define XFA_RESOLVENODE_Siblings 0x0020 |
| 17 #define XFA_RESOLVENODE_Parent 0x0040 | 18 #define XFA_RESOLVENODE_Parent 0x0040 |
| 18 #define XFA_RESOLVENODE_AnyChild 0x0080 | 19 #define XFA_RESOLVENODE_AnyChild 0x0080 |
| 19 #define XFA_RESOLVENODE_ALL 0x0100 | 20 #define XFA_RESOLVENODE_ALL 0x0100 |
| 20 #define XFA_RESOLVENODE_CreateNode 0x0400 | 21 #define XFA_RESOLVENODE_CreateNode 0x0400 |
| 21 #define XFA_RESOLVENODE_Bind 0x0800 | 22 #define XFA_RESOLVENODE_Bind 0x0800 |
| 22 #define XFA_RESOLVENODE_BindNew 0x1000 | 23 #define XFA_RESOLVENODE_BindNew 0x1000 |
| 23 | 24 |
| 24 enum XFA_SCRIPTLANGTYPE { | 25 enum XFA_SCRIPTLANGTYPE { |
| 25 XFA_SCRIPTLANGTYPE_Formcalc = XFA_SCRIPTTYPE_Formcalc, | 26 XFA_SCRIPTLANGTYPE_Formcalc = XFA_SCRIPTTYPE_Formcalc, |
| 26 XFA_SCRIPTLANGTYPE_Javascript = XFA_SCRIPTTYPE_Javascript, | 27 XFA_SCRIPTLANGTYPE_Javascript = XFA_SCRIPTTYPE_Javascript, |
| 27 XFA_SCRIPTLANGTYPE_Unkown = XFA_SCRIPTTYPE_Unkown, | 28 XFA_SCRIPTLANGTYPE_Unkown = XFA_SCRIPTTYPE_Unkown, |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 enum XFA_RESOVENODE_RSTYPE { | 31 enum XFA_RESOVENODE_RSTYPE { |
| 31 XFA_RESOVENODE_RSTYPE_Nodes, | 32 XFA_RESOVENODE_RSTYPE_Nodes, |
| 32 XFA_RESOVENODE_RSTYPE_Attribute, | 33 XFA_RESOVENODE_RSTYPE_Attribute, |
| 33 XFA_RESOLVENODE_RSTYPE_CreateNodeOne, | 34 XFA_RESOLVENODE_RSTYPE_CreateNodeOne, |
| 34 XFA_RESOLVENODE_RSTYPE_CreateNodeAll, | 35 XFA_RESOLVENODE_RSTYPE_CreateNodeAll, |
| 35 XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll, | 36 XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll, |
| 36 XFA_RESOVENODE_RSTYPE_ExistNodes, | 37 XFA_RESOVENODE_RSTYPE_ExistNodes, |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 class CXFA_ValueArray : public CFX_ArrayTemplate<CFXJSE_Value*> { | |
| 40 public: | |
| 41 CXFA_ValueArray(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {} | |
| 42 | |
| 43 ~CXFA_ValueArray() { | |
| 44 for (int32_t i = 0; i < GetSize(); i++) { | |
| 45 delete GetAt(i); | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 void GetAttributeObject(CXFA_ObjArray& objArray) { | |
| 50 for (int32_t i = 0; i < GetSize(); i++) { | |
| 51 objArray.Add( | |
| 52 static_cast<CXFA_Object*>(FXJSE_Value_ToObject(GetAt(i), nullptr))); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 v8::Isolate* m_pIsolate; | |
| 57 }; | |
| 58 | |
| 59 struct XFA_RESOLVENODE_RS { | 40 struct XFA_RESOLVENODE_RS { |
| 60 XFA_RESOLVENODE_RS() | 41 XFA_RESOLVENODE_RS() |
| 61 : dwFlags(XFA_RESOVENODE_RSTYPE_Nodes), pScriptAttribute(NULL) {} | 42 : dwFlags(XFA_RESOVENODE_RSTYPE_Nodes), pScriptAttribute(NULL) {} |
| 62 | 43 |
| 63 ~XFA_RESOLVENODE_RS() { nodes.RemoveAll(); } | 44 ~XFA_RESOLVENODE_RS() { nodes.RemoveAll(); } |
| 64 | 45 |
| 65 int32_t GetAttributeResult(CXFA_ValueArray& valueArray) const { | 46 int32_t GetAttributeResult(CXFA_ValueArray& valueArray) const { |
| 66 if (pScriptAttribute && pScriptAttribute->eValueType == XFA_SCRIPT_Object) { | 47 if (pScriptAttribute && pScriptAttribute->eValueType == XFA_SCRIPT_Object) { |
| 67 v8::Isolate* pIsolate = valueArray.m_pIsolate; | 48 v8::Isolate* pIsolate = valueArray.m_pIsolate; |
| 68 for (int32_t i = 0; i < nodes.GetSize(); i++) { | 49 for (int32_t i = 0; i < nodes.GetSize(); i++) { |
| 69 std::unique_ptr<CFXJSE_Value> pValue(new CFXJSE_Value(pIsolate)); | 50 std::unique_ptr<CFXJSE_Value> pValue(new CFXJSE_Value(pIsolate)); |
| 70 (nodes[i]->*(pScriptAttribute->lpfnCallback))( | 51 (nodes[i]->*(pScriptAttribute->lpfnCallback))( |
| 71 pValue.get(), FALSE, (XFA_ATTRIBUTE)pScriptAttribute->eAttribute); | 52 pValue.get(), FALSE, (XFA_ATTRIBUTE)pScriptAttribute->eAttribute); |
| 72 valueArray.Add(pValue.release()); | 53 valueArray.Add(pValue.release()); |
| 73 } | 54 } |
| 74 } | 55 } |
| 75 return valueArray.GetSize(); | 56 return valueArray.GetSize(); |
| 76 } | 57 } |
| 77 | 58 |
| 78 CXFA_ObjArray nodes; | 59 CXFA_ObjArray nodes; |
| 79 XFA_RESOVENODE_RSTYPE dwFlags; | 60 XFA_RESOVENODE_RSTYPE dwFlags; |
| 80 const XFA_SCRIPTATTRIBUTEINFO* pScriptAttribute; | 61 const XFA_SCRIPTATTRIBUTEINFO* pScriptAttribute; |
| 81 }; | 62 }; |
| 82 | 63 |
| 83 #endif // XFA_FXFA_PARSER_XFA_SCRIPT_H_ | 64 #endif // XFA_FXFA_PARSER_XFA_SCRIPT_H_ |
| OLD | NEW |