diff -r 000000000000 -r 6474c204b198 js/src/vm/ScopeObject-inl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/js/src/vm/ScopeObject-inl.h Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef vm_ScopeObject_inl_h +#define vm_ScopeObject_inl_h + +#include "vm/ScopeObject.h" + +#include "jsinferinlines.h" + +namespace js { + +inline void +ScopeObject::setAliasedVar(JSContext *cx, ScopeCoordinate sc, PropertyName *name, const Value &v) +{ + JS_ASSERT(is() || is()); + JS_STATIC_ASSERT(CallObject::RESERVED_SLOTS == BlockObject::RESERVED_SLOTS); + + setSlot(sc.slot(), v); + + // name may be null if we don't need to track side effects on the object. + if (hasSingletonType() && !hasLazyType()) { + JS_ASSERT(name); + types::AddTypePropertyId(cx, this, NameToId(name), v); + } +} + +inline void +CallObject::setAliasedVar(JSContext *cx, AliasedFormalIter fi, PropertyName *name, const Value &v) +{ + JS_ASSERT(name == fi->name()); + setSlot(fi.scopeSlot(), v); + if (hasSingletonType()) + types::AddTypePropertyId(cx, this, NameToId(name), v); +} + +inline void +CallObject::setAliasedVarFromArguments(JSContext *cx, const Value &argsValue, jsid id, const Value &v) +{ + setSlot(argsValue.magicUint32(), v); + if (hasSingletonType()) + types::AddTypePropertyId(cx, this, id, v); +} + +template +inline bool +StaticScopeIter::done() const +{ + return !obj; +} + +template +inline void +StaticScopeIter::operator++(int) +{ + if (obj->template is()) { + obj = obj->template as().enclosingScopeForStaticScopeIter(); + } else if (onNamedLambda || !obj->template as().isNamedLambda()) { + onNamedLambda = false; + obj = obj->template as().nonLazyScript()->enclosingStaticScope(); + } else { + onNamedLambda = true; + } + JS_ASSERT_IF(obj, obj->template is() || obj->template is()); + JS_ASSERT_IF(onNamedLambda, obj->template is()); +} + +template +inline bool +StaticScopeIter::hasDynamicScopeObject() const +{ + return obj->template is() + ? obj->template as().needsClone() + : (obj->template is() || + obj->template as().isHeavyweight()); +} + +template +inline Shape * +StaticScopeIter::scopeShape() const +{ + JS_ASSERT(hasDynamicScopeObject()); + JS_ASSERT(type() != NAMED_LAMBDA); + if (type() == BLOCK) + return block().lastProperty(); + return funScript()->callObjShape(); +} + +template +inline typename StaticScopeIter::Type +StaticScopeIter::type() const +{ + if (onNamedLambda) + return NAMED_LAMBDA; + return obj->template is() + ? BLOCK + : (obj->template is() ? WITH : FUNCTION); +} + +template +inline StaticBlockObject & +StaticScopeIter::block() const +{ + JS_ASSERT(type() == BLOCK); + return obj->template as(); +} + +template +inline StaticWithObject & +StaticScopeIter::staticWith() const +{ + JS_ASSERT(type() == WITH); + return obj->template as(); +} + +template +inline JSScript * +StaticScopeIter::funScript() const +{ + JS_ASSERT(type() == FUNCTION); + return obj->template as().nonLazyScript(); +} + +} /* namespace js */ + +#endif /* vm_ScopeObject_inl_h */