BooleanPrototype.cpp [plain text]
#include "config.h"
#include "BooleanPrototype.h"
#include "IntegrityInlines.h"
#include "JSCInlines.h"
namespace JSC {
static JSC_DECLARE_HOST_FUNCTION(booleanProtoFuncToString);
static JSC_DECLARE_HOST_FUNCTION(booleanProtoFuncValueOf);
}
#include "BooleanPrototype.lut.h"
namespace JSC {
const ClassInfo BooleanPrototype::s_info = { "Boolean", &BooleanObject::s_info, &booleanPrototypeTable, nullptr, CREATE_METHOD_TABLE(BooleanPrototype) };
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(BooleanPrototype);
BooleanPrototype::BooleanPrototype(VM& vm, Structure* structure)
: BooleanObject(vm, structure)
{
}
void BooleanPrototype::finishCreation(VM& vm, JSGlobalObject*)
{
Base::finishCreation(vm);
setInternalValue(vm, jsBoolean(false));
ASSERT(inherits(vm, info()));
}
JSC_DEFINE_HOST_FUNCTION(booleanProtoFuncToString, (JSGlobalObject* globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue thisValue = callFrame->thisValue();
if (thisValue == jsBoolean(false))
return JSValue::encode(vm.smallStrings.falseString());
if (thisValue == jsBoolean(true))
return JSValue::encode(vm.smallStrings.trueString());
auto* thisObject = jsDynamicCast<BooleanObject*>(vm, thisValue);
if (UNLIKELY(!thisObject))
return throwVMTypeError(globalObject, scope);
Integrity::auditStructureID(vm, thisObject->structureID());
if (thisObject->internalValue() == jsBoolean(false))
return JSValue::encode(vm.smallStrings.falseString());
ASSERT(thisObject->internalValue() == jsBoolean(true));
return JSValue::encode(vm.smallStrings.trueString());
}
JSC_DEFINE_HOST_FUNCTION(booleanProtoFuncValueOf, (JSGlobalObject* globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue thisValue = callFrame->thisValue();
if (thisValue.isBoolean())
return JSValue::encode(thisValue);
auto* thisObject = jsDynamicCast<BooleanObject*>(vm, thisValue);
if (UNLIKELY(!thisObject))
return throwVMTypeError(globalObject, scope);
Integrity::auditStructureID(vm, thisObject->structureID());
return JSValue::encode(thisObject->internalValue());
}
}