1 | /* |
2 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
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 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "CallFrame.h" |
29 | #include "JSCallee.h" |
30 | #include "JSGlobalObject.h" |
31 | #include "RegisterInlines.h" |
32 | |
33 | namespace JSC { |
34 | |
35 | inline Register& CallFrame::r(int index) |
36 | { |
37 | CodeBlock* codeBlock = this->codeBlock(); |
38 | if (codeBlock->isConstantRegisterIndex(index)) |
39 | return *reinterpret_cast<Register*>(&codeBlock->constantRegister(index)); |
40 | return this[index]; |
41 | } |
42 | |
43 | inline Register& CallFrame::r(VirtualRegister reg) |
44 | { |
45 | return r(reg.offset()); |
46 | } |
47 | |
48 | inline Register& CallFrame::uncheckedR(int index) |
49 | { |
50 | RELEASE_ASSERT(index < FirstConstantRegisterIndex); |
51 | return this[index]; |
52 | } |
53 | |
54 | inline Register& CallFrame::uncheckedR(VirtualRegister reg) |
55 | { |
56 | return uncheckedR(reg.offset()); |
57 | } |
58 | |
59 | inline JSValue CallFrame::guaranteedJSValueCallee() const |
60 | { |
61 | ASSERT(!callee().isWasm()); |
62 | return this[CallFrameSlot::callee].jsValue(); |
63 | } |
64 | |
65 | inline JSObject* CallFrame::jsCallee() const |
66 | { |
67 | ASSERT(!callee().isWasm()); |
68 | return this[CallFrameSlot::callee].object(); |
69 | } |
70 | |
71 | inline CodeBlock* CallFrame::codeBlock() const |
72 | { |
73 | return this[CallFrameSlot::codeBlock].Register::codeBlock(); |
74 | } |
75 | |
76 | inline SUPPRESS_ASAN CodeBlock* CallFrame::unsafeCodeBlock() const |
77 | { |
78 | return this[CallFrameSlot::codeBlock].Register::asanUnsafeCodeBlock(); |
79 | } |
80 | |
81 | inline JSGlobalObject* CallFrame::lexicalGlobalObject(VM& vm) const |
82 | { |
83 | UNUSED_PARAM(vm); |
84 | #if ENABLE(WEBASSEMBLY) |
85 | if (callee().isWasm()) |
86 | return lexicalGlobalObjectFromWasmCallee(vm); |
87 | #endif |
88 | return jsCallee()->globalObject(); |
89 | } |
90 | |
91 | inline bool CallFrame::isStackOverflowFrame() const |
92 | { |
93 | if (callee().isWasm()) |
94 | return false; |
95 | return jsCallee() == jsCallee()->globalObject()->stackOverflowFrameCallee(); |
96 | } |
97 | |
98 | inline bool CallFrame::isWasmFrame() const |
99 | { |
100 | return callee().isWasm(); |
101 | } |
102 | |
103 | inline void CallFrame::setCallee(JSObject* callee) |
104 | { |
105 | static_cast<Register*>(this)[CallFrameSlot::callee] = callee; |
106 | } |
107 | |
108 | inline void CallFrame::setCodeBlock(CodeBlock* codeBlock) |
109 | { |
110 | static_cast<Register*>(this)[CallFrameSlot::codeBlock] = codeBlock; |
111 | } |
112 | |
113 | inline void CallFrame::setScope(int scopeRegisterOffset, JSScope* scope) |
114 | { |
115 | static_cast<Register*>(this)[scopeRegisterOffset] = scope; |
116 | } |
117 | |
118 | inline JSScope* CallFrame::scope(int scopeRegisterOffset) const |
119 | { |
120 | ASSERT(this[scopeRegisterOffset].Register::scope()); |
121 | return this[scopeRegisterOffset].Register::scope(); |
122 | } |
123 | |
124 | inline Register* CallFrame::topOfFrame() |
125 | { |
126 | if (!codeBlock()) |
127 | return registers(); |
128 | return topOfFrameInternal(); |
129 | } |
130 | |
131 | } // namespace JSC |
132 | |