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.
File:
1 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);
Note: See TracChangeset for help on using the changeset viewer.