| 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 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 return std::numeric_limits<double>::quiet_NaN(); | 595 return std::numeric_limits<double>::quiet_NaN(); |
| 596 } | 596 } |
| 597 | 597 |
| 598 inline v8::MaybeLocal<v8::Value> v8DateOrNaN(v8::Isolate* isolate, double value) | 598 inline v8::MaybeLocal<v8::Value> v8DateOrNaN(v8::Isolate* isolate, double value) |
| 599 { | 599 { |
| 600 ASSERT(isolate); | 600 ASSERT(isolate); |
| 601 return v8::Date::New(isolate->GetCurrentContext(), std::isfinite(value) ? va
lue : std::numeric_limits<double>::quiet_NaN()); | 601 return v8::Date::New(isolate->GetCurrentContext(), std::isfinite(value) ? va
lue : std::numeric_limits<double>::quiet_NaN()); |
| 602 } | 602 } |
| 603 | 603 |
| 604 // FIXME: Remove the special casing for NodeFilter and XPathNSResolver. | 604 // FIXME: Remove the special casing for NodeFilter and XPathNSResolver. |
| 605 PassRefPtrWillBeRawPtr<NodeFilter> toNodeFilter(v8::Local<v8::Value>, v8::Local<
v8::Object>, ScriptState*); | 605 RawPtr<NodeFilter> toNodeFilter(v8::Local<v8::Value>, v8::Local<v8::Object>, Scr
iptState*); |
| 606 XPathNSResolver* toXPathNSResolver(ScriptState*, v8::Local<v8::Value>); | 606 XPathNSResolver* toXPathNSResolver(ScriptState*, v8::Local<v8::Value>); |
| 607 | 607 |
| 608 bool toV8Sequence(v8::Local<v8::Value>, uint32_t& length, v8::Isolate*, Exceptio
nState&); | 608 bool toV8Sequence(v8::Local<v8::Value>, uint32_t& length, v8::Isolate*, Exceptio
nState&); |
| 609 | 609 |
| 610 // Converts a JavaScript value to an array as per the Web IDL specification: | 610 // Converts a JavaScript value to an array as per the Web IDL specification: |
| 611 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 611 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
| 612 template <typename T, typename V8T> | 612 template <typename T, typename V8T> |
| 613 Vector<RefPtr<T>> toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, uin
t32_t length, v8::Isolate* isolate, ExceptionState& exceptionState) | 613 Vector<RefPtr<T>> toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, uin
t32_t length, v8::Isolate* isolate, ExceptionState& exceptionState) |
| 614 { | 614 { |
| 615 Vector<RefPtr<T>> result; | 615 Vector<RefPtr<T>> result; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 657 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
| 658 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { | 658 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
| 659 if (!exceptionState.hadException()) | 659 if (!exceptionState.hadException()) |
| 660 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePro
perty(propertyName)); | 660 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePro
perty(propertyName)); |
| 661 return Vector<RefPtr<T>>(); | 661 return Vector<RefPtr<T>>(); |
| 662 } | 662 } |
| 663 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, except
ionState); | 663 return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, except
ionState); |
| 664 } | 664 } |
| 665 | 665 |
| 666 template <typename T, typename V8T> | 666 template <typename T, typename V8T> |
| 667 WillBeHeapVector<RefPtrWillBeMember<T>> toRefPtrWillBeMemberNativeArray(v8::Loca
l<v8::Value> value, int argumentIndex, v8::Isolate* isolate, ExceptionState& exc
eptionState) | 667 HeapVector<Member<T>> toMemberNativeArray(v8::Local<v8::Value> value, int argume
ntIndex, v8::Isolate* isolate, ExceptionState& exceptionState) |
| 668 { | 668 { |
| 669 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)); |
| 670 uint32_t length = 0; | 670 uint32_t length = 0; |
| 671 if (value->IsArray()) { | 671 if (value->IsArray()) { |
| 672 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 672 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
| 673 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { | 673 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
| 674 if (!exceptionState.hadException()) | 674 if (!exceptionState.hadException()) |
| 675 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum
entOrValue(argumentIndex)); | 675 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum
entOrValue(argumentIndex)); |
| 676 return WillBeHeapVector<RefPtrWillBeMember<T>>(); | 676 return HeapVector<Member<T>>(); |
| 677 } | 677 } |
| 678 | 678 |
| 679 WillBeHeapVector<RefPtrWillBeMember<T>> result; | 679 HeapVector<Member<T>> result; |
| 680 result.reserveInitialCapacity(length); | 680 result.reserveInitialCapacity(length); |
| 681 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(isolate); | 682 v8::TryCatch block(isolate); |
| 683 for (uint32_t i = 0; i < length; ++i) { | 683 for (uint32_t i = 0; i < length; ++i) { |
| 684 v8::Local<v8::Value> element; | 684 v8::Local<v8::Value> element; |
| 685 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { | 685 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { |
| 686 exceptionState.rethrowV8Exception(block.Exception()); | 686 exceptionState.rethrowV8Exception(block.Exception()); |
| 687 return WillBeHeapVector<RefPtrWillBeMember<T>>(); | 687 return HeapVector<Member<T>>(); |
| 688 } | 688 } |
| 689 if (V8T::hasInstance(element, isolate)) { | 689 if (V8T::hasInstance(element, isolate)) { |
| 690 v8::Local<v8::Object> elementObject = v8::Local<v8::Object>::Cast(el
ement); | 690 v8::Local<v8::Object> elementObject = v8::Local<v8::Object>::Cast(el
ement); |
| 691 result.uncheckedAppend(V8T::toImpl(elementObject)); | 691 result.uncheckedAppend(V8T::toImpl(elementObject)); |
| 692 } else { | 692 } else { |
| 693 exceptionState.throwTypeError("Invalid Array element type"); | 693 exceptionState.throwTypeError("Invalid Array element type"); |
| 694 return WillBeHeapVector<RefPtrWillBeMember<T>>(); | 694 return HeapVector<Member<T>>(); |
| 695 } | 695 } |
| 696 } | 696 } |
| 697 return result; | 697 return result; |
| 698 } | 698 } |
| 699 | 699 |
| 700 template <typename T, typename V8T> | 700 template <typename T, typename V8T> |
| 701 WillBeHeapVector<RefPtrWillBeMember<T>> toRefPtrWillBeMemberNativeArray(v8::Loca
l<v8::Value> value, const String& propertyName, v8::Isolate* isolate, ExceptionS
tate& exceptionState) | 701 HeapVector<Member<T>> toMemberNativeArray(v8::Local<v8::Value> value, const Stri
ng& propertyName, v8::Isolate* isolate, ExceptionState& exceptionState) |
| 702 { | 702 { |
| 703 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)); |
| 704 uint32_t length = 0; | 704 uint32_t length = 0; |
| 705 if (value->IsArray()) { | 705 if (value->IsArray()) { |
| 706 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 706 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
| 707 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { | 707 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
| 708 if (!exceptionState.hadException()) | 708 if (!exceptionState.hadException()) |
| 709 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePro
perty(propertyName)); | 709 exceptionState.throwTypeError(ExceptionMessages::notASequenceTypePro
perty(propertyName)); |
| 710 return WillBeHeapVector<RefPtrWillBeMember<T>>(); | |
| 711 } | |
| 712 | |
| 713 WillBeHeapVector<RefPtrWillBeMember<T>> result; | |
| 714 result.reserveInitialCapacity(length); | |
| 715 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | |
| 716 v8::TryCatch block(isolate); | |
| 717 for (uint32_t i = 0; i < length; ++i) { | |
| 718 v8::Local<v8::Value> element; | |
| 719 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { | |
| 720 exceptionState.rethrowV8Exception(block.Exception()); | |
| 721 return WillBeHeapVector<RefPtrWillBeMember<T>>(); | |
| 722 } | |
| 723 if (V8T::hasInstance(element, isolate)) { | |
| 724 v8::Local<v8::Object> elementObject = v8::Local<v8::Object>::Cast(el
ement); | |
| 725 result.uncheckedAppend(V8T::toImpl(elementObject)); | |
| 726 } else { | |
| 727 exceptionState.throwTypeError("Invalid Array element type"); | |
| 728 return WillBeHeapVector<RefPtrWillBeMember<T>>(); | |
| 729 } | |
| 730 } | |
| 731 return result; | |
| 732 } | |
| 733 | |
| 734 template <typename T, typename V8T> | |
| 735 HeapVector<Member<T>> toMemberNativeArray(v8::Local<v8::Value> value, int argume
ntIndex, v8::Isolate* isolate, ExceptionState& exceptionState) | |
| 736 { | |
| 737 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | |
| 738 uint32_t length = 0; | |
| 739 if (value->IsArray()) { | |
| 740 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | |
| 741 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { | |
| 742 if (!exceptionState.hadException()) | |
| 743 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum
entOrValue(argumentIndex)); | |
| 744 return HeapVector<Member<T>>(); | 710 return HeapVector<Member<T>>(); |
| 745 } | 711 } |
| 746 | 712 |
| 747 HeapVector<Member<T>> result; | 713 HeapVector<Member<T>> result; |
| 748 result.reserveInitialCapacity(length); | 714 result.reserveInitialCapacity(length); |
| 749 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | 715 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 750 v8::TryCatch block(isolate); | 716 v8::TryCatch block(isolate); |
| 751 for (uint32_t i = 0; i < length; ++i) { | 717 for (uint32_t i = 0; i < length; ++i) { |
| 752 v8::Local<v8::Value> element; | 718 v8::Local<v8::Value> element; |
| 753 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { | 719 if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block
)) { |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 PassRefPtr<TracedValue> devToolsTraceEventData(v8::Isolate*, ExecutionContext*,
v8::Local<v8::Function>); | 1049 PassRefPtr<TracedValue> devToolsTraceEventData(v8::Isolate*, ExecutionContext*,
v8::Local<v8::Function>); |
| 1084 | 1050 |
| 1085 // Callback functions used by generated code. | 1051 // Callback functions used by generated code. |
| 1086 CORE_EXPORT void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName,
const v8::PropertyCallbackInfo<v8::Value>&); | 1052 CORE_EXPORT void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName,
const v8::PropertyCallbackInfo<v8::Value>&); |
| 1087 | 1053 |
| 1088 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso
late*); | 1054 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso
late*); |
| 1089 | 1055 |
| 1090 } // namespace blink | 1056 } // namespace blink |
| 1091 | 1057 |
| 1092 #endif // V8Binding_h | 1058 #endif // V8Binding_h |
| OLD | NEW |