summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/PropertyName.h
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/runtime/PropertyName.h
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/JavaScriptCore/runtime/PropertyName.h')
-rw-r--r--Source/JavaScriptCore/runtime/PropertyName.h104
1 files changed, 41 insertions, 63 deletions
diff --git a/Source/JavaScriptCore/runtime/PropertyName.h b/Source/JavaScriptCore/runtime/PropertyName.h
index e4d5fabd5..d1d4d1994 100644
--- a/Source/JavaScriptCore/runtime/PropertyName.h
+++ b/Source/JavaScriptCore/runtime/PropertyName.h
@@ -23,95 +23,60 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef PropertyName_h
-#define PropertyName_h
+#pragma once
#include "Identifier.h"
#include "PrivateName.h"
+#include <wtf/Optional.h>
namespace JSC {
-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(UniquedStringImpl* propertyName)
+ : m_impl(propertyName)
+ {
+ }
+
PropertyName(const Identifier& propertyName)
- : m_impl(propertyName.impl())
+ : PropertyName(propertyName.impl())
{
- ASSERT(!m_impl || m_impl->isIdentifier() || m_impl->isEmptyUnique());
}
PropertyName(const PrivateName& propertyName)
- : m_impl(propertyName.uid())
+ : m_impl(&propertyName.uid())
{
- ASSERT(m_impl && m_impl->isEmptyUnique());
+ ASSERT(m_impl);
+ ASSERT(m_impl->isSymbol());
}
- StringImpl* uid() const
+ bool isNull() const { return !m_impl; }
+
+ bool isSymbol()
{
- ASSERT(!m_impl || (m_impl->isIdentifier() == !m_impl->isEmptyUnique()));
- return m_impl;
+ return m_impl && m_impl->isSymbol();
}
- StringImpl* publicName() const
+ UniquedStringImpl* uid() const
{
- ASSERT(!m_impl || (m_impl->isIdentifier() == !m_impl->isEmptyUnique()));
- return m_impl->isIdentifier() ? m_impl : 0;
+ return m_impl;
}
- static const uint32_t NotAnIndex = UINT_MAX;
+ AtomicStringImpl* publicName() const
+ {
+ return (!m_impl || m_impl->isSymbol()) ? nullptr : static_cast<AtomicStringImpl*>(m_impl);
+ }
- uint32_t asIndex()
+ void dump(PrintStream& out) const
{
- ASSERT(!m_impl || (m_impl->isIdentifier() == !m_impl->isEmptyUnique()));
- return m_impl ? toUInt32FromStringImpl(m_impl) : NotAnIndex;
+ if (m_impl)
+ out.print(m_impl);
+ else
+ out.print("<null property name>");
}
private:
- StringImpl* m_impl;
+ UniquedStringImpl* m_impl;
};
inline bool operator==(PropertyName a, const Identifier& b)
@@ -129,6 +94,11 @@ 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();
@@ -144,6 +114,14 @@ inline bool operator!=(PropertyName a, PropertyName b)
return a.uid() != b.uid();
}
+ALWAYS_INLINE std::optional<uint32_t> parseIndex(PropertyName propertyName)
+{
+ auto uid = propertyName.uid();
+ if (!uid)
+ return std::nullopt;
+ if (uid->isSymbol())
+ return std::nullopt;
+ return parseIndex(*uid);
}
-#endif
+} // namespace JSC