diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-11-02 21:10:13 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-05 22:23:25 +0100 |
commit | 90338de17a56304eace1f64661a9aac21fe4d29c (patch) | |
tree | 0960479c21e3d6f49c60ad7e90ae5fbdf9595ef2 /src/qml/compiler/qv4codegen.cpp | |
parent | b5f76295659dd49d46b306b66807f44841fca992 (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/compiler/qv4codegen.cpp')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 58c9fc59bb..4810e4dace 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -355,6 +355,12 @@ bool Codegen::ScanFunctions::visit(LocalForEachStatement *ast) { return false; } +bool Codegen::ScanFunctions::visit(ThisExpression *) +{ + _env->usesThis = true; + return false; +} + bool Codegen::ScanFunctions::visit(Block *ast) { TemporaryBoolAssignment allowFuncDecls(_allowFuncDecls, _env->isStrict ? false : _allowFuncDecls); Node::accept(ast->statements, this); @@ -1953,6 +1959,7 @@ int Codegen::defineFunction(const QString &name, AST::Node *ast, V4IR::BasicBlock *exitBlock = function->newBasicBlock(groupStartBlock(), 0, V4IR::Function::DontInsertBlock); function->hasDirectEval = _env->hasDirectEval; function->usesArgumentsObject = _env->parent && (_env->usesArgumentsObject == Environment::ArgumentsObjectUsed); + function->usesThis = _env->usesThis; function->maxNumberOfArguments = qMax(_env->maxNumberOfArguments, (int)QV4::Global::ReservedArgumentCount); function->isStrict = _env->isStrict; function->isNamedExpression = _env->isNamedFunctionExpression; @@ -2036,6 +2043,11 @@ int Codegen::defineFunction(const QString &name, AST::Node *ast, _block->CALL(_block->NAME(V4IR::Name::builtin_setup_argument_object, ast->firstSourceLocation().startLine, ast->firstSourceLocation().startColumn), 0)); } + if (_function->usesThis && !_function->isStrict) { + // make sure we convert this to an object + _block->EXP(_block->CALL(_block->NAME(V4IR::Name::builtin_convert_this_to_object, + ast->firstSourceLocation().startLine, ast->firstSourceLocation().startColumn), 0)); + } sourceElements(body); |