]>
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" | |
b37bf2e1 A |
29 | #include <wtf/MathExtras.h> |
30 | ||
9dae56ea | 31 | namespace JSC { |
b37bf2e1 A |
32 | |
33 | #if defined NAN && defined INFINITY | |
34 | ||
35 | extern const double NaN = NAN; | |
36 | extern const double Inf = INFINITY; | |
37 | ||
38 | #else // !(defined NAN && defined INFINITY) | |
39 | ||
40 | // The trick is to define the NaN and Inf globals with a different type than the declaration. | |
41 | // This trick works because the mangled name of the globals does not include the type, although | |
42 | // I'm not sure that's guaranteed. There could be alignment issues with this, since arrays of | |
43 | // characters don't necessarily need the same alignment doubles do, but for now it seems to work. | |
44 | // It would be good to figure out a 100% clean way that still avoids code that runs at init time. | |
45 | ||
46 | // Note, we have to use union to ensure alignment. Otherwise, NaN_Bytes can start anywhere, | |
47 | // while NaN_double has to be 4-byte aligned for 32-bits. | |
48 | // With -fstrict-aliasing enabled, unions are the only safe way to do type masquerading. | |
49 | ||
50 | static const union { | |
51 | struct { | |
52 | unsigned char NaN_Bytes[8]; | |
53 | unsigned char Inf_Bytes[8]; | |
54 | } bytes; | |
55 | ||
56 | struct { | |
57 | double NaN_Double; | |
58 | double Inf_Double; | |
59 | } doubles; | |
60 | ||
61 | } NaNInf = { { | |
f9bf01c6 | 62 | #if CPU(BIG_ENDIAN) |
b37bf2e1 A |
63 | { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 }, |
64 | { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 } | |
f9bf01c6 | 65 | #elif CPU(MIDDLE_ENDIAN) |
b37bf2e1 A |
66 | { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 }, |
67 | { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 } | |
68 | #else | |
69 | { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f }, | |
70 | { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } | |
71 | #endif | |
72 | } } ; | |
73 | ||
74 | extern const double NaN = NaNInf.doubles.NaN_Double; | |
75 | extern const double Inf = NaNInf.doubles.Inf_Double; | |
76 | ||
77 | #endif // !(defined NAN && defined INFINITY) | |
78 | ||
14957cd0 A |
79 | const ClassInfo JSCell::s_dummyCellInfo = { "DummyCell", 0, 0, 0 }; |
80 | ||
b37bf2e1 A |
81 | bool JSCell::getUInt32(uint32_t&) const |
82 | { | |
83 | return false; | |
84 | } | |
85 | ||
f9bf01c6 | 86 | bool JSCell::getString(ExecState* exec, UString&stringValue) const |
b37bf2e1 | 87 | { |
9dae56ea A |
88 | if (!isString()) |
89 | return false; | |
f9bf01c6 | 90 | stringValue = static_cast<const JSString*>(this)->value(exec); |
9dae56ea | 91 | return true; |
b37bf2e1 A |
92 | } |
93 | ||
f9bf01c6 | 94 | UString JSCell::getString(ExecState* exec) const |
b37bf2e1 | 95 | { |
f9bf01c6 | 96 | return isString() ? static_cast<const JSString*>(this)->value(exec) : UString(); |
b37bf2e1 A |
97 | } |
98 | ||
9dae56ea | 99 | JSObject* JSCell::getObject() |
b37bf2e1 | 100 | { |
f9bf01c6 | 101 | return isObject() ? asObject(this) : 0; |
b37bf2e1 A |
102 | } |
103 | ||
9dae56ea | 104 | const JSObject* JSCell::getObject() const |
b37bf2e1 | 105 | { |
9dae56ea | 106 | return isObject() ? static_cast<const JSObject*>(this) : 0; |
b37bf2e1 A |
107 | } |
108 | ||
9dae56ea | 109 | CallType JSCell::getCallData(CallData&) |
b37bf2e1 | 110 | { |
9dae56ea | 111 | return CallTypeNone; |
b37bf2e1 A |
112 | } |
113 | ||
9dae56ea | 114 | ConstructType JSCell::getConstructData(ConstructData&) |
b37bf2e1 | 115 | { |
9dae56ea | 116 | return ConstructTypeNone; |
b37bf2e1 A |
117 | } |
118 | ||
9dae56ea | 119 | bool JSCell::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, PropertySlot& slot) |
b37bf2e1 | 120 | { |
9dae56ea A |
121 | // This is not a general purpose implementation of getOwnPropertySlot. |
122 | // It should only be called by JSValue::get. | |
123 | // It calls getPropertySlot, not getOwnPropertySlot. | |
14957cd0 | 124 | JSObject* object = toObject(exec, exec->lexicalGlobalObject()); |
9dae56ea A |
125 | slot.setBase(object); |
126 | if (!object->getPropertySlot(exec, identifier, slot)) | |
127 | slot.setUndefined(); | |
128 | return true; | |
b37bf2e1 A |
129 | } |
130 | ||
9dae56ea | 131 | bool JSCell::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySlot& slot) |
b37bf2e1 | 132 | { |
9dae56ea A |
133 | // This is not a general purpose implementation of getOwnPropertySlot. |
134 | // It should only be called by JSValue::get. | |
135 | // It calls getPropertySlot, not getOwnPropertySlot. | |
14957cd0 | 136 | JSObject* object = toObject(exec, exec->lexicalGlobalObject()); |
9dae56ea A |
137 | slot.setBase(object); |
138 | if (!object->getPropertySlot(exec, identifier, slot)) | |
139 | slot.setUndefined(); | |
b37bf2e1 A |
140 | return true; |
141 | } | |
142 | ||
ba379fdc | 143 | void JSCell::put(ExecState* exec, const Identifier& identifier, JSValue value, PutPropertySlot& slot) |
b37bf2e1 | 144 | { |
14957cd0 | 145 | toObject(exec, exec->lexicalGlobalObject())->put(exec, identifier, value, slot); |
b37bf2e1 A |
146 | } |
147 | ||
ba379fdc | 148 | void JSCell::put(ExecState* exec, unsigned identifier, JSValue value) |
b37bf2e1 | 149 | { |
14957cd0 | 150 | toObject(exec, exec->lexicalGlobalObject())->put(exec, identifier, value); |
b37bf2e1 A |
151 | } |
152 | ||
9dae56ea | 153 | bool JSCell::deleteProperty(ExecState* exec, const Identifier& identifier) |
b37bf2e1 | 154 | { |
14957cd0 | 155 | return toObject(exec, exec->lexicalGlobalObject())->deleteProperty(exec, identifier); |
b37bf2e1 A |
156 | } |
157 | ||
9dae56ea | 158 | bool JSCell::deleteProperty(ExecState* exec, unsigned identifier) |
b37bf2e1 | 159 | { |
14957cd0 | 160 | return toObject(exec, exec->lexicalGlobalObject())->deleteProperty(exec, identifier); |
b37bf2e1 A |
161 | } |
162 | ||
9dae56ea | 163 | JSObject* JSCell::toThisObject(ExecState* exec) const |
b37bf2e1 | 164 | { |
14957cd0 | 165 | return toObject(exec, exec->lexicalGlobalObject()); |
b37bf2e1 A |
166 | } |
167 | ||
ba379fdc | 168 | JSValue JSCell::getJSNumber() |
b37bf2e1 | 169 | { |
ba379fdc | 170 | return JSValue(); |
9dae56ea A |
171 | } |
172 | ||
173 | bool JSCell::isGetterSetter() const | |
174 | { | |
175 | return false; | |
b37bf2e1 A |
176 | } |
177 | ||
f9bf01c6 A |
178 | JSValue JSCell::toPrimitive(ExecState*, PreferredPrimitiveType) const |
179 | { | |
180 | ASSERT_NOT_REACHED(); | |
181 | return JSValue(); | |
182 | } | |
183 | ||
184 | bool JSCell::getPrimitiveNumber(ExecState*, double&, JSValue&) | |
185 | { | |
186 | ASSERT_NOT_REACHED(); | |
187 | return false; | |
188 | } | |
189 | ||
190 | bool JSCell::toBoolean(ExecState*) const | |
191 | { | |
192 | ASSERT_NOT_REACHED(); | |
193 | return false; | |
194 | } | |
195 | ||
196 | double JSCell::toNumber(ExecState*) const | |
197 | { | |
198 | ASSERT_NOT_REACHED(); | |
199 | return 0; | |
200 | } | |
201 | ||
202 | UString JSCell::toString(ExecState*) const | |
203 | { | |
204 | ASSERT_NOT_REACHED(); | |
205 | return UString(); | |
206 | } | |
207 | ||
14957cd0 | 208 | JSObject* JSCell::toObject(ExecState*, JSGlobalObject*) const |
f9bf01c6 A |
209 | { |
210 | ASSERT_NOT_REACHED(); | |
211 | return 0; | |
212 | } | |
213 | ||
14957cd0 A |
214 | bool isZombie(const JSCell* cell) |
215 | { | |
216 | #if ENABLE(JSC_ZOMBIES) | |
217 | return cell && cell->isZombie(); | |
218 | #else | |
219 | UNUSED_PARAM(cell); | |
220 | return false; | |
221 | #endif | |
222 | } | |
223 | ||
224 | void slowValidateCell(JSCell* cell) | |
225 | { | |
226 | ASSERT_GC_OBJECT_LOOKS_VALID(cell); | |
227 | } | |
228 | ||
9dae56ea | 229 | } // namespace JSC |