diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-06-23 21:05:13 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-07-02 19:29:36 +0000 |
commit | 8728a2b494eb384b65bd4e7c6ec785435a37de9d (patch) | |
tree | 85e42b08a4b1e2836ba5db6d40f4b99a6d52f839 /src/qml/jsruntime/qv4reflect.cpp | |
parent | 56602df447c5f16257874f2e97b078dcf76f2467 (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/qv4reflect.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4reflect.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/qml/jsruntime/qv4reflect.cpp b/src/qml/jsruntime/qv4reflect.cpp index 7d8c8db089..41aa4b402e 100644 --- a/src/qml/jsruntime/qv4reflect.cpp +++ b/src/qml/jsruntime/qv4reflect.cpp @@ -41,6 +41,7 @@ #include "qv4symbol_p.h" #include "qv4runtimeapi_p.h" #include "qv4objectproto_p.h" +#include "qv4propertykey_p.h" using namespace QV4; @@ -120,7 +121,7 @@ ReturnedValue Reflect::method_defineProperty(const FunctionObject *f, const Valu return scope.engine->throwTypeError(); ScopedObject O(scope, argv[0]); - ScopedStringOrSymbol name(scope, (argc > 1 ? argv[1] : Primitive::undefinedValue()).toPropertyKey(scope.engine)); + ScopedPropertyKey name(scope, (argc > 1 ? argv[1] : Primitive::undefinedValue()).toPropertyKey(scope.engine)); if (scope.engine->hasException) return QV4::Encode::undefined(); @@ -131,7 +132,7 @@ ReturnedValue Reflect::method_defineProperty(const FunctionObject *f, const Valu if (scope.engine->hasException) return QV4::Encode::undefined(); - bool result = O->defineOwnProperty(name->toPropertyKey(), pd, attrs); + bool result = O->defineOwnProperty(name->toIdentifier(), pd, attrs); return Encode(result); } @@ -155,12 +156,12 @@ ReturnedValue Reflect::method_get(const FunctionObject *f, const Value *, const ScopedObject o(scope, static_cast<const Object *>(argv)); Value undef = Primitive::undefinedValue(); const Value *index = argc > 1 ? &argv[1] : &undef; - ScopedStringOrSymbol name(scope, index->toPropertyKey(scope.engine)); + ScopedPropertyKey name(scope, index->toPropertyKey(scope.engine)); if (scope.hasException()) return Encode::undefined(); ScopedValue receiver(scope, argc > 2 ? argv[2] : *o); - return Encode(o->get(name->toPropertyKey(), receiver)); + return Encode(o->get(name->toIdentifier(), receiver)); } ReturnedValue Reflect::method_getOwnPropertyDescriptor(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc) @@ -198,10 +199,10 @@ ReturnedValue Reflect::method_has(const FunctionObject *f, const Value *, const return Encode(hasProperty); } - ScopedStringOrSymbol name(scope, index->toPropertyKey(scope.engine)); + ScopedPropertyKey name(scope, index->toPropertyKey(scope.engine)); if (scope.engine->hasException) return false; - (void) o->get(name, &hasProperty); + (void) o->get(name->toIdentifier(), nullptr, &hasProperty); return Encode(hasProperty); } @@ -245,10 +246,10 @@ ReturnedValue Reflect::method_set(const FunctionObject *f, const Value *, const const Value &val = argc > 2 ? argv[2] : undef; ScopedValue receiver(scope, argc >3 ? argv[3] : argv[0]); - Scoped<StringOrSymbol> propertyKey(scope, index->toPropertyKey(scope.engine)); + ScopedPropertyKey propertyKey(scope, index->toPropertyKey(scope.engine)); if (scope.engine->hasException) return false; - bool result = o->put(propertyKey->toPropertyKey(), val, receiver); + bool result = o->put(propertyKey->toIdentifier(), val, receiver); return Encode(result); } |