~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/JavaScriptCore/runtime/ArgList.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
 
3
 *  Copyright (C) 2003, 2007, 2008, 2009 Apple Inc. All rights reserved.
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 *
 
20
 */
 
21
 
 
22
#ifndef ArgList_h
 
23
#define ArgList_h
 
24
 
 
25
#include "CallFrame.h"
 
26
#include "Register.h"
 
27
#include <wtf/HashSet.h>
 
28
#include <wtf/Vector.h>
 
29
 
 
30
namespace JSC {
 
31
 
 
32
class SlotVisitor;
 
33
 
 
34
class MarkedArgumentBuffer {
 
35
    WTF_MAKE_NONCOPYABLE(MarkedArgumentBuffer);
 
36
    friend class JSGlobalData;
 
37
    friend class ArgList;
 
38
 
 
39
private:
 
40
    static const size_t inlineCapacity = 8;
 
41
    typedef Vector<Register, inlineCapacity> VectorType;
 
42
    typedef HashSet<MarkedArgumentBuffer*> ListSet;
 
43
 
 
44
public:
 
45
    // Constructor for a read-write list, to which you may append values.
 
46
    // FIXME: Remove all clients of this API, then remove this API.
 
47
    MarkedArgumentBuffer()
 
48
        : m_size(0)
 
49
        , m_capacity(inlineCapacity)
 
50
        , m_buffer(&m_inlineBuffer[m_capacity - 1])
 
51
        , m_markSet(0)
 
52
    {
 
53
    }
 
54
 
 
55
    ~MarkedArgumentBuffer()
 
56
    {
 
57
        if (m_markSet)
 
58
            m_markSet->remove(this);
 
59
 
 
60
        if (EncodedJSValue* base = mallocBase())
 
61
            delete [] base;
 
62
    }
 
63
 
 
64
    size_t size() const { return m_size; }
 
65
    bool isEmpty() const { return !m_size; }
 
66
 
 
67
    JSValue at(int i) const
 
68
    {
 
69
        if (i >= m_size)
 
70
            return jsUndefined();
 
71
 
 
72
        return JSValue::decode(slotFor(i));
 
73
    }
 
74
 
 
75
    void clear()
 
76
    {
 
77
        m_size = 0;
 
78
    }
 
79
 
 
80
    void append(JSValue v)
 
81
    {
 
82
        if (m_size >= m_capacity)
 
83
            return slowAppend(v);
 
84
 
 
85
        slotFor(m_size) = JSValue::encode(v);
 
86
        ++m_size;
 
87
    }
 
88
 
 
89
    void removeLast()
 
90
    { 
 
91
        ASSERT(m_size);
 
92
        m_size--;
 
93
    }
 
94
 
 
95
    JSValue last() 
 
96
    {
 
97
        ASSERT(m_size);
 
98
        return JSValue::decode(slotFor(m_size - 1));
 
99
    }
 
100
        
 
101
    static void markLists(HeapRootVisitor&, ListSet&);
 
102
 
 
103
private:
 
104
    JS_EXPORT_PRIVATE void slowAppend(JSValue);
 
105
        
 
106
    EncodedJSValue& slotFor(int item) const
 
107
    {
 
108
        return m_buffer[-item];
 
109
    }
 
110
        
 
111
    EncodedJSValue* mallocBase()
 
112
    {
 
113
        if (m_capacity == static_cast<int>(inlineCapacity))
 
114
            return 0;
 
115
        return &slotFor(m_capacity - 1);
 
116
    }
 
117
        
 
118
    int m_size;
 
119
    int m_capacity;
 
120
    EncodedJSValue m_inlineBuffer[inlineCapacity];
 
121
    EncodedJSValue* m_buffer;
 
122
    ListSet* m_markSet;
 
123
 
 
124
private:
 
125
    // Prohibits new / delete, which would break GC.
 
126
    void* operator new(size_t size)
 
127
    {
 
128
        return fastMalloc(size);
 
129
    }
 
130
    void operator delete(void* p)
 
131
    {
 
132
        fastFree(p);
 
133
    }
 
134
 
 
135
    void* operator new[](size_t);
 
136
    void operator delete[](void*);
 
137
 
 
138
    void* operator new(size_t, void*);
 
139
    void operator delete(void*, size_t);
 
140
};
 
141
 
 
142
class ArgList {
 
143
    friend class JIT;
 
144
public:
 
145
    ArgList()
 
146
        : m_args(0)
 
147
        , m_argCount(0)
 
148
    {
 
149
    }
 
150
 
 
151
    ArgList(ExecState* exec)
 
152
        : m_args(reinterpret_cast<JSValue*>(&exec[CallFrame::argumentOffset(0)]))
 
153
        , m_argCount(exec->argumentCount())
 
154
    {
 
155
    }
 
156
 
 
157
    ArgList(const MarkedArgumentBuffer& args)
 
158
        : m_args(reinterpret_cast<JSValue*>(args.m_buffer))
 
159
        , m_argCount(args.size())
 
160
    {
 
161
    }
 
162
 
 
163
    JSValue at(int i) const
 
164
    {
 
165
        if (i >= m_argCount)
 
166
            return jsUndefined();
 
167
        return m_args[-i];
 
168
    }
 
169
 
 
170
    bool isEmpty() const { return !m_argCount; }
 
171
    size_t size() const { return m_argCount; }
 
172
        
 
173
    JS_EXPORT_PRIVATE void getSlice(int startIndex, ArgList& result) const;
 
174
 
 
175
private:
 
176
    JSValue* m_args;
 
177
    int m_argCount;
 
178
};
 
179
 
 
180
} // namespace JSC
 
181
 
 
182
#endif // ArgList_h