diff options
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 5 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 28 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject_p.h | 7 |
4 files changed, 27 insertions, 17 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index e6a4932c2d..af87ee2a45 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -163,6 +163,11 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) FunctionPrototype *functionPrototype = new (memoryManager) FunctionPrototype(objectClass); functionClass = emptyClass->changePrototype(functionPrototype); + uint index; + functionWithProtoClass = functionClass->addMember(id_prototype, Attr_NotEnumerable|Attr_NotConfigurable, &index); + Q_ASSERT(index == FunctionObject::Index_Prototype); + protoClass = objectClass->addMember(id_constructor, Attr_NotEnumerable, &index); + Q_ASSERT(index == FunctionObject::Index_ProtoConstructor); RegExpPrototype *regExpPrototype = new (memoryManager) RegExpPrototype(objectClass); regExpClass = emptyClass->changePrototype(regExpPrototype); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 5a399ebcd9..857079a48f 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -157,7 +157,11 @@ struct Q_QML_EXPORT ExecutionEngine InternalClass *booleanClass; InternalClass *numberClass; InternalClass *dateClass; + InternalClass *functionClass; + InternalClass *functionWithProtoClass; + InternalClass *protoClass; + InternalClass *regExpClass; InternalClass *errorClass; InternalClass *evalErrorClass; 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); diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h index 09a91138cb..4d4174d053 100644 --- a/src/qml/jsruntime/qv4functionobject_p.h +++ b/src/qml/jsruntime/qv4functionobject_p.h @@ -99,6 +99,11 @@ struct Q_QML_EXPORT FunctionObject: Object { WrappedQtMethod = 1 }; + enum { + Index_Prototype = 0, + Index_ProtoConstructor = 0 + }; + ExecutionContext *scope; String *name; String * const *formalParameterList; @@ -107,7 +112,7 @@ struct Q_QML_EXPORT FunctionObject: Object { unsigned int varCount; Function *function; - FunctionObject(ExecutionContext *scope, String *name = 0); + FunctionObject(ExecutionContext *scope, String *name = 0, bool createProto = false); ~FunctionObject(); Value newInstance(); |