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.
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.
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.
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.
26 #include "JSFunction.h"
29 #include "NumberObject.h"
30 #include <wtf/MathExtras.h>
34 ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSCell
);
36 void JSCell::destroy(JSCell
* cell
)
38 cell
->JSCell::~JSCell();
41 bool JSCell::getString(ExecState
* exec
, UString
&stringValue
) const
45 stringValue
= static_cast<const JSString
*>(this)->value(exec
);
49 UString
JSCell::getString(ExecState
* exec
) const
51 return isString() ? static_cast<const JSString
*>(this)->value(exec
) : UString();
54 JSObject
* JSCell::getObject()
56 return isObject() ? asObject(this) : 0;
59 const JSObject
* JSCell::getObject() const
61 return isObject() ? static_cast<const JSObject
*>(this) : 0;
64 CallType
JSCell::getCallData(JSCell
*, CallData
&)
69 ConstructType
JSCell::getConstructData(JSCell
*, ConstructData
&)
71 return ConstructTypeNone
;
74 bool JSCell::getOwnPropertySlot(JSCell
* cell
, ExecState
* exec
, const Identifier
& identifier
, PropertySlot
& slot
)
76 // This is not a general purpose implementation of getOwnPropertySlot.
77 // It should only be called by JSValue::get.
78 // It calls getPropertySlot, not getOwnPropertySlot.
79 JSObject
* object
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
81 if (!object
->getPropertySlot(exec
, identifier
, slot
))
86 bool JSCell::getOwnPropertySlotByIndex(JSCell
* cell
, ExecState
* exec
, unsigned identifier
, PropertySlot
& slot
)
88 // This is not a general purpose implementation of getOwnPropertySlot.
89 // It should only be called by JSValue::get.
90 // It calls getPropertySlot, not getOwnPropertySlot.
91 JSObject
* object
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
93 if (!object
->getPropertySlot(exec
, identifier
, slot
))
98 void JSCell::put(JSCell
* cell
, ExecState
* exec
, const Identifier
& identifier
, JSValue value
, PutPropertySlot
& slot
)
100 if (cell
->isString()) {
101 JSValue(cell
).putToPrimitive(exec
, identifier
, value
, slot
);
104 JSObject
* thisObject
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
105 thisObject
->methodTable()->put(thisObject
, exec
, identifier
, value
, slot
);
108 void JSCell::putByIndex(JSCell
* cell
, ExecState
* exec
, unsigned identifier
, JSValue value
, bool shouldThrow
)
110 if (cell
->isString()) {
111 PutPropertySlot
slot(shouldThrow
);
112 JSValue(cell
).putToPrimitive(exec
, Identifier::from(exec
, identifier
), value
, slot
);
115 JSObject
* thisObject
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
116 thisObject
->methodTable()->putByIndex(thisObject
, exec
, identifier
, value
, shouldThrow
);
119 bool JSCell::deleteProperty(JSCell
* cell
, ExecState
* exec
, const Identifier
& identifier
)
121 JSObject
* thisObject
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
122 return thisObject
->methodTable()->deleteProperty(thisObject
, exec
, identifier
);
125 bool JSCell::deletePropertyByIndex(JSCell
* cell
, ExecState
* exec
, unsigned identifier
)
127 JSObject
* thisObject
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
128 return thisObject
->methodTable()->deletePropertyByIndex(thisObject
, exec
, identifier
);
131 JSObject
* JSCell::toThisObject(JSCell
* cell
, ExecState
* exec
)
133 return cell
->toObject(exec
, exec
->lexicalGlobalObject());
136 JSValue
JSCell::toPrimitive(ExecState
* exec
, PreferredPrimitiveType preferredType
) const
139 return static_cast<const JSString
*>(this)->toPrimitive(exec
, preferredType
);
140 return static_cast<const JSObject
*>(this)->toPrimitive(exec
, preferredType
);
143 bool JSCell::getPrimitiveNumber(ExecState
* exec
, double& number
, JSValue
& value
) const
146 return static_cast<const JSString
*>(this)->getPrimitiveNumber(exec
, number
, value
);
147 return static_cast<const JSObject
*>(this)->getPrimitiveNumber(exec
, number
, value
);
150 double JSCell::toNumber(ExecState
* exec
) const
153 return static_cast<const JSString
*>(this)->toNumber(exec
);
154 return static_cast<const JSObject
*>(this)->toNumber(exec
);
157 JSObject
* JSCell::toObject(ExecState
* exec
, JSGlobalObject
* globalObject
) const
160 return static_cast<const JSString
*>(this)->toObject(exec
, globalObject
);
162 return jsCast
<JSObject
*>(const_cast<JSCell
*>(this));
165 void slowValidateCell(JSCell
* cell
)
167 ASSERT_GC_OBJECT_LOOKS_VALID(cell
);
170 JSValue
JSCell::defaultValue(const JSObject
*, ExecState
*, PreferredPrimitiveType
)
172 ASSERT_NOT_REACHED();
173 return jsUndefined();
176 void JSCell::getOwnPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
178 ASSERT_NOT_REACHED();
181 UString
JSCell::className(const JSObject
*)
183 ASSERT_NOT_REACHED();
187 void JSCell::getPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
189 ASSERT_NOT_REACHED();
192 bool JSCell::hasInstance(JSObject
*, ExecState
*, JSValue
, JSValue
)
194 ASSERT_NOT_REACHED();
198 void JSCell::putDirectVirtual(JSObject
*, ExecState
*, const Identifier
&, JSValue
, unsigned)
200 ASSERT_NOT_REACHED();
203 bool JSCell::defineOwnProperty(JSObject
*, ExecState
*, const Identifier
&, PropertyDescriptor
&, bool)
205 ASSERT_NOT_REACHED();
209 bool JSCell::getOwnPropertyDescriptor(JSObject
*, ExecState
*, const Identifier
&, PropertyDescriptor
&)
211 ASSERT_NOT_REACHED();