michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef jsscriptinlines_h michael@0: #define jsscriptinlines_h michael@0: michael@0: #include "jsscript.h" michael@0: michael@0: #include "jit/AsmJSLink.h" michael@0: #include "jit/BaselineJIT.h" michael@0: #include "jit/IonAnalysis.h" michael@0: #include "vm/ScopeObject.h" michael@0: michael@0: #include "jscompartmentinlines.h" michael@0: michael@0: #include "vm/Shape-inl.h" michael@0: michael@0: namespace js { michael@0: michael@0: inline michael@0: Bindings::Bindings() michael@0: : callObjShape_(nullptr), bindingArrayAndFlag_(TEMPORARY_STORAGE_BIT), michael@0: numArgs_(0), numBlockScoped_(0), numVars_(0) michael@0: {} michael@0: michael@0: inline michael@0: AliasedFormalIter::AliasedFormalIter(JSScript *script) michael@0: : begin_(script->bindingArray()), michael@0: p_(begin_), michael@0: end_(begin_ + (script->funHasAnyAliasedFormal() ? script->numArgs() : 0)), michael@0: slot_(CallObject::RESERVED_SLOTS) michael@0: { michael@0: settle(); michael@0: } michael@0: michael@0: inline void michael@0: ScriptCounts::destroy(FreeOp *fop) michael@0: { michael@0: fop->free_(pcCountsVector); michael@0: fop->delete_(ionCounts); michael@0: } michael@0: michael@0: void michael@0: SetFrameArgumentsObject(JSContext *cx, AbstractFramePtr frame, michael@0: HandleScript script, JSObject *argsobj); michael@0: michael@0: inline JSFunction * michael@0: LazyScript::functionDelazifying(JSContext *cx) const michael@0: { michael@0: if (function_ && !function_->getOrCreateScript(cx)) michael@0: return nullptr; michael@0: return function_; michael@0: } michael@0: michael@0: } // namespace js michael@0: michael@0: inline JSFunction * michael@0: JSScript::functionDelazifying() const michael@0: { michael@0: if (function_ && function_->isInterpretedLazy()) { michael@0: function_->setUnlazifiedScript(const_cast(this)); michael@0: // If this script has a LazyScript, make sure the LazyScript has a michael@0: // reference to the script when delazifying its canonical function. michael@0: if (lazyScript && !lazyScript->maybeScript()) michael@0: lazyScript->initScript(const_cast(this)); michael@0: } michael@0: return function_; michael@0: } michael@0: michael@0: inline void michael@0: JSScript::setFunction(JSFunction *fun) michael@0: { michael@0: JS_ASSERT(fun->isTenured()); michael@0: function_ = fun; michael@0: } michael@0: michael@0: inline void michael@0: JSScript::ensureNonLazyCanonicalFunction(JSContext *cx) michael@0: { michael@0: // Infallibly delazify the canonical script. michael@0: if (function_ && function_->isInterpretedLazy()) michael@0: functionDelazifying(); michael@0: } michael@0: michael@0: inline JSFunction * michael@0: JSScript::getFunction(size_t index) michael@0: { michael@0: JSFunction *fun = &getObject(index)->as(); michael@0: JS_ASSERT_IF(fun->isNative(), IsAsmJSModuleNative(fun->native())); michael@0: return fun; michael@0: } michael@0: michael@0: inline JSFunction * michael@0: JSScript::getCallerFunction() michael@0: { michael@0: JS_ASSERT(savedCallerFun()); michael@0: return getFunction(0); michael@0: } michael@0: michael@0: inline JSFunction * michael@0: JSScript::functionOrCallerFunction() michael@0: { michael@0: if (functionNonDelazifying()) michael@0: return functionNonDelazifying(); michael@0: if (savedCallerFun()) michael@0: return getCallerFunction(); michael@0: return nullptr; michael@0: } michael@0: michael@0: inline js::RegExpObject * michael@0: JSScript::getRegExp(size_t index) michael@0: { michael@0: js::ObjectArray *arr = regexps(); michael@0: JS_ASSERT(uint32_t(index) < arr->length); michael@0: JSObject *obj = arr->vector[index]; michael@0: JS_ASSERT(obj->is()); michael@0: return (js::RegExpObject *) obj; michael@0: } michael@0: michael@0: inline js::RegExpObject * michael@0: JSScript::getRegExp(jsbytecode *pc) michael@0: { michael@0: JS_ASSERT(containsPC(pc) && containsPC(pc + sizeof(uint32_t))); michael@0: return getRegExp(GET_UINT32_INDEX(pc)); michael@0: } michael@0: michael@0: inline js::GlobalObject & michael@0: JSScript::global() const michael@0: { michael@0: /* michael@0: * A JSScript always marks its compartment's global (via bindings) so we michael@0: * can assert that maybeGlobal is non-null here. michael@0: */ michael@0: return *compartment()->maybeGlobal(); michael@0: } michael@0: michael@0: inline JSPrincipals * michael@0: JSScript::principals() michael@0: { michael@0: return compartment()->principals; michael@0: } michael@0: michael@0: inline JSFunction * michael@0: JSScript::donorFunction() const michael@0: { michael@0: if (!isCallsiteClone()) michael@0: return nullptr; michael@0: return &enclosingScopeOrOriginalFunction_->as(); michael@0: } michael@0: michael@0: inline void michael@0: JSScript::setIsCallsiteClone(JSObject *fun) michael@0: { michael@0: JS_ASSERT(shouldCloneAtCallsite()); michael@0: shouldCloneAtCallsite_ = false; michael@0: isCallsiteClone_ = true; michael@0: JS_ASSERT(isCallsiteClone()); michael@0: JS_ASSERT(fun->is()); michael@0: enclosingScopeOrOriginalFunction_ = fun; michael@0: } michael@0: michael@0: inline void michael@0: JSScript::setBaselineScript(JSContext *maybecx, js::jit::BaselineScript *baselineScript) michael@0: { michael@0: #ifdef JS_ION michael@0: if (hasBaselineScript()) michael@0: js::jit::BaselineScript::writeBarrierPre(tenuredZone(), baseline); michael@0: #endif michael@0: MOZ_ASSERT(!hasIonScript()); michael@0: baseline = baselineScript; michael@0: updateBaselineOrIonRaw(); michael@0: } michael@0: michael@0: inline bool michael@0: JSScript::ensureHasAnalyzedArgsUsage(JSContext *cx) michael@0: { michael@0: if (analyzedArgsUsage()) michael@0: return true; michael@0: #ifdef JS_ION michael@0: return js::jit::AnalyzeArgumentsUsage(cx, this); michael@0: #else michael@0: MOZ_CRASH(); michael@0: #endif michael@0: } michael@0: michael@0: #endif /* jsscriptinlines_h */