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, new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ToString,0,toStringPropertyName), DontEnum);
00058 putDirect(valueOfPropertyName, new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ValueOf,0,valueOfPropertyName), DontEnum);
00059 setInternalValue(Boolean(false));
00060 }
00061
00062
00063
00064
00065 BooleanProtoFuncImp::BooleanProtoFuncImp(ExecState * ,
00066 FunctionPrototypeImp *funcProto, int i, int len, const Identifier &_ident)
00067 : InternalFunctionImp(funcProto), id(i)
00068 {
00069 Value protect(this);
00070 putDirect(lengthPropertyName, len, DontDelete|ReadOnly|DontEnum);
00071 ident = _ident;
00072 }
00073
00074
00075 bool BooleanProtoFuncImp::implementsCall() const
00076 {
00077 return true;
00078 }
00079
00080
00081
00082 Value BooleanProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &)
00083 {
00084
00085 KJS_CHECK_THIS( BooleanInstanceImp, thisObj );
00086
00087
00088
00089 Value v = thisObj.internalValue();
00090 assert(v.isValid());
00091
00092 if (id == ToString)
00093 return String(v.toString(exec));
00094 return Boolean(v.toBoolean(exec));
00095 }
00096
00097
00098
00099
00100 BooleanObjectImp::BooleanObjectImp(ExecState * , FunctionPrototypeImp *funcProto,
00101 BooleanPrototypeImp *booleanProto)
00102 : InternalFunctionImp(funcProto)
00103 {
00104 Value protect(this);
00105 putDirect(prototypePropertyName, booleanProto, DontEnum|DontDelete|ReadOnly);
00106
00107
00108 putDirect(lengthPropertyName, NumberImp::one(), ReadOnly|DontDelete|DontEnum);
00109 }
00110
00111
00112 bool BooleanObjectImp::implementsConstruct() const
00113 {
00114 return true;
00115 }
00116
00117
00118 Object BooleanObjectImp::construct(ExecState *exec, const List &args)
00119 {
00120 Object obj(new BooleanInstanceImp(exec->lexicalInterpreter()->builtinBooleanPrototype().imp()));
00121
00122 Boolean b;
00123 if (args.size() > 0)
00124 b = args.begin()->dispatchToBoolean(exec);
00125 else
00126 b = Boolean(false);
00127
00128 obj.setInternalValue(b);
00129
00130 return obj;
00131 }
00132
00133 bool BooleanObjectImp::implementsCall() const
00134 {
00135 return true;
00136 }
00137
00138
00139 Value BooleanObjectImp::call(ExecState *exec, Object &, const List &args)
00140 {
00141 if (args.isEmpty())
00142 return Boolean(false);
00143 else
00144 return Boolean(args[0].toBoolean(exec));
00145 }
00146