Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
js_define.cpp
Go to the documentation of this file.
1
// Copyright 2014 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/js_define.h"
8
9
#
include
<
math
.
h
>
10
#
include
<
stdarg
.
h
>
11
12
#
include
<
algorithm
>
13
#
include
<
limits
>
14
15
#
include
"core/fxcrt/check.h"
16
#
include
"core/fxcrt/fx_extension.h"
17
#
include
"core/fxcrt/span.h"
18
#
include
"fxjs/cjs_document.h"
19
#
include
"fxjs/cjs_object.h"
20
#
include
"fxjs/fx_date_helpers.h"
21
#
include
"fxjs/fxv8.h"
22
#
include
"v8/include/v8-context.h"
23
#
include
"v8/include/v8-function.h"
24
#
include
"v8/include/v8-isolate.h"
25
26
void
JSDestructor
(v8::Local<v8::Object> obj) {
27
CFXJS_Engine::SetBinding(obj,
nullptr
);
28
}
29
30
double
JS_DateParse
(v8::Isolate* pIsolate,
const
WideString
& str) {
31
v8::Isolate::Scope isolate_scope(pIsolate);
32
v8::HandleScope scope(pIsolate);
33
34
v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
35
36
// Use the built-in object method.
37
v8::MaybeLocal<v8::Value> maybe_value =
38
context->Global()->Get(context, fxv8::NewStringHelper(pIsolate,
"Date"
));
39
40
v8::Local<v8::Value> value;
41
if
(!maybe_value.ToLocal(&value) || !value->IsObject())
42
return
0;
43
44
v8::Local<v8::Object> obj = value.As<v8::Object>();
45
maybe_value = obj->Get(context, fxv8::NewStringHelper(pIsolate,
"parse"
));
46
if
(!maybe_value.ToLocal(&value) || !value->IsFunction())
47
return
0;
48
49
v8::Local<v8::Function> func = value.As<v8::Function>();
50
static
constexpr
int
argc = 1;
51
v8::Local<v8::Value> argv[argc] = {
52
fxv8::NewStringHelper(pIsolate, str.AsStringView()),
53
};
54
maybe_value = func->Call(context, context->Global(), argc, argv);
55
if
(!maybe_value.ToLocal(&value) || !value->IsNumber())
56
return
0;
57
58
double
date = value.As<v8::Number>()->Value();
59
return
isfinite(date) ?
FX_LocalTime
(
date
)
: date;
60
}
61
62
v8
::
LocalVector
<
v8
::
Value
>
ExpandKeywordParams
(
63
CJS_Runtime* pRuntime,
64
pdfium
::
span
<
v8
::
Local
<
v8
::
Value
>>
originals
,
65
size_t
nKeywords
,
66
...) {
67
DCHECK
(nKeywords);
68
69
v8::LocalVector<v8::Value> result(pRuntime->GetIsolate(), nKeywords);
70
size_t size =
std
::min(originals.size(), nKeywords);
71
for
(size_t i = 0; i < size; ++i)
72
result[i] = originals[i];
73
74
if
(originals.size() != 1 || !originals[0]->IsObject() ||
75
originals[0]->IsArray()) {
76
return
result;
77
}
78
result[0] = v8::Local<v8::Value>();
// Make unknown.
79
80
v8::Local<v8::Object> pObj = pRuntime->ToObject(originals[0]);
81
va_list ap;
82
va_start(ap, nKeywords);
83
for
(size_t i = 0; i < nKeywords; ++i) {
84
const
char
* property = va_arg(ap,
const
char
*);
85
v8::Local<v8::Value> v8Value = pRuntime->GetObjectProperty(pObj, property);
86
if
(!v8Value->IsUndefined())
87
result[i] = v8Value;
88
}
89
va_end(ap);
90
91
return
result;
92
}
93
94
bool
IsExpandedParamKnown
(v8::Local<v8::Value> value) {
95
return
!value.IsEmpty() &&
96
(value->IsString() || value->IsNumber() || value->IsBoolean() ||
97
value->IsDate() || value->IsObject() || value->IsNull() ||
98
value->IsUndefined());
99
}
DCHECK
#define DCHECK
Definition
check.h:33
IsExpandedParamKnown
bool IsExpandedParamKnown(v8::Local< v8::Value > value)
Definition
js_define.cpp:94
JSDestructor
void JSDestructor(v8::Local< v8::Object > obj)
Definition
js_define.cpp:26
ExpandKeywordParams
v8::LocalVector< v8::Value > ExpandKeywordParams(CJS_Runtime *pRuntime, pdfium::span< v8::Local< v8::Value > > originals, size_t nKeywords,...)
Definition
js_define.cpp:62
JS_DateParse
double JS_DateParse(v8::Isolate *pIsolate, const WideString &str)
Definition
js_define.cpp:30
fxjs::FX_LocalTime
double FX_LocalTime(double d)
Definition
fx_date_helpers.cpp:241
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
fxjs
js_define.cpp
Generated on
for Qt by
1.18.0