]>
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 | ||
b37bf2e1 A |
79 | bool JSCell::getUInt32(uint32_t&) const |
80 | { | |
81 | return false; | |
82 | } | |
83 | ||
f9bf01c6 | 84 | bool JSCell::getString(ExecState* exec, UString&stringValue) const |
b37bf2e1 | 85 | { |
9dae56ea A |
86 | if (!isString()) |
87 | return false; | |
f9bf01c6 | 88 | stringValue = static_cast<const JSString*>(this)->value(exec); |
9dae56ea | 89 | return true; |
b37bf2e1 A |
90 | } |
91 | ||
f9bf01c6 | 92 | UString JSCell::getString(ExecState* exec) const |
b37bf2e1 | 93 | { |
f9bf01c6 | 94 | return isString() ? static_cast<const JSString*>(this)->value(exec) : UString(); |
b37bf2e1 A |
95 | } |
96 | ||
9dae56ea | 97 | JSObject* JSCell::getObject() |
b37bf2e1 | 98 | { |
f9bf01c6 | 99 | return isObject() ? asObject(this) : 0; |
b37bf2e1 A |
100 | } |
101 | ||
9dae56ea | 102 | const JSObject* JSCell::getObject() const |
b37bf2e1 | 103 | { |
9dae56ea | 104 | return isObject() ? static_cast<const JSObject*>(this) : 0; |
b37bf2e1 A |
105 | } |
106 | ||
9dae56ea | 107 | CallType JSCell::getCallData(CallData&) |
b37bf2e1 | 108 | { |
9dae56ea | 109 | return CallTypeNone; |
b37bf2e1 A |
110 | } |
111 | ||
9dae56ea | 112 | ConstructType JSCell::getConstructData(ConstructData&) |
b37bf2e1 | 113 | { |
9dae56ea | 114 | return ConstructTypeNone; |
b37bf2e1 A |
115 | } |
116 | ||
9dae56ea | 117 | bool JSCell::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, PropertySlot& slot) |
b37bf2e1 | 118 | { |
9dae56ea A |
119 | // This is not a general purpose implementation of getOwnPropertySlot. |
120 | // It should only be called by JSValue::get. | |
121 | // It calls getPropertySlot, not getOwnPropertySlot. | |
122 | JSObject* object = toObject(exec); | |
123 | slot.setBase(object); | |
124 | if (!object->getPropertySlot(exec, identifier, slot)) | |
125 | slot.setUndefined(); | |
126 | return true; | |
b37bf2e1 A |
127 | } |
128 | ||
9dae56ea | 129 | bool JSCell::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySlot& slot) |
b37bf2e1 | 130 | { |
9dae56ea A |
131 | // This is not a general purpose implementation of getOwnPropertySlot. |
132 | // It should only be called by JSValue::get. | |
133 | // It calls getPropertySlot, not getOwnPropertySlot. | |
134 | JSObject* object = toObject(exec); | |
135 | slot.setBase(object); | |
136 | if (!object->getPropertySlot(exec, identifier, slot)) | |
137 | slot.setUndefined(); | |
b37bf2e1 A |
138 | return true; |
139 | } | |
140 | ||
ba379fdc | 141 | void JSCell::put(ExecState* exec, const Identifier& identifier, JSValue value, PutPropertySlot& slot) |
b37bf2e1 | 142 | { |
9dae56ea | 143 | toObject(exec)->put(exec, identifier, value, slot); |
b37bf2e1 A |
144 | } |
145 | ||
ba379fdc | 146 | void JSCell::put(ExecState* exec, unsigned identifier, JSValue value) |
b37bf2e1 | 147 | { |
9dae56ea | 148 | toObject(exec)->put(exec, identifier, value); |
b37bf2e1 A |
149 | } |
150 | ||
9dae56ea | 151 | bool JSCell::deleteProperty(ExecState* exec, const Identifier& identifier) |
b37bf2e1 | 152 | { |
9dae56ea | 153 | return toObject(exec)->deleteProperty(exec, identifier); |
b37bf2e1 A |
154 | } |
155 | ||
9dae56ea | 156 | bool JSCell::deleteProperty(ExecState* exec, unsigned identifier) |
b37bf2e1 | 157 | { |
9dae56ea | 158 | return toObject(exec)->deleteProperty(exec, identifier); |
b37bf2e1 A |
159 | } |
160 | ||
9dae56ea | 161 | JSObject* JSCell::toThisObject(ExecState* exec) const |
b37bf2e1 | 162 | { |
9dae56ea | 163 | return toObject(exec); |
b37bf2e1 A |
164 | } |
165 | ||
9dae56ea | 166 | const ClassInfo* JSCell::classInfo() const |
b37bf2e1 | 167 | { |
9dae56ea | 168 | return 0; |
b37bf2e1 A |
169 | } |
170 | ||
ba379fdc | 171 | JSValue JSCell::getJSNumber() |
b37bf2e1 | 172 | { |
ba379fdc | 173 | return JSValue(); |
9dae56ea A |
174 | } |
175 | ||
176 | bool JSCell::isGetterSetter() const | |
177 | { | |
178 | return false; | |
b37bf2e1 A |
179 | } |
180 | ||
f9bf01c6 A |
181 | JSValue JSCell::toPrimitive(ExecState*, PreferredPrimitiveType) const |
182 | { | |
183 | ASSERT_NOT_REACHED(); | |
184 | return JSValue(); | |
185 | } | |
186 | ||
187 | bool JSCell::getPrimitiveNumber(ExecState*, double&, JSValue&) | |
188 | { | |
189 | ASSERT_NOT_REACHED(); | |
190 | return false; | |
191 | } | |
192 | ||
193 | bool JSCell::toBoolean(ExecState*) const | |
194 | { | |
195 | ASSERT_NOT_REACHED(); | |
196 | return false; | |
197 | } | |
198 | ||
199 | double JSCell::toNumber(ExecState*) const | |
200 | { | |
201 | ASSERT_NOT_REACHED(); | |
202 | return 0; | |
203 | } | |
204 | ||
205 | UString JSCell::toString(ExecState*) const | |
206 | { | |
207 | ASSERT_NOT_REACHED(); | |
208 | return UString(); | |
209 | } | |
210 | ||
211 | JSObject* JSCell::toObject(ExecState*) const | |
212 | { | |
213 | ASSERT_NOT_REACHED(); | |
214 | return 0; | |
215 | } | |
216 | ||
9dae56ea | 217 | } // namespace JSC |