Changeset 11836 in webkit for trunk/JavaScriptCore/kjs/object.cpp


Ignore:
Timestamp:
Dec 30, 2005, 1:44:50 AM (19 years ago)
Author:
andersca
Message:

2005-12-30 Anders Carlsson <[email protected]>

Reviewed by Maciej.

  • kjs/object.cpp: (KJS::JSObject::put):

Rework the getter setter part. We now walk the prototype chain, checking for
getter/setter properties and only take the slow path if any are found.

File:
1 edited

Legend:

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

    r11774 r11836  
    219219  }
    220220
     221  // Check if there are any setters or getters in the prototype chain
    221222  JSObject *obj = this;
     223  bool hasGettersOrSetters = false;
    222224  while (true) {
    223     JSValue *gs;
    224     int attributes;
    225     if (obj->_prop.hasGetterSetterProperties() && (gs = obj->_prop.get(propertyName, attributes))) {
    226       if (attributes & GetterSetter) {
    227         JSObject *setterFunc = static_cast<GetterSetterImp *>(gs)->getSetter();
    228            
    229         if (!setterFunc) {
    230           throwSetterError(exec);
    231           return;
    232         }
    233            
    234         List args;
    235         args.append(value);
    236        
    237         setterFunc->call(exec, this, args);
    238         return;
    239       } else  {
    240         // If there's an existing property on the object or one of its
    241         // prototype it should be replaced, so we just break here.
    242         break;
    243       }
    244     }
    245      
     225    if (obj->_prop.hasGetterSetterProperties()) {
     226      hasGettersOrSetters = true;
     227      break;
     228    }
     229     
    246230    if (!obj->_proto->isObject())
    247231      break;
     232     
     233    obj = static_cast<JSObject *>(obj->_proto);
     234  }
     235 
     236  if (hasGettersOrSetters) {
     237    obj = this;
     238    while (true) {
     239      int attributes;
     240      if (JSValue *gs = obj->_prop.get(propertyName, attributes)) {
     241        if (attributes & GetterSetter) {
     242          JSObject *setterFunc = static_cast<GetterSetterImp *>(gs)->getSetter();
    248243       
    249     obj = static_cast<JSObject *>(obj->_proto);
    250   }
    251 
     244          if (!setterFunc) {
     245            throwSetterError(exec);
     246            return;
     247          }
     248           
     249          List args;
     250          args.append(value);
     251       
     252          setterFunc->call(exec, this, args);
     253          return;
     254        } else {
     255          // If there's an existing property on the object or one of its
     256          // prototype it should be replaced, so we just break here.
     257          break;
     258        }
     259      }
     260     
     261      if (!obj->_proto->isObject())
     262        break;
     263       
     264      obj = static_cast<JSObject *>(obj->_proto);
     265    }
     266  }
     267 
    252268  _prop.put(propertyName,value,attr);
    253269}
Note: See TracChangeset for help on using the changeset viewer.