JSValue* DebuggerCallFrame::evaluate(const UString& script, JSValue*& exception) const { if (!m_codeBlock) return 0; JSObject* thisObject = this->thisObject(); ExecState newExec(m_scopeChain->globalObject(), thisObject, m_scopeChain); int sourceId; int errLine; UString errMsg; RefPtr<SourceProvider> sourceProvider = UStringSourceProvider::create(script); RefPtr<EvalNode> evalNode = newExec.parser()->parse<EvalNode>(&newExec, UString(), 1, sourceProvider, &sourceId, &errLine, &errMsg); if (!evalNode) return Error::create(&newExec, SyntaxError, errMsg, errLine, sourceId, 0); return newExec.machine()->execute(evalNode.get(), &newExec, thisObject, m_scopeChain, &exception); }
Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV) { JSLock lock; // prevent against infinite recursion if (m_recursion >= 20) return Completion(Throw, Error::create(&m_globalExec, GeneralError, "Recursion too deep")); // parse the source code int sid; int errLine; UString errMsg; RefPtr<ProgramNode> progNode = Parser::parse(sourceURL, startingLineNumber, code, codeLength, &sid, &errLine, &errMsg); // notify debugger that source has been parsed if (m_debugger) { bool cont = m_debugger->sourceParsed(&m_globalExec, sid, sourceURL, UString(code, codeLength), startingLineNumber, errLine, errMsg); if (!cont) return Completion(Break); } // no program node means a syntax error occurred if (!progNode) return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, sid, sourceURL)); m_globalExec.clearException(); m_recursion++; JSObject* globalObj = m_globalObject; JSObject* thisObj = globalObj; // "this" must be an object... use same rules as Function.prototype.apply() if (thisV && !thisV->isUndefinedOrNull()) thisObj = thisV->toObject(&m_globalExec); Completion res; if (m_globalExec.hadException()) // the thisV->toObject() conversion above might have thrown an exception - if so, propagate it res = Completion(Throw, m_globalExec.exception()); else { // execute the code Context ctx(globalObj, this, thisObj, progNode.get()); ExecState newExec(this, &ctx); ctx.setExecState(&newExec); progNode->processVarDecls(&newExec); res = progNode->execute(&newExec); } m_recursion--; if (shouldPrintExceptions() && res.complType() == Throw) { JSLock lock; ExecState* exec = globalExec(); CString f = sourceURL.UTF8String(); CString message = res.value()->toObject(exec)->toString(exec).UTF8String(); int line = res.value()->toObject(exec)->get(exec, "line")->toUInt32(exec); #if PLATFORM(WIN_OS) printf("%s line %d: %s\n", f.c_str(), line, message.c_str()); #else printf("[%d] %s line %d: %s\n", getpid(), f.c_str(), line, message.c_str()); #endif } return res; }