WeakSetConstructor.cpp [plain text]
#include "config.h"
#include "WeakSetConstructor.h"
#include "Error.h"
#include "IteratorOperations.h"
#include "JSCInlines.h"
#include "JSGlobalObject.h"
#include "JSObjectInlines.h"
#include "JSWeakSet.h"
#include "WeakSetPrototype.h"
namespace JSC {
const ClassInfo WeakSetConstructor::s_info = { "Function", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(WeakSetConstructor) };
void WeakSetConstructor::finishCreation(VM& vm, WeakSetPrototype* prototype)
{
Base::finishCreation(vm, prototype->classInfo(vm)->className);
putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(0), PropertyAttribute::DontEnum | PropertyAttribute::ReadOnly);
}
static EncodedJSValue JSC_HOST_CALL callWeakSet(ExecState*);
static EncodedJSValue JSC_HOST_CALL constructWeakSet(ExecState*);
WeakSetConstructor::WeakSetConstructor(VM& vm, Structure* structure)
: Base(vm, structure, callWeakSet, constructWeakSet)
{
}
static EncodedJSValue JSC_HOST_CALL callWeakSet(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(exec, scope, "WeakSet"));
}
static EncodedJSValue JSC_HOST_CALL constructWeakSet(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSGlobalObject* globalObject = jsCast<InternalFunction*>(exec->jsCallee())->globalObject(vm);
Structure* weakSetStructure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), globalObject->weakSetStructure());
RETURN_IF_EXCEPTION(scope, encodedJSValue());
JSWeakSet* weakSet = JSWeakSet::create(vm, 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(vm, 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);
ASSERT(!arguments.hasOverflowed());
call(exec, adderFunction, adderFunctionCallType, adderFunctionCallData, weakSet, arguments);
});
return JSValue::encode(weakSet);
}
}