1 // Copyright 2017 The PDFium Authors
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 "fxjs/xfa/cjx_boolean.h"
8
9 #include "fxjs/fxv8.h"
10 #include "fxjs/xfa/cfxjse_value.h"
11 #include "v8/include/v8-primitive.h"
12 #include "xfa/fxfa/parser/cxfa_boolean.h"
13
CJX_Boolean(CXFA_Boolean * node)14 CJX_Boolean::CJX_Boolean(CXFA_Boolean* node) : CJX_Object(node) {}
15
16 CJX_Boolean::~CJX_Boolean() = default;
17
DynamicTypeIs(TypeTag eType) const18 bool CJX_Boolean::DynamicTypeIs(TypeTag eType) const {
19 return eType == static_type__ || ParentType__::DynamicTypeIs(eType);
20 }
21
defaultValue(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)22 void CJX_Boolean::defaultValue(v8::Isolate* pIsolate,
23 v8::Local<v8::Value>* pValue,
24 bool bSetting,
25 XFA_Attribute eAttribute) {
26 if (!bSetting) {
27 *pValue =
28 fxv8::NewBooleanHelper(pIsolate, GetContent(true).EqualsASCII("1"));
29 return;
30 }
31
32 ByteString newValue;
33 if (pValue && !(fxv8::IsNull(*pValue) || fxv8::IsUndefined(*pValue)))
34 newValue = fxv8::ReentrantToByteStringHelper(pIsolate, *pValue);
35
36 int32_t iValue = FXSYS_atoi(newValue.c_str());
37 WideString wsNewValue(iValue == 0 ? L"0" : L"1");
38 WideString wsFormatValue(wsNewValue);
39 CXFA_Node* pContainerNode = GetXFANode()->GetContainerNode();
40 if (pContainerNode)
41 wsFormatValue = pContainerNode->GetFormatDataValue(wsNewValue);
42
43 SetContent(wsNewValue, wsFormatValue, true, true, true);
44 }
45
value(v8::Isolate * pIsolate,v8::Local<v8::Value> * pValue,bool bSetting,XFA_Attribute eAttribute)46 void CJX_Boolean::value(v8::Isolate* pIsolate,
47 v8::Local<v8::Value>* pValue,
48 bool bSetting,
49 XFA_Attribute eAttribute) {
50 defaultValue(pIsolate, pValue, bSetting, eAttribute);
51 }
52