summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/debugger
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
commit1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (patch)
tree4457a7306ea5acb43fe05bfe0973b1f7faf97ba2 /JavaScriptCore/debugger
parent9364f22aed35e1a1e9d07c121510f80be3ab0502 (diff)
downloadexternal_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.zip
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.gz
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'JavaScriptCore/debugger')
-rw-r--r--JavaScriptCore/debugger/Debugger.cpp54
-rw-r--r--JavaScriptCore/debugger/Debugger.h59
-rw-r--r--JavaScriptCore/debugger/DebuggerCallFrame.cpp82
-rw-r--r--JavaScriptCore/debugger/DebuggerCallFrame.h67
4 files changed, 262 insertions, 0 deletions
diff --git a/JavaScriptCore/debugger/Debugger.cpp b/JavaScriptCore/debugger/Debugger.cpp
new file mode 100644
index 0000000..a52a542
--- /dev/null
+++ b/JavaScriptCore/debugger/Debugger.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
+ * Copyright (C) 2001 Peter Kelly (pmk@post.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "config.h"
+#include "Debugger.h"
+
+#include "JSGlobalObject.h"
+
+namespace JSC {
+
+Debugger::Debugger()
+{
+}
+
+Debugger::~Debugger()
+{
+ HashSet<JSGlobalObject*>::iterator end = m_globalObjects.end();
+ for (HashSet<JSGlobalObject*>::iterator it = m_globalObjects.begin(); it != end; ++it)
+ (*it)->setDebugger(0);
+}
+
+void Debugger::attach(JSGlobalObject* globalObject)
+{
+ ASSERT(!globalObject->debugger());
+ globalObject->setDebugger(this);
+ m_globalObjects.add(globalObject);
+}
+
+void Debugger::detach(JSGlobalObject* globalObject)
+{
+ ASSERT(m_globalObjects.contains(globalObject));
+ m_globalObjects.remove(globalObject);
+ globalObject->setDebugger(0);
+}
+
+} // namespace JSC
diff --git a/JavaScriptCore/debugger/Debugger.h b/JavaScriptCore/debugger/Debugger.h
new file mode 100644
index 0000000..4a6a9b3
--- /dev/null
+++ b/JavaScriptCore/debugger/Debugger.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
+ * Copyright (C) 2001 Peter Kelly (pmk@post.com)
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef Debugger_h
+#define Debugger_h
+
+#include "protect.h"
+
+namespace JSC {
+
+ class DebuggerCallFrame;
+ class ExecState;
+ class JSGlobalObject;
+ class SourceCode;
+ class UString;
+
+ class Debugger {
+ public:
+ Debugger();
+ virtual ~Debugger();
+
+ void attach(JSGlobalObject*);
+ void detach(JSGlobalObject*);
+
+ virtual void sourceParsed(ExecState*, const SourceCode&, int errorLine, const UString& errorMsg) = 0;
+ virtual void exception(const DebuggerCallFrame&, intptr_t sourceID, int lineno) = 0;
+ virtual void atStatement(const DebuggerCallFrame&, intptr_t sourceID, int lineno) = 0;
+ virtual void callEvent(const DebuggerCallFrame&, intptr_t sourceID, int lineno) = 0;
+ virtual void returnEvent(const DebuggerCallFrame&, intptr_t sourceID, int lineno) = 0;
+
+ virtual void willExecuteProgram(const DebuggerCallFrame&, intptr_t sourceID, int lineno) = 0;
+ virtual void didExecuteProgram(const DebuggerCallFrame&, intptr_t sourceID, int lineno) = 0;
+ virtual void didReachBreakpoint(const DebuggerCallFrame&, intptr_t sourceID, int lineno) = 0;
+
+ private:
+ HashSet<JSGlobalObject*> m_globalObjects;
+ };
+
+} // namespace JSC
+
+#endif // Debugger_h
diff --git a/JavaScriptCore/debugger/DebuggerCallFrame.cpp b/JavaScriptCore/debugger/DebuggerCallFrame.cpp
new file mode 100644
index 0000000..ae62cd3
--- /dev/null
+++ b/JavaScriptCore/debugger/DebuggerCallFrame.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DebuggerCallFrame.h"
+
+#include "JSFunction.h"
+#include "CodeBlock.h"
+#include "Machine.h"
+#include "Parser.h"
+
+namespace JSC {
+
+const UString* DebuggerCallFrame::functionName() const
+{
+ if (!m_callFrame->codeBlock())
+ return 0;
+
+ JSFunction* function = static_cast<JSFunction*>(m_callFrame->callee());
+ if (!function)
+ return 0;
+ return &function->name(&m_callFrame->globalData());
+}
+
+DebuggerCallFrame::Type DebuggerCallFrame::type() const
+{
+ if (m_callFrame->callee())
+ return FunctionType;
+
+ return ProgramType;
+}
+
+JSObject* DebuggerCallFrame::thisObject() const
+{
+ if (!m_callFrame->codeBlock())
+ return 0;
+
+ // FIXME: Why is it safe to assume this is an object?
+ return asObject(m_callFrame->thisValue());
+}
+
+JSValue* DebuggerCallFrame::evaluate(const UString& script, JSValue*& exception) const
+{
+ if (!m_callFrame->codeBlock())
+ return noValue();
+
+ int errLine;
+ UString errMsg;
+ SourceCode source = makeSource(script);
+ RefPtr<EvalNode> evalNode = m_callFrame->scopeChain()->globalData->parser->parse<EvalNode>(m_callFrame, m_callFrame->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
+ if (!evalNode)
+ return Error::create(m_callFrame, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url());
+
+ return m_callFrame->scopeChain()->globalData->machine->execute(evalNode.get(), m_callFrame, thisObject(), m_callFrame->scopeChain(), &exception);
+}
+
+} // namespace JSC
diff --git a/JavaScriptCore/debugger/DebuggerCallFrame.h b/JavaScriptCore/debugger/DebuggerCallFrame.h
new file mode 100644
index 0000000..8326b20
--- /dev/null
+++ b/JavaScriptCore/debugger/DebuggerCallFrame.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DebuggerCallFrame_h
+#define DebuggerCallFrame_h
+
+#include "ExecState.h"
+
+namespace JSC {
+
+ class DebuggerCallFrame {
+ public:
+ enum Type { ProgramType, FunctionType };
+
+ DebuggerCallFrame(CallFrame* callFrame)
+ : m_callFrame(callFrame)
+ , m_exception(noValue())
+ {
+ }
+
+ DebuggerCallFrame(CallFrame* callFrame, JSValue* exception)
+ : m_callFrame(callFrame)
+ , m_exception(exception)
+ {
+ }
+
+ JSGlobalObject* dynamicGlobalObject() const { return m_callFrame->dynamicGlobalObject(); }
+ const ScopeChainNode* scopeChain() const { return m_callFrame->scopeChain(); }
+ const UString* functionName() const;
+ Type type() const;
+ JSObject* thisObject() const;
+ JSValue* evaluate(const UString&, JSValue*& exception) const;
+ JSValue* exception() const { return m_exception; }
+
+ private:
+ CallFrame* m_callFrame;
+ JSValue* m_exception;
+ };
+
+} // namespace JSC
+
+#endif // DebuggerCallFrame_h