]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/JSCell.cpp
JavaScriptCore-521.tar.gz
[apple/javascriptcore.git] / runtime / JSCell.cpp
CommitLineData
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 31namespace JSC {
b37bf2e1
A
32
33#if defined NAN && defined INFINITY
34
35extern const double NaN = NAN;
36extern 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
50static 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
74extern const double NaN = NaNInf.doubles.NaN_Double;
75extern const double Inf = NaNInf.doubles.Inf_Double;
76
77#endif // !(defined NAN && defined INFINITY)
78
9dae56ea 79void* JSCell::operator new(size_t size, ExecState* exec)
b37bf2e1 80{
9dae56ea
A
81#ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE
82 return exec->heap()->inlineAllocate(size);
83#else
84 return exec->heap()->allocate(size);
85#endif
b37bf2e1
A
86}
87
88bool JSCell::getUInt32(uint32_t&) const
89{
90 return false;
91}
92
93bool JSCell::getTruncatedInt32(int32_t&) const
94{
95 return false;
96}
97
98bool JSCell::getTruncatedUInt32(uint32_t&) const
99{
100 return false;
101}
102
9dae56ea 103bool JSCell::getString(UString&stringValue) const
b37bf2e1 104{
9dae56ea
A
105 if (!isString())
106 return false;
107 stringValue = static_cast<const JSString*>(this)->value();
108 return true;
b37bf2e1
A
109}
110
9dae56ea 111UString JSCell::getString() const
b37bf2e1 112{
9dae56ea 113 return isString() ? static_cast<const JSString*>(this)->value() : UString();
b37bf2e1
A
114}
115
9dae56ea 116JSObject* JSCell::getObject()
b37bf2e1 117{
9dae56ea 118 return isObject() ? static_cast<JSObject*>(this) : 0;
b37bf2e1
A
119}
120
9dae56ea 121const JSObject* JSCell::getObject() const
b37bf2e1 122{
9dae56ea 123 return isObject() ? static_cast<const JSObject*>(this) : 0;
b37bf2e1
A
124}
125
9dae56ea 126CallType JSCell::getCallData(CallData&)
b37bf2e1 127{
9dae56ea 128 return CallTypeNone;
b37bf2e1
A
129}
130
9dae56ea 131ConstructType JSCell::getConstructData(ConstructData&)
b37bf2e1 132{
9dae56ea 133 return ConstructTypeNone;
b37bf2e1
A
134}
135
9dae56ea 136bool JSCell::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, PropertySlot& slot)
b37bf2e1 137{
9dae56ea
A
138 // This is not a general purpose implementation of getOwnPropertySlot.
139 // It should only be called by JSValue::get.
140 // It calls getPropertySlot, not getOwnPropertySlot.
141 JSObject* object = toObject(exec);
142 slot.setBase(object);
143 if (!object->getPropertySlot(exec, identifier, slot))
144 slot.setUndefined();
145 return true;
b37bf2e1
A
146}
147
9dae56ea 148bool JSCell::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySlot& slot)
b37bf2e1 149{
9dae56ea
A
150 // This is not a general purpose implementation of getOwnPropertySlot.
151 // It should only be called by JSValue::get.
152 // It calls getPropertySlot, not getOwnPropertySlot.
153 JSObject* object = toObject(exec);
154 slot.setBase(object);
155 if (!object->getPropertySlot(exec, identifier, slot))
156 slot.setUndefined();
b37bf2e1
A
157 return true;
158}
159
9dae56ea 160void JSCell::put(ExecState* exec, const Identifier& identifier, JSValuePtr value, PutPropertySlot& slot)
b37bf2e1 161{
9dae56ea 162 toObject(exec)->put(exec, identifier, value, slot);
b37bf2e1
A
163}
164
9dae56ea 165void JSCell::put(ExecState* exec, unsigned identifier, JSValuePtr value)
b37bf2e1 166{
9dae56ea 167 toObject(exec)->put(exec, identifier, value);
b37bf2e1
A
168}
169
9dae56ea 170bool JSCell::deleteProperty(ExecState* exec, const Identifier& identifier)
b37bf2e1 171{
9dae56ea 172 return toObject(exec)->deleteProperty(exec, identifier);
b37bf2e1
A
173}
174
9dae56ea 175bool JSCell::deleteProperty(ExecState* exec, unsigned identifier)
b37bf2e1 176{
9dae56ea 177 return toObject(exec)->deleteProperty(exec, identifier);
b37bf2e1
A
178}
179
9dae56ea 180JSObject* JSCell::toThisObject(ExecState* exec) const
b37bf2e1 181{
9dae56ea 182 return toObject(exec);
b37bf2e1
A
183}
184
9dae56ea 185UString JSCell::toThisString(ExecState* exec) const
b37bf2e1 186{
9dae56ea 187 return toThisObject(exec)->toString(exec);
b37bf2e1
A
188}
189
9dae56ea 190JSString* JSCell::toThisJSString(ExecState* exec)
b37bf2e1 191{
9dae56ea 192 return jsString(exec, toThisString(exec));
b37bf2e1
A
193}
194
9dae56ea 195const ClassInfo* JSCell::classInfo() const
b37bf2e1 196{
9dae56ea 197 return 0;
b37bf2e1
A
198}
199
9dae56ea 200JSValuePtr JSCell::getJSNumber()
b37bf2e1 201{
9dae56ea
A
202 return noValue();
203}
204
205bool JSCell::isGetterSetter() const
206{
207 return false;
b37bf2e1
A
208}
209
9dae56ea 210} // namespace JSC