Speculatively change iteration protocall to use the same next function
[WebKit-https.git] / Source / JavaScriptCore / runtime / JSGenericTypedArrayViewConstructorInlines.h
index 8c40792..c6165fb 100644 (file)
@@ -77,27 +77,16 @@ Structure* JSGenericTypedArrayViewConstructor<ViewClass>::createStructure(
 }
 
 template<typename ViewClass>
-inline JSObject* constructGenericTypedArrayViewFromIterator(ExecState* exec, Structure* structure, JSValue iterator)
+inline JSObject* constructGenericTypedArrayViewFromIterator(ExecState* exec, Structure* structure, JSObject* iterable, JSValue iteratorMethod)
 {
     VM& vm = exec->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
 
-    if (!iterator.isObject())
-        return throwTypeError(exec, scope, ASCIILiteral("Symbol.Iterator for the first argument did not return an object."));
-
     MarkedArgumentBuffer storage;
-    while (true) {
-        JSValue next = iteratorStep(exec, iterator);
-        RETURN_IF_EXCEPTION(scope, nullptr);
-
-        if (next.isFalse())
-            break;
-
-        JSValue nextItem = iteratorValue(exec, next);
-        RETURN_IF_EXCEPTION(scope, nullptr);
-
-        storage.append(nextItem);
-    }
+    forEachInIterable(*exec, iterable, iteratorMethod, [&] (VM&, ExecState&, JSValue value) {
+        storage.append(value);
+    });
+    RETURN_IF_EXCEPTION(scope, nullptr);
 
     ViewClass* result = ViewClass::createUninitialized(exec, structure, storage.size());
     EXCEPTION_ASSERT(!!scope.exception() == !result);
@@ -172,17 +161,7 @@ inline JSObject* constructGenericTypedArrayViewWithArguments(ExecState* exec, St
                     || lengthSlot.isAccessor() || lengthSlot.isCustom() || lengthSlot.isTaintedByOpaqueObject()
                     || hasAnyArrayStorage(object->indexingType()))) {
 
-                    CallData callData;
-                    CallType callType = getCallData(iteratorFunc, callData);
-                    if (callType == CallType::None)
-                        return throwTypeError(exec, scope, ASCIILiteral("Symbol.Iterator for the first argument cannot be called."));
-
-                    ArgList arguments;
-                    JSValue iterator = call(exec, iteratorFunc, callType, callData, object, arguments);
-                    RETURN_IF_EXCEPTION(scope, nullptr);
-
-                    scope.release();
-                    return constructGenericTypedArrayViewFromIterator<ViewClass>(exec, structure, iterator);
+                    return constructGenericTypedArrayViewFromIterator<ViewClass>(exec, structure, object, iteratorFunc);
             }
 
             if (lengthSlot.isUnset())