aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-09-01 10:20:49 +0200
committerLars Knoll <lars.knoll@qt.io>2018-09-04 18:25:10 +0000
commit656db7a425fec6661ee3b42b89594a3e28637cdd (patch)
treeb3546bd33b128d2789b70b98e1122b903937bc33 /src/qml
parenta0a702cd9a315946a1b35dfe54d2dc965210ab6e (diff)
Don't define a prototype property for most functions
Only functions that are constructors should have a prototype property. Change-Id: Ifcf6f8b6c38de055d871d57ada38a23432974263 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/jsruntime/qv4engine.cpp4
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp11
-rw-r--r--src/qml/jsruntime/qv4functionobject_p.h5
3 files changed, 6 insertions, 14 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index c40d6414ff..7b1fd720a7 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -342,12 +342,8 @@ ExecutionEngine::ExecutionEngine(QJSEngine *jsEngine)
uint index;
ic = newInternalClass(QV4::FunctionPrototype::staticVTable(), objectPrototype());
- ic = ic->addMember(id_prototype()->propertyKey(), Attr_NotEnumerable, &index);
- Q_ASSERT(index == Heap::FunctionObject::Index_Prototype);
jsObjects[FunctionProto] = memoryManager->allocObject<FunctionPrototype>(ic->d());
ic = newInternalClass(FunctionObject::staticVTable(), functionPrototype());
- ic = ic->addMember(id_prototype()->propertyKey(), Attr_NotEnumerable|Attr_NotConfigurable, &index);
- Q_ASSERT(index == Heap::FunctionObject::Index_Prototype);
classes[Class_FunctionObject] = ic->d();
ic = ic->addMember(id_name()->propertyKey(), Attr_ReadOnly, &index);
Q_ASSERT(index == Heap::ScriptFunction::Index_Name);
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index fe1ebbd556..f4037991b1 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -96,7 +96,7 @@ void Heap::FunctionObject::init(QV4::ExecutionContext *scope, QV4::String *name,
f->setName(name);
if (createProto)
- f->createDefaultPrototypeProperty(Heap::FunctionObject::Index_Prototype, Heap::FunctionObject::Index_ProtoConstructor);
+ f->createDefaultPrototypeProperty(Heap::FunctionObject::Index_ProtoConstructor);
}
@@ -130,8 +130,6 @@ void Heap::FunctionObject::init()
Object::init();
this->scope.set(internalClass->engine, internalClass->engine->rootContext()->d());
- Q_ASSERT(internalClass && internalClass->find(internalClass->engine->id_prototype()->propertyKey()) == Index_Prototype);
- setProperty(internalClass->engine, Index_Prototype, Primitive::undefinedValue());
}
void Heap::FunctionObject::setFunction(Function *f)
@@ -148,16 +146,15 @@ void Heap::FunctionObject::destroy()
Object::destroy();
}
-void FunctionObject::createDefaultPrototypeProperty(uint protoSlot, uint protoConstructorSlot)
+void FunctionObject::createDefaultPrototypeProperty(uint protoConstructorSlot)
{
Scope s(this);
- Q_ASSERT(internalClass() && internalClass()->find(s.engine->id_prototype()->propertyKey()) == protoSlot);
Q_ASSERT(s.engine->internalClasses(EngineBase::Class_ObjectProto)->find(s.engine->id_constructor()->propertyKey()) == protoConstructorSlot);
ScopedObject proto(s, s.engine->newObject(s.engine->internalClasses(EngineBase::Class_ObjectProto)));
proto->setProperty(protoConstructorSlot, d());
- setProperty(protoSlot, proto);
+ defineDefaultProperty(s.engine->id_prototype(), proto, Attr_NotEnumerable|Attr_NotConfigurable);
}
ReturnedValue FunctionObject::name() const
@@ -524,7 +521,7 @@ void Heap::ScriptFunction::init(QV4::ExecutionContext *scope, Function *function
ScopedString name(s, n ? n->d() : function->name());
if (name)
f->setName(name);
- f->createDefaultPrototypeProperty(Heap::FunctionObject::Index_Prototype, Heap::FunctionObject::Index_ProtoConstructor);
+ f->createDefaultPrototypeProperty(Heap::FunctionObject::Index_ProtoConstructor);
Q_ASSERT(internalClass && internalClass->find(s.engine->id_length()->propertyKey()) == Index_Length);
setProperty(s.engine, Index_Length, Primitive::fromInt32(int(function->compiledFunction->length)));
diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h
index 766960d2ac..5976fd8f78 100644
--- a/src/qml/jsruntime/qv4functionobject_p.h
+++ b/src/qml/jsruntime/qv4functionobject_p.h
@@ -76,7 +76,6 @@ namespace Heap {
DECLARE_HEAP_OBJECT(FunctionObject, Object) {
DECLARE_MARKOBJECTS(FunctionObject);
enum {
- Index_Prototype = 0,
Index_ProtoConstructor = 0
};
@@ -116,7 +115,7 @@ struct IndexedBuiltinFunction : FunctionObject {
DECLARE_HEAP_OBJECT(ScriptFunction, FunctionObject) {
DECLARE_MARKOBJECTS(ScriptFunction)
enum {
- Index_Name = FunctionObject::Index_Prototype + 1,
+ Index_Name,
Index_Length
};
void init(QV4::ExecutionContext *scope, Function *function, QV4::String *name = nullptr);
@@ -173,7 +172,7 @@ struct Q_QML_EXPORT FunctionObject: Object {
void setName(String *name) {
defineReadonlyConfigurableProperty(engine()->id_name(), *name);
}
- void createDefaultPrototypeProperty(uint protoSlot, uint protoConstructorSlot);
+ void createDefaultPrototypeProperty(uint protoConstructorSlot);
inline ReturnedValue callAsConstructor(const JSCallData &data) const;
ReturnedValue callAsConstructor(const Value *argv, int argc, const Value *newTarget = nullptr) const {