#ifndef Symbol_h
#define Symbol_h
#include "JSCell.h"
#include "JSString.h"
#include "PrivateName.h"
namespace JSC {
class Symbol final : public JSCell {
public:
typedef JSCell Base;
static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero | StructureIsImmortal;
DECLARE_EXPORT_INFO;
static const bool needsDestruction = true;
static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
return Structure::create(vm, globalObject, prototype, TypeInfo(SymbolType, StructureFlags), info());
}
static Symbol* create(VM& vm)
{
Symbol* symbol = new (NotNull, allocateCell<Symbol>(vm.heap)) Symbol(vm);
symbol->finishCreation(vm);
return symbol;
}
static Symbol* create(ExecState* exec, JSString* description)
{
VM& vm = exec->vm();
String desc = description->value(exec);
Symbol* symbol = new (NotNull, allocateCell<Symbol>(vm.heap)) Symbol(vm, desc);
symbol->finishCreation(vm);
return symbol;
}
static Symbol* create(VM& vm, SymbolImpl& uid)
{
Symbol* symbol = new (NotNull, allocateCell<Symbol>(vm.heap)) Symbol(vm, uid);
symbol->finishCreation(vm);
return symbol;
}
const PrivateName& privateName() const { return m_privateName; }
String descriptiveString() const;
JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const;
JSObject* toObject(ExecState*, JSGlobalObject*) const;
double toNumber(ExecState*) const;
protected:
static void destroy(JSCell*);
Symbol(VM&);
Symbol(VM&, const String&);
Symbol(VM&, SymbolImpl& uid);
void finishCreation(VM& vm)
{
Base::finishCreation(vm);
ASSERT(inherits(info()));
}
PrivateName m_privateName;
};
Symbol* asSymbol(JSValue);
inline Symbol* asSymbol(JSValue value)
{
ASSERT(value.asCell()->isSymbol());
return jsCast<Symbol*>(value.asCell());
}
}
#endif // Symbol_h