BooleanConstructor.cpp [plain text]
#include "config.h"
#include "BooleanConstructor.h"
#include "BooleanPrototype.h"
#include "JSGlobalObject.h"
#include "JSCInlines.h"
namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(BooleanConstructor);
const ClassInfo BooleanConstructor::s_info = { "Function", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(BooleanConstructor) };
static EncodedJSValue JSC_HOST_CALL callBooleanConstructor(ExecState* exec)
{
return JSValue::encode(jsBoolean(exec->argument(0).toBoolean(exec)));
}
static EncodedJSValue JSC_HOST_CALL constructWithBooleanConstructor(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue boolean = jsBoolean(exec->argument(0).toBoolean(exec));
Structure* booleanStructure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), asInternalFunction(exec->jsCallee())->globalObject()->booleanObjectStructure());
RETURN_IF_EXCEPTION(scope, encodedJSValue());
BooleanObject* obj = BooleanObject::create(vm, booleanStructure);
obj->setInternalValue(vm, boolean);
return JSValue::encode(obj);
}
BooleanConstructor::BooleanConstructor(VM& vm, Structure* structure)
: InternalFunction(vm, structure, callBooleanConstructor, constructWithBooleanConstructor)
{
}
void BooleanConstructor::finishCreation(VM& vm, BooleanPrototype* booleanPrototype)
{
Base::finishCreation(vm, booleanPrototype->classInfo()->className);
putDirectWithoutTransition(vm, vm.propertyNames->prototype, booleanPrototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), PropertyAttribute::ReadOnly | PropertyAttribute::DontEnum);
}
JSObject* constructBooleanFromImmediateBoolean(ExecState* exec, JSGlobalObject* globalObject, JSValue immediateBooleanValue)
{
VM& vm = exec->vm();
BooleanObject* obj = BooleanObject::create(vm, globalObject->booleanObjectStructure());
obj->setInternalValue(vm, immediateBooleanValue);
return obj;
}
}