[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.21-584-g1e41756
barraclough at apple.com
barraclough at apple.com
Fri Feb 26 22:20:22 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit 28e548ee2e4152fb1878ff39059b138c71e48dab
Author: barraclough at apple.com <barraclough at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Mon Feb 15 21:03:45 2010 +0000
Bug 34952 - String lengths in UString should be unsigned.
This matches WebCore::StringImpl, and better unifies behaviour throughout JSC.
Reviewed by Geoff Garen.
JavaScriptCore:
* JavaScriptCore.exp:
* bytecode/EvalCodeCache.h:
* runtime/Identifier.cpp:
(JSC::Identifier::equal):
* runtime/Identifier.h:
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::globalFuncEscape):
* runtime/JSONObject.cpp:
(JSC::gap):
(JSC::Stringifier::indent):
* runtime/NumberPrototype.cpp:
(JSC::numberProtoFuncToFixed):
(JSC::numberProtoFuncToPrecision):
* runtime/RegExp.cpp:
(JSC::RegExp::match):
* runtime/StringPrototype.cpp:
(JSC::substituteBackreferencesSlow):
(JSC::stringProtoFuncReplace):
(JSC::stringProtoFuncSplit):
(JSC::trimString):
* runtime/UString.cpp:
(JSC::UString::UString):
(JSC::UString::from):
(JSC::UString::getCString):
(JSC::UString::ascii):
(JSC::UString::operator[]):
(JSC::UString::toStrictUInt32):
(JSC::UString::find):
(JSC::UString::rfind):
(JSC::UString::substr):
(JSC::operator<):
(JSC::operator>):
(JSC::compare):
(JSC::equal):
(JSC::UString::UTF8String):
* runtime/UString.h:
(JSC::UString::size):
(JSC::operator==):
* runtime/UStringImpl.cpp:
(JSC::UStringImpl::create):
* runtime/UStringImpl.h:
(JSC::UStringImpl::create):
(JSC::UStringImpl::size):
(JSC::UStringImpl::computeHash):
(JSC::UStringImpl::UStringImpl):
WebCore:
* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::JSDOMWindow::atob):
(WebCore::JSDOMWindow::btoa):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54789 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 68ebc20..e79d598 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -2,6 +2,59 @@
Reviewed by Geoff Garen.
+ Bug 34952 - String lengths in UString should be unsigned.
+ This matches WebCore::StringImpl, and better unifies behaviour throughout JSC.
+
+ * JavaScriptCore.exp:
+ * bytecode/EvalCodeCache.h:
+ * runtime/Identifier.cpp:
+ (JSC::Identifier::equal):
+ * runtime/Identifier.h:
+ * runtime/JSGlobalObjectFunctions.cpp:
+ (JSC::globalFuncEscape):
+ * runtime/JSONObject.cpp:
+ (JSC::gap):
+ (JSC::Stringifier::indent):
+ * runtime/NumberPrototype.cpp:
+ (JSC::numberProtoFuncToFixed):
+ (JSC::numberProtoFuncToPrecision):
+ * runtime/RegExp.cpp:
+ (JSC::RegExp::match):
+ * runtime/StringPrototype.cpp:
+ (JSC::substituteBackreferencesSlow):
+ (JSC::stringProtoFuncReplace):
+ (JSC::stringProtoFuncSplit):
+ (JSC::trimString):
+ * runtime/UString.cpp:
+ (JSC::UString::UString):
+ (JSC::UString::from):
+ (JSC::UString::getCString):
+ (JSC::UString::ascii):
+ (JSC::UString::operator[]):
+ (JSC::UString::toStrictUInt32):
+ (JSC::UString::find):
+ (JSC::UString::rfind):
+ (JSC::UString::substr):
+ (JSC::operator<):
+ (JSC::operator>):
+ (JSC::compare):
+ (JSC::equal):
+ (JSC::UString::UTF8String):
+ * runtime/UString.h:
+ (JSC::UString::size):
+ (JSC::operator==):
+ * runtime/UStringImpl.cpp:
+ (JSC::UStringImpl::create):
+ * runtime/UStringImpl.h:
+ (JSC::UStringImpl::create):
+ (JSC::UStringImpl::size):
+ (JSC::UStringImpl::computeHash):
+ (JSC::UStringImpl::UStringImpl):
+
+2010-02-15 Gavin Barraclough <barraclough at apple.com>
+
+ Reviewed by Geoff Garen.
+
Bug 34948 - tryMakeString should fail on error in length calculation
The sum of the length of substrings could overflow.
diff --git a/JavaScriptCore/JavaScriptCore.exp b/JavaScriptCore/JavaScriptCore.exp
index f562b52..09f647f 100644
--- a/JavaScriptCore/JavaScriptCore.exp
+++ b/JavaScriptCore/JavaScriptCore.exp
@@ -240,7 +240,7 @@ __ZN3JSC7UString4fromEj
__ZN3JSC7UString4fromEl
__ZN3JSC7UString9s_nullRepE
__ZN3JSC7UStringC1EPKc
-__ZN3JSC7UStringC1EPKti
+__ZN3JSC7UStringC1EPKtj
__ZN3JSC8Debugger23recompileAllJSFunctionsEPNS_12JSGlobalDataE
__ZN3JSC8Debugger6attachEPNS_14JSGlobalObjectE
__ZN3JSC8Debugger6detachEPNS_14JSGlobalObjectE
@@ -393,7 +393,7 @@ __ZNK3JSC7UString10UTF8StringEb
__ZNK3JSC7UString14toStrictUInt32EPb
__ZNK3JSC7UString5asciiEv
__ZNK3JSC7UString6is8BitEv
-__ZNK3JSC7UString6substrEii
+__ZNK3JSC7UString6substrEjj
__ZNK3JSC7UString8toUInt32EPb
__ZNK3JSC7UString8toUInt32EPbb
__ZNK3JSC8JSObject11hasPropertyEPNS_9ExecStateERKNS_10IdentifierE
diff --git a/JavaScriptCore/bytecode/CodeBlock.cpp b/JavaScriptCore/bytecode/CodeBlock.cpp
index fd56ece..0ec1888 100644
--- a/JavaScriptCore/bytecode/CodeBlock.cpp
+++ b/JavaScriptCore/bytecode/CodeBlock.cpp
@@ -49,8 +49,8 @@ namespace JSC {
static UString escapeQuotes(const UString& str)
{
UString result = str;
- int pos = 0;
- while ((pos = result.find('\"', pos)) >= 0) {
+ unsigned pos = 0;
+ while ((pos = result.find('\"', pos)) != UString::NotFound) {
result = makeString(result.substr(0, pos), "\"\\\"\"", result.substr(pos + 1));
pos += 4;
}
diff --git a/JavaScriptCore/bytecode/EvalCodeCache.h b/JavaScriptCore/bytecode/EvalCodeCache.h
index 05834fc..a036dd4 100644
--- a/JavaScriptCore/bytecode/EvalCodeCache.h
+++ b/JavaScriptCore/bytecode/EvalCodeCache.h
@@ -65,7 +65,7 @@ namespace JSC {
bool isEmpty() const { return m_cacheMap.isEmpty(); }
private:
- static const int maxCacheableSourceLength = 256;
+ static const unsigned maxCacheableSourceLength = 256;
static const int maxCacheEntries = 64;
typedef HashMap<RefPtr<UString::Rep>, RefPtr<EvalExecutable> > EvalCacheMap;
diff --git a/JavaScriptCore/bytecompiler/NodesCodegen.cpp b/JavaScriptCore/bytecompiler/NodesCodegen.cpp
index b66c50d..4162873 100644
--- a/JavaScriptCore/bytecompiler/NodesCodegen.cpp
+++ b/JavaScriptCore/bytecompiler/NodesCodegen.cpp
@@ -76,8 +76,8 @@ namespace JSC {
static void substitute(UString& string, const UString& substring)
{
- int position = string.find("%s");
- ASSERT(position != -1);
+ unsigned position = string.find("%s");
+ ASSERT(position != UString::NotFound);
string = makeString(string.substr(0, position), substring, string.substr(position + 2));
}
diff --git a/JavaScriptCore/runtime/Identifier.cpp b/JavaScriptCore/runtime/Identifier.cpp
index 97929e2..be8943a 100644
--- a/JavaScriptCore/runtime/Identifier.cpp
+++ b/JavaScriptCore/runtime/Identifier.cpp
@@ -87,12 +87,12 @@ bool Identifier::equal(const UString::Rep* r, const char* s)
return s[length] == 0;
}
-bool Identifier::equal(const UString::Rep* r, const UChar* s, int length)
+bool Identifier::equal(const UString::Rep* r, const UChar* s, unsigned length)
{
if (r->size() != length)
return false;
const UChar* d = r->data();
- for (int i = 0; i != length; ++i)
+ for (unsigned i = 0; i != length; ++i)
if (d[i] != s[i])
return false;
return true;
diff --git a/JavaScriptCore/runtime/Identifier.h b/JavaScriptCore/runtime/Identifier.h
index 1d1bd18..73e2af8 100644
--- a/JavaScriptCore/runtime/Identifier.h
+++ b/JavaScriptCore/runtime/Identifier.h
@@ -76,7 +76,7 @@ namespace JSC {
static void remove(UString::Rep*);
static bool equal(const UString::Rep*, const char*);
- static bool equal(const UString::Rep*, const UChar*, int length);
+ static bool equal(const UString::Rep*, const UChar*, unsigned length);
static bool equal(const UString::Rep* a, const UString::Rep* b) { return JSC::equal(a, b); }
static PassRefPtr<UString::Rep> add(ExecState*, const char*); // Only to be used with string literals.
diff --git a/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp b/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
index 3ddac7c..0e1fbee 100644
--- a/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
+++ b/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
@@ -381,7 +381,7 @@ JSValue JSC_HOST_CALL globalFuncEscape(ExecState* exec, JSObject*, JSValue, cons
JSStringBuilder builder;
UString str = args.at(0).toString(exec);
const UChar* c = str.data();
- for (int k = 0; k < str.size(); k++, c++) {
+ for (unsigned k = 0; k < str.size(); k++, c++) {
int u = c[0];
if (u > 255) {
char tmp[7];
diff --git a/JavaScriptCore/runtime/JSONObject.cpp b/JavaScriptCore/runtime/JSONObject.cpp
index acd9280..d69a8da 100644
--- a/JavaScriptCore/runtime/JSONObject.cpp
+++ b/JavaScriptCore/runtime/JSONObject.cpp
@@ -135,7 +135,7 @@ static inline JSValue unwrapBoxedPrimitive(ExecState* exec, JSValue value)
static inline UString gap(ExecState* exec, JSValue space)
{
- const int maxGapLength = 10;
+ const unsigned maxGapLength = 10;
space = unwrapBoxedPrimitive(exec, space);
// If the space value is a number, create a gap string with that number of spaces.
@@ -456,7 +456,7 @@ inline bool Stringifier::willIndent() const
inline void Stringifier::indent()
{
// Use a single shared string, m_repeatedGap, so we don't keep allocating new ones as we indent and unindent.
- int newSize = m_indent.size() + m_gap.size();
+ unsigned newSize = m_indent.size() + m_gap.size();
if (newSize > m_repeatedGap.size())
m_repeatedGap = makeString(m_repeatedGap, m_gap);
ASSERT(newSize <= m_repeatedGap.size());
diff --git a/JavaScriptCore/runtime/NumberPrototype.cpp b/JavaScriptCore/runtime/NumberPrototype.cpp
index fa32b86..5680eb1 100644
--- a/JavaScriptCore/runtime/NumberPrototype.cpp
+++ b/JavaScriptCore/runtime/NumberPrototype.cpp
@@ -265,11 +265,11 @@ JSValue JSC_HOST_CALL numberProtoFuncToFixed(ExecState* exec, JSObject*, JSValue
z.append(m);
m = z.build();
k = f + 1;
- ASSERT(k == m.size());
+ ASSERT(k == static_cast<int>(m.size()));
}
int kMinusf = k - f;
- if (kMinusf < m.size())
+ if (kMinusf < static_cast<int>(m.size()))
return jsString(exec, makeString(s, m.substr(0, kMinusf), ".", m.substr(kMinusf)));
return jsString(exec, makeString(s, m.substr(0, kMinusf)));
}
@@ -444,7 +444,7 @@ JSValue JSC_HOST_CALL numberProtoFuncToPrecision(ExecState* exec, JSObject*, JSV
if (e == precision - 1)
return jsString(exec, makeString(s, m));
if (e >= 0) {
- if (e + 1 < m.size())
+ if (e + 1 < static_cast<int>(m.size()))
return jsString(exec, makeString(s, m.substr(0, e + 1), ".", m.substr(e + 1)));
return jsString(exec, makeString(s, m));
}
diff --git a/JavaScriptCore/runtime/RegExp.cpp b/JavaScriptCore/runtime/RegExp.cpp
index 4e958f4..9142349 100644
--- a/JavaScriptCore/runtime/RegExp.cpp
+++ b/JavaScriptCore/runtime/RegExp.cpp
@@ -71,11 +71,11 @@ inline RegExp::RegExp(JSGlobalData* globalData, const UString& pattern, const US
{
// NOTE: The global flag is handled on a case-by-case basis by functions like
// String::match and RegExpObject::match.
- if (flags.find('g') != -1)
+ if (flags.find('g') != UString::NotFound)
m_flagBits |= Global;
- if (flags.find('i') != -1)
+ if (flags.find('i') != UString::NotFound)
m_flagBits |= IgnoreCase;
- if (flags.find('m') != -1)
+ if (flags.find('m') != UString::NotFound)
m_flagBits |= Multiline;
compile(globalData);
@@ -117,7 +117,7 @@ int RegExp::match(const UString& s, int startOffset, Vector<int, 32>* ovector)
if (ovector)
ovector->clear();
- if (startOffset > s.size() || s.isNull())
+ if (static_cast<unsigned>(startOffset) > s.size() || s.isNull())
return -1;
#if ENABLE(YARR_JIT)
diff --git a/JavaScriptCore/runtime/StringPrototype.cpp b/JavaScriptCore/runtime/StringPrototype.cpp
index 8c014ec..bef4083 100644
--- a/JavaScriptCore/runtime/StringPrototype.cpp
+++ b/JavaScriptCore/runtime/StringPrototype.cpp
@@ -150,7 +150,7 @@ bool StringPrototype::getOwnPropertyDescriptor(ExecState* exec, const Identifier
// ------------------------------ Functions --------------------------
-static NEVER_INLINE UString substituteBackreferencesSlow(const UString& replacement, const UString& source, const int* ovector, RegExp* reg, int i)
+static NEVER_INLINE UString substituteBackreferencesSlow(const UString& replacement, const UString& source, const int* ovector, RegExp* reg, unsigned i)
{
Vector<UChar> substitutedReplacement;
int offset = 0;
@@ -206,7 +206,7 @@ static NEVER_INLINE UString substituteBackreferencesSlow(const UString& replacem
i += 1 + advance;
offset = i + 1;
substitutedReplacement.append(source.data() + backrefStart, backrefLength);
- } while ((i = replacement.find('$', i + 1)) != -1);
+ } while ((i = replacement.find('$', i + 1)) != UString::NotFound);
if (replacement.size() - offset)
substitutedReplacement.append(replacement.data() + offset, replacement.size() - offset);
@@ -217,8 +217,8 @@ static NEVER_INLINE UString substituteBackreferencesSlow(const UString& replacem
static inline UString substituteBackreferences(const UString& replacement, const UString& source, const int* ovector, RegExp* reg)
{
- int i = replacement.find('$', 0);
- if (UNLIKELY(i != -1))
+ unsigned i = replacement.find('$', 0);
+ if (UNLIKELY(i != UString::NotFound))
return substituteBackreferencesSlow(replacement, source, ovector, reg, i);
return replacement;
}
@@ -329,7 +329,7 @@ JSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec, JSObject*, JSValue
RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor();
int lastIndex = 0;
- int startPosition = 0;
+ unsigned startPosition = 0;
Vector<StringRange, 16> sourceRanges;
Vector<UString, 16> replacements;
@@ -432,7 +432,7 @@ JSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec, JSObject*, JSValue
if (!lastIndex && replacements.isEmpty())
return sourceVal;
- if (lastIndex < source.size())
+ if (static_cast<unsigned>(lastIndex) < source.size())
sourceRanges.append(StringRange(lastIndex, source.size() - lastIndex));
return jsSpliceSubstringsWithSeparators(exec, sourceVal, source, sourceRanges.data(), sourceRanges.size(), replacements.data(), replacements.size());
@@ -441,9 +441,9 @@ JSValue JSC_HOST_CALL stringProtoFuncReplace(ExecState* exec, JSObject*, JSValue
// Not a regular expression, so treat the pattern as a string.
UString patternString = pattern.toString(exec);
- int matchPos = source.find(patternString);
+ unsigned matchPos = source.find(patternString);
- if (matchPos == -1)
+ if (matchPos == UString::NotFound)
return sourceVal;
int matchLen = patternString.size();
@@ -541,7 +541,10 @@ JSValue JSC_HOST_CALL stringProtoFuncIndexOf(ExecState* exec, JSObject*, JSValue
pos = static_cast<int>(dpos);
}
- return jsNumber(exec, s.find(u2, pos));
+ unsigned result = s.find(u2, pos);
+ if (result == UString::NotFound)
+ return jsNumber(exec, -1);
+ return jsNumber(exec, result);
}
JSValue JSC_HOST_CALL stringProtoFuncLastIndexOf(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
@@ -563,7 +566,11 @@ JSValue JSC_HOST_CALL stringProtoFuncLastIndexOf(ExecState* exec, JSObject*, JSV
else if (isnan(dpos))
dpos = len;
#endif
- return jsNumber(exec, s.rfind(u2, static_cast<int>(dpos)));
+
+ unsigned result = s.rfind(u2, static_cast<unsigned>(dpos));
+ if (result == UString::NotFound)
+ return jsNumber(exec, -1);
+ return jsNumber(exec, result);
}
JSValue JSC_HOST_CALL stringProtoFuncMatch(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
@@ -675,7 +682,7 @@ JSValue JSC_HOST_CALL stringProtoFuncSplit(ExecState* exec, JSObject*, JSValue t
JSArray* result = constructEmptyArray(exec);
unsigned i = 0;
- int p0 = 0;
+ unsigned p0 = 0;
unsigned limit = a1.isUndefined() ? 0xFFFFFFFFU : a1.toUInt32(exec);
if (a0.inherits(&RegExpObject::info)) {
RegExp* reg = asRegExpObject(a0)->regExp();
@@ -683,7 +690,7 @@ JSValue JSC_HOST_CALL stringProtoFuncSplit(ExecState* exec, JSObject*, JSValue t
// empty string matched by regexp -> empty array
return result;
}
- int pos = 0;
+ unsigned pos = 0;
while (i != limit && pos < s.size()) {
Vector<int, 32> ovector;
int mpos = reg->match(s, pos, &ovector);
@@ -691,7 +698,7 @@ JSValue JSC_HOST_CALL stringProtoFuncSplit(ExecState* exec, JSObject*, JSValue t
break;
int mlen = ovector[1] - ovector[0];
pos = mpos + (mlen == 0 ? 1 : mlen);
- if (mpos != p0 || mlen) {
+ if (static_cast<unsigned>(mpos) != p0 || mlen) {
result->put(exec, i++, jsSubstring(exec, s, p0, mpos - p0));
p0 = mpos + mlen;
}
@@ -713,8 +720,9 @@ JSValue JSC_HOST_CALL stringProtoFuncSplit(ExecState* exec, JSObject*, JSValue t
while (i != limit && p0 < s.size() - 1)
result->put(exec, i++, jsSingleCharacterSubstring(exec, s, p0++));
} else {
- int pos;
- while (i != limit && (pos = s.find(u2, p0)) >= 0) {
+ unsigned pos;
+
+ while (i != limit && (pos = s.find(u2, p0)) != UString::NotFound) {
result->put(exec, i++, jsSubstring(exec, s, p0, pos - p0));
p0 = pos + u2.size();
}
@@ -1022,12 +1030,12 @@ static inline bool isTrimWhitespace(UChar c)
static inline JSValue trimString(ExecState* exec, JSValue thisValue, int trimKind)
{
UString str = thisValue.toThisString(exec);
- int left = 0;
+ unsigned left = 0;
if (trimKind & TrimLeft) {
while (left < str.size() && isTrimWhitespace(str[left]))
left++;
}
- int right = str.size();
+ unsigned right = str.size();
if (trimKind & TrimRight) {
while (right > left && isTrimWhitespace(str[right - 1]))
right--;
diff --git a/JavaScriptCore/runtime/UString.cpp b/JavaScriptCore/runtime/UString.cpp
index 4a89a23..876945f 100644
--- a/JavaScriptCore/runtime/UString.cpp
+++ b/JavaScriptCore/runtime/UString.cpp
@@ -167,12 +167,12 @@ UString::UString(const char* c)
{
}
-UString::UString(const char* c, int length)
+UString::UString(const char* c, unsigned length)
: m_rep(Rep::create(c, length))
{
}
-UString::UString(const UChar* c, int length)
+UString::UString(const UChar* c, unsigned length)
{
if (length == 0)
m_rep = &Rep::empty();
@@ -206,7 +206,7 @@ UString UString::from(int i)
*--p = '-';
}
- return UString(p, static_cast<int>(end - p));
+ return UString(p, static_cast<unsigned>(end - p));
}
UString UString::from(long long i)
@@ -239,7 +239,7 @@ UString UString::from(long long i)
*--p = '-';
}
- return UString(p, static_cast<int>(end - p));
+ return UString(p, static_cast<unsigned>(end - p));
}
UString UString::from(unsigned int u)
@@ -257,7 +257,7 @@ UString UString::from(unsigned int u)
}
}
- return UString(p, static_cast<int>(end - p));
+ return UString(p, static_cast<unsigned>(end - p));
}
UString UString::from(long l)
@@ -286,7 +286,7 @@ UString UString::from(long l)
*--p = '-';
}
- return UString(p, static_cast<int>(end - p));
+ return UString(p, end - p);
}
UString UString::from(double d)
@@ -299,8 +299,8 @@ UString UString::from(double d)
bool UString::getCString(CStringBuffer& buffer) const
{
- int length = size();
- int neededSize = length + 1;
+ unsigned length = size();
+ unsigned neededSize = length + 1;
buffer.resize(neededSize);
char* buf = buffer.data();
@@ -324,8 +324,8 @@ char* UString::ascii() const
{
static char* asciiBuffer = 0;
- int length = size();
- int neededSize = length + 1;
+ unsigned length = size();
+ unsigned neededSize = length + 1;
delete[] asciiBuffer;
asciiBuffer = new char[neededSize];
@@ -355,7 +355,7 @@ bool UString::is8Bit() const
return true;
}
-UChar UString::operator[](int pos) const
+UChar UString::operator[](unsigned pos) const
{
if (pos >= size())
return '\0';
@@ -495,7 +495,7 @@ uint32_t UString::toStrictUInt32(bool* ok) const
*ok = false;
// Empty string is not OK.
- int len = m_rep->size();
+ unsigned len = m_rep->size();
if (len == 0)
return 0;
const UChar* p = m_rep->data();
@@ -539,12 +539,9 @@ uint32_t UString::toStrictUInt32(bool* ok) const
}
}
-int UString::find(const UString& f, int pos) const
+unsigned UString::find(const UString& f, unsigned pos) const
{
- int fsz = f.size();
-
- if (pos < 0)
- pos = 0;
+ unsigned fsz = f.size();
if (fsz == 1) {
UChar ch = f[0];
@@ -553,16 +550,16 @@ int UString::find(const UString& f, int pos) const
if (*c == ch)
return static_cast<int>(c - data());
}
- return -1;
+ return NotFound;
}
- int sz = size();
+ unsigned sz = size();
if (sz < fsz)
- return -1;
+ return NotFound;
if (fsz == 0)
return pos;
const UChar* end = data() + sz - fsz;
- int fsizeminusone = (fsz - 1) * sizeof(UChar);
+ unsigned fsizeminusone = (fsz - 1) * sizeof(UChar);
const UChar* fdata = f.data();
unsigned short fchar = fdata[0];
++fdata;
@@ -571,48 +568,44 @@ int UString::find(const UString& f, int pos) const
return static_cast<int>(c - data());
}
- return -1;
+ return NotFound;
}
-int UString::find(UChar ch, int pos) const
+unsigned UString::find(UChar ch, unsigned pos) const
{
- if (pos < 0)
- pos = 0;
const UChar* end = data() + size();
for (const UChar* c = data() + pos; c < end; c++) {
if (*c == ch)
return static_cast<int>(c - data());
}
- return -1;
+ return NotFound;
}
-int UString::rfind(const UString& f, int pos) const
+unsigned UString::rfind(const UString& f, unsigned pos) const
{
- int sz = size();
- int fsz = f.size();
+ unsigned sz = size();
+ unsigned fsz = f.size();
if (sz < fsz)
- return -1;
- if (pos < 0)
- pos = 0;
+ return NotFound;
if (pos > sz - fsz)
pos = sz - fsz;
if (fsz == 0)
return pos;
- int fsizeminusone = (fsz - 1) * sizeof(UChar);
+ unsigned fsizeminusone = (fsz - 1) * sizeof(UChar);
const UChar* fdata = f.data();
for (const UChar* c = data() + pos; c >= data(); c--) {
if (*c == *fdata && !memcmp(c + 1, fdata + 1, fsizeminusone))
return static_cast<int>(c - data());
}
- return -1;
+ return NotFound;
}
-int UString::rfind(UChar ch, int pos) const
+unsigned UString::rfind(UChar ch, unsigned pos) const
{
if (isEmpty())
- return -1;
+ return NotFound;
if (pos + 1 >= size())
pos = size() - 1;
for (const UChar* c = data() + pos; c >= data(); c--) {
@@ -620,21 +613,18 @@ int UString::rfind(UChar ch, int pos) const
return static_cast<int>(c - data());
}
- return -1;
+ return NotFound;
}
-UString UString::substr(int pos, int len) const
+UString UString::substr(unsigned pos, unsigned len) const
{
- int s = size();
+ unsigned s = size();
- if (pos < 0)
- pos = 0;
- else if (pos >= s)
+ if (pos >= s)
pos = s;
- if (len < 0)
- len = s;
- if (pos + len >= s)
- len = s - pos;
+ unsigned limit = s - pos;
+ if (len > limit)
+ len = limit;
if (pos == 0 && len == s)
return *this;
@@ -661,12 +651,12 @@ bool operator==(const UString& s1, const char *s2)
bool operator<(const UString& s1, const UString& s2)
{
- const int l1 = s1.size();
- const int l2 = s2.size();
- const int lmin = l1 < l2 ? l1 : l2;
+ const unsigned l1 = s1.size();
+ const unsigned l2 = s2.size();
+ const unsigned lmin = l1 < l2 ? l1 : l2;
const UChar* c1 = s1.data();
const UChar* c2 = s2.data();
- int l = 0;
+ unsigned l = 0;
while (l < lmin && *c1 == *c2) {
c1++;
c2++;
@@ -680,12 +670,12 @@ bool operator<(const UString& s1, const UString& s2)
bool operator>(const UString& s1, const UString& s2)
{
- const int l1 = s1.size();
- const int l2 = s2.size();
- const int lmin = l1 < l2 ? l1 : l2;
+ const unsigned l1 = s1.size();
+ const unsigned l2 = s2.size();
+ const unsigned lmin = l1 < l2 ? l1 : l2;
const UChar* c1 = s1.data();
const UChar* c2 = s2.data();
- int l = 0;
+ unsigned l = 0;
while (l < lmin && *c1 == *c2) {
c1++;
c2++;
@@ -699,12 +689,12 @@ bool operator>(const UString& s1, const UString& s2)
int compare(const UString& s1, const UString& s2)
{
- const int l1 = s1.size();
- const int l2 = s2.size();
- const int lmin = l1 < l2 ? l1 : l2;
+ const unsigned l1 = s1.size();
+ const unsigned l2 = s2.size();
+ const unsigned lmin = l1 < l2 ? l1 : l2;
const UChar* c1 = s1.data();
const UChar* c2 = s2.data();
- int l = 0;
+ unsigned l = 0;
while (l < lmin && *c1 == *c2) {
c1++;
c2++;
@@ -722,12 +712,12 @@ int compare(const UString& s1, const UString& s2)
bool equal(const UString::Rep* r, const UString::Rep* b)
{
- int length = r->size();
+ unsigned length = r->size();
if (length != b->size())
return false;
const UChar* d = r->data();
const UChar* s = b->data();
- for (int i = 0; i != length; ++i) {
+ for (unsigned i = 0; i != length; ++i) {
if (d[i] != s[i])
return false;
}
@@ -737,7 +727,7 @@ bool equal(const UString::Rep* r, const UString::Rep* b)
CString UString::UTF8String(bool strict) const
{
// Allocate a buffer big enough to hold all the characters.
- const int length = size();
+ const unsigned length = size();
Vector<char, 1024> buffer(length * 3);
// Convert to runs of 8-bit characters.
diff --git a/JavaScriptCore/runtime/UString.h b/JavaScriptCore/runtime/UString.h
index 0277f43..6cf0386 100644
--- a/JavaScriptCore/runtime/UString.h
+++ b/JavaScriptCore/runtime/UString.h
@@ -82,8 +82,8 @@ namespace JSC {
public:
UString();
UString(const char*); // Constructor for null-terminated string.
- UString(const char*, int length);
- UString(const UChar*, int length);
+ UString(const char*, unsigned length);
+ UString(const UChar*, unsigned length);
UString(const Vector<UChar>& buffer);
UString(const UString& s)
@@ -136,9 +136,9 @@ namespace JSC {
bool is8Bit() const;
- int size() const { return m_rep->size(); }
+ unsigned size() const { return m_rep->size(); }
- UChar operator[](int pos) const;
+ UChar operator[](unsigned pos) const;
double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const;
double toDouble(bool tolerateTrailingJunk) const;
@@ -150,12 +150,13 @@ namespace JSC {
unsigned toArrayIndex(bool* ok = 0) const;
- int find(const UString& f, int pos = 0) const;
- int find(UChar, int pos = 0) const;
- int rfind(const UString& f, int pos) const;
- int rfind(UChar, int pos) const;
+ static const unsigned NotFound = 0xFFFFFFFFu;
+ unsigned find(const UString& f, unsigned pos = 0) const;
+ unsigned find(UChar, unsigned pos = 0) const;
+ unsigned rfind(const UString& f, unsigned pos) const;
+ unsigned rfind(UChar, unsigned pos) const;
- UString substr(int pos = 0, int len = -1) const;
+ UString substr(unsigned pos = 0, unsigned len = 0xFFFFFFFF) const;
static const UString& null() { return *s_nullUString; }
@@ -181,7 +182,7 @@ namespace JSC {
ALWAYS_INLINE bool operator==(const UString& s1, const UString& s2)
{
- int size = s1.size();
+ unsigned size = s1.size();
switch (size) {
case 0:
return !s2.size();
@@ -245,9 +246,7 @@ namespace JSC {
// We'd rather not do shared substring append for small strings, since
// this runs too much risk of a tiny initial string holding down a
// huge buffer.
- // FIXME: this should be size_t but that would cause warnings until we
- // fix UString sizes to be size_t instead of int
- static const int minShareSize = Heap::minExtraCost / sizeof(UChar);
+ static const unsigned minShareSize = Heap::minExtraCost / sizeof(UChar);
struct IdentifierRepHash : PtrHash<RefPtr<JSC::UString::Rep> > {
static unsigned hash(const RefPtr<JSC::UString::Rep>& key) { return key->existingHash(); }
diff --git a/JavaScriptCore/runtime/UStringImpl.cpp b/JavaScriptCore/runtime/UStringImpl.cpp
index 743fdf5..d7f7e03 100644
--- a/JavaScriptCore/runtime/UStringImpl.cpp
+++ b/JavaScriptCore/runtime/UStringImpl.cpp
@@ -50,7 +50,7 @@ PassRefPtr<UStringImpl> UStringImpl::create(const char* c)
return result;
}
-PassRefPtr<UStringImpl> UStringImpl::create(const char* c, int length)
+PassRefPtr<UStringImpl> UStringImpl::create(const char* c, unsigned length)
{
ASSERT(c);
@@ -59,12 +59,12 @@ PassRefPtr<UStringImpl> UStringImpl::create(const char* c, int length)
UChar* d;
PassRefPtr<UStringImpl> result = UStringImpl::createUninitialized(length, d);
- for (int i = 0; i < length; i++)
+ for (unsigned i = 0; i < length; i++)
d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
return result;
}
-PassRefPtr<UStringImpl> UStringImpl::create(const UChar* buffer, int length)
+PassRefPtr<UStringImpl> UStringImpl::create(const UChar* buffer, unsigned length)
{
UChar* newBuffer;
PassRefPtr<UStringImpl> impl = createUninitialized(length, newBuffer);
diff --git a/JavaScriptCore/runtime/UStringImpl.h b/JavaScriptCore/runtime/UStringImpl.h
index b2fbdf6..1a72554 100644
--- a/JavaScriptCore/runtime/UStringImpl.h
+++ b/JavaScriptCore/runtime/UStringImpl.h
@@ -53,17 +53,17 @@ public:
}
static PassRefPtr<UStringImpl> create(const char* c);
- static PassRefPtr<UStringImpl> create(const char* c, int length);
- static PassRefPtr<UStringImpl> create(const UChar* buffer, int length);
+ static PassRefPtr<UStringImpl> create(const char* c, unsigned length);
+ static PassRefPtr<UStringImpl> create(const UChar* buffer, unsigned length);
- static PassRefPtr<UStringImpl> create(PassRefPtr<UStringImpl> rep, int offset, int length)
+ static PassRefPtr<UStringImpl> create(PassRefPtr<UStringImpl> rep, unsigned offset, unsigned length)
{
ASSERT(rep);
rep->checkConsistency();
return adoptRef(new UStringImpl(rep->m_data + offset, length, rep->bufferOwnerString()));
}
- static PassRefPtr<UStringImpl> create(PassRefPtr<SharedUChar> sharedBuffer, UChar* buffer, int length)
+ static PassRefPtr<UStringImpl> create(PassRefPtr<SharedUChar> sharedBuffer, UChar* buffer, unsigned length)
{
return adoptRef(new UStringImpl(buffer, length, sharedBuffer));
}
@@ -100,7 +100,7 @@ public:
SharedUChar* sharedBuffer();
UChar* data() const { return m_data; }
- int size() const { return m_length; }
+ unsigned size() const { return m_length; }
size_t cost()
{
// For substrings, return the cost of the base string.
@@ -136,8 +136,8 @@ public:
memcpy(destination, source, numCharacters * sizeof(UChar));
}
- static unsigned computeHash(const UChar* s, int length) { ASSERT(length >= 0); return WTF::stringHash(s, length); }
- static unsigned computeHash(const char* s, int length) { ASSERT(length >= 0); return WTF::stringHash(s, length); }
+ static unsigned computeHash(const UChar* s, unsigned length) { return WTF::stringHash(s, length); }
+ static unsigned computeHash(const char* s, unsigned length) { return WTF::stringHash(s, length); }
static unsigned computeHash(const char* s) { return WTF::stringHash(s); }
static UStringImpl& empty() { return *s_empty; }
@@ -162,7 +162,7 @@ private:
UStringImpl() { }
// Used to construct normal strings with an internal or external buffer.
- UStringImpl(UChar* data, int length, BufferOwnership ownership)
+ UStringImpl(UChar* data, unsigned length, BufferOwnership ownership)
: m_data(data)
, m_buffer(0)
, m_length(length)
@@ -177,7 +177,7 @@ private:
// This means that the static string will never be destroyed, which is important because
// static strings will be shared across threads & ref-counted in a non-threadsafe manner.
enum StaticStringConstructType { ConstructStaticString };
- UStringImpl(UChar* data, int length, StaticStringConstructType)
+ UStringImpl(UChar* data, unsigned length, StaticStringConstructType)
: m_data(data)
, m_buffer(0)
, m_length(length)
@@ -188,7 +188,7 @@ private:
}
// Used to create new strings that are a substring of an existing string.
- UStringImpl(UChar* data, int length, PassRefPtr<UStringImpl> base)
+ UStringImpl(UChar* data, unsigned length, PassRefPtr<UStringImpl> base)
: m_data(data)
, m_bufferSubstring(base.releaseRef())
, m_length(length)
@@ -204,7 +204,7 @@ private:
}
// Used to construct new strings sharing an existing shared buffer.
- UStringImpl(UChar* data, int length, PassRefPtr<SharedUChar> sharedBuffer)
+ UStringImpl(UChar* data, unsigned length, PassRefPtr<SharedUChar> sharedBuffer)
: m_data(data)
, m_bufferShared(sharedBuffer.releaseRef())
, m_length(length)
@@ -220,13 +220,13 @@ private:
~UStringImpl();
// This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings.
- static const int s_minLengthToShare = 10;
+ static const unsigned s_minLengthToShare = 10;
static const unsigned s_copyCharsInlineCutOff = 20;
// We initialize and increment/decrement the refCount for all normal (non-static) strings by the value 2.
// We initialize static strings with an odd number (specifically, 1), such that the refCount cannot reach zero.
static const unsigned s_refCountMask = 0xFFFFFFF0;
- static const int s_refCountIncrement = 0x20;
- static const int s_refCountFlagStatic = 0x10;
+ static const unsigned s_refCountIncrement = 0x20;
+ static const unsigned s_refCountFlagStatic = 0x10;
static const unsigned s_refCountFlagHasReportedCost = 0x8;
static const unsigned s_refCountFlagIsIdentifier = 0x4;
static const unsigned s_refCountMaskBufferOwnership = 0x3;
@@ -244,7 +244,7 @@ private:
UStringImpl* m_bufferSubstring;
SharedUChar* m_bufferShared;
};
- int m_length;
+ unsigned m_length;
unsigned m_refCountAndFlags;
mutable unsigned m_hash;
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 979ff11..e92dabf 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,14 @@
+2010-02-15 Gavin Barraclough <barraclough at apple.com>
+
+ Reviewed by Geoff Garen.
+
+ Bug 34952 - String lengths in UString should be unsigned.
+ This matches WebCore::StringImpl, and better unifies behaviour throughout JSC.
+
+ * bindings/js/JSDOMWindowCustom.cpp:
+ (WebCore::JSDOMWindow::atob):
+ (WebCore::JSDOMWindow::btoa):
+
2010-02-15 Gustavo Noronha Silva <gustavo.noronha at collabora.co.uk>
Reviewed by Xan Lopez.
diff --git a/WebCore/bindings/js/JSDOMWindowCustom.cpp b/WebCore/bindings/js/JSDOMWindowCustom.cpp
index b8cd1dc..82fa227 100644
--- a/WebCore/bindings/js/JSDOMWindowCustom.cpp
+++ b/WebCore/bindings/js/JSDOMWindowCustom.cpp
@@ -954,7 +954,7 @@ JSValue JSDOMWindow::atob(ExecState* exec, const ArgList& args)
}
Vector<char> in(s.size());
- for (int i = 0; i < s.size(); ++i)
+ for (unsigned i = 0; i < s.size(); ++i)
in[i] = static_cast<char>(s.data()[i]);
Vector<char> out;
@@ -980,7 +980,7 @@ JSValue JSDOMWindow::btoa(ExecState* exec, const ArgList& args)
}
Vector<char> in(s.size());
- for (int i = 0; i < s.size(); ++i)
+ for (unsigned i = 0; i < s.size(); ++i)
in[i] = static_cast<char>(s.data()[i]);
Vector<char> out;
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list