Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: xfa/src/fxfa/fm2js/xfa_fm2jscontext.cpp

Issue 1803723002: Move xfa/src up to xfa/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/src/fxfa/fm2js/xfa_fm2jscontext.h ('k') | xfa/src/fxfa/fm2js/xfa_fmparse.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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/src/fxfa/fm2js/xfa_fm2jscontext.h"
8
9 #include <time.h>
10
11 #include "core/include/fxcrt/fx_ext.h"
12 #include "xfa/src/fgas/localization/fgas_locale.h"
13 #include "xfa/src/fxfa/fm2js/xfa_fm2jsapi.h"
14 #include "xfa/src/fxfa/parser/xfa_document.h"
15 #include "xfa/src/fxfa/parser/xfa_localevalue.h"
16 #include "xfa/src/fxfa/parser/xfa_parser.h"
17
18 #define FINANCIAL_PRECISION 0.00000001
19
20 namespace {
21
22 struct XFA_FMHtmlReserveCode {
23 uint32_t m_uCode;
24 const FX_WCHAR* m_htmlReserve;
25 };
26 struct XFA_FMHtmlHashedReserveCode {
27 uint32_t m_uHash;
28 const FX_WCHAR* m_htmlReserve;
29 uint32_t m_uCode;
30 };
31
32 const XFA_FMHtmlHashedReserveCode reservesForDecode[] = {
33 {0x00018b62, L"Mu", 924}, {0x00019083, L"Nu", 925},
34 {0x00019ab9, L"Pi", 928}, {0x0001c3c1, L"Xi", 926},
35 {0x000210ac, L"ge", 8805}, {0x000210bb, L"gt", 62},
36 {0x00022a51, L"le", 8804}, {0x00022a60, L"lt", 60},
37 {0x00022f82, L"mu", 956}, {0x00023493, L"ne", 8800},
38 {0x00023497, L"ni", 8715}, {0x000234a3, L"nu", 957},
39 {0x000239c1, L"or", 8744}, {0x00023ed9, L"pi", 960},
40 {0x000267e1, L"xi", 958}, {0x00c41789, L"lceil", 8968},
41 {0x00eef34f, L"thetasym", 977}, {0x012d7ead, L"lcirc", 206},
42 {0x01637b56, L"agrave", 224}, {0x020856da, L"crarr", 8629},
43 {0x022188c3, L"gamma", 947}, {0x033586d3, L"nbsp", 160},
44 {0x04f4c358, L"nsub", 8836}, {0x0581466a, L"dagger", 8224},
45 {0x06b1f790, L"oelig", 339}, {0x06e490d4, L"Chi", 935},
46 {0x0718c6a1, L"ETH", 208}, {0x07196ada, L"Eta", 919},
47 {0x07f667ca, L"Ugrave", 217}, {0x083a8a21, L"Phi", 934},
48 {0x083ac28c, L"Psi", 936}, {0x086f26a9, L"Rho", 929},
49 {0x089b5b51, L"aring", 229}, {0x08a39f4a, L"Tau", 932},
50 {0x08b6188b, L"THORN", 222}, {0x09ce792a, L"icirc", 238},
51 {0x09f9d61e, L"amp", 38}, {0x09f9db33, L"and", 8743},
52 {0x09f9db36, L"ang", 8736}, {0x0a2e3514, L"cap", 8745},
53 {0x0a2e58f4, L"chi", 967}, {0x0a2e9ba8, L"cup", 8746},
54 {0x0a4897d0, L"deg", 176}, {0x0a6332fa, L"eta", 951},
55 {0x0a633301, L"eth", 240}, {0x0acc4d4b, L"int", 8747},
56 {0x0b1b3d35, L"loz", 9674}, {0x0b1b4c8b, L"lrm", 8206},
57 {0x0b4fd9b1, L"not", 172}, {0x0b845241, L"phi", 966},
58 {0x0b84576f, L"piv", 982}, {0x0b848aac, L"psi", 968},
59 {0x0bb8df5e, L"reg", 174}, {0x0bb8eec9, L"rho", 961},
60 {0x0bb9034b, L"rlm", 8207}, {0x0bd33d14, L"shy", 173},
61 {0x0bd34229, L"sim", 8764}, {0x0bd37faa, L"sub", 8834},
62 {0x0bd37fb5, L"sum", 8721}, {0x0bd37fb8, L"sup", 8835},
63 {0x0bed676a, L"tau", 964}, {0x0c07f32e, L"uml", 168},
64 {0x0c71032c, L"yen", 165}, {0x0c7f2889, L"szlig", 223},
65 {0x0c8badbb, L"zwj", 8205}, {0x10ba4dba, L"Egrave", 200},
66 {0x10f1ea24, L"para", 182}, {0x10f1ea37, L"part", 8706},
67 {0x115b2337, L"perp", 8869}, {0x12b10d15, L"prod", 8719},
68 {0x12b10d21, L"prop", 8733}, {0x12dfa9f4, L"rfloor", 8971},
69 {0x12eb4736, L"Agrave", 192}, {0x12fff2b7, L"pund", 163},
70 {0x13fda9f2, L"tilde", 732}, {0x1417fd62, L"times", 215},
71 {0x154fc726, L"ecirc", 234}, {0x165aa451, L"sigma", 963},
72 {0x1709124a, L"Dagger", 8225}, {0x192f78d5, L"iexcl", 161},
73 {0x1b7ed8d7, L"rArr", 8658}, {0x1ec88c68, L"rang", 9002},
74 {0x1ec8a0f7, L"rarr", 8594}, {0x1eda07f3, L"atilde", 227},
75 {0x1f3182c4, L"real", 8476}, {0x1fc34f8b, L"yacute", 253},
76 {0x20d11522, L"acirc", 226}, {0x21933a9b, L"rsaquo", 8250},
77 {0x21f44907, L"uacute", 250}, {0x220cca72, L"acute", 180},
78 {0x242cded1, L"alefsym", 8501}, {0x2655c66a, L"delta", 948},
79 {0x269e4b4d, L"exist", 8707}, {0x273379fa, L"micro", 181},
80 {0x27a37440, L"forall", 8704}, {0x2854e62c, L"minus", 8722},
81 {0x28636f81, L"cedil", 184}, {0x2887357b, L"iacute", 237},
82 {0x2994d5ff, L"frac12", 189}, {0x2994d601, L"frac14", 188},
83 {0x2994e043, L"frac34", 190}, {0x2a1feb41, L"lambda", 955},
84 {0x2ab215f3, L"apos", 39}, {0x2ab82ef7, L"eacute", 233},
85 {0x2b3592ef, L"auml", 228}, {0x2ce92873, L"aacute", 225},
86 {0x2daff48a, L"oslash", 248}, {0x2ef68882, L"aelig", 230},
87 {0x3061d3d3, L"Atilde", 195}, {0x314b1b6b, L"Yacute", 221},
88 {0x337c14e7, L"Uacute", 218}, {0x37676aca, L"cent", 162},
89 {0x37d0b841, L"circ", 710}, {0x386e7947, L"cong", 8773},
90 {0x386e839b, L"copy", 169}, {0x3a0e225a, L"Epsilon", 917},
91 {0x3ba7b721, L"Lambda", 923}, {0x3bd9abe6, L"Alpha", 913},
92 {0x3c3ffad7, L"Eacute", 201}, {0x3cfaf69f, L"brvbar", 166},
93 {0x3d54a489, L"omega", 969}, {0x3e70f453, L"Aacute", 193},
94 {0x3f37c06a, L"Oslash", 216}, {0x40e1b34e, L"diams", 9830},
95 {0x416596df, L"plusmn", 177}, {0x4354ff16, L"Ucirc", 219},
96 {0x454fce6a, L"Upsilon", 933}, {0x4610ad35, L"emsp", 8195},
97 {0x462afb76, L"ensp", 8194}, {0x46e30073, L"euml", 235},
98 {0x46e31a1b, L"euro", 8364}, {0x46f2eada, L"lowast", 8727},
99 {0x4dca26cf, L"Auml", 196}, {0x4e2d6083, L"image", 8465},
100 {0x4f964ee8, L"notin", 8713}, {0x50917a7a, L"epsilon", 949},
101 {0x52f9a4cd, L"Kappa", 922}, {0x5496f410, L"Ocirc", 212},
102 {0x568cbf34, L"zeta", 950}, {0x57badd20, L"ntilde", 241},
103 {0x58662109, L"zwnj", 8204}, {0x5b39870f, L"empty", 8709},
104 {0x5bd3268a, L"upsilon", 965}, {0x5e2bf8a3, L"Gamma", 915},
105 {0x5f73c13a, L"rsquo", 8217}, {0x61f2bc4d, L"iota", 953},
106 {0x625bbcf3, L"isin", 8712}, {0x62906df7, L"iuml", 239},
107 {0x64a5cb31, L"Aring", 197}, {0x66f25c4a, L"sbquo", 8218},
108 {0x6851ab60, L"spades", 9824}, {0x6942a900, L"Ntilde", 209},
109 {0x69779453, L"Euml", 203}, {0x6cda6e23, L"current", 164},
110 {0x70b5b634, L"lsquo", 8216}, {0x715a3706, L"Ecirc", 202},
111 {0x71e8bf8d, L"tdquo", 8221}, {0x72651431, L"Sigma", 931},
112 {0x7569813b, L"iquest", 191}, {0x776a436a, L"equiv", 8801},
113 {0x79215314, L"Zeta", 918}, {0x79b81224, L"ograve", 242},
114 {0x7c2f8b23, L"macr", 175}, {0x7cdb8502, L"Acirc", 194},
115 {0x8185c62e, L"ndash", 8211}, {0x8260364a, L"Delta", 916},
116 {0x846619ad, L"mdash", 8212}, {0x8550fb50, L"OElig", 338},
117 {0x88eb5b85, L"ldquo", 8220}, {0x8b3fde04, L"Ograve", 210},
118 {0x8bc5794b, L"ordf", 170}, {0x8bc57952, L"ordm", 186},
119 {0x8c14923d, L"ouml", 246}, {0x8c5a7cd6, L"theta", 952},
120 {0x8d61812b, L"thorn", 254}, {0x912b95aa, L"asymp", 8776},
121 {0x947faf81, L"middot", 183}, {0x9629202e, L"lfloor", 8970},
122 {0x972e9ec1, L"otilde", 245}, {0x9748f231, L"otimes", 8855},
123 {0x995f1469, L"Omega", 937}, {0x99eb5349, L"quot", 34},
124 {0x9aeb639e, L"hellip", 8230}, {0xa0ae2f86, L"Scaron", 352},
125 {0xa4dcb0d5, L"lsaquo", 8249}, {0xa53dbf41, L"oacute", 243},
126 {0xa5ae9e7b, L"bdquo", 8222}, {0xa602d7ba, L"sdot", 8901},
127 {0xa61ce86f, L"sect", 167}, {0xa6e4c3d7, L"sigmaf", 962},
128 {0xa7c1c74f, L"sube", 8838}, {0xa7c20ee9, L"sup1", 185},
129 {0xa7c20eea, L"sup2", 178}, {0xa7c20eeb, L"sup3", 179},
130 {0xa7c20f1d, L"supe", 8839}, {0xa8b66aa1, L"Otilde", 213},
131 {0xad958c42, L"AElig", 198}, {0xaea9261d, L"Ouml", 214},
132 {0xb040eafa, L"uArr", 8657}, {0xb07c2e1c, L"beta", 946},
133 {0xb220e92f, L"bull", 8226}, {0xb22750c4, L"ccedil", 231},
134 {0xb38ab31a, L"uarr", 8593}, {0xb598b683, L"uuml", 252},
135 {0xb6c58b21, L"Oacute", 211}, {0xb6d2a617, L"oline", 8254},
136 {0xba9fd989, L"dArr", 8659}, {0xbb5ccd41, L"lgrave", 204},
137 {0xbd39b44c, L"weierp", 8472}, {0xbde9a1a9, L"darr", 8595},
138 {0xc027e329, L"permil", 8240}, {0xc2451389, L"upsih", 978},
139 {0xc3af1ca4, L"Ccedil", 199}, {0xcd164249, L"fnof", 402},
140 {0xcf6c8467, L"hearts", 9829}, {0xd1228390, L"trade", 8482},
141 {0xd1462407, L"yuml", 255}, {0xd2cf2253, L"oplus", 8853},
142 {0xd310c1fc, L"Beta", 914}, {0xd59c4d74, L"infin", 8734},
143 {0xd64d470d, L"hArr", 8660}, {0xd67d9c75, L"divide", 247},
144 {0xd698dd37, L"Omicron", 927}, {0xd82d4a63, L"Uuml", 220},
145 {0xd9970f2d, L"harr", 8596}, {0xda91fd99, L"clubs", 9827},
146 {0xdbe5bdcc, L"there4", 8756}, {0xdd7671bd, L"prime", 8242},
147 {0xdfcf3c06, L"alpha", 945}, {0xe0213063, L"saron", 353},
148 {0xe1911d83, L"radic", 8730}, {0xe2e75468, L"raquo", 187},
149 {0xe6e27a5e, L"lacute", 205}, {0xe74a8f36, L"ucirc", 251},
150 {0xe864ecb6, L"Theta", 920}, {0xecddde5e, L"nabla", 8711},
151 {0xed1c3557, L"omicron", 959}, {0xef82228f, L"rceil", 8969},
152 {0xf1fab491, L"lArr", 8656}, {0xf3dab7e7, L"Yuml", 376},
153 {0xf4294962, L"laquo", 171}, {0xf5446822, L"lang", 9001},
154 {0xf5447cb1, L"larr", 8592}, {0xf66e9bea, L"ugrave", 249},
155 {0xf6b4ce70, L"lota", 921}, {0xf6ef34ed, L"kappa", 954},
156 {0xf72a3a56, L"thinsp", 8201}, {0xf752801a, L"luml", 207},
157 {0xf88c8430, L"ocirc", 244}, {0xf9676178, L"frasl", 8260},
158 {0xfd01885e, L"igrave", 236}, {0xff3281da, L"egrave", 232},
159 };
160
161 const XFA_FMHtmlReserveCode reservesForEncode[] = {
162 {34, L"quot"}, {38, L"amp"}, {39, L"apos"},
163 {60, L"lt"}, {62, L"gt"}, {160, L"nbsp"},
164 {161, L"iexcl"}, {162, L"cent"}, {163, L"pund"},
165 {164, L"current"}, {165, L"yen"}, {166, L"brvbar"},
166 {167, L"sect"}, {168, L"uml"}, {169, L"copy"},
167 {170, L"ordf"}, {171, L"laquo"}, {172, L"not"},
168 {173, L"shy"}, {174, L"reg"}, {175, L"macr"},
169 {176, L"deg"}, {177, L"plusmn"}, {178, L"sup2"},
170 {179, L"sup3"}, {180, L"acute"}, {181, L"micro"},
171 {182, L"para"}, {183, L"middot"}, {184, L"cedil"},
172 {185, L"sup1"}, {186, L"ordm"}, {187, L"raquo"},
173 {188, L"frac14"}, {189, L"frac12"}, {190, L"frac34"},
174 {191, L"iquest"}, {192, L"Agrave"}, {193, L"Aacute"},
175 {194, L"Acirc"}, {195, L"Atilde"}, {196, L"Auml"},
176 {197, L"Aring"}, {198, L"AElig"}, {199, L"Ccedil"},
177 {200, L"Egrave"}, {201, L"Eacute"}, {202, L"Ecirc"},
178 {203, L"Euml"}, {204, L"lgrave"}, {205, L"lacute"},
179 {206, L"lcirc"}, {207, L"luml"}, {208, L"ETH"},
180 {209, L"Ntilde"}, {210, L"Ograve"}, {211, L"Oacute"},
181 {212, L"Ocirc"}, {213, L"Otilde"}, {214, L"Ouml"},
182 {215, L"times"}, {216, L"Oslash"}, {217, L"Ugrave"},
183 {218, L"Uacute"}, {219, L"Ucirc"}, {220, L"Uuml"},
184 {221, L"Yacute"}, {222, L"THORN"}, {223, L"szlig"},
185 {224, L"agrave"}, {225, L"aacute"}, {226, L"acirc"},
186 {227, L"atilde"}, {228, L"auml"}, {229, L"aring"},
187 {230, L"aelig"}, {231, L"ccedil"}, {232, L"egrave"},
188 {233, L"eacute"}, {234, L"ecirc"}, {235, L"euml"},
189 {236, L"igrave"}, {237, L"iacute"}, {238, L"icirc"},
190 {239, L"iuml"}, {240, L"eth"}, {241, L"ntilde"},
191 {242, L"ograve"}, {243, L"oacute"}, {244, L"ocirc"},
192 {245, L"otilde"}, {246, L"ouml"}, {247, L"divide"},
193 {248, L"oslash"}, {249, L"ugrave"}, {250, L"uacute"},
194 {251, L"ucirc"}, {252, L"uuml"}, {253, L"yacute"},
195 {254, L"thorn"}, {255, L"yuml"}, {338, L"OElig"},
196 {339, L"oelig"}, {352, L"Scaron"}, {353, L"saron"},
197 {376, L"Yuml"}, {402, L"fnof"}, {710, L"circ"},
198 {732, L"tilde"}, {913, L"Alpha"}, {914, L"Beta"},
199 {915, L"Gamma"}, {916, L"Delta"}, {917, L"Epsilon"},
200 {918, L"Zeta"}, {919, L"Eta"}, {920, L"Theta"},
201 {921, L"lota"}, {922, L"Kappa"}, {923, L"Lambda"},
202 {924, L"Mu"}, {925, L"Nu"}, {926, L"Xi"},
203 {927, L"Omicron"}, {928, L"Pi"}, {929, L"Rho"},
204 {931, L"Sigma"}, {932, L"Tau"}, {933, L"Upsilon"},
205 {934, L"Phi"}, {935, L"Chi"}, {936, L"Psi"},
206 {937, L"Omega"}, {945, L"alpha"}, {946, L"beta"},
207 {947, L"gamma"}, {948, L"delta"}, {949, L"epsilon"},
208 {950, L"zeta"}, {951, L"eta"}, {952, L"theta"},
209 {953, L"iota"}, {954, L"kappa"}, {955, L"lambda"},
210 {956, L"mu"}, {957, L"nu"}, {958, L"xi"},
211 {959, L"omicron"}, {960, L"pi"}, {961, L"rho"},
212 {962, L"sigmaf"}, {963, L"sigma"}, {964, L"tau"},
213 {965, L"upsilon"}, {966, L"phi"}, {967, L"chi"},
214 {968, L"psi"}, {969, L"omega"}, {977, L"thetasym"},
215 {978, L"upsih"}, {982, L"piv"}, {8194, L"ensp"},
216 {8195, L"emsp"}, {8201, L"thinsp"}, {8204, L"zwnj"},
217 {8205, L"zwj"}, {8206, L"lrm"}, {8207, L"rlm"},
218 {8211, L"ndash"}, {8212, L"mdash"}, {8216, L"lsquo"},
219 {8217, L"rsquo"}, {8218, L"sbquo"}, {8220, L"ldquo"},
220 {8221, L"tdquo"}, {8222, L"bdquo"}, {8224, L"dagger"},
221 {8225, L"Dagger"}, {8226, L"bull"}, {8230, L"hellip"},
222 {8240, L"permil"}, {8242, L"prime"}, {8249, L"lsaquo"},
223 {8250, L"rsaquo"}, {8254, L"oline"}, {8260, L"frasl"},
224 {8364, L"euro"}, {8465, L"image"}, {8472, L"weierp"},
225 {8476, L"real"}, {8482, L"trade"}, {8501, L"alefsym"},
226 {8592, L"larr"}, {8593, L"uarr"}, {8594, L"rarr"},
227 {8595, L"darr"}, {8596, L"harr"}, {8629, L"crarr"},
228 {8656, L"lArr"}, {8657, L"uArr"}, {8658, L"rArr"},
229 {8659, L"dArr"}, {8660, L"hArr"}, {8704, L"forall"},
230 {8706, L"part"}, {8707, L"exist"}, {8709, L"empty"},
231 {8711, L"nabla"}, {8712, L"isin"}, {8713, L"notin"},
232 {8715, L"ni"}, {8719, L"prod"}, {8721, L"sum"},
233 {8722, L"minus"}, {8727, L"lowast"}, {8730, L"radic"},
234 {8733, L"prop"}, {8734, L"infin"}, {8736, L"ang"},
235 {8743, L"and"}, {8744, L"or"}, {8745, L"cap"},
236 {8746, L"cup"}, {8747, L"int"}, {8756, L"there4"},
237 {8764, L"sim"}, {8773, L"cong"}, {8776, L"asymp"},
238 {8800, L"ne"}, {8801, L"equiv"}, {8804, L"le"},
239 {8805, L"ge"}, {8834, L"sub"}, {8835, L"sup"},
240 {8836, L"nsub"}, {8838, L"sube"}, {8839, L"supe"},
241 {8853, L"oplus"}, {8855, L"otimes"}, {8869, L"perp"},
242 {8901, L"sdot"}, {8968, L"lceil"}, {8969, L"rceil"},
243 {8970, L"lfloor"}, {8971, L"rfloor"}, {9001, L"lang"},
244 {9002, L"rang"}, {9674, L"loz"}, {9824, L"spades"},
245 {9827, L"clubs"}, {9829, L"hearts"}, {9830, L"diams"},
246 };
247
248 } // namespace
249
250 void CXFA_FM2JSContext::Abs(FXJSE_HOBJECT hThis,
251 const CFX_ByteStringC& szFuncName,
252 CFXJSE_Arguments& args) {
253 if (args.GetLength() == 1) {
254 FXJSE_HVALUE argOne = args.GetValue(0);
255 if (HValueIsNull(hThis, argOne)) {
256 FXJSE_Value_SetNull(args.GetReturnValue());
257 } else {
258 FX_DOUBLE dValue = HValueToDouble(hThis, argOne);
259 if (dValue < 0) {
260 dValue = -dValue;
261 }
262 FXJSE_Value_SetDouble(args.GetReturnValue(), dValue);
263 }
264 FXJSE_Value_Release(argOne);
265 } else {
266 CXFA_FM2JSContext* pContext =
267 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
268 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
269 L"Abs");
270 }
271 }
272 void CXFA_FM2JSContext::Avg(FXJSE_HOBJECT hThis,
273 const CFX_ByteStringC& szFuncName,
274 CFXJSE_Arguments& args) {
275 CXFA_FM2JSContext* pContext =
276 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
277 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
278 int32_t argc = args.GetLength();
279 uint32_t uCount = 0;
280 FX_DOUBLE dSum = 0.0;
281 if (argc >= 1) {
282 FXJSE_HVALUE argValue = 0;
283 for (int32_t i = 0; i < argc; i++) {
284 argValue = args.GetValue(i);
285 if (FXJSE_Value_IsNull(argValue)) {
286 FXJSE_Value_Release(argValue);
287 continue;
288 } else if (FXJSE_Value_IsArray(argValue)) {
289 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
290 FXJSE_Value_GetObjectProp(argValue, "length", lengthValue);
291 int32_t iLength = FXJSE_Value_ToInteger(lengthValue);
292 FXJSE_Value_Release(lengthValue);
293 if (iLength > 2) {
294 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
295 FXJSE_Value_GetObjectPropByIdx(argValue, 1, propertyValue);
296 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
297 if (FXJSE_Value_IsNull(propertyValue)) {
298 for (int32_t j = 2; j < iLength; j++) {
299 FXJSE_Value_GetObjectPropByIdx(argValue, j, jsObjectValue);
300 FXJSE_HVALUE defaultPropValue = FXJSE_Value_Create(hruntime);
301 GetObjectDefaultValue(jsObjectValue, defaultPropValue);
302 if (!FXJSE_Value_IsNull(defaultPropValue)) {
303 dSum += HValueToDouble(hThis, defaultPropValue);
304 uCount++;
305 }
306 FXJSE_Value_Release(defaultPropValue);
307 }
308 } else {
309 CFX_ByteString propertyStr;
310 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
311 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
312 for (int32_t j = 2; j < iLength; j++) {
313 FXJSE_Value_GetObjectPropByIdx(argValue, j, jsObjectValue);
314 FXJSE_Value_GetObjectProp(jsObjectValue, propertyStr,
315 newPropertyValue);
316 if (!FXJSE_Value_IsNull(newPropertyValue)) {
317 dSum += HValueToDouble(hThis, newPropertyValue);
318 uCount++;
319 }
320 }
321 FXJSE_Value_Release(newPropertyValue);
322 }
323 FXJSE_Value_Release(jsObjectValue);
324 FXJSE_Value_Release(propertyValue);
325 }
326 } else {
327 dSum += HValueToDouble(hThis, argValue);
328 uCount++;
329 }
330 FXJSE_Value_Release(argValue);
331 }
332 argValue = 0;
333 }
334 if (0 == uCount) {
335 FXJSE_Value_SetNull(args.GetReturnValue());
336 } else {
337 FXJSE_Value_SetDouble(args.GetReturnValue(), dSum / uCount);
338 }
339 }
340 void CXFA_FM2JSContext::Ceil(FXJSE_HOBJECT hThis,
341 const CFX_ByteStringC& szFuncName,
342 CFXJSE_Arguments& args) {
343 CXFA_FM2JSContext* pContext =
344 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
345 if (args.GetLength() == 1) {
346 FXJSE_HVALUE argValue = GetSimpleHValue(hThis, args, 0);
347 if (HValueIsNull(hThis, argValue)) {
348 FXJSE_Value_SetNull(args.GetReturnValue());
349 } else {
350 FXJSE_Value_SetFloat(args.GetReturnValue(),
351 FXSYS_ceil(HValueToFloat(hThis, argValue)));
352 }
353 FXJSE_Value_Release(argValue);
354 } else {
355 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
356 L"Ceil");
357 }
358 }
359 void CXFA_FM2JSContext::Count(FXJSE_HOBJECT hThis,
360 const CFX_ByteStringC& szFuncName,
361 CFXJSE_Arguments& args) {
362 CXFA_FM2JSContext* pContext =
363 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
364 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
365 int32_t argc = args.GetLength();
366 uint32_t uCount = 0;
367 FXJSE_HVALUE argValue = 0;
368 for (int32_t i = 0; i < argc; i++) {
369 argValue = args.GetValue(i);
370 if (FXJSE_Value_IsNull(argValue)) {
371 FXJSE_Value_Release(argValue);
372 continue;
373 } else if (FXJSE_Value_IsArray(argValue)) {
374 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
375 FXJSE_Value_GetObjectProp(argValue, "length", lengthValue);
376 int32_t iLength = FXJSE_Value_ToInteger(lengthValue);
377 FXJSE_Value_Release(lengthValue);
378 if (iLength > 2) {
379 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
380 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
381 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
382 FXJSE_Value_GetObjectPropByIdx(argValue, 1, propertyValue);
383 FXJSE_Value_GetObjectPropByIdx(argValue, 2, jsObjectValue);
384 if (FXJSE_Value_IsNull(propertyValue)) {
385 for (int32_t i = 2; i < iLength; i++) {
386 FXJSE_Value_GetObjectPropByIdx(argValue, i, jsObjectValue);
387 GetObjectDefaultValue(jsObjectValue, newPropertyValue);
388 if (!FXJSE_Value_IsNull(newPropertyValue)) {
389 uCount++;
390 }
391 }
392 } else {
393 CFX_ByteString propertyStr;
394 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
395 for (int32_t i = 2; i < iLength; i++) {
396 FXJSE_Value_GetObjectPropByIdx(argValue, i, jsObjectValue);
397 FXJSE_Value_GetObjectProp(jsObjectValue, propertyStr,
398 newPropertyValue);
399 uCount += (FXJSE_Value_IsNull(newPropertyValue) ? 0 : 1);
400 }
401 }
402 FXJSE_Value_Release(propertyValue);
403 FXJSE_Value_Release(jsObjectValue);
404 FXJSE_Value_Release(newPropertyValue);
405 } else {
406 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
407 }
408 } else if (FXJSE_Value_IsObject(argValue)) {
409 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
410 GetObjectDefaultValue(argValue, newPropertyValue);
411 if (!FXJSE_Value_IsNull(newPropertyValue)) {
412 uCount++;
413 }
414 FXJSE_Value_Release(newPropertyValue);
415 } else {
416 uCount++;
417 }
418 FXJSE_Value_Release(argValue);
419 }
420 argValue = 0;
421 FXJSE_Value_SetInteger(args.GetReturnValue(), (int32_t)uCount);
422 }
423 void CXFA_FM2JSContext::Floor(FXJSE_HOBJECT hThis,
424 const CFX_ByteStringC& szFuncName,
425 CFXJSE_Arguments& args) {
426 CXFA_FM2JSContext* pContext =
427 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
428 if (args.GetLength() == 1) {
429 FXJSE_HVALUE argValue = GetSimpleHValue(hThis, args, 0);
430 if (HValueIsNull(hThis, argValue)) {
431 FXJSE_Value_SetNull(args.GetReturnValue());
432 } else {
433 FXJSE_Value_SetFloat(args.GetReturnValue(),
434 FXSYS_floor(HValueToFloat(hThis, argValue)));
435 }
436 FXJSE_Value_Release(argValue);
437 } else {
438 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
439 L"Floor");
440 }
441 }
442 void CXFA_FM2JSContext::Max(FXJSE_HOBJECT hThis,
443 const CFX_ByteStringC& szFuncName,
444 CFXJSE_Arguments& args) {
445 CXFA_FM2JSContext* pContext =
446 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
447 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
448 int32_t argc = args.GetLength();
449 uint32_t uCount = 0;
450 FX_DOUBLE dMaxValue = 0.0;
451 FXJSE_HVALUE argValue = 0;
452 for (int32_t i = 0; i < argc; i++) {
453 argValue = args.GetValue(i);
454 if (FXJSE_Value_IsNull(argValue)) {
455 FXJSE_Value_Release(argValue);
456 continue;
457 } else if (FXJSE_Value_IsArray(argValue)) {
458 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
459 FXJSE_Value_GetObjectProp(argValue, "length", lengthValue);
460 int32_t iLength = FXJSE_Value_ToInteger(lengthValue);
461 FXJSE_Value_Release(lengthValue);
462 if (iLength > 2) {
463 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
464 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
465 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
466 FXJSE_Value_GetObjectPropByIdx(argValue, 1, propertyValue);
467 FXJSE_Value_GetObjectPropByIdx(argValue, 2, jsObjectValue);
468 if (FXJSE_Value_IsNull(propertyValue)) {
469 for (int32_t i = 2; i < iLength; i++) {
470 FXJSE_Value_GetObjectPropByIdx(argValue, i, jsObjectValue);
471 GetObjectDefaultValue(jsObjectValue, newPropertyValue);
472 if (!FXJSE_Value_IsNull(newPropertyValue)) {
473 uCount++;
474 if (uCount == 1) {
475 dMaxValue = HValueToDouble(hThis, newPropertyValue);
476 } else {
477 FX_DOUBLE dValue = HValueToDouble(hThis, newPropertyValue);
478 if (dMaxValue < dValue) {
479 dMaxValue = dValue;
480 }
481 }
482 }
483 }
484 } else {
485 CFX_ByteString propertyStr;
486 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
487 for (int32_t i = 2; i < iLength; i++) {
488 FXJSE_Value_GetObjectPropByIdx(argValue, i, jsObjectValue);
489 FXJSE_Value_GetObjectProp(jsObjectValue, propertyStr,
490 newPropertyValue);
491 if (!FXJSE_Value_IsNull(newPropertyValue)) {
492 uCount++;
493 if (uCount == 1) {
494 dMaxValue = HValueToDouble(hThis, newPropertyValue);
495 } else {
496 FX_DOUBLE dValue = HValueToDouble(hThis, newPropertyValue);
497 if (dMaxValue < dValue) {
498 dMaxValue = dValue;
499 }
500 }
501 }
502 }
503 }
504 FXJSE_Value_Release(propertyValue);
505 FXJSE_Value_Release(jsObjectValue);
506 FXJSE_Value_Release(newPropertyValue);
507 } else {
508 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
509 }
510 } else if (FXJSE_Value_IsObject(argValue)) {
511 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
512 GetObjectDefaultValue(argValue, newPropertyValue);
513 if (!FXJSE_Value_IsNull(newPropertyValue)) {
514 uCount++;
515 if (uCount == 1) {
516 dMaxValue = HValueToDouble(hThis, newPropertyValue);
517 } else {
518 FX_DOUBLE dValue = HValueToDouble(hThis, newPropertyValue);
519 if (dMaxValue < dValue) {
520 dMaxValue = dValue;
521 }
522 }
523 }
524 FXJSE_Value_Release(newPropertyValue);
525 } else {
526 uCount++;
527 if (uCount == 1) {
528 dMaxValue = HValueToDouble(hThis, argValue);
529 } else {
530 FX_DOUBLE dValue = HValueToDouble(hThis, argValue);
531 if (dMaxValue < dValue) {
532 dMaxValue = dValue;
533 }
534 }
535 }
536 FXJSE_Value_Release(argValue);
537 }
538 argValue = 0;
539 if (uCount) {
540 FXJSE_Value_SetDouble(args.GetReturnValue(), dMaxValue);
541 } else {
542 FXJSE_Value_SetNull(args.GetReturnValue());
543 }
544 }
545 void CXFA_FM2JSContext::Min(FXJSE_HOBJECT hThis,
546 const CFX_ByteStringC& szFuncName,
547 CFXJSE_Arguments& args) {
548 CXFA_FM2JSContext* pContext =
549 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
550 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
551 int32_t argc = args.GetLength();
552 uint32_t uCount = 0;
553 FX_DOUBLE dMinValue = 0.0;
554 FXJSE_HVALUE argValue = 0;
555 for (int32_t i = 0; i < argc; i++) {
556 argValue = args.GetValue(i);
557 if (FXJSE_Value_IsNull(argValue)) {
558 FXJSE_Value_Release(argValue);
559 continue;
560 } else if (FXJSE_Value_IsArray(argValue)) {
561 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
562 FXJSE_Value_GetObjectProp(argValue, "length", lengthValue);
563 int32_t iLength = FXJSE_Value_ToInteger(lengthValue);
564 FXJSE_Value_Release(lengthValue);
565 if (iLength > 2) {
566 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
567 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
568 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
569 FXJSE_Value_GetObjectPropByIdx(argValue, 1, propertyValue);
570 FXJSE_Value_GetObjectPropByIdx(argValue, 2, jsObjectValue);
571 if (FXJSE_Value_IsNull(propertyValue)) {
572 for (int32_t i = 2; i < iLength; i++) {
573 FXJSE_Value_GetObjectPropByIdx(argValue, i, jsObjectValue);
574 GetObjectDefaultValue(jsObjectValue, newPropertyValue);
575 if (!FXJSE_Value_IsNull(newPropertyValue)) {
576 uCount++;
577 if (uCount == 1) {
578 dMinValue = HValueToDouble(hThis, newPropertyValue);
579 } else {
580 FX_DOUBLE dValue = HValueToDouble(hThis, newPropertyValue);
581 if (dMinValue > dValue) {
582 dMinValue = dValue;
583 }
584 }
585 }
586 }
587 } else {
588 CFX_ByteString propertyStr;
589 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
590 for (int32_t i = 2; i < iLength; i++) {
591 FXJSE_Value_GetObjectPropByIdx(argValue, i, jsObjectValue);
592 FXJSE_Value_GetObjectProp(jsObjectValue, propertyStr,
593 newPropertyValue);
594 if (!FXJSE_Value_IsNull(newPropertyValue)) {
595 uCount++;
596 if (uCount == 1) {
597 dMinValue = HValueToDouble(hThis, newPropertyValue);
598 } else {
599 FX_DOUBLE dValue = HValueToDouble(hThis, newPropertyValue);
600 if (dMinValue > dValue) {
601 dMinValue = dValue;
602 }
603 }
604 }
605 }
606 }
607 FXJSE_Value_Release(propertyValue);
608 FXJSE_Value_Release(jsObjectValue);
609 FXJSE_Value_Release(newPropertyValue);
610 } else {
611 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
612 }
613 } else if (FXJSE_Value_IsObject(argValue)) {
614 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
615 GetObjectDefaultValue(argValue, newPropertyValue);
616 if (!FXJSE_Value_IsNull(newPropertyValue)) {
617 uCount++;
618 if (uCount == 1) {
619 dMinValue = HValueToDouble(hThis, newPropertyValue);
620 } else {
621 FX_DOUBLE dValue = HValueToDouble(hThis, newPropertyValue);
622 if (dMinValue > dValue) {
623 dMinValue = dValue;
624 }
625 }
626 }
627 FXJSE_Value_Release(newPropertyValue);
628 } else {
629 uCount++;
630 if (uCount == 1) {
631 dMinValue = HValueToDouble(hThis, argValue);
632 } else {
633 FX_DOUBLE dValue = HValueToDouble(hThis, argValue);
634 if (dMinValue > dValue) {
635 dMinValue = dValue;
636 }
637 }
638 }
639 FXJSE_Value_Release(argValue);
640 }
641 argValue = 0;
642 if (uCount) {
643 FXJSE_Value_SetDouble(args.GetReturnValue(), dMinValue);
644 } else {
645 FXJSE_Value_SetNull(args.GetReturnValue());
646 }
647 }
648 void CXFA_FM2JSContext::Mod(FXJSE_HOBJECT hThis,
649 const CFX_ByteStringC& szFuncName,
650 CFXJSE_Arguments& args) {
651 CXFA_FM2JSContext* pContext =
652 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
653 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
654 if (args.GetLength() == 2) {
655 FXJSE_HVALUE argOne = args.GetValue(0);
656 FXJSE_HVALUE argTwo = args.GetValue(1);
657 if (FXJSE_Value_IsNull(argOne) || FXJSE_Value_IsNull(argTwo)) {
658 FXJSE_Value_SetNull(args.GetReturnValue());
659 } else {
660 FX_DOUBLE dDividend = 0.0;
661 FX_DOUBLE dDividor = 0.0;
662 if (FXJSE_Value_IsArray(argOne)) {
663 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
664 FXJSE_Value_GetObjectProp(argOne, "length", lengthValue);
665 int32_t iLength = FXJSE_Value_ToInteger(lengthValue);
666 FXJSE_Value_Release(lengthValue);
667 if (iLength > 2) {
668 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
669 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
670 FXJSE_Value_GetObjectPropByIdx(argOne, 1, propertyValue);
671 FXJSE_Value_GetObjectPropByIdx(argOne, 2, jsObjectValue);
672 if (FXJSE_Value_IsNull(propertyValue)) {
673 dDividend = HValueToDouble(hThis, jsObjectValue);
674 } else {
675 CFX_ByteString propertyStr;
676 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
677 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
678 FXJSE_Value_GetObjectProp(jsObjectValue, propertyStr,
679 newPropertyValue);
680 dDividend = HValueToDouble(hThis, newPropertyValue);
681 FXJSE_Value_Release(newPropertyValue);
682 }
683 FXJSE_Value_Release(propertyValue);
684 FXJSE_Value_Release(jsObjectValue);
685 } else {
686 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
687 }
688 } else {
689 dDividend = HValueToDouble(hThis, argOne);
690 }
691 if (FXJSE_Value_IsArray(argTwo)) {
692 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
693 FXJSE_Value_GetObjectProp(argTwo, "length", lengthValue);
694 int32_t iLength = FXJSE_Value_ToInteger(lengthValue);
695 FXJSE_Value_Release(lengthValue);
696 if (iLength > 2) {
697 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
698 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
699 FXJSE_Value_GetObjectPropByIdx(argTwo, 1, propertyValue);
700 FXJSE_Value_GetObjectPropByIdx(argTwo, 2, jsObjectValue);
701 if (FXJSE_Value_IsNull(propertyValue)) {
702 dDividor = HValueToDouble(hThis, jsObjectValue);
703 } else {
704 CFX_ByteString propertyStr;
705 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
706 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
707 FXJSE_Value_GetObjectProp(jsObjectValue, propertyStr,
708 newPropertyValue);
709 dDividor = HValueToDouble(hThis, newPropertyValue);
710 FXJSE_Value_Release(newPropertyValue);
711 }
712 FXJSE_Value_Release(propertyValue);
713 FXJSE_Value_Release(jsObjectValue);
714 } else {
715 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
716 }
717 } else {
718 dDividor = HValueToDouble(hThis, argTwo);
719 }
720 if (dDividor) {
721 FXJSE_Value_SetDouble(
722 args.GetReturnValue(),
723 dDividend - dDividor * (int32_t)(dDividend / dDividor));
724 } else {
725 pContext->ThrowScriptErrorMessage(XFA_IDS_DIVIDE_ZERO);
726 }
727 }
728 FXJSE_Value_Release(argOne);
729 FXJSE_Value_Release(argTwo);
730 } else {
731 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
732 L"Mod");
733 }
734 }
735 void CXFA_FM2JSContext::Round(FXJSE_HOBJECT hThis,
736 const CFX_ByteStringC& szFuncName,
737 CFXJSE_Arguments& args) {
738 CXFA_FM2JSContext* pContext =
739 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
740 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
741 int32_t argc = args.GetLength();
742 uint8_t uPrecision = 0;
743 if (argc == 1) {
744 FXJSE_HVALUE argOne = args.GetValue(0);
745 if (FXJSE_Value_IsNull(argOne)) {
746 FXJSE_Value_SetNull(args.GetReturnValue());
747 } else {
748 FX_DOUBLE dValue = 0.0;
749 if (FXJSE_Value_IsArray(argOne)) {
750 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
751 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
752 FXJSE_Value_GetObjectPropByIdx(argOne, 1, propertyValue);
753 FXJSE_Value_GetObjectPropByIdx(argOne, 2, jsObjectValue);
754 if (FXJSE_Value_IsNull(propertyValue)) {
755 dValue = HValueToDouble(hThis, jsObjectValue);
756 } else {
757 CFX_ByteString propertyStr;
758 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
759 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
760 FXJSE_Value_GetObjectProp(jsObjectValue, propertyStr,
761 newPropertyValue);
762 dValue = HValueToDouble(hThis, newPropertyValue);
763 FXJSE_Value_Release(newPropertyValue);
764 }
765 FXJSE_Value_Release(propertyValue);
766 FXJSE_Value_Release(jsObjectValue);
767 } else {
768 dValue = HValueToDouble(hThis, argOne);
769 }
770 CFX_Decimal decimalValue((FX_FLOAT)dValue, uPrecision);
771 CFX_WideString wsValue = decimalValue;
772 FXJSE_Value_SetUTF8String(args.GetReturnValue(), wsValue.UTF8Encode());
773 }
774 FXJSE_Value_Release(argOne);
775 } else if (argc == 2) {
776 FXJSE_HVALUE argOne = args.GetValue(0);
777 FXJSE_HVALUE argTwo = args.GetValue(1);
778 if (FXJSE_Value_IsNull(argOne) || FXJSE_Value_IsNull(argTwo)) {
779 FXJSE_Value_SetNull(args.GetReturnValue());
780 } else {
781 FX_DOUBLE dValue = 0.0;
782 if (FXJSE_Value_IsArray(argOne)) {
783 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
784 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
785 FXJSE_Value_GetObjectPropByIdx(argOne, 1, propertyValue);
786 FXJSE_Value_GetObjectPropByIdx(argOne, 2, jsObjectValue);
787 if (FXJSE_Value_IsNull(propertyValue)) {
788 dValue = HValueToDouble(hThis, jsObjectValue);
789 } else {
790 CFX_ByteString propertyStr;
791 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
792 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
793 FXJSE_Value_GetObjectProp(jsObjectValue, propertyStr,
794 newPropertyValue);
795 dValue = HValueToDouble(hThis, newPropertyValue);
796 FXJSE_Value_Release(newPropertyValue);
797 }
798 FXJSE_Value_Release(propertyValue);
799 FXJSE_Value_Release(jsObjectValue);
800 } else {
801 dValue = HValueToDouble(hThis, argOne);
802 }
803 FX_DOUBLE dPrecision = 0.0;
804 if (FXJSE_Value_IsArray(argTwo)) {
805 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
806 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
807 FXJSE_Value_GetObjectPropByIdx(argTwo, 1, propertyValue);
808 FXJSE_Value_GetObjectPropByIdx(argTwo, 2, jsObjectValue);
809 if (FXJSE_Value_IsNull(propertyValue)) {
810 dPrecision = HValueToDouble(hThis, jsObjectValue);
811 } else {
812 CFX_ByteString propertyStr;
813 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
814 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
815 FXJSE_Value_GetObjectProp(jsObjectValue, propertyStr,
816 newPropertyValue);
817 dPrecision = HValueToDouble(hThis, newPropertyValue);
818 FXJSE_Value_Release(newPropertyValue);
819 }
820 FXJSE_Value_Release(propertyValue);
821 FXJSE_Value_Release(jsObjectValue);
822 } else {
823 dPrecision = HValueToDouble(hThis, argTwo);
824 }
825 if (dPrecision < 0) {
826 uPrecision = 0;
827 } else if (dPrecision > 12.0) {
828 uPrecision = 12;
829 } else {
830 uPrecision = (uint8_t)dPrecision;
831 }
832 CFX_Decimal decimalValue((FX_FLOAT)dValue, uPrecision);
833 CFX_WideString wsValue = decimalValue;
834 FXJSE_Value_SetUTF8String(args.GetReturnValue(), wsValue.UTF8Encode());
835 }
836 FXJSE_Value_Release(argOne);
837 FXJSE_Value_Release(argTwo);
838 } else {
839 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
840 L"Round");
841 }
842 }
843 void CXFA_FM2JSContext::Sum(FXJSE_HOBJECT hThis,
844 const CFX_ByteStringC& szFuncName,
845 CFXJSE_Arguments& args) {
846 CXFA_FM2JSContext* pContext =
847 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
848 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
849 int32_t argc = args.GetLength();
850 uint32_t uCount = 0;
851 FX_DOUBLE dSum = 0.0;
852 if (argc) {
853 FXJSE_HVALUE argValue = 0;
854 for (int32_t i = 0; i < argc; i++) {
855 argValue = args.GetValue(i);
856 if (FXJSE_Value_IsNull(argValue)) {
857 FXJSE_Value_Release(argValue);
858 continue;
859 } else if (FXJSE_Value_IsArray(argValue)) {
860 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
861 FXJSE_Value_GetObjectProp(argValue, "length", lengthValue);
862 int32_t iLength = FXJSE_Value_ToInteger(lengthValue);
863 FXJSE_Value_Release(lengthValue);
864 if (iLength > 2) {
865 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
866 FXJSE_Value_GetObjectPropByIdx(argValue, 1, propertyValue);
867 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
868 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
869 if (FXJSE_Value_IsNull(propertyValue)) {
870 for (int32_t j = 2; j < iLength; j++) {
871 FXJSE_Value_GetObjectPropByIdx(argValue, j, jsObjectValue);
872 GetObjectDefaultValue(jsObjectValue, newPropertyValue);
873 if (!FXJSE_Value_IsNull(newPropertyValue)) {
874 dSum += HValueToDouble(hThis, jsObjectValue);
875 uCount++;
876 }
877 }
878 } else {
879 CFX_ByteString propertyStr;
880 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
881 for (int32_t j = 2; j < iLength; j++) {
882 FXJSE_Value_GetObjectPropByIdx(argValue, j, jsObjectValue);
883 FXJSE_Value_GetObjectProp(jsObjectValue, propertyStr,
884 newPropertyValue);
885 if (!FXJSE_Value_IsNull(newPropertyValue)) {
886 dSum += HValueToDouble(hThis, newPropertyValue);
887 uCount++;
888 }
889 }
890 }
891 FXJSE_Value_Release(newPropertyValue);
892 FXJSE_Value_Release(jsObjectValue);
893 FXJSE_Value_Release(propertyValue);
894 } else {
895 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
896 }
897 } else if (FXJSE_Value_IsObject(argValue)) {
898 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
899 GetObjectDefaultValue(argValue, newPropertyValue);
900 if (!FXJSE_Value_IsNull(newPropertyValue)) {
901 dSum += HValueToDouble(hThis, argValue);
902 uCount++;
903 }
904 FXJSE_Value_Release(newPropertyValue);
905 } else {
906 dSum += HValueToDouble(hThis, argValue);
907 uCount++;
908 }
909 FXJSE_Value_Release(argValue);
910 }
911 argValue = 0;
912 }
913 if (uCount < 1) {
914 FXJSE_Value_SetNull(args.GetReturnValue());
915 } else {
916 FXJSE_Value_SetDouble(args.GetReturnValue(), dSum);
917 }
918 }
919 void CXFA_FM2JSContext::Date(FXJSE_HOBJECT hThis,
920 const CFX_ByteStringC& szFuncName,
921 CFXJSE_Arguments& args) {
922 if (args.GetLength() == 0) {
923 struct tm* pTmStruct = 0;
924 time_t currentTime;
925 time(&currentTime);
926 pTmStruct = gmtime(&currentTime);
927 CFX_ByteString bufferYear;
928 CFX_ByteString bufferMon;
929 CFX_ByteString bufferDay;
930 bufferYear.Format("%d", pTmStruct->tm_year + 1900);
931 bufferMon.Format("%02d", pTmStruct->tm_mon + 1);
932 bufferDay.Format("%02d", pTmStruct->tm_mday);
933 CFX_ByteString bufferCurrent = bufferYear + bufferMon + bufferDay;
934 int32_t dDays = DateString2Num(bufferCurrent);
935 FXJSE_Value_SetInteger(args.GetReturnValue(), dDays);
936 } else {
937 CXFA_FM2JSContext* pContext =
938 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
939 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
940 L"Date");
941 }
942 }
943 void CXFA_FM2JSContext::Date2Num(FXJSE_HOBJECT hThis,
944 const CFX_ByteStringC& szFuncName,
945 CFXJSE_Arguments& args) {
946 int32_t argc = args.GetLength();
947 if ((argc > 0) && (argc < 4)) {
948 FX_BOOL bFlags = FALSE;
949 CFX_ByteString dateString;
950 CFX_ByteString formatString;
951 CFX_ByteString localString;
952 FXJSE_HVALUE dateValue = GetSimpleHValue(hThis, args, 0);
953 FXJSE_HVALUE formatValue = 0;
954 FXJSE_HVALUE localValue = 0;
955 if (HValueIsNull(hThis, dateValue)) {
956 bFlags = TRUE;
957 } else {
958 HValueToUTF8String(dateValue, dateString);
959 }
960 if (argc > 1) {
961 formatValue = GetSimpleHValue(hThis, args, 1);
962 if (HValueIsNull(hThis, formatValue)) {
963 bFlags = TRUE;
964 } else {
965 HValueToUTF8String(formatValue, formatString);
966 }
967 }
968 if (argc == 3) {
969 localValue = GetSimpleHValue(hThis, args, 2);
970 if (HValueIsNull(hThis, localValue)) {
971 bFlags = TRUE;
972 } else {
973 HValueToUTF8String(localValue, localString);
974 }
975 }
976 if (!bFlags) {
977 CFX_ByteString szIsoDateString;
978 FX_BOOL bRet = Local2IsoDate(hThis, dateString, formatString, localString,
979 szIsoDateString);
980 if (bRet) {
981 FXJSE_Value_SetInteger(args.GetReturnValue(),
982 DateString2Num(szIsoDateString));
983 } else {
984 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
985 }
986 } else {
987 FXJSE_Value_SetNull(args.GetReturnValue());
988 }
989 FXJSE_Value_Release(dateValue);
990 if (argc > 1) {
991 FXJSE_Value_Release(formatValue);
992 if (argc == 3) {
993 FXJSE_Value_Release(localValue);
994 }
995 }
996 } else {
997 CXFA_FM2JSContext* pContext =
998 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
999 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1000 L"Date2Num");
1001 }
1002 }
1003 void CXFA_FM2JSContext::DateFmt(FXJSE_HOBJECT hThis,
1004 const CFX_ByteStringC& szFuncName,
1005 CFXJSE_Arguments& args) {
1006 int32_t argc = args.GetLength();
1007 if (argc < 3) {
1008 FX_BOOL bFlags = FALSE;
1009 int32_t iStyle = 0;
1010 CFX_ByteString szLocal;
1011 FXJSE_HVALUE argStyle = 0;
1012 FXJSE_HVALUE argLocal = 0;
1013 if (argc > 0) {
1014 argStyle = GetSimpleHValue(hThis, args, 0);
1015 if (FXJSE_Value_IsNull(argStyle)) {
1016 bFlags = TRUE;
1017 }
1018 iStyle = (int32_t)HValueToFloat(hThis, argStyle);
1019 if (iStyle > 4 || iStyle < 0) {
1020 iStyle = 0;
1021 }
1022 }
1023 if (argc == 2) {
1024 argLocal = GetSimpleHValue(hThis, args, 1);
1025 if (FXJSE_Value_IsNull(argLocal)) {
1026 bFlags = TRUE;
1027 } else {
1028 HValueToUTF8String(argLocal, szLocal);
1029 }
1030 }
1031 if (!bFlags) {
1032 CFX_ByteString formatStr;
1033 GetStandardDateFormat(hThis, iStyle, szLocal, formatStr);
1034 if (formatStr.IsEmpty()) {
1035 formatStr = "";
1036 }
1037 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr);
1038 } else {
1039 FXJSE_Value_SetNull(args.GetReturnValue());
1040 }
1041 if (argc > 0) {
1042 FXJSE_Value_Release(argStyle);
1043 if (argc == 2) {
1044 FXJSE_Value_Release(argLocal);
1045 }
1046 }
1047 } else {
1048 CXFA_FM2JSContext* pContext =
1049 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
1050 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1051 L"Date2Num");
1052 }
1053 }
1054 void CXFA_FM2JSContext::IsoDate2Num(FXJSE_HOBJECT hThis,
1055 const CFX_ByteStringC& szFuncName,
1056 CFXJSE_Arguments& args) {
1057 if (args.GetLength() == 1) {
1058 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
1059 if (FXJSE_Value_IsNull(argOne)) {
1060 FXJSE_Value_SetNull(args.GetReturnValue());
1061 } else {
1062 CFX_ByteString szArgString;
1063 HValueToUTF8String(argOne, szArgString);
1064 int32_t dDays = DateString2Num(szArgString);
1065 FXJSE_Value_SetInteger(args.GetReturnValue(), (int32_t)dDays);
1066 }
1067 FXJSE_Value_Release(argOne);
1068 } else {
1069 CXFA_FM2JSContext* pContext =
1070 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
1071 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1072 L"IsoDate2Num");
1073 }
1074 }
1075 void CXFA_FM2JSContext::IsoTime2Num(FXJSE_HOBJECT hThis,
1076 const CFX_ByteStringC& szFuncName,
1077 CFXJSE_Arguments& args) {
1078 CXFA_FM2JSContext* pContext =
1079 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
1080 if (args.GetLength() == 1) {
1081 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
1082 if (HValueIsNull(hThis, argOne)) {
1083 FXJSE_Value_SetNull(args.GetReturnValue());
1084 } else {
1085 CXFA_Document* pDoc = pContext->GetDocument();
1086 FXSYS_assert(pDoc);
1087 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
1088 CFX_ByteString szArgString;
1089 HValueToUTF8String(argOne, szArgString);
1090 szArgString = szArgString.Mid(szArgString.Find('T', 0) + 1);
1091 if (szArgString.IsEmpty()) {
1092 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
1093 FXJSE_Value_Release(argOne);
1094 return;
1095 }
1096 CXFA_LocaleValue timeValue(
1097 XFA_VT_TIME,
1098 CFX_WideString::FromUTF8(szArgString, szArgString.GetLength()),
1099 (CXFA_LocaleMgr*)pMgr);
1100 if (timeValue.IsValid()) {
1101 CFX_Unitime uniTime = timeValue.GetTime();
1102 int32_t hour = uniTime.GetHour();
1103 int32_t min = uniTime.GetMinute();
1104 int32_t second = uniTime.GetSecond();
1105 int32_t milSecond = uniTime.GetMillisecond();
1106 IFX_Locale* pDefLocale = pMgr->GetDefLocale();
1107 FXSYS_assert(pDefLocale);
1108 FX_TIMEZONE tzLocale;
1109 pDefLocale->GetTimeZone(tzLocale);
1110 int32_t mins = hour * 60 + min;
1111 mins -= (tzLocale.tzHour * 60);
1112 while (mins > 1440) {
1113 mins -= 1440;
1114 }
1115 while (mins < 0) {
1116 mins += 1440;
1117 }
1118 hour = mins / 60;
1119 min = mins % 60;
1120 int32_t iResult =
1121 hour * 3600000 + min * 60000 + second * 1000 + milSecond + 1;
1122 FXJSE_Value_SetInteger(args.GetReturnValue(), iResult);
1123 } else {
1124 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
1125 }
1126 }
1127 FXJSE_Value_Release(argOne);
1128 } else {
1129 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1130 L"IsoTime2Num");
1131 }
1132 }
1133 void CXFA_FM2JSContext::LocalDateFmt(FXJSE_HOBJECT hThis,
1134 const CFX_ByteStringC& szFuncName,
1135 CFXJSE_Arguments& args) {
1136 int32_t argc = args.GetLength();
1137 if (argc < 3) {
1138 FX_BOOL bFlags = FALSE;
1139 int32_t iStyle = 0;
1140 CFX_ByteString szLocal;
1141 FXJSE_HVALUE argStyle = 0;
1142 FXJSE_HVALUE argLocal = 0;
1143 if (argc > 0) {
1144 argStyle = GetSimpleHValue(hThis, args, 0);
1145 if (FXJSE_Value_IsNull(argStyle)) {
1146 bFlags = TRUE;
1147 }
1148 iStyle = (int32_t)HValueToFloat(hThis, argStyle);
1149 if (iStyle > 4 || iStyle < 0) {
1150 iStyle = 0;
1151 }
1152 }
1153 if (argc == 2) {
1154 argLocal = GetSimpleHValue(hThis, args, 1);
1155 if (FXJSE_Value_IsNull(argLocal)) {
1156 bFlags = TRUE;
1157 } else {
1158 HValueToUTF8String(argLocal, szLocal);
1159 }
1160 }
1161 if (!bFlags) {
1162 CFX_ByteString formatStr;
1163 GetLocalDateFormat(hThis, iStyle, szLocal, formatStr, FALSE);
1164 if (formatStr.IsEmpty()) {
1165 formatStr = "";
1166 }
1167 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr);
1168 } else {
1169 FXJSE_Value_SetNull(args.GetReturnValue());
1170 }
1171 if (argc > 0) {
1172 FXJSE_Value_Release(argStyle);
1173 if (argc == 2) {
1174 FXJSE_Value_Release(argLocal);
1175 }
1176 }
1177 } else {
1178 CXFA_FM2JSContext* pContext =
1179 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
1180 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1181 L"LocalDateFmt");
1182 }
1183 }
1184 void CXFA_FM2JSContext::LocalTimeFmt(FXJSE_HOBJECT hThis,
1185 const CFX_ByteStringC& szFuncName,
1186 CFXJSE_Arguments& args) {
1187 int32_t argc = args.GetLength();
1188 if (argc < 3) {
1189 FX_BOOL bFlags = FALSE;
1190 int32_t iStyle = 0;
1191 CFX_ByteString szLocal;
1192 FXJSE_HVALUE argStyle = 0;
1193 FXJSE_HVALUE argLocal = 0;
1194 if (argc > 0) {
1195 argStyle = GetSimpleHValue(hThis, args, 0);
1196 if (FXJSE_Value_IsNull(argStyle)) {
1197 bFlags = TRUE;
1198 }
1199 iStyle = (int32_t)HValueToFloat(hThis, argStyle);
1200 if (iStyle > 4 || iStyle < 0) {
1201 iStyle = 0;
1202 }
1203 }
1204 if (argc == 2) {
1205 argLocal = GetSimpleHValue(hThis, args, 1);
1206 if (FXJSE_Value_IsNull(argLocal)) {
1207 bFlags = TRUE;
1208 } else {
1209 HValueToUTF8String(argLocal, szLocal);
1210 }
1211 }
1212 if (!bFlags) {
1213 CFX_ByteString formatStr;
1214 GetLocalTimeFormat(hThis, iStyle, szLocal, formatStr, FALSE);
1215 if (formatStr.IsEmpty()) {
1216 formatStr = "";
1217 }
1218 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr);
1219 } else {
1220 FXJSE_Value_SetNull(args.GetReturnValue());
1221 }
1222 if (argc > 0) {
1223 FXJSE_Value_Release(argStyle);
1224 if (argc == 2) {
1225 FXJSE_Value_Release(argLocal);
1226 }
1227 }
1228 } else {
1229 CXFA_FM2JSContext* pContext =
1230 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
1231 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1232 L"LocalTimeFmt");
1233 }
1234 }
1235 void CXFA_FM2JSContext::Num2Date(FXJSE_HOBJECT hThis,
1236 const CFX_ByteStringC& szFuncName,
1237 CFXJSE_Arguments& args) {
1238 int32_t argc = args.GetLength();
1239 if ((argc > 0) && (argc < 4)) {
1240 FX_BOOL bFlags = FALSE;
1241 int32_t dDate;
1242 CFX_ByteString formatString;
1243 CFX_ByteString localString;
1244 FXJSE_HVALUE dateValue = GetSimpleHValue(hThis, args, 0);
1245 FXJSE_HVALUE formatValue = 0;
1246 FXJSE_HVALUE localValue = 0;
1247 if (HValueIsNull(hThis, dateValue)) {
1248 bFlags = TRUE;
1249 } else {
1250 dDate = (int32_t)HValueToFloat(hThis, dateValue);
1251 bFlags = dDate < 1;
1252 }
1253 if (argc > 1) {
1254 formatValue = GetSimpleHValue(hThis, args, 1);
1255 if (HValueIsNull(hThis, formatValue)) {
1256 bFlags = TRUE;
1257 } else {
1258 HValueToUTF8String(formatValue, formatString);
1259 }
1260 }
1261 if (argc == 3) {
1262 localValue = GetSimpleHValue(hThis, args, 2);
1263 if (HValueIsNull(hThis, localValue)) {
1264 bFlags = TRUE;
1265 } else {
1266 HValueToUTF8String(localValue, localString);
1267 }
1268 }
1269 if (!bFlags) {
1270 int32_t iYear = 1900;
1271 int32_t iMonth = 1;
1272 int32_t iDay = 1;
1273 int32_t i = 0;
1274 while (dDate > 0) {
1275 if (iMonth == 2) {
1276 if ((!((iYear + i) % 4) && ((iYear + i) % 100)) ||
1277 !((iYear + i) % 400)) {
1278 if (dDate > 29) {
1279 ++iMonth;
1280 if (iMonth > 12) {
1281 iMonth = 1;
1282 ++i;
1283 }
1284 iDay = 1;
1285 dDate -= 29;
1286 } else {
1287 iDay += static_cast<int32_t>(dDate) - 1;
1288 dDate = 0;
1289 }
1290 } else {
1291 if (dDate > 28) {
1292 ++iMonth;
1293 if (iMonth > 12) {
1294 iMonth = 1;
1295 ++i;
1296 }
1297 iDay = 1;
1298 dDate -= 28;
1299 } else {
1300 iDay += static_cast<int32_t>(dDate) - 1;
1301 dDate = 0;
1302 }
1303 }
1304 } else if (iMonth < 8) {
1305 if ((iMonth % 2 == 0)) {
1306 if (dDate > 30) {
1307 ++iMonth;
1308 if (iMonth > 12) {
1309 iMonth = 1;
1310 ++i;
1311 }
1312 iDay = 1;
1313 dDate -= 30;
1314 } else {
1315 iDay += static_cast<int32_t>(dDate) - 1;
1316 dDate = 0;
1317 }
1318 } else {
1319 if (dDate > 31) {
1320 ++iMonth;
1321 if (iMonth > 12) {
1322 iMonth = 1;
1323 ++i;
1324 }
1325 iDay = 1;
1326 dDate -= 31;
1327 } else {
1328 iDay += static_cast<int32_t>(dDate) - 1;
1329 dDate = 0;
1330 }
1331 }
1332 } else {
1333 if (iMonth % 2 != 0) {
1334 if (dDate > 30) {
1335 ++iMonth;
1336 if (iMonth > 12) {
1337 iMonth = 1;
1338 ++i;
1339 }
1340 iDay = 1;
1341 dDate -= 30;
1342 } else {
1343 iDay += static_cast<int32_t>(dDate) - 1;
1344 dDate = 0;
1345 }
1346 } else {
1347 if (dDate > 31) {
1348 ++iMonth;
1349 if (iMonth > 12) {
1350 iMonth = 1;
1351 ++i;
1352 }
1353 iDay = 1;
1354 dDate -= 31;
1355 } else {
1356 iDay += static_cast<int32_t>(dDate) - 1;
1357 dDate = 0;
1358 }
1359 }
1360 }
1361 }
1362 CFX_ByteString szIsoDateString;
1363 szIsoDateString.Format("%d%02d%02d", iYear + i, iMonth, iDay);
1364 CFX_ByteString szLocalDateString;
1365 IsoDate2Local(hThis, szIsoDateString, formatString, localString,
1366 szLocalDateString);
1367 if (szLocalDateString.IsEmpty()) {
1368 szLocalDateString = "";
1369 }
1370 FXJSE_Value_SetUTF8String(args.GetReturnValue(), szLocalDateString);
1371 } else {
1372 FXJSE_Value_SetNull(args.GetReturnValue());
1373 }
1374 FXJSE_Value_Release(dateValue);
1375 if (argc > 1) {
1376 FXJSE_Value_Release(formatValue);
1377 if (argc == 3) {
1378 FXJSE_Value_Release(localValue);
1379 }
1380 }
1381 } else {
1382 CXFA_FM2JSContext* pContext =
1383 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
1384 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1385 L"Num2Date");
1386 }
1387 }
1388 void CXFA_FM2JSContext::Num2GMTime(FXJSE_HOBJECT hThis,
1389 const CFX_ByteStringC& szFuncName,
1390 CFXJSE_Arguments& args) {
1391 int32_t argc = args.GetLength();
1392 if ((argc > 0) && (argc < 4)) {
1393 FX_BOOL bFlags = FALSE;
1394 int32_t iTime;
1395 CFX_ByteString formatString;
1396 CFX_ByteString localString;
1397 FXJSE_HVALUE timeValue = GetSimpleHValue(hThis, args, 0);
1398 FXJSE_HVALUE formatValue = 0;
1399 FXJSE_HVALUE localValue = 0;
1400 if (FXJSE_Value_IsNull(timeValue)) {
1401 bFlags = TRUE;
1402 } else {
1403 iTime = (int32_t)HValueToFloat(hThis, timeValue);
1404 if (FXSYS_abs(iTime) < 1.0) {
1405 bFlags = TRUE;
1406 }
1407 }
1408 if (argc > 1) {
1409 formatValue = GetSimpleHValue(hThis, args, 1);
1410 if (FXJSE_Value_IsNull(formatValue)) {
1411 bFlags = TRUE;
1412 } else {
1413 HValueToUTF8String(formatValue, formatString);
1414 }
1415 }
1416 if (argc == 3) {
1417 localValue = GetSimpleHValue(hThis, args, 2);
1418 if (FXJSE_Value_IsNull(localValue)) {
1419 bFlags = TRUE;
1420 } else {
1421 HValueToUTF8String(localValue, localString);
1422 }
1423 }
1424 if (!bFlags) {
1425 CFX_ByteString szGMTTimeString;
1426 Num2AllTime(hThis, iTime, formatString, localString, TRUE,
1427 szGMTTimeString);
1428 if (szGMTTimeString.IsEmpty()) {
1429 szGMTTimeString = "";
1430 }
1431 FXJSE_Value_SetUTF8String(args.GetReturnValue(), szGMTTimeString);
1432 } else {
1433 FXJSE_Value_SetNull(args.GetReturnValue());
1434 }
1435 FXJSE_Value_Release(timeValue);
1436 if (argc > 1) {
1437 FXJSE_Value_Release(formatValue);
1438 if (argc == 3) {
1439 FXJSE_Value_Release(localValue);
1440 }
1441 }
1442 } else {
1443 CXFA_FM2JSContext* pContext =
1444 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
1445 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1446 L"Num2GMTime");
1447 }
1448 }
1449 void CXFA_FM2JSContext::Num2Time(FXJSE_HOBJECT hThis,
1450 const CFX_ByteStringC& szFuncName,
1451 CFXJSE_Arguments& args) {
1452 int32_t argc = args.GetLength();
1453 if ((argc > 0) && (argc < 4)) {
1454 FX_BOOL bFlags = FALSE;
1455 FX_FLOAT fTime;
1456 CFX_ByteString formatString;
1457 CFX_ByteString localString;
1458 FXJSE_HVALUE timeValue = GetSimpleHValue(hThis, args, 0);
1459 FXJSE_HVALUE formatValue = 0;
1460 FXJSE_HVALUE localValue = 0;
1461 if (FXJSE_Value_IsNull(timeValue)) {
1462 bFlags = TRUE;
1463 } else {
1464 fTime = HValueToFloat(hThis, timeValue);
1465 if (FXSYS_fabs(fTime) < 1.0) {
1466 bFlags = TRUE;
1467 }
1468 }
1469 if (argc > 1) {
1470 formatValue = GetSimpleHValue(hThis, args, 1);
1471 if (FXJSE_Value_IsNull(formatValue)) {
1472 bFlags = TRUE;
1473 } else {
1474 HValueToUTF8String(formatValue, formatString);
1475 }
1476 }
1477 if (argc == 3) {
1478 localValue = GetSimpleHValue(hThis, args, 2);
1479 if (FXJSE_Value_IsNull(localValue)) {
1480 bFlags = TRUE;
1481 } else {
1482 HValueToUTF8String(localValue, localString);
1483 }
1484 }
1485 if (!bFlags) {
1486 CFX_ByteString szLocalTimeString;
1487 Num2AllTime(hThis, (int32_t)fTime, formatString, localString, FALSE,
1488 szLocalTimeString);
1489 if (szLocalTimeString.IsEmpty()) {
1490 szLocalTimeString = "";
1491 }
1492 FXJSE_Value_SetUTF8String(args.GetReturnValue(), szLocalTimeString);
1493 } else {
1494 FXJSE_Value_SetNull(args.GetReturnValue());
1495 }
1496 FXJSE_Value_Release(timeValue);
1497 if (argc > 1) {
1498 FXJSE_Value_Release(formatValue);
1499 if (argc == 3) {
1500 FXJSE_Value_Release(localValue);
1501 }
1502 }
1503 } else {
1504 CXFA_FM2JSContext* pContext =
1505 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
1506 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1507 L"Num2Time");
1508 }
1509 }
1510 void CXFA_FM2JSContext::Time(FXJSE_HOBJECT hThis,
1511 const CFX_ByteStringC& szFuncName,
1512 CFXJSE_Arguments& args) {
1513 if (args.GetLength() == 0) {
1514 time_t now;
1515 time(&now);
1516 struct tm* pGmt = gmtime(&now);
1517 int32_t iGMHour = pGmt->tm_hour;
1518 int32_t iGMMin = pGmt->tm_min;
1519 int32_t iGMSec = pGmt->tm_sec;
1520 FXJSE_Value_SetInteger(args.GetReturnValue(),
1521 ((iGMHour * 3600 + iGMMin * 60 + iGMSec) * 1000));
1522 } else {
1523 CXFA_FM2JSContext* pContext =
1524 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
1525 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1526 L"Time");
1527 }
1528 }
1529 void CXFA_FM2JSContext::Time2Num(FXJSE_HOBJECT hThis,
1530 const CFX_ByteStringC& szFuncName,
1531 CFXJSE_Arguments& args) {
1532 int32_t argc = args.GetLength();
1533 if ((argc > 0) && (argc < 4)) {
1534 FX_BOOL bFlags = FALSE;
1535 CFX_ByteString timeString;
1536 CFX_ByteString formatString;
1537 CFX_ByteString localString;
1538 FXJSE_HVALUE timeValue = GetSimpleHValue(hThis, args, 0);
1539 FXJSE_HVALUE formatValue = 0;
1540 FXJSE_HVALUE localValue = 0;
1541 if (HValueIsNull(hThis, timeValue)) {
1542 bFlags = TRUE;
1543 } else {
1544 HValueToUTF8String(timeValue, timeString);
1545 }
1546 if (argc > 1) {
1547 formatValue = GetSimpleHValue(hThis, args, 1);
1548 if (HValueIsNull(hThis, formatValue)) {
1549 bFlags = TRUE;
1550 } else {
1551 HValueToUTF8String(formatValue, formatString);
1552 }
1553 }
1554 if (argc == 3) {
1555 localValue = GetSimpleHValue(hThis, args, 2);
1556 if (HValueIsNull(hThis, localValue)) {
1557 bFlags = TRUE;
1558 } else {
1559 HValueToUTF8String(localValue, localString);
1560 }
1561 }
1562 if (!bFlags) {
1563 CXFA_FM2JSContext* pContext =
1564 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
1565 CXFA_Document* pDoc = pContext->GetDocument();
1566 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
1567 IFX_Locale* pLocale = NULL;
1568 if (localString.IsEmpty()) {
1569 CXFA_Node* pThisNode =
1570 ToNode(pDoc->GetScriptContext()->GetThisObject());
1571 FXSYS_assert(pThisNode);
1572 CXFA_WidgetData widgetData(pThisNode);
1573 pLocale = widgetData.GetLocal();
1574 } else {
1575 pLocale = pMgr->GetLocaleByName(
1576 CFX_WideString::FromUTF8(localString, localString.GetLength()));
1577 }
1578 CFX_WideString wsFormat;
1579 if (formatString.IsEmpty()) {
1580 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
1581 } else {
1582 wsFormat =
1583 CFX_WideString::FromUTF8(formatString, formatString.GetLength());
1584 }
1585 wsFormat = FX_WSTRC(L"time{") + wsFormat;
1586 wsFormat += FX_WSTRC(L"}");
1587 CXFA_LocaleValue timeValue(
1588 XFA_VT_TIME,
1589 CFX_WideString::FromUTF8(timeString, timeString.GetLength()),
1590 wsFormat, pLocale, (CXFA_LocaleMgr*)pMgr);
1591 if (timeValue.IsValid()) {
1592 CFX_Unitime uniTime = timeValue.GetTime();
1593 int32_t hour = uniTime.GetHour();
1594 int32_t min = uniTime.GetMinute();
1595 int32_t second = uniTime.GetSecond();
1596 int32_t milSecond = uniTime.GetMillisecond();
1597 int32_t mins = hour * 60 + min;
1598 IXFA_TimeZoneProvider* pProvider = IXFA_TimeZoneProvider::Get();
1599 if (pProvider) {
1600 FX_TIMEZONE tz;
1601 pProvider->GetTimeZone(tz);
1602 mins -= (tz.tzHour * 60);
1603 while (mins > 1440) {
1604 mins -= 1440;
1605 }
1606 while (mins < 0) {
1607 mins += 1440;
1608 }
1609 hour = mins / 60;
1610 min = mins % 60;
1611 }
1612 int32_t iResult =
1613 hour * 3600000 + min * 60000 + second * 1000 + milSecond + 1;
1614 FXJSE_Value_SetInteger(args.GetReturnValue(), iResult);
1615 } else {
1616 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
1617 }
1618 } else {
1619 FXJSE_Value_SetNull(args.GetReturnValue());
1620 }
1621 FXJSE_Value_Release(timeValue);
1622 if (argc > 1) {
1623 FXJSE_Value_Release(formatValue);
1624 if (argc == 3) {
1625 FXJSE_Value_Release(localValue);
1626 }
1627 }
1628 } else {
1629 CXFA_FM2JSContext* pContext =
1630 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
1631 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1632 L"Time2Num");
1633 }
1634 }
1635 void CXFA_FM2JSContext::TimeFmt(FXJSE_HOBJECT hThis,
1636 const CFX_ByteStringC& szFuncName,
1637 CFXJSE_Arguments& args) {
1638 int32_t argc = args.GetLength();
1639 if (argc < 3) {
1640 FX_BOOL bFlags = FALSE;
1641 int32_t iStyle = 0;
1642 CFX_ByteString szLocal;
1643 FXJSE_HVALUE argStyle = 0;
1644 FXJSE_HVALUE argLocal = 0;
1645 if (argc > 0) {
1646 argStyle = GetSimpleHValue(hThis, args, 0);
1647 if (FXJSE_Value_IsNull(argStyle)) {
1648 bFlags = TRUE;
1649 }
1650 iStyle = (int32_t)HValueToFloat(hThis, argStyle);
1651 if (iStyle > 4 || iStyle < 0) {
1652 iStyle = 0;
1653 }
1654 }
1655 if (argc == 2) {
1656 argLocal = GetSimpleHValue(hThis, args, 1);
1657 if (FXJSE_Value_IsNull(argLocal)) {
1658 bFlags = TRUE;
1659 } else {
1660 HValueToUTF8String(argLocal, szLocal);
1661 }
1662 }
1663 if (!bFlags) {
1664 CFX_ByteString formatStr;
1665 GetStandardTimeFormat(hThis, iStyle, szLocal, formatStr);
1666 if (formatStr.IsEmpty()) {
1667 formatStr = "";
1668 }
1669 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr);
1670 } else {
1671 FXJSE_Value_SetNull(args.GetReturnValue());
1672 }
1673 if (argc > 0) {
1674 FXJSE_Value_Release(argStyle);
1675 if (argc == 2) {
1676 FXJSE_Value_Release(argLocal);
1677 }
1678 }
1679 } else {
1680 CXFA_FM2JSContext* pContext =
1681 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
1682 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1683 L"TimeFmt");
1684 }
1685 }
1686 FX_BOOL CXFA_FM2JSContext::IsIsoDateFormat(const FX_CHAR* pData,
1687 int32_t iLength,
1688 int32_t& iStyle,
1689 int32_t& iYear,
1690 int32_t& iMonth,
1691 int32_t& iDay) {
1692 iYear = 0;
1693 iMonth = 1;
1694 iDay = 1;
1695 FX_BOOL iRet = FALSE;
1696 if (iLength < 4) {
1697 return iRet;
1698 }
1699 FX_CHAR strYear[5];
1700 strYear[4] = '\0';
1701 for (int32_t i = 0; i < 4; ++i) {
1702 if (*(pData + i) <= '9' && *(pData + i) >= '0') {
1703 strYear[i] = *(pData + i);
1704 } else {
1705 return iRet;
1706 }
1707 }
1708 iYear = FXSYS_atoi(strYear);
1709 iStyle = 0;
1710 if (iLength > 4) {
1711 if (*(pData + 4) == '-') {
1712 iStyle = 1;
1713 } else {
1714 iStyle = 0;
1715 }
1716 } else {
1717 iRet = TRUE;
1718 return iRet;
1719 }
1720 FX_CHAR strTemp[3];
1721 strTemp[2] = '\0';
1722 int32_t iPosOff = 0;
1723 if (iStyle == 0) {
1724 iPosOff = 4;
1725 if (iLength == 4) {
1726 iRet = TRUE;
1727 return iRet;
1728 }
1729 } else {
1730 iPosOff = 5;
1731 if (iLength == 4) {
1732 iRet = TRUE;
1733 return iRet;
1734 }
1735 }
1736 if ((*(pData + iPosOff) > '9' || *(pData + iPosOff) < '0') ||
1737 (*(pData + iPosOff + 1) > '9' || *(pData + iPosOff + 1) < '0')) {
1738 return iRet;
1739 }
1740 strTemp[0] = *(pData + iPosOff);
1741 strTemp[1] = *(pData + iPosOff + 1);
1742 iMonth = FXSYS_atoi(strTemp);
1743 if (iMonth > 12 || iMonth < 1) {
1744 return iRet;
1745 }
1746 if (iStyle == 0) {
1747 iPosOff += 2;
1748 if (iLength == 6) {
1749 iRet = 1;
1750 return iRet;
1751 }
1752 } else {
1753 iPosOff += 3;
1754 if (iLength == 7) {
1755 iRet = 1;
1756 return iRet;
1757 }
1758 }
1759 if ((*(pData + iPosOff) > '9' || *(pData + iPosOff) < '0') ||
1760 (*(pData + iPosOff + 1) > '9' || *(pData + iPosOff + 1) < '0')) {
1761 return iRet;
1762 }
1763 strTemp[0] = *(pData + iPosOff);
1764 strTemp[1] = *(pData + iPosOff + 1);
1765 iDay = FXSYS_atoi(strTemp);
1766 if (iPosOff + 2 < iLength) {
1767 return iRet;
1768 }
1769 if ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) {
1770 if (iMonth == 2) {
1771 if (iDay > 29) {
1772 return iRet;
1773 }
1774 } else {
1775 if (iMonth < 8) {
1776 if (iDay > (iMonth % 2 == 0 ? 30 : 31)) {
1777 return iRet;
1778 }
1779 } else {
1780 if (iDay > (iMonth % 2 == 0 ? 31 : 30)) {
1781 return iRet;
1782 }
1783 }
1784 }
1785 } else {
1786 if (iMonth == 2) {
1787 if (iDay > 28) {
1788 return iRet;
1789 }
1790 } else {
1791 if (iMonth < 8) {
1792 if (iDay > (iMonth % 2 == 0 ? 30 : 31)) {
1793 return iRet;
1794 }
1795 } else {
1796 if (iDay > (iMonth % 2 == 0 ? 31 : 30)) {
1797 return iRet;
1798 }
1799 }
1800 }
1801 }
1802 iRet = TRUE;
1803 return iRet;
1804 }
1805 FX_BOOL CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData,
1806 int32_t iLength,
1807 int32_t& iHour,
1808 int32_t& iMinute,
1809 int32_t& iSecond,
1810 int32_t& iMilliSecond,
1811 int32_t& iZoneHour,
1812 int32_t& iZoneMinute) {
1813 iHour = 0;
1814 iMinute = 0;
1815 iSecond = 0;
1816 iMilliSecond = 0;
1817 iZoneHour = 0;
1818 iZoneMinute = 0;
1819 if (!pData) {
1820 return FALSE;
1821 }
1822 int32_t iRet = FALSE;
1823 FX_CHAR strTemp[3];
1824 strTemp[2] = '\0';
1825 int32_t iIndex = 0;
1826 int32_t iZone = 0;
1827 int32_t i = iIndex;
1828 while (i < iLength) {
1829 if ((*(pData + i) > '9' || *(pData + i) < '0') && *(pData + i) != ':') {
1830 iZone = i;
1831 break;
1832 }
1833 ++i;
1834 }
1835 if (i == iLength) {
1836 iZone = iLength;
1837 }
1838 int32_t iPos = 0;
1839 while (iIndex < iZone) {
1840 if (iIndex >= iZone) {
1841 break;
1842 }
1843 if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') {
1844 return iRet;
1845 }
1846 strTemp[0] = *(pData + iIndex);
1847 if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') {
1848 return iRet;
1849 }
1850 strTemp[1] = *(pData + iIndex + 1);
1851 if (FXSYS_atoi(strTemp) > 60) {
1852 return iRet;
1853 }
1854 if (*(pData + 2) == ':') {
1855 if (iPos == 0) {
1856 iHour = FXSYS_atoi(strTemp);
1857 ++iPos;
1858 } else if (iPos == 1) {
1859 iMinute = FXSYS_atoi(strTemp);
1860 ++iPos;
1861 } else {
1862 iSecond = FXSYS_atoi(strTemp);
1863 }
1864 iIndex += 3;
1865 } else {
1866 if (iPos == 0) {
1867 iHour = FXSYS_atoi(strTemp);
1868 ++iPos;
1869 } else if (iPos == 1) {
1870 iMinute = FXSYS_atoi(strTemp);
1871 ++iPos;
1872 } else if (iPos == 2) {
1873 iSecond = FXSYS_atoi(strTemp);
1874 ++iPos;
1875 }
1876 iIndex += 2;
1877 }
1878 }
1879 if (*(pData + iIndex) == '.') {
1880 ++iIndex;
1881 FX_CHAR strTemp[4];
1882 strTemp[3] = '\0';
1883 if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') {
1884 return iRet;
1885 }
1886 strTemp[0] = *(pData + iIndex);
1887 if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') {
1888 return iRet;
1889 }
1890 strTemp[1] = *(pData + iIndex + 1);
1891 if (*(pData + iIndex + 2) > '9' || *(pData + iIndex + 2) < '0') {
1892 return iRet;
1893 }
1894 strTemp[2] = *(pData + iIndex + 2);
1895 iMilliSecond = FXSYS_atoi(strTemp);
1896 if (iMilliSecond > 100) {
1897 iMilliSecond = 0;
1898 return iRet;
1899 }
1900 iIndex += 3;
1901 }
1902 int32_t iSign = 1;
1903 if (*(pData + iIndex) == 'z' || *(pData + iIndex) == 'Z') {
1904 iRet = 1;
1905 return iRet;
1906 } else if (*(pData + iIndex) == '+') {
1907 ++iIndex;
1908 } else if (*(pData + iIndex) == '-') {
1909 iSign = -1;
1910 ++iIndex;
1911 }
1912 iPos = 0;
1913 while (iIndex < iLength) {
1914 if (iIndex >= iLength) {
1915 return iRet;
1916 }
1917 if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') {
1918 return iRet;
1919 }
1920 strTemp[0] = *(pData + iIndex);
1921 if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') {
1922 return iRet;
1923 }
1924 strTemp[1] = *(pData + iIndex + 1);
1925 if (FXSYS_atoi(strTemp) > 60) {
1926 return iRet;
1927 }
1928 if (*(pData + 2) == ':') {
1929 if (iPos == 0) {
1930 iZoneHour = FXSYS_atoi(strTemp);
1931 } else if (iPos == 1) {
1932 iZoneMinute = FXSYS_atoi(strTemp);
1933 }
1934 iIndex += 3;
1935 } else {
1936 if (!iPos) {
1937 iZoneHour = FXSYS_atoi(strTemp);
1938 ++iPos;
1939 } else if (iPos == 1) {
1940 iZoneMinute = FXSYS_atoi(strTemp);
1941 ++iPos;
1942 }
1943 iIndex += 2;
1944 }
1945 }
1946 if (iIndex < iLength) {
1947 return iRet;
1948 }
1949 iZoneHour *= iSign;
1950 iRet = TRUE;
1951 return iRet;
1952 }
1953 FX_BOOL CXFA_FM2JSContext::IsIsoDateTimeFormat(const FX_CHAR* pData,
1954 int32_t iLength,
1955 int32_t& iYear,
1956 int32_t& iMonth,
1957 int32_t& iDay,
1958 int32_t& iHour,
1959 int32_t& iMinute,
1960 int32_t& iSecond,
1961 int32_t& iMillionSecond,
1962 int32_t& iZoneHour,
1963 int32_t& iZoneMinute) {
1964 iYear = 0;
1965 iMonth = 0;
1966 iDay = 0;
1967 iHour = 0;
1968 iMinute = 0;
1969 iSecond = 0;
1970 if (!pData) {
1971 return FALSE;
1972 }
1973 int32_t iRet = FALSE;
1974 int32_t iIndex = 0;
1975 while (*(pData + iIndex) != 'T' && *(pData + iIndex) != 't') {
1976 if (iIndex >= iLength) {
1977 return iRet;
1978 }
1979 ++iIndex;
1980 }
1981 if (iIndex != 8 && iIndex != 10) {
1982 return iRet;
1983 }
1984 int32_t iStyle = -1;
1985 iRet = IsIsoDateFormat(pData, iIndex, iStyle, iYear, iMonth, iDay);
1986 if (!iRet) {
1987 return iRet;
1988 }
1989 if (*(pData + iIndex) != 'T' && *(pData + iIndex) != 't') {
1990 return iRet;
1991 }
1992 ++iIndex;
1993 if (((iLength - iIndex > 13) && (iLength - iIndex < 6)) &&
1994 (iLength - iIndex != 15)) {
1995 return iRet;
1996 }
1997 iRet = IsIsoTimeFormat(pData + iIndex, iLength - iIndex, iHour, iMinute,
1998 iSecond, iMillionSecond, iZoneHour, iZoneMinute);
1999 if (!iRet) {
2000 return iRet;
2001 }
2002 iRet = TRUE;
2003 return iRet;
2004 }
2005 FX_BOOL CXFA_FM2JSContext::Local2IsoDate(FXJSE_HOBJECT hThis,
2006 const CFX_ByteStringC& szDate,
2007 const CFX_ByteStringC& szFormat,
2008 const CFX_ByteStringC& szLocale,
2009 CFX_ByteString& strIsoDate) {
2010 CXFA_FM2JSContext* pContext =
2011 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2012 CXFA_Document* pDoc = pContext->GetDocument();
2013 if (!pDoc) {
2014 return FALSE;
2015 }
2016 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
2017 IFX_Locale* pLocale = NULL;
2018 if (szLocale.IsEmpty()) {
2019 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2020 FXSYS_assert(pThisNode);
2021 CXFA_WidgetData widgetData(pThisNode);
2022 pLocale = widgetData.GetLocal();
2023 } else {
2024 pLocale = pMgr->GetLocaleByName(
2025 CFX_WideString::FromUTF8(szLocale.GetCStr(), szLocale.GetLength()));
2026 }
2027 if (!pLocale) {
2028 return FALSE;
2029 }
2030 CFX_WideString wsFormat;
2031 if (szFormat.IsEmpty()) {
2032 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2033 } else {
2034 wsFormat =
2035 CFX_WideString::FromUTF8(szFormat.GetCStr(), szFormat.GetLength());
2036 }
2037 CXFA_LocaleValue widgetValue(
2038 XFA_VT_DATE,
2039 CFX_WideString::FromUTF8(szDate.GetCStr(), szDate.GetLength()), wsFormat,
2040 pLocale, (CXFA_LocaleMgr*)pMgr);
2041 CFX_Unitime dt = widgetValue.GetDate();
2042 strIsoDate.Format("%4d-%02d-%02d", dt.GetYear(), dt.GetMonth(), dt.GetDay());
2043 return TRUE;
2044 }
2045 FX_BOOL CXFA_FM2JSContext::Local2IsoTime(FXJSE_HOBJECT hThis,
2046 const CFX_ByteStringC& szTime,
2047 const CFX_ByteStringC& szFormat,
2048 const CFX_ByteStringC& szLocale,
2049 CFX_ByteString& strIsoTime) {
2050 CXFA_FM2JSContext* pContext =
2051 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2052 CXFA_Document* pDoc = pContext->GetDocument();
2053 if (!pDoc) {
2054 return FALSE;
2055 }
2056 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
2057 IFX_Locale* pLocale = NULL;
2058 if (szLocale.IsEmpty()) {
2059 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2060 FXSYS_assert(pThisNode);
2061 CXFA_WidgetData widgetData(pThisNode);
2062 pLocale = widgetData.GetLocal();
2063 } else {
2064 pLocale = pMgr->GetLocaleByName(
2065 CFX_WideString::FromUTF8(szLocale.GetCStr(), szLocale.GetLength()));
2066 }
2067 if (!pLocale) {
2068 return FALSE;
2069 }
2070 CFX_WideString wsFormat;
2071 if (szFormat.IsEmpty()) {
2072 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2073 } else {
2074 wsFormat =
2075 CFX_WideString::FromUTF8(szFormat.GetCStr(), szFormat.GetLength());
2076 }
2077 wsFormat = FX_WSTRC(L"time{") + wsFormat;
2078 wsFormat += FX_WSTRC(L"}");
2079 CXFA_LocaleValue widgetValue(
2080 XFA_VT_TIME,
2081 CFX_WideString::FromUTF8(szTime.GetCStr(), szTime.GetLength()), wsFormat,
2082 pLocale, (CXFA_LocaleMgr*)pMgr);
2083 CFX_Unitime utime = widgetValue.GetTime();
2084 strIsoTime.Format("%02d:%02d:%02d.%03d", utime.GetHour(), utime.GetMinute(),
2085 utime.GetSecond(), utime.GetMillisecond());
2086 return TRUE;
2087 }
2088 FX_BOOL CXFA_FM2JSContext::IsoDate2Local(FXJSE_HOBJECT hThis,
2089 const CFX_ByteStringC& szDate,
2090 const CFX_ByteStringC& szFormat,
2091 const CFX_ByteStringC& szLocale,
2092 CFX_ByteString& strLocalDate) {
2093 CXFA_FM2JSContext* pContext =
2094 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2095 CXFA_Document* pDoc = pContext->GetDocument();
2096 if (!pDoc) {
2097 return FALSE;
2098 }
2099 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
2100 IFX_Locale* pLocale = NULL;
2101 if (szLocale.IsEmpty()) {
2102 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2103 FXSYS_assert(pThisNode);
2104 CXFA_WidgetData widgetData(pThisNode);
2105 pLocale = widgetData.GetLocal();
2106 } else {
2107 pLocale = pMgr->GetLocaleByName(
2108 CFX_WideString::FromUTF8(szLocale.GetCStr(), szLocale.GetLength()));
2109 }
2110 if (!pLocale) {
2111 return FALSE;
2112 }
2113 CFX_WideString wsFormat;
2114 if (szFormat.IsEmpty()) {
2115 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2116 } else {
2117 wsFormat =
2118 CFX_WideString::FromUTF8(szFormat.GetCStr(), szFormat.GetLength());
2119 }
2120 CXFA_LocaleValue widgetValue(
2121 XFA_VT_DATE,
2122 CFX_WideString::FromUTF8(szDate.GetCStr(), szDate.GetLength()),
2123 (CXFA_LocaleMgr*)pMgr);
2124 CFX_WideString wsRet;
2125 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale,
2126 XFA_VALUEPICTURE_Display);
2127 strLocalDate = FX_UTF8Encode(wsRet, wsRet.GetLength());
2128 return TRUE;
2129 }
2130 FX_BOOL CXFA_FM2JSContext::IsoTime2Local(FXJSE_HOBJECT hThis,
2131 const CFX_ByteStringC& szTime,
2132 const CFX_ByteStringC& szFormat,
2133 const CFX_ByteStringC& szLocale,
2134 CFX_ByteString& strLocalTime) {
2135 CXFA_FM2JSContext* pContext =
2136 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2137 CXFA_Document* pDoc = pContext->GetDocument();
2138 if (!pDoc) {
2139 return FALSE;
2140 }
2141 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
2142 IFX_Locale* pLocale = NULL;
2143 if (szLocale.IsEmpty()) {
2144 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2145 FXSYS_assert(pThisNode);
2146 CXFA_WidgetData widgetData(pThisNode);
2147 pLocale = widgetData.GetLocal();
2148 } else {
2149 pLocale = pMgr->GetLocaleByName(
2150 CFX_WideString::FromUTF8(szLocale.GetCStr(), szLocale.GetLength()));
2151 }
2152 if (!pLocale) {
2153 return FALSE;
2154 }
2155 CFX_WideString wsFormat;
2156 if (szFormat.IsEmpty()) {
2157 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2158 } else {
2159 wsFormat =
2160 CFX_WideString::FromUTF8(szFormat.GetCStr(), szFormat.GetLength());
2161 }
2162 wsFormat = FX_WSTRC(L"time{") + wsFormat;
2163 wsFormat += FX_WSTRC(L"}");
2164 CXFA_LocaleValue widgetValue(
2165 XFA_VT_TIME,
2166 CFX_WideString::FromUTF8(szTime.GetCStr(), szTime.GetLength()),
2167 (CXFA_LocaleMgr*)pMgr);
2168 CFX_WideString wsRet;
2169 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale,
2170 XFA_VALUEPICTURE_Display);
2171 strLocalTime = FX_UTF8Encode(wsRet, wsRet.GetLength());
2172 return TRUE;
2173 }
2174 FX_BOOL CXFA_FM2JSContext::GetGMTTime(FXJSE_HOBJECT hThis,
2175 const CFX_ByteStringC& szTime,
2176 const CFX_ByteStringC& szFormat,
2177 const CFX_ByteStringC& szLocale,
2178 CFX_ByteString& strGMTTime) {
2179 CXFA_FM2JSContext* pContext =
2180 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2181 CXFA_Document* pDoc = pContext->GetDocument();
2182 if (!pDoc) {
2183 return FALSE;
2184 }
2185 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
2186 IFX_Locale* pLocale = NULL;
2187 if (szLocale.IsEmpty()) {
2188 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2189 FXSYS_assert(pThisNode);
2190 CXFA_WidgetData widgetData(pThisNode);
2191 pLocale = widgetData.GetLocal();
2192 } else {
2193 pLocale = pMgr->GetLocaleByName(
2194 CFX_WideString::FromUTF8(szLocale.GetCStr(), szLocale.GetLength()));
2195 }
2196 if (!pLocale) {
2197 return FALSE;
2198 }
2199 CFX_WideString wsFormat;
2200 if (szFormat.IsEmpty()) {
2201 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2202 } else {
2203 wsFormat =
2204 CFX_WideString::FromUTF8(szFormat.GetCStr(), szFormat.GetLength());
2205 }
2206 wsFormat = FX_WSTRC(L"time{") + wsFormat;
2207 wsFormat += FX_WSTRC(L"}");
2208 CXFA_LocaleValue widgetValue(
2209 XFA_VT_TIME,
2210 CFX_WideString::FromUTF8(szTime.GetCStr(), szTime.GetLength()),
2211 (CXFA_LocaleMgr*)pMgr);
2212 CFX_WideString wsRet;
2213 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale,
2214 XFA_VALUEPICTURE_Display);
2215 strGMTTime = FX_UTF8Encode(wsRet, wsRet.GetLength());
2216 return TRUE;
2217 }
2218 int32_t CXFA_FM2JSContext::DateString2Num(const CFX_ByteStringC& szDateString) {
2219 FX_BOOL bFlags = FALSE;
2220 int32_t iLength = szDateString.GetLength();
2221 FX_BOOL iRet = FALSE;
2222 int32_t iStyle = -1;
2223 int32_t iYear = 0;
2224 int32_t iMonth = 0;
2225 int32_t iDay = 0;
2226 int32_t iHour = 0;
2227 int32_t iMinute = 0;
2228 int32_t iSecond = 0;
2229 int32_t iMillionSecond = 0;
2230 int32_t iZoneHour = 0;
2231 int32_t iZoneMinute = 0;
2232 if (iLength <= 10) {
2233 iRet = IsIsoDateFormat(szDateString.GetCStr(), iLength, iStyle, iYear,
2234 iMonth, iDay);
2235 } else {
2236 iRet = IsIsoDateTimeFormat(szDateString.GetCStr(), iLength, iYear, iMonth,
2237 iDay, iHour, iMinute, iSecond, iMillionSecond,
2238 iZoneHour, iZoneMinute);
2239 }
2240 if (!iRet) {
2241 bFlags = TRUE;
2242 }
2243 FX_FLOAT dDays = 0;
2244 int32_t i = 1;
2245 if (iYear < 1900) {
2246 bFlags = TRUE;
2247 }
2248 if (!bFlags) {
2249 while (iYear - i >= 1900) {
2250 if ((!((iYear - i) % 4) && ((iYear - i) % 100)) || !((iYear - i) % 400)) {
2251 dDays += 366;
2252 } else {
2253 dDays += 365;
2254 }
2255 ++i;
2256 }
2257 i = 1;
2258 while (i < iMonth) {
2259 if (i == 2) {
2260 if ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) {
2261 dDays += 29;
2262 } else {
2263 dDays += 28;
2264 }
2265 } else if (i <= 7) {
2266 if (i % 2 == 0) {
2267 dDays += 30;
2268 } else {
2269 dDays += 31;
2270 }
2271 } else {
2272 if (i % 2 == 0) {
2273 dDays += 31;
2274 } else {
2275 dDays += 30;
2276 }
2277 }
2278 ++i;
2279 }
2280 i = 0;
2281 while (iDay - i > 0) {
2282 dDays += 1;
2283 ++i;
2284 }
2285 } else {
2286 dDays = 0;
2287 }
2288 return (int32_t)dDays;
2289 }
2290 #define XFA_N 19
2291 static uint8_t g_sAltTable_Date[] = {
2292 XFA_N, XFA_N, XFA_N, 3, 9, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N,
2293 XFA_N, 2, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N,
2294 XFA_N, XFA_N, 1, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N,
2295 XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N,
2296 XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N,
2297 XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N,
2298 };
2299 static uint8_t g_sAltTable_Time[] = {
2300 14, XFA_N, XFA_N, 3, 9, XFA_N, XFA_N, 15, XFA_N, XFA_N, XFA_N,
2301 XFA_N, 6, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, 7, XFA_N, XFA_N, XFA_N,
2302 XFA_N, XFA_N, 1, 17, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N,
2303 XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, 15, XFA_N, XFA_N, XFA_N, XFA_N,
2304 XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N,
2305 XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N, XFA_N,
2306 };
2307 static void XFA_FM_AlternateDateTimeSymbols(CFX_WideString& wsPattern,
2308 const CFX_WideString& wsAltSymbols,
2309 uint8_t* pAltTable) {
2310 int32_t nLength = wsPattern.GetLength();
2311 FX_BOOL bInConstRange = FALSE;
2312 FX_BOOL bEscape = FALSE;
2313 int32_t i = 0, n = 0;
2314 while (i < nLength) {
2315 FX_WCHAR wc = wsPattern[i];
2316 if (wc == L'\'') {
2317 bInConstRange = !bInConstRange;
2318 if (bEscape) {
2319 i++;
2320 } else {
2321 wsPattern.Delete(i);
2322 nLength--;
2323 }
2324 bEscape = !bEscape;
2325 continue;
2326 }
2327 if (!bInConstRange && (n = wc - L'A') >= 0 && n <= (L'a' - L'A')) {
2328 int32_t nAlt = (int32_t)pAltTable[n];
2329 if (nAlt != XFA_N) {
2330 wsPattern.SetAt(i, wsAltSymbols[nAlt]);
2331 }
2332 }
2333 i++;
2334 bEscape = FALSE;
2335 }
2336 }
2337 #undef XFA_N
2338 void CXFA_FM2JSContext::GetLocalDateFormat(FXJSE_HOBJECT hThis,
2339 int32_t iStyle,
2340 const CFX_ByteStringC& szLocalStr,
2341 CFX_ByteString& strFormat,
2342 FX_BOOL bStandard) {
2343 FX_LOCALEDATETIMESUBCATEGORY strStyle;
2344 switch (iStyle) {
2345 case 0:
2346 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2347 break;
2348 case 1:
2349 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short;
2350 break;
2351 case 2:
2352 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2353 break;
2354 case 3:
2355 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long;
2356 break;
2357 case 4:
2358 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full;
2359 break;
2360 default:
2361 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2362 break;
2363 }
2364 CXFA_FM2JSContext* pContext =
2365 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2366 CXFA_Document* pDoc = pContext->GetDocument();
2367 if (!pDoc) {
2368 return;
2369 }
2370 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
2371 IFX_Locale* pLocale = NULL;
2372 if (szLocalStr.IsEmpty()) {
2373 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2374 FXSYS_assert(pThisNode);
2375 CXFA_WidgetData widgetData(pThisNode);
2376 pLocale = widgetData.GetLocal();
2377 } else {
2378 pLocale = pMgr->GetLocaleByName(
2379 CFX_WideString::FromUTF8(szLocalStr.GetCStr(), szLocalStr.GetLength()));
2380 }
2381 if (!pLocale) {
2382 return;
2383 }
2384 CFX_WideString strRet;
2385 pLocale->GetDatePattern(strStyle, strRet);
2386 if (!bStandard) {
2387 CFX_WideString wsSymbols;
2388 pLocale->GetDateTimeSymbols(wsSymbols);
2389 XFA_FM_AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Date);
2390 }
2391 strFormat = FX_UTF8Encode(strRet, strRet.GetLength());
2392 }
2393 void CXFA_FM2JSContext::GetLocalTimeFormat(FXJSE_HOBJECT hThis,
2394 int32_t iStyle,
2395 const CFX_ByteStringC& szLocalStr,
2396 CFX_ByteString& strFormat,
2397 FX_BOOL bStandard) {
2398 FX_LOCALEDATETIMESUBCATEGORY strStyle;
2399 switch (iStyle) {
2400 case 0:
2401 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2402 break;
2403 case 1:
2404 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short;
2405 break;
2406 case 2:
2407 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2408 break;
2409 case 3:
2410 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long;
2411 break;
2412 case 4:
2413 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full;
2414 break;
2415 default:
2416 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2417 break;
2418 }
2419 CXFA_FM2JSContext* pContext =
2420 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2421 CXFA_Document* pDoc = pContext->GetDocument();
2422 if (!pDoc) {
2423 return;
2424 }
2425 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
2426 IFX_Locale* pLocale = NULL;
2427 if (szLocalStr.IsEmpty()) {
2428 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2429 FXSYS_assert(pThisNode);
2430 CXFA_WidgetData widgetData(pThisNode);
2431 pLocale = widgetData.GetLocal();
2432 } else {
2433 pLocale = pMgr->GetLocaleByName(
2434 CFX_WideString::FromUTF8(szLocalStr.GetCStr(), szLocalStr.GetLength()));
2435 }
2436 if (!pLocale) {
2437 return;
2438 }
2439 CFX_WideString strRet;
2440 pLocale->GetTimePattern(strStyle, strRet);
2441 if (!bStandard) {
2442 CFX_WideString wsSymbols;
2443 pLocale->GetDateTimeSymbols(wsSymbols);
2444 XFA_FM_AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Time);
2445 }
2446 strFormat = FX_UTF8Encode(strRet, strRet.GetLength());
2447 }
2448 void CXFA_FM2JSContext::GetStandardDateFormat(FXJSE_HOBJECT hThis,
2449 int32_t iStyle,
2450 const CFX_ByteStringC& szLocalStr,
2451 CFX_ByteString& strFormat) {
2452 GetLocalDateFormat(hThis, iStyle, szLocalStr, strFormat, TRUE);
2453 }
2454 void CXFA_FM2JSContext::GetStandardTimeFormat(FXJSE_HOBJECT hThis,
2455 int32_t iStyle,
2456 const CFX_ByteStringC& szLocalStr,
2457 CFX_ByteString& strFormat) {
2458 GetLocalTimeFormat(hThis, iStyle, szLocalStr, strFormat, TRUE);
2459 }
2460 void CXFA_FM2JSContext::Num2AllTime(FXJSE_HOBJECT hThis,
2461 int32_t iTime,
2462 const CFX_ByteStringC& szFormat,
2463 const CFX_ByteStringC& szLocale,
2464 FX_BOOL bGM,
2465 CFX_ByteString& strTime) {
2466 int32_t iHour = 0;
2467 int32_t iMin = 0;
2468 int32_t iSec = 0;
2469 int32_t iZoneHour = 0;
2470 int32_t iZoneMin = 0;
2471 int32_t iZoneSec = 0;
2472 iHour = static_cast<int>(iTime) / 3600000;
2473 iMin = (static_cast<int>(iTime) - iHour * 3600000) / 60000;
2474 iSec = (static_cast<int>(iTime) - iHour * 3600000 - iMin * 60000) / 1000;
2475 if (!bGM) {
2476 GetLocalTimeZone(iZoneHour, iZoneMin, iZoneSec);
2477 iHour += iZoneHour;
2478 iMin += iZoneMin;
2479 iSec += iZoneSec;
2480 }
2481 int32_t iRet = 0;
2482 CFX_ByteString strIsoTime;
2483 strIsoTime.Format("%02d:%02d:%02d", iHour, iMin, iSec);
2484 if (bGM) {
2485 iRet = GetGMTTime(hThis, strIsoTime, szFormat, szLocale, strTime);
2486 } else {
2487 iRet = IsoTime2Local(hThis, strIsoTime, szFormat, szLocale, strTime);
2488 }
2489 if (!iRet) {
2490 strTime = "";
2491 }
2492 }
2493
2494 void CXFA_FM2JSContext::GetLocalTimeZone(int32_t& iHour,
2495 int32_t& iMin,
2496 int32_t& iSec) {
2497 time_t now;
2498 time(&now);
2499 struct tm* pGmt = gmtime(&now);
2500 int32_t iGMHour = pGmt->tm_hour;
2501 int32_t iGMMin = pGmt->tm_min;
2502 int32_t iGMSec = pGmt->tm_sec;
2503 struct tm* pLocal = localtime(&now);
2504 int32_t iLocalHour = pLocal->tm_hour;
2505 int32_t iLocalMin = pLocal->tm_min;
2506 int32_t iLocalSec = pLocal->tm_sec;
2507 iHour = iLocalHour - iGMHour;
2508 iMin = iLocalMin - iGMMin;
2509 iSec = iLocalSec - iGMSec;
2510 }
2511 void CXFA_FM2JSContext::Apr(FXJSE_HOBJECT hThis,
2512 const CFX_ByteStringC& szFuncName,
2513 CFXJSE_Arguments& args) {
2514 CXFA_FM2JSContext* pContext =
2515 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2516 if (args.GetLength() == 3) {
2517 FX_BOOL bFlags = FALSE;
2518 FX_DOUBLE nPrincipal = 0;
2519 FX_DOUBLE nPayment = 0;
2520 FX_DOUBLE nPeriods = 0;
2521 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
2522 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
2523 FXJSE_HVALUE argThree = GetSimpleHValue(hThis, args, 2);
2524 bFlags = (HValueIsNull(hThis, argOne) || HValueIsNull(hThis, argTwo) ||
2525 HValueIsNull(hThis, argThree));
2526 if (bFlags) {
2527 FXJSE_Value_SetNull(args.GetReturnValue());
2528 } else {
2529 nPrincipal = HValueToDouble(hThis, argOne);
2530 nPayment = HValueToDouble(hThis, argTwo);
2531 nPeriods = HValueToDouble(hThis, argThree);
2532 bFlags = ((nPrincipal <= 0) || (nPayment <= 0) || (nPeriods <= 0));
2533 if (bFlags) {
2534 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
2535 } else {
2536 FX_DOUBLE r =
2537 2 * (nPeriods * nPayment - nPrincipal) / (nPeriods * nPrincipal);
2538 FX_DOUBLE nTemp = 1;
2539 for (int32_t i = 0; i < nPeriods; ++i) {
2540 nTemp *= (1 + r);
2541 }
2542 FX_DOUBLE nRet = r * nTemp / (nTemp - 1) - nPayment / nPrincipal;
2543 while ((nRet > FINANCIAL_PRECISION || nRet < -FINANCIAL_PRECISION) &&
2544 (!bFlags)) {
2545 FX_DOUBLE nDerivative = 0;
2546 nDerivative =
2547 ((nTemp + r * nPeriods * (nTemp / (1 + r))) * (nTemp - 1) -
2548 (r * nTemp * nPeriods * (nTemp / (1 + r)))) /
2549 ((nTemp - 1) * (nTemp - 1));
2550 if (nDerivative == 0) {
2551 bFlags = TRUE;
2552 continue;
2553 }
2554 r = r - nRet / nDerivative;
2555 nTemp = 1;
2556 for (int32_t i = 0; i < nPeriods; ++i) {
2557 nTemp *= (1 + r);
2558 }
2559 nRet = r * nTemp / (nTemp - 1) - nPayment / nPrincipal;
2560 }
2561 if (bFlags) {
2562 FXJSE_Value_SetNull(args.GetReturnValue());
2563 } else {
2564 r = r * 12;
2565 FXJSE_Value_SetDouble(args.GetReturnValue(), r);
2566 }
2567 }
2568 }
2569 FXJSE_Value_Release(argOne);
2570 FXJSE_Value_Release(argTwo);
2571 FXJSE_Value_Release(argThree);
2572 } else {
2573 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
2574 L"Apr");
2575 }
2576 }
2577 void CXFA_FM2JSContext::CTerm(FXJSE_HOBJECT hThis,
2578 const CFX_ByteStringC& szFuncName,
2579 CFXJSE_Arguments& args) {
2580 CXFA_FM2JSContext* pContext =
2581 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2582 if (args.GetLength() == 3) {
2583 FX_BOOL bFlags = FALSE;
2584 FX_FLOAT nRate = 0;
2585 FX_FLOAT nFutureValue = 0;
2586 FX_FLOAT nInitAmount = 0;
2587 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
2588 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
2589 FXJSE_HVALUE argThree = GetSimpleHValue(hThis, args, 2);
2590 bFlags = (HValueIsNull(hThis, argOne) || HValueIsNull(hThis, argTwo) ||
2591 HValueIsNull(hThis, argThree));
2592 if (bFlags) {
2593 FXJSE_Value_SetNull(args.GetReturnValue());
2594 } else {
2595 nRate = HValueToFloat(hThis, argOne);
2596 nFutureValue = HValueToFloat(hThis, argTwo);
2597 nInitAmount = HValueToFloat(hThis, argThree);
2598 bFlags = ((nRate <= 0) || (nFutureValue <= 0) || (nInitAmount <= 0));
2599 if (bFlags) {
2600 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
2601 } else {
2602 FXJSE_Value_SetFloat(args.GetReturnValue(),
2603 FXSYS_log((FX_FLOAT)(nFutureValue / nInitAmount)) /
2604 FXSYS_log((FX_FLOAT)(1 + nRate)));
2605 }
2606 }
2607 FXJSE_Value_Release(argOne);
2608 FXJSE_Value_Release(argTwo);
2609 FXJSE_Value_Release(argThree);
2610 } else {
2611 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
2612 L"CTerm");
2613 }
2614 }
2615 void CXFA_FM2JSContext::FV(FXJSE_HOBJECT hThis,
2616 const CFX_ByteStringC& szFuncName,
2617 CFXJSE_Arguments& args) {
2618 CXFA_FM2JSContext* pContext =
2619 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2620 if (args.GetLength() == 3) {
2621 FX_BOOL bFlags = FALSE;
2622 FX_DOUBLE nAmount = 0;
2623 FX_DOUBLE nRate = 0;
2624 FX_DOUBLE nPeriod = 0;
2625 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
2626 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
2627 FXJSE_HVALUE argThree = GetSimpleHValue(hThis, args, 2);
2628 bFlags = (HValueIsNull(hThis, argOne) || HValueIsNull(hThis, argTwo) ||
2629 HValueIsNull(hThis, argThree));
2630 if (bFlags) {
2631 FXJSE_Value_SetNull(args.GetReturnValue());
2632 } else {
2633 nAmount = HValueToDouble(hThis, argOne);
2634 nRate = HValueToDouble(hThis, argTwo);
2635 nPeriod = HValueToDouble(hThis, argThree);
2636 bFlags = ((nRate < 0) || (nPeriod <= 0) || (nAmount <= 0));
2637 if (bFlags) {
2638 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
2639 } else {
2640 FX_DOUBLE dResult = 0;
2641 if (!nRate) {
2642 dResult = nAmount * nPeriod;
2643 } else {
2644 FX_DOUBLE nTemp = 1;
2645 for (int i = 0; i < nPeriod; ++i) {
2646 nTemp *= 1 + nRate;
2647 }
2648 dResult = nAmount * (nTemp - 1) / nRate;
2649 }
2650 FXJSE_Value_SetDouble(args.GetReturnValue(), dResult);
2651 }
2652 }
2653 FXJSE_Value_Release(argOne);
2654 FXJSE_Value_Release(argTwo);
2655 FXJSE_Value_Release(argThree);
2656 } else {
2657 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
2658 L"FV");
2659 }
2660 }
2661 void CXFA_FM2JSContext::IPmt(FXJSE_HOBJECT hThis,
2662 const CFX_ByteStringC& szFuncName,
2663 CFXJSE_Arguments& args) {
2664 CXFA_FM2JSContext* pContext =
2665 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2666 if (args.GetLength() == 5) {
2667 FX_BOOL bFlags = FALSE;
2668 FX_FLOAT nPrincpalAmount = 0;
2669 FX_FLOAT nRate = 0;
2670 FX_FLOAT nPayment = 0;
2671 FX_FLOAT nFirstMonth = 0;
2672 FX_FLOAT nNumberOfMonths = 0;
2673 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
2674 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
2675 FXJSE_HVALUE argThree = GetSimpleHValue(hThis, args, 2);
2676 FXJSE_HVALUE argFour = GetSimpleHValue(hThis, args, 3);
2677 FXJSE_HVALUE argFive = GetSimpleHValue(hThis, args, 4);
2678 bFlags = (HValueIsNull(hThis, argOne) || HValueIsNull(hThis, argTwo) ||
2679 HValueIsNull(hThis, argThree) || HValueIsNull(hThis, argFour) ||
2680 HValueIsNull(hThis, argFive));
2681 if (bFlags) {
2682 FXJSE_Value_SetNull(args.GetReturnValue());
2683 } else {
2684 nPrincpalAmount = HValueToFloat(hThis, argOne);
2685 nRate = HValueToFloat(hThis, argTwo);
2686 nPayment = HValueToFloat(hThis, argThree);
2687 nFirstMonth = HValueToFloat(hThis, argFour);
2688 nNumberOfMonths = HValueToFloat(hThis, argFive);
2689 bFlags = ((nPrincpalAmount <= 0) || (nRate <= 0) || (nPayment <= 0) ||
2690 (nFirstMonth < 0) || (nNumberOfMonths < 0));
2691 if (bFlags) {
2692 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
2693 } else {
2694 FX_FLOAT fResult = 0;
2695 FX_FLOAT nRateOfMonth = nRate / 12;
2696 int32_t iNums =
2697 (int32_t)((FXSYS_log10((FX_FLOAT)(nPayment / nPrincpalAmount)) -
2698 FXSYS_log10((FX_FLOAT)(nPayment / nPrincpalAmount -
2699 nRateOfMonth))) /
2700 FXSYS_log10((FX_FLOAT)(1 + nRateOfMonth)));
2701 int32_t iEnd = (int32_t)(nFirstMonth + nNumberOfMonths - 1);
2702 if (iEnd > iNums) {
2703 iEnd = iNums;
2704 }
2705 FX_FLOAT nSum = 0;
2706 if (nPayment < nPrincpalAmount * nRateOfMonth) {
2707 bFlags = TRUE;
2708 fResult = 0;
2709 }
2710 if (!bFlags) {
2711 int32_t i = 0;
2712 for (i = 0; i < nFirstMonth - 1; ++i) {
2713 nPrincpalAmount -= nPayment - nPrincpalAmount * nRateOfMonth;
2714 }
2715 for (; i < iEnd; ++i) {
2716 nSum += nPrincpalAmount * nRateOfMonth;
2717 nPrincpalAmount -= nPayment - nPrincpalAmount * nRateOfMonth;
2718 }
2719 fResult = nSum;
2720 }
2721 FXJSE_Value_SetFloat(args.GetReturnValue(), fResult);
2722 }
2723 }
2724 FXJSE_Value_Release(argOne);
2725 FXJSE_Value_Release(argTwo);
2726 FXJSE_Value_Release(argThree);
2727 FXJSE_Value_Release(argFour);
2728 FXJSE_Value_Release(argFive);
2729 } else {
2730 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
2731 L"IPmt");
2732 }
2733 }
2734 void CXFA_FM2JSContext::NPV(FXJSE_HOBJECT hThis,
2735 const CFX_ByteStringC& szFuncName,
2736 CFXJSE_Arguments& args) {
2737 CXFA_FM2JSContext* pContext =
2738 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2739 int32_t argc = args.GetLength();
2740 if (argc > 2) {
2741 FX_BOOL bFlags = FALSE;
2742 FXJSE_HVALUE* argValues = FX_Alloc(FXJSE_HVALUE, argc);
2743 for (int32_t i = 0; i < argc; i++) {
2744 argValues[i] = GetSimpleHValue(hThis, args, i);
2745 if (HValueIsNull(hThis, argValues[i])) {
2746 bFlags = TRUE;
2747 }
2748 }
2749 if (!bFlags) {
2750 FX_DOUBLE nRate = 0;
2751 nRate = HValueToDouble(hThis, argValues[0]);
2752 if (nRate <= 0) {
2753 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
2754 } else {
2755 FX_DOUBLE* pData = FX_Alloc(FX_DOUBLE, argc - 1);
2756 for (int32_t i = 1; i < argc; i++) {
2757 pData[i - 1] = HValueToDouble(hThis, argValues[i]);
2758 }
2759 FX_DOUBLE nSum = 0;
2760 int32_t iIndex = 0;
2761 for (int32_t i = 0; i < argc - 1; i++) {
2762 FX_DOUBLE nTemp = 1;
2763 for (int32_t j = 0; j <= i; j++) {
2764 nTemp *= 1 + nRate;
2765 }
2766 FX_DOUBLE nNum = *(pData + iIndex++);
2767 nSum += nNum / nTemp;
2768 }
2769 FXJSE_Value_SetDouble(args.GetReturnValue(), nSum);
2770 FX_Free(pData);
2771 pData = 0;
2772 }
2773 } else {
2774 FXJSE_Value_SetNull(args.GetReturnValue());
2775 }
2776 for (int32_t i = 0; i < argc; i++) {
2777 FXJSE_Value_Release(argValues[i]);
2778 }
2779 FX_Free(argValues);
2780 } else {
2781 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
2782 L"NPV");
2783 }
2784 }
2785 void CXFA_FM2JSContext::Pmt(FXJSE_HOBJECT hThis,
2786 const CFX_ByteStringC& szFuncName,
2787 CFXJSE_Arguments& args) {
2788 CXFA_FM2JSContext* pContext =
2789 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2790 if (args.GetLength() == 3) {
2791 FX_BOOL bFlags = FALSE;
2792 FX_FLOAT nPrincipal = 0;
2793 FX_FLOAT nRate = 0;
2794 FX_FLOAT nPeriods = 0;
2795 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
2796 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
2797 FXJSE_HVALUE argThree = GetSimpleHValue(hThis, args, 2);
2798 bFlags = (HValueIsNull(hThis, argOne) || HValueIsNull(hThis, argTwo) ||
2799 HValueIsNull(hThis, argThree));
2800 if (bFlags) {
2801 FXJSE_Value_SetNull(args.GetReturnValue());
2802 } else {
2803 nPrincipal = HValueToFloat(hThis, argOne);
2804 nRate = HValueToFloat(hThis, argTwo);
2805 nPeriods = HValueToFloat(hThis, argThree);
2806 bFlags = ((nPrincipal <= 0) || (nRate <= 0) || (nPeriods <= 0));
2807 if (bFlags) {
2808 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
2809 } else {
2810 FX_FLOAT nSum = 0;
2811 FX_FLOAT nTmp = 1 + nRate;
2812 nSum = nTmp;
2813 for (int32_t i = 0; i < nPeriods - 1; ++i) {
2814 nSum *= nTmp;
2815 }
2816 FXJSE_Value_SetFloat(args.GetReturnValue(),
2817 (nPrincipal * nRate * nSum) / (nSum - 1));
2818 }
2819 }
2820 FXJSE_Value_Release(argOne);
2821 FXJSE_Value_Release(argTwo);
2822 FXJSE_Value_Release(argThree);
2823 } else {
2824 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
2825 L"Pmt");
2826 }
2827 }
2828 void CXFA_FM2JSContext::PPmt(FXJSE_HOBJECT hThis,
2829 const CFX_ByteStringC& szFuncName,
2830 CFXJSE_Arguments& args) {
2831 CXFA_FM2JSContext* pContext =
2832 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2833 if (args.GetLength() == 5) {
2834 FX_BOOL bFlags = FALSE;
2835 FX_FLOAT nPrincpalAmount = 0;
2836 FX_FLOAT nRate = 0;
2837 FX_FLOAT nPayment = 0;
2838 FX_FLOAT nFirstMonth = 0;
2839 FX_FLOAT nNumberOfMonths = 0;
2840 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
2841 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
2842 FXJSE_HVALUE argThree = GetSimpleHValue(hThis, args, 2);
2843 FXJSE_HVALUE argFour = GetSimpleHValue(hThis, args, 3);
2844 FXJSE_HVALUE argFive = GetSimpleHValue(hThis, args, 4);
2845 bFlags = (HValueIsNull(hThis, argOne) || HValueIsNull(hThis, argTwo) ||
2846 HValueIsNull(hThis, argThree) || HValueIsNull(hThis, argFour) ||
2847 HValueIsNull(hThis, argFive));
2848 if (bFlags) {
2849 FXJSE_Value_SetNull(args.GetReturnValue());
2850 } else {
2851 nPrincpalAmount = HValueToFloat(hThis, argOne);
2852 nRate = HValueToFloat(hThis, argTwo);
2853 nPayment = HValueToFloat(hThis, argThree);
2854 nFirstMonth = HValueToFloat(hThis, argFour);
2855 nNumberOfMonths = HValueToFloat(hThis, argFive);
2856 bFlags = ((nPrincpalAmount <= 0) || (nRate <= 0) || (nPayment <= 0) ||
2857 (nFirstMonth < 0) || (nNumberOfMonths < 0));
2858 if (bFlags) {
2859 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
2860 } else {
2861 int32_t iEnd = (int32_t)(nFirstMonth + nNumberOfMonths - 1);
2862 FX_FLOAT nSum = 0;
2863 FX_FLOAT nRateOfMonth = nRate / 12;
2864 int32_t iNums =
2865 (int32_t)((FXSYS_log10((FX_FLOAT)(nPayment / nPrincpalAmount)) -
2866 FXSYS_log10((FX_FLOAT)(nPayment / nPrincpalAmount -
2867 nRateOfMonth))) /
2868 FXSYS_log10((FX_FLOAT)(1 + nRateOfMonth)));
2869 if (iEnd > iNums) {
2870 iEnd = iNums;
2871 }
2872 if (nPayment < nPrincpalAmount * nRateOfMonth) {
2873 bFlags = TRUE;
2874 }
2875 if (!bFlags) {
2876 int32_t i = 0;
2877 for (i = 0; i < nFirstMonth - 1; ++i) {
2878 nPrincpalAmount -= nPayment - nPrincpalAmount * nRateOfMonth;
2879 }
2880 FX_FLOAT nTemp = 0;
2881 for (; i < iEnd; ++i) {
2882 nTemp = nPayment - nPrincpalAmount * nRateOfMonth;
2883 nSum += nTemp;
2884 nPrincpalAmount -= nTemp;
2885 }
2886 FXJSE_Value_SetFloat(args.GetReturnValue(), nSum);
2887 } else {
2888 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
2889 }
2890 }
2891 }
2892 FXJSE_Value_Release(argOne);
2893 FXJSE_Value_Release(argTwo);
2894 FXJSE_Value_Release(argThree);
2895 FXJSE_Value_Release(argFour);
2896 FXJSE_Value_Release(argFive);
2897 } else {
2898 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
2899 L"PPmt");
2900 }
2901 }
2902 void CXFA_FM2JSContext::PV(FXJSE_HOBJECT hThis,
2903 const CFX_ByteStringC& szFuncName,
2904 CFXJSE_Arguments& args) {
2905 CXFA_FM2JSContext* pContext =
2906 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2907 if (args.GetLength() == 3) {
2908 FX_BOOL bFlags = FALSE;
2909 FX_DOUBLE nAmount = 0;
2910 FX_DOUBLE nRate = 0;
2911 FX_DOUBLE nPeriod = 0;
2912 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
2913 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
2914 FXJSE_HVALUE argThree = GetSimpleHValue(hThis, args, 2);
2915 bFlags = (HValueIsNull(hThis, argOne) || HValueIsNull(hThis, argTwo) ||
2916 HValueIsNull(hThis, argThree));
2917 if (bFlags) {
2918 FXJSE_Value_SetNull(args.GetReturnValue());
2919 } else {
2920 nAmount = HValueToDouble(hThis, argOne);
2921 nRate = HValueToDouble(hThis, argTwo);
2922 nPeriod = HValueToDouble(hThis, argThree);
2923 bFlags = ((nAmount <= 0) || (nRate < 0) || (nPeriod <= 0));
2924 if (bFlags) {
2925 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
2926 } else {
2927 FX_DOUBLE nTemp = 1;
2928 for (int32_t i = 0; i < nPeriod; ++i) {
2929 nTemp *= 1 + nRate;
2930 }
2931 nTemp = 1 / nTemp;
2932 FXJSE_Value_SetDouble(args.GetReturnValue(),
2933 nAmount * ((1 - nTemp) / nRate));
2934 }
2935 }
2936 FXJSE_Value_Release(argOne);
2937 FXJSE_Value_Release(argTwo);
2938 FXJSE_Value_Release(argThree);
2939 } else {
2940 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
2941 L"PV");
2942 }
2943 }
2944 void CXFA_FM2JSContext::Rate(FXJSE_HOBJECT hThis,
2945 const CFX_ByteStringC& szFuncName,
2946 CFXJSE_Arguments& args) {
2947 CXFA_FM2JSContext* pContext =
2948 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2949 if (args.GetLength() == 3) {
2950 FX_BOOL bFlags = FALSE;
2951 FX_FLOAT nFuture = 0;
2952 FX_FLOAT nPresent = 0;
2953 FX_FLOAT nTotalNumber = 0;
2954 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
2955 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
2956 FXJSE_HVALUE argThree = GetSimpleHValue(hThis, args, 2);
2957 bFlags = (HValueIsNull(hThis, argOne) || HValueIsNull(hThis, argTwo) ||
2958 HValueIsNull(hThis, argThree));
2959 if (bFlags) {
2960 FXJSE_Value_SetNull(args.GetReturnValue());
2961 } else {
2962 nFuture = HValueToFloat(hThis, argOne);
2963 nPresent = HValueToFloat(hThis, argTwo);
2964 nTotalNumber = HValueToFloat(hThis, argThree);
2965 bFlags = ((nFuture <= 0) || (nPresent < 0) || (nTotalNumber <= 0));
2966 if (bFlags) {
2967 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
2968 } else {
2969 FXJSE_Value_SetFloat(args.GetReturnValue(),
2970 (FXSYS_pow((FX_FLOAT)(nFuture / nPresent),
2971 (FX_FLOAT)(1 / nTotalNumber)) -
2972 1));
2973 }
2974 }
2975 FXJSE_Value_Release(argOne);
2976 FXJSE_Value_Release(argTwo);
2977 FXJSE_Value_Release(argThree);
2978 } else {
2979 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
2980 L"Rate");
2981 }
2982 }
2983 void CXFA_FM2JSContext::Term(FXJSE_HOBJECT hThis,
2984 const CFX_ByteStringC& szFuncName,
2985 CFXJSE_Arguments& args) {
2986 CXFA_FM2JSContext* pContext =
2987 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
2988 if (args.GetLength() == 3) {
2989 FX_BOOL bFlags = FALSE;
2990 FX_FLOAT nMount = 0;
2991 FX_FLOAT nRate = 0;
2992 FX_FLOAT nFuture = 0;
2993 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
2994 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
2995 FXJSE_HVALUE argThree = GetSimpleHValue(hThis, args, 2);
2996 bFlags = (FXJSE_Value_IsNull(argOne) || FXJSE_Value_IsNull(argTwo) ||
2997 FXJSE_Value_IsNull(argThree));
2998 if (bFlags) {
2999 FXJSE_Value_SetNull(args.GetReturnValue());
3000 } else {
3001 nMount = HValueToFloat(hThis, argOne);
3002 nRate = HValueToFloat(hThis, argTwo);
3003 nFuture = HValueToFloat(hThis, argThree);
3004 bFlags = ((nMount <= 0) || (nRate <= 0) || (nFuture <= 0));
3005 if (bFlags) {
3006 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
3007 } else {
3008 FXJSE_Value_SetFloat(
3009 args.GetReturnValue(),
3010 (FXSYS_log((FX_FLOAT)(nFuture / nMount * nRate) + 1) /
3011 FXSYS_log((FX_FLOAT)(1 + nRate))));
3012 }
3013 }
3014 FXJSE_Value_Release(argOne);
3015 FXJSE_Value_Release(argTwo);
3016 FXJSE_Value_Release(argThree);
3017 } else {
3018 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3019 L"Term");
3020 }
3021 }
3022 void CXFA_FM2JSContext::Choose(FXJSE_HOBJECT hThis,
3023 const CFX_ByteStringC& szFuncName,
3024 CFXJSE_Arguments& args) {
3025 CXFA_FM2JSContext* pContext =
3026 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3027 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
3028 int32_t argc = args.GetLength();
3029 if (argc > 1) {
3030 FXJSE_HVALUE argOne = args.GetValue(0);
3031 FX_BOOL argOneIsNull = FALSE;
3032 int32_t iIndex = 0;
3033 argOneIsNull = HValueIsNull(hThis, argOne);
3034 if (!argOneIsNull) {
3035 iIndex = (int32_t)HValueToFloat(hThis, argOne);
3036 }
3037 FXJSE_Value_Release(argOne);
3038 if (argOneIsNull) {
3039 FXJSE_Value_SetNull(args.GetReturnValue());
3040 } else if (iIndex < 1) {
3041 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "");
3042 } else {
3043 FX_BOOL bFound = FALSE;
3044 FX_BOOL bStopCounterFlags = FALSE;
3045 int32_t iArgIndex = 1;
3046 int32_t iValueIndex = 0;
3047 while (!bFound && !bStopCounterFlags && (iArgIndex < argc)) {
3048 FXJSE_HVALUE argIndexValue = args.GetValue(iArgIndex);
3049 if (FXJSE_Value_IsArray(argIndexValue)) {
3050 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
3051 FXJSE_Value_GetObjectProp(argIndexValue, "length", lengthValue);
3052 int32_t iLength = FXJSE_Value_ToInteger(lengthValue);
3053 FXJSE_Value_Release(lengthValue);
3054 if (iLength > 3) {
3055 bStopCounterFlags = TRUE;
3056 }
3057 iValueIndex += (iLength - 2);
3058 if (iValueIndex >= iIndex) {
3059 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
3060 FXJSE_HVALUE jsobjectValue = FXJSE_Value_Create(hruntime);
3061 FXJSE_HVALUE newProperty = FXJSE_Value_Create(hruntime);
3062 FXJSE_Value_GetObjectPropByIdx(argIndexValue, 1, propertyValue);
3063 FXJSE_Value_GetObjectPropByIdx(
3064 argIndexValue, ((iLength - 1) - (iValueIndex - iIndex)),
3065 jsobjectValue);
3066 if (FXJSE_Value_IsNull(propertyValue)) {
3067 GetObjectDefaultValue(jsobjectValue, newProperty);
3068 } else {
3069 CFX_ByteString propStr;
3070 FXJSE_Value_ToUTF8String(propertyValue, propStr);
3071 FXJSE_Value_GetObjectProp(jsobjectValue, propStr, newProperty);
3072 }
3073 CFX_ByteString bsChoosed;
3074 HValueToUTF8String(newProperty, bsChoosed);
3075 FXJSE_Value_SetUTF8String(args.GetReturnValue(), bsChoosed);
3076 FXJSE_Value_Release(newProperty);
3077 FXJSE_Value_Release(jsobjectValue);
3078 FXJSE_Value_Release(propertyValue);
3079 bFound = TRUE;
3080 }
3081 } else {
3082 iValueIndex++;
3083 if (iValueIndex == iIndex) {
3084 CFX_ByteString bsChoosed;
3085 HValueToUTF8String(argIndexValue, bsChoosed);
3086 FXJSE_Value_SetUTF8String(args.GetReturnValue(), bsChoosed);
3087 bFound = TRUE;
3088 }
3089 }
3090 FXJSE_Value_Release(argIndexValue);
3091 iArgIndex++;
3092 }
3093 if (!bFound) {
3094 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "");
3095 }
3096 }
3097 } else {
3098 CXFA_FM2JSContext* pContext =
3099 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3100 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3101 L"Choose");
3102 }
3103 }
3104 void CXFA_FM2JSContext::Exists(FXJSE_HOBJECT hThis,
3105 const CFX_ByteStringC& szFuncName,
3106 CFXJSE_Arguments& args) {
3107 if (args.GetLength() == 1) {
3108 FXJSE_HVALUE argOne = args.GetValue(0);
3109 FXJSE_Value_SetInteger(args.GetReturnValue(), FXJSE_Value_IsObject(argOne));
3110 FXJSE_Value_Release(argOne);
3111 } else {
3112 CXFA_FM2JSContext* pContext =
3113 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3114 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3115 L"Exists");
3116 }
3117 }
3118 void CXFA_FM2JSContext::HasValue(FXJSE_HOBJECT hThis,
3119 const CFX_ByteStringC& szFuncName,
3120 CFXJSE_Arguments& args) {
3121 if (args.GetLength() == 1) {
3122 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
3123 if (FXJSE_Value_IsUTF8String(argOne)) {
3124 CFX_ByteString valueStr;
3125 FXJSE_Value_ToUTF8String(argOne, valueStr);
3126 valueStr.TrimLeft();
3127 FXJSE_Value_SetInteger(args.GetReturnValue(), (!valueStr.IsEmpty()));
3128 } else if (FXJSE_Value_IsNumber(argOne) || FXJSE_Value_IsBoolean(argOne)) {
3129 FXJSE_Value_SetInteger(args.GetReturnValue(), TRUE);
3130 } else {
3131 FXJSE_Value_SetInteger(args.GetReturnValue(), FALSE);
3132 }
3133 FXJSE_Value_Release(argOne);
3134 } else {
3135 CXFA_FM2JSContext* pContext =
3136 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3137 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3138 L"HasValue");
3139 }
3140 }
3141 void CXFA_FM2JSContext::Oneof(FXJSE_HOBJECT hThis,
3142 const CFX_ByteStringC& szFuncName,
3143 CFXJSE_Arguments& args) {
3144 int32_t argc = args.GetLength();
3145 if (argc > 1) {
3146 FX_BOOL bFlags = FALSE;
3147 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
3148 FXJSE_HVALUE* parametersValue = 0;
3149 int32_t iCount = 0;
3150 unfoldArgs(hThis, args, parametersValue, iCount, 1);
3151 for (int32_t i = 0; i < iCount; i++) {
3152 if (simpleValueCompare(hThis, argOne, parametersValue[i])) {
3153 bFlags = TRUE;
3154 break;
3155 }
3156 }
3157 FXJSE_Value_SetInteger(args.GetReturnValue(), bFlags);
3158 FXJSE_Value_Release(argOne);
3159 for (int32_t i = 0; i < iCount; i++) {
3160 FXJSE_Value_Release(parametersValue[i]);
3161 }
3162 FX_Free(parametersValue);
3163 parametersValue = 0;
3164 } else {
3165 CXFA_FM2JSContext* pContext =
3166 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3167 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3168 L"Oneof");
3169 }
3170 }
3171 void CXFA_FM2JSContext::Within(FXJSE_HOBJECT hThis,
3172 const CFX_ByteStringC& szFuncName,
3173 CFXJSE_Arguments& args) {
3174 int32_t argc = args.GetLength();
3175 if (argc == 3) {
3176 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
3177 if (FXJSE_Value_IsNull(argOne)) {
3178 FXJSE_Value_SetUndefined(args.GetReturnValue());
3179 } else {
3180 FXJSE_HVALUE argLow = GetSimpleHValue(hThis, args, 1);
3181 FXJSE_HVALUE argHeight = GetSimpleHValue(hThis, args, 2);
3182 if (FXJSE_Value_IsNumber(argOne)) {
3183 FX_FLOAT oneNumber = HValueToFloat(hThis, argOne);
3184 FX_FLOAT lowNumber = HValueToFloat(hThis, argLow);
3185 FX_FLOAT heightNumber = HValueToFloat(hThis, argHeight);
3186 FXJSE_Value_SetInteger(
3187 args.GetReturnValue(),
3188 ((oneNumber >= lowNumber) && (oneNumber <= heightNumber)));
3189 } else {
3190 CFX_ByteString oneString;
3191 CFX_ByteString lowString;
3192 CFX_ByteString heightString;
3193 HValueToUTF8String(argOne, oneString);
3194 HValueToUTF8String(argLow, lowString);
3195 HValueToUTF8String(argHeight, heightString);
3196 FXJSE_Value_SetInteger(args.GetReturnValue(),
3197 ((oneString.Compare(lowString) >= 0) &&
3198 (oneString.Compare(heightString) <= 0)));
3199 }
3200 FXJSE_Value_Release(argLow);
3201 FXJSE_Value_Release(argHeight);
3202 }
3203 FXJSE_Value_Release(argOne);
3204 } else {
3205 CXFA_FM2JSContext* pContext =
3206 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3207 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3208 L"Within");
3209 }
3210 }
3211 void CXFA_FM2JSContext::If(FXJSE_HOBJECT hThis,
3212 const CFX_ByteStringC& szFuncName,
3213 CFXJSE_Arguments& args) {
3214 if (args.GetLength() == 3) {
3215 FXJSE_HVALUE argCondition = GetSimpleHValue(hThis, args, 0);
3216 FXJSE_HVALUE argFirstValue = GetSimpleHValue(hThis, args, 1);
3217 FXJSE_HVALUE argSecondValue = GetSimpleHValue(hThis, args, 2);
3218 FX_BOOL bCondition = FXJSE_Value_ToBoolean(argCondition);
3219 FXJSE_Value_Set(args.GetReturnValue(),
3220 bCondition ? argFirstValue : argSecondValue);
3221 FXJSE_Value_Release(argSecondValue);
3222 FXJSE_Value_Release(argFirstValue);
3223 FXJSE_Value_Release(argCondition);
3224 } else {
3225 CXFA_FM2JSContext* pContext =
3226 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3227 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3228 L"If");
3229 }
3230 }
3231 void CXFA_FM2JSContext::Eval(FXJSE_HOBJECT hThis,
3232 const CFX_ByteStringC& szFuncName,
3233 CFXJSE_Arguments& args) {
3234 CXFA_FM2JSContext* pContext =
3235 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3236 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
3237 if (args.GetLength() == 1) {
3238 FXJSE_HVALUE scriptValue = GetSimpleHValue(hThis, args, 0);
3239 CFX_ByteString utf8ScriptString;
3240 HValueToUTF8String(scriptValue, utf8ScriptString);
3241 if (utf8ScriptString.IsEmpty()) {
3242 FXJSE_Value_SetNull(args.GetReturnValue());
3243 } else {
3244 CFX_WideTextBuf wsJavaScriptBuf;
3245 CFX_WideString javaScript;
3246 CFX_WideString wsError;
3247 XFA_FM2JS_Translate(CFX_WideString::FromUTF8(
3248 utf8ScriptString, utf8ScriptString.GetLength()),
3249 wsJavaScriptBuf, wsError);
3250 FXJSE_HCONTEXT hContext = FXJSE_Context_Create(hruntime);
3251 FXJSE_HVALUE returnValue = FXJSE_Value_Create(hruntime);
3252 javaScript = wsJavaScriptBuf.GetWideString();
3253 FXJSE_ExecuteScript(hContext,
3254 FX_UTF8Encode(javaScript, javaScript.GetLength()),
3255 returnValue);
3256 FXJSE_Value_Set(args.GetReturnValue(), returnValue);
3257 FXJSE_Value_Release(returnValue);
3258 FXJSE_Context_Release(hContext);
3259 }
3260 FXJSE_Value_Release(scriptValue);
3261 } else {
3262 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3263 L"Eval");
3264 }
3265 }
3266 void CXFA_FM2JSContext::Ref(FXJSE_HOBJECT hThis,
3267 const CFX_ByteStringC& szFuncName,
3268 CFXJSE_Arguments& args) {
3269 CXFA_FM2JSContext* pContext =
3270 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3271 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
3272 if (args.GetLength() == 1) {
3273 FXJSE_HVALUE argOne = args.GetValue(0);
3274 if (FXJSE_Value_IsNull(argOne)) {
3275 FXJSE_HVALUE rgValues[3];
3276 for (int32_t i = 0; i < 3; i++) {
3277 rgValues[i] = FXJSE_Value_Create(hruntime);
3278 }
3279 FXJSE_Value_SetInteger(rgValues[0], 4);
3280 FXJSE_Value_SetNull(rgValues[1]);
3281 FXJSE_Value_SetNull(rgValues[2]);
3282 FXJSE_Value_SetArray(args.GetReturnValue(), 3, rgValues);
3283 for (int32_t i = 0; i < 3; i++) {
3284 FXJSE_Value_Release(rgValues[i]);
3285 }
3286 } else if (FXJSE_Value_IsArray(argOne)) {
3287 #ifndef NDEBUG
3288 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
3289 FXJSE_Value_GetObjectProp(argOne, "length", lengthValue);
3290 FXSYS_assert(FXJSE_Value_ToInteger(lengthValue) >= 3);
3291 FXJSE_Value_Release(lengthValue);
3292 #endif
3293 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
3294 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
3295 FXJSE_Value_GetObjectPropByIdx(argOne, 1, propertyValue);
3296 FXJSE_Value_GetObjectPropByIdx(argOne, 2, jsObjectValue);
3297 if (FXJSE_Value_IsNull(jsObjectValue)) {
3298 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
3299 } else if (FXJSE_Value_IsNull(propertyValue) &&
3300 (!FXJSE_Value_IsNull(jsObjectValue))) {
3301 FXJSE_HVALUE rgValues[3];
3302 for (int32_t i = 0; i < 3; i++) {
3303 rgValues[i] = FXJSE_Value_Create(hruntime);
3304 }
3305 FXJSE_Value_SetInteger(rgValues[0], 3);
3306 FXJSE_Value_SetNull(rgValues[1]);
3307 FXJSE_Value_Set(rgValues[2], jsObjectValue);
3308 FXJSE_Value_SetArray(args.GetReturnValue(), 3, rgValues);
3309 for (int32_t i = 0; i < 3; i++) {
3310 FXJSE_Value_Release(rgValues[i]);
3311 }
3312 } else {
3313 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
3314 }
3315 FXJSE_Value_Release(jsObjectValue);
3316 FXJSE_Value_Release(propertyValue);
3317 } else if (FXJSE_Value_IsObject(argOne)) {
3318 FXJSE_HVALUE rgValues[3];
3319 for (int32_t i = 0; i < 3; i++) {
3320 rgValues[i] = FXJSE_Value_Create(hruntime);
3321 }
3322 FXJSE_Value_SetInteger(rgValues[0], 3);
3323 FXJSE_Value_SetNull(rgValues[1]);
3324 FXJSE_Value_Set(rgValues[2], argOne);
3325 FXJSE_Value_SetArray(args.GetReturnValue(), 3, rgValues);
3326 for (int32_t i = 0; i < 3; i++) {
3327 FXJSE_Value_Release(rgValues[i]);
3328 }
3329 } else if (FXJSE_Value_IsBoolean(argOne) ||
3330 FXJSE_Value_IsUTF8String(argOne) ||
3331 FXJSE_Value_IsNumber(argOne)) {
3332 FXJSE_Value_Set(args.GetReturnValue(), argOne);
3333 } else {
3334 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
3335 }
3336 FXJSE_Value_Release(argOne);
3337 } else {
3338 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3339 L"Ref");
3340 }
3341 }
3342 void CXFA_FM2JSContext::UnitType(FXJSE_HOBJECT hThis,
3343 const CFX_ByteStringC& szFuncName,
3344 CFXJSE_Arguments& args) {
3345 if (args.GetLength() == 1) {
3346 FXJSE_HVALUE unitspanValue = GetSimpleHValue(hThis, args, 0);
3347 if (FXJSE_Value_IsNull(unitspanValue)) {
3348 FXJSE_Value_SetNull(args.GetReturnValue());
3349 FXJSE_Value_Release(unitspanValue);
3350 return;
3351 }
3352 CFX_ByteString unitspanString;
3353 HValueToUTF8String(unitspanValue, unitspanString);
3354 if (unitspanString.IsEmpty()) {
3355 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "in");
3356 } else {
3357 enum XFA_FM2JS_VALUETYPE_ParserStatus {
3358 VALUETYPE_START,
3359 VALUETYPE_HAVEINVALIDCHAR,
3360 VALUETYPE_HAVEDIGIT,
3361 VALUETYPE_HAVEDIGITWHITE,
3362 VALUETYPE_ISCM,
3363 VALUETYPE_ISMM,
3364 VALUETYPE_ISPT,
3365 VALUETYPE_ISMP,
3366 VALUETYPE_ISIN,
3367 };
3368 unitspanString.MakeLower();
3369 CFX_WideString wsTypeString =
3370 CFX_WideString::FromUTF8(unitspanString, unitspanString.GetLength());
3371 const FX_WCHAR* pData = wsTypeString;
3372 int32_t u = 0;
3373 int32_t uLen = wsTypeString.GetLength();
3374 while (*(pData + u) == 0x20 || *(pData + u) == 0x09 ||
3375 *(pData + u) == 0x0B || *(pData + u) == 0x0C ||
3376 *(pData + u) == 0x0A || *(pData + u) == 0x0D) {
3377 u++;
3378 }
3379 XFA_FM2JS_VALUETYPE_ParserStatus eParserStatus = VALUETYPE_START;
3380 FX_WCHAR typeChar;
3381 while (u < uLen) {
3382 typeChar = *(pData + u);
3383 if (typeChar == 0x20 || typeChar == 0x09 || typeChar == 0x0B ||
3384 typeChar == 0x0C || typeChar == 0x0A || typeChar == 0x0D) {
3385 if (eParserStatus == VALUETYPE_HAVEDIGIT ||
3386 eParserStatus == VALUETYPE_HAVEDIGITWHITE) {
3387 eParserStatus = VALUETYPE_HAVEDIGITWHITE;
3388 } else {
3389 eParserStatus = VALUETYPE_ISIN;
3390 break;
3391 }
3392 } else if ((typeChar >= '0' && typeChar <= '9') || typeChar == '-' ||
3393 typeChar == '.') {
3394 if (eParserStatus == VALUETYPE_HAVEDIGITWHITE) {
3395 eParserStatus = VALUETYPE_ISIN;
3396 break;
3397 } else {
3398 eParserStatus = VALUETYPE_HAVEDIGIT;
3399 }
3400 } else if ((typeChar == 'c' || typeChar == 'p') && (u + 1 < uLen)) {
3401 FX_WCHAR nextChar = *(pData + u + 1);
3402 if ((eParserStatus == VALUETYPE_START ||
3403 eParserStatus == VALUETYPE_HAVEDIGIT ||
3404 eParserStatus == VALUETYPE_HAVEDIGITWHITE) &&
3405 (nextChar > '9' || nextChar < '0') && nextChar != '.' &&
3406 nextChar != '-') {
3407 eParserStatus = (typeChar == 'c') ? VALUETYPE_ISCM : VALUETYPE_ISPT;
3408 break;
3409 } else {
3410 eParserStatus = VALUETYPE_HAVEINVALIDCHAR;
3411 }
3412 } else if (typeChar == 'm' && (u + 1 < uLen)) {
3413 FX_WCHAR nextChar = *(pData + u + 1);
3414 if ((eParserStatus == VALUETYPE_START ||
3415 eParserStatus == VALUETYPE_HAVEDIGIT ||
3416 eParserStatus == VALUETYPE_HAVEDIGITWHITE) &&
3417 (nextChar > '9' || nextChar < '0') && nextChar != '.' &&
3418 nextChar != '-') {
3419 eParserStatus = VALUETYPE_ISMM;
3420 if (nextChar == 'p' ||
3421 ((u + 5 < uLen) && *(pData + u + 1) == 'i' &&
3422 *(pData + u + 2) == 'l' && *(pData + u + 3) == 'l' &&
3423 *(pData + u + 4) == 'i' && *(pData + u + 5) == 'p')) {
3424 eParserStatus = VALUETYPE_ISMP;
3425 }
3426 break;
3427 }
3428 } else {
3429 eParserStatus = VALUETYPE_HAVEINVALIDCHAR;
3430 }
3431 u++;
3432 }
3433 switch (eParserStatus) {
3434 case VALUETYPE_ISCM:
3435 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "cm");
3436 break;
3437 case VALUETYPE_ISMM:
3438 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "mm");
3439 break;
3440 case VALUETYPE_ISPT:
3441 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "pt");
3442 break;
3443 case VALUETYPE_ISMP:
3444 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "mp");
3445 break;
3446 default:
3447 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "in");
3448 break;
3449 }
3450 }
3451 FXJSE_Value_Release(unitspanValue);
3452 } else {
3453 CXFA_FM2JSContext* pContext =
3454 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3455 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3456 L"UnitType");
3457 }
3458 }
3459 void CXFA_FM2JSContext::UnitValue(FXJSE_HOBJECT hThis,
3460 const CFX_ByteStringC& szFuncName,
3461 CFXJSE_Arguments& args) {
3462 int32_t argc = args.GetLength();
3463 if ((argc == 1) || (argc == 2)) {
3464 FXJSE_HVALUE unitspanValue = GetSimpleHValue(hThis, args, 0);
3465 FXJSE_HVALUE unitValue = 0;
3466 CFX_ByteString unitspanString;
3467 FX_DOUBLE dFirstNumber = 0;
3468 CFX_ByteString strFirstUnit;
3469 CFX_ByteString strUnit;
3470 if (FXJSE_Value_IsNull(unitspanValue)) {
3471 FXJSE_Value_SetNull(args.GetReturnValue());
3472 } else {
3473 HValueToUTF8String(unitspanValue, unitspanString);
3474 const FX_CHAR* pData = unitspanString;
3475 if (pData) {
3476 int32_t u = 0;
3477 while (*(pData + u) == 0x20 || *(pData + u) == 0x09 ||
3478 *(pData + u) == 0x0B || *(pData + u) == 0x0C ||
3479 *(pData + u) == 0x0A || *(pData + u) == 0x0D) {
3480 ++u;
3481 }
3482 while (u < unitspanString.GetLength()) {
3483 if ((*(pData + u) > '9' || *(pData + u) < '0') &&
3484 *(pData + u) != '.' && *(pData + u) != '-') {
3485 break;
3486 }
3487 ++u;
3488 }
3489 FX_CHAR* pTemp = NULL;
3490 dFirstNumber = strtod(pData, &pTemp);
3491 while (*(pData + u) == ' ' || *(pData + u) == 0x09 ||
3492 *(pData + u) == 0x0B || *(pData + u) == 0x0C ||
3493 *(pData + u) == 0x0A || *(pData + u) == 0x0D) {
3494 ++u;
3495 }
3496 int32_t uLen = unitspanString.GetLength();
3497 while (u < uLen) {
3498 if (*(pData + u) == ' ') {
3499 break;
3500 }
3501 strFirstUnit += (*(pData + u));
3502 ++u;
3503 }
3504 strFirstUnit.MakeLower();
3505 if (argc == 2) {
3506 unitValue = GetSimpleHValue(hThis, args, 1);
3507 CFX_ByteString unitTempString;
3508 HValueToUTF8String(unitValue, unitTempString);
3509 const FX_CHAR* pData = unitTempString;
3510 int32_t u = 0;
3511 while (*(pData + u) == ' ' || *(pData + u) == 0x09 ||
3512 *(pData + u) == 0x0B || *(pData + u) == 0x0C ||
3513 *(pData + u) == 0x0A || *(pData + u) == 0x0D) {
3514 ++u;
3515 }
3516 while (u < unitTempString.GetLength()) {
3517 if ((*(pData + u) > '9' || *(pData + u) < '0') &&
3518 *(pData + u) != '.') {
3519 break;
3520 }
3521 ++u;
3522 }
3523 while (*(pData + u) == ' ' || *(pData + u) == 0x09 ||
3524 *(pData + u) == 0x0B || *(pData + u) == 0x0C ||
3525 *(pData + u) == 0x0A || *(pData + u) == 0x0D) {
3526 ++u;
3527 }
3528 int32_t uLen = unitTempString.GetLength();
3529 while (u < uLen) {
3530 if (*(pData + u) == ' ') {
3531 break;
3532 }
3533 strUnit += (*(pData + u));
3534 ++u;
3535 }
3536 strUnit.MakeLower();
3537 } else {
3538 strUnit = strFirstUnit;
3539 }
3540 FX_DOUBLE dResult = 0;
3541 if (strFirstUnit.Equal("in") || strFirstUnit.Equal("inches")) {
3542 if (strUnit.Equal("mm") || strUnit.Equal("millimeters")) {
3543 dResult = dFirstNumber * 25.4;
3544 } else if (strUnit.Equal("cm") || strUnit.Equal("centimeters")) {
3545 dResult = dFirstNumber * 2.54;
3546 } else if (strUnit.Equal("pt") || strUnit.Equal("points")) {
3547 dResult = dFirstNumber / 72;
3548 } else if (strUnit.Equal("mp") || strUnit.Equal("millipoints")) {
3549 dResult = dFirstNumber / 72000;
3550 } else {
3551 dResult = dFirstNumber;
3552 }
3553 } else if (strFirstUnit.Equal("mm") ||
3554 strFirstUnit.Equal("millimeters")) {
3555 if (strUnit.Equal("mm") || strUnit.Equal("millimeters")) {
3556 dResult = dFirstNumber;
3557 } else if (strUnit.Equal("cm") || strUnit.Equal("centimeters")) {
3558 dResult = dFirstNumber / 10;
3559 } else if (strUnit.Equal("pt") || strUnit.Equal("points")) {
3560 dResult = dFirstNumber / 25.4 / 72;
3561 } else if (strUnit.Equal("mp") || strUnit.Equal("millipoints")) {
3562 dResult = dFirstNumber / 25.4 / 72000;
3563 } else {
3564 dResult = dFirstNumber / 25.4;
3565 }
3566 } else if (strFirstUnit.Equal("cm") ||
3567 strFirstUnit.Equal("centimeters")) {
3568 if (strUnit.Equal("mm") || strUnit.Equal("millimeters")) {
3569 dResult = dFirstNumber * 10;
3570 } else if (strUnit.Equal("cm") || strUnit.Equal("centimeters")) {
3571 dResult = dFirstNumber;
3572 } else if (strUnit.Equal("pt") || strUnit.Equal("points")) {
3573 dResult = dFirstNumber / 2.54 / 72;
3574 } else if (strUnit.Equal("mp") || strUnit.Equal("millipoints")) {
3575 dResult = dFirstNumber / 2.54 / 72000;
3576 } else {
3577 dResult = dFirstNumber / 2.54;
3578 }
3579 } else if (strFirstUnit.Equal("pt") || strFirstUnit.Equal("points")) {
3580 if (strUnit.Equal("mm") || strUnit.Equal("millimeters")) {
3581 dResult = dFirstNumber / 72 * 25.4;
3582 } else if (strUnit.Equal("cm") || strUnit.Equal("centimeters")) {
3583 dResult = dFirstNumber / 72 * 2.54;
3584 } else if (strUnit.Equal("pt") || strUnit.Equal("points")) {
3585 dResult = dFirstNumber;
3586 } else if (strUnit.Equal("mp") || strUnit.Equal("millipoints")) {
3587 dResult = dFirstNumber * 1000;
3588 } else {
3589 dResult = dFirstNumber / 72;
3590 }
3591 } else if (strFirstUnit.Equal("mp") ||
3592 strFirstUnit.Equal("millipoints")) {
3593 if (strUnit.Equal("mm") || strUnit.Equal("millimeters")) {
3594 dResult = dFirstNumber / 72000 * 25.4;
3595 } else if (strUnit.Equal("cm") || strUnit.Equal("centimeters")) {
3596 dResult = dFirstNumber / 72000 * 2.54;
3597 } else if (strUnit.Equal("pt") || strUnit.Equal("points")) {
3598 dResult = dFirstNumber / 1000;
3599 } else if (strUnit.Equal("mp") || strUnit.Equal("millipoints")) {
3600 dResult = dFirstNumber;
3601 } else {
3602 dResult = dFirstNumber / 72000;
3603 }
3604 }
3605 FXJSE_Value_SetDouble(args.GetReturnValue(), dResult);
3606 } else {
3607 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
3608 }
3609 }
3610 FXJSE_Value_Release(unitspanValue);
3611 if (argc == 2) {
3612 FXJSE_Value_Release(unitValue);
3613 }
3614 } else {
3615 CXFA_FM2JSContext* pContext =
3616 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3617 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3618 L"UnitValue");
3619 }
3620 }
3621 void CXFA_FM2JSContext::At(FXJSE_HOBJECT hThis,
3622 const CFX_ByteStringC& szFuncName,
3623 CFXJSE_Arguments& args) {
3624 CXFA_FM2JSContext* pContext =
3625 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3626 if (args.GetLength() == 2) {
3627 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
3628 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
3629 if (HValueIsNull(hThis, argOne) || HValueIsNull(hThis, argTwo)) {
3630 FXJSE_Value_SetNull(args.GetReturnValue());
3631 } else {
3632 CFX_ByteString stringTwo;
3633 HValueToUTF8String(argTwo, stringTwo);
3634 if (stringTwo.IsEmpty()) {
3635 FXJSE_Value_SetInteger(args.GetReturnValue(), 1);
3636 } else {
3637 CFX_ByteString stringOne;
3638 HValueToUTF8String(argOne, stringOne);
3639 FX_STRSIZE iPosition = stringOne.Find(stringTwo);
3640 FXJSE_Value_SetInteger(args.GetReturnValue(), iPosition + 1);
3641 }
3642 }
3643 FXJSE_Value_Release(argOne);
3644 FXJSE_Value_Release(argTwo);
3645 } else {
3646 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3647 L"At");
3648 }
3649 }
3650 void CXFA_FM2JSContext::Concat(FXJSE_HOBJECT hThis,
3651 const CFX_ByteStringC& szFuncName,
3652 CFXJSE_Arguments& args) {
3653 CXFA_FM2JSContext* pContext =
3654 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3655 int32_t argc = args.GetLength();
3656 if (argc >= 1) {
3657 CFX_ByteString resultString;
3658 FX_BOOL bAllNull = TRUE;
3659 FXJSE_HVALUE* argValues = FX_Alloc(FXJSE_HVALUE, argc);
3660 for (int32_t i = 0; i < argc; i++) {
3661 argValues[i] = GetSimpleHValue(hThis, args, i);
3662 if (!HValueIsNull(hThis, argValues[i])) {
3663 CFX_ByteString valueStr;
3664 HValueToUTF8String(argValues[i], valueStr);
3665 resultString += valueStr;
3666 bAllNull = FALSE;
3667 }
3668 }
3669 for (int32_t i = 0; i < argc; i++) {
3670 FXJSE_Value_Release(argValues[i]);
3671 }
3672 FX_Free(argValues);
3673 if (bAllNull) {
3674 FXJSE_Value_SetNull(args.GetReturnValue());
3675 } else {
3676 FXJSE_Value_SetUTF8String(args.GetReturnValue(), resultString);
3677 }
3678 } else {
3679 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3680 L"Concat");
3681 }
3682 }
3683 void CXFA_FM2JSContext::Decode(FXJSE_HOBJECT hThis,
3684 const CFX_ByteStringC& szFuncName,
3685 CFXJSE_Arguments& args) {
3686 CXFA_FM2JSContext* pContext =
3687 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3688 int32_t argc = args.GetLength();
3689 if (argc == 1) {
3690 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
3691 if (HValueIsNull(hThis, argOne)) {
3692 FXJSE_Value_SetNull(args.GetReturnValue());
3693 } else {
3694 CFX_ByteString toDecodeString;
3695 HValueToUTF8String(argOne, toDecodeString);
3696 CFX_ByteTextBuf resultBuf;
3697 DecodeURL(toDecodeString, resultBuf);
3698 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
3699 resultBuf.GetByteString());
3700 }
3701 FXJSE_Value_Release(argOne);
3702 } else if (argc == 2) {
3703 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
3704 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
3705 if (HValueIsNull(hThis, argOne) || HValueIsNull(hThis, argTwo)) {
3706 FXJSE_Value_SetNull(args.GetReturnValue());
3707 } else {
3708 CFX_ByteString toDecodeString;
3709 HValueToUTF8String(argOne, toDecodeString);
3710 CFX_ByteString identifyString;
3711 HValueToUTF8String(argTwo, identifyString);
3712 CFX_ByteTextBuf resultBuf;
3713 if (identifyString.EqualNoCase("html")) {
3714 DecodeHTML(toDecodeString, resultBuf);
3715 } else if (identifyString.EqualNoCase("xml")) {
3716 DecodeXML(toDecodeString, resultBuf);
3717 } else {
3718 DecodeURL(toDecodeString, resultBuf);
3719 }
3720 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
3721 resultBuf.GetByteString());
3722 }
3723 FXJSE_Value_Release(argOne);
3724 FXJSE_Value_Release(argTwo);
3725 } else {
3726 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
3727 L"Decode");
3728 }
3729 }
3730 void CXFA_FM2JSContext::DecodeURL(const CFX_ByteStringC& szURLString,
3731 CFX_ByteTextBuf& szResultString) {
3732 CFX_WideString wsURLString =
3733 CFX_WideString::FromUTF8(szURLString.GetCStr(), szURLString.GetLength());
3734 const FX_WCHAR* pData = wsURLString;
3735 int32_t iLen = wsURLString.GetLength();
3736 int32_t i = 0;
3737 FX_WCHAR ch = 0;
3738 FX_WCHAR chTemp = 0;
3739 CFX_WideTextBuf wsResultBuf;
3740 while (i < iLen) {
3741 ch = *(pData + i);
3742 if ('%' == ch) {
3743 chTemp = 0;
3744 int32_t iCount = 0;
3745 while (iCount < 2) {
3746 ++i;
3747 ch = *(pData + i);
3748 if (ch <= '9' && ch >= '0') {
3749 if (!iCount) {
3750 chTemp += (ch - '0') * 16;
3751 } else {
3752 chTemp += (ch - '0');
3753 }
3754 } else {
3755 if (ch <= 'F' && ch >= 'A') {
3756 if (!iCount) {
3757 chTemp += (ch - 'A' + 10) * 16;
3758 } else {
3759 chTemp += (ch - 'A' + 10);
3760 }
3761 } else if (ch <= 'f' && ch >= 'a') {
3762 if (!iCount) {
3763 chTemp += (ch - 'a' + 10) * 16;
3764 } else {
3765 chTemp += (ch - 'a' + 10);
3766 }
3767 } else {
3768 wsResultBuf.Clear();
3769 return;
3770 }
3771 }
3772 ++iCount;
3773 }
3774 wsResultBuf.AppendChar(chTemp);
3775 } else {
3776 wsResultBuf.AppendChar(ch);
3777 }
3778 ++i;
3779 }
3780 wsResultBuf.AppendChar(0);
3781 szResultString.Clear();
3782 szResultString << FX_UTF8Encode(wsResultBuf.GetBuffer(),
3783 wsResultBuf.GetLength());
3784 }
3785 void CXFA_FM2JSContext::DecodeHTML(const CFX_ByteStringC& szHTMLString,
3786 CFX_ByteTextBuf& szResultString) {
3787 CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(
3788 szHTMLString.GetCStr(), szHTMLString.GetLength());
3789 FX_WCHAR strString[9];
3790 int32_t iStrIndex = 0;
3791 int32_t iLen = wsHTMLString.GetLength();
3792 int32_t i = 0;
3793 int32_t iCode = 0;
3794 FX_WCHAR ch = 0;
3795 const FX_WCHAR* pData = wsHTMLString;
3796 CFX_WideTextBuf wsResultBuf;
3797 while (i < iLen) {
3798 ch = *(pData + i);
3799 if (ch == '&') {
3800 ++i;
3801 ch = *(pData + i);
3802 if (ch == '#') {
3803 ++i;
3804 ch = *(pData + i);
3805 if (ch == 'x' || ch == 'X') {
3806 ++i;
3807 ch = *(pData + i);
3808 if ((ch >= '0' && ch <= '9') || (ch <= 'f' && ch >= 'a') ||
3809 (ch <= 'F' && ch >= 'A')) {
3810 while (ch != ';' && i < iLen) {
3811 if (ch >= '0' && ch <= '9') {
3812 iCode += ch - '0';
3813 } else if (ch <= 'f' && ch >= 'a') {
3814 iCode += ch - 'a' + 10;
3815 } else if (ch <= 'F' && ch >= 'A') {
3816 iCode += ch - 'A' + 10;
3817 } else {
3818 wsResultBuf.Clear();
3819 return;
3820 }
3821 ++i;
3822 iCode *= 16;
3823 ch = *(pData + i);
3824 }
3825 iCode /= 16;
3826 }
3827 } else {
3828 wsResultBuf.Clear();
3829 return;
3830 }
3831 } else {
3832 while (ch != ';' && i < iLen) {
3833 strString[iStrIndex++] = ch;
3834 ++i;
3835 ch = *(pData + i);
3836 }
3837 strString[iStrIndex] = 0;
3838 }
3839 } else {
3840 wsResultBuf.AppendChar(ch);
3841 ++i;
3842 continue;
3843 }
3844 uint32_t iData = 0;
3845 if (HTMLSTR2Code(strString, iData)) {
3846 wsResultBuf.AppendChar((FX_WCHAR)iData);
3847 } else {
3848 wsResultBuf.AppendChar(iCode);
3849 }
3850 iStrIndex = 0;
3851 strString[iStrIndex] = 0;
3852 ++i;
3853 }
3854 wsResultBuf.AppendChar(0);
3855 szResultString.Clear();
3856 szResultString << FX_UTF8Encode(wsResultBuf.GetBuffer(),
3857 wsResultBuf.GetLength());
3858 }
3859 void CXFA_FM2JSContext::DecodeXML(const CFX_ByteStringC& szXMLString,
3860 CFX_ByteTextBuf& szResultString) {
3861 CFX_WideString wsXMLString =
3862 CFX_WideString::FromUTF8(szXMLString.GetCStr(), szXMLString.GetLength());
3863 FX_WCHAR strString[9];
3864 int32_t iStrIndex = 0;
3865 int32_t iLen = wsXMLString.GetLength();
3866 int32_t i = 0;
3867 int32_t iCode = 0;
3868 FX_WCHAR ch = 0;
3869 const FX_WCHAR* pData = wsXMLString;
3870 CFX_WideTextBuf wsXMLBuf;
3871 while (i < iLen) {
3872 ch = *(pData + i);
3873 if (ch == '&') {
3874 ++i;
3875 ch = *(pData + i);
3876 if (ch == '#') {
3877 ++i;
3878 ch = *(pData + i);
3879 if (ch == 'x' || ch == 'X') {
3880 ++i;
3881 ch = *(pData + i);
3882 if ((ch >= '0' && ch <= '9') || (ch <= 'f' && ch >= 'a') ||
3883 (ch <= 'F' && ch >= 'A')) {
3884 while (ch != ';') {
3885 if (ch >= '0' && ch <= '9') {
3886 iCode += ch - '0';
3887 } else if (ch <= 'f' && ch >= 'a') {
3888 iCode += ch - 'a' + 10;
3889 } else if (ch <= 'F' && ch >= 'A') {
3890 iCode += ch - 'A' + 10;
3891 } else {
3892 wsXMLBuf.Clear();
3893 return;
3894 }
3895 ++i;
3896 iCode *= 16;
3897 ch = *(pData + i);
3898 }
3899 iCode /= 16;
3900 }
3901 } else {
3902 wsXMLBuf.Clear();
3903 return;
3904 }
3905 } else {
3906 while (ch != ';' && i < iLen) {
3907 strString[iStrIndex++] = ch;
3908 ++i;
3909 ch = *(pData + i);
3910 }
3911 strString[iStrIndex] = 0;
3912 }
3913 } else {
3914 wsXMLBuf.AppendChar(ch);
3915 ++i;
3916 continue;
3917 }
3918 const FX_WCHAR* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"};
3919 int32_t iIndex = 0;
3920 while (iIndex < 5) {
3921 if (FXSYS_memcmp(strString, strName[iIndex],
3922 FXSYS_wcslen(strName[iIndex])) == 0) {
3923 break;
3924 }
3925 ++iIndex;
3926 }
3927 switch (iIndex) {
3928 case 0:
3929 wsXMLBuf.AppendChar('"');
3930 break;
3931 case 1:
3932 wsXMLBuf.AppendChar('&');
3933 break;
3934 case 2:
3935 wsXMLBuf.AppendChar('\'');
3936 break;
3937 case 3:
3938 wsXMLBuf.AppendChar('<');
3939 break;
3940 case 4:
3941 wsXMLBuf.AppendChar('>');
3942 break;
3943 default:
3944 wsXMLBuf.AppendChar(iCode);
3945 break;
3946 }
3947 iStrIndex = 0;
3948 strString[iStrIndex] = 0;
3949 ++i;
3950 iCode = 0;
3951 }
3952 wsXMLBuf.AppendChar(0);
3953 szResultString.Clear();
3954 szResultString << FX_UTF8Encode(wsXMLBuf.GetBuffer(), wsXMLBuf.GetLength());
3955 }
3956 void CXFA_FM2JSContext::Encode(FXJSE_HOBJECT hThis,
3957 const CFX_ByteStringC& szFuncName,
3958 CFXJSE_Arguments& args) {
3959 CXFA_FM2JSContext* pContext =
3960 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
3961 int32_t argc = args.GetLength();
3962 if (argc == 1) {
3963 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
3964 if (HValueIsNull(hThis, argOne)) {
3965 FXJSE_Value_SetNull(args.GetReturnValue());
3966 } else {
3967 CFX_ByteString toEncodeString;
3968 HValueToUTF8String(argOne, toEncodeString);
3969 CFX_ByteTextBuf resultBuf;
3970 EncodeURL(toEncodeString, resultBuf);
3971 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
3972 resultBuf.GetByteString());
3973 }
3974 FXJSE_Value_Release(argOne);
3975 } else if (argc == 2) {
3976 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
3977 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
3978 if (HValueIsNull(hThis, argOne) || HValueIsNull(hThis, argTwo)) {
3979 FXJSE_Value_SetNull(args.GetReturnValue());
3980 } else {
3981 CFX_ByteString toEncodeString;
3982 HValueToUTF8String(argOne, toEncodeString);
3983 CFX_ByteString identifyString;
3984 HValueToUTF8String(argTwo, identifyString);
3985 CFX_ByteTextBuf resultBuf;
3986 if (identifyString.EqualNoCase("html")) {
3987 EncodeHTML(toEncodeString, resultBuf);
3988 } else if (identifyString.EqualNoCase("xml")) {
3989 EncodeXML(toEncodeString, resultBuf);
3990 } else {
3991 EncodeURL(toEncodeString, resultBuf);
3992 }
3993 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
3994 resultBuf.GetByteString());
3995 }
3996 FXJSE_Value_Release(argOne);
3997 FXJSE_Value_Release(argTwo);
3998 } else {
3999 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
4000 L"Encode");
4001 }
4002 }
4003 void CXFA_FM2JSContext::EncodeURL(const CFX_ByteStringC& szURLString,
4004 CFX_ByteTextBuf& szResultBuf) {
4005 CFX_WideString wsURLString =
4006 CFX_WideString::FromUTF8(szURLString.GetCStr(), szURLString.GetLength());
4007 CFX_WideTextBuf wsResultBuf;
4008 FX_WCHAR ch = 0;
4009 int32_t iLength = wsURLString.GetLength();
4010 FX_WCHAR strEncode[4];
4011 strEncode[0] = '%';
4012 strEncode[3] = 0;
4013 FX_WCHAR strUnsafe[] = {' ', '<', '>', '"', '#', '%', '{', '}',
4014 '|', '\\', '^', '~', '[', ']', '`'};
4015 FX_WCHAR strReserved[] = {';', '/', '?', ':', '@', '=', '&'};
4016 FX_WCHAR strSpecial[] = {'$', '-', '+', '!', '*', '\'', '(', ')', ','};
4017 const FX_WCHAR* strCode = L"0123456789abcdef";
4018 for (int32_t u = 0; u < iLength; ++u) {
4019 ch = wsURLString.GetAt(u);
4020 int32_t i = 0;
4021 int32_t iCount = sizeof(strUnsafe) / sizeof(strUnsafe[0]);
4022 while (i < iCount) {
4023 if (ch == strUnsafe[i]) {
4024 int32_t iIndex = ch / 16;
4025 strEncode[1] = strCode[iIndex];
4026 strEncode[2] = strCode[ch - iIndex * 16];
4027 wsResultBuf << FX_WSTRC(strEncode);
4028 break;
4029 }
4030 ++i;
4031 }
4032 if (i < iCount) {
4033 continue;
4034 }
4035 i = 0;
4036 iCount = sizeof(strReserved) / sizeof(strReserved[0]);
4037 while (i < iCount) {
4038 if (ch == strReserved[i]) {
4039 int32_t iIndex = ch / 16;
4040 strEncode[1] = strCode[iIndex];
4041 strEncode[2] = strCode[ch - iIndex * 16];
4042 wsResultBuf << FX_WSTRC(strEncode);
4043 break;
4044 }
4045 ++i;
4046 }
4047 if (i < iCount) {
4048 continue;
4049 }
4050 i = 0;
4051 iCount = sizeof(strSpecial) / sizeof(strSpecial[0]);
4052 while (i < iCount) {
4053 if (ch == strSpecial[i]) {
4054 wsResultBuf.AppendChar(ch);
4055 break;
4056 }
4057 ++i;
4058 }
4059 if (i < iCount) {
4060 continue;
4061 }
4062 if (ch >= 0x80 && ch <= 0xff) {
4063 int32_t iIndex = ch / 16;
4064 strEncode[1] = strCode[iIndex];
4065 strEncode[2] = strCode[ch - iIndex * 16];
4066 wsResultBuf << FX_WSTRC(strEncode);
4067 } else if (ch <= 0x1f || ch == 0x7f) {
4068 int32_t iIndex = ch / 16;
4069 strEncode[1] = strCode[iIndex];
4070 strEncode[2] = strCode[ch - iIndex * 16];
4071 wsResultBuf << FX_WSTRC(strEncode);
4072 } else if (ch >= 0x20 && ch <= 0x7e) {
4073 wsResultBuf.AppendChar(ch);
4074 } else {
4075 int32_t iRadix = 16;
4076 CFX_WideString strTmp;
4077 while (ch >= iRadix) {
4078 FX_WCHAR tmp = strCode[ch % iRadix];
4079 ch /= iRadix;
4080 strTmp += tmp;
4081 }
4082 strTmp += strCode[ch];
4083 int32_t iLen = strTmp.GetLength();
4084 if (iLen < 2) {
4085 break;
4086 }
4087 int32_t iIndex = 0;
4088 if (iLen % 2 != 0) {
4089 strEncode[1] = '0';
4090 strEncode[2] = strTmp.GetAt(iLen - 1);
4091 iIndex = iLen - 2;
4092 } else {
4093 strEncode[1] = strTmp.GetAt(iLen - 1);
4094 strEncode[2] = strTmp.GetAt(iLen - 2);
4095 iIndex = iLen - 3;
4096 }
4097 wsResultBuf << FX_WSTRC(strEncode);
4098 while (iIndex > 0) {
4099 strEncode[1] = strTmp.GetAt(iIndex);
4100 strEncode[2] = strTmp.GetAt(iIndex - 1);
4101 iIndex -= 2;
4102 wsResultBuf << FX_WSTRC(strEncode);
4103 }
4104 }
4105 }
4106 wsResultBuf.AppendChar(0);
4107 szResultBuf.Clear();
4108 szResultBuf << FX_UTF8Encode(wsResultBuf.GetBuffer(),
4109 wsResultBuf.GetLength());
4110 }
4111 void CXFA_FM2JSContext::EncodeHTML(const CFX_ByteStringC& szHTMLString,
4112 CFX_ByteTextBuf& szResultBuf) {
4113 CFX_ByteString str = szHTMLString.GetCStr();
4114 CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(str, str.GetLength());
4115 const FX_WCHAR* strCode = L"0123456789abcdef";
4116 FX_WCHAR strEncode[9];
4117 strEncode[0] = '&';
4118 strEncode[1] = '#';
4119 strEncode[2] = 'x';
4120 strEncode[5] = ';';
4121 strEncode[6] = 0;
4122 strEncode[7] = ';';
4123 strEncode[8] = 0;
4124 CFX_WideTextBuf wsResultBuf;
4125 uint32_t ch = 0;
4126 int32_t iLen = wsHTMLString.GetLength();
4127 int32_t i = 0;
4128 const FX_WCHAR* pData = wsHTMLString;
4129 int32_t iIndex = 0;
4130 CFX_WideString htmlReserve;
4131 while (i < iLen) {
4132 ch = *(pData + i);
4133 htmlReserve.Empty();
4134 if (HTMLCode2STR(ch, htmlReserve)) {
4135 wsResultBuf.AppendChar(L'&');
4136 wsResultBuf << htmlReserve;
4137 wsResultBuf.AppendChar(L';');
4138 } else {
4139 if (ch >= 32 && ch <= 126) {
4140 wsResultBuf.AppendChar((FX_WCHAR)ch);
4141 } else if (ch < 256) {
4142 iIndex = ch / 16;
4143 strEncode[3] = strCode[iIndex];
4144 strEncode[4] = strCode[ch - iIndex * 16];
4145 strEncode[5] = ';';
4146 strEncode[6] = 0;
4147 wsResultBuf << FX_WSTRC(strEncode);
4148 } else {
4149 int32_t iBigByte = ch / 256;
4150 int32_t iLittleByte = ch % 256;
4151 strEncode[3] = strCode[iBigByte / 16];
4152 strEncode[4] = strCode[iBigByte % 16];
4153 strEncode[5] = strCode[iLittleByte / 16];
4154 strEncode[6] = strCode[iLittleByte % 16];
4155 wsResultBuf << FX_WSTRC(strEncode);
4156 }
4157 }
4158 ++i;
4159 }
4160 wsResultBuf.AppendChar(0);
4161 szResultBuf.Clear();
4162 szResultBuf << FX_UTF8Encode(wsResultBuf.GetBuffer(),
4163 wsResultBuf.GetLength());
4164 }
4165 void CXFA_FM2JSContext::EncodeXML(const CFX_ByteStringC& szXMLString,
4166 CFX_ByteTextBuf& szResultBuf) {
4167 CFX_WideString wsXMLString =
4168 CFX_WideString::FromUTF8(szXMLString.GetCStr(), szXMLString.GetLength());
4169 CFX_WideTextBuf wsResultBuf;
4170 enum {
4171 QUOT,
4172 AMP,
4173 APOS,
4174 LT,
4175 GT,
4176 };
4177 FX_WCHAR strEncode[9];
4178 strEncode[0] = '&';
4179 strEncode[1] = '#';
4180 strEncode[2] = 'x';
4181 strEncode[5] = ';';
4182 strEncode[6] = 0;
4183 strEncode[7] = ';';
4184 strEncode[8] = 0;
4185 const FX_WCHAR* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"};
4186 const FX_WCHAR* strCode = L"0123456789abcdef";
4187 FX_WCHAR ch = 0;
4188 int32_t iLength = wsXMLString.GetLength();
4189 int32_t iIndex = 0;
4190 int32_t u = 0;
4191 const FX_WCHAR* pData = wsXMLString;
4192 for (u = 0; u < iLength; ++u) {
4193 ch = *(pData + u);
4194 switch (ch) {
4195 case '"':
4196 wsResultBuf.AppendChar('&');
4197 wsResultBuf << CFX_WideStringC(strName[QUOT]);
4198 wsResultBuf.AppendChar(';');
4199 break;
4200 case '&':
4201 wsResultBuf.AppendChar('&');
4202 wsResultBuf << CFX_WideStringC(strName[AMP]);
4203 wsResultBuf.AppendChar(';');
4204 break;
4205 case '\'':
4206 wsResultBuf.AppendChar('&');
4207 wsResultBuf << CFX_WideStringC(strName[APOS]);
4208 wsResultBuf.AppendChar(';');
4209 break;
4210 case '<':
4211 wsResultBuf.AppendChar('&');
4212 wsResultBuf << CFX_WideStringC(strName[LT]);
4213 wsResultBuf.AppendChar(';');
4214 break;
4215 case '>':
4216 wsResultBuf.AppendChar('&');
4217 wsResultBuf << CFX_WideStringC(strName[GT]);
4218 wsResultBuf.AppendChar(';');
4219 break;
4220 default: {
4221 if (ch >= 32 && ch <= 126) {
4222 wsResultBuf.AppendChar(ch);
4223 } else if (ch < 256) {
4224 iIndex = ch / 16;
4225 strEncode[3] = strCode[iIndex];
4226 strEncode[4] = strCode[ch - iIndex * 16];
4227 strEncode[5] = ';';
4228 strEncode[6] = 0;
4229 wsResultBuf << FX_WSTRC(strEncode);
4230 } else {
4231 int32_t iBigByte = ch / 256;
4232 int32_t iLittleByte = ch % 256;
4233 strEncode[3] = strCode[iBigByte / 16];
4234 strEncode[4] = strCode[iBigByte % 16];
4235 strEncode[5] = strCode[iLittleByte / 16];
4236 strEncode[6] = strCode[iLittleByte % 16];
4237 wsResultBuf << FX_WSTRC(strEncode);
4238 }
4239 } break;
4240 }
4241 }
4242 wsResultBuf.AppendChar(0);
4243 szResultBuf.Clear();
4244 szResultBuf << FX_UTF8Encode(wsResultBuf.GetBuffer(),
4245 wsResultBuf.GetLength());
4246 }
4247 FX_BOOL CXFA_FM2JSContext::HTMLSTR2Code(const CFX_WideStringC& pData,
4248 uint32_t& iCode) {
4249 int32_t iLength = pData.GetLength();
4250 uint32_t uHash = FX_HashCode_String_GetW(pData.GetPtr(), iLength);
4251 XFA_FMHtmlHashedReserveCode htmlhashedreservecode;
4252 int32_t iStart = 0,
4253 iEnd = (sizeof(reservesForDecode) / sizeof(reservesForDecode[0])) - 1;
4254 int32_t iMid = (iStart + iEnd) / 2;
4255 do {
4256 iMid = (iStart + iEnd) / 2;
4257 htmlhashedreservecode = reservesForDecode[iMid];
4258 if (uHash == htmlhashedreservecode.m_uHash) {
4259 iCode = htmlhashedreservecode.m_uCode;
4260 return TRUE;
4261 } else if (uHash < htmlhashedreservecode.m_uHash) {
4262 iEnd = iMid - 1;
4263 } else {
4264 iStart = iMid + 1;
4265 }
4266 } while (iStart <= iEnd);
4267 return FALSE;
4268 }
4269 FX_BOOL CXFA_FM2JSContext::HTMLCode2STR(uint32_t iCode,
4270 CFX_WideString& wsHTMLReserve) {
4271 XFA_FMHtmlReserveCode htmlreservecode;
4272 int32_t iStart = 0,
4273 iEnd = (sizeof(reservesForEncode) / sizeof(reservesForEncode[0])) - 1;
4274 int32_t iMid = (iStart + iEnd) / 2;
4275 do {
4276 iMid = (iStart + iEnd) / 2;
4277 htmlreservecode = reservesForEncode[iMid];
4278 if (iCode == htmlreservecode.m_uCode) {
4279 wsHTMLReserve = htmlreservecode.m_htmlReserve;
4280 return TRUE;
4281 } else if (iCode < htmlreservecode.m_uCode) {
4282 iEnd = iMid - 1;
4283 } else {
4284 iStart = iMid + 1;
4285 }
4286 } while (iStart <= iEnd);
4287 return FALSE;
4288 }
4289 static FX_BOOL XFA_PATTERN_STRING_Type(const CFX_ByteStringC& szPattern,
4290 FX_DWORD& patternType) {
4291 CFX_WideString wsPattern =
4292 CFX_WideString::FromUTF8(szPattern.GetCStr(), szPattern.GetLength());
4293 if (FX_WSTRC(L"datetime") == wsPattern.Left(8)) {
4294 patternType = XFA_VT_DATETIME;
4295 return TRUE;
4296 } else if (FX_WSTRC(L"date") == wsPattern.Left(4)) {
4297 patternType = wsPattern.Find(L"time") > 0 ? XFA_VT_DATETIME : XFA_VT_DATE;
4298 return TRUE;
4299 } else if (FX_WSTRC(L"time") == wsPattern.Left(4)) {
4300 patternType = XFA_VT_TIME;
4301 return TRUE;
4302 } else if (FX_WSTRC(L"text") == wsPattern.Left(4)) {
4303 patternType = XFA_VT_TEXT;
4304 return TRUE;
4305 } else if (FX_WSTRC(L"num") == wsPattern.Left(3)) {
4306 if (FX_WSTRC(L"integer") == wsPattern.Mid(4, 7)) {
4307 patternType = XFA_VT_INTEGER;
4308 } else if (FX_WSTRC(L"decimal") == wsPattern.Mid(4, 7)) {
4309 patternType = XFA_VT_DECIMAL;
4310 } else if (FX_WSTRC(L"currency") == wsPattern.Mid(4, 8)) {
4311 patternType = XFA_VT_FLOAT;
4312 } else if (FX_WSTRC(L"percent") == wsPattern.Mid(4, 7)) {
4313 patternType = XFA_VT_FLOAT;
4314 } else {
4315 patternType = XFA_VT_FLOAT;
4316 }
4317 return TRUE;
4318 }
4319 patternType = XFA_VT_NULL;
4320 wsPattern.MakeLower();
4321 const FX_WCHAR* pData = wsPattern;
4322 int32_t iLength = wsPattern.GetLength();
4323 int32_t iIndex = 0;
4324 FX_BOOL bSingleQuotation = FALSE;
4325 FX_WCHAR patternChar;
4326 while (iIndex < iLength) {
4327 patternChar = *(pData + iIndex);
4328 if (patternChar == 0x27) {
4329 bSingleQuotation = !bSingleQuotation;
4330 } else if (!bSingleQuotation &&
4331 (patternChar == 'y' || patternChar == 'j')) {
4332 patternType = XFA_VT_DATE;
4333 iIndex++;
4334 FX_WCHAR timePatternChar;
4335 while (iIndex < iLength) {
4336 timePatternChar = *(pData + iIndex);
4337 if (timePatternChar == 0x27) {
4338 bSingleQuotation = !bSingleQuotation;
4339 } else if (!bSingleQuotation && timePatternChar == 't') {
4340 patternType = XFA_VT_DATETIME;
4341 break;
4342 }
4343 iIndex++;
4344 }
4345 break;
4346 } else if (!bSingleQuotation &&
4347 (patternChar == 'h' || patternChar == 'k')) {
4348 patternType = XFA_VT_TIME;
4349 break;
4350 } else if (!bSingleQuotation &&
4351 (patternChar == 'a' || patternChar == 'x' ||
4352 patternChar == 'o' || patternChar == '0')) {
4353 patternType = XFA_VT_TEXT;
4354 if (patternChar == 'x' || patternChar == 'o' || patternChar == '0') {
4355 break;
4356 }
4357 } else if (!bSingleQuotation &&
4358 (patternChar == 'z' || patternChar == 's' ||
4359 patternChar == 'e' || patternChar == 'v' ||
4360 patternChar == '8' || patternChar == ',' ||
4361 patternChar == '.' || patternChar == '$')) {
4362 patternType = XFA_VT_FLOAT;
4363 if (patternChar == 'v' || patternChar == '8' || patternChar == '$') {
4364 break;
4365 }
4366 }
4367 iIndex++;
4368 }
4369 if (patternType == XFA_VT_NULL) {
4370 patternType = XFA_VT_TEXT | XFA_VT_FLOAT;
4371 }
4372 return FALSE;
4373 }
4374 void CXFA_FM2JSContext::Format(FXJSE_HOBJECT hThis,
4375 const CFX_ByteStringC& szFuncName,
4376 CFXJSE_Arguments& args) {
4377 CXFA_FM2JSContext* pContext =
4378 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
4379 int32_t argc = args.GetLength();
4380 if (argc >= 2) {
4381 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
4382 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
4383 CFX_ByteString szPattern;
4384 HValueToUTF8String(argOne, szPattern);
4385 CFX_ByteString szValue;
4386 HValueToUTF8String(argTwo, szValue);
4387 CXFA_Document* pDoc = pContext->GetDocument();
4388 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
4389 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
4390 FXSYS_assert(pThisNode);
4391 CXFA_WidgetData widgetData(pThisNode);
4392 IFX_Locale* pLocale = widgetData.GetLocal();
4393 FX_DWORD patternType;
4394 FX_BOOL bCompelte = XFA_PATTERN_STRING_Type(szPattern, patternType);
4395 CFX_WideString wsPattern =
4396 CFX_WideString::FromUTF8(szPattern, szPattern.GetLength());
4397 CFX_WideString wsValue =
4398 CFX_WideString::FromUTF8(szValue, szValue.GetLength());
4399 if (!bCompelte) {
4400 switch (patternType) {
4401 case XFA_VT_DATETIME: {
4402 FX_STRSIZE iTChar = wsPattern.Find(L'T');
4403 CFX_WideString wsDatePattern = FX_WSTRC(L"date{");
4404 wsDatePattern += wsPattern.Left(iTChar);
4405 wsDatePattern += FX_WSTRC(L"} ");
4406 CFX_WideString wsTimePattern = FX_WSTRC(L"time{");
4407 wsTimePattern += wsPattern.Mid(iTChar + 1);
4408 wsTimePattern += FX_WSTRC(L"}");
4409 wsPattern = wsDatePattern + wsTimePattern;
4410 } break;
4411 case XFA_VT_DATE: {
4412 wsPattern = FX_WSTRC(L"date{") + wsPattern;
4413 wsPattern += FX_WSTRC(L"}");
4414 } break;
4415 case XFA_VT_TIME: {
4416 wsPattern = FX_WSTRC(L"time{") + wsPattern;
4417 wsPattern += FX_WSTRC(L"}");
4418 } break;
4419 case XFA_VT_TEXT: {
4420 wsPattern = FX_WSTRC(L"text{") + wsPattern;
4421 wsPattern += FX_WSTRC(L"}");
4422 } break;
4423 case XFA_VT_FLOAT: {
4424 wsPattern = FX_WSTRC(L"num{") + wsPattern;
4425 wsPattern += FX_WSTRC(L"}");
4426 } break;
4427 default: {
4428 CFX_WideString wsTestPattern;
4429 wsTestPattern = FX_WSTRC(L"num{") + wsPattern;
4430 wsTestPattern += FX_WSTRC(L"}");
4431 CXFA_LocaleValue tempLocaleValue(XFA_VT_FLOAT, wsValue, wsTestPattern,
4432 pLocale, (CXFA_LocaleMgr*)pMgr);
4433 if (tempLocaleValue.IsValid()) {
4434 wsPattern = wsTestPattern;
4435 patternType = XFA_VT_FLOAT;
4436 } else {
4437 wsTestPattern = FX_WSTRC(L"text{") + wsPattern;
4438 wsTestPattern += FX_WSTRC(L"}");
4439 wsPattern = wsTestPattern;
4440 patternType = XFA_VT_TEXT;
4441 }
4442 } break;
4443 }
4444 }
4445 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale,
4446 (CXFA_LocaleMgr*)pMgr);
4447 CFX_WideString wsRet;
4448 if (localeValue.FormatPatterns(wsRet, wsPattern, pLocale,
4449 XFA_VALUEPICTURE_Display)) {
4450 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
4451 FX_UTF8Encode(wsRet, wsRet.GetLength()));
4452 } else {
4453 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "");
4454 }
4455 FXJSE_Value_Release(argOne);
4456 FXJSE_Value_Release(argTwo);
4457 } else {
4458 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
4459 L"Format");
4460 }
4461 }
4462 void CXFA_FM2JSContext::Left(FXJSE_HOBJECT hThis,
4463 const CFX_ByteStringC& szFuncName,
4464 CFXJSE_Arguments& args) {
4465 CXFA_FM2JSContext* pContext =
4466 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
4467 if (args.GetLength() == 2) {
4468 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
4469 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
4470 FX_BOOL argIsNull = FALSE;
4471 if ((HValueIsNull(hThis, argOne)) || (HValueIsNull(hThis, argTwo))) {
4472 argIsNull = TRUE;
4473 }
4474 if (argIsNull) {
4475 FXJSE_Value_SetNull(args.GetReturnValue());
4476 } else {
4477 CFX_ByteString sourceString;
4478 HValueToUTF8String(argOne, sourceString);
4479 int32_t count = HValueToInteger(hThis, argTwo);
4480 if (count < 0) {
4481 count = 0;
4482 }
4483 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
4484 sourceString.Left(count));
4485 }
4486 FXJSE_Value_Release(argOne);
4487 FXJSE_Value_Release(argTwo);
4488 } else {
4489 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
4490 L"Left");
4491 }
4492 }
4493 void CXFA_FM2JSContext::Len(FXJSE_HOBJECT hThis,
4494 const CFX_ByteStringC& szFuncName,
4495 CFXJSE_Arguments& args) {
4496 CXFA_FM2JSContext* pContext =
4497 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
4498 if (args.GetLength() == 1) {
4499 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
4500 if (HValueIsNull(hThis, argOne)) {
4501 FXJSE_Value_SetNull(args.GetReturnValue());
4502 } else {
4503 CFX_ByteString sourceString;
4504 HValueToUTF8String(argOne, sourceString);
4505 FXJSE_Value_SetInteger(args.GetReturnValue(), sourceString.GetLength());
4506 }
4507 FXJSE_Value_Release(argOne);
4508 } else {
4509 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
4510 L"Len");
4511 }
4512 }
4513 void CXFA_FM2JSContext::Lower(FXJSE_HOBJECT hThis,
4514 const CFX_ByteStringC& szFuncName,
4515 CFXJSE_Arguments& args) {
4516 int32_t argc = args.GetLength();
4517 if ((argc > 0) && (argc < 3)) {
4518 CFX_ByteString argString;
4519 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
4520 FXJSE_HVALUE localeValue = 0;
4521 if (HValueIsNull(hThis, argOne)) {
4522 FXJSE_Value_SetNull(args.GetReturnValue());
4523 } else {
4524 if (argc == 2) {
4525 localeValue = GetSimpleHValue(hThis, args, 1);
4526 }
4527 HValueToUTF8String(argOne, argString);
4528 CFX_WideTextBuf lowStringBuf;
4529 CFX_WideString wsArgString =
4530 CFX_WideString::FromUTF8(argString, argString.GetLength());
4531 const FX_WCHAR* pData = wsArgString;
4532 int32_t iLen = argString.GetLength();
4533 int32_t i = 0;
4534 int32_t ch = 0;
4535 while (i < iLen) {
4536 ch = *(pData + i);
4537 if (ch >= 0x41 && ch <= 0x5A) {
4538 ch += 32;
4539 } else if (ch >= 0xC0 && ch <= 0xDE) {
4540 ch += 32;
4541 } else if (ch == 0x100 || ch == 0x102 || ch == 0x104) {
4542 ch += 1;
4543 }
4544 lowStringBuf.AppendChar(ch);
4545 ++i;
4546 }
4547 lowStringBuf.AppendChar(0);
4548 FXJSE_Value_SetUTF8String(
4549 args.GetReturnValue(),
4550 FX_UTF8Encode(lowStringBuf.GetBuffer(), lowStringBuf.GetLength()));
4551 if (argc == 2) {
4552 FXJSE_Value_Release(localeValue);
4553 }
4554 }
4555 FXJSE_Value_Release(argOne);
4556 } else {
4557 CXFA_FM2JSContext* pContext =
4558 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
4559 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
4560 L"Lower");
4561 }
4562 }
4563 void CXFA_FM2JSContext::Ltrim(FXJSE_HOBJECT hThis,
4564 const CFX_ByteStringC& szFuncName,
4565 CFXJSE_Arguments& args) {
4566 CXFA_FM2JSContext* pContext =
4567 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
4568 if (args.GetLength() == 1) {
4569 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
4570 if (HValueIsNull(hThis, argOne)) {
4571 FXJSE_Value_SetNull(args.GetReturnValue());
4572 } else {
4573 CFX_ByteString sourceString;
4574 HValueToUTF8String(argOne, sourceString);
4575 sourceString.TrimLeft();
4576 FXJSE_Value_SetUTF8String(args.GetReturnValue(), sourceString);
4577 }
4578 FXJSE_Value_Release(argOne);
4579 } else {
4580 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
4581 L"Ltrim");
4582 }
4583 }
4584 void CXFA_FM2JSContext::Parse(FXJSE_HOBJECT hThis,
4585 const CFX_ByteStringC& szFuncName,
4586 CFXJSE_Arguments& args) {
4587 CXFA_FM2JSContext* pContext =
4588 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
4589 if (args.GetLength() == 2) {
4590 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
4591 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
4592 if (HValueIsNull(hThis, argTwo)) {
4593 FXJSE_Value_SetNull(args.GetReturnValue());
4594 } else {
4595 CFX_ByteString szPattern;
4596 HValueToUTF8String(argOne, szPattern);
4597 CFX_ByteString szValue;
4598 HValueToUTF8String(argTwo, szValue);
4599 CXFA_Document* pDoc = pContext->GetDocument();
4600 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
4601 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
4602 FXSYS_assert(pThisNode);
4603 CXFA_WidgetData widgetData(pThisNode);
4604 IFX_Locale* pLocale = widgetData.GetLocal();
4605 FX_DWORD patternType;
4606 FX_BOOL bCompletePattern =
4607 XFA_PATTERN_STRING_Type(szPattern, patternType);
4608 CFX_WideString wsPattern =
4609 CFX_WideString::FromUTF8(szPattern, szPattern.GetLength());
4610 CFX_WideString wsValue =
4611 CFX_WideString::FromUTF8(szValue, szValue.GetLength());
4612 CFX_ByteString szParsedValue;
4613 if (bCompletePattern) {
4614 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale,
4615 (CXFA_LocaleMgr*)pMgr);
4616 if (localeValue.IsValid()) {
4617 szParsedValue = FX_UTF8Encode(localeValue.GetValue());
4618 FXJSE_Value_SetUTF8String(args.GetReturnValue(), szParsedValue);
4619 } else {
4620 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "");
4621 }
4622 } else {
4623 switch (patternType) {
4624 case XFA_VT_DATETIME: {
4625 FX_STRSIZE iTChar = wsPattern.Find(L'T');
4626 CFX_WideString wsDatePattern = FX_WSTRC(L"date{");
4627 wsDatePattern += wsPattern.Left(iTChar);
4628 wsDatePattern += FX_WSTRC(L"} ");
4629 CFX_WideString wsTimePattern = FX_WSTRC(L"time{");
4630 wsTimePattern += wsPattern.Mid(iTChar + 1);
4631 wsTimePattern += FX_WSTRC(L"}");
4632 wsPattern = wsDatePattern + wsTimePattern;
4633 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern,
4634 pLocale, (CXFA_LocaleMgr*)pMgr);
4635 if (localeValue.IsValid()) {
4636 szParsedValue = FX_UTF8Encode(localeValue.GetValue());
4637 FXJSE_Value_SetUTF8String(args.GetReturnValue(), szParsedValue);
4638 } else {
4639 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "");
4640 }
4641 } break;
4642 case XFA_VT_DATE: {
4643 wsPattern = FX_WSTRC(L"date{") + wsPattern;
4644 wsPattern += FX_WSTRC(L"}");
4645 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern,
4646 pLocale, (CXFA_LocaleMgr*)pMgr);
4647 if (localeValue.IsValid()) {
4648 szParsedValue = FX_UTF8Encode(localeValue.GetValue());
4649 FXJSE_Value_SetUTF8String(args.GetReturnValue(), szParsedValue);
4650 } else {
4651 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "");
4652 }
4653 } break;
4654 case XFA_VT_TIME: {
4655 wsPattern = FX_WSTRC(L"time{") + wsPattern;
4656 wsPattern += FX_WSTRC(L"}");
4657 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern,
4658 pLocale, (CXFA_LocaleMgr*)pMgr);
4659 if (localeValue.IsValid()) {
4660 szParsedValue = FX_UTF8Encode(localeValue.GetValue());
4661 FXJSE_Value_SetUTF8String(args.GetReturnValue(), szParsedValue);
4662 } else {
4663 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "");
4664 }
4665 } break;
4666 case XFA_VT_TEXT: {
4667 wsPattern = FX_WSTRC(L"text{") + wsPattern;
4668 wsPattern += FX_WSTRC(L"}");
4669 CXFA_LocaleValue localeValue(XFA_VT_TEXT, wsValue, wsPattern,
4670 pLocale, (CXFA_LocaleMgr*)pMgr);
4671 if (localeValue.IsValid()) {
4672 szParsedValue = FX_UTF8Encode(localeValue.GetValue());
4673 FXJSE_Value_SetUTF8String(args.GetReturnValue(), szParsedValue);
4674 } else {
4675 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "");
4676 }
4677 } break;
4678 case XFA_VT_FLOAT: {
4679 wsPattern = FX_WSTRC(L"num{") + wsPattern;
4680 wsPattern += FX_WSTRC(L"}");
4681 CXFA_LocaleValue localeValue(XFA_VT_FLOAT, wsValue, wsPattern,
4682 pLocale, (CXFA_LocaleMgr*)pMgr);
4683 if (localeValue.IsValid()) {
4684 FXJSE_Value_SetDouble(args.GetReturnValue(),
4685 localeValue.GetDoubleNum());
4686 } else {
4687 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "");
4688 }
4689 } break;
4690 default: {
4691 CFX_WideString wsTestPattern;
4692 wsTestPattern = FX_WSTRC(L"num{") + wsPattern;
4693 wsTestPattern += FX_WSTRC(L"}");
4694 CXFA_LocaleValue localeValue(XFA_VT_FLOAT, wsValue, wsTestPattern,
4695 pLocale, (CXFA_LocaleMgr*)pMgr);
4696 if (localeValue.IsValid()) {
4697 FXJSE_Value_SetDouble(args.GetReturnValue(),
4698 localeValue.GetDoubleNum());
4699 } else {
4700 wsTestPattern = FX_WSTRC(L"text{") + wsPattern;
4701 wsTestPattern += FX_WSTRC(L"}");
4702 CXFA_LocaleValue localeValue(XFA_VT_TEXT, wsValue, wsTestPattern,
4703 pLocale, (CXFA_LocaleMgr*)pMgr);
4704 if (localeValue.IsValid()) {
4705 szParsedValue = FX_UTF8Encode(localeValue.GetValue());
4706 FXJSE_Value_SetUTF8String(args.GetReturnValue(), szParsedValue);
4707 } else {
4708 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "");
4709 }
4710 }
4711 } break;
4712 }
4713 }
4714 }
4715 FXJSE_Value_Release(argOne);
4716 FXJSE_Value_Release(argTwo);
4717 } else {
4718 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
4719 L"Parse");
4720 }
4721 }
4722 void CXFA_FM2JSContext::Replace(FXJSE_HOBJECT hThis,
4723 const CFX_ByteStringC& szFuncName,
4724 CFXJSE_Arguments& args) {
4725 int32_t argc = args.GetLength();
4726 if ((argc == 2) || (argc == 3)) {
4727 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
4728 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
4729 FXJSE_HVALUE argThree = 0;
4730 CFX_ByteString oneString;
4731 CFX_ByteString twoString;
4732 CFX_ByteString threeString;
4733 if (!HValueIsNull(hThis, argOne) && !HValueIsNull(hThis, argTwo)) {
4734 HValueToUTF8String(argOne, oneString);
4735 HValueToUTF8String(argTwo, twoString);
4736 }
4737 if (argc == 3) {
4738 argThree = GetSimpleHValue(hThis, args, 2);
4739 HValueToUTF8String(argThree, threeString);
4740 }
4741 int32_t iSrcLen = oneString.GetLength();
4742 int32_t iFindLen = twoString.GetLength();
4743 CFX_ByteTextBuf resultString;
4744 int32_t iFindIndex = 0;
4745 uint8_t ch = 0;
4746 for (int32_t u = 0; u < iSrcLen; ++u) {
4747 ch = oneString.GetAt(u);
4748 if (ch == twoString.GetAt(iFindIndex)) {
4749 int32_t iTemp = u + 1;
4750 ++iFindIndex;
4751 uint8_t chTemp = 0;
4752 while (iFindIndex < iFindLen) {
4753 chTemp = oneString.GetAt(iTemp);
4754 if (chTemp == twoString.GetAt(iFindIndex)) {
4755 ++iTemp;
4756 ++iFindIndex;
4757 } else {
4758 iFindIndex = 0;
4759 break;
4760 }
4761 }
4762 if (iFindIndex == iFindLen) {
4763 resultString << threeString;
4764 u += iFindLen - 1;
4765 iFindIndex = 0;
4766 } else {
4767 resultString.AppendChar(ch);
4768 }
4769 } else {
4770 resultString.AppendChar(ch);
4771 }
4772 }
4773 resultString.AppendChar(0);
4774 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
4775 resultString.GetByteString());
4776 FXJSE_Value_Release(argOne);
4777 FXJSE_Value_Release(argTwo);
4778 if (argc == 3) {
4779 FXJSE_Value_Release(argThree);
4780 }
4781 } else {
4782 CXFA_FM2JSContext* pContext =
4783 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
4784 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
4785 L"Replace");
4786 }
4787 }
4788 void CXFA_FM2JSContext::Right(FXJSE_HOBJECT hThis,
4789 const CFX_ByteStringC& szFuncName,
4790 CFXJSE_Arguments& args) {
4791 CXFA_FM2JSContext* pContext =
4792 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
4793 if (args.GetLength() == 2) {
4794 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
4795 FXJSE_HVALUE argTwo = GetSimpleHValue(hThis, args, 1);
4796 FX_BOOL argIsNull = FALSE;
4797 if ((HValueIsNull(hThis, argOne)) || (HValueIsNull(hThis, argTwo))) {
4798 argIsNull = TRUE;
4799 }
4800 if (argIsNull) {
4801 FXJSE_Value_SetNull(args.GetReturnValue());
4802 } else {
4803 CFX_ByteString sourceString;
4804 HValueToUTF8String(argOne, sourceString);
4805 int32_t count = HValueToInteger(hThis, argTwo);
4806 if (count < 0) {
4807 count = 0;
4808 }
4809 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
4810 sourceString.Right(count));
4811 }
4812 FXJSE_Value_Release(argOne);
4813 FXJSE_Value_Release(argTwo);
4814 } else {
4815 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
4816 L"Right");
4817 }
4818 }
4819 void CXFA_FM2JSContext::Rtrim(FXJSE_HOBJECT hThis,
4820 const CFX_ByteStringC& szFuncName,
4821 CFXJSE_Arguments& args) {
4822 CXFA_FM2JSContext* pContext =
4823 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
4824 if (args.GetLength() == 1) {
4825 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
4826 if (HValueIsNull(hThis, argOne)) {
4827 FXJSE_Value_SetNull(args.GetReturnValue());
4828 } else {
4829 CFX_ByteString sourceString;
4830 HValueToUTF8String(argOne, sourceString);
4831 sourceString.TrimRight();
4832 FXJSE_Value_SetUTF8String(args.GetReturnValue(), sourceString);
4833 }
4834 FXJSE_Value_Release(argOne);
4835 } else {
4836 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
4837 L"Rtrim");
4838 }
4839 }
4840 void CXFA_FM2JSContext::Space(FXJSE_HOBJECT hThis,
4841 const CFX_ByteStringC& szFuncName,
4842 CFXJSE_Arguments& args) {
4843 CXFA_FM2JSContext* pContext =
4844 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
4845 if (args.GetLength() == 1) {
4846 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
4847 if (FXJSE_Value_IsNull(argOne)) {
4848 FXJSE_Value_SetNull(args.GetReturnValue());
4849 } else {
4850 int32_t count = 0;
4851 count = HValueToInteger(hThis, argOne);
4852 count = (count < 0) ? 0 : count;
4853 CFX_ByteTextBuf spaceString;
4854 int32_t index = 0;
4855 while (index < count) {
4856 spaceString.AppendByte(' ');
4857 index++;
4858 }
4859 spaceString.AppendByte(0);
4860 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
4861 spaceString.GetByteString());
4862 }
4863 FXJSE_Value_Release(argOne);
4864 } else {
4865 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
4866 L"Space");
4867 }
4868 }
4869 void CXFA_FM2JSContext::Str(FXJSE_HOBJECT hThis,
4870 const CFX_ByteStringC& szFuncName,
4871 CFXJSE_Arguments& args) {
4872 int32_t argc = args.GetLength();
4873 if ((argc > 0) && (argc < 4)) {
4874 FX_BOOL bFlags = FALSE;
4875 FX_FLOAT fNumber;
4876 int32_t iWidth = 10;
4877 int32_t iPrecision = 0;
4878 FXJSE_HVALUE numberValue = GetSimpleHValue(hThis, args, 0);
4879 FXJSE_HVALUE widthValue = 0;
4880 FXJSE_HVALUE precisionValue = 0;
4881 if (FXJSE_Value_IsNull(numberValue)) {
4882 bFlags = TRUE;
4883 } else {
4884 fNumber = HValueToFloat(hThis, numberValue);
4885 }
4886 if (argc > 1) {
4887 widthValue = GetSimpleHValue(hThis, args, 1);
4888 iWidth = (int32_t)HValueToFloat(hThis, widthValue);
4889 }
4890 if (argc == 3) {
4891 precisionValue = GetSimpleHValue(hThis, args, 2);
4892 iPrecision = (int32_t)HValueToFloat(hThis, precisionValue);
4893 if (iPrecision < 0) {
4894 iPrecision = 0;
4895 }
4896 }
4897 if (!bFlags) {
4898 CFX_ByteString numberString;
4899 CFX_ByteString formatStr = "%";
4900 if (iPrecision) {
4901 formatStr += ".";
4902 formatStr += CFX_ByteString::FormatInteger(iPrecision);
4903 }
4904 formatStr += "f";
4905 numberString.Format(formatStr, fNumber);
4906 const FX_CHAR* pData = numberString;
4907 int32_t iLength = numberString.GetLength();
4908 int32_t u = 0;
4909 while (u < iLength) {
4910 if (*(pData + u) == '.') {
4911 break;
4912 }
4913 ++u;
4914 }
4915 CFX_ByteTextBuf resultBuf;
4916 if (u > iWidth || (iPrecision + u) >= iWidth) {
4917 int32_t i = 0;
4918 while (i < iWidth) {
4919 resultBuf.AppendChar('*');
4920 ++i;
4921 }
4922 resultBuf.AppendChar(0);
4923 } else {
4924 if (u == iLength) {
4925 if (iLength > iWidth) {
4926 int32_t i = 0;
4927 while (i < iWidth) {
4928 resultBuf.AppendChar('*');
4929 ++i;
4930 }
4931 } else {
4932 int32_t i = 0;
4933 int32_t iSpace = iWidth - iLength;
4934 while (i < iSpace) {
4935 resultBuf.AppendChar(' ');
4936 ++i;
4937 }
4938 resultBuf << pData;
4939 }
4940 } else {
4941 int32_t iLeavingSpace = 0;
4942 if (iPrecision == 0) {
4943 iLeavingSpace = iWidth - (u + iPrecision);
4944 } else {
4945 iLeavingSpace = iWidth - (u + iPrecision + 1);
4946 }
4947 int32_t i = 0;
4948 while (i < iLeavingSpace) {
4949 resultBuf.AppendChar(' ');
4950 ++i;
4951 }
4952 i = 0;
4953 while (i < u) {
4954 resultBuf.AppendChar(*(pData + i));
4955 ++i;
4956 }
4957 if (iPrecision != 0) {
4958 resultBuf.AppendChar('.');
4959 }
4960 u++;
4961 i = 0;
4962 while (u < iLength) {
4963 if (i >= iPrecision) {
4964 break;
4965 }
4966 resultBuf.AppendChar(*(pData + u));
4967 ++i;
4968 ++u;
4969 }
4970 while (i < iPrecision) {
4971 resultBuf.AppendChar('0');
4972 ++i;
4973 }
4974 resultBuf.AppendChar(0);
4975 }
4976 }
4977 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
4978 resultBuf.GetByteString());
4979 } else {
4980 FXJSE_Value_SetNull(args.GetReturnValue());
4981 }
4982 FXJSE_Value_Release(numberValue);
4983 if (argc > 1) {
4984 FXJSE_Value_Release(widthValue);
4985 if (argc == 3) {
4986 FXJSE_Value_Release(precisionValue);
4987 }
4988 }
4989 } else {
4990 CXFA_FM2JSContext* pContext =
4991 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
4992 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
4993 L"Str");
4994 }
4995 }
4996 void CXFA_FM2JSContext::Stuff(FXJSE_HOBJECT hThis,
4997 const CFX_ByteStringC& szFuncName,
4998 CFXJSE_Arguments& args) {
4999 int32_t argc = args.GetLength();
5000 if ((argc == 3) || (argc == 4)) {
5001 CFX_ByteString sourceString;
5002 CFX_ByteString insertString;
5003 int32_t iLength = 0;
5004 int32_t iStart = 0;
5005 int32_t iDelete = 0;
5006 FXJSE_HVALUE sourceValue = GetSimpleHValue(hThis, args, 0);
5007 FXJSE_HVALUE startValue = GetSimpleHValue(hThis, args, 1);
5008 FXJSE_HVALUE deleteValue = GetSimpleHValue(hThis, args, 2);
5009 FXJSE_HVALUE insertValue = 0;
5010 if (!FXJSE_Value_IsNull(sourceValue) && !FXJSE_Value_IsNull(startValue) &&
5011 !FXJSE_Value_IsNull(deleteValue)) {
5012 HValueToUTF8String(sourceValue, sourceString);
5013 iLength = sourceString.GetLength();
5014 iStart = (int32_t)HValueToFloat(hThis, startValue);
5015 if (iStart < 1) {
5016 iStart = 1;
5017 }
5018 if (iStart > iLength) {
5019 iStart = iLength;
5020 }
5021 iDelete = (int32_t)HValueToFloat(hThis, deleteValue);
5022 if (iDelete <= 0) {
5023 iDelete = 0;
5024 }
5025 }
5026 if (argc == 4) {
5027 insertValue = GetSimpleHValue(hThis, args, 3);
5028 HValueToUTF8String(insertValue, insertString);
5029 }
5030 iStart -= 1;
5031 CFX_ByteTextBuf resultString;
5032 int32_t i = 0;
5033 while (i < iStart) {
5034 resultString.AppendChar(sourceString.GetAt(i));
5035 ++i;
5036 }
5037 resultString << insertString;
5038 i = iStart + iDelete;
5039 while (i < iLength) {
5040 resultString.AppendChar(sourceString.GetAt(i));
5041 ++i;
5042 }
5043 resultString.AppendChar(0);
5044 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
5045 resultString.GetByteString());
5046 FXJSE_Value_Release(sourceValue);
5047 FXJSE_Value_Release(startValue);
5048 FXJSE_Value_Release(deleteValue);
5049 if (argc == 4) {
5050 FXJSE_Value_Release(insertValue);
5051 }
5052 } else {
5053 CXFA_FM2JSContext* pContext =
5054 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5055 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
5056 L"Stuff");
5057 }
5058 }
5059 void CXFA_FM2JSContext::Substr(FXJSE_HOBJECT hThis,
5060 const CFX_ByteStringC& szFuncName,
5061 CFXJSE_Arguments& args) {
5062 int32_t argc = args.GetLength();
5063 if (argc == 3) {
5064 FXJSE_HVALUE stringValue = GetSimpleHValue(hThis, args, 0);
5065 FXJSE_HVALUE startValue = GetSimpleHValue(hThis, args, 1);
5066 FXJSE_HVALUE endValue = GetSimpleHValue(hThis, args, 2);
5067 if (HValueIsNull(hThis, stringValue) || (HValueIsNull(hThis, startValue)) ||
5068 (HValueIsNull(hThis, endValue))) {
5069 FXJSE_Value_SetNull(args.GetReturnValue());
5070 } else {
5071 CFX_ByteString szSourceStr;
5072 int32_t iStart = 0;
5073 int32_t iCount = 0;
5074 HValueToUTF8String(stringValue, szSourceStr);
5075 int32_t iLength = szSourceStr.GetLength();
5076 if (iLength == 0) {
5077 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "");
5078 } else {
5079 iStart = (int32_t)HValueToFloat(hThis, startValue);
5080 iCount = (int32_t)HValueToFloat(hThis, endValue);
5081 if (iStart < 1) {
5082 iStart = 1;
5083 }
5084 if (iStart > iLength) {
5085 iStart = iLength;
5086 }
5087 if (iCount <= 0) {
5088 iCount = 0;
5089 }
5090 iStart -= 1;
5091 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
5092 szSourceStr.Mid(iStart, iCount));
5093 }
5094 }
5095 FXJSE_Value_Release(stringValue);
5096 FXJSE_Value_Release(startValue);
5097 FXJSE_Value_Release(endValue);
5098 } else {
5099 CXFA_FM2JSContext* pContext =
5100 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5101 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
5102 L"Substr");
5103 }
5104 }
5105 void CXFA_FM2JSContext::Uuid(FXJSE_HOBJECT hThis,
5106 const CFX_ByteStringC& szFuncName,
5107 CFXJSE_Arguments& args) {
5108 int32_t argc = args.GetLength();
5109 if ((argc == 0) || (argc == 1)) {
5110 int32_t iNum = 0;
5111 FXJSE_HVALUE argOne = 0;
5112 if (argc == 1) {
5113 argOne = GetSimpleHValue(hThis, args, 0);
5114 iNum = (int32_t)HValueToFloat(hThis, argOne);
5115 }
5116 FX_GUID guid;
5117 FX_GUID_CreateV4(&guid);
5118 CFX_ByteString bsUId;
5119 FX_GUID_ToString(&guid, bsUId, iNum);
5120 FXJSE_Value_SetUTF8String(args.GetReturnValue(), bsUId);
5121 if (argc == 1) {
5122 FXJSE_Value_Release(argOne);
5123 }
5124 } else {
5125 CXFA_FM2JSContext* pContext =
5126 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5127 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
5128 L"Uuid");
5129 }
5130 }
5131 void CXFA_FM2JSContext::Upper(FXJSE_HOBJECT hThis,
5132 const CFX_ByteStringC& szFuncName,
5133 CFXJSE_Arguments& args) {
5134 int32_t argc = args.GetLength();
5135 if ((argc > 0) && (argc < 3)) {
5136 CFX_ByteString argString;
5137 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
5138 FXJSE_HVALUE localeValue = 0;
5139 if (HValueIsNull(hThis, argOne)) {
5140 FXJSE_Value_SetNull(args.GetReturnValue());
5141 } else {
5142 if (argc == 2) {
5143 localeValue = GetSimpleHValue(hThis, args, 1);
5144 }
5145 HValueToUTF8String(argOne, argString);
5146 CFX_WideTextBuf upperStringBuf;
5147 CFX_WideString wsArgString =
5148 CFX_WideString::FromUTF8(argString, argString.GetLength());
5149 const FX_WCHAR* pData = wsArgString;
5150 int32_t iLen = wsArgString.GetLength();
5151 int32_t i = 0;
5152 int32_t ch = 0;
5153 while (i < iLen) {
5154 ch = *(pData + i);
5155 if (ch >= 0x61 && ch <= 0x7A) {
5156 ch -= 32;
5157 } else if (ch >= 0xE0 && ch <= 0xFE) {
5158 ch -= 32;
5159 } else if (ch == 0x101 || ch == 0x103 || ch == 0x105) {
5160 ch -= 1;
5161 }
5162 upperStringBuf.AppendChar(ch);
5163 ++i;
5164 }
5165 upperStringBuf.AppendChar(0);
5166 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
5167 FX_UTF8Encode(upperStringBuf.GetBuffer(),
5168 upperStringBuf.GetLength()));
5169 if (argc == 2) {
5170 FXJSE_Value_Release(localeValue);
5171 }
5172 }
5173 FXJSE_Value_Release(argOne);
5174 } else {
5175 CXFA_FM2JSContext* pContext =
5176 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5177 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
5178 L"Upper");
5179 }
5180 }
5181 void CXFA_FM2JSContext::WordNum(FXJSE_HOBJECT hThis,
5182 const CFX_ByteStringC& szFuncName,
5183 CFXJSE_Arguments& args) {
5184 int32_t argc = args.GetLength();
5185 if ((argc > 0) && (argc < 4)) {
5186 FX_BOOL bFlags = FALSE;
5187 FX_FLOAT fNumber;
5188 int32_t iIdentifier = 0;
5189 CFX_ByteString localeString;
5190 FXJSE_HVALUE numberValue = GetSimpleHValue(hThis, args, 0);
5191 FXJSE_HVALUE identifierValue = 0;
5192 FXJSE_HVALUE localeValue = 0;
5193 if (FXJSE_Value_IsNull(numberValue)) {
5194 bFlags = TRUE;
5195 } else {
5196 fNumber = HValueToFloat(hThis, numberValue);
5197 }
5198 if (argc > 1) {
5199 identifierValue = GetSimpleHValue(hThis, args, 1);
5200 if (FXJSE_Value_IsNull(identifierValue)) {
5201 bFlags = TRUE;
5202 } else {
5203 iIdentifier = (int32_t)HValueToFloat(hThis, identifierValue);
5204 }
5205 }
5206 if (argc == 3) {
5207 localeValue = GetSimpleHValue(hThis, args, 2);
5208 if (FXJSE_Value_IsNull(localeValue)) {
5209 bFlags = TRUE;
5210 } else {
5211 HValueToUTF8String(localeValue, localeString);
5212 }
5213 }
5214 if (!bFlags) {
5215 if ((fNumber < 0) || (fNumber > 922337203685477550)) {
5216 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "*");
5217 } else {
5218 CFX_ByteTextBuf resultBuf;
5219 CFX_ByteString numberString;
5220 numberString.Format("%.2f", fNumber);
5221 WordUS(numberString, iIdentifier, resultBuf);
5222 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
5223 resultBuf.GetByteString());
5224 }
5225 } else {
5226 FXJSE_Value_SetNull(args.GetReturnValue());
5227 }
5228 FXJSE_Value_Release(numberValue);
5229 if (argc > 1) {
5230 FXJSE_Value_Release(identifierValue);
5231 if (argc == 3) {
5232 FXJSE_Value_Release(localeValue);
5233 }
5234 }
5235 } else {
5236 CXFA_FM2JSContext* pContext =
5237 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5238 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
5239 L"WordNum");
5240 }
5241 }
5242 void CXFA_FM2JSContext::TrillionUS(const CFX_ByteStringC& szData,
5243 CFX_ByteTextBuf& strBuf) {
5244 CFX_ByteStringC pUnits[] = {"zero", "one", "two", "three", "four",
5245 "five", "six", "seven", "eight", "nine"};
5246 CFX_ByteStringC pCapUnits[] = {"Zero", "One", "Two", "Three", "Four",
5247 "Five", "Six", "Seven", "Eight", "Nine"};
5248 CFX_ByteStringC pTens[] = {"Ten", "Eleven", "Twelve", "Thirteen",
5249 "Fourteen", "Fifteen", "Sixteen", "Seventeen",
5250 "Eighteen", "Nineteen"};
5251 CFX_ByteStringC pLastTens[] = {"Twenty", "Thirty", "Forty", "Fifty",
5252 "Sixty", "Seventy", "Eighty", "Ninety"};
5253 CFX_ByteStringC pComm[] = {" Hundred ", " Thousand ", " Million ",
5254 " Billion ", "Trillion"};
5255 int32_t iComm = 0;
5256 const FX_CHAR* pData = szData.GetCStr();
5257 int32_t iLength = szData.GetLength();
5258 if (iLength > 12) {
5259 iComm = 4;
5260 } else if (iLength > 9) {
5261 iComm = 3;
5262 } else if (iLength > 6) {
5263 iComm = 2;
5264 } else if (iLength > 3) {
5265 iComm = 1;
5266 }
5267 int32_t iIndex = 0;
5268 int32_t iFirstCount = iLength % 3;
5269 if (iFirstCount == 0) {
5270 iFirstCount = 3;
5271 }
5272 if (iFirstCount == 3) {
5273 if (*(pData + iIndex) != '0') {
5274 strBuf << pCapUnits[*(pData + iIndex) - '0'];
5275 strBuf << pComm[0];
5276 }
5277 if (*(pData + iIndex + 1) == '0') {
5278 strBuf << pCapUnits[*(pData + iIndex + 2) - '0'];
5279 } else {
5280 if (*(pData + iIndex + 1) > '1') {
5281 strBuf << pLastTens[*(pData + iIndex + 1) - '2'];
5282 strBuf << "-";
5283 strBuf << pUnits[*(pData + iIndex + 2) - '0'];
5284 } else if (*(pData + iIndex + 1) == '1') {
5285 strBuf << pTens[*(pData + iIndex + 2) - '0'];
5286 } else if (*(pData + iIndex + 1) == '0') {
5287 strBuf << pCapUnits[*(pData + iIndex + 2) - '0'];
5288 }
5289 }
5290 iIndex += 3;
5291 } else if (iFirstCount == 2) {
5292 if (*(pData + iIndex) == '0') {
5293 strBuf << pCapUnits[*(pData + iIndex + 1) - '0'];
5294 } else {
5295 if (*(pData + iIndex) > '1') {
5296 strBuf << pLastTens[*(pData + iIndex) - '2'];
5297 strBuf << "-";
5298 strBuf << pUnits[*(pData + iIndex + 1) - '0'];
5299 } else if (*(pData + iIndex) == '1') {
5300 strBuf << pTens[*(pData + iIndex + 1) - '0'];
5301 } else if (*(pData + iIndex) == '0') {
5302 strBuf << pCapUnits[*(pData + iIndex + 1) - '0'];
5303 }
5304 }
5305 iIndex += 2;
5306 } else if (iFirstCount == 1) {
5307 strBuf << pCapUnits[*(pData + iIndex) - '0'];
5308 iIndex += 1;
5309 }
5310 if (iLength > 3 && iFirstCount > 0) {
5311 strBuf << pComm[iComm];
5312 --iComm;
5313 }
5314 while (iIndex < iLength) {
5315 if (*(pData + iIndex) != '0') {
5316 strBuf << pCapUnits[*(pData + iIndex) - '0'];
5317 strBuf << pComm[0];
5318 }
5319 if (*(pData + iIndex + 1) == '0') {
5320 strBuf << pCapUnits[*(pData + iIndex + 2) - '0'];
5321 } else {
5322 if (*(pData + iIndex + 1) > '1') {
5323 strBuf << pLastTens[*(pData + iIndex + 1) - '2'];
5324 strBuf << "-";
5325 strBuf << pUnits[*(pData + iIndex + 2) - '0'];
5326 } else if (*(pData + iIndex + 1) == '1') {
5327 strBuf << pTens[*(pData + iIndex + 2) - '0'];
5328 } else if (*(pData + iIndex + 1) == '0') {
5329 strBuf << pCapUnits[*(pData + iIndex + 2) - '0'];
5330 }
5331 }
5332 if (iIndex < iLength - 3) {
5333 strBuf << pComm[iComm];
5334 --iComm;
5335 }
5336 iIndex += 3;
5337 }
5338 }
5339 void CXFA_FM2JSContext::WordUS(const CFX_ByteStringC& szData,
5340 int32_t iStyle,
5341 CFX_ByteTextBuf& strBuf) {
5342 const FX_CHAR* pData = szData.GetCStr();
5343 int32_t iLength = szData.GetLength();
5344 switch (iStyle) {
5345 case 0: {
5346 int32_t iIndex = 0;
5347 while (iIndex < iLength) {
5348 if (*(pData + iIndex) == '.') {
5349 break;
5350 }
5351 ++iIndex;
5352 }
5353 iLength = iIndex;
5354 iIndex = 0;
5355 int32_t iCount = 0;
5356 while (iIndex < iLength) {
5357 iCount = (iLength - iIndex) % 12;
5358 if (!iCount && iLength - iIndex > 0) {
5359 iCount = 12;
5360 }
5361 TrillionUS(CFX_ByteStringC(pData + iIndex, iCount), strBuf);
5362 iIndex += iCount;
5363 if (iIndex < iLength) {
5364 strBuf << " Trillion ";
5365 }
5366 }
5367 } break;
5368 case 1: {
5369 int32_t iIndex = 0;
5370 while (iIndex < iLength) {
5371 if (*(pData + iIndex) == '.') {
5372 break;
5373 }
5374 ++iIndex;
5375 }
5376 iLength = iIndex;
5377 iIndex = 0;
5378 int32_t iCount = 0;
5379 while (iIndex < iLength) {
5380 iCount = (iLength - iIndex) % 12;
5381 if (!iCount && iLength - iIndex > 0) {
5382 iCount = 12;
5383 }
5384 TrillionUS(CFX_ByteStringC(pData + iIndex, iCount), strBuf);
5385 iIndex += iCount;
5386 if (iIndex < iLength) {
5387 strBuf << " Trillion ";
5388 }
5389 }
5390 strBuf << " Dollars";
5391 } break;
5392 case 2: {
5393 int32_t iIndex = 0;
5394 while (iIndex < iLength) {
5395 if (*(pData + iIndex) == '.') {
5396 break;
5397 }
5398 ++iIndex;
5399 }
5400 int32_t iInteger = iIndex;
5401 iIndex = 0;
5402 int32_t iCount = 0;
5403 while (iIndex < iInteger) {
5404 iCount = (iInteger - iIndex) % 12;
5405 if (!iCount && iLength - iIndex > 0) {
5406 iCount = 12;
5407 }
5408 TrillionUS(CFX_ByteStringC(pData + iIndex, iCount), strBuf);
5409 iIndex += iCount;
5410 if (iIndex < iInteger) {
5411 strBuf << " Trillion ";
5412 }
5413 }
5414 strBuf << " Dollars";
5415 if (iInteger < iLength) {
5416 strBuf << " And ";
5417 iIndex = iInteger + 1;
5418 int32_t iCount = 0;
5419 while (iIndex < iLength) {
5420 iCount = (iLength - iIndex) % 12;
5421 if (!iCount && iLength - iIndex > 0) {
5422 iCount = 12;
5423 }
5424 TrillionUS(CFX_ByteStringC(pData + iIndex, iCount), strBuf);
5425 iIndex += iCount;
5426 if (iIndex < iLength) {
5427 strBuf << " Trillion ";
5428 }
5429 }
5430 strBuf << " Cents";
5431 }
5432 } break;
5433 default:
5434 break;
5435 }
5436 }
5437 void CXFA_FM2JSContext::Get(FXJSE_HOBJECT hThis,
5438 const CFX_ByteStringC& szFuncName,
5439 CFXJSE_Arguments& args) {
5440 CXFA_FM2JSContext* pContext =
5441 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5442 int32_t argc = args.GetLength();
5443 if (argc == 1) {
5444 CXFA_Document* pDoc = pContext->GetDocument();
5445 if (!pDoc) {
5446 return;
5447 }
5448 IXFA_AppProvider* pAppProvider =
5449 pDoc->GetParser()->GetNotify()->GetAppProvider();
5450 if (!pAppProvider) {
5451 return;
5452 }
5453 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
5454 CFX_ByteString urlString;
5455 HValueToUTF8String(argOne, urlString);
5456 IFX_FileRead* pFile = pAppProvider->DownloadURL(
5457 CFX_WideString::FromUTF8(urlString, urlString.GetLength()));
5458 if (pFile) {
5459 int32_t size = pFile->GetSize();
5460 uint8_t* pData = FX_Alloc(uint8_t, size);
5461 pFile->ReadBlock(pData, size);
5462 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
5463 CFX_ByteStringC(pData, size));
5464 FX_Free(pData);
5465 pFile->Release();
5466 }
5467 FXJSE_Value_Release(argOne);
5468 } else {
5469 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
5470 L"Get");
5471 }
5472 }
5473 void CXFA_FM2JSContext::Post(FXJSE_HOBJECT hThis,
5474 const CFX_ByteStringC& szFuncName,
5475 CFXJSE_Arguments& args) {
5476 CXFA_FM2JSContext* pContext =
5477 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5478 int32_t argc = args.GetLength();
5479 if ((argc >= 2) && (argc <= 5)) {
5480 CXFA_Document* pDoc = pContext->GetDocument();
5481 if (!pDoc) {
5482 return;
5483 }
5484 IXFA_AppProvider* pAppProvider =
5485 pDoc->GetParser()->GetNotify()->GetAppProvider();
5486 if (!pAppProvider) {
5487 return;
5488 }
5489 CFX_ByteString bsURL;
5490 CFX_ByteString bsData;
5491 CFX_ByteString bsContentType;
5492 CFX_ByteString bsEncode;
5493 CFX_ByteString bsHeader;
5494 FXJSE_HVALUE argOne;
5495 FXJSE_HVALUE argTwo;
5496 FXJSE_HVALUE argThree;
5497 FXJSE_HVALUE argFour;
5498 FXJSE_HVALUE argFive;
5499 argOne = GetSimpleHValue(hThis, args, 0);
5500 HValueToUTF8String(argOne, bsURL);
5501 argTwo = GetSimpleHValue(hThis, args, 1);
5502 HValueToUTF8String(argTwo, bsData);
5503 if (argc > 2) {
5504 argThree = GetSimpleHValue(hThis, args, 2);
5505 HValueToUTF8String(argThree, bsContentType);
5506 }
5507 if (argc > 3) {
5508 argFour = GetSimpleHValue(hThis, args, 3);
5509 HValueToUTF8String(argFour, bsEncode);
5510 }
5511 if (argc > 4) {
5512 argFive = GetSimpleHValue(hThis, args, 4);
5513 HValueToUTF8String(argFive, bsHeader);
5514 }
5515 CFX_WideString decodedResponse;
5516 FX_BOOL bFlags = pAppProvider->PostRequestURL(
5517 CFX_WideString::FromUTF8(bsURL, bsURL.GetLength()),
5518 CFX_WideString::FromUTF8(bsData, bsData.GetLength()),
5519 CFX_WideString::FromUTF8(bsContentType, bsContentType.GetLength()),
5520 CFX_WideString::FromUTF8(bsEncode, bsEncode.GetLength()),
5521 CFX_WideString::FromUTF8(bsHeader, bsHeader.GetLength()),
5522 decodedResponse);
5523 FXJSE_Value_Release(argOne);
5524 FXJSE_Value_Release(argTwo);
5525 if (argc > 2) {
5526 FXJSE_Value_Release(argThree);
5527 }
5528 if (argc > 3) {
5529 FXJSE_Value_Release(argFour);
5530 }
5531 if (argc > 4) {
5532 FXJSE_Value_Release(argFive);
5533 }
5534 if (bFlags) {
5535 FXJSE_Value_SetUTF8String(
5536 args.GetReturnValue(),
5537 FX_UTF8Encode(decodedResponse, decodedResponse.GetLength()));
5538 } else {
5539 pContext->ThrowScriptErrorMessage(XFA_IDS_SERVER_DENY);
5540 }
5541 } else {
5542 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
5543 L"Post");
5544 }
5545 }
5546 void CXFA_FM2JSContext::Put(FXJSE_HOBJECT hThis,
5547 const CFX_ByteStringC& szFuncName,
5548 CFXJSE_Arguments& args) {
5549 CXFA_FM2JSContext* pContext =
5550 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5551 int32_t argc = args.GetLength();
5552 if ((argc == 2) || (argc == 3)) {
5553 CXFA_Document* pDoc = pContext->GetDocument();
5554 if (!pDoc) {
5555 return;
5556 }
5557 IXFA_AppProvider* pAppProvider =
5558 pDoc->GetParser()->GetNotify()->GetAppProvider();
5559 if (!pAppProvider) {
5560 return;
5561 }
5562 CFX_ByteString bsURL;
5563 CFX_ByteString bsData;
5564 CFX_ByteString bsEncode;
5565 FXJSE_HVALUE argOne;
5566 FXJSE_HVALUE argTwo;
5567 FXJSE_HVALUE argThree;
5568 argOne = GetSimpleHValue(hThis, args, 0);
5569 HValueToUTF8String(argOne, bsURL);
5570 argTwo = GetSimpleHValue(hThis, args, 1);
5571 HValueToUTF8String(argTwo, bsData);
5572 if (argc > 2) {
5573 argThree = GetSimpleHValue(hThis, args, 2);
5574 HValueToUTF8String(argThree, bsEncode);
5575 }
5576 FX_BOOL bFlags = pAppProvider->PutRequestURL(
5577 CFX_WideString::FromUTF8(bsURL, bsURL.GetLength()),
5578 CFX_WideString::FromUTF8(bsData, bsData.GetLength()),
5579 CFX_WideString::FromUTF8(bsEncode, bsEncode.GetLength()));
5580 FXJSE_Value_Release(argOne);
5581 FXJSE_Value_Release(argTwo);
5582 if (argc > 2) {
5583 FXJSE_Value_Release(argThree);
5584 }
5585 if (bFlags) {
5586 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "");
5587 } else {
5588 pContext->ThrowScriptErrorMessage(XFA_IDS_SERVER_DENY);
5589 }
5590 } else {
5591 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
5592 L"Put");
5593 }
5594 }
5595 void CXFA_FM2JSContext::assign_value_operator(FXJSE_HOBJECT hThis,
5596 const CFX_ByteStringC& szFuncName,
5597 CFXJSE_Arguments& args) {
5598 CXFA_FM2JSContext* pContext =
5599 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5600 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
5601 if (args.GetLength() == 2) {
5602 FXJSE_HVALUE lValue = args.GetValue(0);
5603 FXJSE_HVALUE rValue = GetSimpleHValue(hThis, args, 1);
5604 FX_BOOL bSetStatus = TRUE;
5605 if (FXJSE_Value_IsArray(lValue)) {
5606 FXJSE_HVALUE leftLengthValue = FXJSE_Value_Create(hruntime);
5607 FXJSE_Value_GetObjectProp(lValue, "length", leftLengthValue);
5608 int32_t iLeftLength = FXJSE_Value_ToInteger(leftLengthValue);
5609 FXJSE_Value_Release(leftLengthValue);
5610 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
5611 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
5612 FXJSE_Value_GetObjectPropByIdx(lValue, 1, propertyValue);
5613 if (FXJSE_Value_IsNull(propertyValue)) {
5614 for (int32_t i = 2; i < iLeftLength; i++) {
5615 FXJSE_Value_GetObjectPropByIdx(lValue, i, jsObjectValue);
5616 bSetStatus = SetObjectDefaultValue(jsObjectValue, rValue);
5617 if (!bSetStatus) {
5618 pContext->ThrowScriptErrorMessage(XFA_IDS_NOT_DEFAUL_VALUE);
5619 break;
5620 }
5621 }
5622 } else {
5623 CFX_ByteString propertyStr;
5624 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
5625 for (int32_t i = 2; i < iLeftLength; i++) {
5626 FXJSE_Value_GetObjectPropByIdx(lValue, i, jsObjectValue);
5627 FXJSE_Value_SetObjectProp(jsObjectValue, propertyStr, rValue);
5628 }
5629 }
5630 FXJSE_Value_Release(jsObjectValue);
5631 FXJSE_Value_Release(propertyValue);
5632 } else if (FXJSE_Value_IsObject(lValue)) {
5633 bSetStatus = SetObjectDefaultValue(lValue, rValue);
5634 if (!bSetStatus) {
5635 pContext->ThrowScriptErrorMessage(XFA_IDS_NOT_DEFAUL_VALUE);
5636 }
5637 }
5638 FXJSE_Value_Set(args.GetReturnValue(), rValue);
5639 FXJSE_Value_Release(lValue);
5640 FXJSE_Value_Release(rValue);
5641 } else {
5642 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
5643 }
5644 }
5645 void CXFA_FM2JSContext::logical_or_operator(FXJSE_HOBJECT hThis,
5646 const CFX_ByteStringC& szFuncName,
5647 CFXJSE_Arguments& args) {
5648 if (args.GetLength() == 2) {
5649 FXJSE_HVALUE argFirst = GetSimpleHValue(hThis, args, 0);
5650 FXJSE_HVALUE argSecond = GetSimpleHValue(hThis, args, 1);
5651 if (FXJSE_Value_IsNull(argFirst) && FXJSE_Value_IsNull(argSecond)) {
5652 FXJSE_Value_SetNull(args.GetReturnValue());
5653 } else {
5654 FX_FLOAT first = HValueToFloat(hThis, argFirst);
5655 FX_FLOAT second = HValueToFloat(hThis, argSecond);
5656 FXJSE_Value_SetInteger(args.GetReturnValue(), (first || second) ? 1 : 0);
5657 }
5658 FXJSE_Value_Release(argFirst);
5659 FXJSE_Value_Release(argSecond);
5660 } else {
5661 CXFA_FM2JSContext* pContext =
5662 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5663 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
5664 }
5665 }
5666 void CXFA_FM2JSContext::logical_and_operator(FXJSE_HOBJECT hThis,
5667 const CFX_ByteStringC& szFuncName,
5668 CFXJSE_Arguments& args) {
5669 if (args.GetLength() == 2) {
5670 FXJSE_HVALUE argFirst = GetSimpleHValue(hThis, args, 0);
5671 FXJSE_HVALUE argSecond = GetSimpleHValue(hThis, args, 1);
5672 if (FXJSE_Value_IsNull(argFirst) && FXJSE_Value_IsNull(argSecond)) {
5673 FXJSE_Value_SetNull(args.GetReturnValue());
5674 } else {
5675 FX_FLOAT first = HValueToFloat(hThis, argFirst);
5676 FX_FLOAT second = HValueToFloat(hThis, argSecond);
5677 FXJSE_Value_SetInteger(args.GetReturnValue(), (first && second) ? 1 : 0);
5678 }
5679 FXJSE_Value_Release(argFirst);
5680 FXJSE_Value_Release(argSecond);
5681 } else {
5682 CXFA_FM2JSContext* pContext =
5683 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5684 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
5685 }
5686 }
5687 void CXFA_FM2JSContext::equality_operator(FXJSE_HOBJECT hThis,
5688 const CFX_ByteStringC& szFuncName,
5689 CFXJSE_Arguments& args) {
5690 if (args.GetLength() == 2) {
5691 if (fm_ref_equal(hThis, args)) {
5692 FXJSE_Value_SetInteger(args.GetReturnValue(), 1);
5693 } else {
5694 FXJSE_HVALUE argFirst = GetSimpleHValue(hThis, args, 0);
5695 FXJSE_HVALUE argSecond = GetSimpleHValue(hThis, args, 1);
5696 if (FXJSE_Value_IsNull(argFirst) || FXJSE_Value_IsNull(argSecond)) {
5697 FXJSE_Value_SetInteger(
5698 args.GetReturnValue(),
5699 (FXJSE_Value_IsNull(argFirst) && FXJSE_Value_IsNull(argSecond))
5700 ? 1
5701 : 0);
5702 } else if (FXJSE_Value_IsUTF8String(argFirst) &&
5703 FXJSE_Value_IsUTF8String(argSecond)) {
5704 CFX_ByteString firstOutput;
5705 CFX_ByteString secondOutput;
5706 FXJSE_Value_ToUTF8String(argFirst, firstOutput);
5707 FXJSE_Value_ToUTF8String(argSecond, secondOutput);
5708 FXJSE_Value_SetInteger(args.GetReturnValue(),
5709 firstOutput.Equal(secondOutput) ? 1 : 0);
5710 } else {
5711 FX_DOUBLE first = HValueToDouble(hThis, argFirst);
5712 FX_DOUBLE second = HValueToDouble(hThis, argSecond);
5713 FXJSE_Value_SetInteger(args.GetReturnValue(),
5714 (first == second) ? 1 : 0);
5715 }
5716 FXJSE_Value_Release(argFirst);
5717 FXJSE_Value_Release(argSecond);
5718 }
5719 } else {
5720 CXFA_FM2JSContext* pContext =
5721 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5722 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
5723 }
5724 }
5725 void CXFA_FM2JSContext::notequality_operator(FXJSE_HOBJECT hThis,
5726 const CFX_ByteStringC& szFuncName,
5727 CFXJSE_Arguments& args) {
5728 if (args.GetLength() == 2) {
5729 if (fm_ref_equal(hThis, args)) {
5730 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
5731 } else {
5732 FXJSE_HVALUE argFirst = GetSimpleHValue(hThis, args, 0);
5733 FXJSE_HVALUE argSecond = GetSimpleHValue(hThis, args, 1);
5734 if (FXJSE_Value_IsNull(argFirst) || FXJSE_Value_IsNull(argSecond)) {
5735 FXJSE_Value_SetInteger(
5736 args.GetReturnValue(),
5737 (FXJSE_Value_IsNull(argFirst) && FXJSE_Value_IsNull(argSecond))
5738 ? 0
5739 : 1);
5740 } else if (FXJSE_Value_IsUTF8String(argFirst) &&
5741 FXJSE_Value_IsUTF8String(argSecond)) {
5742 CFX_ByteString firstOutput;
5743 CFX_ByteString secondOutput;
5744 FXJSE_Value_ToUTF8String(argFirst, firstOutput);
5745 FXJSE_Value_ToUTF8String(argSecond, secondOutput);
5746 FXJSE_Value_SetInteger(args.GetReturnValue(),
5747 firstOutput.Equal(secondOutput) ? 0 : 1);
5748 } else {
5749 FX_DOUBLE first = HValueToDouble(hThis, argFirst);
5750 FX_DOUBLE second = HValueToDouble(hThis, argSecond);
5751 FXJSE_Value_SetInteger(args.GetReturnValue(),
5752 (first == second) ? 0 : 1);
5753 }
5754 FXJSE_Value_Release(argFirst);
5755 FXJSE_Value_Release(argSecond);
5756 }
5757 } else {
5758 CXFA_FM2JSContext* pContext =
5759 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5760 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
5761 }
5762 }
5763 FX_BOOL CXFA_FM2JSContext::fm_ref_equal(FXJSE_HOBJECT hThis,
5764 CFXJSE_Arguments& args) {
5765 FX_BOOL bRet = FALSE;
5766 CXFA_FM2JSContext* pContext =
5767 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5768 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
5769 FXJSE_HVALUE argFirst = args.GetValue(0);
5770 FXJSE_HVALUE argSecond = args.GetValue(0);
5771 if (FXJSE_Value_IsArray(argFirst) && FXJSE_Value_IsArray(argSecond)) {
5772 FXJSE_HVALUE firstFlagValue = FXJSE_Value_Create(hruntime);
5773 FXJSE_HVALUE secondFlagValue = FXJSE_Value_Create(hruntime);
5774 FXJSE_Value_GetObjectPropByIdx(argFirst, 0, firstFlagValue);
5775 FXJSE_Value_GetObjectPropByIdx(argSecond, 0, secondFlagValue);
5776 if ((FXJSE_Value_ToInteger(firstFlagValue) == 3) &&
5777 (FXJSE_Value_ToInteger(secondFlagValue) == 3)) {
5778 FXJSE_HVALUE firstJSObject = FXJSE_Value_Create(hruntime);
5779 FXJSE_HVALUE secondJSObject = FXJSE_Value_Create(hruntime);
5780 FXJSE_Value_GetObjectPropByIdx(argFirst, 2, firstJSObject);
5781 FXJSE_Value_GetObjectPropByIdx(argSecond, 2, secondJSObject);
5782 if (!FXJSE_Value_IsNull(firstJSObject) &&
5783 !FXJSE_Value_IsNull(secondJSObject)) {
5784 bRet = (FXJSE_Value_ToObject(firstJSObject, NULL) ==
5785 FXJSE_Value_ToObject(secondJSObject, NULL));
5786 }
5787 FXJSE_Value_Release(firstJSObject);
5788 FXJSE_Value_Release(secondJSObject);
5789 }
5790 FXJSE_Value_Release(firstFlagValue);
5791 FXJSE_Value_Release(secondFlagValue);
5792 }
5793 FXJSE_Value_Release(argFirst);
5794 FXJSE_Value_Release(argSecond);
5795 return bRet;
5796 }
5797 void CXFA_FM2JSContext::less_operator(FXJSE_HOBJECT hThis,
5798 const CFX_ByteStringC& szFuncName,
5799 CFXJSE_Arguments& args) {
5800 if (args.GetLength() == 2) {
5801 FXJSE_HVALUE argFirst = GetSimpleHValue(hThis, args, 0);
5802 FXJSE_HVALUE argSecond = GetSimpleHValue(hThis, args, 1);
5803 if (FXJSE_Value_IsNull(argFirst) || FXJSE_Value_IsNull(argSecond)) {
5804 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
5805 } else if (FXJSE_Value_IsUTF8String(argFirst) &&
5806 FXJSE_Value_IsUTF8String(argSecond)) {
5807 CFX_ByteString firstOutput;
5808 CFX_ByteString secondOutput;
5809 FXJSE_Value_ToUTF8String(argFirst, firstOutput);
5810 FXJSE_Value_ToUTF8String(argSecond, secondOutput);
5811 FXJSE_Value_SetInteger(args.GetReturnValue(),
5812 (firstOutput.Compare(secondOutput) == -1) ? 1 : 0);
5813 } else {
5814 FX_DOUBLE first = HValueToDouble(hThis, argFirst);
5815 FX_DOUBLE second = HValueToDouble(hThis, argSecond);
5816 FXJSE_Value_SetInteger(args.GetReturnValue(), (first < second) ? 1 : 0);
5817 }
5818 FXJSE_Value_Release(argFirst);
5819 FXJSE_Value_Release(argSecond);
5820 } else {
5821 CXFA_FM2JSContext* pContext =
5822 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5823 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
5824 }
5825 }
5826 void CXFA_FM2JSContext::lessequal_operator(FXJSE_HOBJECT hThis,
5827 const CFX_ByteStringC& szFuncName,
5828 CFXJSE_Arguments& args) {
5829 if (args.GetLength() == 2) {
5830 FXJSE_HVALUE argFirst = GetSimpleHValue(hThis, args, 0);
5831 FXJSE_HVALUE argSecond = GetSimpleHValue(hThis, args, 1);
5832 if (FXJSE_Value_IsNull(argFirst) || FXJSE_Value_IsNull(argSecond)) {
5833 FXJSE_Value_SetInteger(
5834 args.GetReturnValue(),
5835 (FXJSE_Value_IsNull(argFirst) && FXJSE_Value_IsNull(argSecond)) ? 1
5836 : 0);
5837 } else if (FXJSE_Value_IsUTF8String(argFirst) &&
5838 FXJSE_Value_IsUTF8String(argSecond)) {
5839 CFX_ByteString firstOutput;
5840 CFX_ByteString secondOutput;
5841 FXJSE_Value_ToUTF8String(argFirst, firstOutput);
5842 FXJSE_Value_ToUTF8String(argSecond, secondOutput);
5843 FXJSE_Value_SetInteger(args.GetReturnValue(),
5844 (firstOutput.Compare(secondOutput) != 1) ? 1 : 0);
5845 } else {
5846 FX_DOUBLE first = HValueToDouble(hThis, argFirst);
5847 FX_DOUBLE second = HValueToDouble(hThis, argSecond);
5848 FXJSE_Value_SetInteger(args.GetReturnValue(), (first <= second) ? 1 : 0);
5849 }
5850 FXJSE_Value_Release(argFirst);
5851 FXJSE_Value_Release(argSecond);
5852 } else {
5853 CXFA_FM2JSContext* pContext =
5854 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5855 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
5856 }
5857 }
5858 void CXFA_FM2JSContext::greater_operator(FXJSE_HOBJECT hThis,
5859 const CFX_ByteStringC& szFuncName,
5860 CFXJSE_Arguments& args) {
5861 if (args.GetLength() == 2) {
5862 FXJSE_HVALUE argFirst = GetSimpleHValue(hThis, args, 0);
5863 FXJSE_HVALUE argSecond = GetSimpleHValue(hThis, args, 1);
5864 if (FXJSE_Value_IsNull(argFirst) || FXJSE_Value_IsNull(argSecond)) {
5865 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
5866 } else if (FXJSE_Value_IsUTF8String(argFirst) &&
5867 FXJSE_Value_IsUTF8String(argSecond)) {
5868 CFX_ByteString firstOutput;
5869 CFX_ByteString secondOutput;
5870 FXJSE_Value_ToUTF8String(argFirst, firstOutput);
5871 FXJSE_Value_ToUTF8String(argSecond, secondOutput);
5872 FXJSE_Value_SetInteger(args.GetReturnValue(),
5873 (firstOutput.Compare(secondOutput) == 1) ? 1 : 0);
5874 } else {
5875 FX_DOUBLE first = HValueToDouble(hThis, argFirst);
5876 FX_DOUBLE second = HValueToDouble(hThis, argSecond);
5877 FXJSE_Value_SetInteger(args.GetReturnValue(), (first > second) ? 1 : 0);
5878 }
5879 FXJSE_Value_Release(argFirst);
5880 FXJSE_Value_Release(argSecond);
5881 } else {
5882 CXFA_FM2JSContext* pContext =
5883 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5884 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
5885 }
5886 }
5887 void CXFA_FM2JSContext::greaterequal_operator(FXJSE_HOBJECT hThis,
5888 const CFX_ByteStringC& szFuncName,
5889 CFXJSE_Arguments& args) {
5890 if (args.GetLength() == 2) {
5891 FXJSE_HVALUE argFirst = GetSimpleHValue(hThis, args, 0);
5892 FXJSE_HVALUE argSecond = GetSimpleHValue(hThis, args, 1);
5893 if (FXJSE_Value_IsNull(argFirst) || FXJSE_Value_IsNull(argSecond)) {
5894 FXJSE_Value_SetInteger(
5895 args.GetReturnValue(),
5896 (FXJSE_Value_IsNull(argFirst) && FXJSE_Value_IsNull(argSecond)) ? 1
5897 : 0);
5898 } else if (FXJSE_Value_IsUTF8String(argFirst) &&
5899 FXJSE_Value_IsUTF8String(argSecond)) {
5900 CFX_ByteString firstOutput;
5901 CFX_ByteString secondOutput;
5902 FXJSE_Value_ToUTF8String(argFirst, firstOutput);
5903 FXJSE_Value_ToUTF8String(argSecond, secondOutput);
5904 FXJSE_Value_SetInteger(args.GetReturnValue(),
5905 (firstOutput.Compare(secondOutput) != -1) ? 1 : 0);
5906 } else {
5907 FX_DOUBLE first = HValueToDouble(hThis, argFirst);
5908 FX_DOUBLE second = HValueToDouble(hThis, argSecond);
5909 FXJSE_Value_SetInteger(args.GetReturnValue(), (first >= second) ? 1 : 0);
5910 }
5911 FXJSE_Value_Release(argFirst);
5912 FXJSE_Value_Release(argSecond);
5913 } else {
5914 CXFA_FM2JSContext* pContext =
5915 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5916 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
5917 }
5918 }
5919 void CXFA_FM2JSContext::plus_operator(FXJSE_HOBJECT hThis,
5920 const CFX_ByteStringC& szFuncName,
5921 CFXJSE_Arguments& args) {
5922 if (args.GetLength() == 2) {
5923 FXJSE_HVALUE argFirst = args.GetValue(0);
5924 FXJSE_HVALUE argSecond = args.GetValue(1);
5925 if (HValueIsNull(hThis, argFirst) && HValueIsNull(hThis, argSecond)) {
5926 FXJSE_Value_SetNull(args.GetReturnValue());
5927 } else {
5928 FX_DOUBLE first = HValueToDouble(hThis, argFirst);
5929 FX_DOUBLE second = HValueToDouble(hThis, argSecond);
5930 FXJSE_Value_SetDouble(args.GetReturnValue(), first + second);
5931 }
5932 FXJSE_Value_Release(argFirst);
5933 FXJSE_Value_Release(argSecond);
5934 } else {
5935 CXFA_FM2JSContext* pContext =
5936 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5937 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
5938 }
5939 }
5940 void CXFA_FM2JSContext::minus_operator(FXJSE_HOBJECT hThis,
5941 const CFX_ByteStringC& szFuncName,
5942 CFXJSE_Arguments& args) {
5943 if (args.GetLength() == 2) {
5944 FXJSE_HVALUE argFirst = GetSimpleHValue(hThis, args, 0);
5945 FXJSE_HVALUE argSecond = GetSimpleHValue(hThis, args, 1);
5946 if (FXJSE_Value_IsNull(argFirst) && FXJSE_Value_IsNull(argSecond)) {
5947 FXJSE_Value_SetNull(args.GetReturnValue());
5948 } else {
5949 FX_DOUBLE first = HValueToDouble(hThis, argFirst);
5950 FX_DOUBLE second = HValueToDouble(hThis, argSecond);
5951 FXJSE_Value_SetDouble(args.GetReturnValue(), first - second);
5952 }
5953 FXJSE_Value_Release(argFirst);
5954 FXJSE_Value_Release(argSecond);
5955 } else {
5956 CXFA_FM2JSContext* pContext =
5957 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5958 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
5959 }
5960 }
5961 void CXFA_FM2JSContext::multiple_operator(FXJSE_HOBJECT hThis,
5962 const CFX_ByteStringC& szFuncName,
5963 CFXJSE_Arguments& args) {
5964 if (args.GetLength() == 2) {
5965 FXJSE_HVALUE argFirst = GetSimpleHValue(hThis, args, 0);
5966 FXJSE_HVALUE argSecond = GetSimpleHValue(hThis, args, 1);
5967 if (FXJSE_Value_IsNull(argFirst) && FXJSE_Value_IsNull(argSecond)) {
5968 FXJSE_Value_SetNull(args.GetReturnValue());
5969 } else {
5970 FX_DOUBLE first = HValueToDouble(hThis, argFirst);
5971 FX_DOUBLE second = HValueToDouble(hThis, argSecond);
5972 FXJSE_Value_SetDouble(args.GetReturnValue(), first * second);
5973 }
5974 FXJSE_Value_Release(argFirst);
5975 FXJSE_Value_Release(argSecond);
5976 } else {
5977 CXFA_FM2JSContext* pContext =
5978 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5979 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
5980 }
5981 }
5982 void CXFA_FM2JSContext::divide_operator(FXJSE_HOBJECT hThis,
5983 const CFX_ByteStringC& szFuncName,
5984 CFXJSE_Arguments& args) {
5985 CXFA_FM2JSContext* pContext =
5986 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
5987 if (args.GetLength() == 2) {
5988 FXJSE_HVALUE argFirst = GetSimpleHValue(hThis, args, 0);
5989 FXJSE_HVALUE argSecond = GetSimpleHValue(hThis, args, 1);
5990 if (FXJSE_Value_IsNull(argFirst) && FXJSE_Value_IsNull(argSecond)) {
5991 FXJSE_Value_SetNull(args.GetReturnValue());
5992 } else {
5993 FX_DOUBLE first = HValueToDouble(hThis, argFirst);
5994 FX_DOUBLE second = HValueToDouble(hThis, argSecond);
5995 if (second == 0.0) {
5996 pContext->ThrowScriptErrorMessage(XFA_IDS_DIVIDE_ZERO);
5997 } else {
5998 FXJSE_Value_SetDouble(args.GetReturnValue(), first / second);
5999 }
6000 }
6001 FXJSE_Value_Release(argFirst);
6002 FXJSE_Value_Release(argSecond);
6003 } else {
6004 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
6005 }
6006 }
6007 void CXFA_FM2JSContext::positive_operator(FXJSE_HOBJECT hThis,
6008 const CFX_ByteStringC& szFuncName,
6009 CFXJSE_Arguments& args) {
6010 int32_t iLength = args.GetLength();
6011 if (iLength == 1) {
6012 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
6013 if (FXJSE_Value_IsNull(argOne)) {
6014 FXJSE_Value_SetNull(args.GetReturnValue());
6015 } else {
6016 FXJSE_Value_SetDouble(args.GetReturnValue(),
6017 0.0 + HValueToDouble(hThis, argOne));
6018 }
6019 FXJSE_Value_Release(argOne);
6020 } else {
6021 CXFA_FM2JSContext* pContext =
6022 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6023 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
6024 }
6025 }
6026 void CXFA_FM2JSContext::negative_operator(FXJSE_HOBJECT hThis,
6027 const CFX_ByteStringC& szFuncName,
6028 CFXJSE_Arguments& args) {
6029 int32_t iLength = args.GetLength();
6030 if (iLength == 1) {
6031 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
6032 if (FXJSE_Value_IsNull(argOne)) {
6033 FXJSE_Value_SetNull(args.GetReturnValue());
6034 } else {
6035 FXJSE_Value_SetDouble(args.GetReturnValue(),
6036 0.0 - HValueToDouble(hThis, argOne));
6037 }
6038 FXJSE_Value_Release(argOne);
6039 } else {
6040 CXFA_FM2JSContext* pContext =
6041 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6042 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
6043 }
6044 }
6045 void CXFA_FM2JSContext::logical_not_operator(FXJSE_HOBJECT hThis,
6046 const CFX_ByteStringC& szFuncName,
6047 CFXJSE_Arguments& args) {
6048 int32_t iLength = args.GetLength();
6049 if (iLength == 1) {
6050 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
6051 if (FXJSE_Value_IsNull(argOne)) {
6052 FXJSE_Value_SetNull(args.GetReturnValue());
6053 } else {
6054 FX_DOUBLE first = HValueToDouble(hThis, argOne);
6055 FXJSE_Value_SetInteger(args.GetReturnValue(), (first == 0.0) ? 1 : 0);
6056 }
6057 FXJSE_Value_Release(argOne);
6058 } else {
6059 CXFA_FM2JSContext* pContext =
6060 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6061 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
6062 }
6063 }
6064 void CXFA_FM2JSContext::dot_accessor(FXJSE_HOBJECT hThis,
6065 const CFX_ByteStringC& szFuncName,
6066 CFXJSE_Arguments& args) {
6067 CXFA_FM2JSContext* pContext =
6068 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6069 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
6070 int32_t argc = args.GetLength();
6071 if ((argc == 4) || (argc == 5)) {
6072 FX_BOOL bIsStar = TRUE;
6073 FXJSE_HVALUE argAccessor = args.GetValue(0);
6074 CFX_ByteString bsAccessorName = args.GetUTF8String(1);
6075 CFX_ByteString szName = args.GetUTF8String(2);
6076 int32_t iIndexFlags = args.GetInt32(3);
6077 int32_t iIndexValue = 0;
6078 FXJSE_HVALUE argIndex = NULL;
6079 if (argc == 5) {
6080 bIsStar = FALSE;
6081 argIndex = args.GetValue(4);
6082 iIndexValue = HValueToInteger(hThis, argIndex);
6083 }
6084 CFX_ByteString szSomExp;
6085 GenerateSomExpression(szName, iIndexFlags, iIndexValue, bIsStar, szSomExp);
6086 if (FXJSE_Value_IsArray(argAccessor)) {
6087 FXJSE_HVALUE hLengthValue = FXJSE_Value_Create(hruntime);
6088 FXJSE_Value_GetObjectProp(argAccessor, "length", hLengthValue);
6089 int32_t iLength = FXJSE_Value_ToInteger(hLengthValue);
6090 FXJSE_Value_Release(hLengthValue);
6091 int32_t iCounter = 0;
6092 FXJSE_HVALUE** hResolveValues = FX_Alloc(FXJSE_HVALUE*, iLength - 2);
6093 int32_t* iSizes = FX_Alloc(int32_t, iLength - 2);
6094 for (int32_t i = 0; i < (iLength - 2); i++) {
6095 iSizes[i] = 0;
6096 }
6097 FXJSE_HVALUE hJSObjValue = FXJSE_Value_Create(hruntime);
6098 FX_BOOL bAttribute = FALSE;
6099 for (int32_t i = 2; i < iLength; i++) {
6100 FXJSE_Value_GetObjectPropByIdx(argAccessor, i, hJSObjValue);
6101 XFA_RESOLVENODE_RS resoveNodeRS;
6102 int32_t iRet = ResolveObjects(hThis, hJSObjValue, szSomExp,
6103 resoveNodeRS, TRUE, szName.IsEmpty());
6104 if (iRet > 0) {
6105 ParseResolveResult(hThis, resoveNodeRS, hJSObjValue,
6106 hResolveValues[i - 2], iSizes[i - 2], bAttribute);
6107 iCounter += iSizes[i - 2];
6108 }
6109 }
6110 FXJSE_Value_Release(hJSObjValue);
6111 if (iCounter > 0) {
6112 FXJSE_HVALUE* rgValues = FX_Alloc(FXJSE_HVALUE, iCounter + 2);
6113 for (int32_t i = 0; i < (iCounter + 2); i++) {
6114 rgValues[i] = FXJSE_Value_Create(hruntime);
6115 }
6116 FXJSE_Value_SetInteger(rgValues[0], 1);
6117 if (bAttribute) {
6118 FXJSE_Value_SetUTF8String(rgValues[1], szName);
6119 } else {
6120 FXJSE_Value_SetNull(rgValues[1]);
6121 }
6122 int32_t iIndex = 2;
6123 for (int32_t i = 0; i < iLength - 2; i++) {
6124 for (int32_t j = 0; j < iSizes[i]; j++) {
6125 FXJSE_Value_Set(rgValues[iIndex], hResolveValues[i][j]);
6126 iIndex++;
6127 }
6128 }
6129 FXJSE_Value_SetArray(args.GetReturnValue(), (iCounter + 2), rgValues);
6130 for (int32_t i = 0; i < (iCounter + 2); i++) {
6131 FXJSE_Value_Release(rgValues[i]);
6132 }
6133 FX_Free(rgValues);
6134 } else {
6135 CFX_WideString wsPropertyName =
6136 CFX_WideString::FromUTF8(szName, szName.GetLength());
6137 CFX_WideString wsSomExpression =
6138 CFX_WideString::FromUTF8(szSomExp, szSomExp.GetLength());
6139 pContext->ThrowScriptErrorMessage(XFA_IDS_ACCESS_PROPERTY_IN_NOT_OBJECT,
6140 (const FX_WCHAR*)wsPropertyName,
6141 (const FX_WCHAR*)wsSomExpression);
6142 }
6143 for (int32_t i = 0; i < iLength - 2; i++) {
6144 for (int32_t j = 0; j < iSizes[i]; j++) {
6145 FXJSE_Value_Release(hResolveValues[i][j]);
6146 }
6147 if (iSizes[i] > 0) {
6148 FX_Free(hResolveValues[i]);
6149 }
6150 }
6151 FX_Free(hResolveValues);
6152 FX_Free(iSizes);
6153 } else {
6154 XFA_RESOLVENODE_RS resoveNodeRS;
6155 int32_t iRet = 0;
6156 if (FXJSE_Value_IsObject(argAccessor) ||
6157 (FXJSE_Value_IsNull(argAccessor) && bsAccessorName.IsEmpty())) {
6158 iRet = ResolveObjects(hThis, argAccessor, szSomExp, resoveNodeRS, TRUE,
6159 szName.IsEmpty());
6160 } else if (!FXJSE_Value_IsObject(argAccessor) &&
6161 !bsAccessorName.IsEmpty()) {
6162 FX_BOOL bGetObject =
6163 GetObjectByName(hThis, argAccessor, bsAccessorName);
6164 if (bGetObject) {
6165 iRet = ResolveObjects(hThis, argAccessor, szSomExp, resoveNodeRS,
6166 TRUE, szName.IsEmpty());
6167 }
6168 }
6169 if (iRet > 0) {
6170 FXJSE_HVALUE* hResolveValues;
6171 int32_t iSize = 0;
6172 FX_BOOL bAttribute = FALSE;
6173 ParseResolveResult(hThis, resoveNodeRS, argAccessor, hResolveValues,
6174 iSize, bAttribute);
6175 FXJSE_HVALUE* rgValues = FX_Alloc(FXJSE_HVALUE, iSize + 2);
6176 for (int32_t i = 0; i < (iSize + 2); i++) {
6177 rgValues[i] = FXJSE_Value_Create(hruntime);
6178 }
6179 FXJSE_Value_SetInteger(rgValues[0], 1);
6180 if (bAttribute) {
6181 FXJSE_Value_SetUTF8String(rgValues[1], szName);
6182 } else {
6183 FXJSE_Value_SetNull(rgValues[1]);
6184 }
6185 for (int32_t i = 0; i < iSize; i++) {
6186 FXJSE_Value_Set(rgValues[i + 2], hResolveValues[i]);
6187 }
6188 FXJSE_Value_SetArray(args.GetReturnValue(), (iSize + 2), rgValues);
6189 for (int32_t i = 0; i < (iSize + 2); i++) {
6190 FXJSE_Value_Release(rgValues[i]);
6191 }
6192 FX_Free(rgValues);
6193 for (int32_t i = 0; i < iSize; i++) {
6194 FXJSE_Value_Release(hResolveValues[i]);
6195 }
6196 FX_Free(hResolveValues);
6197 } else {
6198 CFX_WideString wsPropertyName =
6199 CFX_WideString::FromUTF8(szName, szName.GetLength());
6200 CFX_WideString wsSomExpression =
6201 CFX_WideString::FromUTF8(szSomExp, szSomExp.GetLength());
6202 pContext->ThrowScriptErrorMessage(XFA_IDS_ACCESS_PROPERTY_IN_NOT_OBJECT,
6203 (const FX_WCHAR*)wsPropertyName,
6204 (const FX_WCHAR*)wsSomExpression);
6205 }
6206 }
6207 if (argc == 5) {
6208 FXJSE_Value_Release(argIndex);
6209 }
6210 FXJSE_Value_Release(argAccessor);
6211 } else {
6212 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
6213 }
6214 }
6215 void CXFA_FM2JSContext::dotdot_accessor(FXJSE_HOBJECT hThis,
6216 const CFX_ByteStringC& szFuncName,
6217 CFXJSE_Arguments& args) {
6218 CXFA_FM2JSContext* pContext =
6219 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6220 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
6221 int32_t argc = args.GetLength();
6222 if ((argc == 4) || (argc == 5)) {
6223 FX_BOOL bIsStar = TRUE;
6224 FXJSE_HVALUE argAccessor = args.GetValue(0);
6225 CFX_ByteString bsAccessorName = args.GetUTF8String(1);
6226 CFX_ByteString szName = args.GetUTF8String(2);
6227 int32_t iIndexFlags = args.GetInt32(3);
6228 int32_t iIndexValue = 0;
6229 FXJSE_HVALUE argIndex = NULL;
6230 if (argc == 5) {
6231 bIsStar = FALSE;
6232 argIndex = args.GetValue(4);
6233 iIndexValue = HValueToInteger(hThis, argIndex);
6234 }
6235 CFX_ByteString szSomExp;
6236 GenerateSomExpression(szName, iIndexFlags, iIndexValue, bIsStar, szSomExp);
6237 if (FXJSE_Value_IsArray(argAccessor)) {
6238 FXJSE_HVALUE hLengthValue = FXJSE_Value_Create(hruntime);
6239 FXJSE_Value_GetObjectProp(argAccessor, "length", hLengthValue);
6240 int32_t iLength = FXJSE_Value_ToInteger(hLengthValue);
6241 int32_t iCounter = 0;
6242 FXJSE_HVALUE** hResolveValues = FX_Alloc(FXJSE_HVALUE*, iLength - 2);
6243 int32_t* iSizes = FX_Alloc(int32_t, iLength - 2);
6244 FXJSE_HVALUE hJSObjValue = FXJSE_Value_Create(hruntime);
6245 FX_BOOL bAttribute = FALSE;
6246 for (int32_t i = 2; i < iLength; i++) {
6247 FXJSE_Value_GetObjectPropByIdx(argAccessor, i, hJSObjValue);
6248 XFA_RESOLVENODE_RS resoveNodeRS;
6249 int32_t iRet =
6250 ResolveObjects(hThis, hJSObjValue, szSomExp, resoveNodeRS, FALSE);
6251 if (iRet > 0) {
6252 ParseResolveResult(hThis, resoveNodeRS, hJSObjValue,
6253 hResolveValues[i - 2], iSizes[i - 2], bAttribute);
6254 iCounter += iSizes[i - 2];
6255 }
6256 }
6257 FXJSE_Value_Release(hJSObjValue);
6258 if (iCounter > 0) {
6259 FXJSE_HVALUE* rgValues = FX_Alloc(FXJSE_HVALUE, iCounter + 2);
6260 for (int32_t i = 0; i < (iCounter + 2); i++) {
6261 rgValues[i] = FXJSE_Value_Create(hruntime);
6262 }
6263 FXJSE_Value_SetInteger(rgValues[0], 1);
6264 if (bAttribute) {
6265 FXJSE_Value_SetUTF8String(rgValues[1], szName);
6266 } else {
6267 FXJSE_Value_SetNull(rgValues[1]);
6268 }
6269 int32_t iIndex = 2;
6270 for (int32_t i = 0; i < iLength - 2; i++) {
6271 for (int32_t j = 0; j < iSizes[i]; j++) {
6272 FXJSE_Value_Set(rgValues[iIndex], hResolveValues[i][j]);
6273 iIndex++;
6274 }
6275 }
6276 FXJSE_Value_SetArray(args.GetReturnValue(), (iCounter + 2), rgValues);
6277 for (int32_t i = 0; i < (iCounter + 2); i++) {
6278 FXJSE_Value_Release(rgValues[i]);
6279 }
6280 FX_Free(rgValues);
6281 } else {
6282 CFX_WideString wsPropertyName =
6283 CFX_WideString::FromUTF8(szName, szName.GetLength());
6284 CFX_WideString wsSomExpression =
6285 CFX_WideString::FromUTF8(szSomExp, szSomExp.GetLength());
6286 pContext->ThrowScriptErrorMessage(XFA_IDS_ACCESS_PROPERTY_IN_NOT_OBJECT,
6287 (const FX_WCHAR*)wsPropertyName,
6288 (const FX_WCHAR*)wsSomExpression);
6289 }
6290 for (int32_t i = 0; i < iLength - 2; i++) {
6291 for (int32_t j = 0; j < iSizes[i]; j++) {
6292 FXJSE_Value_Release(hResolveValues[i][j]);
6293 }
6294 FX_Free(hResolveValues[i]);
6295 }
6296 FX_Free(hResolveValues);
6297 FX_Free(iSizes);
6298 FXJSE_Value_Release(hLengthValue);
6299 } else {
6300 XFA_RESOLVENODE_RS resoveNodeRS;
6301 int32_t iRet = 0;
6302 if (FXJSE_Value_IsObject(argAccessor) ||
6303 (FXJSE_Value_IsNull(argAccessor) && bsAccessorName.IsEmpty())) {
6304 iRet =
6305 ResolveObjects(hThis, argAccessor, szSomExp, resoveNodeRS, FALSE);
6306 } else if (!FXJSE_Value_IsObject(argAccessor) &&
6307 !bsAccessorName.IsEmpty()) {
6308 FX_BOOL bGetObject =
6309 GetObjectByName(hThis, argAccessor, bsAccessorName);
6310 if (bGetObject) {
6311 iRet =
6312 ResolveObjects(hThis, argAccessor, szSomExp, resoveNodeRS, FALSE);
6313 }
6314 }
6315 if (iRet > 0) {
6316 FXJSE_HVALUE* hResolveValues;
6317 int32_t iSize = 0;
6318 FX_BOOL bAttribute = FALSE;
6319 ParseResolveResult(hThis, resoveNodeRS, argAccessor, hResolveValues,
6320 iSize, bAttribute);
6321 FXJSE_HVALUE* rgValues = FX_Alloc(FXJSE_HVALUE, iSize + 2);
6322 for (int32_t i = 0; i < (iSize + 2); i++) {
6323 rgValues[i] = FXJSE_Value_Create(hruntime);
6324 }
6325 FXJSE_Value_SetInteger(rgValues[0], 1);
6326 if (bAttribute) {
6327 FXJSE_Value_SetUTF8String(rgValues[1], szName);
6328 } else {
6329 FXJSE_Value_SetNull(rgValues[1]);
6330 }
6331 for (int32_t i = 0; i < iSize; i++) {
6332 FXJSE_Value_Set(rgValues[i + 2], hResolveValues[i]);
6333 }
6334 FXJSE_Value_SetArray(args.GetReturnValue(), (iSize + 2), rgValues);
6335 for (int32_t i = 0; i < (iSize + 2); i++) {
6336 FXJSE_Value_Release(rgValues[i]);
6337 }
6338 FX_Free(rgValues);
6339 for (int32_t i = 0; i < iSize; i++) {
6340 FXJSE_Value_Release(hResolveValues[i]);
6341 }
6342 FX_Free(hResolveValues);
6343 } else {
6344 CFX_WideString wsPropertyName =
6345 CFX_WideString::FromUTF8(szName, szName.GetLength());
6346 CFX_WideString wsSomExpression =
6347 CFX_WideString::FromUTF8(szSomExp, szSomExp.GetLength());
6348 pContext->ThrowScriptErrorMessage(XFA_IDS_ACCESS_PROPERTY_IN_NOT_OBJECT,
6349 (const FX_WCHAR*)wsPropertyName,
6350 (const FX_WCHAR*)wsSomExpression);
6351 }
6352 }
6353 if (argc == 5) {
6354 FXJSE_Value_Release(argIndex);
6355 }
6356 FXJSE_Value_Release(argAccessor);
6357 } else {
6358 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
6359 }
6360 }
6361 void CXFA_FM2JSContext::eval_translation(FXJSE_HOBJECT hThis,
6362 const CFX_ByteStringC& szFuncName,
6363 CFXJSE_Arguments& args) {
6364 CXFA_FM2JSContext* pContext =
6365 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6366 int32_t argc = args.GetLength();
6367 if (argc == 1) {
6368 FXJSE_HVALUE argOne = GetSimpleHValue(hThis, args, 0);
6369 CFX_ByteString argString;
6370 HValueToUTF8String(argOne, argString);
6371 if (argString.IsEmpty()) {
6372 pContext->ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
6373 } else {
6374 CFX_WideString scriptString =
6375 CFX_WideString::FromUTF8(argString, argString.GetLength());
6376 CFX_WideTextBuf wsJavaScriptBuf;
6377 CFX_WideString wsError;
6378 XFA_FM2JS_Translate(scriptString, wsJavaScriptBuf, wsError);
6379 if (wsError.IsEmpty()) {
6380 CFX_WideString javaScript = wsJavaScriptBuf.GetWideString();
6381 FXJSE_Value_SetUTF8String(
6382 args.GetReturnValue(),
6383 FX_UTF8Encode(javaScript, javaScript.GetLength()));
6384 } else {
6385 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
6386 }
6387 }
6388 FXJSE_Value_Release(argOne);
6389 } else {
6390 pContext->ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
6391 L"Eval");
6392 }
6393 }
6394 void CXFA_FM2JSContext::is_fm_object(FXJSE_HOBJECT hThis,
6395 const CFX_ByteStringC& szFuncName,
6396 CFXJSE_Arguments& args) {
6397 int32_t iLength = args.GetLength();
6398 if (iLength == 1) {
6399 FXJSE_HVALUE argOne = args.GetValue(0);
6400 FXJSE_Value_SetBoolean(args.GetReturnValue(), FXJSE_Value_IsObject(argOne));
6401 FXJSE_Value_Release(argOne);
6402 } else {
6403 FXJSE_Value_SetBoolean(args.GetReturnValue(), FALSE);
6404 }
6405 }
6406 void CXFA_FM2JSContext::is_fm_array(FXJSE_HOBJECT hThis,
6407 const CFX_ByteStringC& szFuncName,
6408 CFXJSE_Arguments& args) {
6409 int32_t iLength = args.GetLength();
6410 if (iLength == 1) {
6411 FXJSE_HVALUE argOne = args.GetValue(0);
6412 FX_BOOL bIsArray = FXJSE_Value_IsArray(argOne);
6413 FXJSE_Value_SetBoolean(args.GetReturnValue(), bIsArray);
6414 FXJSE_Value_Release(argOne);
6415 } else {
6416 FXJSE_Value_SetBoolean(args.GetReturnValue(), FALSE);
6417 }
6418 }
6419 void CXFA_FM2JSContext::get_fm_value(FXJSE_HOBJECT hThis,
6420 const CFX_ByteStringC& szFuncName,
6421 CFXJSE_Arguments& args) {
6422 CXFA_FM2JSContext* pContext =
6423 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6424 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
6425 int32_t iLength = args.GetLength();
6426 if (iLength == 1) {
6427 FXJSE_HVALUE argOne = args.GetValue(0);
6428 if (FXJSE_Value_IsArray(argOne)) {
6429 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
6430 FXJSE_HVALUE jsobjectValue = FXJSE_Value_Create(hruntime);
6431 FXJSE_Value_GetObjectPropByIdx(argOne, 1, propertyValue);
6432 FXJSE_Value_GetObjectPropByIdx(argOne, 2, jsobjectValue);
6433 if (FXJSE_Value_IsNull(propertyValue)) {
6434 GetObjectDefaultValue(jsobjectValue, args.GetReturnValue());
6435 } else {
6436 CFX_ByteString propertyStr;
6437 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
6438 FXJSE_Value_GetObjectProp(jsobjectValue, propertyStr,
6439 args.GetReturnValue());
6440 }
6441 FXJSE_Value_Release(propertyValue);
6442 FXJSE_Value_Release(jsobjectValue);
6443 } else if (FXJSE_Value_IsObject(argOne)) {
6444 GetObjectDefaultValue(argOne, args.GetReturnValue());
6445 } else {
6446 FXJSE_Value_Set(args.GetReturnValue(), argOne);
6447 }
6448 FXJSE_Value_Release(argOne);
6449 } else {
6450 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
6451 }
6452 }
6453 void CXFA_FM2JSContext::get_fm_jsobj(FXJSE_HOBJECT hThis,
6454 const CFX_ByteStringC& szFuncName,
6455 CFXJSE_Arguments& args) {
6456 CXFA_FM2JSContext* pContext =
6457 static_cast<CXFA_FM2JSContext*>(FXJSE_Value_ToObject(hThis, nullptr));
6458 int32_t argc = args.GetLength();
6459 if (argc == 1) {
6460 FXJSE_HVALUE argOne = args.GetValue(0);
6461 if (FXJSE_Value_IsArray(argOne)) {
6462 #ifndef NDEBUG
6463 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
6464 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
6465 FXJSE_Value_GetObjectProp(argOne, "length", lengthValue);
6466 FXSYS_assert(FXJSE_Value_ToInteger(lengthValue) >= 3);
6467 FXJSE_Value_Release(lengthValue);
6468 #endif
6469 FXJSE_Value_GetObjectPropByIdx(argOne, 2, args.GetReturnValue());
6470 } else {
6471 FXJSE_Value_Set(args.GetReturnValue(), argOne);
6472 }
6473 FXJSE_Value_Release(argOne);
6474 } else {
6475 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
6476 }
6477 }
6478 void CXFA_FM2JSContext::fm_var_filter(FXJSE_HOBJECT hThis,
6479 const CFX_ByteStringC& szFuncName,
6480 CFXJSE_Arguments& args) {
6481 CXFA_FM2JSContext* pContext =
6482 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6483 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
6484 int32_t argc = args.GetLength();
6485 if (argc == 1) {
6486 FXJSE_HVALUE argOne = args.GetValue(0);
6487 if (FXJSE_Value_IsArray(argOne)) {
6488 #ifndef NDEBUG
6489 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
6490 FXJSE_Value_GetObjectProp(argOne, "length", lengthValue);
6491 FXSYS_assert(FXJSE_Value_ToInteger(lengthValue) >= 3);
6492 FXJSE_Value_Release(lengthValue);
6493 #endif
6494 FXJSE_HVALUE flagsValue = FXJSE_Value_Create(hruntime);
6495 FXJSE_Value_GetObjectPropByIdx(argOne, 0, flagsValue);
6496 int32_t iFlags = FXJSE_Value_ToInteger(flagsValue);
6497 FXJSE_Value_Release(flagsValue);
6498 if (iFlags == 4) {
6499 FXJSE_HVALUE rgValues[3];
6500 for (int32_t i = 0; i < 3; i++) {
6501 rgValues[i] = FXJSE_Value_Create(hruntime);
6502 }
6503 FXJSE_Value_SetInteger(rgValues[0], 3);
6504 FXJSE_Value_SetNull(rgValues[1]);
6505 FXJSE_Value_SetNull(rgValues[2]);
6506 FXJSE_Value_SetArray(args.GetReturnValue(), 3, rgValues);
6507 for (int32_t i = 0; i < 3; i++) {
6508 FXJSE_Value_Release(rgValues[i]);
6509 }
6510 } else if (iFlags == 3) {
6511 FXJSE_HVALUE objectValue = FXJSE_Value_Create(hruntime);
6512 FXJSE_Value_GetObjectPropByIdx(argOne, 2, objectValue);
6513 if (!FXJSE_Value_IsNull(objectValue)) {
6514 FXJSE_Value_Set(args.GetReturnValue(), argOne);
6515 } else {
6516 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
6517 }
6518 FXJSE_Value_Release(objectValue);
6519 } else {
6520 FXJSE_HVALUE simpleValue = GetSimpleHValue(hThis, args, 0);
6521 FXJSE_Value_Set(args.GetReturnValue(), simpleValue);
6522 FXJSE_Value_Release(simpleValue);
6523 }
6524 } else {
6525 FXJSE_HVALUE simpleValue = GetSimpleHValue(hThis, args, 0);
6526 FXJSE_Value_Set(args.GetReturnValue(), simpleValue);
6527 FXJSE_Value_Release(simpleValue);
6528 }
6529 FXJSE_Value_Release(argOne);
6530 } else {
6531 pContext->ThrowScriptErrorMessage(XFA_IDS_COMPILER_ERROR);
6532 }
6533 }
6534 void CXFA_FM2JSContext::concat_fm_object(FXJSE_HOBJECT hThis,
6535 const CFX_ByteStringC& szFuncName,
6536 CFXJSE_Arguments& args) {
6537 CXFA_FM2JSContext* pContext =
6538 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6539 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
6540 uint32_t iLength = 0;
6541 int32_t argCount = args.GetLength();
6542 FXJSE_HVALUE* argValues = FX_Alloc(FXJSE_HVALUE, argCount);
6543 for (int32_t i = 0; i < argCount; i++) {
6544 argValues[i] = args.GetValue(i);
6545 if (FXJSE_Value_IsArray(argValues[i])) {
6546 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
6547 FXJSE_Value_GetObjectProp(argValues[i], "length", lengthValue);
6548 int32_t length = FXJSE_Value_ToInteger(lengthValue);
6549 iLength = iLength + ((length > 2) ? (length - 2) : 0);
6550 FXJSE_Value_Release(lengthValue);
6551 }
6552 iLength += 1;
6553 }
6554 FXJSE_HVALUE* returnValues = FX_Alloc(FXJSE_HVALUE, iLength);
6555 for (int32_t i = 0; i < (int32_t)iLength; i++) {
6556 returnValues[i] = FXJSE_Value_Create(hruntime);
6557 }
6558 int32_t index = 0;
6559 for (int32_t i = 0; i < argCount; i++) {
6560 if (FXJSE_Value_IsArray(argValues[i])) {
6561 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
6562 FXJSE_Value_GetObjectProp(argValues[i], "length", lengthValue);
6563 int32_t length = FXJSE_Value_ToInteger(lengthValue);
6564 for (int32_t j = 2; j < length; j++) {
6565 FXJSE_Value_GetObjectPropByIdx(argValues[i], j, returnValues[index]);
6566 index++;
6567 }
6568 FXJSE_Value_Release(lengthValue);
6569 }
6570 FXJSE_Value_Set(returnValues[index], argValues[i]);
6571 index++;
6572 }
6573 FXJSE_Value_SetArray(args.GetReturnValue(), iLength, returnValues);
6574 for (int32_t i = 0; i < argCount; i++) {
6575 FXJSE_Value_Release(argValues[i]);
6576 }
6577 FX_Free(argValues);
6578 for (int32_t i = 0; i < (int32_t)iLength; i++) {
6579 FXJSE_Value_Release(returnValues[i]);
6580 }
6581 FX_Free(returnValues);
6582 }
6583 FXJSE_HVALUE CXFA_FM2JSContext::GetSimpleHValue(FXJSE_HOBJECT hThis,
6584 CFXJSE_Arguments& args,
6585 uint32_t index) {
6586 CXFA_FM2JSContext* pContext =
6587 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6588 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
6589 FXSYS_assert(index < (uint32_t)args.GetLength());
6590 FXJSE_HVALUE argIndex = args.GetValue(index);
6591 if (FXJSE_Value_IsArray(argIndex)) {
6592 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
6593 FXJSE_Value_GetObjectProp(argIndex, "length", lengthValue);
6594 int32_t iLength = FXJSE_Value_ToInteger(lengthValue);
6595 FXJSE_Value_Release(lengthValue);
6596 FXJSE_HVALUE simpleValue = FXJSE_Value_Create(hruntime);
6597 if (iLength > 2) {
6598 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
6599 FXJSE_HVALUE jsobjectValue = FXJSE_Value_Create(hruntime);
6600 FXJSE_Value_GetObjectPropByIdx(argIndex, 1, propertyValue);
6601 FXJSE_Value_GetObjectPropByIdx(argIndex, 2, jsobjectValue);
6602 if (FXJSE_Value_IsNull(propertyValue)) {
6603 GetObjectDefaultValue(jsobjectValue, simpleValue);
6604 } else {
6605 CFX_ByteString propertyStr;
6606 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
6607 FXJSE_Value_GetObjectProp(jsobjectValue, propertyStr, simpleValue);
6608 }
6609 FXJSE_Value_Release(propertyValue);
6610 FXJSE_Value_Release(jsobjectValue);
6611 } else {
6612 FXJSE_Value_SetUndefined(simpleValue);
6613 }
6614 FXJSE_Value_Release(argIndex);
6615 return simpleValue;
6616 } else if (FXJSE_Value_IsObject(argIndex)) {
6617 FXJSE_HVALUE defaultValue = FXJSE_Value_Create(hruntime);
6618 GetObjectDefaultValue(argIndex, defaultValue);
6619 FXJSE_Value_Release(argIndex);
6620 return defaultValue;
6621 } else {
6622 return argIndex;
6623 }
6624 }
6625 FX_BOOL CXFA_FM2JSContext::HValueIsNull(FXJSE_HOBJECT hThis, FXJSE_HVALUE arg) {
6626 CXFA_FM2JSContext* pContext =
6627 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6628 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
6629 FX_BOOL isNull = FALSE;
6630 if (FXJSE_Value_IsNull(arg)) {
6631 isNull = TRUE;
6632 } else if (FXJSE_Value_IsArray(arg)) {
6633 int32_t iLength = hvalue_get_array_length(hThis, arg);
6634 if (iLength > 2) {
6635 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
6636 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
6637 FXJSE_Value_GetObjectPropByIdx(arg, 1, propertyValue);
6638 FXJSE_Value_GetObjectPropByIdx(arg, 2, jsObjectValue);
6639 if (FXJSE_Value_IsNull(propertyValue)) {
6640 FXJSE_HVALUE defaultValue = FXJSE_Value_Create(hruntime);
6641 GetObjectDefaultValue(jsObjectValue, defaultValue);
6642 if (FXJSE_Value_IsNull(defaultValue)) {
6643 isNull = TRUE;
6644 }
6645 FXJSE_Value_Release(defaultValue);
6646 } else {
6647 CFX_ByteString propertyStr;
6648 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
6649 FXJSE_HVALUE newPropertyValue = FXJSE_Value_Create(hruntime);
6650 FXJSE_Value_GetObjectProp(jsObjectValue, propertyStr, newPropertyValue);
6651 if (FXJSE_Value_IsNull(newPropertyValue)) {
6652 isNull = TRUE;
6653 }
6654 FXJSE_Value_Release(newPropertyValue);
6655 }
6656 FXJSE_Value_Release(propertyValue);
6657 FXJSE_Value_Release(jsObjectValue);
6658 } else {
6659 isNull = TRUE;
6660 }
6661 } else if (FXJSE_Value_IsObject(arg)) {
6662 FXJSE_HVALUE defaultValue = FXJSE_Value_Create(hruntime);
6663 GetObjectDefaultValue(arg, defaultValue);
6664 if (FXJSE_Value_IsNull(defaultValue)) {
6665 isNull = TRUE;
6666 }
6667 FXJSE_Value_Release(defaultValue);
6668 }
6669 return isNull;
6670 }
6671 int32_t CXFA_FM2JSContext::hvalue_get_array_length(FXJSE_HOBJECT hThis,
6672 FXJSE_HVALUE arg) {
6673 CXFA_FM2JSContext* pContext =
6674 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6675 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
6676 int32_t iLength = 0;
6677 if (FXJSE_Value_IsArray(arg)) {
6678 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
6679 FXJSE_Value_GetObjectProp(arg, "length", lengthValue);
6680 iLength = FXJSE_Value_ToInteger(lengthValue);
6681 FXJSE_Value_Release(lengthValue);
6682 }
6683 return iLength;
6684 }
6685 FX_BOOL CXFA_FM2JSContext::simpleValueCompare(FXJSE_HOBJECT hThis,
6686 FXJSE_HVALUE firstValue,
6687 FXJSE_HVALUE secondValue) {
6688 FX_BOOL bReturn = FALSE;
6689 if (FXJSE_Value_IsUTF8String(firstValue)) {
6690 CFX_ByteString firstString, secondString;
6691 HValueToUTF8String(firstValue, firstString);
6692 HValueToUTF8String(secondValue, secondString);
6693 bReturn = firstString.Equal(secondString);
6694 } else if (FXJSE_Value_IsNumber(firstValue)) {
6695 FX_FLOAT first = HValueToFloat(hThis, firstValue);
6696 FX_FLOAT second = HValueToFloat(hThis, secondValue);
6697 bReturn = (first == second);
6698 } else if (FXJSE_Value_IsBoolean(firstValue)) {
6699 bReturn = (FXJSE_Value_ToBoolean(firstValue) ==
6700 FXJSE_Value_ToBoolean(secondValue));
6701 } else if (FXJSE_Value_IsNull(firstValue) &&
6702 FXJSE_Value_IsNull(secondValue)) {
6703 bReturn = TRUE;
6704 }
6705 return bReturn;
6706 }
6707 void CXFA_FM2JSContext::unfoldArgs(FXJSE_HOBJECT hThis,
6708 CFXJSE_Arguments& args,
6709 FXJSE_HVALUE*& resultValues,
6710 int32_t& iCount,
6711 int32_t iStart) {
6712 CXFA_FM2JSContext* pContext =
6713 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6714 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
6715 iCount = 0;
6716 int32_t argc = args.GetLength();
6717 FXJSE_HVALUE* argsValue = FX_Alloc(FXJSE_HVALUE, argc);
6718 for (int32_t i = iStart; i < argc; i++) {
6719 argsValue[i] = args.GetValue(i);
6720 if (FXJSE_Value_IsArray(argsValue[i])) {
6721 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
6722 FXJSE_Value_GetObjectProp(argsValue[i], "length", lengthValue);
6723 int32_t iLength = FXJSE_Value_ToInteger(lengthValue);
6724 FXJSE_Value_Release(lengthValue);
6725 iCount += ((iLength > 2) ? (iLength - 2) : 0);
6726 } else {
6727 iCount += 1;
6728 }
6729 }
6730 resultValues = FX_Alloc(FXJSE_HVALUE, iCount);
6731 for (int32_t i = 0; i < iCount; i++) {
6732 resultValues[i] = FXJSE_Value_Create(hruntime);
6733 }
6734 int32_t index = 0;
6735 for (int32_t i = iStart; i < argc; i++) {
6736 if (FXJSE_Value_IsArray(argsValue[i])) {
6737 FXJSE_HVALUE lengthValue = FXJSE_Value_Create(hruntime);
6738 FXJSE_Value_GetObjectProp(argsValue[i], "length", lengthValue);
6739 int32_t iLength = FXJSE_Value_ToInteger(lengthValue);
6740 FXJSE_Value_Release(lengthValue);
6741 if (iLength > 2) {
6742 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
6743 FXJSE_HVALUE jsObjectValue = FXJSE_Value_Create(hruntime);
6744 FXJSE_Value_GetObjectPropByIdx(argsValue[i], 1, propertyValue);
6745 if (FXJSE_Value_IsNull(propertyValue)) {
6746 for (int32_t j = 2; j < iLength; j++) {
6747 FXJSE_Value_GetObjectPropByIdx(argsValue[i], j, jsObjectValue);
6748 GetObjectDefaultValue(jsObjectValue, resultValues[index]);
6749 index++;
6750 }
6751 } else {
6752 CFX_ByteString propertyString;
6753 FXJSE_Value_ToUTF8String(propertyValue, propertyString);
6754 for (int32_t j = 2; j < iLength; j++) {
6755 FXJSE_Value_GetObjectPropByIdx(argsValue[i], j, jsObjectValue);
6756 FXJSE_Value_GetObjectProp(jsObjectValue, propertyString,
6757 resultValues[index]);
6758 index++;
6759 }
6760 }
6761 FXJSE_Value_Release(propertyValue);
6762 FXJSE_Value_Release(jsObjectValue);
6763 }
6764 } else if (FXJSE_Value_IsObject(argsValue[i])) {
6765 GetObjectDefaultValue(argsValue[i], resultValues[index]);
6766 index++;
6767 } else {
6768 FXJSE_Value_Set(resultValues[index], argsValue[i]);
6769 index++;
6770 }
6771 }
6772 for (int32_t i = iStart; i < argc; i++) {
6773 FXJSE_Value_Release(argsValue[i]);
6774 }
6775 FX_Free(argsValue);
6776 }
6777 void CXFA_FM2JSContext::GetObjectDefaultValue(FXJSE_HVALUE hObjectValue,
6778 FXJSE_HVALUE hDefaultValue) {
6779 CXFA_Node* pNode =
6780 ToNode((CXFA_Object*)FXJSE_Value_ToObject(hObjectValue, NULL));
6781 if (pNode) {
6782 pNode->Script_Som_DefaultValue(hDefaultValue, FALSE, (XFA_ATTRIBUTE)-1);
6783 } else {
6784 FXJSE_Value_SetNull(hDefaultValue);
6785 }
6786 }
6787 FX_BOOL CXFA_FM2JSContext::SetObjectDefaultValue(FXJSE_HVALUE hObjectValue,
6788 FXJSE_HVALUE hNewValue) {
6789 CXFA_Node* pNode =
6790 ToNode((CXFA_Object*)FXJSE_Value_ToObject(hObjectValue, NULL));
6791 if (pNode) {
6792 pNode->Script_Som_DefaultValue(hNewValue, TRUE, (XFA_ATTRIBUTE)-1);
6793 return TRUE;
6794 }
6795 return FALSE;
6796 }
6797 void CXFA_FM2JSContext::GenerateSomExpression(const CFX_ByteStringC& szName,
6798 int32_t iIndexFlags,
6799 int32_t iIndexValue,
6800 FX_BOOL bIsStar,
6801 CFX_ByteString& szSomExp) {
6802 if (bIsStar) {
6803 szSomExp = szName + "[*]";
6804 return;
6805 }
6806 if (iIndexFlags == 0) {
6807 szSomExp = szName;
6808 return;
6809 }
6810 if (iIndexFlags == 1 || iIndexValue == 0) {
6811 szSomExp = szName + "[" +
6812 CFX_ByteString::FormatInteger(iIndexValue, FXFORMAT_SIGNED) +
6813 "]";
6814 } else if (iIndexFlags == 2) {
6815 szSomExp = (iIndexValue < 0) ? (szName + "[-") : (szName + "[+");
6816 iIndexValue = (iIndexValue < 0) ? (0 - iIndexValue) : iIndexValue;
6817 szSomExp += CFX_ByteString::FormatInteger(iIndexValue);
6818 szSomExp += "]";
6819 } else {
6820 szSomExp = (iIndexValue < 0) ? (szName + "[") : (szName + "[-");
6821 iIndexValue = (iIndexValue < 0) ? (0 - iIndexValue) : iIndexValue;
6822 szSomExp += CFX_ByteString::FormatInteger(iIndexValue);
6823 szSomExp += "]";
6824 }
6825 }
6826 FX_BOOL CXFA_FM2JSContext::GetObjectByName(
6827 FXJSE_HOBJECT hThis,
6828 FXJSE_HVALUE accessorValue,
6829 const CFX_ByteStringC& szAccessorName) {
6830 FX_BOOL bFlags = FALSE;
6831 CXFA_FM2JSContext* pContext =
6832 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6833 CXFA_Document* pDoc = pContext->GetDocument();
6834 if (!pDoc) {
6835 return bFlags;
6836 }
6837 IXFA_ScriptContext* pScriptContext = pDoc->GetScriptContext();
6838 XFA_RESOLVENODE_RS resoveNodeRS;
6839 FX_DWORD dwFlags = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties |
6840 XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent;
6841 int32_t iRet = pScriptContext->ResolveObjects(
6842 pScriptContext->GetThisObject(),
6843 CFX_WideString::FromUTF8(szAccessorName.GetCStr(),
6844 szAccessorName.GetLength()),
6845 resoveNodeRS, dwFlags);
6846 if (iRet >= 1 && resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
6847 FXJSE_Value_Set(accessorValue, pScriptContext->GetJSValueFromMap(
6848 resoveNodeRS.nodes.GetAt(0)));
6849 bFlags = TRUE;
6850 }
6851 return bFlags;
6852 }
6853 int32_t CXFA_FM2JSContext::ResolveObjects(FXJSE_HOBJECT hThis,
6854 FXJSE_HVALUE hRefValue,
6855 const CFX_ByteStringC& bsSomExp,
6856 XFA_RESOLVENODE_RS& resoveNodeRS,
6857 FX_BOOL bdotAccessor,
6858 FX_BOOL bHasNoResolveName) {
6859 CFX_WideString wsSomExpression =
6860 CFX_WideString::FromUTF8(bsSomExp.GetCStr(), bsSomExp.GetLength());
6861 int32_t iRet = -1;
6862 CXFA_FM2JSContext* pContext =
6863 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6864 CXFA_Document* pDoc = pContext->GetDocument();
6865 if (!pDoc) {
6866 return iRet;
6867 }
6868 IXFA_ScriptContext* pScriptContext = pDoc->GetScriptContext();
6869 CXFA_Object* pNode = NULL;
6870 FX_DWORD dFlags = 0UL;
6871 if (bdotAccessor) {
6872 if (FXJSE_Value_IsNull(hRefValue)) {
6873 pNode = pScriptContext->GetThisObject();
6874 dFlags = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent;
6875 } else {
6876 pNode = (CXFA_Object*)FXJSE_Value_ToObject(hRefValue, NULL);
6877 FXSYS_assert(pNode);
6878 if (bHasNoResolveName) {
6879 CFX_WideString wsName;
6880 if (CXFA_Node* pXFANode = pNode->AsNode()) {
6881 pXFANode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, FALSE);
6882 }
6883 if (wsName.IsEmpty()) {
6884 CFX_WideStringC className;
6885 pNode->GetClassName(className);
6886 wsName = FX_WSTRC(L"#") + className;
6887 }
6888 wsSomExpression = wsName + wsSomExpression;
6889 dFlags = XFA_RESOLVENODE_Siblings;
6890 } else {
6891 dFlags = (bsSomExp == "*")
6892 ? (XFA_RESOLVENODE_Children)
6893 : (XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
6894 XFA_RESOLVENODE_Properties);
6895 }
6896 }
6897 } else {
6898 pNode = (CXFA_Object*)FXJSE_Value_ToObject(hRefValue, NULL);
6899 dFlags = XFA_RESOLVENODE_AnyChild;
6900 }
6901 iRet = pScriptContext->ResolveObjects(pNode, wsSomExpression, resoveNodeRS,
6902 dFlags);
6903 return iRet;
6904 }
6905 void CXFA_FM2JSContext::ParseResolveResult(
6906 FXJSE_HOBJECT hThis,
6907 const XFA_RESOLVENODE_RS& resoveNodeRS,
6908 FXJSE_HVALUE hParentValue,
6909 FXJSE_HVALUE*& resultValues,
6910 int32_t& iSize,
6911 FX_BOOL& bAttribute) {
6912 CXFA_FM2JSContext* pContext =
6913 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6914 FXJSE_HRUNTIME hRuntime = pContext->GetScriptRuntime();
6915 iSize = 0;
6916 resultValues = NULL;
6917 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
6918 bAttribute = FALSE;
6919 iSize = resoveNodeRS.nodes.GetSize();
6920 resultValues = FX_Alloc(FXJSE_HVALUE, iSize);
6921 for (int32_t i = 0; i < iSize; i++) {
6922 resultValues[i] = FXJSE_Value_Create(hRuntime);
6923 FXJSE_Value_Set(
6924 resultValues[i],
6925 pContext->GetDocument()->GetScriptContext()->GetJSValueFromMap(
6926 resoveNodeRS.nodes.GetAt(i)));
6927 }
6928 } else {
6929 CXFA_HVALUEArray objectProperties(hRuntime);
6930 int32_t iRet = resoveNodeRS.GetAttributeResult(objectProperties);
6931 bAttribute = (iRet == 0);
6932 if (bAttribute) {
6933 if (FXJSE_Value_IsObject(hParentValue)) {
6934 iSize = 1;
6935 resultValues = FX_Alloc(FXJSE_HVALUE, 1);
6936 resultValues[0] = FXJSE_Value_Create(hRuntime);
6937 FXJSE_Value_Set(resultValues[0], hParentValue);
6938 }
6939 } else {
6940 iSize = iRet;
6941 resultValues = FX_Alloc(FXJSE_HVALUE, iSize);
6942 for (int32_t i = 0; i < iSize; i++) {
6943 resultValues[i] = FXJSE_Value_Create(hRuntime);
6944 FXJSE_Value_Set(resultValues[i], objectProperties[i]);
6945 }
6946 }
6947 }
6948 }
6949 int32_t CXFA_FM2JSContext::HValueToInteger(FXJSE_HOBJECT hThis,
6950 FXJSE_HVALUE hValue) {
6951 CXFA_FM2JSContext* pContext =
6952 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6953 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
6954 int32_t iValue = 0;
6955 if (FXJSE_Value_IsArray(hValue)) {
6956 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
6957 FXJSE_HVALUE jsobjectValue = FXJSE_Value_Create(hruntime);
6958 FXJSE_HVALUE newProperty = FXJSE_Value_Create(hruntime);
6959 FXJSE_Value_GetObjectPropByIdx(hValue, 1, propertyValue);
6960 FXJSE_Value_GetObjectPropByIdx(hValue, 2, jsobjectValue);
6961 if (FXJSE_Value_IsNull(propertyValue)) {
6962 GetObjectDefaultValue(jsobjectValue, newProperty);
6963 } else {
6964 CFX_ByteString propertyStr;
6965 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
6966 FXJSE_Value_GetObjectProp(jsobjectValue, propertyStr, newProperty);
6967 }
6968 iValue = HValueToInteger(hThis, newProperty);
6969 FXJSE_Value_Release(newProperty);
6970 FXJSE_Value_Release(jsobjectValue);
6971 FXJSE_Value_Release(propertyValue);
6972 return iValue;
6973 } else if (FXJSE_Value_IsObject(hValue)) {
6974 FXJSE_HVALUE newProperty = FXJSE_Value_Create(hruntime);
6975 GetObjectDefaultValue(hValue, newProperty);
6976 iValue = HValueToInteger(hThis, newProperty);
6977 FXJSE_Value_Release(newProperty);
6978 return iValue;
6979 } else if (FXJSE_Value_IsUTF8String(hValue)) {
6980 CFX_ByteString szValue;
6981 FXJSE_Value_ToUTF8String(hValue, szValue);
6982 iValue = FXSYS_atoi(szValue);
6983 } else {
6984 iValue = FXJSE_Value_ToInteger(hValue);
6985 }
6986 return iValue;
6987 }
6988 FX_DOUBLE CXFA_FM2JSContext::StringToDouble(
6989 const CFX_ByteStringC& szStringVal) {
6990 return XFA_ByteStringToDouble(szStringVal);
6991 }
6992 FX_FLOAT CXFA_FM2JSContext::HValueToFloat(FXJSE_HOBJECT hThis,
6993 FXJSE_HVALUE arg) {
6994 CXFA_FM2JSContext* pContext =
6995 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
6996 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
6997 FX_FLOAT fRet = 0.0f;
6998 if (FXJSE_Value_IsArray(arg)) {
6999 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
7000 FXJSE_HVALUE jsobjectValue = FXJSE_Value_Create(hruntime);
7001 FXJSE_HVALUE newProperty = FXJSE_Value_Create(hruntime);
7002 FXJSE_Value_GetObjectPropByIdx(arg, 1, propertyValue);
7003 FXJSE_Value_GetObjectPropByIdx(arg, 2, jsobjectValue);
7004 if (FXJSE_Value_IsNull(propertyValue)) {
7005 GetObjectDefaultValue(jsobjectValue, newProperty);
7006 } else {
7007 CFX_ByteString propertyStr;
7008 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
7009 FXJSE_Value_GetObjectProp(jsobjectValue, propertyStr, newProperty);
7010 }
7011 fRet = HValueToFloat(hThis, newProperty);
7012 FXJSE_Value_Release(newProperty);
7013 FXJSE_Value_Release(jsobjectValue);
7014 FXJSE_Value_Release(propertyValue);
7015 } else if (FXJSE_Value_IsObject(arg)) {
7016 FXJSE_HVALUE newProperty = FXJSE_Value_Create(hruntime);
7017 GetObjectDefaultValue(arg, newProperty);
7018 fRet = HValueToFloat(hThis, newProperty);
7019 FXJSE_Value_Release(newProperty);
7020 } else if (FXJSE_Value_IsUTF8String(arg)) {
7021 CFX_ByteString bsOutput;
7022 FXJSE_Value_ToUTF8String(arg, bsOutput);
7023 fRet = (FX_FLOAT)StringToDouble(bsOutput);
7024 } else if (FXJSE_Value_IsUndefined(arg)) {
7025 fRet = 0;
7026 } else {
7027 fRet = FXJSE_Value_ToFloat(arg);
7028 }
7029 return fRet;
7030 }
7031 FX_DOUBLE CXFA_FM2JSContext::HValueToDouble(FXJSE_HOBJECT hThis,
7032 FXJSE_HVALUE arg) {
7033 CXFA_FM2JSContext* pContext =
7034 (CXFA_FM2JSContext*)FXJSE_Value_ToObject(hThis, NULL);
7035 FXJSE_HRUNTIME hruntime = pContext->GetScriptRuntime();
7036 FX_DOUBLE dRet = 0;
7037 if (FXJSE_Value_IsArray(arg)) {
7038 FXJSE_HVALUE propertyValue = FXJSE_Value_Create(hruntime);
7039 FXJSE_HVALUE jsobjectValue = FXJSE_Value_Create(hruntime);
7040 FXJSE_HVALUE newProperty = FXJSE_Value_Create(hruntime);
7041 FXJSE_Value_GetObjectPropByIdx(arg, 1, propertyValue);
7042 FXJSE_Value_GetObjectPropByIdx(arg, 2, jsobjectValue);
7043 if (FXJSE_Value_IsNull(propertyValue)) {
7044 GetObjectDefaultValue(jsobjectValue, newProperty);
7045 } else {
7046 CFX_ByteString propertyStr;
7047 FXJSE_Value_ToUTF8String(propertyValue, propertyStr);
7048 FXJSE_Value_GetObjectProp(jsobjectValue, propertyStr, newProperty);
7049 }
7050 dRet = HValueToDouble(hThis, newProperty);
7051 FXJSE_Value_Release(newProperty);
7052 FXJSE_Value_Release(jsobjectValue);
7053 FXJSE_Value_Release(propertyValue);
7054 } else if (FXJSE_Value_IsObject(arg)) {
7055 FXJSE_HVALUE newProperty = FXJSE_Value_Create(hruntime);
7056 GetObjectDefaultValue(arg, newProperty);
7057 dRet = HValueToDouble(hThis, newProperty);
7058 FXJSE_Value_Release(newProperty);
7059 } else if (FXJSE_Value_IsUTF8String(arg)) {
7060 CFX_ByteString bsOutput;
7061 FXJSE_Value_ToUTF8String(arg, bsOutput);
7062 dRet = StringToDouble(bsOutput);
7063 } else if (FXJSE_Value_IsUndefined(arg)) {
7064 dRet = 0;
7065 } else {
7066 dRet = FXJSE_Value_ToDouble(arg);
7067 }
7068 return dRet;
7069 }
7070 void CXFA_FM2JSContext::HValueToUTF8String(FXJSE_HVALUE arg,
7071 CFX_ByteString& szOutputString) {
7072 if (FXJSE_Value_IsNull(arg) || FXJSE_Value_IsUndefined(arg)) {
7073 szOutputString = "";
7074 } else if (FXJSE_Value_IsBoolean(arg)) {
7075 szOutputString = FXJSE_Value_ToBoolean(arg) ? "1" : "0";
7076 } else {
7077 szOutputString = "";
7078 FXJSE_Value_ToUTF8String(arg, szOutputString);
7079 }
7080 }
7081 static FXJSE_FUNCTION formcalc_fm2js_functions[] = {
7082 {"Abs", CXFA_FM2JSContext::Abs},
7083 {"Avg", CXFA_FM2JSContext::Avg},
7084 {"Ceil", CXFA_FM2JSContext::Ceil},
7085 {"Count", CXFA_FM2JSContext::Count},
7086 {"Floor", CXFA_FM2JSContext::Floor},
7087 {"Max", CXFA_FM2JSContext::Max},
7088 {"Min", CXFA_FM2JSContext::Min},
7089 {"Mod", CXFA_FM2JSContext::Mod},
7090 {"Round", CXFA_FM2JSContext::Round},
7091 {"Sum", CXFA_FM2JSContext::Sum},
7092 {"Date", CXFA_FM2JSContext::Date},
7093 {"Date2Num", CXFA_FM2JSContext::Date2Num},
7094 {"DateFmt", CXFA_FM2JSContext::DateFmt},
7095 {"IsoDate2Num", CXFA_FM2JSContext::IsoDate2Num},
7096 {"IsoTime2Num", CXFA_FM2JSContext::IsoTime2Num},
7097 {"LocalDateFmt", CXFA_FM2JSContext::LocalDateFmt},
7098 {"LocalTimeFmt", CXFA_FM2JSContext::LocalTimeFmt},
7099 {"Num2Date", CXFA_FM2JSContext::Num2Date},
7100 {"Num2GMTime", CXFA_FM2JSContext::Num2GMTime},
7101 {"Num2Time", CXFA_FM2JSContext::Num2Time},
7102 {"Time", CXFA_FM2JSContext::Time},
7103 {"Time2Num", CXFA_FM2JSContext::Time2Num},
7104 {"TimeFmt", CXFA_FM2JSContext::TimeFmt},
7105 {"Apr", CXFA_FM2JSContext::Apr},
7106 {"Cterm", CXFA_FM2JSContext::CTerm},
7107 {"FV", CXFA_FM2JSContext::FV},
7108 {"Ipmt", CXFA_FM2JSContext::IPmt},
7109 {"NPV", CXFA_FM2JSContext::NPV},
7110 {"Pmt", CXFA_FM2JSContext::Pmt},
7111 {"PPmt", CXFA_FM2JSContext::PPmt},
7112 {"PV", CXFA_FM2JSContext::PV},
7113 {"Rate", CXFA_FM2JSContext::Rate},
7114 {"Term", CXFA_FM2JSContext::Term},
7115 {"Choose", CXFA_FM2JSContext::Choose},
7116 {"Exists", CXFA_FM2JSContext::Exists},
7117 {"HasValue", CXFA_FM2JSContext::HasValue},
7118 {"Oneof", CXFA_FM2JSContext::Oneof},
7119 {"Within", CXFA_FM2JSContext::Within},
7120 {"If", CXFA_FM2JSContext::If},
7121 {"Eval", CXFA_FM2JSContext::Eval},
7122 {"Translate", CXFA_FM2JSContext::eval_translation},
7123 {"Ref", CXFA_FM2JSContext::Ref},
7124 {"UnitType", CXFA_FM2JSContext::UnitType},
7125 {"UnitValue", CXFA_FM2JSContext::UnitValue},
7126 {"At", CXFA_FM2JSContext::At},
7127 {"Concat", CXFA_FM2JSContext::Concat},
7128 {"Decode", CXFA_FM2JSContext::Decode},
7129 {"Encode", CXFA_FM2JSContext::Encode},
7130 {"Format", CXFA_FM2JSContext::Format},
7131 {"Left", CXFA_FM2JSContext::Left},
7132 {"Len", CXFA_FM2JSContext::Len},
7133 {"Lower", CXFA_FM2JSContext::Lower},
7134 {"Ltrim", CXFA_FM2JSContext::Ltrim},
7135 {"Parse", CXFA_FM2JSContext::Parse},
7136 {"Replace", CXFA_FM2JSContext::Replace},
7137 {"Right", CXFA_FM2JSContext::Right},
7138 {"Rtrim", CXFA_FM2JSContext::Rtrim},
7139 {"Space", CXFA_FM2JSContext::Space},
7140 {"Str", CXFA_FM2JSContext::Str},
7141 {"Stuff", CXFA_FM2JSContext::Stuff},
7142 {"Substr", CXFA_FM2JSContext::Substr},
7143 {"Uuid", CXFA_FM2JSContext::Uuid},
7144 {"Upper", CXFA_FM2JSContext::Upper},
7145 {"WordNum", CXFA_FM2JSContext::WordNum},
7146 {"Get", CXFA_FM2JSContext::Get},
7147 {"Post", CXFA_FM2JSContext::Post},
7148 {"Put", CXFA_FM2JSContext::Put},
7149 {"positive_operator", CXFA_FM2JSContext::positive_operator},
7150 {"negative_operator", CXFA_FM2JSContext::negative_operator},
7151 {"logical_or_operator", CXFA_FM2JSContext::logical_or_operator},
7152 {"logical_and_operator", CXFA_FM2JSContext::logical_and_operator},
7153 {"logical_not_operator", CXFA_FM2JSContext::logical_not_operator},
7154 {"equality_operator", CXFA_FM2JSContext::equality_operator},
7155 {"notequality_operator", CXFA_FM2JSContext::notequality_operator},
7156 {"less_operator", CXFA_FM2JSContext::less_operator},
7157 {"lessequal_operator", CXFA_FM2JSContext::lessequal_operator},
7158 {"greater_operator", CXFA_FM2JSContext::greater_operator},
7159 {"greaterequal_operator", CXFA_FM2JSContext::greaterequal_operator},
7160 {"plus_operator", CXFA_FM2JSContext::plus_operator},
7161 {"minus_operator", CXFA_FM2JSContext::minus_operator},
7162 {"multiple_operator", CXFA_FM2JSContext::multiple_operator},
7163 {"divide_operator", CXFA_FM2JSContext::divide_operator},
7164 {"assign_value_operator", CXFA_FM2JSContext::assign_value_operator},
7165 {"dot_accessor", CXFA_FM2JSContext::dot_accessor},
7166 {"dotdot_accessor", CXFA_FM2JSContext::dotdot_accessor},
7167 {"concat_fm_object", CXFA_FM2JSContext::concat_fm_object},
7168 {"is_fm_object", CXFA_FM2JSContext::is_fm_object},
7169 {"is_fm_array", CXFA_FM2JSContext::is_fm_array},
7170 {"get_fm_value", CXFA_FM2JSContext::get_fm_value},
7171 {"get_fm_jsobj", CXFA_FM2JSContext::get_fm_jsobj},
7172 {"fm_var_filter", CXFA_FM2JSContext::fm_var_filter},
7173 };
7174 CXFA_FM2JSContext::CXFA_FM2JSContext()
7175 : m_hFMClass(nullptr), m_pDocument(nullptr) {
7176 FXSYS_memset(&m_fmClass, 0, sizeof(FXJSE_CLASS));
7177 }
7178 CXFA_FM2JSContext::~CXFA_FM2JSContext() {
7179 m_pDocument = NULL;
7180 if (m_hValue) {
7181 FXJSE_Value_Release(m_hValue);
7182 m_hValue = NULL;
7183 }
7184 m_hScriptRuntime = NULL;
7185 }
7186 CXFA_FM2JSContext* CXFA_FM2JSContext::Create() {
7187 return new CXFA_FM2JSContext;
7188 }
7189 void CXFA_FM2JSContext::Initialize(FXJSE_HRUNTIME hScriptRuntime,
7190 FXJSE_HCONTEXT hScriptContext,
7191 CXFA_Document* pDoc) {
7192 m_pDocument = pDoc;
7193 m_hScriptRuntime = hScriptRuntime;
7194 m_fmClass.name = "XFA_FM2JS_FormCalcClass";
7195 m_fmClass.constructor = NULL;
7196 m_fmClass.properties = NULL;
7197 m_fmClass.methods = formcalc_fm2js_functions;
7198 m_fmClass.propNum = 0;
7199 m_fmClass.methNum =
7200 sizeof(formcalc_fm2js_functions) / sizeof(formcalc_fm2js_functions[0]);
7201 m_hFMClass = FXJSE_DefineClass(hScriptContext, &m_fmClass);
7202 m_hValue = FXJSE_Value_Create(hScriptRuntime);
7203 FXJSE_Value_SetNull(m_hValue);
7204 FXJSE_Value_SetObject(m_hValue, this, m_hFMClass);
7205 }
7206 void CXFA_FM2JSContext::GlobalPropertyGetter(FXJSE_HVALUE hValue) {
7207 FXJSE_Value_Set(hValue, m_hValue);
7208 }
7209 void CXFA_FM2JSContext::Release() {
7210 delete this;
7211 }
7212 void CXFA_FM2JSContext::ThrowScriptErrorMessage(int32_t iStringID, ...) {
7213 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();
7214 FXSYS_assert(pAppProvider);
7215 CFX_WideString wsFormat;
7216 pAppProvider->LoadString(iStringID, wsFormat);
7217 CFX_WideString wsMessage;
7218 va_list arg_ptr;
7219 va_start(arg_ptr, iStringID);
7220 wsMessage.FormatV((const FX_WCHAR*)wsFormat, arg_ptr);
7221 va_end(arg_ptr);
7222 FXJSE_ThrowMessage("", FX_UTF8Encode(wsMessage, wsMessage.GetLength()));
7223 }
OLDNEW
« no previous file with comments | « xfa/src/fxfa/fm2js/xfa_fm2jscontext.h ('k') | xfa/src/fxfa/fm2js/xfa_fmparse.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698