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()) {
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()) {
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
);
141 return static_cast<const JSObject
*>(this)->toPrimitive(exec
, preferredType
);
144 bool JSCell::getPrimitiveNumber(ExecState
* exec
, double& number
, JSValue
& value
) const
147 return static_cast<const JSString
*>(this)->getPrimitiveNumber(exec
, number
, value
);
148 return static_cast<const JSObject
*>(this)->getPrimitiveNumber(exec
, number
, value
);
151 double JSCell::toNumber(ExecState
* exec
) const
154 return static_cast<const JSString
*>(this)->toNumber(exec
);
155 return static_cast<const JSObject
*>(this)->toNumber(exec
);
158 JSObject
* JSCell::toObject(ExecState
* exec
, JSGlobalObject
* globalObject
) const
161 return static_cast<const JSString
*>(this)->toObject(exec
, globalObject
);
163 return jsCast
<JSObject
*>(const_cast<JSCell
*>(this));
166 void slowValidateCell(JSCell
* cell
)
168 ASSERT_GC_OBJECT_LOOKS_VALID(cell
);
171 JSValue
JSCell::defaultValue(const JSObject
*, ExecState
*, PreferredPrimitiveType
)
173 RELEASE_ASSERT_NOT_REACHED();
174 return jsUndefined();
177 bool JSCell::getOwnPropertySlot(JSObject
*, ExecState
*, PropertyName
, PropertySlot
&)
179 RELEASE_ASSERT_NOT_REACHED();
183 bool JSCell::getOwnPropertySlotByIndex(JSObject
*, ExecState
*, unsigned, PropertySlot
&)
185 RELEASE_ASSERT_NOT_REACHED();
189 void JSCell::getOwnPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
191 RELEASE_ASSERT_NOT_REACHED();
194 void JSCell::getOwnNonIndexPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
196 RELEASE_ASSERT_NOT_REACHED();
199 String
JSCell::className(const JSObject
*)
201 RELEASE_ASSERT_NOT_REACHED();
205 const char* JSCell::className() const
207 return classInfo()->className
;
210 void JSCell::getPropertyNames(JSObject
*, ExecState
*, PropertyNameArray
&, EnumerationMode
)
212 RELEASE_ASSERT_NOT_REACHED();
215 bool JSCell::customHasInstance(JSObject
*, ExecState
*, JSValue
)
217 RELEASE_ASSERT_NOT_REACHED();
221 bool JSCell::defineOwnProperty(JSObject
*, ExecState
*, PropertyName
, const PropertyDescriptor
&, bool)
223 RELEASE_ASSERT_NOT_REACHED();
227 ArrayBuffer
* JSCell::slowDownAndWasteMemory(JSArrayBufferView
*)
229 RELEASE_ASSERT_NOT_REACHED();
233 PassRefPtr
<ArrayBufferView
> JSCell::getTypedArrayImpl(JSArrayBufferView
*)
235 RELEASE_ASSERT_NOT_REACHED();