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