Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cjs_globalarrays.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "fxjs/cjs_globalarrays.h"
8
9#include <iterator>
10
11#include "core/fxcrt/numerics/safe_conversions.h"
12#include "v8/include/v8-container.h"
13#include "v8/include/v8-isolate.h"
14
15#define GLOBAL_ARRAY(rt, name, ...)
16 {
17 static const wchar_t* const kValues[] = {__VA_ARGS__};
18 v8::Local<v8::Array> array = (rt)->NewArray();
19 v8::Local<v8::Context> ctx = (rt)->GetIsolate()->GetCurrentContext();
20 uint32_t i = 0;
21 for (const auto* value : kValues) {
22 array->Set(ctx, i, (rt)->NewString(value)).FromJust();
23 ++i;
24 }
25 (rt)->SetConstArray((name), array);
26 (rt)->DefineGlobalConst(
27 (name), [](const v8::FunctionCallbackInfo<v8::Value>& info) {
28 auto* pObj = static_cast<CJS_Object*>(
29 CFXJS_Engine::GetBinding(info.GetIsolate(), info.This()));
30 CJS_Runtime* pCurrentRuntime = pObj->GetRuntime();
31 if (pCurrentRuntime)
32 info.GetReturnValue().Set(pCurrentRuntime->GetConstArray(name));
33 });
34 }
35
36// static
37void CJS_GlobalArrays::DefineJSObjects(CJS_Runtime* pRuntime) {
38 GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_ENTRY_DOT_SEP", L"[+-]?\\d*\\.?\\d*");
39 GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_COMMIT_DOT_SEP",
40 L"[+-]?\\d+(\\.\\d+)?", // -1.0 or -1
41 L"[+-]?\\.\\d+", // -.1
42 L"[+-]?\\d+\\."); // -1.
43
44 GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_ENTRY_COMMA_SEP", L"[+-]?\\d*,?\\d*");
45 GLOBAL_ARRAY(pRuntime, L"RE_NUMBER_COMMIT_COMMA_SEP",
46 L"[+-]?\\d+([.,]\\d+)?", // -1,0 or -1
47 L"[+-]?[.,]\\d+", // -,1
48 L"[+-]?\\d+[.,]"); // -1,
49
50 GLOBAL_ARRAY(pRuntime, L"RE_ZIP_ENTRY", L"\\d{0,5}");
51 GLOBAL_ARRAY(pRuntime, L"RE_ZIP_COMMIT", L"\\d{5}");
52 GLOBAL_ARRAY(pRuntime, L"RE_ZIP4_ENTRY", L"\\d{0,5}(\\.|[- ])?\\d{0,4}");
53 GLOBAL_ARRAY(pRuntime, L"RE_ZIP4_COMMIT", L"\\d{5}(\\.|[- ])?\\d{4}");
54 GLOBAL_ARRAY(pRuntime, L"RE_PHONE_ENTRY",
55 // 555-1234 or 408 555-1234
56 L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",
57
58 // (408
59 L"\\‍(\\d{0,3}",
60
61 // (408) 555-1234
62 // (allow the addition of parens as an afterthought)
63 L"\\‍(\\d{0,3}\\‍)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",
64
65 // (408 555-1234
66 L"\\‍(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",
67
68 // 408) 555-1234
69 L"\\d{0,3}\\‍)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}",
70
71 // international
72 L"011(\\.|[- \\d])*");
73
75 pRuntime, L"RE_PHONE_COMMIT", L"\\d{3}(\\.|[- ])?\\d{4}", // 555-1234
76 L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", // 408 555-1234
77 L"\\‍(\\d{3}\\‍)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", // (408) 555-1234
78 L"011(\\.|[- \\d])*"); // international
79
80 GLOBAL_ARRAY(pRuntime, L"RE_SSN_ENTRY",
81 L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}");
82
83 GLOBAL_ARRAY(pRuntime, L"RE_SSN_COMMIT",
84 L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}");
85}
#define GLOBAL_ARRAY(rt, name,...)
static void DefineJSObjects(CJS_Runtime *pRuntmie)