Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp b/third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp |
| index d0bb9de194cf24ec8ad2487adc5c89c2ed997404..e1b506c3bed84c919bf10b19fab437bf7e1f6d70 100644 |
| --- a/third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp |
| +++ b/third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp |
| @@ -905,6 +905,30 @@ v8::Local<v8::Function> getBoundFunction(v8::Local<v8::Function> function) |
| return boundFunction->IsFunction() ? v8::Local<v8::Function>::Cast(boundFunction) : function; |
| } |
| +v8::MaybeLocal<v8::Object> getIterator(v8::Local<v8::Object> object, v8::Isolate* isolate, ExceptionState& exceptionState) |
|
Yuki
2016/09/08 06:24:21
Is it worth doing to make this a general utility a
bashi
2016/09/08 06:30:49
That's a good idea but the point of this CL is to
Yuki
2016/09/08 08:32:21
Oops, I thought this is an accessor property, but
Yuki
2016/09/08 08:32:21
Please make v8::Isolate* as the first argument.
bashi
2016/09/09 00:54:22
Done.
|
| +{ |
| + v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| + v8::Local<v8::Value> iteratorGetter; |
| + if (!object->Get(context, v8::Symbol::GetIterator(isolate)).ToLocal(&iteratorGetter)) { |
| + return v8::MaybeLocal<v8::Object>(); |
|
haraken
2016/09/08 09:32:08
Don't we need to throw an exception here?
bashi
2016/09/09 00:54:22
No. IIRC, !ToLocal() means that v8 already thrown
|
| + } |
| + if (!iteratorGetter->IsFunction()) { |
| + exceptionState.throwTypeError("Iterator getter is not callable."); |
| + return v8::MaybeLocal<v8::Object>(); |
| + } |
| + |
| + v8::Local<v8::Function> getterFunction = iteratorGetter.As<v8::Function>(); |
| + v8::Local<v8::Value> iterator; |
| + if (!getterFunction->Call(context, object, 0, nullptr).ToLocal(&iterator)) { |
| + return v8::MaybeLocal<v8::Object>(); |
|
haraken
2016/09/08 09:32:08
Ditto.
|
| + } |
| + if (!iterator->IsObject()) { |
| + exceptionState.throwTypeError("Iterator is not an object."); |
| + return v8::MaybeLocal<v8::Object>(); |
| + } |
| + return v8::MaybeLocal<v8::Object>(iterator.As<v8::Object>()); |
| +} |
| + |
| bool addHiddenValueToArray(v8::Isolate* isolate, v8::Local<v8::Object> object, v8::Local<v8::Value> value, int arrayIndex) |
| { |
| ASSERT(!value.IsEmpty()); |