Ignore:
Timestamp:
Aug 19, 2002, 1:54:20 AM (23 years ago)
Author:
mjs
Message:

Maintain stack of old "arguments" property values for functions
implicitly on the system stack instead of explicitly in the
FunctionImp. This eliminates only a trivial number of GC
allocations (less than 200) but eliminates one of the two cases
where a ListImp * is stored directly, paving the way to separate
List from Value.

  • kjs/function.h: Remove argStack, pushArgs and popArgs.
  • kjs/function.cpp: (FunctionImp::FunctionImp): Don't initalize argStack. (FunctionImp::~FunctionImp): Remove comment about argStack. (FunctionImp::mark): Don't mark the argStack. (FunctionImp::call): Save old "arguments" property in a Value, where it will be GC-protected, rather than keeping a list, and restore the old value when done executing.
File:
1 edited

Legend:

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

    r1859 r1864  
    5656  : InternalFunctionImp(
    5757      static_cast<FunctionPrototypeImp*>(exec->interpreter()->builtinFunctionPrototype().imp())
    58       ), param(0L), ident(n), argStack(0)
     58      ), param(0L), ident(n)
    5959{
    6060  Value protect(this);
    61   argStack = new ListImp();
    62   Value protectArgStack( argStack ); // this also calls setGcAllowed on argStack
    63   //fprintf(stderr,"FunctionImp::FunctionImp this=%p argStack=%p\n");
     61  //fprintf(stderr,"FunctionImp::FunctionImp this=%p\n");
    6462  put(exec,"arguments",Null(),ReadOnly|DontDelete|DontEnum);
    6563}
     
    6765FunctionImp::~FunctionImp()
    6866{
    69   // The function shouldn't be deleted while it is still executed; argStack
    70   // should be set to 0 by the last call to popArgs()
    71   //assert(argStack->isEmpty());
    72   // Accessing argStack from here is a problem though.
    73   // When the function isn't used anymore, it's not marked, and neither is the
    74   // argStack, so both can be deleted - in any order!
    7567  delete param;
    7668}
     
    7971{
    8072  InternalFunctionImp::mark();
    81   if (argStack && !argStack->marked())
    82     argStack->mark();
    8373}
    8474
     
    115105  newExec.setException(exec->exception()); // could be null
    116106
    117   // In order to maintain our "arguments" property, we maintain a list of arguments
    118   // properties from earlier in the execution stack. Upon return, we restore the
    119   // previous arguments object using popArgs().
     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.
    120110  // Note: this does not appear to be part of the spec
     111  Value oldArgs = get(&newExec, "arguments");
     112
    121113  if (codeType() == FunctionCode) {
    122114    assert(ctx.activationObject().inherits(&ActivationImp::info));
    123115    Object argsObj = static_cast<ActivationImp*>(ctx.activationObject().imp())->argumentsObject();
    124116    put(&newExec, "arguments", argsObj, DontDelete|DontEnum|ReadOnly);
    125     pushArgs(&newExec, argsObj);
    126117  }
    127118
     
    137128    exec->setException(newExec.exception());
    138129  if (codeType() == FunctionCode)
    139     popArgs(&newExec);
     130    put(&newExec, "arguments", oldArgs, DontDelete|DontEnum|ReadOnly);
    140131
    141132#ifdef KJS_VERBOSE
     
    228219void FunctionImp::processVarDecls(ExecState */*exec*/)
    229220{
    230 }
    231 
    232 void FunctionImp::pushArgs(ExecState *exec, const Object &args)
    233 {
    234   argStack->append(args);
    235   put(exec,"arguments",args,ReadOnly|DontDelete|DontEnum);
    236 }
    237 
    238 void FunctionImp::popArgs(ExecState *exec)
    239 {
    240   argStack->removeLast();
    241   if (argStack->isEmpty()) {
    242     put(exec,"arguments",Null(),ReadOnly|DontDelete|DontEnum);
    243   }
    244   else
    245     put(exec,"arguments",argStack->at(argStack->size()-1),ReadOnly|DontDelete|DontEnum);
    246221}
    247222
Note: See TracChangeset for help on using the changeset viewer.