forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScopeObject-inl.h
308 lines (259 loc) · 6.79 KB
/
ScopeObject-inl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sw=4 et tw=78:
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef ScopeObject_inl_h___
#define ScopeObject_inl_h___
#include "ScopeObject.h"
#include "jsscriptinlines.h"
namespace js {
inline
ScopeCoordinate::ScopeCoordinate(jsbytecode *pc)
: hops(GET_UINT16(pc)), slot(GET_UINT16(pc + 2))
{
JS_ASSERT(JOF_OPTYPE(*pc) == JOF_SCOPECOORD);
}
inline JSObject &
ScopeObject::enclosingScope() const
{
return getReservedSlot(SCOPE_CHAIN_SLOT).toObject();
}
inline void
ScopeObject::setEnclosingScope(HandleObject obj)
{
JS_ASSERT_IF(obj->isCall() || obj->isDeclEnv() || obj->isBlock(),
obj->isDelegate());
setFixedSlot(SCOPE_CHAIN_SLOT, ObjectValue(*obj));
}
inline const Value &
ScopeObject::aliasedVar(ScopeCoordinate sc)
{
JS_ASSERT(isCall() || isClonedBlock());
return getSlot(sc.slot);
}
inline void
ScopeObject::setAliasedVar(ScopeCoordinate sc, const Value &v)
{
JS_ASSERT(isCall() || isClonedBlock());
JS_STATIC_ASSERT(CallObject::RESERVED_SLOTS == BlockObject::RESERVED_SLOTS);
setSlot(sc.slot, v);
}
/*static*/ inline size_t
ScopeObject::offsetOfEnclosingScope()
{
return getFixedSlotOffset(SCOPE_CHAIN_SLOT);
}
inline bool
CallObject::isForEval() const
{
JS_ASSERT(getReservedSlot(CALLEE_SLOT).isObjectOrNull());
JS_ASSERT_IF(getReservedSlot(CALLEE_SLOT).isObject(),
getReservedSlot(CALLEE_SLOT).toObject().isFunction());
return getReservedSlot(CALLEE_SLOT).isNull();
}
inline JSFunction &
CallObject::callee() const
{
return *getReservedSlot(CALLEE_SLOT).toObject().toFunction();
}
inline const Value &
CallObject::aliasedVar(AliasedFormalIter fi)
{
return getSlot(fi.scopeSlot());
}
inline void
CallObject::setAliasedVar(AliasedFormalIter fi, const Value &v)
{
setSlot(fi.scopeSlot(), v);
}
/*static*/ inline size_t
CallObject::offsetOfCallee()
{
return getFixedSlotOffset(CALLEE_SLOT);
}
inline uint32_t
NestedScopeObject::stackDepth() const
{
return getReservedSlot(DEPTH_SLOT).toPrivateUint32();
}
inline JSObject &
WithObject::withThis() const
{
return getReservedSlot(THIS_SLOT).toObject();
}
inline JSObject &
WithObject::object() const
{
return *JSObject::getProto();
}
inline uint32_t
BlockObject::slotCount() const
{
return propertyCount();
}
inline unsigned
BlockObject::slotToLocalIndex(const Bindings &bindings, unsigned slot)
{
JS_ASSERT(slot < RESERVED_SLOTS + slotCount());
return bindings.numVars() + stackDepth() + (slot - RESERVED_SLOTS);
}
inline unsigned
BlockObject::localIndexToSlot(const Bindings &bindings, unsigned i)
{
return RESERVED_SLOTS + (i - (bindings.numVars() + stackDepth()));
}
inline const Value &
BlockObject::slotValue(unsigned i)
{
return getSlotRef(RESERVED_SLOTS + i);
}
inline void
BlockObject::setSlotValue(unsigned i, const Value &v)
{
setSlot(RESERVED_SLOTS + i, v);
}
inline void
StaticBlockObject::initPrevBlockChainFromParser(StaticBlockObject *prev)
{
setReservedSlot(SCOPE_CHAIN_SLOT, ObjectOrNullValue(prev));
}
inline void
StaticBlockObject::resetPrevBlockChainFromParser()
{
setReservedSlot(SCOPE_CHAIN_SLOT, UndefinedValue());
}
inline void
StaticBlockObject::initEnclosingStaticScope(JSObject *obj)
{
JS_ASSERT(getReservedSlot(SCOPE_CHAIN_SLOT).isUndefined());
setReservedSlot(SCOPE_CHAIN_SLOT, ObjectOrNullValue(obj));
}
inline StaticBlockObject *
StaticBlockObject::enclosingBlock() const
{
JSObject *obj = getReservedSlot(SCOPE_CHAIN_SLOT).toObjectOrNull();
return obj && obj->isStaticBlock() ? &obj->asStaticBlock() : NULL;
}
inline JSObject *
StaticBlockObject::enclosingStaticScope() const
{
return getReservedSlot(SCOPE_CHAIN_SLOT).toObjectOrNull();
}
inline void
StaticBlockObject::setStackDepth(uint32_t depth)
{
JS_ASSERT(getReservedSlot(DEPTH_SLOT).isUndefined());
initReservedSlot(DEPTH_SLOT, PrivateUint32Value(depth));
}
inline void
StaticBlockObject::setDefinitionParseNode(unsigned i, frontend::Definition *def)
{
JS_ASSERT(slotValue(i).isUndefined());
setSlotValue(i, PrivateValue(def));
}
inline frontend::Definition *
StaticBlockObject::maybeDefinitionParseNode(unsigned i)
{
Value v = slotValue(i);
return v.isUndefined() ? NULL : reinterpret_cast<frontend::Definition *>(v.toPrivate());
}
inline void
StaticBlockObject::setAliased(unsigned i, bool aliased)
{
JS_ASSERT_IF(i > 0, slotValue(i-1).isBoolean());
setSlotValue(i, BooleanValue(aliased));
if (aliased && !needsClone()) {
setSlotValue(0, MagicValue(JS_BLOCK_NEEDS_CLONE));
JS_ASSERT(needsClone());
}
}
inline bool
StaticBlockObject::isAliased(unsigned i)
{
return slotValue(i).isTrue();
}
inline bool
StaticBlockObject::needsClone()
{
return !slotValue(0).isFalse();
}
inline bool
StaticBlockObject::containsVarAtDepth(uint32_t depth)
{
return depth >= stackDepth() && depth < stackDepth() + slotCount();
}
inline StaticBlockObject &
ClonedBlockObject::staticBlock() const
{
return getProto()->asStaticBlock();
}
inline const Value &
ClonedBlockObject::var(unsigned i, MaybeCheckAliasing checkAliasing)
{
JS_ASSERT_IF(checkAliasing, staticBlock().isAliased(i));
return slotValue(i);
}
inline void
ClonedBlockObject::setVar(unsigned i, const Value &v, MaybeCheckAliasing checkAliasing)
{
JS_ASSERT_IF(checkAliasing, staticBlock().isAliased(i));
setSlotValue(i, v);
}
} /* namespace js */
inline js::ScopeObject &
JSObject::asScope()
{
JS_ASSERT(isScope());
return *static_cast<js::ScopeObject *>(this);
}
inline js::CallObject &
JSObject::asCall()
{
JS_ASSERT(isCall());
return *static_cast<js::CallObject *>(this);
}
inline js::DeclEnvObject &
JSObject::asDeclEnv()
{
JS_ASSERT(isDeclEnv());
return *static_cast<js::DeclEnvObject *>(this);
}
inline js::NestedScopeObject &
JSObject::asNestedScope()
{
JS_ASSERT(isWith() || isBlock());
return *static_cast<js::NestedScopeObject *>(this);
}
inline js::WithObject &
JSObject::asWith()
{
JS_ASSERT(isWith());
return *static_cast<js::WithObject *>(this);
}
inline js::BlockObject &
JSObject::asBlock()
{
JS_ASSERT(isBlock());
return *static_cast<js::BlockObject *>(this);
}
inline js::StaticBlockObject &
JSObject::asStaticBlock()
{
JS_ASSERT(isStaticBlock());
return *static_cast<js::StaticBlockObject *>(this);
}
inline js::ClonedBlockObject &
JSObject::asClonedBlock()
{
JS_ASSERT(isClonedBlock());
return *static_cast<js::ClonedBlockObject *>(this);
}
inline js::DebugScopeObject &
JSObject::asDebugScope()
{
JS_ASSERT(isDebugScope());
return *static_cast<js::DebugScopeObject *>(this);
}
#endif /* CallObject_inl_h___ */