Changeset 178894 in webkit for trunk/Source/JavaScriptCore/runtime/PropertyName.h
- Timestamp:
- Jan 22, 2015, 12:54:52 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/PropertyName.h
r178756 r178894 29 29 #include "Identifier.h" 30 30 #include "PrivateName.h" 31 #include <wtf/Optional.h> 31 32 32 33 namespace JSC { 33 34 34 35 template <typename CharType> 35 ALWAYS_INLINE uint32_ttoUInt32FromCharacters(const CharType* characters, unsigned length)36 ALWAYS_INLINE Optional<uint32_t> toUInt32FromCharacters(const CharType* characters, unsigned length) 36 37 { 37 38 // An empty string is not a number. 38 39 if (!length) 39 return UINT_MAX;40 return Nullopt; 40 41 41 42 // Get the first character, turning it into a digit. 42 43 uint32_t value = characters[0] - '0'; 43 44 if (value > 9) 44 return UINT_MAX;45 return Nullopt; 45 46 46 47 // Check for leading zeros. If the first characher is 0, then the 47 48 // length of the string must be one - e.g. "042" is not equal to "42". 48 49 if (!value && length > 1) 49 return UINT_MAX;50 return Nullopt; 50 51 51 52 while (--length) { 52 53 // Multiply value by 10, checking for overflow out of 32 bits. 53 54 if (value > 0xFFFFFFFFU / 10) 54 return UINT_MAX;55 return Nullopt; 55 56 value *= 10; 56 57 … … 58 59 uint32_t newValue = *(++characters) - '0'; 59 60 if (newValue > 9) 60 return UINT_MAX;61 return Nullopt; 61 62 62 63 // Add in the old value, checking for overflow out of 32 bits. 63 64 newValue += value; 64 65 if (newValue < value) 65 return UINT_MAX;66 return Nullopt; 66 67 value = newValue; 67 68 } 68 69 70 if (value == UINT_MAX) 71 return Nullopt; 69 72 return value; 70 73 } 71 74 72 ALWAYS_INLINE uint32_ttoUInt32FromStringImpl(StringImpl* impl)75 ALWAYS_INLINE Optional<uint32_t> toUInt32FromStringImpl(StringImpl* impl) 73 76 { 74 77 if (impl->is8Bit()) … … 110 113 static const uint32_t NotAnIndex = UINT_MAX; 111 114 112 uint32_tasIndex()115 Optional<uint32_t> asIndex() 113 116 { 114 return m_impl ? toUInt32FromStringImpl(m_impl) : N otAnIndex;117 return m_impl ? toUInt32FromStringImpl(m_impl) : Nullopt; 115 118 } 116 119 117 120 void dump(PrintStream& out) const 118 121 {
Note:
See TracChangeset
for help on using the changeset viewer.