diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-04-03 15:23:07 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-02 14:18:36 +0000 |
commit | bab5e5adf578fb37402ff03f4bd5e9ed3ce4c2d2 (patch) | |
tree | 1bbc320c5594faf5d2156385088c12222b9542b8 /src/qml/jsruntime/qv4stringobject.cpp | |
parent | a6da23bb5f6004e13d22838c7db1246169874930 (diff) |
Partial Symbol support
Added basic infrastructure to create symbols and convert them
back to strings. In addition, storing and retrieving of symbol
based properties in Objects works.
Change-Id: I185f7aa46e7afa19db5a801102142892e03b7bf1
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4stringobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4stringobject.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index 61176b3706..db873d32e2 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -44,6 +44,7 @@ #include "qv4objectproto_p.h" #include <private/qv4mm_p.h> #include "qv4scopedvalue_p.h" +#include "qv4symbol_p.h" #include "qv4alloca_p.h" #include "qv4jscall_p.h" #include <QtCore/QDateTime> @@ -152,16 +153,18 @@ ReturnedValue StringCtor::callAsConstructor(const FunctionObject *f, const Value value = argv[0].toString(v4); else value = v4->newString(); + CHECK_EXCEPTION(); return Encode(v4->newStringObject(value)); } ReturnedValue StringCtor::call(const FunctionObject *m, const Value *, const Value *argv, int argc) { ExecutionEngine *v4 = m->engine(); - if (argc) - return argv[0].toString(v4)->asReturnedValue(); - else + if (!argc) return v4->newString()->asReturnedValue(); + if (argv[0].isSymbol()) + return v4->newString(argv[0].symbolValue()->descriptiveString())->asReturnedValue(); + return argv[0].toString(v4)->asReturnedValue(); } void StringPrototype::init(ExecutionEngine *engine, Object *ctor) @@ -169,6 +172,11 @@ void StringPrototype::init(ExecutionEngine *engine, Object *ctor) Scope scope(engine); ScopedObject o(scope); + // need to set this once again, as these were not fully defined when creating the string proto + Heap::InternalClass *ic = scope.engine->classes[ExecutionEngine::Class_StringObject]->changePrototype(scope.engine->objectPrototype()->d()); + d()->internalClass.set(scope.engine, ic); + d()->string.set(scope.engine, scope.engine->id_empty()->d()); + ctor->defineReadonlyProperty(engine->id_prototype(), (o = this)); ctor->defineReadonlyProperty(engine->id_length(), Primitive::fromInt32(1)); ctor->defineDefaultProperty(QStringLiteral("fromCharCode"), method_fromCharCode, 1); |