]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/Identifier.cpp
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #include "Identifier.h"
24 #include "CallFrame.h"
27 #include "NumericStrings.h"
28 #include "JSCInlines.h"
31 #include <wtf/Assertions.h>
32 #include <wtf/FastMalloc.h>
33 #include <wtf/HashSet.h>
34 #include <wtf/text/ASCIIFastPath.h>
35 #include <wtf/text/StringHash.h>
37 using WTF::ThreadSpecific
;
41 Ref
<StringImpl
> Identifier::add(VM
* vm
, const char* c
)
46 return *vm
->smallStrings
.singleCharacterStringRep(c
[0]);
48 return *AtomicStringImpl::add(c
);
51 Ref
<StringImpl
> Identifier::add(ExecState
* exec
, const char* c
)
53 return add(&exec
->vm(), c
);
56 Ref
<StringImpl
> Identifier::add8(VM
* vm
, const UChar
* s
, int length
)
61 if (canUseSingleCharacterString(c
))
62 return *vm
->smallStrings
.singleCharacterStringRep(c
);
65 return *StringImpl::empty();
67 return *AtomicStringImpl::add(s
, length
);
70 Identifier
Identifier::from(ExecState
* exec
, unsigned value
)
72 return Identifier(exec
, exec
->vm().numericStrings
.add(value
));
75 Identifier
Identifier::from(ExecState
* exec
, int value
)
77 return Identifier(exec
, exec
->vm().numericStrings
.add(value
));
80 Identifier
Identifier::from(ExecState
* exec
, double value
)
82 return Identifier(exec
, exec
->vm().numericStrings
.add(value
));
85 Identifier
Identifier::from(VM
* vm
, unsigned value
)
87 return Identifier(vm
, vm
->numericStrings
.add(value
));
90 Identifier
Identifier::from(VM
* vm
, int value
)
92 return Identifier(vm
, vm
->numericStrings
.add(value
));
95 Identifier
Identifier::from(VM
* vm
, double value
)
97 return Identifier(vm
, vm
->numericStrings
.add(value
));
100 void Identifier::dump(PrintStream
& out
) const
105 out
.print("<null identifier>");
110 void Identifier::checkCurrentAtomicStringTable(VM
* vm
)
112 // Check the identifier table accessible through the threadspecific matches the
113 // vm's identifier table.
114 ASSERT_UNUSED(vm
, vm
->atomicStringTable() == wtfThreadData().atomicStringTable());
117 void Identifier::checkCurrentAtomicStringTable(ExecState
* exec
)
119 checkCurrentAtomicStringTable(&exec
->vm());
124 // These only exists so that our exports are the same for debug and release builds.
125 // This would be an RELEASE_ASSERT_NOT_REACHED(), but we're in NDEBUG only code here!
126 NO_RETURN_DUE_TO_CRASH
void Identifier::checkCurrentAtomicStringTable(VM
*) { CRASH(); }
127 NO_RETURN_DUE_TO_CRASH
void Identifier::checkCurrentAtomicStringTable(ExecState
*) { CRASH(); }