Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright (C) 1999-2002 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2004, 2007, 2008 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "config.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/config.h`/
24 #include "JSString.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSString.h`/
25
26 #include "JSGlobalObject.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSGlobalObject.h`/
27 #include "JSObject.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSObject.h`/
28 #include "Operations.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Operations.h`/
29 #include "StringObject.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/StringObject.h`/
30 #include "StringPrototype.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/StringPrototype.h`/
31
32 namespace JSCcxx . . $ `<built-in>:463:9`! {
33
34 void JSStringcxx . . $ QTJSC/JSString#::Ropecxx . . $ QTJSC/JSString#Rope#::destructNonRecursivecxx . . $ QTJSC/JSString#Rope#destructNonRecursive(49f6e7a06ebc5aa8).()
35 {
36 Vectorcxx . . $ Vector#<Ropecxx . . $ QTJSC/JSString#Rope#*, 32> workQueue;
37 Ropecxx . . $ QTJSC/JSString#Rope#* rope = this;
38
39 while (true) {
40 unsigned length = rope->ropeLengthcxx . . $ QTJSC/JSString#Rope#ropeLength(db52760e79bf9054).();
41 for (unsigned i = 0; i < length; ++i) {
42 Fibercxx . . $ QTJSC/JSString#Rope#Fiber#& fiber = rope->fiberscxx . . $ QTJSC/JSString#Rope#fibers(7e1a90947211103c).(i);
43 if (fiber.isStringcxx . . $ QTJSC/JSString#Rope#Fiber#isString(c9857a73d68e59ba).())
44 fiber.stringcxx . . $ QTJSC/JSString#Rope#Fiber#string(b56a90d0afa3b8ee).()->derefcxx . . $ QTJSC/UStringImpl#deref(49f6e7a06ebc5aa8).();
45 else {
46 Ropecxx . . $ QTJSC/JSString#Rope#* nextRope = fiber.ropecxx . . $ QTJSC/JSString#Rope#Fiber#rope(df5b0e1d7fcc6802).();
47 if (nextRope->hasOneRef())
48 workQueue.append(nextRope);
49 else
50 nextRope->deref();
51 }
52 }
53 if (rope != this)
54 fastFreecxx . . $ fastFree(5d22bdacc48458e8).(rope);
55
56 if (workQueue.isEmpty())
57 return;
58
59 rope = workQueue.last();
60 workQueue.removeLast();
61 }
62 }
63
64 JSStringcxx . . $ QTJSC/JSString#::Ropecxx . . $ QTJSC/JSString#Rope#::~cxx . . $ QTJSC/JSString#Rope#`~Rope`(49f6e7a06ebc5aa8).Ropecxx . . $ QTJSC/JSString#Rope#()
65 {
66 destructNonRecursivecxx . . $ QTJSC/JSString#Rope#destructNonRecursive(49f6e7a06ebc5aa8).();
67 }
68
69 // Overview: this methods converts a JSString from holding a string in rope form
70 // down to a simple UString representation. It does so by building up the string
71 // backwards, since we want to avoid recursion, we expect that the tree structure
72 // representing the rope is likely imbalanced with more nodes down the left side
73 // (since appending to the string is likely more common) - and as such resolving
74 // in this fashion should minimize work queue size. (If we built the queue forwards
75 // we would likely have to place all of the constituent UString::Reps into the
76 // Vector before performing any concatenation, but by working backwards we likely
77 // only fill the queue with the number of substrings at any given level in a
78 // rope-of-ropes.)
79 void JSStringcxx . . $ QTJSC/JSString#::resolveRopecxx . . $ QTJSC/JSString#resolveRope(31a096c468e6ff8e).(ExecStatecxx . . $ QTJSC/ExecState#* exec) const
80 {
81 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(isRope());
82
83 // Allocate the buffer to hold the final string, position initially points to the end.
84 UCharcxx . . $ UChar#* buffer;
85 if (PassRefPtr<UStringImpl> newImpl = UStringImpl::tryCreateUninitialized(m_stringLength, buffer))
86 m_value = newImpl;
87 else {
88 for (unsigned i = 0; i < m_ropeLengthcxx . . $ QTJSC/JSString#m_ropeLength.; ++i) {
89 m_fiberscxx . . $ QTJSC/JSString#m_fibers.[i].derefcxx . . $ QTJSC/JSString#Rope#Fiber#deref(49f6e7a06ebc5aa8).();
90 m_fiberscxx . . $ QTJSC/JSString#m_fibers.[i] =cxx . . $ QTJSC/JSString#Rope#Fiber#`operator=`(fc541412aae2cab1). static_castcxx . . $ QTJSC/JSString#Rope#Fiber#Fiber(5d22bdacc48458e8).<void*>(0);
91 }
92 m_ropeLengthcxx . . $ QTJSC/JSString#m_ropeLength. = 0;
93 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!isRope());
94 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(m_value == UString());
95 throwOutOfMemoryErrorcxx . . $ QTJSC/throwOutOfMemoryError(3fbe51058e39576a).(exec);
96 return;
97 }
98 UCharcxx . . $ UChar#* position = buffer + m_stringLengthcxx . . $ QTJSC/JSString#m_stringLength.;
99
100 // Start with the current Rope.
101 Vectorcxx . . $ Vector#<Ropecxx . . $ QTJSC/JSString#Rope#::Fibercxx . . $ QTJSC/JSString#Rope#Fiber#, 32> workQueue;
102 Ropecxx . . $ QTJSC/JSString#Rope#::Fibercxx . . $ QTJSC/JSString#Rope#Fiber# currentFibercxx . . $ QTJSC/JSString#Rope#Fiber#Fiber(49f6e7a06ebc5aa8).;
103 for (unsigned i = 0; i < (m_ropeLengthcxx . . $ QTJSC/JSString#m_ropeLength. - 1); ++i)
104 workQueue.append(m_fiberscxx . . $ QTJSC/JSString#m_fibers.[i]);
105 currentFiber =cxx . . $ QTJSC/JSString#Rope#Fiber#`operator=`(53f9878e948ca4ab). m_fiberscxx . . $ QTJSC/JSString#m_fibers.[m_ropeLengthcxx . . $ QTJSC/JSString#m_ropeLength. - 1];
106 while (true) {
107 if (currentFiber.isRopecxx . . $ QTJSC/JSString#Rope#Fiber#isRope(c9857a73d68e59ba).()) {
108 Ropecxx . . $ QTJSC/JSString#Rope#* rope = currentFiber.ropecxx . . $ QTJSC/JSString#Rope#Fiber#rope(df5b0e1d7fcc6802).();
109 // Copy the contents of the current rope into the workQueue, with the last item in 'currentFiber'
110 // (we will be working backwards over the rope).
111 unsigned ropeLengthMinusOne = rope->ropeLengthcxx . . $ QTJSC/JSString#Rope#ropeLength(db52760e79bf9054).() - 1;
112 for (unsigned i = 0; i < ropeLengthMinusOne; ++i)
113 workQueue.append(rope->fiberscxx . . $ QTJSC/JSString#Rope#fibers(7e1a90947211103c).(i));
114 currentFiber =cxx . . $ QTJSC/JSString#Rope#Fiber#`operator=`(53f9878e948ca4ab). rope->fiberscxx . . $ QTJSC/JSString#Rope#fibers(7e1a90947211103c).(ropeLengthMinusOne);
115 } else {
116 UStringcxx . . $ QTJSC/UString#::Repcxx . . $ QTJSC/UString#Rep#* string = currentFiber.stringcxx . . $ QTJSC/JSString#Rope#Fiber#string(b56a90d0afa3b8ee).();
117 unsigned length = string->sizecxx . . $ QTJSC/UStringImpl#size(455f465bc33b4cdf).();
118 position -= length;
119 UStringImplcxx . . $ QTJSC/UStringImpl#::copyCharscxx . . $ QTJSC/UStringImpl#copyChars(a032ecf025a4823a).(position, string->datacxx . . $ QTJSC/UStringImpl#data(da28cdd8371e77b7).(), length);
120
121 // Was this the last item in the work queue?
122 if (workQueue.isEmpty()) {
123 // Create a string from the UChar buffer, clear the rope RefPtr.
124 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(buffer == position);
125 for (unsigned i = 0; i < m_ropeLengthcxx . . $ QTJSC/JSString#m_ropeLength.; ++i) {
126 m_fiberscxx . . $ QTJSC/JSString#m_fibers.[i].derefcxx . . $ QTJSC/JSString#Rope#Fiber#deref(49f6e7a06ebc5aa8).();
127 m_fiberscxx . . $ QTJSC/JSString#m_fibers.[i] =cxx . . $ QTJSC/JSString#Rope#Fiber#`operator=`(fc541412aae2cab1). static_castcxx . . $ QTJSC/JSString#Rope#Fiber#Fiber(5d22bdacc48458e8).<void*>(0);
128 }
129 m_ropeLengthcxx . . $ QTJSC/JSString#m_ropeLength. = 0;
130
131 ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!isRope());
132 return;
133 }
134
135 // No! - set the next item up to process.
136 currentFiber = workQueue.last();
137 workQueue.removeLast();
138 }
139 }
140 }
141
142 JSValuecxx . . $ QTJSC/JSValue# JSStringcxx . . $ QTJSC/JSString#::toPrimitivecxx . . $ QTJSC/JSString#toPrimitive(9c1c7f5535dadf1e).(ExecStatecxx . . $ QTJSC/ExecState#*, PreferredPrimitiveTypecxx . . $ QTJSC/PreferredPrimitiveType#) const
143 {
144 return const_cast<JSStringcxx . . $ QTJSC/JSString#*>(this);
145 }
146
147 bool JSStringcxx . . $ QTJSC/JSString#::getPrimitiveNumbercxx . . $ QTJSC/JSString#getPrimitiveNumber(5ae801b0dd2b44e9).(ExecStatecxx . . $ QTJSC/ExecState#* exec, double& number, JSValuecxx . . $ QTJSC/JSValue#& result)
148 {
149 result = this;
150 number = valuecxx . . $ QTJSC/JSString#value(fc696c135aaf08bd).(exec).toDoublecxx . . $ QTJSC/UString#toDouble(21b6c25e127938e2).();
151 return false;
152 }
153
154 bool JSStringcxx . . $ QTJSC/JSString#::toBooleancxx . . $ QTJSC/JSString#toBoolean(9608304f86fd7dc).(ExecStatecxx . . $ QTJSC/ExecState#*) const
155 {
156 return m_stringLengthcxx . . $ QTJSC/JSString#m_stringLength.;
157 }
158
159 double JSStringcxx . . $ QTJSC/JSString#::toNumbercxx . . $ QTJSC/JSString#toNumber(1fd034e372fd1279).(ExecStatecxx . . $ QTJSC/ExecState#* exec) const
160 {
161 return valuecxx . . $ QTJSC/JSString#value(fc696c135aaf08bd).(exec).toDoublecxx . . $ QTJSC/UString#toDouble(21b6c25e127938e2).();
162 }
163
164 UStringcxx . . $ QTJSC/UString# JSStringcxx . . $ QTJSC/JSString#::toStringcxx . . $ QTJSC/JSString#toString(9c94f5abb1995042).(ExecStatecxx . . $ QTJSC/ExecState#* exec) const
165 {
166 return valuecxx . . $ QTJSC/UString#UString(e6bad6cb9b63b14d).(exec);
167 }
168
169 UStringcxx . . $ QTJSC/UString# JSStringcxx . . $ QTJSC/JSString#::toThisStringcxx . . $ QTJSC/JSString#toThisString(9c94f5abb1995042).(ExecStatecxx . . $ QTJSC/ExecState#* exec) const
170 {
171 return valuecxx . . $ QTJSC/UString#UString(e6bad6cb9b63b14d).(exec);
172 }
173
174 JSStringcxx . . $ QTJSC/JSString#* JSStringcxx . . $ QTJSC/JSString#::toThisJSStringcxx . . $ QTJSC/JSString#toThisJSString(193b2cc77222fd6b).(ExecStatecxx . . $ QTJSC/ExecState#*)
175 {
176 return this;
177 }
178
179 inline StringObjectcxx . . $ QTJSC/StringObject#* StringObjectcxx . . $ QTJSC/StringObject#::createcxx . . $ QTJSC/StringObject#create(e96ea6c2e6b4bd4b).(ExecStatecxx . . $ QTJSC/ExecState#* exec, JSStringcxx . . $ QTJSC/JSString#* string)
180 {
181 return new (exec) StringObject(exec->lexicalGlobalObject()->stringObjectStructure(), string);
182 }
183
184 JSObjectcxx . . $ QTJSC/JSObject#* JSStringcxx . . $ QTJSC/JSString#::toObjectcxx . . $ QTJSC/JSString#toObject(8709ed4849a165ab).(ExecStatecxx . . $ QTJSC/ExecState#* exec) const
185 {
186 return StringObjectcxx . . $ QTJSC/StringObject#::createcxx . . $ QTJSC/StringObject#create(e96ea6c2e6b4bd4b).(exec, const_cast<JSStringcxx . . $ QTJSC/JSString#*>(this));
187 }
188
189 JSObjectcxx . . $ QTJSC/JSObject#* JSStringcxx . . $ QTJSC/JSString#::toThisObjectcxx . . $ QTJSC/JSString#toThisObject(8709ed4849a165ab).(ExecStatecxx . . $ QTJSC/ExecState#* exec) const
190 {
191 return StringObjectcxx . . $ QTJSC/StringObject#::createcxx . . $ QTJSC/StringObject#create(e96ea6c2e6b4bd4b).(exec, const_cast<JSStringcxx . . $ QTJSC/JSString#*>(this));
192 }
193
194 bool JSStringcxx . . $ QTJSC/JSString#::getOwnPropertySlotcxx . . $ QTJSC/JSString#getOwnPropertySlot(6f4ef3dbfe7d5ab9).(ExecStatecxx . . $ QTJSC/ExecState#* exec, const Identifiercxx . . $ QTJSC/Identifier#& propertyName, PropertySlotcxx . . $ QTJSC/PropertySlot#& slot)
195 {
196 // The semantics here are really getPropertySlot, not getOwnPropertySlot.
197 // This function should only be called by JSValue::get.
198 if (getStringPropertySlotcxx . . $ QTJSC/JSString#getStringPropertySlot(6f4ef3dbfe7d5ab9).(exec, propertyName, slot))
199 return true;
200 if (propertyName ==cxx . . $ QTJSC/`operator==`(8208a731c2dadbc2). exec->propertyNamescxx . . $ QTJSC/ExecState#propertyNames(16296db726e31f87).().underscoreProto) {
201 slot.setValuecxx . . $ QTJSC/PropertySlot#setValue(5c2ac18db087b3e6).(exec->lexicalGlobalObjectcxx . . $ QTJSC/ExecState#lexicalGlobalObject(3d50c730b5e26899).()->stringPrototypecxx . . $ QTJSC/JSGlobalObject#stringPrototype(c4eaef10a1984443).());
202 return true;
203 }
204 slot.setBasecxx . . $ QTJSC/PropertySlot#setBase(5c2ac18db087b3e6).(this);
205 JSObjectcxx . . $ QTJSC/JSObject#* object;
206 for (JSValuecxx . . $ QTJSC/JSValue# prototype = exec->lexicalGlobalObjectcxx . . $ QTJSC/ExecState#lexicalGlobalObject(3d50c730b5e26899).()->stringPrototypecxx . . $ QTJSC/JSGlobalObject#stringPrototype(c4eaef10a1984443).(); !prototype.isNullcxx . . $ QTJSC/JSValue#isNull(50ce9a9e25b4a850).(); prototype =cxx . . $ QTJSC/JSValue#`operator=`(5dfb8b6405afb35f). object->prototypecxx . . $ QTJSC/JSObject#prototype(888c053acf364da1).()) {
207 object = asObjectcxx . . $ QTJSC/asObject(107e81180f8dd622).(prototype);
208 if (object->getOwnPropertySlotcxx . . $ QTJSC/JSObject#getOwnPropertySlot(6f4ef3dbfe7d5ab9).(exec, propertyName, slot))
209 return true;
210 }
211 slot.setUndefinedcxx . . $ QTJSC/PropertySlot#setUndefined(49f6e7a06ebc5aa8).();
212 return true;
213 }
214
215 bool JSStringcxx . . $ QTJSC/JSString#::getStringPropertyDescriptorcxx . . $ QTJSC/JSString#getStringPropertyDescriptor(dce4ef7012294c32).(ExecStatecxx . . $ QTJSC/ExecState#* exec, const Identifiercxx . . $ QTJSC/Identifier#& propertyName, PropertyDescriptorcxx . . $ QTJSC/PropertyDescriptor#& descriptor)
216 {
217 if (propertyName ==cxx . . $ QTJSC/`operator==`(8208a731c2dadbc2). exec->propertyNamescxx . . $ QTJSC/ExecState#propertyNames(16296db726e31f87).().length) {
218 descriptor.setDescriptorcxx . . $ QTJSC/PropertyDescriptor#setDescriptor(48358939f851dacc).(jsNumbercxx . . $ QTJSC/jsNumber(bf7e02f8c8245e31).(exec, m_stringLengthcxx . . $ QTJSC/JSString#m_stringLength.), DontEnumcxx . . $ QTJSC/DontEnum. | DontDeletecxx . . $ QTJSC/DontDelete. | ReadOnlycxx . . $ QTJSC/ReadOnly.);
219 return true;
220 }
221
222 bool isStrictUInt32;
223 unsigned i = propertyName.toStrictUInt32cxx . . $ QTJSC/Identifier#toStrictUInt32(870b63f89c7fb98).(&isStrictUInt32);
224 if (isStrictUInt32 && i < m_stringLengthcxx . . $ QTJSC/JSString#m_stringLength.) {
225 descriptor.setDescriptorcxx . . $ QTJSC/PropertyDescriptor#setDescriptor(48358939f851dacc).(jsSingleCharacterSubstringcxx . . $ QTJSC/jsSingleCharacterSubstring(933fdf172a0cf95c).(exec, valuecxx . . $ QTJSC/JSString#value(fc696c135aaf08bd).(exec), i), DontDeletecxx . . $ QTJSC/DontDelete. | ReadOnlycxx . . $ QTJSC/ReadOnly.);
226 return true;
227 }
228
229 return false;
230 }
231
232 bool JSStringcxx . . $ QTJSC/JSString#::getOwnPropertyDescriptorcxx . . $ QTJSC/JSString#getOwnPropertyDescriptor(dce4ef7012294c32).(ExecStatecxx . . $ QTJSC/ExecState#* exec, const Identifiercxx . . $ QTJSC/Identifier#& propertyName, PropertyDescriptorcxx . . $ QTJSC/PropertyDescriptor#& descriptor)
233 {
234 if (getStringPropertyDescriptorcxx . . $ QTJSC/JSString#getStringPropertyDescriptor(dce4ef7012294c32).(exec, propertyName, descriptor))
235 return true;
236 if (propertyName !=cxx . . $ QTJSC/`operator!=`(8208a731c2dadbc2). exec->propertyNamescxx . . $ QTJSC/ExecState#propertyNames(16296db726e31f87).().underscoreProto)
237 return false;
238 descriptor.setDescriptorcxx . . $ QTJSC/PropertyDescriptor#setDescriptor(48358939f851dacc).(exec->lexicalGlobalObjectcxx . . $ QTJSC/ExecState#lexicalGlobalObject(3d50c730b5e26899).()->stringPrototypecxx . . $ QTJSC/JSGlobalObject#stringPrototype(c4eaef10a1984443).(), DontEnumcxx . . $ QTJSC/DontEnum.);
239 return true;
240 }
241
242 bool JSStringcxx . . $ QTJSC/JSString#::getOwnPropertySlotcxx . . $ QTJSC/JSString#getOwnPropertySlot(d57d1c8d4b24d235).(ExecStatecxx . . $ QTJSC/ExecState#* exec, unsigned propertyName, PropertySlotcxx . . $ QTJSC/PropertySlot#& slot)
243 {
244 // The semantics here are really getPropertySlot, not getOwnPropertySlot.
245 // This function should only be called by JSValue::get.
246 if (getStringPropertySlotcxx . . $ QTJSC/JSString#getStringPropertySlot(d57d1c8d4b24d235).(exec, propertyName, slot))
247 return true;
248 return JSStringcxx . . $ QTJSC/JSString#::getOwnPropertySlotcxx . . $ QTJSC/JSString#getOwnPropertySlot(6f4ef3dbfe7d5ab9).(exec, Identifiercxx . . $ QTJSC/Identifier#::fromcxx . . $ QTJSC/Identifier#from(d1afedae20629715).(exec, propertyName), slot);
249 }
250
251 } // namespace JSC