Changeset 40663 in webkit
- Timestamp:
- Feb 4, 2009 9:31:40 PM (15 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r40660 r40663 1 2009-02-04 Gavin Barraclough <barraclough@apple.com> 2 3 Reviewed by Oliver 'the nun' Hunt. 4 5 Add -e switch to jsc to enable evaluation of scripts passed on the command line. 6 7 * jsc.cpp: 8 (Script::Script): 9 (runWithScripts): 10 (printUsageStatement): 11 (parseArguments): 12 (jscmain): 13 1 14 2009-02-04 Gavin Barraclough <barraclough@apple.com> 2 15 -
trunk/JavaScriptCore/jsc.cpp
r40419 r40663 77 77 static NO_RETURN JSValuePtr functionQuit(ExecState*, JSObject*, JSValuePtr, const ArgList&); 78 78 79 struct Script { 80 bool isFile; 81 char *argument; 82 83 Script(bool isFile, char *argument) 84 : isFile(isFile) 85 , argument(argument) 86 { 87 } 88 }; 89 79 90 struct Options { 80 91 Options() … … 86 97 bool interactive; 87 98 bool dump; 88 Vector< UString> fileNames;99 Vector<Script> scripts; 89 100 Vector<UString> arguments; 90 101 }; … … 312 323 } 313 324 314 static bool runWithScripts(GlobalObject* globalObject, const Vector<UString>& fileNames, bool dump) 315 { 316 Vector<char> script; 325 static bool runWithScripts(GlobalObject* globalObject, const Vector<Script>& scripts, bool dump) 326 { 327 UString script; 328 UString fileName; 329 Vector<char> scriptBuffer; 317 330 318 331 if (dump) … … 325 338 326 339 bool success = true; 327 for (size_t i = 0; i < fileNames.size(); i++) { 328 UString fileName = fileNames[i]; 329 330 if (!fillBufferWithContentsOfFile(fileName, script)) 331 return false; // fail early so we can catch missing files 340 for (size_t i = 0; i < scripts.size(); i++) { 341 if (scripts[i].isFile) { 342 fileName = scripts[i].argument; 343 if (!fillBufferWithContentsOfFile(fileName, scriptBuffer)) 344 return false; // fail early so we can catch missing files 345 script = scriptBuffer.data(); 346 } else { 347 script = scripts[i].argument; 348 fileName = "[Command Line]"; 349 } 332 350 333 351 #if ENABLE(OPCODE_SAMPLING) 334 352 interpreter->sampler()->start(); 335 353 #endif 336 Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script .data(), fileName));354 Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script, fileName)); 337 355 success = success && completion.complType() != Throw; 338 356 if (dump) { … … 391 409 } 392 410 393 static NO_RETURN void printUsageStatement( )411 static NO_RETURN void printUsageStatement(bool help = false) 394 412 { 395 413 fprintf(stderr, "Usage: jsc [options] [files] [-- arguments]\n"); 396 414 fprintf(stderr, " -d Dumps bytecode (debug builds only)\n"); 415 fprintf(stderr, " -e Evaluate argument as script code\n"); 397 416 fprintf(stderr, " -f Specifies a source file (deprecated)\n"); 398 417 fprintf(stderr, " -h|--help Prints this help message\n"); 399 418 fprintf(stderr, " -i Enables interactive mode (default if no files are specified)\n"); 400 419 fprintf(stderr, " -s Installs signal handlers that exit on a crash (Unix platforms only)\n"); 401 exit( EXIT_FAILURE);420 exit(help ? EXIT_SUCCESS : EXIT_FAILURE); 402 421 } 403 422 … … 410 429 if (++i == argc) 411 430 printUsageStatement(); 412 options. fileNames.append(argv[i]);431 options.scripts.append(Script(true, argv[i])); 413 432 continue; 414 433 } 434 if (strcmp(arg, "-e") == 0) { 435 if (++i == argc) 436 printUsageStatement(); 437 options.scripts.append(Script(false, argv[i])); 438 continue; 439 } 415 440 if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) { 416 printUsageStatement( );441 printUsageStatement(true); 417 442 } 418 443 if (strcmp(arg, "-i") == 0) { … … 437 462 break; 438 463 } 439 options. fileNames.append(argv[i]);464 options.scripts.append(Script(true, argv[i])); 440 465 } 441 466 442 if (options. fileNames.isEmpty())467 if (options.scripts.isEmpty()) 443 468 options.interactive = true; 444 469 … … 455 480 456 481 GlobalObject* globalObject = new (globalData) GlobalObject(options.arguments); 457 bool success = runWithScripts(globalObject, options. fileNames, options.dump);482 bool success = runWithScripts(globalObject, options.scripts, options.dump); 458 483 if (options.interactive && success) 459 484 runInteractive(globalObject);
Note: See TracChangeset
for help on using the changeset viewer.