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 "JSFunction.h"
29
#include "NumberObject.h"
30
#include <wtf/MathExtras.h>
34
ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSCell);
36
void JSCell::destroy(JSCell* cell)
38
cell->JSCell::~JSCell();
41
void JSCell::copyBackingStore(JSCell*, CopyVisitor&)
45
bool JSCell::getString(ExecState* exec, String& stringValue) const
49
stringValue = static_cast<const JSString*>(this)->value(exec);
53
String JSCell::getString(ExecState* exec) const
55
return isString() ? static_cast<const JSString*>(this)->value(exec) : String();
58
JSObject* JSCell::getObject()
60
return isObject() ? asObject(this) : 0;
63
const JSObject* JSCell::getObject() const
65
return isObject() ? static_cast<const JSObject*>(this) : 0;
68
CallType JSCell::getCallData(JSCell*, CallData&)
73
ConstructType JSCell::getConstructData(JSCell*, ConstructData&)
75
return ConstructTypeNone;
78
bool JSCell::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName identifier, PropertySlot& slot)
80
// This is not a general purpose implementation of getOwnPropertySlot.
81
// It should only be called by JSValue::get.
82
// It calls getPropertySlot, not getOwnPropertySlot.
83
JSObject* object = cell->toObject(exec, exec->lexicalGlobalObject());
85
if (!object->getPropertySlot(exec, identifier, slot))
90
bool JSCell::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned identifier, PropertySlot& slot)
92
// This is not a general purpose implementation of getOwnPropertySlot.
93
// It should only be called by JSValue::get.
94
// It calls getPropertySlot, not getOwnPropertySlot.
95
JSObject* object = cell->toObject(exec, exec->lexicalGlobalObject());
97
if (!object->getPropertySlot(exec, identifier, slot))
102
void JSCell::put(JSCell* cell, ExecState* exec, PropertyName identifier, JSValue value, PutPropertySlot& slot)
104
if (cell->isString()) {
105
JSValue(cell).putToPrimitive(exec, identifier, value, slot);
108
JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
109
thisObject->methodTable()->put(thisObject, exec, identifier, value, slot);
112
void JSCell::putByIndex(JSCell* cell, ExecState* exec, unsigned identifier, JSValue value, bool shouldThrow)
114
if (cell->isString()) {
115
PutPropertySlot slot(shouldThrow);
116
JSValue(cell).putToPrimitive(exec, Identifier::from(exec, identifier), value, slot);
119
JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
120
thisObject->methodTable()->putByIndex(thisObject, exec, identifier, value, shouldThrow);
123
bool JSCell::deleteProperty(JSCell* cell, ExecState* exec, PropertyName identifier)
125
JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
126
return thisObject->methodTable()->deleteProperty(thisObject, exec, identifier);
129
bool JSCell::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned identifier)
131
JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
132
return thisObject->methodTable()->deletePropertyByIndex(thisObject, exec, identifier);
135
JSObject* JSCell::toThisObject(JSCell* cell, ExecState* exec)
137
return cell->toObject(exec, exec->lexicalGlobalObject());
140
JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
143
return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType);
144
return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType);
147
bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const
150
return static_cast<const JSString*>(this)->getPrimitiveNumber(exec, number, value);
151
return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value);
154
double JSCell::toNumber(ExecState* exec) const
157
return static_cast<const JSString*>(this)->toNumber(exec);
158
return static_cast<const JSObject*>(this)->toNumber(exec);
161
JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const
164
return static_cast<const JSString*>(this)->toObject(exec, globalObject);
166
return jsCast<JSObject*>(const_cast<JSCell*>(this));
169
void slowValidateCell(JSCell* cell)
171
ASSERT_GC_OBJECT_LOOKS_VALID(cell);
174
JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType)
176
ASSERT_NOT_REACHED();
177
return jsUndefined();
180
void JSCell::getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
182
ASSERT_NOT_REACHED();
185
void JSCell::getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
187
ASSERT_NOT_REACHED();
190
String JSCell::className(const JSObject*)
192
ASSERT_NOT_REACHED();
196
const char* JSCell::className()
198
return classInfo()->className;
201
void JSCell::getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
203
ASSERT_NOT_REACHED();
206
bool JSCell::customHasInstance(JSObject*, ExecState*, JSValue)
208
ASSERT_NOT_REACHED();
212
void JSCell::putDirectVirtual(JSObject*, ExecState*, PropertyName, JSValue, unsigned)
214
ASSERT_NOT_REACHED();
217
bool JSCell::defineOwnProperty(JSObject*, ExecState*, PropertyName, PropertyDescriptor&, bool)
219
ASSERT_NOT_REACHED();
223
bool JSCell::getOwnPropertyDescriptor(JSObject*, ExecState*, PropertyName, PropertyDescriptor&)
225
ASSERT_NOT_REACHED();