From 950de04322191c16c3066707889b17b0f5eb2ee6 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 23 Apr 2018 09:09:19 +0200 Subject: Fix crash in Function.prototype.bind Allocating a 0 sized MemberData hits an assertion in debug builds. Change-Id: I0251b2b38f4b48c7ed35d22f88c0c5c4a98e6464 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4functionobject.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index dc8ee550d5..83608070ec 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -360,13 +360,15 @@ ReturnedValue FunctionPrototype::method_bind(const FunctionObject *b, const Valu BoundFunction *bound = static_cast(target.getPointer()); Scoped oldArgs(scope, bound->boundArgs()); boundThis = bound->boundThis(); - int oldSize = oldArgs->size(); - boundArgs = MemberData::allocate(scope.engine, oldSize + nArgs); - boundArgs->d()->values.size = oldSize + nArgs; - for (uint i = 0; i < static_cast(oldSize); ++i) - boundArgs->set(scope.engine, i, oldArgs->data()[i]); - for (uint i = 0; i < static_cast(nArgs); ++i) - boundArgs->set(scope.engine, oldSize + i, argv[i + 1]); + int oldSize = !oldArgs ? 0 : oldArgs->size(); + if (oldSize + nArgs) { + boundArgs = MemberData::allocate(scope.engine, oldSize + nArgs); + boundArgs->d()->values.size = oldSize + nArgs; + for (uint i = 0; i < static_cast(oldSize); ++i) + boundArgs->set(scope.engine, i, oldArgs->data()[i]); + for (uint i = 0; i < static_cast(nArgs); ++i) + boundArgs->set(scope.engine, oldSize + i, argv[i + 1]); + } target = bound->target(); } else if (nArgs) { boundArgs = MemberData::allocate(scope.engine, nArgs); -- cgit v1.2.3 From fb027435f597d55b9e72465036cb0daa2b272ec0 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 25 Apr 2018 15:19:54 +0200 Subject: Only create CallContext objects for bindings that might be signal handlers Creating the callcontext for all bindings causes a 15% performance regression in both of the moving images benchmarks of qmlbench. But in most cases, we know that a binding can't be a signal handler, as those always have to start with 'on'. Take this into account and avoid creating the context for most binding expressions. Task-number: QTBUG-67782 Task-number: QTBUG-67783 Change-Id: I9a25cb916e374c7d03693e49646ca28853c6ba54 Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4codegen.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 8ada1d505e..c281275da1 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -2104,9 +2104,14 @@ int Codegen::defineFunction(const QString &name, AST::Node *ast, _context->addLocalVar(QStringLiteral("arguments"), Context::VariableDeclaration, AST::VariableDeclaration::FunctionScope); bool allVarsEscape = _context->hasWith || _context->hasTry || _context->hasDirectEval; - if (_context->compilationMode == QmlBinding // we don't really need this for bindings, but we do for signal handlers, and we don't know if the code is a signal handler or not. - || (!_context->canUseSimpleCall() && _context->compilationMode != GlobalCode && - (_context->compilationMode != EvalCode || _context->isStrict))) { + bool needsCallContext = false; + const QLatin1String exprForOn("expression for on"); + if (!_context->canUseSimpleCall() && _context->compilationMode != GlobalCode && (_context->compilationMode != EvalCode || _context->isStrict)) + needsCallContext = true; + else if (_context->compilationMode == QmlBinding && name.length() > exprForOn.size() && name.startsWith(exprForOn) && name.at(exprForOn.size()).isUpper()) + // we don't really need this for bindings, but we do for signal handlers, and we don't know if the code is a signal handler or not. + needsCallContext = true; + if (needsCallContext) { Instruction::CreateCallContext createContext; bytecodeGenerator->addInstruction(createContext); } -- cgit v1.2.3