OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * Copyright (C) 2012 Ericsson AB. All rights reserved. | 3 * Copyright (C) 2012 Ericsson AB. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 v8::Local<v8::Value> createMinimumArityTypeErrorForConstructor(v8::Isolate*, con
st char* type, unsigned expected, unsigned provided); | 82 v8::Local<v8::Value> createMinimumArityTypeErrorForConstructor(v8::Isolate*, con
st char* type, unsigned expected, unsigned provided); |
83 CORE_EXPORT void setMinimumArityTypeError(ExceptionState&, unsigned expected, un
signed provided); | 83 CORE_EXPORT void setMinimumArityTypeError(ExceptionState&, unsigned expected, un
signed provided); |
84 | 84 |
85 template<typename CallbackInfo, typename S> | 85 template<typename CallbackInfo, typename S> |
86 inline void v8SetReturnValue(const CallbackInfo& info, const v8::Persistent<S>&
handle) | 86 inline void v8SetReturnValue(const CallbackInfo& info, const v8::Persistent<S>&
handle) |
87 { | 87 { |
88 info.GetReturnValue().Set(handle); | 88 info.GetReturnValue().Set(handle); |
89 } | 89 } |
90 | 90 |
91 template<typename CallbackInfo, typename S> | 91 template<typename CallbackInfo, typename S> |
92 inline void v8SetReturnValue(const CallbackInfo& info, const v8::Handle<S> handl
e) | 92 inline void v8SetReturnValue(const CallbackInfo& info, const v8::Local<S> handle
) |
93 { | 93 { |
94 info.GetReturnValue().Set(handle); | 94 info.GetReturnValue().Set(handle); |
95 } | 95 } |
96 | 96 |
97 template<typename CallbackInfo, typename S> | 97 template<typename CallbackInfo, typename S> |
98 inline void v8SetReturnValue(const CallbackInfo& info, v8::MaybeLocal<S> maybe) | 98 inline void v8SetReturnValue(const CallbackInfo& info, v8::MaybeLocal<S> maybe) |
99 { | 99 { |
100 if (LIKELY(!maybe.IsEmpty())) | 100 if (LIKELY(!maybe.IsEmpty())) |
101 info.GetReturnValue().Set(maybe.ToLocalChecked()); | 101 info.GetReturnValue().Set(maybe.ToLocalChecked()); |
102 } | 102 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 193 |
194 template<typename CallbackInfo> | 194 template<typename CallbackInfo> |
195 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, ScriptWrappable*
impl) | 195 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, ScriptWrappable*
impl) |
196 { | 196 { |
197 if (UNLIKELY(!impl)) { | 197 if (UNLIKELY(!impl)) { |
198 v8SetReturnValueNull(callbackInfo); | 198 v8SetReturnValueNull(callbackInfo); |
199 return; | 199 return; |
200 } | 200 } |
201 if (DOMDataStore::setReturnValue(callbackInfo.GetReturnValue(), impl)) | 201 if (DOMDataStore::setReturnValue(callbackInfo.GetReturnValue(), impl)) |
202 return; | 202 return; |
203 v8::Handle<v8::Object> wrapper = impl->wrap(callbackInfo.Holder(), callbackI
nfo.GetIsolate()); | 203 v8::Local<v8::Object> wrapper = impl->wrap(callbackInfo.Holder(), callbackIn
fo.GetIsolate()); |
204 v8SetReturnValue(callbackInfo, wrapper); | 204 v8SetReturnValue(callbackInfo, wrapper); |
205 } | 205 } |
206 | 206 |
207 template<typename CallbackInfo> | 207 template<typename CallbackInfo> |
208 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, Node* impl) | 208 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, Node* impl) |
209 { | 209 { |
210 if (UNLIKELY(!impl)) { | 210 if (UNLIKELY(!impl)) { |
211 v8SetReturnValueNull(callbackInfo); | 211 v8SetReturnValueNull(callbackInfo); |
212 return; | 212 return; |
213 } | 213 } |
214 if (DOMDataStore::setReturnValue(callbackInfo.GetReturnValue(), impl)) | 214 if (DOMDataStore::setReturnValue(callbackInfo.GetReturnValue(), impl)) |
215 return; | 215 return; |
216 v8::Handle<v8::Object> wrapper = ScriptWrappable::fromNode(impl)->wrap(callb
ackInfo.Holder(), callbackInfo.GetIsolate()); | 216 v8::Local<v8::Object> wrapper = ScriptWrappable::fromNode(impl)->wrap(callba
ckInfo.Holder(), callbackInfo.GetIsolate()); |
217 v8SetReturnValue(callbackInfo, wrapper); | 217 v8SetReturnValue(callbackInfo, wrapper); |
218 } | 218 } |
219 | 219 |
220 // Special versions for DOMWindow, WorkerGlobalScope and EventTarget | 220 // Special versions for DOMWindow, WorkerGlobalScope and EventTarget |
221 | 221 |
222 template<typename CallbackInfo> | 222 template<typename CallbackInfo> |
223 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, DOMWindow* impl) | 223 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, DOMWindow* impl) |
224 { | 224 { |
225 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); | 225 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); |
226 } | 226 } |
(...skipping 25 matching lines...) Expand all Loading... |
252 template<typename CallbackInfo> | 252 template<typename CallbackInfo> |
253 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, Scrip
tWrappable* impl) | 253 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, Scrip
tWrappable* impl) |
254 { | 254 { |
255 ASSERT(DOMWrapperWorld::current(callbackInfo.GetIsolate()).isMainWorld()); | 255 ASSERT(DOMWrapperWorld::current(callbackInfo.GetIsolate()).isMainWorld()); |
256 if (UNLIKELY(!impl)) { | 256 if (UNLIKELY(!impl)) { |
257 v8SetReturnValueNull(callbackInfo); | 257 v8SetReturnValueNull(callbackInfo); |
258 return; | 258 return; |
259 } | 259 } |
260 if (DOMDataStore::setReturnValueForMainWorld(callbackInfo.GetReturnValue(),
impl)) | 260 if (DOMDataStore::setReturnValueForMainWorld(callbackInfo.GetReturnValue(),
impl)) |
261 return; | 261 return; |
262 v8::Handle<v8::Object> wrapper = impl->wrap(callbackInfo.Holder(), callbackI
nfo.GetIsolate()); | 262 v8::Local<v8::Object> wrapper = impl->wrap(callbackInfo.Holder(), callbackIn
fo.GetIsolate()); |
263 v8SetReturnValue(callbackInfo, wrapper); | 263 v8SetReturnValue(callbackInfo, wrapper); |
264 } | 264 } |
265 | 265 |
266 template<typename CallbackInfo> | 266 template<typename CallbackInfo> |
267 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, Node*
impl) | 267 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, Node*
impl) |
268 { | 268 { |
269 // Since EventTarget has a special version of ToV8 and V8EventTarget.h | 269 // Since EventTarget has a special version of ToV8 and V8EventTarget.h |
270 // defines its own v8SetReturnValue family, which are slow, we need to | 270 // defines its own v8SetReturnValue family, which are slow, we need to |
271 // override them with optimized versions for Node and its subclasses. | 271 // override them with optimized versions for Node and its subclasses. |
272 // Without this overload, v8SetReturnValueForMainWorld for Node would be | 272 // Without this overload, v8SetReturnValueForMainWorld for Node would be |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 321 |
322 template<typename CallbackInfo> | 322 template<typename CallbackInfo> |
323 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, ScriptWrappab
le* impl, const ScriptWrappable* wrappable) | 323 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, ScriptWrappab
le* impl, const ScriptWrappable* wrappable) |
324 { | 324 { |
325 if (UNLIKELY(!impl)) { | 325 if (UNLIKELY(!impl)) { |
326 v8SetReturnValueNull(callbackInfo); | 326 v8SetReturnValueNull(callbackInfo); |
327 return; | 327 return; |
328 } | 328 } |
329 if (DOMDataStore::setReturnValueFast(callbackInfo.GetReturnValue(), impl, ca
llbackInfo.Holder(), wrappable)) | 329 if (DOMDataStore::setReturnValueFast(callbackInfo.GetReturnValue(), impl, ca
llbackInfo.Holder(), wrappable)) |
330 return; | 330 return; |
331 v8::Handle<v8::Object> wrapper = impl->wrap(callbackInfo.Holder(), callbackI
nfo.GetIsolate()); | 331 v8::Local<v8::Object> wrapper = impl->wrap(callbackInfo.Holder(), callbackIn
fo.GetIsolate()); |
332 v8SetReturnValue(callbackInfo, wrapper); | 332 v8SetReturnValue(callbackInfo, wrapper); |
333 } | 333 } |
334 | 334 |
335 template<typename CallbackInfo> | 335 template<typename CallbackInfo> |
336 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, Node* impl, c
onst ScriptWrappable* wrappable) | 336 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, Node* impl, c
onst ScriptWrappable* wrappable) |
337 { | 337 { |
338 if (UNLIKELY(!impl)) { | 338 if (UNLIKELY(!impl)) { |
339 v8SetReturnValueNull(callbackInfo); | 339 v8SetReturnValueNull(callbackInfo); |
340 return; | 340 return; |
341 } | 341 } |
342 if (DOMDataStore::setReturnValueFast(callbackInfo.GetReturnValue(), impl, ca
llbackInfo.Holder(), wrappable)) | 342 if (DOMDataStore::setReturnValueFast(callbackInfo.GetReturnValue(), impl, ca
llbackInfo.Holder(), wrappable)) |
343 return; | 343 return; |
344 v8::Handle<v8::Object> wrapper = ScriptWrappable::fromNode(impl)->wrap(callb
ackInfo.Holder(), callbackInfo.GetIsolate()); | 344 v8::Local<v8::Object> wrapper = ScriptWrappable::fromNode(impl)->wrap(callba
ckInfo.Holder(), callbackInfo.GetIsolate()); |
345 v8SetReturnValue(callbackInfo, wrapper); | 345 v8SetReturnValue(callbackInfo, wrapper); |
346 } | 346 } |
347 | 347 |
348 // Special versions for DOMWindow, WorkerGlobalScope and EventTarget | 348 // Special versions for DOMWindow, WorkerGlobalScope and EventTarget |
349 | 349 |
350 template<typename CallbackInfo> | 350 template<typename CallbackInfo> |
351 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, DOMWindow* im
pl, const ScriptWrappable*) | 351 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, DOMWindow* im
pl, const ScriptWrappable*) |
352 { | 352 { |
353 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); | 353 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); |
354 } | 354 } |
(...skipping 18 matching lines...) Expand all Loading... |
373 | 373 |
374 template<typename CallbackInfo, typename T, typename Wrappable> | 374 template<typename CallbackInfo, typename T, typename Wrappable> |
375 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, RawPtr<T> imp
l, const Wrappable* wrappable) | 375 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, RawPtr<T> imp
l, const Wrappable* wrappable) |
376 { | 376 { |
377 v8SetReturnValueFast(callbackInfo, impl.get(), wrappable); | 377 v8SetReturnValueFast(callbackInfo, impl.get(), wrappable); |
378 } | 378 } |
379 | 379 |
380 // Convert v8::String to a WTF::String. If the V8 string is not already | 380 // Convert v8::String to a WTF::String. If the V8 string is not already |
381 // an external string then it is transformed into an external string at this | 381 // an external string then it is transformed into an external string at this |
382 // point to avoid repeated conversions. | 382 // point to avoid repeated conversions. |
383 inline String toCoreString(v8::Handle<v8::String> value) | 383 inline String toCoreString(v8::Local<v8::String> value) |
384 { | 384 { |
385 return v8StringToWebCoreString<String>(value, Externalize); | 385 return v8StringToWebCoreString<String>(value, Externalize); |
386 } | 386 } |
387 | 387 |
388 inline String toCoreStringWithNullCheck(v8::Handle<v8::String> value) | 388 inline String toCoreStringWithNullCheck(v8::Local<v8::String> value) |
389 { | 389 { |
390 if (value.IsEmpty() || value->IsNull()) | 390 if (value.IsEmpty() || value->IsNull()) |
391 return String(); | 391 return String(); |
392 return toCoreString(value); | 392 return toCoreString(value); |
393 } | 393 } |
394 | 394 |
395 inline String toCoreStringWithUndefinedOrNullCheck(v8::Handle<v8::String> value) | 395 inline String toCoreStringWithUndefinedOrNullCheck(v8::Local<v8::String> value) |
396 { | 396 { |
397 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) | 397 if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) |
398 return String(); | 398 return String(); |
399 return toCoreString(value); | 399 return toCoreString(value); |
400 } | 400 } |
401 | 401 |
402 inline AtomicString toCoreAtomicString(v8::Handle<v8::String> value) | 402 inline AtomicString toCoreAtomicString(v8::Local<v8::String> value) |
403 { | 403 { |
404 return v8StringToWebCoreString<AtomicString>(value, Externalize); | 404 return v8StringToWebCoreString<AtomicString>(value, Externalize); |
405 } | 405 } |
406 | 406 |
407 // This method will return a null String if the v8::Value does not contain a v8:
:String. | 407 // This method will return a null String if the v8::Value does not contain a v8:
:String. |
408 // It will not call ToString() on the v8::Value. If you want ToString() to be ca
lled, | 408 // It will not call ToString() on the v8::Value. If you want ToString() to be ca
lled, |
409 // please use the TONATIVE_FOR_V8STRINGRESOURCE_*() macros instead. | 409 // please use the TONATIVE_FOR_V8STRINGRESOURCE_*() macros instead. |
410 inline String toCoreStringWithUndefinedOrNullCheck(v8::Handle<v8::Value> value) | 410 inline String toCoreStringWithUndefinedOrNullCheck(v8::Local<v8::Value> value) |
411 { | 411 { |
412 if (value.IsEmpty() || !value->IsString()) | 412 if (value.IsEmpty() || !value->IsString()) |
413 return String(); | 413 return String(); |
414 return toCoreString(value.As<v8::String>()); | 414 return toCoreString(value.As<v8::String>()); |
415 } | 415 } |
416 | 416 |
417 // Convert a string to a V8 string. | 417 // Convert a string to a V8 string. |
418 // Return a V8 external string that shares the underlying buffer with the given | 418 // Return a V8 external string that shares the underlying buffer with the given |
419 // WebCore string. The reference counting mechanism is used to keep the | 419 // WebCore string. The reference counting mechanism is used to keep the |
420 // underlying buffer alive while the string is still live in the V8 engine. | 420 // underlying buffer alive while the string is still live in the V8 engine. |
421 inline v8::Handle<v8::String> v8String(v8::Isolate* isolate, const String& strin
g) | 421 inline v8::Local<v8::String> v8String(v8::Isolate* isolate, const String& string
) |
422 { | 422 { |
423 if (string.isNull()) | 423 if (string.isNull()) |
424 return v8::String::Empty(isolate); | 424 return v8::String::Empty(isolate); |
425 return V8PerIsolateData::from(isolate)->stringCache()->v8ExternalString(isol
ate, string.impl()); | 425 return V8PerIsolateData::from(isolate)->stringCache()->v8ExternalString(isol
ate, string.impl()); |
426 } | 426 } |
427 | 427 |
428 inline v8::Handle<v8::String> v8AtomicString(v8::Isolate* isolate, const char* s
tr, int length = -1) | 428 inline v8::Local<v8::String> v8AtomicString(v8::Isolate* isolate, const char* st
r, int length = -1) |
429 { | 429 { |
430 ASSERT(isolate); | 430 ASSERT(isolate); |
431 v8::Local<v8::String> value; | 431 v8::Local<v8::String> value; |
432 if (LIKELY(v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kInterna
lized, length).ToLocal(&value))) | 432 if (LIKELY(v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kInterna
lized, length).ToLocal(&value))) |
433 return value; | 433 return value; |
434 // Immediately crashes when NewFromUtf8() fails because it only fails the | 434 // Immediately crashes when NewFromUtf8() fails because it only fails the |
435 // given str is too long. | 435 // given str is too long. |
436 RELEASE_ASSERT_NOT_REACHED(); | 436 RELEASE_ASSERT_NOT_REACHED(); |
437 return v8::String::Empty(isolate); | 437 return v8::String::Empty(isolate); |
438 } | 438 } |
439 | 439 |
440 inline v8::Handle<v8::Value> v8Undefined() | 440 inline v8::Local<v8::Value> v8Undefined() |
441 { | 441 { |
442 return v8::Handle<v8::Value>(); | 442 return v8::Local<v8::Value>(); |
443 } | 443 } |
444 | 444 |
445 // Conversion flags, used in toIntXX/toUIntXX. | 445 // Conversion flags, used in toIntXX/toUIntXX. |
446 enum IntegerConversionConfiguration { | 446 enum IntegerConversionConfiguration { |
447 NormalConversion, | 447 NormalConversion, |
448 EnforceRange, | 448 EnforceRange, |
449 Clamp | 449 Clamp |
450 }; | 450 }; |
451 | 451 |
452 // Convert a value to a boolean. | 452 // Convert a value to a boolean. |
453 CORE_EXPORT bool toBooleanSlow(v8::Isolate*, v8::Local<v8::Value>, ExceptionStat
e&); | 453 CORE_EXPORT bool toBooleanSlow(v8::Isolate*, v8::Local<v8::Value>, ExceptionStat
e&); |
454 inline bool toBoolean(v8::Isolate* isolate, v8::Local<v8::Value> value, Exceptio
nState& exceptionState) | 454 inline bool toBoolean(v8::Isolate* isolate, v8::Local<v8::Value> value, Exceptio
nState& exceptionState) |
455 { | 455 { |
456 if (LIKELY(value->IsBoolean())) | 456 if (LIKELY(value->IsBoolean())) |
457 return value.As<v8::Boolean>()->Value(); | 457 return value.As<v8::Boolean>()->Value(); |
458 return toBooleanSlow(isolate, value, exceptionState); | 458 return toBooleanSlow(isolate, value, exceptionState); |
459 } | 459 } |
460 | 460 |
461 // Convert a value to a 8-bit signed integer. The conversion fails if the | 461 // Convert a value to a 8-bit signed integer. The conversion fails if the |
462 // value cannot be converted to a number or the range violated per WebIDL: | 462 // value cannot be converted to a number or the range violated per WebIDL: |
463 // http://www.w3.org/TR/WebIDL/#es-byte | 463 // http://www.w3.org/TR/WebIDL/#es-byte |
464 CORE_EXPORT int8_t toInt8(v8::Isolate*, v8::Handle<v8::Value>, IntegerConversion
Configuration, ExceptionState&); | 464 CORE_EXPORT int8_t toInt8(v8::Isolate*, v8::Local<v8::Value>, IntegerConversionC
onfiguration, ExceptionState&); |
465 | 465 |
466 // Convert a value to a 8-bit unsigned integer. The conversion fails if the | 466 // Convert a value to a 8-bit unsigned integer. The conversion fails if the |
467 // value cannot be converted to a number or the range violated per WebIDL: | 467 // value cannot be converted to a number or the range violated per WebIDL: |
468 // http://www.w3.org/TR/WebIDL/#es-octet | 468 // http://www.w3.org/TR/WebIDL/#es-octet |
469 CORE_EXPORT uint8_t toUInt8(v8::Isolate*, v8::Handle<v8::Value>, IntegerConversi
onConfiguration, ExceptionState&); | 469 CORE_EXPORT uint8_t toUInt8(v8::Isolate*, v8::Local<v8::Value>, IntegerConversio
nConfiguration, ExceptionState&); |
470 | 470 |
471 // Convert a value to a 16-bit signed integer. The conversion fails if the | 471 // Convert a value to a 16-bit signed integer. The conversion fails if the |
472 // value cannot be converted to a number or the range violated per WebIDL: | 472 // value cannot be converted to a number or the range violated per WebIDL: |
473 // http://www.w3.org/TR/WebIDL/#es-short | 473 // http://www.w3.org/TR/WebIDL/#es-short |
474 CORE_EXPORT int16_t toInt16(v8::Isolate*, v8::Handle<v8::Value>, IntegerConversi
onConfiguration, ExceptionState&); | 474 CORE_EXPORT int16_t toInt16(v8::Isolate*, v8::Local<v8::Value>, IntegerConversio
nConfiguration, ExceptionState&); |
475 | 475 |
476 // Convert a value to a 16-bit unsigned integer. The conversion fails if the | 476 // Convert a value to a 16-bit unsigned integer. The conversion fails if the |
477 // value cannot be converted to a number or the range violated per WebIDL: | 477 // value cannot be converted to a number or the range violated per WebIDL: |
478 // http://www.w3.org/TR/WebIDL/#es-unsigned-short | 478 // http://www.w3.org/TR/WebIDL/#es-unsigned-short |
479 CORE_EXPORT uint16_t toUInt16(v8::Isolate*, v8::Handle<v8::Value>, IntegerConver
sionConfiguration, ExceptionState&); | 479 CORE_EXPORT uint16_t toUInt16(v8::Isolate*, v8::Local<v8::Value>, IntegerConvers
ionConfiguration, ExceptionState&); |
480 | 480 |
481 // Convert a value to a 32-bit signed integer. The conversion fails if the | 481 // Convert a value to a 32-bit signed integer. The conversion fails if the |
482 // value cannot be converted to a number or the range violated per WebIDL: | 482 // value cannot be converted to a number or the range violated per WebIDL: |
483 // http://www.w3.org/TR/WebIDL/#es-long | 483 // http://www.w3.org/TR/WebIDL/#es-long |
484 CORE_EXPORT int32_t toInt32Slow(v8::Isolate*, v8::Handle<v8::Value>, IntegerConv
ersionConfiguration, ExceptionState&); | 484 CORE_EXPORT int32_t toInt32Slow(v8::Isolate*, v8::Local<v8::Value>, IntegerConve
rsionConfiguration, ExceptionState&); |
485 inline int32_t toInt32(v8::Isolate* isolate, v8::Handle<v8::Value> value, Intege
rConversionConfiguration configuration, ExceptionState& exceptionState) | 485 inline int32_t toInt32(v8::Isolate* isolate, v8::Local<v8::Value> value, Integer
ConversionConfiguration configuration, ExceptionState& exceptionState) |
486 { | 486 { |
487 // Fast case. The value is already a 32-bit integer. | 487 // Fast case. The value is already a 32-bit integer. |
488 if (LIKELY(value->IsInt32())) | 488 if (LIKELY(value->IsInt32())) |
489 return value.As<v8::Int32>()->Value(); | 489 return value.As<v8::Int32>()->Value(); |
490 return toInt32Slow(isolate, value, configuration, exceptionState); | 490 return toInt32Slow(isolate, value, configuration, exceptionState); |
491 } | 491 } |
492 | 492 |
493 // Convert a value to a 32-bit unsigned integer. The conversion fails if the | 493 // Convert a value to a 32-bit unsigned integer. The conversion fails if the |
494 // value cannot be converted to a number or the range violated per WebIDL: | 494 // value cannot be converted to a number or the range violated per WebIDL: |
495 // http://www.w3.org/TR/WebIDL/#es-unsigned-long | 495 // http://www.w3.org/TR/WebIDL/#es-unsigned-long |
496 CORE_EXPORT uint32_t toUInt32Slow(v8::Isolate*, v8::Handle<v8::Value>, IntegerCo
nversionConfiguration, ExceptionState&); | 496 CORE_EXPORT uint32_t toUInt32Slow(v8::Isolate*, v8::Local<v8::Value>, IntegerCon
versionConfiguration, ExceptionState&); |
497 inline uint32_t toUInt32(v8::Isolate* isolate, v8::Handle<v8::Value> value, Inte
gerConversionConfiguration configuration, ExceptionState& exceptionState) | 497 inline uint32_t toUInt32(v8::Isolate* isolate, v8::Local<v8::Value> value, Integ
erConversionConfiguration configuration, ExceptionState& exceptionState) |
498 { | 498 { |
499 // Fast case. The value is already a 32-bit unsigned integer. | 499 // Fast case. The value is already a 32-bit unsigned integer. |
500 if (LIKELY(value->IsUint32())) | 500 if (LIKELY(value->IsUint32())) |
501 return value.As<v8::Uint32>()->Value(); | 501 return value.As<v8::Uint32>()->Value(); |
502 | 502 |
503 // Fast case. The value is a 32-bit signed integer with NormalConversion con
figuration. | 503 // Fast case. The value is a 32-bit signed integer with NormalConversion con
figuration. |
504 if (LIKELY(value->IsInt32() && configuration == NormalConversion)) | 504 if (LIKELY(value->IsInt32() && configuration == NormalConversion)) |
505 return value.As<v8::Int32>()->Value(); | 505 return value.As<v8::Int32>()->Value(); |
506 | 506 |
507 return toUInt32Slow(isolate, value, configuration, exceptionState); | 507 return toUInt32Slow(isolate, value, configuration, exceptionState); |
508 } | 508 } |
509 | 509 |
510 // Convert a value to a 64-bit signed integer. The conversion fails if the | 510 // Convert a value to a 64-bit signed integer. The conversion fails if the |
511 // value cannot be converted to a number or the range violated per WebIDL: | 511 // value cannot be converted to a number or the range violated per WebIDL: |
512 // http://www.w3.org/TR/WebIDL/#es-long-long | 512 // http://www.w3.org/TR/WebIDL/#es-long-long |
513 CORE_EXPORT int64_t toInt64Slow(v8::Isolate*, v8::Handle<v8::Value>, IntegerConv
ersionConfiguration, ExceptionState&); | 513 CORE_EXPORT int64_t toInt64Slow(v8::Isolate*, v8::Local<v8::Value>, IntegerConve
rsionConfiguration, ExceptionState&); |
514 inline int64_t toInt64(v8::Isolate* isolate, v8::Handle<v8::Value> value, Intege
rConversionConfiguration configuration, ExceptionState& exceptionState) | 514 inline int64_t toInt64(v8::Isolate* isolate, v8::Local<v8::Value> value, Integer
ConversionConfiguration configuration, ExceptionState& exceptionState) |
515 { | 515 { |
516 // Clamping not supported for int64_t/long long int. See Source/wtf/MathExtr
as.h. | 516 // Clamping not supported for int64_t/long long int. See Source/wtf/MathExtr
as.h. |
517 ASSERT(configuration != Clamp); | 517 ASSERT(configuration != Clamp); |
518 | 518 |
519 // Fast case. The value is a 32-bit integer. | 519 // Fast case. The value is a 32-bit integer. |
520 if (LIKELY(value->IsInt32())) | 520 if (LIKELY(value->IsInt32())) |
521 return value.As<v8::Int32>()->Value(); | 521 return value.As<v8::Int32>()->Value(); |
522 | 522 |
523 return toInt64Slow(isolate, value, configuration, exceptionState); | 523 return toInt64Slow(isolate, value, configuration, exceptionState); |
524 } | 524 } |
525 | 525 |
526 // Convert a value to a 64-bit unsigned integer. The conversion fails if the | 526 // Convert a value to a 64-bit unsigned integer. The conversion fails if the |
527 // value cannot be converted to a number or the range violated per WebIDL: | 527 // value cannot be converted to a number or the range violated per WebIDL: |
528 // http://www.w3.org/TR/WebIDL/#es-unsigned-long-long | 528 // http://www.w3.org/TR/WebIDL/#es-unsigned-long-long |
529 CORE_EXPORT uint64_t toUInt64Slow(v8::Isolate*, v8::Handle<v8::Value>, IntegerCo
nversionConfiguration, ExceptionState&); | 529 CORE_EXPORT uint64_t toUInt64Slow(v8::Isolate*, v8::Local<v8::Value>, IntegerCon
versionConfiguration, ExceptionState&); |
530 inline uint64_t toUInt64(v8::Isolate* isolate, v8::Handle<v8::Value> value, Inte
gerConversionConfiguration configuration, ExceptionState& exceptionState) | 530 inline uint64_t toUInt64(v8::Isolate* isolate, v8::Local<v8::Value> value, Integ
erConversionConfiguration configuration, ExceptionState& exceptionState) |
531 { | 531 { |
532 // Fast case. The value is a 32-bit unsigned integer. | 532 // Fast case. The value is a 32-bit unsigned integer. |
533 if (LIKELY(value->IsUint32())) | 533 if (LIKELY(value->IsUint32())) |
534 return value.As<v8::Uint32>()->Value(); | 534 return value.As<v8::Uint32>()->Value(); |
535 | 535 |
536 if (LIKELY(value->IsInt32() && configuration == NormalConversion)) | 536 if (LIKELY(value->IsInt32() && configuration == NormalConversion)) |
537 return value.As<v8::Int32>()->Value(); | 537 return value.As<v8::Int32>()->Value(); |
538 | 538 |
539 return toUInt64Slow(isolate, value, configuration, exceptionState); | 539 return toUInt64Slow(isolate, value, configuration, exceptionState); |
540 } | 540 } |
541 | 541 |
542 // Convert a value to a double precision float, which might fail. | 542 // Convert a value to a double precision float, which might fail. |
543 CORE_EXPORT double toDoubleSlow(v8::Isolate*, v8::Handle<v8::Value>, ExceptionSt
ate&); | 543 CORE_EXPORT double toDoubleSlow(v8::Isolate*, v8::Local<v8::Value>, ExceptionSta
te&); |
544 inline double toDouble(v8::Isolate* isolate, v8::Handle<v8::Value> value, Except
ionState& exceptionState) | 544 inline double toDouble(v8::Isolate* isolate, v8::Local<v8::Value> value, Excepti
onState& exceptionState) |
545 { | 545 { |
546 if (LIKELY(value->IsNumber())) | 546 if (LIKELY(value->IsNumber())) |
547 return value.As<v8::Number>()->Value(); | 547 return value.As<v8::Number>()->Value(); |
548 return toDoubleSlow(isolate, value, exceptionState); | 548 return toDoubleSlow(isolate, value, exceptionState); |
549 } | 549 } |
550 | 550 |
551 // Convert a value to a double precision float, throwing on non-finite values. | 551 // Convert a value to a double precision float, throwing on non-finite values. |
552 CORE_EXPORT double toRestrictedDouble(v8::Isolate*, v8::Handle<v8::Value>, Excep
tionState&); | 552 CORE_EXPORT double toRestrictedDouble(v8::Isolate*, v8::Local<v8::Value>, Except
ionState&); |
553 | 553 |
554 // Convert a value to a single precision float, which might fail. | 554 // Convert a value to a single precision float, which might fail. |
555 inline float toFloat(v8::Isolate* isolate, v8::Handle<v8::Value> value, Exceptio
nState& exceptionState) | 555 inline float toFloat(v8::Isolate* isolate, v8::Local<v8::Value> value, Exception
State& exceptionState) |
556 { | 556 { |
557 return static_cast<float>(toDouble(isolate, value, exceptionState)); | 557 return static_cast<float>(toDouble(isolate, value, exceptionState)); |
558 } | 558 } |
559 | 559 |
560 // Convert a value to a single precision float, throwing on non-finite values. | 560 // Convert a value to a single precision float, throwing on non-finite values. |
561 CORE_EXPORT float toRestrictedFloat(v8::Isolate*, v8::Handle<v8::Value>, Excepti
onState&); | 561 CORE_EXPORT float toRestrictedFloat(v8::Isolate*, v8::Local<v8::Value>, Exceptio
nState&); |
562 | 562 |
563 // Converts a value to a String, throwing if any code unit is outside 0-255. | 563 // Converts a value to a String, throwing if any code unit is outside 0-255. |
564 CORE_EXPORT String toByteString(v8::Isolate*, v8::Handle<v8::Value>, ExceptionSt
ate&); | 564 CORE_EXPORT String toByteString(v8::Isolate*, v8::Local<v8::Value>, ExceptionSta
te&); |
565 | 565 |
566 // Converts a value to a String, replacing unmatched UTF-16 surrogates with repl
acement characters. | 566 // Converts a value to a String, replacing unmatched UTF-16 surrogates with repl
acement characters. |
567 CORE_EXPORT String toUSVString(v8::Isolate*, v8::Handle<v8::Value>, ExceptionSta
te&); | 567 CORE_EXPORT String toUSVString(v8::Isolate*, v8::Local<v8::Value>, ExceptionStat
e&); |
568 | 568 |
569 inline v8::Handle<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) | 569 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) |
570 { | 570 { |
571 return value ? v8::True(isolate) : v8::False(isolate); | 571 return value ? v8::True(isolate) : v8::False(isolate); |
572 } | 572 } |
573 | 573 |
574 inline double toCoreDate(v8::Isolate* isolate, v8::Handle<v8::Value> object) | 574 inline double toCoreDate(v8::Isolate* isolate, v8::Local<v8::Value> object) |
575 { | 575 { |
576 if (object->IsDate()) | 576 if (object->IsDate()) |
577 return object.As<v8::Date>()->ValueOf(); | 577 return object.As<v8::Date>()->ValueOf(); |
578 if (object->IsNumber()) | 578 if (object->IsNumber()) |
579 return object.As<v8::Number>()->Value(); | 579 return object.As<v8::Number>()->Value(); |
580 return std::numeric_limits<double>::quiet_NaN(); | 580 return std::numeric_limits<double>::quiet_NaN(); |
581 } | 581 } |
582 | 582 |
583 inline v8::MaybeLocal<v8::Value> v8DateOrNaN(v8::Isolate* isolate, double value) | 583 inline v8::MaybeLocal<v8::Value> v8DateOrNaN(v8::Isolate* isolate, double value) |
584 { | 584 { |
585 ASSERT(isolate); | 585 ASSERT(isolate); |
586 return v8::Date::New(isolate->GetCurrentContext(), std::isfinite(value) ? va
lue : std::numeric_limits<double>::quiet_NaN()); | 586 return v8::Date::New(isolate->GetCurrentContext(), std::isfinite(value) ? va
lue : std::numeric_limits<double>::quiet_NaN()); |
587 } | 587 } |
588 | 588 |
589 // FIXME: Remove the special casing for NodeFilter and XPathNSResolver. | 589 // FIXME: Remove the special casing for NodeFilter and XPathNSResolver. |
590 PassRefPtrWillBeRawPtr<NodeFilter> toNodeFilter(v8::Handle<v8::Value>, v8::Handl
e<v8::Object>, ScriptState*); | 590 PassRefPtrWillBeRawPtr<NodeFilter> toNodeFilter(v8::Local<v8::Value>, v8::Local<
v8::Object>, ScriptState*); |
591 XPathNSResolver* toXPathNSResolver(ScriptState*, v8::Handle<v8::Value>); | 591 XPathNSResolver* toXPathNSResolver(ScriptState*, v8::Local<v8::Value>); |
592 | 592 |
593 bool toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::Isolate*, Excepti
onState&); | 593 bool toV8Sequence(v8::Local<v8::Value>, uint32_t& length, v8::Isolate*, Exceptio
nState&); |
594 | 594 |
595 // Converts a JavaScript value to an array as per the Web IDL specification: | 595 // Converts a JavaScript value to an array as per the Web IDL specification: |
596 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 596 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
597 template <class T, class V8T> | 597 template <class T, class V8T> |
598 Vector<RefPtr<T>> toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, uin
t32_t length, v8::Isolate* isolate, ExceptionState& exceptionState) | 598 Vector<RefPtr<T>> toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, uin
t32_t length, v8::Isolate* isolate, ExceptionState& exceptionState) |
599 { | 599 { |
600 Vector<RefPtr<T>> result; | 600 Vector<RefPtr<T>> result; |
601 result.reserveInitialCapacity(length); | 601 result.reserveInitialCapacity(length); |
602 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 602 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
603 v8::TryCatch block; | 603 v8::TryCatch block; |
604 for (uint32_t i = 0; i < length; ++i) { | 604 for (uint32_t i = 0; i < length; ++i) { |
605 v8::Local<v8::Value> element; | 605 v8::Local<v8::Value> element; |
606 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { | 606 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { |
607 exceptionState.rethrowV8Exception(block.Exception()); | 607 exceptionState.rethrowV8Exception(block.Exception()); |
608 return Vector<RefPtr<T>>(); | 608 return Vector<RefPtr<T>>(); |
609 } | 609 } |
610 if (V8T::hasInstance(element, isolate)) { | 610 if (V8T::hasInstance(element, isolate)) { |
611 v8::Local<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(e
lement); | 611 v8::Local<v8::Object> elementObject = v8::Local<v8::Object>::Cast(el
ement); |
612 result.uncheckedAppend(V8T::toImpl(elementObject)); | 612 result.uncheckedAppend(V8T::toImpl(elementObject)); |
613 } else { | 613 } else { |
614 exceptionState.throwTypeError("Invalid Array element type"); | 614 exceptionState.throwTypeError("Invalid Array element type"); |
615 return Vector<RefPtr<T>>(); | 615 return Vector<RefPtr<T>>(); |
616 } | 616 } |
617 } | 617 } |
618 return result; | 618 return result; |
619 } | 619 } |
620 | 620 |
621 template <class T, class V8T> | 621 template <class T, class V8T> |
622 Vector<RefPtr<T>> toRefPtrNativeArray(v8::Local<v8::Value> value, int argumentIn
dex, v8::Isolate* isolate, ExceptionState& exceptionState) | 622 Vector<RefPtr<T>> toRefPtrNativeArray(v8::Local<v8::Value> value, int argumentIn
dex, v8::Isolate* isolate, ExceptionState& exceptionState) |
623 { | 623 { |
624 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 624 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
625 uint32_t length = 0; | 625 uint32_t length = 0; |
626 if (value->IsArray()) { | 626 if (value->IsArray()) { |
627 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 627 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
628 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { | 628 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
629 if (!exceptionState.hadException()) | 629 if (!exceptionState.hadException()) |
630 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum
entOrValue(argumentIndex)); | 630 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum
entOrValue(argumentIndex)); |
631 return Vector<RefPtr<T>>(); | 631 return Vector<RefPtr<T>>(); |
632 } | 632 } |
633 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, except
ionState); | 633 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, except
ionState); |
634 } | 634 } |
635 | 635 |
636 template <class T, class V8T> | 636 template <class T, class V8T> |
637 Vector<RefPtr<T>> toRefPtrNativeArray(v8::Handle<v8::Value> value, const String&
propertyName, v8::Isolate* isolate, ExceptionState& exceptionState) | 637 Vector<RefPtr<T>> toRefPtrNativeArray(v8::Local<v8::Value> value, const String&
propertyName, v8::Isolate* isolate, ExceptionState& exceptionState) |
638 { | 638 { |
639 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 639 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
640 uint32_t length = 0; | 640 uint32_t length = 0; |
641 if (value->IsArray()) { | 641 if (value->IsArray()) { |
642 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 642 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
643 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { | 643 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
644 if (!exceptionState.hadException()) | 644 if (!exceptionState.hadException()) |
645 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePro
perty(propertyName)); | 645 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePro
perty(propertyName)); |
646 return Vector<RefPtr<T>>(); | 646 return Vector<RefPtr<T>>(); |
647 } | 647 } |
(...skipping 17 matching lines...) Expand all Loading... |
665 result.reserveInitialCapacity(length); | 665 result.reserveInitialCapacity(length); |
666 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 666 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
667 v8::TryCatch block; | 667 v8::TryCatch block; |
668 for (uint32_t i = 0; i < length; ++i) { | 668 for (uint32_t i = 0; i < length; ++i) { |
669 v8::Local<v8::Value> element; | 669 v8::Local<v8::Value> element; |
670 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { | 670 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { |
671 exceptionState.rethrowV8Exception(block.Exception()); | 671 exceptionState.rethrowV8Exception(block.Exception()); |
672 return WillBeHeapVector<RefPtrWillBeMember<T>>(); | 672 return WillBeHeapVector<RefPtrWillBeMember<T>>(); |
673 } | 673 } |
674 if (V8T::hasInstance(element, isolate)) { | 674 if (V8T::hasInstance(element, isolate)) { |
675 v8::Local<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(e
lement); | 675 v8::Local<v8::Object> elementObject = v8::Local<v8::Object>::Cast(el
ement); |
676 result.uncheckedAppend(V8T::toImpl(elementObject)); | 676 result.uncheckedAppend(V8T::toImpl(elementObject)); |
677 } else { | 677 } else { |
678 exceptionState.throwTypeError("Invalid Array element type"); | 678 exceptionState.throwTypeError("Invalid Array element type"); |
679 return WillBeHeapVector<RefPtrWillBeMember<T>>(); | 679 return WillBeHeapVector<RefPtrWillBeMember<T>>(); |
680 } | 680 } |
681 } | 681 } |
682 return result; | 682 return result; |
683 } | 683 } |
684 | 684 |
685 template <class T, class V8T> | 685 template <class T, class V8T> |
(...skipping 13 matching lines...) Expand all Loading... |
699 result.reserveInitialCapacity(length); | 699 result.reserveInitialCapacity(length); |
700 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 700 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
701 v8::TryCatch block; | 701 v8::TryCatch block; |
702 for (uint32_t i = 0; i < length; ++i) { | 702 for (uint32_t i = 0; i < length; ++i) { |
703 v8::Local<v8::Value> element; | 703 v8::Local<v8::Value> element; |
704 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { | 704 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { |
705 exceptionState.rethrowV8Exception(block.Exception()); | 705 exceptionState.rethrowV8Exception(block.Exception()); |
706 return WillBeHeapVector<RefPtrWillBeMember<T>>(); | 706 return WillBeHeapVector<RefPtrWillBeMember<T>>(); |
707 } | 707 } |
708 if (V8T::hasInstance(element, isolate)) { | 708 if (V8T::hasInstance(element, isolate)) { |
709 v8::Local<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(e
lement); | 709 v8::Local<v8::Object> elementObject = v8::Local<v8::Object>::Cast(el
ement); |
710 result.uncheckedAppend(V8T::toImpl(elementObject)); | 710 result.uncheckedAppend(V8T::toImpl(elementObject)); |
711 } else { | 711 } else { |
712 exceptionState.throwTypeError("Invalid Array element type"); | 712 exceptionState.throwTypeError("Invalid Array element type"); |
713 return WillBeHeapVector<RefPtrWillBeMember<T>>(); | 713 return WillBeHeapVector<RefPtrWillBeMember<T>>(); |
714 } | 714 } |
715 } | 715 } |
716 return result; | 716 return result; |
717 } | 717 } |
718 | 718 |
719 template <class T, class V8T> | 719 template <class T, class V8T> |
(...skipping 13 matching lines...) Expand all Loading... |
733 result.reserveInitialCapacity(length); | 733 result.reserveInitialCapacity(length); |
734 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 734 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
735 v8::TryCatch block; | 735 v8::TryCatch block; |
736 for (uint32_t i = 0; i < length; ++i) { | 736 for (uint32_t i = 0; i < length; ++i) { |
737 v8::Local<v8::Value> element; | 737 v8::Local<v8::Value> element; |
738 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { | 738 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { |
739 exceptionState.rethrowV8Exception(block.Exception()); | 739 exceptionState.rethrowV8Exception(block.Exception()); |
740 return HeapVector<Member<T>>(); | 740 return HeapVector<Member<T>>(); |
741 } | 741 } |
742 if (V8T::hasInstance(element, isolate)) { | 742 if (V8T::hasInstance(element, isolate)) { |
743 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); | 743 v8::Local<v8::Object> elementObject = v8::Local<v8::Object>::Cast(el
ement); |
744 result.uncheckedAppend(V8T::toImpl(elementObject)); | 744 result.uncheckedAppend(V8T::toImpl(elementObject)); |
745 } else { | 745 } else { |
746 exceptionState.throwTypeError("Invalid Array element type"); | 746 exceptionState.throwTypeError("Invalid Array element type"); |
747 return HeapVector<Member<T>>(); | 747 return HeapVector<Member<T>>(); |
748 } | 748 } |
749 } | 749 } |
750 return result; | 750 return result; |
751 } | 751 } |
752 | 752 |
753 // Converts a JavaScript value to an array as per the Web IDL specification: | 753 // Converts a JavaScript value to an array as per the Web IDL specification: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 result.uncheckedAppend(TraitsType::nativeValue(info.GetIsolate(), in
fo[i], exceptionState)); | 813 result.uncheckedAppend(TraitsType::nativeValue(info.GetIsolate(), in
fo[i], exceptionState)); |
814 if (exceptionState.hadException()) | 814 if (exceptionState.hadException()) |
815 return Vector<T>(); | 815 return Vector<T>(); |
816 } | 816 } |
817 } | 817 } |
818 return result; | 818 return result; |
819 } | 819 } |
820 | 820 |
821 // Validates that the passed object is a sequence type per WebIDL spec | 821 // Validates that the passed object is a sequence type per WebIDL spec |
822 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence | 822 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence |
823 inline bool toV8Sequence(v8::Handle<v8::Value> value, uint32_t& length, v8::Isol
ate* isolate, ExceptionState& exceptionState) | 823 inline bool toV8Sequence(v8::Local<v8::Value> value, uint32_t& length, v8::Isola
te* isolate, ExceptionState& exceptionState) |
824 { | 824 { |
825 // Attempt converting to a sequence if the value is not already an array but
is | 825 // Attempt converting to a sequence if the value is not already an array but
is |
826 // any kind of object except for a native Date object or a native RegExp obj
ect. | 826 // any kind of object except for a native Date object or a native RegExp obj
ect. |
827 ASSERT(!value->IsArray()); | 827 ASSERT(!value->IsArray()); |
828 // FIXME: Do we really need to special case Date and RegExp object? | 828 // FIXME: Do we really need to special case Date and RegExp object? |
829 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806 | 829 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806 |
830 if (!value->IsObject() || value->IsDate() || value->IsRegExp()) { | 830 if (!value->IsObject() || value->IsDate() || value->IsRegExp()) { |
831 // The caller is responsible for reporting a TypeError. | 831 // The caller is responsible for reporting a TypeError. |
832 return false; | 832 return false; |
833 } | 833 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 | 930 |
931 using JSONValuePtr = PassRefPtr<JSONValue>; | 931 using JSONValuePtr = PassRefPtr<JSONValue>; |
932 template <> | 932 template <> |
933 struct NativeValueTraits<JSONValuePtr> { | 933 struct NativeValueTraits<JSONValuePtr> { |
934 CORE_EXPORT static JSONValuePtr nativeValue(v8::Isolate*, v8::Local<v8::Valu
e>, ExceptionState&, int maxDepth = JSONValue::maxDepth); | 934 CORE_EXPORT static JSONValuePtr nativeValue(v8::Isolate*, v8::Local<v8::Valu
e>, ExceptionState&, int maxDepth = JSONValue::maxDepth); |
935 }; | 935 }; |
936 | 936 |
937 CORE_EXPORT v8::Isolate* toIsolate(ExecutionContext*); | 937 CORE_EXPORT v8::Isolate* toIsolate(ExecutionContext*); |
938 CORE_EXPORT v8::Isolate* toIsolate(LocalFrame*); | 938 CORE_EXPORT v8::Isolate* toIsolate(LocalFrame*); |
939 | 939 |
940 DOMWindow* toDOMWindow(v8::Isolate*, v8::Handle<v8::Value>); | 940 DOMWindow* toDOMWindow(v8::Isolate*, v8::Local<v8::Value>); |
941 DOMWindow* toDOMWindow(v8::Handle<v8::Context>); | 941 DOMWindow* toDOMWindow(v8::Local<v8::Context>); |
942 LocalDOMWindow* enteredDOMWindow(v8::Isolate*); | 942 LocalDOMWindow* enteredDOMWindow(v8::Isolate*); |
943 CORE_EXPORT LocalDOMWindow* currentDOMWindow(v8::Isolate*); | 943 CORE_EXPORT LocalDOMWindow* currentDOMWindow(v8::Isolate*); |
944 LocalDOMWindow* callingDOMWindow(v8::Isolate*); | 944 LocalDOMWindow* callingDOMWindow(v8::Isolate*); |
945 ExecutionContext* toExecutionContext(v8::Handle<v8::Context>); | 945 ExecutionContext* toExecutionContext(v8::Local<v8::Context>); |
946 CORE_EXPORT ExecutionContext* currentExecutionContext(v8::Isolate*); | 946 CORE_EXPORT ExecutionContext* currentExecutionContext(v8::Isolate*); |
947 CORE_EXPORT ExecutionContext* callingExecutionContext(v8::Isolate*); | 947 CORE_EXPORT ExecutionContext* callingExecutionContext(v8::Isolate*); |
948 | 948 |
949 // Returns a V8 context associated with a ExecutionContext and a DOMWrapperWorld
. | 949 // Returns a V8 context associated with a ExecutionContext and a DOMWrapperWorld
. |
950 // This method returns an empty context if there is no frame or the frame is alr
eady detached. | 950 // This method returns an empty context if there is no frame or the frame is alr
eady detached. |
951 CORE_EXPORT v8::Local<v8::Context> toV8Context(ExecutionContext*, DOMWrapperWorl
d&); | 951 CORE_EXPORT v8::Local<v8::Context> toV8Context(ExecutionContext*, DOMWrapperWorl
d&); |
952 // Returns a V8 context associated with a Frame and a DOMWrapperWorld. | 952 // Returns a V8 context associated with a Frame and a DOMWrapperWorld. |
953 // This method returns an empty context if the frame is already detached. | 953 // This method returns an empty context if the frame is already detached. |
954 CORE_EXPORT v8::Local<v8::Context> toV8Context(Frame*, DOMWrapperWorld&); | 954 CORE_EXPORT v8::Local<v8::Context> toV8Context(Frame*, DOMWrapperWorld&); |
955 | 955 |
956 // Returns the frame object of the window object associated with | 956 // Returns the frame object of the window object associated with |
957 // a context, if the window is currently being displayed in a Frame. | 957 // a context, if the window is currently being displayed in a Frame. |
958 CORE_EXPORT Frame* toFrameIfNotDetached(v8::Handle<v8::Context>); | 958 CORE_EXPORT Frame* toFrameIfNotDetached(v8::Local<v8::Context>); |
959 | 959 |
960 CORE_EXPORT EventTarget* toEventTarget(v8::Isolate*, v8::Handle<v8::Value>); | 960 CORE_EXPORT EventTarget* toEventTarget(v8::Isolate*, v8::Local<v8::Value>); |
961 | 961 |
962 // If the current context causes out of memory, JavaScript setting | 962 // If the current context causes out of memory, JavaScript setting |
963 // is disabled and it returns true. | 963 // is disabled and it returns true. |
964 bool handleOutOfMemory(); | 964 bool handleOutOfMemory(); |
965 void crashIfV8IsDead(); | 965 void crashIfV8IsDead(); |
966 | 966 |
967 inline bool isUndefinedOrNull(v8::Handle<v8::Value> value) | 967 inline bool isUndefinedOrNull(v8::Local<v8::Value> value) |
968 { | 968 { |
969 return value.IsEmpty() || value->IsNull() || value->IsUndefined(); | 969 return value.IsEmpty() || value->IsNull() || value->IsUndefined(); |
970 } | 970 } |
971 v8::Handle<v8::Function> getBoundFunction(v8::Handle<v8::Function>); | 971 v8::Local<v8::Function> getBoundFunction(v8::Local<v8::Function>); |
972 | 972 |
973 // Attaches |environment| to |function| and returns it. | 973 // Attaches |environment| to |function| and returns it. |
974 inline v8::Local<v8::Function> createClosure(v8::FunctionCallback function, v8::
Handle<v8::Value> environment, v8::Isolate* isolate) | 974 inline v8::Local<v8::Function> createClosure(v8::FunctionCallback function, v8::
Local<v8::Value> environment, v8::Isolate* isolate) |
975 { | 975 { |
976 return v8::Function::New(isolate, function, environment); | 976 return v8::Function::New(isolate, function, environment); |
977 } | 977 } |
978 | 978 |
979 // FIXME: This will be soon embedded in the generated code. | 979 // FIXME: This will be soon embedded in the generated code. |
980 template<class Collection> static void indexedPropertyEnumerator(const v8::Prope
rtyCallbackInfo<v8::Array>& info) | 980 template<class Collection> static void indexedPropertyEnumerator(const v8::Prope
rtyCallbackInfo<v8::Array>& info) |
981 { | 981 { |
982 Collection* collection = toScriptWrappable(info.Holder())->toImpl<Collection
>(); | 982 Collection* collection = toScriptWrappable(info.Holder())->toImpl<Collection
>(); |
983 int length = collection->length(); | 983 int length = collection->length(); |
984 v8::Handle<v8::Array> properties = v8::Array::New(info.GetIsolate(), length)
; | 984 v8::Local<v8::Array> properties = v8::Array::New(info.GetIsolate(), length); |
985 for (int i = 0; i < length; ++i) { | 985 for (int i = 0; i < length; ++i) { |
986 // FIXME: Do we need to check that the item function returns a non-null
value for this index? | 986 // FIXME: Do we need to check that the item function returns a non-null
value for this index? |
987 v8::Handle<v8::Integer> integer = v8::Integer::New(info.GetIsolate(), i)
; | 987 v8::Local<v8::Integer> integer = v8::Integer::New(info.GetIsolate(), i); |
988 properties->Set(integer, integer); | 988 properties->Set(integer, integer); |
989 } | 989 } |
990 v8SetReturnValue(info, properties); | 990 v8SetReturnValue(info, properties); |
991 } | 991 } |
992 | 992 |
993 CORE_EXPORT bool isValidEnum(const String& value, const char** validValues, size
_t length, const String& enumName, ExceptionState&); | 993 CORE_EXPORT bool isValidEnum(const String& value, const char** validValues, size
_t length, const String& enumName, ExceptionState&); |
994 CORE_EXPORT bool isValidEnum(const Vector<String>& values, const char** validVal
ues, size_t length, const String& enumName, ExceptionState&); | 994 CORE_EXPORT bool isValidEnum(const Vector<String>& values, const char** validVal
ues, size_t length, const String& enumName, ExceptionState&); |
995 | 995 |
996 // These methods store hidden values into an array that is stored in the interna
l field of a DOM wrapper. | 996 // These methods store hidden values into an array that is stored in the interna
l field of a DOM wrapper. |
997 void addHiddenValueToArray(v8::Isolate*, v8::Handle<v8::Object>, v8::Local<v8::V
alue>, int cacheIndex); | 997 void addHiddenValueToArray(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v8::Va
lue>, int cacheIndex); |
998 void removeHiddenValueFromArray(v8::Isolate*, v8::Handle<v8::Object>, v8::Local<
v8::Value>, int cacheIndex); | 998 void removeHiddenValueFromArray(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v
8::Value>, int cacheIndex); |
999 CORE_EXPORT void moveEventListenerToNewWrapper(v8::Isolate*, v8::Handle<v8::Obje
ct>, EventListener* oldValue, v8::Local<v8::Value> newValue, int cacheIndex); | 999 CORE_EXPORT void moveEventListenerToNewWrapper(v8::Isolate*, v8::Local<v8::Objec
t>, EventListener* oldValue, v8::Local<v8::Value> newValue, int cacheIndex); |
1000 | 1000 |
1001 // Result values for platform object 'deleter' methods, | 1001 // Result values for platform object 'deleter' methods, |
1002 // http://www.w3.org/TR/WebIDL/#delete | 1002 // http://www.w3.org/TR/WebIDL/#delete |
1003 enum DeleteResult { | 1003 enum DeleteResult { |
1004 DeleteSuccess, | 1004 DeleteSuccess, |
1005 DeleteReject, | 1005 DeleteReject, |
1006 DeleteUnknownProperty | 1006 DeleteUnknownProperty |
1007 }; | 1007 }; |
1008 | 1008 |
1009 class V8IsolateInterruptor : public ThreadState::Interruptor { | 1009 class V8IsolateInterruptor : public ThreadState::Interruptor { |
(...skipping 13 matching lines...) Expand all Loading... |
1023 { | 1023 { |
1024 m_isolate->RequestInterrupt(&onInterruptCallback, this); | 1024 m_isolate->RequestInterrupt(&onInterruptCallback, this); |
1025 } | 1025 } |
1026 | 1026 |
1027 private: | 1027 private: |
1028 v8::Isolate* m_isolate; | 1028 v8::Isolate* m_isolate; |
1029 }; | 1029 }; |
1030 | 1030 |
1031 class DevToolsFunctionInfo final { | 1031 class DevToolsFunctionInfo final { |
1032 public: | 1032 public: |
1033 explicit DevToolsFunctionInfo(v8::Handle<v8::Function>& function) | 1033 explicit DevToolsFunctionInfo(v8::Local<v8::Function>& function) |
1034 : m_scriptId(0) | 1034 : m_scriptId(0) |
1035 , m_lineNumber(1) | 1035 , m_lineNumber(1) |
1036 , m_function(function) | 1036 , m_function(function) |
1037 { | 1037 { |
1038 ASSERT(!m_function.IsEmpty()); | 1038 ASSERT(!m_function.IsEmpty()); |
1039 } | 1039 } |
1040 | 1040 |
1041 DevToolsFunctionInfo(int scriptId, const String& resourceName, int lineNumbe
r) | 1041 DevToolsFunctionInfo(int scriptId, const String& resourceName, int lineNumbe
r) |
1042 : m_scriptId(scriptId) | 1042 : m_scriptId(scriptId) |
1043 , m_lineNumber(lineNumber) | 1043 , m_lineNumber(lineNumber) |
1044 , m_resourceName(resourceName) | 1044 , m_resourceName(resourceName) |
1045 { | 1045 { |
1046 } | 1046 } |
1047 | 1047 |
1048 int scriptId() const; | 1048 int scriptId() const; |
1049 int lineNumber() const; | 1049 int lineNumber() const; |
1050 String resourceName() const; | 1050 String resourceName() const; |
1051 | 1051 |
1052 private: | 1052 private: |
1053 void ensureInitialized() const; | 1053 void ensureInitialized() const; |
1054 | 1054 |
1055 mutable int m_scriptId; | 1055 mutable int m_scriptId; |
1056 mutable int m_lineNumber; | 1056 mutable int m_lineNumber; |
1057 mutable String m_resourceName; | 1057 mutable String m_resourceName; |
1058 mutable v8::Handle<v8::Function> m_function; | 1058 mutable v8::Local<v8::Function> m_function; |
1059 }; | 1059 }; |
1060 | 1060 |
1061 PassRefPtr<TraceEvent::ConvertableToTraceFormat> devToolsTraceEventData(v8::Isol
ate*, ExecutionContext*, v8::Handle<v8::Function>); | 1061 PassRefPtr<TraceEvent::ConvertableToTraceFormat> devToolsTraceEventData(v8::Isol
ate*, ExecutionContext*, v8::Local<v8::Function>); |
1062 | 1062 |
1063 // Callback functions used by generated code. | 1063 // Callback functions used by generated code. |
1064 CORE_EXPORT void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName,
const v8::PropertyCallbackInfo<v8::Value>&); | 1064 CORE_EXPORT void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName,
const v8::PropertyCallbackInfo<v8::Value>&); |
1065 | 1065 |
1066 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso
late*); | 1066 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso
late*); |
1067 | 1067 |
1068 } // namespace blink | 1068 } // namespace blink |
1069 | 1069 |
1070 #endif // V8Binding_h | 1070 #endif // V8Binding_h |
OLD | NEW |