| 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 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 result.reserveInitialCapacity(length); | 687 result.reserveInitialCapacity(length); |
| 688 typedef NativeValueTraits<T> TraitsType; | 688 typedef NativeValueTraits<T> TraitsType; |
| 689 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 689 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 690 v8::TryCatch block; | 690 v8::TryCatch block; |
| 691 for (uint32_t i = 0; i < length; ++i) { | 691 for (uint32_t i = 0; i < length; ++i) { |
| 692 v8::Handle<v8::Value> element = object->Get(i); | 692 v8::Handle<v8::Value> element = object->Get(i); |
| 693 if (UNLIKELY(block.HasCaught())) { | 693 if (UNLIKELY(block.HasCaught())) { |
| 694 exceptionState.rethrowV8Exception(block.Exception()); | 694 exceptionState.rethrowV8Exception(block.Exception()); |
| 695 return Vector<T>(); | 695 return Vector<T>(); |
| 696 } | 696 } |
| 697 result.uncheckedAppend(TraitsType::nativeValue(element, isolate, excepti
onState)); | 697 result.uncheckedAppend(TraitsType::nativeValue(isolate, element, excepti
onState)); |
| 698 if (exceptionState.hadException()) | 698 if (exceptionState.hadException()) |
| 699 return Vector<T>(); | 699 return Vector<T>(); |
| 700 } | 700 } |
| 701 return result; | 701 return result; |
| 702 } | 702 } |
| 703 | 703 |
| 704 template <typename T> | 704 template <typename T> |
| 705 Vector<T> toImplArray(const Vector<ScriptValue>& value, v8::Isolate* isolate, Ex
ceptionState& exceptionState) | 705 Vector<T> toImplArray(const Vector<ScriptValue>& value, v8::Isolate* isolate, Ex
ceptionState& exceptionState) |
| 706 { | 706 { |
| 707 Vector<T> result; | 707 Vector<T> result; |
| 708 result.reserveInitialCapacity(value.size()); | 708 result.reserveInitialCapacity(value.size()); |
| 709 for (unsigned i = 0; i < value.size(); ++i) { | 709 for (unsigned i = 0; i < value.size(); ++i) { |
| 710 result.uncheckedAppend(NativeValueTraits<T>::nativeValue(value[i].v8Valu
e(), isolate, exceptionState)); | 710 result.uncheckedAppend(NativeValueTraits<T>::nativeValue(isolate, value[
i].v8Value(), exceptionState)); |
| 711 if (exceptionState.hadException()) | 711 if (exceptionState.hadException()) |
| 712 return Vector<T>(); | 712 return Vector<T>(); |
| 713 } | 713 } |
| 714 return result; | 714 return result; |
| 715 } | 715 } |
| 716 | 716 |
| 717 template <class T> | 717 template <class T> |
| 718 Vector<T> toImplArguments(const v8::FunctionCallbackInfo<v8::Value>& info, int s
tartIndex, ExceptionState& exceptionState) | 718 Vector<T> toImplArguments(const v8::FunctionCallbackInfo<v8::Value>& info, int s
tartIndex, ExceptionState& exceptionState) |
| 719 { | 719 { |
| 720 Vector<T> result; | 720 Vector<T> result; |
| 721 typedef NativeValueTraits<T> TraitsType; | 721 typedef NativeValueTraits<T> TraitsType; |
| 722 int length = info.Length(); | 722 int length = info.Length(); |
| 723 if (startIndex < length) { | 723 if (startIndex < length) { |
| 724 result.reserveInitialCapacity(length - startIndex); | 724 result.reserveInitialCapacity(length - startIndex); |
| 725 for (int i = startIndex; i < length; ++i) { | 725 for (int i = startIndex; i < length; ++i) { |
| 726 result.uncheckedAppend(TraitsType::nativeValue(info[i], info.GetIsol
ate(), exceptionState)); | 726 result.uncheckedAppend(TraitsType::nativeValue(info.GetIsolate(), in
fo[i], exceptionState)); |
| 727 if (exceptionState.hadException()) | 727 if (exceptionState.hadException()) |
| 728 return Vector<T>(); | 728 return Vector<T>(); |
| 729 } | 729 } |
| 730 } | 730 } |
| 731 return result; | 731 return result; |
| 732 } | 732 } |
| 733 | 733 |
| 734 // Validates that the passed object is a sequence type per WebIDL spec | 734 // Validates that the passed object is a sequence type per WebIDL spec |
| 735 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence | 735 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence |
| 736 inline bool toV8Sequence(v8::Handle<v8::Value> value, uint32_t& length, v8::Isol
ate* isolate, ExceptionState& exceptionState) | 736 inline bool toV8Sequence(v8::Handle<v8::Value> value, uint32_t& length, v8::Isol
ate* isolate, ExceptionState& exceptionState) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 exceptionState.rethrowV8Exception(block.Exception()); | 769 exceptionState.rethrowV8Exception(block.Exception()); |
| 770 return false; | 770 return false; |
| 771 } | 771 } |
| 772 | 772 |
| 773 length = sequenceLength; | 773 length = sequenceLength; |
| 774 return true; | 774 return true; |
| 775 } | 775 } |
| 776 | 776 |
| 777 template<> | 777 template<> |
| 778 struct NativeValueTraits<String> { | 778 struct NativeValueTraits<String> { |
| 779 static inline String nativeValue(v8::Local<v8::Value> value, v8::Isolate* is
olate, ExceptionState& exceptionState) | 779 static inline String nativeValue(v8::Isolate* isolate, v8::Local<v8::Value>
value, ExceptionState& exceptionState) |
| 780 { | 780 { |
| 781 V8StringResource<> stringValue(value); | 781 V8StringResource<> stringValue(value); |
| 782 if (!stringValue.prepare(exceptionState)) | 782 if (!stringValue.prepare(exceptionState)) |
| 783 return String(); | 783 return String(); |
| 784 return stringValue; | 784 return stringValue; |
| 785 } | 785 } |
| 786 }; | 786 }; |
| 787 | 787 |
| 788 template<> | 788 template<> |
| 789 struct NativeValueTraits<int> { | 789 struct NativeValueTraits<int> { |
| 790 static inline int nativeValue(v8::Local<v8::Value> value, v8::Isolate* isola
te, ExceptionState& exceptionState) | 790 static inline int nativeValue(v8::Isolate* isolate, v8::Local<v8::Value> val
ue, ExceptionState& exceptionState) |
| 791 { | 791 { |
| 792 return toInt32(isolate, value, NormalConversion, exceptionState); | 792 return toInt32(isolate, value, NormalConversion, exceptionState); |
| 793 } | 793 } |
| 794 }; | 794 }; |
| 795 | 795 |
| 796 template<> | 796 template<> |
| 797 struct NativeValueTraits<unsigned> { | 797 struct NativeValueTraits<unsigned> { |
| 798 static inline unsigned nativeValue(v8::Local<v8::Value> value, v8::Isolate*
isolate, ExceptionState& exceptionState) | 798 static inline unsigned nativeValue(v8::Isolate* isolate, v8::Local<v8::Value
> value, ExceptionState& exceptionState) |
| 799 { | 799 { |
| 800 return toUInt32(isolate, value, NormalConversion, exceptionState); | 800 return toUInt32(isolate, value, NormalConversion, exceptionState); |
| 801 } | 801 } |
| 802 }; | 802 }; |
| 803 | 803 |
| 804 template<> | 804 template<> |
| 805 struct NativeValueTraits<float> { | 805 struct NativeValueTraits<float> { |
| 806 static inline float nativeValue(v8::Local<v8::Value> value, v8::Isolate* iso
late, ExceptionState& exceptionState) | 806 static inline float nativeValue(v8::Isolate* isolate, v8::Local<v8::Value> v
alue, ExceptionState& exceptionState) |
| 807 { | 807 { |
| 808 return toFloat(isolate, value, exceptionState); | 808 return toFloat(isolate, value, exceptionState); |
| 809 } | 809 } |
| 810 }; | 810 }; |
| 811 | 811 |
| 812 template<> | 812 template<> |
| 813 struct NativeValueTraits<double> { | 813 struct NativeValueTraits<double> { |
| 814 static inline double nativeValue(v8::Local<v8::Value> value, v8::Isolate* is
olate, ExceptionState& exceptionState) | 814 static inline double nativeValue(v8::Isolate* isolate, v8::Local<v8::Value>
value, ExceptionState& exceptionState) |
| 815 { | 815 { |
| 816 return toDouble(isolate, value, exceptionState); | 816 return toDouble(isolate, value, exceptionState); |
| 817 } | 817 } |
| 818 }; | 818 }; |
| 819 | 819 |
| 820 template<> | 820 template<> |
| 821 struct NativeValueTraits<v8::Local<v8::Value>> { | 821 struct NativeValueTraits<v8::Local<v8::Value>> { |
| 822 static inline v8::Local<v8::Value> nativeValue(v8::Local<v8::Value> value, v
8::Isolate* isolate, ExceptionState&) | 822 static inline v8::Local<v8::Value> nativeValue(v8::Isolate* isolate, v8::Loc
al<v8::Value> value, ExceptionState& exceptionState) |
| 823 { | 823 { |
| 824 return value; | 824 return value; |
| 825 } | 825 } |
| 826 }; | 826 }; |
| 827 | 827 |
| 828 template<> | 828 template<> |
| 829 struct NativeValueTraits<ScriptValue> { | 829 struct NativeValueTraits<ScriptValue> { |
| 830 static inline ScriptValue nativeValue(v8::Local<v8::Value> value, v8::Isolat
e* isolate, ExceptionState&) | 830 static inline ScriptValue nativeValue(v8::Isolate* isolate, v8::Local<v8::Va
lue> value, ExceptionState& exceptionState) |
| 831 { | 831 { |
| 832 return ScriptValue(ScriptState::current(isolate), value); | 832 return ScriptValue(ScriptState::current(isolate), value); |
| 833 } | 833 } |
| 834 }; | 834 }; |
| 835 | 835 |
| 836 template <typename T> | 836 template <typename T> |
| 837 struct NativeValueTraits<Vector<T>> { | 837 struct NativeValueTraits<Vector<T>> { |
| 838 static inline Vector<T> nativeValue(v8::Local<v8::Value> value, v8::Isolate*
isolate, ExceptionState& exceptionState) | 838 static inline Vector<T> nativeValue(v8::Isolate* isolate, v8::Local<v8::Valu
e> value, ExceptionState& exceptionState) |
| 839 { | 839 { |
| 840 return toImplArray<T>(value, 0, isolate, exceptionState); | 840 return toImplArray<T>(value, 0, isolate, exceptionState); |
| 841 } | 841 } |
| 842 }; | 842 }; |
| 843 | 843 |
| 844 CORE_EXPORT v8::Isolate* toIsolate(ExecutionContext*); | 844 CORE_EXPORT v8::Isolate* toIsolate(ExecutionContext*); |
| 845 v8::Isolate* toIsolate(LocalFrame*); | 845 v8::Isolate* toIsolate(LocalFrame*); |
| 846 | 846 |
| 847 DOMWindow* toDOMWindow(v8::Isolate*, v8::Handle<v8::Value>); | 847 DOMWindow* toDOMWindow(v8::Isolate*, v8::Handle<v8::Value>); |
| 848 DOMWindow* toDOMWindow(v8::Handle<v8::Context>); | 848 DOMWindow* toDOMWindow(v8::Handle<v8::Context>); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 PassRefPtr<TraceEvent::ConvertableToTraceFormat> devToolsTraceEventData(v8::Isol
ate*, ExecutionContext*, v8::Handle<v8::Function>); | 967 PassRefPtr<TraceEvent::ConvertableToTraceFormat> devToolsTraceEventData(v8::Isol
ate*, ExecutionContext*, v8::Handle<v8::Function>); |
| 968 | 968 |
| 969 // Callback functions used by generated code. | 969 // Callback functions used by generated code. |
| 970 void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName, const v8::Pr
opertyCallbackInfo<v8::Value>&); | 970 void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName, const v8::Pr
opertyCallbackInfo<v8::Value>&); |
| 971 | 971 |
| 972 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso
late*); | 972 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso
late*); |
| 973 | 973 |
| 974 } // namespace blink | 974 } // namespace blink |
| 975 | 975 |
| 976 #endif // V8Binding_h | 976 #endif // V8Binding_h |
| OLD | NEW |