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 16 matching lines...) Expand all Loading... |
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 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 ASSERT(isolate); | 564 ASSERT(isolate); |
564 return v8::Date::New(isolate, std::isfinite(value) ? value : std::numeric_li
mits<double>::quiet_NaN()); | 565 return v8::Date::New(isolate, std::isfinite(value) ? value : std::numeric_li
mits<double>::quiet_NaN()); |
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 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::
Isolate*); | 574 bool toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::Isolate*, Excepti
onState&); |
574 | 575 |
575 // Converts a JavaScript value to an array as per the Web IDL specification: | 576 // Converts a JavaScript value to an array as per the Web IDL specification: |
576 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 577 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
577 template <class T, class V8T> | 578 template <class T, class V8T> |
578 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, ui
nt32_t length, v8::Isolate* isolate, bool* success = 0) | 579 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, ui
nt32_t length, v8::Isolate* isolate, ExceptionState& exceptionState) |
579 { | 580 { |
580 Vector<RefPtr<T> > result; | 581 Vector<RefPtr<T> > result; |
581 result.reserveInitialCapacity(length); | 582 result.reserveInitialCapacity(length); |
582 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 583 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 584 v8::TryCatch block; |
583 for (uint32_t i = 0; i < length; ++i) { | 585 for (uint32_t i = 0; i < length; ++i) { |
584 v8::Handle<v8::Value> element = object->Get(i); | 586 v8::Handle<v8::Value> element = object->Get(i); |
| 587 if (block.HasCaught()) { |
| 588 exceptionState.rethrowV8Exception(block.Exception()); |
| 589 return Vector<RefPtr<T> >(); |
| 590 } |
585 if (V8T::hasInstance(element, isolate)) { | 591 if (V8T::hasInstance(element, isolate)) { |
586 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); | 592 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); |
587 result.uncheckedAppend(V8T::toImpl(elementObject)); | 593 result.uncheckedAppend(V8T::toImpl(elementObject)); |
588 } else { | 594 } else { |
589 if (success) | 595 exceptionState.throwTypeError("Invalid Array element type"); |
590 *success = false; | |
591 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); | |
592 return Vector<RefPtr<T> >(); | 596 return Vector<RefPtr<T> >(); |
593 } | 597 } |
594 } | 598 } |
595 return result; | 599 return result; |
596 } | 600 } |
597 | 601 |
598 template <class T, class V8T> | 602 template <class T, class V8T> |
599 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, int argument
Index, v8::Isolate* isolate, bool* success = 0) | 603 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, int argument
Index, v8::Isolate* isolate, ExceptionState& exceptionState) |
600 { | 604 { |
601 if (success) | |
602 *success = true; | |
603 | |
604 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 605 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
605 uint32_t length = 0; | 606 uint32_t length = 0; |
606 if (value->IsArray()) { | 607 if (value->IsArray()) { |
607 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 608 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
608 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 609 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
609 V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgume
ntOrValue(argumentIndex), isolate); | 610 if (!exceptionState.hadException()) |
| 611 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum
entOrValue(argumentIndex)); |
610 return Vector<RefPtr<T> >(); | 612 return Vector<RefPtr<T> >(); |
611 } | 613 } |
612 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, succes
s); | 614 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, except
ionState); |
613 } | 615 } |
614 | 616 |
615 template <class T, class V8T> | 617 template <class T, class V8T> |
616 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, const String
& propertyName, v8::Isolate* isolate, bool* success = 0) | 618 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, const String
& propertyName, v8::Isolate* isolate, ExceptionState& exceptionState) |
617 { | 619 { |
618 if (success) | |
619 *success = true; | |
620 | |
621 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 620 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
622 uint32_t length = 0; | 621 uint32_t length = 0; |
623 if (value->IsArray()) { | 622 if (value->IsArray()) { |
624 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 623 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
625 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 624 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
626 V8ThrowException::throwTypeError(ExceptionMessages::notASequenceTypeProp
erty(propertyName), isolate); | 625 if (!exceptionState.hadException()) |
| 626 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePro
perty(propertyName)); |
627 return Vector<RefPtr<T> >(); | 627 return Vector<RefPtr<T> >(); |
628 } | 628 } |
629 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, succes
s); | 629 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, except
ionState); |
630 } | 630 } |
631 | 631 |
632 template <class T, class V8T> | 632 template <class T, class V8T> |
633 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han
dle<v8::Value> value, int argumentIndex, v8::Isolate* isolate, bool* success = 0
) | 633 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han
dle<v8::Value> value, int argumentIndex, v8::Isolate* isolate, ExceptionState& e
xceptionState) |
634 { | 634 { |
635 if (success) | |
636 *success = true; | |
637 | |
638 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 635 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
639 uint32_t length = 0; | 636 uint32_t length = 0; |
640 if (value->IsArray()) { | 637 if (value->IsArray()) { |
641 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 638 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
642 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 639 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
643 V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgume
ntOrValue(argumentIndex), isolate); | 640 if (!exceptionState.hadException()) |
| 641 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum
entOrValue(argumentIndex)); |
644 return WillBeHeapVector<RefPtrWillBeMember<T> >(); | 642 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
645 } | 643 } |
646 | 644 |
647 WillBeHeapVector<RefPtrWillBeMember<T> > result; | 645 WillBeHeapVector<RefPtrWillBeMember<T> > result; |
648 result.reserveInitialCapacity(length); | 646 result.reserveInitialCapacity(length); |
649 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 647 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 648 v8::TryCatch block; |
650 for (uint32_t i = 0; i < length; ++i) { | 649 for (uint32_t i = 0; i < length; ++i) { |
651 v8::Handle<v8::Value> element = object->Get(i); | 650 v8::Handle<v8::Value> element = object->Get(i); |
| 651 if (block.HasCaught()) { |
| 652 exceptionState.rethrowV8Exception(block.Exception()); |
| 653 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
| 654 } |
652 if (V8T::hasInstance(element, isolate)) { | 655 if (V8T::hasInstance(element, isolate)) { |
653 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); | 656 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); |
654 result.uncheckedAppend(V8T::toImpl(elementObject)); | 657 result.uncheckedAppend(V8T::toImpl(elementObject)); |
655 } else { | 658 } else { |
656 if (success) | 659 exceptionState.throwTypeError("Invalid Array element type"); |
657 *success = false; | |
658 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); | |
659 return WillBeHeapVector<RefPtrWillBeMember<T> >(); | 660 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
660 } | 661 } |
661 } | 662 } |
662 return result; | 663 return result; |
663 } | 664 } |
664 | 665 |
665 template <class T, class V8T> | 666 template <class T, class V8T> |
666 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han
dle<v8::Value> value, const String& propertyName, v8::Isolate* isolate, bool* su
ccess = 0) | 667 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han
dle<v8::Value> value, const String& propertyName, v8::Isolate* isolate, Exceptio
nState& exceptionState) |
667 { | 668 { |
668 if (success) | |
669 *success = true; | |
670 | |
671 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 669 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
672 uint32_t length = 0; | 670 uint32_t length = 0; |
673 if (value->IsArray()) { | 671 if (value->IsArray()) { |
674 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 672 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
675 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 673 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
676 V8ThrowException::throwTypeError(ExceptionMessages::notASequenceTypeProp
erty(propertyName), isolate); | 674 if (!exceptionState.hadException()) |
| 675 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePro
perty(propertyName)); |
677 return WillBeHeapVector<RefPtrWillBeMember<T> >(); | 676 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
678 } | 677 } |
679 | 678 |
680 WillBeHeapVector<RefPtrWillBeMember<T> > result; | 679 WillBeHeapVector<RefPtrWillBeMember<T> > result; |
681 result.reserveInitialCapacity(length); | 680 result.reserveInitialCapacity(length); |
682 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 681 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 682 v8::TryCatch block; |
683 for (uint32_t i = 0; i < length; ++i) { | 683 for (uint32_t i = 0; i < length; ++i) { |
684 v8::Handle<v8::Value> element = object->Get(i); | 684 v8::Handle<v8::Value> element = object->Get(i); |
| 685 if (block.HasCaught()) { |
| 686 exceptionState.rethrowV8Exception(block.Exception()); |
| 687 return Vector<RefPtr<T> >(); |
| 688 } |
685 if (V8T::hasInstance(element, isolate)) { | 689 if (V8T::hasInstance(element, isolate)) { |
686 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); | 690 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); |
687 result.uncheckedAppend(V8T::toImpl(elementObject)); | 691 result.uncheckedAppend(V8T::toImpl(elementObject)); |
688 } else { | 692 } else { |
689 if (success) | 693 exceptionState.throwTypeError("Invalid Array element type"); |
690 *success = false; | |
691 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); | |
692 return WillBeHeapVector<RefPtrWillBeMember<T> >(); | 694 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
693 } | 695 } |
694 } | 696 } |
695 return result; | 697 return result; |
696 } | 698 } |
697 | 699 |
698 template <class T, class V8T> | 700 template <class T, class V8T> |
699 HeapVector<Member<T> > toMemberNativeArray(v8::Handle<v8::Value> value, int argu
mentIndex, v8::Isolate* isolate, bool* success = 0) | 701 HeapVector<Member<T> > toMemberNativeArray(v8::Handle<v8::Value> value, int argu
mentIndex, v8::Isolate* isolate, ExceptionState& exceptionState) |
700 { | 702 { |
701 if (success) | |
702 *success = true; | |
703 | |
704 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 703 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
705 uint32_t length = 0; | 704 uint32_t length = 0; |
706 if (value->IsArray()) { | 705 if (value->IsArray()) { |
707 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 706 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
708 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 707 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
709 V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgume
ntOrValue(argumentIndex), isolate); | 708 if (!exceptionState.hadException()) |
| 709 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum
entOrValue(argumentIndex)); |
710 return HeapVector<Member<T> >(); | 710 return HeapVector<Member<T> >(); |
711 } | 711 } |
712 | 712 |
713 HeapVector<Member<T> > result; | 713 HeapVector<Member<T> > result; |
714 result.reserveInitialCapacity(length); | 714 result.reserveInitialCapacity(length); |
715 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 715 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 716 v8::TryCatch block; |
716 for (uint32_t i = 0; i < length; ++i) { | 717 for (uint32_t i = 0; i < length; ++i) { |
717 v8::Handle<v8::Value> element = object->Get(i); | 718 v8::Handle<v8::Value> element = object->Get(i); |
| 719 if (UNLIKELY(block.HasCaught())) { |
| 720 exceptionState.rethrowV8Exception(block.Exception()); |
| 721 return HeapVector<Member<T> >(); |
| 722 } |
718 if (V8T::hasInstance(element, isolate)) { | 723 if (V8T::hasInstance(element, isolate)) { |
719 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); | 724 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); |
720 result.uncheckedAppend(V8T::toImpl(elementObject)); | 725 result.uncheckedAppend(V8T::toImpl(elementObject)); |
721 } else { | 726 } else { |
722 if (success) | 727 exceptionState.throwTypeError("Invalid Array element type"); |
723 *success = false; | |
724 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); | |
725 return HeapVector<Member<T> >(); | 728 return HeapVector<Member<T> >(); |
726 } | 729 } |
727 } | 730 } |
728 return result; | 731 return result; |
729 } | 732 } |
730 | 733 |
731 // Converts a JavaScript value to an array as per the Web IDL specification: | 734 // Converts a JavaScript value to an array as per the Web IDL specification: |
732 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 735 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
733 template <class T> | 736 template <class T> |
734 Vector<T> toImplArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isolat
e* isolate) | 737 Vector<T> toImplArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isolat
e* isolate, ExceptionState& exceptionState) |
735 { | 738 { |
736 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 739 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
737 uint32_t length = 0; | 740 uint32_t length = 0; |
738 if (value->IsArray()) { | 741 if (value->IsArray()) { |
739 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 742 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
740 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 743 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
741 V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgume
ntOrValue(argumentIndex), isolate); | 744 if (!exceptionState.hadException()) |
| 745 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum
entOrValue(argumentIndex)); |
742 return Vector<T>(); | 746 return Vector<T>(); |
743 } | 747 } |
744 | 748 |
745 Vector<T> result; | 749 Vector<T> result; |
746 result.reserveInitialCapacity(length); | 750 result.reserveInitialCapacity(length); |
747 typedef NativeValueTraits<T> TraitsType; | 751 typedef NativeValueTraits<T> TraitsType; |
748 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 752 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
749 for (uint32_t i = 0; i < length; ++i) | 753 v8::TryCatch block; |
750 result.uncheckedAppend(TraitsType::nativeValue(object->Get(i), isolate))
; | 754 for (uint32_t i = 0; i < length; ++i) { |
| 755 v8::Handle<v8::Value> element = object->Get(i); |
| 756 if (UNLIKELY(block.HasCaught())) { |
| 757 exceptionState.rethrowV8Exception(block.Exception()); |
| 758 return Vector<T>(); |
| 759 } |
| 760 result.uncheckedAppend(TraitsType::nativeValue(element, isolate, excepti
onState)); |
| 761 if (exceptionState.hadException()) |
| 762 return Vector<T>(); |
| 763 } |
751 return result; | 764 return result; |
752 } | 765 } |
753 | 766 |
754 template <class T> | 767 template <class T> |
755 Vector<T> toImplArguments(const v8::FunctionCallbackInfo<v8::Value>& info, int s
tartIndex) | 768 Vector<T> toImplArguments(const v8::FunctionCallbackInfo<v8::Value>& info, int s
tartIndex, ExceptionState& exceptionState) |
756 { | 769 { |
757 ASSERT(startIndex <= info.Length()); | 770 ASSERT(startIndex <= info.Length()); |
758 Vector<T> result; | 771 Vector<T> result; |
759 typedef NativeValueTraits<T> TraitsType; | 772 typedef NativeValueTraits<T> TraitsType; |
760 int length = info.Length(); | 773 int length = info.Length(); |
761 result.reserveInitialCapacity(length); | 774 result.reserveInitialCapacity(length); |
762 for (int i = startIndex; i < length; ++i) | 775 for (int i = startIndex; i < length; ++i) { |
763 result.uncheckedAppend(TraitsType::nativeValue(info[i], info.GetIsolate(
))); | 776 result.uncheckedAppend(TraitsType::nativeValue(info[i], info.GetIsolate(
), exceptionState)); |
| 777 if (exceptionState.hadException()) |
| 778 return Vector<T>(); |
| 779 } |
764 return result; | 780 return result; |
765 } | 781 } |
766 | 782 |
767 // Validates that the passed object is a sequence type per WebIDL spec | 783 // Validates that the passed object is a sequence type per WebIDL spec |
768 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence | 784 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-sequence |
769 inline v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value> value, uint32_t&
length, v8::Isolate* isolate) | 785 inline bool toV8Sequence(v8::Handle<v8::Value> value, uint32_t& length, v8::Isol
ate* isolate, ExceptionState& exceptionState) |
770 { | 786 { |
771 // Attempt converting to a sequence if the value is not already an array but
is | 787 // Attempt converting to a sequence if the value is not already an array but
is |
772 // any kind of object except for a native Date object or a native RegExp obj
ect. | 788 // any kind of object except for a native Date object or a native RegExp obj
ect. |
773 ASSERT(!value->IsArray()); | 789 ASSERT(!value->IsArray()); |
774 // FIXME: Do we really need to special case Date and RegExp object? | 790 // FIXME: Do we really need to special case Date and RegExp object? |
775 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806 | 791 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806 |
776 if (!value->IsObject() || value->IsDate() || value->IsRegExp()) { | 792 if (!value->IsObject() || value->IsDate() || value->IsRegExp()) { |
777 // The caller is responsible for reporting a TypeError. | 793 // The caller is responsible for reporting a TypeError. |
778 return v8Undefined(); | 794 return false; |
779 } | 795 } |
780 | 796 |
781 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 797 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
782 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 798 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
783 v8::Local<v8::String> lengthSymbol = v8AtomicString(isolate, "length"); | 799 v8::Local<v8::String> lengthSymbol = v8AtomicString(isolate, "length"); |
784 | 800 |
785 // FIXME: The specification states that the length property should be used a
s fallback, if value | 801 // FIXME: The specification states that the length property should be used a
s fallback, if value |
786 // is not a platform object that supports indexed properties. If it supports
indexed properties, | 802 // is not a platform object that supports indexed properties. If it supports
indexed properties, |
787 // length should actually be one greater than value’s maximum indexed proper
ty index. | 803 // length should actually be one greater than value’s maximum indexed proper
ty index. |
788 TONATIVE_EXCEPTION(v8::Local<v8::Value>, lengthValue, object->Get(lengthSymb
ol)); | 804 v8::TryCatch block; |
| 805 v8::Local<v8::Value> lengthValue = object->Get(lengthSymbol); |
| 806 if (block.HasCaught()) { |
| 807 exceptionState.rethrowV8Exception(block.Exception()); |
| 808 return false; |
| 809 } |
789 | 810 |
790 if (lengthValue->IsUndefined() || lengthValue->IsNull()) { | 811 if (lengthValue->IsUndefined() || lengthValue->IsNull()) { |
791 // The caller is responsible for reporting a TypeError. | 812 // The caller is responsible for reporting a TypeError. |
792 return v8Undefined(); | 813 return false; |
793 } | 814 } |
794 | 815 |
795 TONATIVE_EXCEPTION(uint32_t, sequenceLength, lengthValue->Int32Value()); | 816 uint32_t sequenceLength = lengthValue->Int32Value(); |
| 817 if (block.HasCaught()) { |
| 818 exceptionState.rethrowV8Exception(block.Exception()); |
| 819 return false; |
| 820 } |
| 821 |
796 length = sequenceLength; | 822 length = sequenceLength; |
797 return v8Value; | 823 return true; |
798 } | 824 } |
799 | 825 |
800 template<> | 826 template<> |
801 struct NativeValueTraits<String> { | 827 struct NativeValueTraits<String> { |
802 static inline String nativeValue(const v8::Handle<v8::Value>& value, v8::Iso
late* isolate) | 828 static inline String nativeValue(const v8::Handle<v8::Value>& value, v8::Iso
late* isolate, ExceptionState& exceptionState) |
803 { | 829 { |
804 TOSTRING_DEFAULT(V8StringResource<>, stringValue, value, String()); | 830 V8StringResource<> stringValue(value); |
| 831 if (!stringValue.prepare(exceptionState)) |
| 832 return String(); |
805 return stringValue; | 833 return stringValue; |
806 } | 834 } |
807 }; | 835 }; |
808 | 836 |
809 template<> | 837 template<> |
810 struct NativeValueTraits<int> { | 838 struct NativeValueTraits<int> { |
811 static inline int nativeValue(const v8::Handle<v8::Value>& value, v8::Isolat
e* isolate) | 839 static inline int nativeValue(const v8::Handle<v8::Value>& value, v8::Isolat
e* isolate, ExceptionState& exceptionState) |
812 { | 840 { |
813 return toInt32(value); | 841 return toInt32(value, exceptionState); |
814 } | 842 } |
815 }; | 843 }; |
816 | 844 |
817 template<> | 845 template<> |
818 struct NativeValueTraits<unsigned> { | 846 struct NativeValueTraits<unsigned> { |
819 static inline unsigned nativeValue(const v8::Handle<v8::Value>& value, v8::I
solate* isolate) | 847 static inline unsigned nativeValue(const v8::Handle<v8::Value>& value, v8::I
solate* isolate, ExceptionState& exceptionState) |
820 { | 848 { |
821 return toUInt32(value); | 849 return toUInt32(value, exceptionState); |
822 } | 850 } |
823 }; | 851 }; |
824 | 852 |
825 template<> | 853 template<> |
826 struct NativeValueTraits<float> { | 854 struct NativeValueTraits<float> { |
827 static inline float nativeValue(const v8::Handle<v8::Value>& value, v8::Isol
ate* isolate) | 855 static inline float nativeValue(const v8::Handle<v8::Value>& value, v8::Isol
ate* isolate, ExceptionState& exceptionState) |
828 { | 856 { |
829 return static_cast<float>(value->NumberValue()); | 857 return toFloat(value, exceptionState); |
830 } | 858 } |
831 }; | 859 }; |
832 | 860 |
833 template<> | 861 template<> |
834 struct NativeValueTraits<double> { | 862 struct NativeValueTraits<double> { |
835 static inline double nativeValue(const v8::Handle<v8::Value>& value, v8::Iso
late* isolate) | 863 static inline double nativeValue(const v8::Handle<v8::Value>& value, v8::Iso
late* isolate, ExceptionState& exceptionState) |
836 { | 864 { |
837 return static_cast<double>(value->NumberValue()); | 865 return toDouble(value, exceptionState); |
838 } | 866 } |
839 }; | 867 }; |
840 | 868 |
841 template<> | 869 template<> |
842 struct NativeValueTraits<v8::Handle<v8::Value> > { | 870 struct NativeValueTraits<v8::Handle<v8::Value> > { |
843 static inline v8::Handle<v8::Value> nativeValue(const v8::Handle<v8::Value>&
value, v8::Isolate* isolate) | 871 static inline v8::Handle<v8::Value> nativeValue(const v8::Handle<v8::Value>&
value, v8::Isolate* isolate, ExceptionState&) |
844 { | 872 { |
845 return value; | 873 return value; |
846 } | 874 } |
847 }; | 875 }; |
848 | 876 |
849 template<> | 877 template<> |
850 struct NativeValueTraits<ScriptValue> { | 878 struct NativeValueTraits<ScriptValue> { |
851 static inline ScriptValue nativeValue(const v8::Handle<v8::Value>& value, v8
::Isolate* isolate) | 879 static inline ScriptValue nativeValue(const v8::Handle<v8::Value>& value, v8
::Isolate* isolate, ExceptionState&) |
852 { | 880 { |
853 return ScriptValue(ScriptState::current(isolate), value); | 881 return ScriptValue(ScriptState::current(isolate), value); |
854 } | 882 } |
855 }; | 883 }; |
856 | 884 |
857 template <typename T> | 885 template <typename T> |
858 struct NativeValueTraits<Vector<T> > { | 886 struct NativeValueTraits<Vector<T> > { |
859 static inline Vector<T> nativeValue(const v8::Handle<v8::Value>& value, v8::
Isolate* isolate) | 887 static inline Vector<T> nativeValue(const v8::Handle<v8::Value>& value, v8::
Isolate* isolate, ExceptionState& exceptionState) |
860 { | 888 { |
861 return toImplArray<T>(value, 0, isolate); | 889 return toImplArray<T>(value, 0, isolate, exceptionState); |
862 } | 890 } |
863 }; | 891 }; |
864 | 892 |
865 v8::Isolate* toIsolate(ExecutionContext*); | 893 v8::Isolate* toIsolate(ExecutionContext*); |
866 v8::Isolate* toIsolate(LocalFrame*); | 894 v8::Isolate* toIsolate(LocalFrame*); |
867 | 895 |
868 LocalDOMWindow* toDOMWindow(v8::Handle<v8::Value>, v8::Isolate*); | 896 LocalDOMWindow* toDOMWindow(v8::Handle<v8::Value>, v8::Isolate*); |
869 LocalDOMWindow* toDOMWindow(v8::Handle<v8::Context>); | 897 LocalDOMWindow* toDOMWindow(v8::Handle<v8::Context>); |
870 LocalDOMWindow* enteredDOMWindow(v8::Isolate*); | 898 LocalDOMWindow* enteredDOMWindow(v8::Isolate*); |
871 LocalDOMWindow* currentDOMWindow(v8::Isolate*); | 899 LocalDOMWindow* currentDOMWindow(v8::Isolate*); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 v8::Local<v8::Value> v8IteratorResult(v8::Isolate*, v8::Handle<v8::Value>); | 1018 v8::Local<v8::Value> v8IteratorResult(v8::Isolate*, v8::Handle<v8::Value>); |
991 template <typename T> | 1019 template <typename T> |
992 v8::Local<v8::Value> v8IteratorResult(ScriptState* scriptState, const T& value) | 1020 v8::Local<v8::Value> v8IteratorResult(ScriptState* scriptState, const T& value) |
993 { | 1021 { |
994 return v8IteratorResult(scriptState->isolate(), V8ValueTraits<T>::toV8Value(
value, scriptState->context()->Global(), scriptState->isolate())); | 1022 return v8IteratorResult(scriptState->isolate(), V8ValueTraits<T>::toV8Value(
value, scriptState->context()->Global(), scriptState->isolate())); |
995 } | 1023 } |
996 | 1024 |
997 } // namespace blink | 1025 } // namespace blink |
998 | 1026 |
999 #endif // V8Binding_h | 1027 #endif // V8Binding_h |
OLD | NEW |