|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef jsscriptinlines_h |
|
8 #define jsscriptinlines_h |
|
9 |
|
10 #include "jsscript.h" |
|
11 |
|
12 #include "jit/AsmJSLink.h" |
|
13 #include "jit/BaselineJIT.h" |
|
14 #include "jit/IonAnalysis.h" |
|
15 #include "vm/ScopeObject.h" |
|
16 |
|
17 #include "jscompartmentinlines.h" |
|
18 |
|
19 #include "vm/Shape-inl.h" |
|
20 |
|
21 namespace js { |
|
22 |
|
23 inline |
|
24 Bindings::Bindings() |
|
25 : callObjShape_(nullptr), bindingArrayAndFlag_(TEMPORARY_STORAGE_BIT), |
|
26 numArgs_(0), numBlockScoped_(0), numVars_(0) |
|
27 {} |
|
28 |
|
29 inline |
|
30 AliasedFormalIter::AliasedFormalIter(JSScript *script) |
|
31 : begin_(script->bindingArray()), |
|
32 p_(begin_), |
|
33 end_(begin_ + (script->funHasAnyAliasedFormal() ? script->numArgs() : 0)), |
|
34 slot_(CallObject::RESERVED_SLOTS) |
|
35 { |
|
36 settle(); |
|
37 } |
|
38 |
|
39 inline void |
|
40 ScriptCounts::destroy(FreeOp *fop) |
|
41 { |
|
42 fop->free_(pcCountsVector); |
|
43 fop->delete_(ionCounts); |
|
44 } |
|
45 |
|
46 void |
|
47 SetFrameArgumentsObject(JSContext *cx, AbstractFramePtr frame, |
|
48 HandleScript script, JSObject *argsobj); |
|
49 |
|
50 inline JSFunction * |
|
51 LazyScript::functionDelazifying(JSContext *cx) const |
|
52 { |
|
53 if (function_ && !function_->getOrCreateScript(cx)) |
|
54 return nullptr; |
|
55 return function_; |
|
56 } |
|
57 |
|
58 } // namespace js |
|
59 |
|
60 inline JSFunction * |
|
61 JSScript::functionDelazifying() const |
|
62 { |
|
63 if (function_ && function_->isInterpretedLazy()) { |
|
64 function_->setUnlazifiedScript(const_cast<JSScript *>(this)); |
|
65 // If this script has a LazyScript, make sure the LazyScript has a |
|
66 // reference to the script when delazifying its canonical function. |
|
67 if (lazyScript && !lazyScript->maybeScript()) |
|
68 lazyScript->initScript(const_cast<JSScript *>(this)); |
|
69 } |
|
70 return function_; |
|
71 } |
|
72 |
|
73 inline void |
|
74 JSScript::setFunction(JSFunction *fun) |
|
75 { |
|
76 JS_ASSERT(fun->isTenured()); |
|
77 function_ = fun; |
|
78 } |
|
79 |
|
80 inline void |
|
81 JSScript::ensureNonLazyCanonicalFunction(JSContext *cx) |
|
82 { |
|
83 // Infallibly delazify the canonical script. |
|
84 if (function_ && function_->isInterpretedLazy()) |
|
85 functionDelazifying(); |
|
86 } |
|
87 |
|
88 inline JSFunction * |
|
89 JSScript::getFunction(size_t index) |
|
90 { |
|
91 JSFunction *fun = &getObject(index)->as<JSFunction>(); |
|
92 JS_ASSERT_IF(fun->isNative(), IsAsmJSModuleNative(fun->native())); |
|
93 return fun; |
|
94 } |
|
95 |
|
96 inline JSFunction * |
|
97 JSScript::getCallerFunction() |
|
98 { |
|
99 JS_ASSERT(savedCallerFun()); |
|
100 return getFunction(0); |
|
101 } |
|
102 |
|
103 inline JSFunction * |
|
104 JSScript::functionOrCallerFunction() |
|
105 { |
|
106 if (functionNonDelazifying()) |
|
107 return functionNonDelazifying(); |
|
108 if (savedCallerFun()) |
|
109 return getCallerFunction(); |
|
110 return nullptr; |
|
111 } |
|
112 |
|
113 inline js::RegExpObject * |
|
114 JSScript::getRegExp(size_t index) |
|
115 { |
|
116 js::ObjectArray *arr = regexps(); |
|
117 JS_ASSERT(uint32_t(index) < arr->length); |
|
118 JSObject *obj = arr->vector[index]; |
|
119 JS_ASSERT(obj->is<js::RegExpObject>()); |
|
120 return (js::RegExpObject *) obj; |
|
121 } |
|
122 |
|
123 inline js::RegExpObject * |
|
124 JSScript::getRegExp(jsbytecode *pc) |
|
125 { |
|
126 JS_ASSERT(containsPC(pc) && containsPC(pc + sizeof(uint32_t))); |
|
127 return getRegExp(GET_UINT32_INDEX(pc)); |
|
128 } |
|
129 |
|
130 inline js::GlobalObject & |
|
131 JSScript::global() const |
|
132 { |
|
133 /* |
|
134 * A JSScript always marks its compartment's global (via bindings) so we |
|
135 * can assert that maybeGlobal is non-null here. |
|
136 */ |
|
137 return *compartment()->maybeGlobal(); |
|
138 } |
|
139 |
|
140 inline JSPrincipals * |
|
141 JSScript::principals() |
|
142 { |
|
143 return compartment()->principals; |
|
144 } |
|
145 |
|
146 inline JSFunction * |
|
147 JSScript::donorFunction() const |
|
148 { |
|
149 if (!isCallsiteClone()) |
|
150 return nullptr; |
|
151 return &enclosingScopeOrOriginalFunction_->as<JSFunction>(); |
|
152 } |
|
153 |
|
154 inline void |
|
155 JSScript::setIsCallsiteClone(JSObject *fun) |
|
156 { |
|
157 JS_ASSERT(shouldCloneAtCallsite()); |
|
158 shouldCloneAtCallsite_ = false; |
|
159 isCallsiteClone_ = true; |
|
160 JS_ASSERT(isCallsiteClone()); |
|
161 JS_ASSERT(fun->is<JSFunction>()); |
|
162 enclosingScopeOrOriginalFunction_ = fun; |
|
163 } |
|
164 |
|
165 inline void |
|
166 JSScript::setBaselineScript(JSContext *maybecx, js::jit::BaselineScript *baselineScript) |
|
167 { |
|
168 #ifdef JS_ION |
|
169 if (hasBaselineScript()) |
|
170 js::jit::BaselineScript::writeBarrierPre(tenuredZone(), baseline); |
|
171 #endif |
|
172 MOZ_ASSERT(!hasIonScript()); |
|
173 baseline = baselineScript; |
|
174 updateBaselineOrIonRaw(); |
|
175 } |
|
176 |
|
177 inline bool |
|
178 JSScript::ensureHasAnalyzedArgsUsage(JSContext *cx) |
|
179 { |
|
180 if (analyzedArgsUsage()) |
|
181 return true; |
|
182 #ifdef JS_ION |
|
183 return js::jit::AnalyzeArgumentsUsage(cx, this); |
|
184 #else |
|
185 MOZ_CRASH(); |
|
186 #endif |
|
187 } |
|
188 |
|
189 #endif /* jsscriptinlines_h */ |