| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../include/javascript/JavaScript.h" | 7 #include "../../include/javascript/JavaScript.h" |
| 8 #include "../../include/javascript/IJavaScript.h" | 8 #include "../../include/javascript/IJavaScript.h" |
| 9 #include "../../include/javascript/JS_Define.h" | 9 #include "../../include/javascript/JS_Define.h" |
| 10 #include "../../include/javascript/JS_Object.h" | 10 #include "../../include/javascript/JS_Object.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 JS_STATIC_CONST_ENTRY_STRING(L"fitH", L"FitHeight") | 122 JS_STATIC_CONST_ENTRY_STRING(L"fitH", L"FitHeight") |
| 123 JS_STATIC_CONST_ENTRY_STRING(L"fitV", L"FitVisibleWidth") | 123 JS_STATIC_CONST_ENTRY_STRING(L"fitV", L"FitVisibleWidth") |
| 124 JS_STATIC_CONST_ENTRY_STRING(L"pref", L"Preferred") | 124 JS_STATIC_CONST_ENTRY_STRING(L"pref", L"Preferred") |
| 125 JS_STATIC_CONST_ENTRY_STRING(L"refW", L"ReflowWidth") | 125 JS_STATIC_CONST_ENTRY_STRING(L"refW", L"ReflowWidth") |
| 126 END_JS_STATIC_CONST() | 126 END_JS_STATIC_CONST() |
| 127 | 127 |
| 128 IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype, zoomtype) | 128 IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype, zoomtype) |
| 129 | 129 |
| 130 /* ------------------------------ CJS_GlobalConsts ------------------------- */ | 130 /* ------------------------------ CJS_GlobalConsts ------------------------- */ |
| 131 | 131 |
| 132 #define DEFINE_GLOBAL_CONST(pIsolate, const_name, const_value) \ | 132 static void DefineGlobalConstString(v8::Isolate* pIsolate, |
| 133 if (JS_DefineGlobalConst( \ | 133 const wchar_t* pConstName, |
| 134 pIsolate, JS_WIDESTRING(const_name), \ | 134 const wchar_t* pValue) { |
| 135 JS_NewString(pIsolate, JS_WIDESTRING(const_value)))) { \ | 135 JS_DefineGlobalConst(pIsolate, pConstName, JS_NewString(pIsolate, pValue)); |
| 136 return -1; \ | 136 } |
| 137 } | |
| 138 | 137 |
| 139 int CJS_GlobalConsts::DefineJSObjects(v8::Isolate* pIsolate) { | 138 void CJS_GlobalConsts::DefineJSObjects(v8::Isolate* pIsolate) { |
| 140 DEFINE_GLOBAL_CONST(pIsolate, IDS_GREATER_THAN, Invalid value | 139 DefineGlobalConstString( |
| 141 : must be greater than or equal to % s.); | 140 pIsolate, L"IDS_GREATER_THAN", |
| 142 DEFINE_GLOBAL_CONST( | 141 L"Invalid value: must be greater than or equal to % s."); |
| 143 pIsolate, IDS_GT_AND_LT, Invalid value | 142 DefineGlobalConstString( |
| 144 : must be greater than or equal to % s and less than or equal to % s.); | 143 pIsolate, L"IDS_GT_AND_LT", |
| 145 DEFINE_GLOBAL_CONST(pIsolate, IDS_LESS_THAN, Invalid value | 144 L"Invalid value: must be greater than or equal to % s " |
| 146 : must be less than or equal to % s.); | 145 L"and less than or equal to % s."); |
| 147 DEFINE_GLOBAL_CONST(pIsolate, IDS_INVALID_MONTH, **Invalid**); | 146 DefineGlobalConstString(pIsolate, L"IDS_LESS_THAN", |
| 148 DEFINE_GLOBAL_CONST(pIsolate, IDS_INVALID_DATE, Invalid date / time | 147 L"Invalid value: must be less than or equal to % s."); |
| 149 : please ensure that the date / time exists.Field); | 148 DefineGlobalConstString(pIsolate, L"IDS_INVALID_MONTH", L"**Invalid**"); |
| 150 DEFINE_GLOBAL_CONST(pIsolate, IDS_INVALID_VALUE, | 149 DefineGlobalConstString( |
| 151 The value entered does not match the format of the field); | 150 pIsolate, L"IDS_INVALID_DATE", |
| 152 DEFINE_GLOBAL_CONST(pIsolate, IDS_AM, am); | 151 L"Invalid date / time: please ensure that the date / time exists.Field"); |
| 153 DEFINE_GLOBAL_CONST(pIsolate, IDS_PM, pm); | 152 DefineGlobalConstString( |
| 154 DEFINE_GLOBAL_CONST( | 153 pIsolate, L"IDS_INVALID_VALUE", |
| 155 pIsolate, IDS_MONTH_INFO, | 154 L"The value entered does not match the format of the field"); |
| 156 January[1] February[2] March[3] April[4] May[5] June[6] July[7] August | 155 DefineGlobalConstString(pIsolate, L"IDS_AM", L"am"); |
| 157 [8] September[9] October[10] November[11] December[12] Sept[9] Jan | 156 DefineGlobalConstString(pIsolate, L"IDS_PM", L"pm"); |
| 158 [1] Feb[2] Mar[3] Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov | 157 DefineGlobalConstString( |
| 159 [11] Dec[12]); | 158 pIsolate, L"IDS_MONTH_INFO", |
| 160 DEFINE_GLOBAL_CONST(pIsolate, IDS_STARTUP_CONSOLE_MSG, ** ^ _ ^ **); | 159 L"January[1] February[2] March[3] April[4] May[5] " |
| 161 | 160 L"June[6] July[7] August[8] September[9] October[10] " |
| 162 return 0; | 161 L"November[11] December[12] Sept[9] Jan[1] Feb[2] Mar[3] " |
| 162 L"Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov[11] " |
| 163 L"Dec[12]"); |
| 164 DefineGlobalConstString(pIsolate, L"IDS_STARTUP_CONSOLE_MSG", L"** ^ _ ^ **"); |
| 163 } | 165 } |
| 164 | 166 |
| 165 /* ------------------------------ CJS_GlobalArrays ------------------------ */ | 167 /* ------------------------------ CJS_GlobalArrays ------------------------ */ |
| 166 | 168 |
| 167 #define DEFINE_GLOBAL_ARRAY(pIsolate) \ | 169 void DefineGlobalConstStringArray(v8::Isolate* pIsolate, |
| 168 int size = FX_ArraySize(ArrayContent); \ | 170 const wchar_t* sConstName, |
| 169 \ | 171 const wchar_t** pValues, |
| 170 CJS_Array array(pIsolate); \ | 172 size_t nValues) { |
| 171 for (int i = 0; i < size; i++) \ | 173 CJS_Array array(pIsolate); |
| 172 array.SetElement(i, CJS_Value(pIsolate, ArrayContent[i])); \ | 174 for (size_t i = 0; i < nValues; ++i) { |
| 173 \ | 175 array.SetElement(i, CJS_Value(pIsolate, pValues[i])); |
| 174 CJS_PropValue prop(pIsolate); \ | |
| 175 prop << array; \ | |
| 176 if (JS_DefineGlobalConst(pIsolate, (const wchar_t*)ArrayName, \ | |
| 177 prop.ToV8Value()) < 0) { \ | |
| 178 return -1; \ | |
| 179 } | 176 } |
| 177 CJS_PropValue prop(pIsolate); |
| 178 prop << array; |
| 179 JS_DefineGlobalConst(pIsolate, sConstName, prop.ToV8Value()); |
| 180 } |
| 180 | 181 |
| 181 int CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) { | 182 void CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) { |
| 182 { | 183 { |
| 183 const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_DOT_SEP"; | 184 const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_DOT_SEP"; |
| 184 const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*\\.?\\d*"}; | 185 const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*\\.?\\d*"}; |
| 185 DEFINE_GLOBAL_ARRAY(pIsolate); | 186 DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent, |
| 187 FX_ArraySize(ArrayContent)); |
| 186 } | 188 } |
| 187 | 189 |
| 188 { | 190 { |
| 189 const FX_WCHAR* ArrayName = L"RE_NUMBER_COMMIT_DOT_SEP"; | 191 const FX_WCHAR* ArrayName = L"RE_NUMBER_COMMIT_DOT_SEP"; |
| 190 const FX_WCHAR* ArrayContent[] = { | 192 const FX_WCHAR* ArrayContent[] = { |
| 191 L"[+-]?\\d+(\\.\\d+)?", /* -1.0 or -1 */ | 193 L"[+-]?\\d+(\\.\\d+)?", /* -1.0 or -1 */ |
| 192 L"[+-]?\\.\\d+", /* -.1 */ | 194 L"[+-]?\\.\\d+", /* -.1 */ |
| 193 L"[+-]?\\d+\\." /* -1. */ | 195 L"[+-]?\\d+\\." /* -1. */ |
| 194 }; | 196 }; |
| 195 DEFINE_GLOBAL_ARRAY(pIsolate); | 197 DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent, |
| 198 FX_ArraySize(ArrayContent)); |
| 196 } | 199 } |
| 197 | 200 |
| 198 { | 201 { |
| 199 const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_COMMA_SEP"; | 202 const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_COMMA_SEP"; |
| 200 const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*,?\\d*"}; | 203 const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*,?\\d*"}; |
| 201 | 204 |
| 202 DEFINE_GLOBAL_ARRAY(pIsolate); | 205 DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent, |
| 206 FX_ArraySize(ArrayContent)); |
| 203 } | 207 } |
| 204 | 208 |
| 205 { | 209 { |
| 206 const FX_WCHAR* ArrayName = L"RE_NUMBER_COMMIT_COMMA_SEP"; | 210 const FX_WCHAR* ArrayName = L"RE_NUMBER_COMMIT_COMMA_SEP"; |
| 207 const FX_WCHAR* ArrayContent[] = { | 211 const FX_WCHAR* ArrayContent[] = { |
| 208 L"[+-]?\\d+([.,]\\d+)?", /* -1,0 or -1 */ | 212 L"[+-]?\\d+([.,]\\d+)?", /* -1,0 or -1 */ |
| 209 L"[+-]?[.,]\\d+", /* -,1 */ | 213 L"[+-]?[.,]\\d+", /* -,1 */ |
| 210 L"[+-]?\\d+[.,]" /* -1, */ | 214 L"[+-]?\\d+[.,]" /* -1, */ |
| 211 }; | 215 }; |
| 212 DEFINE_GLOBAL_ARRAY(pIsolate); | 216 DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent, |
| 217 FX_ArraySize(ArrayContent)); |
| 213 } | 218 } |
| 214 | 219 |
| 215 { | 220 { |
| 216 const FX_WCHAR* ArrayName = L"RE_ZIP_ENTRY"; | 221 const FX_WCHAR* ArrayName = L"RE_ZIP_ENTRY"; |
| 217 const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}"}; | 222 const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}"}; |
| 218 DEFINE_GLOBAL_ARRAY(pIsolate); | 223 DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent, |
| 224 FX_ArraySize(ArrayContent)); |
| 219 } | 225 } |
| 220 | 226 |
| 221 { | 227 { |
| 222 const FX_WCHAR* ArrayName = L"RE_ZIP_COMMIT"; | 228 const FX_WCHAR* ArrayName = L"RE_ZIP_COMMIT"; |
| 223 const FX_WCHAR* ArrayContent[] = {L"\\d{5}"}; | 229 const FX_WCHAR* ArrayContent[] = {L"\\d{5}"}; |
| 224 DEFINE_GLOBAL_ARRAY(pIsolate); | 230 DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent, |
| 231 FX_ArraySize(ArrayContent)); |
| 225 } | 232 } |
| 226 | 233 |
| 227 { | 234 { |
| 228 const FX_WCHAR* ArrayName = L"RE_ZIP4_ENTRY"; | 235 const FX_WCHAR* ArrayName = L"RE_ZIP4_ENTRY"; |
| 229 const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}(\\.|[- ])?\\d{0,4}"}; | 236 const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}(\\.|[- ])?\\d{0,4}"}; |
| 230 DEFINE_GLOBAL_ARRAY(pIsolate); | 237 DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent, |
| 238 FX_ArraySize(ArrayContent)); |
| 231 } | 239 } |
| 232 | 240 |
| 233 { | 241 { |
| 234 const FX_WCHAR* ArrayName = L"RE_ZIP4_COMMIT"; | 242 const FX_WCHAR* ArrayName = L"RE_ZIP4_COMMIT"; |
| 235 const FX_WCHAR* ArrayContent[] = {L"\\d{5}(\\.|[- ])?\\d{4}"}; | 243 const FX_WCHAR* ArrayContent[] = {L"\\d{5}(\\.|[- ])?\\d{4}"}; |
| 236 DEFINE_GLOBAL_ARRAY(pIsolate); | 244 DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent, |
| 245 FX_ArraySize(ArrayContent)); |
| 237 } | 246 } |
| 238 | 247 |
| 239 { | 248 { |
| 240 const FX_WCHAR* ArrayName = L"RE_PHONE_ENTRY"; | 249 const FX_WCHAR* ArrayName = L"RE_PHONE_ENTRY"; |
| 241 const FX_WCHAR* ArrayContent[] = { | 250 const FX_WCHAR* ArrayContent[] = { |
| 242 L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 555-1234 or 408 | 251 L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 555-1234 or 408 |
| 243 555-1234 */ | 252 555-1234 */ |
| 244 L"\\(\\d{0,3}", /* (408 */ | 253 L"\\(\\d{0,3}", /* (408 */ |
| 245 L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408) | 254 L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408) |
| 246 555-1234 */ | 255 555-1234 */ |
| 247 /* (allow the addition of parens as an afterthought) */ | 256 /* (allow the addition of parens as an afterthought) */ |
| 248 L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408 555-1234 | 257 L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408 555-1234 |
| 249 */ | 258 */ |
| 250 L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 408) 555-1234 | 259 L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 408) 555-1234 |
| 251 */ | 260 */ |
| 252 L"011(\\.|[- \\d])*" /* international */ | 261 L"011(\\.|[- \\d])*" /* international */ |
| 253 }; | 262 }; |
| 254 DEFINE_GLOBAL_ARRAY(pIsolate); | 263 DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent, |
| 264 FX_ArraySize(ArrayContent)); |
| 255 } | 265 } |
| 256 | 266 |
| 257 { | 267 { |
| 258 const FX_WCHAR* ArrayName = L"RE_PHONE_COMMIT"; | 268 const FX_WCHAR* ArrayName = L"RE_PHONE_COMMIT"; |
| 259 const FX_WCHAR* ArrayContent[] = { | 269 const FX_WCHAR* ArrayContent[] = { |
| 260 L"\\d{3}(\\.|[- ])?\\d{4}", /* 555-1234 */ | 270 L"\\d{3}(\\.|[- ])?\\d{4}", /* 555-1234 */ |
| 261 L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* 408 555-1234 */ | 271 L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* 408 555-1234 */ |
| 262 L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */ | 272 L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */ |
| 263 L"011(\\.|[- \\d])*" /* international */ | 273 L"011(\\.|[- \\d])*" /* international */ |
| 264 }; | 274 }; |
| 265 DEFINE_GLOBAL_ARRAY(pIsolate); | 275 DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent, |
| 276 FX_ArraySize(ArrayContent)); |
| 266 } | 277 } |
| 267 | 278 |
| 268 { | 279 { |
| 269 const FX_WCHAR* ArrayName = L"RE_SSN_ENTRY"; | 280 const FX_WCHAR* ArrayName = L"RE_SSN_ENTRY"; |
| 270 const FX_WCHAR* ArrayContent[] = { | 281 const FX_WCHAR* ArrayContent[] = { |
| 271 L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"}; | 282 L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"}; |
| 272 DEFINE_GLOBAL_ARRAY(pIsolate); | 283 DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent, |
| 284 FX_ArraySize(ArrayContent)); |
| 273 } | 285 } |
| 274 | 286 |
| 275 { | 287 { |
| 276 const FX_WCHAR* ArrayName = L"RE_SSN_COMMIT"; | 288 const FX_WCHAR* ArrayName = L"RE_SSN_COMMIT"; |
| 277 const FX_WCHAR* ArrayContent[] = { | 289 const FX_WCHAR* ArrayContent[] = { |
| 278 L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"}; | 290 L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"}; |
| 279 DEFINE_GLOBAL_ARRAY(pIsolate); | 291 DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent, |
| 292 FX_ArraySize(ArrayContent)); |
| 280 } | 293 } |
| 281 | |
| 282 return 0; | |
| 283 } | 294 } |
| OLD | NEW |