00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#include "value.h"
00024
#include "object.h"
00025
#include "types.h"
00026
#include "interpreter.h"
00027
#include "operations.h"
00028
#include "bool_object.h"
00029
#include "error_object.h"
00030
#include "lookup.h"
00031
00032
#include <assert.h>
00033
00034
using namespace KJS;
00035
00036
00037
00038
const ClassInfo BooleanInstanceImp::info = {
"Boolean", 0, 0, 0};
00039
00040 BooleanInstanceImp::BooleanInstanceImp(ObjectImp *proto)
00041 : ObjectImp(proto)
00042 {
00043 }
00044
00045
00046
00047
00048
00049 BooleanPrototypeImp::BooleanPrototypeImp(
ExecState *exec,
00050 ObjectPrototypeImp *objectProto,
00051
FunctionPrototypeImp *funcProto)
00052 : BooleanInstanceImp(objectProto)
00053 {
00054
Value protect(
this);
00055
00056
00057 putDirect(toStringPropertyName,
00058
new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ToString,0,toStringPropertyName), DontEnum);
00059 putDirect(valueOfPropertyName,
00060
new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ValueOf,0,valueOfPropertyName), DontEnum);
00061 setInternalValue(
Boolean(
false));
00062 }
00063
00064
00065
00066
00067 BooleanProtoFuncImp::BooleanProtoFuncImp(
ExecState * ,
FunctionPrototypeImp *funcProto,
00068
int i,
int len,
const Identifier &_ident)
00069 :
InternalFunctionImp(funcProto), id(i)
00070 {
00071
Value protect(
this);
00072 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum);
00073 ident = _ident;
00074 }
00075
00076
00077
bool BooleanProtoFuncImp::implementsCall()
const
00078
{
00079
return true;
00080 }
00081
00082
00083
00084
Value BooleanProtoFuncImp::call(
ExecState *exec,
Object &thisObj,
const List &)
00085 {
00086
00087 KJS_CHECK_THIS( BooleanInstanceImp, thisObj );
00088
00089
00090
00091
Value v = thisObj.
internalValue();
00092 assert(v.
isValid());
00093
00094
if (
id == ToString)
00095
return String(v.
toString(exec));
00096
else
00097
return Boolean(v.
toBoolean(exec));
00098 }
00099
00100
00101
00102
00103 BooleanObjectImp::BooleanObjectImp(
ExecState * ,
FunctionPrototypeImp *funcProto,
00104 BooleanPrototypeImp *booleanProto)
00105 :
InternalFunctionImp(funcProto)
00106 {
00107
Value protect(
this);
00108 putDirect(prototypePropertyName, booleanProto,DontEnum|DontDelete|ReadOnly);
00109
00110
00111 putDirect(lengthPropertyName, NumberImp::one(), ReadOnly|DontDelete|DontEnum);
00112 }
00113
00114
00115
bool BooleanObjectImp::implementsConstruct()
const
00116
{
00117
return true;
00118 }
00119
00120
00121
Object BooleanObjectImp::construct(
ExecState *exec,
const List &args)
00122 {
00123
Object obj(
new BooleanInstanceImp(exec->
interpreter()->
builtinBooleanPrototype().
imp()));
00124
00125
Boolean b;
00126
if (args.
size() > 0)
00127 b = args.
begin()->dispatchToBoolean(exec);
00128
else
00129 b =
Boolean(
false);
00130
00131 obj.
setInternalValue(b);
00132
00133
return obj;
00134 }
00135
00136
bool BooleanObjectImp::implementsCall()
const
00137
{
00138
return true;
00139 }
00140
00141
00142
Value BooleanObjectImp::call(
ExecState *exec,
Object &,
const List &args)
00143 {
00144
if (args.
isEmpty())
00145
return Boolean(
false);
00146
else
00147
return Boolean(args[0].toBoolean(exec));
00148 }
00149