Index: Source/bindings/v8/V8Binding.h |
diff --git a/Source/bindings/v8/V8Binding.h b/Source/bindings/v8/V8Binding.h |
index 86602d66f86fb6077ef4df698950292d8c716adc..3bf2d725948a4255a2155bed2307caa0ba279ca0 100644 |
--- a/Source/bindings/v8/V8Binding.h |
+++ b/Source/bindings/v8/V8Binding.h |
@@ -471,6 +471,8 @@ struct NativeValueTraits<v8::Handle<v8::Value> > { |
} |
}; |
+v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::Isolate*); |
+ |
// Converts a JavaScript value to an array as per the Web IDL specification: |
// http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
template <class T, class V8T> |
@@ -494,8 +496,6 @@ Vector<RefPtr<T> > toRefPtrNativeArrayUnchecked(v8::Local<v8::Value> v8Value, ui |
return result; |
} |
-v8::Handle<v8::Value> toV8Sequence(v8::Handle<v8::Value>, uint32_t& length, v8::Isolate*); |
- |
template <class T, class V8T> |
Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isolate* isolate, bool* success = 0) |
{ |
@@ -530,6 +530,39 @@ Vector<RefPtr<T> > toRefPtrNativeArray(v8::Handle<v8::Value> value, const String |
return toRefPtrNativeArrayUnchecked<T, V8T>(v8Value, length, isolate, success); |
} |
+template <class T, class V8T> |
+HeapVector<Member<T> > toMemberNativeArray(v8::Handle<v8::Value> value, int argumentIndex, v8::Isolate* isolate, bool* success = 0) |
+{ |
+ if (success) |
+ *success = true; |
+ |
+ v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
+ uint32_t length = 0; |
+ if (value->IsArray()) { |
+ length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
+ } else if (toV8Sequence(value, length, isolate).IsEmpty()) { |
+ throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex), isolate); |
+ return HeapVector<Member<T> >(); |
+ } |
+ |
+ HeapVector<Member<T> > result; |
+ result.reserveInitialCapacity(length); |
+ v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
+ for (uint32_t i = 0; i < length; ++i) { |
+ v8::Handle<v8::Value> element = object->Get(i); |
+ if (V8T::hasInstance(element, isolate)) { |
+ v8::Handle<v8::Object> elementObject = v8::Handle<v8::Object>::Cast(element); |
+ result.uncheckedAppend(V8T::toNative(elementObject)); |
+ } else { |
+ if (success) |
+ *success = false; |
+ throwTypeError("Invalid Array element type", isolate); |
+ return HeapVector<Member<T> >(); |
+ } |
+ } |
+ return result; |
+} |
+ |
// Converts a JavaScript value to an array as per the Web IDL specification: |
// http://www.w3.org/TR/2012/CR-WebIDL-20120419/#es-array |
template <class T> |