BooleanConstructor.cpp [plain text]
#include "config.h"
#include "BooleanConstructor.h"
#include "BooleanPrototype.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 JSC_DECLARE_HOST_FUNCTION(callBooleanConstructor);
static JSC_DECLARE_HOST_FUNCTION(constructWithBooleanConstructor);
JSC_DEFINE_HOST_FUNCTION(callBooleanConstructor, (JSGlobalObject* globalObject, CallFrame* callFrame))
{
return JSValue::encode(jsBoolean(callFrame->argument(0).toBoolean(globalObject)));
}
JSC_DEFINE_HOST_FUNCTION(constructWithBooleanConstructor, (JSGlobalObject* globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue boolean = jsBoolean(callFrame->argument(0).toBoolean(globalObject));
JSObject* newTarget = asObject(callFrame->newTarget());
Structure* booleanStructure = newTarget == callFrame->jsCallee()
? globalObject->booleanObjectStructure()
: InternalFunction::createSubclassStructure(globalObject, newTarget, getFunctionRealm(vm, newTarget)->booleanObjectStructure());
RETURN_IF_EXCEPTION(scope, { });
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, 1, vm.propertyNames->Boolean.string(), PropertyAdditionMode::WithoutStructureTransition);
putDirectWithoutTransition(vm, vm.propertyNames->prototype, booleanPrototype, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
}
JSObject* constructBooleanFromImmediateBoolean(JSGlobalObject* globalObject, JSValue immediateBooleanValue)
{
VM& vm = globalObject->vm();
BooleanObject* obj = BooleanObject::create(vm, globalObject->booleanObjectStructure());
obj->setInternalValue(vm, immediateBooleanValue);
return obj;
}
}