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

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: adjust test expectations 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
« no previous file with comments | « Source/bindings/tests/results/modules/V8TestInterface5.cpp ('k') | Source/modules/webmidi/MIDIInputMap.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+
+ 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() { }
« no previous file with comments | « Source/bindings/tests/results/modules/V8TestInterface5.cpp ('k') | Source/modules/webmidi/MIDIInputMap.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698