aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4functionobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-09-01 21:22:57 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-02 17:27:36 +0200
commit6359ab63cd9c730a168e8b8da4c275e2d03d25d5 (patch)
tree78e12031a279fe3c0ea07440ec48f908ec93322c /src/qml/jsruntime/qv4functionobject.cpp
parent036d1bcde9096ff71bf042caa14996aa71fae331 (diff)
Optimize ScriptFunction::construct() and creation of FunctionObjects
Change-Id: I7df04171a26cbe659e85f14878cc4e51030e8a5a Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4functionobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 26587bd91b..934973168d 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -69,8 +69,8 @@ using namespace QV4;
DEFINE_MANAGED_VTABLE(FunctionObject);
-FunctionObject::FunctionObject(ExecutionContext *scope, String *name)
- : Object(scope->engine->functionClass)
+FunctionObject::FunctionObject(ExecutionContext *scope, String *name, bool createProto)
+ : Object(createProto ? scope->engine->functionWithProtoClass : scope->engine->functionClass)
, scope(scope)
, name(name)
, formalParameterList(0)
@@ -89,6 +89,12 @@ FunctionObject::FunctionObject(ExecutionContext *scope, String *name)
assert(scope->next != (ExecutionContext *)0x1);
#endif
+ if (createProto) {
+ Object *proto = scope->engine->newObject(scope->engine->protoClass);
+ proto->memberData[Index_ProtoConstructor].value = Value::fromObject(this);
+ memberData[Index_Prototype].value = Value::fromObject(proto);
+ }
+
if (name)
defineReadonlyProperty(scope->engine->id_name, Value::fromString(name));
}
@@ -358,7 +364,7 @@ static Value throwTypeError(SimpleCallContext *ctx)
DEFINE_MANAGED_VTABLE(ScriptFunction);
ScriptFunction::ScriptFunction(ExecutionContext *scope, Function *function)
- : FunctionObject(scope, function->name)
+ : FunctionObject(scope, function->name, true)
{
vtbl = &static_vtbl;
this->function = function;
@@ -382,11 +388,6 @@ ScriptFunction::ScriptFunction(ExecutionContext *scope, Function *function)
varCount = function->locals.size();
varList = function->locals.constData();
- Object *proto = scope->engine->newObject();
- proto->defineDefaultProperty(scope->engine->id_constructor, Value::fromObject(this));
- Property *pd = insertMember(scope->engine->id_prototype, Attr_NotEnumerable|Attr_NotConfigurable);
- pd->value = Value::fromObject(proto);
-
if (scope->strictMode) {
FunctionObject *thrower = scope->engine->newBuiltinFunction(scope, 0, throwTypeError);
Property pd = Property::fromAccessor(thrower, thrower);
@@ -401,7 +402,7 @@ Value ScriptFunction::construct(Managed *that, const CallData &d)
ExecutionEngine *v4 = f->engine();
InternalClass *ic = v4->objectClass;
- Value proto = f->get(v4->id_prototype);
+ Value proto = f->memberData[Index_Prototype].value;
if (proto.isObject())
ic = v4->emptyClass->changePrototype(proto.objectValue());
Object *obj = v4->newObject(ic);
@@ -454,7 +455,7 @@ Value ScriptFunction::call(Managed *that, const CallData &d)
DEFINE_MANAGED_VTABLE(SimpleScriptFunction);
SimpleScriptFunction::SimpleScriptFunction(ExecutionContext *scope, Function *function)
- : FunctionObject(scope, function->name)
+ : FunctionObject(scope, function->name, true)
{
vtbl = &static_vtbl;
this->function = function;
@@ -478,11 +479,6 @@ SimpleScriptFunction::SimpleScriptFunction(ExecutionContext *scope, Function *fu
varCount = function->locals.size();
varList = function->locals.constData();
- Object *proto = scope->engine->newObject();
- proto->defineDefaultProperty(scope->engine->id_constructor, Value::fromObject(this));
- Property *pd = insertMember(scope->engine->id_prototype, Attr_NotEnumerable|Attr_NotConfigurable);
- pd->value = Value::fromObject(proto);
-
if (scope->strictMode) {
FunctionObject *thrower = scope->engine->newBuiltinFunction(scope, 0, throwTypeError);
Property pd = Property::fromAccessor(thrower, thrower);
@@ -497,7 +493,7 @@ Value SimpleScriptFunction::construct(Managed *that, const CallData &d)
ExecutionEngine *v4 = f->engine();
InternalClass *ic = v4->objectClass;
- Value proto = f->get(v4->id_prototype);
+ Value proto = f->memberData[Index_Prototype].value;
if (proto.isObject())
ic = v4->emptyClass->changePrototype(proto.objectValue());
Object *obj = v4->newObject(ic);