#include "JSFunction.h"
#include "JSString.h"
#include "JSObject.h"
+#include "NumberObject.h"
#include <wtf/MathExtras.h>
namespace JSC {
-#if defined NAN && defined INFINITY
-
-extern const double NaN = NAN;
-extern const double Inf = INFINITY;
-
-#else // !(defined NAN && defined INFINITY)
-
-// The trick is to define the NaN and Inf globals with a different type than the declaration.
-// This trick works because the mangled name of the globals does not include the type, although
-// I'm not sure that's guaranteed. There could be alignment issues with this, since arrays of
-// characters don't necessarily need the same alignment doubles do, but for now it seems to work.
-// It would be good to figure out a 100% clean way that still avoids code that runs at init time.
-
-// Note, we have to use union to ensure alignment. Otherwise, NaN_Bytes can start anywhere,
-// while NaN_double has to be 4-byte aligned for 32-bits.
-// With -fstrict-aliasing enabled, unions are the only safe way to do type masquerading.
-
-static const union {
- struct {
- unsigned char NaN_Bytes[8];
- unsigned char Inf_Bytes[8];
- } bytes;
-
- struct {
- double NaN_Double;
- double Inf_Double;
- } doubles;
-
-} NaNInf = { {
-#if CPU(BIG_ENDIAN)
- { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 },
- { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 }
-#elif CPU(MIDDLE_ENDIAN)
- { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 },
- { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 }
-#else
- { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f },
- { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f }
-#endif
-} } ;
-
-extern const double NaN = NaNInf.doubles.NaN_Double;
-extern const double Inf = NaNInf.doubles.Inf_Double;
-
-#endif // !(defined NAN && defined INFINITY)
-
-const ClassInfo JSCell::s_dummyCellInfo = { "DummyCell", 0, 0, 0 };
-
-bool JSCell::getUInt32(uint32_t&) const
+ASSERT_HAS_TRIVIAL_DESTRUCTOR(JSCell);
+
+void JSCell::destroy(JSCell* cell)
{
- return false;
+ cell->JSCell::~JSCell();
}
bool JSCell::getString(ExecState* exec, UString&stringValue) const
return isObject() ? static_cast<const JSObject*>(this) : 0;
}
-CallType JSCell::getCallData(CallData&)
+CallType JSCell::getCallData(JSCell*, CallData&)
{
return CallTypeNone;
}
-ConstructType JSCell::getConstructData(ConstructData&)
+ConstructType JSCell::getConstructData(JSCell*, ConstructData&)
{
return ConstructTypeNone;
}
-bool JSCell::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, PropertySlot& slot)
+bool JSCell::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& identifier, PropertySlot& slot)
{
// This is not a general purpose implementation of getOwnPropertySlot.
// It should only be called by JSValue::get.
// It calls getPropertySlot, not getOwnPropertySlot.
- JSObject* object = toObject(exec, exec->lexicalGlobalObject());
+ JSObject* object = cell->toObject(exec, exec->lexicalGlobalObject());
slot.setBase(object);
if (!object->getPropertySlot(exec, identifier, slot))
slot.setUndefined();
return true;
}
-bool JSCell::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySlot& slot)
+bool JSCell::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned identifier, PropertySlot& slot)
{
// This is not a general purpose implementation of getOwnPropertySlot.
// It should only be called by JSValue::get.
// It calls getPropertySlot, not getOwnPropertySlot.
- JSObject* object = toObject(exec, exec->lexicalGlobalObject());
+ JSObject* object = cell->toObject(exec, exec->lexicalGlobalObject());
slot.setBase(object);
if (!object->getPropertySlot(exec, identifier, slot))
slot.setUndefined();
return true;
}
-void JSCell::put(ExecState* exec, const Identifier& identifier, JSValue value, PutPropertySlot& slot)
+void JSCell::put(JSCell* cell, ExecState* exec, const Identifier& identifier, JSValue value, PutPropertySlot& slot)
{
- toObject(exec, exec->lexicalGlobalObject())->put(exec, identifier, value, slot);
+ if (cell->isString()) {
+ JSValue(cell).putToPrimitive(exec, identifier, value, slot);
+ return;
+ }
+ JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
+ thisObject->methodTable()->put(thisObject, exec, identifier, value, slot);
}
-void JSCell::put(ExecState* exec, unsigned identifier, JSValue value)
+void JSCell::putByIndex(JSCell* cell, ExecState* exec, unsigned identifier, JSValue value, bool shouldThrow)
{
- toObject(exec, exec->lexicalGlobalObject())->put(exec, identifier, value);
+ if (cell->isString()) {
+ PutPropertySlot slot(shouldThrow);
+ JSValue(cell).putToPrimitive(exec, Identifier::from(exec, identifier), value, slot);
+ return;
+ }
+ JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
+ thisObject->methodTable()->putByIndex(thisObject, exec, identifier, value, shouldThrow);
}
-bool JSCell::deleteProperty(ExecState* exec, const Identifier& identifier)
+bool JSCell::deleteProperty(JSCell* cell, ExecState* exec, const Identifier& identifier)
{
- return toObject(exec, exec->lexicalGlobalObject())->deleteProperty(exec, identifier);
+ JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
+ return thisObject->methodTable()->deleteProperty(thisObject, exec, identifier);
}
-bool JSCell::deleteProperty(ExecState* exec, unsigned identifier)
+bool JSCell::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned identifier)
{
- return toObject(exec, exec->lexicalGlobalObject())->deleteProperty(exec, identifier);
+ JSObject* thisObject = cell->toObject(exec, exec->lexicalGlobalObject());
+ return thisObject->methodTable()->deletePropertyByIndex(thisObject, exec, identifier);
}
-JSObject* JSCell::toThisObject(ExecState* exec) const
+JSObject* JSCell::toThisObject(JSCell* cell, ExecState* exec)
{
- return toObject(exec, exec->lexicalGlobalObject());
+ return cell->toObject(exec, exec->lexicalGlobalObject());
}
-JSValue JSCell::getJSNumber()
+JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
{
- return JSValue();
+ if (isString())
+ return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType);
+ return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType);
}
-bool JSCell::isGetterSetter() const
+bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const
{
- return false;
+ if (isString())
+ return static_cast<const JSString*>(this)->getPrimitiveNumber(exec, number, value);
+ return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value);
+}
+
+double JSCell::toNumber(ExecState* exec) const
+{
+ if (isString())
+ return static_cast<const JSString*>(this)->toNumber(exec);
+ return static_cast<const JSObject*>(this)->toNumber(exec);
+}
+
+JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const
+{
+ if (isString())
+ return static_cast<const JSString*>(this)->toObject(exec, globalObject);
+ ASSERT(isObject());
+ return jsCast<JSObject*>(const_cast<JSCell*>(this));
}
-JSValue JSCell::toPrimitive(ExecState*, PreferredPrimitiveType) const
+void slowValidateCell(JSCell* cell)
+{
+ ASSERT_GC_OBJECT_LOOKS_VALID(cell);
+}
+
+JSValue JSCell::defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType)
{
ASSERT_NOT_REACHED();
- return JSValue();
+ return jsUndefined();
}
-bool JSCell::getPrimitiveNumber(ExecState*, double&, JSValue&)
+void JSCell::getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
{
ASSERT_NOT_REACHED();
- return false;
}
-bool JSCell::toBoolean(ExecState*) const
+UString JSCell::className(const JSObject*)
{
ASSERT_NOT_REACHED();
- return false;
+ return UString();
}
-double JSCell::toNumber(ExecState*) const
+void JSCell::getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode)
{
ASSERT_NOT_REACHED();
- return 0;
}
-UString JSCell::toString(ExecState*) const
+bool JSCell::hasInstance(JSObject*, ExecState*, JSValue, JSValue)
{
ASSERT_NOT_REACHED();
- return UString();
+ return false;
}
-JSObject* JSCell::toObject(ExecState*, JSGlobalObject*) const
+void JSCell::putDirectVirtual(JSObject*, ExecState*, const Identifier&, JSValue, unsigned)
{
ASSERT_NOT_REACHED();
- return 0;
}
-bool isZombie(const JSCell* cell)
+bool JSCell::defineOwnProperty(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&, bool)
{
-#if ENABLE(JSC_ZOMBIES)
- return cell && cell->isZombie();
-#else
- UNUSED_PARAM(cell);
+ ASSERT_NOT_REACHED();
return false;
-#endif
}
-void slowValidateCell(JSCell* cell)
+bool JSCell::getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&)
{
- ASSERT_GC_OBJECT_LOOKS_VALID(cell);
+ ASSERT_NOT_REACHED();
+ return false;
}
} // namespace JSC