1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/fxfa/parser/xfa_object.h"
8
9 #include "core/fxcrt/fx_ext.h"
10 #include "fxjs/cfxjse_value.h"
11 #include "xfa/fxfa/app/xfa_ffnotify.h"
12 #include "xfa/fxfa/parser/cxfa_document.h"
13
CXFA_Object(CXFA_Document * pDocument,XFA_ObjectType objectType,XFA_Element elementType,const CFX_WideStringC & elementName)14 CXFA_Object::CXFA_Object(CXFA_Document* pDocument,
15 XFA_ObjectType objectType,
16 XFA_Element elementType,
17 const CFX_WideStringC& elementName)
18 : m_pDocument(pDocument),
19 m_objectType(objectType),
20 m_elementType(elementType),
21 m_elementNameHash(FX_HashCode_GetW(elementName, false)),
22 m_elementName(elementName) {}
23
~CXFA_Object()24 CXFA_Object::~CXFA_Object() {}
25
GetClassName() const26 CFX_WideStringC CXFA_Object::GetClassName() const {
27 return m_elementName;
28 }
29
GetClassHashCode() const30 uint32_t CXFA_Object::GetClassHashCode() const {
31 return m_elementNameHash;
32 }
33
GetElementType() const34 XFA_Element CXFA_Object::GetElementType() const {
35 return m_elementType;
36 }
37
Script_ObjectClass_ClassName(CFXJSE_Value * pValue,bool bSetting,XFA_ATTRIBUTE eAttribute)38 void CXFA_Object::Script_ObjectClass_ClassName(CFXJSE_Value* pValue,
39 bool bSetting,
40 XFA_ATTRIBUTE eAttribute) {
41 if (bSetting) {
42 ThrowInvalidPropertyException();
43 return;
44 }
45 pValue->SetString(FX_UTF8Encode(GetClassName()).AsStringC());
46 }
47
ThrowInvalidPropertyException() const48 void CXFA_Object::ThrowInvalidPropertyException() const {
49 ThrowException(L"Invalid property set operation.");
50 }
51
ThrowIndexOutOfBoundsException() const52 void CXFA_Object::ThrowIndexOutOfBoundsException() const {
53 ThrowException(L"Index value is out of bounds.");
54 }
55
ThrowParamCountMismatchException(const CFX_WideString & method) const56 void CXFA_Object::ThrowParamCountMismatchException(
57 const CFX_WideString& method) const {
58 ThrowException(L"Incorrect number of parameters calling method '%s'.",
59 method.c_str());
60 }
61
ThrowArgumentMismatchException() const62 void CXFA_Object::ThrowArgumentMismatchException() const {
63 ThrowException(L"Argument mismatch in property or function argument.");
64 }
65
ThrowException(const FX_WCHAR * str,...) const66 void CXFA_Object::ThrowException(const FX_WCHAR* str, ...) const {
67 CFX_WideString wsMessage;
68 va_list arg_ptr;
69 va_start(arg_ptr, str);
70 wsMessage.FormatV(str, arg_ptr);
71 va_end(arg_ptr);
72 FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC());
73 }
74