Changeset 10728 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Oct 4, 2005, 2:33:33 AM (20 years ago)
Author:
eseidel
Message:

Bug #: none
Submitted by: eseidel
Reviewed by: mjs

Code cleanup, which resulted in a small win on iBench.

  • kjs/object.cpp: (KJS::tryGetAndCallProperty): new static inline (KJS::ObjectImp::defaultValue): code cleanup
File:
1 edited

Legend:

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

    r10701 r10728  
    278278}
    279279
    280 // ECMA 8.6.2.6
    281 ValueImp *ObjectImp::defaultValue(ExecState *exec, Type hint) const
    282 {
    283   if (hint != StringType && hint != NumberType) {
    284     /* Prefer String for Date objects */
    285     if (_proto == exec->lexicalInterpreter()->builtinDatePrototype())
    286       hint = StringType;
    287     else
    288       hint = NumberType;
    289   }
    290 
    291   ValueImp *v;
    292   if (hint == StringType)
    293     v = get(exec,toStringPropertyName);
    294   else
    295     v = get(exec,valueOfPropertyName);
    296 
     280static inline
     281#ifdef __GNUC__
     282__attribute__((always_inline))
     283#endif
     284ValueImp *tryGetAndCallProperty(ExecState *exec, const ObjectImp *object, const Identifier &propertyName) {
     285  ValueImp *v = object->get(exec, propertyName);
    297286  if (v->isObject()) {
    298287    ObjectImp *o = static_cast<ObjectImp*>(v);
    299288    if (o->implementsCall()) { // spec says "not primitive type" but ...
    300       ObjectImp *thisObj = const_cast<ObjectImp*>(this);
    301       ValueImp *def = o->call(exec,thisObj,List::empty());
     289      ObjectImp *thisObj = const_cast<ObjectImp*>(object);
     290      ValueImp *def = o->call(exec, thisObj, List::empty());
    302291      Type defType = def->type();
    303292      if (defType == UnspecifiedType || defType == UndefinedType ||
     
    308297    }
    309298  }
    310 
    311   if (hint == StringType)
    312     v = get(exec,valueOfPropertyName);
    313   else
    314     v = get(exec,toStringPropertyName);
    315 
    316   if (v->isObject()) {
    317     ObjectImp *o = static_cast<ObjectImp*>(v);
    318     if (o->implementsCall()) { // spec says "not primitive type" but ...
    319       ObjectImp *thisObj = const_cast<ObjectImp*>(this);
    320       ValueImp *def = o->call(exec,thisObj,List::empty());
    321       Type defType = def->type();
    322       if (defType == UnspecifiedType || defType == UndefinedType ||
    323           defType == NullType || defType == BooleanType ||
    324           defType == StringType || defType == NumberType) {
    325         return def;
    326       }
    327     }
    328   }
     299  return NULL;
     300}
     301
     302// ECMA 8.6.2.6
     303ValueImp *ObjectImp::defaultValue(ExecState *exec, Type hint) const
     304{
     305  Identifier firstPropertyName;
     306  Identifier secondPropertyName;
     307  /* Prefer String for Date objects */
     308  if ((hint == StringType) || (hint != StringType) && (hint != NumberType) && (_proto == exec->lexicalInterpreter()->builtinDatePrototype())) {
     309    firstPropertyName = toStringPropertyName;
     310    secondPropertyName = valueOfPropertyName;
     311  } else {
     312    firstPropertyName = valueOfPropertyName;
     313    secondPropertyName = toStringPropertyName;
     314  }
     315
     316  ValueImp *v;
     317  if ((v = tryGetAndCallProperty(exec, this, firstPropertyName)))
     318    return v;
     319  if ((v = tryGetAndCallProperty(exec, this, secondPropertyName)))
     320    return v;
    329321
    330322  if (exec->hadException())
Note: See TracChangeset for help on using the changeset viewer.