Changeset 27031 in webkit


Ignore:
Timestamp:
Oct 25, 2007 2:08:51 AM (16 years ago)
Author:
eseidel
Message:

2007-10-25 Eric Seidel <eric@webkit.org>

Reviewed by Maciej.


More preparation work before adding long-running mode to testkjs.

  • kjs/testkjs.cpp: (TestFunctionImp::callAsFunction): (prettyPrintScript): (runWithScripts): (parseArguments): (kjsmain): (fillBufferWithContentsOfFile):
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r27029 r27031  
     12007-10-25  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Maciej.
     4       
     5        More preparation work before adding long-running mode to testkjs.
     6
     7        * kjs/testkjs.cpp:
     8        (TestFunctionImp::callAsFunction):
     9        (prettyPrintScript):
     10        (runWithScripts):
     11        (parseArguments):
     12        (kjsmain):
     13        (fillBufferWithContentsOfFile):
     14
    1152007-10-25  Eric Seidel  <eric@webkit.org>
    216
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r27028 r27031  
    13801380                        isa = PBXProject;
    13811381                        buildConfigurationList = 149C277108902AFE008A9EFC /* Build configuration list for PBXProject "JavaScriptCore" */;
    1382                         compatibilityVersion = "Xcode 2.4";
    13831382                        hasScannedForEncodings = 1;
    13841383                        mainGroup = 0867D691FE84028FC02AAC07 /* JavaScriptCore */;
  • trunk/JavaScriptCore/kjs/testkjs.cpp

    r27029 r27031  
    5353
    5454static void testIsInteger();
    55 static bool fillBufferWithContentsOfFile(const char* fileName, Vector<char>& buffer);
     55static bool fillBufferWithContentsOfFile(const UString& fileName, Vector<char>& buffer);
    5656
    5757class StopWatch
     
    160160      UString fileName = args[0]->toString(exec);
    161161      Vector<char> script;
    162       if (!fillBufferWithContentsOfFile(fileName.UTF8String().c_str(), script))
     162      if (!fillBufferWithContentsOfFile(fileName, script))
    163163        return throwError(exec, GeneralError, "Could not open file.");
    164164
     
    173173      UString fileName = args[0]->toString(exec);
    174174      Vector<char> script;
    175       if (!fillBufferWithContentsOfFile(fileName.UTF8String().c_str(), script))
     175      if (!fillBufferWithContentsOfFile(fileName, script))
    176176        return throwError(exec, GeneralError, "Could not open file.");
    177177
     
    188188}
    189189
    190 #if PLATFORM(WIN_OS)
    191 
    192190// Use SEH for Release builds only to get rid of the crash report dialog
    193 // (luckyly the same tests fail in Release and Debug builds so far). Need to
     191// (luckily the same tests fail in Release and Debug builds so far). Need to
    194192// be in a separate main function because the kjsmain function requires object
    195193// unwinding.
    196194
    197 #if defined(_DEBUG)
     195#if PLATFORM(WIN_OS) && !defined(_DEBUG)
     196#define TRY       __try {
     197#define EXCEPT(x) } __except (EXCEPTION_EXECUTE_HANDLER) { x; }
     198#else
    198199#define TRY
    199200#define EXCEPT(x)
    200 #else
    201 #define TRY       __try {
    202 #define EXCEPT(x) } __except (EXCEPTION_EXECUTE_HANDLER) { x; }
    203 #endif
    204 
    205 #else
    206 
    207 #define TRY
    208 #define EXCEPT(x)
    209 
    210201#endif
    211202
     
    251242}
    252243
    253 static bool prettyPrintScript(const char* fileName, const Vector<char>& script)
     244static bool prettyPrintScript(const UString& fileName, const Vector<char>& script)
    254245{
    255246  int errLine = 0;
     
    257248  UString s = Parser::prettyPrint(script.data(), &errLine, &errMsg);
    258249  if (s.isNull()) {
    259     fprintf(stderr, "%s:%d: %s.\n", fileName, errLine, errMsg.UTF8String().c_str());
     250    fprintf(stderr, "%s:%d: %s.\n", fileName.UTF8String().c_str(), errLine, errMsg.UTF8String().c_str());
    260251    return false;
    261252  }
     
    265256}
    266257
    267 static bool doIt(int argc, char** argv)
    268 {
    269   bool success = true;
    270   bool prettyPrint = false;
    271 
     258static bool runWithScripts(const Vector<UString>& fileNames, bool prettyPrint)
     259{
    272260  RefPtr<Interpreter> interp = setupInterpreter();
    273261  Vector<char> script;
     262 
     263  bool success = true;
     264 
     265  for (size_t i = 0; i < fileNames.size(); i++) {
     266    UString fileName = fileNames[i];
     267   
     268    if (!fillBufferWithContentsOfFile(fileName, script))
     269      return false; // fail early so we can catch missing files
     270   
     271    if (prettyPrint)
     272      prettyPrintScript(fileName, script);
     273    else {
     274      Completion completion = interp->evaluate(fileName, 0, script.data());
     275      success = success && completion.complType() != Throw;
     276    }
     277  }
     278  return success;
     279}
     280
     281static void parseArguments(int argc, char** argv, Vector<UString>& fileNames, bool& prettyPrint)
     282{
     283  if (argc < 2) {
     284    fprintf(stderr, "Usage: testkjs file1 [file2...]\n");
     285    exit(-1);
     286  }
    274287 
    275288  for (int i = 1; i < argc; i++) {
     
    281294      continue;
    282295    }
    283    
    284     script.clear();
    285     if (!fillBufferWithContentsOfFile(fileName, script)) {
    286       success = false;
    287       break; // fail early so we can catch missing files
    288     }
    289    
    290     if (prettyPrint)
    291       prettyPrintScript(fileName, script);
    292     else {
    293       Completion completion = interp->evaluate(fileName, 0, script.data());
    294       success = success && completion.complType() != Throw;
    295     }
    296   }
    297 
    298   return success;
    299 }
    300 
     296    fileNames.append(fileName);
     297  }
     298}
    301299
    302300int kjsmain(int argc, char** argv)
    303301{
    304   if (argc < 2) {
    305     fprintf(stderr, "Usage: testkjs file1 [file2...]\n");
    306     return -1;
    307   }
    308 
    309302  testIsInteger();
    310303
    311304  JSLock lock;
    312 
    313   bool success = doIt(argc, argv);
     305 
     306  bool prettyPrint = false;
     307  Vector<UString> fileNames;
     308  parseArguments(argc, argv, fileNames, prettyPrint);
     309 
     310  bool success = runWithScripts(fileNames, prettyPrint);
    314311
    315312#ifndef NDEBUG
     
    349346}
    350347
    351 static bool fillBufferWithContentsOfFile(const char* fileName, Vector<char>& buffer)
    352 {
    353   FILE* f = fopen(fileName, "r");
     348static bool fillBufferWithContentsOfFile(const UString& fileName, Vector<char>& buffer)
     349{
     350  FILE* f = fopen(fileName.UTF8String().c_str(), "r");
    354351  if (!f) {
    355     fprintf(stderr, "Could not open file: %s\n", fileName);
     352    fprintf(stderr, "Could not open file: %s\n", fileName.UTF8String().c_str());
    356353    return false;
    357354  }
Note: See TracChangeset for help on using the changeset viewer.