bool_object.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "value.h"
00023 #include "object.h"
00024 #include "types.h"
00025 #include "interpreter.h"
00026 #include "operations.h"
00027 #include "bool_object.h"
00028 #include "error_object.h"
00029 #include "lookup.h"
00030
00031 #include <assert.h>
00032
00033 using namespace KJS;
00034
00035
00036
00037 const ClassInfo BooleanInstanceImp::info = {"Boolean", 0, 0, 0};
00038
00039 BooleanInstanceImp::BooleanInstanceImp(const Object &proto)
00040 : ObjectImp(proto)
00041 {
00042 }
00043
00044
00045
00046
00047
00048 BooleanPrototypeImp::BooleanPrototypeImp(ExecState *exec,
00049 ObjectPrototypeImp *objectProto,
00050 FunctionPrototypeImp *funcProto)
00051 : BooleanInstanceImp(Object(objectProto))
00052 {
00053 Value protect(this);
00054
00055
00056 put(exec,"toString", Object(new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ToString,0)), DontEnum);
00057 put(exec,"valueOf", Object(new BooleanProtoFuncImp(exec,funcProto,BooleanProtoFuncImp::ValueOf,0)), DontEnum);
00058 setInternalValue(Boolean(false));
00059 }
00060
00061
00062
00063
00064 BooleanProtoFuncImp::BooleanProtoFuncImp(ExecState *exec,
00065 FunctionPrototypeImp *funcProto, int i, int len)
00066 : InternalFunctionImp(funcProto), id(i)
00067 {
00068 Value protect(this);
00069 put(exec,"length",Number(len),DontDelete|ReadOnly|DontEnum);
00070 }
00071
00072
00073 bool BooleanProtoFuncImp::implementsCall() const
00074 {
00075 return true;
00076 }
00077
00078
00079
00080 Value BooleanProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &)
00081 {
00082
00083 KJS_CHECK_THIS( BooleanInstanceImp, thisObj );
00084
00085
00086
00087 Value v = thisObj.internalValue();
00088 assert(!v.isNull());
00089
00090 if (id == ToString)
00091 return String(v.toString(exec));
00092 else
00093 return Boolean(v.toBoolean(exec));
00094 }
00095
00096
00097
00098
00099 BooleanObjectImp::BooleanObjectImp(ExecState *exec, FunctionPrototypeImp *funcProto,
00100 BooleanPrototypeImp *booleanProto)
00101 : InternalFunctionImp(funcProto)
00102 {
00103 Value protect(this);
00104 put(exec,"prototype", Object(booleanProto),DontEnum|DontDelete|ReadOnly);
00105
00106
00107 put(exec,"length", Number(1), ReadOnly|DontDelete|DontEnum);
00108 }
00109
00110
00111 bool BooleanObjectImp::implementsConstruct() const
00112 {
00113 return true;
00114 }
00115
00116
00117 Object BooleanObjectImp::construct(ExecState *exec, const List &args)
00118 {
00119 Object proto = exec->interpreter()->builtinBooleanPrototype();
00120 Object obj(new BooleanInstanceImp(proto));
00121
00122 Boolean b;
00123 if (args.size() > 0)
00124 b = args.begin()->toBoolean(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
This file is part of the documentation for kdelibs Version 3.1.0.