source: webkit/trunk/JavaScriptCore/kjs/object.cpp@ 10207

Last change on this file since 10207 was 10207, checked in by darin, 20 years ago

JavaScriptCore:

Reviewed by Geoff.

  • bindings/NP_jsobject.cpp: (_NPN_SetException):
  • bindings/jni/jni_instance.cpp: (JavaInstance::invokeMethod):
  • bindings/jni/jni_runtime.cpp: (JavaField::dispatchValueFromInstance): (JavaField::dispatchSetValueToInstance):
  • bindings/objc/WebScriptObject.mm: (-[WebScriptObject _initializeWithObjectImp:originExecutionContext:executionContext:]): (-[WebScriptObject _initWithObjectImp:originExecutionContext:executionContext:]): (+[WebScriptObject throwException:]): (-[WebScriptObject setException:]): (+[WebScriptObject _convertValueToObjcValue:originExecutionContext:executionContext:]):
  • bindings/objc/objc_class.h: (KJS::Bindings::ObjcClass::~ObjcClass): (KJS::Bindings::ObjcClass::ObjcClass): (KJS::Bindings::ObjcClass::operator=): (KJS::Bindings::ObjcClass::constructorAt): (KJS::Bindings::ObjcClass::numConstructors):
  • bindings/objc/objc_header.h:
  • bindings/objc/objc_runtime.h: (KJS::Bindings::ObjcField::~ObjcField): (KJS::Bindings::ObjcField::ObjcField): (KJS::Bindings::ObjcField::operator=): (KJS::Bindings::ObjcMethod::ObjcMethod): (KJS::Bindings::ObjcMethod::~ObjcMethod): (KJS::Bindings::ObjcMethod::operator=):
  • bindings/objc/objc_runtime.mm: (ObjcField::valueFromInstance): (ObjcField::setValueToInstance): (ObjcArray::setValueAt): (ObjcArray::valueAt):
  • bindings/objc/objc_utility.h:
  • bindings/objc/objc_utility.mm: (KJS::Bindings::JSMethodNameToObjCMethodName): (KJS::Bindings::convertValueToObjcValue): (KJS::Bindings::convertNSStringToString): (KJS::Bindings::convertObjcValueToValue): (KJS::Bindings::objcValueTypeForType): (KJS::Bindings::createObjcInstanceForValue): (KJS::Bindings::throwError):
  • bindings/runtime.h: (KJS::Bindings::Parameter::~Parameter): (KJS::Bindings::Method::~Method): (KJS::Bindings::Instance::Instance): (KJS::Bindings::Instance::begin): (KJS::Bindings::Instance::end): (KJS::Bindings::Instance::getValueOfUndefinedField): (KJS::Bindings::Instance::supportsSetValueOfUndefinedField): (KJS::Bindings::Instance::setValueOfUndefinedField): (KJS::Bindings::Instance::valueOf):
  • bindings/runtime_array.cpp: (RuntimeArrayImp::put):
  • bindings/runtime_object.h: (KJS::RuntimeObjectImp::setInternalInstance): (KJS::RuntimeObjectImp::getInternalInstance):
  • kjs/array_object.cpp: (getProperty): (ArrayProtoFuncImp::callAsFunction): (ArrayObjectImp::construct):
  • kjs/bool_object.cpp: (BooleanProtoFuncImp::callAsFunction):
  • kjs/date_object.cpp: (KJS::DateProtoFuncImp::callAsFunction):
  • kjs/function.cpp: (KJS::decode): (KJS::GlobalFuncImp::callAsFunction):
  • kjs/function_object.cpp: (FunctionProtoFuncImp::callAsFunction): (FunctionObjectImp::construct):
  • kjs/internal.cpp: (KJS::UndefinedImp::toObject): (KJS::NullImp::toObject): (KJS::InterpreterImp::evaluate): (KJS::InternalFunctionImp::hasInstance):
  • kjs/nodes.cpp: (Node::throwError): (substitute): (Node::setExceptionDetailsIfNeeded): (undefinedVariableError): (ProgramNode::ProgramNode):
  • kjs/number_object.cpp: (NumberProtoFuncImp::callAsFunction):
  • kjs/object.cpp: (KJS::ObjectImp::call): (KJS::ObjectImp::defaultValue): (KJS::Error::create): (KJS::throwError):
  • kjs/object.h: (KJS::ObjectImp::clearProperties): (KJS::ObjectImp::getPropertySlot): (KJS::ObjectImp::getOwnPropertySlot):
  • kjs/object_object.cpp: (ObjectProtoFuncImp::callAsFunction):
  • kjs/reference.cpp: (KJS::Reference::getBase): (KJS::Reference::getValue): (KJS::Reference::putValue): (KJS::Reference::deleteValue):
  • kjs/regexp_object.cpp: (RegExpProtoFuncImp::callAsFunction): (RegExpObjectImp::construct):
  • kjs/string_object.cpp: (StringProtoFuncImp::callAsFunction):

WebCore:

Reviewed by Geoff.

  • khtml/css/cssstyleselector.cpp: (khtml::CSSStyleSelector::CSSStyleSelector): (khtml::parseUASheet): (khtml::CSSStyleSelector::initElementAndPseudoState): (khtml::checkPseudoState): (khtml::CSSStyleSelector::locateCousinList): (khtml::CSSStyleSelector::locateSharedStyle): (khtml::CSSStyleSelector::adjustRenderStyle): (khtml::CSSStyleSelector::checkOneSelector): (khtml::CSSRuleSet::addToRuleSet): (khtml::colorForCSSValue): (khtml::CSSStyleSelector::applyProperty): (khtml::CSSStyleSelector::mapBackgroundAttachment): (khtml::CSSStyleSelector::mapBackgroundImage): (khtml::CSSStyleSelector::mapBackgroundRepeat): (khtml::CSSStyleSelector::mapBackgroundXPosition): (khtml::CSSStyleSelector::mapBackgroundYPosition): (khtml::CSSStyleSelector::getComputedSizeFromSpecifiedSize):
  • khtml/ecma/domparser.cpp: (KJS::DOMParserProtoFunc::callAsFunction):
  • khtml/ecma/kjs_binding.cpp: (KJS::ScriptInterpreter::putDOMObject): (KJS::ScriptInterpreter::putDOMNodeForDocument): (KJS::setDOMException):
  • khtml/ecma/kjs_css.cpp: (KJS::DOMCSSStyleDeclarationProtoFunc::callAsFunction): (KJS::DOMStyleSheetListFunc::callAsFunction): (KJS::KJS::DOMMediaListProtoFunc::callAsFunction): (KJS::DOMCSSStyleSheetProtoFunc::callAsFunction): (KJS::DOMCSSRuleListFunc::callAsFunction): (KJS::DOMCSSRuleFunc::callAsFunction): (KJS::DOMCSSPrimitiveValueProtoFunc::callAsFunction): (KJS::DOMCSSValueListFunc::callAsFunction):
  • khtml/ecma/kjs_dom.cpp: (KJS::DOMNodeProtoFunc::callAsFunction): (KJS::DOMNodeListFunc::callAsFunction): (KJS::DOMDocumentProtoFunc::callAsFunction): (KJS::DOMElementProtoFunc::callAsFunction): (KJS::DOMDOMImplementationProtoFunc::callAsFunction): (KJS::DOMNamedNodeMapProtoFunc::callAsFunction): (KJS::DOMCharacterDataProtoFunc::callAsFunction): (KJS::DOMTextProtoFunc::callAsFunction):
  • khtml/ecma/kjs_events.cpp: (KJS::DOMEventProtoFunc::callAsFunction): (KJS::DOMUIEventProtoFunc::callAsFunction): (KJS::DOMMouseEventProtoFunc::callAsFunction): (KJS::DOMKeyboardEventProtoFunc::callAsFunction): (KJS::DOMMutationEventProtoFunc::callAsFunction): (KJS::DOMWheelEventProtoFunc::callAsFunction): (KJS::ClipboardProtoFunc::callAsFunction):
  • khtml/ecma/kjs_html.cpp: (KJS::KJS::HTMLDocFunction::callAsFunction): (KJS::KJS::HTMLElementFunction::callAsFunction): (KJS::KJS::HTMLCollectionProtoFunc::callAsFunction): (KJS::KJS::Context2DFunction::callAsFunction): (KJS::Context2D::putValueProperty): (KJS::GradientFunction::callAsFunction):
  • khtml/ecma/kjs_navigator.cpp: (KJS::NavigatorFunc::callAsFunction):
  • khtml/ecma/kjs_range.cpp: (KJS::DOMRangeProtoFunc::callAsFunction):
  • khtml/ecma/kjs_traversal.cpp: (KJS::DOMNodeIteratorProtoFunc::callAsFunction): (KJS::DOMNodeFilterProtoFunc::callAsFunction): (KJS::DOMTreeWalkerProtoFunc::callAsFunction):
  • khtml/ecma/kjs_views.cpp: (KJS::DOMAbstractViewFunc::callAsFunction):
  • khtml/ecma/kjs_window.cpp: (KJS::Window::interpreter): (KJS::Window::retrieveWindow): (KJS::Window::retrieveActive): (KJS::Window::isSafeScript): (KJS::Window::clear): (KJS::WindowFunc::callAsFunction): (KJS::ScheduledAction::execute): (KJS::WindowQObject::pauseTimeouts): (KJS::LocationFunc::callAsFunction): (KJS::Selection::toString): (KJS::SelectionFunc::callAsFunction): (KJS::HistoryFunc::callAsFunction):
  • khtml/ecma/xmlhttprequest.cpp: (KJS::XMLHttpRequestProtoFunc::callAsFunction):
  • khtml/ecma/xmlserializer.cpp: (KJS::XMLSerializerProtoFunc::callAsFunction):
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.4 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2001 Harri Porten ([email protected])
5 * Copyright (C) 2001 Peter Kelly ([email protected])
6 * Copyright (C) 2003 Apple Computer, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#include "value.h"
26#include "object.h"
27#include "types.h"
28#include "interpreter.h"
29#include "lookup.h"
30#include "reference_list.h"
31
32#include <assert.h>
33#include <math.h>
34#include <stdio.h>
35
36#include "internal.h"
37#include "collector.h"
38#include "operations.h"
39#include "error_object.h"
40#include "nodes.h"
41
42#ifndef NDEBUG
43//#define JAVASCRIPT_CALL_TRACING 1
44#endif
45
46#if JAVASCRIPT_CALL_TRACING
47static bool _traceJavaScript = false;
48
49extern "C" {
50 void setTraceJavaScript(bool f)
51 {
52 _traceJavaScript = f;
53 }
54
55 static bool traceJavaScript()
56 {
57 return _traceJavaScript;
58 }
59}
60#endif
61
62namespace KJS {
63
64// ------------------------------ Object ---------------------------------------
65
66ValueImp *ObjectImp::call(ExecState *exec, ObjectImp *thisObj, const List &args)
67{
68 assert(implementsCall());
69
70#if KJS_MAX_STACK > 0
71 static int depth = 0; // sum of all concurrent interpreters
72
73#if JAVASCRIPT_CALL_TRACING
74 static bool tracing = false;
75 if (traceJavaScript() && !tracing) {
76 tracing = true;
77 for (int i = 0; i < depth; i++)
78 putchar (' ');
79 printf ("*** calling: %s\n", toString(exec).ascii());
80 for (int j = 0; j < args.size(); j++) {
81 for (int i = 0; i < depth; i++)
82 putchar (' ');
83 printf ("*** arg[%d] = %s\n", j, args[j]->toString(exec).ascii());
84 }
85 tracing = false;
86 }
87#endif
88
89 if (++depth > KJS_MAX_STACK) {
90 --depth;
91 return throwError(exec, RangeError, "Maximum call stack size exceeded.");
92 }
93#endif
94
95 ValueImp *ret = callAsFunction(exec,thisObj,args);
96
97#if KJS_MAX_STACK > 0
98 --depth;
99#endif
100
101#if JAVASCRIPT_CALL_TRACING
102 if (traceJavaScript() && !tracing) {
103 tracing = true;
104 for (int i = 0; i < depth; i++)
105 putchar (' ');
106 printf ("*** returning: %s\n", ret->toString(exec).ascii());
107 tracing = false;
108 }
109#endif
110
111 return ret;
112}
113
114// ------------------------------ ObjectImp ------------------------------------
115
116void ObjectImp::mark()
117{
118 AllocatedValueImp::mark();
119
120 ValueImp *proto = _proto;
121 if (!proto->marked())
122 proto->mark();
123
124 _prop.mark();
125
126 if (_internalValue && !_internalValue->marked())
127 _internalValue->mark();
128
129 _scope.mark();
130}
131
132Type ObjectImp::type() const
133{
134 return ObjectType;
135}
136
137const ClassInfo *ObjectImp::classInfo() const
138{
139 return 0;
140}
141
142UString ObjectImp::className() const
143{
144 const ClassInfo *ci = classInfo();
145 if ( ci )
146 return ci->className;
147 return "Object";
148}
149
150ValueImp *ObjectImp::get(ExecState *exec, const Identifier &propertyName) const
151{
152 PropertySlot slot;
153
154 if (const_cast<ObjectImp *>(this)->getPropertySlot(exec, propertyName, slot))
155 return slot.getValue(exec, propertyName);
156
157 return Undefined();
158}
159
160ValueImp *ObjectImp::get(ExecState *exec, unsigned propertyName) const
161{
162 PropertySlot slot;
163 if (const_cast<ObjectImp *>(this)->getPropertySlot(exec, propertyName, slot))
164 return slot.getValue(exec, propertyName);
165
166 return Undefined();
167}
168
169bool ObjectImp::getPropertySlot(ExecState *exec, unsigned propertyName, PropertySlot& slot)
170{
171 ObjectImp *imp = this;
172
173 while (true) {
174 if (imp->getOwnPropertySlot(exec, propertyName, slot))
175 return true;
176
177 ValueImp *proto = imp->_proto;
178 if (!proto->isObject())
179 break;
180
181 imp = static_cast<ObjectImp *>(proto);
182 }
183
184 return false;
185}
186
187bool ObjectImp::getOwnPropertySlot(ExecState *exec, unsigned propertyName, PropertySlot& slot)
188{
189 return getOwnPropertySlot(exec, Identifier::from(propertyName), slot);
190}
191
192// ECMA 8.6.2.2
193void ObjectImp::put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr)
194{
195 assert(value);
196
197 // non-standard netscape extension
198 if (propertyName == exec->dynamicInterpreter()->specialPrototypeIdentifier()) {
199 setPrototype(value);
200 return;
201 }
202
203 /* TODO: check for write permissions directly w/o this call */
204 /* Doesn't look very easy with the PropertyMap API - David */
205 // putValue() is used for JS assignemnts. It passes no attribute.
206 // Assume that a C++ implementation knows what it is doing
207 // and let it override the canPut() check.
208 if ((attr == None || attr == DontDelete) && !canPut(exec,propertyName)) {
209#ifdef KJS_VERBOSE
210 fprintf( stderr, "WARNING: canPut %s said NO\n", propertyName.ascii() );
211#endif
212 return;
213 }
214
215 _prop.put(propertyName,value,attr);
216}
217
218void ObjectImp::put(ExecState *exec, unsigned propertyName,
219 ValueImp *value, int attr)
220{
221 put(exec, Identifier::from(propertyName), value, attr);
222}
223
224// ECMA 8.6.2.3
225bool ObjectImp::canPut(ExecState *, const Identifier &propertyName) const
226{
227 int attributes;
228 ValueImp *v = _prop.get(propertyName, attributes);
229 if (v)
230 return!(attributes & ReadOnly);
231
232 // Look in the static hashtable of properties
233 const HashEntry* e = findPropertyHashEntry(propertyName);
234 if (e)
235 return !(e->attr & ReadOnly);
236
237 // Don't look in the prototype here. We can always put an override
238 // in the object, even if the prototype has a ReadOnly property.
239 return true;
240}
241
242// ECMA 8.6.2.4
243bool ObjectImp::hasProperty(ExecState *exec, const Identifier &propertyName) const
244{
245 PropertySlot slot;
246 return const_cast<ObjectImp *>(this)->getPropertySlot(exec, propertyName, slot);
247}
248
249bool ObjectImp::hasProperty(ExecState *exec, unsigned propertyName) const
250{
251 PropertySlot slot;
252 return const_cast<ObjectImp *>(this)->getPropertySlot(exec, propertyName, slot);
253}
254
255// ECMA 8.6.2.5
256bool ObjectImp::deleteProperty(ExecState */*exec*/, const Identifier &propertyName)
257{
258 int attributes;
259 ValueImp *v = _prop.get(propertyName, attributes);
260 if (v) {
261 if ((attributes & DontDelete))
262 return false;
263 _prop.remove(propertyName);
264 return true;
265 }
266
267 // Look in the static hashtable of properties
268 const HashEntry* entry = findPropertyHashEntry(propertyName);
269 if (entry && entry->attr & DontDelete)
270 return false; // this builtin property can't be deleted
271 return true;
272}
273
274bool ObjectImp::deleteProperty(ExecState *exec, unsigned propertyName)
275{
276 return deleteProperty(exec, Identifier::from(propertyName));
277}
278
279// ECMA 8.6.2.6
280ValueImp *ObjectImp::defaultValue(ExecState *exec, Type hint) const
281{
282 if (hint != StringType && hint != NumberType) {
283 /* Prefer String for Date objects */
284 if (_proto == exec->lexicalInterpreter()->builtinDatePrototype())
285 hint = StringType;
286 else
287 hint = NumberType;
288 }
289
290 ValueImp *v;
291 if (hint == StringType)
292 v = get(exec,toStringPropertyName);
293 else
294 v = get(exec,valueOfPropertyName);
295
296 if (v->isObject()) {
297 ObjectImp *o = static_cast<ObjectImp*>(v);
298 if (o->implementsCall()) { // spec says "not primitive type" but ...
299 ObjectImp *thisObj = const_cast<ObjectImp*>(this);
300 ValueImp *def = o->call(exec,thisObj,List::empty());
301 Type defType = def->type();
302 if (defType == UnspecifiedType || defType == UndefinedType ||
303 defType == NullType || defType == BooleanType ||
304 defType == StringType || defType == NumberType) {
305 return def;
306 }
307 }
308 }
309
310 if (hint == StringType)
311 v = get(exec,valueOfPropertyName);
312 else
313 v = get(exec,toStringPropertyName);
314
315 if (v->isObject()) {
316 ObjectImp *o = static_cast<ObjectImp*>(v);
317 if (o->implementsCall()) { // spec says "not primitive type" but ...
318 ObjectImp *thisObj = const_cast<ObjectImp*>(this);
319 ValueImp *def = o->call(exec,thisObj,List::empty());
320 Type defType = def->type();
321 if (defType == UnspecifiedType || defType == UndefinedType ||
322 defType == NullType || defType == BooleanType ||
323 defType == StringType || defType == NumberType) {
324 return def;
325 }
326 }
327 }
328
329 if (exec->hadException())
330 return exec->exception();
331
332 return throwError(exec, TypeError, "No default value");
333}
334
335const HashEntry* ObjectImp::findPropertyHashEntry(const Identifier& propertyName) const
336{
337 for (const ClassInfo *info = classInfo(); info; info = info->parentClass) {
338 if (const HashTable *propHashTable = info->propHashTable) {
339 if (const HashEntry *e = Lookup::findEntry(propHashTable, propertyName))
340 return e;
341 }
342 }
343 return 0;
344}
345
346bool ObjectImp::implementsConstruct() const
347{
348 return false;
349}
350
351ObjectImp *ObjectImp::construct(ExecState */*exec*/, const List &/*args*/)
352{
353 assert(false);
354 return NULL;
355}
356
357ObjectImp *ObjectImp::construct(ExecState *exec, const List &args, const UString &/*sourceURL*/, int /*lineNumber*/)
358{
359 return construct(exec, args);
360}
361
362bool ObjectImp::implementsCall() const
363{
364 return false;
365}
366
367ValueImp *ObjectImp::callAsFunction(ExecState */*exec*/, ObjectImp */*thisObj*/, const List &/*args*/)
368{
369 assert(false);
370 return NULL;
371}
372
373bool ObjectImp::implementsHasInstance() const
374{
375 return false;
376}
377
378bool ObjectImp::hasInstance(ExecState */*exec*/, ValueImp */*value*/)
379{
380 assert(false);
381 return false;
382}
383
384ReferenceList ObjectImp::propList(ExecState *exec, bool recursive)
385{
386 ReferenceList list;
387 if (_proto->isObject() && recursive)
388 list = static_cast<ObjectImp*>(_proto)->propList(exec,recursive);
389
390 _prop.addEnumerablesToReferenceList(list, this);
391
392 // Add properties from the static hashtable of properties
393 const ClassInfo *info = classInfo();
394 while (info) {
395 if (info->propHashTable) {
396 int size = info->propHashTable->size;
397 const HashEntry *e = info->propHashTable->entries;
398 for (int i = 0; i < size; ++i, ++e) {
399 if ( e->s && !(e->attr & DontEnum) )
400 list.append(Reference(this, e->s)); /// ######### check for duplicates with the propertymap
401 }
402 }
403 info = info->parentClass;
404 }
405
406 return list;
407}
408
409ValueImp *ObjectImp::toPrimitive(ExecState *exec, Type preferredType) const
410{
411 return defaultValue(exec,preferredType);
412}
413
414bool ObjectImp::toBoolean(ExecState */*exec*/) const
415{
416 return true;
417}
418
419double ObjectImp::toNumber(ExecState *exec) const
420{
421 ValueImp *prim = toPrimitive(exec,NumberType);
422 if (exec->hadException()) // should be picked up soon in nodes.cpp
423 return 0.0;
424 return prim->toNumber(exec);
425}
426
427UString ObjectImp::toString(ExecState *exec) const
428{
429 ValueImp *prim = toPrimitive(exec,StringType);
430 if (exec->hadException()) // should be picked up soon in nodes.cpp
431 return "";
432 return prim->toString(exec);
433}
434
435ObjectImp *ObjectImp::toObject(ExecState */*exec*/) const
436{
437 return const_cast<ObjectImp*>(this);
438}
439
440void ObjectImp::putDirect(const Identifier &propertyName, ValueImp *value, int attr)
441{
442 _prop.put(propertyName, value, attr);
443}
444
445void ObjectImp::putDirect(const Identifier &propertyName, int value, int attr)
446{
447 _prop.put(propertyName, jsNumber(value), attr);
448}
449
450// ------------------------------ Error ----------------------------------------
451
452const char * const errorNamesArr[] = {
453 I18N_NOOP("Error"), // GeneralError
454 I18N_NOOP("Evaluation error"), // EvalError
455 I18N_NOOP("Range error"), // RangeError
456 I18N_NOOP("Reference error"), // ReferenceError
457 I18N_NOOP("Syntax error"), // SyntaxError
458 I18N_NOOP("Type error"), // TypeError
459 I18N_NOOP("URI error"), // URIError
460};
461
462const char * const * const Error::errorNames = errorNamesArr;
463
464ObjectImp *Error::create(ExecState *exec, ErrorType errtype, const UString &message,
465 int lineno, int sourceId, const UString *sourceURL)
466{
467 ObjectImp *cons;
468 switch (errtype) {
469 case EvalError:
470 cons = exec->lexicalInterpreter()->builtinEvalError();
471 break;
472 case RangeError:
473 cons = exec->lexicalInterpreter()->builtinRangeError();
474 break;
475 case ReferenceError:
476 cons = exec->lexicalInterpreter()->builtinReferenceError();
477 break;
478 case SyntaxError:
479 cons = exec->lexicalInterpreter()->builtinSyntaxError();
480 break;
481 case TypeError:
482 cons = exec->lexicalInterpreter()->builtinTypeError();
483 break;
484 case URIError:
485 cons = exec->lexicalInterpreter()->builtinURIError();
486 break;
487 default:
488 cons = exec->lexicalInterpreter()->builtinError();
489 break;
490 }
491
492 List args;
493 if (message.isEmpty())
494 args.append(jsString(errorNames[errtype]));
495 else
496 args.append(jsString(message));
497 ObjectImp *err = static_cast<ObjectImp *>(cons->construct(exec,args));
498
499 if (lineno != -1)
500 err->put(exec, "line", Number(lineno));
501 if (sourceId != -1)
502 err->put(exec, "sourceId", Number(sourceId));
503
504 if(sourceURL)
505 err->put(exec,"sourceURL", String(*sourceURL));
506
507 return err;
508
509/*
510#ifndef NDEBUG
511 const char *msg = err->get("message")->toString().value().ascii();
512 if (l >= 0)
513 fprintf(stderr, "KJS: %s at line %d. %s\n", estr, l, msg);
514 else
515 fprintf(stderr, "KJS: %s. %s\n", estr, msg);
516#endif
517
518 return err;
519*/
520}
521
522ObjectImp *Error::create(ExecState *exec, ErrorType type, const char *message)
523{
524 return create(exec, type, message, -1, -1, NULL);
525}
526
527ObjectImp *throwError(ExecState *exec, ErrorType type)
528{
529 ObjectImp *error = Error::create(exec, type, UString(), -1, -1, NULL);
530 exec->setException(error);
531 return error;
532}
533
534ObjectImp *throwError(ExecState *exec, ErrorType type, const UString &message)
535{
536 ObjectImp *error = Error::create(exec, type, message, -1, -1, NULL);
537 exec->setException(error);
538 return error;
539}
540
541ObjectImp *throwError(ExecState *exec, ErrorType type, const char *message)
542{
543 ObjectImp *error = Error::create(exec, type, message, -1, -1, NULL);
544 exec->setException(error);
545 return error;
546}
547
548ObjectImp *throwError(ExecState *exec, ErrorType type, const UString &message, int line, int sourceId, const UString *sourceURL)
549{
550 ObjectImp *error = Error::create(exec, type, message, line, sourceId, sourceURL);
551 exec->setException(error);
552 return error;
553}
554
555} // namespace KJS
Note: See TracBrowser for help on using the repository browser.