From 1cadc5071ced2ef3f60635d26f0b3c53cc37fc3f Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 22 Jun 2018 13:02:10 +0200 Subject: Cleanups in FunctionObject rename init() to setName() as that's the only thing it's doing. Change-Id: Iecf586bc6b6df0f169bc7d2969b711e758ea3813 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4functionobject.cpp | 44 +++++++++++++++++---------------- src/qml/jsruntime/qv4functionobject_p.h | 7 +++--- 2 files changed, 27 insertions(+), 24 deletions(-) (limited to 'src/qml/jsruntime') 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(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))); } diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h index 3245137ac9..b87eab2fcf 100644 --- a/src/qml/jsruntime/qv4functionobject_p.h +++ b/src/qml/jsruntime/qv4functionobject_p.h @@ -163,9 +163,10 @@ struct Q_QML_EXPORT FunctionObject: Object { unsigned int formalParameterCount() const { return d()->formalParameterCount(); } unsigned int varCount() const { return d()->varCount(); } - void init(String *name, bool createProto); - - void createDefaultPrototypeProperty(); + void setName(String *name) { + defineReadonlyConfigurableProperty(engine()->id_name(), *name); + } + void createDefaultPrototypeProperty(uint protoSlot, uint protoConstructorSlot); inline ReturnedValue callAsConstructor(const JSCallData &data) const; ReturnedValue callAsConstructor(const Value *argv, int argc) const { -- cgit v1.2.3