Changeset 232089 in webkit
- Timestamp:
- May 22, 2018 4:54:16 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r232070 r232089 1 2018-05-22 Mark Lam <mark.lam@apple.com> 2 3 StringImpl utf8 conversion should not fail silently. 4 https://bugs.webkit.org/show_bug.cgi?id=185888 5 <rdar://problem/40464506> 6 7 Reviewed by Filip Pizlo. 8 9 * stress/regress-185888.js: Added. 10 1 11 2018-05-22 Keith Miller <keith_miller@apple.com> 2 12 -
trunk/Source/JavaScriptCore/ChangeLog
r232080 r232089 1 2018-05-22 Mark Lam <mark.lam@apple.com> 2 3 StringImpl utf8 conversion should not fail silently. 4 https://bugs.webkit.org/show_bug.cgi?id=185888 5 <rdar://problem/40464506> 6 7 Reviewed by Filip Pizlo. 8 9 * dfg/DFGLazyJSValue.cpp: 10 (JSC::DFG::LazyJSValue::dumpInContext const): 11 * runtime/DateConstructor.cpp: 12 (JSC::constructDate): 13 (JSC::dateParse): 14 * runtime/JSDateMath.cpp: 15 (JSC::parseDate): 16 * runtime/JSDateMath.h: 17 1 18 2018-05-22 Keith Miller <keith_miller@apple.com> 2 19 -
trunk/Source/JavaScriptCore/dfg/DFGLazyJSValue.cpp
r214571 r232089 251 251 out.print("Lazy:SingleCharacterString("); 252 252 out.printf("%04X", static_cast<unsigned>(character())); 253 out.print(" / ", StringImpl::utf8ForCharacters(&u.character, 1) , ")");253 out.print(" / ", StringImpl::utf8ForCharacters(&u.character, 1).value(), ")"); 254 254 return; 255 255 case KnownStringImpl: -
trunk/Source/JavaScriptCore/runtime/DateConstructor.cpp
r230369 r232089 1 1 /* 2 2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) 3 * Copyright (C) 2004-20 08, 2011, 2016Apple Inc. All rights reserved.3 * Copyright (C) 2004-2018 Apple Inc. All rights reserved. 4 4 * 5 5 * This library is free software; you can redistribute it and/or … … 137 137 JSValue primitive = arg0.toPrimitive(exec); 138 138 RETURN_IF_EXCEPTION(scope, nullptr); 139 if (primitive.isString()) 140 value = parseDate(vm, asString(primitive)->value(exec)); 141 else 139 if (primitive.isString()) { 140 value = parseDate(exec, vm, asString(primitive)->value(exec)); 141 RETURN_IF_EXCEPTION(scope, nullptr); 142 } else 142 143 value = primitive.toNumber(exec); 143 144 } … … 173 174 String dateStr = exec->argument(0).toWTFString(exec); 174 175 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 175 return JSValue::encode(jsNumber(parseDate(vm, dateStr))); 176 scope.release(); 177 return JSValue::encode(jsNumber(parseDate(exec, vm, dateStr))); 176 178 } 177 179 -
trunk/Source/JavaScriptCore/runtime/JSDateMath.cpp
r229209 r232089 1 1 /* 2 2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) 3 * Copyright (C) 2006 , 2007, 2012Apple Inc. All rights reserved.3 * Copyright (C) 2006-2018 Apple Inc. All rights reserved. 4 4 * Copyright (C) 2009 Google Inc. All rights reserved. 5 5 * Copyright (C) 2007-2009 Torch Mobile, Inc. … … 236 236 } 237 237 238 double parseDate(VM& vm, const String& date) 239 { 238 double parseDate(ExecState* exec, VM& vm, const String& date) 239 { 240 auto scope = DECLARE_THROW_SCOPE(vm); 241 240 242 if (date == vm.cachedDateString) 241 243 return vm.cachedDateStringValue; 242 double value = parseES5DateFromNullTerminatedCharacters(date.utf8().data()); 244 auto expectedString = date.tryGetUtf8(); 245 if (!expectedString) { 246 if (expectedString.error() == UTF8ConversionError::OutOfMemory) 247 throwOutOfMemoryError(exec, scope); 248 // https://tc39.github.io/ecma262/#sec-date-objects section 20.3.3.2 states that: 249 // "Unrecognizable Strings or dates containing illegal element values in the 250 // format String shall cause Date.parse to return NaN." 251 return std::numeric_limits<double>::quiet_NaN(); 252 } 253 254 auto dateUtf8 = expectedString.value(); 255 double value = parseES5DateFromNullTerminatedCharacters(dateUtf8.data()); 243 256 if (std::isnan(value)) 244 value = parseDateFromNullTerminatedCharacters(vm, date .utf8().data());257 value = parseDateFromNullTerminatedCharacters(vm, dateUtf8.data()); 245 258 vm.cachedDateString = date; 246 259 vm.cachedDateStringValue = value; -
trunk/Source/JavaScriptCore/runtime/JSDateMath.h
r206525 r232089 1 1 /* 2 2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) 3 * Copyright (C) 2006 , 2007Apple Inc. All rights reserved.3 * Copyright (C) 2006-2018 Apple Inc. All rights reserved. 4 4 * Copyright (C) 2009 Google Inc. All rights reserved. 5 5 * Copyright (C) 2010 Research In Motion Limited. All rights reserved. … … 48 48 namespace JSC { 49 49 50 class ExecState; 50 51 class VM; 51 52 … … 54 55 JS_EXPORT_PRIVATE double getUTCOffset(VM&); 55 56 JS_EXPORT_PRIVATE double parseDateFromNullTerminatedCharacters(VM&, const char* dateString); 56 JS_EXPORT_PRIVATE double parseDate( VM&, const WTF::String&);57 JS_EXPORT_PRIVATE double parseDate(ExecState*, VM&, const WTF::String&); 57 58 58 59 } // namespace JSC -
trunk/Source/WTF/ChangeLog
r232082 r232089 1 2018-05-22 Mark Lam <mark.lam@apple.com> 2 3 StringImpl utf8 conversion should not fail silently. 4 https://bugs.webkit.org/show_bug.cgi?id=185888 5 <rdar://problem/40464506> 6 7 Reviewed by Filip Pizlo. 8 9 * WTF.xcodeproj/project.pbxproj: 10 * wtf/CMakeLists.txt: 11 * wtf/PrintStream.cpp: 12 (WTF::printExpectedCStringHelper): 13 (WTF::printInternal): 14 * wtf/text/StringImpl.cpp: 15 (WTF::StringImpl::utf8Impl): 16 (WTF::StringImpl::utf8ForCharacters): 17 (WTF::StringImpl::tryUtf8ForRange const): 18 (WTF::StringImpl::tryUtf8 const): 19 (WTF::StringImpl::utf8 const): 20 (WTF::StringImpl::utf8ForRange const): Deleted. 21 * wtf/text/StringImpl.h: 22 * wtf/text/StringView.cpp: 23 (WTF::StringView::tryUtf8 const): 24 (WTF::StringView::utf8 const): 25 * wtf/text/StringView.h: 26 * wtf/text/UTF8ConversionError.h: Added. 27 * wtf/text/WTFString.cpp: 28 (WTF::String::tryUtf8 const): 29 (WTF::String::utf8 const): 30 * wtf/text/WTFString.h: 31 1 32 2018-05-22 Chris Dumez <cdumez@apple.com> 2 33 -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r232082 r232089 642 642 FEDACD3B1630F83F00C69634 /* StackStats.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StackStats.cpp; sourceTree = "<group>"; }; 643 643 FEDACD3C1630F83F00C69634 /* StackStats.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StackStats.h; sourceTree = "<group>"; }; 644 FEF295BF20B49DCB00CF283A /* UTF8ConversionError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTF8ConversionError.h; sourceTree = "<group>"; }; 644 645 FF0A436588954F3CB07DBECA /* StdList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StdList.h; sourceTree = "<group>"; }; 645 646 /* End PBXFileReference section */ … … 1219 1220 A3E4DD911F3A803400DED0B4 /* TextStream.cpp */, 1220 1221 A3E4DD921F3A803400DED0B4 /* TextStream.h */, 1222 FEF295BF20B49DCB00CF283A /* UTF8ConversionError.h */, 1221 1223 70ECA60C1B02426800449739 /* UniquedStringImpl.h */, 1222 1224 A3AB6E6A1F3E1AD6009C14B1 /* ValueToString.h */, -
trunk/Source/WTF/wtf/CMakeLists.txt
r232000 r232089 306 306 text/TextPosition.h 307 307 text/TextStream.h 308 text/UTF8ConversionError.h 308 309 text/UniquedStringImpl.h 309 310 text/ValueToString.h -
trunk/Source/WTF/wtf/PrintStream.cpp
r220058 r232089 83 83 } 84 84 85 static void printExpectedCStringHelper(PrintStream& out, const char* type, Expected<CString, UTF8ConversionError> expectedCString) 86 { 87 if (UNLIKELY(!expectedCString)) { 88 if (expectedCString.error() == UTF8ConversionError::OutOfMemory) 89 out.print("(Out of memory while converting ", type, " to utf8)"); 90 else 91 out.print("(failed to convert ", type, " to utf8)"); 92 return; 93 } 94 out.print(expectedCString.value()); 95 } 96 85 97 void printInternal(PrintStream& out, const StringView& string) 86 98 { 87 out.print(string.utf8());99 printExpectedCStringHelper(out, "StringView", string.tryGetUtf8()); 88 100 } 89 101 … … 95 107 void printInternal(PrintStream& out, const String& string) 96 108 { 97 out.print(string.utf8());109 printExpectedCStringHelper(out, "String", string.tryGetUtf8()); 98 110 } 99 111 … … 104 116 return; 105 117 } 106 out.print(string->utf8());118 printExpectedCStringHelper(out, "StringImpl*", string->tryGetUtf8()); 107 119 } 108 120 -
trunk/Source/WTF/wtf/text/StringImpl.cpp
r231337 r232089 1727 1727 } 1728 1728 1729 boolStringImpl::utf8Impl(const UChar* characters, unsigned length, char*& buffer, size_t bufferSize, ConversionMode mode)1729 UTF8ConversionError StringImpl::utf8Impl(const UChar* characters, unsigned length, char*& buffer, size_t bufferSize, ConversionMode mode) 1730 1730 { 1731 1731 if (mode == StrictConversionReplacingUnpairedSurrogatesWithFFFD) { … … 1755 1755 if (result == sourceIllegal) { 1756 1756 ASSERT(strict); 1757 return false;1757 return UTF8ConversionError::IllegalSource; 1758 1758 } 1759 1759 … … 1761 1761 if (result == sourceExhausted) { 1762 1762 if (strict) 1763 return false;1763 return UTF8ConversionError::SourceExhausted; 1764 1764 // This should be one unpaired high surrogate. Treat it the same 1765 1765 // was as an unpaired high surrogate would have been handled in … … 1775 1775 } 1776 1776 1777 return true;1778 } 1779 1780 CStringStringImpl::utf8ForCharacters(const LChar* characters, unsigned length)1777 return UTF8ConversionError::None; 1778 } 1779 1780 Expected<CString, UTF8ConversionError> StringImpl::utf8ForCharacters(const LChar* characters, unsigned length) 1781 1781 { 1782 1782 if (!length) 1783 1783 return CString("", 0); 1784 1784 if (length > std::numeric_limits<unsigned>::max() / 3) 1785 return CString();1785 return makeUnexpected(UTF8ConversionError::OutOfMemory); 1786 1786 Vector<char, 1024> bufferVector(length * 3); 1787 1787 char* buffer = bufferVector.data(); … … 1792 1792 } 1793 1793 1794 CStringStringImpl::utf8ForCharacters(const UChar* characters, unsigned length, ConversionMode mode)1794 Expected<CString, UTF8ConversionError> StringImpl::utf8ForCharacters(const UChar* characters, unsigned length, ConversionMode mode) 1795 1795 { 1796 1796 if (!length) 1797 1797 return CString("", 0); 1798 1798 if (length > std::numeric_limits<unsigned>::max() / 3) 1799 return CString();1799 return makeUnexpected(UTF8ConversionError::OutOfMemory); 1800 1800 Vector<char, 1024> bufferVector(length * 3); 1801 1801 char* buffer = bufferVector.data(); 1802 if (!utf8Impl(characters, length, buffer, bufferVector.size(), mode)) 1803 return CString(); 1802 UTF8ConversionError error = utf8Impl(characters, length, buffer, bufferVector.size(), mode); 1803 if (error != UTF8ConversionError::None) 1804 return makeUnexpected(error); 1804 1805 return CString(bufferVector.data(), buffer - bufferVector.data()); 1805 1806 } 1806 1807 1807 CString StringImpl::utf8ForRange(unsigned offset, unsigned length, ConversionMode mode) const1808 Expected<CString, UTF8ConversionError> StringImpl::tryGetUtf8ForRange(unsigned offset, unsigned length, ConversionMode mode) const 1808 1809 { 1809 1810 ASSERT(offset <= this->length()); … … 1824 1825 // buffer without reallocing (say, 1.5 x length). 1825 1826 if (length > std::numeric_limits<unsigned>::max() / 3) 1826 return CString();1827 return makeUnexpected(UTF8ConversionError::OutOfMemory); 1827 1828 Vector<char, 1024> bufferVector(length * 3); 1828 1829 … … 1835 1836 ASSERT_UNUSED(result, result != targetExhausted); // (length * 3) should be sufficient for any conversion 1836 1837 } else { 1837 if (!utf8Impl(this->characters16() + offset, length, buffer, bufferVector.size(), mode)) 1838 return CString(); 1838 UTF8ConversionError error = utf8Impl(this->characters16() + offset, length, buffer, bufferVector.size(), mode); 1839 if (error != UTF8ConversionError::None) 1840 return makeUnexpected(error); 1839 1841 } 1840 1842 … … 1842 1844 } 1843 1845 1846 Expected<CString, UTF8ConversionError> StringImpl::tryGetUtf8(ConversionMode mode) const 1847 { 1848 return tryGetUtf8ForRange(0, length(), mode); 1849 } 1850 1844 1851 CString StringImpl::utf8(ConversionMode mode) const 1845 1852 { 1846 return utf8ForRange(0, length(), mode); 1853 auto expectedString = tryGetUtf8ForRange(0, length(), mode); 1854 RELEASE_ASSERT(expectedString); 1855 return expectedString.value(); 1847 1856 } 1848 1857 -
trunk/Source/WTF/wtf/text/StringImpl.h
r231337 r232089 28 28 #include <wtf/ASCIICType.h> 29 29 #include <wtf/CheckedArithmetic.h> 30 #include <wtf/Expected.h> 30 31 #include <wtf/MathExtras.h> 31 32 #include <wtf/StdLibExtras.h> … … 35 36 #include <wtf/text/StringCommon.h> 36 37 #include <wtf/text/StringHasher.h> 38 #include <wtf/text/UTF8ConversionError.h> 37 39 38 40 #if USE(CF) … … 285 287 #endif 286 288 287 static WTF_EXPORT_PRIVATE CString utf8ForCharacters(const LChar* characters, unsigned length); 288 static WTF_EXPORT_PRIVATE CString utf8ForCharacters(const UChar* characters, unsigned length, ConversionMode = LenientConversion); 289 WTF_EXPORT_PRIVATE CString utf8ForRange(unsigned offset, unsigned length, ConversionMode = LenientConversion) const; 289 static WTF_EXPORT_PRIVATE Expected<CString, UTF8ConversionError> utf8ForCharacters(const LChar* characters, unsigned length); 290 static WTF_EXPORT_PRIVATE Expected<CString, UTF8ConversionError> utf8ForCharacters(const UChar* characters, unsigned length, ConversionMode = LenientConversion); 291 292 WTF_EXPORT_PRIVATE Expected<CString, UTF8ConversionError> tryGetUtf8ForRange(unsigned offset, unsigned length, ConversionMode = LenientConversion) const; 293 WTF_EXPORT_PRIVATE Expected<CString, UTF8ConversionError> tryGetUtf8(ConversionMode = LenientConversion) const; 290 294 WTF_EXPORT_PRIVATE CString utf8(ConversionMode = LenientConversion) const; 291 295 292 296 private: 293 static WTF_EXPORT_PRIVATE boolutf8Impl(const UChar* characters, unsigned length, char*& buffer, size_t bufferSize, ConversionMode);297 static WTF_EXPORT_PRIVATE UTF8ConversionError utf8Impl(const UChar* characters, unsigned length, char*& buffer, size_t bufferSize, ConversionMode); 294 298 295 299 // The high bits of 'hash' are always empty, but we prefer to store our flags … … 1203 1207 } // namespace WTF 1204 1208 1209 using WTF::StaticStringImpl; 1205 1210 using WTF::StringImpl; 1206 using WTF::StaticStringImpl;1207 1211 using WTF::equal; 1208 1212 -
trunk/Source/WTF/wtf/text/StringView.cpp
r230303 r232089 81 81 } 82 82 83 CString StringView::utf8(ConversionMode mode) const83 Expected<CString, UTF8ConversionError> StringView::tryGetUtf8(ConversionMode mode) const 84 84 { 85 85 if (isNull()) … … 88 88 return StringImpl::utf8ForCharacters(characters8(), length()); 89 89 return StringImpl::utf8ForCharacters(characters16(), length(), mode); 90 } 91 92 CString StringView::utf8(ConversionMode mode) const 93 { 94 auto expectedString = tryGetUtf8(mode); 95 RELEASE_ASSERT(expectedString); 96 return expectedString.value(); 90 97 } 91 98 -
trunk/Source/WTF/wtf/text/StringView.h
r230130 r232089 37 37 #include <wtf/text/LChar.h> 38 38 #include <wtf/text/StringCommon.h> 39 #include <wtf/text/UTF8ConversionError.h> 39 40 40 41 // FIXME: Enabling the StringView lifetime checking causes the MSVC build to fail. Figure out why. … … 107 108 #endif 108 109 110 WTF_EXPORT_PRIVATE Expected<CString, UTF8ConversionError> tryGetUtf8(ConversionMode = LenientConversion) const; 109 111 WTF_EXPORT_PRIVATE CString utf8(ConversionMode = LenientConversion) const; 110 112 -
trunk/Source/WTF/wtf/text/WTFString.cpp
r230113 r232089 805 805 } 806 806 807 Expected<CString, UTF8ConversionError> String::tryGetUtf8(ConversionMode mode) const 808 { 809 return m_impl ? m_impl->tryGetUtf8(mode) : CString { "", 0 }; 810 } 811 812 Expected<CString, UTF8ConversionError> String::tryGetUtf8() const 813 { 814 return tryGetUtf8(LenientConversion); 815 } 816 807 817 CString String::utf8(ConversionMode mode) const 808 818 { 809 return m_impl ? m_impl->utf8(mode) : CString { "", 0 }; 819 Expected<CString, UTF8ConversionError> expectedString = tryGetUtf8(mode); 820 RELEASE_ASSERT(expectedString); 821 return expectedString.value(); 810 822 } 811 823 -
trunk/Source/WTF/wtf/text/WTFString.h
r231337 r232089 165 165 WTF_EXPORT_PRIVATE CString utf8(ConversionMode) const; 166 166 WTF_EXPORT_PRIVATE CString utf8() const; 167 168 WTF_EXPORT_PRIVATE Expected<CString, UTF8ConversionError> tryGetUtf8(ConversionMode) const; 169 WTF_EXPORT_PRIVATE Expected<CString, UTF8ConversionError> tryGetUtf8() const; 167 170 168 171 UChar characterAt(unsigned index) const;
Note: See TracChangeset
for help on using the changeset viewer.