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 <wtf/HashSet.h>
28 #include <wtf/Vector.h>
34 class MarkedArgumentBuffer
{
35 WTF_MAKE_NONCOPYABLE(MarkedArgumentBuffer
);
40 static const size_t inlineCapacity
= 8;
41 typedef HashSet
<MarkedArgumentBuffer
*> ListSet
;
44 // Constructor for a read-write list, to which you may append values.
45 // FIXME: Remove all clients of this API, then remove this API.
46 MarkedArgumentBuffer()
48 , m_capacity(inlineCapacity
)
49 , m_buffer(m_inlineBuffer
)
54 ~MarkedArgumentBuffer()
57 m_markSet
->remove(this);
59 if (EncodedJSValue
* base
= mallocBase())
63 size_t size() const { return m_size
; }
64 bool isEmpty() const { return !m_size
; }
66 JSValue
at(int i
) const
71 return JSValue::decode(slotFor(i
));
79 void append(JSValue v
)
81 if (m_size
>= m_capacity
)
84 slotFor(m_size
) = JSValue::encode(v
);
97 return JSValue::decode(slotFor(m_size
- 1));
100 static void markLists(HeapRootVisitor
&, ListSet
&);
103 JS_EXPORT_PRIVATE
void slowAppend(JSValue
);
105 EncodedJSValue
& slotFor(int item
) const
107 return m_buffer
[item
];
110 EncodedJSValue
* mallocBase()
112 if (m_capacity
== static_cast<int>(inlineCapacity
))
119 EncodedJSValue m_inlineBuffer
[inlineCapacity
];
120 EncodedJSValue
* m_buffer
;
124 // Prohibits new / delete, which would break GC.
125 void* operator new(size_t size
)
127 return fastMalloc(size
);
129 void operator delete(void* p
)
134 void* operator new[](size_t);
135 void operator delete[](void*);
137 void* operator new(size_t, void*);
138 void operator delete(void*, size_t);
142 friend class Interpreter
;
151 ArgList(ExecState
* exec
)
152 : m_args(reinterpret_cast<JSValue
*>(&exec
[CallFrame::argumentOffset(0)]))
153 , m_argCount(exec
->argumentCount())
157 ArgList(const MarkedArgumentBuffer
& args
)
158 : m_args(reinterpret_cast<JSValue
*>(args
.m_buffer
))
159 , m_argCount(args
.size())
163 JSValue
at(int i
) const
166 return jsUndefined();
170 bool isEmpty() const { return !m_argCount
; }
171 size_t size() const { return m_argCount
; }
173 JS_EXPORT_PRIVATE
void getSlice(int startIndex
, ArgList
& result
) const;
176 JSValue
* data() const { return m_args
; }