+ Structure* weakMapStructure = globalObject->weakMapStructure();
+ JSWeakMap* weakMap = JSWeakMap::create(exec, weakMapStructure);
+ JSValue iterable = exec->argument(0);
+ if (iterable.isUndefinedOrNull())
+ return JSValue::encode(weakMap);
+
+ JSValue adderFunction = weakMap->JSObject::get(exec, exec->propertyNames().set);
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+
+ CallData adderFunctionCallData;
+ CallType adderFunctionCallType = getCallData(adderFunction, adderFunctionCallData);
+ if (adderFunctionCallType == CallTypeNone)
+ return JSValue::encode(throwTypeError(exec));
+
+ JSValue iteratorFunction = iterable.get(exec, exec->propertyNames().iteratorSymbol);
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+
+ CallData iteratorFunctionCallData;
+ CallType iteratorFunctionCallType = getCallData(iteratorFunction, iteratorFunctionCallData);
+ if (iteratorFunctionCallType == CallTypeNone)
+ return JSValue::encode(throwTypeError(exec));
+
+ ArgList iteratorFunctionArguments;
+ JSValue iterator = call(exec, iteratorFunction, iteratorFunctionCallType, iteratorFunctionCallData, iterable, iteratorFunctionArguments);
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+
+ if (!iterator.isObject())
+ return JSValue::encode(throwTypeError(exec));
+
+ while (true) {
+ JSValue next = iteratorStep(exec, iterator);
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+
+ if (next.isFalse())
+ return JSValue::encode(weakMap);
+
+ JSValue nextItem = iteratorValue(exec, next);
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+
+ if (!nextItem.isObject()) {
+ throwTypeError(exec);
+ iteratorClose(exec, iterator);
+ return JSValue::encode(jsUndefined());
+ }
+
+ JSValue key = nextItem.get(exec, 0);
+ if (exec->hadException()) {
+ iteratorClose(exec, iterator);
+ return JSValue::encode(jsUndefined());
+ }
+
+ JSValue value = nextItem.get(exec, 1);
+ if (exec->hadException()) {
+ iteratorClose(exec, iterator);
+ return JSValue::encode(jsUndefined());
+ }
+
+ MarkedArgumentBuffer arguments;
+ arguments.append(key);
+ arguments.append(value);
+ call(exec, adderFunction, adderFunctionCallType, adderFunctionCallData, weakMap, arguments);
+ if (exec->hadException()) {
+ iteratorClose(exec, iterator);
+ return JSValue::encode(jsUndefined());
+ }
+ }
+ RELEASE_ASSERT_NOT_REACHED();
+ return JSValue::encode(weakMap);