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


Ignore:
Timestamp:
Dec 13, 2005, 1:24:53 PM (19 years ago)
Author:
andersca
Message:

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

Reviewed by Darin.

  • bindings/runtime_array.cpp: (RuntimeArray::lengthGetter): (RuntimeArray::indexGetter):
  • bindings/runtime_array.h:
  • bindings/runtime_method.cpp: (RuntimeMethod::lengthGetter):
  • bindings/runtime_method.h:
  • bindings/runtime_object.cpp: (RuntimeObjectImp::fallbackObjectGetter): (RuntimeObjectImp::fieldGetter): (RuntimeObjectImp::methodGetter):
  • bindings/runtime_object.h:
  • kjs/array_instance.h:
  • kjs/array_object.cpp: (ArrayInstance::lengthGetter): (getProperty): Update for changes to PropertySlot::getValue and PropertySlot::GetValueFunc.
  • kjs/collector.cpp: (KJS::className): Handle GetterSetterType.
  • kjs/function.cpp: (KJS::FunctionImp::argumentsGetter): (KJS::FunctionImp::lengthGetter): (KJS::Arguments::mappedIndexGetter): (KJS::ActivationImp::argumentsGetter):
  • kjs/function.h: Update for changes to PropertySlot::getValue and PropertySlot::GetValueFunc.
  • kjs/grammar.y: Rework grammar parts for get set declarations directly in the object literal.
  • kjs/internal.cpp: (KJS::GetterSetterImp::mark): (KJS::GetterSetterImp::toPrimitive): (KJS::GetterSetterImp::toBoolean): (KJS::GetterSetterImp::toNumber): (KJS::GetterSetterImp::toString): (KJS::GetterSetterImp::toObject): Add type conversion functions. These aren't meant to be called.

(KJS::printInfo):
Handle GetterSetterType.

  • kjs/lookup.h: (KJS::staticFunctionGetter): (KJS::staticValueGetter): Update for changes to PropertySlot::GetValueFunc.
  • kjs/nodes.cpp: Refactor they way properties nodes are implemented. We now have a PropertyListNode which is a list of PropertyNodes. Each PropertyNode has a name (which is a PropertyNameNode) and an associated value node. PropertyNodes can be of different types. The Constant type is the old constant declaration and the Getter and Setter types are for property getters and setters. (ResolveNode::evaluate): Update for changes to PropertySlot::getValue.

(PropertyListNode::evaluate):
Go through all property nodes and set them on the newly created object. If the
property nodes are of type Getter or Setter, define getters and setters. Otherwise,
just add the properties like before.

(PropertyNode::evaluate):
This should never be called directly.

(PropertyNameNode::evaluate):
Rename from PropertyNode::evaluate.

(FunctionCallResolveNode::evaluate):
(FunctionCallBracketNode::evaluate):
(FunctionCallDotNode::evaluate):
(PostfixResolveNode::evaluate):
(PostfixBracketNode::evaluate):
(PostfixDotNode::evaluate):
(TypeOfResolveNode::evaluate):
(PrefixResolveNode::evaluate):
(PrefixBracketNode::evaluate):
(PrefixDotNode::evaluate):
(AssignResolveNode::evaluate):
(AssignDotNode::evaluate):
(AssignBracketNode::evaluate):
Update for changes to PropertySlot::getValue.

  • kjs/nodes.h: (KJS::PropertyNameNode::PropertyNameNode): Rename from PropertyNode.

(KJS::PropertyNode::):
(KJS::PropertyNode::PropertyNode):
New class, representing a single property.

(KJS::PropertyListNode::PropertyListNode):
Rename from PropertyValueNode.

(KJS::FuncExprNode::FuncExprNode):
Put ParameterNode parameter last, and make it optional.

(KJS::ObjectLiteralNode::ObjectLiteralNode):
Use a PropertyListNode here now.

  • kjs/nodes2string.cpp: (PropertyListNode::streamTo): Iterate through all property nodes.

(PropertyNode::streamTo):
Print out the name and value. Doesn't handle getters and setters currently.

(PropertyNameNode::streamTo):
Rename from PropertyNode::streamTo.

  • kjs/object.cpp: (KJS::JSObject::get): Update for changes to PropertySlot::getValue.

(KJS::JSObject::put):
If the property already exists and has a Setter, invoke
the setter function instead of setting the property directly.

(KJS::JSObject::defineGetter):
(KJS::JSObject::defineSetter):
New functions for defining property getters and setters on the object.

  • kjs/object.h: (KJS::GetterSetterImp::type): (KJS::GetterSetterImp::GetterSetterImp): (KJS::GetterSetterImp::getGetter): (KJS::GetterSetterImp::setGetter): (KJS::GetterSetterImp::getSetter): (KJS::GetterSetterImp::setSetter): New class for properties which have getters and setters defined. This class is only used internally and should never be seen from the outside.

(KJS::JSObject::getOwnPropertySlot):

If the property is a getter, call setGetterSlot on the property slot.

  • kjs/object_object.cpp: (ObjectPrototype::ObjectPrototype): Add defineGetter, defineSetter, lookupGetter, lookupSetter to prototype.

(ObjectProtoFunc::callAsFunction):
Implement handlers for new functions.

  • kjs/object_object.h: (KJS::ObjectProtoFunc::): Add ids for new functions.
  • kjs/property_slot.cpp: (KJS::PropertySlot::undefinedGetter): Update for changes to PropertySlot::GetValueFunc.

(KJS::PropertySlot::functionGetter):
Call the function getter object and return its value.

  • kjs/property_slot.h: (KJS::PropertySlot::getValue): Add a new argument which is the original object that getPropertySlot was called on.

(KJS::PropertySlot::setGetterSlot):
(KJS::PropertySlot::):
New function which sets a getter slot. When getValue is called on a
getter slot, the getter function object is invoked.

  • kjs/string_object.cpp: (StringInstance::lengthGetter): (StringInstance::indexGetter):
  • kjs/string_object.h: Update for changes to PropertySlot::GetValueFunc.
  • kjs/value.h: (KJS::): Add GetterSetterType and make GetterSetterImp a friend class of JSCell.
File:
1 edited

Legend:

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

    r11527 r11566  
    8181  };
    8282 
     83  // This is an internal value object which stores getter and setter functions
     84  // for a property.
     85  class GetterSetterImp : public JSCell {
     86  public:
     87    Type type() const { return GetterSetterType; }
     88     
     89    GetterSetterImp() : getter(0), setter(0) { }
     90     
     91    virtual JSValue *toPrimitive(ExecState *exec, Type preferred = UnspecifiedType) const;
     92    virtual bool toBoolean(ExecState *exec) const;
     93    virtual double toNumber(ExecState *exec) const;
     94    virtual UString toString(ExecState *exec) const;
     95    virtual JSObject *toObject(ExecState *exec) const;
     96     
     97    virtual void mark();
     98     
     99    JSObject *getGetter() { return getter; }
     100    void setGetter(JSObject *g) { getter = g; }
     101    JSObject *getSetter() { return setter; }
     102    void setSetter(JSObject *s) { setter = s; }
     103     
     104  private:
     105    JSObject *getter;
     106    JSObject *setter; 
     107  };
     108 
    83109  class JSObject : public JSCell {
    84110  public:
     
    478504    void putDirect(const Identifier &propertyName, int value, int attr = 0);
    479505   
     506    void defineGetter(ExecState *exec, const Identifier& propertyName, JSObject *getterFunc);
     507    void defineSetter(ExecState *exec, const Identifier& propertyName, JSObject *setterFunc);
     508
    480509    /**
    481510     * Remove all properties from this object.
     
    607636{
    608637    if (JSValue **location = getDirectLocation(propertyName)) {
    609         slot.setValueSlot(this, location);
     638        if ((*location)->type() == GetterSetterType) {
     639            GetterSetterImp *gs = static_cast<GetterSetterImp *>(*location);
     640            JSObject *getterFunc = gs->getGetter();
     641            if (getterFunc)
     642                slot.setGetterSlot(this, getterFunc);
     643            else
     644                slot.setUndefined(this);
     645        } else {
     646            slot.setValueSlot(this, location);
     647        }
    610648        return true;
    611649    }
Note: See TracChangeset for help on using the changeset viewer.