ggaren | 01b2e77 | 2006-06-13 06:08:52 +0000 | [diff] [blame] | 1 | /* |
ggaren | 01b2e77 | 2006-06-13 06:08:52 +0000 | [diff] [blame] | 2 | * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) |
| 3 | * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
mark.lam@apple.com | 65a636f | 2014-02-01 01:24:39 +0000 | [diff] [blame] | 4 | * Copyright (C) 2003, 2007, 2008, 2011, 2013, 2014 Apple Inc. All rights reserved. |
ggaren | 01b2e77 | 2006-06-13 06:08:52 +0000 | [diff] [blame] | 5 | * |
| 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.com | 5169fc9 | 2008-11-17 22:11:26 +0000 | [diff] [blame] | 23 | #ifndef CallFrame_h |
| 24 | #define CallFrame_h |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 25 | |
fpizlo@apple.com | e8a38be | 2012-01-27 01:15:16 +0000 | [diff] [blame] | 26 | #include "AbstractPC.h" |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 27 | #include "VM.h" |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 28 | #include "JSStack.h" |
ggaren@apple.com | 11760a7 | 2010-05-19 23:24:31 +0000 | [diff] [blame] | 29 | #include "MacroAssemblerCodeRef.h" |
fpizlo@apple.com | a4b4cbe | 2013-01-12 04:47:03 +0000 | [diff] [blame] | 30 | #include "Register.h" |
mark.lam@apple.com | fa2a142 | 2013-09-05 00:40:15 +0000 | [diff] [blame] | 31 | #include "StackVisitor.h" |
ggaren | 01b2e77 | 2006-06-13 06:08:52 +0000 | [diff] [blame] | 32 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 33 | namespace JSC { |
mjs | e58111c | 2007-10-26 08:32:40 +0000 | [diff] [blame] | 34 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 35 | class Arguments; |
| 36 | class JSActivation; |
ggaren@apple.com | a268c78 | 2008-11-17 21:51:09 +0000 | [diff] [blame] | 37 | class Interpreter; |
ggaren@apple.com | b11e787 | 2012-08-30 22:50:00 +0000 | [diff] [blame] | 38 | class JSScope; |
darin@apple.com | d3f4640 | 2008-10-04 21:12:54 +0000 | [diff] [blame] | 39 | |
darin@apple.com | 41343c3 | 2008-01-26 18:55:52 +0000 | [diff] [blame] | 40 | // Represents the current state of script execution. |
| 41 | // Passed as the first argument to most functions. |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 42 | class ExecState : private Register { |
mjs | e58111c | 2007-10-26 08:32:40 +0000 | [diff] [blame] | 43 | public: |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 44 | 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.com | b11e787 | 2012-08-30 22:50:00 +0000 | [diff] [blame] | 47 | JSScope* scope() const |
oliver@apple.com | fb4bbbc | 2009-12-04 02:17:46 +0000 | [diff] [blame] | 48 | { |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 49 | ASSERT(this[JSStack::ScopeChain].Register::scope()); |
| 50 | return this[JSStack::ScopeChain].Register::scope(); |
oliver@apple.com | fb4bbbc | 2009-12-04 02:17:46 +0000 | [diff] [blame] | 51 | } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 52 | |
mark.lam@apple.com | 65a636f | 2014-02-01 01:24:39 +0000 | [diff] [blame] | 53 | bool hasActivation() const { return !!uncheckedActivation(); } |
| 54 | JSActivation* activation() const; |
mark.lam@apple.com | 8355b38 | 2014-02-01 02:42:30 +0000 | [diff] [blame^] | 55 | JSValue uncheckedActivation() const; |
mark.lam@apple.com | 65a636f | 2014-02-01 01:24:39 +0000 | [diff] [blame] | 56 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 57 | // Global object in which execution began. |
mark.lam@apple.com | 3072125 | 2013-11-21 05:29:42 +0000 | [diff] [blame] | 58 | JS_EXPORT_PRIVATE JSGlobalObject* vmEntryGlobalObject(); |
darin@apple.com | 3d73fee | 2008-10-03 21:39:16 +0000 | [diff] [blame] | 59 | |
darin@apple.com | d3f4640 | 2008-10-04 21:12:54 +0000 | [diff] [blame] | 60 | // Global object in which the currently executing code was defined. |
mark.lam@apple.com | a0b59db | 2013-11-22 21:09:25 +0000 | [diff] [blame] | 61 | // Differs from vmEntryGlobalObject() during function calls across web browser frames. |
ggaren@apple.com | 1281f32 | 2012-08-30 23:36:41 +0000 | [diff] [blame] | 62 | JSGlobalObject* lexicalGlobalObject() const; |
darin@apple.com | 3d73fee | 2008-10-03 21:39:16 +0000 | [diff] [blame] | 63 | |
darin@apple.com | d3f4640 | 2008-10-04 21:12:54 +0000 | [diff] [blame] | 64 | // Differs from lexicalGlobalObject because this will have DOM window shell rather than |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 65 | // the actual DOM window, which can't be "this" for security reasons. |
ggaren@apple.com | 1281f32 | 2012-08-30 23:36:41 +0000 | [diff] [blame] | 66 | JSObject* globalThisValue() const; |
darin@apple.com | 3d73fee | 2008-10-03 21:39:16 +0000 | [diff] [blame] | 67 | |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 68 | VM& vm() const; |
ap@webkit.org | 5b30cfc | 2008-06-07 06:03:24 +0000 | [diff] [blame] | 69 | |
darin@apple.com | d3f4640 | 2008-10-04 21:12:54 +0000 | [diff] [blame] | 70 | // Convenience functions for access to global data. |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 71 | // 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.com | d3f4640 | 2008-10-04 21:12:54 +0000 | [diff] [blame] | 74 | |
commit-queue@webkit.org | 3f922f9 | 2013-08-29 00:28:42 +0000 | [diff] [blame] | 75 | void clearException() { vm().clearException(); } |
oliver@apple.com | 5683d16 | 2013-04-07 18:47:20 +0000 | [diff] [blame] | 76 | void clearSupplementaryExceptionInfo() |
| 77 | { |
oliver@apple.com | 90a10c5 | 2013-05-16 00:29:25 +0000 | [diff] [blame] | 78 | vm().clearExceptionStack(); |
oliver@apple.com | 5683d16 | 2013-04-07 18:47:20 +0000 | [diff] [blame] | 79 | } |
| 80 | |
commit-queue@webkit.org | 3f922f9 | 2013-08-29 00:28:42 +0000 | [diff] [blame] | 81 | JSValue exception() const { return vm().exception(); } |
oliver@apple.com | 02fe014 | 2013-08-30 18:30:41 +0000 | [diff] [blame] | 82 | bool hadException() const { return !vm().exception().isEmpty(); } |
darin@apple.com | d3f4640 | 2008-10-04 21:12:54 +0000 | [diff] [blame] | 83 | |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 84 | 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.com | 4476dcc | 2009-04-30 21:38:01 +0000 | [diff] [blame] | 88 | #ifndef NDEBUG |
| 89 | void dumpCaller(); |
| 90 | #endif |
oliver@apple.com | 10825da | 2014-01-25 01:03:40 +0000 | [diff] [blame] | 91 | 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.com | 59af0f5 | 2013-08-29 23:36:43 +0000 | [diff] [blame] | 108 | #if ENABLE(PROMISES) |
oliver@apple.com | 10825da | 2014-01-25 01:03:40 +0000 | [diff] [blame] | 109 | static const HashTable& promisePrototypeTable(VM& vm) { return *vm.promisePrototypeTable; } |
| 110 | static const HashTable& promiseConstructorTable(VM& vm) { return *vm.promiseConstructorTable; } |
bfulgham@apple.com | 59af0f5 | 2013-08-29 23:36:43 +0000 | [diff] [blame] | 111 | #endif |
ap@webkit.org | 960c28e | 2008-06-19 17:29:29 +0000 | [diff] [blame] | 112 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 113 | static CallFrame* create(Register* callFrameBase) { return static_cast<CallFrame*>(callFrameBase); } |
| 114 | Register* registers() { return this; } |
mark.lam@apple.com | 65a636f | 2014-02-01 01:24:39 +0000 | [diff] [blame] | 115 | const Register* registers() const { return this; } |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 116 | |
| 117 | CallFrame& operator=(const Register& r) { *static_cast<Register*>(this) = r; return *this; } |
| 118 | |
mark.lam@apple.com | c8151c4 | 2013-10-30 21:26:46 +0000 | [diff] [blame] | 119 | 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.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 126 | AbstractPC abstractReturnPC(VM& vm) { return AbstractPC(vm, this); } |
oliver@apple.com | c449732 | 2013-07-25 04:02:03 +0000 | [diff] [blame] | 127 | |
oliver@apple.com | 1e7b6b5 | 2013-07-25 04:02:07 +0000 | [diff] [blame] | 128 | class Location { |
| 129 | public: |
oliver@apple.com | 1e7b6b5 | 2013-07-25 04:02:07 +0000 | [diff] [blame] | 130 | static inline uint32_t decode(uint32_t bits); |
oliver@apple.com | c4c9b8a | 2013-07-25 04:02:09 +0000 | [diff] [blame] | 131 | |
| 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.com | 1e7b6b5 | 2013-07-25 04:02:07 +0000 | [diff] [blame] | 139 | static inline bool isCodeOriginIndex(uint32_t bits); |
oliver@apple.com | c4c9b8a | 2013-07-25 04:02:09 +0000 | [diff] [blame] | 140 | static inline uint32_t encodeAsCodeOriginIndex(uint32_t bits); |
| 141 | |
oliver@apple.com | 1e7b6b5 | 2013-07-25 04:02:07 +0000 | [diff] [blame] | 142 | private: |
oliver@apple.com | c4c9b8a | 2013-07-25 04:02:09 +0000 | [diff] [blame] | 143 | enum TypeTag { |
| 144 | BytecodeLocationTag = 0, |
| 145 | CodeOriginIndexTag = 1, |
oliver@apple.com | c4c9b8a | 2013-07-25 04:02:09 +0000 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | static inline uint32_t encode(TypeTag, uint32_t bits); |
| 149 | |
fpizlo@apple.com | 7130944 | 2013-09-21 17:40:35 +0000 | [diff] [blame] | 150 | static const uint32_t s_mask = 0x1; |
oliver@apple.com | 1e7b6b5 | 2013-07-25 04:02:07 +0000 | [diff] [blame] | 151 | #if USE(JSVALUE64) |
fpizlo@apple.com | 7130944 | 2013-09-21 17:40:35 +0000 | [diff] [blame] | 152 | static const uint32_t s_shift = 31; |
oliver@apple.com | 1e7b6b5 | 2013-07-25 04:02:07 +0000 | [diff] [blame] | 153 | static const uint32_t s_shiftedMask = s_mask << s_shift; |
| 154 | #else |
fpizlo@apple.com | 7130944 | 2013-09-21 17:40:35 +0000 | [diff] [blame] | 155 | static const uint32_t s_shift = 1; |
oliver@apple.com | 1e7b6b5 | 2013-07-25 04:02:07 +0000 | [diff] [blame] | 156 | #endif |
| 157 | }; |
| 158 | |
oliver@apple.com | c449732 | 2013-07-25 04:02:03 +0000 | [diff] [blame] | 159 | 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.com | 8b234c9 | 2012-02-08 21:22:49 +0000 | [diff] [blame] | 168 | |
oliver@apple.com | 0919f4f | 2013-07-25 04:02:20 +0000 | [diff] [blame] | 169 | #if ENABLE(DFG_JIT) |
oliver@apple.com | 1e7b6b5 | 2013-07-25 04:02:07 +0000 | [diff] [blame] | 170 | unsigned bytecodeOffsetFromCodeOriginIndex(); |
oliver@apple.com | 0919f4f | 2013-07-25 04:02:20 +0000 | [diff] [blame] | 171 | #endif |
fpizlo@apple.com | f825bf6 | 2013-09-22 05:00:45 +0000 | [diff] [blame] | 172 | |
| 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.com | 1e7b6b5 | 2013-07-25 04:02:07 +0000 | [diff] [blame] | 183 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 184 | Register* topOfFrame() |
oliver@apple.com | 0ebd428 | 2012-04-21 00:12:04 +0000 | [diff] [blame] | 185 | { |
msaboff@apple.com | c9b3ad6 | 2013-11-04 21:28:38 +0000 | [diff] [blame] | 186 | if (isVMEntrySentinel() || !codeBlock()) |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 187 | return registers(); |
| 188 | return topOfFrameInternal(); |
oliver@apple.com | 0ebd428 | 2012-04-21 00:12:04 +0000 | [diff] [blame] | 189 | } |
| 190 | |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 191 | #if USE(JSVALUE32_64) |
| 192 | Instruction* currentVPC() const |
| 193 | { |
msaboff@apple.com | c9b3ad6 | 2013-11-04 21:28:38 +0000 | [diff] [blame] | 194 | ASSERT(!isVMEntrySentinel()); |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 195 | return bitwise_cast<Instruction*>(this[JSStack::ArgumentCount].tag()); |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 196 | } |
| 197 | void setCurrentVPC(Instruction* vpc) |
| 198 | { |
msaboff@apple.com | c9b3ad6 | 2013-11-04 21:28:38 +0000 | [diff] [blame] | 199 | ASSERT(!isVMEntrySentinel()); |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 200 | this[JSStack::ArgumentCount].tag() = bitwise_cast<int32_t>(vpc); |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 201 | } |
| 202 | #else |
| 203 | Instruction* currentVPC() const; |
| 204 | void setCurrentVPC(Instruction* vpc); |
| 205 | #endif |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 206 | |
mark.lam@apple.com | c8151c4 | 2013-10-30 21:26:46 +0000 | [diff] [blame] | 207 | void setCallerFrame(CallFrame* frame) { callerFrameAndPC().callerFrame = frame; } |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 208 | void setScope(JSScope* scope) { static_cast<Register*>(this)[JSStack::ScopeChain] = scope; } |
mark.lam@apple.com | 65a636f | 2014-02-01 01:24:39 +0000 | [diff] [blame] | 209 | void setActivation(JSActivation*); |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 210 | |
ggaren@apple.com | b11e787 | 2012-08-30 22:50:00 +0000 | [diff] [blame] | 211 | ALWAYS_INLINE void init(CodeBlock* codeBlock, Instruction* vPC, JSScope* scope, |
ggaren@apple.com | fea29f1 | 2010-05-29 06:33:05 +0000 | [diff] [blame] | 212 | CallFrame* callerFrame, int argc, JSObject* callee) |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 213 | { |
msaboff@apple.com | c9b3ad6 | 2013-11-04 21:28:38 +0000 | [diff] [blame] | 214 | ASSERT(callerFrame == noCaller() || callerFrame->isVMEntrySentinel() || callerFrame->stack()->containsAddress(this)); |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 215 | |
| 216 | setCodeBlock(codeBlock); |
ggaren@apple.com | b11e787 | 2012-08-30 22:50:00 +0000 | [diff] [blame] | 217 | setScope(scope); |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 218 | setCallerFrame(callerFrame); |
barraclough@apple.com | 5ec969f | 2010-05-28 21:18:35 +0000 | [diff] [blame] | 219 | setReturnPC(vPC); // This is either an Instruction* or a pointer into JIT generated code stored as an Instruction*. |
ggaren@apple.com | fea29f1 | 2010-05-29 06:33:05 +0000 | [diff] [blame] | 220 | setArgumentCountIncludingThis(argc); // original argument count (for the sake of the "arguments" object) |
| 221 | setCallee(callee); |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 222 | } |
| 223 | |
barraclough@apple.com | b35bbd3 | 2009-07-07 21:52:07 +0000 | [diff] [blame] | 224 | // Read a register from the codeframe (or constant from the CodeBlock). |
ggaren@apple.com | 1281f32 | 2012-08-30 23:36:41 +0000 | [diff] [blame] | 225 | Register& r(int); |
msaboff@apple.com | 62aa8b7 | 2013-09-26 22:53:54 +0000 | [diff] [blame] | 226 | // Read a register for a non-constant |
ggaren@apple.com | 1281f32 | 2012-08-30 23:36:41 +0000 | [diff] [blame] | 227 | Register& uncheckedR(int); |
barraclough@apple.com | 5b374fc | 2009-06-02 05:36:18 +0000 | [diff] [blame] | 228 | |
ggaren@apple.com | af710d8 | 2012-09-18 01:15:04 +0000 | [diff] [blame] | 229 | // Access to arguments as passed. (After capture, arguments may move to a different location.) |
ggaren@apple.com | fea29f1 | 2010-05-29 06:33:05 +0000 | [diff] [blame] | 230 | size_t argumentCount() const { return argumentCountIncludingThis() - 1; } |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 231 | size_t argumentCountIncludingThis() const { return this[JSStack::ArgumentCount].payload(); } |
msaboff@apple.com | d19c462 | 2013-10-29 23:15:09 +0000 | [diff] [blame] | 232 | static int argumentOffset(int argument) { return (JSStack::FirstArgument + argument); } |
| 233 | static int argumentOffsetIncludingThis(int argument) { return (JSStack::ThisArgument + argument); } |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 234 | |
mark.lam@apple.com | 7398208 | 2012-09-28 00:50:34 +0000 | [diff] [blame] | 235 | // 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.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 244 | JSValue argument(size_t argument) |
ggaren@apple.com | fea29f1 | 2010-05-29 06:33:05 +0000 | [diff] [blame] | 245 | { |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 246 | if (argument >= argumentCount()) |
| 247 | return jsUndefined(); |
darin@apple.com | d9b2213 | 2013-09-22 04:02:59 +0000 | [diff] [blame] | 248 | return getArgumentUnsafe(argument); |
| 249 | } |
| 250 | JSValue uncheckedArgument(size_t argument) |
| 251 | { |
| 252 | ASSERT(argument < argumentCount()); |
| 253 | return getArgumentUnsafe(argument); |
ggaren@apple.com | fea29f1 | 2010-05-29 06:33:05 +0000 | [diff] [blame] | 254 | } |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 255 | 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.com | af710d8 | 2012-09-18 01:15:04 +0000 | [diff] [blame] | 264 | JSValue argumentAfterCapture(size_t argument); |
| 265 | |
msaboff@apple.com | d19c462 | 2013-10-29 23:15:09 +0000 | [diff] [blame] | 266 | static int offsetFor(size_t argumentCountIncludingThis) { return argumentCountIncludingThis + JSStack::ThisArgument - 1; } |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 267 | |
| 268 | // FIXME: Remove these. |
| 269 | int hostThisRegister() { return thisArgumentOffset(); } |
| 270 | JSValue hostThisValue() { return thisValue(); } |
ggaren@apple.com | fea29f1 | 2010-05-29 06:33:05 +0000 | [diff] [blame] | 271 | |
msaboff@apple.com | c9b3ad6 | 2013-11-04 21:28:38 +0000 | [diff] [blame] | 272 | static CallFrame* noCaller() { return 0; } |
barraclough@apple.com | 5b374fc | 2009-06-02 05:36:18 +0000 | [diff] [blame] | 273 | |
msaboff@apple.com | c9b3ad6 | 2013-11-04 21:28:38 +0000 | [diff] [blame] | 274 | 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.com | b35bbd3 | 2009-07-07 21:52:07 +0000 | [diff] [blame] | 302 | |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 303 | 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.com | c8151c4 | 2013-10-30 21:26:46 +0000 | [diff] [blame] | 306 | void setReturnPC(void* value) { callerFrameAndPC().pc = reinterpret_cast<Instruction*>(value); } |
| 307 | |
mark.lam@apple.com | 99c89d4 | 2013-09-04 22:33:57 +0000 | [diff] [blame] | 308 | // CallFrame::iterate() expects a Functor that implements the following method: |
mark.lam@apple.com | fa2a142 | 2013-09-05 00:40:15 +0000 | [diff] [blame] | 309 | // StackVisitor::Status operator()(StackVisitor&); |
mark.lam@apple.com | 99c89d4 | 2013-09-04 22:33:57 +0000 | [diff] [blame] | 310 | |
| 311 | template <typename Functor> void iterate(Functor& functor) |
| 312 | { |
mark.lam@apple.com | fa2a142 | 2013-09-05 00:40:15 +0000 | [diff] [blame] | 313 | StackVisitor::visit<Functor>(this, functor); |
mark.lam@apple.com | 99c89d4 | 2013-09-04 22:33:57 +0000 | [diff] [blame] | 314 | } |
oliver@apple.com | 2b2e132 | 2013-07-25 04:02:28 +0000 | [diff] [blame] | 315 | |
barraclough@apple.com | a114be4 | 2010-05-25 04:32:45 +0000 | [diff] [blame] | 316 | private: |
msaboff@apple.com | c9b3ad6 | 2013-11-04 21:28:38 +0000 | [diff] [blame] | 317 | static const intptr_t s_VMEntrySentinel = 1; |
ggaren@apple.com | 0af1468 | 2011-12-12 00:35:51 +0000 | [diff] [blame] | 318 | |
oliver@apple.com | 87df830 | 2012-05-02 19:18:28 +0000 | [diff] [blame] | 319 | #ifndef NDEBUG |
mark.lam@apple.com | 4fbb9c3 | 2012-10-09 07:12:56 +0000 | [diff] [blame] | 320 | JSStack* stack(); |
oliver@apple.com | 87df830 | 2012-05-02 19:18:28 +0000 | [diff] [blame] | 321 | #endif |
darin@apple.com | d3f4640 | 2008-10-04 21:12:54 +0000 | [diff] [blame] | 322 | ExecState(); |
| 323 | ~ExecState(); |
commit-queue@webkit.org | a22c4cd | 2012-08-22 00:11:20 +0000 | [diff] [blame] | 324 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 325 | Register* topOfFrameInternal(); |
| 326 | |
mark.lam@apple.com | 05ed984 | 2012-10-23 07:12:29 +0000 | [diff] [blame] | 327 | // 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.com | d19c462 | 2013-10-29 23:15:09 +0000 | [diff] [blame] | 340 | // offset = JSStack::FirstArgument - argIndex; |
mark.lam@apple.com | 05ed984 | 2012-10-23 07:12:29 +0000 | [diff] [blame] | 341 | // Hence: |
msaboff@apple.com | d19c462 | 2013-10-29 23:15:09 +0000 | [diff] [blame] | 342 | // argIndex = JSStack::FirstArgument - offset; |
| 343 | size_t argIndex = offset - JSStack::FirstArgument; |
mark.lam@apple.com | 05ed984 | 2012-10-23 07:12:29 +0000 | [diff] [blame] | 344 | 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.com | c8151c4 | 2013-10-30 21:26:46 +0000 | [diff] [blame] | 356 | CallerFrameAndPC& callerFrameAndPC() { return *reinterpret_cast<CallerFrameAndPC*>(this); } |
| 357 | const CallerFrameAndPC& callerFrameAndPC() const { return *reinterpret_cast<const CallerFrameAndPC*>(this); } |
| 358 | |
msaboff@apple.com | c9b3ad6 | 2013-11-04 21:28:38 +0000 | [diff] [blame] | 359 | static CodeBlock* vmEntrySentinelCodeBlock() { return reinterpret_cast<CodeBlock*>(s_VMEntrySentinel); } |
| 360 | |
mark.lam@apple.com | 05ed984 | 2012-10-23 07:12:29 +0000 | [diff] [blame] | 361 | friend class JSStack; |
commit-queue@webkit.org | a22c4cd | 2012-08-22 00:11:20 +0000 | [diff] [blame] | 362 | friend class VMInspector; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 363 | }; |
| 364 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 365 | } // namespace JSC |
ggaren | 01b2e77 | 2006-06-13 06:08:52 +0000 | [diff] [blame] | 366 | |
ggaren@apple.com | 5169fc9 | 2008-11-17 22:11:26 +0000 | [diff] [blame] | 367 | #endif // CallFrame_h |