aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4value.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-06-23 21:05:13 +0200
committerLars Knoll <lars.knoll@qt.io>2018-07-02 19:29:36 +0000
commit8728a2b494eb384b65bd4e7c6ec785435a37de9d (patch)
tree85e42b08a4b1e2836ba5db6d40f4b99a6d52f839 /src/qml/jsruntime/qv4value.cpp
parent56602df447c5f16257874f2e97b078dcf76f2467 (diff)
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 <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4value.cpp')
-rw-r--r--src/qml/jsruntime/qv4value.cpp17
1 files changed, 14 insertions, 3 deletions
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 <qv4engine_p.h>
#include <qv4runtime_p.h>
#include <qv4string_p.h>
+#include <qv4propertykey_p.h>
#ifndef V4_BOOTSTRAP
#include <qv4symbol_p.h>
#include <qv4object_p.h>
@@ -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<uint>(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<Heap::StringOrSymbol *>(v->m());
+ return PropertyKey::invalid();
+ ScopedStringOrSymbol s(scope, v);
+ s->makeIdentifier();
+ return PropertyKey::fromIdentifier(s->identifier());
}
#endif // V4_BOOTSTRAP