Changeset 11566 in webkit for trunk/JavaScriptCore/kjs/nodes.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/nodes.h

    r11527 r11566  
    3333
    3434  class ProgramNode;
    35   class PropertyNode;
    36   class PropertyValueNode;
     35  class PropertyNameNode;
     36  class PropertyListNode;
    3737  class Reference;
    3838  class RegExp;
     
    247247  };
    248248
    249   class PropertyValueNode : public Node {
    250   public:
    251     // list pointer is tail of a circular list, cracked in the ObjectLiteralNode ctor
    252     PropertyValueNode(PropertyNode *n, Node *a)
    253       : name(n), assign(a), list(this) { }
    254     PropertyValueNode(PropertyNode *n, Node *a, PropertyValueNode *l)
    255       : name(n), assign(a), list(l->list) { l->list = this; }
    256     JSValue *evaluate(ExecState *exec);
    257     virtual void streamTo(SourceStream &s) const;
    258   private:
    259     friend class ObjectLiteralNode;
    260     RefPtr<PropertyNode> name;
    261     RefPtr<Node> assign;
    262     RefPtr<PropertyValueNode> list;
    263   };
    264 
    265   class ObjectLiteralNode : public Node {
    266   public:
    267     ObjectLiteralNode() : list(0) { }
    268     ObjectLiteralNode(PropertyValueNode *l) : list(l->list) { l->list = 0; }
    269     JSValue *evaluate(ExecState *exec);
    270     virtual void streamTo(SourceStream &s) const;
    271   private:
    272     RefPtr<PropertyValueNode> list;
    273   };
    274 
    275   class PropertyNode : public Node {
    276   public:
    277     PropertyNode(double d) : numeric(d) { }
    278     PropertyNode(const Identifier &s) : str(s) { }
     249  class PropertyNameNode : public Node {
     250  public:
     251    PropertyNameNode(double d) : numeric(d) { }
     252    PropertyNameNode(const Identifier &s) : str(s) { }
    279253    JSValue *evaluate(ExecState *exec);
    280254    virtual void streamTo(SourceStream &s) const;
     
    282256    double numeric;
    283257    Identifier str;
     258  };
     259 
     260  class PropertyNode : public Node {
     261  public:
     262    enum Type { Constant, Getter, Setter };
     263    PropertyNode(PropertyNameNode *n, Node *a, Type t)
     264      : name(n), assign(a), type(t) { }
     265    JSValue *evaluate(ExecState *exec);
     266    virtual void streamTo(SourceStream &s) const;
     267    friend class PropertyListNode;
     268  private:
     269    RefPtr<PropertyNameNode> name;
     270    RefPtr<Node> assign;
     271    Type type;
     272  };
     273 
     274  class PropertyListNode : public Node {
     275  public:
     276    // list pointer is tail of a circular list, cracked in the ObjectLiteralNode ctor
     277    PropertyListNode(PropertyNode *n)
     278
     279      : node(n), list(this) { }
     280    PropertyListNode(PropertyNode *n, PropertyListNode *l)
     281      : node(n), list(l->list) { l->list = this; }
     282    JSValue *evaluate(ExecState *exec);
     283    virtual void streamTo(SourceStream &s) const;
     284  private:
     285    friend class ObjectLiteralNode;
     286    RefPtr<PropertyNode> node;
     287    RefPtr<PropertyListNode> list;
     288  };
     289
     290  class ObjectLiteralNode : public Node {
     291  public:
     292    ObjectLiteralNode() : list(0) { }
     293    ObjectLiteralNode(PropertyListNode *l) : list(l->list) { l->list = 0; }
     294    JSValue *evaluate(ExecState *exec);
     295    virtual void streamTo(SourceStream &s) const;
     296  private:
     297    RefPtr<PropertyListNode> list;
    284298  };
    285299
     
    10311045  class FuncExprNode : public Node {
    10321046  public:
    1033     FuncExprNode(const Identifier &i, FunctionBodyNode *b)
    1034       : ident(i), param(0), body(b) { }
    1035     FuncExprNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
    1036       : ident(i), param(p->next), body(b) { p->next = 0; }
     1047    FuncExprNode(const Identifier &i, FunctionBodyNode *b, ParameterNode *p = 0)
     1048      : ident(i), param(p ? p->next : 0), body(b) { if (p) p->next = 0; }
    10371049    virtual JSValue *evaluate(ExecState *);
    10381050    virtual void streamTo(SourceStream &) const;
    10391051  private:
     1052    // Used for streamTo
     1053    friend class PropertyNode;
    10401054    Identifier ident;
    10411055    RefPtr<ParameterNode> param;
Note: See TracChangeset for help on using the changeset viewer.