Changeset 33979 in webkit for trunk/JavaScriptCore/kjs/interpreter.cpp
- Timestamp:
- May 21, 2008, 6:20:45 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/interpreter.cpp
r31949 r33979 26 26 #include "ExecState.h" 27 27 #include "JSGlobalObject.h" 28 #include "Machine.h" 28 29 #include "Parser.h" 29 30 #include "debugger.h" … … 39 40 Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UString& code) 40 41 { 41 return checkSyntax(exec, sourceURL, startingLineNumber, code.data(), code.size());42 return checkSyntax(exec, sourceURL, startingLineNumber, UStringSourceProvider::create(code)); 42 43 } 43 44 44 Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength)45 Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source) 45 46 { 46 47 JSLock lock; … … 48 49 int errLine; 49 50 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); 51 53 if (!progNode) 52 54 return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, 0, sourceURL)); … … 54 56 } 55 57 56 Completion Interpreter::evaluate(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)58 Completion Interpreter::evaluate(ExecState* exec, ScopeChain& scopeChain, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV) 57 59 { 58 return evaluate(exec, s ourceURL, startingLineNumber, code.data(), code.size(), thisV);60 return evaluate(exec, scopeChain, sourceURL, startingLineNumber, UStringSourceProvider::create(code), thisV); 59 61 } 60 62 61 Completion Interpreter::evaluate(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV)63 Completion Interpreter::evaluate(ExecState* exec, ScopeChain& scopeChain, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source, JSValue* thisValue) 62 64 { 63 65 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"));69 66 70 67 // parse the source code … … 77 74 #endif 78 75 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 88 78 // no program node means a syntax error occurred 89 if (!prog Node)79 if (!programNode) 90 80 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); 112 86 113 87 #if JAVASCRIPT_PROFILING 114 88 Profiler::profiler()->didExecute(exec, sourceURL, startingLineNumber); 115 89 #endif 116 90 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); 133 92 } 134 93
Note:
See TracChangeset
for help on using the changeset viewer.