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/. */
7 #ifndef jsscriptinlines_h
8 #define jsscriptinlines_h
12 #include "asmjs/AsmJSLink.h"
13 #include "jit/BaselineJIT.h"
14 #include "jit/IonAnalysis.h"
15 #include "vm/ScopeObject.h"
17 #include "jscompartmentinlines.h"
19 #include "vm/Shape-inl.h"
25 : callObjShape_(nullptr), bindingArrayAndFlag_(TEMPORARY_STORAGE_BIT
),
26 numArgs_(0), numBlockScoped_(0),
27 numBodyLevelLexicals_(0), numUnaliasedBodyLevelLexicals_(0),
28 numVars_(0), numUnaliasedVars_(0)
32 AliasedFormalIter::AliasedFormalIter(JSScript
* script
)
33 : begin_(script
->bindingArray()),
35 end_(begin_
+ (script
->funHasAnyAliasedFormal() ? script
->numArgs() : 0)),
36 slot_(CallObject::RESERVED_SLOTS
)
42 ScriptCounts::destroy(FreeOp
* fop
)
44 fop
->free_(pcCountsVector
);
45 fop
->delete_(ionCounts
);
49 SetFrameArgumentsObject(JSContext
* cx
, AbstractFramePtr frame
,
50 HandleScript script
, JSObject
* argsobj
);
53 LazyScript::functionDelazifying(JSContext
* cx
) const
55 if (function_
&& !function_
->getOrCreateScript(cx
))
63 JSScript::functionDelazifying() const
65 if (function_
&& function_
->isInterpretedLazy()) {
66 function_
->setUnlazifiedScript(const_cast<JSScript
*>(this));
67 // If this script has a LazyScript, make sure the LazyScript has a
68 // reference to the script when delazifying its canonical function.
69 if (lazyScript
&& !lazyScript
->maybeScript())
70 lazyScript
->initScript(const_cast<JSScript
*>(this));
76 JSScript::setFunction(JSFunction
* fun
)
78 MOZ_ASSERT(fun
->isTenured());
83 JSScript::ensureNonLazyCanonicalFunction(JSContext
* cx
)
85 // Infallibly delazify the canonical script.
86 if (function_
&& function_
->isInterpretedLazy())
87 functionDelazifying();
91 JSScript::getFunction(size_t index
)
93 JSFunction
* fun
= &getObject(index
)->as
<JSFunction
>();
94 MOZ_ASSERT_IF(fun
->isNative(), IsAsmJSModuleNative(fun
->native()));
99 JSScript::getCallerFunction()
101 MOZ_ASSERT(savedCallerFun());
102 return getFunction(0);
106 JSScript::functionOrCallerFunction()
108 if (functionNonDelazifying())
109 return functionNonDelazifying();
110 if (savedCallerFun())
111 return getCallerFunction();
115 inline js::RegExpObject
*
116 JSScript::getRegExp(size_t index
)
118 js::ObjectArray
* arr
= regexps();
119 MOZ_ASSERT(uint32_t(index
) < arr
->length
);
120 JSObject
* obj
= arr
->vector
[index
];
121 MOZ_ASSERT(obj
->is
<js::RegExpObject
>());
122 return (js::RegExpObject
*) obj
;
125 inline js::RegExpObject
*
126 JSScript::getRegExp(jsbytecode
* pc
)
128 MOZ_ASSERT(containsPC(pc
) && containsPC(pc
+ sizeof(uint32_t)));
129 return getRegExp(GET_UINT32_INDEX(pc
));
132 inline js::GlobalObject
&
133 JSScript::global() const
136 * A JSScript always marks its compartment's global (via bindings) so we
137 * can assert that maybeGlobal is non-null here.
139 return *compartment()->maybeGlobal();
143 JSScript::principals()
145 return compartment()->principals
;
149 JSScript::donorFunction() const
151 if (!isCallsiteClone())
153 return &enclosingScopeOrOriginalFunction_
->as
<JSFunction
>();
157 JSScript::setIsCallsiteClone(JSObject
* fun
)
159 MOZ_ASSERT(shouldCloneAtCallsite());
160 shouldCloneAtCallsite_
= false;
161 isCallsiteClone_
= true;
162 MOZ_ASSERT(isCallsiteClone());
163 MOZ_ASSERT(fun
->is
<JSFunction
>());
164 enclosingScopeOrOriginalFunction_
= fun
;
168 JSScript::setBaselineScript(JSContext
* maybecx
, js::jit::BaselineScript
* baselineScript
)
170 if (hasBaselineScript())
171 js::jit::BaselineScript::writeBarrierPre(zone(), baseline
);
172 MOZ_ASSERT(!hasIonScript());
173 baseline
= baselineScript
;
174 updateBaselineOrIonRaw(maybecx
);
178 JSScript::ensureHasAnalyzedArgsUsage(JSContext
* cx
)
180 if (analyzedArgsUsage())
182 return js::jit::AnalyzeArgumentsUsage(cx
, this);
186 JSScript::isDebuggee() const
188 return compartment_
->debugObservesAllExecution() || hasDebugScript_
;
191 #endif /* jsscriptinlines_h */