Chromium Code Reviews

Unified Diff: Source/bindings/tests/results/core/V8TestObject.cpp

Issue 807263007: IDL: Add forEach() method to iterable<>/maplike<>/setlike<> interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: Source/bindings/tests/results/core/V8TestObject.cpp
diff --git a/Source/bindings/tests/results/core/V8TestObject.cpp b/Source/bindings/tests/results/core/V8TestObject.cpp
index 65810f209a48e923a0fe53f5155f7b1217a66081..7d498bd3ebb4342f3844a468e61c4f06efe735d3 100644
--- a/Source/bindings/tests/results/core/V8TestObject.cpp
+++ b/Source/bindings/tests/results/core/V8TestObject.cpp
@@ -10763,6 +10763,41 @@ static void entriesMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& inf
TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
}
+static void forEachMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ ExceptionState exceptionState(ExceptionState::ExecutionContext, "forEach", "TestObject", info.Holder(), info.GetIsolate());
+ if (UNLIKELY(info.Length() < 1)) {
+ setMinimumArityTypeError(exceptionState, 1, info.Length());
+ exceptionState.throwIfNeeded();
+ return;
+ }
+ TestObject* impl = V8TestObject::toImpl(info.Holder());
+ ScriptValue callback;
+ ScriptValue thisArg;
+ {
+ if (!info[0]->IsFunction()) {
+ exceptionState.throwTypeError("The callback provided as parameter 1 is not a function.");
+ exceptionState.throwIfNeeded();
+ return;
+ }
+ callback = ScriptValue(ScriptState::current(info.GetIsolate()), info[0]);
+ thisArg = ScriptValue(ScriptState::current(info.GetIsolate()), info[1]);
+ }
+ ScriptState* scriptState = ScriptState::current(info.GetIsolate());
+ impl->forEach(scriptState, ScriptValue(scriptState, info.This()), callback, thisArg, exceptionState);
+ if (exceptionState.hadException()) {
+ exceptionState.throwIfNeeded();
+ return;
+ }
+}
+
+static void forEachMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
+{
+ TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod");
+ TestObjectV8Internal::forEachMethod(info);
+ TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
+}
+
static void toStringMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
{
TestObject* impl = V8TestObject::toImpl(info.Holder());
@@ -11193,6 +11228,7 @@ static const V8DOMConfiguration::MethodConfiguration V8TestObjectMethods[] = {
{"keys", TestObjectV8Internal::keysMethodCallback, 0, 0, V8DOMConfiguration::ExposedToAllScripts},
{"values", TestObjectV8Internal::valuesMethodCallback, 0, 0, V8DOMConfiguration::ExposedToAllScripts},
{"entries", TestObjectV8Internal::entriesMethodCallback, 0, 0, V8DOMConfiguration::ExposedToAllScripts},
+ {"forEach", TestObjectV8Internal::forEachMethodCallback, 0, 1, V8DOMConfiguration::ExposedToAllScripts},
{"toString", TestObjectV8Internal::toStringMethodCallback, 0, 0, V8DOMConfiguration::ExposedToAllScripts},
};

Powered by Google App Engine