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

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

Issue 921813002: Fix template angle bracket syntax in bindings (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « Source/bindings/core/v8/ToV8Test.cpp ('k') | Source/bindings/core/v8/V8BindingTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 PassRefPtrWillBeRawPtr<NodeFilter> toNodeFilter(v8::Handle<v8::Value>, v8::Handl e<v8::Object>, ScriptState*); 513 PassRefPtrWillBeRawPtr<NodeFilter> toNodeFilter(v8::Handle<v8::Value>, v8::Handl e<v8::Object>, ScriptState*);
514 PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Isolate*, v8::Hand le<v8::Value>); 514 PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Isolate*, v8::Hand le<v8::Value>);
515 515
516 template<class T> struct NativeValueTraits; 516 template<class T> struct NativeValueTraits;
517 517
518 bool toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::Isolate*, Excepti onState&); 518 bool toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::Isolate*, Excepti onState&);
519 519
520 // Converts a JavaScript value to an array as per the Web IDL specification: 520 // Converts a JavaScript value to an array as per the Web IDL specification:
521 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array 521 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array
522 template <class T, class V8T> 522 template <class T, class V8T>
523 Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, ui nt32_t length, v8::Isolate* isolate, ExceptionState& exceptionState) 523 Vector<RefPtr<T>> toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, uin t32_t length, v8::Isolate* isolate, ExceptionState& exceptionState)
524 { 524 {
525 Vector<RefPtr<T> > result; 525 Vector<RefPtr<T>> result;
526 result.reserveInitialCapacity(length); 526 result.reserveInitialCapacity(length);
527 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 527 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
528 v8::TryCatch block; 528 v8::TryCatch block;
529 for (uint32_t i = 0; i < length; ++i) { 529 for (uint32_t i = 0; i < length; ++i) {
530 v8::Handle<v8::Value> element = object->Get(i); 530 v8::Handle<v8::Value> element = object->Get(i);
531 if (block.HasCaught()) { 531 if (block.HasCaught()) {
532 exceptionState.rethrowV8Exception(block.Exception()); 532 exceptionState.rethrowV8Exception(block.Exception());
533 return Vector<RefPtr<T> >(); 533 return Vector<RefPtr<T>>();
534 } 534 }
535 if (V8T::hasInstance(element, isolate)) { 535 if (V8T::hasInstance(element, isolate)) {
536 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element); 536 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element);
537 result.uncheckedAppend(V8T::toImpl(elementObject)); 537 result.uncheckedAppend(V8T::toImpl(elementObject));
538 } else { 538 } else {
539 exceptionState.throwTypeError("Invalid Array element type"); 539 exceptionState.throwTypeError("Invalid Array element type");
540 return Vector<RefPtr<T> >(); 540 return Vector<RefPtr<T>>();
541 } 541 }
542 } 542 }
543 return result; 543 return result;
544 } 544 }
545 545
546 template <class T, class V8T> 546 template <class T, class V8T>
547 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, int argument Index, v8::Isolate* isolate, ExceptionState& exceptionState) 547 Vector<RefPtr<T>> toRefPtrNativeArray(v8::Handle<v8::Value> value, int argumentI ndex, v8::Isolate* isolate, ExceptionState& exceptionState)
548 { 548 {
549 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); 549 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
550 uint32_t length = 0; 550 uint32_t length = 0;
551 if (value->IsArray()) { 551 if (value->IsArray()) {
552 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); 552 length = v8::Local<v8::Array>::Cast(v8Value)->Length();
553 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { 553 } else if (!toV8Sequence(value, length, isolate, exceptionState)) {
554 if (!exceptionState.hadException()) 554 if (!exceptionState.hadException())
555 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum entOrValue(argumentIndex)); 555 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum entOrValue(argumentIndex));
556 return Vector<RefPtr<T> >(); 556 return Vector<RefPtr<T>>();
557 } 557 }
558 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, except ionState); 558 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, except ionState);
559 } 559 }
560 560
561 template <class T, class V8T> 561 template <class T, class V8T>
562 Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, const String & propertyName, v8::Isolate* isolate, ExceptionState& exceptionState) 562 Vector<RefPtr<T>> toRefPtrNativeArray(v8::Handle<v8::Value> value, const String& propertyName, v8::Isolate* isolate, ExceptionState& exceptionState)
563 { 563 {
564 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); 564 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
565 uint32_t length = 0; 565 uint32_t length = 0;
566 if (value->IsArray()) { 566 if (value->IsArray()) {
567 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); 567 length = v8::Local<v8::Array>::Cast(v8Value)->Length();
568 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { 568 } else if (!toV8Sequence(value, length, isolate, exceptionState)) {
569 if (!exceptionState.hadException()) 569 if (!exceptionState.hadException())
570 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePro perty(propertyName)); 570 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePro perty(propertyName));
571 return Vector<RefPtr<T> >(); 571 return Vector<RefPtr<T>>();
572 } 572 }
573 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, except ionState); 573 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, except ionState);
574 } 574 }
575 575
576 template <class T, class V8T> 576 template <class T, class V8T>
577 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han dle<v8::Value> value, int argumentIndex, v8::Isolate* isolate, ExceptionState& e xceptionState) 577 WillBeHeapVector<RefPtrWillBeMember<T>> toRefPtrWillBeMemberNativeArray(v8::Hand le<v8::Value> value, int argumentIndex, v8::Isolate* isolate, ExceptionState& ex ceptionState)
578 { 578 {
579 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); 579 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
580 uint32_t length = 0; 580 uint32_t length = 0;
581 if (value->IsArray()) { 581 if (value->IsArray()) {
582 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); 582 length = v8::Local<v8::Array>::Cast(v8Value)->Length();
583 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { 583 } else if (!toV8Sequence(value, length, isolate, exceptionState)) {
584 if (!exceptionState.hadException()) 584 if (!exceptionState.hadException())
585 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum entOrValue(argumentIndex)); 585 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum entOrValue(argumentIndex));
586 return WillBeHeapVector<RefPtrWillBeMember<T> >(); 586 return WillBeHeapVector<RefPtrWillBeMember<T>>();
587 } 587 }
588 588
589 WillBeHeapVector<RefPtrWillBeMember<T> > result; 589 WillBeHeapVector<RefPtrWillBeMember<T>> result;
590 result.reserveInitialCapacity(length); 590 result.reserveInitialCapacity(length);
591 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 591 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
592 v8::TryCatch block; 592 v8::TryCatch block;
593 for (uint32_t i = 0; i < length; ++i) { 593 for (uint32_t i = 0; i < length; ++i) {
594 v8::Handle<v8::Value> element = object->Get(i); 594 v8::Handle<v8::Value> element = object->Get(i);
595 if (block.HasCaught()) { 595 if (block.HasCaught()) {
596 exceptionState.rethrowV8Exception(block.Exception()); 596 exceptionState.rethrowV8Exception(block.Exception());
597 return WillBeHeapVector<RefPtrWillBeMember<T> >(); 597 return WillBeHeapVector<RefPtrWillBeMember<T>>();
598 } 598 }
599 if (V8T::hasInstance(element, isolate)) { 599 if (V8T::hasInstance(element, isolate)) {
600 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element); 600 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element);
601 result.uncheckedAppend(V8T::toImpl(elementObject)); 601 result.uncheckedAppend(V8T::toImpl(elementObject));
602 } else { 602 } else {
603 exceptionState.throwTypeError("Invalid Array element type"); 603 exceptionState.throwTypeError("Invalid Array element type");
604 return WillBeHeapVector<RefPtrWillBeMember<T> >(); 604 return WillBeHeapVector<RefPtrWillBeMember<T>>();
605 } 605 }
606 } 606 }
607 return result; 607 return result;
608 } 608 }
609 609
610 template <class T, class V8T> 610 template <class T, class V8T>
611 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han dle<v8::Value> value, const String& propertyName, v8::Isolate* isolate, Exceptio nState& exceptionState) 611 WillBeHeapVector<RefPtrWillBeMember<T>> toRefPtrWillBeMemberNativeArray(v8::Hand le<v8::Value> value, const String& propertyName, v8::Isolate* isolate, Exception State& exceptionState)
612 { 612 {
613 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); 613 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
614 uint32_t length = 0; 614 uint32_t length = 0;
615 if (value->IsArray()) { 615 if (value->IsArray()) {
616 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); 616 length = v8::Local<v8::Array>::Cast(v8Value)->Length();
617 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { 617 } else if (!toV8Sequence(value, length, isolate, exceptionState)) {
618 if (!exceptionState.hadException()) 618 if (!exceptionState.hadException())
619 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePro perty(propertyName)); 619 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePro perty(propertyName));
620 return WillBeHeapVector<RefPtrWillBeMember<T> >(); 620 return WillBeHeapVector<RefPtrWillBeMember<T>>();
621 } 621 }
622 622
623 WillBeHeapVector<RefPtrWillBeMember<T> > result; 623 WillBeHeapVector<RefPtrWillBeMember<T>> result;
624 result.reserveInitialCapacity(length); 624 result.reserveInitialCapacity(length);
625 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 625 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
626 v8::TryCatch block; 626 v8::TryCatch block;
627 for (uint32_t i = 0; i < length; ++i) { 627 for (uint32_t i = 0; i < length; ++i) {
628 v8::Handle<v8::Value> element = object->Get(i); 628 v8::Handle<v8::Value> element = object->Get(i);
629 if (block.HasCaught()) { 629 if (block.HasCaught()) {
630 exceptionState.rethrowV8Exception(block.Exception()); 630 exceptionState.rethrowV8Exception(block.Exception());
631 return WillBeHeapVector<RefPtrWillBeMember<T> >(); 631 return WillBeHeapVector<RefPtrWillBeMember<T>>();
632 } 632 }
633 if (V8T::hasInstance(element, isolate)) { 633 if (V8T::hasInstance(element, isolate)) {
634 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element); 634 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element);
635 result.uncheckedAppend(V8T::toImpl(elementObject)); 635 result.uncheckedAppend(V8T::toImpl(elementObject));
636 } else { 636 } else {
637 exceptionState.throwTypeError("Invalid Array element type"); 637 exceptionState.throwTypeError("Invalid Array element type");
638 return WillBeHeapVector<RefPtrWillBeMember<T> >(); 638 return WillBeHeapVector<RefPtrWillBeMember<T>>();
639 } 639 }
640 } 640 }
641 return result; 641 return result;
642 } 642 }
643 643
644 template <class T, class V8T> 644 template <class T, class V8T>
645 HeapVector<Member<T> > toMemberNativeArray(v8::Handle<v8::Value> value, int argu mentIndex, v8::Isolate* isolate, ExceptionState& exceptionState) 645 HeapVector<Member<T>> toMemberNativeArray(v8::Handle<v8::Value> value, int argum entIndex, v8::Isolate* isolate, ExceptionState& exceptionState)
646 { 646 {
647 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); 647 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
648 uint32_t length = 0; 648 uint32_t length = 0;
649 if (value->IsArray()) { 649 if (value->IsArray()) {
650 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); 650 length = v8::Local<v8::Array>::Cast(v8Value)->Length();
651 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { 651 } else if (!toV8Sequence(value, length, isolate, exceptionState)) {
652 if (!exceptionState.hadException()) 652 if (!exceptionState.hadException())
653 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum entOrValue(argumentIndex)); 653 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum entOrValue(argumentIndex));
654 return HeapVector<Member<T> >(); 654 return HeapVector<Member<T>>();
655 } 655 }
656 656
657 HeapVector<Member<T> > result; 657 HeapVector<Member<T>> result;
658 result.reserveInitialCapacity(length); 658 result.reserveInitialCapacity(length);
659 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 659 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
660 v8::TryCatch block; 660 v8::TryCatch block;
661 for (uint32_t i = 0; i < length; ++i) { 661 for (uint32_t i = 0; i < length; ++i) {
662 v8::Handle<v8::Value> element = object->Get(i); 662 v8::Handle<v8::Value> element = object->Get(i);
663 if (UNLIKELY(block.HasCaught())) { 663 if (UNLIKELY(block.HasCaught())) {
664 exceptionState.rethrowV8Exception(block.Exception()); 664 exceptionState.rethrowV8Exception(block.Exception());
665 return HeapVector<Member<T> >(); 665 return HeapVector<Member<T>>();
666 } 666 }
667 if (V8T::hasInstance(element, isolate)) { 667 if (V8T::hasInstance(element, isolate)) {
668 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element); 668 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast( element);
669 result.uncheckedAppend(V8T::toImpl(elementObject)); 669 result.uncheckedAppend(V8T::toImpl(elementObject));
670 } else { 670 } else {
671 exceptionState.throwTypeError("Invalid Array element type"); 671 exceptionState.throwTypeError("Invalid Array element type");
672 return HeapVector<Member<T> >(); 672 return HeapVector<Member<T>>();
673 } 673 }
674 } 674 }
675 return result; 675 return result;
676 } 676 }
677 677
678 // Converts a JavaScript value to an array as per the Web IDL specification: 678 // Converts a JavaScript value to an array as per the Web IDL specification:
679 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array 679 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array
680 template <class T> 680 template <class T>
681 Vector<T> toImplArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isolat e* isolate, ExceptionState& exceptionState) 681 Vector<T> toImplArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isolat e* isolate, ExceptionState& exceptionState)
682 { 682 {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 810
811 template<> 811 template<>
812 struct NativeValueTraits<double> { 812 struct NativeValueTraits<double> {
813 static inline double nativeValue(const v8::Local<v8::Value>& value, v8::Isol ate* isolate, ExceptionState& exceptionState) 813 static inline double nativeValue(const v8::Local<v8::Value>& value, v8::Isol ate* isolate, ExceptionState& exceptionState)
814 { 814 {
815 return toDouble(value, exceptionState); 815 return toDouble(value, exceptionState);
816 } 816 }
817 }; 817 };
818 818
819 template<> 819 template<>
820 struct NativeValueTraits<v8::Local<v8::Value> > { 820 struct NativeValueTraits<v8::Local<v8::Value>> {
821 static inline v8::Local<v8::Value> nativeValue(const v8::Local<v8::Value>& v alue, v8::Isolate* isolate, ExceptionState&) 821 static inline v8::Local<v8::Value> nativeValue(const v8::Local<v8::Value>& v alue, v8::Isolate* isolate, ExceptionState&)
822 { 822 {
823 return value; 823 return value;
824 } 824 }
825 }; 825 };
826 826
827 template<> 827 template<>
828 struct NativeValueTraits<ScriptValue> { 828 struct NativeValueTraits<ScriptValue> {
829 static inline ScriptValue nativeValue(const v8::Local<v8::Value>& value, v8: :Isolate* isolate, ExceptionState&) 829 static inline ScriptValue nativeValue(const v8::Local<v8::Value>& value, v8: :Isolate* isolate, ExceptionState&)
830 { 830 {
831 return ScriptValue(ScriptState::current(isolate), value); 831 return ScriptValue(ScriptState::current(isolate), value);
832 } 832 }
833 }; 833 };
834 834
835 template <typename T> 835 template <typename T>
836 struct NativeValueTraits<Vector<T> > { 836 struct NativeValueTraits<Vector<T>> {
837 static inline Vector<T> nativeValue(const v8::Local<v8::Value>& value, v8::I solate* isolate, ExceptionState& exceptionState) 837 static inline Vector<T> nativeValue(const v8::Local<v8::Value>& value, v8::I solate* isolate, ExceptionState& exceptionState)
838 { 838 {
839 return toImplArray<T>(value, 0, isolate, exceptionState); 839 return toImplArray<T>(value, 0, isolate, exceptionState);
840 } 840 }
841 }; 841 };
842 842
843 v8::Isolate* toIsolate(ExecutionContext*); 843 v8::Isolate* toIsolate(ExecutionContext*);
844 v8::Isolate* toIsolate(LocalFrame*); 844 v8::Isolate* toIsolate(LocalFrame*);
845 845
846 DOMWindow* toDOMWindow(v8::Isolate*, v8::Handle<v8::Value>); 846 DOMWindow* toDOMWindow(v8::Isolate*, v8::Handle<v8::Value>);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 989
990 private: 990 private:
991 v8::TryCatch& m_block; 991 v8::TryCatch& m_block;
992 }; 992 };
993 993
994 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso late*); 994 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso late*);
995 995
996 } // namespace blink 996 } // namespace blink
997 997
998 #endif // V8Binding_h 998 #endif // V8Binding_h
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ToV8Test.cpp ('k') | Source/bindings/core/v8/V8BindingTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698