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 vm_ScopeObject_inl_h michael@0: #define vm_ScopeObject_inl_h michael@0: michael@0: #include "vm/ScopeObject.h" michael@0: michael@0: #include "jsinferinlines.h" michael@0: michael@0: namespace js { michael@0: michael@0: inline void michael@0: ScopeObject::setAliasedVar(JSContext *cx, ScopeCoordinate sc, PropertyName *name, const Value &v) michael@0: { michael@0: JS_ASSERT(is() || is()); michael@0: JS_STATIC_ASSERT(CallObject::RESERVED_SLOTS == BlockObject::RESERVED_SLOTS); michael@0: michael@0: setSlot(sc.slot(), v); michael@0: michael@0: // name may be null if we don't need to track side effects on the object. michael@0: if (hasSingletonType() && !hasLazyType()) { michael@0: JS_ASSERT(name); michael@0: types::AddTypePropertyId(cx, this, NameToId(name), v); michael@0: } michael@0: } michael@0: michael@0: inline void michael@0: CallObject::setAliasedVar(JSContext *cx, AliasedFormalIter fi, PropertyName *name, const Value &v) michael@0: { michael@0: JS_ASSERT(name == fi->name()); michael@0: setSlot(fi.scopeSlot(), v); michael@0: if (hasSingletonType()) michael@0: types::AddTypePropertyId(cx, this, NameToId(name), v); michael@0: } michael@0: michael@0: inline void michael@0: CallObject::setAliasedVarFromArguments(JSContext *cx, const Value &argsValue, jsid id, const Value &v) michael@0: { michael@0: setSlot(argsValue.magicUint32(), v); michael@0: if (hasSingletonType()) michael@0: types::AddTypePropertyId(cx, this, id, v); michael@0: } michael@0: michael@0: template michael@0: inline bool michael@0: StaticScopeIter::done() const michael@0: { michael@0: return !obj; michael@0: } michael@0: michael@0: template michael@0: inline void michael@0: StaticScopeIter::operator++(int) michael@0: { michael@0: if (obj->template is()) { michael@0: obj = obj->template as().enclosingScopeForStaticScopeIter(); michael@0: } else if (onNamedLambda || !obj->template as().isNamedLambda()) { michael@0: onNamedLambda = false; michael@0: obj = obj->template as().nonLazyScript()->enclosingStaticScope(); michael@0: } else { michael@0: onNamedLambda = true; michael@0: } michael@0: JS_ASSERT_IF(obj, obj->template is() || obj->template is()); michael@0: JS_ASSERT_IF(onNamedLambda, obj->template is()); michael@0: } michael@0: michael@0: template michael@0: inline bool michael@0: StaticScopeIter::hasDynamicScopeObject() const michael@0: { michael@0: return obj->template is() michael@0: ? obj->template as().needsClone() michael@0: : (obj->template is() || michael@0: obj->template as().isHeavyweight()); michael@0: } michael@0: michael@0: template michael@0: inline Shape * michael@0: StaticScopeIter::scopeShape() const michael@0: { michael@0: JS_ASSERT(hasDynamicScopeObject()); michael@0: JS_ASSERT(type() != NAMED_LAMBDA); michael@0: if (type() == BLOCK) michael@0: return block().lastProperty(); michael@0: return funScript()->callObjShape(); michael@0: } michael@0: michael@0: template michael@0: inline typename StaticScopeIter::Type michael@0: StaticScopeIter::type() const michael@0: { michael@0: if (onNamedLambda) michael@0: return NAMED_LAMBDA; michael@0: return obj->template is() michael@0: ? BLOCK michael@0: : (obj->template is() ? WITH : FUNCTION); michael@0: } michael@0: michael@0: template michael@0: inline StaticBlockObject & michael@0: StaticScopeIter::block() const michael@0: { michael@0: JS_ASSERT(type() == BLOCK); michael@0: return obj->template as(); michael@0: } michael@0: michael@0: template michael@0: inline StaticWithObject & michael@0: StaticScopeIter::staticWith() const michael@0: { michael@0: JS_ASSERT(type() == WITH); michael@0: return obj->template as(); michael@0: } michael@0: michael@0: template michael@0: inline JSScript * michael@0: StaticScopeIter::funScript() const michael@0: { michael@0: JS_ASSERT(type() == FUNCTION); michael@0: return obj->template as().nonLazyScript(); michael@0: } michael@0: michael@0: } /* namespace js */ michael@0: michael@0: #endif /* vm_ScopeObject_inl_h */