Changeset 2778 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Nov 20, 2002, 1:11:43 AM (23 years ago)
Author:
darin
Message:
  • on the road to killing ActivationImp
  • kjs/function.h: Add get/put to FunctionImp. Remove argumentsObject() from ActivationImp. Add function() to ActivationImp.
  • kjs/function.cpp: (FunctionImp::FunctionImp): No arguments property. (FunctionImp::call): No need to set up the arguments property. (FunctionImp::parameterString): Remove strangeness. (FunctionImp::processParameters): Ditto. (FunctionImp::get): Added, handles arguments and length properties. (FunctionImp::put): Ditto. (FunctionImp::hasProperty): Ditto. (FunctionImp::deleteProperty): Ditto. (ActivationImp::ActivationImp): Store a function pointer so we can find it in the context.
  • kjs/function_object.cpp: (FunctionObjectImp::construct): No need to set up arguments property.
  • kjs/nodes.cpp: (FuncExprNode::evaluate): No need to set up length property.
  • kjs/internal.h: Return ObjectImp * for activation object.
  • kjs/interpreter.h: Remove stray declaration of ExecStateImp.
Location:
trunk/JavaScriptCore/kjs
Files:
6 edited

Legend:

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

    r2772 r2778  
    5858      ), param(0L), ident(n)
    5959{
    60   Value protect(this);
    6160  //fprintf(stderr,"FunctionImp::FunctionImp this=%p\n");
    62   put(exec,argumentsPropertyName,Null(),ReadOnly|DontDelete|DontEnum);
    6361}
    6462
     
    105103  newExec.setException(exec->exception()); // could be null
    106104
    107   // In order to maintain our "arguments" property, we save the old
    108   // value from a possible earlier call. Upon return, we restore the
    109   // previous arguments object.
    110   // Note: this does not appear to be part of the spec
    111   Value oldArgs = get(&newExec, argumentsPropertyName);
    112 
    113   if (codeType() == FunctionCode) {
    114     assert(ctx.activationObject().inherits(&ActivationImp::info));
    115     Object argsObj = static_cast<ActivationImp*>(ctx.activationObject().imp())->argumentsObject();
    116     put(&newExec, argumentsPropertyName, argsObj, DontDelete|DontEnum|ReadOnly);
    117   }
    118 
    119105  // assign user supplied arguments to parameters
    120106  processParameters(&newExec, args);
     
    127113  if (newExec.hadException())
    128114    exec->setException(newExec.exception());
    129   if (codeType() == FunctionCode)
    130     put(&newExec, argumentsPropertyName, oldArgs, DontDelete|DontEnum|ReadOnly);
    131115
    132116#ifdef KJS_VERBOSE
     
    170154{
    171155  UString s;
    172   const Parameter * const *p = &param;
    173   while (*p) {
     156  const Parameter *p = param;
     157  while (p) {
    174158    if (!s.isEmpty())
    175159        s += ", ";
    176     s += (*p)->name.ustring();
    177     p = &(*p)->next;
     160    s += p->name.ustring();
     161    p = p->next;
    178162  }
    179163
     
    195179  if (param) {
    196180    ListIterator it = args.begin();
    197     Parameter **p = &param;
    198     while (*p) {
     181    Parameter *p = param;
     182    while (p) {
    199183      if (it != args.end()) {
    200184#ifdef KJS_VERBOSE
    201         fprintf(stderr, "setting parameter %s ", (*p)->name.ascii());
     185        fprintf(stderr, "setting parameter %s ", p->name.ascii());
    202186        printInfo(exec,"to", *it);
    203187#endif
    204         variable.put(exec,(*p)->name, *it);
     188        variable.put(exec, p->name, *it);
    205189        it++;
    206190      } else
    207         variable.put(exec,(*p)->name, Undefined());
    208       p = &(*p)->next;
     191        variable.put(exec, p->name, Undefined());
     192      p = p->next;
    209193    }
    210194  }
     
    219203void FunctionImp::processVarDecls(ExecState */*exec*/)
    220204{
     205}
     206
     207Value FunctionImp::get(ExecState *exec, const Identifier &propertyName) const
     208{
     209    // Find the arguments from the closest context.
     210    if (propertyName == argumentsPropertyName) {
     211        ContextImp *context = exec->_context;
     212        while (context) {
     213            ActivationImp *activation = static_cast<ActivationImp *>(context->activationObject());
     214            if (activation->function() == this)
     215                return activation->get(exec, propertyName);
     216            context = context->callingContext();
     217        }
     218        return Undefined();
     219    }
     220   
     221    // Compute length of parameters.
     222    if (propertyName == lengthPropertyName) {
     223        const Parameter * p = param;
     224        int count = 0;
     225        while (p) {
     226            ++count;
     227            p = p->next;
     228        }
     229        return Number(count);
     230    }
     231   
     232    return InternalFunctionImp::get(exec, propertyName);
     233}
     234
     235void FunctionImp::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)
     236{
     237    if (propertyName == argumentsPropertyName || propertyName == lengthPropertyName)
     238        return;
     239    InternalFunctionImp::put(exec, propertyName, value, attr);
     240}
     241
     242bool FunctionImp::hasProperty(ExecState *exec, const Identifier &propertyName) const
     243{
     244    if (propertyName == argumentsPropertyName || propertyName == lengthPropertyName)
     245        return true;
     246    return InternalFunctionImp::hasProperty(exec, propertyName);
     247}
     248
     249bool FunctionImp::deleteProperty(ExecState *exec, const Identifier &propertyName)
     250{
     251    if (propertyName == argumentsPropertyName || propertyName == lengthPropertyName)
     252        return false;
     253    return InternalFunctionImp::deleteProperty(exec, propertyName);
    221254}
    222255
     
    305338// ECMA 10.1.6
    306339ActivationImp::ActivationImp(ExecState *exec, FunctionImp *f, const List &args)
    307   : ObjectImp()
     340  : _function(f)
    308341{
    309342  Value protect(this);
  • trunk/JavaScriptCore/kjs/function.h

    r2760 r2778  
    3939    FunctionImp(ExecState *exec, const Identifier &n = Identifier::null);
    4040    virtual ~FunctionImp();
     41
     42    virtual Value get(ExecState *exec, const Identifier &propertyName) const;
     43    virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
     44    virtual bool hasProperty(ExecState *exec, const Identifier &propertyName) const;
     45    virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
    4146
    4247    virtual void mark();
     
    99104    ~ActivationImp();
    100105
    101     Object argumentsObject() { return Object(arguments); }
    102 
    103106    virtual const ClassInfo *classInfo() const { return &info; }
    104107    static const ClassInfo info;
     108   
     109    FunctionImp *function() const { return _function; }
     110   
    105111  private:
     112    FunctionImp *_function;
    106113    ObjectImp* arguments;
    107114  };
  • trunk/JavaScriptCore/kjs/function_object.cpp

    r2772 r2778  
    284284                Object(fimp), DontEnum|DontDelete|ReadOnly);
    285285  fimp->put(exec,prototypePropertyName,prototype,DontEnum|DontDelete|ReadOnly);
    286   fimp->put(exec,argumentsPropertyName,Null(),DontEnum|DontDelete|ReadOnly);
    287286  return ret;
    288287}
  • trunk/JavaScriptCore/kjs/internal.h

    r2760 r2778  
    197197    Object thisValue() const { return thisVal; }
    198198    ContextImp *callingContext() { return callingCon; }
    199     Object activationObject() { return activation; }
     199    ObjectImp *activationObject() { return activation.imp(); }
    200200
    201201    void pushScope(const Object &s);
  • trunk/JavaScriptCore/kjs/interpreter.h

    r2753 r2778  
    3232
    3333  class ContextImp;
    34   class ExecStateImp;
    3534  class InterpreterImp;
    3635
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r2772 r2778  
    28312831  for(ParameterNode *p = param; p != 0L; p = p->nextParam(), plen++)
    28322832    fimp->addParameter(p->ident());
    2833   fimp->put(exec,lengthPropertyName, Number(plen), ReadOnly|DontDelete|DontEnum);
    28342833
    28352834  return ret;
Note: See TracChangeset for help on using the changeset viewer.