Changeset 34470 in webkit for trunk/JavaScriptCore
- Timestamp:
- Jun 9, 2008, 10:10:27 AM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r34457 r34470 1 2008-06-09 Cameron Zwarich <[email protected]> 2 3 Reviewed by Darin. 4 5 Bug 17531: Add interactive mode to testkjs 6 <https://bugs.webkit.org/show_bug.cgi?id=17531> 7 8 This is a cleaned up version of Sam's earlier patch to add an 9 interactive mode to testkjs. 10 11 Readline support is only enabled on Darwin platforms for now, but 12 other ports can enable it by defining HAVE_READLINE in kjs/config.h. 13 14 * JavaScriptCore.xcodeproj/project.pbxproj: 15 * kjs/config.h: 16 * kjs/testkjs.cpp: 17 (Options::Options): 18 (runWithScripts): 19 (runInteractive): 20 (printUsageStatement): 21 (parseArguments): 22 (kjsmain): 23 1 24 2008-06-08 Cameron Zwarich <[email protected]> 2 25 -
trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r34412 r34470 228 228 A8E894320CD0602400367179 /* JSCallbackObjectFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = A8E894310CD0602400367179 /* JSCallbackObjectFunctions.h */; }; 229 229 A8E894340CD0603F00367179 /* JSGlobalObject.h in Headers */ = {isa = PBXBuildFile; fileRef = A8E894330CD0603F00367179 /* JSGlobalObject.h */; settings = {ATTRIBUTES = (Private, ); }; }; 230 BC8E03F60D72A9FC006FC608 /* libedit.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BC8E03F50D72A9FC006FC608 /* libedit.2.dylib */; }; 230 231 BC8F3CED0DAF1A8000577A80 /* ConstructData.h in Headers */ = {isa = PBXBuildFile; fileRef = BC8F3CCF0DAF17BA00577A80 /* ConstructData.h */; settings = {ATTRIBUTES = (Private, ); }; }; 231 232 BCF655590A2049710038A194 /* MathExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = BCF6553B0A2048DE0038A194 /* MathExtras.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 575 576 A8E894310CD0602400367179 /* JSCallbackObjectFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCallbackObjectFunctions.h; sourceTree = "<group>"; }; 576 577 A8E894330CD0603F00367179 /* JSGlobalObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSGlobalObject.h; sourceTree = "<group>"; }; 578 BC8E03F50D72A9FC006FC608 /* libedit.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libedit.2.dylib; path = /usr/lib/libedit.2.dylib; sourceTree = "<absolute>"; }; 577 579 BC8F3CCF0DAF17BA00577A80 /* ConstructData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConstructData.h; sourceTree = "<group>"; }; 578 580 BCF6553B0A2048DE0038A194 /* MathExtras.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MathExtras.h; sourceTree = "<group>"; }; … … 687 689 files = ( 688 690 932F5BEA0822A1C700736975 /* JavaScriptCore.framework in Frameworks */, 691 BC8E03F60D72A9FC006FC608 /* libedit.2.dylib in Frameworks */, 689 692 ); 690 693 runOnlyForDeploymentPostprocessing = 0; … … 746 749 9322A00306C341D3009067BB /* libicucore.dylib */, 747 750 51F0EC0705C86C9A00E6DF1B /* libobjc.dylib */, 751 BC8E03F50D72A9FC006FC608 /* libedit.2.dylib */, 748 752 ); 749 753 name = Frameworks; -
trunk/JavaScriptCore/kjs/config.h
r34067 r34470 27 27 #define HAVE_MMAP 1 28 28 #define HAVE_MERGESORT 1 29 #define HAVE_READLINE 1 29 30 #define HAVE_SBRK 1 30 31 #define HAVE_STRINGS_H 1 -
trunk/JavaScriptCore/kjs/testkjs.cpp
r34437 r34470 45 45 #endif 46 46 47 #if HAVE(READLINE) 48 #include <readline/readline.h> 49 #endif 50 47 51 #if HAVE(SYS_TIME_H) 48 52 #include <sys/time.h> … … 76 80 static JSValue* functionQuit(ExecState*, JSObject*, const List&); 77 81 82 struct Options { 83 Options() 84 : interactive(false) 85 , prettyPrint(false) 86 , dump(false) 87 { 88 } 89 90 bool interactive; 91 bool prettyPrint; 92 bool dump; 93 Vector<UString> fileNames; 94 Vector<UString> arguments; 95 }; 96 97 static const char interactivePrompt[] = "> "; 98 static const UString interpreterName("Interpreter"); 99 78 100 class StopWatch { 79 101 public: … … 293 315 } 294 316 295 static bool runWithScripts(const Vector<UString>& fileNames, Vector<UString>& arguments, bool prettyPrint, bool dump) 296 { 297 GlobalObject* globalObject = new GlobalObject(arguments); 317 static bool runWithScripts(GlobalObject* globalObject, const Vector<UString>& fileNames, bool prettyPrint, bool dump) 318 { 298 319 Vector<char> script; 299 320 … … 302 323 303 324 bool success = true; 304 305 325 for (size_t i = 0; i < fileNames.size(); i++) { 306 326 UString fileName = fileNames[i]; … … 325 345 } 326 346 347 static void runInteractive(GlobalObject* globalObject) 348 { 349 bool done = false; 350 while (!done) { 351 #if HAVE_READLINE 352 char* line = readline(interactivePrompt); 353 if (!line) 354 break; 355 if (line[0]) 356 add_history(line); 357 Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), interpreterName, 1, line); 358 free(line); 359 #else 360 printf(interactivePrompt); 361 Vector<char, 256> line; 362 int c; 363 while ((c = getchar()) != EOF) { 364 // FIXME: Should we also break on \r? 365 if (c == '\n') 366 break; 367 line.append(c); 368 } 369 line.append('\0'); 370 Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), interpreterName, 1, line.data()); 371 #endif 372 if (completion.isValueCompletion()) 373 printf("%s\n", completion.value()->toString(globalObject->globalExec()).UTF8String().c_str()); 374 } 375 } 376 327 377 static void printUsageStatement() 328 378 { 329 379 fprintf(stderr, "Usage: testkjs [options] [files] [-- arguments]\n"); 330 fprintf(stderr, " -f Specifies a source file (deprecated)\n"); 331 fprintf(stderr, " -p Prints formatted source code\n"); 332 fprintf(stderr, " -d Dumps bytecode (debug builds only)\n"); 333 fprintf(stderr, " -s Installs signal handlers that exit on a crash (Unix platforms only)\n"); 380 fprintf(stderr, " -d Dumps bytecode (debug builds only)\n"); 381 fprintf(stderr, " -f Specifies a source file (deprecated)\n"); 382 fprintf(stderr, " -h|--help Prints this help message\n"); 383 fprintf(stderr, " -i Enables interactive mode (default if no files are specified)\n"); 384 fprintf(stderr, " -p Prints formatted source code\n"); 385 fprintf(stderr, " -s Installs signal handlers that exit on a crash (Unix platforms only)\n"); 334 386 exit(-1); 335 387 } 336 388 337 static void parseArguments(int argc, char** argv, Vector<UString>& fileNames, Vector<UString>& arguments, bool& prettyPrint, bool& dump) 338 { 339 if (argc < 2) 340 printUsageStatement(); 341 389 static void parseArguments(int argc, char** argv, Options& options) 390 { 342 391 int i = 1; 343 392 for (; i < argc; ++i) { … … 346 395 if (++i == argc) 347 396 printUsageStatement(); 348 fileNames.append(argv[i]);397 options.fileNames.append(argv[i]); 349 398 continue; 350 399 } 400 if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) { 401 printUsageStatement(); 402 } 403 if (strcmp(arg, "-i") == 0) { 404 options.interactive = true; 405 continue; 406 } 351 407 if (strcmp(arg, "-p") == 0) { 352 prettyPrint = true;408 options.prettyPrint = true; 353 409 continue; 354 410 } 355 411 if (strcmp(arg, "-d") == 0) { 356 dump = true;412 options.dump = true; 357 413 continue; 358 414 } … … 370 426 break; 371 427 } 372 fileNames.append(argv[i]);428 options.fileNames.append(argv[i]); 373 429 } 374 430 375 if ( fileNames.isEmpty())376 printUsageStatement();431 if (options.fileNames.isEmpty()) 432 options.interactive = true; 377 433 378 434 for (; i < argc; ++i) 379 arguments.append(argv[i]);435 options.arguments.append(argv[i]); 380 436 } 381 437 … … 386 442 JSLock lock; 387 443 388 bool prettyPrint = false;389 bool dump = false;390 Vector<UString> fileNames; 391 Vector<UString> arguments;392 parseArguments(argc, argv, fileNames, arguments, prettyPrint,dump);393 394 bool success = runWithScripts(fileNames, arguments, prettyPrint, dump);444 Options options; 445 parseArguments(argc, argv, options); 446 447 GlobalObject* globalObject = new GlobalObject(options.arguments); 448 bool success = runWithScripts(globalObject, options.fileNames, options.prettyPrint, options.dump); 449 if (options.interactive && success) 450 runInteractive(globalObject); 395 451 396 452 #ifndef NDEBUG
Note:
See TracChangeset
for help on using the changeset viewer.