blob: eb686fed2cec4195e6ed7bebef104655b292c620 [file] [log] [blame]
ggaren01b2e772006-06-13 06:08:52 +00001/*
ggaren01b2e772006-06-13 06:08:52 +00002 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
mark.lam@apple.com65a636f2014-02-01 01:24:39 +00004 * Copyright (C) 2003, 2007, 2008, 2011, 2013, 2014 Apple Inc. All rights reserved.
ggaren01b2e772006-06-13 06:08:52 +00005 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
ggaren@apple.com5169fc92008-11-17 22:11:26 +000023#ifndef CallFrame_h
24#define CallFrame_h
darin@apple.com8c2bac02008-10-09 00:40:43 +000025
fpizlo@apple.come8a38be2012-01-27 01:15:16 +000026#include "AbstractPC.h"
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000027#include "VM.h"
mark.lam@apple.com4fbb9c32012-10-09 07:12:56 +000028#include "JSStack.h"
ggaren@apple.com11760a72010-05-19 23:24:31 +000029#include "MacroAssemblerCodeRef.h"
fpizlo@apple.coma4b4cbe2013-01-12 04:47:03 +000030#include "Register.h"
mark.lam@apple.comfa2a1422013-09-05 00:40:15 +000031#include "StackVisitor.h"
ggaren01b2e772006-06-13 06:08:52 +000032
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000033namespace JSC {
mjse58111c2007-10-26 08:32:40 +000034
darin@apple.com8c2bac02008-10-09 00:40:43 +000035 class Arguments;
36 class JSActivation;
ggaren@apple.coma268c782008-11-17 21:51:09 +000037 class Interpreter;
ggaren@apple.comb11e7872012-08-30 22:50:00 +000038 class JSScope;
darin@apple.comd3f46402008-10-04 21:12:54 +000039
darin@apple.com41343c32008-01-26 18:55:52 +000040 // Represents the current state of script execution.
41 // Passed as the first argument to most functions.
darin@apple.com8c2bac02008-10-09 00:40:43 +000042 class ExecState : private Register {
mjse58111c2007-10-26 08:32:40 +000043 public:
mark.lam@apple.com4fbb9c32012-10-09 07:12:56 +000044 JSValue calleeAsValue() const { return this[JSStack::Callee].jsValue(); }
45 JSObject* callee() const { return this[JSStack::Callee].function(); }
46 CodeBlock* codeBlock() const { return this[JSStack::CodeBlock].Register::codeBlock(); }
ggaren@apple.comb11e7872012-08-30 22:50:00 +000047 JSScope* scope() const
oliver@apple.comfb4bbbc2009-12-04 02:17:46 +000048 {
mark.lam@apple.com4fbb9c32012-10-09 07:12:56 +000049 ASSERT(this[JSStack::ScopeChain].Register::scope());
50 return this[JSStack::ScopeChain].Register::scope();
oliver@apple.comfb4bbbc2009-12-04 02:17:46 +000051 }
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000052
mark.lam@apple.com65a636f2014-02-01 01:24:39 +000053 bool hasActivation() const { return !!uncheckedActivation(); }
54 JSActivation* activation() const;
mark.lam@apple.com8355b382014-02-01 02:42:30 +000055 JSValue uncheckedActivation() const;
mark.lam@apple.com65a636f2014-02-01 01:24:39 +000056
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000057 // Global object in which execution began.
mark.lam@apple.com30721252013-11-21 05:29:42 +000058 JS_EXPORT_PRIVATE JSGlobalObject* vmEntryGlobalObject();
darin@apple.com3d73fee2008-10-03 21:39:16 +000059
darin@apple.comd3f46402008-10-04 21:12:54 +000060 // Global object in which the currently executing code was defined.
mark.lam@apple.coma0b59db2013-11-22 21:09:25 +000061 // Differs from vmEntryGlobalObject() during function calls across web browser frames.
ggaren@apple.com1281f322012-08-30 23:36:41 +000062 JSGlobalObject* lexicalGlobalObject() const;
darin@apple.com3d73fee2008-10-03 21:39:16 +000063
darin@apple.comd3f46402008-10-04 21:12:54 +000064 // Differs from lexicalGlobalObject because this will have DOM window shell rather than
darin@apple.com8c2bac02008-10-09 00:40:43 +000065 // the actual DOM window, which can't be "this" for security reasons.
ggaren@apple.com1281f322012-08-30 23:36:41 +000066 JSObject* globalThisValue() const;
darin@apple.com3d73fee2008-10-03 21:39:16 +000067
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000068 VM& vm() const;
ap@webkit.org5b30cfc2008-06-07 06:03:24 +000069
darin@apple.comd3f46402008-10-04 21:12:54 +000070 // Convenience functions for access to global data.
darin@apple.com8c2bac02008-10-09 00:40:43 +000071 // It takes a few memory references to get from a call frame to the global data
72 // pointer, so these are inefficient, and should be used sparingly in new code.
73 // But they're used in many places in legacy code, so they're not going away any time soon.
darin@apple.comd3f46402008-10-04 21:12:54 +000074
commit-queue@webkit.org3f922f92013-08-29 00:28:42 +000075 void clearException() { vm().clearException(); }
oliver@apple.com5683d162013-04-07 18:47:20 +000076 void clearSupplementaryExceptionInfo()
77 {
oliver@apple.com90a10c52013-05-16 00:29:25 +000078 vm().clearExceptionStack();
oliver@apple.com5683d162013-04-07 18:47:20 +000079 }
80
commit-queue@webkit.org3f922f92013-08-29 00:28:42 +000081 JSValue exception() const { return vm().exception(); }
oliver@apple.com02fe0142013-08-30 18:30:41 +000082 bool hadException() const { return !vm().exception().isEmpty(); }
darin@apple.comd3f46402008-10-04 21:12:54 +000083
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000084 const CommonIdentifiers& propertyNames() const { return *vm().propertyNames; }
85 const MarkedArgumentBuffer& emptyList() const { return *vm().emptyList; }
86 Interpreter* interpreter() { return vm().interpreter; }
87 Heap* heap() { return &vm().heap; }
oliver@apple.com4476dcc2009-04-30 21:38:01 +000088#ifndef NDEBUG
89 void dumpCaller();
90#endif
oliver@apple.com10825da2014-01-25 01:03:40 +000091 static const HashTable& arrayConstructorTable(VM& vm) { return *vm.arrayConstructorTable; }
92 static const HashTable& arrayPrototypeTable(VM& vm) { return *vm.arrayPrototypeTable; }
93 static const HashTable& booleanPrototypeTable(VM& vm) { return *vm.booleanPrototypeTable; }
94 static const HashTable& dataViewTable(VM& vm) { return *vm.dataViewTable; }
95 static const HashTable& dateTable(VM& vm) { return *vm.dateTable; }
96 static const HashTable& dateConstructorTable(VM& vm) { return *vm.dateConstructorTable; }
97 static const HashTable& errorPrototypeTable(VM& vm) { return *vm.errorPrototypeTable; }
98 static const HashTable& globalObjectTable(VM& vm) { return *vm.globalObjectTable; }
99 static const HashTable& jsonTable(VM& vm) { return *vm.jsonTable; }
100 static const HashTable& numberConstructorTable(VM& vm) { return *vm.numberConstructorTable; }
101 static const HashTable& numberPrototypeTable(VM& vm) { return *vm.numberPrototypeTable; }
102 static const HashTable& objectConstructorTable(VM& vm) { return *vm.objectConstructorTable; }
103 static const HashTable& privateNamePrototypeTable(VM& vm) { return *vm.privateNamePrototypeTable; }
104 static const HashTable& regExpTable(VM& vm) { return *vm.regExpTable; }
105 static const HashTable& regExpConstructorTable(VM& vm) { return *vm.regExpConstructorTable; }
106 static const HashTable& regExpPrototypeTable(VM& vm) { return *vm.regExpPrototypeTable; }
107 static const HashTable& stringConstructorTable(VM& vm) { return *vm.stringConstructorTable; }
bfulgham@apple.com59af0f52013-08-29 23:36:43 +0000108#if ENABLE(PROMISES)
oliver@apple.com10825da2014-01-25 01:03:40 +0000109 static const HashTable& promisePrototypeTable(VM& vm) { return *vm.promisePrototypeTable; }
110 static const HashTable& promiseConstructorTable(VM& vm) { return *vm.promiseConstructorTable; }
bfulgham@apple.com59af0f52013-08-29 23:36:43 +0000111#endif
ap@webkit.org960c28e2008-06-19 17:29:29 +0000112
darin@apple.com8c2bac02008-10-09 00:40:43 +0000113 static CallFrame* create(Register* callFrameBase) { return static_cast<CallFrame*>(callFrameBase); }
114 Register* registers() { return this; }
mark.lam@apple.com65a636f2014-02-01 01:24:39 +0000115 const Register* registers() const { return this; }
darin@apple.com8c2bac02008-10-09 00:40:43 +0000116
117 CallFrame& operator=(const Register& r) { *static_cast<Register*>(this) = r; return *this; }
118
mark.lam@apple.comc8151c42013-10-30 21:26:46 +0000119 CallFrame* callerFrame() const { return callerFrameAndPC().callerFrame; }
120 static ptrdiff_t callerFrameOffset() { return OBJECT_OFFSETOF(CallerFrameAndPC, callerFrame); }
121
122 ReturnAddressPtr returnPC() const { return ReturnAddressPtr(callerFrameAndPC().pc); }
123 bool hasReturnPC() const { return !!callerFrameAndPC().pc; }
124 void clearReturnPC() { callerFrameAndPC().pc = 0; }
125 static ptrdiff_t returnPCOffset() { return OBJECT_OFFSETOF(CallerFrameAndPC, pc); }
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +0000126 AbstractPC abstractReturnPC(VM& vm) { return AbstractPC(vm, this); }
oliver@apple.comc4497322013-07-25 04:02:03 +0000127
oliver@apple.com1e7b6b52013-07-25 04:02:07 +0000128 class Location {
129 public:
oliver@apple.com1e7b6b52013-07-25 04:02:07 +0000130 static inline uint32_t decode(uint32_t bits);
oliver@apple.comc4c9b8a2013-07-25 04:02:09 +0000131
132 static inline bool isBytecodeLocation(uint32_t bits);
133#if USE(JSVALUE64)
134 static inline uint32_t encodeAsBytecodeOffset(uint32_t bits);
135#else
136 static inline uint32_t encodeAsBytecodeInstruction(Instruction*);
137#endif
138
oliver@apple.com1e7b6b52013-07-25 04:02:07 +0000139 static inline bool isCodeOriginIndex(uint32_t bits);
oliver@apple.comc4c9b8a2013-07-25 04:02:09 +0000140 static inline uint32_t encodeAsCodeOriginIndex(uint32_t bits);
141
oliver@apple.com1e7b6b52013-07-25 04:02:07 +0000142 private:
oliver@apple.comc4c9b8a2013-07-25 04:02:09 +0000143 enum TypeTag {
144 BytecodeLocationTag = 0,
145 CodeOriginIndexTag = 1,
oliver@apple.comc4c9b8a2013-07-25 04:02:09 +0000146 };
147
148 static inline uint32_t encode(TypeTag, uint32_t bits);
149
fpizlo@apple.com71309442013-09-21 17:40:35 +0000150 static const uint32_t s_mask = 0x1;
oliver@apple.com1e7b6b52013-07-25 04:02:07 +0000151#if USE(JSVALUE64)
fpizlo@apple.com71309442013-09-21 17:40:35 +0000152 static const uint32_t s_shift = 31;
oliver@apple.com1e7b6b52013-07-25 04:02:07 +0000153 static const uint32_t s_shiftedMask = s_mask << s_shift;
154#else
fpizlo@apple.com71309442013-09-21 17:40:35 +0000155 static const uint32_t s_shift = 1;
oliver@apple.com1e7b6b52013-07-25 04:02:07 +0000156#endif
157 };
158
oliver@apple.comc4497322013-07-25 04:02:03 +0000159 bool hasLocationAsBytecodeOffset() const;
160 bool hasLocationAsCodeOriginIndex() const;
161
162 unsigned locationAsRawBits() const;
163 unsigned locationAsBytecodeOffset() const;
164 unsigned locationAsCodeOriginIndex() const;
165
166 void setLocationAsRawBits(unsigned);
167 void setLocationAsBytecodeOffset(unsigned);
oliver@apple.com8b234c92012-02-08 21:22:49 +0000168
oliver@apple.com0919f4f2013-07-25 04:02:20 +0000169#if ENABLE(DFG_JIT)
oliver@apple.com1e7b6b52013-07-25 04:02:07 +0000170 unsigned bytecodeOffsetFromCodeOriginIndex();
oliver@apple.com0919f4f2013-07-25 04:02:20 +0000171#endif
fpizlo@apple.comf825bf62013-09-22 05:00:45 +0000172
173 // This will try to get you the bytecode offset, but you should be aware that
174 // this bytecode offset may be bogus in the presence of inlining. This will
175 // also return 0 if the call frame has no notion of bytecode offsets (for
176 // example if it's native code).
177 // https://bugs.webkit.org/show_bug.cgi?id=121754
178 unsigned bytecodeOffset();
179
180 // This will get you a CodeOrigin. It will always succeed. May return
181 // CodeOrigin(0) if we're in native code.
182 CodeOrigin codeOrigin();
oliver@apple.com1e7b6b52013-07-25 04:02:07 +0000183
msaboff@apple.com95894332014-01-29 19:18:54 +0000184 Register* topOfFrame()
oliver@apple.com0ebd4282012-04-21 00:12:04 +0000185 {
msaboff@apple.comc9b3ad62013-11-04 21:28:38 +0000186 if (isVMEntrySentinel() || !codeBlock())
msaboff@apple.com95894332014-01-29 19:18:54 +0000187 return registers();
188 return topOfFrameInternal();
oliver@apple.com0ebd4282012-04-21 00:12:04 +0000189 }
190
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000191#if USE(JSVALUE32_64)
192 Instruction* currentVPC() const
193 {
msaboff@apple.comc9b3ad62013-11-04 21:28:38 +0000194 ASSERT(!isVMEntrySentinel());
mark.lam@apple.com4fbb9c32012-10-09 07:12:56 +0000195 return bitwise_cast<Instruction*>(this[JSStack::ArgumentCount].tag());
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000196 }
197 void setCurrentVPC(Instruction* vpc)
198 {
msaboff@apple.comc9b3ad62013-11-04 21:28:38 +0000199 ASSERT(!isVMEntrySentinel());
mark.lam@apple.com4fbb9c32012-10-09 07:12:56 +0000200 this[JSStack::ArgumentCount].tag() = bitwise_cast<int32_t>(vpc);
fpizlo@apple.com7bbcaab2012-02-22 05:23:19 +0000201 }
202#else
203 Instruction* currentVPC() const;
204 void setCurrentVPC(Instruction* vpc);
205#endif
darin@apple.com8c2bac02008-10-09 00:40:43 +0000206
mark.lam@apple.comc8151c42013-10-30 21:26:46 +0000207 void setCallerFrame(CallFrame* frame) { callerFrameAndPC().callerFrame = frame; }
mark.lam@apple.com4fbb9c32012-10-09 07:12:56 +0000208 void setScope(JSScope* scope) { static_cast<Register*>(this)[JSStack::ScopeChain] = scope; }
mark.lam@apple.com65a636f2014-02-01 01:24:39 +0000209 void setActivation(JSActivation*);
darin@apple.com8c2bac02008-10-09 00:40:43 +0000210
ggaren@apple.comb11e7872012-08-30 22:50:00 +0000211 ALWAYS_INLINE void init(CodeBlock* codeBlock, Instruction* vPC, JSScope* scope,
ggaren@apple.comfea29f12010-05-29 06:33:05 +0000212 CallFrame* callerFrame, int argc, JSObject* callee)
darin@apple.com8c2bac02008-10-09 00:40:43 +0000213 {
msaboff@apple.comc9b3ad62013-11-04 21:28:38 +0000214 ASSERT(callerFrame == noCaller() || callerFrame->isVMEntrySentinel() || callerFrame->stack()->containsAddress(this));
darin@apple.com8c2bac02008-10-09 00:40:43 +0000215
216 setCodeBlock(codeBlock);
ggaren@apple.comb11e7872012-08-30 22:50:00 +0000217 setScope(scope);
darin@apple.com8c2bac02008-10-09 00:40:43 +0000218 setCallerFrame(callerFrame);
barraclough@apple.com5ec969f2010-05-28 21:18:35 +0000219 setReturnPC(vPC); // This is either an Instruction* or a pointer into JIT generated code stored as an Instruction*.
ggaren@apple.comfea29f12010-05-29 06:33:05 +0000220 setArgumentCountIncludingThis(argc); // original argument count (for the sake of the "arguments" object)
221 setCallee(callee);
darin@apple.com8c2bac02008-10-09 00:40:43 +0000222 }
223
barraclough@apple.comb35bbd32009-07-07 21:52:07 +0000224 // Read a register from the codeframe (or constant from the CodeBlock).
ggaren@apple.com1281f322012-08-30 23:36:41 +0000225 Register& r(int);
msaboff@apple.com62aa8b72013-09-26 22:53:54 +0000226 // Read a register for a non-constant
ggaren@apple.com1281f322012-08-30 23:36:41 +0000227 Register& uncheckedR(int);
barraclough@apple.com5b374fc2009-06-02 05:36:18 +0000228
ggaren@apple.comaf710d82012-09-18 01:15:04 +0000229 // Access to arguments as passed. (After capture, arguments may move to a different location.)
ggaren@apple.comfea29f12010-05-29 06:33:05 +0000230 size_t argumentCount() const { return argumentCountIncludingThis() - 1; }
mark.lam@apple.com4fbb9c32012-10-09 07:12:56 +0000231 size_t argumentCountIncludingThis() const { return this[JSStack::ArgumentCount].payload(); }
msaboff@apple.comd19c4622013-10-29 23:15:09 +0000232 static int argumentOffset(int argument) { return (JSStack::FirstArgument + argument); }
233 static int argumentOffsetIncludingThis(int argument) { return (JSStack::ThisArgument + argument); }
ggaren@apple.com0af14682011-12-12 00:35:51 +0000234
mark.lam@apple.com73982082012-09-28 00:50:34 +0000235 // In the following (argument() and setArgument()), the 'argument'
236 // parameter is the index of the arguments of the target function of
237 // this frame. The index starts at 0 for the first arg, 1 for the
238 // second, etc.
239 //
240 // The arguments (in this case) do not include the 'this' value.
241 // arguments(0) will not fetch the 'this' value. To get/set 'this',
242 // use thisValue() and setThisValue() below.
243
ggaren@apple.com0af14682011-12-12 00:35:51 +0000244 JSValue argument(size_t argument)
ggaren@apple.comfea29f12010-05-29 06:33:05 +0000245 {
ggaren@apple.com0af14682011-12-12 00:35:51 +0000246 if (argument >= argumentCount())
247 return jsUndefined();
darin@apple.comd9b22132013-09-22 04:02:59 +0000248 return getArgumentUnsafe(argument);
249 }
250 JSValue uncheckedArgument(size_t argument)
251 {
252 ASSERT(argument < argumentCount());
253 return getArgumentUnsafe(argument);
ggaren@apple.comfea29f12010-05-29 06:33:05 +0000254 }
ggaren@apple.com0af14682011-12-12 00:35:51 +0000255 void setArgument(size_t argument, JSValue value)
256 {
257 this[argumentOffset(argument)] = value;
258 }
259
260 static int thisArgumentOffset() { return argumentOffsetIncludingThis(0); }
261 JSValue thisValue() { return this[thisArgumentOffset()].jsValue(); }
262 void setThisValue(JSValue value) { this[thisArgumentOffset()] = value; }
263
ggaren@apple.comaf710d82012-09-18 01:15:04 +0000264 JSValue argumentAfterCapture(size_t argument);
265
msaboff@apple.comd19c4622013-10-29 23:15:09 +0000266 static int offsetFor(size_t argumentCountIncludingThis) { return argumentCountIncludingThis + JSStack::ThisArgument - 1; }
ggaren@apple.com0af14682011-12-12 00:35:51 +0000267
268 // FIXME: Remove these.
269 int hostThisRegister() { return thisArgumentOffset(); }
270 JSValue hostThisValue() { return thisValue(); }
ggaren@apple.comfea29f12010-05-29 06:33:05 +0000271
msaboff@apple.comc9b3ad62013-11-04 21:28:38 +0000272 static CallFrame* noCaller() { return 0; }
barraclough@apple.com5b374fc2009-06-02 05:36:18 +0000273
msaboff@apple.comc9b3ad62013-11-04 21:28:38 +0000274 bool isVMEntrySentinel() const
275 {
276 return !!this && codeBlock() == vmEntrySentinelCodeBlock();
277 }
278
279 CallFrame* vmEntrySentinelCallerFrame() const
280 {
281 ASSERT(isVMEntrySentinel());
282 return this[JSStack::ScopeChain].callFrame();
283 }
284
285 void initializeVMEntrySentinelFrame(CallFrame* callFrame)
286 {
287 setCallerFrame(noCaller());
288 setReturnPC(0);
289 setCodeBlock(vmEntrySentinelCodeBlock());
290 static_cast<Register*>(this)[JSStack::ScopeChain] = callFrame;
291 setCallee(0);
292 setArgumentCountIncludingThis(0);
293 }
294
295 CallFrame* callerFrameSkippingVMEntrySentinel()
296 {
297 CallFrame* caller = callerFrame();
298 if (caller->isVMEntrySentinel())
299 return caller->vmEntrySentinelCallerFrame();
300 return caller;
301 }
barraclough@apple.comb35bbd32009-07-07 21:52:07 +0000302
mark.lam@apple.com4fbb9c32012-10-09 07:12:56 +0000303 void setArgumentCountIncludingThis(int count) { static_cast<Register*>(this)[JSStack::ArgumentCount].payload() = count; }
304 void setCallee(JSObject* callee) { static_cast<Register*>(this)[JSStack::Callee] = Register::withCallee(callee); }
305 void setCodeBlock(CodeBlock* codeBlock) { static_cast<Register*>(this)[JSStack::CodeBlock] = codeBlock; }
mark.lam@apple.comc8151c42013-10-30 21:26:46 +0000306 void setReturnPC(void* value) { callerFrameAndPC().pc = reinterpret_cast<Instruction*>(value); }
307
mark.lam@apple.com99c89d42013-09-04 22:33:57 +0000308 // CallFrame::iterate() expects a Functor that implements the following method:
mark.lam@apple.comfa2a1422013-09-05 00:40:15 +0000309 // StackVisitor::Status operator()(StackVisitor&);
mark.lam@apple.com99c89d42013-09-04 22:33:57 +0000310
311 template <typename Functor> void iterate(Functor& functor)
312 {
mark.lam@apple.comfa2a1422013-09-05 00:40:15 +0000313 StackVisitor::visit<Functor>(this, functor);
mark.lam@apple.com99c89d42013-09-04 22:33:57 +0000314 }
oliver@apple.com2b2e1322013-07-25 04:02:28 +0000315
barraclough@apple.coma114be42010-05-25 04:32:45 +0000316 private:
msaboff@apple.comc9b3ad62013-11-04 21:28:38 +0000317 static const intptr_t s_VMEntrySentinel = 1;
ggaren@apple.com0af14682011-12-12 00:35:51 +0000318
oliver@apple.com87df8302012-05-02 19:18:28 +0000319#ifndef NDEBUG
mark.lam@apple.com4fbb9c32012-10-09 07:12:56 +0000320 JSStack* stack();
oliver@apple.com87df8302012-05-02 19:18:28 +0000321#endif
darin@apple.comd3f46402008-10-04 21:12:54 +0000322 ExecState();
323 ~ExecState();
commit-queue@webkit.orga22c4cd2012-08-22 00:11:20 +0000324
msaboff@apple.com95894332014-01-29 19:18:54 +0000325 Register* topOfFrameInternal();
326
mark.lam@apple.com05ed9842012-10-23 07:12:29 +0000327 // The following are for internal use in debugging and verification
328 // code only and not meant as an API for general usage:
329
330 size_t argIndexForRegister(Register* reg)
331 {
332 // The register at 'offset' number of slots from the frame pointer
333 // i.e.
334 // reg = frame[offset];
335 // ==> reg = frame + offset;
336 // ==> offset = reg - frame;
337 int offset = reg - this->registers();
338
339 // The offset is defined (based on argumentOffset()) to be:
msaboff@apple.comd19c4622013-10-29 23:15:09 +0000340 // offset = JSStack::FirstArgument - argIndex;
mark.lam@apple.com05ed9842012-10-23 07:12:29 +0000341 // Hence:
msaboff@apple.comd19c4622013-10-29 23:15:09 +0000342 // argIndex = JSStack::FirstArgument - offset;
343 size_t argIndex = offset - JSStack::FirstArgument;
mark.lam@apple.com05ed9842012-10-23 07:12:29 +0000344 return argIndex;
345 }
346
347 JSValue getArgumentUnsafe(size_t argIndex)
348 {
349 // User beware! This method does not verify that there is a valid
350 // argument at the specified argIndex. This is used for debugging
351 // and verification code only. The caller is expected to know what
352 // he/she is doing when calling this method.
353 return this[argumentOffset(argIndex)].jsValue();
354 }
355
mark.lam@apple.comc8151c42013-10-30 21:26:46 +0000356 CallerFrameAndPC& callerFrameAndPC() { return *reinterpret_cast<CallerFrameAndPC*>(this); }
357 const CallerFrameAndPC& callerFrameAndPC() const { return *reinterpret_cast<const CallerFrameAndPC*>(this); }
358
msaboff@apple.comc9b3ad62013-11-04 21:28:38 +0000359 static CodeBlock* vmEntrySentinelCodeBlock() { return reinterpret_cast<CodeBlock*>(s_VMEntrySentinel); }
360
mark.lam@apple.com05ed9842012-10-23 07:12:29 +0000361 friend class JSStack;
commit-queue@webkit.orga22c4cd2012-08-22 00:11:20 +0000362 friend class VMInspector;
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +0000363 };
364
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +0000365} // namespace JSC
ggaren01b2e772006-06-13 06:08:52 +0000366
ggaren@apple.com5169fc92008-11-17 22:11:26 +0000367#endif // CallFrame_h