blob: 013b7dd7592113bd99476e3d502c98b0a96fb375 [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"
sbarati@apple.com812da912016-12-12 03:11:18 +000027#include "JSCInlines.h"
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000028#include "JSFunction.h"
29#include "JSString.h"
30#include "JSObject.h"
mhahnenberg@apple.come5e24642011-09-24 01:19:56 +000031#include "NumberObject.h"
sbarati@apple.com812da912016-12-12 03:11:18 +000032#include "WebAssemblyToJSCallee.h"
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000033#include <wtf/MathExtras.h>
34
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000035namespace JSC {
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000036
mhahnenberg@apple.comb6f85192014-02-27 01:27:18 +000037COMPILE_ASSERT(sizeof(JSCell) == sizeof(uint64_t), jscell_is_eight_bytes);
andersca@apple.com7de5aae2013-09-05 20:12:23 +000038STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSCell);
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +000039
40void JSCell::destroy(JSCell* cell)
41{
42 cell->JSCell::~JSCell();
43}
44
mhahnenberg@apple.com040ef242014-04-05 20:05:04 +000045void JSCell::dump(PrintStream& out) const
46{
47 methodTable()->dumpToStream(this, out);
48}
49
50void JSCell::dumpToStream(const JSCell* cell, PrintStream& out)
51{
keith_miller@apple.com45da7602017-01-27 01:47:52 +000052 out.printf("<%p, %s>", cell, cell->className(*cell->vm()));
mhahnenberg@apple.com040ef242014-04-05 20:05:04 +000053}
54
commit-queue@webkit.org00eb52f2016-03-01 02:07:12 +000055size_t JSCell::estimatedSizeInBytes() const
56{
57 return methodTable()->estimatedSize(const_cast<JSCell*>(this));
58}
59
60size_t JSCell::estimatedSize(JSCell* cell)
61{
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +000062 return cell->cellSize();
commit-queue@webkit.org00eb52f2016-03-01 02:07:12 +000063}
64
commit-queue@webkit.orgc4c0f562016-03-07 23:45:38 +000065void JSCell::heapSnapshot(JSCell*, HeapSnapshotBuilder&)
66{
67}
68
benjamin@webkit.orgcff06e42012-08-30 21:23:51 +000069bool JSCell::getString(ExecState* exec, String& stringValue) const
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000070{
71 if (!isString())
72 return false;
barraclough@apple.comb749f0b2009-12-07 23:14:04 +000073 stringValue = static_cast<const JSString*>(this)->value(exec);
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000074 return true;
75}
76
benjamin@webkit.orgcff06e42012-08-30 21:23:51 +000077String JSCell::getString(ExecState* exec) const
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000078{
benjamin@webkit.orgcff06e42012-08-30 21:23:51 +000079 return isString() ? static_cast<const JSString*>(this)->value(exec) : String();
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000080}
81
82JSObject* JSCell::getObject()
83{
darin@apple.com9fb218b2009-09-04 18:53:02 +000084 return isObject() ? asObject(this) : 0;
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000085}
86
87const JSObject* JSCell::getObject() const
88{
89 return isObject() ? static_cast<const JSObject*>(this) : 0;
90}
91
oliver@apple.com6ff615e2013-07-11 18:35:35 +000092CallType JSCell::getCallData(JSCell*, CallData& callData)
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000093{
oliver@apple.com6ff615e2013-07-11 18:35:35 +000094 callData.js.functionExecutable = 0;
95 callData.js.scope = 0;
96 callData.native.function = 0;
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +000097 return CallType::None;
weinig@apple.com6a03b4c2008-07-01 17:32:44 +000098}
99
oliver@apple.com6ff615e2013-07-11 18:35:35 +0000100ConstructType JSCell::getConstructData(JSCell*, ConstructData& constructData)
mhahnenberg@apple.com79c8e6e2011-10-08 23:26:41 +0000101{
oliver@apple.com6ff615e2013-07-11 18:35:35 +0000102 constructData.js.functionExecutable = 0;
103 constructData.js.scope = 0;
104 constructData.native.function = 0;
utatane.tea@gmail.comf76f1b42016-03-05 17:01:04 +0000105 return ConstructType::None;
mhahnenberg@apple.com79c8e6e2011-10-08 23:26:41 +0000106}
107
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +0000108bool JSCell::put(JSCell* cell, ExecState* exec, PropertyName identifier, JSValue value, PutPropertySlot& slot)
mhahnenberg@apple.com5e2b7122011-10-08 00:06:07 +0000109{
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +0000110 if (cell->isString() || cell->isSymbol())
111 return JSValue(cell).putToPrimitive(exec, identifier, value, slot);
112
mhahnenberg@apple.com39512782011-10-26 00:56:55 +0000113 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +0000114 return thisObject->methodTable(exec->vm())->put(thisObject, exec, identifier, value, slot);
mhahnenberg@apple.com5e2b7122011-10-08 00:06:07 +0000115}
116
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +0000117bool JSCell::putByIndex(JSCell* cell, ExecState* exec, unsigned identifier, JSValue value, bool shouldThrow)
mhahnenberg@apple.com5e2b7122011-10-08 00:06:07 +0000118{
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +0000119 if (cell->isString() || cell->isSymbol()) {
oliver@apple.com68848412014-01-02 20:56:20 +0000120 PutPropertySlot slot(cell, shouldThrow);
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +0000121 return JSValue(cell).putToPrimitive(exec, Identifier::from(exec, identifier), value, slot);
barraclough@apple.comb1db28d82012-03-06 07:23:21 +0000122 }
mhahnenberg@apple.com39512782011-10-26 00:56:55 +0000123 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
utatane.tea@gmail.com78b50c62016-03-11 17:28:46 +0000124 return thisObject->methodTable(exec->vm())->putByIndex(thisObject, exec, identifier, value, shouldThrow);
weinig@apple.com6a03b4c2008-07-01 17:32:44 +0000125}
126
barraclough@apple.com38d3c752012-05-12 00:39:43 +0000127bool JSCell::deleteProperty(JSCell* cell, ExecState* exec, PropertyName identifier)
mhahnenberg@apple.com914c3ee2011-10-08 06:37:45 +0000128{
mhahnenberg@apple.comc0f87c12011-10-26 01:49:00 +0000129 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
mhahnenberg@apple.comb6f85192014-02-27 01:27:18 +0000130 return thisObject->methodTable(exec->vm())->deleteProperty(thisObject, exec, identifier);
mhahnenberg@apple.com914c3ee2011-10-08 06:37:45 +0000131}
132
mhahnenberg@apple.com8a10db92011-10-20 18:14:50 +0000133bool JSCell::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned identifier)
mhahnenberg@apple.com914c3ee2011-10-08 06:37:45 +0000134{
mhahnenberg@apple.comc0f87c12011-10-26 01:49:00 +0000135 JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
mhahnenberg@apple.comb6f85192014-02-27 01:27:18 +0000136 return thisObject->methodTable(exec->vm())->deletePropertyByIndex(thisObject, exec, identifier);
weinig@apple.com6a03b4c2008-07-01 17:32:44 +0000137}
138
oliver@apple.come2fe4ce2013-07-25 03:59:41 +0000139JSValue JSCell::toThis(JSCell* cell, ExecState* exec, ECMAMode ecmaMode)
weinig@apple.com6a03b4c2008-07-01 17:32:44 +0000140{
oliver@apple.come2fe4ce2013-07-25 03:59:41 +0000141 if (ecmaMode == StrictMode)
142 return cell;
mhahnenberg@apple.comc93887c2011-10-27 17:01:38 +0000143 return cell->toObject(exec, exec->lexicalGlobalObject());
weinig@apple.com6a03b4c2008-07-01 17:32:44 +0000144}
145
mhahnenberg@apple.com02a74ea2011-09-20 04:33:10 +0000146JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
commit-queue@webkit.orga7d0ea52011-09-19 21:28:06 +0000147{
mhahnenberg@apple.com02a74ea2011-09-20 04:33:10 +0000148 if (isString())
149 return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType);
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +0000150 if (isSymbol())
151 return static_cast<const Symbol*>(this)->toPrimitive(exec, preferredType);
mhahnenberg@apple.com02a74ea2011-09-20 04:33:10 +0000152 return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType);
commit-queue@webkit.orga7d0ea52011-09-19 21:28:06 +0000153}
154
mhahnenberg@apple.com061133e2011-09-27 19:53:49 +0000155bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const
ggaren@apple.comcece7562009-08-26 23:00:39 +0000156{
mhahnenberg@apple.com061133e2011-09-27 19:53:49 +0000157 if (isString())
158 return static_cast<const JSString*>(this)->getPrimitiveNumber(exec, number, value);
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +0000159 if (isSymbol())
160 return static_cast<const Symbol*>(this)->getPrimitiveNumber(exec, number, value);
mhahnenberg@apple.com061133e2011-09-27 19:53:49 +0000161 return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value);
ggaren@apple.comcece7562009-08-26 23:00:39 +0000162}
163
mhahnenberg@apple.com8d0ab172011-10-13 19:24:53 +0000164double JSCell::toNumber(ExecState* exec) const
mark.lam@apple.comd42b3b82016-11-22 03:35:25 +0000165{
mhahnenberg@apple.com8d0ab172011-10-13 19:24:53 +0000166 if (isString())
167 return static_cast<const JSString*>(this)->toNumber(exec);
utatane.tea@gmail.com947fa4e2015-01-31 01:23:56 +0000168 if (isSymbol())
169 return static_cast<const Symbol*>(this)->toNumber(exec);
mhahnenberg@apple.com8d0ab172011-10-13 19:24:53 +0000170 return static_cast<const JSObject*>(this)->toNumber(exec);
ggaren@apple.comcece7562009-08-26 23:00:39 +0000171}
172
cdumez@apple.comff56ee12016-12-09 23:37:00 +0000173JSObject* JSCell::toObjectSlow(ExecState* exec, JSGlobalObject* globalObject) const
ggaren@apple.comcece7562009-08-26 23:00:39 +0000174{
cdumez@apple.comff56ee12016-12-09 23:37:00 +0000175 ASSERT(!isObject());
mhahnenberg@apple.comb6e2ac62011-09-30 02:09:16 +0000176 if (isString())
177 return static_cast<const JSString*>(this)->toObject(exec, globalObject);
cdumez@apple.comff56ee12016-12-09 23:37:00 +0000178 ASSERT(isSymbol());
179 return static_cast<const Symbol*>(this)->toObject(exec, globalObject);
ggaren@apple.comcece7562009-08-26 23:00:39 +0000180}
181
oliver@apple.com41037162011-05-14 22:10:01 +0000182void slowValidateCell(JSCell* cell)
183{
184 ASSERT_GC_OBJECT_LOOKS_VALID(cell);
185}
186
mhahnenberg@apple.com6e506e62011-11-01 01:15:06 +0000187JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType)
188{
oliver@apple.com5598c182013-01-23 22:25:07 +0000189 RELEASE_ASSERT_NOT_REACHED();
mhahnenberg@apple.com6e506e62011-11-01 01:15:06 +0000190 return jsUndefined();
191}
192
barraclough@apple.comab7b6092013-07-31 19:03:05 +0000193bool JSCell::getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&)
194{
195 RELEASE_ASSERT_NOT_REACHED();
196 return false;
197}
198
199bool JSCell::getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned, PropertySlot&)
200{
201 RELEASE_ASSERT_NOT_REACHED();
202 return false;
203}
204
mhahnenberg@apple.com57262382011-11-03 00:25:45 +0000205void JSCell::getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
206{
oliver@apple.com5598c182013-01-23 22:25:07 +0000207 RELEASE_ASSERT_NOT_REACHED();
mhahnenberg@apple.com57262382011-11-03 00:25:45 +0000208}
209
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +0000210void JSCell::getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
211{
oliver@apple.com5598c182013-01-23 22:25:07 +0000212 RELEASE_ASSERT_NOT_REACHED();
fpizlo@apple.comd8dd0532012-09-13 04:18:52 +0000213}
214
benjamin@webkit.orgcff06e42012-08-30 21:23:51 +0000215String JSCell::className(const JSObject*)
mhahnenberg@apple.comb039de02011-11-03 18:20:08 +0000216{
oliver@apple.com5598c182013-01-23 22:25:07 +0000217 RELEASE_ASSERT_NOT_REACHED();
benjamin@webkit.orgcff06e42012-08-30 21:23:51 +0000218 return String();
mhahnenberg@apple.comb039de02011-11-03 18:20:08 +0000219}
220
keith_miller@apple.com398a66a2016-08-29 18:50:44 +0000221String JSCell::toStringName(const JSObject*, ExecState*)
keith_miller@apple.comecc04d12016-08-26 17:05:21 +0000222{
223 RELEASE_ASSERT_NOT_REACHED();
224 return String();
225}
226
keith_miller@apple.com45da7602017-01-27 01:47:52 +0000227const char* JSCell::className(VM& vm) const
msaboff@apple.com9d9eab62012-06-06 23:11:09 +0000228{
keith_miller@apple.com45da7602017-01-27 01:47:52 +0000229 return classInfo(vm)->className;
msaboff@apple.com9d9eab62012-06-06 23:11:09 +0000230}
231
mhahnenberg@apple.com2358ae12011-11-04 01:32:18 +0000232void JSCell::getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
233{
oliver@apple.com5598c182013-01-23 22:25:07 +0000234 RELEASE_ASSERT_NOT_REACHED();
mhahnenberg@apple.com2358ae12011-11-04 01:32:18 +0000235}
236
barraclough@apple.comb46d57b42012-09-22 00:43:03 +0000237bool JSCell::customHasInstance(JSObject*, ExecState*, JSValue)
mhahnenberg@apple.com069ad172011-11-04 20:37:32 +0000238{
oliver@apple.com5598c182013-01-23 22:25:07 +0000239 RELEASE_ASSERT_NOT_REACHED();
mhahnenberg@apple.com069ad172011-11-04 20:37:32 +0000240 return false;
241}
242
barraclough@apple.com61ff98c2013-08-21 22:32:10 +0000243bool JSCell::defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool)
mhahnenberg@apple.com8c9572d2011-11-09 10:18:04 +0000244{
oliver@apple.com5598c182013-01-23 22:25:07 +0000245 RELEASE_ASSERT_NOT_REACHED();
mhahnenberg@apple.com8c9572d2011-11-09 10:18:04 +0000246 return false;
247}
248
fpizlo@apple.comcd07b472013-08-21 20:53:57 +0000249ArrayBuffer* JSCell::slowDownAndWasteMemory(JSArrayBufferView*)
fpizlo@apple.com0e0d9312013-08-15 20:43:06 +0000250{
251 RELEASE_ASSERT_NOT_REACHED();
utatane.tea@gmail.com473448d2017-02-17 06:04:16 +0000252 return nullptr;
fpizlo@apple.com0e0d9312013-08-15 20:43:06 +0000253}
254
utatane.tea@gmail.com473448d2017-02-17 06:04:16 +0000255RefPtr<ArrayBufferView> JSCell::getTypedArrayImpl(JSArrayBufferView*)
fpizlo@apple.com0e0d9312013-08-15 20:43:06 +0000256{
257 RELEASE_ASSERT_NOT_REACHED();
utatane.tea@gmail.com473448d2017-02-17 06:04:16 +0000258 return nullptr;
fpizlo@apple.com0e0d9312013-08-15 20:43:06 +0000259}
260
fpizlo@apple.coma398a562014-08-06 21:32:55 +0000261uint32_t JSCell::getEnumerableLength(ExecState*, JSObject*)
262{
263 RELEASE_ASSERT_NOT_REACHED();
mark.lam@apple.com6663ef32014-08-07 00:48:01 +0000264 return 0;
fpizlo@apple.coma398a562014-08-06 21:32:55 +0000265}
266
267void JSCell::getStructurePropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
268{
269 RELEASE_ASSERT_NOT_REACHED();
270}
271
272void JSCell::getGenericPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
273{
274 RELEASE_ASSERT_NOT_REACHED();
275}
276
sbarati@apple.com78007022016-03-01 08:11:20 +0000277bool JSCell::preventExtensions(JSObject*, ExecState*)
278{
279 RELEASE_ASSERT_NOT_REACHED();
280}
281
sbarati@apple.com5fd2ac82016-03-01 21:45:16 +0000282bool JSCell::isExtensible(JSObject*, ExecState*)
283{
284 RELEASE_ASSERT_NOT_REACHED();
285}
286
sbarati@apple.comf3cac472016-03-03 19:18:35 +0000287bool JSCell::setPrototype(JSObject*, ExecState*, JSValue, bool)
sbarati@apple.com48c57df2016-03-02 22:39:02 +0000288{
289 RELEASE_ASSERT_NOT_REACHED();
290}
291
sbarati@apple.comfa857522016-03-07 01:00:33 +0000292JSValue JSCell::getPrototype(JSObject*, ExecState*)
293{
294 RELEASE_ASSERT_NOT_REACHED();
295}
296
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +0000297} // namespace JSC