diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-07-03 11:07:15 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-07-03 11:19:03 +0000 |
commit | fc01254cf89543e509e8ebaca93aac7f009247dd (patch) | |
tree | 5da1b88e31797bc7dfa63343d3a9e9c3659c8252 /src | |
parent | a2372fd2c643615687ea3b8b1ccf53d699b6debd (diff) |
Fix class members that are generators
Properly support member functions that are generators in classes.
Change-Id: I5fc8d5b58a17c61a446b43d6576bb83de5ecd920
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4enginebase_p.h | 1 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4generatorobject.cpp | 18 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4generatorobject_p.h | 12 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 5 |
5 files changed, 37 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index a482d83a97..f9ef6b45a1 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -350,6 +350,8 @@ ExecutionEngine::ExecutionEngine(QJSEngine *jsEngine) classes[Class_MemberFunction] = ic->d(); ic = ic->changeVTable(GeneratorFunction::staticVTable()); classes[Class_GeneratorFunction] = ic->d(); + ic = ic->changeVTable(MemberGeneratorFunction::staticVTable()); + classes[Class_MemberGeneratorFunction] = ic->d(); classes[Class_ObjectProto] = classes[Class_Object]->addMember(id_constructor()->propertyKey(), Attr_NotEnumerable, &index); Q_ASSERT(index == Heap::FunctionObject::Index_ProtoConstructor); diff --git a/src/qml/jsruntime/qv4enginebase_p.h b/src/qml/jsruntime/qv4enginebase_p.h index 645f8e375f..3e89e57abb 100644 --- a/src/qml/jsruntime/qv4enginebase_p.h +++ b/src/qml/jsruntime/qv4enginebase_p.h @@ -107,6 +107,7 @@ struct Q_QML_EXPORT EngineBase { Class_ScriptFunction, Class_ConstructorFunction, Class_MemberFunction, + Class_MemberGeneratorFunction, Class_ObjectProto, Class_RegExp, Class_RegExpObject, diff --git a/src/qml/jsruntime/qv4generatorobject.cpp b/src/qml/jsruntime/qv4generatorobject.cpp index bfc27954c4..8c3cd8b863 100644 --- a/src/qml/jsruntime/qv4generatorobject.cpp +++ b/src/qml/jsruntime/qv4generatorobject.cpp @@ -232,3 +232,21 @@ ReturnedValue GeneratorObject::resume(ExecutionEngine *engine, const Value &arg) return Encode::undefined(); return IteratorPrototype::createIterResultObject(engine, result, done); } + +DEFINE_OBJECT_VTABLE(MemberGeneratorFunction); + +Heap::FunctionObject *MemberGeneratorFunction::create(ExecutionContext *context, Function *function) +{ + Scope scope(context); + Scoped<GeneratorFunction> g(scope, context->engine()->memoryManager->allocate<MemberGeneratorFunction>(context, function)); + ScopedObject proto(scope, scope.engine->newObject()); + proto->setPrototypeOf(scope.engine->generatorPrototype()); + g->defineDefaultProperty(scope.engine->id_prototype(), proto, Attr_NotConfigurable|Attr_NotEnumerable); + g->setPrototypeOf(ScopedObject(scope, scope.engine->generatorFunctionCtor()->get(scope.engine->id_prototype()))); + return g->d(); +} + +ReturnedValue MemberGeneratorFunction::virtualCallAsConstructor(const FunctionObject *f, const Value *, int, const Value *) +{ + return f->engine()->throwTypeError(QStringLiteral("Function is not a constructor.")); +} diff --git a/src/qml/jsruntime/qv4generatorobject_p.h b/src/qml/jsruntime/qv4generatorobject_p.h index 331b416856..a97050473c 100644 --- a/src/qml/jsruntime/qv4generatorobject_p.h +++ b/src/qml/jsruntime/qv4generatorobject_p.h @@ -75,6 +75,9 @@ struct GeneratorFunctionCtor : FunctionObject { struct GeneratorFunction : ScriptFunction { }; +struct MemberGeneratorFunction : ScriptFunction { +}; + struct GeneratorPrototype : FunctionObject { void init(); }; @@ -110,6 +113,15 @@ struct GeneratorFunction : ScriptFunction static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc); }; +struct MemberGeneratorFunction : GeneratorFunction +{ + V4_OBJECT2(MemberGeneratorFunction, GeneratorFunction) + V4_INTERNALCLASS(MemberGeneratorFunction) + + static Heap::FunctionObject *create(ExecutionContext *scope, Function *function); + static ReturnedValue virtualCallAsConstructor(const FunctionObject *f, const Value *argv, int argc, const Value *); +}; + struct GeneratorPrototype : Object { void init(ExecutionEngine *engine, Object *ctor); diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 9848c60602..f387285e37 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -1569,7 +1569,10 @@ ReturnedValue Runtime::method_createClass(ExecutionEngine *engine, int classInde } QV4::Function *f = unit->runtimeFunctions[methods[i].function]; Q_ASSERT(f); - function = FunctionObject::createMemberFunction(current, f); + if (f->isGenerator()) + function = MemberGeneratorFunction::create(current, f); + else + function = FunctionObject::createMemberFunction(current, f); Q_ASSERT(function); PropertyAttributes attributes; switch (methods[i].type) { |