From 4576aa36e9a9671459299c7963ac95aa94beaea9 Mon Sep 17 00:00:00 2001 From: "Shimeng (Simon) Wang" Date: Tue, 7 Dec 2010 17:22:45 -0800 Subject: Merge WebKit at r73109: Initial merge by git. Change-Id: I61f1a66d9642e3d8405d3ac6ccab2a53421c75d8 --- JavaScriptCore/wtf/Assertions.cpp | 4 +- JavaScriptCore/wtf/Assertions.h | 5 +- JavaScriptCore/wtf/BumpPointerAllocator.h | 5 +- JavaScriptCore/wtf/DateMath.cpp | 4 +- JavaScriptCore/wtf/DateMath.h | 7 ++ JavaScriptCore/wtf/FixedArray.h | 9 +- JavaScriptCore/wtf/OSAllocator.h | 46 ++++++++ JavaScriptCore/wtf/OSAllocatorPosix.cpp | 87 ++++++++++++++ JavaScriptCore/wtf/OSAllocatorSymbian.cpp | 60 ++++++++++ JavaScriptCore/wtf/OSAllocatorWin.cpp | 64 ++++++++++ JavaScriptCore/wtf/PageAllocation.h | 19 ++- JavaScriptCore/wtf/Platform.h | 14 +-- JavaScriptCore/wtf/StdLibExtras.h | 2 +- JavaScriptCore/wtf/Vector3.h | 138 ---------------------- JavaScriptCore/wtf/text/CString.cpp | 7 +- JavaScriptCore/wtf/text/StringImpl.cpp | 9 +- JavaScriptCore/wtf/text/StringImpl.h | 5 +- JavaScriptCore/wtf/unicode/UTF8.cpp | 90 ++++++++------ JavaScriptCore/wtf/unicode/UnicodeMacrosFromICU.h | 31 ++++- JavaScriptCore/wtf/unicode/glib/UnicodeGLib.cpp | 117 ++++++++---------- JavaScriptCore/wtf/wtf.pri | 3 + 21 files changed, 445 insertions(+), 281 deletions(-) create mode 100644 JavaScriptCore/wtf/OSAllocator.h create mode 100644 JavaScriptCore/wtf/OSAllocatorPosix.cpp create mode 100644 JavaScriptCore/wtf/OSAllocatorSymbian.cpp create mode 100644 JavaScriptCore/wtf/OSAllocatorWin.cpp delete mode 100644 JavaScriptCore/wtf/Vector3.h (limited to 'JavaScriptCore/wtf') diff --git a/JavaScriptCore/wtf/Assertions.cpp b/JavaScriptCore/wtf/Assertions.cpp index 9222c1d..1841150 100644 --- a/JavaScriptCore/wtf/Assertions.cpp +++ b/JavaScriptCore/wtf/Assertions.cpp @@ -50,7 +50,7 @@ #endif #if PLATFORM(BREWMP) -#include +#include #include #endif @@ -76,7 +76,7 @@ static void printLog(const Vector& buffer) const char* end = buffer.data() + buffer.size(); while (p < end) { strncpy(printBuffer, p, printBufferSize); - DBGPRINTF(printBuffer); + dbg_Message(printBuffer, DBG_MSG_LEVEL_HIGH, __FILE__, __LINE__); p += printBufferSize; } } diff --git a/JavaScriptCore/wtf/Assertions.h b/JavaScriptCore/wtf/Assertions.h index 2907d04..3f3af72 100644 --- a/JavaScriptCore/wtf/Assertions.h +++ b/JavaScriptCore/wtf/Assertions.h @@ -56,7 +56,8 @@ #endif #if PLATFORM(BREWMP) -#include +#include +#include #endif #ifdef NDEBUG @@ -169,7 +170,7 @@ void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChann } while(false) #elif PLATFORM(BREWMP) #define CRASH() do { \ - DBGPRINTF_FATAL("WebKit CRASH"); \ + dbg_Message("WebKit CRASH", DBG_MSG_LEVEL_FATAL, __FILE__, __LINE__); \ *(int *)(uintptr_t)0xbbadbeef = 0; \ ((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \ } while(false) diff --git a/JavaScriptCore/wtf/BumpPointerAllocator.h b/JavaScriptCore/wtf/BumpPointerAllocator.h index 3deefe6..682283c 100644 --- a/JavaScriptCore/wtf/BumpPointerAllocator.h +++ b/JavaScriptCore/wtf/BumpPointerAllocator.h @@ -138,10 +138,7 @@ private: void destroy() { - // 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(); + m_allocation.deallocate(); } static BumpPointerPool* ensureCapacityCrossPool(BumpPointerPool* previousPool, size_t size) diff --git a/JavaScriptCore/wtf/DateMath.cpp b/JavaScriptCore/wtf/DateMath.cpp index f3627e6..675f093 100644 --- a/JavaScriptCore/wtf/DateMath.cpp +++ b/JavaScriptCore/wtf/DateMath.cpp @@ -379,7 +379,7 @@ int equivalentYearForDST(int year) return year; } -static int32_t calculateUTCOffset() +int32_t calculateUTCOffset() { #if PLATFORM(BREWMP) time_t localTime = static_cast(currentTime()); @@ -449,7 +449,7 @@ static double calculateDSTOffsetSimple(double localTimeSeconds, double utcOffset } // Get the DST offset, given a time in UTC -static double calculateDSTOffset(double ms, double utcOffset) +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 be51947..cb84708 100644 --- a/JavaScriptCore/wtf/DateMath.h +++ b/JavaScriptCore/wtf/DateMath.h @@ -84,6 +84,10 @@ 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; @@ -92,10 +96,13 @@ 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/FixedArray.h b/JavaScriptCore/wtf/FixedArray.h index 66f2327..c67d18c 100644 --- a/JavaScriptCore/wtf/FixedArray.h +++ b/JavaScriptCore/wtf/FixedArray.h @@ -29,7 +29,8 @@ #include namespace WTF { -template class FixedArray { + +template class FixedArray { public: T& operator[](size_t i) { @@ -44,10 +45,14 @@ public: } T* data() { return m_data; } + size_t size() const { return Size; } + private: T m_data[Size]; }; -} + +} // namespace WTF + using WTF::FixedArray; #endif // FixedArray_h diff --git a/JavaScriptCore/wtf/OSAllocator.h b/JavaScriptCore/wtf/OSAllocator.h new file mode 100644 index 0000000..9d80714 --- /dev/null +++ b/JavaScriptCore/wtf/OSAllocator.h @@ -0,0 +1,46 @@ +/* + * 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 new file mode 100644 index 0000000..d1d4af5 --- /dev/null +++ b/JavaScriptCore/wtf/OSAllocatorPosix.cpp @@ -0,0 +1,87 @@ +/* + * 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 +#include +#include +#include + +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 new file mode 100644 index 0000000..c1cc08c --- /dev/null +++ b/JavaScriptCore/wtf/OSAllocatorSymbian.cpp @@ -0,0 +1,60 @@ +/* + * 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 + +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 new file mode 100644 index 0000000..384fe13 --- /dev/null +++ b/JavaScriptCore/wtf/OSAllocatorWin.cpp @@ -0,0 +1,64 @@ +/* + * 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 26d53a5..c13821c 100644 --- a/JavaScriptCore/wtf/PageAllocation.h +++ b/JavaScriptCore/wtf/PageAllocation.h @@ -29,6 +29,7 @@ #include #include #include +#include #if OS(DARWIN) #include @@ -266,9 +267,11 @@ inline PageAllocation PageAllocation::systemAllocateAligned(size_t size, Usage u inline void PageAllocation::systemDeallocate(bool) { - int result = munmap(m_base, m_size); + void* tmp = 0; + std::swap(tmp, m_base); + + int result = munmap(tmp, m_size); ASSERT_UNUSED(result, !result); - m_base = 0; } inline size_t PageAllocation::systemPageSize() @@ -303,14 +306,16 @@ 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(m_base, m_size, MEM_DECOMMIT); + VirtualFree(tmp, m_size, MEM_DECOMMIT); #else UNUSED_PARAM(committed); #endif - VirtualFree(m_base, 0, MEM_RELEASE); - m_base = 0; + VirtualFree(tmp, 0, MEM_RELEASE); } inline size_t PageAllocation::systemPageSize() @@ -338,9 +343,11 @@ 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/Platform.h b/JavaScriptCore/wtf/Platform.h index 84f03de..221cda6 100644 --- a/JavaScriptCore/wtf/Platform.h +++ b/JavaScriptCore/wtf/Platform.h @@ -541,6 +541,7 @@ #define WTF_USE_ICCJPEG 1 #else #define WTF_PLATFORM_SKIA 1 +#define WTF_USE_CHROMIUM_NET 1 #endif #endif @@ -665,7 +666,7 @@ #endif #endif -#if PLATFORM(WIN) +#if PLATFORM(WIN) && !OS(WINCE) #define WTF_PLATFORM_CF 1 #define WTF_USE_PTHREADS 0 #endif @@ -994,7 +995,7 @@ /* Configure the JIT */ #if ENABLE(JIT) - #if CPU(ARM_TRADITIONAL) + #if CPU(ARM) #if !defined(ENABLE_JIT_USE_SOFT_MODULO) && WTF_ARM_ARCH_AT_LEAST(5) #define ENABLE_JIT_USE_SOFT_MODULO 1 #endif @@ -1034,16 +1035,10 @@ #define ENABLE_REGEXP_TRACING 0 /* Yet Another Regex Runtime - turned on by default for JIT enabled ports. */ -#if ENABLE(JIT) && !defined(ENABLE_YARR) && !defined(ENABLE_YARR_JIT) -#define ENABLE_YARR 1 +#if ENABLE(JIT) && !defined(ENABLE_YARR_JIT) #define ENABLE_YARR_JIT 1 #endif -/* Sanity Check */ -#if ENABLE(YARR_JIT) && !ENABLE(YARR) -#error "YARR_JIT requires YARR" -#endif - #if ENABLE(JIT) || ENABLE(YARR_JIT) #define ENABLE_ASSEMBLER 1 #endif @@ -1141,4 +1136,3 @@ #endif #endif /* WTF_Platform_h */ - diff --git a/JavaScriptCore/wtf/StdLibExtras.h b/JavaScriptCore/wtf/StdLibExtras.h index fd7ada2..4bb0076 100644 --- a/JavaScriptCore/wtf/StdLibExtras.h +++ b/JavaScriptCore/wtf/StdLibExtras.h @@ -61,7 +61,7 @@ * - https://bugs.webkit.org/show_bug.cgi?id=38045 * - http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43976 */ -#if CPU(ARM) && COMPILER(GCC) +#if (CPU(ARM) || CPU(MIPS)) && COMPILER(GCC) template bool isPointerTypeAlignmentOkay(Type* ptr) { diff --git a/JavaScriptCore/wtf/Vector3.h b/JavaScriptCore/wtf/Vector3.h deleted file mode 100644 index 1850929..0000000 --- a/JavaScriptCore/wtf/Vector3.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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 - -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 db6443f..981d77a 100644 --- a/JavaScriptCore/wtf/text/CString.cpp +++ b/JavaScriptCore/wtf/text/CString.cpp @@ -49,8 +49,11 @@ void CString::init(const char* str, size_t length) if (!str) return; - if (length >= numeric_limits::max()) - CRASH(); + // 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::max()); m_buffer = CStringBuffer::create(length + 1); memcpy(m_buffer->mutableData(), str, length); diff --git a/JavaScriptCore/wtf/text/StringImpl.cpp b/JavaScriptCore/wtf/text/StringImpl.cpp index 1c4de66..c83ec42 100644 --- a/JavaScriptCore/wtf/text/StringImpl.cpp +++ b/JavaScriptCore/wtf/text/StringImpl.cpp @@ -270,12 +270,17 @@ PassRefPtr StringImpl::upper() return newImpl.release(); } -PassRefPtr StringImpl::secure(UChar character) +PassRefPtr StringImpl::secure(UChar character, LastCharacterBehavior behavior) { + if (!m_length) + return this; + UChar* data; RefPtr newImpl = createUninitialized(m_length, data); - for (unsigned i = 0; i < m_length; ++i) + unsigned lastCharacterIndex = m_length - 1; + for (unsigned i = 0; i < lastCharacterIndex; ++i) data[i] = character; + data[lastCharacterIndex] = (behavior == ObscureLastCharacter) ? character : m_data[lastCharacterIndex]; return newImpl.release(); } diff --git a/JavaScriptCore/wtf/text/StringImpl.h b/JavaScriptCore/wtf/text/StringImpl.h index 8f0af52..99d0e9d 100644 --- a/JavaScriptCore/wtf/text/StringImpl.h +++ b/JavaScriptCore/wtf/text/StringImpl.h @@ -284,7 +284,10 @@ public: PassRefPtr lower(); PassRefPtr upper(); - PassRefPtr secure(UChar aChar); + + enum LastCharacterBehavior { ObscureLastCharacter, DisplayLastCharacter }; + + PassRefPtr secure(UChar, LastCharacterBehavior = ObscureLastCharacter); PassRefPtr foldCase(); PassRefPtr stripWhiteSpace(); diff --git a/JavaScriptCore/wtf/unicode/UTF8.cpp b/JavaScriptCore/wtf/unicode/UTF8.cpp index 40c5609..ca4fc1c 100644 --- a/JavaScriptCore/wtf/unicode/UTF8.cpp +++ b/JavaScriptCore/wtf/unicode/UTF8.cpp @@ -26,9 +26,14 @@ #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) @@ -44,12 +49,12 @@ inline int inlineUTF8SequenceLengthNonASCII(char b0) inline int inlineUTF8SequenceLength(char b0) { - return (b0 & 0x80) == 0 ? 1 : inlineUTF8SequenceLengthNonASCII(b0); + return isASCII(b0) ? 1 : inlineUTF8SequenceLengthNonASCII(b0); } int UTF8SequenceLength(char b0) { - return (b0 & 0x80) == 0 ? 1 : inlineUTF8SequenceLengthNonASCII(b0); + return isASCII(b0) ? 1 : inlineUTF8SequenceLengthNonASCII(b0); } int decodeUTF8Sequence(const char* sequence) @@ -172,7 +177,7 @@ ConversionResult convertUTF16ToUTF8( bytesToWrite = 4; } else { bytesToWrite = 3; - ch = 0xFFFD; + ch = replacementCharacter; } target += bytesToWrite; @@ -231,6 +236,23 @@ 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(*sequence++); character <<= 6; + case 5: character += static_cast(*sequence++); character <<= 6; + case 4: character += static_cast(*sequence++); character <<= 6; + case 3: character += static_cast(*sequence++); character <<= 6; + case 2: character += static_cast(*sequence++); character <<= 6; + case 1: character += static_cast(*sequence++); + } + + return character - offsetsFromUTF8[length - 1]; +} + ConversionResult convertUTF8ToUTF16( const char** sourceStart, const char* sourceEnd, UChar** targetStart, UChar* targetEnd, bool strict) @@ -239,60 +261,52 @@ ConversionResult convertUTF8ToUTF16( const char* source = *sourceStart; UChar* target = *targetStart; while (source < sourceEnd) { - UChar32 ch = 0; - int extraBytesToRead = inlineUTF8SequenceLength(*source) - 1; - if (source + extraBytesToRead >= sourceEnd) { + int utf8SequenceLength = inlineUTF8SequenceLength(*source); + if (sourceEnd - source < utf8SequenceLength) { result = sourceExhausted; break; } // Do this check whether lenient or strict - if (!isLegalUTF8(reinterpret_cast(source), extraBytesToRead + 1)) { + if (!isLegalUTF8(reinterpret_cast(source), utf8SequenceLength)) { result = sourceIllegal; break; } - // The cases all fall through. - switch (extraBytesToRead) { - case 5: ch += static_cast(*source++); ch <<= 6; // remember, illegal UTF-8 - case 4: ch += static_cast(*source++); ch <<= 6; // remember, illegal UTF-8 - case 3: ch += static_cast(*source++); ch <<= 6; - case 2: ch += static_cast(*source++); ch <<= 6; - case 1: ch += static_cast(*source++); ch <<= 6; - case 0: ch += static_cast(*source++); - } - ch -= offsetsFromUTF8[extraBytesToRead]; + + UChar32 character = readUTF8Sequence(source, utf8SequenceLength); if (target >= targetEnd) { - source -= (extraBytesToRead + 1); // Back up source pointer! - result = targetExhausted; break; + source -= utf8SequenceLength; // Back up source pointer! + result = targetExhausted; + break; } - if (ch <= 0xFFFF) { + + if (U_IS_BMP(character)) { // UTF-16 surrogate values are illegal in UTF-32 - if (ch >= 0xD800 && ch <= 0xDFFF) { + if (U_IS_SURROGATE(character)) { if (strict) { - source -= (extraBytesToRead + 1); // return to the illegal value itself + source -= utf8SequenceLength; // return to the illegal value itself result = sourceIllegal; break; } else - *target++ = 0xFFFD; + *target++ = replacementCharacter; } else - *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++ = character; // normal case + } else if (U_IS_SUPPLEMENTARY(character)) { // target is a character in range 0xFFFF - 0x10FFFF if (target + 1 >= targetEnd) { - source -= (extraBytesToRead + 1); // Back up source pointer! + source -= utf8SequenceLength; // Back up source pointer! result = targetExhausted; break; } - ch -= 0x0010000UL; - *target++ = (UChar)((ch >> 10) + 0xD800); - *target++ = (UChar)((ch & 0x03FF) + 0xDC00); + *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; } } *sourceStart = source; @@ -300,5 +314,5 @@ ConversionResult convertUTF8ToUTF16( return result; } -} -} +} // namespace Unicode +} // namespace WTF diff --git a/JavaScriptCore/wtf/unicode/UnicodeMacrosFromICU.h b/JavaScriptCore/wtf/unicode/UnicodeMacrosFromICU.h index f865ef1..8959912 100644 --- a/JavaScriptCore/wtf/unicode/UnicodeMacrosFromICU.h +++ b/JavaScriptCore/wtf/unicode/UnicodeMacrosFromICU.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 1999-2004, International Business Machines Corporation and others. All Rights Reserved. * Copyright (C) 2006 George Staikos * Copyright (C) 2006 Alexey Proskuryakov * Copyright (C) 2007 Apple Computer, Inc. All rights reserved. @@ -38,11 +39,28 @@ #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)) { \ @@ -54,6 +72,12 @@ } \ } +#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)) { \ @@ -65,7 +89,12 @@ } \ } +#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/unicode/glib/UnicodeGLib.cpp b/JavaScriptCore/wtf/unicode/glib/UnicodeGLib.cpp index e20c376..a01c3ee 100644 --- a/JavaScriptCore/wtf/unicode/glib/UnicodeGLib.cpp +++ b/JavaScriptCore/wtf/unicode/glib/UnicodeGLib.cpp @@ -1,6 +1,7 @@ /* * Copyright (C) 2008 Jürg Billeter * Copyright (C) 2008 Dominik Röttsches + * Copyright (C) 2010 Igalia S.L. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -22,6 +23,11 @@ #include "config.h" #include "UnicodeGLib.h" +#include +#include + +#define UTF8_IS_SURROGATE(character) (character >= 0x10000 && character <= 0x10FFFF) + namespace WTF { namespace Unicode { @@ -43,100 +49,71 @@ UChar32 foldCase(UChar32 ch) return *ucs4Result; } -int foldCase(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) +static int getUTF16LengthFromUTF8(const gchar* utf8String, int length) { - *error = false; - GOwnPtr gerror; + int utf16Length = 0; + const gchar* inputString = utf8String; - GOwnPtr utf8src; - utf8src.set(g_utf16_to_utf8(src, srcLength, 0, 0, &gerror.outPtr())); - if (gerror) { - *error = true; - return -1; - } - - GOwnPtr utf8result; - utf8result.set(g_utf8_casefold(utf8src.get(), -1)); + while ((utf8String + length - inputString > 0) && *inputString) { + gunichar character = g_utf8_get_char(inputString); - long utf16resultLength = -1; - GOwnPtr utf16result; - utf16result.set(g_utf8_to_utf16(utf8result.get(), -1, 0, &utf16resultLength, &gerror.outPtr())); - if (gerror) { - *error = true; - return -1; + utf16Length += UTF8_IS_SURROGATE(character) ? 2 : 1; + inputString = g_utf8_next_char(inputString); } - if (utf16resultLength > resultLength) { - *error = true; - return utf16resultLength; - } - memcpy(result, utf16result.get(), utf16resultLength * sizeof(UChar)); - - return utf16resultLength; + return utf16Length; } -int toLower(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) +typedef gchar* (*UTF8CaseFunction)(const gchar*, gssize length); + +static int convertCase(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error, UTF8CaseFunction caseFunction) { *error = false; - GOwnPtr gerror; - GOwnPtr utf8src; - utf8src.set(g_utf16_to_utf8(src, srcLength, 0, 0, &gerror.outPtr())); - if (gerror) { + // Allocate a buffer big enough to hold all the characters. + Vector buffer(srcLength * 3); + char* utf8Target = buffer.data(); + const UChar* utf16Source = src; + ConversionResult conversionResult = convertUTF16ToUTF8(&utf16Source, utf16Source + srcLength, &utf8Target, utf8Target + buffer.size(), true); + if (conversionResult != conversionOK) { *error = true; return -1; } + buffer.shrink(utf8Target - buffer.data()); - GOwnPtr utf8result; - utf8result.set(g_utf8_strdown(utf8src.get(), -1)); + GOwnPtr utf8Result(caseFunction(buffer.data(), buffer.size())); + long utf8ResultLength = strlen(utf8Result.get()); - long utf16resultLength = -1; - GOwnPtr utf16result; - utf16result.set(g_utf8_to_utf16(utf8result.get(), -1, 0, &utf16resultLength, &gerror.outPtr())); - if (gerror) { + // Calculate the destination buffer size. + int realLength = getUTF16LengthFromUTF8(utf8Result.get(), utf8ResultLength); + if (realLength > resultLength) { *error = true; - return -1; + return realLength; } - if (utf16resultLength > resultLength) { + // Convert the result to UTF-16. + UChar* utf16Target = result; + const char* utf8Source = utf8Result.get(); + conversionResult = convertUTF8ToUTF16(&utf8Source, utf8Source + utf8ResultLength, &utf16Target, utf16Target + resultLength, true); + long utf16ResultLength = utf16Target - result; + if (conversionResult != conversionOK) *error = true; - return utf16resultLength; - } - memcpy(result, utf16result.get(), utf16resultLength * sizeof(UChar)); - return utf16resultLength; + return utf16ResultLength <= 0 ? -1 : utf16ResultLength; } - -int toUpper(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) +int foldCase(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) { - *error = false; - GOwnPtr gerror; - - GOwnPtr utf8src; - utf8src.set(g_utf16_to_utf8(src, srcLength, 0, 0, &gerror.outPtr())); - if (gerror) { - *error = true; - return -1; - } - - GOwnPtr utf8result; - utf8result.set(g_utf8_strup(utf8src.get(), -1)); - - long utf16resultLength = -1; - GOwnPtr utf16result; - utf16result.set(g_utf8_to_utf16(utf8result.get(), -1, 0, &utf16resultLength, &gerror.outPtr())); - if (gerror) { - *error = true; - return -1; - } + return convertCase(result, resultLength, src, srcLength, error, g_utf8_casefold); +} - if (utf16resultLength > resultLength) { - *error = true; - return utf16resultLength; - } - memcpy(result, utf16result.get(), utf16resultLength * sizeof(UChar)); +int toLower(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) +{ + return convertCase(result, resultLength, src, srcLength, error, g_utf8_strdown); +} - return utf16resultLength; +int toUpper(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error) +{ + return convertCase(result, resultLength, src, srcLength, error, g_utf8_strup); } Direction direction(UChar32 c) diff --git a/JavaScriptCore/wtf/wtf.pri b/JavaScriptCore/wtf/wtf.pri index 1780334..0f7241c 100644 --- a/JavaScriptCore/wtf/wtf.pri +++ b/JavaScriptCore/wtf/wtf.pri @@ -13,6 +13,9 @@ 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 \ -- cgit v1.1