blob: c283f0917d64e6b01c4fda432b2f17161cbd44c6 [file] [log] [blame]
weinig@apple.com6a03b4c2008-07-01 17:32:44 +00001/*
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.
5 *
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.
10 *
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.
15 *
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.
20 *
21 */
22
23#include "config.h"
24#include "JSCell.h"
25
fpizlo@apple.com0e0d9312013-08-15 20:43:06 +000026#include "ArrayBufferView.h"
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000027#include "JSFunction.h"
28#include "JSString.h"
29#include "JSObject.h"
mhahnenberg@apple.come5e24642011-09-24 01:19:56 +000030#include "NumberObject.h"
fpizlo@apple.coma4b4cbe2013-01-12 04:47:03 +000031#include "Operations.h"
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000032#include <wtf/MathExtras.h>
33
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000034namespace JSC {
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000035
andersca@apple.com7de5aae2013-09-05 20:12:23 +000036STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSCell);
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +000037
38void JSCell::destroy(JSCell* cell)
39{
40 cell->JSCell::~JSCell();
41}
42
fpizlo@apple.com059375802013-08-05 19:52:43 +000043void JSCell::copyBackingStore(JSCell*, CopyVisitor&, CopyToken)
mhahnenberg@apple.com02e39c72012-10-12 19:38:35 +000044{
45}
46
benjamin@webkit.orgcff06e42012-08-30 21:23:51 +000047bool JSCell::getString(ExecState* exec, String& stringValue) const
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000048{
49 if (!isString())
50 return false;
barraclough@apple.comb749f0b2009-12-07 23:14:04 +000051 stringValue = static_cast<const JSString*>(this)->value(exec);
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000052 return true;
53}
54
benjamin@webkit.orgcff06e42012-08-30 21:23:51 +000055String JSCell::getString(ExecState* exec) const
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000056{
benjamin@webkit.orgcff06e42012-08-30 21:23:51 +000057 return isString() ? static_cast<const JSString*>(this)->value(exec) : String();
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000058}
59
60JSObject* JSCell::getObject()
61{
darin@apple.com9fb218b2009-09-04 18:53:02 +000062 return isObject() ? asObject(this) : 0;
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000063}
64
65const JSObject* JSCell::getObject() const
66{
67 return isObject() ? static_cast<const JSObject*>(this) : 0;
68}
69
oliver@apple.com6ff615e2013-07-11 18:35:35 +000070CallType JSCell::getCallData(JSCell*, CallData& callData)
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000071{
oliver@apple.com6ff615e2013-07-11 18:35:35 +000072 callData.js.functionExecutable = 0;
73 callData.js.scope = 0;
74 callData.native.function = 0;
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000075 return CallTypeNone;
76}
77
oliver@apple.com6ff615e2013-07-11 18:35:35 +000078ConstructType JSCell::getConstructData(JSCell*, ConstructData& constructData)
mhahnenberg@apple.com79c8e6e2011-10-08 23:26:41 +000079{
oliver@apple.com6ff615e2013-07-11 18:35:35 +000080 constructData.js.functionExecutable = 0;
81 constructData.js.scope = 0;
82 constructData.native.function = 0;
mhahnenberg@apple.com79c8e6e2011-10-08 23:26:41 +000083 return ConstructTypeNone;
84}
85
barraclough@apple.com38d3c752012-05-12 00:39:43 +000086void JSCell::put(JSCell* cell, ExecState* exec, PropertyName identifier, JSValue value, PutPropertySlot& slot)
mhahnenberg@apple.com5e2b7122011-10-08 00:06:07 +000087{
barraclough@apple.comdca6b2e2012-02-29 01:39:15 +000088 if (cell->isString()) {
89 JSValue(cell).putToPrimitive(exec, identifier, value, slot);
90 return;
91 }
mhahnenberg@apple.com39512782011-10-26 00:56:55 +000092 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
93 thisObject->methodTable()->put(thisObject, exec, identifier, value, slot);
mhahnenberg@apple.com5e2b7122011-10-08 00:06:07 +000094}
95
barraclough@apple.comb1db28d82012-03-06 07:23:21 +000096void JSCell::putByIndex(JSCell* cell, ExecState* exec, unsigned identifier, JSValue value, bool shouldThrow)
mhahnenberg@apple.com5e2b7122011-10-08 00:06:07 +000097{
barraclough@apple.comb1db28d82012-03-06 07:23:21 +000098 if (cell->isString()) {
99 PutPropertySlot slot(shouldThrow);
100 JSValue(cell).putToPrimitive(exec, Identifier::from(exec, identifier), value, slot);
101 return;
102 }
mhahnenberg@apple.com39512782011-10-26 00:56:55 +0000103 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
barraclough@apple.comb1db28d82012-03-06 07:23:21 +0000104 thisObject->methodTable()->putByIndex(thisObject, exec, identifier, value, shouldThrow);
weinig@apple.com6a03b4c2008-07-01 17:32:44 +0000105}
106
barraclough@apple.com38d3c752012-05-12 00:39:43 +0000107bool JSCell::deleteProperty(JSCell* cell, ExecState* exec, PropertyName identifier)
mhahnenberg@apple.com914c3ee2011-10-08 06:37:45 +0000108{
mhahnenberg@apple.comc0f87c12011-10-26 01:49:00 +0000109 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
110 return thisObject->methodTable()->deleteProperty(thisObject, exec, identifier);
mhahnenberg@apple.com914c3ee2011-10-08 06:37:45 +0000111}
112
mhahnenberg@apple.com8a10db92011-10-20 18:14:50 +0000113bool JSCell::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned identifier)
mhahnenberg@apple.com914c3ee2011-10-08 06:37:45 +0000114{
mhahnenberg@apple.comc0f87c12011-10-26 01:49:00 +0000115 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
116 return thisObject->methodTable()->deletePropertyByIndex(thisObject, exec, identifier);
weinig@apple.com6a03b4c2008-07-01 17:32:44 +0000117}
118
oliver@apple.come2fe4ce2013-07-25 03:59:41 +0000119JSValue JSCell::toThis(JSCell* cell, ExecState* exec, ECMAMode ecmaMode)
weinig@apple.com6a03b4c2008-07-01 17:32:44 +0000120{
oliver@apple.come2fe4ce2013-07-25 03:59:41 +0000121 if (ecmaMode == StrictMode)
122 return cell;
mhahnenberg@apple.comc93887c2011-10-27 17:01:38 +0000123 return cell->toObject(exec, exec->lexicalGlobalObject());
weinig@apple.com6a03b4c2008-07-01 17:32:44 +0000124}
125
mhahnenberg@apple.com02a74ea2011-09-20 04:33:10 +0000126JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
commit-queue@webkit.orga7d0ea52011-09-19 21:28:06 +0000127{
mhahnenberg@apple.com02a74ea2011-09-20 04:33:10 +0000128 if (isString())
129 return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType);
130 return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType);
commit-queue@webkit.orga7d0ea52011-09-19 21:28:06 +0000131}
132
mhahnenberg@apple.com061133e2011-09-27 19:53:49 +0000133bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const
ggaren@apple.comcece7562009-08-26 23:00:39 +0000134{
mhahnenberg@apple.com061133e2011-09-27 19:53:49 +0000135 if (isString())
136 return static_cast<const JSString*>(this)->getPrimitiveNumber(exec, number, value);
137 return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value);
ggaren@apple.comcece7562009-08-26 23:00:39 +0000138}
139
mhahnenberg@apple.com8d0ab172011-10-13 19:24:53 +0000140double JSCell::toNumber(ExecState* exec) const
141{
142 if (isString())
143 return static_cast<const JSString*>(this)->toNumber(exec);
144 return static_cast<const JSObject*>(this)->toNumber(exec);
ggaren@apple.comcece7562009-08-26 23:00:39 +0000145}
146
mhahnenberg@apple.comb6e2ac62011-09-30 02:09:16 +0000147JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const
ggaren@apple.comcece7562009-08-26 23:00:39 +0000148{
mhahnenberg@apple.comb6e2ac62011-09-30 02:09:16 +0000149 if (isString())
150 return static_cast<const JSString*>(this)->toObject(exec, globalObject);
151 ASSERT(isObject());
oliver@apple.com0c59caf2012-04-05 20:09:33 +0000152 return jsCast<JSObject*>(const_cast<JSCell*>(this));
ggaren@apple.comcece7562009-08-26 23:00:39 +0000153}
154
oliver@apple.com41037162011-05-14 22:10:01 +0000155void slowValidateCell(JSCell* cell)
156{
157 ASSERT_GC_OBJECT_LOOKS_VALID(cell);
158}
159
mhahnenberg@apple.com6e506e62011-11-01 01:15:06 +0000160JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType)
161{
oliver@apple.com5598c182013-01-23 22:25:07 +0000162 RELEASE_ASSERT_NOT_REACHED();
mhahnenberg@apple.com6e506e62011-11-01 01:15:06 +0000163 return jsUndefined();
164}
165
barraclough@apple.comab7b6092013-07-31 19:03:05 +0000166bool JSCell::getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&)
167{
168 RELEASE_ASSERT_NOT_REACHED();
169 return false;
170}
171
172bool JSCell::getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned, PropertySlot&)
173{
174 RELEASE_ASSERT_NOT_REACHED();
175 return false;
176}
177
mhahnenberg@apple.com57262382011-11-03 00:25:45 +0000178void JSCell::getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
179{
oliver@apple.com5598c182013-01-23 22:25:07 +0000180 RELEASE_ASSERT_NOT_REACHED();
mhahnenberg@apple.com57262382011-11-03 00:25:45 +0000181}
182
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +0000183void JSCell::getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
184{
oliver@apple.com5598c182013-01-23 22:25:07 +0000185 RELEASE_ASSERT_NOT_REACHED();
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +0000186}
187
benjamin@webkit.orgcff06e42012-08-30 21:23:51 +0000188String JSCell::className(const JSObject*)
mhahnenberg@apple.comb039de02011-11-03 18:20:08 +0000189{
oliver@apple.com5598c182013-01-23 22:25:07 +0000190 RELEASE_ASSERT_NOT_REACHED();
benjamin@webkit.orgcff06e42012-08-30 21:23:51 +0000191 return String();
mhahnenberg@apple.comb039de02011-11-03 18:20:08 +0000192}
193
msaboff@apple.com9d9eab62012-06-06 23:11:09 +0000194const char* JSCell::className()
195{
196 return classInfo()->className;
197}
198
mhahnenberg@apple.com2358ae12011-11-04 01:32:18 +0000199void JSCell::getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
200{
oliver@apple.com5598c182013-01-23 22:25:07 +0000201 RELEASE_ASSERT_NOT_REACHED();
mhahnenberg@apple.com2358ae12011-11-04 01:32:18 +0000202}
203
barraclough@apple.comb46d57b42012-09-22 00:43:03 +0000204bool JSCell::customHasInstance(JSObject*, ExecState*, JSValue)
mhahnenberg@apple.com069ad172011-11-04 20:37:32 +0000205{
oliver@apple.com5598c182013-01-23 22:25:07 +0000206 RELEASE_ASSERT_NOT_REACHED();
mhahnenberg@apple.com069ad172011-11-04 20:37:32 +0000207 return false;
208}
209
barraclough@apple.com61ff98c2013-08-21 22:32:10 +0000210bool JSCell::defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool)
mhahnenberg@apple.com8c9572d2011-11-09 10:18:04 +0000211{
oliver@apple.com5598c182013-01-23 22:25:07 +0000212 RELEASE_ASSERT_NOT_REACHED();
mhahnenberg@apple.com8c9572d2011-11-09 10:18:04 +0000213 return false;
214}
215
fpizlo@apple.comcd07b472013-08-21 20:53:57 +0000216ArrayBuffer* JSCell::slowDownAndWasteMemory(JSArrayBufferView*)
fpizlo@apple.com0e0d9312013-08-15 20:43:06 +0000217{
218 RELEASE_ASSERT_NOT_REACHED();
fpizlo@apple.comcd07b472013-08-21 20:53:57 +0000219 return 0;
fpizlo@apple.com0e0d9312013-08-15 20:43:06 +0000220}
221
222PassRefPtr<ArrayBufferView> JSCell::getTypedArrayImpl(JSArrayBufferView*)
223{
224 RELEASE_ASSERT_NOT_REACHED();
225 return 0;
226}
227
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +0000228} // namespace JSC