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