Chromium Code Reviews| Index: Source/core/dom/Iterable.h |
| diff --git a/Source/core/dom/Iterable.h b/Source/core/dom/Iterable.h |
| index c1ba4d8e5832ed2fa0631708c206a47e530a7f25..3d87f9c84799c165a50ee50f6b59a975a470a7d6 100644 |
| --- a/Source/core/dom/Iterable.h |
| +++ b/Source/core/dom/Iterable.h |
| @@ -6,6 +6,7 @@ |
| #define Iterable_h |
| #include "bindings/core/v8/V8IteratorResultValue.h" |
| +#include "bindings/core/v8/V8ScriptRunner.h" |
| #include "core/dom/Iterator.h" |
| namespace blink { |
| @@ -38,6 +39,44 @@ public: |
| return new IterableIterator<EntrySelector>(source); |
| } |
| + void forEach(ScriptState* scriptState, const ScriptValue& thisValue, const ScriptValue& callback, const ScriptValue& thisArg, ExceptionState& exceptionState) |
| + { |
| + IterationSource* source = this->startIteration(scriptState, exceptionState); |
| + |
| + v8::Isolate* isolate = scriptState->isolate(); |
| + |
| + v8::Context::Scope contextScope(scriptState->context()); |
| + v8::HandleScope handleScope(isolate); |
|
yhirano
2015/01/23 11:49:03
Can you tell me why v8::Context::Scope is necessar
Jens Widell
2015/01/23 11:53:55
I don't know that it is, to be honest. I put it he
haraken
2015/01/23 11:55:39
Given that forEach is always called from JavaScrip
Jens Widell
2015/01/23 11:58:14
Yeah, that makes sense.
|
| + v8::TryCatch tryCatch(isolate); |
| + |
| + v8::Local<v8::Object> creationContext(scriptState->context()->Global()); |
| + v8::Local<v8::Function> v8Callback(callback.v8Value().As<v8::Function>()); |
| + v8::Local<v8::Value> v8ThisArg(thisArg.v8Value()); |
| + v8::Local<v8::Value> args[3]; |
| + |
| + args[2] = thisValue.v8Value(); |
| + |
| + while (true) { |
| + KeyType key; |
| + ValueType value; |
| + |
| + if (!source->next(scriptState, key, value, exceptionState)) |
| + return; |
| + |
| + ASSERT(!exceptionState.hadException()); |
| + |
| + args[0] = toV8(value, creationContext, isolate); |
| + args[1] = toV8(key, creationContext, isolate); |
| + |
| + V8ScriptRunner::callFunction(v8Callback, scriptState->executionContext(), v8ThisArg, 3, args, isolate); |
| + |
| + if (tryCatch.HasCaught()) { |
| + exceptionState.rethrowV8Exception(tryCatch.Exception()); |
| + return; |
| + } |
| + } |
| + } |
| + |
| class IterationSource : public GarbageCollectedFinalized<IterationSource> { |
| public: |
| virtual ~IterationSource() { } |