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 "Operations.h"
31 #include <wtf/MathExtras.h>
35 ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSCell
);
37 void JSCell::destroy(JSCell
* cell
)
39 cell
->JSCell::~JSCell();
42 void JSCell::copyBackingStore(JSCell
*, CopyVisitor
&)
46 bool JSCell::getString(ExecState
* exec
, String
& stringValue
) const
50 stringValue
= static_cast<const JSString
*>(this)->value(exec
);
54 String
JSCell::getString(ExecState
* exec
) const
56 return isString() ? static_cast<const JSString
*>(this)->value(exec
) : String();
59 JSObject
* JSCell::getObject()
61 return isObject() ? asObject(this) : 0;
64 const JSObject
* JSCell::getObject() const
66 return isObject() ? static_cast<const JSObject
*>(this) : 0;
69 CallType
JSCell::getCallData(JSCell
*, CallData
& callData
)
71 callData
.js
.functionExecutable
= 0;
72 callData
.js
.scope
= 0;
73 callData
.native
.function
= 0;
77 ConstructType
JSCell::getConstructData(JSCell
*, ConstructData
& constructData
)
79 constructData
.js
.functionExecutable
= 0;
80 constructData
.js
.scope
= 0;
81 constructData
.native
.function
= 0;
82 return ConstructTypeNone
;
85 bool JSCell::getOwnPropertySlot(JSCell
* cell
, ExecState
* exec
, PropertyName identifier
, PropertySlot
& slot
)
87 // This is not a general purpose implementation of getOwnPropertySlot.
88 // It should only be called by JSValue::get.
89 // It calls getPropertySlot, not getOwnPropertySlot.
90 JSObject
* object
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
92 if (!object
->getPropertySlot(exec
, identifier
, slot
))
97 bool JSCell::getOwnPropertySlotByIndex(JSCell
* cell
, ExecState
* exec
, unsigned identifier
, PropertySlot
& slot
)
99 // This is not a general purpose implementation of getOwnPropertySlot.
100 // It should only be called by JSValue::get.
101 // It calls getPropertySlot, not getOwnPropertySlot.
102 JSObject
* object
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
103 slot
.setBase(object
);
104 if (!object
->getPropertySlot(exec
, identifier
, slot
))
109 void JSCell::put(JSCell
* cell
, ExecState
* exec
, PropertyName identifier
, JSValue value
, PutPropertySlot
& slot
)
111 if (cell
->isString()) {
112 JSValue(cell
).putToPrimitive(exec
, identifier
, value
, slot
);
115 JSObject
* thisObject
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
116 thisObject
->methodTable()->put(thisObject
, exec
, identifier
, value
, slot
);
119 void JSCell::putByIndex(JSCell
* cell
, ExecState
* exec
, unsigned identifier
, JSValue value
, bool shouldThrow
)
121 if (cell
->isString()) {
122 PutPropertySlot
slot(shouldThrow
);
123 JSValue(cell
).putToPrimitive(exec
, Identifier::from(exec
, identifier
), value
, slot
);
126 JSObject
* thisObject
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
127 thisObject
->methodTable()->putByIndex(thisObject
, exec
, identifier
, value
, shouldThrow
);
130 bool JSCell::deleteProperty(JSCell
* cell
, ExecState
* exec
, PropertyName identifier
)
132 JSObject
* thisObject
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
133 return thisObject
->methodTable()->deleteProperty(thisObject
, exec
, identifier
);
136 bool JSCell::deletePropertyByIndex(JSCell
* cell
, ExecState
* exec
, unsigned identifier
)
138 JSObject
* thisObject
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
139 return thisObject
->methodTable()->deletePropertyByIndex(thisObject
, exec
, identifier
);
142 JSObject
* JSCell::toThisObject(JSCell
* cell
, ExecState
* exec
)
144 return cell
->toObject(exec
, exec
->lexicalGlobalObject());
147 JSValue
JSCell::toPrimitive(ExecState
* exec
, PreferredPrimitiveType preferredType
) const
150 return static_cast<const JSString
*>(this)->toPrimitive(exec
, preferredType
);
151 return static_cast<const JSObject
*>(this)->toPrimitive(exec
, preferredType
);
154 bool JSCell::getPrimitiveNumber(ExecState
* exec
, double& number
, JSValue
& value
) const
157 return static_cast<const JSString
*>(this)->getPrimitiveNumber(exec
, number
, value
);
158 return static_cast<const JSObject
*>(this)->getPrimitiveNumber(exec
, number
, value
);
161 double JSCell::toNumber(ExecState
* exec
) const
164 return static_cast<const JSString
*>(this)->toNumber(exec
);
165 return static_cast<const JSObject
*>(this)->toNumber(exec
);
168 JSObject
* JSCell::toObject(ExecState
* exec
, JSGlobalObject
* globalObject
) const
171 return static_cast<const JSString
*>(this)->toObject(exec
, globalObject
);
173 return jsCast
<JSObject
*>(const_cast<JSCell
*>(this));
176 void slowValidateCell(JSCell
* cell
)
178 ASSERT_GC_OBJECT_LOOKS_VALID(cell
);
181 JSValue
JSCell::defaultValue(const JSObject
*, ExecState
*, PreferredPrimitiveType
)
183 RELEASE_ASSERT_NOT_REACHED();
184 return jsUndefined();
187 void JSCell::getOwnPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
189 RELEASE_ASSERT_NOT_REACHED();
192 void JSCell::getOwnNonIndexPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
194 RELEASE_ASSERT_NOT_REACHED();
197 String
JSCell::className(const JSObject
*)
199 RELEASE_ASSERT_NOT_REACHED();
203 const char* JSCell::className()
205 return classInfo()->className
;
208 void JSCell::getPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
210 RELEASE_ASSERT_NOT_REACHED();
213 bool JSCell::customHasInstance(JSObject
*, ExecState
*, JSValue
)
215 RELEASE_ASSERT_NOT_REACHED();
219 void JSCell::putDirectVirtual(JSObject
*, ExecState
*, PropertyName
, JSValue
, unsigned)
221 RELEASE_ASSERT_NOT_REACHED();
224 bool JSCell::defineOwnProperty(JSObject
*, ExecState
*, PropertyName
, PropertyDescriptor
&, bool)
226 RELEASE_ASSERT_NOT_REACHED();
230 bool JSCell::getOwnPropertyDescriptor(JSObject
*, ExecState
*, PropertyName
, PropertyDescriptor
&)
232 RELEASE_ASSERT_NOT_REACHED();