[webkit-changes] cvs commit: JavaScriptCore/kjs object.cpp object.h object_object.cpp object_object.h

Anders andersca at opensource.apple.com
Sun Dec 4 15:28:58 PST 2005


andersca    05/12/04 15:28:57

  Modified:    .        ChangeLog
               kjs      object.cpp object.h object_object.cpp
                        object_object.h
  Log:
  2005-12-04  Anders Carlsson  <andersca at mac.com>
  
          Reviewed by Geoffrey.
  
          - Fixes <http://bugzilla.opendarwin.org/show_bug.cgi?id=3999>
  
          * kjs/object.cpp:
          (KJS::ObjectImp::canPut):
          Refactor to use getPropertyAttributes.
  
          (KJS::ObjectImp::propertyIsEnumerable):
          New function which checks if a property is enumerable.
  
          (KJS::ObjectImp::getPropertyAttributes):
          * kjs/object.h:
          Add getPropertyAttributes and propertyIsEnumerable.
  
          * kjs/object_object.cpp:
          (ObjectPrototypeImp::ObjectPrototypeImp):
          (ObjectProtoFuncImp::callAsFunction):
          * kjs/object_object.h:
          (KJS::ObjectProtoFuncImp::):
          Add propertyIsEnumerable to the Object prototype.
  
  Revision  Changes    Path
  1.891     +24 -0     JavaScriptCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
  retrieving revision 1.890
  retrieving revision 1.891
  diff -u -r1.890 -r1.891
  --- ChangeLog	2 Dec 2005 03:47:59 -0000	1.890
  +++ ChangeLog	4 Dec 2005 23:28:54 -0000	1.891
  @@ -1,3 +1,27 @@
  +2005-12-04  Anders Carlsson  <andersca at mac.com>
  +
  +        Reviewed by Geoffrey.
  +
  +        - Fixes <http://bugzilla.opendarwin.org/show_bug.cgi?id=3999>
  +
  +        * kjs/object.cpp:
  +        (KJS::ObjectImp::canPut):
  +        Refactor to use getPropertyAttributes.
  +
  +        (KJS::ObjectImp::propertyIsEnumerable):
  +        New function which checks if a property is enumerable.
  +
  +        (KJS::ObjectImp::getPropertyAttributes):
  +        * kjs/object.h:
  +        Add getPropertyAttributes and propertyIsEnumerable.
  +
  +        * kjs/object_object.cpp:
  +        (ObjectPrototypeImp::ObjectPrototypeImp):
  +        (ObjectProtoFuncImp::callAsFunction):
  +        * kjs/object_object.h:
  +        (KJS::ObjectProtoFuncImp::):
  +        Add propertyIsEnumerable to the Object prototype.
  +
   2005-12-01  Maciej Stachowiak  <mjs at apple.com>
   
           Reviewed by Tim Hatcher.
  
  
  
  1.56      +31 -10    JavaScriptCore/kjs/object.cpp
  
  Index: object.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/object.cpp,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- object.cpp	16 Oct 2005 00:46:22 -0000	1.55
  +++ object.cpp	4 Dec 2005 23:28:56 -0000	1.56
  @@ -226,18 +226,14 @@
   bool ObjectImp::canPut(ExecState *, const Identifier &propertyName) const
   {
     int attributes;
  -  ValueImp *v = _prop.get(propertyName, attributes);
  -  if (v)
  -    return!(attributes & ReadOnly);
  -
  -  // Look in the static hashtable of properties
  -  const HashEntry* e = findPropertyHashEntry(propertyName);
  -  if (e)
  -    return !(e->attr & ReadOnly);
  -
  +    
     // Don't look in the prototype here. We can always put an override
     // in the object, even if the prototype has a ReadOnly property.
  -  return true;
  +
  +  if (!getPropertyAttributes(propertyName, attributes))
  +    return true;
  +  else
  +    return !(attributes & ReadOnly);
   }
   
   // ECMA 8.6.2.4
  @@ -374,6 +370,31 @@
     return false;
   }
   
  +bool ObjectImp::propertyIsEnumerable(ExecState *exec, const Identifier &propertyName) const
  +{
  +  int attributes;
  + 
  +  if (!getPropertyAttributes(propertyName, attributes))
  +    return false;
  +  else
  +    return !(attributes & DontEnum);
  +}
  +
  +bool ObjectImp::getPropertyAttributes(const Identifier& propertyName, int& attributes) const
  +{
  +  if (_prop.get(propertyName, attributes))
  +    return true;
  +    
  +  // Look in the static hashtable of properties
  +  const HashEntry* e = findPropertyHashEntry(propertyName);
  +  if (e) {
  +    attributes = e->attr;
  +    return true;
  +  }
  +    
  +  return false;
  +}
  +
   ReferenceList ObjectImp::propList(ExecState *exec, bool recursive)
   {
     ReferenceList list;
  
  
  
  1.49      +13 -0     JavaScriptCore/kjs/object.h
  
  Index: object.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/object.h,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- object.h	27 Nov 2005 01:28:30 -0000	1.48
  +++ object.h	4 Dec 2005 23:28:56 -0000	1.49
  @@ -246,6 +246,17 @@
       virtual bool canPut(ExecState *exec, const Identifier &propertyName) const;
   
       /**
  +     * Checks if a property is enumerable, that is if it doesn't have the DontEnum
  +     * flag set
  +     *
  +     * See ECMA 15.2.4
  +     * @param exec The current execution state
  +     * @param propertyName The name of the property
  +     * @return true if the property is enumerable, otherwise false
  +     */
  +    bool propertyIsEnumerable(ExecState *exec, const Identifier &propertyName) const;
  +
  +    /**
        * Checks to see whether the object (or any object in it's prototype chain)
        * has a property with the specified name.
        *
  @@ -454,6 +465,8 @@
       UString toString(ExecState *exec) const;
       ObjectImp *toObject(ExecState *exec) const;
   
  +    bool getPropertyAttributes(const Identifier& propertyName, int& attributes) const;
  +    
       // This get function only looks at the property map.
       // This is used e.g. by lookupOrCreateFunction (to cache a function, we don't want
       // to look up in the prototype, it might already exist there)
  
  
  
  1.16      +8 -5      JavaScriptCore/kjs/object_object.cpp
  
  Index: object_object.cpp
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/object_object.cpp,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- object_object.cpp	3 Oct 2005 21:11:50 -0000	1.15
  +++ object_object.cpp	4 Dec 2005 23:28:56 -0000	1.16
  @@ -38,10 +38,11 @@
                                          FunctionPrototypeImp *funcProto)
     : ObjectImp() // [[Prototype]] is Null()
   {
  -    putDirect(toStringPropertyName, new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ToString,            0), DontEnum);
  -    putDirect(toLocaleStringPropertyName, new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ToLocaleString,0), DontEnum);
  -    putDirect(valueOfPropertyName,  new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::ValueOf,             0), DontEnum);
  -    putDirect("hasOwnProperty", new ObjectProtoFuncImp(exec,funcProto,ObjectProtoFuncImp::HasOwnProperty,          1), DontEnum);
  +    putDirect(toStringPropertyName, new ObjectProtoFuncImp(exec, funcProto, ObjectProtoFuncImp::ToString,               0), DontEnum);
  +    putDirect(toLocaleStringPropertyName, new ObjectProtoFuncImp(exec, funcProto, ObjectProtoFuncImp::ToLocaleString,   0), DontEnum);
  +    putDirect(valueOfPropertyName, new ObjectProtoFuncImp(exec, funcProto, ObjectProtoFuncImp::ValueOf,                 0), DontEnum);
  +    putDirect("hasOwnProperty", new ObjectProtoFuncImp(exec, funcProto, ObjectProtoFuncImp::HasOwnProperty,             1), DontEnum);
  +    putDirect("propertyIsEnumerable", new ObjectProtoFuncImp(exec, funcProto, ObjectProtoFuncImp::PropertyIsEnumerable, 1), DontEnum);
   }
   
   
  @@ -61,7 +62,7 @@
     return true;
   }
   
  -// ECMA 15.2.4.2, 15.2.4.4, 15.2.4.5
  +// ECMA 15.2.4.2, 15.2.4.4, 15.2.4.5, 15.2.4.7
   
   ValueImp *ObjectProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args)
   {
  @@ -72,6 +73,8 @@
               PropertySlot slot;
               return jsBoolean(thisObj->getOwnPropertySlot(exec, Identifier(args[0]->toString(exec)), slot));
           }
  +        case PropertyIsEnumerable:
  +            return jsBoolean(thisObj->propertyIsEnumerable(exec, Identifier(args[0]->toString(exec))));
           case ToLocaleString:
               return jsString(thisObj->toString(exec));
           case ToString:
  
  
  
  1.10      +1 -1      JavaScriptCore/kjs/object_object.h
  
  Index: object_object.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/kjs/object_object.h,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- object_object.h	8 Aug 2005 04:07:29 -0000	1.9
  +++ object_object.h	4 Dec 2005 23:28:56 -0000	1.10
  @@ -52,7 +52,7 @@
       virtual bool implementsCall() const;
       virtual ValueImp *callAsFunction(ExecState *, ObjectImp *, const List &args);
   
  -    enum { ToString, ToLocaleString, ValueOf, HasOwnProperty };
  +    enum { ToString, ToLocaleString, ValueOf, HasOwnProperty, PropertyIsEnumerable };
     private:
       int id;
     };
  
  
  



More information about the webkit-changes mailing list