Ignore:
Timestamp:
May 21, 2008, 6:20:45 PM (17 years ago)
Author:
[email protected]
Message:

Merge squirrelfish branch into trunk.

File:
1 edited

Legend:

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

    r33038 r33979  
    2323#include "config.h"
    2424
     25#include "CodeGenerator.h"
    2526#include "JSGlobalObject.h"
    2627#include "JSLock.h"
     
    184185        return throwError(exec, GeneralError, "Could not open file.");
    185186
     187    JSGlobalObject* globalObject = exec->dynamicGlobalObject();
     188
    186189    stopWatch.start();
    187     Interpreter::evaluate(exec->dynamicGlobalObject()->globalExec(), fileName, 0, script.data());
     190    Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), fileName, 0, script.data());
    188191    stopWatch.stop();
    189192
     
    198201        return throwError(exec, GeneralError, "Could not open file.");
    199202
    200     Interpreter::evaluate(exec->dynamicGlobalObject()->globalExec(), fileName, 0, script.data());
     203    JSGlobalObject* globalObject = exec->dynamicGlobalObject();
     204    Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), fileName, 0, script.data());
    201205
    202206    return jsUndefined();
     
    259263}
    260264
    261 static bool prettyPrintScript(const UString& fileName, const Vector<char>& script)
     265static bool prettyPrintScript(ExecState* exec, const UString& fileName, const Vector<char>& script)
    262266{
    263267    int errLine = 0;
    264268    UString errMsg;
    265269    UString scriptUString(script.data());
    266     RefPtr<ProgramNode> programNode = parser().parse<ProgramNode>(fileName, 0, scriptUString.data(), scriptUString.size(), 0, &errLine, &errMsg);
     270    RefPtr<ProgramNode> programNode = parser().parse<ProgramNode>(exec, fileName, 0, UStringSourceProvider::create(scriptUString), 0, &errLine, &errMsg);
    267271    if (!programNode) {
    268272        fprintf(stderr, "%s:%d: %s.\n", fileName.UTF8String().c_str(), errLine, errMsg.UTF8String().c_str());
     
    274278}
    275279
    276 static bool runWithScripts(const Vector<UString>& fileNames, Vector<UString>& arguments, bool prettyPrint)
     280static bool runWithScripts(const Vector<UString>& fileNames, Vector<UString>& arguments, bool prettyPrint, bool dump)
    277281{
    278282    GlobalObject* globalObject = new GlobalObject(arguments);
    279283    Vector<char> script;
    280284
     285    if (dump)
     286        CodeGenerator::setDumpsGeneratedCode(true);
     287
    281288    bool success = true;
    282289
     
    288295
    289296        if (prettyPrint)
    290             prettyPrintScript(fileName, script);
     297            prettyPrintScript(globalObject->globalExec(), fileName, script);
    291298        else {
    292             Completion completion = Interpreter::evaluate(globalObject->globalExec(), fileName, 0, script.data());
     299            Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), fileName, 0, script.data());
    293300            success = success && completion.complType() != Throw;
     301            if (dump) {
     302                if (success)
     303                    printf("End: %s\n", completion.value()->toString(globalObject->globalExec()).ascii());
     304                else
     305                    printf("Exception: %s\n", completion.value()->toString(globalObject->globalExec()).ascii());
     306            }
    294307        }
    295308    }
     
    303316}
    304317
    305 static void parseArguments(int argc, char** argv, Vector<UString>& fileNames, Vector<UString>& arguments, bool& prettyPrint)
     318static void parseArguments(int argc, char** argv, Vector<UString>& fileNames, Vector<UString>& arguments, bool& prettyPrint, bool& dump)
    306319{
    307320    if (argc < 3)
     
    321334            continue;
    322335        }
     336        if (strcmp(arg, "-d") == 0) {
     337            dump = true;
     338            continue;
     339        }
     340        if (strcmp(arg, "-s") == 0) {
     341#if PLATFORM(UNIX)
     342            signal(SIGILL, _exit);
     343            signal(SIGFPE, _exit);
     344            signal(SIGBUS, _exit);
     345            signal(SIGSEGV, _exit);
     346#endif
     347            continue;
     348        }
    323349        if (strcmp(arg, "--") == 0) {
    324350            ++i;
     
    339365
    340366    bool prettyPrint = false;
     367    bool dump = false;
    341368    Vector<UString> fileNames;
    342369    Vector<UString> arguments;
    343     parseArguments(argc, argv, fileNames, arguments, prettyPrint);
    344 
    345     bool success = runWithScripts(fileNames, arguments, prettyPrint);
     370    parseArguments(argc, argv, fileNames, arguments, prettyPrint, dump);
     371
     372    bool success = runWithScripts(fileNames, arguments, prettyPrint, dump);
    346373
    347374#ifndef NDEBUG
Note: See TracChangeset for help on using the changeset viewer.