From 74f4065caa7254b0e30afa955aa59092024decdb Mon Sep 17 00:00:00 2001 From: Yulong Bai Date: Fri, 15 Jun 2018 14:44:19 +0200 Subject: Add basic support for EcmaScript classes Most of the class creation is done inside the runtime in the CreateClass method. Added a corresponding instruction to the interpreter and jit. The compiled data now contains an array of classes containing the compile time generated layout of the class. Currently, classes without an explicit constructor and classes with inheritance are not supported. Done-with: Yulong Bai Change-Id: I0185dcc1e3b0b8f44deff74e44a8262fc646aa9e Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4functionobject.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/qml/jsruntime/qv4functionobject.cpp') diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index a9aaa344cb..7fcb1c3536 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -179,6 +179,11 @@ Heap::FunctionObject *FunctionObject::createScriptFunction(ExecutionContext *sco return scope->engine()->memoryManager->allocate(scope, function); } +Heap::FunctionObject *FunctionObject::createConstructorFunction(ExecutionContext *scope, Function *function) +{ + return scope->engine()->memoryManager->allocate(scope, function); +} + Heap::FunctionObject *FunctionObject::createBuiltinFunction(ExecutionEngine *engine, StringOrSymbol *nameOrSymbol, jsCallFunction code, int argumentCount) { Scope scope(engine); @@ -490,6 +495,13 @@ Heap::InternalClass *ScriptFunction::classForConstructor() const return ic->d(); } +DEFINE_OBJECT_VTABLE(ConstructorFunction); + +ReturnedValue ConstructorFunction::call(const FunctionObject *f, const Value *, const Value *, int) +{ + return f->engine()->throwTypeError(QStringLiteral("Cannot call a class constructor without |new|")); +} + DEFINE_OBJECT_VTABLE(IndexedBuiltinFunction); DEFINE_OBJECT_VTABLE(BoundFunction); -- cgit v1.2.3