2 * Copyright (C) 2003, 2008, 2009 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
25 #include "Structure.h"
26 #include <wtf/FastAllocBase.h>
34 class ScopeChainIterator
;
35 typedef MarkStack SlotVisitor
;
37 class ScopeChainNode
: public JSCell
{
39 ScopeChainNode(ScopeChainNode
* next
, JSObject
* object
, JSGlobalData
* globalData
, JSGlobalObject
* globalObject
, JSObject
* globalThis
)
40 : JSCell(*globalData
, globalData
->scopeChainNodeStructure
.get())
41 , globalData(globalData
)
42 , next(*globalData
, this, next
, WriteBarrier
<ScopeChainNode
>::MayBeNull
)
43 , object(*globalData
, this, object
)
44 , globalObject(*globalData
, this, globalObject
)
45 , globalThis(*globalData
, this, globalThis
)
51 JSGlobalData
* globalData
;
52 WriteBarrier
<ScopeChainNode
> next
;
53 WriteBarrier
<JSObject
> object
;
54 WriteBarrier
<JSGlobalObject
> globalObject
;
55 WriteBarrier
<JSObject
> globalThis
;
57 ScopeChainNode
* push(JSObject
*);
58 ScopeChainNode
* pop();
60 ScopeChainIterator
begin();
61 ScopeChainIterator
end();
69 static Structure
* createStructure(JSGlobalData
& globalData
, JSValue proto
) { return Structure::create(globalData
, proto
, TypeInfo(CompoundType
, StructureFlags
), AnonymousSlotCount
, &s_info
); }
70 virtual void visitChildren(SlotVisitor
&);
71 static JS_EXPORTDATA
const ClassInfo s_info
;
74 static const unsigned StructureFlags
= OverridesVisitChildren
;
77 inline ScopeChainNode
* ScopeChainNode::push(JSObject
* o
)
80 return new (globalData
) ScopeChainNode(this, o
, globalData
, globalObject
.get(), globalThis
.get());
83 inline ScopeChainNode
* ScopeChainNode::pop()
89 class ScopeChainIterator
{
91 ScopeChainIterator(ScopeChainNode
* node
)
96 WriteBarrier
<JSObject
> const & operator*() const { return m_node
->object
; }
97 WriteBarrier
<JSObject
> const * operator->() const { return &(operator*()); }
99 ScopeChainIterator
& operator++() { m_node
= m_node
->next
.get(); return *this; }
101 // postfix ++ intentionally omitted
103 bool operator==(const ScopeChainIterator
& other
) const { return m_node
== other
.m_node
; }
104 bool operator!=(const ScopeChainIterator
& other
) const { return m_node
!= other
.m_node
; }
107 ScopeChainNode
* m_node
;
110 inline ScopeChainIterator
ScopeChainNode::begin()
112 return ScopeChainIterator(this);
115 inline ScopeChainIterator
ScopeChainNode::end()
117 return ScopeChainIterator(0);
120 ALWAYS_INLINE JSGlobalData
& ExecState::globalData() const
122 ASSERT(scopeChain()->globalData
);
123 return *scopeChain()->globalData
;
126 ALWAYS_INLINE JSGlobalObject
* ExecState::lexicalGlobalObject() const
128 return scopeChain()->globalObject
.get();
131 ALWAYS_INLINE JSObject
* ExecState::globalThisValue() const
133 return scopeChain()->globalThis
.get();
136 ALWAYS_INLINE ScopeChainNode
* Register::scopeChain() const
138 return static_cast<ScopeChainNode
*>(jsValue().asCell());
141 ALWAYS_INLINE Register
& Register::operator=(ScopeChainNode
* scopeChain
)
143 *this = JSValue(scopeChain
);
149 #endif // ScopeChain_h