]>
Commit | Line | Data |
---|---|---|
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 | 34 | namespace JSC { |
b37bf2e1 | 35 | |
81345200 A |
36 | COMPILE_ASSERT(sizeof(JSCell) == sizeof(uint64_t), jscell_is_eight_bytes); |
37 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSCell); | |
6fe7ccc8 A |
38 | |
39 | void JSCell::destroy(JSCell* cell) | |
b37bf2e1 | 40 | { |
6fe7ccc8 | 41 | cell->JSCell::~JSCell(); |
b37bf2e1 A |
42 | } |
43 | ||
81345200 A |
44 | void JSCell::dump(PrintStream& out) const |
45 | { | |
46 | methodTable()->dumpToStream(this, out); | |
47 | } | |
48 | ||
49 | void JSCell::dumpToStream(const JSCell* cell, PrintStream& out) | |
50 | { | |
51 | out.printf("<%p, %s>", cell, cell->className()); | |
52 | } | |
53 | ||
54 | void JSCell::copyBackingStore(JSCell*, CopyVisitor&, CopyToken) | |
93a37866 A |
55 | { |
56 | } | |
57 | ||
58 | bool 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 | 66 | String JSCell::getString(ExecState* exec) const |
b37bf2e1 | 67 | { |
93a37866 | 68 | return isString() ? static_cast<const JSString*>(this)->value(exec) : String(); |
b37bf2e1 A |
69 | } |
70 | ||
9dae56ea | 71 | JSObject* JSCell::getObject() |
b37bf2e1 | 72 | { |
f9bf01c6 | 73 | return isObject() ? asObject(this) : 0; |
b37bf2e1 A |
74 | } |
75 | ||
9dae56ea | 76 | const JSObject* JSCell::getObject() const |
b37bf2e1 | 77 | { |
9dae56ea | 78 | return isObject() ? static_cast<const JSObject*>(this) : 0; |
b37bf2e1 A |
79 | } |
80 | ||
93a37866 | 81 | CallType 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 | 89 | ConstructType 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 | 97 | void JSCell::put(JSCell* cell, ExecState* exec, PropertyName identifier, JSValue value, PutPropertySlot& slot) |
b37bf2e1 | 98 | { |
6fe7ccc8 A |
99 | if (cell->isString()) { |
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 | 107 | void JSCell::putByIndex(JSCell* cell, ExecState* exec, unsigned identifier, JSValue value, bool shouldThrow) |
b37bf2e1 | 108 | { |
6fe7ccc8 | 109 | if (cell->isString()) { |
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 | 118 | bool 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 | 124 | bool 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 | 130 | JSValue 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 | 137 | JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const |
b37bf2e1 | 138 | { |
6fe7ccc8 A |
139 | if (isString()) |
140 | return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType); | |
141 | return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType); | |
9dae56ea A |
142 | } |
143 | ||
6fe7ccc8 | 144 | bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const |
9dae56ea | 145 | { |
6fe7ccc8 A |
146 | if (isString()) |
147 | return static_cast<const JSString*>(this)->getPrimitiveNumber(exec, number, value); | |
148 | return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value); | |
149 | } | |
150 | ||
151 | double JSCell::toNumber(ExecState* exec) const | |
152 | { | |
153 | if (isString()) | |
154 | return static_cast<const JSString*>(this)->toNumber(exec); | |
155 | return static_cast<const JSObject*>(this)->toNumber(exec); | |
156 | } | |
157 | ||
158 | JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const | |
159 | { | |
160 | if (isString()) | |
161 | return static_cast<const JSString*>(this)->toObject(exec, globalObject); | |
162 | ASSERT(isObject()); | |
163 | return jsCast<JSObject*>(const_cast<JSCell*>(this)); | |
b37bf2e1 A |
164 | } |
165 | ||
6fe7ccc8 A |
166 | void slowValidateCell(JSCell* cell) |
167 | { | |
168 | ASSERT_GC_OBJECT_LOOKS_VALID(cell); | |
169 | } | |
170 | ||
171 | JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType) | |
f9bf01c6 | 172 | { |
93a37866 | 173 | RELEASE_ASSERT_NOT_REACHED(); |
6fe7ccc8 | 174 | return jsUndefined(); |
f9bf01c6 A |
175 | } |
176 | ||
81345200 A |
177 | bool JSCell::getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&) |
178 | { | |
179 | RELEASE_ASSERT_NOT_REACHED(); | |
180 | return false; | |
181 | } | |
182 | ||
183 | bool JSCell::getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned, PropertySlot&) | |
184 | { | |
185 | RELEASE_ASSERT_NOT_REACHED(); | |
186 | return false; | |
187 | } | |
188 | ||
6fe7ccc8 | 189 | void JSCell::getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode) |
f9bf01c6 | 190 | { |
93a37866 A |
191 | RELEASE_ASSERT_NOT_REACHED(); |
192 | } | |
193 | ||
194 | void JSCell::getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode) | |
195 | { | |
196 | RELEASE_ASSERT_NOT_REACHED(); | |
197 | } | |
198 | ||
199 | String JSCell::className(const JSObject*) | |
200 | { | |
201 | RELEASE_ASSERT_NOT_REACHED(); | |
202 | return String(); | |
f9bf01c6 A |
203 | } |
204 | ||
81345200 | 205 | const char* JSCell::className() const |
f9bf01c6 | 206 | { |
93a37866 | 207 | return classInfo()->className; |
f9bf01c6 A |
208 | } |
209 | ||
6fe7ccc8 | 210 | void JSCell::getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode) |
f9bf01c6 | 211 | { |
93a37866 | 212 | RELEASE_ASSERT_NOT_REACHED(); |
f9bf01c6 A |
213 | } |
214 | ||
93a37866 | 215 | bool JSCell::customHasInstance(JSObject*, ExecState*, JSValue) |
f9bf01c6 | 216 | { |
93a37866 | 217 | RELEASE_ASSERT_NOT_REACHED(); |
6fe7ccc8 | 218 | return false; |
f9bf01c6 A |
219 | } |
220 | ||
81345200 | 221 | bool JSCell::defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool) |
f9bf01c6 | 222 | { |
93a37866 | 223 | RELEASE_ASSERT_NOT_REACHED(); |
81345200 | 224 | return false; |
f9bf01c6 A |
225 | } |
226 | ||
81345200 | 227 | ArrayBuffer* JSCell::slowDownAndWasteMemory(JSArrayBufferView*) |
14957cd0 | 228 | { |
93a37866 | 229 | RELEASE_ASSERT_NOT_REACHED(); |
81345200 | 230 | return 0; |
14957cd0 A |
231 | } |
232 | ||
81345200 | 233 | PassRefPtr<ArrayBufferView> JSCell::getTypedArrayImpl(JSArrayBufferView*) |
14957cd0 | 234 | { |
93a37866 | 235 | RELEASE_ASSERT_NOT_REACHED(); |
81345200 | 236 | return 0; |
14957cd0 A |
237 | } |
238 | ||
9dae56ea | 239 | } // namespace JSC |