Commit f1623c9f authored by mjs's avatar mjs
Browse files

Reviewed by Mitz.

        - fixed REGRESSION (r16606): javascriptCore Crash on website load
        
        Plus style fixes.
        
            - fixed some possible off-by-one bugs
            - use indexing, not iterators, for Vectors
            - store Vector by pointer instead of by value to avoid blowing out FunctionImp size
        
        * kjs/function.cpp:
        (KJS::FunctionImp::addParameter):
        (KJS::FunctionImp::parameterString):
        (KJS::FunctionImp::processParameters):
        (KJS::FunctionImp::lengthGetter):
        (KJS::FunctionImp::getParameterName):
        * kjs/function.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@16613 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 18d2f317
2006-09-28 Maciej Stachowiak <mjs@apple.com>
Reviewed by Mitz.
- fixed REGRESSION (r16606): javascriptCore Crash on website load
Plus style fixes.
- fixed some possible off-by-one bugs
- use indexing, not iterators, for Vectors
- store Vector by pointer instead of by value to avoid blowing out FunctionImp size
* kjs/function.cpp:
(KJS::FunctionImp::addParameter):
(KJS::FunctionImp::parameterString):
(KJS::FunctionImp::processParameters):
(KJS::FunctionImp::lengthGetter):
(KJS::FunctionImp::getParameterName):
* kjs/function.h:
2006-09-27 Steve Falkenburg <sfalken@apple.com>
 
Reviewed by Maciej.
......
......@@ -151,31 +151,39 @@ JSValue *FunctionImp::callAsFunction(ExecState* exec, JSObject* thisObj, const L
void FunctionImp::addParameter(const Identifier &n)
{
parameters.append(Parameter(n));
if (!parameters)
parameters.set(new Vector<Parameter>);
parameters->append(Parameter(n));
}
UString FunctionImp::parameterString() const
{
UString s;
UString s;
if (!parameters)
return s;
Vector<Parameter>::const_iterator end = parameters.end();
for(Vector<Parameter>::const_iterator it = parameters.begin(); it < end; it++) {
for (size_t i = 0; i < parameters->size(); ++i) {
if (!s.isEmpty())
s += ", ";
s += it->name.ustring();
s += parameters->at(i).name.ustring();
}
return s;
return s;
}
// ECMA 10.1.3q
void FunctionImp::processParameters(ExecState *exec, const List &args)
{
JSObject* variable = exec->context()->variableObject();
if (!parameters)
return;
JSObject* variable = exec->context()->variableObject();
#ifdef KJS_VERBOSE
fprintf(stderr, "---------------------------------------------------\n"
fprintf(stderr, "---------------------------------------------------\n"
"processing parameters for %s call\n",
name().isEmpty() ? "(internal)" : name().ascii());
#endif
......@@ -183,21 +191,20 @@ void FunctionImp::processParameters(ExecState *exec, const List &args)
ListIterator it = args.begin();
JSValue *v = *it;
Vector<Parameter>::const_iterator end = parameters.end();
for(Vector<Parameter>::iterator pit = parameters.begin(); pit < end; pit++) {
for (size_t i = 0; i < parameters->size(); ++i) {
if (it != args.end()) {
#ifdef KJS_VERBOSE
fprintf(stderr, "setting parameter %s ", p->name.ascii());
printInfo(exec,"to", *it);
fprintf(stderr, "setting parameter %s ", parameters->at(i).name.ascii());
printInfo(exec, "to", *it);
#endif
variable->put(exec, pit->name, v);
variable->put(exec, parameters->at(i).name, v);
v = ++it;
} else
variable->put(exec, pit->name, jsUndefined());
variable->put(exec, parameters->at(i).name, jsUndefined());
}
#ifdef KJS_VERBOSE
else {
for (int i = 0; i < args.size(); i++)
for (int i = 0; i < args.size(); ++i)
printInfo(exec,"setting argument", args[i]);
}
#endif
......@@ -223,7 +230,7 @@ JSValue *FunctionImp::argumentsGetter(ExecState* exec, JSObject*, const Identifi
JSValue *FunctionImp::lengthGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot)
{
FunctionImp *thisObj = static_cast<FunctionImp *>(slot.slotBase());
return jsNumber(thisObj->parameters.size());
return jsNumber(thisObj->parameters ? thisObj->parameters->size() : 0);
}
bool FunctionImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
......@@ -266,15 +273,17 @@ bool FunctionImp::deleteProperty(ExecState *exec, const Identifier &propertyName
*/
Identifier FunctionImp::getParameterName(int index)
{
if (static_cast<size_t>(index) > parameters.size())
if (!parameters)
return Identifier::null();
if (static_cast<size_t>(index) >= parameters->size())
return Identifier::null();
Identifier name = parameters[index].name;
Identifier name = parameters->at(index).name;
// Are there any subsequent parameters with the same name?
Vector<Parameter>::const_iterator end = parameters.end();
for (Vector<Parameter>::iterator it = &(parameters[index+1]); it < end; it++)
if (it->name == name)
for (size_t i = index + 1; i < parameters->size(); ++i)
if (parameters->at(i).name == name)
return Identifier::null();
return name;
......
......@@ -93,7 +93,7 @@ namespace KJS {
virtual void mark();
protected:
Vector<Parameter> parameters;
OwnPtr<Vector<Parameter> > parameters;
private:
ScopeChain _scope;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment