• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kjs
 

kjs

  • kjs
error_object.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
4 * Copyright (C) 2003 Apple Computer, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22#include "value.h"
23#include "object.h"
24#include "types.h"
25#include "interpreter.h"
26#include "operations.h"
27#include "error_object.h"
28//#include "debugger.h"
29
30using namespace KJS;
31
32// ------------------------------ ErrorInstanceImp ----------------------------
33
34const ClassInfo ErrorInstanceImp::info = {"Error", 0, 0, 0};
35
36ErrorInstanceImp::ErrorInstanceImp(ObjectImp *proto)
37 : ObjectImp(proto)
38{
39}
40
41// ------------------------------ ErrorPrototypeImp ----------------------------
42
43// ECMA 15.9.4
44ErrorPrototypeImp::ErrorPrototypeImp(ExecState *exec,
45 ObjectPrototypeImp *objectProto,
46 FunctionPrototypeImp *funcProto)
47 : ObjectImp(objectProto)
48{
49 Value protect(this);
50 setInternalValue(Undefined());
51 // The constructor will be added later in ErrorObjectImp's constructor
52
53 put(exec, namePropertyName, String("Error"), DontEnum);
54 put(exec, messagePropertyName, String("Unknown error"), DontEnum);
55 putDirect(toStringPropertyName, new ErrorProtoFuncImp(exec,funcProto), DontEnum);
56}
57
58// ------------------------------ ErrorProtoFuncImp ----------------------------
59
60ErrorProtoFuncImp::ErrorProtoFuncImp(ExecState * /*exec*/, FunctionPrototypeImp *funcProto)
61 : InternalFunctionImp(funcProto)
62{
63 Value protect(this);
64 putDirect(lengthPropertyName, NumberImp::zero(), DontDelete|ReadOnly|DontEnum);
65 ident = "toString";
66}
67
68bool ErrorProtoFuncImp::implementsCall() const
69{
70 return true;
71}
72
73Value ErrorProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &/*args*/)
74{
75 // toString()
76 UString s = "Error";
77
78 Value v = thisObj.get(exec, namePropertyName);
79 if (v.type() != UndefinedType) {
80 s = v.toString(exec);
81 }
82
83 v = thisObj.get(exec, messagePropertyName);
84 if (v.type() != UndefinedType) {
85 s += ": " + v.toString(exec); // Mozilla compatible format
86 }
87
88 return String(s);
89}
90
91// ------------------------------ ErrorObjectImp -------------------------------
92
93ErrorObjectImp::ErrorObjectImp(ExecState * /*exec*/, FunctionPrototypeImp *funcProto,
94 ErrorPrototypeImp *errorProto)
95 : InternalFunctionImp(funcProto)
96{
97 Value protect(this);
98 // ECMA 15.11.3.1 Error.prototype
99 putDirect(prototypePropertyName, errorProto, DontEnum|DontDelete|ReadOnly);
100 putDirect(lengthPropertyName, NumberImp::one(), DontDelete|ReadOnly|DontEnum);
101 //putDirect(namePropertyName, String(n));
102}
103
104bool ErrorObjectImp::implementsConstruct() const
105{
106 return true;
107}
108
109// ECMA 15.9.3
110Object ErrorObjectImp::construct(ExecState *exec, const List &args)
111{
112 Object proto = Object::dynamicCast(exec->lexicalInterpreter()->builtinErrorPrototype());
113 ObjectImp *imp = new ErrorInstanceImp(proto.imp());
114 Object obj(imp);
115
116 if (!args.isEmpty() && args[0].type() != UndefinedType) {
117 imp->putDirect(messagePropertyName, new StringImp(args[0].toString(exec)));
118 }
119
120 return obj;
121}
122
123bool ErrorObjectImp::implementsCall() const
124{
125 return true;
126}
127
128// ECMA 15.9.2
129Value ErrorObjectImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
130{
131 // "Error()" gives the sames result as "new Error()"
132 return construct(exec,args);
133}
134
135// ------------------------------ NativeErrorPrototypeImp ----------------------
136
137NativeErrorPrototypeImp::NativeErrorPrototypeImp(ExecState * /*exec*/, ErrorPrototypeImp *errorProto,
138 ErrorType et, UString name, UString message)
139 : ObjectImp(errorProto)
140{
141 Value protect(this);
142 errType = et;
143 putDirect(namePropertyName, new StringImp(name), 0);
144 putDirect(messagePropertyName, new StringImp(message), 0);
145}
146
147// ------------------------------ NativeErrorImp -------------------------------
148
149const ClassInfo NativeErrorImp::info = {"Function", &InternalFunctionImp::info, 0, 0};
150
151NativeErrorImp::NativeErrorImp(ExecState * /*exec*/, FunctionPrototypeImp *funcProto,
152 const Object &prot)
153 : InternalFunctionImp(funcProto), proto(0)
154{
155 Value protect(this);
156 proto = static_cast<ObjectImp*>(prot.imp());
157
158 putDirect(lengthPropertyName, NumberImp::one(), DontDelete|ReadOnly|DontEnum); // ECMA 15.11.7.5
159 putDirect(prototypePropertyName, proto, DontDelete|ReadOnly|DontEnum);
160}
161
162bool NativeErrorImp::implementsConstruct() const
163{
164 return true;
165}
166
167Object NativeErrorImp::construct(ExecState *exec, const List &args)
168{
169 ObjectImp *imp = new ErrorInstanceImp(proto);
170 Object obj(imp);
171 if (args[0].type() != UndefinedType)
172 imp->putDirect(messagePropertyName, new StringImp(args[0].toString(exec)));
173 return obj;
174}
175
176bool NativeErrorImp::implementsCall() const
177{
178 return true;
179}
180
181Value NativeErrorImp::call(ExecState *exec, Object &/*thisObj*/, const List &args)
182{
183 return construct(exec,args);
184}
185
186void NativeErrorImp::mark()
187{
188 ObjectImp::mark();
189 if (proto && !proto->marked())
190 proto->mark();
191}
KJS::ExecState
Represents the current state of script execution.
Definition: interpreter.h:438
KJS::ExecState::lexicalInterpreter
Interpreter * lexicalInterpreter() const
Returns the interpreter associated with the current scope's global object.
Definition: interpreter.cpp:394
KJS::FunctionPrototypeImp
The initial value of Function.prototype (and thus all objects created with the Function constructor)
Definition: function_object.h:34
KJS::InternalFunctionImp
Base class for all function objects.
Definition: function.h:40
KJS::Interpreter::builtinErrorPrototype
Object builtinErrorPrototype() const
Returns the builtin "Error.prototype" object.
Definition: interpreter.cpp:258
KJS::List
Native list type.
Definition: list.h:48
KJS::List::isEmpty
bool isEmpty() const
Definition: list.h:86
KJS::Object
Represents an Object.
Definition: object.h:81
KJS::Object::get
Value get(ExecState *exec, const Identifier &propertyName) const
Retrieves the specified property from the object.
Definition: object.h:663
KJS::String
Represents an primitive String value.
Definition: value.h:340
KJS::UString
Unicode string class.
Definition: ustring.h:189
KJS::Undefined
Represents an primitive Undefined value.
Definition: value.h:269
KJS::Value
Value objects are act as wrappers ("smart pointers") around ValueImp objects and their descendents.
Definition: value.h:167
KJS::Value::toString
UString toString(ExecState *exec) const
Performs the ToString type conversion operation on this value (ECMA 9.8)
Definition: value.h:246
KJS::Value::type
Type type() const
Returns the type of value.
Definition: value.h:195
KJS::ClassInfo
Class Information.
Definition: object.h:58

kjs

Skip menu "kjs"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kjs

Skip menu "kjs"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kjs by doxygen 1.9.4
This website is maintained by Timothy Pearson.