Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: xfa/src/fxjse/value.h

Issue 1803723002: Move xfa/src up to xfa/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/src/fxjse/util_inline.h ('k') | xfa/src/fxjse/value.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
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 #ifndef XFA_SRC_FXJSE_VALUE_H_
8 #define XFA_SRC_FXJSE_VALUE_H_
9
10 #include "xfa/src/fxjse/scope_inline.h"
11
12 class CFXJSE_Value {
13 public:
14 CFXJSE_Value(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {}
15
16 protected:
17 CFXJSE_Value();
18 CFXJSE_Value(const CFXJSE_Value&);
19 CFXJSE_Value& operator=(const CFXJSE_Value&);
20
21 public:
22 V8_INLINE FX_BOOL IsUndefined() const {
23 if (m_hValue.IsEmpty()) {
24 return FALSE;
25 }
26 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
27 v8::Local<v8::Value> hValue =
28 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
29 return hValue->IsUndefined();
30 }
31 V8_INLINE FX_BOOL IsNull() const {
32 if (m_hValue.IsEmpty()) {
33 return FALSE;
34 }
35 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
36 v8::Local<v8::Value> hValue =
37 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
38 return hValue->IsNull();
39 }
40 V8_INLINE FX_BOOL IsBoolean() const {
41 if (m_hValue.IsEmpty()) {
42 return FALSE;
43 }
44 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
45 v8::Local<v8::Value> hValue =
46 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
47 return hValue->IsBoolean();
48 }
49 V8_INLINE FX_BOOL IsString() const {
50 if (m_hValue.IsEmpty()) {
51 return FALSE;
52 }
53 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
54 v8::Local<v8::Value> hValue =
55 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
56 return hValue->IsString();
57 }
58 V8_INLINE FX_BOOL IsNumber() const {
59 if (m_hValue.IsEmpty()) {
60 return FALSE;
61 }
62 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
63 v8::Local<v8::Value> hValue =
64 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
65 return hValue->IsNumber();
66 }
67 V8_INLINE FX_BOOL IsInteger() const {
68 if (m_hValue.IsEmpty()) {
69 return FALSE;
70 }
71 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
72 v8::Local<v8::Value> hValue =
73 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
74 return hValue->IsInt32();
75 }
76 V8_INLINE FX_BOOL IsObject() const {
77 if (m_hValue.IsEmpty()) {
78 return FALSE;
79 }
80 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
81 v8::Local<v8::Value> hValue =
82 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
83 return hValue->IsObject();
84 }
85 V8_INLINE FX_BOOL IsArray() const {
86 if (m_hValue.IsEmpty()) {
87 return FALSE;
88 }
89 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
90 v8::Local<v8::Value> hValue =
91 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
92 return hValue->IsArray();
93 }
94 V8_INLINE FX_BOOL IsFunction() const {
95 if (m_hValue.IsEmpty()) {
96 return FALSE;
97 }
98 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
99 v8::Local<v8::Value> hValue =
100 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
101 return hValue->IsFunction();
102 }
103 V8_INLINE FX_BOOL IsDate() const {
104 if (m_hValue.IsEmpty()) {
105 return FALSE;
106 }
107 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
108 v8::Local<v8::Value> hValue =
109 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
110 return hValue->IsDate();
111 }
112
113 public:
114 V8_INLINE FX_BOOL ToBoolean() const {
115 ASSERT(!m_hValue.IsEmpty());
116 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
117 v8::Local<v8::Value> hValue =
118 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
119 return static_cast<FX_BOOL>(hValue->BooleanValue());
120 }
121 V8_INLINE FX_FLOAT ToFloat() const {
122 ASSERT(!m_hValue.IsEmpty());
123 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
124 v8::Local<v8::Value> hValue =
125 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
126 return static_cast<FX_FLOAT>(hValue->NumberValue());
127 }
128 V8_INLINE FXJSE_DOUBLE ToDouble() const {
129 ASSERT(!m_hValue.IsEmpty());
130 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
131 v8::Local<v8::Value> hValue =
132 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
133 return static_cast<FXJSE_DOUBLE>(hValue->NumberValue());
134 }
135 V8_INLINE int32_t ToInteger() const {
136 ASSERT(!m_hValue.IsEmpty());
137 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
138 v8::Local<v8::Value> hValue =
139 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
140 return static_cast<int32_t>(hValue->NumberValue());
141 }
142 V8_INLINE void ToString(CFX_ByteString& szStrOutput) const {
143 ASSERT(!m_hValue.IsEmpty());
144 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
145 v8::Local<v8::Value> hValue =
146 v8::Local<v8::Value>::New(m_pIsolate, m_hValue);
147 v8::Local<v8::String> hString = hValue->ToString();
148 v8::String::Utf8Value hStringVal(hString);
149 szStrOutput = *hStringVal;
150 }
151 void* ToObject(CFXJSE_Class* lpClass) const;
152
153 public:
154 V8_INLINE void SetUndefined() {
155 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
156 v8::Local<v8::Value> hValue = v8::Undefined(m_pIsolate);
157 m_hValue.Reset(m_pIsolate, hValue);
158 }
159 V8_INLINE void SetNull() {
160 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
161 v8::Local<v8::Value> hValue = v8::Null(m_pIsolate);
162 m_hValue.Reset(m_pIsolate, hValue);
163 }
164 V8_INLINE void SetBoolean(FX_BOOL bBoolean) {
165 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
166 v8::Local<v8::Value> hValue =
167 v8::Boolean::New(m_pIsolate, bBoolean != FALSE);
168 m_hValue.Reset(m_pIsolate, hValue);
169 }
170 V8_INLINE void SetInteger(int32_t nInteger) {
171 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
172 v8::Local<v8::Value> hValue = v8::Integer::New(m_pIsolate, nInteger);
173 m_hValue.Reset(m_pIsolate, hValue);
174 }
175 V8_INLINE void SetDouble(FXJSE_DOUBLE dDouble) {
176 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
177 v8::Local<v8::Value> hValue = v8::Number::New(m_pIsolate, dDouble);
178 m_hValue.Reset(m_pIsolate, hValue);
179 }
180 V8_INLINE void SetString(const CFX_ByteStringC& szString) {
181 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate);
182 v8::Local<v8::Value> hValue = v8::String::NewFromUtf8(
183 m_pIsolate, reinterpret_cast<const char*>(szString.GetPtr()),
184 v8::String::kNormalString, szString.GetLength());
185 m_hValue.Reset(m_pIsolate, hValue);
186 }
187 V8_INLINE void SetFloat(FX_FLOAT fFloat);
188 V8_INLINE void SetJSObject() {
189 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate);
190 v8::Local<v8::Value> hValue = v8::Object::New(m_pIsolate);
191 m_hValue.Reset(m_pIsolate, hValue);
192 }
193 void SetHostObject(void* lpObject, CFXJSE_Class* lpClass);
194 void SetArray(uint32_t uValueCount, CFXJSE_Value** rgValues);
195 void SetDate(FXJSE_DOUBLE dDouble);
196
197 public:
198 FX_BOOL GetObjectProperty(const CFX_ByteStringC& szPropName,
199 CFXJSE_Value* lpPropValue);
200 FX_BOOL SetObjectProperty(const CFX_ByteStringC& szPropName,
201 CFXJSE_Value* lpPropValue);
202 FX_BOOL GetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
203 FX_BOOL SetObjectProperty(uint32_t uPropIdx, CFXJSE_Value* lpPropValue);
204 FX_BOOL DeleteObjectProperty(const CFX_ByteStringC& szPropName);
205 FX_BOOL HasObjectOwnProperty(const CFX_ByteStringC& szPropName,
206 FX_BOOL bUseTypeGetter);
207 FX_BOOL SetObjectOwnProperty(const CFX_ByteStringC& szPropName,
208 CFXJSE_Value* lpPropValue);
209 FX_BOOL SetFunctionBind(CFXJSE_Value* lpOldFunction, CFXJSE_Value* lpNewThis);
210 FX_BOOL Call(CFXJSE_Value* lpReceiver,
211 CFXJSE_Value* lpRetValue,
212 uint32_t nArgCount,
213 FXJSE_HVALUE* lpArgs);
214
215 public:
216 V8_INLINE v8::Isolate* GetIsolate() const { return m_pIsolate; }
217 V8_INLINE const v8::Global<v8::Value>& DirectGetValue() const {
218 return m_hValue;
219 }
220 V8_INLINE void ForceSetValue(v8::Local<v8::Value> hValue) {
221 m_hValue.Reset(m_pIsolate, hValue);
222 }
223 V8_INLINE void Assign(const CFXJSE_Value* lpValue) {
224 if (lpValue) {
225 m_hValue.Reset(m_pIsolate, lpValue->m_hValue);
226 } else {
227 m_hValue.Reset();
228 }
229 }
230
231 public:
232 static CFXJSE_Value* Create(v8::Isolate* pIsolate);
233
234 protected:
235 v8::Isolate* m_pIsolate;
236 v8::Global<v8::Value> m_hValue;
237 friend class CFXJSE_Context;
238 friend class CFXJSE_Class;
239 };
240
241 #endif // XFA_SRC_FXJSE_VALUE_H_
OLDNEW
« no previous file with comments | « xfa/src/fxjse/util_inline.h ('k') | xfa/src/fxjse/value.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698