aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4functionobject_p.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-09-18 17:01:59 +0200
committerLars Knoll <lars.knoll@qt.io>2018-09-23 17:27:43 +0000
commita97d118bf55e1c44ded9bbcd143b0f0725db8268 (patch)
treee0f22b61ba294199758eaf25c7e4f3c71bae7470 /src/qml/jsruntime/qv4functionobject_p.h
parent3440b8f9c5b198be4124ee1defd69d807bb972c6 (diff)
Better inheritance structure for functions
Give Arrow functions their own representation. This also prepares for further optimizations especially for the instanceof operator. Change-Id: I1f70c0271169a237e1acdeb7fe855be957ba2ea5 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4functionobject_p.h')
-rw-r--r--src/qml/jsruntime/qv4functionobject_p.h45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h
index 908a9fcb1e..11ddd9a211 100644
--- a/src/qml/jsruntime/qv4functionobject_p.h
+++ b/src/qml/jsruntime/qv4functionobject_p.h
@@ -109,32 +109,42 @@ struct IndexedBuiltinFunction : FunctionObject {
uint index;
};
+struct ArrowFunction : FunctionObject {
+ enum {
+ Index_Name,
+ Index_Length
+ };
+ void init(QV4::ExecutionContext *scope, Function *function, QV4::String *name = nullptr);
+};
+
#define ScriptFunctionMembers(class, Member) \
Member(class, Pointer, InternalClass *, cachedClassForConstructor)
-DECLARE_HEAP_OBJECT(ScriptFunction, FunctionObject) {
+DECLARE_HEAP_OBJECT(ScriptFunction, ArrowFunction) {
DECLARE_MARKOBJECTS(ScriptFunction)
enum {
Index_Name,
Index_Length
};
- void initNoConstructor(QV4::ExecutionContext *scope, Function *function, QV4::String *name = nullptr);
void init(QV4::ExecutionContext *scope, Function *function);
};
#define MemberFunctionMembers(class, Member) \
Member(class, Pointer, Object *, homeObject)
-DECLARE_HEAP_OBJECT(MemberFunction, ScriptFunction) {
+DECLARE_HEAP_OBJECT(MemberFunction, ArrowFunction) {
DECLARE_MARKOBJECTS(MemberFunction)
void init(QV4::ExecutionContext *scope, Function *function, QV4::String *name = nullptr) {
- ScriptFunction::initNoConstructor(scope, function, name);
+ ArrowFunction::init(scope, function, name);
}
};
-struct ConstructorFunction : MemberFunction
-{
+#define ConstructorFunctionMembers(class, Member) \
+ Member(class, Pointer, Object *, homeObject)
+
+DECLARE_HEAP_OBJECT(ConstructorFunction, ScriptFunction) {
+ DECLARE_MARKOBJECTS(ConstructorFunction)
bool isDerivedConstructor;
};
@@ -205,6 +215,8 @@ struct Q_QML_EXPORT FunctionObject: Object {
return d()->isConstructor();
}
+ ReturnedValue getHomeObject() const;
+
ReturnedValue protoProperty() const { return get(engine()->id_prototype()); }
@@ -256,25 +268,30 @@ void Heap::IndexedBuiltinFunction::init(QV4::ExecutionContext *scope, uint index
this->index = index;
}
+struct ArrowFunction : FunctionObject {
+ V4_OBJECT2(ArrowFunction, FunctionObject)
+ V4_INTERNALCLASS(ArrowFunction)
+ enum { NInlineProperties = 3 };
+
+ static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
+};
-struct ScriptFunction : FunctionObject {
- V4_OBJECT2(ScriptFunction, FunctionObject)
+struct ScriptFunction : ArrowFunction {
+ V4_OBJECT2(ScriptFunction, ArrowFunction)
V4_INTERNALCLASS(ScriptFunction)
- enum { NInlineProperties = 3 };
static ReturnedValue virtualCallAsConstructor(const FunctionObject *, const Value *argv, int argc, const Value *);
- static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
Heap::InternalClass *classForConstructor() const;
};
-struct MemberFunction : ScriptFunction {
- V4_OBJECT2(MemberFunction, ScriptFunction)
+struct MemberFunction : ArrowFunction {
+ V4_OBJECT2(MemberFunction, ArrowFunction)
V4_INTERNALCLASS(MemberFunction)
};
-struct ConstructorFunction : MemberFunction {
- V4_OBJECT2(ConstructorFunction, MemberFunction)
+struct ConstructorFunction : ScriptFunction {
+ V4_OBJECT2(ConstructorFunction, ScriptFunction)
V4_INTERNALCLASS(ConstructorFunction)
static ReturnedValue virtualCallAsConstructor(const FunctionObject *, const Value *argv, int argc, const Value *);
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);