Changeset 10076 in webkit for trunk/JavaScriptCore/kjs/object.h
- Timestamp:
- Aug 6, 2005, 11:17:49 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/object.h
r9889 r10076 39 39 #endif 40 40 41 #include "value.h"42 41 #include "types.h" 42 #include "interpreter.h" 43 43 #include "reference_list.h" 44 44 #include "property_map.h" 45 #include "property_slot.h" 45 46 #include "scope_chain.h" 46 47 … … 50 51 class HashEntry; 51 52 class ListImp; 52 class ReferenceList;53 54 // ECMA 262-3 8.6.155 // Attributes (only applicable to the Object type)56 enum Attribute { None = 0,57 ReadOnly = 1 << 1, // property can be only read, not written58 DontEnum = 1 << 2, // property doesn't appear in (for .. in ..)59 DontDelete = 1 << 3, // property can't be deleted60 Internal = 1 << 4, // an internal property, set to by pass checks61 Function = 1 << 5 }; // property is a function - only used by static hashtables62 53 63 54 /** … … 84 75 }; 85 76 86 /**87 * Represents an Object. This is a wrapper for ObjectImp88 */89 class Object : public Value {90 public:91 Object() { }92 Object(ObjectImp *);93 operator ObjectImp *() const { return imp(); }94 95 ObjectImp *imp() const;96 97 const ClassInfo *classInfo() const;98 bool inherits(const ClassInfo *cinfo) const;99 100 /**101 * Converts a Value into an Object. If the value's type is not ObjectType,102 * a null object will be returned (i.e. one with it's internal pointer set103 * to 0). If you do not know for sure whether the value is of type104 * ObjectType, you should check the isValid() methods afterwards before105 * calling any methods on the Object.106 *107 * @return The value converted to an object108 */109 static Object dynamicCast(const Value &v);110 111 /**112 * Returns the prototype of this object. Note that this is not the same as113 * the "prototype" property.114 *115 * See ECMA 8.6.2116 *117 * @return The object's prototype118 */119 Value prototype() const;120 121 /**122 * Returns the class name of the object123 *124 * See ECMA 8.6.2125 *126 * @return The object's class name127 */128 UString className() const;129 130 /**131 * Retrieves the specified property from the object. If neither the object132 * or any other object in it's prototype chain have the property, this133 * function will return Undefined.134 *135 * See ECMA 8.6.2.1136 *137 * @param exec The current execution state138 * @param propertyName The name of the property to retrieve139 *140 * @return The specified property, or Undefined141 */142 Value get(ExecState *exec, const Identifier &propertyName) const;143 Value get(ExecState *exec, unsigned propertyName) const;144 145 /**146 * Sets the specified property.147 *148 * See ECMA 8.6.2.2149 *150 * @param exec The current execution state151 * @param propertyName The name of the property to set152 * @param propertyValue The value to set153 */154 void put(ExecState *exec, const Identifier &propertyName,155 const Value &value, int attr = None);156 void put(ExecState *exec, unsigned propertyName,157 const Value &value, int attr = None);158 159 /**160 * Used to check whether or not a particular property is allowed to be set161 * on an object162 *163 * See ECMA 8.6.2.3164 *165 * @param exec The current execution state166 * @param propertyName The name of the property167 * @return true if the property can be set, otherwise false168 */169 bool canPut(ExecState *exec, const Identifier &propertyName) const;170 171 /**172 * Checks to see whether the object (or any object in it's prototype chain)173 * has a property with the specified name.174 *175 * See ECMA 8.6.2.4176 *177 * @param exec The current execution state178 * @param propertyName The name of the property to check for179 * @return true if the object has the property, otherwise false180 */181 bool hasProperty(ExecState *exec, const Identifier &propertyName) const;182 bool hasProperty(ExecState *exec, unsigned propertyName) const;183 184 /**185 * Checks to see whether the object has a property with the specified name.186 *187 * See ECMA 15.2.4.5188 *189 * @param exec The current execution state190 * @param propertyName The name of the property to check for191 * @return true if the object has the property, otherwise false192 */193 bool hasOwnProperty(ExecState *exec, const Identifier &propertyName) const;194 bool hasOwnProperty(ExecState *exec, unsigned propertyName) const;195 196 /**197 * Removes the specified property from the object.198 *199 * See ECMA 8.6.2.5200 *201 * @param exec The current execution state202 * @param propertyName The name of the property to delete203 * @return true if the property was successfully deleted or did not204 * exist on the object. false if deleting the specified property is not205 * allowed.206 */207 bool deleteProperty(ExecState *exec, const Identifier &propertyName);208 bool deleteProperty(ExecState *exec, unsigned propertyName);209 210 /**211 * Converts the object into a primitive value. The value return may differ212 * depending on the supplied hint213 *214 * See ECMA 8.6.2.6215 *216 * @param exec The current execution state217 * @param hint The desired primitive type to convert to218 * @return A primitive value converted from the objetc. Note that the219 * type of primitive value returned may not be the same as the requested220 * hint.221 */222 Value defaultValue(ExecState *exec, Type hint) const;223 224 /**225 * Whether or not the object implements the construct() method. If this226 * returns false you should not call the construct() method on this227 * object (typically, an assertion will fail to indicate this).228 *229 * @return true if this object implements the construct() method, otherwise230 * false231 */232 bool implementsConstruct() const;233 234 /**235 * Creates a new object based on this object. Typically this means the236 * following:237 * 1. A new object is created238 * 2. The prototype of the new object is set to the value of this object's239 * "prototype" property240 * 3. The call() method of this object is called, with the new object241 * passed as the this value242 * 4. The new object is returned243 *244 * In some cases, Host objects may differ from these semantics, although245 * this is discouraged.246 *247 * If an error occurs during construction, the execution state's exception248 * will be set. This can be tested for with ExecState::hadException().249 * Under some circumstances, the exception object may also be returned.250 *251 * Note: This function should not be called if implementsConstruct() returns252 * false, in which case it will result in an assertion failure.253 *254 * @param exec The current execution state255 * @param args The arguments to be passed to call() once the new object has256 * been created257 * @return The newly created & initialized object258 */259 Object construct(ExecState *exec, const List &args);260 Object construct(ExecState *exec, const List &args, const UString &sourceURL, int lineNumber);261 262 /**263 * Whether or not the object implements the call() method. If this returns264 * false you should not call the call() method on this object (typically,265 * an assertion will fail to indicate this).266 *267 * @return true if this object implements the call() method, otherwise268 * false269 */270 bool implementsCall() const;271 272 273 /**274 * Calls this object as if it is a function.275 *276 * Note: This function should not be called if implementsCall() returns277 * false, in which case it will result in an assertion failure.278 *279 * See ECMA 8.6.2.3280 *281 * @param exec The current execution state282 * @param thisObj The obj to be used as "this" within function execution.283 * Note that in most cases this will be different from the C++ "this"284 * object. For example, if the ECMAScript code "window.location.toString()"285 * is executed, call() will be invoked on the C++ object which implements286 * the toString method, with the thisObj being window.location287 * @param args List of arguments to be passed to the function288 * @return The return value from the function289 */290 Value call(ExecState *exec, Object &thisObj, const List &args);291 292 /**293 * Whether or not the object implements the hasInstance() method. If this294 * returns false you should not call the hasInstance() method on this295 * object (typically, an assertion will fail to indicate this).296 *297 * @return true if this object implements the hasInstance() method,298 * otherwise false299 */300 bool implementsHasInstance() const;301 302 /**303 * Checks whether value delegates behavior to this object. Used by the304 * instanceof operator.305 *306 * @param exec The current execution state307 * @param value The value to check308 * @return true if value delegates behavior to this object, otherwise309 * false310 */311 Boolean hasInstance(ExecState *exec, const Value &value);312 313 /**314 * Returns the scope of this object. This is used when execution declared315 * functions - the execution context for the function is initialized with316 * extra object in it's scope. An example of this is functions declared317 * inside other functions:318 *319 * \code320 * function f() {321 *322 * function b() {323 * return prototype;324 * }325 *326 * var x = 4;327 * // do some stuff328 * }329 * f.prototype = new String();330 * \endcode331 *332 * When the function f.b is executed, its scope will include properties of333 * f. So in the example above the return value of f.b() would be the new334 * String object that was assigned to f.prototype.335 *336 * @param exec The current execution state337 * @return The function's scope338 */339 const ScopeChain &scope() const;340 void setScope(const ScopeChain &s);341 342 /**343 * Returns a List of References to all the properties of the object. Used344 * in "for x in y" statements. The list is created new, so it can be freely345 * modified without affecting the object's properties. It should be deleted346 * by the caller.347 *348 * Subclasses can override this method in ObjectImpl to provide the349 * appearance of350 * having extra properties other than those set specifically with put().351 *352 * @param exec The current execution state353 * @param recursive Whether or not properties in the object's prototype354 * chain should be355 * included in the list.356 * @return A List of References to properties of the object.357 **/358 ReferenceList propList(ExecState *exec, bool recursive = true);359 360 /**361 * Returns the internal value of the object. This is used for objects such362 * as String and Boolean which are wrappers for native types. The interal363 * value is the actual value represented by the wrapper objects.364 *365 * @see ECMA 8.6.2366 * @return The internal value of the object367 */368 Value internalValue() const;369 370 /**371 * Sets the internal value of the object372 *373 * @see internalValue()374 *375 * @param v The new internal value376 */377 void setInternalValue(const Value &v);378 379 void saveProperties(SavedProperties &p) const;380 void restoreProperties(const SavedProperties &p);381 };382 383 77 inline Object Value::toObject(ExecState *exec) const { return rep->dispatchToObject(exec); } 384 78 … … 510 204 bool getProperty(ExecState *exec, unsigned propertyName, Value& result) const; 511 205 512 virtual bool getOwnProperty(ExecState *exec, const Identifier& propertyName, Value& result) const; 513 virtual bool getOwnProperty(ExecState *exec, unsigned propertyName, Value& result) const; 206 bool getPropertySlot(ExecState *, const Identifier&, PropertySlot&); 207 bool getPropertySlot(ExecState *, unsigned, PropertySlot&); 208 virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); 209 virtual bool getOwnPropertySlot(ExecState *, unsigned index, PropertySlot&); 514 210 515 211 /** … … 538 234 * @see Object::hasProperty() 539 235 */ 540 bool hasProperty(ExecState *exec, 541 const Identifier &propertyName) const; 236 bool hasProperty(ExecState *exec, const Identifier &propertyName) const; 542 237 bool hasProperty(ExecState *exec, unsigned propertyName) const; 543 238 544 virtual bool hasOwnProperty(ExecState *exec, 545 const Identifier &propertyName) const; 546 virtual bool hasOwnProperty(ExecState *exec, unsigned propertyName) const; 239 virtual bool hasOwnProperty(ExecState *exec, const Identifier &propertyName) const; 547 240 548 241 /** … … 624 317 ValueImp *getDirect(const Identifier& propertyName) const 625 318 { return _prop.get(propertyName); } 319 ValueImp **getDirectLocation(const Identifier& propertyName) 320 { return _prop.getLocation(propertyName); } 626 321 void putDirect(const Identifier &propertyName, ValueImp *value, int attr = 0); 627 322 void putDirect(const Identifier &propertyName, int value, int attr = 0); … … 639 334 }; 640 335 641 642 336 // it may seem crazy to inline a function this large but it makes a big difference 643 337 // since this is function very hot in variable lookup 644 inline bool ObjectImp::getProperty (ExecState *exec, const Identifier& propertyName, Value& result) const338 inline bool ObjectImp::getPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot) 645 339 { 646 constObjectImp *imp = this;340 ObjectImp *imp = this; 647 341 648 342 while (true) { 649 if (imp->getOwnProperty (exec, propertyName, result))343 if (imp->getOwnPropertySlot(exec, propertyName, slot)) 650 344 return true; 651 345 652 constValueImp *proto = imp->_proto;346 ValueImp *proto = imp->_proto; 653 347 if (proto->dispatchType() != ObjectType) 654 348 break; 655 349 656 imp = static_cast< constObjectImp *>(proto);350 imp = static_cast<ObjectImp *>(proto); 657 351 } 658 352 … … 663 357 // but it makes a big difference to property lookup if subclasses can inline their 664 358 // superclass call to this 665 inline bool ObjectImp::getOwnProperty (ExecState *exec, const Identifier &propertyName, Value &result) const359 inline bool ObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot) 666 360 { 667 ValueImp * imp = getDirect(propertyName);668 if (imp ) {669 result = Value(imp);361 ValueImp **impLocation = getDirectLocation(propertyName); 362 if (impLocation) { 363 slot.setValueSlot(this, impLocation); 670 364 return true; 671 365 } 672 366 673 367 // non-standard netscape extension 674 if (propertyName == specialPrototypePropertyName) {675 result = Value(_proto);368 if (propertyName == exec->dynamicInterpreter()->specialPrototypeIdentifier()) { 369 slot.setValueSlot(this, &_proto); 676 370 return true; 677 371 } … … 760 454 { return imp()->hasProperty(exec, propertyName); } 761 455 762 inline bool Object::hasProperty(ExecState *exec, unsigned propertyName) const763 { return imp()->hasProperty(exec, propertyName); }764 765 456 inline bool Object::hasOwnProperty(ExecState *exec, const Identifier &propertyName) const 766 { return imp()->hasOwnProperty(exec, propertyName); }767 768 inline bool Object::hasOwnProperty(ExecState *exec, unsigned propertyName) const769 457 { return imp()->hasOwnProperty(exec, propertyName); } 770 458
Note:
See TracChangeset
for help on using the changeset viewer.