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 15 matching lines...) Expand all Loading... |
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 */ | 30 */ |
31 | 31 |
32 #ifndef V8Binding_h | 32 #ifndef V8Binding_h |
33 #define V8Binding_h | 33 #define V8Binding_h |
34 | 34 |
35 #include "bindings/v8/DOMWrapperWorld.h" | 35 #include "bindings/v8/DOMWrapperWorld.h" |
36 #include "bindings/v8/Dictionary.h" | |
37 #include "bindings/v8/ExceptionMessages.h" | 36 #include "bindings/v8/ExceptionMessages.h" |
38 #include "bindings/v8/V8BindingMacros.h" | 37 #include "bindings/v8/V8BindingMacros.h" |
39 #include "bindings/v8/V8PerIsolateData.h" | 38 #include "bindings/v8/V8PerIsolateData.h" |
40 #include "bindings/v8/V8StringResource.h" | 39 #include "bindings/v8/V8StringResource.h" |
41 #include "bindings/v8/V8ThrowException.h" | 40 #include "bindings/v8/V8ThrowException.h" |
42 #include "bindings/v8/V8ValueCache.h" | 41 #include "bindings/v8/V8ValueCache.h" |
43 #include "wtf/MathExtras.h" | 42 #include "wtf/MathExtras.h" |
44 #include "wtf/text/AtomicString.h" | 43 #include "wtf/text/AtomicString.h" |
45 #include <v8.h> | 44 #include <v8.h> |
46 | 45 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 typedef V8ValueTraits<T> TraitsType; | 304 typedef V8ValueTraits<T> TraitsType; |
306 for (typename Vector<T, inlineCapacity>::const_iterator iter = iterator.
begin(); iter != end; ++iter) | 305 for (typename Vector<T, inlineCapacity>::const_iterator iter = iterator.
begin(); iter != end; ++iter) |
307 result->Set(v8::Integer::New(index++, isolate), TraitsType::arrayV8V
alue(*iter, isolate)); | 306 result->Set(v8::Integer::New(index++, isolate), TraitsType::arrayV8V
alue(*iter, isolate)); |
308 return result; | 307 return result; |
309 } | 308 } |
310 | 309 |
311 // Conversion flags, used in toIntXX/toUIntXX. | 310 // Conversion flags, used in toIntXX/toUIntXX. |
312 enum IntegerConversionConfiguration { | 311 enum IntegerConversionConfiguration { |
313 NormalConversion, | 312 NormalConversion, |
314 EnforceRange, | 313 EnforceRange, |
315 // FIXME: Implement Clamp | 314 Clamp |
316 }; | 315 }; |
317 | 316 |
318 // Convert a value to a 8-bit signed integer. The conversion fails if the | 317 // Convert a value to a 8-bit signed integer. The conversion fails if the |
319 // value cannot be converted to a number or the range violated per WebIDL: | 318 // value cannot be converted to a number or the range violated per WebIDL: |
320 // http://www.w3.org/TR/WebIDL/#es-byte | 319 // http://www.w3.org/TR/WebIDL/#es-byte |
321 int8_t toInt8(v8::Handle<v8::Value>, IntegerConversionConfiguration, bool& o
k); | 320 int8_t toInt8(v8::Handle<v8::Value>, IntegerConversionConfiguration, bool& o
k); |
322 inline int8_t toInt8(v8::Handle<v8::Value> value, bool& ok) { return toInt8(
value, NormalConversion, ok); } | 321 inline int8_t toInt8(v8::Handle<v8::Value> value, bool& ok) { return toInt8(
value, NormalConversion, ok); } |
323 | 322 |
324 // Convert a value to a 8-bit integer assuming the conversion cannot fail. | 323 // Convert a value to a 8-bit integer assuming the conversion cannot fail. |
325 inline int8_t toInt8(v8::Handle<v8::Value> value) | 324 inline int8_t toInt8(v8::Handle<v8::Value> value) |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 }; | 462 }; |
464 | 463 |
465 template<> | 464 template<> |
466 struct NativeValueTraits<v8::Handle<v8::Value> > { | 465 struct NativeValueTraits<v8::Handle<v8::Value> > { |
467 static inline v8::Handle<v8::Value> nativeValue(const v8::Handle<v8::Val
ue>& value, v8::Isolate* isolate) | 466 static inline v8::Handle<v8::Value> nativeValue(const v8::Handle<v8::Val
ue>& value, v8::Isolate* isolate) |
468 { | 467 { |
469 return value; | 468 return value; |
470 } | 469 } |
471 }; | 470 }; |
472 | 471 |
473 template<> | |
474 struct NativeValueTraits<Dictionary> { | |
475 static inline Dictionary nativeValue(const v8::Handle<v8::Value>& value,
v8::Isolate* isolate) | |
476 { | |
477 return Dictionary(value, isolate); | |
478 } | |
479 }; | |
480 | |
481 // Converts a JavaScript value to an array as per the Web IDL specification: | 472 // Converts a JavaScript value to an array as per the Web IDL specification: |
482 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 473 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
483 template <class T, class V8T> | 474 template <class T, class V8T> |
484 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value
, uint32_t length, v8::Isolate* isolate, bool* success = 0) | 475 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value
, uint32_t length, v8::Isolate* isolate, bool* success = 0) |
485 { | 476 { |
486 Vector<RefPtr<T> > result; | 477 Vector<RefPtr<T> > result; |
487 result.reserveInitialCapacity(length); | 478 result.reserveInitialCapacity(length); |
488 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 479 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
489 for (uint32_t i = 0; i < length; ++i) { | 480 for (uint32_t i = 0; i < length; ++i) { |
490 v8::Handle<v8::Value> element = object->Get(i); | 481 v8::Handle<v8::Value> element = object->Get(i); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 | 712 |
722 v8::Isolate* mainThreadIsolate(); | 713 v8::Isolate* mainThreadIsolate(); |
723 v8::Isolate* toIsolate(ExecutionContext*); | 714 v8::Isolate* toIsolate(ExecutionContext*); |
724 v8::Isolate* toIsolate(Frame*); | 715 v8::Isolate* toIsolate(Frame*); |
725 | 716 |
726 // Can only be called by blink::initialize | 717 // Can only be called by blink::initialize |
727 void setMainThreadIsolate(v8::Isolate*); | 718 void setMainThreadIsolate(v8::Isolate*); |
728 } // namespace WebCore | 719 } // namespace WebCore |
729 | 720 |
730 #endif // V8Binding_h | 721 #endif // V8Binding_h |
OLD | NEW |