2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2007, 2008, 2009 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
25 #include "CallFrame.h"
27 #include "WriteBarrier.h"
28 #include <wtf/HashSet.h>
29 #include <wtf/Vector.h>
35 class MarkedArgumentBuffer
{
36 WTF_MAKE_NONCOPYABLE(MarkedArgumentBuffer
);
37 friend class JSGlobalData
;
41 static const size_t inlineCapacity
= 8;
42 typedef Vector
<Register
, inlineCapacity
> VectorType
;
43 typedef HashSet
<MarkedArgumentBuffer
*> ListSet
;
46 // Constructor for a read-write list, to which you may append values.
47 // FIXME: Remove all clients of this API, then remove this API.
48 MarkedArgumentBuffer()
50 , m_capacity(inlineCapacity
)
51 , m_buffer(&m_inlineBuffer
[m_capacity
- 1])
56 ~MarkedArgumentBuffer()
59 m_markSet
->remove(this);
61 if (EncodedJSValue
* base
= mallocBase())
65 size_t size() const { return m_size
; }
66 bool isEmpty() const { return !m_size
; }
68 JSValue
at(int i
) const
73 return JSValue::decode(slotFor(i
));
81 void append(JSValue v
)
83 if (m_size
>= m_capacity
)
86 slotFor(m_size
) = JSValue::encode(v
);
99 return JSValue::decode(slotFor(m_size
- 1));
102 static void markLists(HeapRootVisitor
&, ListSet
&);
105 JS_EXPORT_PRIVATE
void slowAppend(JSValue
);
107 EncodedJSValue
& slotFor(int item
) const
109 return m_buffer
[-item
];
112 EncodedJSValue
* mallocBase()
114 if (m_capacity
== static_cast<int>(inlineCapacity
))
116 return &slotFor(m_capacity
- 1);
121 EncodedJSValue m_inlineBuffer
[inlineCapacity
];
122 EncodedJSValue
* m_buffer
;
126 // Prohibits new / delete, which would break GC.
127 void* operator new(size_t size
)
129 return fastMalloc(size
);
131 void operator delete(void* p
)
136 void* operator new[](size_t);
137 void operator delete[](void*);
139 void* operator new(size_t, void*);
140 void operator delete(void*, size_t);
152 ArgList(ExecState
* exec
)
153 : m_args(reinterpret_cast<JSValue
*>(&exec
[CallFrame::argumentOffset(0)]))
154 , m_argCount(exec
->argumentCount())
158 ArgList(const MarkedArgumentBuffer
& args
)
159 : m_args(reinterpret_cast<JSValue
*>(args
.m_buffer
))
160 , m_argCount(args
.size())
164 JSValue
at(int i
) const
167 return jsUndefined();
171 bool isEmpty() const { return !m_argCount
; }
172 size_t size() const { return m_argCount
; }
174 JS_EXPORT_PRIVATE
void getSlice(int startIndex
, ArgList
& result
) const;