tizen beta release
[framework/web/webkit-efl.git] / Source / JavaScriptCore / runtime / ArgList.cpp
1 /*
2  *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
3  *
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.
8  *
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.
13  *
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.
18  *
19  */
20
21 #include "config.h"
22 #include "ArgList.h"
23
24 #include "HeapRootVisitor.h"
25 #include "JSValue.h"
26 #include "JSObject.h"
27 #include "ScopeChain.h"
28
29 using std::min;
30
31 namespace JSC {
32
33 void ArgList::getSlice(int startIndex, ArgList& result) const
34 {
35     if (startIndex <= 0 || static_cast<unsigned>(startIndex) >= m_argCount) {
36         result = ArgList();
37         return;
38     }
39
40     result.m_args = m_args + startIndex;
41     result.m_argCount =  m_argCount - startIndex;
42 }
43
44 void MarkedArgumentBuffer::markLists(HeapRootVisitor& heapRootVisitor, ListSet& markSet)
45 {
46     ListSet::iterator end = markSet.end();
47     for (ListSet::iterator it = markSet.begin(); it != end; ++it) {
48         MarkedArgumentBuffer* list = *it;
49         heapRootVisitor.visit(reinterpret_cast<JSValue*>(list->m_buffer), list->m_size);
50     }
51 }
52
53 void MarkedArgumentBuffer::slowAppend(JSValue v)
54 {
55     // As long as our size stays within our Vector's inline 
56     // capacity, all our values are allocated on the stack, and 
57     // therefore don't need explicit marking. Once our size exceeds
58     // our Vector's inline capacity, though, our values move to the 
59     // heap, where they do need explicit marking.
60     if (!m_markSet) {
61         // FIXME: Even if v is not a JSCell*, if previous values in the buffer
62         // are, then they won't be marked!
63         if (Heap* heap = Heap::heap(v)) {
64             ListSet& markSet = heap->markListSet();
65             markSet.add(this);
66             m_markSet = &markSet;
67         }
68     }
69
70     if (m_vector.size() < m_vector.capacity()) {
71         m_vector.uncheckedAppend(v);
72         return;
73     }
74
75     // 4x growth would be excessive for a normal vector, but it's OK for Lists 
76     // because they're short-lived.
77     m_vector.reserveCapacity(m_vector.capacity() * 4);
78     
79     m_vector.uncheckedAppend(v);
80     m_buffer = m_vector.data();
81 }
82
83 } // namespace JSC