1 | /*
|
---|
2 | * Copyright (C) 1999-2001 Harri Porten ([email protected])
|
---|
3 | * Copyright (C) 2001 Peter Kelly ([email protected])
|
---|
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"
|
---|
24 | #include "JSCell.h"
|
---|
25 |
|
---|
26 | #include "JSFunction.h"
|
---|
27 | #include "JSString.h"
|
---|
28 | #include "JSObject.h"
|
---|
29 | #include <wtf/MathExtras.h>
|
---|
30 |
|
---|
31 | namespace JSC {
|
---|
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 = { {
|
---|
62 | #if PLATFORM(BIG_ENDIAN)
|
---|
63 | { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 },
|
---|
64 | { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 }
|
---|
65 | #elif PLATFORM(MIDDLE_ENDIAN)
|
---|
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 |
|
---|
79 | void* JSCell::operator new(size_t size, ExecState* exec)
|
---|
80 | {
|
---|
81 | #ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
|
---|
82 | return exec->heap()->inlineAllocate(size);
|
---|
83 | #else
|
---|
84 | return exec->heap()->allocate(size);
|
---|
85 | #endif
|
---|
86 | }
|
---|
87 |
|
---|
88 | bool JSCell::getUInt32(uint32_t&) const
|
---|
89 | {
|
---|
90 | return false;
|
---|
91 | }
|
---|
92 |
|
---|
93 | bool JSCell::getTruncatedInt32(int32_t&) const
|
---|
94 | {
|
---|
95 | return false;
|
---|
96 | }
|
---|
97 |
|
---|
98 | bool JSCell::getTruncatedUInt32(uint32_t&) const
|
---|
99 | {
|
---|
100 | return false;
|
---|
101 | }
|
---|
102 |
|
---|
103 | bool JSCell::getNumber(double& numericValue) const
|
---|
104 | {
|
---|
105 | if (!isNumber())
|
---|
106 | return false;
|
---|
107 | numericValue = static_cast<const JSNumberCell*>(this)->value();
|
---|
108 | return true;
|
---|
109 | }
|
---|
110 |
|
---|
111 | double JSCell::getNumber() const
|
---|
112 | {
|
---|
113 | return isNumber() ? static_cast<const JSNumberCell*>(this)->value() : NaN;
|
---|
114 | }
|
---|
115 |
|
---|
116 | bool JSCell::getString(UString&stringValue) const
|
---|
117 | {
|
---|
118 | if (!isString())
|
---|
119 | return false;
|
---|
120 | stringValue = static_cast<const JSString*>(this)->value();
|
---|
121 | return true;
|
---|
122 | }
|
---|
123 |
|
---|
124 | UString JSCell::getString() const
|
---|
125 | {
|
---|
126 | return isString() ? static_cast<const JSString*>(this)->value() : UString();
|
---|
127 | }
|
---|
128 |
|
---|
129 | JSObject* JSCell::getObject()
|
---|
130 | {
|
---|
131 | return isObject() ? static_cast<JSObject*>(this) : 0;
|
---|
132 | }
|
---|
133 |
|
---|
134 | const JSObject* JSCell::getObject() const
|
---|
135 | {
|
---|
136 | return isObject() ? static_cast<const JSObject*>(this) : 0;
|
---|
137 | }
|
---|
138 |
|
---|
139 | CallType JSCell::getCallData(CallData&)
|
---|
140 | {
|
---|
141 | return CallTypeNone;
|
---|
142 | }
|
---|
143 |
|
---|
144 | ConstructType JSCell::getConstructData(ConstructData&)
|
---|
145 | {
|
---|
146 | return ConstructTypeNone;
|
---|
147 | }
|
---|
148 |
|
---|
149 | bool JSCell::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, PropertySlot& slot)
|
---|
150 | {
|
---|
151 | // This is not a general purpose implementation of getOwnPropertySlot.
|
---|
152 | // It should only be called by JSValue::get.
|
---|
153 | // It calls getPropertySlot, not getOwnPropertySlot.
|
---|
154 | JSObject* object = toObject(exec);
|
---|
155 | slot.setBase(object);
|
---|
156 | if (!object->getPropertySlot(exec, identifier, slot))
|
---|
157 | slot.setUndefined();
|
---|
158 | return true;
|
---|
159 | }
|
---|
160 |
|
---|
161 | bool JSCell::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySlot& slot)
|
---|
162 | {
|
---|
163 | // This is not a general purpose implementation of getOwnPropertySlot.
|
---|
164 | // It should only be called by JSValue::get.
|
---|
165 | // It calls getPropertySlot, not getOwnPropertySlot.
|
---|
166 | JSObject* object = toObject(exec);
|
---|
167 | slot.setBase(object);
|
---|
168 | if (!object->getPropertySlot(exec, identifier, slot))
|
---|
169 | slot.setUndefined();
|
---|
170 | return true;
|
---|
171 | }
|
---|
172 |
|
---|
173 | void JSCell::put(ExecState* exec, const Identifier& identifier, JSValue* value, PutPropertySlot& slot)
|
---|
174 | {
|
---|
175 | toObject(exec)->put(exec, identifier, value, slot);
|
---|
176 | }
|
---|
177 |
|
---|
178 | void JSCell::put(ExecState* exec, unsigned identifier, JSValue* value)
|
---|
179 | {
|
---|
180 | toObject(exec)->put(exec, identifier, value);
|
---|
181 | }
|
---|
182 |
|
---|
183 | bool JSCell::deleteProperty(ExecState* exec, const Identifier& identifier)
|
---|
184 | {
|
---|
185 | return toObject(exec)->deleteProperty(exec, identifier);
|
---|
186 | }
|
---|
187 |
|
---|
188 | bool JSCell::deleteProperty(ExecState* exec, unsigned identifier)
|
---|
189 | {
|
---|
190 | return toObject(exec)->deleteProperty(exec, identifier);
|
---|
191 | }
|
---|
192 |
|
---|
193 | JSObject* JSCell::toThisObject(ExecState* exec) const
|
---|
194 | {
|
---|
195 | return toObject(exec);
|
---|
196 | }
|
---|
197 |
|
---|
198 | UString JSCell::toThisString(ExecState* exec) const
|
---|
199 | {
|
---|
200 | return toThisObject(exec)->toString(exec);
|
---|
201 | }
|
---|
202 |
|
---|
203 | JSString* JSCell::toThisJSString(ExecState* exec)
|
---|
204 | {
|
---|
205 | return jsString(exec, toThisString(exec));
|
---|
206 | }
|
---|
207 |
|
---|
208 | const ClassInfo* JSCell::classInfo() const
|
---|
209 | {
|
---|
210 | return 0;
|
---|
211 | }
|
---|
212 |
|
---|
213 | JSValue* JSCell::getJSNumber()
|
---|
214 | {
|
---|
215 | return noValue();
|
---|
216 | }
|
---|
217 |
|
---|
218 | bool JSCell::isGetterSetter() const
|
---|
219 | {
|
---|
220 | return false;
|
---|
221 | }
|
---|
222 |
|
---|
223 | } // namespace JSC
|
---|