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

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: remove FIXMEs about missing forEach() 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..71b090dcd3e4d06ae1febd6c76256e923d819246 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,41 @@ 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::TryCatch tryCatch(isolate);
haraken 2015/01/27 01:56:30 I guess you don't need this TryCatch (see the belo
+
+ 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);
haraken 2015/01/27 01:56:30 Nit: It is interesting that the order is value =>
Jens Widell 2015/01/27 07:19:23 Yeah, in this context it seems a bit backwards. Th
+
+ V8ScriptRunner::callFunction(v8Callback, scriptState->executionContext(), v8ThisArg, 3, args, isolate);
+
+ if (tryCatch.HasCaught()) {
haraken 2015/01/27 01:56:30 Can we use exceptionState.hadException()? We don't
Jens Widell 2015/01/27 07:19:23 Since I'm not passing 'exceptionState' to V8Script
+ exceptionState.rethrowV8Exception(tryCatch.Exception());
+ return;
+ }
+ }
+ }
+
class IterationSource : public GarbageCollectedFinalized<IterationSource> {
public:
virtual ~IterationSource() { }

Powered by Google App Engine
This is Rietveld 408576698