Chromium Code Reviews| Index: Source/bindings/core/v8/V8Binding.h |
| diff --git a/Source/bindings/core/v8/V8Binding.h b/Source/bindings/core/v8/V8Binding.h |
| index 4a80cbef23492bf3dfd9404d5a5df5c5aea5f51e..f69b5102039871f01f598d438997b3dde7327e40 100644 |
| --- a/Source/bindings/core/v8/V8Binding.h |
| +++ b/Source/bindings/core/v8/V8Binding.h |
| @@ -788,6 +788,42 @@ Vector<T> toImplArray(v8::Local<v8::Value> value, int argumentIndex, v8::Isolate |
| return result; |
| } |
| +template <class T> |
|
bashi
2015/05/01 04:31:23
nit: class -> typename
haraken
2015/05/01 05:34:11
Done.
|
| +HeapVector<T> toImplHeapArray(v8::Local<v8::Value> value, int argumentIndex, v8::Isolate* isolate, ExceptionState& exceptionState) |
| +{ |
| + v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); |
|
bashi
2015/05/01 04:31:23
Help me understand: why do you create temporary v8
haraken
2015/05/01 05:34:11
Done. (Actually I just copied the code from the ab
|
| + uint32_t length = 0; |
| + if (value->IsArray()) { |
| + length = v8::Local<v8::Array>::Cast(v8Value)->Length(); |
| + } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
| + if (!exceptionState.hadException()) |
| + exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgumentOrValue(argumentIndex)); |
| + return HeapVector<T>(); |
| + } |
| + |
| + if (length > WTF::DefaultAllocatorQuantizer::kMaxUnquantizedAllocation / sizeof(T)) { |
| + exceptionState.throwTypeError("Array length exceeds supported limit."); |
| + return HeapVector<T>(); |
| + } |
| + |
| + HeapVector<T> result; |
| + result.reserveInitialCapacity(length); |
| + typedef NativeValueTraits<T> TraitsType; |
| + v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); |
| + v8::TryCatch block; |
| + for (uint32_t i = 0; i < length; ++i) { |
| + v8::Local<v8::Value> element; |
| + if (!v8Call(object->Get(isolate->GetCurrentContext(), i), element, block)) { |
| + exceptionState.rethrowV8Exception(block.Exception()); |
| + return HeapVector<T>(); |
| + } |
| + result.uncheckedAppend(TraitsType::nativeValue(isolate, element, exceptionState)); |
| + if (exceptionState.hadException()) |
| + return HeapVector<T>(); |
| + } |
| + return result; |
| +} |
| + |
| template <typename T> |
| Vector<T> toImplArray(const Vector<ScriptValue>& value, v8::Isolate* isolate, ExceptionState& exceptionState) |
| { |