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/interpreter.cpp

    r31949 r33979  
    2626#include "ExecState.h"
    2727#include "JSGlobalObject.h"
     28#include "Machine.h"
    2829#include "Parser.h"
    2930#include "debugger.h"
     
    3940Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UString& code)
    4041{
    41     return checkSyntax(exec, sourceURL, startingLineNumber, code.data(), code.size());
     42    return checkSyntax(exec, sourceURL, startingLineNumber, UStringSourceProvider::create(code));
    4243}
    4344
    44 Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength)
     45Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source)
    4546{
    4647    JSLock lock;
     
    4849    int errLine;
    4950    UString errMsg;
    50     RefPtr<ProgramNode> progNode = parser().parse<ProgramNode>(sourceURL, startingLineNumber, code, codeLength, 0, &errLine, &errMsg);
     51
     52    RefPtr<ProgramNode> progNode = parser().parse<ProgramNode>(exec, sourceURL, startingLineNumber, source, 0, &errLine, &errMsg);
    5153    if (!progNode)
    5254        return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, 0, sourceURL));
     
    5456}
    5557
    56 Completion Interpreter::evaluate(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)
     58Completion Interpreter::evaluate(ExecState* exec, ScopeChain& scopeChain, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)
    5759{
    58     return evaluate(exec, sourceURL, startingLineNumber, code.data(), code.size(), thisV);
     60    return evaluate(exec, scopeChain, sourceURL, startingLineNumber, UStringSourceProvider::create(code), thisV);
    5961}
    6062
    61 Completion Interpreter::evaluate(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV)
     63Completion Interpreter::evaluate(ExecState* exec, ScopeChain& scopeChain, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source, JSValue* thisValue)
    6264{
    6365    JSLock lock;
    64    
    65     JSGlobalObject* globalObject = exec->dynamicGlobalObject();
    66 
    67     if (globalObject->recursion() >= 20)
    68         return Completion(Throw, Error::create(exec, GeneralError, "Recursion too deep"));
    6966   
    7067    // parse the source code
     
    7774#endif
    7875
    79     RefPtr<ProgramNode> progNode = parser().parse<ProgramNode>(sourceURL, startingLineNumber, code, codeLength, &sourceId, &errLine, &errMsg);
    80    
    81     // notify debugger that source has been parsed
    82     if (globalObject->debugger()) {
    83         bool cont = globalObject->debugger()->sourceParsed(exec, sourceId, sourceURL, UString(code, codeLength), startingLineNumber, errLine, errMsg);
    84         if (!cont)
    85             return Completion(Break);
    86     }
    87    
     76    RefPtr<ProgramNode> programNode = parser().parse<ProgramNode>(exec, sourceURL, startingLineNumber, source, &sourceId, &errLine, &errMsg);
     77
    8878    // no program node means a syntax error occurred
    89     if (!progNode)
     79    if (!programNode)
    9080        return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, sourceId, sourceURL));
    91    
    92     exec->clearException();
    93    
    94     globalObject->incRecursion();
    95    
    96     JSObject* thisObj = globalObject;
    97    
    98     // "this" must be an object... use same rules as Function.prototype.apply()
    99     if (thisV && !thisV->isUndefinedOrNull())
    100         thisObj = thisV->toObject(exec);
    101    
    102     Completion res;
    103     if (exec->hadException())
    104         // the thisV->toObject() conversion above might have thrown an exception - if so, propagate it
    105         res = Completion(Throw, exec->exception());
    106     else {
    107         // execute the code
    108         InterpreterExecState newExec(globalObject, thisObj, progNode.get());
    109         JSValue* value = progNode->execute(&newExec);
    110         res = Completion(newExec.completionType(), value);
    111     }
     81
     82    JSObject* thisObj = (!thisValue || thisValue->isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue->toObject(exec);
     83
     84    JSValue* exception = 0;
     85    JSValue* result = machine().execute(programNode.get(), exec, scopeChain.node(), thisObj, &exec->dynamicGlobalObject()->registerFileStack(), &exception);
    11286
    11387#if JAVASCRIPT_PROFILING
    114         Profiler::profiler()->didExecute(exec, sourceURL, startingLineNumber);
     88    Profiler::profiler()->didExecute(exec, sourceURL, startingLineNumber);
    11589#endif
    11690
    117     globalObject->decRecursion();
    118    
    119     if (shouldPrintExceptions() && res.complType() == Throw) {
    120         JSLock lock;
    121         ExecState* exec = globalObject->globalExec();
    122         CString f = sourceURL.UTF8String();
    123         CString message = res.value()->toObject(exec)->toString(exec).UTF8String();
    124         int line = res.value()->toObject(exec)->get(exec, "line")->toUInt32(exec);
    125 #if PLATFORM(WIN_OS)
    126         printf("%s line %d: %s\n", f.c_str(), line, message.c_str());
    127 #else
    128         printf("[%d] %s line %d: %s\n", getpid(), f.c_str(), line, message.c_str());
    129 #endif
    130     }
    131 
    132     return res;
     91    return exception ? Completion(Throw, exception) : Completion(Normal, result);
    13392}
    13493
Note: See TracChangeset for help on using the changeset viewer.