aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-11-02 21:10:13 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-05 22:23:25 +0100
commit90338de17a56304eace1f64661a9aac21fe4d29c (patch)
tree0960479c21e3d6f49c60ad7e90ae5fbdf9595ef2 /src/qml/jsruntime
parentb5f76295659dd49d46b306b66807f44841fca992 (diff)
Move conversion of this object into generated code
When a non strict mode function uses the this object, we need to make sure it's being correctly converted into a object before being accessed. So far this was being done by ScriptFunction::call. Move this into the generated code to avoid overhead for methods not using 'this', and simplify our ScriptFunction::call() implementation. Change-Id: I739f4a89d29ed8082ce59e48d1523776224fc29d Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4engine_p.h3
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp16
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp12
-rw-r--r--src/qml/jsruntime/qv4runtime_p.h1
-rw-r--r--src/qml/jsruntime/qv4vme_moth.cpp5
5 files changed, 19 insertions, 18 deletions
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index c585714dd0..3413238f3d 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -369,8 +369,7 @@ struct ExecutionContextSaver
}
~ExecutionContextSaver()
{
- while (engine->current != savedContext)
- engine->popContext();
+ engine->current = savedContext;
}
};
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index a270689b43..35e4202790 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -471,14 +471,6 @@ ReturnedValue ScriptFunction::call(Managed *that, CallData *callData)
CallContext *ctx = context->newCallContext(f, callData);
- if (!f->strictMode && !callData->thisObject.isObject()) {
- if (callData->thisObject.isNullOrUndefined()) {
- ctx->callData->thisObject = v4->globalObject->asReturnedValue();
- } else {
- ctx->callData->thisObject = callData->thisObject.toObject(context)->asReturnedValue();
- }
- }
-
if (f->function->compiledFunction->hasQmlDependencies())
QmlContextWrapper::registerQmlDependencies(ctx->engine, f->function->compiledFunction);
@@ -568,14 +560,6 @@ ReturnedValue SimpleScriptFunction::call(Managed *that, CallData *callData)
ExecutionContext *context = v4->current;
ExecutionContext *ctx = context->newCallContext(stackSpace, scope.alloc(f->varCount), f.getPointer(), callData);
- if (!f->strictMode && !callData->thisObject.isObject()) {
- if (callData->thisObject.isNullOrUndefined()) {
- ctx->callData->thisObject = v4->globalObject->asReturnedValue();
- } else {
- ctx->callData->thisObject = callData->thisObject.toObject(context)->asReturnedValue();
- }
- }
-
if (f->function->compiledFunction->hasQmlDependencies())
QmlContextWrapper::registerQmlDependencies(v4, f->function->compiledFunction);
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index d8ebe635bd..22af24e527 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -1277,6 +1277,18 @@ ReturnedValue __qmljs_get_imported_scripts(NoThrowContext *ctx)
return context->importedScripts.value();
}
+void __qmljs_builtin_convert_this_to_object(ExecutionContext *ctx)
+{
+ SafeValue *t = &ctx->callData->thisObject;
+ if (t->isObject())
+ return;
+ if (t->isNullOrUndefined()) {
+ *t = ctx->engine->globalObject->asReturnedValue();
+ } else {
+ *t = t->toObject(ctx)->asReturnedValue();
+ }
+}
+
} // namespace QV4
QT_END_NAMESPACE
diff --git a/src/qml/jsruntime/qv4runtime_p.h b/src/qml/jsruntime/qv4runtime_p.h
index 4f6f3a33d4..b2d2d211eb 100644
--- a/src/qml/jsruntime/qv4runtime_p.h
+++ b/src/qml/jsruntime/qv4runtime_p.h
@@ -144,6 +144,7 @@ QV4::ReturnedValue __qmljs_builtin_define_array(QV4::ExecutionContext *ctx, QV4:
void __qmljs_builtin_define_getter_setter(QV4::ExecutionContext *ctx, const QV4::ValueRef object, const QV4::StringRef name, const QV4::ValueRef getter, const QV4::ValueRef setter);
QV4::ReturnedValue __qmljs_builtin_define_object_literal(QV4::ExecutionContext *ctx, const QV4::Value *args, int classId);
QV4::ReturnedValue __qmljs_builtin_setup_arguments_object(ExecutionContext *ctx);
+void __qmljs_builtin_convert_this_to_object(ExecutionContext *ctx);
QV4::ReturnedValue __qmljs_value_from_string(QV4::String *string);
QV4::ReturnedValue __qmljs_lookup_runtime_regexp(QV4::ExecutionContext *ctx, int id);
diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp
index 82d9599582..74a42b6f2f 100644
--- a/src/qml/jsruntime/qv4vme_moth.cpp
+++ b/src/qml/jsruntime/qv4vme_moth.cpp
@@ -478,6 +478,11 @@ QV4::ReturnedValue VME::run(QV4::ExecutionContext *context, const uchar *code,
STOREVALUE(instr.result, __qmljs_builtin_setup_arguments_object(context));
MOTH_END_INSTR(CallBuiltinSetupArgumentsObject)
+ MOTH_BEGIN_INSTR(CallBuiltinConvertThisToObject)
+ __qmljs_builtin_convert_this_to_object(context);
+ CHECK_EXCEPTION;
+ MOTH_END_INSTR(CallBuiltinConvertThisToObject)
+
MOTH_BEGIN_INSTR(CreateValue)
Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::SafeValue) <= stackSize);
QV4::CallData *callData = reinterpret_cast<QV4::CallData *>(stack + instr.callData);