Changeset 35807 in webkit for trunk/JavaScriptCore/kjs/JSObject.h


Ignore:
Timestamp:
Aug 17, 2008, 1:23:49 PM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2008-08-17 Geoffrey Garen <[email protected]>

Reviewed by Cameron Zwarich.

Made room for a free word in JSCell.


SunSpider says no change.


I changed JSCallbackObjectData, Arguments, JSArray, and RegExpObject to
store auxiliary data in a secondary structure.

I changed InternalFunction to store the function's name in the property
map.


I changed JSGlobalObjectData to use a virtual destructor, so WebCore's
JSDOMWindowBaseData could inherit from it safely. (It's a strange design
for JSDOMWindowBase to allocate an object that JSGlobalObject deletes,
but that's really our only option, given the size constraint.)


I also added a bunch of compile-time ASSERTs, and removed lots of comments
in JSObject.h because they were often out of date, and they got in the
way of reading what was actually going on.


Also renamed JSArray::getLength to JSArray::length, to match our style
guidelines.

WebCore:

2008-08-17 Geoffrey Garen <[email protected]>

Reviewed by Cameron Zwarich.

Made room for a free word in JSCell.


Changed JSDOMWindowBase to store its auxiliary data in a subclass of
JSGlobalData, so the two could share a pointer.


Added a bunch of ASSERTs, to help catch over-sized objects.

WebKit/mac:

2008-08-17 Geoffrey Garen <[email protected]>

Reviewed by Cameron Zwarich.

Made room for a free word in JSCell.


(Updated for JavaScriptCore changes.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/JSObject.h

    r35657 r35807  
    7070        virtual JSType type() const;
    7171
    72         /**
    73          * A pointer to a ClassInfo struct for this class. This provides a basic
    74          * facility for run-time type information, and can be used to check an
    75          * object's class an inheritance (see inherits()). This should
    76          * always return a statically declared pointer, or 0 to indicate that
    77          * there is no class information.
    78          *
    79          * This is primarily useful if you have application-defined classes that you
    80          * wish to check against for casting purposes.
    81          *
    82          * For example, to specify the class info for classes FooImp and BarImp,
    83          * where FooImp inherits from BarImp, you would add the following in your
    84          * class declarations:
    85          *
    86          * \code
    87          *   class BarImp : public JSObject {
    88          *     virtual const ClassInfo *classInfo() const { return &info; }
    89          *     static const ClassInfo info;
    90          *     // ...
    91          *   };
    92          *
    93          *   class FooImp : public JSObject {
    94          *     virtual const ClassInfo *classInfo() const { return &info; }
    95          *     static const ClassInfo info;
    96          *     // ...
    97          *   };
    98          * \endcode
    99          *
    100          * And in your source file:
    101          *
    102          * \code
    103          *   const ClassInfo BarImp::info = { "Bar", 0, 0, 0 }; // no parent class
    104          *   const ClassInfo FooImp::info = { "Foo", &BarImp::info, 0, 0 };
    105          * \endcode
    106          *
    107          * @see inherits()
    108          */
    109 
    110         /**
    111          * Checks whether this object inherits from the class with the specified
    112          * classInfo() pointer. This requires that both this class and the other
    113          * class return a non-NULL pointer for their classInfo() methods (otherwise
    114          * it will return false).
    115          *
    116          * For example, for two JSObject pointers obj1 and obj2, you can check
    117          * if obj1's class inherits from obj2's class using the following:
    118          *
    119          *   if (obj1->inherits(obj2->classInfo())) {
    120          *     // ...
    121          *   }
    122          *
    123          * If you have a handle to a statically declared ClassInfo, such as in the
    124          * classInfo() example, you can check for inheritance without needing
    125          * an instance of the other class:
    126          *
    127          *   if (obj1->inherits(FooImp::info)) {
    128          *     // ...
    129          *   }
    130          *
    131          * @param cinfo The ClassInfo pointer for the class you want to check
    132          * inheritance against.
    133          * @return true if this object's class inherits from class with the
    134          * ClassInfo pointer specified in cinfo
    135          */
    13672        bool inherits(const ClassInfo* classInfo) const { return isObject(classInfo); } // FIXME: Merge with isObject.
    13773
    138         // internal properties (ECMA 262-3 8.6.2)
    139 
    140         /**
    141          * Returns the prototype of this object. Note that this is not the same as
    142          * the "prototype" property.
    143          *
    144          * See ECMA 8.6.2
    145          *
    146          * @return The object's prototype
    147          */
    14874        JSValue* prototype() const;
    14975        void setPrototype(JSValue* prototype);
    15076
    151         /**
    152          * Returns the class name of the object
    153          *
    154          * See ECMA 8.6.2
    155          *
    156          * @return The object's class name
    157          */
    158         /**
    159          * Implementation of the [[Class]] internal property (implemented by all
    160          * Objects)
    161          *
    162          * The default implementation uses classInfo().
    163          * You should either implement classInfo(), or
    164          * if you simply need a classname, you can reimplement className()
    165          * instead.
    166          */
    16777        virtual UString className() const;
    16878
    169         /**
    170          * Retrieves the specified property from the object. If neither the object
    171          * or any other object in its prototype chain have the property, this
    172          * function will return Undefined.
    173          *
    174          * See ECMA 8.6.2.1
    175          *
    176          * @param exec The current execution state
    177          * @param propertyName The name of the property to retrieve
    178          *
    179          * @return The specified property, or Undefined
    180          */
    18179        JSValue* get(ExecState*, const Identifier& propertyName) const;
    18280        JSValue* get(ExecState*, unsigned propertyName) const;
     
    18886        virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
    18987
    190         /**
    191          * Sets the specified property.
    192          *
    193          * See ECMA 8.6.2.2
    194          *
    195          * @param exec The current execution state
    196          * @param propertyName The name of the property to set
    197          * @param propertyValue The value to set
    198          */
    19988        virtual void put(ExecState*, const Identifier& propertyName, JSValue* value);
    20089        virtual void put(ExecState*, unsigned propertyName, JSValue* value);
     
    20392        virtual void putWithAttributes(ExecState*, unsigned propertyName, JSValue* value, unsigned attributes);
    20493
    205         /**
    206          * Checks if a property is enumerable, that is if it doesn't have the DontEnum
    207          * flag set
    208          *
    209          * See ECMA 15.2.4
    210          * @param exec The current execution state
    211          * @param propertyName The name of the property
    212          * @return true if the property is enumerable, otherwise false
    213          */
    21494        bool propertyIsEnumerable(ExecState*, const Identifier& propertyName) const;
    21595
    216         /**
    217          * Checks to see whether the object (or any object in its prototype chain)
    218          * has a property with the specified name.
    219          *
    220          * See ECMA 8.6.2.4
    221          *
    222          * @param exec The current execution state
    223          * @param propertyName The name of the property to check for
    224          * @return true if the object has the property, otherwise false
    225          */
    22696        bool hasProperty(ExecState*, const Identifier& propertyName) const;
    22797        bool hasProperty(ExecState*, unsigned propertyName) const;
    22898        bool hasOwnProperty(ExecState*, const Identifier& propertyName) const;
    22999
    230         /**
    231          * Removes the specified property from the object.
    232          *
    233          * See ECMA 8.6.2.5
    234          *
    235          * @param exec The current execution state
    236          * @param propertyName The name of the property to delete
    237          * @return true if the property was successfully deleted or did not
    238          * exist on the object. false if deleting the specified property is not
    239          * allowed.
    240          */
    241100        virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
    242101        virtual bool deleteProperty(ExecState*, unsigned propertyName);
    243102
    244         /**
    245          * Converts the object into a primitive value. The value return may differ
    246          * depending on the supplied hint
    247          *
    248          * See ECMA 8.6.2.6
    249          *
    250          * @param exec The current execution state
    251          * @param hint The desired primitive type to convert to
    252          * @return A primitive value converted from the objetc. Note that the
    253          * type of primitive value returned may not be the same as the requested
    254          * hint.
    255          */
    256         /**
    257          * Implementation of the [[DefaultValue]] internal property (implemented by
    258          * all Objects)
    259          */
    260103        virtual JSValue* defaultValue(ExecState*, JSType hint) const;
    261104
    262         /**
    263          * Whether or not the object implements the hasInstance() method. If this
    264          * returns false you should not call the hasInstance() method on this
    265          * object (typically, an assertion will fail to indicate this).
    266          *
    267          * @return true if this object implements the hasInstance() method,
    268          * otherwise false
    269          */
    270105        virtual bool implementsHasInstance() const;
    271 
    272         /**
    273          * Checks whether value delegates behavior to this object. Used by the
    274          * instanceof operator.
    275          *
    276          * @param exec The current execution state
    277          * @param value The value to check
    278          * @return true if value delegates behavior to this object, otherwise
    279          * false
    280          */
    281106        virtual bool hasInstance(ExecState*, JSValue*);
    282107
     
    299124
    300125        // This get function only looks at the property map.
    301         // This is used e.g. by lookupOrCreateFunction (to cache a function, we don't want
    302         // to look up in the prototype, it might already exist there)
    303126        JSValue* getDirect(const Identifier& propertyName) const { return m_propertyMap.get(propertyName); }
    304127        JSValue** getDirectLocation(const Identifier& propertyName) { return m_propertyMap.getLocation(propertyName); }
     
    310133
    311134        // convenience to add a function property under the function's own built-in name
    312         void putDirectFunction(InternalFunction*, unsigned attr = 0);
     135        void putDirectFunction(ExecState*, InternalFunction*, unsigned attr = 0);
    313136
    314137        void fillGetterPropertySlot(PropertySlot&, JSValue** location);
Note: See TracChangeset for help on using the changeset viewer.