BooleanPrototype.cpp [plain text]
#include "config.h"
#include "BooleanPrototype.h"
#include "Error.h"
#include "ExceptionHelpers.h"
#include "JSFunction.h"
#include "JSString.h"
#include "ObjectPrototype.h"
#include "JSCInlines.h"
namespace JSC {
static EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState*);
static EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState*);
}
#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()));
}
EncodedJSValue JSC_HOST_CALL booleanProtoFuncToString(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue thisValue = exec->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(exec, scope);
if (thisObject->internalValue() == jsBoolean(false))
return JSValue::encode(vm.smallStrings.falseString());
ASSERT(thisObject->internalValue() == jsBoolean(true));
return JSValue::encode(vm.smallStrings.trueString());
}
EncodedJSValue JSC_HOST_CALL booleanProtoFuncValueOf(ExecState* exec)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSValue thisValue = exec->thisValue();
if (thisValue.isBoolean())
return JSValue::encode(thisValue);
auto* thisObject = jsDynamicCast<BooleanObject*>(vm, thisValue);
if (UNLIKELY(!thisObject))
return throwVMTypeError(exec, scope);
return JSValue::encode(thisObject->internalValue());
}
}