1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jsscriptinlines.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,189 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef jsscriptinlines_h 1.11 +#define jsscriptinlines_h 1.12 + 1.13 +#include "jsscript.h" 1.14 + 1.15 +#include "jit/AsmJSLink.h" 1.16 +#include "jit/BaselineJIT.h" 1.17 +#include "jit/IonAnalysis.h" 1.18 +#include "vm/ScopeObject.h" 1.19 + 1.20 +#include "jscompartmentinlines.h" 1.21 + 1.22 +#include "vm/Shape-inl.h" 1.23 + 1.24 +namespace js { 1.25 + 1.26 +inline 1.27 +Bindings::Bindings() 1.28 + : callObjShape_(nullptr), bindingArrayAndFlag_(TEMPORARY_STORAGE_BIT), 1.29 + numArgs_(0), numBlockScoped_(0), numVars_(0) 1.30 +{} 1.31 + 1.32 +inline 1.33 +AliasedFormalIter::AliasedFormalIter(JSScript *script) 1.34 + : begin_(script->bindingArray()), 1.35 + p_(begin_), 1.36 + end_(begin_ + (script->funHasAnyAliasedFormal() ? script->numArgs() : 0)), 1.37 + slot_(CallObject::RESERVED_SLOTS) 1.38 +{ 1.39 + settle(); 1.40 +} 1.41 + 1.42 +inline void 1.43 +ScriptCounts::destroy(FreeOp *fop) 1.44 +{ 1.45 + fop->free_(pcCountsVector); 1.46 + fop->delete_(ionCounts); 1.47 +} 1.48 + 1.49 +void 1.50 +SetFrameArgumentsObject(JSContext *cx, AbstractFramePtr frame, 1.51 + HandleScript script, JSObject *argsobj); 1.52 + 1.53 +inline JSFunction * 1.54 +LazyScript::functionDelazifying(JSContext *cx) const 1.55 +{ 1.56 + if (function_ && !function_->getOrCreateScript(cx)) 1.57 + return nullptr; 1.58 + return function_; 1.59 +} 1.60 + 1.61 +} // namespace js 1.62 + 1.63 +inline JSFunction * 1.64 +JSScript::functionDelazifying() const 1.65 +{ 1.66 + if (function_ && function_->isInterpretedLazy()) { 1.67 + function_->setUnlazifiedScript(const_cast<JSScript *>(this)); 1.68 + // If this script has a LazyScript, make sure the LazyScript has a 1.69 + // reference to the script when delazifying its canonical function. 1.70 + if (lazyScript && !lazyScript->maybeScript()) 1.71 + lazyScript->initScript(const_cast<JSScript *>(this)); 1.72 + } 1.73 + return function_; 1.74 +} 1.75 + 1.76 +inline void 1.77 +JSScript::setFunction(JSFunction *fun) 1.78 +{ 1.79 + JS_ASSERT(fun->isTenured()); 1.80 + function_ = fun; 1.81 +} 1.82 + 1.83 +inline void 1.84 +JSScript::ensureNonLazyCanonicalFunction(JSContext *cx) 1.85 +{ 1.86 + // Infallibly delazify the canonical script. 1.87 + if (function_ && function_->isInterpretedLazy()) 1.88 + functionDelazifying(); 1.89 +} 1.90 + 1.91 +inline JSFunction * 1.92 +JSScript::getFunction(size_t index) 1.93 +{ 1.94 + JSFunction *fun = &getObject(index)->as<JSFunction>(); 1.95 + JS_ASSERT_IF(fun->isNative(), IsAsmJSModuleNative(fun->native())); 1.96 + return fun; 1.97 +} 1.98 + 1.99 +inline JSFunction * 1.100 +JSScript::getCallerFunction() 1.101 +{ 1.102 + JS_ASSERT(savedCallerFun()); 1.103 + return getFunction(0); 1.104 +} 1.105 + 1.106 +inline JSFunction * 1.107 +JSScript::functionOrCallerFunction() 1.108 +{ 1.109 + if (functionNonDelazifying()) 1.110 + return functionNonDelazifying(); 1.111 + if (savedCallerFun()) 1.112 + return getCallerFunction(); 1.113 + return nullptr; 1.114 +} 1.115 + 1.116 +inline js::RegExpObject * 1.117 +JSScript::getRegExp(size_t index) 1.118 +{ 1.119 + js::ObjectArray *arr = regexps(); 1.120 + JS_ASSERT(uint32_t(index) < arr->length); 1.121 + JSObject *obj = arr->vector[index]; 1.122 + JS_ASSERT(obj->is<js::RegExpObject>()); 1.123 + return (js::RegExpObject *) obj; 1.124 +} 1.125 + 1.126 +inline js::RegExpObject * 1.127 +JSScript::getRegExp(jsbytecode *pc) 1.128 +{ 1.129 + JS_ASSERT(containsPC(pc) && containsPC(pc + sizeof(uint32_t))); 1.130 + return getRegExp(GET_UINT32_INDEX(pc)); 1.131 +} 1.132 + 1.133 +inline js::GlobalObject & 1.134 +JSScript::global() const 1.135 +{ 1.136 + /* 1.137 + * A JSScript always marks its compartment's global (via bindings) so we 1.138 + * can assert that maybeGlobal is non-null here. 1.139 + */ 1.140 + return *compartment()->maybeGlobal(); 1.141 +} 1.142 + 1.143 +inline JSPrincipals * 1.144 +JSScript::principals() 1.145 +{ 1.146 + return compartment()->principals; 1.147 +} 1.148 + 1.149 +inline JSFunction * 1.150 +JSScript::donorFunction() const 1.151 +{ 1.152 + if (!isCallsiteClone()) 1.153 + return nullptr; 1.154 + return &enclosingScopeOrOriginalFunction_->as<JSFunction>(); 1.155 +} 1.156 + 1.157 +inline void 1.158 +JSScript::setIsCallsiteClone(JSObject *fun) 1.159 +{ 1.160 + JS_ASSERT(shouldCloneAtCallsite()); 1.161 + shouldCloneAtCallsite_ = false; 1.162 + isCallsiteClone_ = true; 1.163 + JS_ASSERT(isCallsiteClone()); 1.164 + JS_ASSERT(fun->is<JSFunction>()); 1.165 + enclosingScopeOrOriginalFunction_ = fun; 1.166 +} 1.167 + 1.168 +inline void 1.169 +JSScript::setBaselineScript(JSContext *maybecx, js::jit::BaselineScript *baselineScript) 1.170 +{ 1.171 +#ifdef JS_ION 1.172 + if (hasBaselineScript()) 1.173 + js::jit::BaselineScript::writeBarrierPre(tenuredZone(), baseline); 1.174 +#endif 1.175 + MOZ_ASSERT(!hasIonScript()); 1.176 + baseline = baselineScript; 1.177 + updateBaselineOrIonRaw(); 1.178 +} 1.179 + 1.180 +inline bool 1.181 +JSScript::ensureHasAnalyzedArgsUsage(JSContext *cx) 1.182 +{ 1.183 + if (analyzedArgsUsage()) 1.184 + return true; 1.185 +#ifdef JS_ION 1.186 + return js::jit::AnalyzeArgumentsUsage(cx, this); 1.187 +#else 1.188 + MOZ_CRASH(); 1.189 +#endif 1.190 +} 1.191 + 1.192 +#endif /* jsscriptinlines_h */