]>
Commit | Line | Data |
---|---|---|
9dae56ea | 1 | /* |
93a37866 | 2 | * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserved. |
9dae56ea A |
3 | * |
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. | |
8 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
19 | */ | |
20 | ||
21 | #include "config.h" | |
22 | #include "Identifier.h" | |
23 | ||
24 | #include "CallFrame.h" | |
14957cd0 | 25 | #include "JSObject.h" |
93a37866 | 26 | #include "JSScope.h" |
4e4e5a6f | 27 | #include "NumericStrings.h" |
81345200 | 28 | #include "JSCInlines.h" |
93a37866 A |
29 | #include <new> |
30 | #include <string.h> | |
9dae56ea A |
31 | #include <wtf/Assertions.h> |
32 | #include <wtf/FastMalloc.h> | |
33 | #include <wtf/HashSet.h> | |
93a37866 | 34 | #include <wtf/text/ASCIIFastPath.h> |
4e4e5a6f | 35 | #include <wtf/text/StringHash.h> |
9dae56ea | 36 | |
f9bf01c6 A |
37 | using WTF::ThreadSpecific; |
38 | ||
9dae56ea A |
39 | namespace JSC { |
40 | ||
ed1e77d3 | 41 | Ref<StringImpl> Identifier::add(VM* vm, const char* c) |
9dae56ea | 42 | { |
93a37866 A |
43 | ASSERT(c); |
44 | ASSERT(c[0]); | |
9dae56ea | 45 | if (!c[1]) |
81345200 | 46 | return *vm->smallStrings.singleCharacterStringRep(c[0]); |
9dae56ea | 47 | |
ed1e77d3 | 48 | return *AtomicStringImpl::add(c); |
9dae56ea A |
49 | } |
50 | ||
ed1e77d3 | 51 | Ref<StringImpl> Identifier::add(ExecState* exec, const char* c) |
9dae56ea | 52 | { |
93a37866 | 53 | return add(&exec->vm(), c); |
9dae56ea A |
54 | } |
55 | ||
ed1e77d3 | 56 | Ref<StringImpl> Identifier::add8(VM* vm, const UChar* s, int length) |
14957cd0 | 57 | { |
6fe7ccc8 A |
58 | if (length == 1) { |
59 | UChar c = s[0]; | |
60 | ASSERT(c <= 0xff); | |
61 | if (canUseSingleCharacterString(c)) | |
81345200 | 62 | return *vm->smallStrings.singleCharacterStringRep(c); |
6fe7ccc8 | 63 | } |
14957cd0 | 64 | if (!length) |
81345200 | 65 | return *StringImpl::empty(); |
14957cd0 | 66 | |
ed1e77d3 | 67 | return *AtomicStringImpl::add(s, length); |
9dae56ea A |
68 | } |
69 | ||
4e4e5a6f | 70 | Identifier Identifier::from(ExecState* exec, unsigned value) |
9dae56ea | 71 | { |
93a37866 | 72 | return Identifier(exec, exec->vm().numericStrings.add(value)); |
9dae56ea A |
73 | } |
74 | ||
4e4e5a6f | 75 | Identifier Identifier::from(ExecState* exec, int value) |
9dae56ea | 76 | { |
93a37866 | 77 | return Identifier(exec, exec->vm().numericStrings.add(value)); |
9dae56ea A |
78 | } |
79 | ||
4e4e5a6f | 80 | Identifier Identifier::from(ExecState* exec, double value) |
9dae56ea | 81 | { |
93a37866 | 82 | return Identifier(exec, exec->vm().numericStrings.add(value)); |
9dae56ea A |
83 | } |
84 | ||
93a37866 | 85 | Identifier Identifier::from(VM* vm, unsigned value) |
14957cd0 | 86 | { |
93a37866 | 87 | return Identifier(vm, vm->numericStrings.add(value)); |
14957cd0 A |
88 | } |
89 | ||
93a37866 | 90 | Identifier Identifier::from(VM* vm, int value) |
14957cd0 | 91 | { |
93a37866 | 92 | return Identifier(vm, vm->numericStrings.add(value)); |
14957cd0 A |
93 | } |
94 | ||
93a37866 | 95 | Identifier Identifier::from(VM* vm, double value) |
14957cd0 | 96 | { |
93a37866 | 97 | return Identifier(vm, vm->numericStrings.add(value)); |
14957cd0 A |
98 | } |
99 | ||
ed1e77d3 A |
100 | void Identifier::dump(PrintStream& out) const |
101 | { | |
102 | if (impl()) | |
103 | out.print(impl()); | |
104 | else | |
105 | out.print("<null identifier>"); | |
106 | } | |
107 | ||
4e4e5a6f | 108 | #ifndef NDEBUG |
9dae56ea | 109 | |
81345200 | 110 | void Identifier::checkCurrentAtomicStringTable(VM* vm) |
9dae56ea | 111 | { |
4e4e5a6f | 112 | // Check the identifier table accessible through the threadspecific matches the |
93a37866 | 113 | // vm's identifier table. |
81345200 | 114 | ASSERT_UNUSED(vm, vm->atomicStringTable() == wtfThreadData().atomicStringTable()); |
9dae56ea A |
115 | } |
116 | ||
81345200 | 117 | void Identifier::checkCurrentAtomicStringTable(ExecState* exec) |
f9bf01c6 | 118 | { |
81345200 | 119 | checkCurrentAtomicStringTable(&exec->vm()); |
f9bf01c6 A |
120 | } |
121 | ||
4e4e5a6f | 122 | #else |
f9bf01c6 | 123 | |
4e4e5a6f | 124 | // These only exists so that our exports are the same for debug and release builds. |
93a37866 | 125 | // This would be an RELEASE_ASSERT_NOT_REACHED(), but we're in NDEBUG only code here! |
81345200 A |
126 | NO_RETURN_DUE_TO_CRASH void Identifier::checkCurrentAtomicStringTable(VM*) { CRASH(); } |
127 | NO_RETURN_DUE_TO_CRASH void Identifier::checkCurrentAtomicStringTable(ExecState*) { CRASH(); } | |
f9bf01c6 A |
128 | |
129 | #endif | |
130 | ||
9dae56ea | 131 | } // namespace JSC |