Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Unified Diff: Source/core/dom/Iterable.h

Issue 807263007: IDL: Add forEach() method to iterable<>/maplike<>/setlike<> interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: extend testing Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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() { }

Powered by Google App Engine
This is Rietveld 408576698