| 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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 template<> | 600 template<> |
| 601 struct NativeValueTraits<ScriptValue> { | 601 struct NativeValueTraits<ScriptValue> { |
| 602 static inline ScriptValue nativeValue(const v8::Handle<v8::Value>& value, v8
::Isolate* isolate) | 602 static inline ScriptValue nativeValue(const v8::Handle<v8::Value>& value, v8
::Isolate* isolate) |
| 603 { | 603 { |
| 604 return ScriptValue(ScriptState::current(isolate), value); | 604 return ScriptValue(ScriptState::current(isolate), value); |
| 605 } | 605 } |
| 606 }; | 606 }; |
| 607 | 607 |
| 608 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::
Isolate*); | 608 v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::
Isolate*); |
| 609 | 609 |
| 610 template <class T, class V8T> | |
| 611 HeapVector<Member<T> > toMemberNativeArray(v8::Handle<v8::Value> value, int argu
mentIndex, v8::Isolate* isolate, bool* success = 0) | |
| 612 { | |
| 613 if (success) | |
| 614 *success = true; | |
| 615 | |
| 616 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | |
| 617 uint32_t length = 0; | |
| 618 if (value->IsArray()) { | |
| 619 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | |
| 620 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | |
| 621 V8ThrowException::throwTypeError(ExceptionMessages::notAnArrayTypeArgume
ntOrValue(argumentIndex), isolate); | |
| 622 return HeapVector<Member<T> >(); | |
| 623 } | |
| 624 | |
| 625 HeapVector<Member<T> > result; | |
| 626 result.reserveInitialCapacity(length); | |
| 627 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); | |
| 628 for (uint32_t i = 0; i < length; ++i) { | |
| 629 v8::Handle<v8::Value> element = object->Get(i); | |
| 630 if (V8T::hasInstance(element, isolate)) { | |
| 631 v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(
element); | |
| 632 result.uncheckedAppend(V8T::toNative(elementObject)); | |
| 633 } else { | |
| 634 if (success) | |
| 635 *success = false; | |
| 636 V8ThrowException::throwTypeError("Invalid Array element type", isola
te); | |
| 637 return HeapVector<Member<T> >(); | |
| 638 } | |
| 639 } | |
| 640 return result; | |
| 641 } | |
| 642 | |
| 643 // 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: |
| 644 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array | 611 // http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
| 645 template <class T> | 612 template <class T> |
| 646 Vector<T> toNativeArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isol
ate* isolate) | 613 Vector<T> toNativeArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isol
ate* isolate) |
| 647 { | 614 { |
| 648 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); | 615 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
| 649 uint32_t length = 0; | 616 uint32_t length = 0; |
| 650 if (value->IsArray()) { | 617 if (value->IsArray()) { |
| 651 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); | 618 length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
| 652 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { | 619 } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 m_block.ReThrow(); | 770 m_block.ReThrow(); |
| 804 } | 771 } |
| 805 | 772 |
| 806 private: | 773 private: |
| 807 v8::TryCatch& m_block; | 774 v8::TryCatch& m_block; |
| 808 }; | 775 }; |
| 809 | 776 |
| 810 } // namespace blink | 777 } // namespace blink |
| 811 | 778 |
| 812 #endif // V8Binding_h | 779 #endif // V8Binding_h |
| OLD | NEW |