Changeset 18337 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Dec 19, 2006, 10:52:38 PM (18 years ago)
Author:
andersca
Message:

Reviewed by Geoff.

Add -p option to testkjs which pretty prints the files instead of executing them.

  • JavaScriptCore.exp:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/Parser.cpp: (KJS::Parser::prettyPrint):
  • kjs/Parser.h:
  • kjs/testkjs.cpp: (doIt):
Location:
trunk/JavaScriptCore/kjs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/Parser.cpp

    r14256 r18337  
    110110}
    111111
     112UString Parser::prettyPrint(const UString& code)
     113{
     114    RefPtr<ProgramNode> progNode = parse(UString(), 0, code.data(), code.size());
     115    if (!progNode)
     116        return 0;
     117   
     118    return progNode->toString();
    112119}
     120
     121}
  • trunk/JavaScriptCore/kjs/Parser.h

    r17372 r18337  
    4949            int* sourceId = 0, int* errLine = 0, UString* errMsg = 0);
    5050
     51        static UString prettyPrint(const UString&);
     52       
    5153        static void accept(PassRefPtr<ProgramNode>);
    5254
  • trunk/JavaScriptCore/kjs/testkjs.cpp

    r17372 r18337  
    2929#include "JSLock.h"
    3030#include "object.h"
     31#include "Parser.h"
    3132
    3233#include <math.h>
     
    211212{
    212213  bool success = true;
     214  bool prettyPrint = false;
    213215  GlobalImp* global = new GlobalImp();
    214216
     
    233235    if (strcmp(fileName, "-f") == 0) // mozilla test driver script uses "-f" prefix for files
    234236      continue;
     237    if (strcmp(fileName, "-p") == 0) {
     238      prettyPrint = true;
     239      continue;
     240    }
    235241   
    236242    char* script = createStringWithContentsOfFile(fileName);
     
    240246    }
    241247   
    242     Completion completion = interp->evaluate(fileName, 0, script);
    243     success = success && completion.complType() != Throw;
     248    if (prettyPrint) {
     249      UString s = Parser::prettyPrint(script);
     250      if (s.isNull()) {
     251        success = false;
     252        break;
     253      }
     254     
     255      printf("%s\n", s.UTF8String().c_str());
     256     
     257    } else {
     258      Completion completion = interp->evaluate(fileName, 0, script);
     259      success = success && completion.complType() != Throw;
     260    }
     261   
    244262    free(script);
    245263  }
Note: See TracChangeset for help on using the changeset viewer.