Changeset 30553 in webkit for trunk/JavaScriptCore/kjs/testkjs.cpp
- Timestamp:
- Feb 24, 2008, 5:34:09 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/testkjs.cpp
r29293 r30553 27 27 #include "JSLock.h" 28 28 #include "Parser.h" 29 #include "array_object.h" 29 30 #include "collector.h" 30 31 #include "interpreter.h" … … 223 224 } 224 225 225 static GlobalImp* createGlobalObject( )226 static GlobalImp* createGlobalObject(Vector<UString>& arguments) 226 227 { 227 228 GlobalImp* global = new GlobalImp; … … 240 241 global->put(global->globalExec(), "load", new TestFunctionImp(TestFunctionImp::Load, 1)); 241 242 243 JSObject* array = global->arrayConstructor()->construct(global->globalExec(), global->globalExec()->emptyList()); 244 for (size_t i = 0; i < arguments.size(); ++i) 245 array->put(global->globalExec(), i, jsString(arguments[i])); 246 global->put(global->globalExec(), "arguments", array); 247 242 248 Interpreter::setShouldPrintExceptions(true); 243 249 return global; … … 259 265 } 260 266 261 static bool runWithScripts(const Vector<UString>& fileNames, bool prettyPrint)262 { 263 GlobalImp* globalObject = createGlobalObject( );267 static bool runWithScripts(const Vector<UString>& fileNames, Vector<UString>& arguments, bool prettyPrint) 268 { 269 GlobalImp* globalObject = createGlobalObject(arguments); 264 270 Vector<char> script; 265 271 … … 282 288 } 283 289 284 static void parseArguments(int argc, char** argv, Vector<UString>& fileNames, bool& prettyPrint) 285 { 286 if (argc < 2) { 287 fprintf(stderr, "Usage: testkjs file1 [file2...]\n"); 290 static void printUsageStatement() 291 { 292 fprintf(stderr, "Usage: testkjs -f file1 [-f file2...][-p][-- arguments...]\n"); 288 293 exit(-1); 289 } 290 291 for (int i = 1; i < argc; i++) { 292 const char* fileName = argv[i]; 293 if (strcmp(fileName, "-f") == 0) // mozilla test driver script uses "-f" prefix for files 294 } 295 296 static void parseArguments(int argc, char** argv, Vector<UString>& fileNames, Vector<UString>& arguments, bool& prettyPrint) 297 { 298 if (argc < 3) 299 printUsageStatement(); 300 301 int i = 1; 302 for (; i < argc; ++i) { 303 const char* arg = argv[i]; 304 if (strcmp(arg, "-f") == 0) { 305 if (++i == argc) 306 printUsageStatement(); 307 fileNames.append(argv[i]); 294 308 continue; 295 if (strcmp(fileName, "-p") == 0) { 309 } 310 if (strcmp(arg, "-p") == 0) { 296 311 prettyPrint = true; 297 312 continue; 298 313 } 299 fileNames.append(fileName); 300 } 314 if (strcmp(arg, "--") == 0) { 315 ++i; 316 break; 317 } 318 break; 319 } 320 321 for (; i < argc; ++i) 322 arguments.append(argv[i]); 301 323 } 302 324 … … 307 329 bool prettyPrint = false; 308 330 Vector<UString> fileNames; 309 parseArguments(argc, argv, fileNames, prettyPrint); 310 311 bool success = runWithScripts(fileNames, prettyPrint); 331 Vector<UString> arguments; 332 parseArguments(argc, argv, fileNames, arguments, prettyPrint); 333 334 bool success = runWithScripts(fileNames, arguments, prettyPrint); 312 335 313 336 #ifndef NDEBUG
Note:
See TracChangeset
for help on using the changeset viewer.