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

« back to all changes in this revision

Viewing changes to Source/JavaScriptCore/runtime/JSCell.cpp

  • 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) 2001 Peter Kelly (pmk@post.com)
 
4
 *  Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved.
 
5
 *
 
6
 *  This library is free software; you can redistribute it and/or
 
7
 *  modify it under the terms of the GNU Library General Public
 
8
 *  License as published by the Free Software Foundation; either
 
9
 *  version 2 of the License, or (at your option) any later version.
 
10
 *
 
11
 *  This library is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 *  Library General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU Library General Public License
 
17
 *  along with this library; see the file COPYING.LIB.  If not, write to
 
18
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
 *  Boston, MA 02110-1301, USA.
 
20
 *
 
21
 */
 
22
 
 
23
#include "config.h"
 
24
#include "JSCell.h"
 
25
 
 
26
#include "JSFunction.h"
 
27
#include "JSString.h"
 
28
#include "JSObject.h"
 
29
#include "NumberObject.h"
 
30
#include <wtf/MathExtras.h>
 
31
 
 
32
namespace JSC {
 
33
 
 
34
ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSCell);
 
35
 
 
36
void JSCell::destroy(JSCell* cell)
 
37
{
 
38
    cell->JSCell::~JSCell();
 
39
}
 
40
 
 
41
void JSCell::copyBackingStore(JSCell*, CopyVisitor&)
 
42
{
 
43
}
 
44
 
 
45
bool JSCell::getString(ExecState* exec, String& stringValue) const
 
46
{
 
47
    if (!isString())
 
48
        return false;
 
49
    stringValue = static_cast<const JSString*>(this)->value(exec);
 
50
    return true;
 
51
}
 
52
 
 
53
String JSCell::getString(ExecState* exec) const
 
54
{
 
55
    return isString() ? static_cast<const JSString*>(this)->value(exec) : String();
 
56
}
 
57
 
 
58
JSObject* JSCell::getObject()
 
59
{
 
60
    return isObject() ? asObject(this) : 0;
 
61
}
 
62
 
 
63
const JSObject* JSCell::getObject() const
 
64
{
 
65
    return isObject() ? static_cast<const JSObject*>(this) : 0;
 
66
}
 
67
 
 
68
CallType JSCell::getCallData(JSCell*, CallData&)
 
69
{
 
70
    return CallTypeNone;
 
71
}
 
72
 
 
73
ConstructType JSCell::getConstructData(JSCell*, ConstructData&)
 
74
{
 
75
    return ConstructTypeNone;
 
76
}
 
77
 
 
78
bool JSCell::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName identifier, PropertySlot& slot)
 
79
{
 
80
    // This is not a general purpose implementation of getOwnPropertySlot.
 
81
    // It should only be called by JSValue::get.
 
82
    // It calls getPropertySlot, not getOwnPropertySlot.
 
83
    JSObject* object = cell->toObject(exec, exec->lexicalGlobalObject());
 
84
    slot.setBase(object);
 
85
    if (!object->getPropertySlot(exec, identifier, slot))
 
86
        slot.setUndefined();
 
87
    return true;
 
88
}
 
89
 
 
90
bool JSCell::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned identifier, PropertySlot& slot)
 
91
{
 
92
    // This is not a general purpose implementation of getOwnPropertySlot.
 
93
    // It should only be called by JSValue::get.
 
94
    // It calls getPropertySlot, not getOwnPropertySlot.
 
95
    JSObject* object = cell->toObject(exec, exec->lexicalGlobalObject());
 
96
    slot.setBase(object);
 
97
    if (!object->getPropertySlot(exec, identifier, slot))
 
98
        slot.setUndefined();
 
99
    return true;
 
100
}
 
101
 
 
102
void JSCell::put(JSCell* cell, ExecState* exec, PropertyName identifier, JSValue value, PutPropertySlot& slot)
 
103
{
 
104
    if (cell->isString()) {
 
105
        JSValue(cell).putToPrimitive(exec, identifier, value, slot);
 
106
        return;
 
107
    }
 
108
    JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
 
109
    thisObject->methodTable()->put(thisObject, exec, identifier, value, slot);
 
110
}
 
111
 
 
112
void JSCell::putByIndex(JSCell* cell, ExecState* exec, unsigned identifier, JSValue value, bool shouldThrow)
 
113
{
 
114
    if (cell->isString()) {
 
115
        PutPropertySlot slot(shouldThrow);
 
116
        JSValue(cell).putToPrimitive(exec, Identifier::from(exec, identifier), value, slot);
 
117
        return;
 
118
    }
 
119
    JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
 
120
    thisObject->methodTable()->putByIndex(thisObject, exec, identifier, value, shouldThrow);
 
121
}
 
122
 
 
123
bool JSCell::deleteProperty(JSCell* cell, ExecState* exec, PropertyName identifier)
 
124
{
 
125
    JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
 
126
    return thisObject->methodTable()->deleteProperty(thisObject, exec, identifier);
 
127
}
 
128
 
 
129
bool JSCell::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned identifier)
 
130
{
 
131
    JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
 
132
    return thisObject->methodTable()->deletePropertyByIndex(thisObject, exec, identifier);
 
133
}
 
134
 
 
135
JSObject* JSCell::toThisObject(JSCell* cell, ExecState* exec)
 
136
{
 
137
    return cell->toObject(exec, exec->lexicalGlobalObject());
 
138
}
 
139
 
 
140
JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
 
141
{
 
142
    if (isString())
 
143
        return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType);
 
144
    return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType);
 
145
}
 
146
 
 
147
bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const
 
148
{
 
149
    if (isString())
 
150
        return static_cast<const JSString*>(this)->getPrimitiveNumber(exec, number, value);
 
151
    return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value);
 
152
}
 
153
 
 
154
double JSCell::toNumber(ExecState* exec) const
 
155
 
156
    if (isString())
 
157
        return static_cast<const JSString*>(this)->toNumber(exec);
 
158
    return static_cast<const JSObject*>(this)->toNumber(exec);
 
159
}
 
160
 
 
161
JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const
 
162
{
 
163
    if (isString())
 
164
        return static_cast<const JSString*>(this)->toObject(exec, globalObject);
 
165
    ASSERT(isObject());
 
166
    return jsCast<JSObject*>(const_cast<JSCell*>(this));
 
167
}
 
168
 
 
169
void slowValidateCell(JSCell* cell)
 
170
{
 
171
    ASSERT_GC_OBJECT_LOOKS_VALID(cell);
 
172
}
 
173
 
 
174
JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType)
 
175
{
 
176
    ASSERT_NOT_REACHED();
 
177
    return jsUndefined();
 
178
}
 
179
 
 
180
void JSCell::getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
 
181
{
 
182
    ASSERT_NOT_REACHED();
 
183
}
 
184
 
 
185
void JSCell::getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
 
186
{
 
187
    ASSERT_NOT_REACHED();
 
188
}
 
189
 
 
190
String JSCell::className(const JSObject*)
 
191
{
 
192
    ASSERT_NOT_REACHED();
 
193
    return String();
 
194
}
 
195
 
 
196
const char* JSCell::className()
 
197
{
 
198
    return classInfo()->className;
 
199
}
 
200
 
 
201
void JSCell::getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
 
202
{
 
203
    ASSERT_NOT_REACHED();
 
204
}
 
205
 
 
206
bool JSCell::customHasInstance(JSObject*, ExecState*, JSValue)
 
207
{
 
208
    ASSERT_NOT_REACHED();
 
209
    return false;
 
210
}
 
211
 
 
212
void JSCell::putDirectVirtual(JSObject*, ExecState*, PropertyName, JSValue, unsigned)
 
213
{
 
214
    ASSERT_NOT_REACHED();
 
215
}
 
216
 
 
217
bool JSCell::defineOwnProperty(JSObject*, ExecState*, PropertyName, PropertyDescriptor&, bool)
 
218
{
 
219
    ASSERT_NOT_REACHED();
 
220
    return false;
 
221
}
 
222
 
 
223
bool JSCell::getOwnPropertyDescriptor(JSObject*, ExecState*, PropertyName, PropertyDescriptor&)
 
224
{
 
225
    ASSERT_NOT_REACHED();
 
226
    return false;
 
227
}
 
228
 
 
229
} // namespace JSC