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_object.cpp

    r11527 r11566  
    4444    putDirect("hasOwnProperty", new ObjectProtoFunc(exec, funcProto, ObjectProtoFunc::HasOwnProperty,             1), DontEnum);
    4545    putDirect("propertyIsEnumerable", new ObjectProtoFunc(exec, funcProto, ObjectProtoFunc::PropertyIsEnumerable, 1), DontEnum);
     46    // Mozilla extensions
     47    putDirect("__defineGetter__", new ObjectProtoFunc(exec, funcProto, ObjectProtoFunc::DefineGetter,             2), DontEnum);
     48    putDirect("__defineSetter__", new ObjectProtoFunc(exec, funcProto, ObjectProtoFunc::DefineSetter,             2), DontEnum);
     49    putDirect("__lookupGetter__", new ObjectProtoFunc(exec, funcProto, ObjectProtoFunc::LookupGetter,             1), DontEnum);
     50    putDirect("__lookupSetter__", new ObjectProtoFunc(exec, funcProto, ObjectProtoFunc::LookupSetter,             1), DontEnum);
    4651}
    4752
     
    7378            PropertySlot slot;
    7479            return jsBoolean(thisObj->getOwnPropertySlot(exec, Identifier(args[0]->toString(exec)), slot));
     80        }
     81        case DefineGetter:
     82        case DefineSetter: {
     83            if (!args[1]->isObject() ||
     84                !static_cast<JSObject *>(args[1])->implementsCall()) {
     85                if (id == DefineGetter)
     86                    return throwError(exec, SyntaxError, "invalid getter usage");
     87                else
     88                    return throwError(exec, SyntaxError, "invalid setter usage");
     89            }
     90
     91            if (id == DefineGetter)
     92                thisObj->defineGetter(exec, Identifier(args[0]->toString(exec)), static_cast<JSObject *>(args[1]));
     93            else
     94                thisObj->defineSetter(exec, Identifier(args[0]->toString(exec)), static_cast<JSObject *>(args[1]));
     95            return jsUndefined();
     96        }
     97        case LookupGetter:
     98        case LookupSetter: {
     99            Identifier propertyName = Identifier(args[0]->toString(exec));
     100           
     101            JSObject *obj = thisObj;
     102            while (true) {
     103                JSValue *v = obj->getDirect(propertyName);
     104               
     105                if (v) {
     106                    if (v->type() != GetterSetterType)
     107                        return jsUndefined();
     108
     109                    JSObject *funcObj;
     110                       
     111                    if (id == LookupGetter)
     112                        funcObj = static_cast<GetterSetterImp *>(v)->getGetter();
     113                    else
     114                        funcObj = static_cast<GetterSetterImp *>(v)->getSetter();
     115               
     116                    if (!funcObj)
     117                        return jsUndefined();
     118                    else
     119                        return funcObj;
     120                }
     121               
     122                if (!obj->prototype() || !obj->prototype()->isObject())
     123                    return jsUndefined();
     124               
     125                obj = static_cast<JSObject *>(obj->prototype());
     126            }
    75127        }
    76128        case PropertyIsEnumerable:
Note: See TracChangeset for help on using the changeset viewer.