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
cfx_v8.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/cfx_v8.h"
8
9#include "fxjs/fxv8.h"
10#include "v8/include/v8-isolate.h"
11
12CFX_V8::CFX_V8(v8::Isolate* isolate) : m_pIsolate(isolate) {}
13
14CFX_V8::~CFX_V8() = default;
15
16v8::Local<v8::Value> CFX_V8::GetObjectProperty(
17 v8::Local<v8::Object> pObj,
18 ByteStringView bsUTF8PropertyName) {
19 return fxv8::ReentrantGetObjectPropertyHelper(GetIsolate(), pObj,
20 bsUTF8PropertyName);
21}
22
23std::vector<WideString> CFX_V8::GetObjectPropertyNames(
24 v8::Local<v8::Object> pObj) {
25 return fxv8::ReentrantGetObjectPropertyNamesHelper(GetIsolate(), pObj);
26}
27
28void CFX_V8::PutObjectProperty(v8::Local<v8::Object> pObj,
29 ByteStringView bsUTF8PropertyName,
30 v8::Local<v8::Value> pPut) {
31 fxv8::ReentrantPutObjectPropertyHelper(GetIsolate(), pObj, bsUTF8PropertyName,
32 pPut);
33}
34
36 if (m_pIsolate)
37 m_pIsolate.ExtractAsDangling()->Dispose();
38}
39
41 return fxv8::NewArrayHelper(GetIsolate());
42}
43
45 return fxv8::NewObjectHelper(GetIsolate());
46}
47
48void CFX_V8::PutArrayElement(v8::Local<v8::Array> pArray,
49 size_t index,
50 v8::Local<v8::Value> pValue) {
51 fxv8::ReentrantPutArrayElementHelper(GetIsolate(), pArray, index, pValue);
52}
53
54v8::Local<v8::Value> CFX_V8::GetArrayElement(v8::Local<v8::Array> pArray,
55 size_t index) {
56 return fxv8::ReentrantGetArrayElementHelper(GetIsolate(), pArray, index);
57}
58
59size_t CFX_V8::GetArrayLength(v8::Local<v8::Array> pArray) {
60 return fxv8::GetArrayLengthHelper(pArray);
61}
62
63v8::Local<v8::Number> CFX_V8::NewNumber(int number) {
64 return fxv8::NewNumberHelper(GetIsolate(), number);
65}
66
67v8::Local<v8::Number> CFX_V8::NewNumber(double number) {
68 return fxv8::NewNumberHelper(GetIsolate(), number);
69}
70
71v8::Local<v8::Number> CFX_V8::NewNumber(float number) {
72 return fxv8::NewNumberHelper(GetIsolate(), number);
73}
74
76 return fxv8::NewBooleanHelper(GetIsolate(), b);
77}
78
79v8::Local<v8::String> CFX_V8::NewString(ByteStringView str) {
80 return fxv8::NewStringHelper(GetIsolate(), str);
81}
82
83v8::Local<v8::String> CFX_V8::NewString(WideStringView str) {
84 // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t
85 // wide-strings isn't handled by v8, so use UTF8 as a common
86 // intermediate format.
87 return NewString(FX_UTF8Encode(str).AsStringView());
88}
89
91 return fxv8::NewNullHelper(GetIsolate());
92}
93
95 return fxv8::NewUndefinedHelper(GetIsolate());
96}
97
98v8::Local<v8::Date> CFX_V8::NewDate(double d) {
99 return fxv8::NewDateHelper(GetIsolate(), d);
100}
101
102int CFX_V8::ToInt32(v8::Local<v8::Value> pValue) {
103 return fxv8::ReentrantToInt32Helper(GetIsolate(), pValue);
104}
105
106bool CFX_V8::ToBoolean(v8::Local<v8::Value> pValue) {
107 return fxv8::ReentrantToBooleanHelper(GetIsolate(), pValue);
108}
109
110double CFX_V8::ToDouble(v8::Local<v8::Value> pValue) {
111 return fxv8::ReentrantToDoubleHelper(GetIsolate(), pValue);
112}
113
114WideString CFX_V8::ToWideString(v8::Local<v8::Value> pValue) {
115 return fxv8::ReentrantToWideStringHelper(GetIsolate(), pValue);
116}
117
118ByteString CFX_V8::ToByteString(v8::Local<v8::Value> pValue) {
119 return fxv8::ReentrantToByteStringHelper(GetIsolate(), pValue);
120}
121
122v8::Local<v8::Object> CFX_V8::ToObject(v8::Local<v8::Value> pValue) {
123 return fxv8::ReentrantToObjectHelper(GetIsolate(), pValue);
124}
125
126v8::Local<v8::Array> CFX_V8::ToArray(v8::Local<v8::Value> pValue) {
127 return fxv8::ReentrantToArrayHelper(GetIsolate(), pValue);
128}
129
130void CFX_V8IsolateDeleter::operator()(v8::Isolate* ptr) {
131 ptr->Dispose();
132}
v8::Local< v8::Number > NewNumber(double number)
Definition cfx_v8.cpp:67
v8::Local< v8::Number > NewNumber(float number)
Definition cfx_v8.cpp:71
v8::Local< v8::Boolean > NewBoolean(bool b)
Definition cfx_v8.cpp:75
v8::Local< v8::String > NewString(WideStringView str)
Definition cfx_v8.cpp:83
v8::Local< v8::Array > NewArray()
Definition cfx_v8.cpp:40
CFX_V8(v8::Isolate *pIsolate)
Definition cfx_v8.cpp:12
v8::Local< v8::Date > NewDate(double d)
Definition cfx_v8.cpp:98
v8::Local< v8::Value > NewNull()
Definition cfx_v8.cpp:90
void DisposeIsolate()
Definition cfx_v8.cpp:35
v8::Local< v8::Object > NewObject()
Definition cfx_v8.cpp:44
virtual ~CFX_V8()
v8::Local< v8::Number > NewNumber(int number)
Definition cfx_v8.cpp:63
v8::Local< v8::String > NewString(ByteStringView str)
Definition cfx_v8.cpp:79
v8::Local< v8::Value > NewUndefined()
Definition cfx_v8.cpp:94
void operator()(v8::Isolate *ptr)
Definition cfx_v8.cpp:130