#include "config.h"
#include "Identifier.h"
#include "CallFrame.h"
#include "JSObject.h"
#include "JSScope.h"
#include "NumericStrings.h"
#include "JSCInlines.h"
#include <new>
#include <string.h>
#include <wtf/Assertions.h>
#include <wtf/FastMalloc.h>
#include <wtf/HashSet.h>
#include <wtf/text/ASCIIFastPath.h>
#include <wtf/text/StringHash.h>
using WTF::ThreadSpecific;
namespace JSC {
Ref<StringImpl> Identifier::add(VM* vm, const char* c)
{
ASSERT(c);
ASSERT(c[0]);
if (!c[1])
return *vm->smallStrings.singleCharacterStringRep(c[0]);
return *AtomicStringImpl::add(c);
}
Ref<StringImpl> Identifier::add(ExecState* exec, const char* c)
{
return add(&exec->vm(), c);
}
Ref<StringImpl> Identifier::add8(VM* vm, const UChar* s, int length)
{
if (length == 1) {
UChar c = s[0];
ASSERT(c <= 0xff);
if (canUseSingleCharacterString(c))
return *vm->smallStrings.singleCharacterStringRep(c);
}
if (!length)
return *StringImpl::empty();
return *AtomicStringImpl::add(s, length);
}
Identifier Identifier::from(ExecState* exec, unsigned value)
{
return Identifier(exec, exec->vm().numericStrings.add(value));
}
Identifier Identifier::from(ExecState* exec, int value)
{
return Identifier(exec, exec->vm().numericStrings.add(value));
}
Identifier Identifier::from(ExecState* exec, double value)
{
return Identifier(exec, exec->vm().numericStrings.add(value));
}
Identifier Identifier::from(VM* vm, unsigned value)
{
return Identifier(vm, vm->numericStrings.add(value));
}
Identifier Identifier::from(VM* vm, int value)
{
return Identifier(vm, vm->numericStrings.add(value));
}
Identifier Identifier::from(VM* vm, double value)
{
return Identifier(vm, vm->numericStrings.add(value));
}
void Identifier::dump(PrintStream& out) const
{
if (impl())
out.print(impl());
else
out.print("<null identifier>");
}
#ifndef NDEBUG
void Identifier::checkCurrentAtomicStringTable(VM* vm)
{
ASSERT_UNUSED(vm, vm->atomicStringTable() == wtfThreadData().atomicStringTable());
}
void Identifier::checkCurrentAtomicStringTable(ExecState* exec)
{
checkCurrentAtomicStringTable(&exec->vm());
}
#else
NO_RETURN_DUE_TO_CRASH void Identifier::checkCurrentAtomicStringTable(VM*) { CRASH(); }
NO_RETURN_DUE_TO_CRASH void Identifier::checkCurrentAtomicStringTable(ExecState*) { CRASH(); }
#endif
}