diff options
| author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
|---|---|---|
| committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
| commit | 41386e9cb918eed93b3f13648cbef387e371e451 (patch) | |
| tree | a97f9d7bd1d9d091833286085f72da9d83fd0606 /Source/JavaScriptCore/runtime/PropertyName.h | |
| parent | e15dd966d523731101f70ccf768bba12435a0208 (diff) | |
| download | WebKitGtk-tarball-41386e9cb918eed93b3f13648cbef387e371e451.tar.gz | |
webkitgtk-2.4.9webkitgtk-2.4.9
Diffstat (limited to 'Source/JavaScriptCore/runtime/PropertyName.h')
| -rw-r--r-- | Source/JavaScriptCore/runtime/PropertyName.h | 97 |
1 files changed, 59 insertions, 38 deletions
diff --git a/Source/JavaScriptCore/runtime/PropertyName.h b/Source/JavaScriptCore/runtime/PropertyName.h index eaba62804..e4d5fabd5 100644 --- a/Source/JavaScriptCore/runtime/PropertyName.h +++ b/Source/JavaScriptCore/runtime/PropertyName.h @@ -28,54 +28,90 @@ #include "Identifier.h" #include "PrivateName.h" -#include <wtf/Optional.h> namespace JSC { -class PropertyName { -public: - PropertyName(UniquedStringImpl* propertyName) - : m_impl(propertyName) - { +template <typename CharType> +ALWAYS_INLINE uint32_t toUInt32FromCharacters(const CharType* characters, unsigned length) +{ + // An empty string is not a number. + if (!length) + return UINT_MAX; + + // Get the first character, turning it into a digit. + uint32_t value = characters[0] - '0'; + if (value > 9) + return UINT_MAX; + + // Check for leading zeros. If the first characher is 0, then the + // length of the string must be one - e.g. "042" is not equal to "42". + if (!value && length > 1) + return UINT_MAX; + + while (--length) { + // Multiply value by 10, checking for overflow out of 32 bits. + if (value > 0xFFFFFFFFU / 10) + return UINT_MAX; + value *= 10; + + // Get the next character, turning it into a digit. + uint32_t newValue = *(++characters) - '0'; + if (newValue > 9) + return UINT_MAX; + + // Add in the old value, checking for overflow out of 32 bits. + newValue += value; + if (newValue < value) + return UINT_MAX; + value = newValue; } + + return value; +} +ALWAYS_INLINE uint32_t toUInt32FromStringImpl(StringImpl* impl) +{ + if (impl->is8Bit()) + return toUInt32FromCharacters(impl->characters8(), impl->length()); + return toUInt32FromCharacters(impl->characters16(), impl->length()); +} + +class PropertyName { +public: PropertyName(const Identifier& propertyName) - : PropertyName(propertyName.impl()) + : m_impl(propertyName.impl()) { + ASSERT(!m_impl || m_impl->isIdentifier() || m_impl->isEmptyUnique()); } PropertyName(const PrivateName& propertyName) : m_impl(propertyName.uid()) { - ASSERT(m_impl); - ASSERT(m_impl->isSymbol()); + ASSERT(m_impl && m_impl->isEmptyUnique()); } - bool isSymbol() - { - return m_impl && m_impl->isSymbol(); - } - - UniquedStringImpl* uid() const + StringImpl* uid() const { + ASSERT(!m_impl || (m_impl->isIdentifier() == !m_impl->isEmptyUnique())); return m_impl; } - AtomicStringImpl* publicName() const + StringImpl* publicName() const { - return (!m_impl || m_impl->isSymbol()) ? nullptr : static_cast<AtomicStringImpl*>(m_impl); + ASSERT(!m_impl || (m_impl->isIdentifier() == !m_impl->isEmptyUnique())); + return m_impl->isIdentifier() ? m_impl : 0; } - void dump(PrintStream& out) const + static const uint32_t NotAnIndex = UINT_MAX; + + uint32_t asIndex() { - if (m_impl) - out.print(m_impl); - else - out.print("<null property name>"); + ASSERT(!m_impl || (m_impl->isIdentifier() == !m_impl->isEmptyUnique())); + return m_impl ? toUInt32FromStringImpl(m_impl) : NotAnIndex; } private: - UniquedStringImpl* m_impl; + StringImpl* m_impl; }; inline bool operator==(PropertyName a, const Identifier& b) @@ -93,11 +129,6 @@ inline bool operator==(PropertyName a, PropertyName b) return a.uid() == b.uid(); } -inline bool operator==(PropertyName a, const char* b) -{ - return equal(a.uid(), b); -} - inline bool operator!=(PropertyName a, const Identifier& b) { return a.uid() != b.impl(); @@ -113,16 +144,6 @@ inline bool operator!=(PropertyName a, PropertyName b) return a.uid() != b.uid(); } -ALWAYS_INLINE Optional<uint32_t> parseIndex(PropertyName propertyName) -{ - auto uid = propertyName.uid(); - if (!uid) - return Nullopt; - if (uid->isSymbol()) - return Nullopt; - return parseIndex(*uid); -} - } #endif |
