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 "error_object.h"
00028
00029
00030 using namespace KJS;
00031
00032
00033
00034
00035 ErrorPrototypeImp::ErrorPrototypeImp(ExecState *exec,
00036 ObjectPrototypeImp *objectProto,
00037 FunctionPrototypeImp *funcProto)
00038 : ObjectImp(Object(objectProto))
00039 {
00040 Value protect(this);
00041 setInternalValue(Undefined());
00042
00043
00044 put(exec, "name", String("Error"), DontEnum);
00045 put(exec, "message", String("Unknown error"), DontEnum);
00046 put(exec, "toString", Object(new ErrorProtoFuncImp(exec,funcProto)), DontEnum);
00047 }
00048
00049
00050
00051 ErrorProtoFuncImp::ErrorProtoFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto)
00052 : InternalFunctionImp(funcProto)
00053 {
00054 Value protect(this);
00055 put(exec,"length",Number(0),DontDelete|ReadOnly|DontEnum);
00056 }
00057
00058 bool ErrorProtoFuncImp::implementsCall() const
00059 {
00060 return true;
00061 }
00062
00063 Value ErrorProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &)
00064 {
00065
00066 UString s = "Error";
00067
00068 Value v = thisObj.get(exec,"name");
00069 if (v.type() != UndefinedType) {
00070 s = v.toString(exec);
00071 }
00072
00073 v = thisObj.get(exec,"message");
00074 if (v.type() != UndefinedType) {
00075 s += ": "+v.toString(exec);
00076 }
00077
00078 return String(s);
00079 }
00080
00081
00082
00083 ErrorObjectImp::ErrorObjectImp(ExecState *exec, FunctionPrototypeImp *funcProto,
00084 ErrorPrototypeImp *errorProto)
00085 : InternalFunctionImp(funcProto)
00086 {
00087 Value protect(this);
00088
00089 put(exec, "prototype", Object(errorProto), DontEnum|DontDelete|ReadOnly);
00090
00091 }
00092
00093 bool ErrorObjectImp::implementsConstruct() const
00094 {
00095 return true;
00096 }
00097
00098
00099 Object ErrorObjectImp::construct(ExecState *exec, const List &args)
00100 {
00101 Object proto = Object::dynamicCast(exec->interpreter()->builtinErrorPrototype());
00102 Object obj(new ObjectImp(proto));
00103
00104 if (!args.isEmpty() && args[0].type() != UndefinedType) {
00105 obj.put(exec,"message", String(args[0].toString(exec)));
00106 }
00107
00108 return obj;
00109 }
00110
00111 bool ErrorObjectImp::implementsCall() const
00112 {
00113 return true;
00114 }
00115
00116
00117 Value ErrorObjectImp::call(ExecState *exec, Object &, const List &args)
00118 {
00119
00120 return construct(exec,args);
00121 }
00122
00123
00124
00125 NativeErrorPrototypeImp::NativeErrorPrototypeImp(ExecState *exec, ErrorPrototypeImp *errorProto,
00126 ErrorType et, UString name, UString message)
00127 : ObjectImp(Object(errorProto))
00128 {
00129 Value protect(this);
00130 errType = et;
00131 put(exec,"name",String(name));
00132 put(exec,"message",String(message));
00133 }
00134
00135
00136
00137 const ClassInfo NativeErrorImp::info = {"Error", &InternalFunctionImp::info, 0, 0};
00138
00139 NativeErrorImp::NativeErrorImp(ExecState *exec, FunctionPrototypeImp *funcProto,
00140 const Object &prot)
00141 : InternalFunctionImp(funcProto), proto(0)
00142 {
00143 Value protect(this);
00144 proto = static_cast<ObjectImp*>(prot.imp());
00145
00146 put(exec,"length",Number(1),DontDelete|ReadOnly|DontEnum);
00147 put(exec,"prototype",prot);
00148 }
00149
00150 bool NativeErrorImp::implementsConstruct() const
00151 {
00152 return true;
00153 }
00154
00155 Object NativeErrorImp::construct(ExecState *exec, const List &args)
00156 {
00157 Object obj(new ObjectImp(Object(proto)));
00158 if (args[0].type() != UndefinedType)
00159 obj.put(exec, "message", String(args[0].toString(exec)));
00160 return obj;
00161 }
00162
00163 bool NativeErrorImp::implementsCall() const
00164 {
00165 return true;
00166 }
00167
00168 Value NativeErrorImp::call(ExecState *exec, Object &, const List &args)
00169 {
00170 return construct(exec,args);
00171 }
00172
00173 void NativeErrorImp::mark()
00174 {
00175 ObjectImp::mark();
00176 if (proto && !proto->marked())
00177 proto->mark();
00178 }
00179