mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | 7f56978 | 2022-05-04 17:44:44 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008-2022 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" |
mark.lam@apple.com | 65a636f | 2014-02-01 01:24:39 +0000 | [diff] [blame] | 37 | #include "JSFunction.h" |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 38 | #include "JSWithScope.h" |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 39 | #include "ShadowChickenInlines.h" |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 40 | #include "StackVisitor.h" |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 41 | #include "StrongInlines.h" |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 42 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 43 | namespace JSC { |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 44 | |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 45 | class LineAndColumnFunctor { |
| 46 | public: |
mark.lam@apple.com | 7f56978 | 2022-05-04 17:44:44 +0000 | [diff] [blame] | 47 | IterationStatus operator()(StackVisitor& visitor) const |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 48 | { |
| 49 | visitor->computeLineAndColumn(m_line, m_column); |
mark.lam@apple.com | 7f56978 | 2022-05-04 17:44:44 +0000 | [diff] [blame] | 50 | return IterationStatus::Done; |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | unsigned line() const { return m_line; } |
| 54 | unsigned column() const { return m_column; } |
| 55 | |
| 56 | private: |
ddkilzer@apple.com | 137187c | 2018-07-01 00:06:38 +0000 | [diff] [blame] | 57 | mutable unsigned m_line { 0 }; |
| 58 | mutable unsigned m_column { 0 }; |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 61 | Ref<DebuggerCallFrame> DebuggerCallFrame::create(VM& vm, CallFrame* callFrame) |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 62 | { |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 63 | if (UNLIKELY(!callFrame)) { |
| 64 | ShadowChicken::Frame emptyFrame; |
| 65 | RELEASE_ASSERT(!emptyFrame.isTailDeleted); |
| 66 | return adoptRef(*new DebuggerCallFrame(vm, callFrame, emptyFrame)); |
| 67 | } |
| 68 | |
ysuzuki@apple.com | 8db58e8 | 2022-04-13 21:01:19 +0000 | [diff] [blame] | 69 | if (callFrame->isEmptyTopLevelCallFrameForDebugger()) { |
sbarati@apple.com | 867f884 | 2016-05-27 23:42:08 +0000 | [diff] [blame] | 70 | ShadowChicken::Frame emptyFrame; |
| 71 | RELEASE_ASSERT(!emptyFrame.isTailDeleted); |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 72 | return adoptRef(*new DebuggerCallFrame(vm, callFrame, emptyFrame)); |
sbarati@apple.com | 867f884 | 2016-05-27 23:42:08 +0000 | [diff] [blame] | 73 | } |
| 74 | |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 75 | Vector<ShadowChicken::Frame> frames; |
ysuzuki@apple.com | 0a83125 | 2019-01-29 04:33:33 +0000 | [diff] [blame] | 76 | vm.ensureShadowChicken(); |
| 77 | vm.shadowChicken()->iterate(vm, callFrame, [&] (const ShadowChicken::Frame& frame) -> bool { |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 78 | frames.append(frame); |
| 79 | return true; |
| 80 | }); |
| 81 | |
| 82 | RELEASE_ASSERT(frames.size()); |
sbarati@apple.com | ed3e9f5 | 2016-05-27 20:26:06 +0000 | [diff] [blame] | 83 | 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] | 84 | |
| 85 | RefPtr<DebuggerCallFrame> currentParent = nullptr; |
sbarati@apple.com | ed3e9f5 | 2016-05-27 20:26:06 +0000 | [diff] [blame] | 86 | // 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] | 87 | for (unsigned i = frames.size(); i--; ) { |
| 88 | const ShadowChicken::Frame& frame = frames[i]; |
| 89 | if (!frame.isTailDeleted) |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 90 | callFrame = frame.frame; |
| 91 | Ref<DebuggerCallFrame> currentFrame = adoptRef(*new DebuggerCallFrame(vm, callFrame, frame)); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 92 | currentFrame->m_caller = currentParent; |
| 93 | currentParent = WTFMove(currentFrame); |
| 94 | } |
| 95 | return *currentParent; |
| 96 | } |
| 97 | |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 98 | DebuggerCallFrame::DebuggerCallFrame(VM& vm, CallFrame* callFrame, const ShadowChicken::Frame& frame) |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 99 | : m_validMachineFrame(callFrame) |
| 100 | , m_shadowChickenFrame(frame) |
| 101 | { |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 102 | m_position = currentPosition(vm); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 103 | } |
| 104 | |
gyuyoung.kim@webkit.org | be3842f | 2015-06-13 03:52:06 +0000 | [diff] [blame] | 105 | RefPtr<DebuggerCallFrame> DebuggerCallFrame::callerFrame() |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 106 | { |
| 107 | ASSERT(isValid()); |
| 108 | if (!isValid()) |
gyuyoung.kim@webkit.org | be3842f | 2015-06-13 03:52:06 +0000 | [diff] [blame] | 109 | return nullptr; |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 110 | |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 111 | return m_caller; |
| 112 | } |
| 113 | |
ysuzuki@apple.com | 3b713e3 | 2022-04-14 21:56:27 +0000 | [diff] [blame] | 114 | JSGlobalObject* DebuggerCallFrame::globalObject(VM& vm) |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 115 | { |
ysuzuki@apple.com | 3b713e3 | 2022-04-14 21:56:27 +0000 | [diff] [blame] | 116 | return scope(vm)->globalObject(); |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 117 | } |
| 118 | |
mark.lam@apple.com | 26c5340 | 2013-11-08 20:03:50 +0000 | [diff] [blame] | 119 | SourceID DebuggerCallFrame::sourceID() const |
mark.lam@apple.com | 649480f | 2013-09-12 16:27:55 +0000 | [diff] [blame] | 120 | { |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 121 | ASSERT(isValid()); |
| 122 | if (!isValid()) |
mark.lam@apple.com | 26c5340 | 2013-11-08 20:03:50 +0000 | [diff] [blame] | 123 | return noSourceID; |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 124 | if (isTailDeleted()) |
ysuzuki@apple.com | c9db6aa | 2019-02-09 00:29:21 +0000 | [diff] [blame] | 125 | return m_shadowChickenFrame.codeBlock->ownerExecutable()->sourceID(); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 126 | return sourceIDForCallFrame(m_validMachineFrame); |
mark.lam@apple.com | 649480f | 2013-09-12 16:27:55 +0000 | [diff] [blame] | 127 | } |
| 128 | |
ysuzuki@apple.com | 3b713e3 | 2022-04-14 21:56:27 +0000 | [diff] [blame] | 129 | String DebuggerCallFrame::functionName(VM& vm) const |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 130 | { |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 131 | ASSERT(isValid()); |
| 132 | if (!isValid()) |
ggaren@apple.com | 0030e13 | 2012-09-12 06:14:56 +0000 | [diff] [blame] | 133 | return String(); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 134 | |
| 135 | if (isTailDeleted()) { |
ysuzuki@apple.com | 984775d | 2022-04-16 00:00:35 +0000 | [diff] [blame] | 136 | if (JSFunction* func = jsDynamicCast<JSFunction*>(m_shadowChickenFrame.callee)) |
keith_miller@apple.com | 45da760 | 2017-01-27 01:47:52 +0000 | [diff] [blame] | 137 | return func->calculatedDisplayName(vm); |
cdumez@apple.com | 78ea99a | 2022-04-06 19:05:23 +0000 | [diff] [blame] | 138 | return String::fromLatin1(m_shadowChickenFrame.codeBlock->inferredName().data()); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | return m_validMachineFrame->friendlyFunctionName(); |
aroben@apple.com | 261f1ff | 2009-05-15 18:13:28 +0000 | [diff] [blame] | 142 | } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 143 | |
ysuzuki@apple.com | 3b713e3 | 2022-04-14 21:56:27 +0000 | [diff] [blame] | 144 | DebuggerScope* DebuggerCallFrame::scope(VM& vm) |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 145 | { |
| 146 | ASSERT(isValid()); |
| 147 | if (!isValid()) |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 148 | return nullptr; |
mark.lam@apple.com | 65a636f | 2014-02-01 01:24:39 +0000 | [diff] [blame] | 149 | |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 150 | if (!m_scope) { |
msaboff@apple.com | 5e62e3f | 2014-11-21 23:41:26 +0000 | [diff] [blame] | 151 | JSScope* scope; |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 152 | CodeBlock* codeBlock = m_validMachineFrame->codeBlock(); |
| 153 | if (isTailDeleted()) |
| 154 | scope = m_shadowChickenFrame.scope; |
| 155 | else if (codeBlock && codeBlock->scopeRegister().isValid()) |
| 156 | scope = m_validMachineFrame->scope(codeBlock->scopeRegister().offset()); |
ysuzuki@apple.com | 984775d | 2022-04-16 00:00:35 +0000 | [diff] [blame] | 157 | else if (JSCallee* callee = jsDynamicCast<JSCallee*>(m_validMachineFrame->jsCallee())) |
msaboff@apple.com | 95c4315 | 2015-02-26 06:05:02 +0000 | [diff] [blame] | 158 | scope = callee->scope(); |
msaboff@apple.com | 5e62e3f | 2014-11-21 23:41:26 +0000 | [diff] [blame] | 159 | else |
ysuzuki@apple.com | 60f63df | 2019-10-24 05:34:21 +0000 | [diff] [blame] | 160 | scope = m_validMachineFrame->lexicalGlobalObject(vm)->globalLexicalEnvironment(); |
mark.lam@apple.com | 8fe56b8 | 2014-08-09 06:50:19 +0000 | [diff] [blame] | 161 | |
msaboff@apple.com | 5e62e3f | 2014-11-21 23:41:26 +0000 | [diff] [blame] | 162 | m_scope.set(vm, DebuggerScope::create(vm, scope)); |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 163 | } |
| 164 | return m_scope.get(); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 165 | } |
| 166 | |
ysuzuki@apple.com | 984775d | 2022-04-16 00:00:35 +0000 | [diff] [blame] | 167 | DebuggerCallFrame::Type DebuggerCallFrame::type(VM&) const |
timothy@apple.com | c14b52c | 2008-06-17 22:33:07 +0000 | [diff] [blame] | 168 | { |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 169 | ASSERT(isValid()); |
| 170 | if (!isValid()) |
| 171 | return ProgramType; |
| 172 | |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 173 | if (isTailDeleted()) |
| 174 | return FunctionType; |
| 175 | |
ysuzuki@apple.com | 984775d | 2022-04-16 00:00:35 +0000 | [diff] [blame] | 176 | if (jsDynamicCast<JSFunction*>(m_validMachineFrame->jsCallee())) |
timothy@apple.com | c14b52c | 2008-06-17 22:33:07 +0000 | [diff] [blame] | 177 | return FunctionType; |
| 178 | |
| 179 | return ProgramType; |
| 180 | } |
| 181 | |
ysuzuki@apple.com | 60f63df | 2019-10-24 05:34:21 +0000 | [diff] [blame] | 182 | JSValue DebuggerCallFrame::thisValue(VM& vm) const |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 183 | { |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 184 | ASSERT(isValid()); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 185 | if (!isValid()) |
| 186 | return jsUndefined(); |
| 187 | |
| 188 | CodeBlock* codeBlock = nullptr; |
| 189 | JSValue thisValue; |
| 190 | if (isTailDeleted()) { |
| 191 | thisValue = m_shadowChickenFrame.thisValue; |
| 192 | codeBlock = m_shadowChickenFrame.codeBlock; |
| 193 | } else { |
| 194 | thisValue = m_validMachineFrame->thisValue(); |
| 195 | codeBlock = m_validMachineFrame->codeBlock(); |
| 196 | } |
| 197 | |
| 198 | if (!thisValue) |
| 199 | return jsUndefined(); |
| 200 | |
tzagallo@apple.com | a6b8c34 | 2020-04-07 22:32:21 +0000 | [diff] [blame] | 201 | ECMAMode ecmaMode = ECMAMode::sloppy(); |
| 202 | if (codeBlock && codeBlock->ownerExecutable()->isInStrictContext()) |
| 203 | ecmaMode = ECMAMode::strict(); |
ysuzuki@apple.com | 60f63df | 2019-10-24 05:34:21 +0000 | [diff] [blame] | 204 | return thisValue.toThis(m_validMachineFrame->lexicalGlobalObject(vm), ecmaMode); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 205 | } |
| 206 | |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 207 | // Evaluate some JavaScript code in the scope of this frame. |
ysuzuki@apple.com | 3b713e3 | 2022-04-14 21:56:27 +0000 | [diff] [blame] | 208 | JSValue DebuggerCallFrame::evaluateWithScopeExtension(VM& vm, const String& script, JSObject* scopeExtensionObject, NakedPtr<Exception>& exception) |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 209 | { |
drousso@apple.com | 9d5c116 | 2020-09-03 17:53:21 +0000 | [diff] [blame] | 210 | CallFrame* callFrame = nullptr; |
| 211 | CodeBlock* codeBlock = nullptr; |
| 212 | |
| 213 | auto* debuggerCallFrame = this; |
| 214 | while (debuggerCallFrame) { |
| 215 | ASSERT(debuggerCallFrame->isValid()); |
| 216 | |
| 217 | callFrame = debuggerCallFrame->m_validMachineFrame; |
| 218 | if (callFrame) { |
| 219 | if (debuggerCallFrame->isTailDeleted()) |
| 220 | codeBlock = debuggerCallFrame->m_shadowChickenFrame.codeBlock; |
| 221 | else |
| 222 | codeBlock = callFrame->codeBlock(); |
| 223 | } |
| 224 | |
| 225 | if (callFrame && codeBlock) |
| 226 | break; |
| 227 | |
| 228 | debuggerCallFrame = debuggerCallFrame->m_caller.get(); |
| 229 | } |
| 230 | |
| 231 | if (!callFrame || !codeBlock) |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 232 | return jsUndefined(); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 233 | |
mark.lam@apple.com | 451de99 | 2016-09-07 22:10:50 +0000 | [diff] [blame] | 234 | JSLockHolder lock(vm); |
| 235 | auto catchScope = DECLARE_CATCH_SCOPE(vm); |
oliver@apple.com | ba10bec | 2011-03-08 23:17:32 +0000 | [diff] [blame] | 236 | |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 237 | JSGlobalObject* globalObject = codeBlock->globalObject(); |
| 238 | DebuggerEvalEnabler evalEnabler(globalObject, DebuggerEvalEnabler::Mode::EvalOnGlobalObjectAtDebuggerEntry); |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 239 | |
gskachkov@gmail.com | a3f0cdf | 2016-04-03 07:59:19 +0000 | [diff] [blame] | 240 | EvalContextType evalContextType; |
| 241 | |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 242 | if (isFunctionParseMode(codeBlock->unlinkedCodeBlock()->parseMode())) |
gskachkov@gmail.com | a3f0cdf | 2016-04-03 07:59:19 +0000 | [diff] [blame] | 243 | evalContextType = EvalContextType::FunctionEvalContext; |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 244 | else if (codeBlock->unlinkedCodeBlock()->codeType() == EvalCode) |
| 245 | evalContextType = codeBlock->unlinkedCodeBlock()->evalContextType(); |
gskachkov@gmail.com | a3f0cdf | 2016-04-03 07:59:19 +0000 | [diff] [blame] | 246 | else |
| 247 | evalContextType = EvalContextType::None; |
| 248 | |
sbarati@apple.com | 1ffc444 | 2020-10-28 19:25:14 +0000 | [diff] [blame] | 249 | TDZEnvironment variablesUnderTDZ; |
ticaiolima@gmail.com | c2ba2ac | 2021-02-09 16:30:24 +0000 | [diff] [blame] | 250 | PrivateNameEnvironment privateNameEnvironment; |
ysuzuki@apple.com | 3b713e3 | 2022-04-14 21:56:27 +0000 | [diff] [blame] | 251 | JSScope::collectClosureVariablesUnderTDZ(scope(vm)->jsScope(), variablesUnderTDZ, privateNameEnvironment); |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 252 | |
tzagallo@apple.com | a6b8c34 | 2020-04-07 22:32:21 +0000 | [diff] [blame] | 253 | ECMAMode ecmaMode = codeBlock->ownerExecutable()->isInStrictContext() ? ECMAMode::strict() : ECMAMode::sloppy(); |
ticaiolima@gmail.com | c2ba2ac | 2021-02-09 16:30:24 +0000 | [diff] [blame] | 254 | auto* eval = DirectEvalExecutable::create(globalObject, makeSource(script, callFrame->callerSourceOrigin(vm)), codeBlock->unlinkedCodeBlock()->derivedContextType(), codeBlock->unlinkedCodeBlock()->needsClassFieldInitializer(), codeBlock->unlinkedCodeBlock()->privateBrandRequirement(), codeBlock->unlinkedCodeBlock()->isArrowFunction(), codeBlock->ownerExecutable()->isInsideOrdinaryFunction(), evalContextType, &variablesUnderTDZ, &privateNameEnvironment, ecmaMode); |
mark.lam@apple.com | 451de99 | 2016-09-07 22:10:50 +0000 | [diff] [blame] | 255 | if (UNLIKELY(catchScope.exception())) { |
| 256 | exception = catchScope.exception(); |
| 257 | catchScope.clearException(); |
mark.lam@apple.com | 8f98b6b | 2014-01-25 03:15:13 +0000 | [diff] [blame] | 258 | return jsUndefined(); |
oliver@apple.com | ba10bec | 2011-03-08 23:17:32 +0000 | [diff] [blame] | 259 | } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 260 | |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 261 | if (scopeExtensionObject) { |
| 262 | JSScope* ignoredPreviousScope = globalObject->globalScope(); |
commit-queue@webkit.org | 30be13d | 2017-08-16 01:10:01 +0000 | [diff] [blame] | 263 | globalObject->setGlobalScopeExtension(JSWithScope::create(vm, globalObject, ignoredPreviousScope, scopeExtensionObject)); |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 264 | } |
| 265 | |
ysuzuki@apple.com | 3b713e3 | 2022-04-14 21:56:27 +0000 | [diff] [blame] | 266 | JSValue result = vm.interpreter->execute(eval, globalObject, debuggerCallFrame->thisValue(vm), debuggerCallFrame->scope(vm)->jsScope()); |
mark.lam@apple.com | 451de99 | 2016-09-07 22:10:50 +0000 | [diff] [blame] | 267 | if (UNLIKELY(catchScope.exception())) { |
| 268 | exception = catchScope.exception(); |
| 269 | catchScope.clearException(); |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 270 | } |
joepeck@webkit.org | 70d6a30 | 2016-05-10 19:16:19 +0000 | [diff] [blame] | 271 | |
| 272 | if (scopeExtensionObject) |
| 273 | globalObject->clearGlobalScopeExtension(); |
| 274 | |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 275 | ASSERT(result); |
| 276 | return result; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 277 | } |
| 278 | |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 279 | void DebuggerCallFrame::invalidate() |
mark.lam@apple.com | 649480f | 2013-09-12 16:27:55 +0000 | [diff] [blame] | 280 | { |
mark.lam@apple.com | 51d1315 | 2014-09-23 22:29:35 +0000 | [diff] [blame] | 281 | RefPtr<DebuggerCallFrame> frame = this; |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 282 | while (frame) { |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 283 | frame->m_validMachineFrame = nullptr; |
mark.lam@apple.com | 51d1315 | 2014-09-23 22:29:35 +0000 | [diff] [blame] | 284 | if (frame->m_scope) { |
| 285 | frame->m_scope->invalidateChain(); |
| 286 | frame->m_scope.clear(); |
| 287 | } |
krollin@apple.com | 77db180 | 2016-06-20 20:52:45 +0000 | [diff] [blame] | 288 | frame = WTFMove(frame->m_caller); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 292 | TextPosition DebuggerCallFrame::currentPosition(VM& vm) |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 293 | { |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 294 | if (!m_validMachineFrame) |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 295 | return TextPosition(); |
| 296 | |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 297 | if (isTailDeleted()) { |
| 298 | CodeBlock* codeBlock = m_shadowChickenFrame.codeBlock; |
darin@apple.com | a4ddc78 | 2021-05-30 16:11:40 +0000 | [diff] [blame] | 299 | if (std::optional<BytecodeIndex> bytecodeIndex = codeBlock->bytecodeIndexFromCallSiteIndex(m_shadowChickenFrame.callSiteIndex)) { |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 300 | return TextPosition(OrdinalNumber::fromOneBasedInt(codeBlock->lineNumberForBytecodeIndex(*bytecodeIndex)), |
| 301 | OrdinalNumber::fromOneBasedInt(codeBlock->columnNumberForBytecodeIndex(*bytecodeIndex))); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 305 | return positionForCallFrame(vm, m_validMachineFrame); |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 306 | } |
| 307 | |
sbarati@apple.com | 5db42f8 | 2017-04-04 22:23:37 +0000 | [diff] [blame] | 308 | TextPosition DebuggerCallFrame::positionForCallFrame(VM& vm, CallFrame* callFrame) |
sbarati@apple.com | ce5b05e | 2016-05-16 23:31:39 +0000 | [diff] [blame] | 309 | { |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 310 | LineAndColumnFunctor functor; |
ysuzuki@apple.com | 8db58e8 | 2022-04-13 21:01:19 +0000 | [diff] [blame] | 311 | if (!callFrame) |
| 312 | return TextPosition(OrdinalNumber::fromOneBasedInt(0), OrdinalNumber::fromOneBasedInt(0)); |
ysuzuki@apple.com | 638dc2a | 2019-10-22 21:23:26 +0000 | [diff] [blame] | 313 | StackVisitor::visit(callFrame, vm, functor); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 314 | return TextPosition(OrdinalNumber::fromOneBasedInt(functor.line()), OrdinalNumber::fromOneBasedInt(functor.column())); |
| 315 | } |
| 316 | |
mark.lam@apple.com | 26c5340 | 2013-11-08 20:03:50 +0000 | [diff] [blame] | 317 | SourceID DebuggerCallFrame::sourceIDForCallFrame(CallFrame* callFrame) |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 318 | { |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 319 | if (!callFrame) |
| 320 | return noSourceID; |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 321 | CodeBlock* codeBlock = callFrame->codeBlock(); |
tzagallo@apple.com | 9fd9b24 | 2019-11-08 00:37:52 +0000 | [diff] [blame] | 322 | if (!codeBlock || callFrame->callee().isWasm()) |
mark.lam@apple.com | 26c5340 | 2013-11-08 20:03:50 +0000 | [diff] [blame] | 323 | return noSourceID; |
ysuzuki@apple.com | c9db6aa | 2019-02-09 00:29:21 +0000 | [diff] [blame] | 324 | return codeBlock->ownerExecutable()->sourceID(); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 325 | } |
| 326 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 327 | } // namespace JSC |