diff options
author | Steve Block <steveblock@google.com> | 2011-01-05 12:15:11 +0000 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-01-06 14:14:00 +0000 |
commit | d06194330da2bb8da887d2e1adeacb3a5c1504b2 (patch) | |
tree | e0af8413af65a8e30630563441af7bdb8478e513 /JavaScriptCore/wtf | |
parent | 419a5cf2f8db6ca014df624865197ffb82caad37 (diff) | |
download | external_webkit-d06194330da2bb8da887d2e1adeacb3a5c1504b2.zip external_webkit-d06194330da2bb8da887d2e1adeacb3a5c1504b2.tar.gz external_webkit-d06194330da2bb8da887d2e1adeacb3a5c1504b2.tar.bz2 |
Merge WebKit at r72805: Initial merge by Git
Note that this is a backwards merge from Chromium release 9.0.600.0
to 9.0.597.0, to align with the Chromium 9 stable release branch.
Change-Id: I5d2bb4e8cee9d39ae8485abf48bdb55ecf8b3790
Diffstat (limited to 'JavaScriptCore/wtf')
-rw-r--r-- | JavaScriptCore/wtf/BumpPointerAllocator.h | 5 | ||||
-rw-r--r-- | JavaScriptCore/wtf/DateMath.cpp | 4 | ||||
-rw-r--r-- | JavaScriptCore/wtf/DateMath.h | 7 | ||||
-rw-r--r-- | JavaScriptCore/wtf/OSAllocator.h | 46 | ||||
-rw-r--r-- | JavaScriptCore/wtf/OSAllocatorPosix.cpp | 87 | ||||
-rw-r--r-- | JavaScriptCore/wtf/OSAllocatorSymbian.cpp | 60 | ||||
-rw-r--r-- | JavaScriptCore/wtf/OSAllocatorWin.cpp | 64 | ||||
-rw-r--r-- | JavaScriptCore/wtf/PageAllocation.h | 19 | ||||
-rw-r--r-- | JavaScriptCore/wtf/Vector3.h | 138 | ||||
-rw-r--r-- | JavaScriptCore/wtf/text/CString.cpp | 7 | ||||
-rw-r--r-- | JavaScriptCore/wtf/unicode/UTF8.cpp | 90 | ||||
-rw-r--r-- | JavaScriptCore/wtf/unicode/UnicodeMacrosFromICU.h | 31 | ||||
-rw-r--r-- | JavaScriptCore/wtf/wtf.pri | 3 |
13 files changed, 191 insertions, 370 deletions
diff --git a/JavaScriptCore/wtf/BumpPointerAllocator.h b/JavaScriptCore/wtf/BumpPointerAllocator.h index 682283c..3deefe6 100644 --- a/JavaScriptCore/wtf/BumpPointerAllocator.h +++ b/JavaScriptCore/wtf/BumpPointerAllocator.h @@ -138,7 +138,10 @@ private: void destroy() { - m_allocation.deallocate(); + // Don't call deallocate on allocation, because allocation is *inside* allocation, + // and it will get deallocated before deallocate has completed! + PageAllocation allocation = m_allocation; + allocation.deallocate(); } static BumpPointerPool* ensureCapacityCrossPool(BumpPointerPool* previousPool, size_t size) diff --git a/JavaScriptCore/wtf/DateMath.cpp b/JavaScriptCore/wtf/DateMath.cpp index 675f093..f3627e6 100644 --- a/JavaScriptCore/wtf/DateMath.cpp +++ b/JavaScriptCore/wtf/DateMath.cpp @@ -379,7 +379,7 @@ int equivalentYearForDST(int year) return year; } -int32_t calculateUTCOffset() +static int32_t calculateUTCOffset() { #if PLATFORM(BREWMP) time_t localTime = static_cast<time_t>(currentTime()); @@ -449,7 +449,7 @@ static double calculateDSTOffsetSimple(double localTimeSeconds, double utcOffset } // Get the DST offset, given a time in UTC -double calculateDSTOffset(double ms, double utcOffset) +static double calculateDSTOffset(double ms, double utcOffset) { // On Mac OS X, the call to localtime (see calculateDSTOffsetSimple) will return historically accurate // DST information (e.g. New Zealand did not have DST from 1946 to 1974) however the JavaScript diff --git a/JavaScriptCore/wtf/DateMath.h b/JavaScriptCore/wtf/DateMath.h index cb84708..be51947 100644 --- a/JavaScriptCore/wtf/DateMath.h +++ b/JavaScriptCore/wtf/DateMath.h @@ -84,10 +84,6 @@ int dayInYear(double ms, int year); int monthFromDayInYear(int dayInYear, bool leapYear); int dayInMonthFromDayInYear(int dayInYear, bool leapYear); -// Returns offset milliseconds for UTC and DST. -int32_t calculateUTCOffset(); -double calculateDSTOffset(double ms, double utcOffset); - } // namespace WTF using WTF::dateToDaysFrom1970; @@ -96,13 +92,10 @@ using WTF::dayInYear; using WTF::minutesPerHour; using WTF::monthFromDayInYear; using WTF::msPerDay; -using WTF::msPerMinute; using WTF::msPerSecond; using WTF::msToYear; using WTF::secondsPerMinute; using WTF::parseDateFromNullTerminatedCharacters; -using WTF::calculateUTCOffset; -using WTF::calculateDSTOffset; #if USE(JSC) namespace JSC { diff --git a/JavaScriptCore/wtf/OSAllocator.h b/JavaScriptCore/wtf/OSAllocator.h deleted file mode 100644 index 9d80714..0000000 --- a/JavaScriptCore/wtf/OSAllocator.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OSAllocator_h -#define OSAllocator_h - -namespace WTF { - -class OSAllocator { -public: - static void* reserve(size_t); - static void* reserveAndCommit(size_t); - - static void commit(void*, size_t); - static void decommit(void*, size_t); - - static void release(void*, size_t); -}; - -} // namespace WTF - -using WTF::OSAllocator; - -#endif // OSAllocator_h diff --git a/JavaScriptCore/wtf/OSAllocatorPosix.cpp b/JavaScriptCore/wtf/OSAllocatorPosix.cpp deleted file mode 100644 index d1d4af5..0000000 --- a/JavaScriptCore/wtf/OSAllocatorPosix.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "OSAllocator.h" - -#if OS(UNIX) && !OS(SYMBIAN) - -#include <errno.h> -#include <sys/mman.h> -#include <wtf/Assertions.h> -#include <wtf/UnusedParam.h> - -namespace WTF { - -void* OSAllocator::reserve(size_t bytes) -{ - // From a bookkeeping perspective, POSIX reservations start out in the committed state. - void* result = mmap(0, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); - if (result == MAP_FAILED) - CRASH(); -#if HAVE(MADV_FREE_REUSE) - while (madvise(result, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { } -#endif - return result; -} - -void* OSAllocator::reserveAndCommit(size_t bytes) -{ - // From a bookkeeping perspective, POSIX reservations start out in the committed state. - return reserve(bytes); -} - -void OSAllocator::commit(void* address, size_t bytes) -{ -#if HAVE(MADV_FREE_REUSE) - while (madvise(address, bytes, MADV_FREE_REUSE) == -1 && errno == EAGAIN) { } -#else - UNUSED_PARAM(address); - UNUSED_PARAM(bytes); -#endif -} - -void OSAllocator::decommit(void* address, size_t bytes) -{ -#if HAVE(MADV_FREE_REUSE) - while (madvise(address, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { } -#elif HAVE(MADV_FREE) - while (madvise(address, bytes, MADV_FREE) == -1 && errno == EAGAIN) { } -#elif HAVE(MADV_DONTNEED) - while (madvise(address, bytes, MADV_DONTNEED) == -1 && errno == EAGAIN) { } -#else - UNUSED_PARAM(address); - UNUSED_PARAM(bytes); -#endif -} - -void OSAllocator::release(void* address, size_t bytes) -{ - munmap(address, bytes); -} - -} // namespace WTF - -#endif diff --git a/JavaScriptCore/wtf/OSAllocatorSymbian.cpp b/JavaScriptCore/wtf/OSAllocatorSymbian.cpp deleted file mode 100644 index c1cc08c..0000000 --- a/JavaScriptCore/wtf/OSAllocatorSymbian.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "OSAllocator.h" - -#if OS(SYMBIAN) - -#include <wtf/FastMalloc.h> - -namespace WTF { - -void* OSAllocator::reserve(size_t bytes) -{ - return fastMalloc(bytes); -} - -void* OSAllocator::reserveAndCommit(size_t bytes) -{ - return reserve(bytes); -} - -void OSAllocator::commit(void*, size_t) -{ -} - -void OSAllocator::decommit(void*, size_t) -{ -} - -void OSAllocator::release(void* address, size_t) -{ - fastFree(address); -} - -} // namespace WTF - -#endif diff --git a/JavaScriptCore/wtf/OSAllocatorWin.cpp b/JavaScriptCore/wtf/OSAllocatorWin.cpp deleted file mode 100644 index 384fe13..0000000 --- a/JavaScriptCore/wtf/OSAllocatorWin.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "OSAllocator.h" - -#if OS(WINDOWS) - -#include "windows.h" - -namespace WTF { - -void* OSAllocator::reserve(size_t bytes) -{ - return VirtualAlloc(0, bytes, MEM_RESERVE, PAGE_READWRITE); -} - -void* OSAllocator::reserveAndCommit(size_t bytes) -{ - return VirtualAlloc(0, bytes, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); -} - -void OSAllocator::commit(void* address, size_t bytes) -{ - VirtualAlloc(address, bytes, MEM_COMMIT, PAGE_READWRITE); -} - -void OSAllocator::decommit(void* address, size_t bytes) -{ - VirtualFree(address, bytes, MEM_DECOMMIT); -} - -void OSAllocator::release(void* address, size_t bytes) -{ - // According to http://msdn.microsoft.com/en-us/library/aa366892(VS.85).aspx, - // dwSize must be 0 if dwFreeType is MEM_RELEASE. - VirtualFree(address, 0, MEM_RELEASE); -} - -} // namespace WTF - -#endif diff --git a/JavaScriptCore/wtf/PageAllocation.h b/JavaScriptCore/wtf/PageAllocation.h index c13821c..26d53a5 100644 --- a/JavaScriptCore/wtf/PageAllocation.h +++ b/JavaScriptCore/wtf/PageAllocation.h @@ -29,7 +29,6 @@ #include <wtf/Assertions.h> #include <wtf/UnusedParam.h> #include <wtf/VMTags.h> -#include <algorithm> #if OS(DARWIN) #include <mach/mach_init.h> @@ -267,11 +266,9 @@ inline PageAllocation PageAllocation::systemAllocateAligned(size_t size, Usage u inline void PageAllocation::systemDeallocate(bool) { - void* tmp = 0; - std::swap(tmp, m_base); - - int result = munmap(tmp, m_size); + int result = munmap(m_base, m_size); ASSERT_UNUSED(result, !result); + m_base = 0; } inline size_t PageAllocation::systemPageSize() @@ -306,16 +303,14 @@ inline PageAllocation PageAllocation::systemAllocateAligned(size_t size, Usage u inline void PageAllocation::systemDeallocate(bool committed) { - void* tmp = 0; - std::swap(tmp, m_base); - #if OS(WINCE) if (committed) - VirtualFree(tmp, m_size, MEM_DECOMMIT); + VirtualFree(m_base, m_size, MEM_DECOMMIT); #else UNUSED_PARAM(committed); #endif - VirtualFree(tmp, 0, MEM_RELEASE); + VirtualFree(m_base, 0, MEM_RELEASE); + m_base = 0; } inline size_t PageAllocation::systemPageSize() @@ -343,11 +338,9 @@ inline PageAllocation PageAllocation::systemAllocate(size_t size, Usage usage, b inline void PageAllocation::systemDeallocate(bool) { - void* tmp = 0; - std::swap(tmp, m_base); - m_chunk->Close(); delete m_chunk; + m_base = 0; } inline size_t PageAllocation::systemPageSize() diff --git a/JavaScriptCore/wtf/Vector3.h b/JavaScriptCore/wtf/Vector3.h new file mode 100644 index 0000000..1850929 --- /dev/null +++ b/JavaScriptCore/wtf/Vector3.h @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WTF_Vector3_h +#define WTF_Vector3_h + +#include <math.h> + +namespace WTF { + +class Vector3 { +public: + Vector3() + : m_x(0.0) + , m_y(0.0) + , m_z(0.0) + { + } + + Vector3(double x, double y, double z) + : m_x(x) + , m_y(y) + , m_z(z) + { + } + + Vector3(const float p[3]) + : m_x(p[0]) + , m_y(p[1]) + , m_z(p[2]) + { + } + + Vector3(const double p[3]) + : m_x(p[0]) + , m_y(p[1]) + , m_z(p[2]) + { + } + + double abs() const + { + return sqrt(m_x * m_x + m_y * m_y + m_z * m_z); + } + + bool isZero() const + { + return !m_x && !m_y && !m_z; + } + + void normalize() + { + double absValue = abs(); + if (!absValue) + return; + + double k = 1.0 / absValue; + m_x *= k; + m_y *= k; + m_z *= k; + } + + double x() const { return m_x; } + double y() const { return m_y; } + double z() const { return m_z; } + +private: + double m_x; + double m_y; + double m_z; +}; + +inline Vector3 operator+(const Vector3& v1, const Vector3& v2) +{ + return Vector3(v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z()); +} + +inline Vector3 operator-(const Vector3& v1, const Vector3& v2) +{ + return Vector3(v1.x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z()); +} + +inline Vector3 operator*(double k, const Vector3& v) +{ + return Vector3(k * v.x(), k * v.y(), k * v.z()); +} + +inline Vector3 operator*(const Vector3& v, double k) +{ + return Vector3(k * v.x(), k * v.y(), k * v.z()); +} + +inline double dot(const Vector3& v1, const Vector3& v2) +{ + return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z(); +} + +inline Vector3 cross(const Vector3& v1, const Vector3& v2) +{ + double x3 = v1.y() * v2.z() - v1.z() * v2.y(); + double y3 = v1.z() * v2.x() - v1.x() * v2.z(); + double z3 = v1.x() * v2.y() - v1.y() * v2.x(); + return Vector3(x3, y3, z3); +} + +inline double distance(const Vector3& v1, const Vector3& v2) +{ + return (v1 - v2).abs(); +} + +} // WTF + +#endif // WTF_Vector3_h diff --git a/JavaScriptCore/wtf/text/CString.cpp b/JavaScriptCore/wtf/text/CString.cpp index 981d77a..db6443f 100644 --- a/JavaScriptCore/wtf/text/CString.cpp +++ b/JavaScriptCore/wtf/text/CString.cpp @@ -49,11 +49,8 @@ void CString::init(const char* str, size_t length) if (!str) return; - // We need to be sure we can add 1 to length without overflowing. - // Since the passed-in length is the length of an actual existing - // string, and we know the string doesn't occupy the entire address - // space, we can assert here and there's no need for a runtime check. - ASSERT(length < numeric_limits<size_t>::max()); + if (length >= numeric_limits<size_t>::max()) + CRASH(); m_buffer = CStringBuffer::create(length + 1); memcpy(m_buffer->mutableData(), str, length); diff --git a/JavaScriptCore/wtf/unicode/UTF8.cpp b/JavaScriptCore/wtf/unicode/UTF8.cpp index ca4fc1c..40c5609 100644 --- a/JavaScriptCore/wtf/unicode/UTF8.cpp +++ b/JavaScriptCore/wtf/unicode/UTF8.cpp @@ -26,14 +26,9 @@ #include "config.h" #include "UTF8.h" -#include "ASCIICType.h" - namespace WTF { namespace Unicode { -// FIXME: Use definition from CharacterNames.h. -const UChar replacementCharacter = 0xFFFD; - inline int inlineUTF8SequenceLengthNonASCII(char b0) { if ((b0 & 0xC0) != 0xC0) @@ -49,12 +44,12 @@ inline int inlineUTF8SequenceLengthNonASCII(char b0) inline int inlineUTF8SequenceLength(char b0) { - return isASCII(b0) ? 1 : inlineUTF8SequenceLengthNonASCII(b0); + return (b0 & 0x80) == 0 ? 1 : inlineUTF8SequenceLengthNonASCII(b0); } int UTF8SequenceLength(char b0) { - return isASCII(b0) ? 1 : inlineUTF8SequenceLengthNonASCII(b0); + return (b0 & 0x80) == 0 ? 1 : inlineUTF8SequenceLengthNonASCII(b0); } int decodeUTF8Sequence(const char* sequence) @@ -177,7 +172,7 @@ ConversionResult convertUTF16ToUTF8( bytesToWrite = 4; } else { bytesToWrite = 3; - ch = replacementCharacter; + ch = 0xFFFD; } target += bytesToWrite; @@ -236,23 +231,6 @@ static bool isLegalUTF8(const unsigned char* source, int length) static const UChar32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL, 0x03C82080UL, 0xFA082080UL, 0x82082080UL }; -static inline UChar32 readUTF8Sequence(const char*& sequence, unsigned length) -{ - UChar32 character = 0; - - // The cases all fall through. - switch (length) { - case 6: character += static_cast<unsigned char>(*sequence++); character <<= 6; - case 5: character += static_cast<unsigned char>(*sequence++); character <<= 6; - case 4: character += static_cast<unsigned char>(*sequence++); character <<= 6; - case 3: character += static_cast<unsigned char>(*sequence++); character <<= 6; - case 2: character += static_cast<unsigned char>(*sequence++); character <<= 6; - case 1: character += static_cast<unsigned char>(*sequence++); - } - - return character - offsetsFromUTF8[length - 1]; -} - ConversionResult convertUTF8ToUTF16( const char** sourceStart, const char* sourceEnd, UChar** targetStart, UChar* targetEnd, bool strict) @@ -261,52 +239,60 @@ ConversionResult convertUTF8ToUTF16( const char* source = *sourceStart; UChar* target = *targetStart; while (source < sourceEnd) { - int utf8SequenceLength = inlineUTF8SequenceLength(*source); - if (sourceEnd - source < utf8SequenceLength) { + UChar32 ch = 0; + int extraBytesToRead = inlineUTF8SequenceLength(*source) - 1; + if (source + extraBytesToRead >= sourceEnd) { result = sourceExhausted; break; } // Do this check whether lenient or strict - if (!isLegalUTF8(reinterpret_cast<const unsigned char*>(source), utf8SequenceLength)) { + if (!isLegalUTF8(reinterpret_cast<const unsigned char*>(source), extraBytesToRead + 1)) { result = sourceIllegal; break; } - - UChar32 character = readUTF8Sequence(source, utf8SequenceLength); + // The cases all fall through. + switch (extraBytesToRead) { + case 5: ch += static_cast<unsigned char>(*source++); ch <<= 6; // remember, illegal UTF-8 + case 4: ch += static_cast<unsigned char>(*source++); ch <<= 6; // remember, illegal UTF-8 + case 3: ch += static_cast<unsigned char>(*source++); ch <<= 6; + case 2: ch += static_cast<unsigned char>(*source++); ch <<= 6; + case 1: ch += static_cast<unsigned char>(*source++); ch <<= 6; + case 0: ch += static_cast<unsigned char>(*source++); + } + ch -= offsetsFromUTF8[extraBytesToRead]; if (target >= targetEnd) { - source -= utf8SequenceLength; // Back up source pointer! - result = targetExhausted; - break; + source -= (extraBytesToRead + 1); // Back up source pointer! + result = targetExhausted; break; } - - if (U_IS_BMP(character)) { + if (ch <= 0xFFFF) { // UTF-16 surrogate values are illegal in UTF-32 - if (U_IS_SURROGATE(character)) { + if (ch >= 0xD800 && ch <= 0xDFFF) { if (strict) { - source -= utf8SequenceLength; // return to the illegal value itself + source -= (extraBytesToRead + 1); // return to the illegal value itself result = sourceIllegal; break; } else - *target++ = replacementCharacter; + *target++ = 0xFFFD; } else - *target++ = character; // normal case - } else if (U_IS_SUPPLEMENTARY(character)) { + *target++ = (UChar)ch; // normal case + } else if (ch > 0x10FFFF) { + if (strict) { + result = sourceIllegal; + source -= (extraBytesToRead + 1); // return to the start + break; // Bail out; shouldn't continue + } else + *target++ = 0xFFFD; + } else { // target is a character in range 0xFFFF - 0x10FFFF if (target + 1 >= targetEnd) { - source -= utf8SequenceLength; // Back up source pointer! + source -= (extraBytesToRead + 1); // Back up source pointer! result = targetExhausted; break; } - *target++ = U16_LEAD(character); - *target++ = U16_TRAIL(character); - } else { - if (strict) { - source -= utf8SequenceLength; // return to the start - result = sourceIllegal; - break; // Bail out; shouldn't continue - } else - *target++ = replacementCharacter; + ch -= 0x0010000UL; + *target++ = (UChar)((ch >> 10) + 0xD800); + *target++ = (UChar)((ch & 0x03FF) + 0xDC00); } } *sourceStart = source; @@ -314,5 +300,5 @@ ConversionResult convertUTF8ToUTF16( return result; } -} // namespace Unicode -} // namespace WTF +} +} diff --git a/JavaScriptCore/wtf/unicode/UnicodeMacrosFromICU.h b/JavaScriptCore/wtf/unicode/UnicodeMacrosFromICU.h index 8959912..f865ef1 100644 --- a/JavaScriptCore/wtf/unicode/UnicodeMacrosFromICU.h +++ b/JavaScriptCore/wtf/unicode/UnicodeMacrosFromICU.h @@ -1,5 +1,4 @@ /* - * Copyright (C) 1999-2004, International Business Machines Corporation and others. All Rights Reserved. * Copyright (C) 2006 George Staikos <staikos@kde.org> * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> * Copyright (C) 2007 Apple Computer, Inc. All rights reserved. @@ -39,28 +38,11 @@ #define U16_TRAIL(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00) #define U16_LENGTH(c) ((uint32_t)(c) <= 0xffff ? 1 : 2) -#define U_IS_SUPPLEMENTARY(c) ((UChar32)((c)-0x10000)<=0xfffff) #define U_IS_SURROGATE(c) (((c)&0xfffff800)==0xd800) #define U16_IS_SINGLE(c) !U_IS_SURROGATE(c) #define U16_IS_SURROGATE(c) U_IS_SURROGATE(c) #define U16_IS_SURROGATE_LEAD(c) (((c)&0x400)==0) -#define U16_GET(s, start, i, length, c) { \ - (c)=(s)[i]; \ - if(U16_IS_SURROGATE(c)) { \ - uint16_t __c2; \ - if(U16_IS_SURROGATE_LEAD(c)) { \ - if((i)+1<(length) && U16_IS_TRAIL(__c2=(s)[(i)+1])) { \ - (c)=U16_GET_SUPPLEMENTARY((c), __c2); \ - } \ - } else { \ - if((i)-1>=(start) && U16_IS_LEAD(__c2=(s)[(i)-1])) { \ - (c)=U16_GET_SUPPLEMENTARY(__c2, (c)); \ - } \ - } \ - } \ -} - #define U16_PREV(s, start, i, c) { \ (c)=(s)[--(i)]; \ if(U16_IS_TRAIL(c)) { \ @@ -72,12 +54,6 @@ } \ } -#define U16_BACK_1(s, start, i) { \ - if(U16_IS_TRAIL((s)[--(i)]) && (i)>(start) && U16_IS_LEAD((s)[(i)-1])) { \ - --(i); \ - } \ -} - #define U16_NEXT(s, i, length, c) { \ (c)=(s)[(i)++]; \ if(U16_IS_LEAD(c)) { \ @@ -89,12 +65,7 @@ } \ } -#define U16_FWD_1(s, i, length) { \ - if(U16_IS_LEAD((s)[(i)++]) && (i)<(length) && U16_IS_TRAIL((s)[i])) { \ - ++(i); \ - } \ -} - #define U_MASK(x) ((uint32_t)1<<(x)) #endif + diff --git a/JavaScriptCore/wtf/wtf.pri b/JavaScriptCore/wtf/wtf.pri index 0f7241c..1780334 100644 --- a/JavaScriptCore/wtf/wtf.pri +++ b/JavaScriptCore/wtf/wtf.pri @@ -13,9 +13,6 @@ SOURCES += \ wtf/HashTable.cpp \ wtf/MD5.cpp \ wtf/MainThread.cpp \ - wtf/OSAllocatorPosix.cpp \ - wtf/OSAllocatorSymbian.cpp \ - wtf/OSAllocatorWin.cpp \ wtf/qt/MainThreadQt.cpp \ wtf/qt/StringQt.cpp \ wtf/qt/ThreadingQt.cpp \ |