JSCell.cpp 6.51 KB
Newer Older
weinig@apple.com's avatar
weinig@apple.com committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
 *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
 *  Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 *
 */

#include "config.h"
#include "JSCell.h"

26
#include "ArrayBufferView.h"
weinig@apple.com's avatar
weinig@apple.com committed
27 28 29
#include "JSFunction.h"
#include "JSString.h"
#include "JSObject.h"
30
#include "NumberObject.h"
31
#include "Operations.h"
weinig@apple.com's avatar
weinig@apple.com committed
32 33
#include <wtf/MathExtras.h>

34
namespace JSC {
weinig@apple.com's avatar
weinig@apple.com committed
35

36 37 38 39 40 41 42
ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSCell);

void JSCell::destroy(JSCell* cell)
{
    cell->JSCell::~JSCell();
}

43
void JSCell::copyBackingStore(JSCell*, CopyVisitor&, CopyToken)
44 45 46
{
}

47
bool JSCell::getString(ExecState* exec, String& stringValue) const
weinig@apple.com's avatar
weinig@apple.com committed
48 49 50
{
    if (!isString())
        return false;
51
    stringValue = static_cast<const JSString*>(this)->value(exec);
weinig@apple.com's avatar
weinig@apple.com committed
52 53 54
    return true;
}

55
String JSCell::getString(ExecState* exec) const
weinig@apple.com's avatar
weinig@apple.com committed
56
{
57
    return isString() ? static_cast<const JSString*>(this)->value(exec) : String();
weinig@apple.com's avatar
weinig@apple.com committed
58 59 60 61
}

JSObject* JSCell::getObject()
{
62
    return isObject() ? asObject(this) : 0;
weinig@apple.com's avatar
weinig@apple.com committed
63 64 65 66 67 68 69
}

const JSObject* JSCell::getObject() const
{
    return isObject() ? static_cast<const JSObject*>(this) : 0;
}

70
CallType JSCell::getCallData(JSCell*, CallData& callData)
weinig@apple.com's avatar
weinig@apple.com committed
71
{
72 73 74
    callData.js.functionExecutable = 0;
    callData.js.scope = 0;
    callData.native.function = 0;
weinig@apple.com's avatar
weinig@apple.com committed
75 76 77
    return CallTypeNone;
}

78
ConstructType JSCell::getConstructData(JSCell*, ConstructData& constructData)
79
{
80 81 82
    constructData.js.functionExecutable = 0;
    constructData.js.scope = 0;
    constructData.native.function = 0;
83 84 85
    return ConstructTypeNone;
}

86
void JSCell::put(JSCell* cell, ExecState* exec, PropertyName identifier, JSValue value, PutPropertySlot& slot)
87
{
88 89 90 91
    if (cell->isString()) {
        JSValue(cell).putToPrimitive(exec, identifier, value, slot);
        return;
    }
mhahnenberg@apple.com's avatar
mhahnenberg@apple.com committed
92 93
    JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
    thisObject->methodTable()->put(thisObject, exec, identifier, value, slot);
94 95
}

96
void JSCell::putByIndex(JSCell* cell, ExecState* exec, unsigned identifier, JSValue value, bool shouldThrow)
97
{
98 99 100 101 102
    if (cell->isString()) {
        PutPropertySlot slot(shouldThrow);
        JSValue(cell).putToPrimitive(exec, Identifier::from(exec, identifier), value, slot);
        return;
    }
mhahnenberg@apple.com's avatar
mhahnenberg@apple.com committed
103
    JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
104
    thisObject->methodTable()->putByIndex(thisObject, exec, identifier, value, shouldThrow);
weinig@apple.com's avatar
weinig@apple.com committed
105 106
}

107
bool JSCell::deleteProperty(JSCell* cell, ExecState* exec, PropertyName identifier)
108
{
109 110
    JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
    return thisObject->methodTable()->deleteProperty(thisObject, exec, identifier);
111 112
}

113
bool JSCell::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned identifier)
114
{
115 116
    JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
    return thisObject->methodTable()->deletePropertyByIndex(thisObject, exec, identifier);
weinig@apple.com's avatar
weinig@apple.com committed
117 118
}

119
JSValue JSCell::toThis(JSCell* cell, ExecState* exec, ECMAMode ecmaMode)
weinig@apple.com's avatar
weinig@apple.com committed
120
{
121 122
    if (ecmaMode == StrictMode)
        return cell;
123
    return cell->toObject(exec, exec->lexicalGlobalObject());
weinig@apple.com's avatar
weinig@apple.com committed
124 125
}

126
JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
127
{
128 129 130
    if (isString())
        return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType);
    return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType);
131 132
}

133
bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const
134
{
135 136 137
    if (isString())
        return static_cast<const JSString*>(this)->getPrimitiveNumber(exec, number, value);
    return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value);
138 139
}

140 141 142 143 144
double JSCell::toNumber(ExecState* exec) const
{ 
    if (isString())
        return static_cast<const JSString*>(this)->toNumber(exec);
    return static_cast<const JSObject*>(this)->toNumber(exec);
145 146
}

147
JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const
148
{
149 150 151
    if (isString())
        return static_cast<const JSString*>(this)->toObject(exec, globalObject);
    ASSERT(isObject());
152
    return jsCast<JSObject*>(const_cast<JSCell*>(this));
153 154
}

155 156 157 158 159
void slowValidateCell(JSCell* cell)
{
    ASSERT_GC_OBJECT_LOOKS_VALID(cell);
}

160 161
JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType)
{
162
    RELEASE_ASSERT_NOT_REACHED();
163 164 165
    return jsUndefined();
}

166 167 168 169 170 171 172 173 174 175 176 177
bool JSCell::getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&)
{
    RELEASE_ASSERT_NOT_REACHED();
    return false;
}

bool JSCell::getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned, PropertySlot&)
{
    RELEASE_ASSERT_NOT_REACHED();
    return false;
}

178 179
void JSCell::getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
{
180
    RELEASE_ASSERT_NOT_REACHED();
181 182
}

183 184
void JSCell::getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
{
185
    RELEASE_ASSERT_NOT_REACHED();
186 187
}

188
String JSCell::className(const JSObject*)
189
{
190
    RELEASE_ASSERT_NOT_REACHED();
191
    return String();
192 193
}

194 195 196 197 198
const char* JSCell::className()
{
    return classInfo()->className;
}

199 200
void JSCell::getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
{
201
    RELEASE_ASSERT_NOT_REACHED();
202 203
}

204
bool JSCell::customHasInstance(JSObject*, ExecState*, JSValue)
205
{
206
    RELEASE_ASSERT_NOT_REACHED();
207 208 209
    return false;
}

210
void JSCell::putDirectVirtual(JSObject*, ExecState*, PropertyName, JSValue, unsigned)
211
{
212
    RELEASE_ASSERT_NOT_REACHED();
213 214
}

215
bool JSCell::defineOwnProperty(JSObject*, ExecState*, PropertyName, PropertyDescriptor&, bool)
216
{
217
    RELEASE_ASSERT_NOT_REACHED();
218 219 220
    return false;
}

221 222 223 224 225 226 227 228 229 230 231
void JSCell::slowDownAndWasteMemory(JSArrayBufferView*)
{
    RELEASE_ASSERT_NOT_REACHED();
}

PassRefPtr<ArrayBufferView> JSCell::getTypedArrayImpl(JSArrayBufferView*)
{
    RELEASE_ASSERT_NOT_REACHED();
    return 0;
}

232
} // namespace JSC