OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "fxjs/cfxjse_value.h" | 7 #include "fxjs/cfxjse_value.h" |
8 | 8 |
9 #include <math.h> | 9 #include <math.h> |
10 | 10 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 v8::Local<v8::Value> hDate = v8::Date::New(m_pIsolate, dDouble); | 121 v8::Local<v8::Value> hDate = v8::Date::New(m_pIsolate, dDouble); |
122 m_hValue.Reset(m_pIsolate, hDate); | 122 m_hValue.Reset(m_pIsolate, hDate); |
123 } | 123 } |
124 | 124 |
125 void CFXJSE_Value::SetFloat(FX_FLOAT fFloat) { | 125 void CFXJSE_Value::SetFloat(FX_FLOAT fFloat) { |
126 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 126 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
127 v8::Local<v8::Value> pValue = v8::Number::New(m_pIsolate, ftod(fFloat)); | 127 v8::Local<v8::Value> pValue = v8::Number::New(m_pIsolate, ftod(fFloat)); |
128 m_hValue.Reset(m_pIsolate, pValue); | 128 m_hValue.Reset(m_pIsolate, pValue); |
129 } | 129 } |
130 | 130 |
131 FX_BOOL CFXJSE_Value::SetObjectProperty(const CFX_ByteStringC& szPropName, | 131 bool CFXJSE_Value::SetObjectProperty(const CFX_ByteStringC& szPropName, |
132 CFXJSE_Value* lpPropValue) { | 132 CFXJSE_Value* lpPropValue) { |
133 ASSERT(lpPropValue); | 133 ASSERT(lpPropValue); |
134 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 134 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
135 v8::Local<v8::Value> hObject = | 135 v8::Local<v8::Value> hObject = |
136 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 136 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
137 if (!hObject->IsObject()) | 137 if (!hObject->IsObject()) |
138 return FALSE; | 138 return false; |
139 | 139 |
140 v8::Local<v8::Value> hPropValue = | 140 v8::Local<v8::Value> hPropValue = |
141 v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->DirectGetValue()); | 141 v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->DirectGetValue()); |
142 return (FX_BOOL)hObject.As<v8::Object>()->Set( | 142 return (bool)hObject.As<v8::Object>()->Set( |
143 v8::String::NewFromUtf8(m_pIsolate, szPropName.c_str(), | 143 v8::String::NewFromUtf8(m_pIsolate, szPropName.c_str(), |
144 v8::String::kNormalString, | 144 v8::String::kNormalString, |
145 szPropName.GetLength()), | 145 szPropName.GetLength()), |
146 hPropValue); | 146 hPropValue); |
147 } | 147 } |
148 | 148 |
149 FX_BOOL CFXJSE_Value::GetObjectProperty(const CFX_ByteStringC& szPropName, | 149 bool CFXJSE_Value::GetObjectProperty(const CFX_ByteStringC& szPropName, |
150 CFXJSE_Value* lpPropValue) { | 150 CFXJSE_Value* lpPropValue) { |
151 ASSERT(lpPropValue); | 151 ASSERT(lpPropValue); |
152 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 152 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
153 v8::Local<v8::Value> hObject = | 153 v8::Local<v8::Value> hObject = |
154 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 154 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
155 if (!hObject->IsObject()) | 155 if (!hObject->IsObject()) |
156 return FALSE; | 156 return false; |
157 | 157 |
158 v8::Local<v8::Value> hPropValue = | 158 v8::Local<v8::Value> hPropValue = |
159 hObject.As<v8::Object>()->Get(v8::String::NewFromUtf8( | 159 hObject.As<v8::Object>()->Get(v8::String::NewFromUtf8( |
160 m_pIsolate, szPropName.c_str(), v8::String::kNormalString, | 160 m_pIsolate, szPropName.c_str(), v8::String::kNormalString, |
161 szPropName.GetLength())); | 161 szPropName.GetLength())); |
162 lpPropValue->ForceSetValue(hPropValue); | 162 lpPropValue->ForceSetValue(hPropValue); |
163 return TRUE; | 163 return true; |
164 } | 164 } |
165 | 165 |
166 FX_BOOL CFXJSE_Value::SetObjectProperty(uint32_t uPropIdx, | 166 bool CFXJSE_Value::SetObjectProperty(uint32_t uPropIdx, |
167 CFXJSE_Value* lpPropValue) { | 167 CFXJSE_Value* lpPropValue) { |
168 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 168 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
169 v8::Local<v8::Value> hObject = | 169 v8::Local<v8::Value> hObject = |
170 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 170 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
171 if (!hObject->IsObject()) | 171 if (!hObject->IsObject()) |
172 return FALSE; | 172 return false; |
173 | 173 |
174 v8::Local<v8::Value> hPropValue = | 174 v8::Local<v8::Value> hPropValue = |
175 v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->DirectGetValue()); | 175 v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->DirectGetValue()); |
176 return (FX_BOOL)hObject.As<v8::Object>()->Set(uPropIdx, hPropValue); | 176 return (bool)hObject.As<v8::Object>()->Set(uPropIdx, hPropValue); |
177 } | 177 } |
178 | 178 |
179 FX_BOOL CFXJSE_Value::GetObjectPropertyByIdx(uint32_t uPropIdx, | 179 bool CFXJSE_Value::GetObjectPropertyByIdx(uint32_t uPropIdx, |
180 CFXJSE_Value* lpPropValue) { | 180 CFXJSE_Value* lpPropValue) { |
181 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 181 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
182 v8::Local<v8::Value> hObject = | 182 v8::Local<v8::Value> hObject = |
183 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 183 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
184 if (!hObject->IsObject()) | 184 if (!hObject->IsObject()) |
185 return FALSE; | 185 return false; |
186 | 186 |
187 v8::Local<v8::Value> hPropValue = hObject.As<v8::Object>()->Get(uPropIdx); | 187 v8::Local<v8::Value> hPropValue = hObject.As<v8::Object>()->Get(uPropIdx); |
188 lpPropValue->ForceSetValue(hPropValue); | 188 lpPropValue->ForceSetValue(hPropValue); |
189 return TRUE; | 189 return true; |
190 } | 190 } |
191 | 191 |
192 FX_BOOL CFXJSE_Value::DeleteObjectProperty(const CFX_ByteStringC& szPropName) { | 192 bool CFXJSE_Value::DeleteObjectProperty(const CFX_ByteStringC& szPropName) { |
193 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 193 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
194 v8::Local<v8::Value> hObject = | 194 v8::Local<v8::Value> hObject = |
195 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 195 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
196 if (!hObject->IsObject()) | 196 if (!hObject->IsObject()) |
197 return FALSE; | 197 return false; |
198 | 198 |
199 hObject.As<v8::Object>()->Delete(v8::String::NewFromUtf8( | 199 hObject.As<v8::Object>()->Delete(v8::String::NewFromUtf8( |
200 m_pIsolate, szPropName.c_str(), v8::String::kNormalString, | 200 m_pIsolate, szPropName.c_str(), v8::String::kNormalString, |
201 szPropName.GetLength())); | 201 szPropName.GetLength())); |
202 return TRUE; | 202 return true; |
203 } | 203 } |
204 | 204 |
205 FX_BOOL CFXJSE_Value::HasObjectOwnProperty(const CFX_ByteStringC& szPropName, | 205 bool CFXJSE_Value::HasObjectOwnProperty(const CFX_ByteStringC& szPropName, |
206 FX_BOOL bUseTypeGetter) { | 206 bool bUseTypeGetter) { |
207 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 207 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
208 v8::Local<v8::Value> hObject = | 208 v8::Local<v8::Value> hObject = |
209 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 209 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
210 if (!hObject->IsObject()) | 210 if (!hObject->IsObject()) |
211 return FALSE; | 211 return false; |
212 | 212 |
213 v8::Local<v8::String> hKey = v8::String::NewFromUtf8( | 213 v8::Local<v8::String> hKey = v8::String::NewFromUtf8( |
214 m_pIsolate, szPropName.c_str(), v8::String::kNormalString, | 214 m_pIsolate, szPropName.c_str(), v8::String::kNormalString, |
215 szPropName.GetLength()); | 215 szPropName.GetLength()); |
216 return hObject.As<v8::Object>()->HasRealNamedProperty(hKey) || | 216 return hObject.As<v8::Object>()->HasRealNamedProperty(hKey) || |
217 (bUseTypeGetter && | 217 (bUseTypeGetter && |
218 hObject.As<v8::Object>() | 218 hObject.As<v8::Object>() |
219 ->HasOwnProperty(m_pIsolate->GetCurrentContext(), hKey) | 219 ->HasOwnProperty(m_pIsolate->GetCurrentContext(), hKey) |
220 .FromMaybe(false)); | 220 .FromMaybe(false)); |
221 } | 221 } |
222 | 222 |
223 FX_BOOL CFXJSE_Value::SetObjectOwnProperty(const CFX_ByteStringC& szPropName, | 223 bool CFXJSE_Value::SetObjectOwnProperty(const CFX_ByteStringC& szPropName, |
224 CFXJSE_Value* lpPropValue) { | 224 CFXJSE_Value* lpPropValue) { |
225 ASSERT(lpPropValue); | 225 ASSERT(lpPropValue); |
226 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 226 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
227 v8::Local<v8::Value> hObject = | 227 v8::Local<v8::Value> hObject = |
228 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 228 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
229 if (!hObject->IsObject()) | 229 if (!hObject->IsObject()) |
230 return FALSE; | 230 return false; |
231 | 231 |
232 v8::Local<v8::Value> pValue = | 232 v8::Local<v8::Value> pValue = |
233 v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->m_hValue); | 233 v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->m_hValue); |
234 return hObject.As<v8::Object>() | 234 return hObject.As<v8::Object>() |
235 ->DefineOwnProperty( | 235 ->DefineOwnProperty( |
236 m_pIsolate->GetCurrentContext(), | 236 m_pIsolate->GetCurrentContext(), |
237 v8::String::NewFromUtf8(m_pIsolate, szPropName.c_str(), | 237 v8::String::NewFromUtf8(m_pIsolate, szPropName.c_str(), |
238 v8::String::kNormalString, | 238 v8::String::kNormalString, |
239 szPropName.GetLength()), | 239 szPropName.GetLength()), |
240 pValue) | 240 pValue) |
241 .FromMaybe(false); | 241 .FromMaybe(false); |
242 } | 242 } |
243 | 243 |
244 FX_BOOL CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction, | 244 bool CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction, |
245 CFXJSE_Value* lpNewThis) { | 245 CFXJSE_Value* lpNewThis) { |
246 ASSERT(lpOldFunction && lpNewThis); | 246 ASSERT(lpOldFunction && lpNewThis); |
247 | 247 |
248 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 248 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
249 v8::Local<v8::Value> rgArgs[2]; | 249 v8::Local<v8::Value> rgArgs[2]; |
250 v8::Local<v8::Value> hOldFunction = | 250 v8::Local<v8::Value> hOldFunction = |
251 v8::Local<v8::Value>::New(m_pIsolate, lpOldFunction->DirectGetValue()); | 251 v8::Local<v8::Value>::New(m_pIsolate, lpOldFunction->DirectGetValue()); |
252 if (hOldFunction.IsEmpty() || !hOldFunction->IsFunction()) | 252 if (hOldFunction.IsEmpty() || !hOldFunction->IsFunction()) |
253 return FALSE; | 253 return false; |
254 | 254 |
255 rgArgs[0] = hOldFunction; | 255 rgArgs[0] = hOldFunction; |
256 v8::Local<v8::Value> hNewThis = | 256 v8::Local<v8::Value> hNewThis = |
257 v8::Local<v8::Value>::New(m_pIsolate, lpNewThis->DirectGetValue()); | 257 v8::Local<v8::Value>::New(m_pIsolate, lpNewThis->DirectGetValue()); |
258 if (hNewThis.IsEmpty()) | 258 if (hNewThis.IsEmpty()) |
259 return FALSE; | 259 return false; |
260 | 260 |
261 rgArgs[1] = hNewThis; | 261 rgArgs[1] = hNewThis; |
262 v8::Local<v8::String> hBinderFuncSource = | 262 v8::Local<v8::String> hBinderFuncSource = |
263 v8::String::NewFromUtf8(m_pIsolate, | 263 v8::String::NewFromUtf8(m_pIsolate, |
264 "(function (oldfunction, newthis) { return " | 264 "(function (oldfunction, newthis) { return " |
265 "oldfunction.bind(newthis); })"); | 265 "oldfunction.bind(newthis); })"); |
266 v8::Local<v8::Function> hBinderFunc = | 266 v8::Local<v8::Function> hBinderFunc = |
267 v8::Script::Compile(hBinderFuncSource)->Run().As<v8::Function>(); | 267 v8::Script::Compile(hBinderFuncSource)->Run().As<v8::Function>(); |
268 v8::Local<v8::Value> hBoundFunction = | 268 v8::Local<v8::Value> hBoundFunction = |
269 hBinderFunc->Call(m_pIsolate->GetCurrentContext()->Global(), 2, rgArgs); | 269 hBinderFunc->Call(m_pIsolate->GetCurrentContext()->Global(), 2, rgArgs); |
270 if (hBoundFunction.IsEmpty() || !hBoundFunction->IsFunction()) | 270 if (hBoundFunction.IsEmpty() || !hBoundFunction->IsFunction()) |
271 return FALSE; | 271 return false; |
272 | 272 |
273 m_hValue.Reset(m_pIsolate, hBoundFunction); | 273 m_hValue.Reset(m_pIsolate, hBoundFunction); |
274 return TRUE; | 274 return true; |
275 } | 275 } |
276 | 276 |
277 #define FXJSE_INVALID_PTR ((void*)(intptr_t)-1) | 277 #define FXJSE_INVALID_PTR ((void*)(intptr_t)-1) |
278 FX_BOOL CFXJSE_Value::Call(CFXJSE_Value* lpReceiver, | 278 bool CFXJSE_Value::Call(CFXJSE_Value* lpReceiver, |
279 CFXJSE_Value* lpRetValue, | 279 CFXJSE_Value* lpRetValue, |
280 uint32_t nArgCount, | 280 uint32_t nArgCount, |
281 CFXJSE_Value** lpArgs) { | 281 CFXJSE_Value** lpArgs) { |
282 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 282 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
283 v8::Local<v8::Value> hFunctionValue = | 283 v8::Local<v8::Value> hFunctionValue = |
284 v8::Local<v8::Value>::New(m_pIsolate, DirectGetValue()); | 284 v8::Local<v8::Value>::New(m_pIsolate, DirectGetValue()); |
285 v8::Local<v8::Object> hFunctionObject = | 285 v8::Local<v8::Object> hFunctionObject = |
286 !hFunctionValue.IsEmpty() && hFunctionValue->IsObject() | 286 !hFunctionValue.IsEmpty() && hFunctionValue->IsObject() |
287 ? hFunctionValue.As<v8::Object>() | 287 ? hFunctionValue.As<v8::Object>() |
288 : v8::Local<v8::Object>(); | 288 : v8::Local<v8::Object>(); |
289 | 289 |
290 v8::TryCatch trycatch(m_pIsolate); | 290 v8::TryCatch trycatch(m_pIsolate); |
291 if (hFunctionObject.IsEmpty() || !hFunctionObject->IsCallable()) { | 291 if (hFunctionObject.IsEmpty() || !hFunctionObject->IsCallable()) { |
292 if (lpRetValue) | 292 if (lpRetValue) |
293 lpRetValue->ForceSetValue(FXJSE_CreateReturnValue(m_pIsolate, trycatch)); | 293 lpRetValue->ForceSetValue(FXJSE_CreateReturnValue(m_pIsolate, trycatch)); |
294 return FALSE; | 294 return false; |
295 } | 295 } |
296 | 296 |
297 v8::Local<v8::Value> hReturnValue; | 297 v8::Local<v8::Value> hReturnValue; |
298 v8::Local<v8::Value>* lpLocalArgs = NULL; | 298 v8::Local<v8::Value>* lpLocalArgs = NULL; |
299 if (nArgCount) { | 299 if (nArgCount) { |
300 lpLocalArgs = FX_Alloc(v8::Local<v8::Value>, nArgCount); | 300 lpLocalArgs = FX_Alloc(v8::Local<v8::Value>, nArgCount); |
301 for (uint32_t i = 0; i < nArgCount; i++) { | 301 for (uint32_t i = 0; i < nArgCount; i++) { |
302 new (lpLocalArgs + i) v8::Local<v8::Value>; | 302 new (lpLocalArgs + i) v8::Local<v8::Value>; |
303 CFXJSE_Value* lpArg = lpArgs[i]; | 303 CFXJSE_Value* lpArg = lpArgs[i]; |
304 if (lpArg) { | 304 if (lpArg) { |
305 lpLocalArgs[i] = | 305 lpLocalArgs[i] = |
306 v8::Local<v8::Value>::New(m_pIsolate, lpArg->DirectGetValue()); | 306 v8::Local<v8::Value>::New(m_pIsolate, lpArg->DirectGetValue()); |
307 } | 307 } |
308 if (lpLocalArgs[i].IsEmpty()) { | 308 if (lpLocalArgs[i].IsEmpty()) { |
309 lpLocalArgs[i] = v8::Undefined(m_pIsolate); | 309 lpLocalArgs[i] = v8::Undefined(m_pIsolate); |
310 } | 310 } |
311 } | 311 } |
312 } | 312 } |
313 | 313 |
314 FX_BOOL bRetValue = TRUE; | 314 bool bRetValue = true; |
315 if (lpReceiver == FXJSE_INVALID_PTR) { | 315 if (lpReceiver == FXJSE_INVALID_PTR) { |
316 v8::MaybeLocal<v8::Value> maybe_retvalue = | 316 v8::MaybeLocal<v8::Value> maybe_retvalue = |
317 hFunctionObject->CallAsConstructor(m_pIsolate->GetCurrentContext(), | 317 hFunctionObject->CallAsConstructor(m_pIsolate->GetCurrentContext(), |
318 nArgCount, lpLocalArgs); | 318 nArgCount, lpLocalArgs); |
319 hReturnValue = maybe_retvalue.FromMaybe(v8::Local<v8::Value>()); | 319 hReturnValue = maybe_retvalue.FromMaybe(v8::Local<v8::Value>()); |
320 } else { | 320 } else { |
321 v8::Local<v8::Value> hReceiver; | 321 v8::Local<v8::Value> hReceiver; |
322 if (lpReceiver) { | 322 if (lpReceiver) { |
323 hReceiver = | 323 hReceiver = |
324 v8::Local<v8::Value>::New(m_pIsolate, lpReceiver->DirectGetValue()); | 324 v8::Local<v8::Value>::New(m_pIsolate, lpReceiver->DirectGetValue()); |
325 } | 325 } |
326 if (hReceiver.IsEmpty() || !hReceiver->IsObject()) | 326 if (hReceiver.IsEmpty() || !hReceiver->IsObject()) |
327 hReceiver = v8::Object::New(m_pIsolate); | 327 hReceiver = v8::Object::New(m_pIsolate); |
328 | 328 |
329 v8::MaybeLocal<v8::Value> maybe_retvalue = hFunctionObject->CallAsFunction( | 329 v8::MaybeLocal<v8::Value> maybe_retvalue = hFunctionObject->CallAsFunction( |
330 m_pIsolate->GetCurrentContext(), hReceiver, nArgCount, lpLocalArgs); | 330 m_pIsolate->GetCurrentContext(), hReceiver, nArgCount, lpLocalArgs); |
331 hReturnValue = maybe_retvalue.FromMaybe(v8::Local<v8::Value>()); | 331 hReturnValue = maybe_retvalue.FromMaybe(v8::Local<v8::Value>()); |
332 } | 332 } |
333 | 333 |
334 if (trycatch.HasCaught()) { | 334 if (trycatch.HasCaught()) { |
335 hReturnValue = FXJSE_CreateReturnValue(m_pIsolate, trycatch); | 335 hReturnValue = FXJSE_CreateReturnValue(m_pIsolate, trycatch); |
336 bRetValue = FALSE; | 336 bRetValue = false; |
337 } | 337 } |
338 | 338 |
339 if (lpRetValue) | 339 if (lpRetValue) |
340 lpRetValue->ForceSetValue(hReturnValue); | 340 lpRetValue->ForceSetValue(hReturnValue); |
341 | 341 |
342 if (lpLocalArgs) { | 342 if (lpLocalArgs) { |
343 for (uint32_t i = 0; i < nArgCount; i++) | 343 for (uint32_t i = 0; i < nArgCount; i++) |
344 lpLocalArgs[i].~Local(); | 344 lpLocalArgs[i].~Local(); |
345 FX_Free(lpLocalArgs); | 345 FX_Free(lpLocalArgs); |
346 } | 346 } |
347 return bRetValue; | 347 return bRetValue; |
348 } | 348 } |
349 | 349 |
350 FX_BOOL CFXJSE_Value::IsUndefined() const { | 350 bool CFXJSE_Value::IsUndefined() const { |
351 if (m_hValue.IsEmpty()) | 351 if (m_hValue.IsEmpty()) |
352 return FALSE; | 352 return false; |
353 | 353 |
354 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 354 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
355 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 355 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
356 return hValue->IsUndefined(); | 356 return hValue->IsUndefined(); |
357 } | 357 } |
358 | 358 |
359 FX_BOOL CFXJSE_Value::IsNull() const { | 359 bool CFXJSE_Value::IsNull() const { |
360 if (m_hValue.IsEmpty()) | 360 if (m_hValue.IsEmpty()) |
361 return FALSE; | 361 return false; |
362 | 362 |
363 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 363 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
364 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 364 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
365 return hValue->IsNull(); | 365 return hValue->IsNull(); |
366 } | 366 } |
367 | 367 |
368 FX_BOOL CFXJSE_Value::IsBoolean() const { | 368 bool CFXJSE_Value::IsBoolean() const { |
369 if (m_hValue.IsEmpty()) | 369 if (m_hValue.IsEmpty()) |
370 return FALSE; | 370 return false; |
371 | 371 |
372 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 372 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
373 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 373 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
374 return hValue->IsBoolean(); | 374 return hValue->IsBoolean(); |
375 } | 375 } |
376 | 376 |
377 FX_BOOL CFXJSE_Value::IsString() const { | 377 bool CFXJSE_Value::IsString() const { |
378 if (m_hValue.IsEmpty()) | 378 if (m_hValue.IsEmpty()) |
379 return FALSE; | 379 return false; |
380 | 380 |
381 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 381 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
382 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 382 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
383 return hValue->IsString(); | 383 return hValue->IsString(); |
384 } | 384 } |
385 | 385 |
386 FX_BOOL CFXJSE_Value::IsNumber() const { | 386 bool CFXJSE_Value::IsNumber() const { |
387 if (m_hValue.IsEmpty()) | 387 if (m_hValue.IsEmpty()) |
388 return FALSE; | 388 return false; |
389 | 389 |
390 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 390 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
391 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 391 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
392 return hValue->IsNumber(); | 392 return hValue->IsNumber(); |
393 } | 393 } |
394 | 394 |
395 FX_BOOL CFXJSE_Value::IsInteger() const { | 395 bool CFXJSE_Value::IsInteger() const { |
396 if (m_hValue.IsEmpty()) | 396 if (m_hValue.IsEmpty()) |
397 return FALSE; | 397 return false; |
398 | 398 |
399 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 399 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
400 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 400 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
401 return hValue->IsInt32(); | 401 return hValue->IsInt32(); |
402 } | 402 } |
403 | 403 |
404 FX_BOOL CFXJSE_Value::IsObject() const { | 404 bool CFXJSE_Value::IsObject() const { |
405 if (m_hValue.IsEmpty()) | 405 if (m_hValue.IsEmpty()) |
406 return FALSE; | 406 return false; |
407 | 407 |
408 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 408 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
409 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 409 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
410 return hValue->IsObject(); | 410 return hValue->IsObject(); |
411 } | 411 } |
412 | 412 |
413 FX_BOOL CFXJSE_Value::IsArray() const { | 413 bool CFXJSE_Value::IsArray() const { |
414 if (m_hValue.IsEmpty()) | 414 if (m_hValue.IsEmpty()) |
415 return FALSE; | 415 return false; |
416 | 416 |
417 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 417 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
418 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 418 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
419 return hValue->IsArray(); | 419 return hValue->IsArray(); |
420 } | 420 } |
421 | 421 |
422 FX_BOOL CFXJSE_Value::IsFunction() const { | 422 bool CFXJSE_Value::IsFunction() const { |
423 if (m_hValue.IsEmpty()) | 423 if (m_hValue.IsEmpty()) |
424 return FALSE; | 424 return false; |
425 | 425 |
426 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 426 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
427 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 427 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
428 return hValue->IsFunction(); | 428 return hValue->IsFunction(); |
429 } | 429 } |
430 | 430 |
431 FX_BOOL CFXJSE_Value::IsDate() const { | 431 bool CFXJSE_Value::IsDate() const { |
432 if (m_hValue.IsEmpty()) | 432 if (m_hValue.IsEmpty()) |
433 return FALSE; | 433 return false; |
434 | 434 |
435 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 435 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
436 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 436 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
437 return hValue->IsDate(); | 437 return hValue->IsDate(); |
438 } | 438 } |
439 | 439 |
440 FX_BOOL CFXJSE_Value::ToBoolean() const { | 440 bool CFXJSE_Value::ToBoolean() const { |
441 ASSERT(!m_hValue.IsEmpty()); | 441 ASSERT(!m_hValue.IsEmpty()); |
442 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 442 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
443 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 443 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
444 return static_cast<FX_BOOL>(hValue->BooleanValue()); | 444 return static_cast<bool>(hValue->BooleanValue()); |
445 } | 445 } |
446 | 446 |
447 FX_FLOAT CFXJSE_Value::ToFloat() const { | 447 FX_FLOAT CFXJSE_Value::ToFloat() const { |
448 ASSERT(!m_hValue.IsEmpty()); | 448 ASSERT(!m_hValue.IsEmpty()); |
449 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 449 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
450 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 450 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
451 return static_cast<FX_FLOAT>(hValue->NumberValue()); | 451 return static_cast<FX_FLOAT>(hValue->NumberValue()); |
452 } | 452 } |
453 | 453 |
454 double CFXJSE_Value::ToDouble() const { | 454 double CFXJSE_Value::ToDouble() const { |
(...skipping 24 matching lines...) Expand all Loading... |
479 v8::Local<v8::Value> hValue = v8::Undefined(m_pIsolate); | 479 v8::Local<v8::Value> hValue = v8::Undefined(m_pIsolate); |
480 m_hValue.Reset(m_pIsolate, hValue); | 480 m_hValue.Reset(m_pIsolate, hValue); |
481 } | 481 } |
482 | 482 |
483 void CFXJSE_Value::SetNull() { | 483 void CFXJSE_Value::SetNull() { |
484 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 484 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
485 v8::Local<v8::Value> hValue = v8::Null(m_pIsolate); | 485 v8::Local<v8::Value> hValue = v8::Null(m_pIsolate); |
486 m_hValue.Reset(m_pIsolate, hValue); | 486 m_hValue.Reset(m_pIsolate, hValue); |
487 } | 487 } |
488 | 488 |
489 void CFXJSE_Value::SetBoolean(FX_BOOL bBoolean) { | 489 void CFXJSE_Value::SetBoolean(bool bBoolean) { |
490 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 490 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
491 v8::Local<v8::Value> hValue = v8::Boolean::New(m_pIsolate, bBoolean != FALSE); | 491 v8::Local<v8::Value> hValue = v8::Boolean::New(m_pIsolate, bBoolean != false); |
492 m_hValue.Reset(m_pIsolate, hValue); | 492 m_hValue.Reset(m_pIsolate, hValue); |
493 } | 493 } |
494 | 494 |
495 void CFXJSE_Value::SetInteger(int32_t nInteger) { | 495 void CFXJSE_Value::SetInteger(int32_t nInteger) { |
496 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 496 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
497 v8::Local<v8::Value> hValue = v8::Integer::New(m_pIsolate, nInteger); | 497 v8::Local<v8::Value> hValue = v8::Integer::New(m_pIsolate, nInteger); |
498 m_hValue.Reset(m_pIsolate, hValue); | 498 m_hValue.Reset(m_pIsolate, hValue); |
499 } | 499 } |
500 | 500 |
501 void CFXJSE_Value::SetDouble(double dDouble) { | 501 void CFXJSE_Value::SetDouble(double dDouble) { |
502 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 502 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
503 v8::Local<v8::Value> hValue = v8::Number::New(m_pIsolate, dDouble); | 503 v8::Local<v8::Value> hValue = v8::Number::New(m_pIsolate, dDouble); |
504 m_hValue.Reset(m_pIsolate, hValue); | 504 m_hValue.Reset(m_pIsolate, hValue); |
505 } | 505 } |
506 | 506 |
507 void CFXJSE_Value::SetString(const CFX_ByteStringC& szString) { | 507 void CFXJSE_Value::SetString(const CFX_ByteStringC& szString) { |
508 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 508 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
509 v8::Local<v8::Value> hValue = v8::String::NewFromUtf8( | 509 v8::Local<v8::Value> hValue = v8::String::NewFromUtf8( |
510 m_pIsolate, reinterpret_cast<const char*>(szString.raw_str()), | 510 m_pIsolate, reinterpret_cast<const char*>(szString.raw_str()), |
511 v8::String::kNormalString, szString.GetLength()); | 511 v8::String::kNormalString, szString.GetLength()); |
512 m_hValue.Reset(m_pIsolate, hValue); | 512 m_hValue.Reset(m_pIsolate, hValue); |
513 } | 513 } |
514 | 514 |
515 void CFXJSE_Value::SetJSObject() { | 515 void CFXJSE_Value::SetJSObject() { |
516 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 516 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
517 v8::Local<v8::Value> hValue = v8::Object::New(m_pIsolate); | 517 v8::Local<v8::Value> hValue = v8::Object::New(m_pIsolate); |
518 m_hValue.Reset(m_pIsolate, hValue); | 518 m_hValue.Reset(m_pIsolate, hValue); |
519 } | 519 } |
OLD | NEW |