aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4engine.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-09-19 15:27:41 +0200
committerLars Knoll <lars.knoll@qt.io>2018-09-27 08:34:10 +0000
commit7c592625032a98f68fd6a09026e466c5fbc7bb09 (patch)
tree4ab9182d3b1468941226652ad0816e1f0c00e66b /src/qml/jsruntime/qv4engine.cpp
parent9df44b2b502f9ab9a379c8454b000d2085aed744 (diff)
Unify layout of function objects
Ensure we have the proto property at always the same place. This will be used in a subsequent commit to optimize accesses to the prototype property e.g. when doing instanceof operations or constructor calls. Change-Id: I6e9a19e0b7d0e8ab583648a60d1978f5cf838b06 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4engine.cpp')
-rw-r--r--src/qml/jsruntime/qv4engine.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 4c1e660429..522ad7669f 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -351,23 +351,29 @@ ExecutionEngine::ExecutionEngine(QJSEngine *jsEngine)
jsObjects[FunctionProto] = memoryManager->allocObject<FunctionPrototype>(ic->d());
ic = newInternalClass(FunctionObject::staticVTable(), functionPrototype());
classes[Class_FunctionObject] = ic->d();
+ // Add an invalid prototype slot, so that all function objects have the same layout
+ // This helps speed up instanceof operations and other things where we need to query
+ // prototype property (as we always know it's location)
+ ic = ic->addMember(id_prototype()->propertyKey(), Attr_Invalid, index);
+ Q_ASSERT(index->index == Heap::FunctionObject::Index_Prototype);
ic = ic->addMember(id_name()->propertyKey(), Attr_ReadOnly, index);
Q_ASSERT(index->index == Heap::ArrowFunction::Index_Name);
ic = ic->addMember(id_length()->propertyKey(), Attr_ReadOnly_ButConfigurable, index);
Q_ASSERT(index->index == Heap::ArrowFunction::Index_Length);
classes[Class_ArrowFunction] = ic->changeVTable(ArrowFunction::staticVTable());
- ic = ic->changeVTable(ScriptFunction::staticVTable());
- classes[Class_ScriptFunction] = ic->d();
- ic = ic->changeVTable(ConstructorFunction::staticVTable());
- classes[Class_ConstructorFunction] = ic->d();
ic = ic->changeVTable(MemberFunction::staticVTable());
classes[Class_MemberFunction] = ic->d();
ic = ic->changeVTable(GeneratorFunction::staticVTable());
- 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();
+
+ ic = ic->changeMember(id_prototype()->propertyKey(), Attr_NotConfigurable|Attr_NotEnumerable);
+ ic = ic->changeVTable(ScriptFunction::staticVTable());
+ classes[Class_ScriptFunction] = ic->d();
+ ic = ic->changeVTable(ConstructorFunction::staticVTable());
+ classes[Class_ConstructorFunction] = ic->d();
+
classes[Class_ObjectProto] = classes[Class_Object]->addMember(id_constructor()->propertyKey(), Attr_NotEnumerable, index);
Q_ASSERT(index->index == Heap::FunctionObject::Index_ProtoConstructor);