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 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 } else { | 683 } else { |
684 if (success) | 684 if (success) |
685 *success = false; | 685 *success = false; |
686 throwTypeError("Invalid Array element type", isolate); | 686 throwTypeError("Invalid Array element type", isolate); |
687 return WillBeHeapVector<RefPtrWillBeMember<T> >(); | 687 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
688 } | 688 } |
689 } | 689 } |
690 return result; | 690 return result; |
691 } | 691 } |
692 | 692 |
| 693 template <class T, class V8T> |
| 694 WillBeHeapVector<RefPtrWillBeMember<T> > toRefPtrWillBeMemberNativeArray(v8::Han
dle<v8::Value> value, const String& propertyName, v8::Isolate* isolate, bool* su
ccess = 0) |
| 695 { |
| 696 if (success) |
| 697 *success = true; |
| 698 |
| 699 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
| 700 uint32_t length = 0; |
| 701 if (value->IsArray()) { |
| 702 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
| 703 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |
| 704 throwTypeError(ExceptionMessages::notASequenceTypeProperty(propertyName)
, isolate); |
| 705 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
| 706 } |
| 707 |
| 708 WillBeHeapVector<RefPtrWillBeMember<T> > result; |
| 709 result.reserveInitialCapacity(length); |
| 710 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| 711 for (uint32_t i = 0; i < length; ++i) { |
| 712 v8::Handle<v8::Value> element = object->Get(i); |
| 713 if (V8T::hasInstance(element, isolate)) { |
| 714 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); |
| 715 result.uncheckedAppend(V8T::toNative(elementObject)); |
| 716 } else { |
| 717 if (success) |
| 718 *success = false; |
| 719 throwTypeError("Invalid Array element type", isolate); |
| 720 return WillBeHeapVector<RefPtrWillBeMember<T> >(); |
| 721 } |
| 722 } |
| 723 return result; |
| 724 } |
| 725 |
693 // Converts a JavaScript value to an array as per the Web IDL specification: | 726 // Converts a JavaScript value to an array as per the Web IDL specification: |
694 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 727 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
695 template <class T> | 728 template <class T> |
696 Vector<T> toNativeArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isol
ate* isolate) | 729 Vector<T> toNativeArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isol
ate* isolate) |
697 { | 730 { |
698 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 731 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
699 uint32_t length = 0; | 732 uint32_t length = 0; |
700 if (value->IsArray()) { | 733 if (value->IsArray()) { |
701 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 734 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
702 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 735 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 m_block.Reset(); | 999 m_block.Reset(); |
967 } | 1000 } |
968 | 1001 |
969 private: | 1002 private: |
970 v8::TryCatch& m_block; | 1003 v8::TryCatch& m_block; |
971 }; | 1004 }; |
972 | 1005 |
973 } // namespace WebCore | 1006 } // namespace WebCore |
974 | 1007 |
975 #endif // V8Binding_h | 1008 #endif // V8Binding_h |
OLD | NEW |