source: webkit/trunk/JavaScriptCore/kjs/object.h@ 10456

Last change on this file since 10456 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: 20.5 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#ifndef KJS_OBJECT_H
26#define KJS_OBJECT_H
27
28// Objects
29
30// maximum global call stack size. Protects against accidental or
31// malicious infinite recursions. Define to -1 if you want no limit.
32#if APPLE_CHANGES
33// Given OS X stack sizes we run out of stack at about 350 levels.
34// If we improve our stack usage, we can bump this number.
35#define KJS_MAX_STACK 100
36#else
37#define KJS_MAX_STACK 1000
38#endif
39
40#include "interpreter.h"
41#include "property_map.h"
42#include "property_slot.h"
43#include "scope_chain.h"
44
45namespace KJS {
46
47 class HashTable;
48 class HashEntry;
49 class ListImp;
50
51 // ECMA 262-3 8.6.1
52 // Property attributes
53 enum Attribute { None = 0,
54 ReadOnly = 1 << 1, // property can be only read, not written
55 DontEnum = 1 << 2, // property doesn't appear in (for .. in ..)
56 DontDelete = 1 << 3, // property can't be deleted
57 Internal = 1 << 4, // an internal property, set to bypass checks
58 Function = 1 << 5 }; // property is a function - only used by static hashtables
59
60 /**
61 * Class Information
62 */
63 struct ClassInfo {
64 /**
65 * A string denoting the class name. Example: "Window".
66 */
67 const char* className;
68 /**
69 * Pointer to the class information of the base class.
70 * 0L if there is none.
71 */
72 const ClassInfo *parentClass;
73 /**
74 * Static hash-table of properties.
75 */
76 const HashTable *propHashTable;
77 /**
78 * Reserved for future extension.
79 */
80 void *dummy;
81 };
82
83 class ObjectImp : public AllocatedValueImp {
84 public:
85 /**
86 * Creates a new ObjectImp with the specified prototype
87 *
88 * @param proto The prototype
89 */
90 ObjectImp(ObjectImp *proto);
91
92 /**
93 * Creates a new ObjectImp with a prototype of jsNull()
94 * (that is, the ECMAScript "null" value, not a null object pointer).
95 */
96 ObjectImp();
97
98 virtual void mark();
99 virtual Type type() const;
100
101 /**
102 * A pointer to a ClassInfo struct for this class. This provides a basic
103 * facility for run-time type information, and can be used to check an
104 * object's class an inheritance (see inherits()). This should
105 * always return a statically declared pointer, or 0 to indicate that
106 * there is no class information.
107 *
108 * This is primarily useful if you have application-defined classes that you
109 * wish to check against for casting purposes.
110 *
111 * For example, to specify the class info for classes FooImp and BarImp,
112 * where FooImp inherits from BarImp, you would add the following in your
113 * class declarations:
114 *
115 * \code
116 * class BarImp : public ObjectImp {
117 * virtual const ClassInfo *classInfo() const { return &info; }
118 * static const ClassInfo info;
119 * // ...
120 * };
121 *
122 * class FooImp : public ObjectImp {
123 * virtual const ClassInfo *classInfo() const { return &info; }
124 * static const ClassInfo info;
125 * // ...
126 * };
127 * \endcode
128 *
129 * And in your source file:
130 *
131 * \code
132 * const ClassInfo BarImp::info = {"Bar", 0, 0, 0}; // no parent class
133 * const ClassInfo FooImp::info = {"Foo", &BarImp::info, 0, 0};
134 * \endcode
135 *
136 * @see inherits()
137 */
138 virtual const ClassInfo *classInfo() const;
139
140 /**
141 * Checks whether this object inherits from the class with the specified
142 * classInfo() pointer. This requires that both this class and the other
143 * class return a non-NULL pointer for their classInfo() methods (otherwise
144 * it will return false).
145 *
146 * For example, for two ObjectImp pointers obj1 and obj2, you can check
147 * if obj1's class inherits from obj2's class using the following:
148 *
149 * if (obj1->inherits(obj2->classInfo())) {
150 * // ...
151 * }
152 *
153 * If you have a handle to a statically declared ClassInfo, such as in the
154 * classInfo() example, you can check for inheritance without needing
155 * an instance of the other class:
156 *
157 * if (obj1->inherits(FooImp::info)) {
158 * // ...
159 * }
160 *
161 * @param cinfo The ClassInfo pointer for the class you want to check
162 * inheritance against.
163 * @return true if this object's class inherits from class with the
164 * ClassInfo pointer specified in cinfo
165 */
166 bool inherits(const ClassInfo *cinfo) const;
167
168 // internal properties (ECMA 262-3 8.6.2)
169
170 /**
171 * Returns the prototype of this object. Note that this is not the same as
172 * the "prototype" property.
173 *
174 * See ECMA 8.6.2
175 *
176 * @return The object's prototype
177 */
178 ValueImp *prototype() const;
179 void setPrototype(ValueImp *proto);
180
181 /**
182 * Returns the class name of the object
183 *
184 * See ECMA 8.6.2
185 *
186 * @return The object's class name
187 */
188 /**
189 * Implementation of the [[Class]] internal property (implemented by all
190 * Objects)
191 *
192 * The default implementation uses classInfo().
193 * You should either implement classInfo(), or
194 * if you simply need a classname, you can reimplement className()
195 * instead.
196 */
197 virtual UString className() const;
198
199 /**
200 * Retrieves the specified property from the object. If neither the object
201 * or any other object in it's prototype chain have the property, this
202 * function will return Undefined.
203 *
204 * See ECMA 8.6.2.1
205 *
206 * @param exec The current execution state
207 * @param propertyName The name of the property to retrieve
208 *
209 * @return The specified property, or Undefined
210 */
211 ValueImp *get(ExecState *exec, const Identifier &propertyName) const;
212 ValueImp *get(ExecState *exec, unsigned propertyName) const;
213
214 bool getPropertySlot(ExecState *, const Identifier&, PropertySlot&);
215 bool getPropertySlot(ExecState *, unsigned, PropertySlot&);
216
217 virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
218 virtual bool getOwnPropertySlot(ExecState *, unsigned index, PropertySlot&);
219
220 /**
221 * Sets the specified property.
222 *
223 * See ECMA 8.6.2.2
224 *
225 * @param exec The current execution state
226 * @param propertyName The name of the property to set
227 * @param propertyValue The value to set
228 */
229 virtual void put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr = None);
230 virtual void put(ExecState *exec, unsigned propertyName, ValueImp *value, int attr = None);
231
232 /**
233 * Used to check whether or not a particular property is allowed to be set
234 * on an object
235 *
236 * See ECMA 8.6.2.3
237 *
238 * @param exec The current execution state
239 * @param propertyName The name of the property
240 * @return true if the property can be set, otherwise false
241 */
242 /**
243 * Implementation of the [[CanPut]] internal property (implemented by all
244 * Objects)
245 */
246 virtual bool canPut(ExecState *exec, const Identifier &propertyName) const;
247
248 /**
249 * Checks to see whether the object (or any object in it's prototype chain)
250 * has a property with the specified name.
251 *
252 * See ECMA 8.6.2.4
253 *
254 * @param exec The current execution state
255 * @param propertyName The name of the property to check for
256 * @return true if the object has the property, otherwise false
257 */
258 bool hasProperty(ExecState *exec, const Identifier &propertyName) const;
259 bool hasProperty(ExecState *exec, unsigned propertyName) const;
260
261 /**
262 * Removes the specified property from the object.
263 *
264 * See ECMA 8.6.2.5
265 *
266 * @param exec The current execution state
267 * @param propertyName The name of the property to delete
268 * @return true if the property was successfully deleted or did not
269 * exist on the object. false if deleting the specified property is not
270 * allowed.
271 */
272 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
273 virtual bool deleteProperty(ExecState *exec, unsigned propertyName);
274
275 /**
276 * Converts the object into a primitive value. The value return may differ
277 * depending on the supplied hint
278 *
279 * See ECMA 8.6.2.6
280 *
281 * @param exec The current execution state
282 * @param hint The desired primitive type to convert to
283 * @return A primitive value converted from the objetc. Note that the
284 * type of primitive value returned may not be the same as the requested
285 * hint.
286 */
287 /**
288 * Implementation of the [[DefaultValue]] internal property (implemented by
289 * all Objects)
290 */
291 virtual ValueImp *defaultValue(ExecState *exec, Type hint) const;
292
293 /**
294 * Whether or not the object implements the construct() method. If this
295 * returns false you should not call the construct() method on this
296 * object (typically, an assertion will fail to indicate this).
297 *
298 * @return true if this object implements the construct() method, otherwise
299 * false
300 */
301 virtual bool implementsConstruct() const;
302
303 /**
304 * Creates a new object based on this object. Typically this means the
305 * following:
306 * 1. A new object is created
307 * 2. The prototype of the new object is set to the value of this object's
308 * "prototype" property
309 * 3. The call() method of this object is called, with the new object
310 * passed as the this value
311 * 4. The new object is returned
312 *
313 * In some cases, Host objects may differ from these semantics, although
314 * this is discouraged.
315 *
316 * If an error occurs during construction, the execution state's exception
317 * will be set. This can be tested for with ExecState::hadException().
318 * Under some circumstances, the exception object may also be returned.
319 *
320 * Note: This function should not be called if implementsConstruct() returns
321 * false, in which case it will result in an assertion failure.
322 *
323 * @param exec The current execution state
324 * @param args The arguments to be passed to call() once the new object has
325 * been created
326 * @return The newly created &amp; initialized object
327 */
328 /**
329 * Implementation of the [[Construct]] internal property
330 */
331 virtual ObjectImp *construct(ExecState *exec, const List &args);
332 virtual ObjectImp *construct(ExecState *exec, const List &args, const UString &sourceURL, int lineNumber);
333
334 /**
335 * Whether or not the object implements the call() method. If this returns
336 * false you should not call the call() method on this object (typically,
337 * an assertion will fail to indicate this).
338 *
339 * @return true if this object implements the call() method, otherwise
340 * false
341 */
342 virtual bool implementsCall() const;
343
344 /**
345 * Calls this object as if it is a function.
346 *
347 * Note: This function should not be called if implementsCall() returns
348 * false, in which case it will result in an assertion failure.
349 *
350 * See ECMA 8.6.2.3
351 *
352 * @param exec The current execution state
353 * @param thisObj The obj to be used as "this" within function execution.
354 * Note that in most cases this will be different from the C++ "this"
355 * object. For example, if the ECMAScript code "window.location->toString()"
356 * is executed, call() will be invoked on the C++ object which implements
357 * the toString method, with the thisObj being window.location
358 * @param args List of arguments to be passed to the function
359 * @return The return value from the function
360 */
361 ValueImp *call(ExecState *exec, ObjectImp *thisObj, const List &args);
362 virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args);
363
364 /**
365 * Whether or not the object implements the hasInstance() method. If this
366 * returns false you should not call the hasInstance() method on this
367 * object (typically, an assertion will fail to indicate this).
368 *
369 * @return true if this object implements the hasInstance() method,
370 * otherwise false
371 */
372 virtual bool implementsHasInstance() const;
373
374 /**
375 * Checks whether value delegates behavior to this object. Used by the
376 * instanceof operator.
377 *
378 * @param exec The current execution state
379 * @param value The value to check
380 * @return true if value delegates behavior to this object, otherwise
381 * false
382 */
383 virtual bool hasInstance(ExecState *exec, ValueImp *value);
384
385 /**
386 * Returns the scope of this object. This is used when execution declared
387 * functions - the execution context for the function is initialized with
388 * extra object in it's scope. An example of this is functions declared
389 * inside other functions:
390 *
391 * \code
392 * function f() {
393 *
394 * function b() {
395 * return prototype;
396 * }
397 *
398 * var x = 4;
399 * // do some stuff
400 * }
401 * f.prototype = new String();
402 * \endcode
403 *
404 * When the function f.b is executed, its scope will include properties of
405 * f. So in the example above the return value of f.b() would be the new
406 * String object that was assigned to f.prototype.
407 *
408 * @param exec The current execution state
409 * @return The function's scope
410 */
411 const ScopeChain &scope() const { return _scope; }
412 void setScope(const ScopeChain &s) { _scope = s; }
413
414 /**
415 * Returns a List of References to all the properties of the object. Used
416 * in "for x in y" statements. The list is created new, so it can be freely
417 * modified without affecting the object's properties. It should be deleted
418 * by the caller.
419 *
420 * Subclasses can override this method in ObjectImpl to provide the
421 * appearance of
422 * having extra properties other than those set specifically with put().
423 *
424 * @param exec The current execution state
425 * @param recursive Whether or not properties in the object's prototype
426 * chain should be
427 * included in the list.
428 * @return A List of References to properties of the object.
429 **/
430 virtual ReferenceList propList(ExecState *exec, bool recursive = true);
431
432 /**
433 * Returns the internal value of the object. This is used for objects such
434 * as String and Boolean which are wrappers for native types. The interal
435 * value is the actual value represented by the wrapper objects.
436 *
437 * @see ECMA 8.6.2
438 * @return The internal value of the object
439 */
440 ValueImp *internalValue() const;
441
442 /**
443 * Sets the internal value of the object
444 *
445 * @see internalValue()
446 *
447 * @param v The new internal value
448 */
449 void setInternalValue(ValueImp *v);
450
451 ValueImp *toPrimitive(ExecState *exec, Type preferredType = UnspecifiedType) const;
452 bool toBoolean(ExecState *exec) const;
453 double toNumber(ExecState *exec) const;
454 UString toString(ExecState *exec) const;
455 ObjectImp *toObject(ExecState *exec) const;
456
457 // This get function only looks at the property map.
458 // This is used e.g. by lookupOrCreateFunction (to cache a function, we don't want
459 // to look up in the prototype, it might already exist there)
460 ValueImp *getDirect(const Identifier& propertyName) const
461 { return _prop.get(propertyName); }
462 ValueImp **getDirectLocation(const Identifier& propertyName)
463 { return _prop.getLocation(propertyName); }
464 void putDirect(const Identifier &propertyName, ValueImp *value, int attr = 0);
465 void putDirect(const Identifier &propertyName, int value, int attr = 0);
466
467 /**
468 * Remove all properties from this object.
469 * This doesn't take DontDelete into account, and isn't in the ECMA spec.
470 * It's simply a quick way to remove everything stored in the property map.
471 */
472 void clearProperties() { _prop.clear(); }
473
474 void saveProperties(SavedProperties &p) const { _prop.save(p); }
475 void restoreProperties(const SavedProperties &p) { _prop.restore(p); }
476
477 virtual bool isActivation() { return false; }
478 protected:
479 PropertyMap _prop;
480 private:
481 const HashEntry* findPropertyHashEntry( const Identifier& propertyName ) const;
482 ValueImp *_proto;
483 ValueImp *_internalValue;
484 ScopeChain _scope;
485 };
486
487 /**
488 * Types of Native Errors available. For custom errors, GeneralError
489 * should be used.
490 */
491 enum ErrorType { GeneralError = 0,
492 EvalError = 1,
493 RangeError = 2,
494 ReferenceError = 3,
495 SyntaxError = 4,
496 TypeError = 5,
497 URIError = 6};
498
499 /**
500 * @short Factory methods for error objects.
501 */
502 class Error {
503 public:
504 /**
505 * Factory method for error objects.
506 *
507 * @param exec The current execution state
508 * @param errtype Type of error.
509 * @param message Optional error message.
510 * @param lineNumber Optional line number.
511 * @param sourceId Optional source id.
512 * @param sourceURL Optional source URL.
513 */
514 static ObjectImp *create(ExecState *, ErrorType, const UString &message, int lineNumber, int sourceId, const UString *sourceURL);
515 static ObjectImp *create(ExecState *, ErrorType, const char *message);
516
517 /**
518 * Array of error names corresponding to ErrorType
519 */
520 static const char * const * const errorNames;
521 };
522
523ObjectImp *throwError(ExecState *, ErrorType, const UString &message, int lineNumber, int sourceId, const UString *sourceURL);
524ObjectImp *throwError(ExecState *, ErrorType, const UString &message);
525ObjectImp *throwError(ExecState *, ErrorType, const char *message);
526ObjectImp *throwError(ExecState *, ErrorType);
527
528inline bool AllocatedValueImp::isObject(const ClassInfo *info) const
529{
530 return isObject() && static_cast<const ObjectImp *>(this)->inherits(info);
531}
532
533inline ObjectImp::ObjectImp(ObjectImp *proto)
534 : _proto(proto), _internalValue(0)
535{
536 assert(proto);
537}
538
539inline ObjectImp::ObjectImp()
540 : _proto(jsNull()), _internalValue(0)
541{
542}
543
544inline ValueImp *ObjectImp::internalValue() const
545{
546 return _internalValue;
547}
548
549inline void ObjectImp::setInternalValue(ValueImp *v)
550{
551 _internalValue = v;
552}
553
554inline ValueImp *ObjectImp::prototype() const
555{
556 return _proto;
557}
558
559inline void ObjectImp::setPrototype(ValueImp *proto)
560{
561 assert(proto);
562 _proto = proto;
563}
564
565inline bool ObjectImp::inherits(const ClassInfo *info) const
566{
567 for (const ClassInfo *ci = classInfo(); ci; ci = ci->parentClass)
568 if (ci == info)
569 return true;
570 return false;
571}
572
573// It may seem crazy to inline a function this large but it makes a big difference
574// since this is function very hot in variable lookup
575inline bool ObjectImp::getPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
576{
577 ObjectImp *object = this;
578 while (true) {
579 if (object->getOwnPropertySlot(exec, propertyName, slot))
580 return true;
581
582 ValueImp *proto = object->_proto;
583 if (!proto->isObject())
584 return false;
585
586 object = static_cast<ObjectImp *>(proto);
587 }
588}
589
590// It may seem crazy to inline a function this large, especially a virtual function,
591// but it makes a big difference to property lookup that derived classes can inline their
592// base class call to this.
593inline bool ObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
594{
595 if (ValueImp **location = getDirectLocation(propertyName)) {
596 slot.setValueSlot(this, location);
597 return true;
598 }
599
600 // non-standard Netscape extension
601 if (propertyName == exec->dynamicInterpreter()->specialPrototypeIdentifier()) {
602 slot.setValueSlot(this, &_proto);
603 return true;
604 }
605
606 return false;
607}
608
609} // namespace
610
611#endif // KJS_OBJECT_H
Note: See TracBrowser for help on using the repository browser.