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 "ArrayBufferView.h"
27 #include "JSFunction.h"
30 #include "NumberObject.h"
31 #include "JSCInlines.h"
32 #include <wtf/MathExtras.h>
36 COMPILE_ASSERT(sizeof(JSCell
) == sizeof(uint64_t), jscell_is_eight_bytes
);
37 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSCell
);
39 void JSCell::destroy(JSCell
* cell
)
41 cell
->JSCell::~JSCell();
44 void JSCell::dump(PrintStream
& out
) const
46 methodTable()->dumpToStream(this, out
);
49 void JSCell::dumpToStream(const JSCell
* cell
, PrintStream
& out
)
51 out
.printf("<%p, %s>", cell
, cell
->className());
54 void JSCell::copyBackingStore(JSCell
*, CopyVisitor
&, CopyToken
)
58 bool JSCell::getString(ExecState
* exec
, String
& stringValue
) const
62 stringValue
= static_cast<const JSString
*>(this)->value(exec
);
66 String
JSCell::getString(ExecState
* exec
) const
68 return isString() ? static_cast<const JSString
*>(this)->value(exec
) : String();
71 JSObject
* JSCell::getObject()
73 return isObject() ? asObject(this) : 0;
76 const JSObject
* JSCell::getObject() const
78 return isObject() ? static_cast<const JSObject
*>(this) : 0;
81 CallType
JSCell::getCallData(JSCell
*, CallData
& callData
)
83 callData
.js
.functionExecutable
= 0;
84 callData
.js
.scope
= 0;
85 callData
.native
.function
= 0;
89 ConstructType
JSCell::getConstructData(JSCell
*, ConstructData
& constructData
)
91 constructData
.js
.functionExecutable
= 0;
92 constructData
.js
.scope
= 0;
93 constructData
.native
.function
= 0;
94 return ConstructTypeNone
;
97 void JSCell::put(JSCell
* cell
, ExecState
* exec
, PropertyName identifier
, JSValue value
, PutPropertySlot
& slot
)
99 if (cell
->isString() || cell
->isSymbol()) {
100 JSValue(cell
).putToPrimitive(exec
, identifier
, value
, slot
);
103 JSObject
* thisObject
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
104 thisObject
->methodTable(exec
->vm())->put(thisObject
, exec
, identifier
, value
, slot
);
107 void JSCell::putByIndex(JSCell
* cell
, ExecState
* exec
, unsigned identifier
, JSValue value
, bool shouldThrow
)
109 if (cell
->isString() || cell
->isSymbol()) {
110 PutPropertySlot
slot(cell
, shouldThrow
);
111 JSValue(cell
).putToPrimitive(exec
, Identifier::from(exec
, identifier
), value
, slot
);
114 JSObject
* thisObject
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
115 thisObject
->methodTable(exec
->vm())->putByIndex(thisObject
, exec
, identifier
, value
, shouldThrow
);
118 bool JSCell::deleteProperty(JSCell
* cell
, ExecState
* exec
, PropertyName identifier
)
120 JSObject
* thisObject
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
121 return thisObject
->methodTable(exec
->vm())->deleteProperty(thisObject
, exec
, identifier
);
124 bool JSCell::deletePropertyByIndex(JSCell
* cell
, ExecState
* exec
, unsigned identifier
)
126 JSObject
* thisObject
= cell
->toObject(exec
, exec
->lexicalGlobalObject());
127 return thisObject
->methodTable(exec
->vm())->deletePropertyByIndex(thisObject
, exec
, identifier
);
130 JSValue
JSCell::toThis(JSCell
* cell
, ExecState
* exec
, ECMAMode ecmaMode
)
132 if (ecmaMode
== StrictMode
)
134 return cell
->toObject(exec
, exec
->lexicalGlobalObject());
137 JSValue
JSCell::toPrimitive(ExecState
* exec
, PreferredPrimitiveType preferredType
) const
140 return static_cast<const JSString
*>(this)->toPrimitive(exec
, preferredType
);
142 return static_cast<const Symbol
*>(this)->toPrimitive(exec
, preferredType
);
143 return static_cast<const JSObject
*>(this)->toPrimitive(exec
, preferredType
);
146 bool JSCell::getPrimitiveNumber(ExecState
* exec
, double& number
, JSValue
& value
) const
149 return static_cast<const JSString
*>(this)->getPrimitiveNumber(exec
, number
, value
);
151 return static_cast<const Symbol
*>(this)->getPrimitiveNumber(exec
, number
, value
);
152 return static_cast<const JSObject
*>(this)->getPrimitiveNumber(exec
, number
, value
);
155 double JSCell::toNumber(ExecState
* exec
) const
158 return static_cast<const JSString
*>(this)->toNumber(exec
);
160 return static_cast<const Symbol
*>(this)->toNumber(exec
);
161 return static_cast<const JSObject
*>(this)->toNumber(exec
);
164 JSObject
* JSCell::toObject(ExecState
* exec
, JSGlobalObject
* globalObject
) const
167 return static_cast<const JSString
*>(this)->toObject(exec
, globalObject
);
169 return static_cast<const Symbol
*>(this)->toObject(exec
, globalObject
);
171 return jsCast
<JSObject
*>(const_cast<JSCell
*>(this));
174 void slowValidateCell(JSCell
* cell
)
176 ASSERT_GC_OBJECT_LOOKS_VALID(cell
);
179 JSValue
JSCell::defaultValue(const JSObject
*, ExecState
*, PreferredPrimitiveType
)
181 RELEASE_ASSERT_NOT_REACHED();
182 return jsUndefined();
185 bool JSCell::getOwnPropertySlot(JSObject
*, ExecState
*, PropertyName
, PropertySlot
&)
187 RELEASE_ASSERT_NOT_REACHED();
191 bool JSCell::getOwnPropertySlotByIndex(JSObject
*, ExecState
*, unsigned, PropertySlot
&)
193 RELEASE_ASSERT_NOT_REACHED();
197 void JSCell::getOwnPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
199 RELEASE_ASSERT_NOT_REACHED();
202 void JSCell::getOwnNonIndexPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
204 RELEASE_ASSERT_NOT_REACHED();
207 String
JSCell::className(const JSObject
*)
209 RELEASE_ASSERT_NOT_REACHED();
213 const char* JSCell::className() const
215 return classInfo()->className
;
218 void JSCell::getPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
220 RELEASE_ASSERT_NOT_REACHED();
223 bool JSCell::customHasInstance(JSObject
*, ExecState
*, JSValue
)
225 RELEASE_ASSERT_NOT_REACHED();
229 bool JSCell::defineOwnProperty(JSObject
*, ExecState
*, PropertyName
, const PropertyDescriptor
&, bool)
231 RELEASE_ASSERT_NOT_REACHED();
235 ArrayBuffer
* JSCell::slowDownAndWasteMemory(JSArrayBufferView
*)
237 RELEASE_ASSERT_NOT_REACHED();
241 PassRefPtr
<ArrayBufferView
> JSCell::getTypedArrayImpl(JSArrayBufferView
*)
243 RELEASE_ASSERT_NOT_REACHED();
247 uint32_t JSCell::getEnumerableLength(ExecState
*, JSObject
*)
249 RELEASE_ASSERT_NOT_REACHED();
253 void JSCell::getStructurePropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
255 RELEASE_ASSERT_NOT_REACHED();
258 void JSCell::getGenericPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
260 RELEASE_ASSERT_NOT_REACHED();