Debian Codegraph @

src/3rdparty/javascriptcore/JavaScriptCore/runtime/Identifier.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 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"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/config.h`/
22 #include "Identifier.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Identifier.h`/
23
24 #include "CallFrame.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/CallFrame.h`/
25 #include <new> // for placement new
26 #include <string.h> // for strlen
27 #include <wtf/Assertions.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h`/
28 #include <wtf/FastMalloc.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/FastMalloc.h`/
29 #include <wtf/HashSet.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/HashSet.h`/
30
31 using WTFcxx . . $ `<built-in>:467:9`!::ThreadSpecificcxx . . $ ThreadSpecific#;
32
33 namespace JSCcxx . . $ `<built-in>:463:9`! {
34
35 typedef HashMap<const char*, RefPtr<UString::Rep>, PtrHash<const char*> > LiteralIdentifierTablecxx . . $ QTJSC/LiteralIdentifierTable#;
36
37 class IdentifierTablecxx . . $ QTJSC/IdentifierTable# : public FastAllocBasecxx . . $ FastAllocBase# {
38 public:
39 ~cxx . . $ QTJSC/IdentifierTable#`~IdentifierTable`(49f6e7a06ebc5aa8).IdentifierTablecxx . . $ QTJSC/IdentifierTable#()
40 {
41 HashSet<UString::Rep*>::iterator end = m_table.end();
42 for (HashSet<UString::Rep*>::iterator iter = m_table.begin(); iter !=cxx . . $ QTJSC/`operator!=`(8208a731c2dadbc2). end; ++iter)
43 (*iter)->setIsIdentifier(false);
44 }
45
46 std::pair<HashSet<UString::Rep*>::iterator, bool> addcxx . . $ QTJSC/IdentifierTable#add(9cdb91496e3f53cb).(UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#* value)
47 {
48 std::pair<HashSet<UString::Rep*>::iterator, bool> result = m_table.add(value);
49 (*result.first)->setIsIdentifier(true);
50 return result;
51 }
52
53 template<typename U, typename V>
54 std::pair<HashSet<UString::Rep*>::iterator, bool> addcxx . . $ QTJSC/IdentifierTable#add(f4542d83968c5b4e).(U value)
55 {
56 std::pair<HashSet<UString::Rep*>::iterator, bool> result = m_table.add<U, V>(value);
57 (*result.first)->setIsIdentifier(true);
58 return result;
59 }
60
61 void removecxx . . $ QTJSC/IdentifierTable#remove(f38096febece923b).(UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#* r) { m_table.remove(r); }
62
63 LiteralIdentifierTablecxx . . $ QTJSC/LiteralIdentifierTable#& literalTablecxx . . $ QTJSC/IdentifierTable#literalTable(ffa05e89dbf2c50f).() { return m_literalTablecxx . . $ QTJSC/IdentifierTable#m_literalTable.; }
64
65 private:
66 HashSet<UString::Rep*> m_tablecxx . . $ QTJSC/IdentifierTable#m_table.;
67 LiteralIdentifierTablecxx . . $ QTJSC/LiteralIdentifierTable# m_literalTablecxx . . $ QTJSC/IdentifierTable#m_literalTable.;
68 };
69
70 IdentifierTablecxx . . $ QTJSC/IdentifierTable#* createIdentifierTablecxx . . $ QTJSC/createIdentifierTable(a321ca86ef1b282a).()
71 {
72 return new IdentifierTablecxx . . $ QTJSC/IdentifierTable#;
73 }
74
75 void deleteIdentifierTablecxx . . $ QTJSC/deleteIdentifierTable(1628e5553183b104).(IdentifierTablecxx . . $ QTJSC/IdentifierTable#* table)
76 {
77 delete table;
78 }
79
80 bool Identifiercxx . . $ QTJSC/Identifier#::equalcxx . . $ QTJSC/Identifier#equal(a0fb99199941000e).(const UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#* r, const char* s)
81 {
82 int length = r->sizecxx . . $ QTJSC/UStringImpl#size(455f465bc33b4cdf).();
83 const UCharcxx . . $ UChar#* d = r->datacxx . . $ QTJSC/UStringImpl#data(da28cdd8371e77b7).();
84 for (int i = 0; i != length; ++i)
85 if (d[i] != (unsigned char)s[i])
86 return false;
87 return s[length] == 0;
88 }
89
90 bool Identifiercxx . . $ QTJSC/Identifier#::equalcxx . . $ QTJSC/Identifier#equal(47268a0913697c1).(const UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#* r, const UCharcxx . . $ UChar#* s, int length)
91 {
92 if (r->sizecxx . . $ QTJSC/UStringImpl#size(455f465bc33b4cdf).() != length)
93 return false;
94 const UCharcxx . . $ UChar#* d = r->datacxx . . $ QTJSC/UStringImpl#data(da28cdd8371e77b7).();
95 for (int i = 0; i != length; ++i)
96 if (d[i] != s[i])
97 return false;
98 return true;
99 }
100
101 struct CStringTranslatorcxx . . $ QTJSC/CStringTranslator# {
102 static unsigned hashcxx . . $ QTJSC/CStringTranslator#hash(c61c63047ce273de).(const char* c)
103 {
104 return UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#::computeHashcxx . . $ QTJSC/UStringImpl#computeHash(c61c63047ce273de).(c);
105 }
106
107 static bool equalcxx . . $ QTJSC/CStringTranslator#equal(167455d4c4fe8830).(UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#* r, const char* s)
108 {
109 return Identifiercxx . . $ QTJSC/Identifier#::equalcxx . . $ QTJSC/Identifier#equal(a0fb99199941000e).(r, s);
110 }
111
112 static void translatecxx . . $ QTJSC/CStringTranslator#translate(e72e10e17fe8d846).(UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#*& location, const char* c, unsigned hash)
113 {
114 size_t length = strlen(c);
115 UCharcxx . . $ UChar#* d;
116 UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#* r = UString::Rep::createUninitialized(length, d).releaseRef();
117 for (size_t i = 0; i != length; i++)
118 d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
119 r->setHashcxx . . $ QTJSC/UStringImpl#setHash(cb2f890c2fdad230).(hash);
120 location = r;
121 }
122 };
123
124 PassRefPtrcxx . . $ PassRefPtr#<UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#> Identifiercxx . . $ QTJSC/Identifier#::addcxx . . $ QTJSC/Identifier#add(569ed62d0938c2fa).(JSGlobalDatacxx . . $ QTJSC/JSGlobalData#* globalData, const char* c)
125 {
126 if (!c) {
127 UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#::nullcxx . . $ QTJSC/UStringImpl#null(fdf30dd1b4d8233c).().hashcxx . . $ QTJSC/UStringImpl#hash(ddd8539a2fcdd4ce).();
128 return &UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#::nullcxx . . $ QTJSC/UStringImpl#null(fdf30dd1b4d8233c).();
129 }
130 if (!c[0]) {
131 UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#::emptycxx . . $ QTJSC/UStringImpl#empty(fdf30dd1b4d8233c).().hashcxx . . $ QTJSC/UStringImpl#hash(ddd8539a2fcdd4ce).();
132 return &UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#::emptycxx . . $ QTJSC/UStringImpl#empty(fdf30dd1b4d8233c).();
133 }
134 if (!c[1])
135 return addcxx . . $ QTJSC/Identifier#add(b2bc4d53e7e7851c).(globalData, globalData->smallStrings.singleCharacterStringRep(static_cast<unsigned char>(c[0])));
136
137 IdentifierTablecxx . . $ QTJSC/IdentifierTable#& identifierTable = *globalData->identifierTablecxx . . $ QTJSC/JSGlobalData#identifierTable.;
138 LiteralIdentifierTablecxx . . $ QTJSC/LiteralIdentifierTable#& literalIdentifierTable = identifierTable.literalTablecxx . . $ QTJSC/IdentifierTable#literalTable(ffa05e89dbf2c50f).();
139
140 const LiteralIdentifierTable::iterator& iter = literalIdentifierTable.find(c);
141 if (iter !=cxx . . $ QTJSC/`operator!=`(8208a731c2dadbc2). literalIdentifierTable.end())
142 return iter->second;
143
144 pair<HashSet<UString::Rep*>::iterator, bool> addResult = identifierTable.addcxx . . $ QTJSC/IdentifierTable#add(9cdb91496e3f53cb).<const char*, CStringTranslatorcxx . . $ QTJSC/CStringTranslator#>(c);
145
146 // If the string is newly-translated, then we need to adopt it.
147 // The boolean in the pair tells us if that is so.
148 RefPtrcxx . . $ RefPtr#<UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#> addedString = addResult.second ? adoptRef(*addResult.first) : *addResult.first;
149
150 literalIdentifierTable.add(c, addedString.get());
151
152 return addedString.release();
153 }
154
155 PassRefPtrcxx . . $ PassRefPtr#<UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#> Identifiercxx . . $ QTJSC/Identifier#::addcxx . . $ QTJSC/Identifier#add(b2bc4d53e7e7851c).(ExecStatecxx . . $ QTJSC/ExecState#* exec, const char* c)
156 {
157 return addcxx . . $ QTJSC/Identifier#add(b2bc4d53e7e7851c).(&exec->globalDatacxx . . $ QTJSC/ExecState#globalData(ae00a65ac2fd4a61).(), c);
158 }
159
160 struct UCharBuffercxx . . $ QTJSC/UCharBuffer# {
161 const UCharcxx . . $ UChar#* scxx . . $ QTJSC/UCharBuffer#s.;
162 unsigned int lengthcxx . . $ QTJSC/UCharBuffer#length.;
163 };
164
165 struct UCharBufferTranslatorcxx . . $ QTJSC/UCharBufferTranslator# {
166 static unsigned hashcxx . . $ QTJSC/UCharBufferTranslator#hash(cee33e41dce3006c).(const UCharBuffercxx . . $ QTJSC/UCharBuffer#& buf)
167 {
168 return UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#::computeHashcxx . . $ QTJSC/UStringImpl#computeHash(73f81729e39ab85f).(buf.scxx . . $ QTJSC/UCharBuffer#s., buf.lengthcxx . . $ QTJSC/UCharBuffer#length.);
169 }
170
171 static bool equalcxx . . $ QTJSC/UCharBufferTranslator#equal(b47f03a71a2e4739).(UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#* str, const UCharBuffercxx . . $ QTJSC/UCharBuffer#& buf)
172 {
173 return Identifiercxx . . $ QTJSC/Identifier#::equalcxx . . $ QTJSC/Identifier#equal(47268a0913697c1).(str, buf.scxx . . $ QTJSC/UCharBuffer#s., buf.lengthcxx . . $ QTJSC/UCharBuffer#length.);
174 }
175
176 static void translatecxx . . $ QTJSC/UCharBufferTranslator#translate(dd34b0ff5eb3b322).(UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#*& location, const UCharBuffercxx . . $ QTJSC/UCharBuffer#& buf, unsigned hash)
177 {
178 UCharcxx . . $ UChar#* d;
179 UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#* r = UString::Rep::createUninitialized(buf.lengthcxx . . $ QTJSC/UCharBuffer#length., d).releaseRef();
180 for (unsigned i = 0; i != buf.lengthcxx . . $ QTJSC/UCharBuffer#length.; i++)
181 d[i] = buf.scxx . . $ QTJSC/UCharBuffer#s.[i];
182 r->setHashcxx . . $ QTJSC/UStringImpl#setHash(cb2f890c2fdad230).(hash);
183 location = r;
184 }
185 };
186
187 PassRefPtrcxx . . $ PassRefPtr#<UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#> Identifiercxx . . $ QTJSC/Identifier#::addcxx . . $ QTJSC/Identifier#add(4da60fb78fcb64be).(JSGlobalDatacxx . . $ QTJSC/JSGlobalData#* globalData, const UCharcxx . . $ UChar#* s, int length)
188 {
189 if (length == 1) {
190 UCharcxx . . $ UChar# c = s[0];
191 if (c <= 0xFF)
192 return addcxx . . $ QTJSC/Identifier#add(b2bc4d53e7e7851c).(globalData, globalData->smallStrings.singleCharacterStringRep(c));
193 }
194 if (!length) {
195 UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#::emptycxx . . $ QTJSC/UStringImpl#empty(fdf30dd1b4d8233c).().hashcxx . . $ QTJSC/UStringImpl#hash(ddd8539a2fcdd4ce).();
196 return &UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#::emptycxx . . $ QTJSC/UStringImpl#empty(fdf30dd1b4d8233c).();
197 }
198 UCharBuffercxx . . $ QTJSC/UCharBuffer# buf = {s, static_cast<unsigned>(length)};
199 pair<HashSet<UString::Rep*>::iterator, bool> addResult = globalData->identifierTablecxx . . $ QTJSC/JSGlobalData#identifierTable.->addcxx . . $ QTJSC/IdentifierTable#add(9cdb91496e3f53cb).<UCharBuffercxx . . $ QTJSC/UCharBuffer#, UCharBufferTranslatorcxx . . $ QTJSC/UCharBufferTranslator#>(buf);
200
201 // If the string is newly-translated, then we need to adopt it.
202 // The boolean in the pair tells us if that is so.
203 return addResult.second ? adoptRefcxx . . $ adoptRef(e761da608bb8c29c).(*addResult.first) : *addResult.first;
204 }
205
206 PassRefPtrcxx . . $ PassRefPtr#<UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#> Identifiercxx . . $ QTJSC/Identifier#::addcxx . . $ QTJSC/Identifier#add(46b6130ee8ef472f).(ExecStatecxx . . $ QTJSC/ExecState#* exec, const UCharcxx . . $ UChar#* s, int length)
207 {
208 return addcxx . . $ QTJSC/Identifier#add(b2bc4d53e7e7851c).(&exec->globalDatacxx . . $ QTJSC/ExecState#globalData(ae00a65ac2fd4a61).(), s, length);
209 }
210
211 PassRefPtrcxx . . $ PassRefPtr#<UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#> Identifiercxx . . $ QTJSC/Identifier#::addSlowCasecxx . . $ QTJSC/Identifier#addSlowCase(af61cc6867b6ecd1).(JSGlobalDatacxx . . $ QTJSC/JSGlobalData#* globalData, UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#* r)
212 {
213 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!r->isIdentifier());
214 if (r->sizecxx . . $ QTJSC/UStringImpl#size(455f465bc33b4cdf).() == 1) {
215 UCharcxx . . $ UChar# c = r->datacxx . . $ QTJSC/UStringImpl#data(da28cdd8371e77b7).()[0];
216 if (c <= 0xFF)
217 r = globalData->smallStrings.singleCharacterStringRep(c);
218 if (r->isIdentifiercxx . . $ QTJSC/UStringImpl#isIdentifier(50ce9a9e25b4a850).()) {
219 #ifndef NDEBUGcxx . . $ `<built-in>:472:9`!
220 checkSameIdentifierTable(globalData, r);
221 #endif
222 return r;
223 }
224 }
225 if (!r->sizecxx . . $ QTJSC/UStringImpl#size(455f465bc33b4cdf).()) {
226 UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#::emptycxx . . $ QTJSC/UStringImpl#empty(fdf30dd1b4d8233c).().hashcxx . . $ QTJSC/UStringImpl#hash(ddd8539a2fcdd4ce).();
227 return &UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#::emptycxx . . $ QTJSC/UStringImpl#empty(fdf30dd1b4d8233c).();
228 }
229 return *globalData->identifierTablecxx . . $ QTJSC/JSGlobalData#identifierTable.->addcxx . . $ QTJSC/IdentifierTable#add(9cdb91496e3f53cb).(r).first;
230 }
231
232 PassRefPtrcxx . . $ PassRefPtr#<UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#> Identifiercxx . . $ QTJSC/Identifier#::addSlowCasecxx . . $ QTJSC/Identifier#addSlowCase(cb5ebea9f6e2dec7).(ExecStatecxx . . $ QTJSC/ExecState#* exec, UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#* r)
233 {
234 return addSlowCasecxx . . $ QTJSC/Identifier#addSlowCase(cb5ebea9f6e2dec7).(&exec->globalDatacxx . . $ QTJSC/ExecState#globalData(ae00a65ac2fd4a61).(), r);
235 }
236
237 void Identifiercxx . . $ QTJSC/Identifier#::removecxx . . $ QTJSC/Identifier#remove(f38096febece923b).(UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#* r)
238 {
239 currentIdentifierTablecxx . . $ QTJSC/currentIdentifierTable(a321ca86ef1b282a).()->removecxx . . $ QTJSC/IdentifierTable#remove(f38096febece923b).(r);
240 }
241
242 #ifndef NDEBUGcxx . . $ `<built-in>:472:9`!
243
244 void Identifier::checkSameIdentifierTable(ExecState* exec, UString::Rep*)
245 {
246 ASSERT_UNUSED(exec, exec->globalData().identifierTable == currentIdentifierTable());
247 }
248
249 void Identifier::checkSameIdentifierTable(JSGlobalData* globalData, UString::Rep*)
250 {
251 ASSERT_UNUSED(globalData, globalData->identifierTable == currentIdentifierTable());
252 }
253
254 #else
255
256 void Identifiercxx . . $ QTJSC/Identifier#::checkSameIdentifierTablecxx . . $ QTJSC/Identifier#checkSameIdentifierTable(a8e0b2d7f9c69786).(ExecStatecxx . . $ QTJSC/ExecState#*, UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#*)
257 {
258 }
259
260 void Identifiercxx . . $ QTJSC/Identifier#::checkSameIdentifierTablecxx . . $ QTJSC/Identifier#checkSameIdentifierTable(a32b800d6344c8e3).(JSGlobalDatacxx . . $ QTJSC/JSGlobalData#*, UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#*)
261 {
262 }
263
264 #endif
265
266 ThreadSpecificcxx . . $ ThreadSpecific#<ThreadIdentifierTableDatacxx . . $ QTJSC/ThreadIdentifierTableData#>* g_identifierTableSpecificcxx . . $ QTJSC/g_identifierTableSpecific. = 0;
267
268 #if ENABLEcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:57:9`!(JSC_MULTIPLE_THREADS)
269
270 pthread_once_t createIdentifierTableSpecificOnce = PTHREAD_ONCE_INIT;
271 static void createIdentifierTableSpecificCallback()
272 {
273 ASSERT(!g_identifierTableSpecific);
274 g_identifierTableSpecific = new ThreadSpecific<ThreadIdentifierTableData>();
275 }
276 void createIdentifierTableSpecific()
277 {
278 pthread_once(&createIdentifierTableSpecificOnce, createIdentifierTableSpecificCallback);
279 ASSERT(g_identifierTableSpecific);
280 }
281
282 #else
283
284 void createIdentifierTableSpecificcxx . . $ QTJSC/createIdentifierTableSpecific(49f6e7a06ebc5aa8).()
285 {
286 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!g_identifierTableSpecific);
287 g_identifierTableSpecific = new ThreadSpecific<ThreadIdentifierTableData>();
288 }
289
290 #endif
291
292 } // namespace JSC