#include "config.h"
#include "bool_object.h"
#include "JSGlobalObject.h"
#include "error_object.h"
#include "operations.h"
#include <wtf/Assertions.h>
namespace KJS {
const ClassInfo BooleanInstance::info = { "Boolean", 0, 0 };
BooleanInstance::BooleanInstance(JSObject* proto)
: JSWrapperObject(proto)
{
}
static JSValue* booleanProtoFuncToString(ExecState*, JSObject*, const List&);
static JSValue* booleanProtoFuncValueOf(ExecState*, JSObject*, const List&);
BooleanPrototype::BooleanPrototype(ExecState* exec, ObjectPrototype* objectPrototype, FunctionPrototype* functionPrototype)
: BooleanInstance(objectPrototype)
{
setInternalValue(jsBoolean(false));
putDirectFunction(new PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().toString, booleanProtoFuncToString), DontEnum);
putDirectFunction(new PrototypeFunction(exec, functionPrototype, 0, exec->propertyNames().valueOf, booleanProtoFuncValueOf), DontEnum);
}
JSValue* booleanProtoFuncToString(ExecState* exec, JSObject* thisObj, const List&)
{
if (!thisObj->inherits(&BooleanInstance::info))
return throwError(exec, TypeError);
JSValue* v = static_cast<BooleanInstance*>(thisObj)->internalValue();
ASSERT(v);
return jsString(v->toString(exec));
}
JSValue* booleanProtoFuncValueOf(ExecState* exec, JSObject* thisObj, const List&)
{
if (!thisObj->inherits(&BooleanInstance::info))
return throwError(exec, TypeError);
JSValue* v = static_cast<BooleanInstance*>(thisObj)->internalValue();
ASSERT(v);
return jsBoolean(v->toBoolean(exec));
}
BooleanObjectImp::BooleanObjectImp(ExecState* exec, FunctionPrototype* functionPrototype, BooleanPrototype* booleanPrototype)
: InternalFunctionImp(functionPrototype, booleanPrototype->classInfo()->className)
{
putDirect(exec->propertyNames().prototype, booleanPrototype, DontEnum | DontDelete | ReadOnly);
putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly | DontDelete | DontEnum);
}
bool BooleanObjectImp::implementsConstruct() const
{
return true;
}
JSObject* BooleanObjectImp::construct(ExecState* exec, const List& args)
{
BooleanInstance* obj(new BooleanInstance(exec->lexicalGlobalObject()->booleanPrototype()));
obj->setInternalValue(jsBoolean(args[0]->toBoolean(exec)));
return obj;
}
JSValue* BooleanObjectImp::callAsFunction(ExecState* exec, JSObject*, const List& args)
{
return jsBoolean(args[0]->toBoolean(exec));
}
}