Changeset 16606 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Sep 27, 2006, 5:58:52 PM (19 years ago)
Author:
kmccullo
Message:

Reviewed by Adele.

Fixes a GC stack overflow crash.
The change is to move from a linked list implementation of Parameters to a Vector.
The problem with the linked list is that each one creates it's own stack frame when being destroyed and in extreme cases this caused the stack to overflow.

  • kjs/function.cpp: (KJS::Parameter::Parameter): (KJS::FunctionImp::addParameter): (KJS::FunctionImp::parameterString): (KJS::FunctionImp::processParameters): (KJS::FunctionImp::lengthGetter): (KJS::FunctionImp::getParameterName):
  • kjs/function.h:
Location:
trunk/JavaScriptCore/kjs
Files:
2 edited

Legend:

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

    r16117 r16606  
    5151  class Parameter {
    5252  public:
     53    Parameter() {};
    5354    Parameter(const Identifier &n) : name(n) { }
    5455    Identifier name;
    55     OwnPtr<Parameter> next;
     56//    OwnPtr<Parameter> next;
    5657  };
    5758
     
    152153void FunctionImp::addParameter(const Identifier &n)
    153154{
    154   OwnPtr<Parameter> *p = &param;
    155   while (*p)
    156     p = &(*p)->next;
    157 
    158   p->set(new Parameter(n));
     155    params.append(Parameter(n));
    159156}
    160157
     
    162159{
    163160  UString s;
    164   const Parameter *p = param.get();
    165   while (p) {
    166     if (!s.isEmpty())
    167         s += ", ";
    168     s += p->name.ustring();
    169     p = p->next.get();
    170   }
     161
     162    for(Vector<Parameter>::const_iterator it = params.begin(); it < params.end(); it++) {
     163        if (!s.isEmpty())
     164            s += ", ";
     165        s += it->name.ustring();
     166    }
    171167
    172168  return s;
     
    185181#endif
    186182
    187   if (param) {
     183    if(params.size() != 0) {
    188184    ListIterator it = args.begin();
    189     Parameter *p = param.get();
     185
    190186    JSValue  *v = *it;
    191     while (p) {
     187    for(Vector<Parameter>::iterator pit = params.begin(); pit < params.end(); pit++) {
    192188      if (it != args.end()) {
    193189#ifdef KJS_VERBOSE
     
    195191        printInfo(exec,"to", *it);
    196192#endif
    197         variable->put(exec, p->name, v);
     193        variable->put(exec, pit->name, v);
    198194        v = ++it;
    199195      } else
    200         variable->put(exec, p->name, jsUndefined());
    201       p = p->next.get();
     196        variable->put(exec, pit->name, jsUndefined());
    202197    }
    203198  }
     
    229224JSValue *FunctionImp::lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot)
    230225{
    231   FunctionImp *thisObj = static_cast<FunctionImp *>(slot.slotBase());
    232   const Parameter *p = thisObj->param.get();
    233   int count = 0;
    234   while (p) {
    235     ++count;
    236     p = p->next.get();
    237   }
    238   return jsNumber(count);
     226    FunctionImp *thisObj = static_cast<FunctionImp *>(slot.slotBase());
     227    return jsNumber(thisObj->params.size());
    239228}
    240229
     
    279268Identifier FunctionImp::getParameterName(int index)
    280269{
    281   int i = 0;
    282   Parameter *p = param.get();
     270    if(params.size() == 0)
     271        return Identifier::null();
    283272 
    284   if(!p)
    285     return Identifier::null();
     273    if (index > static_cast<int>(params.size()))
     274        return Identifier::null();
    286275 
    287   // skip to the parameter we want
    288   while (i++ < index && (p = p->next.get()))
    289     ;
    290  
    291   if (!p)
    292     return Identifier::null();
    293  
    294   Identifier name = p->name;
    295 
    296   // Are there any subsequent parameters with the same name?
    297   while ((p = p->next.get()))
    298     if (p->name == name)
    299       return Identifier::null();
    300  
    301   return name;
     276    Identifier name = params[index].name;
     277
     278    // Are there any subsequent parameters with the same name?
     279    for (Vector<Parameter>::iterator it = &(params[index+1]); it < params.end(); it++)
     280        if (it->name == name)
     281            return Identifier::null();
     282
     283    return name;
    302284}
    303285
  • trunk/JavaScriptCore/kjs/function.h

    r15846 r16606  
    2727#include "internal.h"
    2828#include <wtf/OwnPtr.h>
     29#include <wtf/Vector.h>
    2930
    3031namespace KJS {
     
    9394    virtual void mark();
    9495  protected:
    95     OwnPtr<Parameter> param;
     96    Vector<Parameter> params;
    9697
    9798  private:
Note: See TracChangeset for help on using the changeset viewer.