From 8728a2b494eb384b65bd4e7c6ec785435a37de9d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sat, 23 Jun 2018 21:05:13 +0200 Subject: Introduce a PropertyKey class that inherits from Value This will replace Identifier over the next few commits. The advantage of PropertyKey is that it can be stored on the JS stack, so that a GC run won't accidentally clean up the string/symbol referenced by the key. Change-Id: Ib4daa4616bcfa537e6d371ef7c7740bc7727a50d Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4value.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/qml/jsruntime/qv4value.cpp') diff --git a/src/qml/jsruntime/qv4value.cpp b/src/qml/jsruntime/qv4value.cpp index 9febd41a00..6b22967bfa 100644 --- a/src/qml/jsruntime/qv4value.cpp +++ b/src/qml/jsruntime/qv4value.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #ifndef V4_BOOTSTRAP #include #include @@ -229,15 +230,25 @@ QString Value::toQString() const } // switch } -Heap::StringOrSymbol *Value::toPropertyKey(ExecutionEngine *e) const +QV4::PropertyKey Value::toPropertyKey(ExecutionEngine *e) const { + if (isInteger() && int_32() >= 0) + return PropertyKey::fromArrayIndex(static_cast(int_32())); + if (isStringOrSymbol()) { + Scope scope(e); + ScopedStringOrSymbol s(scope, this); + s->makeIdentifier(); + return PropertyKey::fromIdentifier(s->identifier()); + } Scope scope(e); ScopedValue v(scope, RuntimeHelpers::toPrimitive(*this, STRING_HINT)); if (!v->isStringOrSymbol()) v = v->toString(e); if (e->hasException) - return nullptr; - return static_cast(v->m()); + return PropertyKey::invalid(); + ScopedStringOrSymbol s(scope, v); + s->makeIdentifier(); + return PropertyKey::fromIdentifier(s->identifier()); } #endif // V4_BOOTSTRAP -- cgit v1.2.3