Changeset 33979 in webkit for trunk/JavaScriptCore/kjs/object.h


Ignore:
Timestamp:
May 21, 2008, 6:20:45 PM (17 years ago)
Author:
[email protected]
Message:

Merge squirrelfish branch into trunk.

File:
1 edited

Legend:

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

    r33038 r33979  
    235235     * @return The specified property, or Undefined
    236236     */
    237     JSValue *get(ExecState *exec, const Identifier &propertyName) const;
    238     JSValue *get(ExecState *exec, unsigned propertyName) const;
    239 
    240     bool getPropertySlot(ExecState *, const Identifier&, PropertySlot&);
    241     bool getPropertySlot(ExecState *, unsigned, PropertySlot&);
    242 
    243     virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
    244     virtual bool getOwnPropertySlot(ExecState *, unsigned index, PropertySlot&);
     237    JSValue* get(ExecState* exec, const Identifier& propertyName) const;
     238    JSValue* get(ExecState* exec, unsigned propertyName) const;
     239
     240    bool getPropertySlot(ExecState*, const Identifier&, PropertySlot&);
     241    bool getPropertySlot(ExecState*, unsigned, PropertySlot&);
     242
     243    virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
     244    virtual bool getOwnPropertySlot(ExecState*, unsigned index, PropertySlot&);
    245245
    246246    /**
     
    315315     */
    316316    virtual JSValue *defaultValue(ExecState *exec, JSType hint) const;
    317 
    318     /**
    319      * Whether or not the object implements the construct() method. If this
    320      * returns false you should not call the construct() method on this
    321      * object (typically, an assertion will fail to indicate this).
    322      *
    323      * @return true if this object implements the construct() method, otherwise
    324      * false
    325      */
    326     virtual bool implementsConstruct() const;
    327317
    328318    /**
     
    343333     * Under some circumstances, the exception object may also be returned.
    344334     *
    345      * Note: This function should not be called if implementsConstruct() returns
    346      * false, in which case it will result in an assertion failure.
     335     * Note: This function should not be called if getConstructData() returns
     336     * ConstructTypeNone, in which case it will result in an assertion failure.
    347337     *
    348338     * @param exec The current execution state
     
    356346    virtual JSObject* construct(ExecState* exec, const List& args);
    357347    virtual JSObject* construct(ExecState* exec, const List& args, const Identifier& functionName, const UString& sourceURL, int lineNumber);
    358 
    359     /**
    360      * Whether or not the object implements the call() method. If this returns
    361      * false you should not call the call() method on this object (typically,
    362      * an assertion will fail to indicate this).
    363      *
    364      * @return true if this object implements the call() method, otherwise
    365      * false
    366      */
    367     virtual bool implementsCall() const;
    368348
    369349    /**
     
    384364     * @return The return value from the function
    385365     */
     366    bool implementsCall();
    386367    JSValue *call(ExecState *exec, JSObject *thisObj, const List &args);
     368
    387369    virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
    388370
     
    432414    JSValue **getDirectLocation(const Identifier& propertyName)
    433415        { return _prop.getLocation(propertyName); }
     416   JSValue **getDirectLocation(const Identifier& propertyName, bool& isWriteable)
     417        { return _prop.getLocation(propertyName, isWriteable); }
    434418    void putDirect(const Identifier &propertyName, JSValue *value, int attr = 0);
    435419    void putDirect(const Identifier &propertyName, int value, int attr = 0);
     
    452436  protected:
    453437    PropertyMap _prop;
     438    bool getOwnPropertySlotForWrite(ExecState*, const Identifier&, PropertySlot&, bool& slotIsWriteable);
    454439
    455440  private:
     
    541526}
    542527
     528inline JSValue *JSObject::get(ExecState *exec, const Identifier &propertyName) const
     529{
     530  PropertySlot slot;
     531
     532  if (const_cast<JSObject *>(this)->getPropertySlot(exec, propertyName, slot))
     533    return slot.getValue(exec, const_cast<JSObject *>(this), propertyName);
     534   
     535  return jsUndefined();
     536}
     537
     538inline JSValue *JSObject::get(ExecState *exec, unsigned propertyName) const
     539{
     540  PropertySlot slot;
     541  if (const_cast<JSObject *>(this)->getPropertySlot(exec, propertyName, slot))
     542    return slot.getValue(exec, const_cast<JSObject *>(this), propertyName);
     543   
     544  return jsUndefined();
     545}
     546
    543547// It may seem crazy to inline a function this large but it makes a big difference
    544548// since this is function very hot in variable lookup
     
    556560        object = static_cast<JSObject *>(proto);
    557561    }
     562}
     563
     564inline bool JSObject::getPropertySlot(ExecState *exec, unsigned propertyName, PropertySlot& slot)
     565{
     566  JSObject *imp = this;
     567 
     568  while (true) {
     569    if (imp->getOwnPropertySlot(exec, propertyName, slot))
     570      return true;
     571   
     572    JSValue *proto = imp->_proto;
     573    if (!proto->isObject())
     574      break;
     575   
     576    imp = static_cast<JSObject *>(proto);
     577  }
     578 
     579  return false;
     580}
     581
     582// It may seem crazy to inline a function this large, especially a virtual function,
     583// but it makes a big difference to property lookup that derived classes can inline their
     584// base class call to this.
     585ALWAYS_INLINE bool JSObject::getOwnPropertySlotForWrite(ExecState* exec, const Identifier& propertyName, PropertySlot& slot, bool& slotIsWriteable)
     586{
     587    if (JSValue **location = getDirectLocation(propertyName, slotIsWriteable)) {
     588        if (_prop.hasGetterSetterProperties() && location[0]->type() == GetterSetterType) {
     589            slotIsWriteable = false;
     590            fillGetterPropertySlot(slot, location);
     591        } else
     592            slot.setValueSlot(this, location);
     593        return true;
     594    }
     595
     596    // non-standard Netscape extension
     597    if (propertyName == exec->propertyNames().underscoreProto) {
     598        slot.setValueSlot(this, &_proto);
     599        slotIsWriteable = true;
     600        return true;
     601    }
     602
     603    return false;
    558604}
    559605
     
    580626}
    581627
    582 inline void ScopeChain::release()
    583 {
    584     // This function is only called by deref(),
    585     // Deref ensures these conditions are true.
    586     ASSERT(_node && _node->refCount == 0);
    587     ScopeChainNode *n = _node;
    588     do {
    589         ScopeChainNode *next = n->next;
    590         delete n;
    591         n = next;
    592     } while (n && --n->refCount == 0);
     628inline void JSObject::putDirect(const Identifier &propertyName, JSValue *value, int attr)
     629{
     630    _prop.put(propertyName, value, attr);
     631}
     632
     633inline void JSObject::putDirect(const Identifier &propertyName, int value, int attr)
     634{
     635    _prop.put(propertyName, jsNumber(value), attr);
    593636}
    594637
Note: See TracChangeset for help on using the changeset viewer.