mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 39303e0 | 2016-04-05 22:17:35 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008, 2013-2014, 2016 Apple Inc. All rights reserved. |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 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. |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 14 | * its contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 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. |
| 27 | */ |
| 28 | |
| 29 | #include "config.h" |
| 30 | #include "DebuggerCallFrame.h" |
| 31 | |
annulen@yandex.ru | 6712c2d | 2017-06-25 17:40:30 +0000 | [diff] [blame] | 32 | #include "CatchScope.h" |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 33 | #include "CodeBlock.h" |
commit-queue@webkit.org | 31d2ef0 | 2014-09-05 21:08:14 +0000 | [diff] [blame] | 34 | #include "DebuggerEvalEnabler.h" |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 35 | #include "DebuggerScope.h" |
ggaren@apple.com | 901a8a2 | 2008-11-17 20:57:18 +0000 | [diff] [blame] | 36 | #include "Interpreter.h" |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 37 | #include "JSCInlines.h" |
mark.lam@apple.com | 65a636f | 2014-02-01 01:24:39 +0000 | [diff] [blame] | 38 | #include "JSFunction.h" |
oliver@apple.com | a7dfb4d | 2014-09-11 18:18:14 +0000 | [diff] [blame] | 39 | #include "JSLexicalEnvironment.h" |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 40 | #include "JSWithScope.h" |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 41 | #include "Parser.h" |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 42 | #include "ShadowChickenInlines.h" |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 43 | #include "StackVisitor.h" |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 44 | #include "StrongInlines.h" |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 45 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 46 | namespace JSC { |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 47 | |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 48 | class LineAndColumnFunctor { |
| 49 | public: |
fpizlo@apple.com | 39303e0 | 2016-04-05 22:17:35 +0000 | [diff] [blame] | 50 | StackVisitor::Status operator()(StackVisitor& visitor) const |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 51 | { |
| 52 | visitor->computeLineAndColumn(m_line, m_column); |
| 53 | return StackVisitor::Done; |
| 54 | } |
| 55 | |
| 56 | unsigned line() const { return m_line; } |
| 57 | unsigned column() const { return m_column; } |
| 58 | |
| 59 | private: |
ddkilzer@apple.com | 137187c | 2018-07-01 00:06:38 +0000 | [diff] [blame] | 60 | mutable unsigned m_line { 0 }; |
| 61 | mutable unsigned m_column { 0 }; |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 64 | Ref<DebuggerCallFrame> DebuggerCallFrame::create(VM& vm, CallFrame* callFrame) |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 65 | { |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 66 | if (UNLIKELY(callFrame == callFrame->wasmAwareLexicalGlobalObject(vm)->globalExec())) { |
sbarati@apple.com | 867f884 | 2016-05-27 23:42:08 +0000 | [diff] [blame] | 67 | ShadowChicken::Frame emptyFrame; |
| 68 | RELEASE_ASSERT(!emptyFrame.isTailDeleted); |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 69 | return adoptRef(*new DebuggerCallFrame(vm, callFrame, emptyFrame)); |
sbarati@apple.com | 867f884 | 2016-05-27 23:42:08 +0000 | [diff] [blame] | 70 | } |
| 71 | |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 72 | Vector<ShadowChicken::Frame> frames; |
ysuzuki@apple.com | 0a83125 | 2019-01-29 04:33:33 +0000 | [diff] [blame^] | 73 | vm.ensureShadowChicken(); |
| 74 | vm.shadowChicken()->iterate(vm, callFrame, [&] (const ShadowChicken::Frame& frame) -> bool { |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 75 | frames.append(frame); |
| 76 | return true; |
| 77 | }); |
| 78 | |
| 79 | RELEASE_ASSERT(frames.size()); |
sbarati@apple.com | ed3e9f5 | 2016-05-27 20:26:06 +0000 | [diff] [blame] | 80 | ASSERT(!frames[0].isTailDeleted); // The top frame should never be tail deleted. |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 81 | |
| 82 | RefPtr<DebuggerCallFrame> currentParent = nullptr; |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 83 | ExecState* exec = callFrame->wasmAwareLexicalGlobalObject(vm)->globalExec(); |
sbarati@apple.com | ed3e9f5 | 2016-05-27 20:26:06 +0000 | [diff] [blame] | 84 | // This walks the stack from the entry stack frame to the top of the stack. |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 85 | for (unsigned i = frames.size(); i--; ) { |
| 86 | const ShadowChicken::Frame& frame = frames[i]; |
| 87 | if (!frame.isTailDeleted) |
| 88 | exec = frame.frame; |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 89 | Ref<DebuggerCallFrame> currentFrame = adoptRef(*new DebuggerCallFrame(vm, exec, frame)); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 90 | currentFrame->m_caller = currentParent; |
| 91 | currentParent = WTFMove(currentFrame); |
| 92 | } |
| 93 | return *currentParent; |
| 94 | } |
| 95 | |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 96 | DebuggerCallFrame::DebuggerCallFrame(VM& vm, CallFrame* callFrame, const ShadowChicken::Frame& frame) |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 97 | : m_validMachineFrame(callFrame) |
| 98 | , m_shadowChickenFrame(frame) |
| 99 | { |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 100 | m_position = currentPosition(vm); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 101 | } |
| 102 | |
gyuyoung.kim@webkit.org | be3842f | 2015-06-13 03:52:06 +0000 | [diff] [blame] | 103 | RefPtr<DebuggerCallFrame> DebuggerCallFrame::callerFrame() |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 104 | { |
| 105 | ASSERT(isValid()); |
| 106 | if (!isValid()) |
gyuyoung.kim@webkit.org | be3842f | 2015-06-13 03:52:06 +0000 | [diff] [blame] | 107 | return nullptr; |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 108 | |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 109 | return m_caller; |
| 110 | } |
| 111 | |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 112 | ExecState* DebuggerCallFrame::globalExec() |
| 113 | { |
| 114 | return scope()->globalObject()->globalExec(); |
| 115 | } |
| 116 | |
mark.lam@apple.com | 3072125 | 2013-11-21 05:29:42 +0000 | [diff] [blame] | 117 | JSC::JSGlobalObject* DebuggerCallFrame::vmEntryGlobalObject() const |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 118 | { |
| 119 | ASSERT(isValid()); |
| 120 | if (!isValid()) |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 121 | return nullptr; |
mark.lam@apple.com | 3816a30 | 2018-08-23 22:57:09 +0000 | [diff] [blame] | 122 | VM& vm = m_validMachineFrame->vm(); |
| 123 | return vm.vmEntryGlobalObject(m_validMachineFrame); |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 124 | } |
| 125 | |
mark.lam@apple.com | 26c5340 | 2013-11-08 20:03:50 +0000 | [diff] [blame] | 126 | SourceID DebuggerCallFrame::sourceID() const |
mark.lam@apple.com | 649480f | 2013-09-12 16:27:55 +0000 | [diff] [blame] | 127 | { |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 128 | ASSERT(isValid()); |
| 129 | if (!isValid()) |
mark.lam@apple.com | 26c5340 | 2013-11-08 20:03:50 +0000 | [diff] [blame] | 130 | return noSourceID; |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 131 | if (isTailDeleted()) |
| 132 | return m_shadowChickenFrame.codeBlock->ownerScriptExecutable()->sourceID(); |
| 133 | return sourceIDForCallFrame(m_validMachineFrame); |
mark.lam@apple.com | 649480f | 2013-09-12 16:27:55 +0000 | [diff] [blame] | 134 | } |
| 135 | |
ggaren@apple.com | 0030e13 | 2012-09-12 06:14:56 +0000 | [diff] [blame] | 136 | String DebuggerCallFrame::functionName() const |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 137 | { |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 138 | ASSERT(isValid()); |
| 139 | if (!isValid()) |
ggaren@apple.com | 0030e13 | 2012-09-12 06:14:56 +0000 | [diff] [blame] | 140 | return String(); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 141 | |
keith_miller@apple.com | 45da760 | 2017-01-27 01:47:52 +0000 | [diff] [blame] | 142 | VM& vm = m_validMachineFrame->vm(); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 143 | if (isTailDeleted()) { |
keith_miller@apple.com | 45da760 | 2017-01-27 01:47:52 +0000 | [diff] [blame] | 144 | if (JSFunction* func = jsDynamicCast<JSFunction*>(vm, m_shadowChickenFrame.callee)) |
| 145 | return func->calculatedDisplayName(vm); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 146 | return m_shadowChickenFrame.codeBlock->inferredName().data(); |
| 147 | } |
| 148 | |
| 149 | return m_validMachineFrame->friendlyFunctionName(); |
aroben@apple.com | 261f1ff | 2009-05-15 18:13:28 +0000 | [diff] [blame] | 150 | } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 151 | |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 152 | DebuggerScope* DebuggerCallFrame::scope() |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 153 | { |
| 154 | ASSERT(isValid()); |
| 155 | if (!isValid()) |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 156 | return nullptr; |
mark.lam@apple.com | 65a636f | 2014-02-01 01:24:39 +0000 | [diff] [blame] | 157 | |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 158 | if (!m_scope) { |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 159 | VM& vm = m_validMachineFrame->vm(); |
msaboff@apple.com | 5e62e3f | 2014-11-21 23:41:26 +0000 | [diff] [blame] | 160 | JSScope* scope; |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 161 | CodeBlock* codeBlock = m_validMachineFrame->codeBlock(); |
| 162 | if (isTailDeleted()) |
| 163 | scope = m_shadowChickenFrame.scope; |
| 164 | else if (codeBlock && codeBlock->scopeRegister().isValid()) |
| 165 | scope = m_validMachineFrame->scope(codeBlock->scopeRegister().offset()); |
keith_miller@apple.com | 45da760 | 2017-01-27 01:47:52 +0000 | [diff] [blame] | 166 | else if (JSCallee* callee = jsDynamicCast<JSCallee*>(vm, m_validMachineFrame->jsCallee())) |
msaboff@apple.com | 95c4315 | 2015-02-26 06:05:02 +0000 | [diff] [blame] | 167 | scope = callee->scope(); |
msaboff@apple.com | 5e62e3f | 2014-11-21 23:41:26 +0000 | [diff] [blame] | 168 | else |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 169 | scope = m_validMachineFrame->lexicalGlobalObject()->globalLexicalEnvironment(); |
mark.lam@apple.com | 8fe56b8 | 2014-08-09 06:50:19 +0000 | [diff] [blame] | 170 | |
msaboff@apple.com | 5e62e3f | 2014-11-21 23:41:26 +0000 | [diff] [blame] | 171 | m_scope.set(vm, DebuggerScope::create(vm, scope)); |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 172 | } |
| 173 | return m_scope.get(); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 174 | } |
| 175 | |
timothy@apple.com | c14b52c | 2008-06-17 22:33:07 +0000 | [diff] [blame] | 176 | DebuggerCallFrame::Type DebuggerCallFrame::type() const |
| 177 | { |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 178 | ASSERT(isValid()); |
| 179 | if (!isValid()) |
| 180 | return ProgramType; |
| 181 | |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 182 | if (isTailDeleted()) |
| 183 | return FunctionType; |
| 184 | |
keith_miller@apple.com | 45da760 | 2017-01-27 01:47:52 +0000 | [diff] [blame] | 185 | if (jsDynamicCast<JSFunction*>(m_validMachineFrame->vm(), m_validMachineFrame->jsCallee())) |
timothy@apple.com | c14b52c | 2008-06-17 22:33:07 +0000 | [diff] [blame] | 186 | return FunctionType; |
| 187 | |
| 188 | return ProgramType; |
| 189 | } |
| 190 | |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 191 | JSValue DebuggerCallFrame::thisValue() const |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 192 | { |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 193 | ASSERT(isValid()); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 194 | if (!isValid()) |
| 195 | return jsUndefined(); |
| 196 | |
| 197 | CodeBlock* codeBlock = nullptr; |
| 198 | JSValue thisValue; |
| 199 | if (isTailDeleted()) { |
| 200 | thisValue = m_shadowChickenFrame.thisValue; |
| 201 | codeBlock = m_shadowChickenFrame.codeBlock; |
| 202 | } else { |
| 203 | thisValue = m_validMachineFrame->thisValue(); |
| 204 | codeBlock = m_validMachineFrame->codeBlock(); |
| 205 | } |
| 206 | |
| 207 | if (!thisValue) |
| 208 | return jsUndefined(); |
| 209 | |
| 210 | ECMAMode ecmaMode = NotStrictMode; |
| 211 | if (codeBlock && codeBlock->isStrictMode()) |
| 212 | ecmaMode = StrictMode; |
| 213 | return thisValue.toThis(m_validMachineFrame, ecmaMode); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 214 | } |
| 215 | |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 216 | // Evaluate some JavaScript code in the scope of this frame. |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 217 | JSValue DebuggerCallFrame::evaluateWithScopeExtension(const String& script, JSObject* scopeExtensionObject, NakedPtr<Exception>& exception) |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 218 | { |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 219 | ASSERT(isValid()); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 220 | CallFrame* callFrame = m_validMachineFrame; |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 221 | if (!callFrame) |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 222 | return jsUndefined(); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 223 | |
mark.lam@apple.com | 451de99 | 2016-09-07 22:10:50 +0000 | [diff] [blame] | 224 | VM& vm = callFrame->vm(); |
| 225 | JSLockHolder lock(vm); |
| 226 | auto catchScope = DECLARE_CATCH_SCOPE(vm); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 227 | |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 228 | CodeBlock* codeBlock = nullptr; |
| 229 | if (isTailDeleted()) |
| 230 | codeBlock = m_shadowChickenFrame.codeBlock; |
| 231 | else |
| 232 | codeBlock = callFrame->codeBlock(); |
| 233 | if (!codeBlock) |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 234 | return jsUndefined(); |
oliver@apple.com | ba10bec | 2011-03-08 23:17:32 +0000 | [diff] [blame] | 235 | |
commit-queue@webkit.org | de3c7af | 2019-01-09 00:39:45 +0000 | [diff] [blame] | 236 | DebuggerEvalEnabler evalEnabler(callFrame, DebuggerEvalEnabler::Mode::EvalOnCallFrameAtDebuggerEntry); |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 237 | |
gskachkov@gmail.com | a3f0cdf | 2016-04-03 07:59:19 +0000 | [diff] [blame] | 238 | EvalContextType evalContextType; |
| 239 | |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 240 | if (isFunctionParseMode(codeBlock->unlinkedCodeBlock()->parseMode())) |
gskachkov@gmail.com | a3f0cdf | 2016-04-03 07:59:19 +0000 | [diff] [blame] | 241 | evalContextType = EvalContextType::FunctionEvalContext; |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 242 | else if (codeBlock->unlinkedCodeBlock()->codeType() == EvalCode) |
| 243 | evalContextType = codeBlock->unlinkedCodeBlock()->evalContextType(); |
gskachkov@gmail.com | a3f0cdf | 2016-04-03 07:59:19 +0000 | [diff] [blame] | 244 | else |
| 245 | evalContextType = EvalContextType::None; |
| 246 | |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 247 | VariableEnvironment variablesUnderTDZ; |
ggaren@apple.com | d31d16d | 2016-11-14 22:57:12 +0000 | [diff] [blame] | 248 | JSScope::collectClosureVariablesUnderTDZ(scope()->jsScope(), variablesUnderTDZ); |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 249 | |
utatane.tea@gmail.com | c4ec8e2 | 2016-12-26 06:35:07 +0000 | [diff] [blame] | 250 | auto* eval = DirectEvalExecutable::create(callFrame, makeSource(script, callFrame->callerSourceOrigin()), codeBlock->isStrictMode(), codeBlock->unlinkedCodeBlock()->derivedContextType(), codeBlock->unlinkedCodeBlock()->isArrowFunction(), evalContextType, &variablesUnderTDZ); |
mark.lam@apple.com | 451de99 | 2016-09-07 22:10:50 +0000 | [diff] [blame] | 251 | if (UNLIKELY(catchScope.exception())) { |
| 252 | exception = catchScope.exception(); |
| 253 | catchScope.clearException(); |
mark.lam@apple.com | 8f98b6b | 2014-01-25 03:15:13 +0000 | [diff] [blame] | 254 | return jsUndefined(); |
oliver@apple.com | ba10bec | 2011-03-08 23:17:32 +0000 | [diff] [blame] | 255 | } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 256 | |
mark.lam@apple.com | 3816a30 | 2018-08-23 22:57:09 +0000 | [diff] [blame] | 257 | JSGlobalObject* globalObject = vm.vmEntryGlobalObject(callFrame); |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 258 | if (scopeExtensionObject) { |
| 259 | JSScope* ignoredPreviousScope = globalObject->globalScope(); |
commit-queue@webkit.org | 30be13d | 2017-08-16 01:10:01 +0000 | [diff] [blame] | 260 | globalObject->setGlobalScopeExtension(JSWithScope::create(vm, globalObject, ignoredPreviousScope, scopeExtensionObject)); |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 261 | } |
| 262 | |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 263 | JSValue thisValue = this->thisValue(); |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 264 | JSValue result = vm.interpreter->execute(eval, callFrame, thisValue, scope()->jsScope()); |
mark.lam@apple.com | 451de99 | 2016-09-07 22:10:50 +0000 | [diff] [blame] | 265 | if (UNLIKELY(catchScope.exception())) { |
| 266 | exception = catchScope.exception(); |
| 267 | catchScope.clearException(); |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 268 | } |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 269 | |
| 270 | if (scopeExtensionObject) |
| 271 | globalObject->clearGlobalScopeExtension(); |
| 272 | |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 273 | ASSERT(result); |
| 274 | return result; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 275 | } |
| 276 | |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 277 | void DebuggerCallFrame::invalidate() |
mark.lam@apple.com | 649480f | 2013-09-12 16:27:55 +0000 | [diff] [blame] | 278 | { |
mark.lam@apple.com | 51d1315 | 2014-09-23 22:29:35 +0000 | [diff] [blame] | 279 | RefPtr<DebuggerCallFrame> frame = this; |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 280 | while (frame) { |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 281 | frame->m_validMachineFrame = nullptr; |
mark.lam@apple.com | 51d1315 | 2014-09-23 22:29:35 +0000 | [diff] [blame] | 282 | if (frame->m_scope) { |
| 283 | frame->m_scope->invalidateChain(); |
| 284 | frame->m_scope.clear(); |
| 285 | } |
krollin@apple.com | 77db180 | 2016-06-20 20:52:45 +0000 | [diff] [blame] | 286 | frame = WTFMove(frame->m_caller); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 290 | TextPosition DebuggerCallFrame::currentPosition(VM& vm) |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 291 | { |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 292 | if (!m_validMachineFrame) |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 293 | return TextPosition(); |
| 294 | |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 295 | if (isTailDeleted()) { |
| 296 | CodeBlock* codeBlock = m_shadowChickenFrame.codeBlock; |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 297 | if (Optional<unsigned> bytecodeOffset = codeBlock->bytecodeOffsetFromCallSiteIndex(m_shadowChickenFrame.callSiteIndex)) { |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 298 | return TextPosition(OrdinalNumber::fromOneBasedInt(codeBlock->lineNumberForBytecodeOffset(*bytecodeOffset)), |
| 299 | OrdinalNumber::fromOneBasedInt(codeBlock->columnNumberForBytecodeOffset(*bytecodeOffset))); |
| 300 | } |
| 301 | } |
| 302 | |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 303 | return positionForCallFrame(vm, m_validMachineFrame); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 304 | } |
| 305 | |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 306 | TextPosition DebuggerCallFrame::positionForCallFrame(VM& vm, CallFrame* callFrame) |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 307 | { |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 308 | LineAndColumnFunctor functor; |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 309 | StackVisitor::visit(callFrame, &vm, functor); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 310 | return TextPosition(OrdinalNumber::fromOneBasedInt(functor.line()), OrdinalNumber::fromOneBasedInt(functor.column())); |
| 311 | } |
| 312 | |
mark.lam@apple.com | 26c5340 | 2013-11-08 20:03:50 +0000 | [diff] [blame] | 313 | SourceID DebuggerCallFrame::sourceIDForCallFrame(CallFrame* callFrame) |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 314 | { |
| 315 | ASSERT(callFrame); |
| 316 | CodeBlock* codeBlock = callFrame->codeBlock(); |
| 317 | if (!codeBlock) |
mark.lam@apple.com | 26c5340 | 2013-11-08 20:03:50 +0000 | [diff] [blame] | 318 | return noSourceID; |
commit-queue@webkit.org | fa19663 | 2015-08-28 21:07:22 +0000 | [diff] [blame] | 319 | return codeBlock->ownerScriptExecutable()->sourceID(); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 320 | } |
| 321 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 322 | } // namespace JSC |