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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 template <class T, class V8T> | 619 template <class T, class V8T> |
620 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, ui
nt32_t length, v8::Isolate* isolate, bool* success = 0) | 620 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, ui
nt32_t length, v8::Isolate* isolate, bool* success = 0) |
621 { | 621 { |
622 Vector<RefPtr<T> > result; | 622 Vector<RefPtr<T> > result; |
623 result.reserveInitialCapacity(length); | 623 result.reserveInitialCapacity(length); |
624 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 624 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
625 for (uint32_t i = 0; i < length; ++i) { | 625 for (uint32_t i = 0; i < length; ++i) { |
626 v8::Handle<v8::Value> element = object->Get(i); | 626 v8::Handle<v8::Value> element = object->Get(i); |
627 if (V8T::hasInstance(element, isolate)) { | 627 if (V8T::hasInstance(element, isolate)) { |
628 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); | 628 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); |
629 result.uncheckedAppend(V8T::toNative(elementObject)); | 629 result.uncheckedAppend(V8T::toImpl(elementObject)); |
630 } else { | 630 } else { |
631 if (success) | 631 if (success) |
632 *success = false; | 632 *success = false; |
633 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); | 633 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); |
634 return Vector<RefPtr<T> >(); | 634 return Vector<RefPtr<T> >(); |
635 } | 635 } |
636 } | 636 } |
637 return result; | 637 return result; |
638 } | 638 } |
639 | 639 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 return WillBeHeapVector<RefPtrWillBeMember<T> >(); | 686 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
687 } | 687 } |
688 | 688 |
689 WillBeHeapVector<RefPtrWillBeMember<T> > result; | 689 WillBeHeapVector<RefPtrWillBeMember<T> > result; |
690 result.reserveInitialCapacity(length); | 690 result.reserveInitialCapacity(length); |
691 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 691 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
692 for (uint32_t i = 0; i < length; ++i) { | 692 for (uint32_t i = 0; i < length; ++i) { |
693 v8::Handle<v8::Value> element = object->Get(i); | 693 v8::Handle<v8::Value> element = object->Get(i); |
694 if (V8T::hasInstance(element, isolate)) { | 694 if (V8T::hasInstance(element, isolate)) { |
695 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); | 695 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); |
696 result.uncheckedAppend(V8T::toNative(elementObject)); | 696 result.uncheckedAppend(V8T::toImpl(elementObject)); |
697 } else { | 697 } else { |
698 if (success) | 698 if (success) |
699 *success = false; | 699 *success = false; |
700 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); | 700 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); |
701 return WillBeHeapVector<RefPtrWillBeMember<T> >(); | 701 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
702 } | 702 } |
703 } | 703 } |
704 return result; | 704 return result; |
705 } | 705 } |
706 | 706 |
(...skipping 12 matching lines...) Expand all Loading... |
719 return WillBeHeapVector<RefPtrWillBeMember<T> >(); | 719 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
720 } | 720 } |
721 | 721 |
722 WillBeHeapVector<RefPtrWillBeMember<T> > result; | 722 WillBeHeapVector<RefPtrWillBeMember<T> > result; |
723 result.reserveInitialCapacity(length); | 723 result.reserveInitialCapacity(length); |
724 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 724 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
725 for (uint32_t i = 0; i < length; ++i) { | 725 for (uint32_t i = 0; i < length; ++i) { |
726 v8::Handle<v8::Value> element = object->Get(i); | 726 v8::Handle<v8::Value> element = object->Get(i); |
727 if (V8T::hasInstance(element, isolate)) { | 727 if (V8T::hasInstance(element, isolate)) { |
728 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); | 728 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); |
729 result.uncheckedAppend(V8T::toNative(elementObject)); | 729 result.uncheckedAppend(V8T::toImpl(elementObject)); |
730 } else { | 730 } else { |
731 if (success) | 731 if (success) |
732 *success = false; | 732 *success = false; |
733 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); | 733 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); |
734 return WillBeHeapVector<RefPtrWillBeMember<T> >(); | 734 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
735 } | 735 } |
736 } | 736 } |
737 return result; | 737 return result; |
738 } | 738 } |
739 | 739 |
(...skipping 12 matching lines...) Expand all Loading... |
752 return HeapVector<Member<T> >(); | 752 return HeapVector<Member<T> >(); |
753 } | 753 } |
754 | 754 |
755 HeapVector<Member<T> > result; | 755 HeapVector<Member<T> > result; |
756 result.reserveInitialCapacity(length); | 756 result.reserveInitialCapacity(length); |
757 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 757 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
758 for (uint32_t i = 0; i < length; ++i) { | 758 for (uint32_t i = 0; i < length; ++i) { |
759 v8::Handle<v8::Value> element = object->Get(i); | 759 v8::Handle<v8::Value> element = object->Get(i); |
760 if (V8T::hasInstance(element, isolate)) { | 760 if (V8T::hasInstance(element, isolate)) { |
761 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); | 761 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); |
762 result.uncheckedAppend(V8T::toNative(elementObject)); | 762 result.uncheckedAppend(V8T::toImpl(elementObject)); |
763 } else { | 763 } else { |
764 if (success) | 764 if (success) |
765 *success = false; | 765 *success = false; |
766 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); | 766 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); |
767 return HeapVector<Member<T> >(); | 767 return HeapVector<Member<T> >(); |
768 } | 768 } |
769 } | 769 } |
770 return result; | 770 return result; |
771 } | 771 } |
772 | 772 |
773 // Converts a JavaScript value to an array as per the Web IDL specification: | 773 // Converts a JavaScript value to an array as per the Web IDL specification: |
774 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 774 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
775 template <class T> | 775 template <class T> |
776 Vector<T> toNativeArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isol
ate* isolate) | 776 Vector<T> toImplArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isolat
e* isolate) |
777 { | 777 { |
778 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 778 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
779 uint32_t length = 0; | 779 uint32_t length = 0; |
780 if (value->IsArray()) { | 780 if (value->IsArray()) { |
781 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 781 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
782 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 782 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |
783 V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgume
ntOrValue(argumentIndex), isolate); | 783 V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgume
ntOrValue(argumentIndex), isolate); |
784 return Vector<T>(); | 784 return Vector<T>(); |
785 } | 785 } |
786 | 786 |
787 Vector<T> result; | 787 Vector<T> result; |
788 result.reserveInitialCapacity(length); | 788 result.reserveInitialCapacity(length); |
789 typedef NativeValueTraits<T> TraitsType; | 789 typedef NativeValueTraits<T> TraitsType; |
790 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 790 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
791 for (uint32_t i = 0; i < length; ++i) | 791 for (uint32_t i = 0; i < length; ++i) |
792 result.uncheckedAppend(TraitsType::nativeValue(object->Get(i), isolate))
; | 792 result.uncheckedAppend(TraitsType::nativeValue(object->Get(i), isolate))
; |
793 return result; | 793 return result; |
794 } | 794 } |
795 | 795 |
796 template <class T> | 796 template <class T> |
797 Vector<T> toNativeArguments(const v8::FunctionCallbackInfo<v8::Value>& info, int
startIndex) | 797 Vector<T> toImplArguments(const v8::FunctionCallbackInfo<v8::Value>& info, int s
tartIndex) |
798 { | 798 { |
799 ASSERT(startIndex <= info.Length()); | 799 ASSERT(startIndex <= info.Length()); |
800 Vector<T> result; | 800 Vector<T> result; |
801 typedef NativeValueTraits<T> TraitsType; | 801 typedef NativeValueTraits<T> TraitsType; |
802 int length = info.Length(); | 802 int length = info.Length(); |
803 result.reserveInitialCapacity(length); | 803 result.reserveInitialCapacity(length); |
804 for (int i = startIndex; i < length; ++i) | 804 for (int i = startIndex; i < length; ++i) |
805 result.uncheckedAppend(TraitsType::nativeValue(info[i], info.GetIsolate(
))); | 805 result.uncheckedAppend(TraitsType::nativeValue(info[i], info.GetIsolate(
))); |
806 return result; | 806 return result; |
807 } | 807 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 | 875 |
876 // Attaches |environment| to |function| and returns it. | 876 // Attaches |environment| to |function| and returns it. |
877 inline v8::Local<v8::Function> createClosure(v8::FunctionCallback function, v8::
Handle<v8::Value> environment, v8::Isolate* isolate) | 877 inline v8::Local<v8::Function> createClosure(v8::FunctionCallback function, v8::
Handle<v8::Value> environment, v8::Isolate* isolate) |
878 { | 878 { |
879 return v8::Function::New(isolate, function, environment); | 879 return v8::Function::New(isolate, function, environment); |
880 } | 880 } |
881 | 881 |
882 // FIXME: This will be soon embedded in the generated code. | 882 // FIXME: This will be soon embedded in the generated code. |
883 template<class Collection> static void indexedPropertyEnumerator(const v8::Prope
rtyCallbackInfo<v8::Array>& info) | 883 template<class Collection> static void indexedPropertyEnumerator(const v8::Prope
rtyCallbackInfo<v8::Array>& info) |
884 { | 884 { |
885 Collection* collection = ScriptWrappableBase::fromInternalPointer<Collection
>(toInternalPointer(info.Holder())); | 885 Collection* collection = toScriptWrappableBase(info.Holder())->toImpl<Collec
tion>(); |
886 int length = collection->length(); | 886 int length = collection->length(); |
887 v8::Handle<v8::Array> properties = v8::Array::New(info.GetIsolate(), length)
; | 887 v8::Handle<v8::Array> properties = v8::Array::New(info.GetIsolate(), length)
; |
888 for (int i = 0; i < length; ++i) { | 888 for (int i = 0; i < length; ++i) { |
889 // FIXME: Do we need to check that the item function returns a non-null
value for this index? | 889 // FIXME: Do we need to check that the item function returns a non-null
value for this index? |
890 v8::Handle<v8::Integer> integer = v8::Integer::New(info.GetIsolate(), i)
; | 890 v8::Handle<v8::Integer> integer = v8::Integer::New(info.GetIsolate(), i)
; |
891 properties->Set(integer, integer); | 891 properties->Set(integer, integer); |
892 } | 892 } |
893 v8SetReturnValue(info, properties); | 893 v8SetReturnValue(info, properties); |
894 } | 894 } |
895 | 895 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 m_block.ReThrow(); | 956 m_block.ReThrow(); |
957 } | 957 } |
958 | 958 |
959 private: | 959 private: |
960 v8::TryCatch& m_block; | 960 v8::TryCatch& m_block; |
961 }; | 961 }; |
962 | 962 |
963 } // namespace blink | 963 } // namespace blink |
964 | 964 |
965 #endif // V8Binding_h | 965 #endif // V8Binding_h |
OLD | NEW |