]>
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 | |
9dae56ea A |
26 | #include "JSFunction.h" |
27 | #include "JSString.h" | |
28 | #include "JSObject.h" | |
6fe7ccc8 | 29 | #include "NumberObject.h" |
93a37866 | 30 | #include "Operations.h" |
b37bf2e1 A |
31 | #include <wtf/MathExtras.h> |
32 | ||
9dae56ea | 33 | namespace JSC { |
b37bf2e1 | 34 | |
6fe7ccc8 A |
35 | ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSCell); |
36 | ||
37 | void JSCell::destroy(JSCell* cell) | |
b37bf2e1 | 38 | { |
6fe7ccc8 | 39 | cell->JSCell::~JSCell(); |
b37bf2e1 A |
40 | } |
41 | ||
93a37866 A |
42 | void JSCell::copyBackingStore(JSCell*, CopyVisitor&) |
43 | { | |
44 | } | |
45 | ||
46 | bool JSCell::getString(ExecState* exec, String& stringValue) const | |
b37bf2e1 | 47 | { |
9dae56ea A |
48 | if (!isString()) |
49 | return false; | |
f9bf01c6 | 50 | stringValue = static_cast<const JSString*>(this)->value(exec); |
9dae56ea | 51 | return true; |
b37bf2e1 A |
52 | } |
53 | ||
93a37866 | 54 | String JSCell::getString(ExecState* exec) const |
b37bf2e1 | 55 | { |
93a37866 | 56 | return isString() ? static_cast<const JSString*>(this)->value(exec) : String(); |
b37bf2e1 A |
57 | } |
58 | ||
9dae56ea | 59 | JSObject* JSCell::getObject() |
b37bf2e1 | 60 | { |
f9bf01c6 | 61 | return isObject() ? asObject(this) : 0; |
b37bf2e1 A |
62 | } |
63 | ||
9dae56ea | 64 | const JSObject* JSCell::getObject() const |
b37bf2e1 | 65 | { |
9dae56ea | 66 | return isObject() ? static_cast<const JSObject*>(this) : 0; |
b37bf2e1 A |
67 | } |
68 | ||
93a37866 | 69 | CallType JSCell::getCallData(JSCell*, CallData& callData) |
b37bf2e1 | 70 | { |
93a37866 A |
71 | callData.js.functionExecutable = 0; |
72 | callData.js.scope = 0; | |
73 | callData.native.function = 0; | |
9dae56ea | 74 | return CallTypeNone; |
b37bf2e1 A |
75 | } |
76 | ||
93a37866 | 77 | ConstructType JSCell::getConstructData(JSCell*, ConstructData& constructData) |
b37bf2e1 | 78 | { |
93a37866 A |
79 | constructData.js.functionExecutable = 0; |
80 | constructData.js.scope = 0; | |
81 | constructData.native.function = 0; | |
9dae56ea | 82 | return ConstructTypeNone; |
b37bf2e1 A |
83 | } |
84 | ||
93a37866 | 85 | bool JSCell::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName identifier, PropertySlot& slot) |
b37bf2e1 | 86 | { |
9dae56ea A |
87 | // This is not a general purpose implementation of getOwnPropertySlot. |
88 | // It should only be called by JSValue::get. | |
89 | // It calls getPropertySlot, not getOwnPropertySlot. | |
6fe7ccc8 | 90 | JSObject* object = cell->toObject(exec, exec->lexicalGlobalObject()); |
9dae56ea A |
91 | slot.setBase(object); |
92 | if (!object->getPropertySlot(exec, identifier, slot)) | |
93 | slot.setUndefined(); | |
94 | return true; | |
b37bf2e1 A |
95 | } |
96 | ||
6fe7ccc8 | 97 | bool JSCell::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned identifier, PropertySlot& slot) |
b37bf2e1 | 98 | { |
9dae56ea A |
99 | // This is not a general purpose implementation of getOwnPropertySlot. |
100 | // It should only be called by JSValue::get. | |
101 | // It calls getPropertySlot, not getOwnPropertySlot. | |
6fe7ccc8 | 102 | JSObject* object = cell->toObject(exec, exec->lexicalGlobalObject()); |
9dae56ea A |
103 | slot.setBase(object); |
104 | if (!object->getPropertySlot(exec, identifier, slot)) | |
105 | slot.setUndefined(); | |
b37bf2e1 A |
106 | return true; |
107 | } | |
108 | ||
93a37866 | 109 | void JSCell::put(JSCell* cell, ExecState* exec, PropertyName identifier, JSValue value, PutPropertySlot& slot) |
b37bf2e1 | 110 | { |
6fe7ccc8 A |
111 | if (cell->isString()) { |
112 | JSValue(cell).putToPrimitive(exec, identifier, value, slot); | |
113 | return; | |
114 | } | |
115 | JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject()); | |
116 | thisObject->methodTable()->put(thisObject, exec, identifier, value, slot); | |
b37bf2e1 A |
117 | } |
118 | ||
6fe7ccc8 | 119 | void JSCell::putByIndex(JSCell* cell, ExecState* exec, unsigned identifier, JSValue value, bool shouldThrow) |
b37bf2e1 | 120 | { |
6fe7ccc8 A |
121 | if (cell->isString()) { |
122 | PutPropertySlot slot(shouldThrow); | |
123 | JSValue(cell).putToPrimitive(exec, Identifier::from(exec, identifier), value, slot); | |
124 | return; | |
125 | } | |
126 | JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject()); | |
127 | thisObject->methodTable()->putByIndex(thisObject, exec, identifier, value, shouldThrow); | |
b37bf2e1 A |
128 | } |
129 | ||
93a37866 | 130 | bool JSCell::deleteProperty(JSCell* cell, ExecState* exec, PropertyName identifier) |
b37bf2e1 | 131 | { |
6fe7ccc8 A |
132 | JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject()); |
133 | return thisObject->methodTable()->deleteProperty(thisObject, exec, identifier); | |
b37bf2e1 A |
134 | } |
135 | ||
6fe7ccc8 | 136 | bool JSCell::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned identifier) |
b37bf2e1 | 137 | { |
6fe7ccc8 A |
138 | JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject()); |
139 | return thisObject->methodTable()->deletePropertyByIndex(thisObject, exec, identifier); | |
b37bf2e1 A |
140 | } |
141 | ||
6fe7ccc8 | 142 | JSObject* JSCell::toThisObject(JSCell* cell, ExecState* exec) |
b37bf2e1 | 143 | { |
6fe7ccc8 | 144 | return cell->toObject(exec, exec->lexicalGlobalObject()); |
b37bf2e1 A |
145 | } |
146 | ||
6fe7ccc8 | 147 | JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const |
b37bf2e1 | 148 | { |
6fe7ccc8 A |
149 | if (isString()) |
150 | return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType); | |
151 | return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType); | |
9dae56ea A |
152 | } |
153 | ||
6fe7ccc8 | 154 | bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const |
9dae56ea | 155 | { |
6fe7ccc8 A |
156 | if (isString()) |
157 | return static_cast<const JSString*>(this)->getPrimitiveNumber(exec, number, value); | |
158 | return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value); | |
159 | } | |
160 | ||
161 | double JSCell::toNumber(ExecState* exec) const | |
162 | { | |
163 | if (isString()) | |
164 | return static_cast<const JSString*>(this)->toNumber(exec); | |
165 | return static_cast<const JSObject*>(this)->toNumber(exec); | |
166 | } | |
167 | ||
168 | JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const | |
169 | { | |
170 | if (isString()) | |
171 | return static_cast<const JSString*>(this)->toObject(exec, globalObject); | |
172 | ASSERT(isObject()); | |
173 | return jsCast<JSObject*>(const_cast<JSCell*>(this)); | |
b37bf2e1 A |
174 | } |
175 | ||
6fe7ccc8 A |
176 | void slowValidateCell(JSCell* cell) |
177 | { | |
178 | ASSERT_GC_OBJECT_LOOKS_VALID(cell); | |
179 | } | |
180 | ||
181 | JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType) | |
f9bf01c6 | 182 | { |
93a37866 | 183 | RELEASE_ASSERT_NOT_REACHED(); |
6fe7ccc8 | 184 | return jsUndefined(); |
f9bf01c6 A |
185 | } |
186 | ||
6fe7ccc8 | 187 | void JSCell::getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode) |
f9bf01c6 | 188 | { |
93a37866 A |
189 | RELEASE_ASSERT_NOT_REACHED(); |
190 | } | |
191 | ||
192 | void JSCell::getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode) | |
193 | { | |
194 | RELEASE_ASSERT_NOT_REACHED(); | |
195 | } | |
196 | ||
197 | String JSCell::className(const JSObject*) | |
198 | { | |
199 | RELEASE_ASSERT_NOT_REACHED(); | |
200 | return String(); | |
f9bf01c6 A |
201 | } |
202 | ||
93a37866 | 203 | const char* JSCell::className() |
f9bf01c6 | 204 | { |
93a37866 | 205 | return classInfo()->className; |
f9bf01c6 A |
206 | } |
207 | ||
6fe7ccc8 | 208 | void JSCell::getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode) |
f9bf01c6 | 209 | { |
93a37866 | 210 | RELEASE_ASSERT_NOT_REACHED(); |
f9bf01c6 A |
211 | } |
212 | ||
93a37866 | 213 | bool JSCell::customHasInstance(JSObject*, ExecState*, JSValue) |
f9bf01c6 | 214 | { |
93a37866 | 215 | RELEASE_ASSERT_NOT_REACHED(); |
6fe7ccc8 | 216 | return false; |
f9bf01c6 A |
217 | } |
218 | ||
93a37866 | 219 | void JSCell::putDirectVirtual(JSObject*, ExecState*, PropertyName, JSValue, unsigned) |
f9bf01c6 | 220 | { |
93a37866 | 221 | RELEASE_ASSERT_NOT_REACHED(); |
f9bf01c6 A |
222 | } |
223 | ||
93a37866 | 224 | bool JSCell::defineOwnProperty(JSObject*, ExecState*, PropertyName, PropertyDescriptor&, bool) |
14957cd0 | 225 | { |
93a37866 | 226 | RELEASE_ASSERT_NOT_REACHED(); |
14957cd0 | 227 | return false; |
14957cd0 A |
228 | } |
229 | ||
93a37866 | 230 | bool JSCell::getOwnPropertyDescriptor(JSObject*, ExecState*, PropertyName, PropertyDescriptor&) |
14957cd0 | 231 | { |
93a37866 | 232 | RELEASE_ASSERT_NOT_REACHED(); |
6fe7ccc8 | 233 | return false; |
14957cd0 A |
234 | } |
235 | ||
9dae56ea | 236 | } // namespace JSC |