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
fxv8.cpp
Go to the documentation of this file.
1// Copyright 2020 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/fxv8.h"
8
9#include "third_party/base/numerics/safe_conversions.h"
10#include "v8/include/v8-container.h"
11#include "v8/include/v8-date.h"
12#include "v8/include/v8-exception.h"
13#include "v8/include/v8-isolate.h"
14#include "v8/include/v8-primitive.h"
15#include "v8/include/v8-value.h"
16
17namespace fxv8 {
18
20 return !value.IsEmpty() && value->IsUndefined();
21}
22
24 return !value.IsEmpty() && value->IsNull();
25}
26
28 return !value.IsEmpty() && value->IsBoolean();
29}
30
32 return !value.IsEmpty() && value->IsString();
33}
34
36 return !value.IsEmpty() && value->IsNumber();
37}
38
40 return !value.IsEmpty() && value->IsInt32();
41}
42
44 return !value.IsEmpty() && value->IsObject();
45}
46
48 return !value.IsEmpty() && value->IsArray();
49}
50
52 return !value.IsEmpty() && value->IsDate();
53}
54
56 return !value.IsEmpty() && value->IsFunction();
57}
58
59v8::Local<v8::Value> NewNullHelper(v8::Isolate* pIsolate) {
60 return v8::Null(pIsolate);
61}
62
63v8::Local<v8::Value> NewUndefinedHelper(v8::Isolate* pIsolate) {
64 return v8::Undefined(pIsolate);
65}
66
67v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, int number) {
68 return v8::Int32::New(pIsolate, number);
69}
70
71v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, double number) {
72 return v8::Number::New(pIsolate, number);
73}
74
75v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, float number) {
76 return v8::Number::New(pIsolate, number);
77}
78
79v8::Local<v8::Boolean> NewBooleanHelper(v8::Isolate* pIsolate, bool b) {
80 return v8::Boolean::New(pIsolate, b);
81}
82
83v8::Local<v8::String> NewStringHelper(v8::Isolate* pIsolate,
84 ByteStringView str) {
85 return v8::String::NewFromUtf8(
86 pIsolate, str.unterminated_c_str(), v8::NewStringType::kNormal,
87 pdfium::base::checked_cast<int>(str.GetLength()))
88 .ToLocalChecked();
89}
90
91v8::Local<v8::String> NewStringHelper(v8::Isolate* pIsolate,
92 WideStringView str) {
93 return NewStringHelper(pIsolate, FX_UTF8Encode(str).AsStringView());
94}
95
96v8::Local<v8::Array> NewArrayHelper(v8::Isolate* pIsolate) {
97 return v8::Array::New(pIsolate);
98}
99
100v8::Local<v8::Array> NewArrayHelper(v8::Isolate* pIsolate,
102 v8::Local<v8::Array> result = NewArrayHelper(pIsolate);
103 for (size_t i = 0; i < values.size(); ++i) {
104 fxv8::ReentrantPutArrayElementHelper(
105 pIsolate, result, i,
106 values[i].IsEmpty() ? fxv8::NewUndefinedHelper(pIsolate) : values[i]);
107 }
108 return result;
109}
110
111v8::Local<v8::Object> NewObjectHelper(v8::Isolate* pIsolate) {
112 return v8::Object::New(pIsolate);
113}
114
115v8::Local<v8::Date> NewDateHelper(v8::Isolate* pIsolate, double d) {
116 return v8::Date::New(pIsolate->GetCurrentContext(), d)
117 .ToLocalChecked()
118 .As<v8::Date>();
119}
120
125
128 return ByteString(*s, s.length());
129}
130
137
145
147 v8::Local<v8::Value> pValue) {
148 return static_cast<float>(ReentrantToDoubleHelper(pIsolate, pValue));
149}
150
158
172
186
196
206
223
243
256
269
282
291
305
308 size_t index) {
309 if (pArray.IsEmpty())
310 return v8::Local<v8::Value>();
311
313 v8::Local<v8::Value> val;
314 if (!pArray
317 .ToLocal(&val)) {
318 return v8::Local<v8::Value>();
319 }
320 return val;
321}
322
324 if (pArray.IsEmpty())
325 return 0;
326 return pArray->Length();
327}
328
329void ThrowExceptionHelper(v8::Isolate* pIsolate, ByteStringView str) {
330 pIsolate->ThrowException(NewStringHelper(pIsolate, str));
331}
332
333void ThrowExceptionHelper(v8::Isolate* pIsolate, WideStringView str) {
334 pIsolate->ThrowException(NewStringHelper(pIsolate, str));
335}
336
337} // namespace fxv8
Definition fxv8.h:22
v8::Local< v8::Number > NewNumberHelper(v8::Isolate *pIsolate, int number)
Definition fxv8.cpp:67
v8::Local< v8::Value > ReentrantGetArrayElementHelper(v8::Isolate *pIsolate, v8::Local< v8::Array > pArray, size_t index)
Definition fxv8.cpp:306
v8::Local< v8::Date > NewDateHelper(v8::Isolate *pIsolate, double d)
Definition fxv8.cpp:115
bool IsBoolean(v8::Local< v8::Value > value)
Definition fxv8.cpp:27
v8::Local< v8::Object > ReentrantToObjectHelper(v8::Isolate *pIsolate, v8::Local< v8::Value > pValue)
Definition fxv8.cpp:187
void ThrowExceptionHelper(v8::Isolate *pIsolate, WideStringView str)
Definition fxv8.cpp:333
v8::Local< v8::Value > NewUndefinedHelper(v8::Isolate *pIsolate)
Definition fxv8.cpp:63
bool IsArray(v8::Local< v8::Value > value)
Definition fxv8.cpp:47
bool IsUndefined(v8::Local< v8::Value > value)
Definition fxv8.cpp:19
double ReentrantToDoubleHelper(v8::Isolate *pIsolate, v8::Local< v8::Value > pValue)
Definition fxv8.cpp:151
v8::Local< v8::String > NewStringHelper(v8::Isolate *pIsolate, WideStringView str)
Definition fxv8.cpp:91
bool ReentrantSetObjectOwnPropertyHelper(v8::Isolate *pIsolate, v8::Local< v8::Object > pObj, ByteStringView bsUTF8PropertyName, v8::Local< v8::Value > pValue)
Definition fxv8.cpp:257
bool ReentrantPutArrayElementHelper(v8::Isolate *pIsolate, v8::Local< v8::Array > pArray, size_t index, v8::Local< v8::Value > pValue)
Definition fxv8.cpp:292
v8::Local< v8::String > NewStringHelper(v8::Isolate *pIsolate, ByteStringView str)
Definition fxv8.cpp:83
bool IsInteger(v8::Local< v8::Value > value)
Definition fxv8.cpp:39
void ThrowExceptionHelper(v8::Isolate *pIsolate, ByteStringView str)
Definition fxv8.cpp:329
bool ReentrantHasObjectOwnPropertyHelper(v8::Isolate *pIsolate, v8::Local< v8::Object > pObj, ByteStringView bsUTF8PropertyName)
Definition fxv8.cpp:244
v8::Local< v8::Boolean > NewBooleanHelper(v8::Isolate *pIsolate, bool b)
Definition fxv8.cpp:79
v8::Local< v8::Array > NewArrayHelper(v8::Isolate *pIsolate, pdfium::span< v8::Local< v8::Value > > values)
Definition fxv8.cpp:100
v8::Local< v8::Value > ReentrantGetObjectPropertyHelper(v8::Isolate *pIsolate, v8::Local< v8::Object > pObj, ByteStringView bsUTF8PropertyName)
Definition fxv8.cpp:207
WideString ReentrantToWideStringHelper(v8::Isolate *pIsolate, v8::Local< v8::Value > pValue)
Definition fxv8.cpp:159
void ReentrantDeleteObjectPropertyHelper(v8::Isolate *pIsolate, v8::Local< v8::Object > pObj, ByteStringView bsUTF8PropertyName)
Definition fxv8.cpp:283
bool IsNumber(v8::Local< v8::Value > value)
Definition fxv8.cpp:35
bool ReentrantPutObjectPropertyHelper(v8::Isolate *pIsolate, v8::Local< v8::Object > pObj, ByteStringView bsUTF8PropertyName, v8::Local< v8::Value > pPut)
Definition fxv8.cpp:270
bool IsObject(v8::Local< v8::Value > value)
Definition fxv8.cpp:43
bool IsString(v8::Local< v8::Value > value)
Definition fxv8.cpp:31
ByteString ReentrantToByteStringHelper(v8::Isolate *pIsolate, v8::Local< v8::Value > pValue)
Definition fxv8.cpp:173
ByteString ToByteString(v8::Isolate *pIsolate, v8::Local< v8::String > pValue)
Definition fxv8.cpp:126
v8::Local< v8::Object > NewObjectHelper(v8::Isolate *pIsolate)
Definition fxv8.cpp:111
bool IsDate(v8::Local< v8::Value > value)
Definition fxv8.cpp:51
v8::Local< v8::Array > NewArrayHelper(v8::Isolate *pIsolate)
Definition fxv8.cpp:96
bool ReentrantToBooleanHelper(v8::Isolate *pIsolate, v8::Local< v8::Value > pValue)
Definition fxv8.cpp:138
size_t GetArrayLengthHelper(v8::Local< v8::Array > pArray)
Definition fxv8.cpp:323
v8::Local< v8::Number > NewNumberHelper(v8::Isolate *pIsolate, double number)
Definition fxv8.cpp:71
WideString ToWideString(v8::Isolate *pIsolate, v8::Local< v8::String > pValue)
Definition fxv8.cpp:121
v8::Local< v8::Value > NewNullHelper(v8::Isolate *pIsolate)
Definition fxv8.cpp:59
bool IsNull(v8::Local< v8::Value > value)
Definition fxv8.cpp:23
v8::Local< v8::Number > NewNumberHelper(v8::Isolate *pIsolate, float number)
Definition fxv8.cpp:75
float ReentrantToFloatHelper(v8::Isolate *pIsolate, v8::Local< v8::Value > pValue)
Definition fxv8.cpp:146
int32_t ReentrantToInt32Helper(v8::Isolate *pIsolate, v8::Local< v8::Value > pValue)
Definition fxv8.cpp:131
v8::Local< v8::Array > ReentrantToArrayHelper(v8::Isolate *pIsolate, v8::Local< v8::Value > pValue)
Definition fxv8.cpp:197
std::vector< WideString > ReentrantGetObjectPropertyNamesHelper(v8::Isolate *pIsolate, v8::Local< v8::Object > pObj)
Definition fxv8.cpp:224
bool IsFunction(v8::Local< v8::Value > value)
Definition fxv8.cpp:55