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 bool JSCell::getString(ExecState* exec, UString&stringValue) const
38 stringValue = static_cast<const JSString*>(this)->value(exec);
42 UString JSCell::getString(ExecState* exec) const
44 return isString() ? static_cast<const JSString*>(this)->value(exec) : UString();
47 JSObject* JSCell::getObject()
49 return isObject() ? asObject(this) : 0;
52 const JSObject* JSCell::getObject() const
54 return isObject() ? static_cast<const JSObject*>(this) : 0;
57 CallType JSCell::getCallData(JSCell*, CallData&)
62 ConstructType JSCell::getConstructData(JSCell*, ConstructData&)
64 return ConstructTypeNone;
67 bool JSCell::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& identifier, PropertySlot& slot)
69 // This is not a general purpose implementation of getOwnPropertySlot.
70 // It should only be called by JSValue::get.
71 // It calls getPropertySlot, not getOwnPropertySlot.
72 JSObject* object = cell->toObject(exec, exec->lexicalGlobalObject());
74 if (!object->getPropertySlot(exec, identifier, slot))
79 bool JSCell::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned identifier, PropertySlot& slot)
81 // This is not a general purpose implementation of getOwnPropertySlot.
82 // It should only be called by JSValue::get.
83 // It calls getPropertySlot, not getOwnPropertySlot.
84 JSObject* object = cell->toObject(exec, exec->lexicalGlobalObject());
86 if (!object->getPropertySlot(exec, identifier, slot))
91 void JSCell::put(JSCell* cell, ExecState* exec, const Identifier& identifier, JSValue value, PutPropertySlot& slot)
93 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
94 thisObject->methodTable()->put(thisObject, exec, identifier, value, slot);
97 void JSCell::putByIndex(JSCell* cell, ExecState* exec, unsigned identifier, JSValue value)
99 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
100 thisObject->methodTable()->putByIndex(thisObject, exec, identifier, value);
103 bool JSCell::deleteProperty(JSCell* cell, ExecState* exec, const Identifier& identifier)
105 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
106 return thisObject->methodTable()->deleteProperty(thisObject, exec, identifier);
109 bool JSCell::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned identifier)
111 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
112 return thisObject->methodTable()->deletePropertyByIndex(thisObject, exec, identifier);
115 JSObject* JSCell::toThisObject(JSCell* cell, ExecState* exec)
117 return cell->toObject(exec, exec->lexicalGlobalObject());
120 JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
123 return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType);
124 return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType);
127 bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const
130 return static_cast<const JSString*>(this)->getPrimitiveNumber(exec, number, value);
131 return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value);
134 double JSCell::toNumber(ExecState* exec) const
137 return static_cast<const JSString*>(this)->toNumber(exec);
138 return static_cast<const JSObject*>(this)->toNumber(exec);
141 UString JSCell::toString(ExecState* exec) const
144 return static_cast<const JSString*>(this)->toString(exec);
145 return static_cast<const JSObject*>(this)->toString(exec);
148 JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const
151 return static_cast<const JSString*>(this)->toObject(exec, globalObject);
153 return static_cast<JSObject*>(const_cast<JSCell*>(this));
156 void slowValidateCell(JSCell* cell)
158 ASSERT_GC_OBJECT_LOOKS_VALID(cell);
161 void JSCell::defineGetter(JSObject*, ExecState*, const Identifier&, JSObject*, unsigned)
163 ASSERT_NOT_REACHED();
166 void JSCell::defineSetter(JSObject*, ExecState*, const Identifier&, JSObject*, unsigned)
168 ASSERT_NOT_REACHED();
171 JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType)
173 ASSERT_NOT_REACHED();
174 return jsUndefined();
177 void JSCell::getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
179 ASSERT_NOT_REACHED();
182 UString JSCell::className(const JSObject*)
184 ASSERT_NOT_REACHED();
188 void JSCell::getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
190 ASSERT_NOT_REACHED();
193 bool JSCell::hasInstance(JSObject*, ExecState*, JSValue, JSValue)
195 ASSERT_NOT_REACHED();
199 void JSCell::putWithAttributes(JSObject*, ExecState*, const Identifier&, JSValue, unsigned)
201 ASSERT_NOT_REACHED();
204 bool JSCell::defineOwnProperty(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&, bool)
206 ASSERT_NOT_REACHED();
210 bool JSCell::getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&)
212 ASSERT_NOT_REACHED();