js/src/vm/ScopeObject-inl.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/vm/ScopeObject-inl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     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 vm_ScopeObject_inl_h
    1.11 +#define vm_ScopeObject_inl_h
    1.12 +
    1.13 +#include "vm/ScopeObject.h"
    1.14 +
    1.15 +#include "jsinferinlines.h"
    1.16 +
    1.17 +namespace js {
    1.18 +
    1.19 +inline void
    1.20 +ScopeObject::setAliasedVar(JSContext *cx, ScopeCoordinate sc, PropertyName *name, const Value &v)
    1.21 +{
    1.22 +    JS_ASSERT(is<CallObject>() || is<ClonedBlockObject>());
    1.23 +    JS_STATIC_ASSERT(CallObject::RESERVED_SLOTS == BlockObject::RESERVED_SLOTS);
    1.24 +
    1.25 +    setSlot(sc.slot(), v);
    1.26 +
    1.27 +    // name may be null if we don't need to track side effects on the object.
    1.28 +    if (hasSingletonType() && !hasLazyType()) {
    1.29 +        JS_ASSERT(name);
    1.30 +        types::AddTypePropertyId(cx, this, NameToId(name), v);
    1.31 +    }
    1.32 +}
    1.33 +
    1.34 +inline void
    1.35 +CallObject::setAliasedVar(JSContext *cx, AliasedFormalIter fi, PropertyName *name, const Value &v)
    1.36 +{
    1.37 +    JS_ASSERT(name == fi->name());
    1.38 +    setSlot(fi.scopeSlot(), v);
    1.39 +    if (hasSingletonType())
    1.40 +        types::AddTypePropertyId(cx, this, NameToId(name), v);
    1.41 +}
    1.42 +
    1.43 +inline void
    1.44 +CallObject::setAliasedVarFromArguments(JSContext *cx, const Value &argsValue, jsid id, const Value &v)
    1.45 +{
    1.46 +    setSlot(argsValue.magicUint32(), v);
    1.47 +    if (hasSingletonType())
    1.48 +        types::AddTypePropertyId(cx, this, id, v);
    1.49 +}
    1.50 +
    1.51 +template <AllowGC allowGC>
    1.52 +inline bool
    1.53 +StaticScopeIter<allowGC>::done() const
    1.54 +{
    1.55 +    return !obj;
    1.56 +}
    1.57 +
    1.58 +template <AllowGC allowGC>
    1.59 +inline void
    1.60 +StaticScopeIter<allowGC>::operator++(int)
    1.61 +{
    1.62 +    if (obj->template is<NestedScopeObject>()) {
    1.63 +        obj = obj->template as<NestedScopeObject>().enclosingScopeForStaticScopeIter();
    1.64 +    } else if (onNamedLambda || !obj->template as<JSFunction>().isNamedLambda()) {
    1.65 +        onNamedLambda = false;
    1.66 +        obj = obj->template as<JSFunction>().nonLazyScript()->enclosingStaticScope();
    1.67 +    } else {
    1.68 +        onNamedLambda = true;
    1.69 +    }
    1.70 +    JS_ASSERT_IF(obj, obj->template is<NestedScopeObject>() || obj->template is<JSFunction>());
    1.71 +    JS_ASSERT_IF(onNamedLambda, obj->template is<JSFunction>());
    1.72 +}
    1.73 +
    1.74 +template <AllowGC allowGC>
    1.75 +inline bool
    1.76 +StaticScopeIter<allowGC>::hasDynamicScopeObject() const
    1.77 +{
    1.78 +    return obj->template is<StaticBlockObject>()
    1.79 +           ? obj->template as<StaticBlockObject>().needsClone()
    1.80 +           : (obj->template is<StaticWithObject>() ||
    1.81 +              obj->template as<JSFunction>().isHeavyweight());
    1.82 +}
    1.83 +
    1.84 +template <AllowGC allowGC>
    1.85 +inline Shape *
    1.86 +StaticScopeIter<allowGC>::scopeShape() const
    1.87 +{
    1.88 +    JS_ASSERT(hasDynamicScopeObject());
    1.89 +    JS_ASSERT(type() != NAMED_LAMBDA);
    1.90 +    if (type() == BLOCK)
    1.91 +        return block().lastProperty();
    1.92 +    return funScript()->callObjShape();
    1.93 +}
    1.94 +
    1.95 +template <AllowGC allowGC>
    1.96 +inline typename StaticScopeIter<allowGC>::Type
    1.97 +StaticScopeIter<allowGC>::type() const
    1.98 +{
    1.99 +    if (onNamedLambda)
   1.100 +        return NAMED_LAMBDA;
   1.101 +    return obj->template is<StaticBlockObject>()
   1.102 +           ? BLOCK
   1.103 +           : (obj->template is<StaticWithObject>() ? WITH : FUNCTION);
   1.104 +}
   1.105 +
   1.106 +template <AllowGC allowGC>
   1.107 +inline StaticBlockObject &
   1.108 +StaticScopeIter<allowGC>::block() const
   1.109 +{
   1.110 +    JS_ASSERT(type() == BLOCK);
   1.111 +    return obj->template as<StaticBlockObject>();
   1.112 +}
   1.113 +
   1.114 +template <AllowGC allowGC>
   1.115 +inline StaticWithObject &
   1.116 +StaticScopeIter<allowGC>::staticWith() const
   1.117 +{
   1.118 +    JS_ASSERT(type() == WITH);
   1.119 +    return obj->template as<StaticWithObject>();
   1.120 +}
   1.121 +
   1.122 +template <AllowGC allowGC>
   1.123 +inline JSScript *
   1.124 +StaticScopeIter<allowGC>::funScript() const
   1.125 +{
   1.126 +    JS_ASSERT(type() == FUNCTION);
   1.127 +    return obj->template as<JSFunction>().nonLazyScript();
   1.128 +}
   1.129 +
   1.130 +}  /* namespace js */
   1.131 +
   1.132 +#endif /* vm_ScopeObject_inl_h */

mercurial