2 * Copyright (C) 2008, 2013, 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "DebuggerCallFrame.h"
32 #include "CodeBlock.h"
33 #include "Interpreter.h"
34 #include "JSActivation.h"
35 #include "JSFunction.h"
36 #include "JSCInlines.h"
38 #include "StackVisitor.h"
42 class LineAndColumnFunctor
{
44 StackVisitor::Status
operator()(StackVisitor
& visitor
)
46 visitor
->computeLineAndColumn(m_line
, m_column
);
47 return StackVisitor::Done
;
50 unsigned line() const { return m_line
; }
51 unsigned column() const { return m_column
; }
58 DebuggerCallFrame::DebuggerCallFrame(CallFrame
* callFrame
)
59 : m_callFrame(callFrame
)
61 m_position
= positionForCallFrame(m_callFrame
);
64 PassRefPtr
<DebuggerCallFrame
> DebuggerCallFrame::callerFrame()
73 CallFrame
* callerFrame
= m_callFrame
->callerFrameSkippingVMEntrySentinel();
77 m_caller
= DebuggerCallFrame::create(callerFrame
);
81 JSC::JSGlobalObject
* DebuggerCallFrame::vmEntryGlobalObject() const
86 return m_callFrame
->vmEntryGlobalObject();
89 SourceID
DebuggerCallFrame::sourceID() const
94 return sourceIDForCallFrame(m_callFrame
);
97 String
DebuggerCallFrame::functionName() const
102 JSObject
* function
= m_callFrame
->callee();
106 return getCalculatedDisplayName(m_callFrame
, function
);
109 JSScope
* DebuggerCallFrame::scope() const
115 CodeBlock
* codeBlock
= m_callFrame
->codeBlock();
116 if (codeBlock
&& codeBlock
->needsActivation() && !m_callFrame
->hasActivation()) {
117 JSActivation
* activation
= JSActivation::create(*codeBlock
->vm(), m_callFrame
, codeBlock
);
118 m_callFrame
->setActivation(activation
);
119 m_callFrame
->setScope(activation
);
122 return m_callFrame
->scope();
125 DebuggerCallFrame::Type
DebuggerCallFrame::type() const
131 if (m_callFrame
->callee())
137 JSValue
DebuggerCallFrame::thisValue() const
140 return thisValueForCallFrame(m_callFrame
);
143 // Evaluate some JavaScript code in the scope of this frame.
144 JSValue
DebuggerCallFrame::evaluate(const String
& script
, JSValue
& exception
)
147 CallFrame
* callFrame
= m_callFrame
;
151 JSLockHolder
lock(callFrame
);
153 if (!callFrame
->codeBlock())
156 VM
& vm
= callFrame
->vm();
157 EvalExecutable
* eval
= EvalExecutable::create(callFrame
, makeSource(script
), callFrame
->codeBlock()->isStrictMode());
158 if (vm
.exception()) {
159 exception
= vm
.exception();
161 return jsUndefined();
164 JSValue thisValue
= thisValueForCallFrame(callFrame
);
165 JSValue result
= vm
.interpreter
->execute(eval
, callFrame
, thisValue
, scope());
166 if (vm
.exception()) {
167 exception
= vm
.exception();
174 void DebuggerCallFrame::invalidate()
176 m_callFrame
= nullptr;
177 RefPtr
<DebuggerCallFrame
> frame
= m_caller
.release();
179 frame
->m_callFrame
= nullptr;
180 frame
= frame
->m_caller
.release();
184 TextPosition
DebuggerCallFrame::positionForCallFrame(CallFrame
* callFrame
)
187 return TextPosition();
189 LineAndColumnFunctor functor
;
190 callFrame
->iterate(functor
);
191 return TextPosition(OrdinalNumber::fromOneBasedInt(functor
.line()), OrdinalNumber::fromOneBasedInt(functor
.column()));
194 SourceID
DebuggerCallFrame::sourceIDForCallFrame(CallFrame
* callFrame
)
197 CodeBlock
* codeBlock
= callFrame
->codeBlock();
200 return codeBlock
->ownerExecutable()->sourceID();
203 JSValue
DebuggerCallFrame::thisValueForCallFrame(CallFrame
* callFrame
)
208 ECMAMode ecmaMode
= NotStrictMode
;
209 CodeBlock
* codeBlock
= callFrame
->codeBlock();
210 if (codeBlock
&& codeBlock
->isStrictMode())
211 ecmaMode
= StrictMode
;
212 JSValue thisValue
= callFrame
->thisValue().toThis(callFrame
, ecmaMode
);