static EncodedJSValue JSC_HOST_CALL constructWeakSet(ExecState* exec) { VM& vm = exec->vm(); auto scope = DECLARE_THROW_SCOPE(vm); JSGlobalObject* globalObject = asInternalFunction(exec->jsCallee())->globalObject(); Structure* weakSetStructure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), globalObject->weakSetStructure()); RETURN_IF_EXCEPTION(scope, encodedJSValue()); JSWeakSet* weakSet = JSWeakSet::create(exec, weakSetStructure); JSValue iterable = exec->argument(0); if (iterable.isUndefinedOrNull()) return JSValue::encode(weakSet); JSValue adderFunction = weakSet->JSObject::get(exec, vm.propertyNames->add); RETURN_IF_EXCEPTION(scope, encodedJSValue()); CallData adderFunctionCallData; CallType adderFunctionCallType = getCallData(adderFunction, adderFunctionCallData); if (adderFunctionCallType == CallType::None) return JSValue::encode(throwTypeError(exec, scope)); scope.release(); forEachInIterable(exec, iterable, [&](VM&, ExecState* exec, JSValue nextValue) { MarkedArgumentBuffer arguments; arguments.append(nextValue); call(exec, adderFunction, adderFunctionCallType, adderFunctionCallData, weakSet, arguments); }); return JSValue::encode(weakSet); }
static EncodedJSValue JSC_HOST_CALL constructWeakMap(ExecState* exec) { VM& vm = exec->vm(); auto scope = DECLARE_THROW_SCOPE(vm); JSGlobalObject* globalObject = asInternalFunction(exec->callee())->globalObject(); Structure* weakMapStructure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), globalObject->weakMapStructure()); if (exec->hadException()) return JSValue::encode(JSValue()); 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 == CallType::None) return JSValue::encode(throwTypeError(exec, scope)); forEachInIterable(exec, iterable, [&](VM& vm, ExecState* exec, JSValue nextItem) { if (!nextItem.isObject()) { throwTypeError(exec, scope); return; } JSValue key = nextItem.get(exec, static_cast<unsigned>(0)); if (vm.exception()) return; JSValue value = nextItem.get(exec, static_cast<unsigned>(1)); if (vm.exception()) return; MarkedArgumentBuffer arguments; arguments.append(key); arguments.append(value); call(exec, adderFunction, adderFunctionCallType, adderFunctionCallData, weakMap, arguments); }); return JSValue::encode(weakMap); }