weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 0e0d931 | 2013-08-15 20:43:06 +0000 | [diff] [blame] | 26 | #include "ArrayBufferView.h" |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 27 | #include "JSFunction.h" |
| 28 | #include "JSString.h" |
| 29 | #include "JSObject.h" |
mhahnenberg@apple.com | e5e2464 | 2011-09-24 01:19:56 +0000 | [diff] [blame] | 30 | #include "NumberObject.h" |
fpizlo@apple.com | a4b4cbe | 2013-01-12 04:47:03 +0000 | [diff] [blame] | 31 | #include "Operations.h" |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 32 | #include <wtf/MathExtras.h> |
| 33 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 34 | namespace JSC { |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 35 | |
andersca@apple.com | 7de5aae | 2013-09-05 20:12:23 +0000 | [diff] [blame] | 36 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSCell); |
mhahnenberg@apple.com | c58d54d | 2011-12-16 19:06:44 +0000 | [diff] [blame] | 37 | |
| 38 | void JSCell::destroy(JSCell* cell) |
| 39 | { |
| 40 | cell->JSCell::~JSCell(); |
| 41 | } |
| 42 | |
fpizlo@apple.com | 05937580 | 2013-08-05 19:52:43 +0000 | [diff] [blame] | 43 | void JSCell::copyBackingStore(JSCell*, CopyVisitor&, CopyToken) |
mhahnenberg@apple.com | 02e39c7 | 2012-10-12 19:38:35 +0000 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 47 | bool JSCell::getString(ExecState* exec, String& stringValue) const |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 48 | { |
| 49 | if (!isString()) |
| 50 | return false; |
barraclough@apple.com | b749f0b | 2009-12-07 23:14:04 +0000 | [diff] [blame] | 51 | stringValue = static_cast<const JSString*>(this)->value(exec); |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 52 | return true; |
| 53 | } |
| 54 | |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 55 | String JSCell::getString(ExecState* exec) const |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 56 | { |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 57 | return isString() ? static_cast<const JSString*>(this)->value(exec) : String(); |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | JSObject* JSCell::getObject() |
| 61 | { |
darin@apple.com | 9fb218b | 2009-09-04 18:53:02 +0000 | [diff] [blame] | 62 | return isObject() ? asObject(this) : 0; |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | const JSObject* JSCell::getObject() const |
| 66 | { |
| 67 | return isObject() ? static_cast<const JSObject*>(this) : 0; |
| 68 | } |
| 69 | |
oliver@apple.com | 6ff615e | 2013-07-11 18:35:35 +0000 | [diff] [blame] | 70 | CallType JSCell::getCallData(JSCell*, CallData& callData) |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 71 | { |
oliver@apple.com | 6ff615e | 2013-07-11 18:35:35 +0000 | [diff] [blame] | 72 | callData.js.functionExecutable = 0; |
| 73 | callData.js.scope = 0; |
| 74 | callData.native.function = 0; |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 75 | return CallTypeNone; |
| 76 | } |
| 77 | |
oliver@apple.com | 6ff615e | 2013-07-11 18:35:35 +0000 | [diff] [blame] | 78 | ConstructType JSCell::getConstructData(JSCell*, ConstructData& constructData) |
mhahnenberg@apple.com | 79c8e6e | 2011-10-08 23:26:41 +0000 | [diff] [blame] | 79 | { |
oliver@apple.com | 6ff615e | 2013-07-11 18:35:35 +0000 | [diff] [blame] | 80 | constructData.js.functionExecutable = 0; |
| 81 | constructData.js.scope = 0; |
| 82 | constructData.native.function = 0; |
mhahnenberg@apple.com | 79c8e6e | 2011-10-08 23:26:41 +0000 | [diff] [blame] | 83 | return ConstructTypeNone; |
| 84 | } |
| 85 | |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 86 | void JSCell::put(JSCell* cell, ExecState* exec, PropertyName identifier, JSValue value, PutPropertySlot& slot) |
mhahnenberg@apple.com | 5e2b712 | 2011-10-08 00:06:07 +0000 | [diff] [blame] | 87 | { |
barraclough@apple.com | dca6b2e | 2012-02-29 01:39:15 +0000 | [diff] [blame] | 88 | if (cell->isString()) { |
| 89 | JSValue(cell).putToPrimitive(exec, identifier, value, slot); |
| 90 | return; |
| 91 | } |
mhahnenberg@apple.com | 3951278 | 2011-10-26 00:56:55 +0000 | [diff] [blame] | 92 | JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject()); |
| 93 | thisObject->methodTable()->put(thisObject, exec, identifier, value, slot); |
mhahnenberg@apple.com | 5e2b712 | 2011-10-08 00:06:07 +0000 | [diff] [blame] | 94 | } |
| 95 | |
barraclough@apple.com | b1db28d8 | 2012-03-06 07:23:21 +0000 | [diff] [blame] | 96 | void JSCell::putByIndex(JSCell* cell, ExecState* exec, unsigned identifier, JSValue value, bool shouldThrow) |
mhahnenberg@apple.com | 5e2b712 | 2011-10-08 00:06:07 +0000 | [diff] [blame] | 97 | { |
barraclough@apple.com | b1db28d8 | 2012-03-06 07:23:21 +0000 | [diff] [blame] | 98 | if (cell->isString()) { |
| 99 | PutPropertySlot slot(shouldThrow); |
| 100 | JSValue(cell).putToPrimitive(exec, Identifier::from(exec, identifier), value, slot); |
| 101 | return; |
| 102 | } |
mhahnenberg@apple.com | 3951278 | 2011-10-26 00:56:55 +0000 | [diff] [blame] | 103 | JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject()); |
barraclough@apple.com | b1db28d8 | 2012-03-06 07:23:21 +0000 | [diff] [blame] | 104 | thisObject->methodTable()->putByIndex(thisObject, exec, identifier, value, shouldThrow); |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 105 | } |
| 106 | |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 107 | bool JSCell::deleteProperty(JSCell* cell, ExecState* exec, PropertyName identifier) |
mhahnenberg@apple.com | 914c3ee | 2011-10-08 06:37:45 +0000 | [diff] [blame] | 108 | { |
mhahnenberg@apple.com | c0f87c1 | 2011-10-26 01:49:00 +0000 | [diff] [blame] | 109 | JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject()); |
| 110 | return thisObject->methodTable()->deleteProperty(thisObject, exec, identifier); |
mhahnenberg@apple.com | 914c3ee | 2011-10-08 06:37:45 +0000 | [diff] [blame] | 111 | } |
| 112 | |
mhahnenberg@apple.com | 8a10db9 | 2011-10-20 18:14:50 +0000 | [diff] [blame] | 113 | bool JSCell::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned identifier) |
mhahnenberg@apple.com | 914c3ee | 2011-10-08 06:37:45 +0000 | [diff] [blame] | 114 | { |
mhahnenberg@apple.com | c0f87c1 | 2011-10-26 01:49:00 +0000 | [diff] [blame] | 115 | JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject()); |
| 116 | return thisObject->methodTable()->deletePropertyByIndex(thisObject, exec, identifier); |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 117 | } |
| 118 | |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 119 | JSValue JSCell::toThis(JSCell* cell, ExecState* exec, ECMAMode ecmaMode) |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 120 | { |
oliver@apple.com | e2fe4ce | 2013-07-25 03:59:41 +0000 | [diff] [blame] | 121 | if (ecmaMode == StrictMode) |
| 122 | return cell; |
mhahnenberg@apple.com | c93887c | 2011-10-27 17:01:38 +0000 | [diff] [blame] | 123 | return cell->toObject(exec, exec->lexicalGlobalObject()); |
weinig@apple.com | 6a03b4c | 2008-07-01 17:32:44 +0000 | [diff] [blame] | 124 | } |
| 125 | |
mhahnenberg@apple.com | 02a74ea | 2011-09-20 04:33:10 +0000 | [diff] [blame] | 126 | JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const |
commit-queue@webkit.org | a7d0ea5 | 2011-09-19 21:28:06 +0000 | [diff] [blame] | 127 | { |
mhahnenberg@apple.com | 02a74ea | 2011-09-20 04:33:10 +0000 | [diff] [blame] | 128 | 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.org | a7d0ea5 | 2011-09-19 21:28:06 +0000 | [diff] [blame] | 131 | } |
| 132 | |
mhahnenberg@apple.com | 061133e | 2011-09-27 19:53:49 +0000 | [diff] [blame] | 133 | bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const |
ggaren@apple.com | cece756 | 2009-08-26 23:00:39 +0000 | [diff] [blame] | 134 | { |
mhahnenberg@apple.com | 061133e | 2011-09-27 19:53:49 +0000 | [diff] [blame] | 135 | 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.com | cece756 | 2009-08-26 23:00:39 +0000 | [diff] [blame] | 138 | } |
| 139 | |
mhahnenberg@apple.com | 8d0ab17 | 2011-10-13 19:24:53 +0000 | [diff] [blame] | 140 | double 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.com | cece756 | 2009-08-26 23:00:39 +0000 | [diff] [blame] | 145 | } |
| 146 | |
mhahnenberg@apple.com | b6e2ac6 | 2011-09-30 02:09:16 +0000 | [diff] [blame] | 147 | JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const |
ggaren@apple.com | cece756 | 2009-08-26 23:00:39 +0000 | [diff] [blame] | 148 | { |
mhahnenberg@apple.com | b6e2ac6 | 2011-09-30 02:09:16 +0000 | [diff] [blame] | 149 | if (isString()) |
| 150 | return static_cast<const JSString*>(this)->toObject(exec, globalObject); |
| 151 | ASSERT(isObject()); |
oliver@apple.com | 0c59caf | 2012-04-05 20:09:33 +0000 | [diff] [blame] | 152 | return jsCast<JSObject*>(const_cast<JSCell*>(this)); |
ggaren@apple.com | cece756 | 2009-08-26 23:00:39 +0000 | [diff] [blame] | 153 | } |
| 154 | |
oliver@apple.com | 4103716 | 2011-05-14 22:10:01 +0000 | [diff] [blame] | 155 | void slowValidateCell(JSCell* cell) |
| 156 | { |
| 157 | ASSERT_GC_OBJECT_LOOKS_VALID(cell); |
| 158 | } |
| 159 | |
mhahnenberg@apple.com | 6e506e6 | 2011-11-01 01:15:06 +0000 | [diff] [blame] | 160 | JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType) |
| 161 | { |
oliver@apple.com | 5598c18 | 2013-01-23 22:25:07 +0000 | [diff] [blame] | 162 | RELEASE_ASSERT_NOT_REACHED(); |
mhahnenberg@apple.com | 6e506e6 | 2011-11-01 01:15:06 +0000 | [diff] [blame] | 163 | return jsUndefined(); |
| 164 | } |
| 165 | |
barraclough@apple.com | ab7b609 | 2013-07-31 19:03:05 +0000 | [diff] [blame] | 166 | bool JSCell::getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&) |
| 167 | { |
| 168 | RELEASE_ASSERT_NOT_REACHED(); |
| 169 | return false; |
| 170 | } |
| 171 | |
| 172 | bool JSCell::getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned, PropertySlot&) |
| 173 | { |
| 174 | RELEASE_ASSERT_NOT_REACHED(); |
| 175 | return false; |
| 176 | } |
| 177 | |
mhahnenberg@apple.com | 5726238 | 2011-11-03 00:25:45 +0000 | [diff] [blame] | 178 | void JSCell::getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode) |
| 179 | { |
oliver@apple.com | 5598c18 | 2013-01-23 22:25:07 +0000 | [diff] [blame] | 180 | RELEASE_ASSERT_NOT_REACHED(); |
mhahnenberg@apple.com | 5726238 | 2011-11-03 00:25:45 +0000 | [diff] [blame] | 181 | } |
| 182 | |
fpizlo@apple.com | d8dd053 | 2012-09-13 04:18:52 +0000 | [diff] [blame] | 183 | void JSCell::getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode) |
| 184 | { |
oliver@apple.com | 5598c18 | 2013-01-23 22:25:07 +0000 | [diff] [blame] | 185 | RELEASE_ASSERT_NOT_REACHED(); |
fpizlo@apple.com | d8dd053 | 2012-09-13 04:18:52 +0000 | [diff] [blame] | 186 | } |
| 187 | |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 188 | String JSCell::className(const JSObject*) |
mhahnenberg@apple.com | b039de0 | 2011-11-03 18:20:08 +0000 | [diff] [blame] | 189 | { |
oliver@apple.com | 5598c18 | 2013-01-23 22:25:07 +0000 | [diff] [blame] | 190 | RELEASE_ASSERT_NOT_REACHED(); |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 191 | return String(); |
mhahnenberg@apple.com | b039de0 | 2011-11-03 18:20:08 +0000 | [diff] [blame] | 192 | } |
| 193 | |
msaboff@apple.com | 9d9eab6 | 2012-06-06 23:11:09 +0000 | [diff] [blame] | 194 | const char* JSCell::className() |
| 195 | { |
| 196 | return classInfo()->className; |
| 197 | } |
| 198 | |
mhahnenberg@apple.com | 2358ae1 | 2011-11-04 01:32:18 +0000 | [diff] [blame] | 199 | void JSCell::getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode) |
| 200 | { |
oliver@apple.com | 5598c18 | 2013-01-23 22:25:07 +0000 | [diff] [blame] | 201 | RELEASE_ASSERT_NOT_REACHED(); |
mhahnenberg@apple.com | 2358ae1 | 2011-11-04 01:32:18 +0000 | [diff] [blame] | 202 | } |
| 203 | |
barraclough@apple.com | b46d57b4 | 2012-09-22 00:43:03 +0000 | [diff] [blame] | 204 | bool JSCell::customHasInstance(JSObject*, ExecState*, JSValue) |
mhahnenberg@apple.com | 069ad17 | 2011-11-04 20:37:32 +0000 | [diff] [blame] | 205 | { |
oliver@apple.com | 5598c18 | 2013-01-23 22:25:07 +0000 | [diff] [blame] | 206 | RELEASE_ASSERT_NOT_REACHED(); |
mhahnenberg@apple.com | 069ad17 | 2011-11-04 20:37:32 +0000 | [diff] [blame] | 207 | return false; |
| 208 | } |
| 209 | |
barraclough@apple.com | 61ff98c | 2013-08-21 22:32:10 +0000 | [diff] [blame] | 210 | bool JSCell::defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool) |
mhahnenberg@apple.com | 8c9572d | 2011-11-09 10:18:04 +0000 | [diff] [blame] | 211 | { |
oliver@apple.com | 5598c18 | 2013-01-23 22:25:07 +0000 | [diff] [blame] | 212 | RELEASE_ASSERT_NOT_REACHED(); |
mhahnenberg@apple.com | 8c9572d | 2011-11-09 10:18:04 +0000 | [diff] [blame] | 213 | return false; |
| 214 | } |
| 215 | |
fpizlo@apple.com | cd07b47 | 2013-08-21 20:53:57 +0000 | [diff] [blame] | 216 | ArrayBuffer* JSCell::slowDownAndWasteMemory(JSArrayBufferView*) |
fpizlo@apple.com | 0e0d931 | 2013-08-15 20:43:06 +0000 | [diff] [blame] | 217 | { |
| 218 | RELEASE_ASSERT_NOT_REACHED(); |
fpizlo@apple.com | cd07b47 | 2013-08-21 20:53:57 +0000 | [diff] [blame] | 219 | return 0; |
fpizlo@apple.com | 0e0d931 | 2013-08-15 20:43:06 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | PassRefPtr<ArrayBufferView> JSCell::getTypedArrayImpl(JSArrayBufferView*) |
| 223 | { |
| 224 | RELEASE_ASSERT_NOT_REACHED(); |
| 225 | return 0; |
| 226 | } |
| 227 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 228 | } // namespace JSC |