Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(748)

Side by Side Diff: Source/bindings/core/v8/V8Binding.h

Issue 555133003: Use ExceptionState to throw exceptions when converting arrays (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
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/core/v8/DOMWrapperWorld.h" 35 #include "bindings/core/v8/DOMWrapperWorld.h"
36 #include "bindings/core/v8/ExceptionMessages.h" 36 #include "bindings/core/v8/ExceptionMessages.h"
37 #include "bindings/core/v8/ExceptionState.h"
37 #include "bindings/core/v8/ScriptValue.h" 38 #include "bindings/core/v8/ScriptValue.h"
38 #include "bindings/core/v8/ScriptWrappable.h" 39 #include "bindings/core/v8/ScriptWrappable.h"
39 #include "bindings/core/v8/V8BindingMacros.h" 40 #include "bindings/core/v8/V8BindingMacros.h"
40 #include "bindings/core/v8/V8PerIsolateData.h" 41 #include "bindings/core/v8/V8PerIsolateData.h"
41 #include "bindings/core/v8/V8StringResource.h" 42 #include "bindings/core/v8/V8StringResource.h"
42 #include "bindings/core/v8/V8ThrowException.h" 43 #include "bindings/core/v8/V8ThrowException.h"
43 #include "bindings/core/v8/V8ValueCache.h" 44 #include "bindings/core/v8/V8ValueCache.h"
44 #include "platform/heap/Heap.h" 45 #include "platform/heap/Heap.h"
45 #include "wtf/GetPtr.h" 46 #include "wtf/GetPtr.h"
46 #include "wtf/MathExtras.h" 47 #include "wtf/MathExtras.h"
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 } 566 }
566 567
567 // FIXME: Remove the special casing for NodeFilter and XPathNSResolver. 568 // FIXME: Remove the special casing for NodeFilter and XPathNSResolver.
568 PassRefPtrWillBeRawPtr<NodeFilter> toNodeFilter(v8::Handle<v8::Value>, v8::Handl e<v8::Object>, ScriptState*); 569 PassRefPtrWillBeRawPtr<NodeFilter> toNodeFilter(v8::Handle<v8::Value>, v8::Handl e<v8::Object>, ScriptState*);
569 PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value>, v8::Isolate*); 570 PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value>, v8::Isolate*);
570 571
571 template<class T> struct NativeValueTraits; 572 template<class T> struct NativeValueTraits;
572 573
573 template<> 574 template<>
574 struct NativeValueTraits<String> { 575 struct NativeValueTraits<String> {
575 static inline String nativeValue(const v8::Handle<v8::Value>& value, v8::Iso late* isolate) 576 static inline String nativeValue(const v8::Handle<v8::Value>& value, v8::Iso late* isolate, ExceptionState& exceptionState)
576 { 577 {
577 TOSTRING_DEFAULT(V8StringResource<>, stringValue, value, String()); 578 V8StringResource<> stringValue(value);
579 if (!stringValue.prepare(exceptionState))
580 return String();
578 return stringValue; 581 return stringValue;
579 } 582 }
580 }; 583 };
581 584
582 template<> 585 template<>
583 struct NativeValueTraits<unsigned> { 586 struct NativeValueTraits<unsigned> {
584 static inline unsigned nativeValue(const v8::Handle<v8::Value>& value, v8::I solate* isolate) 587 static inline unsigned nativeValue(const v8::Handle<v8::Value>& value, v8::I solate* isolate, ExceptionState& exceptionState)
585 { 588 {
586 return toUInt32(value); 589 return toUInt32(value, exceptionState);
587 } 590 }
588 }; 591 };
589 592
590 template<> 593 template<>
591 struct NativeValueTraits<float> { 594 struct NativeValueTraits<float> {
592 static inline float nativeValue(const v8::Handle<v8::Value>& value, v8::Isol ate* isolate) 595 static inline float nativeValue(const v8::Handle<v8::Value>& value, v8::Isol ate* isolate, ExceptionState& exceptionState)
593 { 596 {
594 return static_cast<float>(value->NumberValue()); 597 return toFloat(value, exceptionState);
595 } 598 }
596 }; 599 };
597 600
598 template<> 601 template<>
599 struct NativeValueTraits<double> { 602 struct NativeValueTraits<double> {
600 static inline double nativeValue(const v8::Handle<v8::Value>& value, v8::Iso late* isolate) 603 static inline double nativeValue(const v8::Handle<v8::Value>& value, v8::Iso late* isolate, ExceptionState& exceptionState)
601 { 604 {
602 return static_cast<double>(value->NumberValue()); 605 return toDouble(value, exceptionState);
603 } 606 }
604 }; 607 };
605 608
606 template<> 609 template<>
607 struct NativeValueTraits<v8::Handle<v8::Value> > { 610 struct NativeValueTraits<v8::Handle<v8::Value> > {
608 static inline v8::Handle<v8::Value> nativeValue(const v8::Handle<v8::Value>& value, v8::Isolate* isolate) 611 static inline v8::Handle<v8::Value> nativeValue(const v8::Handle<v8::Value>& value, v8::Isolate* isolate, ExceptionState&)
609 { 612 {
610 return value; 613 return value;
611 } 614 }
612 }; 615 };
613 616
614 template<> 617 template<>
615 struct NativeValueTraits<ScriptValue> { 618 struct NativeValueTraits<ScriptValue> {
616 static inline ScriptValue nativeValue(const v8::Handle<v8::Value>& value, v8 ::Isolate* isolate) 619 static inline ScriptValue nativeValue(const v8::Handle<v8::Value>& value, v8 ::Isolate* isolate, ExceptionState&)
617 { 620 {
618 return ScriptValue(ScriptState::current(isolate), value); 621 return ScriptValue(ScriptState::current(isolate), value);
619 } 622 }
620 }; 623 };
621 624
622 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8:: Isolate*); 625 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8:: Isolate*);
623 626
624 // Converts a JavaScript value to an array as per the Web IDL specification: 627 // Converts a JavaScript value to an array as per the Web IDL specification:
625 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array 628 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array
626 template <class T, class V8T> 629 template <class T, class V8T>
627 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, ui nt32_t length, v8::Isolate* isolate, bool* success = 0) 630 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, ui nt32_t length, v8::Isolate* isolate, ExceptionState& exceptionState)
628 { 631 {
629 Vector<RefPtr<T> > result; 632 Vector<RefPtr<T> > result;
630 result.reserveInitialCapacity(length); 633 result.reserveInitialCapacity(length);
631 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 634 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
635 v8::TryCatch block;
632 for (uint32_t i = 0; i < length; ++i) { 636 for (uint32_t i = 0; i < length; ++i) {
633 v8::Handle<v8::Value> element = object->Get(i); 637 v8::Handle<v8::Value> element = object->Get(i);
638 if (block.HasCaught()) {
639 exceptionState.rethrowV8Exception(block.Exception());
640 return Vector<RefPtr<T> >();
641 }
634 if (V8T::hasInstance(element, isolate)) { 642 if (V8T::hasInstance(element, isolate)) {
635 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element); 643 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element);
636 result.uncheckedAppend(V8T::toImpl(elementObject)); 644 result.uncheckedAppend(V8T::toImpl(elementObject));
637 } else { 645 } else {
638 if (success) 646 exceptionState.throwTypeError("Invalid Array element type");
639 *success = false;
640 V8ThrowException::throwTypeError("Invalid Array element type", isola te);
641 return Vector<RefPtr<T> >(); 647 return Vector<RefPtr<T> >();
642 } 648 }
643 } 649 }
644 return result; 650 return result;
645 } 651 }
646 652
647 template <class T, class V8T> 653 template <class T, class V8T>
648 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, int argument Index, v8::Isolate* isolate, bool* success = 0) 654 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, int argument Index, v8::Isolate* isolate, ExceptionState& exceptionState)
649 { 655 {
650 if (success)
651 *success = true;
652
653 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); 656 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
654 uint32_t length = 0; 657 uint32_t length = 0;
655 if (value->IsArray()) { 658 if (value->IsArray()) {
656 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); 659 length = v8::Local<v8::Array>::Cast(v8Value)->Length();
657 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { 660 } else if (toV8Sequence(value, length, isolate).IsEmpty()) {
658 V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgume ntOrValue(argumentIndex), isolate); 661 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgumentO rValue(argumentIndex));
659 return Vector<RefPtr<T> >(); 662 return Vector<RefPtr<T> >();
660 } 663 }
661 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, succes s); 664 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, except ionState);
662 } 665 }
663 666
664 template <class T, class V8T> 667 template <class T, class V8T>
665 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, const String & propertyName, v8::Isolate* isolate, bool* success = 0) 668 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, const String & propertyName, v8::Isolate* isolate, ExceptionState& exceptionState)
666 { 669 {
667 if (success)
668 *success = true;
669
670 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); 670 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
671 uint32_t length = 0; 671 uint32_t length = 0;
672 if (value->IsArray()) { 672 if (value->IsArray()) {
673 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); 673 length = v8::Local<v8::Array>::Cast(v8Value)->Length();
674 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { 674 } else if (toV8Sequence(value, length, isolate).IsEmpty()) {
675 V8ThrowException::throwTypeError(ExceptionMessages::notASequenceTypeProp erty(propertyName), isolate); 675 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePropert y(propertyName));
676 return Vector<RefPtr<T> >(); 676 return Vector<RefPtr<T> >();
677 } 677 }
678 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, succes s); 678 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, except ionState);
679 } 679 }
680 680
681 template <class T, class V8T> 681 template <class T, class V8T>
682 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han dle<v8::Value> value, int argumentIndex, v8::Isolate* isolate, bool* success = 0 ) 682 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han dle<v8::Value> value, int argumentIndex, v8::Isolate* isolate, ExceptionState& e xceptionState)
683 { 683 {
684 if (success)
685 *success = true;
686
687 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); 684 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
688 uint32_t length = 0; 685 uint32_t length = 0;
689 if (value->IsArray()) { 686 if (value->IsArray()) {
690 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); 687 length = v8::Local<v8::Array>::Cast(v8Value)->Length();
691 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { 688 } else if (toV8Sequence(value, length, isolate).IsEmpty()) {
692 V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgume ntOrValue(argumentIndex), isolate); 689 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgumentO rValue(argumentIndex));
693 return WillBeHeapVector<RefPtrWillBeMember<T> >(); 690 return WillBeHeapVector<RefPtrWillBeMember<T> >();
694 } 691 }
695 692
696 WillBeHeapVector<RefPtrWillBeMember<T> > result; 693 WillBeHeapVector<RefPtrWillBeMember<T> > result;
697 result.reserveInitialCapacity(length); 694 result.reserveInitialCapacity(length);
698 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 695 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
696 v8::TryCatch block;
699 for (uint32_t i = 0; i < length; ++i) { 697 for (uint32_t i = 0; i < length; ++i) {
700 v8::Handle<v8::Value> element = object->Get(i); 698 v8::Handle<v8::Value> element = object->Get(i);
699 if (block.HasCaught()) {
700 exceptionState.rethrowV8Exception(block.Exception());
701 return WillBeHeapVector<RefPtrWillBeMember<T> >();
702 }
701 if (V8T::hasInstance(element, isolate)) { 703 if (V8T::hasInstance(element, isolate)) {
702 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element); 704 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element);
703 result.uncheckedAppend(V8T::toImpl(elementObject)); 705 result.uncheckedAppend(V8T::toImpl(elementObject));
704 } else { 706 } else {
705 if (success) 707 exceptionState.throwTypeError("Invalid Array element type");
706 *success = false;
707 V8ThrowException::throwTypeError("Invalid Array element type", isola te);
708 return WillBeHeapVector<RefPtrWillBeMember<T> >(); 708 return WillBeHeapVector<RefPtrWillBeMember<T> >();
709 } 709 }
710 } 710 }
711 return result; 711 return result;
712 } 712 }
713 713
714 template <class T, class V8T> 714 template <class T, class V8T>
715 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han dle<v8::Value> value, const String& propertyName, v8::Isolate* isolate, bool* su ccess = 0) 715 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han dle<v8::Value> value, const String& propertyName, v8::Isolate* isolate, Exceptio nState& exceptionState)
716 { 716 {
717 if (success)
718 *success = true;
719
720 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); 717 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
721 uint32_t length = 0; 718 uint32_t length = 0;
722 if (value->IsArray()) { 719 if (value->IsArray()) {
723 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); 720 length = v8::Local<v8::Array>::Cast(v8Value)->Length();
724 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { 721 } else if (toV8Sequence(value, length, isolate).IsEmpty()) {
725 V8ThrowException::throwTypeError(ExceptionMessages::notASequenceTypeProp erty(propertyName), isolate); 722 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePropert y(propertyName));
726 return WillBeHeapVector<RefPtrWillBeMember<T> >(); 723 return WillBeHeapVector<RefPtrWillBeMember<T> >();
727 } 724 }
728 725
729 WillBeHeapVector<RefPtrWillBeMember<T> > result; 726 WillBeHeapVector<RefPtrWillBeMember<T> > result;
730 result.reserveInitialCapacity(length); 727 result.reserveInitialCapacity(length);
731 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 728 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
729 v8::TryCatch block;
732 for (uint32_t i = 0; i < length; ++i) { 730 for (uint32_t i = 0; i < length; ++i) {
733 v8::Handle<v8::Value> element = object->Get(i); 731 v8::Handle<v8::Value> element = object->Get(i);
732 if (block.HasCaught()) {
733 exceptionState.rethrowV8Exception(block.Exception());
734 return Vector<RefPtr<T> >();
735 }
734 if (V8T::hasInstance(element, isolate)) { 736 if (V8T::hasInstance(element, isolate)) {
735 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element); 737 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element);
736 result.uncheckedAppend(V8T::toImpl(elementObject)); 738 result.uncheckedAppend(V8T::toImpl(elementObject));
737 } else { 739 } else {
738 if (success) 740 exceptionState.throwTypeError("Invalid Array element type");
739 *success = false;
740 V8ThrowException::throwTypeError("Invalid Array element type", isola te);
741 return WillBeHeapVector<RefPtrWillBeMember<T> >(); 741 return WillBeHeapVector<RefPtrWillBeMember<T> >();
742 } 742 }
743 } 743 }
744 return result; 744 return result;
745 } 745 }
746 746
747 template <class T, class V8T> 747 template <class T, class V8T>
748 HeapVector<Member<T> > toMemberNativeArray(v8::Handle<v8::Value> value, int argu mentIndex, v8::Isolate* isolate, bool* success = 0) 748 HeapVector<Member<T> > toMemberNativeArray(v8::Handle<v8::Value> value, int argu mentIndex, v8::Isolate* isolate, ExceptionState& exceptionState)
749 { 749 {
750 if (success)
751 *success = true;
752
753 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); 750 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
754 uint32_t length = 0; 751 uint32_t length = 0;
755 if (value->IsArray()) { 752 if (value->IsArray()) {
756 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); 753 length = v8::Local<v8::Array>::Cast(v8Value)->Length();
757 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { 754 } else if (toV8Sequence(value, length, isolate).IsEmpty()) {
758 V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgume ntOrValue(argumentIndex), isolate); 755 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgumentO rValue(argumentIndex));
759 return HeapVector<Member<T> >(); 756 return HeapVector<Member<T> >();
760 } 757 }
761 758
762 HeapVector<Member<T> > result; 759 HeapVector<Member<T> > result;
763 result.reserveInitialCapacity(length); 760 result.reserveInitialCapacity(length);
764 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 761 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
762 v8::TryCatch block;
765 for (uint32_t i = 0; i < length; ++i) { 763 for (uint32_t i = 0; i < length; ++i) {
766 v8::Handle<v8::Value> element = object->Get(i); 764 v8::Handle<v8::Value> element = object->Get(i);
765 if (UNLIKELY(block.HasCaught())) {
766 exceptionState.rethrowV8Exception(block.Exception());
767 return HeapVector<Member<T> >();
768 }
767 if (V8T::hasInstance(element, isolate)) { 769 if (V8T::hasInstance(element, isolate)) {
768 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element); 770 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element);
769 result.uncheckedAppend(V8T::toImpl(elementObject)); 771 result.uncheckedAppend(V8T::toImpl(elementObject));
770 } else { 772 } else {
771 if (success) 773 exceptionState.throwTypeError("Invalid Array element type");
772 *success = false;
773 V8ThrowException::throwTypeError("Invalid Array element type", isola te);
774 return HeapVector<Member<T> >(); 774 return HeapVector<Member<T> >();
775 } 775 }
776 } 776 }
777 return result; 777 return result;
778 } 778 }
779 779
780 // Converts a JavaScript value to an array as per the Web IDL specification: 780 // Converts a JavaScript value to an array as per the Web IDL specification:
781 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array 781 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array
782 template <class T> 782 template <class T>
783 Vector<T> toImplArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isolat e* isolate) 783 Vector<T> toImplArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isolat e* isolate, ExceptionState& exceptionState)
784 { 784 {
785 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); 785 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
786 uint32_t length = 0; 786 uint32_t length = 0;
787 if (value->IsArray()) { 787 if (value->IsArray()) {
788 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); 788 length = v8::Local<v8::Array>::Cast(v8Value)->Length();
789 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { 789 } else if (toV8Sequence(value, length, isolate).IsEmpty()) {
790 V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgume ntOrValue(argumentIndex), isolate); 790 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgumentO rValue(argumentIndex));
791 return Vector<T>(); 791 return Vector<T>();
792 } 792 }
793 793
794 Vector<T> result; 794 Vector<T> result;
795 result.reserveInitialCapacity(length); 795 result.reserveInitialCapacity(length);
796 typedef NativeValueTraits<T> TraitsType; 796 typedef NativeValueTraits<T> TraitsType;
797 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 797 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
798 for (uint32_t i = 0; i < length; ++i) 798 v8::TryCatch block;
799 result.uncheckedAppend(TraitsType::nativeValue(object->Get(i), isolate)) ; 799 for (uint32_t i = 0; i < length; ++i) {
Jens Widell 2014/09/11 13:22:31 The change here (and in the other functions) to ad
800 v8::Handle<v8::Value> element = object->Get(i);
801 if (UNLIKELY(block.HasCaught())) {
802 exceptionState.rethrowV8Exception(block.Exception());
803 return Vector<T>();
804 }
805 result.uncheckedAppend(TraitsType::nativeValue(element, isolate, excepti onState));
806 if (exceptionState.hadException())
807 return Vector<T>();
808 }
800 return result; 809 return result;
801 } 810 }
802 811
803 template <class T> 812 template <class T>
804 Vector<T> toImplArguments(const v8::FunctionCallbackInfo<v8::Value>& info, int s tartIndex) 813 Vector<T> toImplArguments(const v8::FunctionCallbackInfo<v8::Value>& info, int s tartIndex, ExceptionState& exceptionState)
805 { 814 {
806 ASSERT(startIndex <= info.Length()); 815 ASSERT(startIndex <= info.Length());
807 Vector<T> result; 816 Vector<T> result;
808 typedef NativeValueTraits<T> TraitsType; 817 typedef NativeValueTraits<T> TraitsType;
809 int length = info.Length(); 818 int length = info.Length();
810 result.reserveInitialCapacity(length); 819 result.reserveInitialCapacity(length);
811 for (int i = startIndex; i < length; ++i) 820 for (int i = startIndex; i < length; ++i) {
812 result.uncheckedAppend(TraitsType::nativeValue(info[i], info.GetIsolate( ))); 821 result.uncheckedAppend(TraitsType::nativeValue(info[i], info.GetIsolate( ), exceptionState));
822 if (exceptionState.hadException())
823 return Vector<T>();
824 }
813 return result; 825 return result;
814 } 826 }
815 827
816 // Validates that the passed object is a sequence type per WebIDL spec 828 // Validates that the passed object is a sequence type per WebIDL spec
817 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence 829 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence
818 inline v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value> value, uint32_t& length, v8::Isolate* isolate) 830 inline v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value> value, uint32_t& length, v8::Isolate* isolate)
819 { 831 {
820 // Attempt converting to a sequence if the value is not already an array but is 832 // Attempt converting to a sequence if the value is not already an array but is
821 // any kind of object except for a native Date object or a native RegExp obj ect. 833 // any kind of object except for a native Date object or a native RegExp obj ect.
822 ASSERT(!value->IsArray()); 834 ASSERT(!value->IsArray());
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 v8::Local<v8::Value> v8IteratorResult(v8::Isolate*, v8::Handle<v8::Value>); 986 v8::Local<v8::Value> v8IteratorResult(v8::Isolate*, v8::Handle<v8::Value>);
975 template <typename T> 987 template <typename T>
976 v8::Local<v8::Value> v8IteratorResult(ScriptState* scriptState, const T& value) 988 v8::Local<v8::Value> v8IteratorResult(ScriptState* scriptState, const T& value)
977 { 989 {
978 return v8IteratorResult(scriptState->isolate(), V8ValueTraits<T>::toV8Value( value, scriptState->context()->Global(), scriptState->isolate())); 990 return v8IteratorResult(scriptState->isolate(), V8ValueTraits<T>::toV8Value( value, scriptState->context()->Global(), scriptState->isolate()));
979 } 991 }
980 992
981 } // namespace blink 993 } // namespace blink
982 994
983 #endif // V8Binding_h 995 #endif // V8Binding_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698