summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/PropertyName.h
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
commit32761a6cee1d0dee366b885b7b9c777e67885688 (patch)
treed6bec92bebfb216f4126356e55518842c2f476a1 /Source/JavaScriptCore/runtime/PropertyName.h
parenta4e969f4965059196ca948db781e52f7cfebf19e (diff)
downloadWebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/JavaScriptCore/runtime/PropertyName.h')
-rw-r--r--Source/JavaScriptCore/runtime/PropertyName.h99
1 files changed, 59 insertions, 40 deletions
diff --git a/Source/JavaScriptCore/runtime/PropertyName.h b/Source/JavaScriptCore/runtime/PropertyName.h
index 9d3cc2b51..e4d5fabd5 100644
--- a/Source/JavaScriptCore/runtime/PropertyName.h
+++ b/Source/JavaScriptCore/runtime/PropertyName.h
@@ -28,56 +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 isNull() const { return !m_impl; }
-
- 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)
@@ -95,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();
@@ -115,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