aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4functionobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-06-22 13:02:10 +0200
committerLars Knoll <lars.knoll@qt.io>2018-06-27 07:00:34 +0000
commit1cadc5071ced2ef3f60635d26f0b3c53cc37fc3f (patch)
treea222ce1bbc7bb6eeb7c3c4281c3b9dc9f9356bd9 /src/qml/jsruntime/qv4functionobject.cpp
parent1e8d4097860e4c92dd49c0df03ce6f9b68eef961 (diff)
Cleanups in FunctionObject
rename init() to setName() as that's the only thing it's doing. Change-Id: Iecf586bc6b6df0f169bc7d2969b711e758ea3813 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4functionobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index f73d6eef43..68a197e11a 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -79,7 +79,8 @@ void Heap::FunctionObject::init(QV4::ExecutionContext *scope, QV4::String *name,
this->scope.set(scope->engine(), scope->d());
Scope s(scope->engine());
ScopedFunctionObject f(s, this);
- f->init(name, false);
+ if (name)
+ f->setName(name);
}
void Heap::FunctionObject::init(QV4::ExecutionContext *scope, QV4::String *name, bool createProto)
@@ -91,9 +92,15 @@ void Heap::FunctionObject::init(QV4::ExecutionContext *scope, QV4::String *name,
this->scope.set(scope->engine(), scope->d());
Scope s(scope->engine());
ScopedFunctionObject f(s, this);
- f->init(name, createProto);
+ if (name)
+ f->setName(name);
+
+ if (createProto)
+ f->createDefaultPrototypeProperty(Heap::FunctionObject::Index_Prototype, Heap::FunctionObject::Index_ProtoConstructor);
}
+
+
void Heap::FunctionObject::init(QV4::ExecutionContext *scope, Function *function, bool createProto)
{
jsCall = reinterpret_cast<const ObjectVTable *>(vtable())->call;
@@ -105,7 +112,11 @@ void Heap::FunctionObject::init(QV4::ExecutionContext *scope, Function *function
Scope s(scope->engine());
ScopedString name(s, function->name());
ScopedFunctionObject f(s, this);
- f->init(name, createProto);
+ if (name)
+ f->setName(name);
+
+ if (createProto)
+ f->createDefaultPrototypeProperty(Heap::FunctionObject::Index_Prototype, Heap::FunctionObject::Index_ProtoConstructor);
}
void Heap::FunctionObject::init(QV4::ExecutionContext *scope, const QString &name, bool createProto)
@@ -140,28 +151,16 @@ void Heap::FunctionObject::destroy()
Object::destroy();
}
-void FunctionObject::init(String *n, bool createProto)
-{
- Scope s(internalClass()->engine);
- ScopedValue protectThis(s, this);
-
- if (createProto)
- createDefaultPrototypeProperty();
-
- if (n)
- defineReadonlyConfigurableProperty(s.engine->id_name(), *n);
-}
-
-void FunctionObject::createDefaultPrototypeProperty()
+void FunctionObject::createDefaultPrototypeProperty(uint protoSlot, uint protoConstructorSlot)
{
Scope s(this);
- Q_ASSERT(internalClass() && internalClass()->find(s.engine->id_prototype()->identifier()) == Heap::FunctionObject::Index_Prototype);
- Q_ASSERT(s.engine->internalClasses(EngineBase::Class_ObjectProto)->find(s.engine->id_constructor()->identifier()) == Heap::FunctionObject::Index_ProtoConstructor);
+ Q_ASSERT(internalClass() && internalClass()->find(s.engine->id_prototype()->identifier()) == protoSlot);
+ Q_ASSERT(s.engine->internalClasses(EngineBase::Class_ObjectProto)->find(s.engine->id_constructor()->identifier()) == protoConstructorSlot);
ScopedObject proto(s, s.engine->newObject(s.engine->internalClasses(EngineBase::Class_ObjectProto)));
- proto->setProperty(Heap::FunctionObject::Index_ProtoConstructor, d());
- setProperty(Heap::FunctionObject::Index_Prototype, proto);
+ proto->setProperty(protoConstructorSlot, d());
+ setProperty(protoSlot, proto);
}
ReturnedValue FunctionObject::name() const
@@ -485,7 +484,10 @@ void Heap::ScriptFunction::init(QV4::ExecutionContext *scope, Function *function
ScopedFunctionObject f(s, this);
ScopedString name(s, function->name());
- f->init(name, true);
+ if (name)
+ f->setName(name);
+ f->createDefaultPrototypeProperty(Heap::FunctionObject::Index_Prototype, Heap::FunctionObject::Index_ProtoConstructor);
+
Q_ASSERT(internalClass && internalClass->find(s.engine->id_length()->identifier()) == Index_Length);
setProperty(s.engine, Index_Length, Primitive::fromInt32(int(function->compiledFunction->length)));
}