Changeset 21032 in webkit for trunk/JavaScriptCore/kjs/function.cpp
- Timestamp:
- Apr 23, 2007, 3:28:10 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/function.cpp
r21019 r21032 52 52 const ClassInfo FunctionImp::info = {"Function", &InternalFunctionImp::info, 0, 0}; 53 53 54 class Parameter {55 public:56 Parameter() {};57 Parameter(const Identifier& n) : name(n) { }58 Identifier name;59 };60 61 54 FunctionImp::FunctionImp(ExecState* exec, const Identifier& n, FunctionBodyNode* b) 62 55 : InternalFunctionImp(static_cast<FunctionPrototype*> … … 89 82 90 83 // assign user supplied arguments to parameters 91 p rocessParameters(&newExec, args);84 passInParameters(&newExec, args); 92 85 // add variable declarations (initialized to undefined) 93 86 processVarDecls(&newExec); … … 153 146 } 154 147 155 void FunctionImp::addParameter(const Identifier& n)156 {157 if (!parameters)158 parameters.set(new Vector<Parameter>);159 160 parameters->append(Parameter(n));161 }162 163 UString FunctionImp::parameterString() const164 {165 UString s;166 167 if (!parameters)168 return s;169 170 for (size_t i = 0; i < parameters->size(); ++i) {171 if (!s.isEmpty())172 s += ", ";173 s += parameters->at(i).name.ustring();174 }175 176 return s;177 }178 179 180 148 // ECMA 10.1.3q 181 void FunctionImp::processParameters(ExecState* exec, const List& args) 182 { 183 if (!parameters) 184 return; 149 inline void FunctionImp::passInParameters(ExecState* exec, const List& args) 150 { 151 Vector<Parameter>& parameters = body->parameters(); 185 152 186 153 JSObject* variable = exec->context()->variableObject(); … … 192 159 #endif 193 160 194 ListIterator it = args.begin(); 195 196 JSValue * v = *it; 197 for (size_t i = 0; i < parameters->size(); ++i) { 198 if (it != args.end()) { 161 size_t size = parameters.size(); 162 for (size_t i = 0; i < size; ++i) { 199 163 #ifdef KJS_VERBOSE 200 201 printInfo(exec, "to", *it);164 fprintf(stderr, "setting parameter %s ", parameters->at(i).name.ascii()); 165 printInfo(exec, "to", args[i]); 202 166 #endif 203 variable->put(exec, parameters->at(i).name, v); 204 v = ++it; 205 } else 206 variable->put(exec, parameters->at(i).name, jsUndefined()); 207 } 208 #ifdef KJS_VERBOSE 209 else { 210 for (int i = 0; i < args.size(); ++i) 211 printInfo(exec,"setting argument", args[i]); 212 } 213 #endif 167 variable->put(exec, parameters[i].name, args[i]); 168 } 214 169 } 215 170 … … 257 212 { 258 213 FunctionImp* thisObj = static_cast<FunctionImp*>(slot.slotBase()); 259 return jsNumber(thisObj-> parameters ? thisObj->parameters->size() : 0);214 return jsNumber(thisObj->body->numParams()); 260 215 } 261 216 … … 305 260 Identifier FunctionImp::getParameterName(int index) 306 261 { 307 if (!parameters) 308 return CommonIdentifiers::shared()->nullIdentifier; 309 310 if (static_cast<size_t>(index) >= parameters->size()) 262 Vector<Parameter>& parameters = body->parameters(); 263 264 if (static_cast<size_t>(index) >= body->numParams()) 311 265 return CommonIdentifiers::shared()->nullIdentifier; 312 266 313 Identifier name = parameters ->at(index).name;267 Identifier name = parameters[index].name; 314 268 315 269 // Are there any subsequent parameters with the same name? 316 for (size_t i = index + 1; i < parameters->size(); ++i) 317 if (parameters->at(i).name == name) 270 size_t size = parameters.size(); 271 for (size_t i = index + 1; i < size; ++i) 272 if (parameters[i].name == name) 318 273 return CommonIdentifiers::shared()->nullIdentifier; 319 274
Note:
See TracChangeset
for help on using the changeset viewer.