X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/9dae56ea45a0f5f8136a5c93d6f3a7f99399ca73..8b637bb680022adfddad653280734877951535a9:/debugger/Debugger.cpp?ds=inline diff --git a/debugger/Debugger.cpp b/debugger/Debugger.cpp index da1cb3d..0f0b31d 100644 --- a/debugger/Debugger.cpp +++ b/debugger/Debugger.cpp @@ -22,16 +22,86 @@ #include "config.h" #include "Debugger.h" -#include "JSGlobalObject.h" +#include "Error.h" #include "Interpreter.h" +#include "JSFunction.h" +#include "JSGlobalObject.h" +#include "Operations.h" #include "Parser.h" +#include "Protect.h" -namespace JSC { +namespace { + +using namespace JSC; + +class Recompiler : public MarkedBlock::VoidFunctor { +public: +#if PLATFORM(IOS) + Recompiler(JSC::Debugger*); +#else + Recompiler(Debugger*); +#endif + ~Recompiler(); + void operator()(JSCell*); + +private: + typedef HashSet FunctionExecutableSet; + typedef HashMap SourceProviderMap; + +#if PLATFORM(IOS) + JSC::Debugger* m_debugger; +#else + Debugger* m_debugger; +#endif + FunctionExecutableSet m_functionExecutables; + SourceProviderMap m_sourceProviders; +}; -Debugger::Debugger() +#if PLATFORM(IOS) +inline Recompiler::Recompiler(JSC::Debugger* debugger) +#else +inline Recompiler::Recompiler(Debugger* debugger) +#endif + : m_debugger(debugger) { } +inline Recompiler::~Recompiler() +{ + // Call sourceParsed() after reparsing all functions because it will execute + // JavaScript in the inspector. + SourceProviderMap::const_iterator end = m_sourceProviders.end(); + for (SourceProviderMap::const_iterator iter = m_sourceProviders.begin(); iter != end; ++iter) + m_debugger->sourceParsed(iter->value, iter->key, -1, String()); +} + +inline void Recompiler::operator()(JSCell* cell) +{ + if (!cell->inherits(&JSFunction::s_info)) + return; + + JSFunction* function = jsCast(cell); + if (function->executable()->isHostFunction()) + return; + + FunctionExecutable* executable = function->jsExecutable(); + + // Check if the function is already in the set - if so, + // we've already retranslated it, nothing to do here. + if (!m_functionExecutables.add(executable).isNewEntry) + return; + + ExecState* exec = function->scope()->globalObject()->JSGlobalObject::globalExec(); + executable->clearCodeIfNotCompiling(); + executable->clearUnlinkedCodeForRecompilationIfNotCompiling(); + if (m_debugger == function->scope()->globalObject()->debugger()) + m_sourceProviders.add(executable->source().provider(), exec); +} + +} // namespace + +namespace JSC { + Debugger::~Debugger() { HashSet::iterator end = m_globalObjects.end(); @@ -53,18 +123,37 @@ void Debugger::detach(JSGlobalObject* globalObject) globalObject->setDebugger(0); } -JSValuePtr evaluateInGlobalCallFrame(const UString& script, JSValuePtr& exception, JSGlobalObject* globalObject) +void Debugger::recompileAllJSFunctions(VM* vm) +{ + // If JavaScript is running, it's not safe to recompile, since we'll end + // up throwing away code that is live on the stack. + ASSERT(!vm->dynamicGlobalObject); + if (vm->dynamicGlobalObject) + return; + + Recompiler recompiler(this); + vm->heap.objectSpace().forEachLiveCell(recompiler); +} + +JSValue evaluateInGlobalCallFrame(const String& script, JSValue& exception, JSGlobalObject* globalObject) { CallFrame* globalCallFrame = globalObject->globalExec(); + VM& vm = globalObject->vm(); - int errLine; - UString errMsg; - SourceCode source = makeSource(script); - RefPtr evalNode = globalObject->globalData()->parser->parse(globalCallFrame, globalObject->debugger(), source, &errLine, &errMsg); - if (!evalNode) - return Error::create(globalCallFrame, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url()); + EvalExecutable* eval = EvalExecutable::create(globalCallFrame, vm.codeCache(), makeSource(script), false); + if (!eval) { + exception = vm.exception; + vm.exception = JSValue(); + return exception; + } - return globalObject->globalData()->interpreter->execute(evalNode.get(), globalCallFrame, globalObject, globalCallFrame->scopeChain(), &exception); + JSValue result = vm.interpreter->execute(eval, globalCallFrame, globalObject, globalCallFrame->scope()); + if (vm.exception) { + exception = vm.exception; + vm.exception = JSValue(); + } + ASSERT(result); + return result; } } // namespace JSC