Changeset 38249 in webkit for trunk/JavaScriptCore/jsc.cpp
- Timestamp:
- Nov 9, 2008, 5:28:10 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/jsc.cpp
r38162 r38249 79 79 Options() 80 80 : interactive(false) 81 , prettyPrint(false)82 81 , dump(false) 83 82 { … … 85 84 86 85 bool interactive; 87 bool prettyPrint;88 86 bool dump; 89 87 Vector<UString> fileNames; … … 300 298 } 301 299 302 static bool prettyPrintScript(ExecState* exec, const UString& fileName, const Vector<char>& script) 303 { 304 int errLine = 0; 305 UString errMsg; 306 RefPtr<ProgramNode> programNode = exec->globalData().parser->parse<ProgramNode>(exec, exec->dynamicGlobalObject()->debugger(), makeSource(script.data(), fileName), &errLine, &errMsg); 307 if (!programNode) { 308 fprintf(stderr, "%s:%d: %s.\n", fileName.UTF8String().c_str(), errLine, errMsg.UTF8String().c_str()); 309 return false; 310 } 311 312 printf("%s\n", programNode->toString().UTF8String().c_str()); 313 return true; 314 } 315 316 static bool runWithScripts(GlobalObject* globalObject, const Vector<UString>& fileNames, bool prettyPrint, bool dump) 300 static bool runWithScripts(GlobalObject* globalObject, const Vector<UString>& fileNames, bool dump) 317 301 { 318 302 Vector<char> script; … … 333 317 return false; // fail early so we can catch missing files 334 318 335 if (prettyPrint)336 prettyPrintScript(globalObject->globalExec(), fileName, script);337 else {338 319 #if ENABLE(OPCODE_SAMPLING) 339 340 #endif 341 342 343 344 345 346 347 348 349 350 320 machine->sampler()->start(); 321 #endif 322 Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script.data(), fileName)); 323 success = success && completion.complType() != Throw; 324 if (dump) { 325 if (completion.complType() == Throw) 326 printf("Exception: %s\n", completion.value()->toString(globalObject->globalExec()).ascii()); 327 else 328 printf("End: %s\n", completion.value()->toString(globalObject->globalExec()).ascii()); 329 } 330 331 globalObject->globalExec()->clearException(); 351 332 352 333 #if ENABLE(OPCODE_SAMPLING) 353 machine->sampler()->stop(); 354 #endif 355 } 334 machine->sampler()->stop(); 335 #endif 356 336 } 357 337 … … 404 384 fprintf(stderr, " -h|--help Prints this help message\n"); 405 385 fprintf(stderr, " -i Enables interactive mode (default if no files are specified)\n"); 406 fprintf(stderr, " -p Prints formatted source code\n");407 386 fprintf(stderr, " -s Installs signal handlers that exit on a crash (Unix platforms only)\n"); 408 387 exit(-1); … … 427 406 continue; 428 407 } 429 if (strcmp(arg, "-p") == 0) {430 options.prettyPrint = true;431 continue;432 }433 408 if (strcmp(arg, "-d") == 0) { 434 409 options.dump = true; … … 468 443 469 444 GlobalObject* globalObject = new (globalData) GlobalObject(options.arguments); 470 bool success = runWithScripts(globalObject, options.fileNames, options. prettyPrint, options.dump);445 bool success = runWithScripts(globalObject, options.fileNames, options.dump); 471 446 if (options.interactive && success) 472 447 runInteractive(globalObject);
Note:
See TracChangeset
for help on using the changeset viewer.