]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/JSCell.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / JSCell.cpp
CommitLineData
b37bf2e1
A
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"
9dae56ea 24#include "JSCell.h"
b37bf2e1 25
81345200 26#include "ArrayBufferView.h"
9dae56ea
A
27#include "JSFunction.h"
28#include "JSString.h"
29#include "JSObject.h"
6fe7ccc8 30#include "NumberObject.h"
81345200 31#include "JSCInlines.h"
b37bf2e1
A
32#include <wtf/MathExtras.h>
33
9dae56ea 34namespace JSC {
b37bf2e1 35
81345200
A
36COMPILE_ASSERT(sizeof(JSCell) == sizeof(uint64_t), jscell_is_eight_bytes);
37STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSCell);
6fe7ccc8
A
38
39void JSCell::destroy(JSCell* cell)
b37bf2e1 40{
6fe7ccc8 41 cell->JSCell::~JSCell();
b37bf2e1
A
42}
43
81345200
A
44void JSCell::dump(PrintStream& out) const
45{
46 methodTable()->dumpToStream(this, out);
47}
48
49void JSCell::dumpToStream(const JSCell* cell, PrintStream& out)
50{
51 out.printf("<%p, %s>", cell, cell->className());
52}
53
54void JSCell::copyBackingStore(JSCell*, CopyVisitor&, CopyToken)
93a37866
A
55{
56}
57
58bool JSCell::getString(ExecState* exec, String& stringValue) const
b37bf2e1 59{
9dae56ea
A
60 if (!isString())
61 return false;
f9bf01c6 62 stringValue = static_cast<const JSString*>(this)->value(exec);
9dae56ea 63 return true;
b37bf2e1
A
64}
65
93a37866 66String JSCell::getString(ExecState* exec) const
b37bf2e1 67{
93a37866 68 return isString() ? static_cast<const JSString*>(this)->value(exec) : String();
b37bf2e1
A
69}
70
9dae56ea 71JSObject* JSCell::getObject()
b37bf2e1 72{
f9bf01c6 73 return isObject() ? asObject(this) : 0;
b37bf2e1
A
74}
75
9dae56ea 76const JSObject* JSCell::getObject() const
b37bf2e1 77{
9dae56ea 78 return isObject() ? static_cast<const JSObject*>(this) : 0;
b37bf2e1
A
79}
80
93a37866 81CallType JSCell::getCallData(JSCell*, CallData& callData)
b37bf2e1 82{
93a37866
A
83 callData.js.functionExecutable = 0;
84 callData.js.scope = 0;
85 callData.native.function = 0;
9dae56ea 86 return CallTypeNone;
b37bf2e1
A
87}
88
93a37866 89ConstructType JSCell::getConstructData(JSCell*, ConstructData& constructData)
b37bf2e1 90{
93a37866
A
91 constructData.js.functionExecutable = 0;
92 constructData.js.scope = 0;
93 constructData.native.function = 0;
9dae56ea 94 return ConstructTypeNone;
b37bf2e1
A
95}
96
93a37866 97void JSCell::put(JSCell* cell, ExecState* exec, PropertyName identifier, JSValue value, PutPropertySlot& slot)
b37bf2e1 98{
ed1e77d3 99 if (cell->isString() || cell->isSymbol()) {
6fe7ccc8
A
100 JSValue(cell).putToPrimitive(exec, identifier, value, slot);
101 return;
102 }
103 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
81345200 104 thisObject->methodTable(exec->vm())->put(thisObject, exec, identifier, value, slot);
b37bf2e1
A
105}
106
6fe7ccc8 107void JSCell::putByIndex(JSCell* cell, ExecState* exec, unsigned identifier, JSValue value, bool shouldThrow)
b37bf2e1 108{
ed1e77d3 109 if (cell->isString() || cell->isSymbol()) {
81345200 110 PutPropertySlot slot(cell, shouldThrow);
6fe7ccc8
A
111 JSValue(cell).putToPrimitive(exec, Identifier::from(exec, identifier), value, slot);
112 return;
113 }
114 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
81345200 115 thisObject->methodTable(exec->vm())->putByIndex(thisObject, exec, identifier, value, shouldThrow);
b37bf2e1
A
116}
117
93a37866 118bool JSCell::deleteProperty(JSCell* cell, ExecState* exec, PropertyName identifier)
b37bf2e1 119{
6fe7ccc8 120 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
81345200 121 return thisObject->methodTable(exec->vm())->deleteProperty(thisObject, exec, identifier);
b37bf2e1
A
122}
123
6fe7ccc8 124bool JSCell::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned identifier)
b37bf2e1 125{
6fe7ccc8 126 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
81345200 127 return thisObject->methodTable(exec->vm())->deletePropertyByIndex(thisObject, exec, identifier);
b37bf2e1
A
128}
129
81345200 130JSValue JSCell::toThis(JSCell* cell, ExecState* exec, ECMAMode ecmaMode)
b37bf2e1 131{
81345200
A
132 if (ecmaMode == StrictMode)
133 return cell;
6fe7ccc8 134 return cell->toObject(exec, exec->lexicalGlobalObject());
b37bf2e1
A
135}
136
6fe7ccc8 137JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
b37bf2e1 138{
6fe7ccc8
A
139 if (isString())
140 return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType);
ed1e77d3
A
141 if (isSymbol())
142 return static_cast<const Symbol*>(this)->toPrimitive(exec, preferredType);
6fe7ccc8 143 return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType);
9dae56ea
A
144}
145
6fe7ccc8 146bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const
9dae56ea 147{
6fe7ccc8
A
148 if (isString())
149 return static_cast<const JSString*>(this)->getPrimitiveNumber(exec, number, value);
ed1e77d3
A
150 if (isSymbol())
151 return static_cast<const Symbol*>(this)->getPrimitiveNumber(exec, number, value);
6fe7ccc8
A
152 return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value);
153}
154
155double JSCell::toNumber(ExecState* exec) const
156{
157 if (isString())
158 return static_cast<const JSString*>(this)->toNumber(exec);
ed1e77d3
A
159 if (isSymbol())
160 return static_cast<const Symbol*>(this)->toNumber(exec);
6fe7ccc8
A
161 return static_cast<const JSObject*>(this)->toNumber(exec);
162}
163
164JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const
165{
166 if (isString())
167 return static_cast<const JSString*>(this)->toObject(exec, globalObject);
ed1e77d3
A
168 if (isSymbol())
169 return static_cast<const Symbol*>(this)->toObject(exec, globalObject);
6fe7ccc8
A
170 ASSERT(isObject());
171 return jsCast<JSObject*>(const_cast<JSCell*>(this));
b37bf2e1
A
172}
173
6fe7ccc8
A
174void slowValidateCell(JSCell* cell)
175{
176 ASSERT_GC_OBJECT_LOOKS_VALID(cell);
177}
178
179JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType)
f9bf01c6 180{
93a37866 181 RELEASE_ASSERT_NOT_REACHED();
6fe7ccc8 182 return jsUndefined();
f9bf01c6
A
183}
184
81345200
A
185bool JSCell::getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&)
186{
187 RELEASE_ASSERT_NOT_REACHED();
188 return false;
189}
190
191bool JSCell::getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned, PropertySlot&)
192{
193 RELEASE_ASSERT_NOT_REACHED();
194 return false;
195}
196
6fe7ccc8 197void JSCell::getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
f9bf01c6 198{
93a37866
A
199 RELEASE_ASSERT_NOT_REACHED();
200}
201
202void JSCell::getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
203{
204 RELEASE_ASSERT_NOT_REACHED();
205}
206
207String JSCell::className(const JSObject*)
208{
209 RELEASE_ASSERT_NOT_REACHED();
210 return String();
f9bf01c6
A
211}
212
81345200 213const char* JSCell::className() const
f9bf01c6 214{
93a37866 215 return classInfo()->className;
f9bf01c6
A
216}
217
6fe7ccc8 218void JSCell::getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
f9bf01c6 219{
93a37866 220 RELEASE_ASSERT_NOT_REACHED();
f9bf01c6
A
221}
222
93a37866 223bool JSCell::customHasInstance(JSObject*, ExecState*, JSValue)
f9bf01c6 224{
93a37866 225 RELEASE_ASSERT_NOT_REACHED();
6fe7ccc8 226 return false;
f9bf01c6
A
227}
228
81345200 229bool JSCell::defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool)
f9bf01c6 230{
93a37866 231 RELEASE_ASSERT_NOT_REACHED();
81345200 232 return false;
f9bf01c6
A
233}
234
81345200 235ArrayBuffer* JSCell::slowDownAndWasteMemory(JSArrayBufferView*)
14957cd0 236{
93a37866 237 RELEASE_ASSERT_NOT_REACHED();
81345200 238 return 0;
14957cd0
A
239}
240
81345200 241PassRefPtr<ArrayBufferView> JSCell::getTypedArrayImpl(JSArrayBufferView*)
14957cd0 242{
93a37866 243 RELEASE_ASSERT_NOT_REACHED();
81345200 244 return 0;
14957cd0
A
245}
246
ed1e77d3
A
247uint32_t JSCell::getEnumerableLength(ExecState*, JSObject*)
248{
249 RELEASE_ASSERT_NOT_REACHED();
250 return 0;
251}
252
253void JSCell::getStructurePropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
254{
255 RELEASE_ASSERT_NOT_REACHED();
256}
257
258void JSCell::getGenericPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
259{
260 RELEASE_ASSERT_NOT_REACHED();
261}
262
9dae56ea 263} // namespace JSC