aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.qmake.conf2
-rw-r--r--examples/quick/canvas/smile/smile.qml12
-rw-r--r--examples/quick/demos/photosurface/main.cpp8
-rw-r--r--examples/quick/demos/samegame/content/qmldir1
-rw-r--r--examples/quick/demos/samegame/samegame.qrc2
-rw-r--r--examples/quick/embeddedinwidgets/main.cpp3
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/fbitem.cpp4
-rw-r--r--examples/quick/quickwidgets/quickwidget/main.cpp3
-rw-r--r--examples/quick/rendercontrol/cuberenderer.cpp4
-rw-r--r--examples/quick/rendercontrol/window_multithreaded.cpp8
-rw-r--r--examples/quick/rendercontrol/window_singlethreaded.cpp8
-rw-r--r--examples/quick/scenegraph/openglunderqml/squircle.cpp32
-rw-r--r--examples/quick/scenegraph/rendernode/openglrenderer.cpp4
-rw-r--r--examples/quick/scenegraph/sgengine/window.cpp2
-rw-r--r--examples/quick/scenegraph/shared/logorenderer.cpp8
-rw-r--r--examples/quick/scenegraph/textureinthread/main.cpp2
-rw-r--r--examples/quick/shared/Label.qml (renamed from examples/quick/demos/samegame/content/+blackberry/Settings.qml)11
-rw-r--r--examples/quick/shared/quick_shared.qrc1
-rw-r--r--examples/quick/shared/shared.qrc1
-rw-r--r--examples/quick/window/AllScreens.qml75
-rw-r--r--examples/quick/window/CurrentScreen.qml (renamed from examples/quick/window/ScreenInfo.qml)43
-rw-r--r--examples/quick/window/Splash.qml2
-rw-r--r--examples/quick/window/doc/src/window.qdoc2
-rw-r--r--examples/quick/window/main.cpp3
-rw-r--r--examples/quick/window/window.qml23
-rw-r--r--examples/quick/window/window.qrc3
-rw-r--r--src/3rdparty/masm/assembler/ARM64Assembler.h139
-rw-r--r--src/3rdparty/masm/assembler/ARMv7Assembler.h91
-rw-r--r--src/3rdparty/masm/assembler/AbstractMacroAssembler.h42
-rw-r--r--src/3rdparty/masm/assembler/LinkBuffer.cpp134
-rw-r--r--src/3rdparty/masm/assembler/LinkBuffer.h292
-rw-r--r--src/3rdparty/masm/assembler/MacroAssembler.h173
-rw-r--r--src/3rdparty/masm/assembler/MacroAssemblerARM.h2
-rw-r--r--src/3rdparty/masm/assembler/MacroAssemblerARM64.h45
-rw-r--r--src/3rdparty/masm/assembler/MacroAssemblerARMv7.h84
-rw-r--r--src/3rdparty/masm/assembler/MacroAssemblerCodeRef.h2
-rw-r--r--src/3rdparty/masm/assembler/MacroAssemblerMIPS.h2
-rw-r--r--src/3rdparty/masm/assembler/MacroAssemblerSH4.h2
-rw-r--r--src/3rdparty/masm/assembler/MacroAssemblerX86.h34
-rw-r--r--src/3rdparty/masm/assembler/MacroAssemblerX86_64.h29
-rw-r--r--src/3rdparty/masm/assembler/X86Assembler.h40
-rw-r--r--src/3rdparty/masm/masm.pri30
-rw-r--r--src/3rdparty/masm/stubs/ExecutableAllocator.h28
-rw-r--r--src/3rdparty/masm/wtf/Compiler.h5
-rw-r--r--src/3rdparty/masm/wtf/OSAllocatorIntegrity.cpp232
-rw-r--r--src/3rdparty/masm/wtf/OSAllocatorWinRT.cpp11
-rw-r--r--src/3rdparty/masm/wtf/Platform.h20
-rw-r--r--src/3rdparty/masm/yarr/YarrJIT.cpp6
-rw-r--r--src/imports/folderlistmodel/fileinfothread_p.h2
-rw-r--r--src/imports/folderlistmodel/fileproperty_p.h20
-rw-r--r--src/imports/folderlistmodel/qquickfolderlistmodel.h12
-rw-r--r--src/imports/imports.pro1
-rw-r--r--src/imports/layouts/qquickgridlayoutengine_p.h6
-rw-r--r--src/imports/layouts/qquicklayout.cpp18
-rw-r--r--src/imports/layouts/qquicklayoutstyleinfo.cpp2
-rw-r--r--src/imports/layouts/qquicklinearlayout.cpp30
-rw-r--r--src/imports/layouts/qquicklinearlayout_p.h6
-rw-r--r--src/imports/localstorage/plugin.cpp42
-rw-r--r--src/imports/settings/qqmlsettings_p.h6
-rw-r--r--src/imports/sharedimage/plugin.cpp134
-rw-r--r--src/imports/sharedimage/qmldir3
-rw-r--r--src/imports/sharedimage/qsharedimageloader.cpp265
-rw-r--r--src/imports/sharedimage/qsharedimageloader_p.h81
-rw-r--r--src/imports/sharedimage/sharedimage.pro17
-rw-r--r--src/imports/sharedimage/sharedimageprovider.cpp156
-rw-r--r--src/imports/sharedimage/sharedimageprovider.h58
-rw-r--r--src/imports/statemachine/signaltransition.cpp2
-rw-r--r--src/imports/statemachine/state.cpp2
-rw-r--r--src/imports/statemachine/state.h4
-rw-r--r--src/imports/statemachine/statemachine.cpp2
-rw-r--r--src/imports/statemachine/statemachine.h4
-rw-r--r--src/imports/statemachine/timeouttransition.cpp2
-rw-r--r--src/imports/statemachine/timeouttransition.h4
-rw-r--r--src/imports/testlib/TestCase.qml258
-rw-r--r--src/imports/testlib/main.cpp1
-rw-r--r--src/imports/testlib/qmldir1
-rw-r--r--src/imports/testlib/toucheventsequence.qdoc110
-rw-r--r--src/imports/xmllistmodel/qqmlxmllistmodel.cpp12
-rw-r--r--src/imports/xmllistmodel/qqmlxmllistmodel_p.h18
-rw-r--r--src/particles/qquickage_p.h3
-rw-r--r--src/particles/qquickangledirection.cpp2
-rw-r--r--src/particles/qquickangledirection_p.h2
-rw-r--r--src/particles/qquickcumulativedirection.cpp2
-rw-r--r--src/particles/qquickcumulativedirection_p.h2
-rw-r--r--src/particles/qquickcustomaffector_p.h5
-rw-r--r--src/particles/qquickcustomparticle.cpp9
-rw-r--r--src/particles/qquickcustomparticle_p.h15
-rw-r--r--src/particles/qquickdirection.cpp2
-rw-r--r--src/particles/qquickdirection_p.h2
-rw-r--r--src/particles/qquickellipseextruder_p.h4
-rw-r--r--src/particles/qquickfriction_p.h2
-rw-r--r--src/particles/qquickgravity.cpp41
-rw-r--r--src/particles/qquickgravity_p.h45
-rw-r--r--src/particles/qquickgroupgoal_p.h2
-rw-r--r--src/particles/qquickimageparticle.cpp31
-rw-r--r--src/particles/qquickimageparticle_p.h12
-rw-r--r--src/particles/qquickitemparticle_p.h10
-rw-r--r--src/particles/qquicklineextruder_p.h6
-rw-r--r--src/particles/qquickmaskextruder.cpp2
-rw-r--r--src/particles/qquickmaskextruder_p.h4
-rw-r--r--src/particles/qquickparticleaffector.cpp2
-rw-r--r--src/particles/qquickparticleaffector_p.h4
-rw-r--r--src/particles/qquickparticleemitter_p.h2
-rw-r--r--src/particles/qquickparticlegroup_p.h4
-rw-r--r--src/particles/qquickparticlepainter_p.h4
-rw-r--r--src/particles/qquickparticlesystem.cpp13
-rw-r--r--src/particles/qquickparticlesystem_p.h11
-rw-r--r--src/particles/qquickpointattractor_p.h3
-rw-r--r--src/particles/qquickpointdirection.cpp2
-rw-r--r--src/particles/qquickpointdirection_p.h2
-rw-r--r--src/particles/qquickrectangleextruder_p.h4
-rw-r--r--src/particles/qquickspritegoal_p.h5
-rw-r--r--src/particles/qquicktargetdirection.cpp2
-rw-r--r--src/particles/qquicktargetdirection_p.h2
-rw-r--r--src/particles/qquicktrailemitter_p.h4
-rw-r--r--src/particles/qquickturbulence_p.h6
-rw-r--r--src/particles/qquickv4particledata.cpp2
-rw-r--r--src/particles/qquickv4particledata_p.h2
-rw-r--r--src/particles/qquickwander_p.h3
-rw-r--r--src/particles/shaders/imageparticle.vert6
-rw-r--r--src/particles/shaders/imageparticle_core.vert6
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qmldbg_debugger.pro4
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservice.json2
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservicefactory.cpp8
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservicefactory.h2
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp14
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qv4debuggeragent.cpp16
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp44
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.h23
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp38
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/globalinspector.cpp23
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/highlight.h4
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/qqmlinspectorservicefactory.h2
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/qquickwindowinspector.h2
-rw-r--r--src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp12
-rw-r--r--src/plugins/qmltooling/qmldbg_local/qlocalclientconnectionfactory.h2
-rw-r--r--src/plugins/qmltooling/qmldbg_messages/qdebugmessageservice.cpp (renamed from src/plugins/qmltooling/qmldbg_debugger/qdebugmessageservice.cpp)0
-rw-r--r--src/plugins/qmltooling/qmldbg_messages/qdebugmessageservice.h (renamed from src/plugins/qmltooling/qmldbg_debugger/qdebugmessageservice.h)4
-rw-r--r--src/plugins/qmltooling/qmldbg_messages/qdebugmessageservice.json3
-rw-r--r--src/plugins/qmltooling/qmldbg_messages/qdebugmessageservicefactory.cpp54
-rw-r--r--src/plugins/qmltooling/qmldbg_messages/qdebugmessageservicefactory.h57
-rw-r--r--src/plugins/qmltooling/qmldbg_messages/qmldbg_messages.pro21
-rw-r--r--src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.cpp14
-rw-r--r--src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.h2
-rw-r--r--src/plugins/qmltooling/qmldbg_nativedebugger/qmldbg_nativedebugger.pro21
-rw-r--r--src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp (renamed from src/plugins/qmltooling/qmldbg_debugger/qqmlnativedebugservice.cpp)39
-rw-r--r--src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.h (renamed from src/plugins/qmltooling/qmldbg_debugger/qqmlnativedebugservice.h)2
-rw-r--r--src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.json3
-rw-r--r--src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservicefactory.cpp54
-rw-r--r--src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservicefactory.h57
-rw-r--r--src/plugins/qmltooling/qmldbg_profiler/qqmlenginecontrolservice.cpp9
-rw-r--r--src/plugins/qmltooling/qmldbg_profiler/qqmlenginecontrolservice.h1
-rw-r--r--src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp51
-rw-r--r--src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservicefactory.h2
-rw-r--r--src/plugins/qmltooling/qmldbg_quickprofiler/qquickprofileradapterfactory.h2
-rw-r--r--src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp16
-rw-r--r--src/plugins/qmltooling/qmldbg_server/qqmldebugserverfactory.h2
-rw-r--r--src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnectionfactory.h2
-rw-r--r--src/plugins/qmltooling/qmltooling.pro6
-rw-r--r--src/plugins/scenegraph/d3d12/qsgd3d12threadedrenderloop.cpp5
-rw-r--r--src/plugins/scenegraph/openvg/openvg.json3
-rw-r--r--src/plugins/scenegraph/openvg/openvg.pro57
-rw-r--r--src/plugins/scenegraph/openvg/qopenvgcontext.cpp218
-rw-r--r--src/plugins/scenegraph/openvg/qopenvgcontext_p.h88
-rw-r--r--src/plugins/scenegraph/openvg/qopenvgmatrix.cpp378
-rw-r--r--src/plugins/scenegraph/openvg/qopenvgmatrix.h108
-rw-r--r--src/plugins/scenegraph/openvg/qopenvgoffscreensurface.cpp124
-rw-r--r--src/plugins/scenegraph/openvg/qopenvgoffscreensurface.h75
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgadaptation.cpp78
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgadaptation_p.h68
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgcontext.cpp219
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgcontext_p.h104
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.cpp162
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.h97
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgglyphnode.cpp215
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgglyphnode_p.h95
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvghelpers.cpp433
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvghelpers.h64
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvginternalimagenode.cpp239
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvginternalimagenode.h92
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.cpp732
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.h100
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvglayer.cpp315
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvglayer.h113
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgnodevisitor.cpp275
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgnodevisitor.h92
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgpainternode.cpp253
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgpainternode.h97
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgpublicnodes.cpp398
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgpublicnodes.h141
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgrenderable.cpp87
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgrenderable.h75
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgrenderer.cpp90
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgrenderer_p.h61
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgrenderloop.cpp261
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgrenderloop_p.h94
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgspritenode.cpp157
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgspritenode.h78
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgtexture.cpp123
-rw-r--r--src/plugins/scenegraph/openvg/qsgopenvgtexture.h67
-rw-r--r--src/plugins/scenegraph/scenegraph.pro2
-rw-r--r--src/qml/animations/qabstractanimationjob_p.h6
-rw-r--r--src/qml/animations/qanimationgroupjob_p.h2
-rw-r--r--src/qml/animations/qcontinuinganimationgroupjob_p.h12
-rw-r--r--src/qml/animations/qparallelanimationgroupjob_p.h12
-rw-r--r--src/qml/animations/qpauseanimationjob_p.h6
-rw-r--r--src/qml/animations/qsequentialanimationgroupjob_p.h16
-rw-r--r--src/qml/compiler/compiler.pri8
-rw-r--r--src/qml/compiler/qqmlirbuilder.cpp174
-rw-r--r--src/qml/compiler/qqmlirbuilder_p.h55
-rw-r--r--src/qml/compiler/qqmltypecompiler.cpp18
-rw-r--r--src/qml/compiler/qqmltypecompiler_p.h4
-rw-r--r--src/qml/compiler/qv4codegen.cpp70
-rw-r--r--src/qml/compiler/qv4codegen_p.h228
-rw-r--r--src/qml/compiler/qv4compilationunitmapper_win.cpp8
-rw-r--r--src/qml/compiler/qv4compileddata.cpp236
-rw-r--r--src/qml/compiler/qv4compileddata_p.h87
-rw-r--r--src/qml/compiler/qv4compiler.cpp6
-rw-r--r--src/qml/compiler/qv4instr_moth_p.h3
-rw-r--r--src/qml/compiler/qv4isel_moth.cpp76
-rw-r--r--src/qml/compiler/qv4isel_moth_p.h129
-rw-r--r--src/qml/compiler/qv4jsir_p.h62
-rw-r--r--src/qml/compiler/qv4ssa.cpp132
-rw-r--r--src/qml/compiler/qv4ssa_p.h50
-rw-r--r--src/qml/debugger/qqmldebug.cpp14
-rw-r--r--src/qml/debugger/qqmldebug.h1
-rw-r--r--src/qml/debugger/qqmldebugconnector.cpp18
-rw-r--r--src/qml/debugger/qqmldebugserviceinterfaces_p.h4
-rw-r--r--src/qml/doc/src/cppintegration/data.qdoc11
-rw-r--r--src/qml/doc/src/cppintegration/definetypes.qdoc3
-rw-r--r--src/qml/doc/src/cppintegration/exposecppattributes.qdoc4
-rw-r--r--src/qml/doc/src/cppintegration/topic.qdoc2
-rw-r--r--src/qml/doc/src/javascript/dynamicobjectcreation.qdoc2
-rw-r--r--src/qml/doc/src/javascript/functionlist.qdoc2
-rw-r--r--src/qml/doc/src/javascript/imports.qdoc8
-rw-r--r--src/qml/doc/src/qmlfunctions.qdoc12
-rw-r--r--src/qml/doc/src/qmllanguageref/documents/networktransparency.qdoc8
-rw-r--r--src/qml/doc/src/qmllanguageref/syntax/objectattributes.qdoc2
-rw-r--r--src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc3
-rw-r--r--src/qml/jit/qv4assembler.cpp405
-rw-r--r--src/qml/jit/qv4assembler_p.h940
-rw-r--r--src/qml/jit/qv4binop.cpp359
-rw-r--r--src/qml/jit/qv4binop_p.h135
-rw-r--r--src/qml/jit/qv4isel_masm.cpp1381
-rw-r--r--src/qml/jit/qv4isel_masm_p.h200
-rw-r--r--src/qml/jit/qv4regalloc.cpp136
-rw-r--r--src/qml/jit/qv4targetplatform_p.h366
-rw-r--r--src/qml/jit/qv4unop.cpp60
-rw-r--r--src/qml/jit/qv4unop_p.h12
-rw-r--r--src/qml/jsruntime/jsruntime.pri6
-rw-r--r--src/qml/jsruntime/qv4argumentsobject.cpp10
-rw-r--r--src/qml/jsruntime/qv4arraybuffer.cpp69
-rw-r--r--src/qml/jsruntime/qv4arraybuffer_p.h8
-rw-r--r--src/qml/jsruntime/qv4arraydata.cpp10
-rw-r--r--src/qml/jsruntime/qv4arrayobject.cpp673
-rw-r--r--src/qml/jsruntime/qv4arrayobject_p.h46
-rw-r--r--src/qml/jsruntime/qv4booleanobject.cpp26
-rw-r--r--src/qml/jsruntime/qv4booleanobject_p.h4
-rw-r--r--src/qml/jsruntime/qv4context.cpp34
-rw-r--r--src/qml/jsruntime/qv4context_p.h24
-rw-r--r--src/qml/jsruntime/qv4dataview.cpp133
-rw-r--r--src/qml/jsruntime/qv4dataview_p.h18
-rw-r--r--src/qml/jsruntime/qv4dateobject.cpp475
-rw-r--r--src/qml/jsruntime/qv4dateobject_p.h102
-rw-r--r--src/qml/jsruntime/qv4engine.cpp16
-rw-r--r--src/qml/jsruntime/qv4engine_p.h2
-rw-r--r--src/qml/jsruntime/qv4errorobject.cpp25
-rw-r--r--src/qml/jsruntime/qv4errorobject_p.h4
-rw-r--r--src/qml/jsruntime/qv4executableallocator.cpp2
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp134
-rw-r--r--src/qml/jsruntime/qv4functionobject_p.h32
-rw-r--r--src/qml/jsruntime/qv4global_p.h9
-rw-r--r--src/qml/jsruntime/qv4globalobject.cpp146
-rw-r--r--src/qml/jsruntime/qv4globalobject_p.h20
-rw-r--r--src/qml/jsruntime/qv4include.cpp19
-rw-r--r--src/qml/jsruntime/qv4include_p.h2
-rw-r--r--src/qml/jsruntime/qv4internalclass.cpp32
-rw-r--r--src/qml/jsruntime/qv4jsonobject.cpp23
-rw-r--r--src/qml/jsruntime/qv4jsonobject_p.h4
-rw-r--r--src/qml/jsruntime/qv4lookup_p.h3
-rw-r--r--src/qml/jsruntime/qv4mathobject.cpp186
-rw-r--r--src/qml/jsruntime/qv4mathobject_p.h38
-rw-r--r--src/qml/jsruntime/qv4memberdata.cpp7
-rw-r--r--src/qml/jsruntime/qv4numberobject.cpp184
-rw-r--r--src/qml/jsruntime/qv4numberobject_p.h16
-rw-r--r--src/qml/jsruntime/qv4object.cpp97
-rw-r--r--src/qml/jsruntime/qv4object_p.h21
-rw-r--r--src/qml/jsruntime/qv4objectproto.cpp412
-rw-r--r--src/qml/jsruntime/qv4objectproto_p.h52
-rw-r--r--src/qml/jsruntime/qv4profiling.cpp2
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp105
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper_p.h4
-rw-r--r--src/qml/jsruntime/qv4regexpobject.cpp99
-rw-r--r--src/qml/jsruntime/qv4regexpobject_p.h18
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp45
-rw-r--r--src/qml/jsruntime/qv4scopedvalue_p.h32
-rw-r--r--src/qml/jsruntime/qv4script.cpp6
-rw-r--r--src/qml/jsruntime/qv4sequenceobject.cpp64
-rw-r--r--src/qml/jsruntime/qv4sequenceobject_p.h6
-rw-r--r--src/qml/jsruntime/qv4string.cpp12
-rw-r--r--src/qml/jsruntime/qv4string_p.h6
-rw-r--r--src/qml/jsruntime/qv4stringobject.cpp399
-rw-r--r--src/qml/jsruntime/qv4stringobject_p.h46
-rw-r--r--src/qml/jsruntime/qv4typedarray.cpp101
-rw-r--r--src/qml/jsruntime/qv4typedarray_p.h12
-rw-r--r--src/qml/jsruntime/qv4util_p.h6
-rw-r--r--src/qml/jsruntime/qv4value_p.h47
-rw-r--r--src/qml/jsruntime/qv4variantobject.cpp54
-rw-r--r--src/qml/jsruntime/qv4variantobject_p.h8
-rw-r--r--src/qml/jsruntime/qv4vme_moth.cpp8
-rw-r--r--src/qml/memory/memory.pri4
-rw-r--r--src/qml/memory/qv4heap_p.h43
-rw-r--r--src/qml/memory/qv4mm.cpp1020
-rw-r--r--src/qml/memory/qv4mm_p.h196
-rw-r--r--src/qml/memory/qv4mmdefs_p.h262
-rw-r--r--src/qml/parser/qqmljsast_p.h558
-rw-r--r--src/qml/qml.pro2
-rw-r--r--src/qml/qml/ftw/qqmlthread.cpp6
-rw-r--r--src/qml/qml/ftw/qqmlthread_p.h24
-rw-r--r--src/qml/qml/qqml.h39
-rw-r--r--src/qml/qml/qqmlabstractbinding.cpp2
-rw-r--r--src/qml/qml/qqmlabstracturlinterceptor.h1
-rw-r--r--src/qml/qml/qqmlapplicationengine.cpp45
-rw-r--r--src/qml/qml/qqmlapplicationengine.h7
-rw-r--r--src/qml/qml/qqmlapplicationengine_p.h4
-rw-r--r--src/qml/qml/qqmlbinding.cpp2
-rw-r--r--src/qml/qml/qqmlbinding_p.h4
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp6
-rw-r--r--src/qml/qml/qqmlboundsignal_p.h4
-rw-r--r--src/qml/qml/qqmlcomponent.cpp71
-rw-r--r--src/qml/qml/qqmlcomponent_p.h4
-rw-r--r--src/qml/qml/qqmlcontext_p.h6
-rw-r--r--src/qml/qml/qqmlcustomparser.cpp2
-rw-r--r--src/qml/qml/qqmldelayedcallqueue.cpp10
-rw-r--r--src/qml/qml/qqmldelayedcallqueue_p.h2
-rw-r--r--src/qml/qml/qqmldirparser.cpp9
-rw-r--r--src/qml/qml/qqmlengine.cpp75
-rw-r--r--src/qml/qml/qqmlengine.h3
-rw-r--r--src/qml/qml/qqmlengine_p.h1
-rw-r--r--src/qml/qml/qqmlerror.cpp72
-rw-r--r--src/qml/qml/qqmlerror.h3
-rw-r--r--src/qml/qml/qqmlexpression.cpp2
-rw-r--r--src/qml/qml/qqmlexpression_p.h4
-rw-r--r--src/qml/qml/qqmlextensionplugin.h4
-rw-r--r--src/qml/qml/qqmlfileselector_p.h2
-rw-r--r--src/qml/qml/qqmlimport.cpp342
-rw-r--r--src/qml/qml/qqmlimport_p.h42
-rw-r--r--src/qml/qml/qqmlincubator.cpp19
-rw-r--r--src/qml/qml/qqmlincubator_p.h5
-rw-r--r--src/qml/qml/qqmlinfo.cpp127
-rw-r--r--src/qml/qml/qqmlinfo.h16
-rw-r--r--src/qml/qml/qqmljavascriptexpression_p.h2
-rw-r--r--src/qml/qml/qqmllistwrapper.cpp25
-rw-r--r--src/qml/qml/qqmllistwrapper_p.h8
-rw-r--r--src/qml/qml/qqmllocale.cpp485
-rw-r--r--src/qml/qml/qqmllocale_p.h82
-rw-r--r--src/qml/qml/qqmlloggingcategory.cpp4
-rw-r--r--src/qml/qml/qqmlmetatype.cpp48
-rw-r--r--src/qml/qml/qqmlmetatype_p.h5
-rw-r--r--src/qml/qml/qqmlnotifier_p.h12
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp19
-rw-r--r--src/qml/qml/qqmlobjectcreator_p.h7
-rw-r--r--src/qml/qml/qqmlopenmetaobject_p.h6
-rw-r--r--src/qml/qml/qqmlplatform.cpp4
-rw-r--r--src/qml/qml/qqmlproperty.cpp9
-rw-r--r--src/qml/qml/qqmlpropertycache.cpp37
-rw-r--r--src/qml/qml/qqmlpropertycache_p.h14
-rw-r--r--src/qml/qml/qqmlproxymetaobject_p.h4
-rw-r--r--src/qml/qml/qqmltypeloader.cpp177
-rw-r--r--src/qml/qml/qqmltypeloader_p.h109
-rw-r--r--src/qml/qml/qqmltypenamecache.cpp65
-rw-r--r--src/qml/qml/qqmltypenamecache_p.h22
-rw-r--r--src/qml/qml/qqmlvaluetype_p.h6
-rw-r--r--src/qml/qml/qqmlvaluetypeproxybinding.cpp2
-rw-r--r--src/qml/qml/qqmlvaluetypeproxybinding_p.h6
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper.cpp20
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper_p.h4
-rw-r--r--src/qml/qml/qqmlvme.cpp12
-rw-r--r--src/qml/qml/qqmlvme_p.h1
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp43
-rw-r--r--src/qml/qml/qqmlvmemetaobject_p.h38
-rw-r--r--src/qml/qml/qqmlxmlhttprequest.cpp505
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions.cpp865
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions_p.h118
-rw-r--r--src/qml/qml/v8/qv4domerrors_p.h5
-rw-r--r--src/qml/qml/v8/qv8engine_p.h6
-rw-r--r--src/qml/qtqmlglobal_p.h40
-rw-r--r--src/qml/types/qqmlbind.cpp4
-rw-r--r--src/qml/types/qqmlbind_p.h6
-rw-r--r--src/qml/types/qqmlconnections.cpp8
-rw-r--r--src/qml/types/qqmlconnections_p.h8
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp165
-rw-r--r--src/qml/types/qqmldelegatemodel_p.h24
-rw-r--r--src/qml/types/qqmldelegatemodel_p_p.h42
-rw-r--r--src/qml/types/qqmlinstantiator.cpp6
-rw-r--r--src/qml/types/qqmlinstantiator_p.h6
-rw-r--r--src/qml/types/qqmllistmodel.cpp111
-rw-r--r--src/qml/types/qqmllistmodel_p.h12
-rw-r--r--src/qml/types/qqmllistmodel_p_p.h20
-rw-r--r--src/qml/types/qqmllistmodelworkeragent_p.h2
-rw-r--r--src/qml/types/qqmlobjectmodel.cpp8
-rw-r--r--src/qml/types/qqmlobjectmodel_p.h16
-rw-r--r--src/qml/types/qqmltimer.cpp4
-rw-r--r--src/qml/types/qqmltimer_p.h6
-rw-r--r--src/qml/types/qquickworkerscript.cpp17
-rw-r--r--src/qml/types/qquickworkerscript_p.h12
-rw-r--r--src/qml/util/qqmladaptormodel.cpp4
-rw-r--r--src/qml/util/qqmladaptormodel_p.h2
-rw-r--r--src/qml/util/qqmlchangeset.cpp12
-rw-r--r--src/qml/util/qqmllistcompositor.cpp4
-rw-r--r--src/qml/util/qqmlpropertymap.cpp8
-rw-r--r--src/qmldebug/qqmlenginecontrolclient_p.h2
-rw-r--r--src/qmldebug/qqmlprofilerclient_p.h2
-rw-r--r--src/qmldevtools/qmldevtools.pro1
-rw-r--r--src/qmldevtools/qtqmldevtoolsglobal_p.h11
-rw-r--r--src/qmltest/qmltest.pro2
-rw-r--r--src/qmltest/quicktest.cpp3
-rw-r--r--src/qmltest/quicktestevent.cpp99
-rw-r--r--src/qmltest/quicktestevent_p.h24
-rw-r--r--src/qmltest/quicktestresult.cpp2
-rw-r--r--src/quick/accessible/qaccessiblequickitem.cpp4
-rw-r--r--src/quick/accessible/qaccessiblequickview_p.h20
-rw-r--r--src/quick/designer/qqmldesignermetaobject_p.h2
-rw-r--r--src/quick/designer/qquickdesignerwindowmanager_p.h22
-rw-r--r--src/quick/doc/images/touchpoint-metrics.pngbin0 -> 38894 bytes
-rw-r--r--src/quick/doc/snippets/qml/listview/listview.qml15
-rw-r--r--src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc80
-rwxr-xr-xsrc/quick/items/checksync.pl106
-rw-r--r--src/quick/items/context2d/qquickcanvasitem.cpp80
-rw-r--r--src/quick/items/context2d/qquickcanvasitem_p.h4
-rw-r--r--src/quick/items/context2d/qquickcontext2d.cpp1297
-rw-r--r--src/quick/items/context2d/qquickcontext2d_p.h18
-rw-r--r--src/quick/items/context2d/qquickcontext2dcommandbuffer_p.h4
-rw-r--r--src/quick/items/context2d/qquickcontext2dtexture_p.h16
-rw-r--r--src/quick/items/context2d/qquickcontext2dtile_p.h8
-rw-r--r--src/quick/items/qquickaccessibleattached_p.h2
-rw-r--r--src/quick/items/qquickanchors.cpp38
-rw-r--r--src/quick/items/qquickanchors_p_p.h4
-rw-r--r--src/quick/items/qquickanimatedimage.cpp4
-rw-r--r--src/quick/items/qquickanimatedsprite.cpp2
-rw-r--r--src/quick/items/qquickborderimage.cpp2
-rw-r--r--src/quick/items/qquickdrag.cpp12
-rw-r--r--src/quick/items/qquickdrag_p.h4
-rw-r--r--src/quick/items/qquickdroparea.cpp2
-rw-r--r--src/quick/items/qquickdroparea_p.h2
-rw-r--r--src/quick/items/qquickevents.cpp2
-rw-r--r--src/quick/items/qquickflickable.cpp90
-rw-r--r--src/quick/items/qquickflickable_p.h14
-rw-r--r--src/quick/items/qquickflickable_p_p.h9
-rw-r--r--src/quick/items/qquickflickablebehavior_p.h12
-rw-r--r--src/quick/items/qquickflipable.cpp6
-rw-r--r--src/quick/items/qquickflipable_p.h2
-rw-r--r--src/quick/items/qquickgenericshadereffect.cpp4
-rw-r--r--src/quick/items/qquickgridview.cpp121
-rw-r--r--src/quick/items/qquickgridview_p.h12
-rw-r--r--src/quick/items/qquickimage.cpp15
-rw-r--r--src/quick/items/qquickimagebase.cpp15
-rw-r--r--src/quick/items/qquickimagebase_p_p.h3
-rw-r--r--src/quick/items/qquickitem.cpp82
-rw-r--r--src/quick/items/qquickitem_p.h8
-rw-r--r--src/quick/items/qquickitemanimation.cpp14
-rw-r--r--src/quick/items/qquickitemanimation_p_p.h4
-rw-r--r--src/quick/items/qquickitemgrabresult.cpp34
-rw-r--r--src/quick/items/qquickitemgrabresult.h7
-rw-r--r--src/quick/items/qquickitemsmodule.cpp12
-rw-r--r--src/quick/items/qquickitemview.cpp129
-rw-r--r--src/quick/items/qquickitemview_p.h24
-rw-r--r--src/quick/items/qquickitemview_p_p.h16
-rw-r--r--src/quick/items/qquickitemviewtransition.cpp4
-rw-r--r--src/quick/items/qquickitemviewtransition_p.h2
-rw-r--r--src/quick/items/qquicklistview.cpp214
-rw-r--r--src/quick/items/qquicklistview_p.h16
-rw-r--r--src/quick/items/qquickloader.cpp2
-rw-r--r--src/quick/items/qquickloader_p_p.h2
-rw-r--r--src/quick/items/qquickmousearea.cpp50
-rw-r--r--src/quick/items/qquickmousearea_p.h6
-rw-r--r--src/quick/items/qquickmousearea_p_p.h1
-rw-r--r--src/quick/items/qquickmultipointtoucharea.cpp73
-rw-r--r--src/quick/items/qquickmultipointtoucharea_p.h19
-rw-r--r--src/quick/items/qquickopenglshadereffect.cpp16
-rw-r--r--src/quick/items/qquickopenglshadereffect_p.h1
-rw-r--r--src/quick/items/qquickopenglshadereffectnode.cpp10
-rw-r--r--src/quick/items/qquickpainteditem.cpp2
-rw-r--r--src/quick/items/qquickpathview.cpp107
-rw-r--r--src/quick/items/qquickpathview_p.h20
-rw-r--r--src/quick/items/qquickpathview_p_p.h4
-rw-r--r--src/quick/items/qquickpositioners.cpp101
-rw-r--r--src/quick/items/qquickpositioners_p.h3
-rw-r--r--src/quick/items/qquickrepeater.cpp2
-rw-r--r--src/quick/items/qquickscreen.cpp195
-rw-r--r--src/quick/items/qquickscreen_p.h48
-rw-r--r--src/quick/items/qquickshadereffectmesh.cpp17
-rw-r--r--src/quick/items/qquickshadereffectmesh_p.h2
-rw-r--r--src/quick/items/qquickshadereffectsource.cpp2
-rw-r--r--src/quick/items/qquickspriteengine.cpp14
-rw-r--r--src/quick/items/qquickspriteengine_p.h10
-rw-r--r--src/quick/items/qquickspritesequence.cpp2
-rw-r--r--src/quick/items/qquickstateoperations.cpp16
-rw-r--r--src/quick/items/qquickstateoperations_p.h4
-rw-r--r--src/quick/items/qquicktext.cpp105
-rw-r--r--src/quick/items/qquicktext_p.h8
-rw-r--r--src/quick/items/qquicktext_p_p.h1
-rw-r--r--src/quick/items/qquicktextcontrol.cpp4
-rw-r--r--src/quick/items/qquicktextcontrol_p.h6
-rw-r--r--src/quick/items/qquicktextdocument.cpp4
-rw-r--r--src/quick/items/qquicktextdocument_p.h8
-rw-r--r--src/quick/items/qquicktextedit.cpp4
-rw-r--r--src/quick/items/qquicktextinput.cpp66
-rw-r--r--src/quick/items/qquicktextinput_p.h1
-rw-r--r--src/quick/items/qquicktextutil.cpp4
-rw-r--r--src/quick/items/qquickview.cpp2
-rw-r--r--src/quick/items/qquickview.h16
-rw-r--r--src/quick/items/qquickview_p.h2
-rw-r--r--src/quick/items/qquickwindow.cpp41
-rw-r--r--src/quick/items/qquickwindow.h1
-rw-r--r--src/quick/items/qquickwindow_p.h4
-rw-r--r--src/quick/items/qquickwindowmodule.cpp18
-rw-r--r--src/quick/items/qquickwindowmodule_p.h5
-rw-r--r--src/quick/qtquick2.cpp26
-rw-r--r--src/quick/quick.pro2
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwareadaptation.cpp2
-rw-r--r--src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp5
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h11
-rw-r--r--src/quick/scenegraph/coreapi/qsgmaterial.cpp4
-rw-r--r--src/quick/scenegraph/coreapi/qsgnode.h2
-rw-r--r--src/quick/scenegraph/coreapi/qsgrenderer_p.h6
-rw-r--r--src/quick/scenegraph/coreapi/qsgrendererinterface.cpp3
-rw-r--r--src/quick/scenegraph/coreapi/qsgrendererinterface.h3
-rw-r--r--src/quick/scenegraph/coreapi/qsgshaderrewriter.cpp14
-rw-r--r--src/quick/scenegraph/qsgadaptationlayer_p.h12
-rw-r--r--src/quick/scenegraph/qsgbasicglyphnode_p.h14
-rw-r--r--src/quick/scenegraph/qsgcontext_p.h98
-rw-r--r--src/quick/scenegraph/qsgcontextplugin_p.h6
-rw-r--r--src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h28
-rw-r--r--src/quick/scenegraph/qsgdefaultglyphnode_p_p.h16
-rw-r--r--src/quick/scenegraph/qsgdefaultrendercontext.cpp4
-rw-r--r--src/quick/scenegraph/qsgdistancefieldglyphnode_p.h18
-rw-r--r--src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h34
-rw-r--r--src/quick/scenegraph/qsgrenderloop.cpp6
-rw-r--r--src/quick/scenegraph/qsgthreadedrenderloop.cpp10
-rw-r--r--src/quick/scenegraph/qsgthreadedrenderloop_p.h30
-rw-r--r--src/quick/scenegraph/qsgwindowsrenderloop.cpp11
-rw-r--r--src/quick/scenegraph/qsgwindowsrenderloop_p.h26
-rw-r--r--src/quick/scenegraph/scenegraph.pri2
-rw-r--r--src/quick/scenegraph/util/qsgatlastexture_p.h16
-rw-r--r--src/quick/scenegraph/util/qsgdefaultimagenode.cpp15
-rw-r--r--src/quick/scenegraph/util/qsgdefaultimagenode_p.h4
-rw-r--r--src/quick/scenegraph/util/qsgdefaultpainternode_p.h30
-rw-r--r--src/quick/scenegraph/util/qsgdepthstencilbuffer_p.h2
-rw-r--r--src/quick/scenegraph/util/qsgflatcolormaterial.h6
-rw-r--r--src/quick/scenegraph/util/qsgimagenode.h2
-rw-r--r--src/quick/scenegraph/util/qsgshadersourcebuilder.cpp15
-rw-r--r--src/quick/scenegraph/util/qsgsimplematerial.h10
-rw-r--r--src/quick/scenegraph/util/qsgtexture.cpp53
-rw-r--r--src/quick/scenegraph/util/qsgtexture.h11
-rw-r--r--src/quick/scenegraph/util/qsgtexture_p.h12
-rw-r--r--src/quick/scenegraph/util/qsgtexturematerial.cpp2
-rw-r--r--src/quick/scenegraph/util/qsgtexturematerial.h17
-rw-r--r--src/quick/scenegraph/util/qsgtexturematerial_p.h10
-rw-r--r--src/quick/scenegraph/util/qsgvertexcolormaterial.h6
-rw-r--r--src/quick/util/qquickanimation.cpp22
-rw-r--r--src/quick/util/qquickanimation_p.h32
-rw-r--r--src/quick/util/qquickanimation_p_p.h30
-rw-r--r--src/quick/util/qquickanimationcontroller.cpp6
-rw-r--r--src/quick/util/qquickanimationcontroller_p.h4
-rw-r--r--src/quick/util/qquickanimator_p.h28
-rw-r--r--src/quick/util/qquickanimatorcontroller.cpp268
-rw-r--r--src/quick/util/qquickanimatorcontroller_p.h50
-rw-r--r--src/quick/util/qquickanimatorjob.cpp422
-rw-r--r--src/quick/util/qquickanimatorjob_p.h102
-rw-r--r--src/quick/util/qquickapplication.cpp46
-rw-r--r--src/quick/util/qquickapplication_p.h13
-rw-r--r--src/quick/util/qquickbehavior.cpp4
-rw-r--r--src/quick/util/qquickbehavior_p.h4
-rw-r--r--src/quick/util/qquickfontloader.cpp2
-rw-r--r--src/quick/util/qquickimageprovider.cpp165
-rw-r--r--src/quick/util/qquickimageprovider.h17
-rw-r--r--src/quick/util/qquickpath.cpp14
-rw-r--r--src/quick/util/qquickpath_p.h17
-rw-r--r--src/quick/util/qquickpixmapcache.cpp181
-rw-r--r--src/quick/util/qquickpixmapcache_p.h80
-rw-r--r--src/quick/util/qquickpropertychanges.cpp24
-rw-r--r--src/quick/util/qquickpropertychanges_p.h6
-rw-r--r--src/quick/util/qquickshortcut.cpp151
-rw-r--r--src/quick/util/qquickshortcut_p.h27
-rw-r--r--src/quick/util/qquicksmoothedanimation_p.h8
-rw-r--r--src/quick/util/qquicksmoothedanimation_p_p.h8
-rw-r--r--src/quick/util/qquickspringanimation.cpp8
-rw-r--r--src/quick/util/qquickspringanimation_p.h4
-rw-r--r--src/quick/util/qquickstate_p_p.h2
-rw-r--r--src/quick/util/qquickstatechangescript.cpp2
-rw-r--r--src/quick/util/qquickstatechangescript_p.h6
-rw-r--r--src/quick/util/qquickstategroup.cpp2
-rw-r--r--src/quick/util/qquickstategroup_p.h4
-rw-r--r--src/quick/util/qquickstyledtext.cpp3
-rw-r--r--src/quick/util/qquicktimeline_p_p.h8
-rw-r--r--src/quick/util/qquicktransition.cpp4
-rw-r--r--src/quick/util/qquickutilmodule.cpp2
-rw-r--r--src/quick/util/qquickvaluetypes.cpp3
-rw-r--r--tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/data/test.qml1
-rw-r--r--tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp96
-rw-r--r--tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenablerserver/qqmldebuggingenablerserver.cpp23
-rw-r--r--tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro1
-rw-r--r--tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp68
-rw-r--r--tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp11
-rw-r--r--tests/auto/qml/debugger/qqmlinspector/data/qtquick2.qml5
-rw-r--r--tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp53
-rw-r--r--tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp26
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp17
-rw-r--r--tests/auto/qml/qqmlapplicationengine/data/LocalComponent.qml6
-rw-r--r--tests/auto/qml/qqmlapplicationengine/data/nonResolvedLocal.qml9
-rw-r--r--tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp24
-rw-r--r--tests/auto/qml/qqmldirparser/data/classname/qmldir5
-rw-r--r--tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp9
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.cpp2
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.h8
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp122
-rw-r--r--tests/auto/qml/qqmlengine/tst_qqmlengine.cpp29
-rw-r--r--tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp58
-rw-r--r--tests/auto/qml/qqmllanguage/data/compositeTypeByName_anon_qmldir.qml9
-rw-r--r--tests/auto/qml/qqmllanguage/data/compositeTypeByName_named_qmldir.qml9
-rw-r--r--tests/auto/qml/qqmllanguage/data/quickTypeByName_anon.qml8
-rw-r--r--tests/auto/qml/qqmllanguage/data/quickTypeByName_named.qml8
-rw-r--r--tests/auto/qml/qqmllanguage/data/simpleimportByName/SimpleType.qml4
-rw-r--r--tests/auto/qml/qqmllanguage/data/simpleimportByName/qmldir1
-rw-r--r--tests/auto/qml/qqmllanguage/testtypes.cpp4
-rw-r--r--tests/auto/qml/qqmllanguage/testtypes.h54
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp88
-rw-r--r--tests/auto/qml/qqmllistreference/data/propertyList.qml12
-rw-r--r--tests/auto/qml/qqmllistreference/qqmllistreference.pro2
-rw-r--r--tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp24
-rw-r--r--tests/auto/qml/qqmllocale/data/date.qml1
-rw-r--r--tests/auto/qml/qqmllocale/tst_qqmllocale.cpp60
-rw-r--r--tests/auto/qml/qqmlmoduleplugin/data/works22.qml3
-rw-r--r--tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.2.2.pro12
-rw-r--r--tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.cpp72
-rw-r--r--tests/auto/qml/qqmlmoduleplugin/plugin.2.2/qmldir1
-rw-r--r--tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro3
-rw-r--r--tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp76
-rw-r--r--tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp42
-rw-r--r--tests/auto/qmltest-blacklist/animators/tst_stopped.qml86
-rw-r--r--tests/auto/qmltest/events/tst_drag.qml6
-rw-r--r--tests/auto/qmltest/events/tst_events.qml16
-rw-r--r--tests/auto/qmltest/events/tst_touch.qml182
-rw-r--r--tests/auto/qmltest/itemgrabber/tst_itemgrabber.qml41
-rw-r--r--tests/auto/qmltest/layout/Container.qml (renamed from examples/quick/demos/samegame/content/BBSettings.qml)32
-rw-r--r--tests/auto/qmltest/layout/ContainerUser.qml53
-rw-r--r--tests/auto/qmltest/layout/tst_layout.qml78
-rw-r--r--tests/auto/qmltest/positioners/tst_positioners.qml75
-rw-r--r--tests/auto/qmltest/selftests/tst_createTemporaryObject.qml179
-rw-r--r--tests/auto/quick/drawingmodes/data/DrawingModes.qml14
-rw-r--r--tests/auto/quick/drawingmodes/drawingmodes.pro17
-rw-r--r--tests/auto/quick/drawingmodes/tst_drawingmodes.cpp340
-rw-r--r--tests/auto/quick/examples/tst_examples.cpp6
-rw-r--r--tests/auto/quick/qquickanimations/data/pathLineUnspecifiedXYBug.qml28
-rw-r--r--tests/auto/quick/qquickanimations/data/pathSvgAnimation.qml25
-rw-r--r--tests/auto/quick/qquickanimations/tst_qquickanimations.cpp44
-rw-r--r--tests/auto/quick/qquickapplication/data/tst_displayname.qml7
-rw-r--r--tests/auto/quick/qquickapplication/qquickapplication.pro6
-rw-r--r--tests/auto/quick/qquickapplication/tst_qquickapplication.cpp27
-rw-r--r--tests/auto/quick/qquickflickable/data/overshoot.qml79
-rw-r--r--tests/auto/quick/qquickflickable/data/overshoot_reentrant.qml55
-rw-r--r--tests/auto/quick/qquickflickable/tst_qquickflickable.cpp196
-rw-r--r--tests/auto/quick/qquickgraphicsinfo/tst_qquickgraphicsinfo.cpp2
-rw-r--r--tests/auto/quick/qquickimage/tst_qquickimage.cpp16
-rw-r--r--tests/auto/quick/qquickitem/data/shortcutOverride.qml65
-rw-r--r--tests/auto/quick/qquickitem/tst_qquickitem.cpp61
-rw-r--r--tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp4
-rw-r--r--tests/auto/quick/qquicklayouts/data/rowlayout/Container2.qml55
-rw-r--r--tests/auto/quick/qquicklayouts/data/rowlayout/ContainerUser2.qml46
-rw-r--r--tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml10
-rw-r--r--tests/auto/quick/qquicklistview/data/flickBothDirections.qml70
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp79
-rw-r--r--tests/auto/quick/qquickmousearea/data/pressAndHold.qml12
-rw-r--r--tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp45
-rw-r--r--tests/auto/quick/qquickpathview/data/removePath.qml26
-rw-r--r--tests/auto/quick/qquickpathview/tst_qquickpathview.cpp14
-rw-r--r--tests/auto/quick/qquickscreen/data/screen.qml14
-rw-r--r--tests/auto/quick/qquickscreen/tst_qquickscreen.cpp40
-rw-r--r--tests/auto/quick/qquickshortcut/data/multiple.qml45
-rw-r--r--tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp45
-rw-r--r--tests/auto/quick/qquicktext/data/fontInfo.qml24
-rw-r--r--tests/auto/quick/qquicktext/tst_qquicktext.cpp24
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp1
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp52
-rw-r--r--tests/auto/quick/qquickwindow/data/grabContentItemToImage.qml15
-rw-r--r--tests/auto/quick/qquickwindow/data/windowWithScreen.qml10
-rw-r--r--tests/auto/quick/qquickwindow/qquickwindow.pro3
-rw-r--r--tests/auto/quick/qquickwindow/tst_qquickwindow.cpp38
-rw-r--r--tests/auto/quick/qquickxmllistmodel/qquickxmllistmodel.pro4
-rw-r--r--tests/auto/quick/quick.pro1
-rw-r--r--tests/auto/quick/touchmouse/tst_touchmouse.cpp602
-rw-r--r--tests/benchmarks/qml/compilation/tst_compilation.cpp71
-rw-r--r--tests/manual/text/SignalIndicator.qml66
-rw-r--r--tests/manual/text/main.cpp51
-rw-r--r--tests/manual/text/main.qml56
-rw-r--r--tests/manual/text/qml.qrc7
-rw-r--r--tests/manual/text/text.pro7
-rw-r--r--tests/manual/text/textInputPropertiesAndSignals.qml134
-rw-r--r--tests/manual/touch/mpta-crosshairs.qml85
-rw-r--r--tests/manual/v4/fun.4.js3
-rw-r--r--tests/manual/v4/tests.pro2
-rw-r--r--tests/testapplications/textlayout/styledtext-layout.qml2
-rw-r--r--tools/qml/main.cpp32
-rw-r--r--tools/qmlcachegen/qmlcache.prf12
-rw-r--r--tools/qmlcachegen/qmlcachegen.cpp312
-rw-r--r--tools/qmlcachegen/qmlcachegen.pro24
-rw-r--r--tools/qmleasing/mainwindow.cpp3
-rw-r--r--tools/qmleasing/mainwindow.h6
-rw-r--r--tools/qmleasing/splineeditor.cpp4
-rw-r--r--tools/qmleasing/splineeditor.h10
-rw-r--r--tools/qmlimportscanner/main.cpp14
-rw-r--r--tools/qmljs/qmljs.cpp12
-rw-r--r--tools/qmllint/main.cpp12
-rw-r--r--tools/qmlplugindump/main.cpp53
-rw-r--r--tools/qmlprofiler/qmlprofilerclient.h26
-rw-r--r--tools/qmlprofiler/qmlprofilerdata.cpp10
-rw-r--r--tools/qmltime/qmltime.cpp2
-rw-r--r--tools/tools.pro5
719 files changed, 26934 insertions, 10841 deletions
diff --git a/.qmake.conf b/.qmake.conf
index 9d7f045e45..f03d05c7ac 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -1,4 +1,4 @@
load(qt_build_config)
CONFIG += warning_clean
-MODULE_VERSION = 5.8.1
+MODULE_VERSION = 5.9.0
diff --git a/examples/quick/canvas/smile/smile.qml b/examples/quick/canvas/smile/smile.qml
index eebfee2d77..25e9d031de 100644
--- a/examples/quick/canvas/smile/smile.qml
+++ b/examples/quick/canvas/smile/smile.qml
@@ -101,14 +101,14 @@ Item {
ctx.moveTo(75 + 50 * Math.cos(0),
75 - 50 * Math.sin(Math.PI*2));
ctx.arc(75,75,50,0,Math.PI*2,true); // Outer circle
- ctx.moveTo(75,70);
- ctx.arc(75,70,35,0,Math.PI,false); // Mouth (clockwise)
- ctx.moveTo(60,65);
- ctx.arc(60,65,5,0,Math.PI*2,true); // Left eye
+ ctx.moveTo(60,60);
+ ctx.arc(60,60,5,0,Math.PI*2,true); // Left eye
ctx.moveTo(90 + 5 * Math.cos(0),
65 - 5 * Math.sin(Math.PI*2));
- ctx.moveTo(90,65);
- ctx.arc(90,65,5,0,Math.PI*2,true); // Right eye
+ ctx.moveTo(90,60);
+ ctx.arc(90,60,5,-Math.PI,Math.PI*3,false); // Right eye
+ ctx.moveTo(75,70);
+ ctx.arc(75,70,35,0,Math.PI,false); // Mouth (clockwise)
ctx.closePath();
if (canvas.fill)
ctx.fill();
diff --git a/examples/quick/demos/photosurface/main.cpp b/examples/quick/demos/photosurface/main.cpp
index 9456694032..b9d093df40 100644
--- a/examples/quick/demos/photosurface/main.cpp
+++ b/examples/quick/demos/photosurface/main.cpp
@@ -59,9 +59,11 @@ static QStringList imageNameFilters()
{
QStringList result;
QMimeDatabase mimeDatabase;
- foreach (const QByteArray &m, QImageReader::supportedMimeTypes()) {
- foreach (const QString &suffix, mimeDatabase.mimeTypeForName(m).suffixes())
- result.append(QStringLiteral("*.") + suffix);
+ const auto supportedMimeTypes = QImageReader::supportedMimeTypes();
+ for (const QByteArray &m : supportedMimeTypes) {
+ const auto suffixes = mimeDatabase.mimeTypeForName(m).suffixes();
+ for (const QString &suffix : suffixes)
+ result.append(QLatin1String("*.") + suffix);
}
return result;
}
diff --git a/examples/quick/demos/samegame/content/qmldir b/examples/quick/demos/samegame/content/qmldir
index 727989d006..3b552ec1f1 100644
--- a/examples/quick/demos/samegame/content/qmldir
+++ b/examples/quick/demos/samegame/content/qmldir
@@ -1,5 +1,4 @@
singleton Settings 1.0 Settings.qml
-BBSettings 1.0 BBSettings.qml
Block 1.0 Block.qml
BlockEmitter 1.0 BlockEmitter.qml
Button 1.0 Button.qml
diff --git a/examples/quick/demos/samegame/samegame.qrc b/examples/quick/demos/samegame/samegame.qrc
index e51d3fae05..348ee109f9 100644
--- a/examples/quick/demos/samegame/samegame.qrc
+++ b/examples/quick/demos/samegame/samegame.qrc
@@ -3,8 +3,6 @@
<file>samegame.qml</file>
<file>content/qmldir</file>
<file>content/Settings.qml</file>
- <file>content/BBSettings.qml</file>
- <file>content/+blackberry/Settings.qml</file>
<file>content/gfx/text-p1-won.png</file>
<file>content/gfx/background-puzzle.png</file>
<file>content/gfx/background.png</file>
diff --git a/examples/quick/embeddedinwidgets/main.cpp b/examples/quick/embeddedinwidgets/main.cpp
index 96b0df7e13..91147772ba 100644
--- a/examples/quick/embeddedinwidgets/main.cpp
+++ b/examples/quick/embeddedinwidgets/main.cpp
@@ -103,7 +103,8 @@ void MainWindow::quickViewStatusChanged(QQuickView::Status status)
{
if (status == QQuickView::Error) {
QStringList errors;
- foreach (const QQmlError &error, m_quickView->errors())
+ const auto viewErrors = m_quickView->errors();
+ for (const QQmlError &error : viewErrors)
errors.append(error.toString());
statusBar()->showMessage(errors.join(QStringLiteral(", ")));
}
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/fbitem.cpp b/examples/quick/quickwidgets/qquickviewcomparison/fbitem.cpp
index c5924bf159..49c4450b89 100644
--- a/examples/quick/quickwidgets/qquickviewcomparison/fbitem.cpp
+++ b/examples/quick/quickwidgets/qquickviewcomparison/fbitem.cpp
@@ -263,8 +263,8 @@ static const char *fragmentShaderSource =
void FbItemRenderer::initProgram()
{
m_program.reset(new QOpenGLShaderProgram);
- m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
- m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
+ m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
+ m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
m_program->bindAttributeLocation("vertex", 0);
m_program->bindAttributeLocation("normal", 1);
m_program->link();
diff --git a/examples/quick/quickwidgets/quickwidget/main.cpp b/examples/quick/quickwidgets/quickwidget/main.cpp
index 6bb6722e02..7cb35d7bcd 100644
--- a/examples/quick/quickwidgets/quickwidget/main.cpp
+++ b/examples/quick/quickwidgets/quickwidget/main.cpp
@@ -133,7 +133,8 @@ void MainWindow::quickWidgetStatusChanged(QQuickWidget::Status status)
{
if (status == QQuickWidget::Error) {
QStringList errors;
- foreach (const QQmlError &error, m_quickWidget->errors())
+ const auto widgetErrors = m_quickWidget->errors();
+ for (const QQmlError &error : widgetErrors)
errors.append(error.toString());
statusBar()->showMessage(errors.join(QStringLiteral(", ")));
}
diff --git a/examples/quick/rendercontrol/cuberenderer.cpp b/examples/quick/rendercontrol/cuberenderer.cpp
index 1b2d7dec8f..4651882542 100644
--- a/examples/quick/rendercontrol/cuberenderer.cpp
+++ b/examples/quick/rendercontrol/cuberenderer.cpp
@@ -101,8 +101,8 @@ void CubeRenderer::init(QWindow *w, QOpenGLContext *share)
" gl_FragColor = vec4(texture2D(sampler, v_coord).rgb, 1.0);\n"
"}\n";
m_program = new QOpenGLShaderProgram;
- m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
- m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
+ m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
+ m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
m_program->bindAttributeLocation("vertex", 0);
m_program->bindAttributeLocation("coord", 1);
m_program->link();
diff --git a/examples/quick/rendercontrol/window_multithreaded.cpp b/examples/quick/rendercontrol/window_multithreaded.cpp
index 4df3488ab3..013ee7c208 100644
--- a/examples/quick/rendercontrol/window_multithreaded.cpp
+++ b/examples/quick/rendercontrol/window_multithreaded.cpp
@@ -356,16 +356,16 @@ void WindowMultiThreaded::run()
disconnect(m_qmlComponent, &QQmlComponent::statusChanged, this, &WindowMultiThreaded::run);
if (m_qmlComponent->isError()) {
- QList<QQmlError> errorList = m_qmlComponent->errors();
- foreach (const QQmlError &error, errorList)
+ const QList<QQmlError> errorList = m_qmlComponent->errors();
+ for (const QQmlError &error : errorList)
qWarning() << error.url() << error.line() << error;
return;
}
QObject *rootObject = m_qmlComponent->create();
if (m_qmlComponent->isError()) {
- QList<QQmlError> errorList = m_qmlComponent->errors();
- foreach (const QQmlError &error, errorList)
+ const QList<QQmlError> errorList = m_qmlComponent->errors();
+ for (const QQmlError &error : errorList)
qWarning() << error.url() << error.line() << error;
return;
}
diff --git a/examples/quick/rendercontrol/window_singlethreaded.cpp b/examples/quick/rendercontrol/window_singlethreaded.cpp
index 45f2635ca4..ef8f2fed43 100644
--- a/examples/quick/rendercontrol/window_singlethreaded.cpp
+++ b/examples/quick/rendercontrol/window_singlethreaded.cpp
@@ -209,16 +209,16 @@ void WindowSingleThreaded::run()
disconnect(m_qmlComponent, &QQmlComponent::statusChanged, this, &WindowSingleThreaded::run);
if (m_qmlComponent->isError()) {
- QList<QQmlError> errorList = m_qmlComponent->errors();
- foreach (const QQmlError &error, errorList)
+ const QList<QQmlError> errorList = m_qmlComponent->errors();
+ for (const QQmlError &error : errorList)
qWarning() << error.url() << error.line() << error;
return;
}
QObject *rootObject = m_qmlComponent->create();
if (m_qmlComponent->isError()) {
- QList<QQmlError> errorList = m_qmlComponent->errors();
- foreach (const QQmlError &error, errorList)
+ const QList<QQmlError> errorList = m_qmlComponent->errors();
+ for (const QQmlError &error : errorList)
qWarning() << error.url() << error.line() << error;
return;
}
diff --git a/examples/quick/scenegraph/openglunderqml/squircle.cpp b/examples/quick/scenegraph/openglunderqml/squircle.cpp
index 6b25756e61..b7082892b8 100644
--- a/examples/quick/scenegraph/openglunderqml/squircle.cpp
+++ b/examples/quick/scenegraph/openglunderqml/squircle.cpp
@@ -125,22 +125,22 @@ void SquircleRenderer::paint()
initializeOpenGLFunctions();
m_program = new QOpenGLShaderProgram();
- m_program->addShaderFromSourceCode(QOpenGLShader::Vertex,
- "attribute highp vec4 vertices;"
- "varying highp vec2 coords;"
- "void main() {"
- " gl_Position = vertices;"
- " coords = vertices.xy;"
- "}");
- m_program->addShaderFromSourceCode(QOpenGLShader::Fragment,
- "uniform lowp float t;"
- "varying highp vec2 coords;"
- "void main() {"
- " lowp float i = 1. - (pow(abs(coords.x), 4.) + pow(abs(coords.y), 4.));"
- " i = smoothstep(t - 0.8, t + 0.8, i);"
- " i = floor(i * 20.) / 20.;"
- " gl_FragColor = vec4(coords * .5 + .5, i, i);"
- "}");
+ m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex,
+ "attribute highp vec4 vertices;"
+ "varying highp vec2 coords;"
+ "void main() {"
+ " gl_Position = vertices;"
+ " coords = vertices.xy;"
+ "}");
+ m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment,
+ "uniform lowp float t;"
+ "varying highp vec2 coords;"
+ "void main() {"
+ " lowp float i = 1. - (pow(abs(coords.x), 4.) + pow(abs(coords.y), 4.));"
+ " i = smoothstep(t - 0.8, t + 0.8, i);"
+ " i = floor(i * 20.) / 20.;"
+ " gl_FragColor = vec4(coords * .5 + .5, i, i);"
+ "}");
m_program->bindAttributeLocation("vertices", 0);
m_program->link();
diff --git a/examples/quick/scenegraph/rendernode/openglrenderer.cpp b/examples/quick/scenegraph/rendernode/openglrenderer.cpp
index 65c2a210bc..c84867797d 100644
--- a/examples/quick/scenegraph/rendernode/openglrenderer.cpp
+++ b/examples/quick/scenegraph/rendernode/openglrenderer.cpp
@@ -86,8 +86,8 @@ void OpenGLRenderNode::init()
" gl_FragColor = col * opacity;\n"
"}\n";
- m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
- m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
+ m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
+ m_program->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
m_program->bindAttributeLocation("posAttr", 0);
m_program->bindAttributeLocation("colAttr", 1);
m_program->link();
diff --git a/examples/quick/scenegraph/sgengine/window.cpp b/examples/quick/scenegraph/sgengine/window.cpp
index 2e4a70d2af..759bbf1fcd 100644
--- a/examples/quick/scenegraph/sgengine/window.cpp
+++ b/examples/quick/scenegraph/sgengine/window.cpp
@@ -187,7 +187,7 @@ void Window::update()
void Window::sync()
{
QList<QSharedPointer<Item> > validItems;
- foreach (QSharedPointer<Item> item, m_items) {
+ for (QSharedPointer<Item> item : qAsConst(m_items)) {
if (!item->isDone()) {
validItems.append(item);
item->sync();
diff --git a/examples/quick/scenegraph/shared/logorenderer.cpp b/examples/quick/scenegraph/shared/logorenderer.cpp
index 06f4892a49..8eb2d44c1e 100644
--- a/examples/quick/scenegraph/shared/logorenderer.cpp
+++ b/examples/quick/scenegraph/shared/logorenderer.cpp
@@ -70,7 +70,6 @@ void LogoRenderer::initialize()
glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
- QOpenGLShader *vshader1 = new QOpenGLShader(QOpenGLShader::Vertex, &program1);
const char *vsrc1 =
"attribute highp vec4 vertex;\n"
"attribute mediump vec3 normal;\n"
@@ -85,19 +84,16 @@ void LogoRenderer::initialize()
" color = clamp(color, 0.0, 1.0);\n"
" gl_Position = matrix * vertex;\n"
"}\n";
- vshader1->compileSourceCode(vsrc1);
- QOpenGLShader *fshader1 = new QOpenGLShader(QOpenGLShader::Fragment, &program1);
const char *fsrc1 =
"varying mediump vec4 color;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = color;\n"
"}\n";
- fshader1->compileSourceCode(fsrc1);
- program1.addShader(vshader1);
- program1.addShader(fshader1);
+ program1.addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vsrc1);
+ program1.addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fsrc1);
program1.link();
vertexAttr1 = program1.attributeLocation("vertex");
diff --git a/examples/quick/scenegraph/textureinthread/main.cpp b/examples/quick/scenegraph/textureinthread/main.cpp
index 22550cd22b..61d1c5e6dc 100644
--- a/examples/quick/scenegraph/textureinthread/main.cpp
+++ b/examples/quick/scenegraph/textureinthread/main.cpp
@@ -82,7 +82,7 @@ int main(int argc, char **argv)
// As the render threads make use of our QGuiApplication object
// to clean up gracefully, wait for them to finish before
// QGuiApp is taken off the heap.
- foreach (QThread *t, ThreadRenderer::threads) {
+ for (QThread *t : qAsConst(ThreadRenderer::threads)) {
t->wait();
delete t;
}
diff --git a/examples/quick/demos/samegame/content/+blackberry/Settings.qml b/examples/quick/shared/Label.qml
index c744ca6f51..ea4bef5415 100644
--- a/examples/quick/demos/samegame/content/+blackberry/Settings.qml
+++ b/examples/quick/shared/Label.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -38,10 +38,9 @@
**
****************************************************************************/
-pragma Singleton
-import QtQml 2.0
+import QtQuick 2.0
-// Instantiating a BBSettings class that can be easily tweaked for future
-// BB devices (we may have more selectors added)
-BBSettings {
+Text {
+ SystemPalette { id: palette }
+ color: palette.text
}
diff --git a/examples/quick/shared/quick_shared.qrc b/examples/quick/shared/quick_shared.qrc
index ea7e0fdd89..21f393a64d 100644
--- a/examples/quick/shared/quick_shared.qrc
+++ b/examples/quick/shared/quick_shared.qrc
@@ -4,6 +4,7 @@
<file>SimpleLauncherDelegate.qml</file>
<file>Button.qml</file>
<file>CheckBox.qml</file>
+ <file>Label.qml</file>
<file>TextField.qml</file>
<file>images/back.png</file>
<file>images/next.png</file>
diff --git a/examples/quick/shared/shared.qrc b/examples/quick/shared/shared.qrc
index 7e0c66c34b..89b3ff757e 100644
--- a/examples/quick/shared/shared.qrc
+++ b/examples/quick/shared/shared.qrc
@@ -6,6 +6,7 @@
<file>Slider.qml</file>
<file>images/slider_handle.png</file>
<file>CheckBox.qml</file>
+ <file>Label.qml</file>
<file>TabSet.qml</file>
<file>TextField.qml</file>
<file>images/back.png</file>
diff --git a/examples/quick/window/AllScreens.qml b/examples/quick/window/AllScreens.qml
new file mode 100644
index 0000000000..83a6c5f958
--- /dev/null
+++ b/examples/quick/window/AllScreens.qml
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.3
+import QtQuick.Window 2.3
+import "../shared" as Shared
+
+Column {
+ id: root
+ spacing: 8
+
+ Shared.Label {
+ text: "Total number of screens: " + screenInfo.count
+ font.bold: true
+ }
+
+ Flow {
+ spacing: 12
+ width: parent.width
+
+ Repeater {
+ id: screenInfo
+ model: Qt.application.screens
+ Shared.Label {
+ lineHeight: 1.5
+ text: name + "\n" + virtualX + ", " + virtualY + " " + modelData.width + "x" + modelData.height
+ }
+ }
+ }
+
+ Component.onCompleted: {
+ var screens = Qt.application.screens;
+ for (var i = 0; i < screens.length; ++i)
+ console.log("screen " + screens[i].name + " has geometry " +
+ screens[i].virtualX + ", " + screens[i].virtualY + " " +
+ screens[i].width + "x" + screens[i].height)
+ }
+}
diff --git a/examples/quick/window/ScreenInfo.qml b/examples/quick/window/CurrentScreen.qml
index ee0a31c794..09fbce9a74 100644
--- a/examples/quick/window/ScreenInfo.qml
+++ b/examples/quick/window/CurrentScreen.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -40,6 +40,7 @@
import QtQuick 2.3
import QtQuick.Window 2.1
+import "../shared" as Shared
Item {
id: root
@@ -70,32 +71,42 @@ Item {
y: spacing
//! [screen]
- Text {
+ Shared.Label {
text: "Screen \"" + Screen.name + "\":"
font.bold: true
}
Item { width: 1; height: 1 } // spacer
- Text { text: "dimensions" }
- Text { text: Screen.width + "x" + Screen.height }
+ Shared.Label { text: "dimensions" }
+ Shared.Label { text: Screen.width + "x" + Screen.height }
- Text { text: "pixel density" }
- Text { text: Screen.pixelDensity.toFixed(2) + " dots/mm (" + (Screen.pixelDensity * 25.4).toFixed(2) + " dots/inch)" }
+ Shared.Label { text: "pixel density" }
+ Shared.Label { text: Screen.pixelDensity.toFixed(2) + " dots/mm (" + (Screen.pixelDensity * 25.4).toFixed(2) + " dots/inch)" }
- Text { text: "logical pixel density" }
- Text { text: Screen.logicalPixelDensity.toFixed(2) + " dots/mm (" + (Screen.logicalPixelDensity * 25.4).toFixed(2) + " dots/inch)" }
+ Shared.Label { text: "logical pixel density" }
+ Shared.Label { text: Screen.logicalPixelDensity.toFixed(2) + " dots/mm (" + (Screen.logicalPixelDensity * 25.4).toFixed(2) + " dots/inch)" }
- Text { text: "device pixel ratio" }
- Text { text: Screen.devicePixelRatio.toFixed(2) }
+ Shared.Label { text: "device pixel ratio" }
+ Shared.Label { text: Screen.devicePixelRatio.toFixed(2) }
- Text { text: "available virtual desktop" }
- Text { text: Screen.desktopAvailableWidth + "x" + Screen.desktopAvailableHeight }
+ Shared.Label { text: "available virtual desktop" }
+ Shared.Label { text: Screen.desktopAvailableWidth + "x" + Screen.desktopAvailableHeight }
- Text { text: "orientation" }
- Text { text: orientationToString(Screen.orientation) + " (" + Screen.orientation + ")" }
+ Shared.Label { text: "position in virtual desktop" }
+ Shared.Label { text: Screen.virtualX + ", " + Screen.virtualY }
- Text { text: "primary orientation" }
- Text { text: orientationToString(Screen.primaryOrientation) + " (" + Screen.primaryOrientation + ")" }
+ Shared.Label { text: "orientation" }
+ Shared.Label { text: orientationToString(Screen.orientation) + " (" + Screen.orientation + ")" }
+
+ Shared.Label { text: "primary orientation" }
+ Shared.Label { text: orientationToString(Screen.primaryOrientation) + " (" + Screen.primaryOrientation + ")" }
//! [screen]
+
+ Shared.Label { text: "10mm rectangle" }
+ Rectangle {
+ color: "red"
+ width: Screen.pixelDensity * 10
+ height: width
+ }
}
}
diff --git a/examples/quick/window/Splash.qml b/examples/quick/window/Splash.qml
index 083c3babc8..3baf207992 100644
--- a/examples/quick/window/Splash.qml
+++ b/examples/quick/window/Splash.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
diff --git a/examples/quick/window/doc/src/window.qdoc b/examples/quick/window/doc/src/window.qdoc
index 5cd51beceb..2028b31383 100644
--- a/examples/quick/window/doc/src/window.qdoc
+++ b/examples/quick/window/doc/src/window.qdoc
@@ -73,7 +73,7 @@
\l Screen has several properties which are generally useful to
applications which need to rotate some content when the screen orientation
changes, to position windows on the screen or to convert real units to
- logical pixel units. ScreenInfo.qml (which is displayed inline in
+ logical pixel units. CurrentScreen.qml (which is displayed inline in
window.qml, or can be run by itself with qmlscene) simply displays the
property values, while the splash screen uses them to center the window on
the screen.
diff --git a/examples/quick/window/main.cpp b/examples/quick/window/main.cpp
index bacf52af15..ee8855cbc8 100644
--- a/examples/quick/window/main.cpp
+++ b/examples/quick/window/main.cpp
@@ -49,7 +49,8 @@
int main(int argc, char* argv[])
{
QGuiApplication app(argc, argv);
- foreach (QScreen * screen, QGuiApplication::screens())
+ const auto screens = QGuiApplication::screens();
+ for (QScreen *screen : screens)
screen->setOrientationUpdateMask(Qt::LandscapeOrientation | Qt::PortraitOrientation |
Qt::InvertedLandscapeOrientation | Qt::InvertedPortraitOrientation);
QQmlEngine engine;
diff --git a/examples/quick/window/window.qml b/examples/quick/window/window.qml
index d50bce61b3..d27ab3d0a3 100644
--- a/examples/quick/window/window.qml
+++ b/examples/quick/window/window.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
-import QtQuick.Window 2.1
+import QtQuick.Window 2.3
import "../shared" as Shared
QtObject {
@@ -47,7 +47,7 @@ QtObject {
property SystemPalette palette: SystemPalette { }
property var controlWindow: Window {
- width: visibilityLabel.implicitWidth * 1.2
+ width: col.implicitWidth + defaultSpacing * 2
height: col.implicitHeight + defaultSpacing * 2
color: palette.window
title: "Control Window"
@@ -57,7 +57,7 @@ QtObject {
anchors.margins: defaultSpacing
spacing: defaultSpacing
property real cellWidth: col.width / 3 - spacing
- Text { text: "Control the second window:" }
+ Shared.Label { text: "Control the second window:" }
Grid {
id: grid
columns: 3
@@ -121,18 +121,23 @@ QtObject {
}
return "unknown";
}
- Text {
+ Shared.Label {
id: visibilityLabel
text: "second window is " + (testWindow.visible ? "visible" : "invisible") +
" and has visibility " + parent.visibilityToString(testWindow.visibility)
}
Rectangle {
- id: horizontalRule
- color: "black"
+ color: palette.text
width: parent.width
height: 1
}
- ScreenInfo { }
+ CurrentScreen { }
+ Rectangle {
+ color: palette.text
+ width: parent.width
+ height: 1
+ }
+ AllScreens { width: parent.width }
}
}
@@ -145,7 +150,7 @@ QtObject {
Rectangle {
anchors.fill: parent
anchors.margins: defaultSpacing
- Text {
+ Shared.Label {
anchors.centerIn: parent
text: "Second Window"
}
diff --git a/examples/quick/window/window.qrc b/examples/quick/window/window.qrc
index dc211bdaaf..89d1de1b1f 100644
--- a/examples/quick/window/window.qrc
+++ b/examples/quick/window/window.qrc
@@ -2,6 +2,7 @@
<qresource prefix="/window">
<file>window.qml</file>
<file>Splash.qml</file>
- <file>ScreenInfo.qml</file>
+ <file>CurrentScreen.qml</file>
+ <file>AllScreens.qml</file>
</qresource>
</RCC>
diff --git a/src/3rdparty/masm/assembler/ARM64Assembler.h b/src/3rdparty/masm/assembler/ARM64Assembler.h
index ad5acdbb85..7390997af1 100644
--- a/src/3rdparty/masm/assembler/ARM64Assembler.h
+++ b/src/3rdparty/masm/assembler/ARM64Assembler.h
@@ -26,9 +26,10 @@
#ifndef ARM64Assembler_h
#define ARM64Assembler_h
-#if ENABLE(ASSEMBLER) && CPU(ARM64)
+#if ENABLE(ASSEMBLER) && (CPU(ARM64) || defined(V4_BOOTSTRAP))
#include "AssemblerBuffer.h"
+#include "AbstractMacroAssembler.h"
#include <limits.h>
#include <wtf/Assertions.h>
#include <wtf/Vector.h>
@@ -520,8 +521,8 @@ typedef enum {
#undef DECLARE_REGISTER
} FPRegisterID;
-static constexpr bool isSp(RegisterID reg) { return reg == sp; }
-static constexpr bool isZr(RegisterID reg) { return reg == zr; }
+static Q_DECL_CONSTEXPR bool isSp(RegisterID reg) { return reg == sp; }
+static Q_DECL_CONSTEXPR bool isZr(RegisterID reg) { return reg == zr; }
} // namespace ARM64Registers
@@ -530,15 +531,15 @@ public:
typedef ARM64Registers::RegisterID RegisterID;
typedef ARM64Registers::FPRegisterID FPRegisterID;
- static constexpr RegisterID firstRegister() { return ARM64Registers::x0; }
- static constexpr RegisterID lastRegister() { return ARM64Registers::sp; }
+ static Q_DECL_CONSTEXPR RegisterID firstRegister() { return ARM64Registers::x0; }
+ static Q_DECL_CONSTEXPR RegisterID lastRegister() { return ARM64Registers::sp; }
- static constexpr FPRegisterID firstFPRegister() { return ARM64Registers::q0; }
- static constexpr FPRegisterID lastFPRegister() { return ARM64Registers::q31; }
+ static Q_DECL_CONSTEXPR FPRegisterID firstFPRegister() { return ARM64Registers::q0; }
+ static Q_DECL_CONSTEXPR FPRegisterID lastFPRegister() { return ARM64Registers::q31; }
private:
- static constexpr bool isSp(RegisterID reg) { return ARM64Registers::isSp(reg); }
- static constexpr bool isZr(RegisterID reg) { return ARM64Registers::isZr(reg); }
+ static Q_DECL_CONSTEXPR bool isSp(RegisterID reg) { return ARM64Registers::isSp(reg); }
+ static Q_DECL_CONSTEXPR bool isZr(RegisterID reg) { return ARM64Registers::isZr(reg); }
public:
ARM64Assembler()
@@ -546,7 +547,7 @@ public:
, m_indexOfTailOfLastWatchpoint(INT_MIN)
{
}
-
+
AssemblerBuffer& buffer() { return m_buffer; }
// (HS, LO, HI, LS) -> (AE, B, A, BE)
@@ -653,9 +654,7 @@ public:
}
void operator=(const LinkRecord& other)
{
- data.copyTypes.content[0] = other.data.copyTypes.content[0];
- data.copyTypes.content[1] = other.data.copyTypes.content[1];
- data.copyTypes.content[2] = other.data.copyTypes.content[2];
+ data.realTypes = other.data.realTypes;
}
intptr_t from() const { return data.realTypes.m_from; }
void setFrom(intptr_t from) { data.realTypes.m_from = from; }
@@ -671,8 +670,8 @@ public:
private:
union {
struct RealTypes {
- intptr_t m_from : 48;
- intptr_t m_to : 48;
+ int64_t m_from : 48;
+ int64_t m_to : 48;
JumpType m_type : 8;
JumpLinkType m_linkType : 8;
Condition m_condition : 4;
@@ -680,10 +679,6 @@ public:
RegisterID m_compareRegister : 6;
bool m_is64Bit : 1;
} realTypes;
- struct CopyTypes {
- uint64_t content[3];
- } copyTypes;
- COMPILE_ASSERT(sizeof(RealTypes) == sizeof(CopyTypes), LinkRecordCopyStructSizeEqualsRealStruct);
} data;
};
@@ -743,6 +738,89 @@ public:
return isValidSignedImm9(offset);
}
+
+ // Jump:
+ //
+ // A jump object is a reference to a jump instruction that has been planted
+ // into the code buffer - it is typically used to link the jump, setting the
+ // relative offset such that when executed it will jump to the desired
+ // destination.
+ template <typename LabelType>
+ class Jump {
+ template<class TemplateAssemblerType>
+ friend class AbstractMacroAssembler;
+ friend class Call;
+ template <typename, template <typename> class> friend class LinkBufferBase;
+ public:
+ Jump()
+ {
+ }
+
+ Jump(AssemblerLabel jmp, ARM64Assembler::JumpType type = ARM64Assembler::JumpNoCondition, ARM64Assembler::Condition condition = ARM64Assembler::ConditionInvalid)
+ : m_label(jmp)
+ , m_type(type)
+ , m_condition(condition)
+ {
+ }
+
+ Jump(AssemblerLabel jmp, ARM64Assembler::JumpType type, ARM64Assembler::Condition condition, bool is64Bit, ARM64Assembler::RegisterID compareRegister)
+ : m_label(jmp)
+ , m_type(type)
+ , m_condition(condition)
+ , m_is64Bit(is64Bit)
+ , m_compareRegister(compareRegister)
+ {
+ ASSERT((type == ARM64Assembler::JumpCompareAndBranch) || (type == ARM64Assembler::JumpCompareAndBranchFixedSize));
+ }
+
+ Jump(AssemblerLabel jmp, ARM64Assembler::JumpType type, ARM64Assembler::Condition condition, unsigned bitNumber, ARM64Assembler::RegisterID compareRegister)
+ : m_label(jmp)
+ , m_type(type)
+ , m_condition(condition)
+ , m_bitNumber(bitNumber)
+ , m_compareRegister(compareRegister)
+ {
+ ASSERT((type == ARM64Assembler::JumpTestBit) || (type == ARM64Assembler::JumpTestBitFixedSize));
+ }
+
+ LabelType label() const
+ {
+ LabelType result;
+ result.m_label = m_label;
+ return result;
+ }
+
+ void link(AbstractMacroAssembler<ARM64Assembler>* masm) const
+ {
+ if ((m_type == ARM64Assembler::JumpCompareAndBranch) || (m_type == ARM64Assembler::JumpCompareAndBranchFixedSize))
+ masm->m_assembler.linkJump(m_label, masm->m_assembler.label(), m_type, m_condition, m_is64Bit, m_compareRegister);
+ else if ((m_type == ARM64Assembler::JumpTestBit) || (m_type == ARM64Assembler::JumpTestBitFixedSize))
+ masm->m_assembler.linkJump(m_label, masm->m_assembler.label(), m_type, m_condition, m_bitNumber, m_compareRegister);
+ else
+ masm->m_assembler.linkJump(m_label, masm->m_assembler.label(), m_type, m_condition);
+ }
+
+ void linkTo(LabelType label, AbstractMacroAssembler<ARM64Assembler>* masm) const
+ {
+ if ((m_type == ARM64Assembler::JumpCompareAndBranch) || (m_type == ARM64Assembler::JumpCompareAndBranchFixedSize))
+ masm->m_assembler.linkJump(m_label, label.label(), m_type, m_condition, m_is64Bit, m_compareRegister);
+ else if ((m_type == ARM64Assembler::JumpTestBit) || (m_type == ARM64Assembler::JumpTestBitFixedSize))
+ masm->m_assembler.linkJump(m_label, label.label(), m_type, m_condition, m_bitNumber, m_compareRegister);
+ else
+ masm->m_assembler.linkJump(m_label, label.label(), m_type, m_condition);
+ }
+
+ bool isSet() const { return m_label.isSet(); }
+
+ private:
+ AssemblerLabel m_label;
+ ARM64Assembler::JumpType m_type;
+ ARM64Assembler::Condition m_condition;
+ bool m_is64Bit;
+ unsigned m_bitNumber;
+ ARM64Assembler::RegisterID m_compareRegister;
+ };
+
private:
int encodeFPImm(double d)
{
@@ -2857,11 +2935,11 @@ public:
expected = disassembleMoveWideImediate(address + 1, sf, opc, hw, imm16, rd);
ASSERT_UNUSED(expected, expected && sf && opc == MoveWideOp_K && hw == 1 && rd == rdFirst);
- result |= static_cast<uintptr_t>(imm16) << 16;
+ result |= static_cast<uint64_t>(imm16) << 16;
expected = disassembleMoveWideImediate(address + 2, sf, opc, hw, imm16, rd);
ASSERT_UNUSED(expected, expected && sf && opc == MoveWideOp_K && hw == 2 && rd == rdFirst);
- result |= static_cast<uintptr_t>(imm16) << 32;
+ result |= static_cast<uint64_t>(imm16) << 32;
return reinterpret_cast<void*>(result);
}
@@ -2932,7 +3010,10 @@ public:
static void cacheFlush(void* code, size_t size)
{
-#if OS(IOS)
+#if defined(V4_BOOTSTRAP)
+ UNUSED_PARAM(code)
+ UNUSED_PARAM(size)
+#elif OS(IOS)
sys_cache_control(kCacheFunctionPrepareForExecution, code, size);
#elif OS(LINUX)
size_t page = pageSize();
@@ -2989,7 +3070,7 @@ public:
case JumpCondition: {
ASSERT(!(reinterpret_cast<intptr_t>(from) & 0x3));
ASSERT(!(reinterpret_cast<intptr_t>(to) & 0x3));
- intptr_t relative = reinterpret_cast<intptr_t>(to) - (reinterpret_cast<intptr_t>(from));
+ int64_t relative = reinterpret_cast<intptr_t>(to) - (reinterpret_cast<intptr_t>(from));
if (((relative << 43) >> 43) == relative)
return LinkJumpConditionDirect;
@@ -2999,7 +3080,7 @@ public:
case JumpCompareAndBranch: {
ASSERT(!(reinterpret_cast<intptr_t>(from) & 0x3));
ASSERT(!(reinterpret_cast<intptr_t>(to) & 0x3));
- intptr_t relative = reinterpret_cast<intptr_t>(to) - (reinterpret_cast<intptr_t>(from));
+ int64_t relative = reinterpret_cast<intptr_t>(to) - (reinterpret_cast<intptr_t>(from));
if (((relative << 43) >> 43) == relative)
return LinkJumpCompareAndBranchDirect;
@@ -3009,7 +3090,7 @@ public:
case JumpTestBit: {
ASSERT(!(reinterpret_cast<intptr_t>(from) & 0x3));
ASSERT(!(reinterpret_cast<intptr_t>(to) & 0x3));
- intptr_t relative = reinterpret_cast<intptr_t>(to) - (reinterpret_cast<intptr_t>(from));
+ int64_t relative = reinterpret_cast<intptr_t>(to) - (reinterpret_cast<intptr_t>(from));
if (((relative << 50) >> 50) == relative)
return LinkJumpTestBitDirect;
@@ -3121,7 +3202,7 @@ private:
{
ASSERT(!(reinterpret_cast<intptr_t>(from) & 3));
ASSERT(!(reinterpret_cast<intptr_t>(to) & 3));
- intptr_t offset = (reinterpret_cast<intptr_t>(to) - reinterpret_cast<intptr_t>(from)) >> 2;
+ int64_t offset = (reinterpret_cast<intptr_t>(to) - reinterpret_cast<intptr_t>(from)) >> 2;
ASSERT(((offset << 38) >> 38) == offset);
bool useDirect = ((offset << 45) >> 45) == offset; // Fits in 19 bits
@@ -3142,7 +3223,7 @@ private:
{
ASSERT(!(reinterpret_cast<intptr_t>(from) & 3));
ASSERT(!(reinterpret_cast<intptr_t>(to) & 3));
- intptr_t offset = (reinterpret_cast<intptr_t>(to) - reinterpret_cast<intptr_t>(from)) >> 2;
+ int64_t offset = (reinterpret_cast<intptr_t>(to) - reinterpret_cast<intptr_t>(from)) >> 2;
ASSERT(((offset << 38) >> 38) == offset);
bool useDirect = ((offset << 45) >> 45) == offset; // Fits in 19 bits
@@ -3163,7 +3244,7 @@ private:
{
ASSERT(!(reinterpret_cast<intptr_t>(from) & 3));
ASSERT(!(reinterpret_cast<intptr_t>(to) & 3));
- intptr_t offset = (reinterpret_cast<intptr_t>(to) - reinterpret_cast<intptr_t>(from)) >> 2;
+ int64_t offset = (reinterpret_cast<intptr_t>(to) - reinterpret_cast<intptr_t>(from)) >> 2;
ASSERT(static_cast<int>(offset) == offset);
ASSERT(((offset << 38) >> 38) == offset);
@@ -3766,6 +3847,8 @@ private:
#undef DATASIZE
#undef MEMOPSIZE
#undef CHECK_FP_MEMOP_DATASIZE
+#undef JUMP_ENUM_WITH_SIZE
+#undef JUMP_ENUM_SIZE
#endif // ENABLE(ASSEMBLER) && CPU(ARM64)
diff --git a/src/3rdparty/masm/assembler/ARMv7Assembler.h b/src/3rdparty/masm/assembler/ARMv7Assembler.h
index f0fa07a1bf..615c72fc15 100644
--- a/src/3rdparty/masm/assembler/ARMv7Assembler.h
+++ b/src/3rdparty/masm/assembler/ARMv7Assembler.h
@@ -27,10 +27,11 @@
#ifndef ARMAssembler_h
#define ARMAssembler_h
-#if ENABLE(ASSEMBLER) && CPU(ARM_THUMB2)
+#if ENABLE(ASSEMBLER) && (CPU(ARM_THUMB2) || defined(V4_BOOTSTRAP))
#include "AssemblerBuffer.h"
#include "MacroAssemblerCodeRef.h"
+#include "AbstractMacroAssembler.h"
#include <wtf/Assertions.h>
#include <wtf/Vector.h>
#include <stdint.h>
@@ -491,8 +492,8 @@ public:
private:
union {
struct RealTypes {
- intptr_t m_from : 31;
- intptr_t m_to : 31;
+ int32_t m_from : 31;
+ int32_t m_to : 31;
JumpType m_type : 8;
JumpLinkType m_linkType : 8;
Condition m_condition : 16;
@@ -510,6 +511,56 @@ public:
{
}
+
+ // Jump:
+ //
+ // A jump object is a reference to a jump instruction that has been planted
+ // into the code buffer - it is typically used to link the jump, setting the
+ // relative offset such that when executed it will jump to the desired
+ // destination.
+ template <typename LabelType>
+ class Jump {
+ template<class TemplateAssemblerType> friend class AbstractMacroAssembler;
+ friend class Call;
+ template <typename, template <typename> class> friend class LinkBufferBase;;
+ public:
+ Jump()
+ {
+ }
+
+ // Fixme: this information should be stored in the instruction stream, not in the Jump object.
+ Jump(AssemblerLabel jmp, ARMv7Assembler::JumpType type = ARMv7Assembler::JumpNoCondition, ARMv7Assembler::Condition condition = ARMv7Assembler::ConditionInvalid)
+ : m_label(jmp)
+ , m_type(type)
+ , m_condition(condition)
+ {
+ }
+
+ LabelType label() const
+ {
+ LabelType result;
+ result.m_label = m_label;
+ return result;
+ }
+
+ void link(AbstractMacroAssembler<ARMv7Assembler>* masm) const
+ {
+ masm->m_assembler.linkJump(m_label, masm->m_assembler.label(), m_type, m_condition);
+ }
+
+ void linkTo(LabelType label, AbstractMacroAssembler<ARMv7Assembler>* masm) const
+ {
+ masm->m_assembler.linkJump(m_label, label.label(), m_type, m_condition);
+ }
+
+ bool isSet() const { return m_label.isSet(); }
+
+ private:
+ AssemblerLabel m_label;
+ ARMv7Assembler::JumpType m_type;
+ ARMv7Assembler::Condition m_condition;
+ };
+
private:
// ARMv7, Appx-A.6.3
@@ -2115,6 +2166,7 @@ public:
linkJumpAbsolute(location, to);
}
+#if !defined(V4_BOOTSTRAP)
static void linkCall(void* code, AssemblerLabel from, void* to)
{
ASSERT(!(reinterpret_cast<intptr_t>(code) & 1));
@@ -2123,12 +2175,14 @@ public:
setPointer(reinterpret_cast<uint16_t*>(reinterpret_cast<intptr_t>(code) + from.m_offset) - 1, to, false);
}
+#endif
static void linkPointer(void* code, AssemblerLabel where, void* value)
{
setPointer(reinterpret_cast<char*>(code) + where.m_offset, value, false);
}
+#if !defined(V4_BOOTSTRAP)
static void relinkJump(void* from, void* to)
{
ASSERT(!(reinterpret_cast<intptr_t>(from) & 1));
@@ -2146,11 +2200,12 @@ public:
setPointer(reinterpret_cast<uint16_t*>(from) - 1, to, true);
}
-
+
static void* readCallTarget(void* from)
{
return readPointer(reinterpret_cast<uint16_t*>(from) - 1);
}
+#endif
static void repatchInt32(void* where, int32_t value)
{
@@ -2179,6 +2234,7 @@ public:
cacheFlush(location, sizeof(uint16_t) * 2);
}
+#if !defined(V4_BOOTSTRAP)
static void repatchPointer(void* where, void* value)
{
ASSERT(!(reinterpret_cast<intptr_t>(where) & 1));
@@ -2190,7 +2246,8 @@ public:
{
return reinterpret_cast<void*>(readInt32(where));
}
-
+#endif
+
static void replaceWithJump(void* instructionStart, void* to)
{
ASSERT(!(bitwise_cast<uintptr_t>(instructionStart) & 1));
@@ -2264,7 +2321,7 @@ public:
unsigned debugOffset() { return m_formatter.debugOffset(); }
-#if OS(LINUX)
+#if OS(LINUX) && !defined(V4_BOOTSTRAP)
static inline void linuxPageFlush(uintptr_t begin, uintptr_t end)
{
asm volatile(
@@ -2284,7 +2341,10 @@ public:
static void cacheFlush(void* code, size_t size)
{
-#if OS(IOS)
+#if defined(V4_BOOTSTRAP)
+ UNUSED_PARAM(code)
+ UNUSED_PARAM(size)
+#elif OS(IOS)
sys_cache_control(kCacheFunctionPrepareForExecution, code, size);
#elif OS(LINUX)
size_t page = pageSize();
@@ -2430,7 +2490,9 @@ private:
static void setPointer(void* code, void* value, bool flush)
{
- setInt32(code, reinterpret_cast<uint32_t>(value), flush);
+ // ### Deliberate "loss" of precision here. On 64-bit hosts void* is wider
+ // than uint32_t, but the target is 32-bit ARM anyway.
+ setInt32(code, static_cast<uint32_t>(reinterpret_cast<uintptr_t>(value)), flush);
}
static bool isB(void* address)
@@ -2594,6 +2656,11 @@ private:
static void linkBX(uint16_t* instruction, void* target)
{
+#if defined(V4_BOOTSTRAP)
+ UNUSED_PARAM(instruction);
+ UNUSED_PARAM(target);
+ RELEASE_ASSERT_NOT_REACHED();
+#else
// FIMXE: this should be up in the MacroAssembler layer. :-(
ASSERT(!(reinterpret_cast<intptr_t>(instruction) & 1));
ASSERT(!(reinterpret_cast<intptr_t>(target) & 1));
@@ -2606,6 +2673,7 @@ private:
instruction[-3] = twoWordOp5i6Imm4Reg4EncodedImmFirst(OP_MOVT, hi16);
instruction[-2] = twoWordOp5i6Imm4Reg4EncodedImmSecond(JUMP_TEMPORARY_REGISTER, hi16);
instruction[-1] = OP_BX | (JUMP_TEMPORARY_REGISTER << 3);
+#endif
}
void linkConditionalBX(Condition cond, uint16_t* instruction, void* target)
@@ -2638,6 +2706,9 @@ private:
instruction[-3] = OP_NOP_T2b;
linkJumpT4(instruction, target);
} else {
+#if defined(V4_BOOTSTRAP)
+ RELEASE_ASSERT_NOT_REACHED();
+#else
const uint16_t JUMP_TEMPORARY_REGISTER = ARMRegisters::ip;
ARMThumbImmediate lo16 = ARMThumbImmediate::makeUInt16(static_cast<uint16_t>(reinterpret_cast<uint32_t>(target) + 1));
ARMThumbImmediate hi16 = ARMThumbImmediate::makeUInt16(static_cast<uint16_t>(reinterpret_cast<uint32_t>(target) >> 16));
@@ -2646,6 +2717,7 @@ private:
instruction[-3] = twoWordOp5i6Imm4Reg4EncodedImmFirst(OP_MOVT, hi16);
instruction[-2] = twoWordOp5i6Imm4Reg4EncodedImmSecond(JUMP_TEMPORARY_REGISTER, hi16);
instruction[-1] = OP_BX | (JUMP_TEMPORARY_REGISTER << 3);
+#endif
}
}
@@ -2795,6 +2867,9 @@ private:
int m_indexOfTailOfLastWatchpoint;
};
+#undef JUMP_ENUM_WITH_SIZE
+#undef JUMP_ENUM_SIZE
+
} // namespace JSC
#endif // ENABLE(ASSEMBLER) && CPU(ARM_THUMB2)
diff --git a/src/3rdparty/masm/assembler/AbstractMacroAssembler.h b/src/3rdparty/masm/assembler/AbstractMacroAssembler.h
index e90dd235c6..6fac27fdf1 100644
--- a/src/3rdparty/masm/assembler/AbstractMacroAssembler.h
+++ b/src/3rdparty/masm/assembler/AbstractMacroAssembler.h
@@ -47,7 +47,10 @@
namespace JSC {
class JumpReplacementWatchpoint;
-class LinkBuffer;
+template <typename, template <typename> class>
+class LinkBufferBase;
+template <typename>
+class BranchCompactingLinkBuffer;
class RepatchBuffer;
class Watchpoint;
namespace DFG {
@@ -63,7 +66,9 @@ public:
typedef MacroAssemblerCodePtr CodePtr;
typedef MacroAssemblerCodeRef CodeRef;
+#if !CPU(ARM_THUMB2) && !CPU(ARM64) && !defined(V4_BOOTSTRAP)
class Jump;
+#endif
typedef typename AssemblerType::RegisterID RegisterID;
typedef typename AssemblerType::FPRegisterID FPRegisterID;
@@ -325,7 +330,7 @@ public:
friend class Jump;
friend class JumpReplacementWatchpoint;
friend class MacroAssemblerCodeRef;
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
friend class Watchpoint;
public:
@@ -339,6 +344,8 @@ public:
}
bool isSet() const { return m_label.isSet(); }
+
+ const AssemblerLabel &label() const { return m_label; }
private:
AssemblerLabel m_label;
};
@@ -356,7 +363,7 @@ public:
class ConvertibleLoadLabel {
template<class TemplateAssemblerType>
friend class AbstractMacroAssembler;
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
public:
ConvertibleLoadLabel()
@@ -380,7 +387,7 @@ public:
class DataLabelPtr {
template<class TemplateAssemblerType>
friend class AbstractMacroAssembler;
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
public:
DataLabelPtr()
{
@@ -404,7 +411,7 @@ public:
class DataLabel32 {
template<class TemplateAssemblerType>
friend class AbstractMacroAssembler;
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
public:
DataLabel32()
{
@@ -428,7 +435,7 @@ public:
class DataLabelCompact {
template<class TemplateAssemblerType>
friend class AbstractMacroAssembler;
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
public:
DataLabelCompact()
{
@@ -448,6 +455,11 @@ public:
AssemblerLabel m_label;
};
+#if CPU(ARM_THUMB2) || CPU(ARM64) || defined(V4_BOOTSTRAP)
+ using Jump = typename AssemblerType::template Jump<Label>;
+ friend Jump;
+#endif
+
// Call:
//
// A Call object is a reference to a call instruction that has been planted
@@ -498,18 +510,19 @@ public:
// into the code buffer - it is typically used to link the jump, setting the
// relative offset such that when executed it will jump to the desired
// destination.
+#if !CPU(ARM_THUMB2) && !CPU(ARM64) && !defined(V4_BOOTSTRAP)
class Jump {
template<class TemplateAssemblerType>
friend class AbstractMacroAssembler;
friend class Call;
friend struct DFG::OSRExit;
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
public:
Jump()
{
}
-#if CPU(ARM_THUMB2)
+#if CPU(ARM_THUMB2) || defined(V4_BOOTSTRAP)
// Fixme: this information should be stored in the instruction stream, not in the Jump object.
Jump(AssemblerLabel jmp, ARMv7Assembler::JumpType type = ARMv7Assembler::JumpNoCondition, ARMv7Assembler::Condition condition = ARMv7Assembler::ConditionInvalid)
: m_label(jmp)
@@ -610,10 +623,11 @@ public:
private:
AssemblerLabel m_label;
-#if CPU(ARM_THUMB2)
+#if CPU(ARM_THUMB2) || defined(V4_BOOTSTRAP)
ARMv7Assembler::JumpType m_type;
ARMv7Assembler::Condition m_condition;
-#elif CPU(ARM64)
+#endif
+#if CPU(ARM64)
ARM64Assembler::JumpType m_type;
ARM64Assembler::Condition m_condition;
bool m_is64Bit;
@@ -624,6 +638,7 @@ public:
SH4Assembler::JumpType m_type;
#endif
};
+#endif
struct PatchableJump {
PatchableJump()
@@ -645,7 +660,7 @@ public:
// A JumpList is a set of Jump objects.
// All jumps in the set will be linked to the same destination.
class JumpList {
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
public:
typedef Vector<Jump, 2> JumpVector;
@@ -819,7 +834,8 @@ protected:
static bool shouldBlindForSpecificArch(uint64_t) { return true; }
#endif
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
+ template <typename> friend class BranchCompactingLinkBuffer;
friend class RepatchBuffer;
static void linkJump(void* code, Jump jump, CodeLocationLabel target)
@@ -867,10 +883,12 @@ protected:
AssemblerType::repatchPointer(dataLabelPtr.dataLocation(), value);
}
+#if !defined(V4_BOOTSTRAP)
static void* readPointer(CodeLocationDataLabelPtr dataLabelPtr)
{
return AssemblerType::readPointer(dataLabelPtr.dataLocation());
}
+#endif
static void replaceWithLoad(CodeLocationConvertibleLoad label)
{
diff --git a/src/3rdparty/masm/assembler/LinkBuffer.cpp b/src/3rdparty/masm/assembler/LinkBuffer.cpp
index 432a7ee227..74c278135b 100644
--- a/src/3rdparty/masm/assembler/LinkBuffer.cpp
+++ b/src/3rdparty/masm/assembler/LinkBuffer.cpp
@@ -32,140 +32,6 @@
namespace JSC {
-LinkBuffer::CodeRef LinkBuffer::finalizeCodeWithoutDisassembly()
-{
- performFinalization();
-
- return CodeRef(m_executableMemory);
-}
-
-LinkBuffer::CodeRef LinkBuffer::finalizeCodeWithDisassembly(const char* format, ...)
-{
- ASSERT(Options::showDisassembly() || Options::showDFGDisassembly());
-
- CodeRef result = finalizeCodeWithoutDisassembly();
-
- dataLogF("Generated JIT code for ");
- va_list argList;
- va_start(argList, format);
- WTF::dataLogFV(format, argList);
- va_end(argList);
- dataLogF(":\n");
-
- dataLogF(
-#if OS(WINDOWS)
- " Code at [0x%p, 0x%p):\n",
-#else
- " Code at [%p, %p):\n",
-#endif
- result.code().executableAddress(), static_cast<char*>(result.code().executableAddress()) + result.size());
- disassemble(result.code(), m_size, " ", WTF::dataFile());
-
- return result;
-}
-
-void LinkBuffer::linkCode(void* ownerUID, JITCompilationEffort effort)
-{
- ASSERT(!m_code);
-#if !ENABLE(BRANCH_COMPACTION)
- m_executableMemory = m_assembler->m_assembler.executableCopy(*m_globalData, ownerUID, effort);
- if (!m_executableMemory)
- return;
- m_code = m_executableMemory->start();
- m_size = m_assembler->m_assembler.codeSize();
- ASSERT(m_code);
-#else
- m_initialSize = m_assembler->m_assembler.codeSize();
- m_executableMemory = m_globalData->executableAllocator.allocate(*m_globalData, m_initialSize, ownerUID, effort);
- if (!m_executableMemory)
- return;
- m_code = (uint8_t*)m_executableMemory->start();
- ASSERT(m_code);
- ExecutableAllocator::makeWritable(m_code, m_initialSize);
- uint8_t* inData = (uint8_t*)m_assembler->unlinkedCode();
- uint8_t* outData = reinterpret_cast<uint8_t*>(m_code);
- int readPtr = 0;
- int writePtr = 0;
- Vector<LinkRecord, 0, UnsafeVectorOverflow>& jumpsToLink = m_assembler->jumpsToLink();
- unsigned jumpCount = jumpsToLink.size();
- for (unsigned i = 0; i < jumpCount; ++i) {
- int offset = readPtr - writePtr;
- ASSERT(!(offset & 1));
-
- // Copy the instructions from the last jump to the current one.
- size_t regionSize = jumpsToLink[i].from() - readPtr;
- uint16_t* copySource = reinterpret_cast_ptr<uint16_t*>(inData + readPtr);
- uint16_t* copyEnd = reinterpret_cast_ptr<uint16_t*>(inData + readPtr + regionSize);
- uint16_t* copyDst = reinterpret_cast_ptr<uint16_t*>(outData + writePtr);
- ASSERT(!(regionSize % 2));
- ASSERT(!(readPtr % 2));
- ASSERT(!(writePtr % 2));
- while (copySource != copyEnd)
- *copyDst++ = *copySource++;
- m_assembler->recordLinkOffsets(readPtr, jumpsToLink[i].from(), offset);
- readPtr += regionSize;
- writePtr += regionSize;
-
- // Calculate absolute address of the jump target, in the case of backwards
- // branches we need to be precise, forward branches we are pessimistic
- const uint8_t* target;
- if (jumpsToLink[i].to() >= jumpsToLink[i].from())
- target = outData + jumpsToLink[i].to() - offset; // Compensate for what we have collapsed so far
- else
- target = outData + jumpsToLink[i].to() - m_assembler->executableOffsetFor(jumpsToLink[i].to());
-
- JumpLinkType jumpLinkType = m_assembler->computeJumpType(jumpsToLink[i], outData + writePtr, target);
- // Compact branch if we can...
- if (m_assembler->canCompact(jumpsToLink[i].type())) {
- // Step back in the write stream
- int32_t delta = m_assembler->jumpSizeDelta(jumpsToLink[i].type(), jumpLinkType);
- if (delta) {
- writePtr -= delta;
- m_assembler->recordLinkOffsets(jumpsToLink[i].from() - delta, readPtr, readPtr - writePtr);
- }
- }
- jumpsToLink[i].setFrom(writePtr);
- }
- // Copy everything after the last jump
- memcpy(outData + writePtr, inData + readPtr, m_initialSize - readPtr);
- m_assembler->recordLinkOffsets(readPtr, m_initialSize, readPtr - writePtr);
-
- for (unsigned i = 0; i < jumpCount; ++i) {
- uint8_t* location = outData + jumpsToLink[i].from();
- uint8_t* target = outData + jumpsToLink[i].to() - m_assembler->executableOffsetFor(jumpsToLink[i].to());
- m_assembler->link(jumpsToLink[i], location, target);
- }
-
- jumpsToLink.clear();
- m_size = writePtr + m_initialSize - readPtr;
- m_executableMemory->shrink(m_size);
-
-#if DUMP_LINK_STATISTICS
- dumpLinkStatistics(m_code, m_initialSize, m_size);
-#endif
-#if DUMP_CODE
- dumpCode(m_code, m_size);
-#endif
-#endif
-}
-
-void LinkBuffer::performFinalization()
-{
-#ifndef NDEBUG
- ASSERT(!m_completed);
- ASSERT(isValid());
- m_completed = true;
-#endif
-
-#if ENABLE(BRANCH_COMPACTION)
- ExecutableAllocator::makeExecutable(code(), m_initialSize);
-#else
- ASSERT(m_size <= INT_MAX);
- ExecutableAllocator::makeExecutable(code(), static_cast<int>(m_size));
-#endif
- MacroAssembler::cacheFlush(code(), m_size);
-}
-
#if DUMP_LINK_STATISTICS
void LinkBuffer::dumpLinkStatistics(void* code, size_t initializeSize, size_t finalSize)
{
diff --git a/src/3rdparty/masm/assembler/LinkBuffer.h b/src/3rdparty/masm/assembler/LinkBuffer.h
index e1882433c1..bfd0e402ca 100644
--- a/src/3rdparty/masm/assembler/LinkBuffer.h
+++ b/src/3rdparty/masm/assembler/LinkBuffer.h
@@ -36,6 +36,7 @@
#include "JITCompilationEffort.h"
#include "MacroAssembler.h"
+#include "Options.h"
#include <wtf/DataLog.h>
#include <wtf/Noncopyable.h>
@@ -43,6 +44,12 @@ namespace JSC {
class JSGlobalData;
+template <typename T>
+struct DefaultExecutableOffsetCalculator {
+ template <typename Assembler>
+ static T applyOffset(Assembler *, T src) { return src; }
+};
+
// LinkBuffer:
//
// This class assists in linking code generated by the macro assembler, once code generation
@@ -57,30 +64,24 @@ class JSGlobalData;
// * The address of a Label pointing into the code may be resolved.
// * The value referenced by a DataLabel may be set.
//
-class LinkBuffer {
- WTF_MAKE_NONCOPYABLE(LinkBuffer);
+template <typename MacroAssembler, template <typename T> class ExecutableOffsetCalculator>
+class LinkBufferBase {
+ WTF_MAKE_NONCOPYABLE(LinkBufferBase);
typedef MacroAssemblerCodeRef CodeRef;
typedef MacroAssemblerCodePtr CodePtr;
- typedef MacroAssembler::Label Label;
- typedef MacroAssembler::Jump Jump;
- typedef MacroAssembler::PatchableJump PatchableJump;
- typedef MacroAssembler::JumpList JumpList;
- typedef MacroAssembler::Call Call;
- typedef MacroAssembler::DataLabelCompact DataLabelCompact;
- typedef MacroAssembler::DataLabel32 DataLabel32;
- typedef MacroAssembler::DataLabelPtr DataLabelPtr;
- typedef MacroAssembler::ConvertibleLoadLabel ConvertibleLoadLabel;
-#if ENABLE(BRANCH_COMPACTION)
- typedef MacroAssembler::LinkRecord LinkRecord;
- typedef MacroAssembler::JumpLinkType JumpLinkType;
-#endif
+ typedef typename MacroAssembler::Label Label;
+ typedef typename MacroAssembler::Jump Jump;
+ typedef typename MacroAssembler::PatchableJump PatchableJump;
+ typedef typename MacroAssembler::JumpList JumpList;
+ typedef typename MacroAssembler::Call Call;
+ typedef typename MacroAssembler::DataLabelCompact DataLabelCompact;
+ typedef typename MacroAssembler::DataLabel32 DataLabel32;
+ typedef typename MacroAssembler::DataLabelPtr DataLabelPtr;
+ typedef typename MacroAssembler::ConvertibleLoadLabel ConvertibleLoadLabel;
public:
- LinkBuffer(JSGlobalData& globalData, MacroAssembler* masm, void* ownerUID, JITCompilationEffort effort = JITCompilationMustSucceed)
+ LinkBufferBase(JSGlobalData& globalData, MacroAssembler* masm, JITCompilationEffort effort = JITCompilationMustSucceed)
: m_size(0)
-#if ENABLE(BRANCH_COMPACTION)
- , m_initialSize(0)
-#endif
, m_code(0)
, m_assembler(masm)
, m_globalData(&globalData)
@@ -89,10 +90,13 @@ public:
, m_effort(effort)
#endif
{
- linkCode(ownerUID, effort);
+#ifdef NDEBUG
+ UNUSED_PARAM(effort)
+#endif
+ // Simon: Moved this to the sub-classes linkCode(ownerUID, effort);
}
- ~LinkBuffer()
+ ~LinkBufferBase()
{
ASSERT(m_completed || (!m_executableMemory && m_effort == JITCompilationCanFail));
}
@@ -204,8 +208,8 @@ public:
// finalizeCodeWithoutDisassembly() directly if you have your own way of
// displaying disassembly.
- CodeRef finalizeCodeWithoutDisassembly();
- CodeRef finalizeCodeWithDisassembly(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
+ inline CodeRef finalizeCodeWithoutDisassembly();
+ inline CodeRef finalizeCodeWithDisassembly(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
CodePtr trampolineAt(Label label)
{
@@ -225,21 +229,19 @@ public:
private:
template <typename T> T applyOffset(T src)
{
-#if ENABLE(BRANCH_COMPACTION)
- src.m_offset -= m_assembler->executableOffsetFor(src.m_offset);
-#endif
- return src;
+ return ExecutableOffsetCalculator<T>::applyOffset(m_assembler, src);
}
+protected:
// Keep this private! - the underlying code should only be obtained externally via finalizeCode().
void* code()
{
return m_code;
}
- void linkCode(void* ownerUID, JITCompilationEffort);
+ inline void linkCode(void* ownerUID, JITCompilationEffort);
- void performFinalization();
+ inline void performFinalization();
#if DUMP_LINK_STATISTICS
static void dumpLinkStatistics(void* code, size_t initialSize, size_t finalSize);
@@ -251,12 +253,10 @@ private:
RefPtr<ExecutableMemoryHandle> m_executableMemory;
size_t m_size;
-#if ENABLE(BRANCH_COMPACTION)
- size_t m_initialSize;
-#endif
void* m_code;
MacroAssembler* m_assembler;
JSGlobalData* m_globalData;
+protected:
#ifndef NDEBUG
bool m_completed;
JITCompilationEffort m_effort;
@@ -290,6 +290,234 @@ private:
#define FINALIZE_DFG_CODE(linkBufferReference, dataLogFArgumentsForHeading) \
FINALIZE_CODE_IF((Options::showDisassembly() || Options::showDFGDisassembly()), linkBufferReference, dataLogFArgumentsForHeading)
+
+template <typename MacroAssembler, template <typename T> class ExecutableOffsetCalculator>
+inline typename LinkBufferBase<MacroAssembler, ExecutableOffsetCalculator>::CodeRef LinkBufferBase<MacroAssembler, ExecutableOffsetCalculator>::finalizeCodeWithoutDisassembly()
+{
+ performFinalization();
+
+ return CodeRef(m_executableMemory);
+}
+
+template <typename MacroAssembler, template <typename T> class ExecutableOffsetCalculator>
+inline typename LinkBufferBase<MacroAssembler, ExecutableOffsetCalculator>::CodeRef LinkBufferBase<MacroAssembler, ExecutableOffsetCalculator>::finalizeCodeWithDisassembly(const char* format, ...)
+{
+ ASSERT(Options::showDisassembly() || Options::showDFGDisassembly());
+
+ CodeRef result = finalizeCodeWithoutDisassembly();
+
+ dataLogF("Generated JIT code for ");
+ va_list argList;
+ va_start(argList, format);
+ WTF::dataLogFV(format, argList);
+ va_end(argList);
+ dataLogF(":\n");
+
+ dataLogF(
+#if OS(WINDOWS)
+ " Code at [0x%p, 0x%p):\n",
+#else
+ " Code at [%p, %p):\n",
+#endif
+ result.code().executableAddress(), static_cast<char*>(result.code().executableAddress()) + result.size());
+ disassemble(result.code(), m_size, " ", WTF::dataFile());
+
+ return result;
+}
+
+template <typename MacroAssembler, template <typename T> class ExecutableOffsetCalculator>
+inline void LinkBufferBase<MacroAssembler, ExecutableOffsetCalculator>::linkCode(void* ownerUID, JITCompilationEffort effort)
+{
+ UNUSED_PARAM(ownerUID)
+ UNUSED_PARAM(effort)
+ ASSERT(!m_code);
+ m_executableMemory = m_assembler->m_assembler.executableCopy(*m_globalData, ownerUID, effort);
+ if (!m_executableMemory)
+ return;
+ m_code = m_executableMemory->start();
+ m_size = m_assembler->m_assembler.codeSize();
+ ASSERT(m_code);
+}
+
+template <typename MacroAssembler, template <typename T> class ExecutableOffsetCalculator>
+inline void LinkBufferBase<MacroAssembler, ExecutableOffsetCalculator>::performFinalization()
+{
+ // NOTE: This function is specialized in LinkBuffer<MacroAssemblerARMv7>
+#ifndef NDEBUG
+ ASSERT(!m_completed);
+ ASSERT(isValid());
+ m_completed = true;
+#endif
+
+ ASSERT(m_size <= INT_MAX);
+ ExecutableAllocator::makeExecutable(code(), static_cast<int>(m_size));
+ MacroAssembler::cacheFlush(code(), m_size);
+}
+
+template <typename MacroAssembler>
+class LinkBuffer : public LinkBufferBase<MacroAssembler, DefaultExecutableOffsetCalculator>
+{
+public:
+ LinkBuffer(JSGlobalData& globalData, MacroAssembler* masm, void* ownerUID, JITCompilationEffort effort = JITCompilationMustSucceed)
+ : LinkBufferBase<MacroAssembler, DefaultExecutableOffsetCalculator>(globalData, masm, effort)
+ {
+ this->linkCode(ownerUID, effort);
+ }
+};
+
+#if CPU(ARM_THUMB2) || CPU(ARM64) || defined(V4_BOOTSTRAP)
+
+template <typename T>
+struct BranchCompactingExecutableOffsetCalculator {
+ template <typename Assembler>
+ static T applyOffset(Assembler *as, T src) {
+ src.m_offset -= as->executableOffsetFor(src.m_offset);
+ return src;
+ }
+};
+
+template <typename MacroAssembler>
+class BranchCompactingLinkBuffer : public LinkBufferBase<MacroAssembler, BranchCompactingExecutableOffsetCalculator>
+{
+public:
+ BranchCompactingLinkBuffer(JSGlobalData& globalData, MacroAssembler* masm, void* ownerUID, JITCompilationEffort effort = JITCompilationMustSucceed)
+ : LinkBufferBase<MacroAssembler, BranchCompactingExecutableOffsetCalculator>(globalData, masm, effort)
+ {
+ linkCode(ownerUID, effort);
+ }
+
+ inline void performFinalization();
+
+ inline void linkCode(void* ownerUID, JITCompilationEffort);
+
+private:
+ using Base = LinkBufferBase<MacroAssembler, BranchCompactingExecutableOffsetCalculator>;
+#ifndef NDEBUG
+ using Base::m_completed;
+#endif
+ using Base::isValid;
+ using Base::code;
+ using Base::m_code;
+ using Base::m_size;
+ using Base::m_assembler;
+ using Base::m_executableMemory;
+ using Base::m_globalData;
+
+ using LinkRecord = typename MacroAssembler::LinkRecord;
+ using JumpLinkType = typename MacroAssembler::JumpLinkType;
+
+ size_t m_initialSize = 0;
+};
+
+template <typename MacroAssembler>
+inline void BranchCompactingLinkBuffer<MacroAssembler>::performFinalization()
+{
+#ifndef NDEBUG
+ ASSERT(!m_completed);
+ ASSERT(isValid());
+ this->m_completed = true;
+#endif
+
+ ExecutableAllocator::makeExecutable(code(), m_initialSize);
+ MacroAssembler::cacheFlush(code(), m_size);
+}
+
+template <typename MacroAssembler>
+inline void BranchCompactingLinkBuffer<MacroAssembler>::linkCode(void* ownerUID, JITCompilationEffort effort)
+{
+ UNUSED_PARAM(ownerUID)
+ UNUSED_PARAM(effort)
+ ASSERT(!m_code);
+ m_initialSize = m_assembler->m_assembler.codeSize();
+ m_executableMemory = m_globalData->executableAllocator.allocate(*m_globalData, m_initialSize, ownerUID, effort);
+ if (!m_executableMemory)
+ return;
+ m_code = (uint8_t*)m_executableMemory->start();
+ ASSERT(m_code);
+ ExecutableAllocator::makeWritable(m_code, m_initialSize);
+ uint8_t* inData = (uint8_t*)m_assembler->unlinkedCode();
+ uint8_t* outData = reinterpret_cast<uint8_t*>(m_code);
+ int readPtr = 0;
+ int writePtr = 0;
+ Vector<LinkRecord, 0, UnsafeVectorOverflow>& jumpsToLink = m_assembler->jumpsToLink();
+ unsigned jumpCount = unsigned(jumpsToLink.size());
+ for (unsigned i = 0; i < jumpCount; ++i) {
+ int offset = readPtr - writePtr;
+ ASSERT(!(offset & 1));
+
+ // Copy the instructions from the last jump to the current one.
+ unsigned regionSize = unsigned(jumpsToLink[i].from() - readPtr);
+ uint16_t* copySource = reinterpret_cast_ptr<uint16_t*>(inData + readPtr);
+ uint16_t* copyEnd = reinterpret_cast_ptr<uint16_t*>(inData + readPtr + regionSize);
+ uint16_t* copyDst = reinterpret_cast_ptr<uint16_t*>(outData + writePtr);
+ ASSERT(!(regionSize % 2));
+ ASSERT(!(readPtr % 2));
+ ASSERT(!(writePtr % 2));
+ while (copySource != copyEnd)
+ *copyDst++ = *copySource++;
+ m_assembler->recordLinkOffsets(readPtr, jumpsToLink[i].from(), offset);
+ readPtr += regionSize;
+ writePtr += regionSize;
+
+ // Calculate absolute address of the jump target, in the case of backwards
+ // branches we need to be precise, forward branches we are pessimistic
+ const uint8_t* target;
+ if (jumpsToLink[i].to() >= jumpsToLink[i].from())
+ target = outData + jumpsToLink[i].to() - offset; // Compensate for what we have collapsed so far
+ else
+ target = outData + jumpsToLink[i].to() - m_assembler->executableOffsetFor(jumpsToLink[i].to());
+
+ JumpLinkType jumpLinkType = m_assembler->computeJumpType(jumpsToLink[i], outData + writePtr, target);
+ // Compact branch if we can...
+ if (m_assembler->canCompact(jumpsToLink[i].type())) {
+ // Step back in the write stream
+ int32_t delta = m_assembler->jumpSizeDelta(jumpsToLink[i].type(), jumpLinkType);
+ if (delta) {
+ writePtr -= delta;
+ m_assembler->recordLinkOffsets(jumpsToLink[i].from() - delta, readPtr, readPtr - writePtr);
+ }
+ }
+ jumpsToLink[i].setFrom(writePtr);
+ }
+ // Copy everything after the last jump
+ memcpy(outData + writePtr, inData + readPtr, m_initialSize - readPtr);
+ m_assembler->recordLinkOffsets(readPtr, unsigned(m_initialSize), readPtr - writePtr);
+
+ for (unsigned i = 0; i < jumpCount; ++i) {
+ uint8_t* location = outData + jumpsToLink[i].from();
+ uint8_t* target = outData + jumpsToLink[i].to() - m_assembler->executableOffsetFor(jumpsToLink[i].to());
+ m_assembler->link(jumpsToLink[i], location, target);
+ }
+
+ jumpsToLink.clear();
+ m_size = writePtr + m_initialSize - readPtr;
+ m_executableMemory->shrink(m_size);
+}
+
+#if CPU(ARM_THUMB2) || defined(V4_BOOTSTRAP)
+template <>
+class LinkBuffer<JSC::MacroAssembler<MacroAssemblerARMv7>> : public BranchCompactingLinkBuffer<JSC::MacroAssembler<MacroAssemblerARMv7>>
+{
+public:
+ LinkBuffer(JSGlobalData& globalData, JSC::MacroAssembler<MacroAssemblerARMv7>* masm, void* ownerUID, JITCompilationEffort effort = JITCompilationMustSucceed)
+ : BranchCompactingLinkBuffer<JSC::MacroAssembler<MacroAssemblerARMv7>>(globalData, masm, ownerUID, effort)
+ {}
+};
+#endif
+
+#if CPU(ARM64) || defined(V4_BOOTSTRAP)
+template <>
+class LinkBuffer<JSC::MacroAssembler<MacroAssemblerARM64>> : public BranchCompactingLinkBuffer<JSC::MacroAssembler<MacroAssemblerARM64>>
+{
+public:
+ LinkBuffer(JSGlobalData& globalData, JSC::MacroAssembler<MacroAssemblerARM64>* masm, void* ownerUID, JITCompilationEffort effort = JITCompilationMustSucceed)
+ : BranchCompactingLinkBuffer<JSC::MacroAssembler<JSC::MacroAssemblerARM64>>(globalData, masm, ownerUID, effort)
+ {}
+};
+#endif
+
+#endif
+
} // namespace JSC
#endif // ENABLE(ASSEMBLER)
diff --git a/src/3rdparty/masm/assembler/MacroAssembler.h b/src/3rdparty/masm/assembler/MacroAssembler.h
index e122e2f3ae..7d9f156c8c 100644
--- a/src/3rdparty/masm/assembler/MacroAssembler.h
+++ b/src/3rdparty/masm/assembler/MacroAssembler.h
@@ -30,12 +30,13 @@
#if ENABLE(ASSEMBLER)
-#if CPU(ARM_THUMB2)
#include "MacroAssemblerARMv7.h"
+#include "MacroAssemblerARM64.h"
+
+#if CPU(ARM_THUMB2)
namespace JSC { typedef MacroAssemblerARMv7 MacroAssemblerBase; };
#elif CPU(ARM64)
-#include "MacroAssemblerARM64.h"
namespace JSC { typedef MacroAssemblerARM64 MacroAssemblerBase; };
#elif CPU(ARM_TRADITIONAL)
@@ -68,13 +69,53 @@ typedef MacroAssemblerSH4 MacroAssemblerBase;
namespace JSC {
+template <typename MacroAssemblerBase>
class MacroAssembler : public MacroAssemblerBase {
public:
+ using DoubleCondition = typename MacroAssemblerBase::DoubleCondition;
+ using ResultCondition = typename MacroAssemblerBase::ResultCondition;
+ using RelationalCondition = typename MacroAssemblerBase::RelationalCondition;
+ using RegisterID = typename MacroAssemblerBase::RegisterID;
+ using Address = typename MacroAssemblerBase::Address;
+ using ExtendedAddress = typename MacroAssemblerBase::ExtendedAddress;
+ using BaseIndex = typename MacroAssemblerBase::BaseIndex;
+ using ImplicitAddress = typename MacroAssemblerBase::ImplicitAddress;
+ using AbsoluteAddress = typename MacroAssemblerBase::AbsoluteAddress;
+ using TrustedImm32 = typename MacroAssemblerBase::TrustedImm32;
+ using TrustedImm64 = typename MacroAssemblerBase::TrustedImm64;
+ using TrustedImmPtr = typename MacroAssemblerBase::TrustedImmPtr;
+ using Imm32 = typename MacroAssemblerBase::Imm32;
+ using Imm64 = typename MacroAssemblerBase::Imm64;
+ using ImmPtr = typename MacroAssemblerBase::ImmPtr;
+ using Label = typename MacroAssemblerBase::Label;
+ using DataLabelPtr = typename MacroAssemblerBase::DataLabelPtr;
+ using DataLabel32 = typename MacroAssemblerBase::DataLabel32;
+ using DataLabelCompact = typename MacroAssemblerBase::DataLabelCompact;
+ using Jump = typename MacroAssemblerBase::Jump;
+ using PatchableJump = typename MacroAssemblerBase::PatchableJump;
+
using MacroAssemblerBase::pop;
using MacroAssemblerBase::jump;
using MacroAssemblerBase::branch32;
using MacroAssemblerBase::move;
+ using MacroAssemblerBase::store32;
+ using MacroAssemblerBase::add32;
+ using MacroAssemblerBase::xor32;
+ using MacroAssemblerBase::sub32;
+ using MacroAssemblerBase::load32;
+
+
+#if defined(V4_BOOTSTRAP)
+ using MacroAssemblerBase::loadPtr;
+ using MacroAssemblerBase::storePtr;
+#elif CPU(X86_64) || CPU(ARM64)
+ using MacroAssemblerBase::add64;
+ using MacroAssemblerBase::sub64;
+ using MacroAssemblerBase::xor64;
+ using MacroAssemblerBase::load64;
+ using MacroAssemblerBase::store64;
+#endif
#if ENABLE(JIT_CONSTANT_BLINDING)
using MacroAssemblerBase::add32;
@@ -100,41 +141,41 @@ public:
static DoubleCondition invert(DoubleCondition cond)
{
switch (cond) {
- case DoubleEqual:
- return DoubleNotEqualOrUnordered;
- case DoubleNotEqual:
- return DoubleEqualOrUnordered;
- case DoubleGreaterThan:
- return DoubleLessThanOrEqualOrUnordered;
- case DoubleGreaterThanOrEqual:
- return DoubleLessThanOrUnordered;
- case DoubleLessThan:
- return DoubleGreaterThanOrEqualOrUnordered;
- case DoubleLessThanOrEqual:
- return DoubleGreaterThanOrUnordered;
- case DoubleEqualOrUnordered:
- return DoubleNotEqual;
- case DoubleNotEqualOrUnordered:
- return DoubleEqual;
- case DoubleGreaterThanOrUnordered:
- return DoubleLessThanOrEqual;
- case DoubleGreaterThanOrEqualOrUnordered:
- return DoubleLessThan;
- case DoubleLessThanOrUnordered:
- return DoubleGreaterThanOrEqual;
- case DoubleLessThanOrEqualOrUnordered:
- return DoubleGreaterThan;
+ case DoubleCondition::DoubleEqual:
+ return DoubleCondition::DoubleNotEqualOrUnordered;
+ case DoubleCondition::DoubleNotEqual:
+ return DoubleCondition::DoubleEqualOrUnordered;
+ case DoubleCondition::DoubleGreaterThan:
+ return DoubleCondition::DoubleLessThanOrEqualOrUnordered;
+ case DoubleCondition::DoubleGreaterThanOrEqual:
+ return DoubleCondition::DoubleLessThanOrUnordered;
+ case DoubleCondition::DoubleLessThan:
+ return DoubleCondition::DoubleGreaterThanOrEqualOrUnordered;
+ case DoubleCondition::DoubleLessThanOrEqual:
+ return DoubleCondition::DoubleGreaterThanOrUnordered;
+ case DoubleCondition::DoubleEqualOrUnordered:
+ return DoubleCondition::DoubleNotEqual;
+ case DoubleCondition::DoubleNotEqualOrUnordered:
+ return DoubleCondition::DoubleEqual;
+ case DoubleCondition::DoubleGreaterThanOrUnordered:
+ return DoubleCondition::DoubleLessThanOrEqual;
+ case DoubleCondition::DoubleGreaterThanOrEqualOrUnordered:
+ return DoubleCondition::DoubleLessThan;
+ case DoubleCondition::DoubleLessThanOrUnordered:
+ return DoubleCondition::DoubleGreaterThanOrEqual;
+ case DoubleCondition::DoubleLessThanOrEqualOrUnordered:
+ return DoubleCondition::DoubleGreaterThan;
default:
RELEASE_ASSERT_NOT_REACHED();
- return DoubleEqual; // make compiler happy
+ return DoubleCondition::DoubleEqual; // make compiler happy
}
}
static bool isInvertible(ResultCondition cond)
{
switch (cond) {
- case Zero:
- case NonZero:
+ case ResultCondition::Zero:
+ case ResultCondition::NonZero:
return true;
default:
return false;
@@ -144,13 +185,13 @@ public:
static ResultCondition invert(ResultCondition cond)
{
switch (cond) {
- case Zero:
- return NonZero;
- case NonZero:
- return Zero;
+ case ResultCondition::Zero:
+ return ResultCondition::NonZero;
+ case ResultCondition::NonZero:
+ return ResultCondition::Zero;
default:
RELEASE_ASSERT_NOT_REACHED();
- return Zero; // Make compiler happy for release builds.
+ return ResultCondition::Zero; // Make compiler happy for release builds.
}
}
#endif
@@ -159,17 +200,17 @@ public:
// described in terms of other macro assembly methods.
void pop()
{
- addPtr(TrustedImm32(sizeof(void*)), stackPointerRegister);
+ addPtr(TrustedImm32(sizeof(void*)), MacroAssemblerBase::stackPointerRegister);
}
void peek(RegisterID dest, int index = 0)
{
- loadPtr(Address(stackPointerRegister, (index * sizeof(void*))), dest);
+ loadPtr(Address(MacroAssemblerBase::stackPointerRegister, (index * sizeof(void*))), dest);
}
Address addressForPoke(int index)
{
- return Address(stackPointerRegister, (index * sizeof(void*)));
+ return Address(MacroAssemblerBase::stackPointerRegister, (index * sizeof(void*)));
}
void poke(RegisterID src, int index = 0)
@@ -187,10 +228,10 @@ public:
storePtr(imm, addressForPoke(index));
}
-#if CPU(X86_64) || CPU(ARM64)
+#if (CPU(X86_64) || CPU(ARM64)) && !defined(V4_BOOTSTRAP)
void peek64(RegisterID dest, int index = 0)
{
- load64(Address(stackPointerRegister, (index * sizeof(void*))), dest);
+ load64(Address(MacroAssemblerBase::stackPointerRegister, (index * sizeof(void*))), dest);
}
void poke(TrustedImm64 value, int index = 0)
@@ -296,36 +337,37 @@ public:
static RelationalCondition commute(RelationalCondition condition)
{
switch (condition) {
- case Above:
- return Below;
- case AboveOrEqual:
- return BelowOrEqual;
- case Below:
- return Above;
- case BelowOrEqual:
- return AboveOrEqual;
- case GreaterThan:
- return LessThan;
- case GreaterThanOrEqual:
- return LessThanOrEqual;
- case LessThan:
- return GreaterThan;
- case LessThanOrEqual:
- return GreaterThanOrEqual;
+ case RelationalCondition::Above:
+ return RelationalCondition::Below;
+ case RelationalCondition::AboveOrEqual:
+ return RelationalCondition::BelowOrEqual;
+ case RelationalCondition::Below:
+ return RelationalCondition::Above;
+ case RelationalCondition::BelowOrEqual:
+ return RelationalCondition::AboveOrEqual;
+ case RelationalCondition::GreaterThan:
+ return RelationalCondition::LessThan;
+ case RelationalCondition::GreaterThanOrEqual:
+ return RelationalCondition::LessThanOrEqual;
+ case RelationalCondition::LessThan:
+ return RelationalCondition::GreaterThan;
+ case RelationalCondition::LessThanOrEqual:
+ return RelationalCondition::GreaterThanOrEqual;
default:
break;
}
- ASSERT(condition == Equal || condition == NotEqual);
+ ASSERT(condition == RelationalCondition::Equal || condition == RelationalCondition::NotEqual);
return condition;
}
static const unsigned BlindingModulus = 64;
bool shouldConsiderBlinding()
{
- return !(random() & (BlindingModulus - 1));
+ return !(this->random() & (BlindingModulus - 1));
}
+#if !defined(V4_BOOTSTRAP)
// Ptr methods
// On 32-bit platforms (i.e. x86), these methods directly map onto their 32-bit equivalents.
// FIXME: should this use a test for 32-bitness instead of this specific exception?
@@ -850,6 +892,7 @@ public:
{
return branchSub64(cond, src1, src2, dest);
}
+#endif // !defined(V4_BOOTSTRAP)
#if ENABLE(JIT_CONSTANT_BLINDING)
using MacroAssemblerBase::and64;
@@ -1447,6 +1490,22 @@ public:
#endif
};
+#if CPU(ARM_THUMB2)
+typedef MacroAssembler<MacroAssemblerARMv7> DefaultMacroAssembler;
+#elif CPU(ARM64)
+typedef MacroAssembler<MacroAssemblerARM64> DefaultMacroAssembler;
+#elif CPU(ARM_TRADITIONAL)
+typedef MacroAssembler<MacroAssemblerARM> DefaultMacroAssembler;
+#elif CPU(MIPS)
+typedef MacroAssembler<MacroAssemblerMIPS> DefaultMacroAssembler;
+#elif CPU(X86)
+typedef MacroAssembler<MacroAssemblerX86> DefaultMacroAssembler;
+#elif CPU(X86_64)
+typedef MacroAssembler<MacroAssemblerX86_64> DefaultMacroAssembler;
+#elif CPU(SH4)
+typedef JSC::MacroAssemblerSH4 DefaultMacroAssembler;
+#endif
+
} // namespace JSC
#else // ENABLE(ASSEMBLER)
diff --git a/src/3rdparty/masm/assembler/MacroAssemblerARM.h b/src/3rdparty/masm/assembler/MacroAssemblerARM.h
index 01e34c97cd..268fe5fe73 100644
--- a/src/3rdparty/masm/assembler/MacroAssemblerARM.h
+++ b/src/3rdparty/masm/assembler/MacroAssemblerARM.h
@@ -1349,7 +1349,7 @@ protected:
}
private:
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
friend class RepatchBuffer;
void internalCompare32(RegisterID left, TrustedImm32 right)
diff --git a/src/3rdparty/masm/assembler/MacroAssemblerARM64.h b/src/3rdparty/masm/assembler/MacroAssemblerARM64.h
index bd85b6b2c1..a11637f7ca 100644
--- a/src/3rdparty/masm/assembler/MacroAssemblerARM64.h
+++ b/src/3rdparty/masm/assembler/MacroAssemblerARM64.h
@@ -26,7 +26,7 @@
#ifndef MacroAssemblerARM64_h
#define MacroAssemblerARM64_h
-#if ENABLE(ASSEMBLER)
+#if ENABLE(ASSEMBLER) && (CPU(ARM64) || defined(V4_BOOTSTRAP))
#include "ARM64Assembler.h"
#include "AbstractMacroAssembler.h"
@@ -42,7 +42,7 @@ class MacroAssemblerARM64 : public AbstractMacroAssembler<ARM64Assembler> {
friend class DataLabelPtr;
friend class DataLabel32;
friend class DataLabelCompact;
- friend class Jump;
+// template <typename> friend class Jump;
friend class Label;
public:
@@ -119,9 +119,9 @@ public:
private:
static const ARM64Registers::FPRegisterID fpTempRegister = ARM64Registers::q31;
static const ARM64Assembler::SetFlags S = ARM64Assembler::S;
- static const intptr_t maskHalfWord0 = 0xffffl;
- static const intptr_t maskHalfWord1 = 0xffff0000l;
- static const intptr_t maskUpperWord = 0xffffffff00000000l;
+ static const int64_t maskHalfWord0 = 0xffffl;
+ static const int64_t maskHalfWord1 = 0xffff0000l;
+ static const int64_t maskUpperWord = 0xffffffff00000000l;
// 4 instructions - 3 to load the function pointer, + blr.
static const ptrdiff_t REPATCH_OFFSET_CALL_TO_POINTER = -16;
@@ -209,6 +209,33 @@ public:
static bool shouldBlindForSpecificArch(uint32_t value) { return value >= 0x00ffffff; }
static bool shouldBlindForSpecificArch(uint64_t value) { return value >= 0x00ffffff; }
+#if defined(V4_BOOTSTRAP)
+ void loadPtr(ImplicitAddress address, RegisterID dest)
+ {
+ load32(address, dest);
+ }
+
+ void subPtr(TrustedImm32 imm, RegisterID dest)
+ {
+ sub32(imm, dest);
+ }
+
+ void addPtr(TrustedImm32 imm, RegisterID dest)
+ {
+ add32(imm, dest);
+ }
+
+ void addPtr(TrustedImm32 imm, RegisterID src, RegisterID dest)
+ {
+ add32(imm, src, dest);
+ }
+
+ void storePtr(RegisterID src, ImplicitAddress address)
+ {
+ store32(src, address);
+ }
+#endif
+
// Integer operations:
void add32(RegisterID a, RegisterID b, RegisterID dest)
@@ -2757,6 +2784,7 @@ public:
return branch32(cond, left, dataTempRegister);
}
+#if !defined(V4_BOOTSTRAP)
PatchableJump patchableBranchPtr(RelationalCondition cond, Address left, TrustedImmPtr right)
{
m_makeJumpPatchable = true;
@@ -2764,6 +2792,7 @@ public:
m_makeJumpPatchable = false;
return PatchableJump(result);
}
+#endif
PatchableJump patchableBranchTest32(ResultCondition cond, RegisterID reg, TrustedImm32 mask = TrustedImm32(-1))
{
@@ -3000,7 +3029,7 @@ private:
return m_cachedMemoryTempRegister.registerIDInvalidate();
}
- ALWAYS_INLINE bool isInIntRange(intptr_t value)
+ ALWAYS_INLINE bool isInIntRange(int64_t value)
{
return value == ((value << 32) >> 32);
}
@@ -3353,7 +3382,9 @@ private:
return makeBranch(cond);
}
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
+ template <typename> friend class BranchCompactingLinkBuffer;
+ template <typename> friend struct BranchCompactingExecutableOffsetCalculator;
void recordLinkOffsets(int32_t regionStart, int32_t regionEnd, int32_t offset) {return m_assembler.recordLinkOffsets(regionStart, regionEnd, offset); }
int executableOffsetFor(int location) { return m_assembler.executableOffsetFor(location); }
diff --git a/src/3rdparty/masm/assembler/MacroAssemblerARMv7.h b/src/3rdparty/masm/assembler/MacroAssemblerARMv7.h
index 0938383513..806f2e13b6 100644
--- a/src/3rdparty/masm/assembler/MacroAssemblerARMv7.h
+++ b/src/3rdparty/masm/assembler/MacroAssemblerARMv7.h
@@ -27,7 +27,7 @@
#ifndef MacroAssemblerARMv7_h
#define MacroAssemblerARMv7_h
-#if ENABLE(ASSEMBLER) && CPU(ARM_THUMB2)
+#if ENABLE(ASSEMBLER) && (CPU(ARM_THUMB2) || defined(V4_BOOTSTRAP))
#include "ARMv7Assembler.h"
#include "AbstractMacroAssembler.h"
@@ -160,12 +160,41 @@ public:
{
add32(imm, dest, dest);
}
+
+#if defined(V4_BOOTSTRAP)
+ void loadPtr(ImplicitAddress address, RegisterID dest)
+ {
+ load32(address, dest);
+ }
+
+ void subPtr(TrustedImm32 imm, RegisterID dest)
+ {
+ sub32(imm, dest);
+ }
+
+ void addPtr(TrustedImm32 imm, RegisterID dest)
+ {
+ add32(imm, dest);
+ }
+
+ void addPtr(TrustedImm32 imm, RegisterID src, RegisterID dest)
+ {
+ add32(imm, src, dest);
+ }
+
+ void storePtr(RegisterID src, ImplicitAddress address)
+ {
+ store32(src, address);
+ }
+#endif
+#if !defined(V4_BOOTSTRAP)
void add32(AbsoluteAddress src, RegisterID dest)
{
load32(src.m_ptr, dataTempRegister);
add32(dataTempRegister, dest);
}
+#endif
void add32(TrustedImm32 imm, RegisterID src, RegisterID dest)
{
@@ -206,6 +235,7 @@ public:
add32(dataTempRegister, dest);
}
+#if !defined(V4_BOOTSTRAP)
void add32(TrustedImm32 imm, AbsoluteAddress address)
{
load32(address.m_ptr, dataTempRegister);
@@ -242,6 +272,7 @@ public:
m_assembler.adc(dataTempRegister, dataTempRegister, ARMThumbImmediate::makeEncodedImm(imm.m_value >> 31));
m_assembler.str(dataTempRegister, addressTempRegister, ARMThumbImmediate::makeUInt12(4));
}
+#endif
void and32(RegisterID op1, RegisterID op2, RegisterID dest)
{
@@ -343,6 +374,7 @@ public:
or32(dataTempRegister, dest);
}
+#if !defined(V4_BOOTSTRAP)
void or32(RegisterID src, AbsoluteAddress dest)
{
move(TrustedImmPtr(dest.m_ptr), addressTempRegister);
@@ -350,6 +382,7 @@ public:
or32(src, dataTempRegister);
store32(dataTempRegister, addressTempRegister);
}
+#endif
void or32(TrustedImm32 imm, RegisterID dest)
{
@@ -461,6 +494,7 @@ public:
sub32(dataTempRegister, dest);
}
+#if !defined(V4_BOOTSTRAP)
void sub32(TrustedImm32 imm, AbsoluteAddress address)
{
load32(address.m_ptr, dataTempRegister);
@@ -477,6 +511,7 @@ public:
store32(dataTempRegister, address.m_ptr);
}
+#endif
void xor32(Address src, RegisterID dest)
{
@@ -526,7 +561,8 @@ public:
// operand objects to loads and store will be implicitly constructed if a
// register is passed.
-private:
+ // internal function, but public because of "using load32;" in template sub-classes to pull
+ // in the other public overloads.
void load32(ArmAddress address, RegisterID dest)
{
if (address.type == ArmAddress::HasIndex)
@@ -541,6 +577,7 @@ private:
}
}
+private:
void load16(ArmAddress address, RegisterID dest)
{
if (address.type == ArmAddress::HasIndex)
@@ -646,11 +683,13 @@ public:
load16(setupArmAddress(address), dest);
}
+#if !defined(V4_BOOTSTRAP)
void load32(const void* address, RegisterID dest)
{
move(TrustedImmPtr(address), addressTempRegister);
m_assembler.ldr(dest, addressTempRegister, ARMThumbImmediate::makeUInt16(0));
}
+#endif
ConvertibleLoadLabel convertibleLoadPtr(Address address, RegisterID dest)
{
@@ -755,6 +794,7 @@ public:
store32(dataTempRegister, setupArmAddress(address));
}
+#if !defined(V4_BOOTSTRAP)
void store32(RegisterID src, const void* address)
{
move(TrustedImmPtr(address), addressTempRegister);
@@ -766,12 +806,14 @@ public:
move(imm, dataTempRegister);
store32(dataTempRegister, address);
}
+#endif
void store8(RegisterID src, BaseIndex address)
{
store8(src, setupArmAddress(address));
}
+#if !defined(V4_BOOTSTRAP)
void store8(RegisterID src, void* address)
{
move(TrustedImmPtr(address), addressTempRegister);
@@ -783,6 +825,7 @@ public:
move(imm, dataTempRegister);
store8(dataTempRegister, address);
}
+#endif
void store16(RegisterID src, BaseIndex address)
{
@@ -880,11 +923,13 @@ public:
m_assembler.vmov(dest, src);
}
+#if !defined(V4_BOOTSTRAP)
void loadDouble(const void* address, FPRegisterID dest)
{
move(TrustedImmPtr(address), addressTempRegister);
m_assembler.vldr(dest, addressTempRegister, 0);
}
+#endif
void storeDouble(FPRegisterID src, ImplicitAddress address)
{
@@ -916,11 +961,13 @@ public:
m_assembler.fsts(ARMRegisters::asSingle(src), base, offset);
}
+#if !defined(V4_BOOTSTRAP)
void storeDouble(FPRegisterID src, const void* address)
{
move(TrustedImmPtr(address), addressTempRegister);
storeDouble(src, addressTempRegister);
}
+#endif
void storeDouble(FPRegisterID src, BaseIndex address)
{
@@ -954,11 +1001,13 @@ public:
m_assembler.vadd(dest, op1, op2);
}
+#if !defined(V4_BOOTSTRAP)
void addDouble(AbsoluteAddress address, FPRegisterID dest)
{
loadDouble(address.m_ptr, fpTempRegister);
m_assembler.vadd(dest, dest, fpTempRegister);
}
+#endif
void divDouble(FPRegisterID src, FPRegisterID dest)
{
@@ -1037,6 +1086,7 @@ public:
m_assembler.vcvt_signedToFloatingPoint(dest, fpTempRegisterAsSingle());
}
+#if !defined(V4_BOOTSTRAP)
void convertInt32ToDouble(AbsoluteAddress address, FPRegisterID dest)
{
// Fixme: load directly into the fpr!
@@ -1044,6 +1094,7 @@ public:
m_assembler.vmov(fpTempRegister, dataTempRegister, dataTempRegister);
m_assembler.vcvt_signedToFloatingPoint(dest, fpTempRegisterAsSingle());
}
+#endif
void convertUInt32ToDouble(RegisterID src, FPRegisterID dest, RegisterID /*scratch*/)
{
@@ -1197,7 +1248,7 @@ public:
void push(RegisterID src)
{
// store preindexed with writeback
- m_assembler.str(src, ARMRegisters::sp, -sizeof(void*), true, true);
+ m_assembler.str(src, ARMRegisters::sp, -4 /*sizeof(void*)*/, true, true);
}
void push(Address address)
@@ -1239,10 +1290,12 @@ public:
m_assembler.mov(dest, src);
}
+#if !defined(V4_BOOTSTRAP)
void move(TrustedImmPtr imm, RegisterID dest)
{
move(TrustedImm32(imm), dest);
}
+#endif
void swap(RegisterID reg1, RegisterID reg2)
{
@@ -1383,6 +1436,7 @@ public:
return branch32(cond, addressTempRegister, right);
}
+#if !defined(V4_BOOTSTRAP)
Jump branch32(RelationalCondition cond, AbsoluteAddress left, RegisterID right)
{
load32(left.m_ptr, dataTempRegister);
@@ -1395,6 +1449,7 @@ public:
load32(left.m_ptr, addressTempRegister);
return branch32(cond, addressTempRegister, right);
}
+#endif
Jump branch8(RelationalCondition cond, RegisterID left, TrustedImm32 right)
{
@@ -1451,6 +1506,7 @@ public:
return branchTest32(cond, addressTempRegister, mask);
}
+#if !defined(V4_BOOTSTRAP)
Jump branchTest8(ResultCondition cond, AbsoluteAddress address, TrustedImm32 mask = TrustedImm32(-1))
{
// use addressTempRegister incase the branchTest8 we call uses dataTempRegister. :-/
@@ -1458,6 +1514,7 @@ public:
load8(Address(addressTempRegister), addressTempRegister);
return branchTest32(cond, addressTempRegister, mask);
}
+#endif
void jump(RegisterID target)
{
@@ -1471,12 +1528,14 @@ public:
m_assembler.bx(dataTempRegister);
}
+#if !defined(V4_BOOTSTRAP)
void jump(AbsoluteAddress address)
{
move(TrustedImmPtr(address.m_ptr), dataTempRegister);
load32(Address(dataTempRegister), dataTempRegister);
m_assembler.bx(dataTempRegister);
}
+#endif
// Arithmetic control flow operations:
@@ -1517,6 +1576,7 @@ public:
return branchAdd32(cond, dest, imm, dest);
}
+#if !defined(V4_BOOTSTRAP)
Jump branchAdd32(ResultCondition cond, TrustedImm32 imm, AbsoluteAddress dest)
{
// Move the high bits of the address into addressTempRegister,
@@ -1542,6 +1602,7 @@ public:
return Jump(makeBranch(cond));
}
+#endif
Jump branchMul32(ResultCondition cond, RegisterID src1, RegisterID src2, RegisterID dest)
{
@@ -1712,6 +1773,7 @@ public:
return DataLabel32(this);
}
+#if !defined(V4_BOOTSTRAP)
ALWAYS_INLINE DataLabelPtr moveWithPatch(TrustedImmPtr imm, RegisterID dst)
{
padBeforePatch();
@@ -1739,7 +1801,8 @@ public:
m_makeJumpPatchable = false;
return PatchableJump(result);
}
-
+#endif
+
PatchableJump patchableBranchTest32(ResultCondition cond, RegisterID reg, TrustedImm32 mask = TrustedImm32(-1))
{
m_makeJumpPatchable = true;
@@ -1756,6 +1819,7 @@ public:
return PatchableJump(result);
}
+#if !defined(V4_BOOTSTRAP)
PatchableJump patchableBranchPtrWithPatch(RelationalCondition cond, Address left, DataLabelPtr& dataLabel, TrustedImmPtr initialRightValue = TrustedImmPtr(0))
{
m_makeJumpPatchable = true;
@@ -1763,6 +1827,7 @@ public:
m_makeJumpPatchable = false;
return PatchableJump(result);
}
+#endif
PatchableJump patchableJump()
{
@@ -1773,6 +1838,7 @@ public:
return PatchableJump(result);
}
+#if !defined(V4_BOOTSTRAP)
ALWAYS_INLINE DataLabelPtr storePtrWithPatch(TrustedImmPtr initialValue, ImplicitAddress address)
{
DataLabelPtr label = moveWithPatch(initialValue, dataTempRegister);
@@ -1780,7 +1846,7 @@ public:
return label;
}
ALWAYS_INLINE DataLabelPtr storePtrWithPatch(ImplicitAddress address) { return storePtrWithPatch(TrustedImmPtr(0), address); }
-
+#endif
ALWAYS_INLINE Call tailRecursiveCall()
{
@@ -1801,6 +1867,7 @@ public:
return m_assembler.executableOffsetFor(location);
}
+#if !defined(V4_BOOTSTRAP)
static FunctionPtr readCallTarget(CodeLocationCall call)
{
return FunctionPtr(reinterpret_cast<void(*)()>(ARMv7Assembler::readCallTarget(call.dataLocation())));
@@ -1813,7 +1880,8 @@ public:
const unsigned twoWordOpSize = 4;
return label.labelAtOffset(-twoWordOpSize * 2);
}
-
+#endif
+
static void revertJumpReplacementToBranchPtrWithPatch(CodeLocationLabel instructionStart, RegisterID rd, void* initialValue)
{
#if OS(LINUX) || OS(QNX)
@@ -1927,9 +1995,10 @@ protected:
}
private:
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
friend class RepatchBuffer;
+#if !defined(V4_BOOTSTRAP)
static void linkCall(void* code, Call call, FunctionPtr function)
{
ARMv7Assembler::linkCall(code, call.m_label, function.value());
@@ -1944,6 +2013,7 @@ private:
{
ARMv7Assembler::relinkCall(call.dataLocation(), destination.executableAddress());
}
+#endif
bool m_makeJumpPatchable;
};
diff --git a/src/3rdparty/masm/assembler/MacroAssemblerCodeRef.h b/src/3rdparty/masm/assembler/MacroAssemblerCodeRef.h
index f03254aa38..e3c77d99e6 100644
--- a/src/3rdparty/masm/assembler/MacroAssemblerCodeRef.h
+++ b/src/3rdparty/masm/assembler/MacroAssemblerCodeRef.h
@@ -66,7 +66,7 @@
#define CALLING_CONVENTION_IS_STDCALL 0
#endif
-#if CPU(X86)
+#if CPU(X86) && !OS(INTEGRITY)
#define HAS_FASTCALL_CALLING_CONVENTION 1
#ifndef FASTCALL
#if COMPILER(MSVC)
diff --git a/src/3rdparty/masm/assembler/MacroAssemblerMIPS.h b/src/3rdparty/masm/assembler/MacroAssemblerMIPS.h
index 734e779c70..68584527fc 100644
--- a/src/3rdparty/masm/assembler/MacroAssemblerMIPS.h
+++ b/src/3rdparty/masm/assembler/MacroAssemblerMIPS.h
@@ -2802,7 +2802,7 @@ private:
// Otherwise, we can emit any number of instructions.
bool m_fixedWidth;
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
friend class RepatchBuffer;
static void linkCall(void* code, Call call, FunctionPtr function)
diff --git a/src/3rdparty/masm/assembler/MacroAssemblerSH4.h b/src/3rdparty/masm/assembler/MacroAssemblerSH4.h
index 56fb74d45b..1e5a3113bb 100644
--- a/src/3rdparty/masm/assembler/MacroAssemblerSH4.h
+++ b/src/3rdparty/masm/assembler/MacroAssemblerSH4.h
@@ -2278,7 +2278,7 @@ protected:
return static_cast<SH4Assembler::Condition>(cond);
}
private:
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
friend class RepatchBuffer;
static void linkCall(void*, Call, FunctionPtr);
diff --git a/src/3rdparty/masm/assembler/MacroAssemblerX86.h b/src/3rdparty/masm/assembler/MacroAssemblerX86.h
index 9a33fe870e..742a4b48f7 100644
--- a/src/3rdparty/masm/assembler/MacroAssemblerX86.h
+++ b/src/3rdparty/masm/assembler/MacroAssemblerX86.h
@@ -54,6 +54,38 @@ public:
using MacroAssemblerX86Common::convertInt32ToDouble;
using MacroAssemblerX86Common::branchTest8;
+#if defined(V4_BOOTSTRAP)
+ void loadPtr(ImplicitAddress address, RegisterID dest)
+ {
+ load32(address, dest);
+ }
+
+ void subPtr(TrustedImm32 imm, RegisterID dest)
+ {
+ sub32(imm, dest);
+ }
+
+ void addPtr(TrustedImm32 imm, RegisterID dest)
+ {
+ add32(imm, dest);
+ }
+
+ void addPtr(TrustedImm32 imm, RegisterID src, RegisterID dest)
+ {
+ add32(imm, src, dest);
+ }
+
+ void storePtr(RegisterID src, ImplicitAddress address)
+ {
+ store32(src, address);
+ }
+
+ Jump branchTest8(ResultCondition cond, ExtendedAddress address, TrustedImm32 mask = TrustedImm32(-1))
+ {
+ return branchTest8(cond, Address(address.base, address.offset), mask);
+ }
+#endif
+
void add32(TrustedImm32 imm, RegisterID src, RegisterID dest)
{
m_assembler.leal_mr(imm.m_value, src, dest);
@@ -306,7 +338,7 @@ public:
}
private:
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
friend class RepatchBuffer;
static void linkCall(void* code, Call call, FunctionPtr function)
diff --git a/src/3rdparty/masm/assembler/MacroAssemblerX86_64.h b/src/3rdparty/masm/assembler/MacroAssemblerX86_64.h
index 9e74f1c29f..3566702413 100644
--- a/src/3rdparty/masm/assembler/MacroAssemblerX86_64.h
+++ b/src/3rdparty/masm/assembler/MacroAssemblerX86_64.h
@@ -52,6 +52,33 @@ public:
using MacroAssemblerX86Common::loadDouble;
using MacroAssemblerX86Common::convertInt32ToDouble;
+#if defined(V4_BOOTSTRAP)
+ void loadPtr(ImplicitAddress address, RegisterID dest)
+ {
+ load64(address, dest);
+ }
+
+ void subPtr(TrustedImm32 imm, RegisterID dest)
+ {
+ sub64(imm, dest);
+ }
+
+ void addPtr(TrustedImm32 imm, RegisterID dest)
+ {
+ add64(imm, dest);
+ }
+
+ void addPtr(TrustedImm32 imm, RegisterID src, RegisterID dest)
+ {
+ add64(imm, src, dest);
+ }
+
+ void storePtr(RegisterID src, ImplicitAddress address)
+ {
+ store64(src, address);
+ }
+#endif
+
void add32(TrustedImm32 imm, AbsoluteAddress address)
{
move(TrustedImmPtr(address.m_ptr), scratchRegister);
@@ -634,7 +661,7 @@ public:
}
private:
- friend class LinkBuffer;
+ template <typename, template <typename> class> friend class LinkBufferBase;
friend class RepatchBuffer;
static void linkCall(void* code, Call call, FunctionPtr function)
diff --git a/src/3rdparty/masm/assembler/X86Assembler.h b/src/3rdparty/masm/assembler/X86Assembler.h
index 1875ebaff0..24462ef38f 100644
--- a/src/3rdparty/masm/assembler/X86Assembler.h
+++ b/src/3rdparty/masm/assembler/X86Assembler.h
@@ -29,6 +29,7 @@
#if ENABLE(ASSEMBLER) && (CPU(X86) || CPU(X86_64))
#include "AssemblerBuffer.h"
+#include "AbstractMacroAssembler.h"
#include "JITCompilationEffort.h"
#include <stdint.h>
#include <wtf/Assertions.h>
@@ -252,6 +253,45 @@ public:
{
}
+ template <typename LabelType>
+ class Jump {
+ template<class TemplateAssemblerType>
+ friend class AbstractMacroAssembler;
+ friend class Call;
+ template <typename, template <typename> class> friend class LinkBufferBase;
+ public:
+ Jump()
+ {
+ }
+
+ Jump(AssemblerLabel jmp)
+ : m_label(jmp)
+ {
+ }
+
+ LabelType label() const
+ {
+ LabelType result;
+ result.m_label = m_label;
+ return result;
+ }
+
+ void link(AbstractMacroAssembler<X86Assembler>* masm) const
+ {
+ masm->m_assembler.linkJump(m_label, masm->m_assembler.label());
+ }
+
+ void linkTo(LabelType label, AbstractMacroAssembler<X86Assembler>* masm) const
+ {
+ masm->m_assembler.linkJump(m_label, label.label());
+ }
+
+ bool isSet() const { return m_label.isSet(); }
+
+ private:
+ AssemblerLabel m_label;
+ };
+
// Stack operations:
void push_r(RegisterID reg)
diff --git a/src/3rdparty/masm/masm.pri b/src/3rdparty/masm/masm.pri
index afa1438974..6c301fea38 100644
--- a/src/3rdparty/masm/masm.pri
+++ b/src/3rdparty/masm/masm.pri
@@ -13,6 +13,7 @@ HEADERS += $$PWD/wtf/RawPointer.h
winrt: SOURCES += $$PWD/wtf/OSAllocatorWinRT.cpp
else:win32: SOURCES += $$PWD/wtf/OSAllocatorWin.cpp
+else:integrity: SOURCES += $$PWD/wtf/OSAllocatorIntegrity.cpp
else: SOURCES += $$PWD/wtf/OSAllocatorPosix.cpp
HEADERS += $$PWD/wtf/OSAllocator.h
@@ -30,7 +31,17 @@ HEADERS += $$PWD/stubs/WTFStubs.h
SOURCES += $$PWD/stubs/Options.cpp
-HEADERS += $$PWD/stubs/wtf/*.h
+HEADERS += $$PWD/stubs/wtf/FastAllocBase.h \
+ $$PWD/stubs/wtf/FastMalloc.h \
+ $$PWD/stubs/wtf/Noncopyable.h \
+ $$PWD/stubs/wtf/OwnPtr.h \
+ $$PWD/stubs/wtf/PassOwnPtr.h \
+ $$PWD/stubs/wtf/PassRefPtr.h \
+ $$PWD/stubs/wtf/RefCounted.h \
+ $$PWD/stubs/wtf/RefPtr.h \
+ $$PWD/stubs/wtf/TypeTraits.h \
+ $$PWD/stubs/wtf/UnusedParam.h \
+ $$PWD/stubs/wtf/Vector.h
SOURCES += $$PWD/disassembler/Disassembler.cpp
SOURCES += $$PWD/disassembler/UDis86Disassembler.cpp
@@ -66,8 +77,21 @@ SOURCES += $$PWD/disassembler/ARM64Disassembler.cpp
SOURCES += $$PWD/disassembler/ARM64/A64DOpcode.cpp
HEADERS += $$PWD/disassembler/ARM64/A64DOpcode.h
-SOURCES += $$PWD/yarr/*.cpp
-HEADERS += $$PWD/yarr/*.h
+!qmldevtools_build {
+SOURCES += $$PWD/yarr/YarrCanonicalizeUCS2.cpp \
+ $$PWD/yarr/YarrInterpreter.cpp \
+ $$PWD/yarr/YarrJIT.cpp \
+ $$PWD/yarr/YarrPattern.cpp \
+ $$PWD/yarr/YarrSyntaxChecker.cpp
+
+HEADERS += $$PWD/yarr/Yarr.h \
+ $$PWD/yarr/YarrCanonicalizeUCS2.h \
+ $$PWD/yarr/YarrInterpreter.h \
+ $$PWD/yarr/YarrJIT.h \
+ $$PWD/yarr/YarrParser.h \
+ $$PWD/yarr/YarrPattern.h \
+ $$PWD/yarr/YarrSyntaxChecker.h
+}
#
# Generate RegExpJitTables.h
diff --git a/src/3rdparty/masm/stubs/ExecutableAllocator.h b/src/3rdparty/masm/stubs/ExecutableAllocator.h
index 5a3939b7b2..3b84b5c986 100644
--- a/src/3rdparty/masm/stubs/ExecutableAllocator.h
+++ b/src/3rdparty/masm/stubs/ExecutableAllocator.h
@@ -39,11 +39,6 @@
#ifndef MASM_EXECUTABLEALLOCATOR_H
#define MASM_EXECUTABLEALLOCATOR_H
-// Defined via mkspec
-#if _MSC_VER >= 1900
-#include <windows.h>
-#endif
-
#include <RefPtr.h>
#include <RefCounted.h>
#include <wtf/PageBlock.h>
@@ -66,7 +61,7 @@ namespace JSC {
class JSGlobalData;
struct ExecutableMemoryHandle : public RefCounted<ExecutableMemoryHandle> {
- ExecutableMemoryHandle(QV4::ExecutableAllocator *allocator, int size)
+ ExecutableMemoryHandle(QV4::ExecutableAllocator *allocator, size_t size)
: m_allocator(allocator)
, m_size(size)
{
@@ -84,14 +79,14 @@ struct ExecutableMemoryHandle : public RefCounted<ExecutableMemoryHandle> {
inline bool isManaged() const { return true; }
void* start() { return m_allocation->start(); }
- int sizeInBytes() { return m_size; }
+ size_t sizeInBytes() { return m_size; }
QV4::ExecutableAllocator::ChunkOfPages *chunk() const
{ return m_allocator->chunkForAllocation(m_allocation); }
QV4::ExecutableAllocator *m_allocator;
QV4::ExecutableAllocator::Allocation *m_allocation;
- int m_size;
+ size_t m_size;
};
struct ExecutableAllocator {
@@ -99,7 +94,7 @@ struct ExecutableAllocator {
: realAllocator(alloc)
{}
- PassRefPtr<ExecutableMemoryHandle> allocate(JSGlobalData&, int size, void*, int)
+ PassRefPtr<ExecutableMemoryHandle> allocate(JSGlobalData&, size_t size, void*, int)
{
return adoptRef(new ExecutableMemoryHandle(realAllocator, size));
}
@@ -112,18 +107,16 @@ struct ExecutableAllocator {
size = size + (iaddr - roundAddr);
addr = reinterpret_cast<void*>(roundAddr);
-#if ENABLE(ASSEMBLER_WX_EXCLUSIVE)
+#if ENABLE(ASSEMBLER_WX_EXCLUSIVE) && !defined(V4_BOOTSTRAP)
# if OS(WINDOWS)
DWORD oldProtect;
# if !OS(WINRT)
VirtualProtect(addr, size, PAGE_READWRITE, &oldProtect);
-# elif _MSC_VER >= 1900
+# else
bool hr = VirtualProtectFromApp(addr, size, PAGE_READWRITE, &oldProtect);
if (!hr) {
Q_UNREACHABLE();
}
-# else
- (void)oldProtect;
# endif
# else
int mode = PROT_READ | PROT_WRITE;
@@ -147,18 +140,17 @@ struct ExecutableAllocator {
size = size + (iaddr - roundAddr);
addr = reinterpret_cast<void*>(roundAddr);
+#if !defined(V4_BOOTSTRAP)
#if ENABLE(ASSEMBLER_WX_EXCLUSIVE)
# if OS(WINDOWS)
DWORD oldProtect;
# if !OS(WINRT)
VirtualProtect(addr, size, PAGE_EXECUTE_READ, &oldProtect);
-# elif _MSC_VER >= 1900
+# else
bool hr = VirtualProtectFromApp(addr, size, PAGE_EXECUTE_READ, &oldProtect);
if (!hr) {
Q_UNREACHABLE();
}
-# else
- (void)oldProtect;
# endif
# else
int mode = PROT_READ | PROT_EXEC;
@@ -170,6 +162,10 @@ struct ExecutableAllocator {
#else
# error "Only W^X is supported"
#endif
+#else
+ (void)addr; // suppress unused parameter warning
+ (void)size; // suppress unused parameter warning
+#endif
}
QV4::ExecutableAllocator *realAllocator;
diff --git a/src/3rdparty/masm/wtf/Compiler.h b/src/3rdparty/masm/wtf/Compiler.h
index fc3b5c5c08..da10196cc1 100644
--- a/src/3rdparty/masm/wtf/Compiler.h
+++ b/src/3rdparty/masm/wtf/Compiler.h
@@ -113,6 +113,11 @@
#define GCCE_VERSION_AT_LEAST(major, minor, patch) (GCCE_VERSION >= (major * 10000 + minor * 100 + patch))
#endif
+/* COMPILER(GHS) - Green Hills MULTI Compiler */
+#if defined(__ghs)
+#define WTF_COMPILER_GHS 1
+#endif
+
/* COMPILER(GCC) - GNU Compiler Collection */
/* --gnu option of the RVCT compiler also defines __GNUC__ */
#if defined(__GNUC__) && !COMPILER(RVCT)
diff --git a/src/3rdparty/masm/wtf/OSAllocatorIntegrity.cpp b/src/3rdparty/masm/wtf/OSAllocatorIntegrity.cpp
new file mode 100644
index 0000000000..451ca147d1
--- /dev/null
+++ b/src/3rdparty/masm/wtf/OSAllocatorIntegrity.cpp
@@ -0,0 +1,232 @@
+/****************************************************************************
+**
+** Copyright (C) Rolland Dudemaine All rights reserved.
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "config.h"
+#include "OSAllocator.h"
+
+#include <INTEGRITY.h>
+#include <memory_region.h>
+#include <set>
+#include <wtf/Assertions.h>
+#include <wtf/UnusedParam.h>
+
+#define ASP_PAGESIZE 0x1000
+
+namespace WTF {
+struct MRPair {
+ mutable MemoryRegion pmr;
+ mutable MemoryRegion vmr;
+
+ mutable bool mapped;
+
+ Address start;
+
+ MRPair(Address _start = 0) :
+ pmr(0),
+ vmr(0),
+ mapped(false),
+ start(_start)
+ {}
+
+ bool operator<(const MRPair& rhs) const
+ {
+ return this->start < rhs.start;
+ }
+};
+
+class MRContainer
+{
+private:
+ std::set<MRPair> mrset;
+ LocalMutex iteratorGuard;
+public:
+ MRContainer() {
+ CheckSuccess(CreateLocalMutex(&iteratorGuard));
+ }
+ const MRPair* getMRPair(Address start) {
+ WaitForLocalMutex(iteratorGuard);
+ auto pairIterator = mrset.find(MRPair(start));
+ const MRPair* result = ((pairIterator == mrset.end()) ? NULL : &(*pairIterator));
+ ReleaseLocalMutex(iteratorGuard);
+ return result;
+ }
+ Error deleteMRPair(const MRPair* pair) {
+ int erased = 0;
+ WaitForLocalMutex(iteratorGuard);
+ erased = mrset.erase(*pair);
+ ReleaseLocalMutex(iteratorGuard);
+ if(erased == 1)
+ return Success;
+ else
+ return ArgumentError; /* An exception could be thrown in this case */
+ }
+ Error insertMRPair(MRPair* pair) {
+ WaitForLocalMutex(iteratorGuard);
+ auto inserted = mrset.insert(*pair);
+ ReleaseLocalMutex(iteratorGuard);
+ if(inserted.second == true)
+ return Success;
+ else
+ return Failure; /* An exception could be thrown in this case */
+ }
+ ~MRContainer() {
+ CheckSuccess(CloseLocalMutex(iteratorGuard));
+ }
+};
+
+static MRContainer memoryRegionsContainer;
+
+Error setAttributes(MemoryRegion mr, bool writable, bool executable)
+{
+ Value attributes = MEMORY_READ;
+ if(writable)
+ attributes |= MEMORY_WRITE;
+ if(executable)
+ attributes |= MEMORY_EXEC;
+ return SetMemoryRegionAttributes(mr, attributes);
+}
+
+void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable, bool executable)
+{
+ MemoryRegion VMR;
+
+ Address virtualStart, length;
+
+ CheckSuccess(AllocateAnyMemoryRegion(__ghs_VirtualMemoryRegionPool, bytes, &VMR));
+ CheckSuccess(GetMemoryRegionAddresses(VMR, &virtualStart, &length));
+ Address addressIterator = virtualStart;
+ for(int i=0; i<(bytes + ASP_PAGESIZE -1)/ASP_PAGESIZE; i++) {
+ MRPair pair;
+ CheckSuccess(SplitMemoryRegion(VMR, ASP_PAGESIZE, &pair.vmr));
+ CheckSuccess(setAttributes(pair.vmr, writable, executable));
+ pair.start = addressIterator;
+
+ memoryRegionsContainer.insertMRPair(&pair);
+ addressIterator += ASP_PAGESIZE;
+ }
+
+ CheckSuccess(CloseMemoryRegion(VMR));
+ return (void*)virtualStart;
+}
+
+void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable, bool includesGuardPages)
+{
+ MemoryRegion VMR;
+
+ Address virtualStart, length;
+
+ CheckSuccess(AllocateAnyMemoryRegion(__ghs_VirtualMemoryRegionPool, bytes, &VMR));
+ CheckSuccess(GetMemoryRegionAddresses(VMR, &virtualStart, &length));
+
+ Address addressIterator = virtualStart;
+ for(int i=0; i<(bytes + ASP_PAGESIZE -1)/ASP_PAGESIZE; i++) {
+ MRPair pair;
+ pair.start = addressIterator;
+ CheckSuccess(SplitMemoryRegion(VMR, ASP_PAGESIZE, &pair.vmr));
+ CheckSuccess(setAttributes(pair.vmr, writable, executable));
+ /* Do not map the first and the last pages if guard pages are required */
+ if(!includesGuardPages || (i!=0 && i!= (bytes + ASP_PAGESIZE -1)/ASP_PAGESIZE -1))
+ {
+ CheckSuccess(GetPageFromAddressSpaceFreeList(GetCurrentAddressSpace(), &pair.pmr));
+ CheckSuccess(MapMemoryRegion(pair.vmr, pair.pmr));
+ pair.mapped = true;
+ }
+
+ memoryRegionsContainer.insertMRPair(&pair);
+ addressIterator += ASP_PAGESIZE;
+ }
+
+ CheckSuccess(CloseMemoryRegion(VMR));
+ return (void*)virtualStart;
+}
+
+void OSAllocator::commit(void* address, size_t bytes, bool writable, bool executable)
+{
+ for(int i=0; i<(bytes + ASP_PAGESIZE -1)/ASP_PAGESIZE; i++)
+ {
+ const MRPair* pair = memoryRegionsContainer.getMRPair((Address)address);
+ if(pair == NULL)
+ return;
+ CheckSuccess(setAttributes(pair->vmr, writable, executable));
+ CheckSuccess(GetPageFromAddressSpaceFreeList(GetCurrentAddressSpace(), &pair->pmr));
+ CheckSuccess(MapMemoryRegion(pair->vmr, pair->pmr));
+ pair->mapped = true;
+ address = (char*)address + ASP_PAGESIZE;
+ }
+}
+
+void OSAllocator::decommit(void* address, size_t bytes)
+{
+ for(int i=0; i<(bytes + ASP_PAGESIZE -1)/ASP_PAGESIZE; i++)
+ {
+ const MRPair* pair = memoryRegionsContainer.getMRPair((Address)address);
+ if(pair == NULL)
+ return;
+ if(pair->mapped == false)
+ continue;
+
+ CheckSuccess(UnmapMemoryRegion(pair->vmr));
+ CheckSuccess(PutPageOnAddressSpaceFreeList(GetCurrentAddressSpace(), pair->pmr));
+ pair->mapped = false;
+ address = (char*)address + ASP_PAGESIZE;
+ }
+}
+
+void OSAllocator::releaseDecommitted(void* address, size_t bytes)
+{
+ for(int i=0; i<(bytes + ASP_PAGESIZE -1)/ASP_PAGESIZE; i++)
+ {
+ const MRPair* pair = memoryRegionsContainer.getMRPair((Address)address);
+ if(pair == NULL)
+ return;
+ /* Check if the memory is still committed */
+ if(pair->mapped == true)
+ {
+ CheckSuccess(UnmapMemoryRegion(pair->vmr));
+ CheckSuccess(PutPageOnAddressSpaceFreeList(GetCurrentAddressSpace(), pair->pmr));
+ pair->mapped = false;
+ }
+ CheckSuccess(AddToMemoryPool(__ghs_VirtualMemoryRegionPool, pair->vmr));
+ address = (char*)address + ASP_PAGESIZE;
+
+ memoryRegionsContainer.deleteMRPair(pair);
+ }
+}
+} // namespace WTF
diff --git a/src/3rdparty/masm/wtf/OSAllocatorWinRT.cpp b/src/3rdparty/masm/wtf/OSAllocatorWinRT.cpp
index b7ad723f07..0a6eda8b98 100644
--- a/src/3rdparty/masm/wtf/OSAllocatorWinRT.cpp
+++ b/src/3rdparty/masm/wtf/OSAllocatorWinRT.cpp
@@ -32,19 +32,8 @@
#include "windows.h"
#include <wtf/Assertions.h>
-#if _MSC_VER >= 1900
// Try to use JIT by default and fallback to non-JIT on first error
static bool qt_winrt_use_jit = true;
-#else // _MSC_VER < 1900
-# define PAGE_EXECUTE 0x10
-# define PAGE_EXECUTE_READ 0x20
-# define PAGE_EXECUTE_READWRITE 0x40
-# define MEM_RELEASE 0x8000
-inline void* VirtualAllocFromApp(void*, size_t, int, int) { return 0; }
-inline bool VirtualProtectFromApp(void *, size_t, int, DWORD*) { return false; }
-inline bool VirtualFree(void *, size_t, DWORD) { return false; }
-static bool qt_winrt_use_jit = false;
-#endif // _MSC_VER < 1900
namespace WTF {
diff --git a/src/3rdparty/masm/wtf/Platform.h b/src/3rdparty/masm/wtf/Platform.h
index 3f480d344a..7f2023a68a 100644
--- a/src/3rdparty/masm/wtf/Platform.h
+++ b/src/3rdparty/masm/wtf/Platform.h
@@ -224,7 +224,8 @@
#elif defined(__ARM_ARCH_7A__) \
|| defined(__ARM_ARCH_7R__) \
- || defined(__ARM_ARCH_7S__)
+ || defined(__ARM_ARCH_7S__) \
+ || defined(__CORE_CORTEXA__) // GHS-specific
#define WTF_ARM_ARCH_VERSION 7
/* MSVC sets _M_ARM */
@@ -268,7 +269,8 @@
|| defined(__ARM_ARCH_7A__) \
|| defined(__ARM_ARCH_7M__) \
|| defined(__ARM_ARCH_7R__) \
- || defined(__ARM_ARCH_7S__)
+ || defined(__ARM_ARCH_7S__) \
+ || defined(__CORE_CORTEXA__) // GHS-specific
#define WTF_THUMB_ARCH_VERSION 4
/* RVCT sets __TARGET_ARCH_THUMB */
@@ -385,6 +387,11 @@
#define WTF_OS_HURD 1
#endif
+/* OS(INTEGRITY) - INTEGRITY */
+#ifdef __INTEGRITY
+#define WTF_OS_INTEGRITY 1
+#endif
+
/* OS(LINUX) - Linux */
#ifdef __linux__
#define WTF_OS_LINUX 1
@@ -433,6 +440,7 @@
|| OS(DARWIN) \
|| OS(FREEBSD) \
|| OS(HURD) \
+ || OS(INTEGRITY) \
|| OS(LINUX) \
|| OS(NETBSD) \
|| OS(OPENBSD) \
@@ -603,7 +611,9 @@
#if OS(UNIX)
#define HAVE_ERRNO_H 1
-#define HAVE_MMAP 1
+#if !OS(INTEGRITY)
+#define HAVE_MMAP 1
+#endif
#define HAVE_SIGNAL_H 1
#define HAVE_STRINGS_H 1
#define HAVE_SYS_PARAM_H 1
@@ -939,10 +949,6 @@
#define WTF_USE_ACCESSIBILITY_CONTEXT_MENUS 1
#endif
-#if CPU(ARM_THUMB2) || CPU(ARM64)
-#define ENABLE_BRANCH_COMPACTION 1
-#endif
-
#if !defined(ENABLE_THREADING_LIBDISPATCH) && HAVE(DISPATCH_H)
#define ENABLE_THREADING_LIBDISPATCH 1
#elif !defined(ENABLE_THREADING_OPENMP) && defined(_OPENMP)
diff --git a/src/3rdparty/masm/yarr/YarrJIT.cpp b/src/3rdparty/masm/yarr/YarrJIT.cpp
index d8211ec4b2..e4f2d97759 100644
--- a/src/3rdparty/masm/yarr/YarrJIT.cpp
+++ b/src/3rdparty/masm/yarr/YarrJIT.cpp
@@ -39,7 +39,7 @@ using namespace WTF;
namespace JSC { namespace Yarr {
template<YarrJITCompileMode compileMode>
-class YarrGenerator : private MacroAssembler {
+class YarrGenerator : private DefaultMacroAssembler {
friend void jitCompile(JSGlobalData*, YarrCodeBlock& jitObject, const String& pattern, unsigned& numSubpatterns, const char*& error, bool ignoreCase, bool multiline);
#if CPU(ARM)
@@ -599,7 +599,7 @@ class YarrGenerator : private MacroAssembler {
}
// Called at the end of code generation to link all return addresses.
- void linkDataLabels(LinkBuffer& linkBuffer)
+ void linkDataLabels(LinkBuffer<JSC::DefaultMacroAssembler>& linkBuffer)
{
ASSERT(isEmpty());
for (unsigned i = 0; i < m_backtrackRecords.size(); ++i)
@@ -2676,7 +2676,7 @@ public:
backtrack();
// Link & finalize the code.
- LinkBuffer linkBuffer(*globalData, this, REGEXP_CODE_ID);
+ LinkBuffer<JSC::DefaultMacroAssembler> linkBuffer(*globalData, this, REGEXP_CODE_ID);
m_backtrackingState.linkDataLabels(linkBuffer);
if (compileMode == MatchOnly) {
diff --git a/src/imports/folderlistmodel/fileinfothread_p.h b/src/imports/folderlistmodel/fileinfothread_p.h
index 75da12a421..b505ece750 100644
--- a/src/imports/folderlistmodel/fileinfothread_p.h
+++ b/src/imports/folderlistmodel/fileinfothread_p.h
@@ -94,7 +94,7 @@ public Q_SLOTS:
#endif
protected:
- void run();
+ void run() override;
void getFileInfos(const QString &path);
void findChangeRange(const QList<FileProperty> &list, int &fromIndex, int &toIndex);
diff --git a/src/imports/folderlistmodel/fileproperty_p.h b/src/imports/folderlistmodel/fileproperty_p.h
index f385cdfdb4..48be4a3d85 100644
--- a/src/imports/folderlistmodel/fileproperty_p.h
+++ b/src/imports/folderlistmodel/fileproperty_p.h
@@ -57,17 +57,17 @@
class FileProperty
{
public:
- FileProperty(const QFileInfo &info)
+ FileProperty(const QFileInfo &info) :
+ mFileName(info.fileName()),
+ mFilePath(info.filePath()),
+ mBaseName(info.baseName()),
+ mSuffix(info.completeSuffix()),
+ mSize(info.size()),
+ mIsDir(info.isDir()),
+ mIsFile(info.isFile()),
+ mLastModified(info.lastModified()),
+ mLastRead(info.lastRead())
{
- mFileName = info.fileName();
- mFilePath = info.filePath();
- mBaseName = info.baseName();
- mSize = info.size();
- mSuffix = info.completeSuffix();
- mIsDir = info.isDir();
- mIsFile = info.isFile();
- mLastModified = info.lastModified();
- mLastRead = info.lastRead();
}
~FileProperty()
{}
diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.h b/src/imports/folderlistmodel/qquickfolderlistmodel.h
index aae6df452d..dee73dff3e 100644
--- a/src/imports/folderlistmodel/qquickfolderlistmodel.h
+++ b/src/imports/folderlistmodel/qquickfolderlistmodel.h
@@ -94,10 +94,10 @@ public:
FileUrlRole = Qt::UserRole + 9
};
- virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
- virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
- virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- virtual QHash<int, QByteArray> roleNames() const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+ QHash<int, QByteArray> roleNames() const override;
//![abslistmodel]
//![count]
@@ -144,8 +144,8 @@ public:
Q_INVOKABLE int indexOf(const QUrl &file) const;
//![parserstatus]
- virtual void classBegin();
- virtual void componentComplete();
+ void classBegin() override;
+ void componentComplete() override;
//![parserstatus]
int roleFromString(const QString &roleName) const;
diff --git a/src/imports/imports.pro b/src/imports/imports.pro
index b030cbcf73..45719df874 100644
--- a/src/imports/imports.pro
+++ b/src/imports/imports.pro
@@ -17,6 +17,7 @@ qtHaveModule(quick) {
layouts \
qtquick2 \
window \
+ sharedimage \
testlib
qtConfig(quick-sprite):qtConfig(opengl(es1|es2)?): \
diff --git a/src/imports/layouts/qquickgridlayoutengine_p.h b/src/imports/layouts/qquickgridlayoutengine_p.h
index 86f56a5af4..2810e2e5d0 100644
--- a/src/imports/layouts/qquickgridlayoutengine_p.h
+++ b/src/imports/layouts/qquickgridlayoutengine_p.h
@@ -67,7 +67,7 @@ public:
: QGridLayoutItem(row, column, rowSpan, columnSpan, alignment), m_item(item), sizeHintCacheDirty(true), useFallbackToWidthOrHeight(true) {}
- QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const override
{
Q_UNUSED(constraint); // Quick Layouts does not support constraint atm
return effectiveSizeHints()[which];
@@ -99,12 +99,12 @@ public:
sizeHintCacheDirty = true;
}
- QLayoutPolicy::Policy sizePolicy(Qt::Orientation orientation) const
+ QLayoutPolicy::Policy sizePolicy(Qt::Orientation orientation) const override
{
return QQuickLayout::effectiveSizePolicy_helper(m_item, orientation, attachedLayoutObject(m_item, false));
}
- void setGeometry(const QRectF &rect)
+ void setGeometry(const QRectF &rect) override
{
QQuickLayoutAttached *info = attachedLayoutObject(m_item, false);
const QRectF r = info ? rect.marginsRemoved(info->qMargins()) : rect;
diff --git a/src/imports/layouts/qquicklayout.cpp b/src/imports/layouts/qquicklayout.cpp
index fd2ff4a73e..df64b593d9 100644
--- a/src/imports/layouts/qquicklayout.cpp
+++ b/src/imports/layouts/qquicklayout.cpp
@@ -42,6 +42,7 @@
#include <QtCore/qcoreapplication.h>
#include <QtCore/private/qnumeric_p.h>
#include <QtCore/qmath.h>
+#include <QtQml/qqmlinfo.h>
#include <limits>
/*!
@@ -678,7 +679,7 @@ QQuickLayout *QQuickLayoutAttached::parentLayout() const
parentItem = parentItem->parentItem();
return qobject_cast<QQuickLayout *>(parentItem);
} else {
- qWarning("Layout must be attached to Item elements");
+ qmlWarning(parent()) << "Layout must be attached to Item elements";
}
return 0;
}
@@ -695,13 +696,20 @@ QQuickLayout::QQuickLayout(QQuickLayoutPrivate &dd, QQuickItem *parent)
{
}
+static QQuickItemPrivate::ChangeTypes changeTypes =
+ QQuickItemPrivate::SiblingOrder
+ | QQuickItemPrivate::ImplicitWidth
+ | QQuickItemPrivate::ImplicitHeight
+ | QQuickItemPrivate::Destroyed
+ | QQuickItemPrivate::Visibility;
+
QQuickLayout::~QQuickLayout()
{
d_func()->m_isReady = false;
const auto childItems = d_func()->childItems;
for (QQuickItem *child : childItems)
- QQuickItemPrivate::get(child)->removeItemChangeListener(this, QQuickItemPrivate::SiblingOrder);
+ QQuickItemPrivate::get(child)->removeItemChangeListener(this, changeTypes);
}
QQuickLayoutAttached *QQuickLayout::qmlAttachedProperties(QObject *object)
@@ -765,14 +773,14 @@ void QQuickLayout::itemChange(ItemChange change, const ItemChangeData &value)
Q_D(QQuickLayout);
QQuickItem *item = value.item;
qmlobject_connect(item, QQuickItem, SIGNAL(baselineOffsetChanged(qreal)), this, QQuickLayout, SLOT(invalidateSenderItem()));
- QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::SiblingOrder | QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed | QQuickItemPrivate::Visibility);
+ QQuickItemPrivate::get(item)->addItemChangeListener(this, changeTypes);
d->m_hasItemChangeListeners = true;
if (isReady())
updateLayoutItems();
} else if (change == ItemChildRemovedChange) {
QQuickItem *item = value.item;
qmlobject_disconnect(item, QQuickItem, SIGNAL(baselineOffsetChanged(qreal)), this, QQuickLayout, SLOT(invalidateSenderItem()));
- QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::SiblingOrder | QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed | QQuickItemPrivate::Visibility);
+ QQuickItemPrivate::get(item)->removeItemChangeListener(this, changeTypes);
if (isReady())
updateLayoutItems();
}
@@ -820,7 +828,7 @@ void QQuickLayout::deactivateRecur()
// When deleting a layout with children, there is no reason for the children to inform the layout that their
// e.g. visibility got changed. The layout already knows that all its children will eventually become invisible, so
// we therefore remove its change listener.
- QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::SiblingOrder | QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed | QQuickItemPrivate::Visibility);
+ QQuickItemPrivate::get(item)->removeItemChangeListener(this, changeTypes);
if (QQuickLayout *layout = qobject_cast<QQuickLayout*>(item))
layout->deactivateRecur();
}
diff --git a/src/imports/layouts/qquicklayoutstyleinfo.cpp b/src/imports/layouts/qquicklayoutstyleinfo.cpp
index c33ceffb2d..5c8be8f306 100644
--- a/src/imports/layouts/qquicklayoutstyleinfo.cpp
+++ b/src/imports/layouts/qquicklayoutstyleinfo.cpp
@@ -50,7 +50,7 @@ QQuickLayoutStyleInfo::QQuickLayoutStyleInfo()
qreal QQuickLayoutStyleInfo::spacing(Qt::Orientation /*orientation*/) const
{
-#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(Q_OS_BLACKBERRY) || defined(Q_OS_QNX) || defined(Q_OS_WINRT)
+#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(Q_OS_QNX) || defined(Q_OS_WINRT)
// On Android and iOS the default spacing between each UI element is 8dp
qreal spacing = 8.0;
#else
diff --git a/src/imports/layouts/qquicklinearlayout.cpp b/src/imports/layouts/qquicklinearlayout.cpp
index 50b3eed87e..887b9b1fa1 100644
--- a/src/imports/layouts/qquicklinearlayout.cpp
+++ b/src/imports/layouts/qquicklinearlayout.cpp
@@ -41,6 +41,7 @@
#include "qquickgridlayoutengine_p.h"
#include "qquicklayoutstyleinfo_p.h"
#include <QtCore/private/qnumeric_p.h>
+#include <QtQml/qqmlinfo.h>
#include "qdebug.h"
#include <limits>
@@ -664,34 +665,25 @@ void QQuickGridLayout::insertLayoutItems()
int &columnSpan = span[0];
int &rowSpan = span[1];
- bool invalidRowColumn = false;
if (info) {
if (info->isRowSet() || info->isColumnSet()) {
// If row is specified and column is not specified (or vice versa),
// the unspecified component of the cell position should default to 0
- row = column = 0;
- if (info->isRowSet()) {
- row = info->row();
- invalidRowColumn = row < 0;
- }
- if (info->isColumnSet()) {
- column = info->column();
- invalidRowColumn = column < 0;
- }
- }
- if (invalidRowColumn) {
- qWarning("QQuickGridLayoutBase::insertLayoutItems: invalid row/column: %d",
- row < 0 ? row : column);
- return;
+ // The getters do this for us, as they will return 0 for an
+ // unset (or negative) value.
+ row = info->row();
+ column = info->column();
}
rowSpan = info->rowSpan();
columnSpan = info->columnSpan();
- if (columnSpan < 1 || rowSpan < 1) {
- qWarning("QQuickGridLayoutBase::addItem: invalid row span/column span: %d",
- rowSpan < 1 ? rowSpan : columnSpan);
+ if (columnSpan < 1) {
+ qmlWarning(child) << "Layout: invalid column span: " << columnSpan;
return;
- }
+ } else if (rowSpan < 1) {
+ qmlWarning(child) << "Layout: invalid row span: " << rowSpan;
+ return;
+ }
alignment = info->alignment();
}
diff --git a/src/imports/layouts/qquicklinearlayout_p.h b/src/imports/layouts/qquicklinearlayout_p.h
index c289416540..f796c8a855 100644
--- a/src/imports/layouts/qquicklinearlayout_p.h
+++ b/src/imports/layouts/qquicklinearlayout_p.h
@@ -152,12 +152,12 @@ public:
int rows() const;
void setRows(int rows);
- Q_ENUMS(Flow)
enum Flow { LeftToRight, TopToBottom };
+ Q_ENUM(Flow)
Flow flow() const;
void setFlow(Flow flow);
- void insertLayoutItems();
+ void insertLayoutItems() override;
signals:
void columnSpacingChanged();
@@ -199,7 +199,7 @@ public:
qreal spacing() const;
void setSpacing(qreal spacing);
- void insertLayoutItems();
+ void insertLayoutItems() override;
signals:
void spacingChanged();
diff --git a/src/imports/localstorage/plugin.cpp b/src/imports/localstorage/plugin.cpp
index 9191700b45..8679750842 100644
--- a/src/imports/localstorage/plugin.cpp
+++ b/src/imports/localstorage/plugin.cpp
@@ -219,24 +219,6 @@ QQmlSqlDatabaseData::~QQmlSqlDatabaseData()
{
}
-static QString qmlsqldatabase_databasesPath(QV4::ExecutionEngine *engine)
-{
- return engine->qmlEngine()->offlineStoragePath() +
- QDir::separator() + QLatin1String("Databases");
-}
-
-static void qmlsqldatabase_initDatabasesPath(QV4::ExecutionEngine *engine)
-{
- QString databasesPath = qmlsqldatabase_databasesPath(engine);
- if (!QDir().mkpath(databasesPath))
- qWarning() << "LocalStorage: can't create path - " << databasesPath;
-}
-
-static QString qmlsqldatabase_databaseFile(const QString& connectionName, QV4::ExecutionEngine *engine)
-{
- return qmlsqldatabase_databasesPath(engine) + QDir::separator() + connectionName;
-}
-
static ReturnedValue qmlsqldatabase_rows_index(const QQmlSqlDatabaseWrapper *r, ExecutionEngine *v4, quint32 index, bool *hasProperty = 0)
{
Scope scope(v4);
@@ -450,7 +432,8 @@ static ReturnedValue qmlsqldatabase_changeVersion(CallContext *ctx)
if (ok) {
*w->d()->version = to_version;
#if QT_CONFIG(settings)
- QSettings ini(qmlsqldatabase_databaseFile(db.connectionName(), scope.engine) + QLatin1String(".ini"), QSettings::IniFormat);
+ const QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(scope.engine->qmlEngine());
+ QSettings ini(enginePrivate->offlineStorageDatabaseDirectory() + db.connectionName() + QLatin1String(".ini"), QSettings::IniFormat);
ini.setValue(QLatin1String("Version"), to_version);
#endif
}
@@ -723,24 +706,23 @@ void QQuickLocalStorage::openDatabaseSync(QQmlV4Function *args)
if (scope.engine->qmlEngine()->offlineStoragePath().isEmpty())
V4THROW_SQL2(SQLEXCEPTION_DATABASE_ERR, QQmlEngine::tr("SQL: can't create database, offline storage is disabled."));
- qmlsqldatabase_initDatabasesPath(scope.engine);
-
- QSqlDatabase database;
-
QV4::ScopedValue v(scope);
QString dbname = (v = (*args)[0])->toQStringNoThrow();
QString dbversion = (v = (*args)[1])->toQStringNoThrow();
QString dbdescription = (v = (*args)[2])->toQStringNoThrow();
int dbestimatedsize = (v = (*args)[3])->toInt32();
FunctionObject *dbcreationCallback = (v = (*args)[4])->as<FunctionObject>();
-
- QCryptographicHash md5(QCryptographicHash::Md5);
- md5.addData(dbname.toUtf8());
- QString dbid(QLatin1String(md5.result().toHex()));
-
- QString basename = qmlsqldatabase_databaseFile(dbid, scope.engine);
+ QString basename = args->v4engine()->qmlEngine()->offlineStorageDatabaseFilePath(dbname);
+ QFileInfo dbFile(basename);
+ if (!QDir().mkpath(dbFile.dir().absolutePath())) {
+ const QString message = QQmlEngine::tr("LocalStorage: can't create path %1").
+ arg(QDir::toNativeSeparators(dbFile.dir().absolutePath()));
+ V4THROW_SQL2(SQLEXCEPTION_DATABASE_ERR, message);
+ }
+ QString dbid = dbFile.fileName();
bool created = false;
QString version = dbversion;
+ QSqlDatabase database;
{
QSettings ini(basename+QLatin1String(".ini"),QSettings::IniFormat);
@@ -812,7 +794,7 @@ public:
}
void registerTypes(const char *uri) Q_DECL_OVERRIDE
{
- Q_ASSERT(QLatin1String(uri) == "QtQuick.LocalStorage");
+ Q_ASSERT(QLatin1String(uri) == QLatin1String("QtQuick.LocalStorage"));
qmlRegisterSingletonType<QQuickLocalStorage>(uri, 2, 0, "LocalStorage", module_api_factory);
}
};
diff --git a/src/imports/settings/qqmlsettings_p.h b/src/imports/settings/qqmlsettings_p.h
index 0ed55579dd..ce942d7564 100644
--- a/src/imports/settings/qqmlsettings_p.h
+++ b/src/imports/settings/qqmlsettings_p.h
@@ -74,10 +74,10 @@ public:
void setCategory(const QString &category);
protected:
- void timerEvent(QTimerEvent *event);
+ void timerEvent(QTimerEvent *event) override;
- void classBegin();
- void componentComplete();
+ void classBegin() override;
+ void componentComplete() override;
private:
Q_DISABLE_COPY(QQmlSettings)
diff --git a/src/imports/sharedimage/plugin.cpp b/src/imports/sharedimage/plugin.cpp
new file mode 100644
index 0000000000..f20edc641c
--- /dev/null
+++ b/src/imports/sharedimage/plugin.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qqmlextensionplugin.h>
+#include <qqmlengine.h>
+#include <sharedimageprovider.h>
+
+
+/*!
+ \qmlmodule QtQuick.SharedImage 1
+ \title Qt Quick Shared Image Provider
+ \ingroup qmlmodules
+ \brief Adds an image provider which utilizes shared CPU memory
+
+ \section2 Summary
+
+ This module provides functionality to save memory in use cases where
+ several Qt Quick applications use the same local image files. It does this
+ by placing the decoded QImage data in shared system memory, making it
+ accessible to all the processes (see QSharedMemory).
+
+ This module only shares CPU memory. It does not provide sharing of GPU
+ memory or textures.
+
+ \section2 Usage
+
+ To use this module, import it like this:
+ \code
+ import QtQuick.SharedImage 1.0
+ \endcode
+
+ The sharing functionality is provided through a QQuickImageProvider. Use
+ the "image:" scheme for the URL source of the image, followed by the
+ identifier \e shared, followed by the image file path. For example:
+
+ \code
+ Image { source: "image://shared/usr/share/wallpapers/mybackground.jpg" }
+ \endcode
+
+ This will look for the file \e /usr/share/wallpapers/mybackground.jpg.
+ The first process that does this will read the image file
+ using normal Qt image loading. The decoded image data will then be placed
+ in shared memory, using the full file path as key. Later processes
+ requesting the same image will discover that the data is already available
+ in shared memory. They will then use that instead of loading the image file
+ again.
+
+ The shared image data will be kept available until the last process has deleted
+ its last reference to the shared image, at which point it is automatically released.
+
+ If system memory sharing is not available, the shared image provider falls
+ back to normal, unshared image loading.
+
+ The file path must be absolute. To use a relative path, make it absolute
+ using \e Qt.resolvedUrl() and replace the URL scheme. For example:
+
+ \code
+ ...
+ property string imagePrefix: Qt.resolvedUrl("../myimages/").replace("file://", "image://shared/")
+ Image { source: imagePrefix + "myimage.png" }
+ \endcode
+
+ The shared image module does not provide any directly usable QML types.
+*/
+
+static void initResources()
+{
+#ifdef QT_STATIC
+ Q_INIT_RESOURCE(qmake_QtQuick_SharedImage);
+#endif
+}
+
+QT_BEGIN_NAMESPACE
+
+class QtQuickSharedImagePlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
+public:
+ QtQuickSharedImagePlugin(QObject *parent = 0) : QQmlExtensionPlugin(parent) { initResources(); }
+
+ void registerTypes(const char *uri) Q_DECL_OVERRIDE
+ {
+ Q_ASSERT(uri == QStringLiteral("QtQuick.SharedImage"));
+ // Need to register *something* to let our version number be known:
+ qmlRegisterTypeNotAvailable(uri, 1, 0, "nosuchtype", QStringLiteral("Just a dummy type, do not use"));
+ }
+
+ void initializeEngine(QQmlEngine *engine, const char *uri) override
+ {
+ Q_UNUSED(uri);
+ engine->addImageProvider("shared", new SharedImageProvider);
+ }
+};
+
+QT_END_NAMESPACE
+
+#include "plugin.moc"
diff --git a/src/imports/sharedimage/qmldir b/src/imports/sharedimage/qmldir
new file mode 100644
index 0000000000..64a5aa8ac1
--- /dev/null
+++ b/src/imports/sharedimage/qmldir
@@ -0,0 +1,3 @@
+module QtQuick.SharedImage
+plugin sharedimageplugin
+classname QtQuickSharedImagePlugin
diff --git a/src/imports/sharedimage/qsharedimageloader.cpp b/src/imports/sharedimage/qsharedimageloader.cpp
new file mode 100644
index 0000000000..65cbd92bb4
--- /dev/null
+++ b/src/imports/sharedimage/qsharedimageloader.cpp
@@ -0,0 +1,265 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsharedimageloader_p.h"
+#include <private/qobject_p.h>
+#include <private/qimage_p.h>
+#include <QSharedMemory>
+
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(lcSharedImage, "qt.quick.sharedimage");
+
+struct SharedImageHeader {
+ quint8 magic;
+ quint8 version;
+ quint16 offset;
+ qint32 width;
+ qint32 height;
+ qint32 bpl;
+ QImage::Format format;
+};
+Q_STATIC_ASSERT(sizeof(SharedImageHeader) % 4 == 0);
+
+#ifndef QT_NO_SHAREDMEMORY
+struct SharedImageInfo {
+ QString path;
+ QPointer<QSharedMemory> shmp;
+};
+
+void cleanupSharedImage(void *cleanupInfo)
+{
+ if (!cleanupInfo)
+ return;
+ SharedImageInfo *sii = static_cast<SharedImageInfo *>(cleanupInfo);
+ qCDebug(lcSharedImage) << "Cleanup called for" << sii->path;
+ if (sii->shmp.isNull()) {
+ qCDebug(lcSharedImage) << "shm is 0 for" << sii->path;
+ return;
+ }
+ QSharedMemory *shm = sii->shmp.data();
+ sii->shmp.clear();
+ delete shm; // destructor detaches
+ delete sii;
+}
+#else
+void cleanupSharedImage(void *) {}
+#endif
+
+class QSharedImageLoaderPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QSharedImageLoader)
+
+public:
+ QSharedImageLoaderPrivate()
+ : QObjectPrivate()
+ {}
+
+ QImage load(const QString &path, QSharedImageLoader::ImageParameters *params);
+
+ void storeImageToMem(void *data, const QImage &img);
+
+ bool verifyMem(const void *data, int size);
+
+ QImage createImageFromMem(const void *data, void *cleanupInfo);
+
+};
+
+
+void QSharedImageLoaderPrivate::storeImageToMem(void *data, const QImage &img)
+{
+ Q_ASSERT(data && !img.isNull());
+
+ SharedImageHeader *h = static_cast<SharedImageHeader *>(data);
+ h->magic = 'Q';
+ h->version = 1;
+ h->offset = sizeof(SharedImageHeader);
+ h->width = img.width();
+ h->height = img.height();
+ h->bpl = img.bytesPerLine();
+ h->format = img.format();
+
+ uchar *p = static_cast<uchar *>(data) + sizeof(SharedImageHeader);
+ memcpy(p, img.constBits(), img.byteCount());
+}
+
+
+bool QSharedImageLoaderPrivate::verifyMem(const void *data, int size)
+{
+ if (!data || size < int(sizeof(SharedImageHeader)))
+ return false;
+
+ const SharedImageHeader *h = static_cast<const SharedImageHeader *>(data);
+ if ((h->magic != 'Q')
+ || (h->version < 1)
+ || (h->offset < sizeof(SharedImageHeader))
+ || (h->width <= 0)
+ || (h->height <= 0)
+ || (h->bpl <= 0)
+ || (h->format <= QImage::Format_Invalid)
+ || (h->format >= QImage::NImageFormats)) {
+ return false;
+ }
+
+ int availSize = size - h->offset;
+ if (h->height * h->bpl > availSize)
+ return false;
+ if ((qt_depthForFormat(h->format) * h->width * h->height) > (8 * availSize))
+ return false;
+
+ return true;
+}
+
+
+QImage QSharedImageLoaderPrivate::createImageFromMem(const void *data, void *cleanupInfo)
+{
+ const SharedImageHeader *h = static_cast<const SharedImageHeader *>(data);
+ const uchar *p = static_cast<const uchar *>(data) + h->offset;
+
+ QImage img(p, h->width, h->height, h->bpl, h->format, cleanupSharedImage, cleanupInfo);
+ return img;
+}
+
+
+QImage QSharedImageLoaderPrivate::load(const QString &path, QSharedImageLoader::ImageParameters *params)
+{
+#ifndef QT_NO_SHAREDMEMORY
+ Q_Q(QSharedImageLoader);
+
+ QImage nil;
+ if (path.isEmpty())
+ return nil;
+
+ QScopedPointer<QSharedMemory> shm(new QSharedMemory(q->key(path, params)));
+ bool locked = false;
+
+ if (!shm->attach(QSharedMemory::ReadOnly)) {
+ QImage img = q->loadFile(path, params);
+ if (img.isNull())
+ return nil;
+ int size = sizeof(SharedImageHeader) + img.byteCount();
+ if (shm->create(size)) {
+ qCDebug(lcSharedImage) << "Created new shm segment of size" << size << "for image" << path;
+ if (!shm->lock()) {
+ qCDebug(lcSharedImage) << "Lock1 failed!?" << shm->errorString();
+ return nil;
+ }
+ locked = true;
+ storeImageToMem(shm->data(), img);
+ } else if (shm->error() == QSharedMemory::AlreadyExists) {
+ // race handling: other process may have created the share while
+ // we loaded the image, so try again to just attach
+ if (!shm->attach(QSharedMemory::ReadOnly)) {
+ qCDebug(lcSharedImage) << "Attach to existing failed?" << shm->errorString();
+ return nil;
+ }
+ } else {
+ qCDebug(lcSharedImage) << "Create failed?" << shm->errorString();
+ return nil;
+ }
+ }
+
+ Q_ASSERT(shm->isAttached());
+
+ if (!locked) {
+ if (!shm->lock()) {
+ qCDebug(lcSharedImage) << "Lock2 failed!?" << shm->errorString();
+ return nil;
+ }
+ locked = true;
+ }
+
+ if (!verifyMem(shm->constData(), shm->size())) {
+ qCDebug(lcSharedImage) << "Verifymem failed!?";
+ shm->unlock();
+ return nil;
+ }
+
+ QSharedMemory *shmp = shm.take();
+ SharedImageInfo *sii = new SharedImageInfo;
+ sii->path = path;
+ sii->shmp = shmp;
+ QImage shImg = createImageFromMem(shmp->constData(), sii);
+
+ if (!shmp->unlock()) {
+ qCDebug(lcSharedImage) << "UnLock failed!?";
+ }
+
+ return shImg;
+#else
+ Q_UNUSED(path);
+ Q_UNUSED(params);
+ return QImage();
+#endif
+}
+
+
+QSharedImageLoader::QSharedImageLoader(QObject *parent)
+ : QObject(*new QSharedImageLoaderPrivate, parent)
+{
+}
+
+QSharedImageLoader::~QSharedImageLoader()
+{
+}
+
+QImage QSharedImageLoader::load(const QString &path, ImageParameters *params)
+{
+ Q_D(QSharedImageLoader);
+
+ return d->load(path, params);
+}
+
+QImage QSharedImageLoader::loadFile(const QString &path, ImageParameters *params)
+{
+ Q_UNUSED(params);
+
+ return QImage(path);
+}
+
+QString QSharedImageLoader::key(const QString &path, ImageParameters *params)
+{
+ Q_UNUSED(params);
+
+ return path;
+}
+
+
+QT_END_NAMESPACE
diff --git a/src/imports/sharedimage/qsharedimageloader_p.h b/src/imports/sharedimage/qsharedimageloader_p.h
new file mode 100644
index 0000000000..afb50e5088
--- /dev/null
+++ b/src/imports/sharedimage/qsharedimageloader_p.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSHAREDIMAGELOADER_H
+#define QSHAREDIMAGELOADER_H
+
+#include <QImage>
+#include <QVariant>
+#include <QLoggingCategory>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(lcSharedImage);
+
+class QSharedImageLoaderPrivate;
+
+class QSharedImageLoader : public QObject
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QSharedImageLoader)
+
+public:
+ enum ImageParameter {
+ OriginalSize = 0,
+ RequestedSize,
+ NumImageParameters
+ };
+ typedef QVector<QVariant> ImageParameters;
+
+ QSharedImageLoader(QObject *parent = Q_NULLPTR);
+ ~QSharedImageLoader();
+
+ QImage load(const QString &path, ImageParameters *params = Q_NULLPTR);
+
+protected:
+ virtual QImage loadFile(const QString &path, ImageParameters *params);
+ virtual QString key(const QString &path, ImageParameters *params);
+
+private:
+ Q_DISABLE_COPY(QSharedImageLoader)
+};
+
+QT_END_NAMESPACE
+
+#endif // QSHAREDIMAGELOADER_H
diff --git a/src/imports/sharedimage/sharedimage.pro b/src/imports/sharedimage/sharedimage.pro
new file mode 100644
index 0000000000..523de66ac1
--- /dev/null
+++ b/src/imports/sharedimage/sharedimage.pro
@@ -0,0 +1,17 @@
+CXX_MODULE = qml
+TARGET = sharedimageplugin
+TARGETPATH = QtQuick/SharedImage
+IMPORT_VERSION = 1.0
+
+QT *= quick qml gui-private core-private
+
+SOURCES += \
+ plugin.cpp \
+ sharedimageprovider.cpp \
+ qsharedimageloader.cpp
+
+HEADERS += \
+ sharedimageprovider.h \
+ qsharedimageloader_p.h
+
+load(qml_plugin)
diff --git a/src/imports/sharedimage/sharedimageprovider.cpp b/src/imports/sharedimage/sharedimageprovider.cpp
new file mode 100644
index 0000000000..2dd3a130e9
--- /dev/null
+++ b/src/imports/sharedimage/sharedimageprovider.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <sharedimageprovider.h>
+#include <qsharedimageloader_p.h>
+#include <qquickimageprovider.h>
+#include <private/qimage_p.h>
+#include <QImageReader>
+#include <QFileInfo>
+#include <QDir>
+
+class QuickSharedImageLoader : public QSharedImageLoader
+{
+ Q_OBJECT
+ friend class SharedImageProvider;
+
+public:
+ QuickSharedImageLoader(QObject *parent = Q_NULLPTR)
+ : QSharedImageLoader(parent)
+ {
+ }
+
+protected:
+ QImage loadFile(const QString &path, ImageParameters *params) override
+ {
+ QImageReader imgio(path);
+ QSize realSize = imgio.size();
+ QSize requestSize = params ? params->value(RequestedSize).toSize() : QSize();
+
+ // Following qquickpixmapcache's readImage, from here...
+ const bool force_scale = imgio.format() == "svg" || imgio.format() == "svgz";
+
+ if (requestSize.width() > 0 || requestSize.height() > 0) {
+ QSize s = realSize;
+ qreal ratio = 0.0;
+ if (requestSize.width() && (force_scale || requestSize.width() < s.width())) {
+ ratio = qreal(requestSize.width())/s.width();
+ }
+ if (requestSize.height() && (force_scale || requestSize.height() < s.height())) {
+ qreal hr = qreal(requestSize.height())/s.height();
+ if (ratio == 0.0 || hr < ratio)
+ ratio = hr;
+ }
+ if (ratio > 0.0) {
+ s.setHeight(qRound(s.height() * ratio));
+ s.setWidth(qRound(s.width() * ratio));
+ imgio.setScaledSize(s);
+ }
+ }
+ // ... to here
+
+ QImage image;
+ if (imgio.read(&image)) {
+ if (realSize.isEmpty())
+ realSize = image.size();
+ // Make sure we have acceptable format for texture uploader, or it will convert & lose sharing
+ // This mimics the testing & conversion normally done by the quick pixmapcache & texturefactory
+ if (image.format() != QImage::Format_RGB32 && image.format() != QImage::Format_ARGB32_Premultiplied) {
+ QImage::Format newFmt = QImage::Format_RGB32;
+ if (image.hasAlphaChannel() && image.data_ptr()->checkForAlphaPixels())
+ newFmt = QImage::Format_ARGB32_Premultiplied;
+ qCDebug(lcSharedImage) << "Convert on load from format" << image.format() << "to" << newFmt;
+ image = image.convertToFormat(newFmt);
+ }
+ }
+
+ if (params && params->count() > OriginalSize)
+ params->replace(OriginalSize, realSize);
+
+ return image;
+ }
+
+ QString key(const QString &path, ImageParameters *params) override
+ {
+ QSize reqSz = params->value(RequestedSize).toSize();
+ if (!reqSz.isValid())
+ return path;
+
+ QString key = path + QStringLiteral("_%1x%2").arg(reqSz.width()).arg(reqSz.height());
+ qCDebug(lcSharedImage) << "KEY:" << key;
+ return key;
+ }
+};
+
+
+SharedImageProvider::SharedImageProvider()
+ : QQuickImageProvider(QQuickImageProvider::Image), loader(new QuickSharedImageLoader)
+{
+}
+
+QImage SharedImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
+{
+ QFileInfo fi(QDir::root(), id);
+ QString path = fi.canonicalFilePath();
+ if (path.isEmpty())
+ return QImage();
+
+ QSharedImageLoader::ImageParameters params(QSharedImageLoader::NumImageParameters);
+ params[QSharedImageLoader::RequestedSize].setValue(requestedSize);
+
+ QImage img = loader->load(path, &params);
+ if (img.isNull()) {
+ // May be sharing problem, fall back to normal local load
+ img = loader->loadFile(path, &params);
+ if (!img.isNull())
+ qCWarning(lcSharedImage) << "Sharing problem; loading" << id << "unshared";
+ }
+
+ //... QSize realSize = params.value(QSharedImageLoader::OriginalSize).toSize();
+ // quickpixmapcache's readImage() reports back the original size, prior to requestedSize scaling, in the *size
+ // parameter. That value is currently ignored by quick however, which only cares about the present size of the
+ // returned image. So handling and sharing of info on pre-scaled size is currently not implemented.
+ if (size) {
+ *size = img.size();
+ }
+
+ return img;
+}
+
+#include "sharedimageprovider.moc"
diff --git a/src/imports/sharedimage/sharedimageprovider.h b/src/imports/sharedimage/sharedimageprovider.h
new file mode 100644
index 0000000000..a2f6b6ef2f
--- /dev/null
+++ b/src/imports/sharedimage/sharedimageprovider.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SHAREDIMAGEPROVIDER_H
+#define SHAREDIMAGEPROVIDER_H
+
+#include <QQuickImageProvider>
+#include <QScopedPointer>
+
+class QuickSharedImageLoader;
+
+class SharedImageProvider : public QQuickImageProvider
+{
+public:
+ SharedImageProvider();
+
+ QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
+
+protected:
+ QScopedPointer<QuickSharedImageLoader> loader;
+};
+#endif // SHAREDIMAGEPROVIDER_H
diff --git a/src/imports/statemachine/signaltransition.cpp b/src/imports/statemachine/signaltransition.cpp
index 2e6381fc08..44fbf69431 100644
--- a/src/imports/statemachine/signaltransition.cpp
+++ b/src/imports/statemachine/signaltransition.cpp
@@ -127,7 +127,7 @@ void SignalTransition::setSignal(const QJSValue &signal)
Q_ASSERT(sender);
signalMethod = sender->metaObject()->method(signalObject->signalIndex());
} else {
- qmlInfo(this) << tr("Specified signal does not exist.");
+ qmlWarning(this) << tr("Specified signal does not exist.");
return;
}
diff --git a/src/imports/statemachine/state.cpp b/src/imports/statemachine/state.cpp
index 09d246cc1e..f1294b0de0 100644
--- a/src/imports/statemachine/state.cpp
+++ b/src/imports/statemachine/state.cpp
@@ -54,7 +54,7 @@ void State::componentComplete()
static bool once = false;
if (!once) {
once = true;
- qmlInfo(this) << "No top level StateMachine found. Nothing will run without a StateMachine.";
+ qmlWarning(this) << "No top level StateMachine found. Nothing will run without a StateMachine.";
}
}
}
diff --git a/src/imports/statemachine/state.h b/src/imports/statemachine/state.h
index 73e4ecda6b..8e8cefab19 100644
--- a/src/imports/statemachine/state.h
+++ b/src/imports/statemachine/state.h
@@ -58,8 +58,8 @@ class State : public QState, public QQmlParserStatus
public:
explicit State(QState *parent = 0);
- void classBegin() {}
- void componentComplete();
+ void classBegin() override {}
+ void componentComplete() override;
QQmlListProperty<QObject> children();
diff --git a/src/imports/statemachine/statemachine.cpp b/src/imports/statemachine/statemachine.cpp
index 76de01fe94..a9ea5f7a95 100644
--- a/src/imports/statemachine/statemachine.cpp
+++ b/src/imports/statemachine/statemachine.cpp
@@ -69,7 +69,7 @@ void StateMachine::setRunning(bool running)
void StateMachine::componentComplete()
{
if (QStateMachine::initialState() == NULL && childMode() == QState::ExclusiveStates)
- qmlInfo(this) << "No initial state set for StateMachine";
+ qmlWarning(this) << "No initial state set for StateMachine";
// Everything is proper setup, now start the state-machine if we got
// asked to do so.
diff --git a/src/imports/statemachine/statemachine.h b/src/imports/statemachine/statemachine.h
index 59a810f387..cb0ab43f8b 100644
--- a/src/imports/statemachine/statemachine.h
+++ b/src/imports/statemachine/statemachine.h
@@ -62,8 +62,8 @@ class StateMachine : public QStateMachine, public QQmlParserStatus
public:
explicit StateMachine(QObject *parent = 0);
- void classBegin() {}
- void componentComplete();
+ void classBegin() override {}
+ void componentComplete() override;
QQmlListProperty<QObject> children();
bool isRunning() const;
diff --git a/src/imports/statemachine/timeouttransition.cpp b/src/imports/statemachine/timeouttransition.cpp
index 4bb1df3c28..0d208b919b 100644
--- a/src/imports/statemachine/timeouttransition.cpp
+++ b/src/imports/statemachine/timeouttransition.cpp
@@ -72,7 +72,7 @@ void TimeoutTransition::componentComplete()
{
QState *state = qobject_cast<QState*>(parent());
if (!state) {
- qmlInfo(this) << "Parent needs to be a State";
+ qmlWarning(this) << "Parent needs to be a State";
return;
}
diff --git a/src/imports/statemachine/timeouttransition.h b/src/imports/statemachine/timeouttransition.h
index 5d71e86bb4..0e5f5377e3 100644
--- a/src/imports/statemachine/timeouttransition.h
+++ b/src/imports/statemachine/timeouttransition.h
@@ -59,8 +59,8 @@ public:
int timeout() const;
void setTimeout(int timeout);
- void classBegin() {}
- void componentComplete();
+ void classBegin() override {}
+ void componentComplete() override;
Q_SIGNALS:
void timeoutChanged();
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index d22ec7c44f..18c70e1169 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -206,6 +206,59 @@ import Qt.test.qtestroot 1.0
will fail. Use the \l when and windowShown properties to track
when the main window has been shown.
+ \section1 Managing Dynamically Created Test Objects
+
+ A typical pattern with QML tests is to
+ \l {Dynamic QML Object Creation from JavaScript}{dynamically create}
+ an item and then destroy it at the end of the test function:
+
+ \code
+ TestCase {
+ id: testCase
+ name: "MyTest"
+ when: windowShown
+
+ function test_click() {
+ var item = Qt.createQmlObject("import QtQuick 2.0; Item {}", testCase);
+ verify(item);
+
+ // Test item...
+
+ item.destroy();
+ }
+ }
+ \endcode
+
+ The problem with this pattern is that any failures in the test function
+ will cause the call to \c item.destroy() to be skipped, leaving the item
+ hanging around in the scene until the test case has finished. This can
+ result in interference with future tests; for example, by blocking input
+ events or producing unrelated debug output that makes it difficult to
+ follow the code's execution.
+
+ By calling \l createTemporaryQmlObject() instead, the object is guaranteed
+ to be destroyed at the end of the test function:
+
+ \code
+ TestCase {
+ id: testCase
+ name: "MyTest"
+ when: windowShown
+
+ function test_click() {
+ var item = createTemporaryQmlObject("import QtQuick 2.0; Item {}", testCase);
+ verify(item);
+
+ // Test item...
+
+ // Don't need to worry about destroying "item" here.
+ }
+ }
+ \endcode
+
+ For objects that are created via the \l {Component::}{createObject()} function
+ of \l Component, the \l createTemporaryObject() function can be used.
+
\sa {QtTest::SignalSpy}{SignalSpy}, {Qt Quick Test Reference Documentation}
*/
@@ -358,6 +411,8 @@ Item {
/*! \internal */
property var qtest_events: qtest_events_normal
TestEvent { id: qtest_events_normal }
+ /*! \internal */
+ property var qtest_temporaryObjects: []
/*!
\qmlmethod TestCase::fail(message = "")
@@ -461,6 +516,105 @@ Item {
throw new Error("QtQuickTest::fail")
}
+ /*!
+ \since 5.9
+ \qmlmethod object TestCase::createTemporaryQmlObject(string qml, object parent, string filePath)
+
+ This function dynamically creates a QML object from the given \a qml
+ string with the specified \a parent. The returned object will be
+ destroyed (if it was not already) after \l cleanup() has finished
+ executing, meaning that objects created with this function are
+ guaranteed to be destroyed after each test, regardless of whether or
+ not the tests fail.
+
+ If there was an error while creating the object, \c null will be
+ returned.
+
+ If \a filePath is specified, it will be used for error reporting for
+ the created object.
+
+ This function calls
+ \l {QtQml::Qt::createQmlObject()}{Qt.createQmlObject()} internally.
+
+ \sa {Managing Dynamically Created Test Objects}
+ */
+ function createTemporaryQmlObject(qml, parent, filePath) {
+ if (typeof qml !== "string") {
+ qtest_results.fail("First argument must be a string of QML; actual type is " + typeof qml,
+ util.callerFile(), util.callerLine());
+ throw new Error("QtQuickTest::fail");
+ }
+
+ if (!parent || typeof parent !== "object") {
+ qtest_results.fail("Second argument must be a valid parent object; actual type is " + typeof parent,
+ util.callerFile(), util.callerLine());
+ throw new Error("QtQuickTest::fail");
+ }
+
+ if (filePath !== undefined && typeof filePath !== "string") {
+ qtest_results.fail("Third argument must be a file path string; actual type is " + typeof filePath,
+ util.callerFile(), util.callerLine());
+ throw new Error("QtQuickTest::fail");
+ }
+
+ var object = Qt.createQmlObject(qml, parent, filePath);
+ qtest_temporaryObjects.push(object);
+ return object;
+ }
+
+ /*!
+ \since 5.9
+ \qmlmethod object TestCase::createTemporaryObject(Component component, object parent, object properties)
+
+ This function dynamically creates a QML object from the given
+ \a component with the specified optional \a parent and \a properties.
+ The returned object will be destroyed (if it was not already) after
+ \l cleanup() has finished executing, meaning that objects created with
+ this function are guaranteed to be destroyed after each test,
+ regardless of whether or not the tests fail.
+
+ If there was an error while creating the object, \c null will be
+ returned.
+
+ This function calls
+ \l {QtQml::Component::createObject()}{component.createObject()}
+ internally.
+
+ \sa {Managing Dynamically Created Test Objects}
+ */
+ function createTemporaryObject(component, parent, properties) {
+ if (typeof component !== "object") {
+ qtest_results.fail("First argument must be a Component; actual type is " + typeof component,
+ util.callerFile(), util.callerLine());
+ throw new Error("QtQuickTest::fail");
+ }
+
+ if (properties && typeof properties !== "object") {
+ qtest_results.fail("Third argument must be an object; actual type is " + typeof properties,
+ util.callerFile(), util.callerLine());
+ throw new Error("QtQuickTest::fail");
+ }
+
+ var object = component.createObject(parent, properties ? properties : ({}));
+ qtest_temporaryObjects.push(object);
+ return object;
+ }
+
+ /*!
+ \internal
+
+ Destroys all temporary objects that still exist.
+ */
+ function qtest_destroyTemporaryObjects() {
+ for (var i = 0; i < qtest_temporaryObjects.length; ++i) {
+ var temporaryObject = qtest_temporaryObjects[i];
+ // ### the typeof check can be removed when QTBUG-57749 is fixed
+ if (temporaryObject && typeof temporaryObject.destroy === "function")
+ temporaryObject.destroy();
+ }
+ qtest_temporaryObjects = [];
+ }
+
/*! \internal */
// Determine what is o.
// Discussions and reference: http://philrathe.com/articles/equiv
@@ -1317,6 +1471,109 @@ Item {
qtest_fail("window not shown", 2)
}
+ /*!
+ \qmlmethod TouchEventSequence TestCase::touchEvent(object item)
+
+ \since 5.9
+
+ Begins a sequence of touch events through a simulated QTouchDevice::TouchScreen.
+ Events are delivered to the window containing \a item.
+
+ The returned object is used to enumerate events to be delivered through a single
+ QTouchEvent. Touches are delivered to the window containing the TestCase unless
+ otherwise specified.
+
+ \code
+ Rectangle {
+ width: 640; height: 480
+
+ MultiPointTouchArea {
+ id: area
+ anchors.fill: parent
+
+ property bool touched: false
+
+ onPressed: touched = true
+ }
+
+ TestCase {
+ name: "ItemTests"
+ when: area.pressed
+ id: test1
+
+ function test_touch() {
+ var touch = touchEvent(area);
+ touch.press(0, area, 10, 10);
+ touch.commit();
+ verify(area.touched);
+ }
+ }
+ }
+ \endcode
+
+ \sa TouchEventSequence::press(), TouchEventSequence::move(), TouchEventSequence::release(), TouchEventSequence::stationary(), TouchEventSequence::commit(), QTouchDevice::TouchScreen
+ */
+
+ function touchEvent(item) {
+ if (!item)
+ qtest_fail("No item given to touchEvent", 1)
+
+ return {
+ _defaultItem: item,
+ _sequence: qtest_events.touchEvent(item),
+
+ press: function (id, target, x, y) {
+ if (!target)
+ target = this._defaultItem;
+ if (id === undefined)
+ qtest_fail("No id given to TouchEventSequence::press", 1);
+ if (x === undefined)
+ x = target.width / 2;
+ if (y === undefined)
+ y = target.height / 2;
+ this._sequence.press(id, target, x, y);
+ return this;
+ },
+
+ move: function (id, target, x, y) {
+ if (!target)
+ target = this._defaultItem;
+ if (id === undefined)
+ qtest_fail("No id given to TouchEventSequence::move", 1);
+ if (x === undefined)
+ x = target.width / 2;
+ if (y === undefined)
+ y = target.height / 2;
+ this._sequence.move(id, target, x, y);
+ return this;
+ },
+
+ stationary: function (id) {
+ if (id === undefined)
+ qtest_fail("No id given to TouchEventSequence::stationary", 1);
+ this._sequence.stationary(id);
+ return this;
+ },
+
+ release: function (id, target, x, y) {
+ if (!target)
+ target = this._defaultItem;
+ if (id === undefined)
+ qtest_fail("No id given to TouchEventSequence::release", 1);
+ if (x === undefined)
+ x = target.width / 2;
+ if (y === undefined)
+ y = target.height / 2;
+ this._sequence.release(id, target, x, y);
+ return this;
+ },
+
+ commit: function () {
+ this._sequence.commit();
+ return this;
+ }
+ };
+ }
// Functions that can be overridden in subclasses for init/cleanup duties.
/*!
@@ -1389,6 +1646,7 @@ Item {
qtest_runInternal(prop, arg)
qtest_results.finishTestData()
qtest_runInternal("cleanup")
+ qtest_destroyTemporaryObjects()
qtest_results.finishTestDataCleanup()
// wait(0) will call processEvents() so objects marked for deletion
// in the test function will be deleted.
diff --git a/src/imports/testlib/main.cpp b/src/imports/testlib/main.cpp
index 4e2bd919e9..3c28000e35 100644
--- a/src/imports/testlib/main.cpp
+++ b/src/imports/testlib/main.cpp
@@ -158,6 +158,7 @@ public:
qmlRegisterType<QuickTestResult, 1>(uri,1,1,"TestResult");
qmlRegisterType<QuickTestEvent>(uri,1,0,"TestEvent");
qmlRegisterType<QuickTestUtil>(uri,1,0,"TestUtil");
+ qmlRegisterType<QQuickTouchEventSequence>();
}
};
diff --git a/src/imports/testlib/qmldir b/src/imports/testlib/qmldir
index 9da8ebb4be..e5757f6a88 100644
--- a/src/imports/testlib/qmldir
+++ b/src/imports/testlib/qmldir
@@ -3,4 +3,5 @@ plugin qmltestplugin
classname QTestQmlModule
typeinfo plugins.qmltypes
TestCase 1.0 TestCase.qml
+TestCase 1.2 TestCase.qml
SignalSpy 1.0 SignalSpy.qml
diff --git a/src/imports/testlib/toucheventsequence.qdoc b/src/imports/testlib/toucheventsequence.qdoc
new file mode 100644
index 0000000000..f85a1cd4f9
--- /dev/null
+++ b/src/imports/testlib/toucheventsequence.qdoc
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Jeremy Katz
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \qmltype TouchEventSequence
+ \inqmlmodule QtTest
+ \ingroup qtquicktest
+ \brief TouchEventSequence is used to build and dispatch touch events
+ for testing.
+
+ \since 5.9
+
+ A TouchEventSequence is created by calling \l [QML] {TestCase::touchEvent()}{TestCase.touchEvent()}.
+ The type can not be directly instantiated. Each method provided by the type returns
+ the same object, allowing chained calls.
+
+ For example:
+ \code
+ touchEvent(item).press(0).commit();
+ \endcode
+ is equivalent to:
+ \code
+ var sequence = touchEvent(item);
+ sequence.press(0);
+ sequence.commit();
+ \endcode
+
+ Events are delivered to the window which contains the item specified in touchEvent.
+
+ \sa TestCase::touchEvent(), QTest::QTouchEventSequence
+*/
+
+/*!
+ \qmlmethod TouchEventSequence TouchEventSequence::press(int touchId, object item, real x = item.width / 2, real y = item.height / 2)
+
+ Creates a new point identified as \a touchId, at the point indicated by \a x and \a y relative to \a item.
+ Further use of the same touch point should maintain the same touchId.
+
+ Item defaults to the value provided via touchEvent().
+ X and y default to the midpoint of the item.
+*/
+
+/*!
+ \qmlmethod TouchEventSequence TouchEventSequence::move(int touchId, object item, real x = item.width / 2, real y = item.height / 2)
+
+ Moves \a touchId to the point indicated by \a x and \a y relative to \a item.
+
+ Item defaults to the value provided via touchEvent().
+ X and y default to the midpoint of the item.
+*/
+
+/*!
+ \qmlmethod TouchEventSequence TouchEventSequence::release(int touchId, object item, real x = item.width / 2, real y = item.height / 2)
+
+ Removes \a touchId at the point indicated by \a x and \a y relative to \a item.
+
+ Item defaults to the value provided via touchEvent().
+ X and y default to the midpoint of the item.
+*/
+
+/*!
+ \qmlmethod TouchEventSequence TouchEventSequence::stationary(int touchId)
+
+ Indicates that \a touchId is present but otherwise unchanged from prior events.
+*/
+
+/*!
+ \qmlmethod TouchEventSequence TouchEventSequence::commit()
+
+ Sends the touch event composed by prior use of press(), move(), release(), and stationary().
+ Following commit's return, the TouchEventSequence can be used to compose a new event.
+
+ \code
+ var sequence = touchEvent(target);
+ // Touch the middle of target with 1 point
+ sequence.press(1);
+ sequence.commit();
+
+ // Begin a new event
+ // Move the point to target's upper left corner
+ sequence.move(1, target, 0, 0);
+ sequence.commit();
+ \endcode
+
+ Commit is automatically invoked when the TouchEventSequence object is destroyed.
+*/
diff --git a/src/imports/xmllistmodel/qqmlxmllistmodel.cpp b/src/imports/xmllistmodel/qqmlxmllistmodel.cpp
index 6e9e57a046..61c8665a14 100644
--- a/src/imports/xmllistmodel/qqmlxmllistmodel.cpp
+++ b/src/imports/xmllistmodel/qqmlxmllistmodel.cpp
@@ -176,7 +176,7 @@ public:
QQuickXmlQueryThreadObject(QQuickXmlQueryEngine *);
void processJobs();
- virtual bool event(QEvent *e);
+ bool event(QEvent *e) override;
private:
QQuickXmlQueryEngine *m_queryEngine;
@@ -202,7 +202,7 @@ signals:
void error(void*, const QString&);
protected:
- void run();
+ void run() override;
private:
void processQuery(XmlQueryJob *job);
@@ -596,7 +596,7 @@ void QQuickXmlListModelPrivate::append_role(QQmlListProperty<QQuickXmlListModelR
int i = _this->d_func()->roleObjects.count();
_this->d_func()->roleObjects.append(role);
if (_this->d_func()->roleNames.contains(role->name())) {
- qmlInfo(role) << QQuickXmlListModel::tr("\"%1\" duplicates a previous role name and will be disabled.").arg(role->name());
+ qmlWarning(role) << QQuickXmlListModel::tr("\"%1\" duplicates a previous role name and will be disabled.").arg(role->name());
return;
}
_this->d_func()->roles.insert(i, _this->d_func()->highestRole);
@@ -847,7 +847,7 @@ void QQuickXmlListModel::setQuery(const QString &query)
{
Q_D(QQuickXmlListModel);
if (!query.startsWith(QLatin1Char('/'))) {
- qmlInfo(this) << QCoreApplication::translate("QQuickXmlRoleList", "An XmlListModel query must start with '/' or \"//\"");
+ qmlWarning(this) << QCoreApplication::translate("QQuickXmlRoleList", "An XmlListModel query must start with '/' or \"//\"");
return;
}
@@ -1136,11 +1136,11 @@ void QQuickXmlListModel::queryError(void* object, const QString& error)
Q_D(QQuickXmlListModel);
for (int i=0; i<d->roleObjects.count(); i++) {
if (d->roleObjects.at(i) == static_cast<QQuickXmlListModelRole*>(object)) {
- qmlInfo(d->roleObjects.at(i)) << QQuickXmlListModel::tr("invalid query: \"%1\"").arg(error);
+ qmlWarning(d->roleObjects.at(i)) << QQuickXmlListModel::tr("invalid query: \"%1\"").arg(error);
return;
}
}
- qmlInfo(this) << QQuickXmlListModel::tr("invalid query: \"%1\"").arg(error);
+ qmlWarning(this) << QQuickXmlListModel::tr("invalid query: \"%1\"").arg(error);
}
void QQuickXmlListModel::queryCompleted(const QQuickXmlQueryResult &result)
diff --git a/src/imports/xmllistmodel/qqmlxmllistmodel_p.h b/src/imports/xmllistmodel/qqmlxmllistmodel_p.h
index f0096a9125..e6a0898bb9 100644
--- a/src/imports/xmllistmodel/qqmlxmllistmodel_p.h
+++ b/src/imports/xmllistmodel/qqmlxmllistmodel_p.h
@@ -79,7 +79,6 @@ class QQuickXmlListModel : public QAbstractListModel, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
- Q_ENUMS(Status)
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
@@ -95,10 +94,10 @@ public:
QQuickXmlListModel(QObject *parent = 0);
~QQuickXmlListModel();
- QModelIndex index(int row, int column, const QModelIndex &parent) const;
- int rowCount(const QModelIndex &parent) const;
- QVariant data(const QModelIndex &index, int role) const;
- QHash<int, QByteArray> roleNames() const;
+ QModelIndex index(int row, int column, const QModelIndex &parent) const override;
+ int rowCount(const QModelIndex &parent) const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+ QHash<int, QByteArray> roleNames() const override;
int count() const;
@@ -119,13 +118,14 @@ public:
Q_INVOKABLE QQmlV4Handle get(int index) const;
enum Status { Null, Ready, Loading, Error };
+ Q_ENUM(Status)
Status status() const;
qreal progress() const;
Q_INVOKABLE QString errorString() const;
- virtual void classBegin();
- virtual void componentComplete();
+ void classBegin() override;
+ void componentComplete() override;
Q_SIGNALS:
void statusChanged(QQuickXmlListModel::Status);
@@ -177,7 +177,7 @@ public:
void setQuery(const QString &query)
{
if (query.startsWith(QLatin1Char('/'))) {
- qmlInfo(this) << tr("An XmlRole query must not start with '/'");
+ qmlWarning(this) << tr("An XmlRole query must not start with '/'");
return;
}
if (m_query == query)
@@ -194,7 +194,7 @@ public:
Q_EMIT isKeyChanged();
}
- bool isValid() {
+ bool isValid() const {
return !m_name.isEmpty() && !m_query.isEmpty();
}
diff --git a/src/particles/qquickage_p.h b/src/particles/qquickage_p.h
index f6e277f8a7..5db6167dc1 100644
--- a/src/particles/qquickage_p.h
+++ b/src/particles/qquickage_p.h
@@ -74,7 +74,8 @@ public:
}
protected:
- virtual bool affectParticle(QQuickParticleData *d, qreal dt);
+ bool affectParticle(QQuickParticleData *d, qreal dt) override;
+
Q_SIGNALS:
void lifeLeftChanged(int arg);
void advancePositionChanged(bool arg);
diff --git a/src/particles/qquickangledirection.cpp b/src/particles/qquickangledirection.cpp
index 09aa047670..6f30e24a26 100644
--- a/src/particles/qquickangledirection.cpp
+++ b/src/particles/qquickangledirection.cpp
@@ -104,7 +104,7 @@ QQuickAngleDirection::QQuickAngleDirection(QObject *parent) :
}
-const QPointF QQuickAngleDirection::sample(const QPointF &from)
+QPointF QQuickAngleDirection::sample(const QPointF &from)
{
Q_UNUSED(from);
QPointF ret;
diff --git a/src/particles/qquickangledirection_p.h b/src/particles/qquickangledirection_p.h
index 3e981c5f9e..66290fb19e 100644
--- a/src/particles/qquickangledirection_p.h
+++ b/src/particles/qquickangledirection_p.h
@@ -62,7 +62,7 @@ class QQuickAngleDirection : public QQuickDirection
Q_PROPERTY(qreal magnitudeVariation READ magnitudeVariation WRITE setMagnitudeVariation NOTIFY magnitudeVariationChanged)
public:
explicit QQuickAngleDirection(QObject *parent = 0);
- const QPointF sample(const QPointF &from);
+ QPointF sample(const QPointF &from) override;
qreal angle() const
{
return m_angle;
diff --git a/src/particles/qquickcumulativedirection.cpp b/src/particles/qquickcumulativedirection.cpp
index b6b3e76f69..6fbd53df48 100644
--- a/src/particles/qquickcumulativedirection.cpp
+++ b/src/particles/qquickcumulativedirection.cpp
@@ -59,7 +59,7 @@ QQmlListProperty<QQuickDirection> QQuickCumulativeDirection::directions()
return QQmlListProperty<QQuickDirection>(this, m_directions);//TODO: Proper list property
}
-const QPointF QQuickCumulativeDirection::sample(const QPointF &from)
+QPointF QQuickCumulativeDirection::sample(const QPointF &from)
{
QPointF ret;
foreach (QQuickDirection* dir, m_directions)
diff --git a/src/particles/qquickcumulativedirection_p.h b/src/particles/qquickcumulativedirection_p.h
index 9af86bd39e..39f8ab8a24 100644
--- a/src/particles/qquickcumulativedirection_p.h
+++ b/src/particles/qquickcumulativedirection_p.h
@@ -62,7 +62,7 @@ class QQuickCumulativeDirection : public QQuickDirection
public:
explicit QQuickCumulativeDirection(QObject *parent = 0);
QQmlListProperty<QQuickDirection> directions();
- const QPointF sample(const QPointF &from);
+ QPointF sample(const QPointF &from) override;
private:
QList<QQuickDirection*> m_directions;
};
diff --git a/src/particles/qquickcustomaffector_p.h b/src/particles/qquickcustomaffector_p.h
index a383b196c2..c1745798c3 100644
--- a/src/particles/qquickcustomaffector_p.h
+++ b/src/particles/qquickcustomaffector_p.h
@@ -69,7 +69,7 @@ class QQuickCustomAffector : public QQuickParticleAffector
public:
explicit QQuickCustomAffector(QQuickItem *parent = 0);
- virtual void affectSystem(qreal dt);
+ void affectSystem(qreal dt) override;
QQuickDirection * position() const
{
@@ -153,7 +153,8 @@ public Q_SLOTS:
protected:
bool isAffectConnected();
- virtual bool affectParticle(QQuickParticleData *d, qreal dt);
+ bool affectParticle(QQuickParticleData *d, qreal dt) override;
+
private:
void affectProperties(const QList<QQuickParticleData*> particles, qreal dt);
QQuickDirection * m_position;
diff --git a/src/particles/qquickcustomparticle.cpp b/src/particles/qquickcustomparticle.cpp
index c08ae3d9ff..babf13a93c 100644
--- a/src/particles/qquickcustomparticle.cpp
+++ b/src/particles/qquickcustomparticle.cpp
@@ -40,6 +40,7 @@
#include "qquickcustomparticle_p.h"
#include <QtQuick/private/qquickshadereffectmesh_p.h>
#include <QtQuick/private/qsgshadersourcebuilder_p.h>
+#include <QtQml/qqmlinfo.h>
#include <cstdlib>
QT_BEGIN_NAMESPACE
@@ -90,6 +91,7 @@ struct PlainVertices {
\brief For specifying shaders to paint particles
\ingroup qtquick-particles
+ \note The maximum number of custom particles is limited to 16383.
*/
QQuickCustomParticle::QQuickCustomParticle(QQuickItem* parent)
@@ -316,13 +318,14 @@ QQuickOpenGLShaderEffectNode* QQuickCustomParticle::buildCustomNodes()
if (!QOpenGLContext::currentContext())
return 0;
- if (QOpenGLContext::currentContext()->isOpenGLES() && m_count * 4 > 0xffff) {
- printf("CustomParticle: Too many particles... \n");
+ if (m_count * 4 > 0xffff) {
+ // Index data is ushort.
+ qmlInfo(this) << "CustomParticle: Too many particles - maximum 16383 per CustomParticle";
return 0;
}
if (m_count <= 0) {
- printf("CustomParticle: Too few particles... \n");
+ qmlInfo(this) << "CustomParticle: Too few particles";
return 0;
}
diff --git a/src/particles/qquickcustomparticle_p.h b/src/particles/qquickcustomparticle_p.h
index e9d68cbe5c..e2292cb33b 100644
--- a/src/particles/qquickcustomparticle_p.h
+++ b/src/particles/qquickcustomparticle_p.h
@@ -53,7 +53,6 @@
#include "qquickparticlepainter_p.h"
#include <private/qquickopenglshadereffectnode_p.h>
#include <private/qquickopenglshadereffect_p.h>
-#include <QSignalMapper>
QT_BEGIN_NAMESPACE
@@ -84,18 +83,18 @@ Q_SIGNALS:
void vertexShaderChanged();
protected:
- virtual void initialize(int gIdx, int pIdx);
- virtual void commit(int gIdx, int pIdx);
+ void initialize(int gIdx, int pIdx) override;
+ void commit(int gIdx, int pIdx) override;
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
+ QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
QQuickOpenGLShaderEffectNode *prepareNextFrame(QQuickOpenGLShaderEffectNode *rootNode);
- void reset();
+ void reset() override;
void resize(int oldCount, int newCount);
- virtual void componentComplete();
+ void componentComplete() override;
QQuickOpenGLShaderEffectNode *buildCustomNodes();
- void sceneGraphInvalidated();
- void itemChange(ItemChange change, const ItemChangeData &value);
+ void sceneGraphInvalidated() override;
+ void itemChange(ItemChange change, const ItemChangeData &value) override;
private Q_SLOTS:
void sourceDestroyed(QObject *object);
diff --git a/src/particles/qquickdirection.cpp b/src/particles/qquickdirection.cpp
index da1edfb3c3..fd94c8945c 100644
--- a/src/particles/qquickdirection.cpp
+++ b/src/particles/qquickdirection.cpp
@@ -56,7 +56,7 @@ QQuickDirection::QQuickDirection(QObject *parent) :
{
}
-const QPointF QQuickDirection::sample(const QPointF &from)
+QPointF QQuickDirection::sample(const QPointF &from)
{
Q_UNUSED(from);
return QPointF();
diff --git a/src/particles/qquickdirection_p.h b/src/particles/qquickdirection_p.h
index f7029488f7..10960f9920 100644
--- a/src/particles/qquickdirection_p.h
+++ b/src/particles/qquickdirection_p.h
@@ -62,7 +62,7 @@ class QQuickDirection : public QObject
public:
explicit QQuickDirection(QObject *parent = 0);
- virtual const QPointF sample(const QPointF &from);
+ virtual QPointF sample(const QPointF &from);
Q_SIGNALS:
public Q_SLOTS:
diff --git a/src/particles/qquickellipseextruder_p.h b/src/particles/qquickellipseextruder_p.h
index 1df7e32c83..0af7f4d94f 100644
--- a/src/particles/qquickellipseextruder_p.h
+++ b/src/particles/qquickellipseextruder_p.h
@@ -60,8 +60,8 @@ class QQuickEllipseExtruder : public QQuickParticleExtruder
Q_PROPERTY(bool fill READ fill WRITE setFill NOTIFY fillChanged)//###Use base class? If it's still box
public:
explicit QQuickEllipseExtruder(QObject *parent = 0);
- virtual QPointF extrude(const QRectF &);
- virtual bool contains(const QRectF &bounds, const QPointF &point);
+ QPointF extrude(const QRectF &) override;
+ bool contains(const QRectF &bounds, const QPointF &point) override;
bool fill() const
{
diff --git a/src/particles/qquickfriction_p.h b/src/particles/qquickfriction_p.h
index b67de631be..05ae7a38d5 100644
--- a/src/particles/qquickfriction_p.h
+++ b/src/particles/qquickfriction_p.h
@@ -73,7 +73,7 @@ public:
}
protected:
- virtual bool affectParticle(QQuickParticleData *d, qreal dt);
+ bool affectParticle(QQuickParticleData *d, qreal dt) override;
Q_SIGNALS:
diff --git a/src/particles/qquickgravity.cpp b/src/particles/qquickgravity.cpp
index 90f305f336..a2a2ad7e0e 100644
--- a/src/particles/qquickgravity.cpp
+++ b/src/particles/qquickgravity.cpp
@@ -37,6 +37,7 @@
**
****************************************************************************/
+#include <QtQml/qqmlinfo.h>
#include "qquickgravity_p.h"
#include <cmath>
QT_BEGIN_NAMESPACE
@@ -64,16 +65,51 @@ const qreal CONV = 0.017453292520444443;
Pixels per second that objects will be accelerated by.
*/
+void QQuickGravityAffector::setMagnitude(qreal arg)
+{
+ if (m_magnitude != arg) {
+ m_magnitude = arg;
+ m_needRecalc = true;
+ emit magnitudeChanged(arg);
+ }
+}
+
+qreal QQuickGravityAffector::magnitude() const
+{
+ return m_magnitude;
+}
+
+
/*!
\qmlproperty real QtQuick.Particles::Gravity::acceleration
+ \deprecated
- Name changed to magnitude, will be removed soon.
+ \warning The name for this property has changed to magnitude, use it instead.
*/
+void QQuickGravityAffector::setAcceleration(qreal arg)
+{
+ qmlWarning(this) << "The acceleration property is deprecated. Please use magnitude instead.";
+ setMagnitude(arg);
+}
+
/*!
\qmlproperty real QtQuick.Particles::Gravity::angle
Angle of acceleration.
*/
+void QQuickGravityAffector::setAngle(qreal arg)
+{
+ if (m_angle != arg) {
+ m_angle = arg;
+ m_needRecalc = true;
+ emit angleChanged(arg);
+ }
+}
+
+qreal QQuickGravityAffector::angle() const
+{
+ return m_angle;
+}
QQuickGravityAffector::QQuickGravityAffector(QQuickItem *parent) :
QQuickParticleAffector(parent), m_magnitude(-10), m_angle(90), m_needRecalc(true)
@@ -94,4 +130,7 @@ bool QQuickGravityAffector::affectParticle(QQuickParticleData *d, qreal dt)
d->setInstantaneousVY(d->curVY(m_system) + m_dy*dt, m_system);
return true;
}
+
+
+
QT_END_NAMESPACE
diff --git a/src/particles/qquickgravity_p.h b/src/particles/qquickgravity_p.h
index 7c071c932d..333d3d1534 100644
--- a/src/particles/qquickgravity_p.h
+++ b/src/particles/qquickgravity_p.h
@@ -62,51 +62,20 @@ class QQuickGravityAffector : public QQuickParticleAffector
Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged)
public:
explicit QQuickGravityAffector(QQuickItem *parent = 0);
- qreal magnitude() const
- {
- return m_magnitude;
- }
+ qreal magnitude() const;
+ qreal angle() const;
- qreal angle() const
- {
- return m_angle;
- }
protected:
- virtual bool affectParticle(QQuickParticleData *d, qreal dt);
-Q_SIGNALS:
+ bool affectParticle(QQuickParticleData *d, qreal dt) override;
+Q_SIGNALS:
void magnitudeChanged(qreal arg);
-
void angleChanged(qreal arg);
public Q_SLOTS:
-void setAcceleration(qreal arg)
-{
- qWarning() << "Gravity::acceleration has been renamed Gravity::magnitude";
- if (m_magnitude != arg) {
- m_magnitude = arg;
- m_needRecalc = true;
- Q_EMIT magnitudeChanged(arg);
- }
-}
-
-void setMagnitude(qreal arg)
-{
- if (m_magnitude != arg) {
- m_magnitude = arg;
- m_needRecalc = true;
- Q_EMIT magnitudeChanged(arg);
- }
-}
-
-void setAngle(qreal arg)
-{
- if (m_angle != arg) {
- m_angle = arg;
- m_needRecalc = true;
- Q_EMIT angleChanged(arg);
- }
-}
+ void setMagnitude(qreal arg);
+ void setAcceleration(qreal arg);
+ void setAngle(qreal arg);
private:
qreal m_magnitude;
diff --git a/src/particles/qquickgroupgoal_p.h b/src/particles/qquickgroupgoal_p.h
index 0b935fc1d1..9a56ef5cce 100644
--- a/src/particles/qquickgroupgoal_p.h
+++ b/src/particles/qquickgroupgoal_p.h
@@ -75,7 +75,7 @@ public:
}
protected:
- virtual bool affectParticle(QQuickParticleData *d, qreal dt);
+ bool affectParticle(QQuickParticleData *d, qreal dt) override;
Q_SIGNALS:
diff --git a/src/particles/qquickimageparticle.cpp b/src/particles/qquickimageparticle.cpp
index e6b921792f..ccfebddb0e 100644
--- a/src/particles/qquickimageparticle.cpp
+++ b/src/particles/qquickimageparticle.cpp
@@ -58,12 +58,6 @@
QT_BEGIN_NAMESPACE
-#if defined(Q_OS_BLACKBERRY)
-#define SHADER_PLATFORM_DEFINES "Q_OS_BLACKBERRY\n"
-#else
-#define SHADER_PLATFORM_DEFINES
-#endif
-
//TODO: Make it larger on desktop? Requires fixing up shader code with the same define
#define UNIFORM_ARRAY_SIZE 64
@@ -102,7 +96,6 @@ public:
const bool isES = QOpenGLContext::currentContext()->isOpenGLES();
builder.appendSourceFile(QStringLiteral(":/particles/shaders/imageparticle.vert"));
- builder.addDefinition(QByteArray(SHADER_PLATFORM_DEFINES));
builder.addDefinition(QByteArrayLiteral("TABLE"));
builder.addDefinition(QByteArrayLiteral("DEFORM"));
builder.addDefinition(QByteArrayLiteral("COLOR"));
@@ -113,7 +106,6 @@ public:
builder.clear();
builder.appendSourceFile(QStringLiteral(":/particles/shaders/imageparticle.frag"));
- builder.addDefinition(QByteArray(SHADER_PLATFORM_DEFINES));
builder.addDefinition(QByteArrayLiteral("TABLE"));
builder.addDefinition(QByteArrayLiteral("DEFORM"));
builder.addDefinition(QByteArrayLiteral("COLOR"));
@@ -180,7 +172,6 @@ public:
const bool isES = QOpenGLContext::currentContext()->isOpenGLES();
builder.appendSourceFile(QStringLiteral(":/particles/shaders/imageparticle.vert"));
- builder.addDefinition(QByteArray(SHADER_PLATFORM_DEFINES));
builder.addDefinition(QByteArrayLiteral("DEFORM"));
builder.addDefinition(QByteArrayLiteral("COLOR"));
if (isES)
@@ -190,7 +181,6 @@ public:
builder.clear();
builder.appendSourceFile(QStringLiteral(":/particles/shaders/imageparticle.frag"));
- builder.addDefinition(QByteArray(SHADER_PLATFORM_DEFINES));
builder.addDefinition(QByteArrayLiteral("DEFORM"));
builder.addDefinition(QByteArrayLiteral("COLOR"));
if (isES)
@@ -245,7 +235,6 @@ public:
const bool isES = QOpenGLContext::currentContext()->isOpenGLES();
builder.appendSourceFile(QStringLiteral(":/particles/shaders/imageparticle.vert"));
- builder.addDefinition(QByteArray(SHADER_PLATFORM_DEFINES));
builder.addDefinition(QByteArrayLiteral("SPRITE"));
builder.addDefinition(QByteArrayLiteral("TABLE"));
builder.addDefinition(QByteArrayLiteral("DEFORM"));
@@ -257,7 +246,6 @@ public:
builder.clear();
builder.appendSourceFile(QStringLiteral(":/particles/shaders/imageparticle.frag"));
- builder.addDefinition(QByteArray(SHADER_PLATFORM_DEFINES));
builder.addDefinition(QByteArrayLiteral("SPRITE"));
builder.addDefinition(QByteArrayLiteral("TABLE"));
builder.addDefinition(QByteArrayLiteral("DEFORM"));
@@ -327,7 +315,6 @@ public:
const bool isES = QOpenGLContext::currentContext()->isOpenGLES();
builder.appendSourceFile(QStringLiteral(":/particles/shaders/imageparticle.vert"));
- builder.addDefinition(QByteArray(SHADER_PLATFORM_DEFINES));
builder.addDefinition(QByteArrayLiteral("COLOR"));
if (isES)
builder.removeVersion();
@@ -336,7 +323,6 @@ public:
builder.clear();
builder.appendSourceFile(QStringLiteral(":/particles/shaders/imageparticle.frag"));
- builder.addDefinition(QByteArray(SHADER_PLATFORM_DEFINES));
builder.addDefinition(QByteArrayLiteral("COLOR"));
if (isES)
builder.removeVersion();
@@ -405,7 +391,6 @@ public:
const bool isES = QOpenGLContext::currentContext()->isOpenGLES();
builder.appendSourceFile(QStringLiteral(":/particles/shaders/imageparticle.vert"));
- builder.addDefinition(QByteArray(SHADER_PLATFORM_DEFINES));
if (isES)
builder.removeVersion();
@@ -413,7 +398,6 @@ public:
builder.clear();
builder.appendSourceFile(QStringLiteral(":/particles/shaders/imageparticle.frag"));
- builder.addDefinition(QByteArray(SHADER_PLATFORM_DEFINES));
if (isES)
builder.removeVersion();
@@ -510,6 +494,8 @@ void fillUniformArrayFromImage(float* array, const QImage& img, int size)
So if you explicitly set an attribute affecting color, such as redVariation, and then reset it (by setting redVariation
to undefined), all color data will be reset and it will begin to have an implicit value of any shared color from
other ImageParticles.
+
+ \note The maximum number of image particles is limited to 16383.
*/
/*!
\qmlproperty url QtQuick.Particles::ImageParticle::source
@@ -1240,8 +1226,9 @@ void QQuickImageParticle::finishBuildParticleNodes(QSGNode** node)
if (!QOpenGLContext::currentContext())
return;
- if (QOpenGLContext::currentContext()->isOpenGLES() && m_count * 4 > 0xffff) {
- printf("ImageParticle: Too many particles - maximum 16,000 per ImageParticle.\n");//ES 2 vertex count limit is ushort
+ if (m_count * 4 > 0xffff) {
+ // Index data is ushort.
+ qmlInfo(this) << "ImageParticle: Too many particles - maximum 16383 per ImageParticle";
return;
}
@@ -1344,21 +1331,21 @@ void QQuickImageParticle::finishBuildParticleNodes(QSGNode** node)
if (m_colorTable->pix.isReady())
colortable = m_colorTable->pix.image();
else
- qmlInfo(this) << "Error loading color table: " << m_colorTable->pix.error();
+ qmlWarning(this) << "Error loading color table: " << m_colorTable->pix.error();
}
if (m_sizeTable) {
if (m_sizeTable->pix.isReady())
sizetable = m_sizeTable->pix.image();
else
- qmlInfo(this) << "Error loading size table: " << m_sizeTable->pix.error();
+ qmlWarning(this) << "Error loading size table: " << m_sizeTable->pix.error();
}
if (m_opacityTable) {
if (m_opacityTable->pix.isReady())
opacitytable = m_opacityTable->pix.image();
else
- qmlInfo(this) << "Error loading opacity table: " << m_opacityTable->pix.error();
+ qmlWarning(this) << "Error loading opacity table: " << m_opacityTable->pix.error();
}
if (colortable.isNull()){//###Goes through image just for this
@@ -1380,7 +1367,7 @@ void QQuickImageParticle::finishBuildParticleNodes(QSGNode** node)
if (!imageLoaded) {
if (!m_image || !m_image->pix.isReady()) {
if (m_image)
- qmlInfo(this) << m_image->pix.error();
+ qmlWarning(this) << m_image->pix.error();
delete m_material;
return;
}
diff --git a/src/particles/qquickimageparticle_p.h b/src/particles/qquickimageparticle_p.h
index 492ec23c07..95323c25a6 100644
--- a/src/particles/qquickimageparticle_p.h
+++ b/src/particles/qquickimageparticle_p.h
@@ -347,15 +347,15 @@ public Q_SLOTS:
void setEntryEffect(EntryEffect arg);
protected:
- void reset();
- virtual void initialize(int gIdx, int pIdx);
- virtual void commit(int gIdx, int pIdx);
+ void reset() override;
+ void initialize(int gIdx, int pIdx) override;
+ void commit(int gIdx, int pIdx) override;
- QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
+ QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
void prepareNextFrame(QSGNode**);
void buildParticleNodes(QSGNode**);
- void sceneGraphInvalidated();
+ void sceneGraphInvalidated() override;
private Q_SLOTS:
void createEngine(); //### method invoked by sprite list changing (in engine.h) - pretty nasty
@@ -440,7 +440,7 @@ private:
}
template<class MaterialData>
- MaterialData* getState(QSGMaterial* m){
+ static MaterialData* getState(QSGMaterial* m) {
return static_cast<QSGSimpleMaterial<MaterialData> *>(m)->state();
}
EntryEffect m_entryEffect;
diff --git a/src/particles/qquickitemparticle_p.h b/src/particles/qquickitemparticle_p.h
index 0edd05dfc7..9e6c7deaea 100644
--- a/src/particles/qquickitemparticle_p.h
+++ b/src/particles/qquickitemparticle_p.h
@@ -70,7 +70,7 @@ public:
bool fade() const { return m_fade; }
- virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
+ QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
static QQuickItemParticleAttached *qmlAttachedProperties(QObject *object);
QQmlComponent* delegate() const
@@ -100,9 +100,9 @@ public Q_SLOTS:
}
protected:
- virtual void reset();
- virtual void commit(int gIdx, int pIdx);
- virtual void initialize(int gIdx, int pIdx);
+ void reset() override;
+ void commit(int gIdx, int pIdx) override;
+ void initialize(int gIdx, int pIdx) override;
void prepareNextFrame();
private:
void processDeletables();
@@ -131,7 +131,7 @@ public:
QQuickItemParticleAttached(QObject* parent)
: QObject(parent), m_mp(0)
{;}
- QQuickItemParticle* particle() {return m_mp;}
+ QQuickItemParticle* particle() const { return m_mp; }
void detach(){Q_EMIT detached();}
void attach(){Q_EMIT attached();}
private:
diff --git a/src/particles/qquicklineextruder_p.h b/src/particles/qquicklineextruder_p.h
index 72d2300dce..306f3a1dd6 100644
--- a/src/particles/qquicklineextruder_p.h
+++ b/src/particles/qquicklineextruder_p.h
@@ -56,11 +56,11 @@ class QQuickLineExtruder : public QQuickParticleExtruder
{
Q_OBJECT
//Default is topleft to bottom right. Flipped makes it topright to bottom left
- Q_PROPERTY(bool mirrored READ mirrored WRITE setmirrored NOTIFY mirroredChanged)
+ Q_PROPERTY(bool mirrored READ mirrored WRITE setMirrored NOTIFY mirroredChanged)
public:
explicit QQuickLineExtruder(QObject *parent = 0);
- virtual QPointF extrude(const QRectF &);
+ QPointF extrude(const QRectF &) override;
bool mirrored() const
{
return m_mirrored;
@@ -72,7 +72,7 @@ Q_SIGNALS:
public Q_SLOTS:
- void setmirrored(bool arg)
+ void setMirrored(bool arg)
{
if (m_mirrored != arg) {
m_mirrored = arg;
diff --git a/src/particles/qquickmaskextruder.cpp b/src/particles/qquickmaskextruder.cpp
index 66d5808c33..7564fa6739 100644
--- a/src/particles/qquickmaskextruder.cpp
+++ b/src/particles/qquickmaskextruder.cpp
@@ -94,7 +94,7 @@ void QQuickMaskExtruder::startMaskLoading()
void QQuickMaskExtruder::finishMaskLoading()
{
if (m_pix.isError())
- qmlInfo(this) << m_pix.error();
+ qmlWarning(this) << m_pix.error();
}
QPointF QQuickMaskExtruder::extrude(const QRectF &r)
diff --git a/src/particles/qquickmaskextruder_p.h b/src/particles/qquickmaskextruder_p.h
index 32ace521da..0fc0331db8 100644
--- a/src/particles/qquickmaskextruder_p.h
+++ b/src/particles/qquickmaskextruder_p.h
@@ -63,8 +63,8 @@ class QQuickMaskExtruder : public QQuickParticleExtruder
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
public:
explicit QQuickMaskExtruder(QObject *parent = 0);
- virtual QPointF extrude(const QRectF &);
- virtual bool contains(const QRectF &bounds, const QPointF &point);
+ QPointF extrude(const QRectF &) override;
+ bool contains(const QRectF &bounds, const QPointF &point) override;
QUrl source() const
{
diff --git a/src/particles/qquickparticleaffector.cpp b/src/particles/qquickparticleaffector.cpp
index 6ed0d9e14a..31bcfb82af 100644
--- a/src/particles/qquickparticleaffector.cpp
+++ b/src/particles/qquickparticleaffector.cpp
@@ -244,7 +244,7 @@ void QQuickParticleAffector::updateOffsets()
m_offset = m_system->mapFromItem(this, QPointF(0, 0));
}
-bool QQuickParticleAffector::isColliding(QQuickParticleData *d)
+bool QQuickParticleAffector::isColliding(QQuickParticleData *d) const
{
qreal myCurX = d->curX(m_system);
qreal myCurY = d->curY(m_system);
diff --git a/src/particles/qquickparticleaffector_p.h b/src/particles/qquickparticleaffector_p.h
index c42c0b4cba..5c9652bc32 100644
--- a/src/particles/qquickparticleaffector_p.h
+++ b/src/particles/qquickparticleaffector_p.h
@@ -185,7 +185,7 @@ protected:
bool activeGroup(int g);
bool shouldAffect(QQuickParticleData* datum);//Call to do the logic on whether it is affecting that datum
void postAffect(QQuickParticleData* datum);//Call to do the post-affect logic on particles which WERE affected(once off, needs reset, affected signal)
- virtual void componentComplete();
+ void componentComplete() override;
bool isAffectedConnected();
static const qreal simulationDelta;
static const qreal simulationCutoff;
@@ -200,7 +200,7 @@ private:
QStringList m_whenCollidingWith;
- bool isColliding(QQuickParticleData* d);
+ bool isColliding(QQuickParticleData* d) const;
};
QT_END_NAMESPACE
diff --git a/src/particles/qquickparticleemitter_p.h b/src/particles/qquickparticleemitter_p.h
index b3f96ae3e6..4f7e12da44 100644
--- a/src/particles/qquickparticleemitter_p.h
+++ b/src/particles/qquickparticleemitter_p.h
@@ -133,7 +133,7 @@ public:
qreal velocityFromMovement() const { return m_velocity_from_movement; }
void setVelocityFromMovement(qreal s);
- virtual void componentComplete();
+ void componentComplete() override;
Q_SIGNALS:
void emitParticles(QQmlV4Handle particles);
void particlesPerSecondChanged(qreal);
diff --git a/src/particles/qquickparticlegroup_p.h b/src/particles/qquickparticlegroup_p.h
index 25cc2130b1..0314234569 100644
--- a/src/particles/qquickparticlegroup_p.h
+++ b/src/particles/qquickparticlegroup_p.h
@@ -104,8 +104,8 @@ Q_SIGNALS:
void systemChanged(QQuickParticleSystem* arg);
protected:
- virtual void componentComplete();
- virtual void classBegin(){;}
+ void componentComplete() override;
+ void classBegin() override {}
private:
diff --git a/src/particles/qquickparticlepainter_p.h b/src/particles/qquickparticlepainter_p.h
index 064ce27fe8..ac14a18103 100644
--- a/src/particles/qquickparticlepainter_p.h
+++ b/src/particles/qquickparticlepainter_p.h
@@ -98,7 +98,7 @@ public:
return m_groupIds;
}
- void itemChange(ItemChange, const ItemChangeData &);
+ void itemChange(ItemChange, const ItemChangeData &) override;
Q_SIGNALS:
void countChanged();
@@ -123,7 +123,7 @@ protected:
*/
virtual void reset();
- virtual void componentComplete();
+ void componentComplete() override;
virtual void initialize(int gIdx, int pIdx){//Called from main thread
Q_UNUSED(gIdx);
Q_UNUSED(pIdx);
diff --git a/src/particles/qquickparticlesystem.cpp b/src/particles/qquickparticlesystem.cpp
index b60180b2ed..99e278238b 100644
--- a/src/particles/qquickparticlesystem.cpp
+++ b/src/particles/qquickparticlesystem.cpp
@@ -575,9 +575,6 @@ QQuickParticleSystem::QQuickParticleSystem(QQuickItem *parent) :
m_paused(false),
m_empty(true)
{
- connect(&m_painterMapper, SIGNAL(mapped(QObject*)),
- this, SLOT(loadPainter(QObject*)));
-
m_debugMode = qmlParticlesDebug();
}
@@ -615,8 +612,8 @@ void QQuickParticleSystem::registerParticlePainter(QQuickParticlePainter* p)
qDebug() << "Registering Painter" << p << "to" << this;
//TODO: a way to Unregister emitters, painters and affectors
m_painters << QPointer<QQuickParticlePainter>(p);//###Set or uniqueness checking?
- connect(p, SIGNAL(groupsChanged(QStringList)),
- &m_painterMapper, SLOT(map()));
+
+ connect(p, &QQuickParticlePainter::groupsChanged, this, [this, p] { this->loadPainter(p); }, Qt::QueuedConnection);
loadPainter(p);
}
@@ -802,13 +799,11 @@ void QQuickParticleSystem::reset()
}
-void QQuickParticleSystem::loadPainter(QObject *p)
+void QQuickParticleSystem::loadPainter(QQuickParticlePainter *painter)
{
- if (!m_componentComplete || !p)
+ if (!m_componentComplete || !painter)
return;
- QQuickParticlePainter* painter = qobject_cast<QQuickParticlePainter*>(p);
- Q_ASSERT(painter);//XXX
for (QQuickParticleGroupData* sg : groupData) {
sg->painters.removeOne(painter);
}
diff --git a/src/particles/qquickparticlesystem_p.h b/src/particles/qquickparticlesystem_p.h
index b57d55bd98..92dca40419 100644
--- a/src/particles/qquickparticlesystem_p.h
+++ b/src/particles/qquickparticlesystem_p.h
@@ -56,7 +56,6 @@
#include <QVector>
#include <QHash>
#include <QPointer>
-#include <QSignalMapper>
#include <private/qquicksprite_p.h>
#include <QAbstractAnimation>
#include <QtQml/qqml.h>
@@ -389,11 +388,11 @@ public Q_SLOTS:
protected:
//This one only once per frame (effectively)
- void componentComplete();
+ void componentComplete() override;
private Q_SLOTS:
void emittersChanged();
- void loadPainter(QObject* p);
+ void loadPainter(QQuickParticlePainter *p);
void createEngine(); //Not invoked by sprite engine, unlike Sprite uses
void particleStateChange(int idx);
@@ -461,8 +460,6 @@ private:
QSet<int> m_reusableIndexes;
bool m_componentComplete;
- QSignalMapper m_painterMapper;
- QSignalMapper m_emitterMapper;
bool m_paused;
bool m_allDead;
bool m_empty;
@@ -477,12 +474,12 @@ public:
: QAbstractAnimation(static_cast<QObject*>(system)), m_system(system)
{ }
protected:
- virtual void updateCurrentTime( int t )
+ void updateCurrentTime(int t) override
{
m_system->updateCurrentTime(t);
}
- virtual int duration() const
+ int duration() const override
{
return -1;
}
diff --git a/src/particles/qquickpointattractor_p.h b/src/particles/qquickpointattractor_p.h
index 99fae300c6..47985b5e82 100644
--- a/src/particles/qquickpointattractor_p.h
+++ b/src/particles/qquickpointattractor_p.h
@@ -160,7 +160,8 @@ void setProportionalToDistance(Proportion arg)
}
protected:
- virtual bool affectParticle(QQuickParticleData *d, qreal dt);
+ bool affectParticle(QQuickParticleData *d, qreal dt) override;
+
private:
qreal m_strength;
qreal m_x;
diff --git a/src/particles/qquickpointdirection.cpp b/src/particles/qquickpointdirection.cpp
index dbd15148ba..9038ce0aa0 100644
--- a/src/particles/qquickpointdirection.cpp
+++ b/src/particles/qquickpointdirection.cpp
@@ -75,7 +75,7 @@ QQuickPointDirection::QQuickPointDirection(QObject *parent) :
{
}
-const QPointF QQuickPointDirection::sample(const QPointF &)
+QPointF QQuickPointDirection::sample(const QPointF &)
{
QPointF ret;
ret.setX(m_x - m_xVariation + rand() / float(RAND_MAX) * m_xVariation * 2);
diff --git a/src/particles/qquickpointdirection_p.h b/src/particles/qquickpointdirection_p.h
index b01dc7ea4e..a80be928ad 100644
--- a/src/particles/qquickpointdirection_p.h
+++ b/src/particles/qquickpointdirection_p.h
@@ -63,7 +63,7 @@ class QQuickPointDirection : public QQuickDirection
Q_PROPERTY(qreal yVariation READ yVariation WRITE setYVariation NOTIFY yVariationChanged)
public:
explicit QQuickPointDirection(QObject *parent = 0);
- virtual const QPointF sample(const QPointF &from);
+ QPointF sample(const QPointF &from) override;
qreal x() const
{
return m_x;
diff --git a/src/particles/qquickrectangleextruder_p.h b/src/particles/qquickrectangleextruder_p.h
index 001031c711..630cf3050d 100644
--- a/src/particles/qquickrectangleextruder_p.h
+++ b/src/particles/qquickrectangleextruder_p.h
@@ -62,8 +62,8 @@ class QQuickRectangleExtruder : public QQuickParticleExtruder
public:
explicit QQuickRectangleExtruder(QObject *parent = 0);
- virtual QPointF extrude(const QRectF &);
- virtual bool contains(const QRectF &bounds, const QPointF &point);
+ QPointF extrude(const QRectF &) override;
+ bool contains(const QRectF &bounds, const QPointF &point) override;
bool fill() const
{
return m_fill;
diff --git a/src/particles/qquickspritegoal_p.h b/src/particles/qquickspritegoal_p.h
index 7174fd2318..e569603550 100644
--- a/src/particles/qquickspritegoal_p.h
+++ b/src/particles/qquickspritegoal_p.h
@@ -81,7 +81,8 @@ public:
}
protected:
- virtual bool affectParticle(QQuickParticleData *d, qreal dt);
+ bool affectParticle(QQuickParticleData *d, qreal dt) override;
+
Q_SIGNALS:
void goalStateChanged(const QString &arg);
@@ -106,7 +107,7 @@ void setSystemStates(bool arg)
{
if (m_systemStates != arg) {
//TODO: GroupGoal was added (and this deprecated) Oct 4 - remove it in a few weeks.
- qmlInfo(this) << "systemStates is deprecated and will be removed soon. Use GroupGoal instead.";
+ qmlWarning(this) << "systemStates is deprecated and will be removed soon. Use GroupGoal instead.";
m_systemStates = arg;
Q_EMIT systemStatesChanged(arg);
}
diff --git a/src/particles/qquicktargetdirection.cpp b/src/particles/qquicktargetdirection.cpp
index f9bcfbc564..012c9a151b 100644
--- a/src/particles/qquicktargetdirection.cpp
+++ b/src/particles/qquicktargetdirection.cpp
@@ -94,7 +94,7 @@ QQuickTargetDirection::QQuickTargetDirection(QObject *parent) :
{
}
-const QPointF QQuickTargetDirection::sample(const QPointF &from)
+QPointF QQuickTargetDirection::sample(const QPointF &from)
{
//###This approach loses interpolating the last position of the target (like we could with the emitter) is it worthwhile?
QPointF ret;
diff --git a/src/particles/qquicktargetdirection_p.h b/src/particles/qquicktargetdirection_p.h
index 4de5867336..13e826743e 100644
--- a/src/particles/qquicktargetdirection_p.h
+++ b/src/particles/qquicktargetdirection_p.h
@@ -71,7 +71,7 @@ class QQuickTargetDirection : public QQuickDirection
public:
explicit QQuickTargetDirection(QObject *parent = 0);
- virtual const QPointF sample(const QPointF &from);
+ QPointF sample(const QPointF &from) override;
qreal targetX() const
{
diff --git a/src/particles/qquicktrailemitter_p.h b/src/particles/qquicktrailemitter_p.h
index b70f34999a..99464436ba 100644
--- a/src/particles/qquicktrailemitter_p.h
+++ b/src/particles/qquicktrailemitter_p.h
@@ -71,8 +71,8 @@ public:
};
Q_ENUM(EmitSize)
explicit QQuickTrailEmitter(QQuickItem *parent = 0);
- virtual void emitWindow(int timeStamp);
- virtual void reset();
+ void emitWindow(int timeStamp) override;
+ void reset() override;
int particlesPerParticlePerSecond() const
{
diff --git a/src/particles/qquickturbulence_p.h b/src/particles/qquickturbulence_p.h
index 7a6be1719e..e73f3ba153 100644
--- a/src/particles/qquickturbulence_p.h
+++ b/src/particles/qquickturbulence_p.h
@@ -65,7 +65,7 @@ class QQuickTurbulenceAffector : public QQuickParticleAffector
public:
explicit QQuickTurbulenceAffector(QQuickItem *parent = 0);
~QQuickTurbulenceAffector();
- virtual void affectSystem(qreal dt);
+ void affectSystem(qreal dt) override;
qreal strength() const
{
@@ -102,8 +102,8 @@ public Q_SLOTS:
}
protected:
- virtual void geometryChanged(const QRectF &newGeometry,
- const QRectF &oldGeometry);
+ void geometryChanged(const QRectF &newGeometry,
+ const QRectF &oldGeometry) override;
private:
void ensureInit();
void mapUpdate();
diff --git a/src/particles/qquickv4particledata.cpp b/src/particles/qquickv4particledata.cpp
index bd43d45c38..967652f31a 100644
--- a/src/particles/qquickv4particledata.cpp
+++ b/src/particles/qquickv4particledata.cpp
@@ -525,7 +525,7 @@ QQuickV4ParticleData::~QQuickV4ParticleData()
{
}
-QQmlV4Handle QQuickV4ParticleData::v4Value()
+QQmlV4Handle QQuickV4ParticleData::v4Value() const
{
return QQmlV4Handle(m_v4Value.value());
}
diff --git a/src/particles/qquickv4particledata_p.h b/src/particles/qquickv4particledata_p.h
index 437491ff42..d73e3b644d 100644
--- a/src/particles/qquickv4particledata_p.h
+++ b/src/particles/qquickv4particledata_p.h
@@ -63,7 +63,7 @@ class QQuickV4ParticleData {
public:
QQuickV4ParticleData(QV8Engine*, QQuickParticleData*, QQuickParticleSystem *system);
~QQuickV4ParticleData();
- QQmlV4Handle v4Value();
+ QQmlV4Handle v4Value() const;
private:
QV4::PersistentValue m_v4Value;
};
diff --git a/src/particles/qquickwander_p.h b/src/particles/qquickwander_p.h
index 6461444cd1..0ad19d4d13 100644
--- a/src/particles/qquickwander_p.h
+++ b/src/particles/qquickwander_p.h
@@ -105,7 +105,8 @@ public:
}
protected:
- virtual bool affectParticle(QQuickParticleData *d, qreal dt);
+ bool affectParticle(QQuickParticleData *d, qreal dt) override;
+
Q_SIGNALS:
void xVarianceChanged(qreal arg);
diff --git a/src/particles/shaders/imageparticle.vert b/src/particles/shaders/imageparticle.vert
index 377f831686..4057a9eb4b 100644
--- a/src/particles/shaders/imageparticle.vert
+++ b/src/particles/shaders/imageparticle.vert
@@ -69,11 +69,7 @@ void main()
fTex = vPosTex.zw;
#endif
highp float currentSize = mix(vData.z, vData.w, t * t);
-#if defined (Q_OS_BLACKBERRY)
- highp float fade = 1.;
-#else
lowp float fade = 1.;
-#endif
highp float fadeIn = min(t * 10., 1.);
highp float fadeOut = 1. - clamp((t - 0.75) * 4.,0., 1.);
@@ -142,4 +138,4 @@ void main()
#endif
}
}
-} \ No newline at end of file
+}
diff --git a/src/particles/shaders/imageparticle_core.vert b/src/particles/shaders/imageparticle_core.vert
index ed9a918eb3..cfa0d57dfd 100644
--- a/src/particles/shaders/imageparticle_core.vert
+++ b/src/particles/shaders/imageparticle_core.vert
@@ -69,11 +69,7 @@ void main()
fTex = vPosTex.zw;
#endif
float currentSize = mix(vData.z, vData.w, t * t);
-#if defined (Q_OS_BLACKBERRY)
float fade = 1.;
-#else
- float fade = 1.;
-#endif
float fadeIn = min(t * 10., 1.);
float fadeOut = 1. - clamp((t - 0.75) * 4.,0., 1.);
@@ -142,4 +138,4 @@ void main()
#endif
}
}
-} \ No newline at end of file
+}
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qmldbg_debugger.pro b/src/plugins/qmltooling/qmldbg_debugger/qmldbg_debugger.pro
index 27b3a5b513..f3f8a21ff8 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qmldbg_debugger.pro
+++ b/src/plugins/qmltooling/qmldbg_debugger/qmldbg_debugger.pro
@@ -2,10 +2,8 @@ TARGET = qmldbg_debugger
QT = qml-private core-private packetprotocol-private
SOURCES += \
- $$PWD/qdebugmessageservice.cpp \
$$PWD/qqmldebuggerservicefactory.cpp \
$$PWD/qqmlenginedebugservice.cpp \
- $$PWD/qqmlnativedebugservice.cpp \
$$PWD/qqmlwatcher.cpp \
$$PWD/qv4debugservice.cpp \
$$PWD/qv4debugger.cpp \
@@ -16,10 +14,8 @@ SOURCES += \
HEADERS += \
$$PWD/../shared/qqmlconfigurabledebugservice.h \
$$PWD/../shared/qqmldebugpacket.h \
- $$PWD/qdebugmessageservice.h \
$$PWD/qqmldebuggerservicefactory.h \
$$PWD/qqmlenginedebugservice.h \
- $$PWD/qqmlnativedebugservice.h \
$$PWD/qqmlwatcher.h \
$$PWD/qv4debugservice.h \
$$PWD/qv4debugger.h \
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservice.json b/src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservice.json
index 967a725903..442d7781a1 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservice.json
+++ b/src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservice.json
@@ -1,3 +1,3 @@
{
- "Keys": [ "DebugMessages", "QmlDebugger", "V8Debugger", "NativeQmlDebugger" ]
+ "Keys": [ "QmlDebugger", "V8Debugger" ]
}
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservicefactory.cpp b/src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservicefactory.cpp
index ca3f07323d..9315adf4ce 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservicefactory.cpp
+++ b/src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservicefactory.cpp
@@ -39,27 +39,19 @@
#include "qqmldebuggerservicefactory.h"
#include "qqmlenginedebugservice.h"
-#include "qdebugmessageservice.h"
#include "qv4debugservice.h"
-#include "qqmlnativedebugservice.h"
#include <private/qqmldebugserviceinterfaces_p.h>
QT_BEGIN_NAMESPACE
QQmlDebugService *QQmlDebuggerServiceFactory::create(const QString &key)
{
- if (key == QDebugMessageServiceImpl::s_key)
- return new QDebugMessageServiceImpl(this);
-
if (key == QQmlEngineDebugServiceImpl::s_key)
return new QQmlEngineDebugServiceImpl(this);
if (key == QV4DebugServiceImpl::s_key)
return new QV4DebugServiceImpl(this);
- if (key == QQmlNativeDebugServiceImpl::s_key)
- return new QQmlNativeDebugServiceImpl(this);
-
return 0;
}
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservicefactory.h b/src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservicefactory.h
index 99d6679833..50eed2369c 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservicefactory.h
+++ b/src/plugins/qmltooling/qmldbg_debugger/qqmldebuggerservicefactory.h
@@ -49,7 +49,7 @@ class QQmlDebuggerServiceFactory : public QQmlDebugServiceFactory
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlDebugServiceFactory_iid FILE "qqmldebuggerservice.json")
public:
- QQmlDebugService *create(const QString &key);
+ QQmlDebugService *create(const QString &key) override;
};
QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp b/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp
index 2b8dcc19ee..151e44c4d4 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp
+++ b/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp
@@ -289,10 +289,12 @@ void QQmlEngineDebugServiceImpl::buildObjectDump(QDataStream &message,
prop.value = expr->expression();
QObject *scope = expr->scopeObject();
if (scope) {
- QString methodName = QString::fromLatin1(QMetaObjectPrivate::signal(scope->metaObject(), signalHandler->signalIndex()).name());
- if (!methodName.isEmpty()) {
- prop.name = QLatin1String("on") + methodName[0].toUpper()
- + methodName.mid(1);
+ const QByteArray methodName = QMetaObjectPrivate::signal(scope->metaObject(),
+ signalHandler->signalIndex()).name();
+ const QLatin1String methodNameStr(methodName);
+ if (methodNameStr.size() != 0) {
+ prop.name = QLatin1String("on") + QChar(methodNameStr.at(0)).toUpper()
+ + methodNameStr.mid(1);
}
}
}
@@ -520,12 +522,12 @@ void QQmlEngineDebugServiceImpl::processMessage(const QByteArray &message)
ds >> file >> lineNumber >> columnNumber >> recurse >> dumpProperties;
- QList<QObject*> objects = objectForLocationInfo(file, lineNumber, columnNumber);
+ const QList<QObject*> objects = objectForLocationInfo(file, lineNumber, columnNumber);
rs << QByteArray("FETCH_OBJECTS_FOR_LOCATION_R") << queryId
<< objects.count();
- foreach (QObject *object, objects) {
+ for (QObject *object : objects) {
if (recurse)
prepareDeferredObjects(object);
buildObjectDump(rs, object, recurse, dumpProperties);
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4debuggeragent.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4debuggeragent.cpp
index 756b6b28be..773bc937f5 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qv4debuggeragent.cpp
+++ b/src/plugins/qmltooling/qmldbg_debugger/qv4debuggeragent.cpp
@@ -52,7 +52,7 @@ QV4DebuggerAgent::QV4DebuggerAgent(QV4DebugServiceImpl *debugService)
QV4Debugger *QV4DebuggerAgent::pausedDebugger() const
{
- foreach (QV4Debugger *debugger, m_debuggers) {
+ for (QV4Debugger *debugger : m_debuggers) {
if (debugger->state() == QV4Debugger::Paused)
return debugger;
}
@@ -147,13 +147,13 @@ void QV4DebuggerAgent::pause(QV4Debugger *debugger) const
void QV4DebuggerAgent::pauseAll() const
{
- foreach (QV4Debugger *debugger, m_debuggers)
+ for (QV4Debugger *debugger : m_debuggers)
pause(debugger);
}
void QV4DebuggerAgent::resumeAll() const
{
- foreach (QV4Debugger *debugger, m_debuggers)
+ for (QV4Debugger *debugger : m_debuggers)
if (debugger->state() == QV4Debugger::Paused)
debugger->resume(QV4Debugger::FullThrottle);
}
@@ -161,7 +161,7 @@ void QV4DebuggerAgent::resumeAll() const
int QV4DebuggerAgent::addBreakPoint(const QString &fileName, int lineNumber, bool enabled, const QString &condition)
{
if (enabled)
- foreach (QV4Debugger *debugger, m_debuggers)
+ for (QV4Debugger *debugger : qAsConst(m_debuggers))
debugger->addBreakPoint(fileName, lineNumber, condition);
int id = m_breakPoints.size();
@@ -178,7 +178,7 @@ void QV4DebuggerAgent::removeBreakPoint(int id)
m_breakPoints.remove(id);
if (breakPoint.enabled)
- foreach (QV4Debugger *debugger, m_debuggers)
+ for (QV4Debugger *debugger : qAsConst(m_debuggers))
debugger->removeBreakPoint(breakPoint.fileName, breakPoint.lineNr);
}
@@ -195,7 +195,7 @@ void QV4DebuggerAgent::enableBreakPoint(int id, bool onoff)
return;
breakPoint.enabled = onoff;
- foreach (QV4Debugger *debugger, m_debuggers) {
+ for (QV4Debugger *debugger : qAsConst(m_debuggers)) {
if (onoff)
debugger->addBreakPoint(breakPoint.fileName, breakPoint.lineNr, breakPoint.condition);
else
@@ -218,14 +218,14 @@ void QV4DebuggerAgent::setBreakOnThrow(bool onoff)
{
if (onoff != m_breakOnThrow) {
m_breakOnThrow = onoff;
- foreach (QV4Debugger *debugger, m_debuggers)
+ for (QV4Debugger *debugger : qAsConst(m_debuggers))
debugger->setBreakOnThrow(onoff);
}
}
void QV4DebuggerAgent::clearAllPauseRequests()
{
- foreach (QV4Debugger *debugger, m_debuggers)
+ for (QV4Debugger *debugger : qAsConst(m_debuggers))
debugger->clearPauseRequest();
}
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp
index d5cc765ea8..df316c1ae6 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp
+++ b/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp
@@ -43,6 +43,7 @@
#include <private/qqmlcontext_p.h>
#include <private/qv4qmlcontext_p.h>
#include <private/qv4qobjectwrapper_p.h>
+#include <private/qqmldebugservice_p.h>
#include <QtQml/qqmlengine.h>
@@ -52,9 +53,10 @@ QV4DebugJob::~QV4DebugJob()
{
}
-JavaScriptJob::JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr,
- const QString &script) :
- engine(engine), frameNr(frameNr), script(script), resultIsException(false)
+JavaScriptJob::JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr, int context,
+ const QString &script) :
+ engine(engine), frameNr(frameNr), context(context), script(script),
+ resultIsException(false)
{}
void JavaScriptJob::run()
@@ -65,7 +67,23 @@ void JavaScriptJob::run()
QV4::ExecutionContext *ctx = engine->currentContext;
QObject scopeObject;
- if (frameNr < 0) { // Use QML context if available
+
+ if (frameNr > 0) {
+ for (int i = 0; i < frameNr; ++i) {
+ ctx = engine->parentContext(ctx);
+ }
+ engine->pushContext(ctx);
+ ctx = engine->currentContext;
+ }
+
+ if (context >= 0) {
+ QQmlContext *extraContext = qmlContext(QQmlDebugService::objectForId(context));
+ if (extraContext) {
+ engine->pushContext(QV4::QmlContext::create(ctx, QQmlContextData::get(extraContext),
+ &scopeObject));
+ ctx = engine->currentContext;
+ }
+ } else if (frameNr < 0) { // Use QML context if available
QQmlEngine *qmlEngine = engine->qmlEngine();
if (qmlEngine) {
QQmlContext *qmlRootContext = qmlEngine->rootContext();
@@ -89,13 +107,6 @@ void JavaScriptJob::run()
engine->pushContext(ctx->newWithContext(withContext->toObject(engine)));
ctx = engine->currentContext;
}
- } else {
- if (frameNr > 0) {
- for (int i = 0; i < frameNr; ++i) {
- ctx = engine->parentContext(ctx);
- }
- engine->pushContext(ctx);
- }
}
QV4::Script script(ctx, this->script);
@@ -206,7 +217,7 @@ void ValueLookupJob::run()
QQmlContextData::get(engine->qmlEngine()->rootContext()),
scopeObject.data()));
}
- foreach (const QJsonValue &handle, handles) {
+ for (const QJsonValue &handle : handles) {
QV4DataCollector::Ref ref = handle.toInt();
if (!collector->isValidRef(ref)) {
exception = QString::fromLatin1("Invalid Ref: %1").arg(ref);
@@ -225,8 +236,9 @@ const QString &ValueLookupJob::exceptionMessage() const
}
ExpressionEvalJob::ExpressionEvalJob(QV4::ExecutionEngine *engine, int frameNr,
- const QString &expression, QV4DataCollector *collector) :
- JavaScriptJob(engine, frameNr, expression), collector(collector)
+ int context, const QString &expression,
+ QV4DataCollector *collector) :
+ JavaScriptJob(engine, frameNr, context, expression), collector(collector)
{
}
@@ -259,7 +271,7 @@ GatherSourcesJob::GatherSourcesJob(QV4::ExecutionEngine *engine)
void GatherSourcesJob::run()
{
- foreach (QV4::CompiledData::CompilationUnit *unit, engine->compilationUnits) {
+ for (QV4::CompiledData::CompilationUnit *unit : qAsConst(engine->compilationUnits)) {
QString fileName = unit->fileName();
if (!fileName.isEmpty())
sources.append(fileName);
@@ -272,7 +284,7 @@ const QStringList &GatherSourcesJob::result() const
}
EvalJob::EvalJob(QV4::ExecutionEngine *engine, const QString &script) :
- JavaScriptJob(engine, /*frameNr*/-1, script), result(false)
+ JavaScriptJob(engine, /*frameNr*/-1, /*context*/ -1, script), result(false)
{}
void EvalJob::handleResult(QV4::ScopedValue &result)
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.h b/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.h
index 721f42b7c2..00d3e6206a 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.h
+++ b/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.h
@@ -60,12 +60,13 @@ class JavaScriptJob : public QV4DebugJob
{
QV4::ExecutionEngine *engine;
int frameNr;
+ int context;
const QString &script;
bool resultIsException;
public:
- JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr, const QString &script);
- void run();
+ JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr, int context, const QString &script);
+ void run() override;
bool hasExeption() const;
protected:
@@ -90,7 +91,7 @@ class BacktraceJob: public CollectJob
int toFrame;
public:
BacktraceJob(QV4DataCollector *collector, int fromFrame, int toFrame);
- void run();
+ void run() override;
};
class FrameJob: public CollectJob
@@ -100,7 +101,7 @@ class FrameJob: public CollectJob
public:
FrameJob(QV4DataCollector *collector, int frameNr);
- void run();
+ void run() override;
bool wasSuccessful() const;
};
@@ -112,7 +113,7 @@ class ScopeJob: public CollectJob
public:
ScopeJob(QV4DataCollector *collector, int frameNr, int scopeNr);
- void run();
+ void run() override;
bool wasSuccessful() const;
};
@@ -123,7 +124,7 @@ class ValueLookupJob: public CollectJob
public:
ValueLookupJob(const QJsonArray &handles, QV4DataCollector *collector);
- void run();
+ void run() override;
const QString &exceptionMessage() const;
};
@@ -135,9 +136,9 @@ class ExpressionEvalJob: public JavaScriptJob
QJsonArray collectedRefs;
public:
- ExpressionEvalJob(QV4::ExecutionEngine *engine, int frameNr, const QString &expression,
- QV4DataCollector *collector);
- virtual void handleResult(QV4::ScopedValue &value);
+ ExpressionEvalJob(QV4::ExecutionEngine *engine, int frameNr, int context,
+ const QString &expression, QV4DataCollector *collector);
+ void handleResult(QV4::ScopedValue &value) override;
const QString &exceptionMessage() const;
const QJsonObject &returnValue() const;
const QJsonArray &refs() const;
@@ -150,7 +151,7 @@ class GatherSourcesJob: public QV4DebugJob
public:
GatherSourcesJob(QV4::ExecutionEngine *engine);
- void run();
+ void run() override;
const QStringList &result() const;
};
@@ -161,7 +162,7 @@ class EvalJob: public JavaScriptJob
public:
EvalJob(QV4::ExecutionEngine *engine, const QString &script);
- virtual void handleResult(QV4::ScopedValue &result);
+ void handleResult(QV4::ScopedValue &result) override;
bool resultAsBoolean() const;
};
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp
index 00c5c1ad77..1d2cc092dc 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp
+++ b/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp
@@ -152,7 +152,7 @@ class UnknownV8CommandHandler: public V8CommandHandler
public:
UnknownV8CommandHandler(): V8CommandHandler(QString()) {}
- virtual void handleRequest()
+ void handleRequest() override
{
QString msg = QLatin1String("unimplemented command \"")
+ req.value(QLatin1String("command")).toString()
@@ -167,7 +167,7 @@ class V8VersionRequest: public V8CommandHandler
public:
V8VersionRequest(): V8CommandHandler(QStringLiteral("version")) {}
- virtual void handleRequest()
+ void handleRequest() override
{
addCommand();
addRequestSequence();
@@ -177,6 +177,7 @@ public:
body.insert(QStringLiteral("V8Version"),
QLatin1String("this is not V8, this is V4 in Qt " QT_VERSION_STR));
body.insert(QStringLiteral("UnpausedEvaluate"), true);
+ body.insert(QStringLiteral("ContextEvaluate"), true);
addBody(body);
}
};
@@ -186,7 +187,7 @@ class V8SetBreakPointRequest: public V8CommandHandler
public:
V8SetBreakPointRequest(): V8CommandHandler(QStringLiteral("setbreakpoint")) {}
- virtual void handleRequest()
+ void handleRequest() override
{
// decypher the payload:
QJsonObject args = req.value(QLatin1String("arguments")).toObject();
@@ -237,7 +238,7 @@ class V8ClearBreakPointRequest: public V8CommandHandler
public:
V8ClearBreakPointRequest(): V8CommandHandler(QStringLiteral("clearbreakpoint")) {}
- virtual void handleRequest()
+ void handleRequest() override
{
// decypher the payload:
QJsonObject args = req.value(QLatin1String("arguments")).toObject();
@@ -270,7 +271,7 @@ class V8BacktraceRequest: public V8CommandHandler
public:
V8BacktraceRequest(): V8CommandHandler(QStringLiteral("backtrace")) {}
- virtual void handleRequest()
+ void handleRequest() override
{
// decypher the payload:
@@ -303,7 +304,7 @@ class V8FrameRequest: public V8CommandHandler
public:
V8FrameRequest(): V8CommandHandler(QStringLiteral("frame")) {}
- virtual void handleRequest()
+ void handleRequest() override
{
// decypher the payload:
QJsonObject arguments = req.value(QLatin1String("arguments")).toObject();
@@ -345,7 +346,7 @@ class V8ScopeRequest: public V8CommandHandler
public:
V8ScopeRequest(): V8CommandHandler(QStringLiteral("scope")) {}
- virtual void handleRequest()
+ void handleRequest() override
{
// decypher the payload:
QJsonObject arguments = req.value(QLatin1String("arguments")).toObject();
@@ -390,7 +391,7 @@ class V8LookupRequest: public V8CommandHandler
public:
V8LookupRequest(): V8CommandHandler(QStringLiteral("lookup")) {}
- virtual void handleRequest()
+ void handleRequest() override
{
// decypher the payload:
QJsonObject arguments = req.value(QLatin1String("arguments")).toObject();
@@ -430,7 +431,7 @@ class V8ContinueRequest: public V8CommandHandler
public:
V8ContinueRequest(): V8CommandHandler(QStringLiteral("continue")) {}
- virtual void handleRequest()
+ void handleRequest() override
{
// decypher the payload:
QJsonObject arguments = req.value(QLatin1String("arguments")).toObject();
@@ -476,7 +477,7 @@ class V8DisconnectRequest: public V8CommandHandler
public:
V8DisconnectRequest(): V8CommandHandler(QStringLiteral("disconnect")) {}
- virtual void handleRequest()
+ void handleRequest() override
{
debugService->debuggerAgent.removeAllBreakPoints();
debugService->debuggerAgent.resumeAll();
@@ -494,7 +495,7 @@ class V8SetExceptionBreakRequest: public V8CommandHandler
public:
V8SetExceptionBreakRequest(): V8CommandHandler(QStringLiteral("setexceptionbreak")) {}
- virtual void handleRequest()
+ void handleRequest() override
{
bool wasEnabled = debugService->debuggerAgent.breakOnThrow();
@@ -534,7 +535,7 @@ class V8ScriptsRequest: public V8CommandHandler
public:
V8ScriptsRequest(): V8CommandHandler(QStringLiteral("scripts")) {}
- virtual void handleRequest()
+ void handleRequest() override
{
//decypher the payload:
QJsonObject arguments = req.value(QLatin1String("arguments")).toObject();
@@ -558,7 +559,7 @@ public:
debugger->runInEngine(&job);
QJsonArray body;
- foreach (const QString &source, job.result()) {
+ for (const QString &source : job.result()) {
QJsonObject src;
src[QLatin1String("name")] = source;
src[QLatin1String("scriptType")] = 4;
@@ -606,10 +607,11 @@ class V8EvaluateRequest: public V8CommandHandler
public:
V8EvaluateRequest(): V8CommandHandler(QStringLiteral("evaluate")) {}
- virtual void handleRequest()
+ void handleRequest() override
{
QJsonObject arguments = req.value(QLatin1String("arguments")).toObject();
QString expression = arguments.value(QLatin1String("expression")).toString();
+ int context = arguments.value(QLatin1String("context")).toInt(-1);
int frame = -1;
QV4Debugger *debugger = debugService->debuggerAgent.pausedDebugger();
@@ -627,7 +629,8 @@ public:
frame = arguments.value(QLatin1String("frame")).toInt(0);
}
- ExpressionEvalJob job(debugger->engine(), frame, expression, debugger->collector());
+ ExpressionEvalJob job(debugger->engine(), frame, context, expression,
+ debugger->collector());
debugger->runInEngine(&job);
if (job.hasExeption()) {
createErrorResponse(job.exceptionMessage());
@@ -718,7 +721,8 @@ void QV4DebugServiceImpl::stateAboutToBeChanged(State state)
{
QMutexLocker lock(&m_configMutex);
if (state == Enabled) {
- foreach (QV4Debugger *debugger, debuggerAgent.debuggers()) {
+ const auto debuggers = debuggerAgent.debuggers();
+ for (QV4Debugger *debugger : debuggers) {
QV4::ExecutionEngine *ee = debugger->engine();
if (!ee->debugger())
ee->setDebugger(debugger);
@@ -737,7 +741,7 @@ void QV4DebugServiceImpl::signalEmitted(const QString &signal)
//Normalize to Lower case.
QString signalName = signal.left(signal.indexOf(QLatin1Char('('))).toLower();
- foreach (const QString &signal, breakOnSignals) {
+ for (const QString &signal : qAsConst(breakOnSignals)) {
if (signal == signalName) {
// TODO: pause debugger
break;
diff --git a/src/plugins/qmltooling/qmldbg_inspector/globalinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/globalinspector.cpp
index ca7c76ab50..7145645609 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/globalinspector.cpp
+++ b/src/plugins/qmltooling/qmldbg_inspector/globalinspector.cpp
@@ -92,7 +92,7 @@ void GlobalInspector::setSelectedItems(const QList<QQuickItem *> &items)
QList<QObject*> objectList;
objectList.reserve(items.count());
- foreach (QQuickItem *item, items)
+ for (QQuickItem *item : items)
objectList << item;
sendCurrentObjects(objectList);
@@ -113,7 +113,7 @@ void GlobalInspector::sendCurrentObjects(const QList<QObject*> &objects)
QList<int> debugIds;
debugIds.reserve(objects.count());
- foreach (QObject *object, objects)
+ for (QObject *object : objects)
debugIds << QQmlDebugService::idForObject(object);
ds << debugIds;
@@ -194,7 +194,7 @@ bool GlobalInspector::createQmlObject(int requestId, const QString &qml, QObject
return false;
QString imports;
- foreach (const QString &s, importList)
+ for (const QString &s : importList)
imports += s + QLatin1Char('\n');
ObjectCreator *objectCreator = new ObjectCreator(requestId, parentContext->engine(), parent);
@@ -223,7 +223,7 @@ void GlobalInspector::removeWindow(QQuickWindow *window)
void GlobalInspector::setParentWindow(QQuickWindow *window, QWindow *parentWindow)
{
- foreach (QmlJSDebugger::QQuickWindowInspector *inspector, m_windowInspectors) {
+ for (QmlJSDebugger::QQuickWindowInspector *inspector : qAsConst(m_windowInspectors)) {
if (inspector->quickWindow() == window)
inspector->setParentWindow(parentWindow);
}
@@ -234,7 +234,8 @@ bool GlobalInspector::syncSelectedItems(const QList<QQuickItem *> &items)
bool selectionChanged = false;
// Disconnect and remove items that are no longer selected
- foreach (QQuickItem *item, m_selectedItems) {
+ const auto selectedItemsCopy = m_selectedItems;
+ for (QQuickItem *item : selectedItemsCopy) {
if (items.contains(item))
continue;
@@ -245,14 +246,14 @@ bool GlobalInspector::syncSelectedItems(const QList<QQuickItem *> &items)
}
// Connect and add newly selected items
- foreach (QQuickItem *item, items) {
+ for (QQuickItem *item : items) {
if (m_selectedItems.contains(item))
continue;
selectionChanged = true;
connect(item, &QObject::destroyed, this, &GlobalInspector::removeFromSelectedItems);
m_selectedItems.append(item);
- foreach (QQuickWindowInspector *inspector, m_windowInspectors) {
+ for (QQuickWindowInspector *inspector : qAsConst(m_windowInspectors)) {
if (inspector->isEnabled() && inspector->quickWindow() == item->window()) {
m_highlightItems.insert(item, new SelectionHighlight(titleForItem(item), item,
inspector->overlay()));
@@ -312,12 +313,12 @@ void GlobalInspector::processMessage(const QByteArray &message)
ds >> requestId >> command;
if (command == ENABLE) {
- foreach (QQuickWindowInspector *inspector, m_windowInspectors)
+ for (QQuickWindowInspector *inspector : qAsConst(m_windowInspectors))
inspector->setEnabled(true);
success = !m_windowInspectors.isEmpty();
} else if (command == DISABLE) {
setSelectedItems(QList<QQuickItem*>());
- foreach (QQuickWindowInspector *inspector, m_windowInspectors)
+ for (QQuickWindowInspector *inspector : qAsConst(m_windowInspectors))
inspector->setEnabled(false);
success = !m_windowInspectors.isEmpty();
} else if (command == SELECT) {
@@ -325,7 +326,7 @@ void GlobalInspector::processMessage(const QByteArray &message)
ds >> debugIds;
QList<QQuickItem *> selectedObjects;
- foreach (int debugId, debugIds) {
+ for (int debugId : qAsConst(debugIds)) {
if (QQuickItem *obj =
qobject_cast<QQuickItem *>(QQmlDebugService::objectForId(debugId)))
selectedObjects << obj;
@@ -339,7 +340,7 @@ void GlobalInspector::processMessage(const QByteArray &message)
} else if (command == SHOW_APP_ON_TOP) {
bool showOnTop;
ds >> showOnTop;
- foreach (QmlJSDebugger::QQuickWindowInspector *inspector, m_windowInspectors)
+ for (QmlJSDebugger::QQuickWindowInspector *inspector : qAsConst(m_windowInspectors))
inspector->setShowAppOnTop(showOnTop);
success = !m_windowInspectors.isEmpty();
} else if (command == CREATE_OBJECT) {
diff --git a/src/plugins/qmltooling/qmldbg_inspector/highlight.h b/src/plugins/qmltooling/qmldbg_inspector/highlight.h
index 2bf4fc1ad5..3f910e833b 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/highlight.h
+++ b/src/plugins/qmltooling/qmldbg_inspector/highlight.h
@@ -81,7 +81,7 @@ class SelectionHighlight : public Highlight
public:
SelectionHighlight(const QString &name, QQuickItem *item, QQuickItem *parent);
- void paint(QPainter *painter);
+ void paint(QPainter *painter) override;
void showName(const QPointF &displayPoint);
private:
@@ -104,7 +104,7 @@ public:
setZ(1); // hover highlight on top of selection highlight
}
- void paint(QPainter *painter);
+ void paint(QPainter *painter) override;
};
} // namespace QmlJSDebugger
diff --git a/src/plugins/qmltooling/qmldbg_inspector/qqmlinspectorservicefactory.h b/src/plugins/qmltooling/qmldbg_inspector/qqmlinspectorservicefactory.h
index 09e6a01f96..3214532c8d 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/qqmlinspectorservicefactory.h
+++ b/src/plugins/qmltooling/qmldbg_inspector/qqmlinspectorservicefactory.h
@@ -64,7 +64,7 @@ class QQmlInspectorServiceFactory : public QQmlDebugServiceFactory
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlDebugServiceFactory_iid FILE "qqmlinspectorservice.json")
public:
- QQmlDebugService *create(const QString &key);
+ QQmlDebugService *create(const QString &key) override;
};
QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_inspector/qquickwindowinspector.h b/src/plugins/qmltooling/qmldbg_inspector/qquickwindowinspector.h
index b37a9face1..fc18f33ad3 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/qquickwindowinspector.h
+++ b/src/plugins/qmltooling/qmldbg_inspector/qquickwindowinspector.h
@@ -78,7 +78,7 @@ public:
void setEnabled(bool enabled);
protected:
- bool eventFilter(QObject *, QEvent *);
+ bool eventFilter(QObject *, QEvent *) override;
private:
QQuickItem *m_overlay;
diff --git a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp
index 64b26bdd0d..6152853917 100644
--- a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp
+++ b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnection.cpp
@@ -43,6 +43,8 @@
#include <QtCore/qplugin.h>
#include <QtNetwork/qlocalsocket.h>
+Q_DECLARE_METATYPE(QLocalSocket::LocalSocketError)
+
QT_BEGIN_NAMESPACE
@@ -133,8 +135,14 @@ bool QLocalClientConnection::connectToServer()
{
m_socket = new QLocalSocket;
m_socket->setParent(this);
- QObject::connect(m_socket, &QLocalSocket::connected,
- this, &QLocalClientConnection::connectionEstablished);
+ connect(m_socket, &QLocalSocket::connected,
+ this, &QLocalClientConnection::connectionEstablished);
+ connect(m_socket, static_cast<void(QLocalSocket::*)(QLocalSocket::LocalSocketError)>(
+ &QLocalSocket::error), m_socket, [this](QLocalSocket::LocalSocketError) {
+ m_socket->disconnectFromServer();
+ m_socket->connectToServer(m_filename);
+ }, Qt::QueuedConnection);
+
m_socket->connectToServer(m_filename);
qDebug("QML Debugger: Connecting to socket %s...", m_filename.toLatin1().constData());
return true;
diff --git a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnectionfactory.h b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnectionfactory.h
index b884a1ec23..b64a1fff95 100644
--- a/src/plugins/qmltooling/qmldbg_local/qlocalclientconnectionfactory.h
+++ b/src/plugins/qmltooling/qmldbg_local/qlocalclientconnectionfactory.h
@@ -50,7 +50,7 @@ class QLocalClientConnectionFactory : public QQmlDebugServerConnectionFactory
Q_PLUGIN_METADATA(IID QQmlDebugServerConnectionFactory_iid FILE "qlocalclientconnection.json")
Q_INTERFACES(QQmlDebugServerConnectionFactory)
public:
- QQmlDebugServerConnection *create(const QString &key);
+ QQmlDebugServerConnection *create(const QString &key) override;
};
QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qdebugmessageservice.cpp b/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservice.cpp
index b0f59717ac..b0f59717ac 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qdebugmessageservice.cpp
+++ b/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservice.cpp
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qdebugmessageservice.h b/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservice.h
index c25e756c2d..24fd27514b 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qdebugmessageservice.h
+++ b/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservice.h
@@ -68,10 +68,10 @@ public:
QDebugMessageServiceImpl(QObject *parent = 0);
void sendDebugMessage(QtMsgType type, const QMessageLogContext &ctxt, const QString &buf);
- void synchronizeTime(const QElapsedTimer &otherTimer);
+ void synchronizeTime(const QElapsedTimer &otherTimer) override;
protected:
- void stateChanged(State);
+ void stateChanged(State) override;
private:
friend class QQmlDebuggerServiceFactory;
diff --git a/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservice.json b/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservice.json
new file mode 100644
index 0000000000..2e8dc65cf5
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservice.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "DebugMessages" ]
+}
diff --git a/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservicefactory.cpp b/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservicefactory.cpp
new file mode 100644
index 0000000000..a066237e77
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservicefactory.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdebugmessageservicefactory.h"
+#include "qdebugmessageservice.h"
+#include <private/qqmldebugserviceinterfaces_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QQmlDebugService *QDebugMessageServiceFactory::create(const QString &key)
+{
+ if (key == QDebugMessageServiceImpl::s_key)
+ return new QDebugMessageServiceImpl(this);
+
+ return 0;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservicefactory.h b/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservicefactory.h
new file mode 100644
index 0000000000..0c5f0f5d0a
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_messages/qdebugmessageservicefactory.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDEBUGMESSAGESERVICEFACTORY_H
+#define QDEBUGMESSAGESERVICEFACTORY_H
+
+#include <private/qqmldebugservicefactory_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QDebugMessageServiceFactory : public QQmlDebugServiceFactory
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QQmlDebugServiceFactory_iid FILE "qdebugmessageservice.json")
+public:
+ QQmlDebugService *create(const QString &key) override;
+};
+
+QT_END_NAMESPACE
+
+#endif // QDEBUGMESSAGESERVICEFACTORY_H
diff --git a/src/plugins/qmltooling/qmldbg_messages/qmldbg_messages.pro b/src/plugins/qmltooling/qmldbg_messages/qmldbg_messages.pro
new file mode 100644
index 0000000000..5ddf7c615d
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_messages/qmldbg_messages.pro
@@ -0,0 +1,21 @@
+TARGET = qmldbg_messages
+QT = qml-private core packetprotocol-private
+
+SOURCES += \
+ $$PWD/qdebugmessageservice.cpp \
+ $$PWD/qdebugmessageservicefactory.cpp
+
+HEADERS += \
+ $$PWD/../shared/qqmldebugpacket.h \
+ $$PWD/qdebugmessageservice.h \
+ $$PWD/qdebugmessageservicefactory.h
+
+INCLUDEPATH += $$PWD \
+ $$PWD/../shared
+
+OTHER_FILES += \
+ $$PWD/qdebugmessageservice.json
+
+PLUGIN_TYPE = qmltooling
+PLUGIN_CLASS_NAME = QDebugMessageServiceFactory
+load(qt_plugin)
diff --git a/src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.cpp b/src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.cpp
index 3145601612..1a318b3ca2 100644
--- a/src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.cpp
+++ b/src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.cpp
@@ -183,7 +183,7 @@ QQmlNativeDebugConnector::QQmlNativeDebugConnector()
: m_blockingMode(false)
{
const QString args = commandLineArguments();
- const auto lstjsDebugArguments = args.splitRef(QLatin1Char(','));
+ const auto lstjsDebugArguments = args.splitRef(QLatin1Char(','), QString::SkipEmptyParts);
QStringList services;
for (const QStringRef &strArgument : lstjsDebugArguments) {
if (strArgument == QLatin1String("block")) {
@@ -195,7 +195,7 @@ QQmlNativeDebugConnector::QQmlNativeDebugConnector()
services.append(strArgument.mid(9).toString());
} else if (!services.isEmpty()) {
services.append(strArgument.toString());
- } else {
+ } else if (!strArgument.startsWith(QLatin1String("connector:"))) {
qWarning("QML Debugger: Invalid argument \"%s\" detected. Ignoring the same.",
strArgument.toUtf8().constData());
}
@@ -205,7 +205,7 @@ QQmlNativeDebugConnector::QQmlNativeDebugConnector()
QQmlNativeDebugConnector::~QQmlNativeDebugConnector()
{
- foreach (QQmlDebugService *service, m_services) {
+ for (QQmlDebugService *service : qAsConst(m_services)) {
service->stateAboutToBeChanged(QQmlDebugService::NotConnected);
service->setState(QQmlDebugService::NotConnected);
service->stateChanged(QQmlDebugService::NotConnected);
@@ -232,12 +232,12 @@ void QQmlNativeDebugConnector::addEngine(QJSEngine *engine)
Q_ASSERT(!m_engines.contains(engine));
TRACE_PROTOCOL("Add engine to connector:" << engine);
- foreach (QQmlDebugService *service, m_services)
+ for (QQmlDebugService *service : qAsConst(m_services))
service->engineAboutToBeAdded(engine);
announceObjectAvailability(QLatin1String("qmlengine"), engine, true);
- foreach (QQmlDebugService *service, m_services)
+ for (QQmlDebugService *service : qAsConst(m_services))
service->engineAdded(engine);
m_engines.append(engine);
@@ -248,12 +248,12 @@ void QQmlNativeDebugConnector::removeEngine(QJSEngine *engine)
Q_ASSERT(m_engines.contains(engine));
TRACE_PROTOCOL("Remove engine from connector:" << engine);
- foreach (QQmlDebugService *service, m_services)
+ for (QQmlDebugService *service : qAsConst(m_services))
service->engineAboutToBeRemoved(engine);
announceObjectAvailability(QLatin1String("qmlengine"), engine, false);
- foreach (QQmlDebugService *service, m_services)
+ for (QQmlDebugService *service : qAsConst(m_services))
service->engineRemoved(engine);
m_engines.removeOne(engine);
diff --git a/src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.h b/src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.h
index 1184925e53..f8b7e1d527 100644
--- a/src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.h
+++ b/src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.h
@@ -78,7 +78,7 @@ class QQmlNativeDebugConnectorFactory : public QQmlDebugConnectorFactory
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlDebugConnectorFactory_iid FILE "qqmlnativedebugconnector.json")
public:
- QQmlDebugConnector *create(const QString &key);
+ QQmlDebugConnector *create(const QString &key) override;
};
QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_nativedebugger/qmldbg_nativedebugger.pro b/src/plugins/qmltooling/qmldbg_nativedebugger/qmldbg_nativedebugger.pro
new file mode 100644
index 0000000000..1873a6a77c
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_nativedebugger/qmldbg_nativedebugger.pro
@@ -0,0 +1,21 @@
+TARGET = qmldbg_nativedebugger
+QT = qml-private core packetprotocol-private
+
+SOURCES += \
+ $$PWD/qqmlnativedebugservicefactory.cpp \
+ $$PWD/qqmlnativedebugservice.cpp
+
+HEADERS += \
+ $$PWD/../shared/qqmldebugpacket.h \
+ $$PWD/qqmlnativedebugservicefactory.h \
+ $$PWD/qqmlnativedebugservice.h \
+
+INCLUDEPATH += $$PWD \
+ $$PWD/../shared
+
+OTHER_FILES += \
+ $$PWD/qqmlnativedebugservice.json
+
+PLUGIN_TYPE = qmltooling
+PLUGIN_CLASS_NAME = QQmlNativeDebugServiceFactory
+load(qt_plugin)
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qqmlnativedebugservice.cpp b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp
index 14dfc5356e..7f842419e7 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qqmlnativedebugservice.cpp
+++ b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp
@@ -287,7 +287,7 @@ void NativeDebugger::signalEmitted(const QString &signal)
//Normalize to Lower case.
QString signalName = signal.left(signal.indexOf(QLatin1Char('('))).toLower();
- foreach (const QString &signal, breakOnSignals) {
+ for (const QString &signal : qAsConst(breakOnSignals)) {
if (signal == signalName) {
// TODO: pause debugger
break;
@@ -339,15 +339,15 @@ void NativeDebugger::handleBacktrace(QJsonObject *response, const QJsonObject &a
if (QV4::Function *function = executionContext->getFunction()) {
QJsonObject frame;
- frame[QStringLiteral("language")] = QStringLiteral("js");
- frame[QStringLiteral("context")] = encodeContext(executionContext);
+ frame.insert(QStringLiteral("language"), QStringLiteral("js"));
+ frame.insert(QStringLiteral("context"), encodeContext(executionContext));
if (QV4::Heap::String *functionName = function->name())
- frame[QStringLiteral("function")] = functionName->toQString();
- frame[QStringLiteral("file")] = function->sourceFile();
+ frame.insert(QStringLiteral("function"), functionName->toQString());
+ frame.insert(QStringLiteral("file"), function->sourceFile());
int line = executionContext->d()->lineNumber;
- frame[QStringLiteral("line")] = (line < 0 ? -line : line);
+ frame.insert(QStringLiteral("line"), (line < 0 ? -line : line));
frameArray.push_back(frame);
}
@@ -473,8 +473,8 @@ void NativeDebugger::handleVariables(QJsonObject *response, const QJsonObject &a
TRACE_PROTOCOL("Engine: " << engine);
Collector collector(engine);
- QJsonArray expanded = arguments.value(QLatin1String("expanded")).toArray();
- foreach (const QJsonValue &ex, expanded)
+ const QJsonArray expanded = arguments.value(QLatin1String("expanded")).toArray();
+ for (const QJsonValue &ex : expanded)
collector.m_expanded.append(ex.toString());
TRACE_PROTOCOL("Expanded: " << collector.m_expanded);
@@ -525,16 +525,16 @@ void NativeDebugger::handleExpressions(QJsonObject *response, const QJsonObject
TRACE_PROTOCOL("Engines: " << engine << m_engine);
Collector collector(engine);
- QJsonArray expanded = arguments.value(QLatin1String("expanded")).toArray();
- foreach (const QJsonValue &ex, expanded)
+ const QJsonArray expanded = arguments.value(QLatin1String("expanded")).toArray();
+ for (const QJsonValue &ex : expanded)
collector.m_expanded.append(ex.toString());
TRACE_PROTOCOL("Expanded: " << collector.m_expanded);
QJsonArray output;
QV4::Scope scope(engine);
- QJsonArray expressions = arguments.value(QLatin1String("expressions")).toArray();
- foreach (const QJsonValue &expr, expressions) {
+ const QJsonArray expressions = arguments.value(QLatin1String("expressions")).toArray();
+ for (const QJsonValue &expr : expressions) {
QString expression = expr.toObject().value(QLatin1String("expression")).toString();
QString name = expr.toObject().value(QLatin1String("name")).toString();
TRACE_PROTOCOL("Evaluate expression: " << expression);
@@ -546,15 +546,15 @@ void NativeDebugger::handleExpressions(QJsonObject *response, const QJsonObject
m_runningJob = false;
if (result->isUndefined()) {
QJsonObject dict;
- dict[QStringLiteral("name")] = name;
- dict[QStringLiteral("valueencoded")] = QStringLiteral("undefined");
+ dict.insert(QStringLiteral("name"), name);
+ dict.insert(QStringLiteral("valueencoded"), QStringLiteral("undefined"));
output.append(dict);
} else if (result.ptr && result.ptr->rawValue()) {
collector.collect(&output, QString(), name, *result);
} else {
QJsonObject dict;
- dict[QStringLiteral("name")] = name;
- dict[QStringLiteral("valueencoded")] = QStringLiteral("notaccessible");
+ dict.insert(QStringLiteral("name"), name);
+ dict.insert(QStringLiteral("valueencoded"), QStringLiteral("notaccessible"));
output.append(dict);
}
TRACE_PROTOCOL("EXCEPTION: " << engine->hasException);
@@ -742,7 +742,8 @@ void QQmlNativeDebugServiceImpl::engineAboutToBeRemoved(QJSEngine *engine)
TRACE_PROTOCOL("Removing engine" << engine);
if (engine) {
QV4::ExecutionEngine *executionEngine = QV8Engine::getV4(engine->handle());
- foreach (NativeDebugger *debugger, m_debuggers) {
+ const auto debuggersCopy = m_debuggers;
+ for (NativeDebugger *debugger : debuggersCopy) {
if (debugger->engine() == executionEngine)
m_debuggers.removeAll(debugger);
}
@@ -753,7 +754,7 @@ void QQmlNativeDebugServiceImpl::engineAboutToBeRemoved(QJSEngine *engine)
void QQmlNativeDebugServiceImpl::stateAboutToBeChanged(QQmlDebugService::State state)
{
if (state == Enabled) {
- foreach (NativeDebugger *debugger, m_debuggers) {
+ for (NativeDebugger *debugger : qAsConst(m_debuggers)) {
QV4::ExecutionEngine *engine = debugger->engine();
if (!engine->debugger())
engine->setDebugger(debugger);
@@ -777,7 +778,7 @@ void QQmlNativeDebugServiceImpl::messageReceived(const QByteArray &message)
} else if (cmd == QLatin1String("echo")) {
response.insert(QStringLiteral("result"), arguments);
} else {
- foreach (NativeDebugger *debugger, m_debuggers)
+ for (NativeDebugger *debugger : qAsConst(m_debuggers))
if (debugger)
debugger->handleCommand(&response, cmd, arguments);
}
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qqmlnativedebugservice.h b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.h
index 8015513f9e..58bf1bc94a 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qqmlnativedebugservice.h
+++ b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.h
@@ -67,7 +67,6 @@ QT_BEGIN_NAMESPACE
class NativeDebugger;
class BreakPointHandler;
-class QQmlDebuggerServiceFactory;
class QQmlNativeDebugServiceImpl : public QQmlNativeDebugService
{
@@ -86,7 +85,6 @@ public:
void emitAsynchronousMessageToClient(const QJsonObject &message);
private:
- friend class QQmlDebuggerServiceFactory;
friend class NativeDebugger;
QList<QPointer<NativeDebugger> > m_debuggers;
diff --git a/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.json b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.json
new file mode 100644
index 0000000000..2951166298
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "NativeQmlDebugger" ]
+}
diff --git a/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservicefactory.cpp b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservicefactory.cpp
new file mode 100644
index 0000000000..1841c82d5d
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservicefactory.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qqmlnativedebugservice.h"
+#include "qqmlnativedebugservicefactory.h"
+#include <private/qqmldebugserviceinterfaces_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QQmlDebugService *QQmlNativeDebugServiceFactory::create(const QString &key)
+{
+ if (key == QQmlNativeDebugServiceImpl::s_key)
+ return new QQmlNativeDebugServiceImpl(this);
+
+ return 0;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservicefactory.h b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservicefactory.h
new file mode 100644
index 0000000000..f2b2e4792e
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservicefactory.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQMLNATIVEDEBUGSERVICEFACTORY_H
+#define QQMLNATIVEDEBUGSERVICEFACTORY_H
+
+#include <private/qqmldebugservicefactory_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQmlNativeDebugServiceFactory : public QQmlDebugServiceFactory
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QQmlDebugServiceFactory_iid FILE "qqmlnativedebugservice.json")
+public:
+ QQmlDebugService *create(const QString &key) override;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQMLNATIVEDEBUGSERVICEFACTORY_H
diff --git a/src/plugins/qmltooling/qmldbg_profiler/qqmlenginecontrolservice.cpp b/src/plugins/qmltooling/qmldbg_profiler/qqmlenginecontrolservice.cpp
index 6b653d5a54..9918a95116 100644
--- a/src/plugins/qmltooling/qmldbg_profiler/qqmlenginecontrolservice.cpp
+++ b/src/plugins/qmltooling/qmldbg_profiler/qqmlenginecontrolservice.cpp
@@ -46,6 +46,7 @@ QT_BEGIN_NAMESPACE
QQmlEngineControlServiceImpl::QQmlEngineControlServiceImpl(QObject *parent) :
QQmlEngineControlService(1, parent)
{
+ blockingMode = QQmlDebugConnector::instance()->blockingMode();
}
void QQmlEngineControlServiceImpl::messageReceived(const QByteArray &message)
@@ -68,7 +69,7 @@ void QQmlEngineControlServiceImpl::messageReceived(const QByteArray &message)
void QQmlEngineControlServiceImpl::engineAboutToBeAdded(QJSEngine *engine)
{
QMutexLocker lock(&dataMutex);
- if (state() == Enabled) {
+ if (blockingMode && state() == Enabled) {
Q_ASSERT(!stoppingEngines.contains(engine));
Q_ASSERT(!startingEngines.contains(engine));
startingEngines.append(engine);
@@ -81,7 +82,7 @@ void QQmlEngineControlServiceImpl::engineAboutToBeAdded(QJSEngine *engine)
void QQmlEngineControlServiceImpl::engineAboutToBeRemoved(QJSEngine *engine)
{
QMutexLocker lock(&dataMutex);
- if (state() == Enabled) {
+ if (blockingMode && state() == Enabled) {
Q_ASSERT(!stoppingEngines.contains(engine));
Q_ASSERT(!startingEngines.contains(engine));
stoppingEngines.append(engine);
@@ -122,10 +123,10 @@ void QQmlEngineControlServiceImpl::stateChanged(State)
{
// We flush everything for any kind of state change, to avoid complicated timing issues.
QMutexLocker lock(&dataMutex);
- foreach (QJSEngine *engine, startingEngines)
+ for (QJSEngine *engine : qAsConst(startingEngines))
emit attachedToEngine(engine);
startingEngines.clear();
- foreach (QJSEngine *engine, stoppingEngines)
+ for (QJSEngine *engine : qAsConst(stoppingEngines))
emit detachedFromEngine(engine);
stoppingEngines.clear();
}
diff --git a/src/plugins/qmltooling/qmldbg_profiler/qqmlenginecontrolservice.h b/src/plugins/qmltooling/qmldbg_profiler/qqmlenginecontrolservice.h
index 1138310820..6392944519 100644
--- a/src/plugins/qmltooling/qmldbg_profiler/qqmlenginecontrolservice.h
+++ b/src/plugins/qmltooling/qmldbg_profiler/qqmlenginecontrolservice.h
@@ -79,6 +79,7 @@ protected:
QMutex dataMutex;
QList<QJSEngine *> startingEngines;
QList<QJSEngine *> stoppingEngines;
+ bool blockingMode;
void messageReceived(const QByteArray &) Q_DECL_OVERRIDE;
void engineAboutToBeAdded(QJSEngine *) Q_DECL_OVERRIDE;
diff --git a/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp b/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp
index dba2fd3cc3..c1f6f93ef1 100644
--- a/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp
+++ b/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp
@@ -51,6 +51,8 @@
#include <QtCore/qthread.h>
#include <QtCore/qcoreapplication.h>
+#include <algorithm>
+
QT_BEGIN_NAMESPACE
Q_QML_DEBUG_PLUGIN_LOADER(QQmlAbstractProfilerAdapter)
@@ -92,16 +94,18 @@ void QQmlProfilerServiceImpl::dataReady(QQmlAbstractProfilerAdapter *profiler)
m_startTimes.insert(0, profiler);
if (dataComplete) {
QList<QJSEngine *> enginesToRelease;
- foreach (QJSEngine *engine, m_stoppingEngines) {
- foreach (QQmlAbstractProfilerAdapter *engineProfiler, m_engineProfilers.values(engine)) {
- if (m_startTimes.values().contains(engineProfiler)) {
+ for (QJSEngine *engine : qAsConst(m_stoppingEngines)) {
+ const auto range = qAsConst(m_engineProfilers).equal_range(engine);
+ const auto startTimesEnd = m_startTimes.cend();
+ for (auto it = range.first; it != range.second; ++it) {
+ if (std::find(m_startTimes.cbegin(), startTimesEnd, *it) != startTimesEnd) {
enginesToRelease.append(engine);
break;
}
}
}
sendMessages();
- foreach (QJSEngine *engine, enginesToRelease) {
+ for (QJSEngine *engine : qAsConst(enginesToRelease)) {
m_stoppingEngines.removeOne(engine);
emit detachedFromEngine(engine);
}
@@ -130,8 +134,9 @@ void QQmlProfilerServiceImpl::engineAdded(QJSEngine *engine)
"QML profilers have to be added from the engine thread");
QMutexLocker lock(&m_configMutex);
- foreach (QQmlAbstractProfilerAdapter *profiler, m_engineProfilers.values(engine))
- profiler->stopWaiting();
+ const auto range = qAsConst(m_engineProfilers).equal_range(engine);
+ for (auto it = range.first; it != range.second; ++it)
+ (*it)->stopWaiting();
}
void QQmlProfilerServiceImpl::engineAboutToBeRemoved(QJSEngine *engine)
@@ -141,7 +146,9 @@ void QQmlProfilerServiceImpl::engineAboutToBeRemoved(QJSEngine *engine)
QMutexLocker lock(&m_configMutex);
bool isRunning = false;
- foreach (QQmlAbstractProfilerAdapter *profiler, m_engineProfilers.values(engine)) {
+ const auto range = qAsConst(m_engineProfilers).equal_range(engine);
+ for (auto it = range.first; it != range.second; ++it) {
+ QQmlAbstractProfilerAdapter *profiler = *it;
if (profiler->isRunning())
isRunning = true;
profiler->startWaiting();
@@ -160,7 +167,9 @@ void QQmlProfilerServiceImpl::engineRemoved(QJSEngine *engine)
"QML profilers have to be removed from the engine thread");
QMutexLocker lock(&m_configMutex);
- foreach (QQmlAbstractProfilerAdapter *profiler, m_engineProfilers.values(engine)) {
+ const auto range = qAsConst(m_engineProfilers).equal_range(engine);
+ for (auto it = range.first; it != range.second; ++it) {
+ QQmlAbstractProfilerAdapter *profiler = *it;
removeProfilerFromStartTimes(profiler);
delete profiler;
}
@@ -183,7 +192,7 @@ void QQmlProfilerServiceImpl::addGlobalProfiler(QQmlAbstractProfilerAdapter *pro
// Global profilers are started whenever any engine profiler is started and stopped when
// all engine profilers are stopped.
quint64 features = 0;
- foreach (QQmlAbstractProfilerAdapter *engineProfiler, m_engineProfilers)
+ for (QQmlAbstractProfilerAdapter *engineProfiler : qAsConst(m_engineProfilers))
features |= engineProfiler->features();
if (features != 0)
@@ -231,7 +240,9 @@ void QQmlProfilerServiceImpl::startProfiling(QJSEngine *engine, quint64 features
d << m_timer.nsecsElapsed() << (int)Event << (int)StartTrace;
bool startedAny = false;
if (engine != 0) {
- foreach (QQmlAbstractProfilerAdapter *profiler, m_engineProfilers.values(engine)) {
+ const auto range = qAsConst(m_engineProfilers).equal_range(engine);
+ for (auto it = range.first; it != range.second; ++it) {
+ QQmlAbstractProfilerAdapter *profiler = *it;
if (!profiler->isRunning()) {
profiler->startProfiling(features);
startedAny = true;
@@ -249,12 +260,12 @@ void QQmlProfilerServiceImpl::startProfiling(QJSEngine *engine, quint64 features
startedAny = true;
}
}
- foreach (QJSEngine *profiledEngine, engines)
+ for (QJSEngine *profiledEngine : qAsConst(engines))
d << idForObject(profiledEngine);
}
if (startedAny) {
- foreach (QQmlAbstractProfilerAdapter *profiler, m_globalProfilers) {
+ for (QQmlAbstractProfilerAdapter *profiler : qAsConst(m_globalProfilers)) {
if (!profiler->isRunning())
profiler->startProfiling(features);
}
@@ -294,7 +305,7 @@ void QQmlProfilerServiceImpl::stopProfiling(QJSEngine *engine)
if (stopping.isEmpty())
return;
- foreach (QQmlAbstractProfilerAdapter *profiler, m_globalProfilers) {
+ for (QQmlAbstractProfilerAdapter *profiler : qAsConst(m_globalProfilers)) {
if (!profiler->isRunning())
continue;
m_startTimes.insert(-1, profiler);
@@ -308,10 +319,10 @@ void QQmlProfilerServiceImpl::stopProfiling(QJSEngine *engine)
emit stopFlushTimer();
m_waitingForStop = true;
- foreach (QQmlAbstractProfilerAdapter *profiler, reporting)
+ for (QQmlAbstractProfilerAdapter *profiler : qAsConst(reporting))
profiler->reportData(m_useMessageTypes);
- foreach (QQmlAbstractProfilerAdapter *profiler, stopping)
+ for (QQmlAbstractProfilerAdapter *profiler : qAsConst(stopping))
profiler->stopProfiling();
}
@@ -327,7 +338,7 @@ void QQmlProfilerServiceImpl::sendMessages()
traceEnd << m_timer.nsecsElapsed() << (int)Event << (int)EndTrace;
QSet<QJSEngine *> seen;
- foreach (QQmlAbstractProfilerAdapter *profiler, m_startTimes) {
+ for (QQmlAbstractProfilerAdapter *profiler : qAsConst(m_startTimes)) {
for (QMultiHash<QJSEngine *, QQmlAbstractProfilerAdapter *>::iterator i(m_engineProfilers.begin());
i != m_engineProfilers.end(); ++i) {
if (i.value() == profiler && !seen.contains(i.key())) {
@@ -367,7 +378,7 @@ void QQmlProfilerServiceImpl::sendMessages()
emit messagesToClient(name(), messages);
// Restart flushing if any profilers are still running
- foreach (const QQmlAbstractProfilerAdapter *profiler, m_engineProfilers) {
+ for (const QQmlAbstractProfilerAdapter *profiler : qAsConst(m_engineProfilers)) {
if (profiler->isRunning()) {
emit startFlushTimer();
break;
@@ -438,21 +449,21 @@ void QQmlProfilerServiceImpl::flush()
QMutexLocker lock(&m_configMutex);
QList<QQmlAbstractProfilerAdapter *> reporting;
- foreach (QQmlAbstractProfilerAdapter *profiler, m_engineProfilers) {
+ for (QQmlAbstractProfilerAdapter *profiler : qAsConst(m_engineProfilers)) {
if (profiler->isRunning()) {
m_startTimes.insert(-1, profiler);
reporting.append(profiler);
}
}
- foreach (QQmlAbstractProfilerAdapter *profiler, m_globalProfilers) {
+ for (QQmlAbstractProfilerAdapter *profiler : qAsConst(m_globalProfilers)) {
if (profiler->isRunning()) {
m_startTimes.insert(-1, profiler);
reporting.append(profiler);
}
}
- foreach (QQmlAbstractProfilerAdapter *profiler, reporting)
+ for (QQmlAbstractProfilerAdapter *profiler : qAsConst(reporting))
profiler->reportData(m_useMessageTypes);
}
diff --git a/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservicefactory.h b/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservicefactory.h
index 772e53bde7..cdce4cd240 100644
--- a/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservicefactory.h
+++ b/src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservicefactory.h
@@ -60,7 +60,7 @@ class QQmlProfilerServiceFactory : public QQmlDebugServiceFactory
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlDebugServiceFactory_iid FILE "qqmlprofilerservice.json")
public:
- QQmlDebugService *create(const QString &key);
+ QQmlDebugService *create(const QString &key) override;
};
QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_quickprofiler/qquickprofileradapterfactory.h b/src/plugins/qmltooling/qmldbg_quickprofiler/qquickprofileradapterfactory.h
index 489545b504..41b9875c03 100644
--- a/src/plugins/qmltooling/qmldbg_quickprofiler/qquickprofileradapterfactory.h
+++ b/src/plugins/qmltooling/qmldbg_quickprofiler/qquickprofileradapterfactory.h
@@ -61,7 +61,7 @@ class QQuickProfilerAdapterFactory : public QQmlAbstractProfilerAdapterFactory
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlAbstractProfilerAdapterFactory_iid FILE "qquickprofileradapter.json")
public:
- QQmlAbstractProfilerAdapter *create(const QString &key);
+ QQmlAbstractProfilerAdapter *create(const QString &key) override;
};
QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp b/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp
index 96b3455790..f6f48e43a4 100644
--- a/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp
+++ b/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp
@@ -346,7 +346,7 @@ void QQmlDebugServerImpl::parseArguments()
QString fileName;
QStringList services;
- const auto lstjsDebugArguments = args.splitRef(QLatin1Char(','));
+ const auto lstjsDebugArguments = args.splitRef(QLatin1Char(','), QString::SkipEmptyParts);
for (auto argsIt = lstjsDebugArguments.begin(), argsItEnd = lstjsDebugArguments.end(); argsIt != argsItEnd; ++argsIt) {
const QStringRef &strArgument = *argsIt;
if (strArgument.startsWith(QLatin1String("port:"))) {
@@ -377,7 +377,7 @@ void QQmlDebugServerImpl::parseArguments()
services.append(strArgument.mid(9).toString());
} else if (!services.isEmpty()) {
services.append(strArgument.toString());
- } else {
+ } else if (!strArgument.startsWith(QLatin1String("connector:"))) {
const QString message = tr("QML Debugger: Invalid argument \"%1\" detected."
" Ignoring the same.").arg(strArgument.toString());
qWarning("%s", qPrintable(message));
@@ -589,12 +589,12 @@ void QQmlDebugServerImpl::addEngine(QJSEngine *engine)
QMutexLocker locker(&m_helloMutex);
Q_ASSERT(!m_engineConditions.contains(engine));
- foreach (QQmlDebugService *service, m_plugins)
+ for (QQmlDebugService *service : qAsConst(m_plugins))
service->engineAboutToBeAdded(engine);
m_engineConditions[engine].waitForServices(&m_helloMutex, m_plugins.count());
- foreach (QQmlDebugService *service, m_plugins)
+ for (QQmlDebugService *service : qAsConst(m_plugins))
service->engineAdded(engine);
}
@@ -606,12 +606,12 @@ void QQmlDebugServerImpl::removeEngine(QJSEngine *engine)
QMutexLocker locker(&m_helloMutex);
Q_ASSERT(m_engineConditions.contains(engine));
- foreach (QQmlDebugService *service, m_plugins)
+ for (QQmlDebugService *service : qAsConst(m_plugins))
service->engineAboutToBeRemoved(engine);
m_engineConditions[engine].waitForServices(&m_helloMutex, m_plugins.count());
- foreach (QQmlDebugService *service, m_plugins)
+ for (QQmlDebugService *service : qAsConst(m_plugins))
service->engineRemoved(engine);
m_engineConditions.remove(engine);
@@ -703,11 +703,11 @@ void QQmlDebugServerImpl::sendMessages(const QString &name, const QList<QByteArr
if (m_clientSupportsMultiPackets) {
QQmlDebugPacket out;
out << name;
- foreach (const QByteArray &message, messages)
+ for (const QByteArray &message : messages)
out << message;
m_protocol->send(out.data());
} else {
- foreach (const QByteArray &message, messages)
+ for (const QByteArray &message : messages)
doSendMessage(name, message);
}
m_connection->flush();
diff --git a/src/plugins/qmltooling/qmldbg_server/qqmldebugserverfactory.h b/src/plugins/qmltooling/qmldbg_server/qqmldebugserverfactory.h
index fd71b03019..2debabaeb2 100644
--- a/src/plugins/qmltooling/qmldbg_server/qqmldebugserverfactory.h
+++ b/src/plugins/qmltooling/qmldbg_server/qqmldebugserverfactory.h
@@ -63,7 +63,7 @@ class QQmlDebugServerFactory : public QQmlDebugConnectorFactory
// QQmlDebugServer is for connection plugins.
Q_PLUGIN_METADATA(IID QQmlDebugConnectorFactory_iid FILE "qqmldebugserver.json")
public:
- QQmlDebugConnector *create(const QString &key);
+ QQmlDebugConnector *create(const QString &key) override;
};
QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnectionfactory.h b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnectionfactory.h
index 52d9f4b709..d3b0e00584 100644
--- a/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnectionfactory.h
+++ b/src/plugins/qmltooling/qmldbg_tcp/qtcpserverconnectionfactory.h
@@ -50,7 +50,7 @@ class QTcpServerConnectionFactory : public QQmlDebugServerConnectionFactory
Q_PLUGIN_METADATA(IID QQmlDebugServerConnectionFactory_iid FILE "qtcpserverconnection.json")
Q_INTERFACES(QQmlDebugServerConnectionFactory)
public:
- QQmlDebugServerConnection *create(const QString &key);
+ QQmlDebugServerConnection *create(const QString &key) override;
};
QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmltooling.pro b/src/plugins/qmltooling/qmltooling.pro
index 907fbe9273..8123e2999e 100644
--- a/src/plugins/qmltooling/qmltooling.pro
+++ b/src/plugins/qmltooling/qmltooling.pro
@@ -19,12 +19,16 @@ qtConfig(qml-network) {
# Services
SUBDIRS += \
qmldbg_debugger \
- qmldbg_profiler
+ qmldbg_profiler \
+ qmldbg_messages \
+ qmldbg_nativedebugger
qmldbg_server.depends = packetprotocol
qmldbg_native.depends = packetprotocol
qmldbg_debugger.depends = packetprotocol
qmldbg_profiler.depends = packetprotocol
+qmldbg_messages.depends = packetprotocol
+qmldbg_nativedebugger.depends = packetprotocol
qtHaveModule(quick) {
SUBDIRS += \
diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12threadedrenderloop.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12threadedrenderloop.cpp
index 317471eeec..11cc257103 100644
--- a/src/plugins/scenegraph/d3d12/qsgd3d12threadedrenderloop.cpp
+++ b/src/plugins/scenegraph/d3d12/qsgd3d12threadedrenderloop.cpp
@@ -773,6 +773,11 @@ void QSGD3D12ThreadedRenderLoop::windowDestroyed(QQuickWindow *window)
break;
}
}
+
+ // Now that we altered the window list, we may need to stop the animation
+ // timer even if we didn't via handleObscurity. This covers the case where
+ // we destroy a visible & exposed QQuickWindow.
+ startOrStopAnimationTimer();
}
void QSGD3D12ThreadedRenderLoop::exposureChanged(QQuickWindow *window)
diff --git a/src/plugins/scenegraph/openvg/openvg.json b/src/plugins/scenegraph/openvg/openvg.json
new file mode 100644
index 0000000000..224afbf784
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/openvg.json
@@ -0,0 +1,3 @@
+{
+ "Keys": ["openvg"]
+}
diff --git a/src/plugins/scenegraph/openvg/openvg.pro b/src/plugins/scenegraph/openvg/openvg.pro
new file mode 100644
index 0000000000..6d5b190b37
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/openvg.pro
@@ -0,0 +1,57 @@
+TARGET = qsgopenvgbackend
+
+QT += gui-private core-private qml-private quick-private
+
+PLUGIN_TYPE = scenegraph
+PLUGIN_CLASS_NAME = QSGOpenVGAdaptation
+load(qt_plugin)
+
+QMAKE_TARGET_PRODUCT = "Qt Quick OpenVG Renderer (Qt $$QT_VERSION)"
+QMAKE_TARGET_DESCRIPTION = "Quick OpenVG Renderer for Qt."
+
+QMAKE_USE += openvg
+CONFIG += egl
+
+OTHER_FILES += $$PWD/openvg.json
+
+HEADERS += \
+ qsgopenvgadaptation_p.h \
+ qsgopenvgcontext_p.h \
+ qsgopenvgrenderloop_p.h \
+ qsgopenvgglyphnode_p.h \
+ qopenvgcontext_p.h \
+ qsgopenvgrenderer_p.h \
+ qsgopenvginternalrectanglenode.h \
+ qsgopenvgnodevisitor.h \
+ qopenvgmatrix.h \
+ qsgopenvgpublicnodes.h \
+ qsgopenvginternalimagenode.h \
+ qsgopenvgtexture.h \
+ qsgopenvglayer.h \
+ qsgopenvghelpers.h \
+ qsgopenvgfontglyphcache.h \
+ qsgopenvgpainternode.h \
+ qsgopenvgspritenode.h \
+ qsgopenvgrenderable.h \
+ qopenvgoffscreensurface.h
+
+SOURCES += \
+ qsgopenvgadaptation.cpp \
+ qsgopenvgcontext.cpp \
+ qsgopenvgrenderloop.cpp \
+ qsgopenvgglyphnode.cpp \
+ qopenvgcontext.cpp \
+ qsgopenvgrenderer.cpp \
+ qsgopenvginternalrectanglenode.cpp \
+ qsgopenvgnodevisitor.cpp \
+ qopenvgmatrix.cpp \
+ qsgopenvgpublicnodes.cpp \
+ qsgopenvginternalimagenode.cpp \
+ qsgopenvgtexture.cpp \
+ qsgopenvglayer.cpp \
+ qsgopenvghelpers.cpp \
+ qsgopenvgfontglyphcache.cpp \
+ qsgopenvgpainternode.cpp \
+ qsgopenvgspritenode.cpp \
+ qsgopenvgrenderable.cpp \
+ qopenvgoffscreensurface.cpp
diff --git a/src/plugins/scenegraph/openvg/qopenvgcontext.cpp b/src/plugins/scenegraph/openvg/qopenvgcontext.cpp
new file mode 100644
index 0000000000..ea2c24afdb
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qopenvgcontext.cpp
@@ -0,0 +1,218 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qpa/qplatformnativeinterface.h>
+#include <QtGui/QGuiApplication>
+#include <QtCore/QVector>
+#include <QtCore/QDebug>
+
+#include "qopenvgcontext_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QOpenVGContext::QOpenVGContext(QWindow *window)
+ : m_window(window)
+{
+ QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
+ m_display = reinterpret_cast<EGLDisplay>(nativeInterface->nativeResourceForWindow("EglDisplay", window));
+ m_surface = reinterpret_cast<EGLSurface>(nativeInterface->nativeResourceForWindow("EglSurface", window));
+
+ if (m_display == 0)
+ qFatal("QOpenVGContext: failed to get EGLDisplay");
+ if (m_surface == 0)
+ qFatal("QOpenVGContext: failed to get EGLSurface");
+
+ EGLint configID = 0;
+ if (eglQuerySurface(m_display, m_surface, EGL_CONFIG_ID, &configID)) {
+ EGLint numConfigs;
+ const EGLint configAttribs[] = {
+ EGL_CONFIG_ID, configID,
+ EGL_NONE
+ };
+ eglChooseConfig(m_display, configAttribs, &m_config, 1, &numConfigs);
+ } else {
+ qFatal("QOpenVGContext: failed to get surface config");
+ }
+
+ // Create an EGL Context
+ eglBindAPI(EGL_OPENVG_API);
+ m_context = eglCreateContext(m_display, m_config, EGL_NO_CONTEXT, 0);
+ if (!m_context)
+ qFatal("QOpenVGContext: eglCreateContext failed");
+}
+
+QOpenVGContext::~QOpenVGContext()
+{
+ doneCurrent();
+ eglDestroyContext(m_display, m_context);
+}
+
+void QOpenVGContext::makeCurrent()
+{
+ makeCurrent(m_surface);
+}
+
+void QOpenVGContext::makeCurrent(EGLSurface surface)
+{
+ eglMakeCurrent(m_display, surface, surface, m_context);
+}
+
+void QOpenVGContext::doneCurrent()
+{
+ eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+}
+
+void QOpenVGContext::swapBuffers()
+{
+ swapBuffers(m_surface);
+}
+
+void QOpenVGContext::swapBuffers(EGLSurface surface)
+{
+ eglSwapBuffers(m_display, surface);
+}
+
+QWindow *QOpenVGContext::window() const
+{
+ return m_window;
+}
+
+QImage QOpenVGContext::readFramebuffer(const QSize &size)
+{
+ QImage framebufferImage(size, QImage::Format_RGB32);
+ vgReadPixels(framebufferImage.bits(), framebufferImage.bytesPerLine(), VG_sXRGB_8888, 0, 0, size.width(), size.height());
+ return framebufferImage.mirrored(false, true);
+}
+
+void QOpenVGContext::getConfigs()
+{
+ EGLint configsAvailable = 0;
+ eglGetConfigs(m_display, 0, 0, &configsAvailable);
+
+ QVector<EGLConfig> configs(configsAvailable);
+ eglGetConfigs(m_display, configs.data(), configs.size(), &configsAvailable);
+
+ for (EGLConfig config : configs) {
+ EGLint value;
+ eglGetConfigAttrib(m_display, config, EGL_CONFIG_ID, &value);
+ qDebug() << "#################\n" << "EGL_CONFIG_ID:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_BUFFER_SIZE, &value);
+ qDebug() << "EGL_BUFFER_SIZE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_ALPHA_SIZE, &value);
+ qDebug() << "EGL_ALPHA_SIZE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_RED_SIZE, &value);
+ qDebug() << "EGL_RED_SIZE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_GREEN_SIZE, &value);
+ qDebug() << "EGL_GREEN_SIZE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_BLUE_SIZE, &value);
+ qDebug() << "EGL_BLUE_SIZE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_DEPTH_SIZE, &value);
+ qDebug() << "EGL_DEPTH_SIZE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_STENCIL_SIZE, &value);
+ qDebug() << "EGL_STENCIL_SIZE:" << value;
+
+ eglGetConfigAttrib(m_display, config, EGL_ALPHA_MASK_SIZE, &value);
+ qDebug() << "EGL_ALPHA_MASK_SIZE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_BIND_TO_TEXTURE_RGB, &value);
+ qDebug() << "EGL_BIND_TO_TEXTURE_RGB:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_BIND_TO_TEXTURE_RGBA, &value);
+ qDebug() << "EGL_BIND_TO_TEXTURE_RGBA:" << value;
+
+
+ eglGetConfigAttrib(m_display, config, EGL_COLOR_BUFFER_TYPE, &value);
+ qDebug() << "EGL_COLOR_BUFFER_TYPE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_CONFIG_CAVEAT, &value);
+ qDebug() << "EGL_CONFIG_CAVEAT:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_CONFORMANT, &value);
+ qDebug() << "EGL_CONFORMANT:" << value;
+
+
+ eglGetConfigAttrib(m_display, config, EGL_LEVEL, &value);
+ qDebug() << "EGL_LEVEL:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_LUMINANCE_SIZE, &value);
+ qDebug() << "EGL_LUMINANCE_SIZE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_MAX_PBUFFER_WIDTH, &value);
+ qDebug() << "EGL_MAX_PBUFFER_WIDTH:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_MAX_PBUFFER_HEIGHT, &value);
+ qDebug() << "EGL_MAX_PBUFFER_HEIGHT:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_MAX_PBUFFER_PIXELS, &value);
+ qDebug() << "EGL_MAX_PBUFFER_PIXELS:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_MAX_SWAP_INTERVAL, &value);
+ qDebug() << "EGL_MAX_SWAP_INTERVAL:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_MIN_SWAP_INTERVAL, &value);
+ qDebug() << "EGL_MIN_SWAP_INTERVAL:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_NATIVE_RENDERABLE, &value);
+ qDebug() << "EGL_NATIVE_RENDERABLE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &value);
+ qDebug() << "EGL_NATIVE_VISUAL_ID:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_TYPE, &value);
+ qDebug() << "EGL_NATIVE_VISUAL_TYPE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_RENDERABLE_TYPE, &value);
+ qDebug() << "EGL_RENDERABLE_TYPE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_SAMPLE_BUFFERS, &value);
+ qDebug() << "EGL_SAMPLE_BUFFERS:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_SAMPLES, &value);
+ qDebug() << "EGL_SAMPLES:" << value;
+
+ eglGetConfigAttrib(m_display, config, EGL_SURFACE_TYPE, &value);
+ qDebug() << "EGL_SURFACE_TYPE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_TRANSPARENT_TYPE, &value);
+ qDebug() << "EGL_TRANSPARENT_TYPE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_TRANSPARENT_RED_VALUE, &value);
+ qDebug() << "EGL_TRANSPARENT_RED_VALUE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_TRANSPARENT_GREEN_VALUE, &value);
+ qDebug() << "EGL_TRANSPARENT_GREEN_VALUE:" << value;
+ eglGetConfigAttrib(m_display, config, EGL_TRANSPARENT_BLUE_VALUE, &value);
+ qDebug() << "EGL_TRANSPARENT_BLUE_VALUE:" << value;
+ }
+}
+
+void QOpenVGContext::checkErrors()
+{
+ VGErrorCode error;
+ EGLint eglError;
+ do {
+ error = vgGetError();
+ eglError = eglGetError();
+ qDebug() << "error: " << QString::number(error, 16);
+ qDebug() << "eglError: " << QString::number(eglError, 16);
+ } while (error != VG_NO_ERROR && eglError != EGL_SUCCESS);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qopenvgcontext_p.h b/src/plugins/scenegraph/openvg/qopenvgcontext_p.h
new file mode 100644
index 0000000000..a1ba73957f
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qopenvgcontext_p.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QOPENVGCONTEXT_H
+#define QOPENVGCONTEXT_H
+
+#include <QtGui/QWindow>
+#include <QtGui/QImage>
+
+#include <EGL/egl.h>
+#include <VG/openvg.h>
+
+QT_BEGIN_NAMESPACE
+
+class QOpenVGContext
+{
+public:
+ QOpenVGContext(QWindow *window);
+ ~QOpenVGContext();
+
+ void makeCurrent();
+ void makeCurrent(EGLSurface surface);
+ void doneCurrent();
+ void swapBuffers();
+ void swapBuffers(EGLSurface surface);
+
+
+ QWindow *window() const;
+
+ EGLDisplay eglDisplay() { return m_display; }
+ EGLConfig eglConfig() { return m_config; }
+ EGLContext eglContext() { return m_context; }
+
+ QImage readFramebuffer(const QSize &size);
+
+ void getConfigs();
+
+ static void checkErrors();
+
+private:
+ EGLSurface m_surface;
+ EGLDisplay m_display;
+ EGLConfig m_config;
+ EGLContext m_context;
+
+ QWindow *m_window;
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QOPENVGCONTEXT_H
diff --git a/src/plugins/scenegraph/openvg/qopenvgmatrix.cpp b/src/plugins/scenegraph/openvg/qopenvgmatrix.cpp
new file mode 100644
index 0000000000..83ce96578e
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qopenvgmatrix.cpp
@@ -0,0 +1,378 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qopenvgmatrix.h"
+
+QT_BEGIN_NAMESPACE
+
+// QOpenVGMatrix: Because Qt will never have enough matrix classes
+// Internally the data is stored as column-major format
+// So this is a 3x3 version of QMatrix4x4 for optimal
+// OpenVG usage.
+
+QOpenVGMatrix::QOpenVGMatrix()
+{
+ setToIdentity();
+}
+
+QOpenVGMatrix::QOpenVGMatrix(const float *values)
+{
+ for (int col = 0; col < 3; ++col)
+ for (int row = 0; row < 3; ++row)
+ m[col][row] = values[col * 3 + row];
+}
+
+const float &QOpenVGMatrix::operator()(int row, int column) const
+{
+ Q_ASSERT(row >= 0 && row < 4 && column >= 0 && column < 4);
+ return m[column][row];
+}
+
+float &QOpenVGMatrix::operator()(int row, int column)
+{
+ Q_ASSERT(row >= 0 && row < 4 && column >= 0 && column < 4);
+ return m[column][row];
+}
+
+bool QOpenVGMatrix::isIdentity() const
+{
+ if (m[0][0] != 1.0f || m[0][1] != 0.0f || m[0][2] != 0.0f)
+ return false;
+ if ( m[1][0] != 0.0f || m[1][1] != 1.0f)
+ return false;
+ if (m[1][2] != 0.0f || m[2][0] != 0.0f)
+ return false;
+ if (m[2][1] != 0.0f || m[2][2] != 1.0f)
+ return false;
+
+ return true;
+}
+
+void QOpenVGMatrix::setToIdentity()
+{
+ m[0][0] = 1.0f;
+ m[0][1] = 0.0f;
+ m[0][2] = 0.0f;
+ m[1][0] = 0.0f;
+ m[1][1] = 1.0f;
+ m[1][2] = 0.0f;
+ m[2][0] = 0.0f;
+ m[2][1] = 0.0f;
+ m[2][2] = 1.0f;
+}
+
+bool QOpenVGMatrix::isAffine() const
+{
+ if (m[0][2] == 0.0f && m[1][2] == 0.0f && m[2][2] == 1.0f)
+ return true;
+
+ return false;
+}
+
+QPointF QOpenVGMatrix::map(const QPointF &point) const
+{
+ return *this * point;
+}
+
+void QOpenVGMatrix::fill(float value)
+{
+ m[0][0] = value;
+ m[0][1] = value;
+ m[0][2] = value;
+ m[1][0] = value;
+ m[1][1] = value;
+ m[1][2] = value;
+ m[2][0] = value;
+ m[2][1] = value;
+ m[2][2] = value;
+}
+
+QOpenVGMatrix QOpenVGMatrix::transposed() const
+{
+ QOpenVGMatrix result;
+ for (int row = 0; row < 3; ++row) {
+ for (int col = 0; col < 3; ++col)
+ result.m[col][row] = m[row][col];
+ }
+ return result;
+}
+
+QOpenVGMatrix &QOpenVGMatrix::operator+=(const QOpenVGMatrix &other)
+{
+ m[0][0] += other.m[0][0];
+ m[0][1] += other.m[0][1];
+ m[0][2] += other.m[0][2];
+ m[1][0] += other.m[1][0];
+ m[1][1] += other.m[1][1];
+ m[1][2] += other.m[1][2];
+ m[2][0] += other.m[2][0];
+ m[2][1] += other.m[2][1];
+ m[2][2] += other.m[2][2];
+ return *this;
+}
+
+QOpenVGMatrix &QOpenVGMatrix::operator-=(const QOpenVGMatrix &other)
+{
+ m[0][0] -= other.m[0][0];
+ m[0][1] -= other.m[0][1];
+ m[0][2] -= other.m[0][2];
+ m[1][0] -= other.m[1][0];
+ m[1][1] -= other.m[1][1];
+ m[1][2] -= other.m[1][2];
+ m[2][0] -= other.m[2][0];
+ m[2][1] -= other.m[2][1];
+ m[2][2] -= other.m[2][2];
+ return *this;
+}
+
+QOpenVGMatrix &QOpenVGMatrix::operator*=(const QOpenVGMatrix &other)
+{
+ float m0, m1;
+ m0 = m[0][0] * other.m[0][0]
+ + m[1][0] * other.m[0][1]
+ + m[2][0] * other.m[0][2];
+ m1 = m[0][0] * other.m[1][0]
+ + m[1][0] * other.m[1][1]
+ + m[2][0] * other.m[1][2];
+ m[2][0] = m[0][0] * other.m[2][0]
+ + m[1][0] * other.m[2][1]
+ + m[2][0] * other.m[2][2];
+ m[0][0] = m0;
+ m[1][0] = m1;
+
+ m0 = m[0][1] * other.m[0][0]
+ + m[1][1] * other.m[0][1]
+ + m[2][1] * other.m[0][2];
+ m1 = m[0][1] * other.m[1][0]
+ + m[1][1] * other.m[1][1]
+ + m[2][1] * other.m[1][2];
+ m[2][1] = m[0][1] * other.m[2][0]
+ + m[1][1] * other.m[2][1]
+ + m[2][1] * other.m[2][2];
+ m[0][1] = m0;
+ m[1][1] = m1;
+
+ m0 = m[0][2] * other.m[0][0]
+ + m[1][2] * other.m[0][1]
+ + m[2][2] * other.m[0][2];
+ m1 = m[0][2] * other.m[1][0]
+ + m[1][2] * other.m[1][1]
+ + m[2][2] * other.m[1][2];
+ m[2][2] = m[0][2] * other.m[2][0]
+ + m[1][2] * other.m[2][1]
+ + m[2][2] * other.m[2][2];
+ m[0][2] = m0;
+ m[1][2] = m1;
+ return *this;
+}
+
+QOpenVGMatrix &QOpenVGMatrix::operator*=(float factor)
+{
+ m[0][0] *= factor;
+ m[0][1] *= factor;
+ m[0][2] *= factor;
+ m[1][0] *= factor;
+ m[1][1] *= factor;
+ m[1][2] *= factor;
+ m[2][0] *= factor;
+ m[2][1] *= factor;
+ m[2][2] *= factor;
+ return *this;
+}
+
+QOpenVGMatrix &QOpenVGMatrix::operator/=(float divisor)
+{
+ m[0][0] /= divisor;
+ m[0][1] /= divisor;
+ m[0][2] /= divisor;
+ m[1][0] /= divisor;
+ m[1][1] /= divisor;
+ m[1][2] /= divisor;
+ m[2][0] /= divisor;
+ m[2][1] /= divisor;
+ m[2][2] /= divisor;
+ return *this;
+}
+
+bool QOpenVGMatrix::operator==(const QOpenVGMatrix &other) const
+{
+ return m[0][0] == other.m[0][0] &&
+ m[0][1] == other.m[0][1] &&
+ m[0][2] == other.m[0][2] &&
+ m[1][0] == other.m[1][0] &&
+ m[1][1] == other.m[1][1] &&
+ m[1][2] == other.m[1][2] &&
+ m[2][0] == other.m[2][0] &&
+ m[2][1] == other.m[2][1] &&
+ m[2][2] == other.m[2][2];
+}
+
+bool QOpenVGMatrix::operator!=(const QOpenVGMatrix &other) const
+{
+ return m[0][0] != other.m[0][0] ||
+ m[0][1] != other.m[0][1] ||
+ m[0][2] != other.m[0][2] ||
+ m[1][0] != other.m[1][0] ||
+ m[1][1] != other.m[1][1] ||
+ m[1][2] != other.m[1][2] ||
+ m[2][0] != other.m[2][0] ||
+ m[2][1] != other.m[2][1] ||
+ m[2][2] != other.m[2][2];
+}
+
+void QOpenVGMatrix::copyDataTo(float *values) const
+{
+ // Row-Major?
+ for (int row = 0; row < 3; ++row) {
+ for (int col = 0; col < 3; ++col)
+ values[row * 3 + col] = float(m[col][row]);
+ }
+}
+
+QOpenVGMatrix operator*(const QOpenVGMatrix &m1, const QOpenVGMatrix &m2)
+{
+ QOpenVGMatrix matrix;
+ matrix.m[0][0] = m1.m[0][0] * m2.m[0][0]
+ + m1.m[1][0] * m2.m[0][1]
+ + m1.m[2][0] * m2.m[0][2];
+ matrix.m[0][1] = m1.m[0][1] * m2.m[0][0]
+ + m1.m[1][1] * m2.m[0][1]
+ + m1.m[2][1] * m2.m[0][2];
+ matrix.m[0][2] = m1.m[0][2] * m2.m[0][0]
+ + m1.m[1][2] * m2.m[0][1]
+ + m1.m[2][2] * m2.m[0][2];
+
+ matrix.m[1][0] = m1.m[0][0] * m2.m[1][0]
+ + m1.m[1][0] * m2.m[1][1]
+ + m1.m[2][0] * m2.m[1][2];
+ matrix.m[1][1] = m1.m[0][1] * m2.m[1][0]
+ + m1.m[1][1] * m2.m[1][1]
+ + m1.m[2][1] * m2.m[1][2];
+ matrix.m[1][2] = m1.m[0][2] * m2.m[1][0]
+ + m1.m[1][2] * m2.m[1][1]
+ + m1.m[2][2] * m2.m[1][2];
+
+ matrix.m[2][0] = m1.m[0][0] * m2.m[2][0]
+ + m1.m[1][0] * m2.m[2][1]
+ + m1.m[2][0] * m2.m[2][2];
+ matrix.m[2][1] = m1.m[0][1] * m2.m[2][0]
+ + m1.m[1][1] * m2.m[2][1]
+ + m1.m[2][1] * m2.m[2][2];
+ matrix.m[2][2] = m1.m[0][2] * m2.m[2][0]
+ + m1.m[1][2] * m2.m[2][1]
+ + m1.m[2][2] * m2.m[2][2];
+ return matrix;
+}
+
+QPointF operator*(const QPointF& point, const QOpenVGMatrix& matrix)
+{
+ float xin = point.x();
+ float yin = point.y();
+ float x = xin * matrix.m[0][0] +
+ yin * matrix.m[0][1] +
+ matrix.m[0][2];
+ float y = xin * matrix.m[1][0] +
+ yin * matrix.m[1][1] +
+ matrix.m[1][2];
+ float w = xin * matrix.m[2][0] +
+ yin * matrix.m[2][1] +
+ matrix.m[2][2];
+ if (w == 1.0f) {
+ return QPointF(float(x), float(y));
+ } else {
+ return QPointF(float(x / w), float(y / w));
+ }
+}
+
+QPointF operator*(const QOpenVGMatrix& matrix, const QPointF& point)
+{
+ float xin = point.x();
+ float yin = point.y();
+ float x = xin * matrix.m[0][0] +
+ yin * matrix.m[1][0] +
+ matrix.m[2][0];
+ float y = xin * matrix.m[0][1] +
+ yin * matrix.m[1][1] +
+ matrix.m[2][1];
+ float w = xin * matrix.m[0][2] +
+ yin * matrix.m[1][2] +
+ matrix.m[2][2];
+ if (w == 1.0f) {
+ return QPointF(float(x), float(y));
+ } else {
+ return QPointF(float(x / w), float(y / w));
+ }
+}
+
+QDebug operator<<(QDebug dbg, const QOpenVGMatrix &m)
+{
+ QDebugStateSaver saver(dbg);
+ // Output in row-major order because it is more human-readable.
+ dbg.nospace() << "QOpenVGMatrix:(" << endl
+ << qSetFieldWidth(10)
+ << m(0, 0) << m(0, 1) << m(0, 2) << endl
+ << m(1, 0) << m(1, 1) << m(1, 2) << endl
+ << m(2, 0) << m(2, 1) << m(2, 2) << endl
+ << qSetFieldWidth(0) << ')';
+ return dbg;
+}
+
+QDataStream &operator<<(QDataStream &stream, const QOpenVGMatrix &matrix)
+{
+ for (int row = 0; row < 3; ++row)
+ for (int col = 0; col < 3; ++col)
+ stream << matrix(row, col);
+ return stream;
+}
+
+
+QDataStream &operator>>(QDataStream &stream, QOpenVGMatrix &matrix)
+{
+ float x;
+ for (int row = 0; row < 4; ++row) {
+ for (int col = 0; col < 4; ++col) {
+ stream >> x;
+ matrix(row, col) = x;
+ }
+ }
+ return stream;
+}
+
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qopenvgmatrix.h b/src/plugins/scenegraph/openvg/qopenvgmatrix.h
new file mode 100644
index 0000000000..f51bf8147d
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qopenvgmatrix.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QOPENVGMATRIX_H
+#define QOPENVGMATRIX_H
+
+#include <QtCore/qdebug.h>
+#include <QtCore/QDataStream>
+#include <QtCore/QPointF>
+
+QT_BEGIN_NAMESPACE
+
+class QOpenVGMatrix
+{
+public:
+ QOpenVGMatrix();
+ explicit QOpenVGMatrix(const float *values);
+
+ const float& operator()(int row, int column) const;
+ float& operator()(int row, int column);
+
+ bool isIdentity() const;
+ void setToIdentity();
+
+ bool isAffine() const;
+
+ QPointF map(const QPointF& point) const;
+
+ void fill(float value);
+
+ QOpenVGMatrix transposed() const;
+
+ QOpenVGMatrix& operator+=(const QOpenVGMatrix& other);
+ QOpenVGMatrix& operator-=(const QOpenVGMatrix& other);
+ QOpenVGMatrix& operator*=(const QOpenVGMatrix& other);
+ QOpenVGMatrix& operator*=(float factor);
+ QOpenVGMatrix& operator/=(float divisor);
+ friend QOpenVGMatrix operator*(const QOpenVGMatrix& m1, const QOpenVGMatrix& m2);
+ friend QPointF operator*(const QPointF& point, const QOpenVGMatrix& matrix);
+ friend QPointF operator*(const QOpenVGMatrix& matrix, const QPointF& point);
+#ifndef QT_NO_DEBUG_STREAM
+ friend QDebug operator<<(QDebug dbg, const QOpenVGMatrix &m);
+#endif
+ bool operator==(const QOpenVGMatrix& other) const;
+ bool operator!=(const QOpenVGMatrix& other) const;
+
+ void copyDataTo(float *values) const;
+
+ float *data() { return *m; }
+ const float *data() const { return *m; }
+ const float *constData() const { return *m; }
+
+private:
+ float m[3][3];
+};
+
+QOpenVGMatrix operator*(const QOpenVGMatrix& m1, const QOpenVGMatrix& m2);
+QPointF operator*(const QPointF& point, const QOpenVGMatrix& matrix);
+QPointF operator*(const QOpenVGMatrix& matrix, const QPointF& point);
+
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug dbg, const QOpenVGMatrix &m);
+#endif
+
+#ifndef QT_NO_DATASTREAM
+QDataStream &operator<<(QDataStream &, const QOpenVGMatrix &);
+QDataStream &operator>>(QDataStream &, QOpenVGMatrix &);
+#endif
+
+QT_END_NAMESPACE
+
+#endif // QOPENVGMATRIX_H
diff --git a/src/plugins/scenegraph/openvg/qopenvgoffscreensurface.cpp b/src/plugins/scenegraph/openvg/qopenvgoffscreensurface.cpp
new file mode 100644
index 0000000000..1f2709e06c
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qopenvgoffscreensurface.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDebug>
+#include "qopenvgoffscreensurface.h"
+
+#include <QtGui/QImage>
+
+
+QT_BEGIN_NAMESPACE
+
+QOpenVGOffscreenSurface::QOpenVGOffscreenSurface(const QSize &size)
+ : m_size(size)
+{
+ m_display = eglGetCurrentDisplay();
+ m_image = vgCreateImage(VG_sARGB_8888_PRE, m_size.width(), m_size.height(), VG_IMAGE_QUALITY_BETTER);
+
+ const EGLint configAttribs[] = {
+ EGL_CONFORMANT, EGL_OPENVG_BIT,
+ EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_ALPHA_SIZE, 8,
+ EGL_ALPHA_MASK_SIZE, 8,
+ EGL_NONE
+ };
+
+ EGLConfig pbufferConfig;
+ EGLint numConfig;
+ eglChooseConfig(m_display, configAttribs, &pbufferConfig, 1, &numConfig);
+
+ m_context = eglCreateContext(m_display, pbufferConfig, eglGetCurrentContext(), 0);
+ if (m_context == EGL_NO_CONTEXT)
+ qWarning("QOpenVGOffscreenSurface: failed to create EGLContext");
+
+ m_renderTarget = eglCreatePbufferFromClientBuffer(m_display,
+ EGL_OPENVG_IMAGE,
+ reinterpret_cast<EGLClientBuffer>(uintptr_t(m_image)),
+ pbufferConfig,
+ 0);
+ if (m_renderTarget == EGL_NO_SURFACE)
+ qWarning("QOpenVGOffscreenSurface: failed to create EGLSurface from VGImage");
+}
+
+QOpenVGOffscreenSurface::~QOpenVGOffscreenSurface()
+{
+ vgDestroyImage(m_image);
+ eglDestroySurface(m_display, m_renderTarget);
+ eglDestroyContext(m_display, m_context);
+}
+
+void QOpenVGOffscreenSurface::makeCurrent()
+{
+ EGLContext currentContext = eglGetCurrentContext();
+ if (m_context != currentContext) {
+ m_previousContext = eglGetCurrentContext();
+ m_previousReadSurface = eglGetCurrentSurface(EGL_READ);
+ m_previousDrawSurface = eglGetCurrentSurface(EGL_DRAW);
+
+ eglMakeCurrent(m_display, m_renderTarget, m_renderTarget, m_context);
+ }
+}
+
+void QOpenVGOffscreenSurface::doneCurrent()
+{
+ EGLContext currentContext = eglGetCurrentContext();
+ if (m_context == currentContext) {
+ eglMakeCurrent(m_display, m_previousDrawSurface, m_previousReadSurface, m_previousContext);
+ m_previousContext = EGL_NO_CONTEXT;
+ m_previousReadSurface = EGL_NO_SURFACE;
+ m_previousDrawSurface = EGL_NO_SURFACE;
+ }
+}
+
+void QOpenVGOffscreenSurface::swapBuffers()
+{
+ eglSwapBuffers(m_display, m_renderTarget);
+}
+
+QImage QOpenVGOffscreenSurface::readbackQImage()
+{
+ QImage readbackImage(m_size, QImage::Format_ARGB32_Premultiplied);
+ vgGetImageSubData(m_image, readbackImage.bits(), readbackImage.bytesPerLine(), VG_sARGB_8888_PRE, 0, 0, m_size.width(), m_size.height());
+ return readbackImage;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qopenvgoffscreensurface.h b/src/plugins/scenegraph/openvg/qopenvgoffscreensurface.h
new file mode 100644
index 0000000000..746e4de1cd
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qopenvgoffscreensurface.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QOPENVGOFFSCREENSURFACE_H
+#define QOPENVGOFFSCREENSURFACE_H
+
+#include "qopenvgcontext_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QOpenVGOffscreenSurface
+{
+public:
+ QOpenVGOffscreenSurface(const QSize &size);
+ ~QOpenVGOffscreenSurface();
+
+ void makeCurrent();
+ void doneCurrent();
+ void swapBuffers();
+
+ VGImage image() { return m_image; }
+ QSize size() const { return m_size; }
+
+ QImage readbackQImage();
+
+private:
+ VGImage m_image;
+ QSize m_size;
+ EGLContext m_context;
+ EGLSurface m_renderTarget;
+ EGLContext m_previousContext = EGL_NO_CONTEXT;
+ EGLSurface m_previousReadSurface = EGL_NO_SURFACE;
+ EGLSurface m_previousDrawSurface = EGL_NO_SURFACE;
+ EGLDisplay m_display;
+};
+
+QT_END_NAMESPACE
+
+#endif // QOPENVGOFFSCREENSURFACE_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgadaptation.cpp b/src/plugins/scenegraph/openvg/qsgopenvgadaptation.cpp
new file mode 100644
index 0000000000..1a26522459
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgadaptation.cpp
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvgadaptation_p.h"
+
+#include "qsgopenvgcontext_p.h"
+#include "qsgopenvgrenderloop_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGAdaptation::QSGOpenVGAdaptation(QObject *parent)
+ : QSGContextPlugin(parent)
+{
+}
+
+QStringList QSGOpenVGAdaptation::keys() const
+{
+ return QStringList() << QLatin1String("openvg");
+}
+
+QSGContext *QSGOpenVGAdaptation::create(const QString &key) const
+{
+ Q_UNUSED(key)
+ if (!instance)
+ instance = new QSGOpenVGContext();
+ return instance;
+}
+
+QSGRenderLoop *QSGOpenVGAdaptation::createWindowManager()
+{
+ return new QSGOpenVGRenderLoop();
+}
+
+QSGContextFactoryInterface::Flags QSGOpenVGAdaptation::flags(const QString &key) const
+{
+ Q_UNUSED(key)
+ return 0;
+}
+
+QSGOpenVGContext *QSGOpenVGAdaptation::instance = nullptr;
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgadaptation_p.h b/src/plugins/scenegraph/openvg/qsgopenvgadaptation_p.h
new file mode 100644
index 0000000000..77f79af9ac
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgadaptation_p.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGADAPTATION_H
+#define QSGOPENVGADAPTATION_H
+
+#include <private/qsgcontextplugin_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGContext;
+class QSGRenderLoop;
+class QSGOpenVGContext;
+
+class QSGOpenVGAdaptation : public QSGContextPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSGContextFactoryInterface" FILE "openvg.json")
+public:
+ QSGOpenVGAdaptation(QObject *parent = nullptr);
+
+ QStringList keys() const override;
+ QSGContext *create(const QString &key) const override;
+ QSGRenderLoop *createWindowManager() override;
+ Flags flags(const QString &key) const override;
+private:
+ static QSGOpenVGContext *instance;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGADAPTATION_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgcontext.cpp b/src/plugins/scenegraph/openvg/qsgopenvgcontext.cpp
new file mode 100644
index 0000000000..41fce7c7fc
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgcontext.cpp
@@ -0,0 +1,219 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvgcontext_p.h"
+#include "qsgopenvgrenderer_p.h"
+#include "qsgopenvgpublicnodes.h"
+#include "qsgopenvgtexture.h"
+#include "qsgopenvglayer.h"
+#include "qsgopenvgglyphnode_p.h"
+#include "qsgopenvgfontglyphcache.h"
+#include "qsgopenvgpainternode.h"
+#include "qsgopenvgspritenode.h"
+
+#include "qopenvgcontext_p.h"
+
+#include <private/qsgrenderer_p.h>
+#include "qsgopenvginternalrectanglenode.h"
+#include "qsgopenvginternalimagenode.h"
+
+// polish, animations, sync, render and swap in the render loop
+Q_LOGGING_CATEGORY(QSG_OPENVG_LOG_TIME_RENDERLOOP, "qt.scenegraph.time.renderloop")
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGRenderContext::QSGOpenVGRenderContext(QSGContext *context)
+ : QSGRenderContext(context)
+ , m_vgContext(nullptr)
+ , m_glyphCacheManager(nullptr)
+{
+
+}
+
+void QSGOpenVGRenderContext::initialize(void *context)
+{
+ m_vgContext = static_cast<QOpenVGContext*>(context);
+ QSGRenderContext::initialize(context);
+}
+
+void QSGOpenVGRenderContext::invalidate()
+{
+ m_vgContext = nullptr;
+ delete m_glyphCacheManager;
+ m_glyphCacheManager = nullptr;
+ QSGRenderContext::invalidate();
+}
+
+void QSGOpenVGRenderContext::renderNextFrame(QSGRenderer *renderer, uint fboId)
+{
+ renderer->renderScene(fboId);
+}
+
+QSGTexture *QSGOpenVGRenderContext::createTexture(const QImage &image, uint flags) const
+{
+ QImage tmp = image;
+
+ // Make sure image is not larger than maxTextureSize
+ int maxSize = maxTextureSize();
+ if (tmp.width() > maxSize || tmp.height() > maxSize) {
+ tmp = tmp.scaled(qMin(maxSize, tmp.width()), qMin(maxSize, tmp.height()), Qt::IgnoreAspectRatio, Qt::FastTransformation);
+ }
+
+ return new QSGOpenVGTexture(tmp, flags);
+}
+
+QSGRenderer *QSGOpenVGRenderContext::createRenderer()
+{
+ return new QSGOpenVGRenderer(this);
+}
+
+QSGOpenVGContext::QSGOpenVGContext(QObject *parent)
+{
+ Q_UNUSED(parent)
+}
+
+QSGRenderContext *QSGOpenVGContext::createRenderContext()
+{
+ return new QSGOpenVGRenderContext(this);
+}
+
+QSGRectangleNode *QSGOpenVGContext::createRectangleNode()
+{
+ return new QSGOpenVGRectangleNode;
+}
+
+QSGImageNode *QSGOpenVGContext::createImageNode()
+{
+ return new QSGOpenVGImageNode;
+}
+
+QSGPainterNode *QSGOpenVGContext::createPainterNode(QQuickPaintedItem *item)
+{
+ Q_UNUSED(item)
+ return new QSGOpenVGPainterNode(item);
+}
+
+QSGGlyphNode *QSGOpenVGContext::createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode)
+{
+ Q_UNUSED(preferNativeGlyphNode)
+ return new QSGOpenVGGlyphNode(rc);
+}
+
+QSGNinePatchNode *QSGOpenVGContext::createNinePatchNode()
+{
+ return new QSGOpenVGNinePatchNode;
+}
+
+QSGLayer *QSGOpenVGContext::createLayer(QSGRenderContext *renderContext)
+{
+ return new QSGOpenVGLayer(renderContext);
+}
+
+QSurfaceFormat QSGOpenVGContext::defaultSurfaceFormat() const
+{
+ QSurfaceFormat format = QSurfaceFormat::defaultFormat();
+ format.setRenderableType(QSurfaceFormat::OpenVG);
+ format.setMajorVersion(1);
+ return format;
+}
+
+QSGInternalRectangleNode *QSGOpenVGContext::createInternalRectangleNode()
+{
+ return new QSGOpenVGInternalRectangleNode();
+}
+
+QSGInternalImageNode *QSGOpenVGContext::createInternalImageNode()
+{
+ return new QSGOpenVGInternalImageNode();
+}
+
+int QSGOpenVGRenderContext::maxTextureSize() const
+{
+ VGint width = vgGeti(VG_MAX_IMAGE_WIDTH);
+ VGint height = vgGeti(VG_MAX_IMAGE_HEIGHT);
+
+ return qMin(width, height);
+}
+
+
+QSGSpriteNode *QSGOpenVGContext::createSpriteNode()
+{
+ return new QSGOpenVGSpriteNode();
+}
+
+QSGRendererInterface *QSGOpenVGContext::rendererInterface(QSGRenderContext *renderContext)
+{
+ return static_cast<QSGOpenVGRenderContext *>(renderContext);
+}
+
+QSGRendererInterface::GraphicsApi QSGOpenVGRenderContext::graphicsApi() const
+{
+ return OpenVG;
+}
+
+QSGRendererInterface::ShaderType QSGOpenVGRenderContext::shaderType() const
+{
+ return UnknownShadingLanguage;
+}
+
+QSGRendererInterface::ShaderCompilationTypes QSGOpenVGRenderContext::shaderCompilationType() const
+{
+ return 0;
+}
+
+QSGRendererInterface::ShaderSourceTypes QSGOpenVGRenderContext::shaderSourceType() const
+{
+ return 0;
+}
+
+QSGOpenVGFontGlyphCache *QSGOpenVGRenderContext::glyphCache(const QRawFont &rawFont)
+{
+ if (!m_glyphCacheManager)
+ m_glyphCacheManager = new QSGOpenVGFontGlyphCacheManager;
+
+ QSGOpenVGFontGlyphCache *cache = m_glyphCacheManager->cache(rawFont);
+ if (!cache) {
+ cache = new QSGOpenVGFontGlyphCache(m_glyphCacheManager, rawFont);
+ m_glyphCacheManager->insertCache(rawFont, cache);
+ }
+
+ return cache;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgcontext_p.h b/src/plugins/scenegraph/openvg/qsgopenvgcontext_p.h
new file mode 100644
index 0000000000..fa9939a253
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgcontext_p.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGCONTEXT_H
+#define QSGOPENVGCONTEXT_H
+
+#include <private/qsgcontext_p.h>
+#include <qsgrendererinterface.h>
+
+Q_DECLARE_LOGGING_CATEGORY(QSG_OPENVG_LOG_TIME_RENDERLOOP)
+
+QT_BEGIN_NAMESPACE
+
+class QOpenVGContext;
+class QSGOpenVGFontGlyphCache;
+class QSGOpenVGFontGlyphCacheManager;
+
+class QSGOpenVGRenderContext : public QSGRenderContext, public QSGRendererInterface
+{
+ Q_OBJECT
+public:
+ QSGOpenVGRenderContext(QSGContext *context);
+
+ void initialize(void *context) override;
+ void invalidate() override;
+ void renderNextFrame(QSGRenderer *renderer, uint fboId) override;
+ QSGTexture *createTexture(const QImage &image, uint flags) const override;
+ QSGRenderer *createRenderer() override;
+ int maxTextureSize() const override;
+
+ // QSGRendererInterface interface
+ GraphicsApi graphicsApi() const override;
+ ShaderType shaderType() const override;
+ ShaderCompilationTypes shaderCompilationType() const override;
+ ShaderSourceTypes shaderSourceType() const override;
+
+ QOpenVGContext* vgContext() { return m_vgContext; }
+ QSGOpenVGFontGlyphCache* glyphCache(const QRawFont &rawFont);
+
+private:
+ QOpenVGContext *m_vgContext;
+ QSGOpenVGFontGlyphCacheManager *m_glyphCacheManager;
+
+};
+
+class QSGOpenVGContext : public QSGContext
+{
+ Q_OBJECT
+public:
+ QSGOpenVGContext(QObject *parent = nullptr);
+
+ QSGRenderContext *createRenderContext() override;
+ QSGRectangleNode *createRectangleNode() override;
+ QSGImageNode *createImageNode() override;
+ QSGPainterNode *createPainterNode(QQuickPaintedItem *item) override;
+ QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode) override;
+ QSGNinePatchNode *createNinePatchNode() override;
+ QSGLayer *createLayer(QSGRenderContext *renderContext) override;
+ QSurfaceFormat defaultSurfaceFormat() const override;
+ QSGInternalRectangleNode *createInternalRectangleNode() override;
+ QSGInternalImageNode *createInternalImageNode() override;
+ QSGSpriteNode *createSpriteNode() override;
+ QSGRendererInterface *rendererInterface(QSGRenderContext *renderContext) override;
+};
+
+#endif // QSGOPENVGCONTEXT_H
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.cpp b/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.cpp
new file mode 100644
index 0000000000..dd630c776f
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.cpp
@@ -0,0 +1,162 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvgfontglyphcache.h"
+#include "qsgopenvghelpers.h"
+#include <private/qfontengine_p.h>
+#include <private/qrawfont_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGFontGlyphCacheManager::QSGOpenVGFontGlyphCacheManager()
+{
+
+}
+
+QSGOpenVGFontGlyphCacheManager::~QSGOpenVGFontGlyphCacheManager()
+{
+ qDeleteAll(m_caches);
+}
+
+QSGOpenVGFontGlyphCache *QSGOpenVGFontGlyphCacheManager::cache(const QRawFont &font)
+{
+ return m_caches.value(font, nullptr);
+}
+
+void QSGOpenVGFontGlyphCacheManager::insertCache(const QRawFont &font, QSGOpenVGFontGlyphCache *cache)
+{
+ m_caches.insert(font, cache);
+}
+
+QSGOpenVGFontGlyphCache::QSGOpenVGFontGlyphCache(QSGOpenVGFontGlyphCacheManager *manager, const QRawFont &font)
+ : m_manager(manager)
+{
+ m_referenceFont = font;
+ QRawFontPrivate *fontD = QRawFontPrivate::get(font);
+ m_glyphCount = fontD->fontEngine->glyphCount();
+ m_font = vgCreateFont(0);
+}
+
+QSGOpenVGFontGlyphCache::~QSGOpenVGFontGlyphCache()
+{
+ if (m_font != VG_INVALID_HANDLE)
+ vgDestroyFont(m_font);
+}
+
+void QSGOpenVGFontGlyphCache::populate(const QVector<quint32> &glyphs)
+{
+ QSet<quint32> referencedGlyphs;
+ QSet<quint32> newGlyphs;
+ int count = glyphs.count();
+ for (int i = 0; i < count; ++i) {
+ quint32 glyphIndex = glyphs.at(i);
+ if ((int) glyphIndex >= glyphCount()) {
+ qWarning("Warning: glyph is not available with index %d", glyphIndex);
+ continue;
+ }
+
+ referencedGlyphs.insert(glyphIndex);
+
+
+ if (!m_cachedGlyphs.contains(glyphIndex)) {
+ newGlyphs.insert(glyphIndex);
+ }
+ }
+
+ referenceGlyphs(referencedGlyphs);
+ if (!newGlyphs.isEmpty())
+ requestGlyphs(newGlyphs);
+}
+
+void QSGOpenVGFontGlyphCache::release(const QVector<quint32> &glyphs)
+{
+ QSet<quint32> unusedGlyphs;
+ int count = glyphs.count();
+ for (int i = 0; i < count; ++i) {
+ quint32 glyphIndex = glyphs.at(i);
+ unusedGlyphs.insert(glyphIndex);
+ }
+ releaseGlyphs(unusedGlyphs);
+}
+
+void QSGOpenVGFontGlyphCache::requestGlyphs(const QSet<quint32> &glyphs)
+{
+ VGfloat origin[2];
+ VGfloat escapement[2];
+ QRectF metrics;
+ QRawFont rawFont = m_referenceFont;
+
+ // Before adding any new glyphs, remove any unused glyphs
+ for (auto glyph : qAsConst(m_unusedGlyphs)) {
+ vgClearGlyph(m_font, glyph);
+ }
+
+ for (auto glyph : glyphs) {
+ m_cachedGlyphs.insert(glyph);
+
+ // Calculate the path for the glyph and cache it.
+ QPainterPath path = rawFont.pathForGlyph(glyph);
+ VGPath vgPath;
+ if (!path.isEmpty()) {
+ vgPath = QSGOpenVGHelpers::qPainterPathToVGPath(path);
+ } else {
+ // Probably a "space" character with no visible outline.
+ vgPath = VG_INVALID_HANDLE;
+ }
+ origin[0] = 0;
+ origin[1] = 0;
+ escapement[0] = 0;
+ escapement[1] = 0;
+ vgSetGlyphToPath(m_font, glyph, vgPath, VG_FALSE, origin, escapement);
+ vgDestroyPath(vgPath); // Reduce reference count.
+ }
+
+}
+
+void QSGOpenVGFontGlyphCache::referenceGlyphs(const QSet<quint32> &glyphs)
+{
+ m_unusedGlyphs -= glyphs;
+}
+
+void QSGOpenVGFontGlyphCache::releaseGlyphs(const QSet<quint32> &glyphs)
+{
+ m_unusedGlyphs += glyphs;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.h b/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.h
new file mode 100644
index 0000000000..a88d28b0fe
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgfontglyphcache.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGFONTGLYPHCACHE_H
+#define QSGOPENVGFONTGLYPHCACHE_H
+
+#include <QtGui/QGlyphRun>
+#include <QtCore/QSet>
+#include <QtCore/QLinkedList>
+#include <VG/openvg.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGOpenVGFontGlyphCache;
+
+class QSGOpenVGFontGlyphCacheManager
+{
+public:
+ QSGOpenVGFontGlyphCacheManager();
+ ~QSGOpenVGFontGlyphCacheManager();
+
+ QSGOpenVGFontGlyphCache *cache(const QRawFont &font);
+ void insertCache(const QRawFont &font, QSGOpenVGFontGlyphCache *cache);
+
+private:
+ QHash<QRawFont, QSGOpenVGFontGlyphCache *> m_caches;
+};
+
+class QSGOpenVGFontGlyphCache
+{
+public:
+ QSGOpenVGFontGlyphCache(QSGOpenVGFontGlyphCacheManager *manager, const QRawFont &font);
+ ~QSGOpenVGFontGlyphCache();
+
+ const QSGOpenVGFontGlyphCacheManager *manager() const { return m_manager; }
+ const QRawFont &referenceFont() const { return m_referenceFont; }
+ int glyphCount() const { return m_glyphCount; }
+
+ void populate(const QVector<quint32> &glyphs);
+ void release(const QVector<quint32> &glyphs);
+
+ VGFont font() { return m_font; }
+
+private:
+ void requestGlyphs(const QSet<quint32> &glyphs);
+ void referenceGlyphs(const QSet<quint32> &glyphs);
+ void releaseGlyphs(const QSet<quint32> &glyphs);
+
+ QSGOpenVGFontGlyphCacheManager *m_manager;
+ QRawFont m_referenceFont;
+ int m_glyphCount;
+
+ VGFont m_font;
+ QSet<quint32> m_cachedGlyphs;
+ QSet<quint32> m_unusedGlyphs;
+};
+
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGFONTGLYPHCACHE_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgglyphnode.cpp b/src/plugins/scenegraph/openvg/qsgopenvgglyphnode.cpp
new file mode 100644
index 0000000000..9cf4184c20
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgglyphnode.cpp
@@ -0,0 +1,215 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvgglyphnode_p.h"
+#include "qopenvgcontext_p.h"
+#include "qsgopenvgcontext_p.h"
+#include "qsgopenvghelpers.h"
+#include "qsgopenvgfontglyphcache.h"
+#include "qopenvgoffscreensurface.h"
+#include <cmath>
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGGlyphNode::QSGOpenVGGlyphNode(QSGRenderContext *rc)
+ : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 0)
+ , m_style(QQuickText::Normal)
+ , m_glyphCache(nullptr)
+{
+ // Set Dummy material to avoid asserts
+ setMaterial((QSGMaterial*)1);
+ setGeometry(&m_geometry);
+ m_fontColorPaint = vgCreatePaint();
+ m_styleColorPaint = vgCreatePaint();
+
+ // Get handle to Glyph Cache
+ m_renderContext = static_cast<QSGOpenVGRenderContext*>(rc);
+}
+
+QSGOpenVGGlyphNode::~QSGOpenVGGlyphNode()
+{
+ if (m_glyphCache)
+ m_glyphCache->release(m_glyphRun.glyphIndexes());
+
+ vgDestroyPaint(m_fontColorPaint);
+ vgDestroyPaint(m_styleColorPaint);
+}
+
+void QSGOpenVGGlyphNode::setGlyphs(const QPointF &position, const QGlyphRun &glyphs)
+{
+ // Obtain glyph cache for font
+ auto oldGlyphCache = m_glyphCache;
+ m_glyphCache = m_renderContext->glyphCache(glyphs.rawFont());
+ if (m_glyphCache != oldGlyphCache) {
+ if (oldGlyphCache)
+ oldGlyphCache->release(m_glyphRun.glyphIndexes());
+ }
+ m_glyphCache->populate(glyphs.glyphIndexes());
+
+ m_position = position;
+ m_glyphRun = glyphs;
+ m_bounding_rect = glyphs.boundingRect().translated(m_position - QPointF(0.0, glyphs.rawFont().ascent()));
+
+ // Recreate ajustments
+ m_xAdjustments.clear();
+ m_yAdjustments.clear();
+
+ for (int i = 1; i < glyphs.positions().count(); ++i) {
+ m_xAdjustments.append(glyphs.positions().at(i).x() - glyphs.positions().at(i-1).x());
+ m_yAdjustments.append(glyphs.positions().at(i).y() - glyphs.positions().at(i-1).y());
+ }
+}
+
+void QSGOpenVGGlyphNode::setColor(const QColor &color)
+{
+ m_color = color;
+ vgSetParameteri(m_fontColorPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
+ vgSetParameterfv(m_fontColorPaint, VG_PAINT_COLOR, 4, QSGOpenVGHelpers::qColorToVGColor(m_color, opacity()).constData());
+}
+
+void QSGOpenVGGlyphNode::setStyle(QQuickText::TextStyle style)
+{
+ m_style = style;
+}
+
+void QSGOpenVGGlyphNode::setStyleColor(const QColor &color)
+{
+ m_styleColor = color;
+ vgSetParameteri(m_styleColorPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
+ vgSetParameterfv(m_styleColorPaint, VG_PAINT_COLOR, 4, QSGOpenVGHelpers::qColorToVGColor(m_styleColor, opacity()).constData());
+}
+
+QPointF QSGOpenVGGlyphNode::baseLine() const
+{
+ return QPointF();
+}
+
+void QSGOpenVGGlyphNode::setPreferredAntialiasingMode(QSGGlyphNode::AntialiasingMode)
+{
+}
+
+void QSGOpenVGGlyphNode::update()
+{
+}
+
+void QSGOpenVGGlyphNode::render()
+{
+ if (m_glyphRun.positions().count() == 0)
+ return;
+
+ // Rendering Style
+ qreal offset = 1.0;
+
+ QOpenVGOffscreenSurface *offscreenSurface = nullptr;
+
+ // Set Transform
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
+ if (transform().isAffine()) {
+ vgLoadMatrix(transform().constData());
+ } else {
+ vgLoadIdentity();
+ offscreenSurface = new QOpenVGOffscreenSurface(QSize(std::ceil(m_bounding_rect.width()), std::ceil(m_bounding_rect.height())));
+ offscreenSurface->makeCurrent();
+ }
+
+ // Set Quality
+ vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER);
+
+
+ switch (m_style) {
+ case QQuickText::Normal: break;
+ case QQuickText::Outline:
+ // Set the correct fill state
+ vgSetPaint(m_styleColorPaint, VG_FILL_PATH);
+ drawGlyphsAtOffset(QPointF(0, offset));
+ drawGlyphsAtOffset(QPointF(0, -offset));
+ drawGlyphsAtOffset(QPointF(offset, 0));
+ drawGlyphsAtOffset(QPointF(-offset, 0));
+ break;
+ case QQuickText::Raised:
+ vgSetPaint(m_styleColorPaint, VG_FILL_PATH);
+ drawGlyphsAtOffset(QPointF(0, offset));
+ break;
+ case QQuickText::Sunken:
+ vgSetPaint(m_styleColorPaint, VG_FILL_PATH);
+ drawGlyphsAtOffset(QPointF(0, -offset));
+ break;
+ }
+
+ // Set the correct fill state
+ vgSetPaint(m_fontColorPaint, VG_FILL_PATH);
+ drawGlyphsAtOffset(QPointF(0.0, 0.0));
+
+ if (!transform().isAffine()) {
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
+ vgLoadMatrix(transform().constData());
+ offscreenSurface->doneCurrent();
+ vgDrawImage(offscreenSurface->image());
+ delete offscreenSurface;
+ }
+}
+
+void QSGOpenVGGlyphNode::setOpacity(float opacity)
+{
+ if (QSGOpenVGRenderable::opacity() != opacity) {
+ QSGOpenVGRenderable::setOpacity(opacity);
+ // Update Colors
+ setColor(m_color);
+ setStyleColor(m_styleColor);
+ }
+}
+
+void QSGOpenVGGlyphNode::drawGlyphsAtOffset(const QPointF &offset)
+{
+ QPointF firstPosition = m_glyphRun.positions()[0] + (m_position - QPointF(0, m_glyphRun.rawFont().ascent()));
+ VGfloat origin[2];
+ origin[0] = firstPosition.x() + offset.x();
+ origin[1] = firstPosition.y() + offset.y();
+ vgSetfv(VG_GLYPH_ORIGIN, 2, origin);
+
+ vgDrawGlyphs(m_glyphCache->font(),
+ m_glyphRun.glyphIndexes().count(),
+ (VGuint*)m_glyphRun.glyphIndexes().constData(),
+ m_xAdjustments.constData(),
+ m_yAdjustments.constData(),
+ VG_FILL_PATH,
+ VG_TRUE);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgglyphnode_p.h b/src/plugins/scenegraph/openvg/qsgopenvgglyphnode_p.h
new file mode 100644
index 0000000000..205e3dcbc8
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgglyphnode_p.h
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGGLYPHNODE_H
+#define QSGOPENVGGLYPHNODE_H
+
+#include <private/qsgadaptationlayer_p.h>
+#include <QtCore/QVector>
+
+#include <VG/openvg.h>
+
+#include "qsgopenvgrenderable.h"
+#include "qsgopenvgfontglyphcache.h"
+
+QT_BEGIN_NAMESPACE
+
+class QSGOpenVGFontGlyphCache;
+class QSGOpenVGRenderContext;
+class QSGRenderContext;
+
+class QSGOpenVGGlyphNode : public QSGGlyphNode, public QSGOpenVGRenderable
+{
+public:
+ QSGOpenVGGlyphNode(QSGRenderContext *rc);
+ ~QSGOpenVGGlyphNode();
+
+ void setGlyphs(const QPointF &position, const QGlyphRun &glyphs) override;
+ void setColor(const QColor &color) override;
+ void setStyle(QQuickText::TextStyle style) override;
+ void setStyleColor(const QColor &color) override;
+ QPointF baseLine() const override;
+ void setPreferredAntialiasingMode(AntialiasingMode) override;
+ void update() override;
+
+ void render() override;
+ void setOpacity(float opacity) override;
+
+private:
+ void drawGlyphsAtOffset(const QPointF &offset);
+
+ QPointF m_position;
+ QGlyphRun m_glyphRun;
+ QColor m_color;
+ QSGGeometry m_geometry;
+ QQuickText::TextStyle m_style;
+ QColor m_styleColor;
+
+ QSGOpenVGFontGlyphCache *m_glyphCache;
+ QVector<VGfloat> m_xAdjustments;
+ QVector<VGfloat> m_yAdjustments;
+ VGPaint m_fontColorPaint;
+ VGPaint m_styleColorPaint;
+
+ QSGOpenVGRenderContext *m_renderContext;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGGLYPHNODE_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvghelpers.cpp b/src/plugins/scenegraph/openvg/qsgopenvghelpers.cpp
new file mode 100644
index 0000000000..6bc99d32a1
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvghelpers.cpp
@@ -0,0 +1,433 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvghelpers.h"
+#include <cmath>
+
+QT_BEGIN_NAMESPACE
+
+namespace QSGOpenVGHelpers {
+
+VGPath qPainterPathToVGPath(const QPainterPath &path)
+{
+ int count = path.elementCount();
+
+ VGPath vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
+ VG_PATH_DATATYPE_F,
+ 1.0f, // scale
+ 0.0f, // bias
+ count + 1, // segmentCapacityHint
+ count * 2, // coordCapacityHint
+ VG_PATH_CAPABILITY_ALL);
+
+ if (count == 0)
+ return vgpath;
+
+ QVector<VGfloat> coords;
+ QVector<VGubyte> segments;
+
+ int curvePos = 0;
+ QPointF temp;
+
+ // Keep track of the start and end of each sub-path. QPainterPath
+ // does not have an "implicit close" flag like QVectorPath does.
+ // We therefore have to detect closed paths by looking for a LineTo
+ // element that connects back to the initial MoveTo element.
+ qreal startx = 0.0;
+ qreal starty = 0.0;
+ qreal endx = 0.0;
+ qreal endy = 0.0;
+ bool haveStart = false;
+ bool haveEnd = false;
+
+ for (int i = 0; i < count; ++i) {
+ const QPainterPath::Element element = path.elementAt(i);
+ switch (element.type) {
+
+ case QPainterPath::MoveToElement:
+ {
+ if (haveStart && haveEnd && startx == endx && starty == endy) {
+ // Implicitly close the previous sub-path.
+ segments.append(VG_CLOSE_PATH);
+ }
+ temp = QPointF(element.x, element.y);
+ startx = temp.x();
+ starty = temp.y();
+ coords.append(startx);
+ coords.append(starty);
+ haveStart = true;
+ haveEnd = false;
+ segments.append(VG_MOVE_TO_ABS);
+ }
+ break;
+
+ case QPainterPath::LineToElement:
+ {
+ temp = QPointF(element.x, element.y);
+ endx = temp.x();
+ endy = temp.y();
+ coords.append(endx);
+ coords.append(endy);
+ haveEnd = true;
+ segments.append(VG_LINE_TO_ABS);
+ }
+ break;
+
+ case QPainterPath::CurveToElement:
+ {
+ temp = QPointF(element.x, element.y);
+ coords.append(temp.x());
+ coords.append(temp.y());
+ haveEnd = false;
+ curvePos = 2;
+ }
+ break;
+
+ case QPainterPath::CurveToDataElement:
+ {
+ temp = QPointF(element.x, element.y);
+ coords.append(temp.x());
+ coords.append(temp.y());
+ haveEnd = false;
+ curvePos += 2;
+ if (curvePos == 6) {
+ curvePos = 0;
+ segments.append(VG_CUBIC_TO_ABS);
+ }
+ }
+ break;
+
+ }
+ }
+
+ if (haveStart && haveEnd && startx == endx && starty == endy) {
+ // Implicitly close the last sub-path.
+ segments.append(VG_CLOSE_PATH);
+ }
+
+ vgAppendPathData(vgpath, segments.count(),
+ segments.constData(), coords.constData());
+
+ return vgpath;
+}
+
+
+void qDrawTiled(VGImage image, const QSize imageSize, const QRectF &targetRect, const QPointF offset, float scaleX, float scaleY) {
+
+ //Check for valid image size and targetRect
+ if (imageSize.width() <= 0 || imageSize.height() <= 0)
+ return;
+ if (targetRect.width() <= 0 || targetRect.height() <= 0)
+ return;
+
+ // This logic is mostly from the Qt Raster PaintEngine's qt_draw_tile
+ qreal drawH;
+ qreal drawW;
+ qreal xPos;
+ qreal xOff;
+ qreal yPos = targetRect.y();
+ qreal yOff;
+
+ if (offset.y() < 0)
+ yOff = imageSize.height() - qRound(-offset.y()) % imageSize.height();
+ else
+ yOff = qRound(offset.y()) % imageSize.height();
+
+
+ // Save the current image transform matrix
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
+ QVector<float> originalMatrix(9);
+ vgGetMatrix(originalMatrix.data());
+
+ while (!qFuzzyCompare(yPos, targetRect.y() + targetRect.height()) &&
+ yPos < targetRect.y() + targetRect.height()) {
+ drawH = imageSize.height() - yOff; // Cropping first row
+ if (yPos + drawH * scaleY > targetRect.y() + targetRect.height()) { // Cropping last row
+ // Check that values aren't equal
+ if (!qFuzzyCompare((float)(yPos + drawH * scaleY), (float)(targetRect.y() + targetRect.height())))
+ drawH = targetRect.y() + targetRect.height() - yPos;
+ }
+ xPos = targetRect.x();
+ if (offset.x() < 0)
+ xOff = imageSize.width() - qRound(-offset.x()) % imageSize.width();
+ else
+ xOff = qRound(offset.x()) % imageSize.width();
+
+ while (!qFuzzyCompare(xPos, targetRect.x() + targetRect.width()) &&
+ xPos < targetRect.x() + targetRect.width()) {
+ drawW = imageSize.width() - xOff; // Cropping first column
+ if (xPos + drawW * scaleX > targetRect.x() + targetRect.width()) {
+ // Check that values aren't equal
+ if (!qFuzzyCompare((float)(xPos + drawW * scaleX), (float)(targetRect.x() + targetRect.width())))
+ drawW = targetRect.x() + targetRect.width() - xPos;
+ }
+ if (round(drawW) > 0 && round(drawH) > 0) { // Can't source image less than 1 width or height
+ //Draw here
+ VGImage childRectImage = vgChildImage(image, xOff, yOff, round(drawW), round(drawH));
+ vgTranslate(xPos, yPos);
+ vgScale(scaleX, scaleY);
+ vgDrawImage(childRectImage);
+ vgDestroyImage(childRectImage);
+ vgLoadMatrix(originalMatrix.constData());
+ }
+ if ( drawW > 0)
+ xPos += drawW * scaleX;
+ xOff = 0;
+ }
+ if ( drawH > 0)
+ yPos += drawH * scaleY;
+ yOff = 0;
+
+ }
+}
+
+void qDrawBorderImage(VGImage image, const QSizeF &textureSize, const QRectF &targetRect, const QRectF &innerTargetRect, const QRectF &subSourceRect)
+{
+ // Create normalized margins
+ QMarginsF margins(qMax(innerTargetRect.left() - targetRect.left(), 0.0),
+ qMax(innerTargetRect.top() - targetRect.top(), 0.0),
+ qMax(targetRect.right() - innerTargetRect.right(), 0.0),
+ qMax(targetRect.bottom() - innerTargetRect.bottom(), 0.0));
+
+ QRectF sourceRect(0, 0, textureSize.width(), textureSize.height());
+
+ // Create all the subRects
+ QRectF topLeftSourceRect(sourceRect.topLeft(), QSizeF(margins.left(), margins.top()));
+ QRectF topRightSourceRect(sourceRect.width() - margins.right(), sourceRect.top(), margins.right(), margins.top());
+ QRectF bottomLeftSourceRect(sourceRect.left(), sourceRect.height() - margins.bottom(), margins.left(), margins.bottom());
+ QRectF bottomRightSourceRect(sourceRect.width() - margins.right(), sourceRect.height() - margins.bottom(), margins.right(), margins.bottom());
+
+ QRectF topSourceRect(margins.left(), 0.0, sourceRect.width() - (margins.right() + margins.left()), margins.top());
+ QRectF topTargetRect(margins.left(), 0.0, innerTargetRect.width(), margins.top());
+ QRectF bottomSourceRect(margins.left(), sourceRect.height() - margins.bottom(), sourceRect.width() - (margins.right() + margins.left()), margins.bottom());
+ QRectF bottomTargetRect(margins.left(), targetRect.height() - margins.bottom(), innerTargetRect.width(), margins.bottom());
+ QRectF leftSourceRect(0.0, margins.top(), margins.left(), sourceRect.height() - (margins.bottom() + margins.top()));
+ QRectF leftTargetRect(0.0, margins.top(), margins.left(), innerTargetRect.height());
+ QRectF rightSourceRect(sourceRect.width() - margins.right(), margins.top(), margins.right(), sourceRect.height() - (margins.bottom() + margins.top()));
+ QRectF rightTargetRect(targetRect.width() - margins.right(), margins.top(), margins.right(), innerTargetRect.height());
+
+ QRectF centerSourceRect(margins.left(), margins.top(), sourceRect.width() - (margins.right() + margins.left()), sourceRect.height() - (margins.top() + margins.bottom()));
+
+ // Draw the 9 different sections
+ // (1) Top Left (unscaled)
+ qDrawSubImage(image,
+ topLeftSourceRect,
+ targetRect.topLeft());
+
+ // (3) Top Right (unscaled)
+ qDrawSubImage(image,
+ topRightSourceRect,
+ QPointF(targetRect.width() - margins.right(), 0.0));
+
+ // (7) Bottom Left (unscaled)
+ qDrawSubImage(image,
+ bottomLeftSourceRect,
+ QPointF(targetRect.left(), targetRect.height() - margins.bottom()));
+
+ // (9) Bottom Right (unscaled)
+ qDrawSubImage(image,
+ bottomRightSourceRect,
+ QPointF(targetRect.width() - margins.right(), targetRect.height() - margins.bottom()));
+
+ double scaledWidth = 1.0;
+ double scaledHeight = 1.0;
+
+ // (2) Top (scaled via horizontalTileRule)
+ VGImage topImage = vgChildImage(image, topSourceRect.x(), topSourceRect.y(), topSourceRect.width(), topSourceRect.height());
+ scaledWidth = (topTargetRect.width() / subSourceRect.width()) / topSourceRect.width();
+
+ QSGOpenVGHelpers::qDrawTiled(topImage, topSourceRect.size().toSize(), topTargetRect, QPoint(0.0, 0.0), scaledWidth, 1);
+
+ vgDestroyImage(topImage);
+
+ // (8) Bottom (scaled via horizontalTileRule)
+ VGImage bottomImage = vgChildImage(image, bottomSourceRect.x(), bottomSourceRect.y(), bottomSourceRect.width(), bottomSourceRect.height());
+ scaledWidth = (bottomTargetRect.width() / subSourceRect.width()) / bottomSourceRect.width();
+
+ QSGOpenVGHelpers::qDrawTiled(bottomImage, bottomSourceRect.size().toSize(), bottomTargetRect, QPoint(0.0, 0.0), scaledWidth, 1);
+
+ vgDestroyImage(bottomImage);
+
+ // (4) Left (scaled via verticalTileRule)
+ VGImage leftImage = vgChildImage(image, leftSourceRect.x(), leftSourceRect.y(), leftSourceRect.width(), leftSourceRect.height());
+ scaledHeight = (leftTargetRect.height() / subSourceRect.height()) / leftSourceRect.height();
+ QSGOpenVGHelpers::qDrawTiled(leftImage, leftSourceRect.size().toSize(), leftTargetRect, QPointF(0.0, 0.0), 1, scaledHeight);
+
+ vgDestroyImage(leftImage);
+
+ // (6) Right (scaled via verticalTileRule)
+ VGImage rightImage = vgChildImage(image, rightSourceRect.x(), rightSourceRect.y(), rightSourceRect.width(), rightSourceRect.height());
+ scaledHeight = (rightTargetRect.height() / subSourceRect.height()) / rightSourceRect.height();
+
+ QSGOpenVGHelpers::qDrawTiled(rightImage, rightSourceRect.size().toSize(), rightTargetRect, QPointF(0, 0), 1, scaledHeight);
+
+ vgDestroyImage(rightImage);
+
+ // (5) Center (saled via verticalTileRule and horizontalTileRule)
+ VGImage centerImage = vgChildImage(image, centerSourceRect.x(), centerSourceRect.y(), centerSourceRect.width(), centerSourceRect.height());
+
+ scaledWidth = (innerTargetRect.width() / subSourceRect.width()) / centerSourceRect.width();
+ scaledHeight = (innerTargetRect.height() / subSourceRect.height()) / centerSourceRect.height();
+
+ QSGOpenVGHelpers::qDrawTiled(centerImage, centerSourceRect.size().toSize(), innerTargetRect, QPointF(0, 0), scaledWidth, scaledHeight);
+
+ vgDestroyImage(centerImage);
+}
+
+void qDrawSubImage(VGImage image, const QRectF &sourceRect, const QPointF &destOffset)
+{
+ // Check for valid source size
+ if (sourceRect.width() <= 0 || sourceRect.height() <= 0)
+ return;
+
+ // Save the current image transform matrix
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
+ QVector<float> originalMatrix(9);
+ vgGetMatrix(originalMatrix.data());
+
+ // Get the child Image
+ VGImage childRectImage = vgChildImage(image, sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height());
+ vgTranslate(destOffset.x(), destOffset.y());
+ vgDrawImage(childRectImage);
+ vgDestroyImage(childRectImage);
+
+ // Pop Matrix
+ vgLoadMatrix(originalMatrix.constData());
+}
+
+const QVector<VGfloat> qColorToVGColor(const QColor &color, float opacity)
+{
+ QVector<VGfloat> vgColor(4);
+ vgColor[0] = color.redF();
+ vgColor[1] = color.greenF();
+ vgColor[2] = color.blueF();
+ vgColor[3] = color.alphaF() * opacity;
+ return vgColor;
+}
+
+VGImageFormat qImageFormatToVGImageFormat(QImage::Format format)
+{
+ VGImageFormat vgFormat;
+
+ switch (format) {
+ case QImage::Format_Mono:
+ case QImage::Format_MonoLSB:
+ vgFormat = VG_BW_1;
+ break;
+ case QImage::Format_RGB32:
+ vgFormat = VG_sXRGB_8888;
+ break;
+ case QImage::Format_ARGB32:
+ vgFormat = VG_sARGB_8888;
+ break;
+ case QImage::Format_ARGB32_Premultiplied:
+ vgFormat = VG_sARGB_8888_PRE;
+ break;
+ case QImage::Format_RGB16:
+ vgFormat = VG_sRGB_565;
+ break;
+ case QImage::Format_RGBX8888:
+ vgFormat = VG_sRGBX_8888;
+ break;
+ case QImage::Format_RGBA8888:
+ vgFormat = VG_sRGBA_8888;
+ break;
+ case QImage::Format_RGBA8888_Premultiplied:
+ vgFormat = VG_sRGBA_8888_PRE;
+ break;
+ case QImage::Format_Alpha8:
+ vgFormat = VG_A_8;
+ break;
+ case QImage::Format_Grayscale8:
+ vgFormat = VG_sL_8;
+ break;
+ default:
+ //Invalid
+ vgFormat = (VGImageFormat)-1;
+ break;
+ }
+
+ return vgFormat;
+}
+
+QImage::Format qVGImageFormatToQImageFormat(VGImageFormat format)
+{
+ QImage::Format qImageFormat;
+
+ switch (format) {
+ case VG_BW_1:
+ qImageFormat = QImage::Format_Mono;
+ break;
+ case VG_sXRGB_8888:
+ qImageFormat = QImage::Format_RGB32;
+ break;
+ case VG_sARGB_8888:
+ qImageFormat = QImage::Format_ARGB32;
+ break;
+ case VG_sARGB_8888_PRE:
+ qImageFormat = QImage::Format_ARGB32_Premultiplied;
+ break;
+ case VG_sRGB_565:
+ qImageFormat = QImage::Format_RGB16;
+ break;
+ case VG_sRGBX_8888:
+ qImageFormat = QImage::Format_RGBX8888;
+ break;
+ case VG_sRGBA_8888:
+ qImageFormat = QImage::Format_RGBA8888;
+ break;
+ case VG_sRGBA_8888_PRE:
+ qImageFormat = QImage::Format_RGBA8888_Premultiplied;
+ break;
+ case VG_A_8:
+ qImageFormat = QImage::Format_Alpha8;
+ break;
+ case VG_sL_8:
+ qImageFormat = QImage::Format_Grayscale8;
+ default:
+ qImageFormat = QImage::Format_ARGB32;
+ break;
+ }
+
+ return qImageFormat;
+}
+
+} // end namespace QSGOpenVGHelpers
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvghelpers.h b/src/plugins/scenegraph/openvg/qsgopenvghelpers.h
new file mode 100644
index 0000000000..ee8ff73ca8
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvghelpers.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGHELPERS_H
+#define QSGOPENVGHELPERS_H
+
+#include <QtGui/QPainterPath>
+#include <QtGui/QColor>
+#include <QtGui/QImage>
+#include <VG/openvg.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QSGOpenVGHelpers {
+
+VGPath qPainterPathToVGPath(const QPainterPath &path);
+void qDrawTiled(VGImage image, const QSize imageSize, const QRectF &targetRect, const QPointF offset, float scaleX, float scaleY);
+void qDrawBorderImage(VGImage image, const QSizeF &textureSize, const QRectF &targetRect, const QRectF &innerTargetRect, const QRectF &subSourceRect);
+void qDrawSubImage(VGImage image, const QRectF &sourceRect, const QPointF &destOffset);
+const QVector<VGfloat> qColorToVGColor(const QColor &color, float opacity = 1.0f);
+VGImageFormat qImageFormatToVGImageFormat(QImage::Format format);
+QImage::Format qVGImageFormatToQImageFormat(VGImageFormat format);
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGHELPERS_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvginternalimagenode.cpp b/src/plugins/scenegraph/openvg/qsgopenvginternalimagenode.cpp
new file mode 100644
index 0000000000..3dd1f9133c
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvginternalimagenode.cpp
@@ -0,0 +1,239 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvginternalimagenode.h"
+#include "qsgopenvghelpers.h"
+
+#include <VG/openvg.h>
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGInternalImageNode::QSGOpenVGInternalImageNode()
+{
+ // Set Dummy material and geometry to avoid asserts
+ setMaterial((QSGMaterial*)1);
+ setGeometry((QSGGeometry*)1);
+}
+
+QSGOpenVGInternalImageNode::~QSGOpenVGInternalImageNode()
+{
+ if (m_subSourceRectImage != 0)
+ vgDestroyImage(m_subSourceRectImage);
+}
+
+void QSGOpenVGInternalImageNode::render()
+{
+ if (!m_texture) {
+ return;
+ }
+
+ // Set Draw Mode
+ if (opacity() < 1.0) {
+ //Transparent
+ vgSetPaint(opacityPaint(), VG_FILL_PATH);
+ vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
+ } else {
+ vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
+ }
+
+ // Set Transform
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
+ vgLoadMatrix(transform().constData());
+
+ VGImage image = static_cast<VGImage>(m_texture->textureId());
+ QSize textureSize = m_texture->textureSize();
+
+ if (image == VG_INVALID_HANDLE || !textureSize.isValid())
+ return;
+
+
+ // If Mirrored
+ if (m_mirror) {
+ vgTranslate(m_targetRect.width(), 0.0f);
+ vgScale(-1.0, 1.0);
+ }
+
+ if (m_smooth)
+ vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_BETTER);
+ else
+ vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_NONANTIALIASED);
+
+
+ if (m_innerTargetRect != m_targetRect) {
+ // border image
+ QSGOpenVGHelpers::qDrawBorderImage(image, textureSize, m_targetRect, m_innerTargetRect, m_subSourceRect);
+ } else if (m_tileHorizontal || m_tileVertical) {
+ // Tilled Image
+
+ float sx = m_targetRect.width() / (m_subSourceRect.width() * textureSize.width());
+ float sy = m_targetRect.height() / (m_subSourceRect.height() * textureSize.height());
+ QPointF offset(m_subSourceRect.left() * textureSize.width(), m_subSourceRect.top() * textureSize.height());
+
+ QSGOpenVGHelpers::qDrawTiled(image, textureSize, m_targetRect, offset, sx, sy);
+
+ } else {
+ // Regular BLIT
+
+ QRectF sr(m_subSourceRect.left() * textureSize.width(), m_subSourceRect.top() * textureSize.height(),
+ m_subSourceRect.width() * textureSize.width(), m_subSourceRect.height() * textureSize.height());
+
+ if (m_subSourceRectImageDirty) {
+ if (m_subSourceRectImage != 0)
+ vgDestroyImage(m_subSourceRectImage);
+ m_subSourceRectImage = vgChildImage(image, sr.x(), sr.y(), sr.width(), sr.height());
+ m_subSourceRectImageDirty = false;
+ }
+
+ // If the the source rect is the same as the target rect
+ if (sr == m_targetRect) {
+ vgDrawImage(image);
+ } else {
+ // Scale
+ float scaleX = m_targetRect.width() / sr.width();
+ float scaleY = m_targetRect.height() / sr.height();
+ vgTranslate(m_targetRect.x(), m_targetRect.y());
+ vgScale(scaleX, scaleY);
+ vgDrawImage(m_subSourceRectImage);
+ }
+ }
+}
+
+void QSGOpenVGInternalImageNode::setTargetRect(const QRectF &rect)
+{
+ if (rect == m_targetRect)
+ return;
+ m_targetRect = rect;
+ markDirty(DirtyGeometry);
+}
+
+void QSGOpenVGInternalImageNode::setInnerTargetRect(const QRectF &rect)
+{
+ if (rect == m_innerTargetRect)
+ return;
+ m_innerTargetRect = rect;
+ markDirty(DirtyGeometry);
+}
+
+void QSGOpenVGInternalImageNode::setInnerSourceRect(const QRectF &rect)
+{
+ if (rect == m_innerSourceRect)
+ return;
+ m_innerSourceRect = rect;
+ markDirty(DirtyGeometry);
+}
+
+void QSGOpenVGInternalImageNode::setSubSourceRect(const QRectF &rect)
+{
+ if (rect == m_subSourceRect)
+ return;
+ m_subSourceRect = rect;
+ m_subSourceRectImageDirty = true;
+ markDirty(DirtyGeometry);
+}
+
+void QSGOpenVGInternalImageNode::setTexture(QSGTexture *texture)
+{
+ m_texture = texture;
+ m_subSourceRectImageDirty = true;
+ markDirty(DirtyMaterial);
+}
+
+void QSGOpenVGInternalImageNode::setMirror(bool mirror)
+{
+ if (m_mirror != mirror) {
+ m_mirror = mirror;
+ markDirty(DirtyMaterial);
+ }
+}
+
+void QSGOpenVGInternalImageNode::setMipmapFiltering(QSGTexture::Filtering)
+{
+}
+
+void QSGOpenVGInternalImageNode::setFiltering(QSGTexture::Filtering filtering)
+{
+ bool smooth = (filtering == QSGTexture::Linear);
+ if (smooth == m_smooth)
+ return;
+
+ m_smooth = smooth;
+ markDirty(DirtyMaterial);
+}
+
+void QSGOpenVGInternalImageNode::setHorizontalWrapMode(QSGTexture::WrapMode wrapMode)
+{
+ bool tileHorizontal = (wrapMode == QSGTexture::Repeat);
+ if (tileHorizontal == m_tileHorizontal)
+ return;
+
+ m_tileHorizontal = tileHorizontal;
+ markDirty(DirtyMaterial);
+}
+
+void QSGOpenVGInternalImageNode::setVerticalWrapMode(QSGTexture::WrapMode wrapMode)
+{
+ bool tileVertical = (wrapMode == QSGTexture::Repeat);
+ if (tileVertical == m_tileVertical)
+ return;
+
+ m_tileVertical = (wrapMode == QSGTexture::Repeat);
+ markDirty(DirtyMaterial);
+}
+
+void QSGOpenVGInternalImageNode::update()
+{
+}
+
+void QSGOpenVGInternalImageNode::preprocess()
+{
+ bool doDirty = false;
+ QSGLayer *t = qobject_cast<QSGLayer *>(m_texture);
+ if (t) {
+ doDirty = t->updateTexture();
+ markDirty(DirtyGeometry);
+ }
+ if (doDirty)
+ markDirty(DirtyMaterial);
+}
+
+QT_END_NAMESPACE
+
+
+
+
diff --git a/src/plugins/scenegraph/openvg/qsgopenvginternalimagenode.h b/src/plugins/scenegraph/openvg/qsgopenvginternalimagenode.h
new file mode 100644
index 0000000000..2361aa4892
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvginternalimagenode.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGINTERNALIMAGENODE_H
+#define QSGOPENVGINTERNALIMAGENODE_H
+
+#include <private/qsgadaptationlayer_p.h>
+#include "qsgopenvgrenderable.h"
+
+#include <VG/openvg.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGOpenVGInternalImageNode : public QSGInternalImageNode, public QSGOpenVGRenderable
+{
+public:
+ QSGOpenVGInternalImageNode();
+ ~QSGOpenVGInternalImageNode();
+
+ void render() override;
+
+ void setTargetRect(const QRectF &rect) override;
+ void setInnerTargetRect(const QRectF &rect) override;
+ void setInnerSourceRect(const QRectF &rect) override;
+ void setSubSourceRect(const QRectF &rect) override;
+ void setTexture(QSGTexture *texture) override;
+ void setMirror(bool mirror) override;
+ void setMipmapFiltering(QSGTexture::Filtering filtering) override;
+ void setFiltering(QSGTexture::Filtering filtering) override;
+ void setHorizontalWrapMode(QSGTexture::WrapMode wrapMode) override;
+ void setVerticalWrapMode(QSGTexture::WrapMode wrapMode) override;
+ void update() override;
+
+ void preprocess() override;
+
+private:
+
+ QRectF m_targetRect;
+ QRectF m_innerTargetRect;
+ QRectF m_innerSourceRect = QRectF(0, 0, 1, 1);
+ QRectF m_subSourceRect = QRectF(0, 0, 1, 1);
+
+ bool m_mirror = false;
+ bool m_smooth = true;
+ bool m_tileHorizontal = false;
+ bool m_tileVertical = false;
+
+ QSGTexture *m_texture = nullptr;
+
+ VGImage m_subSourceRectImage = 0;
+ bool m_subSourceRectImageDirty = true;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGINTERNALIMAGENODE_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.cpp b/src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.cpp
new file mode 100644
index 0000000000..0bd51cbf46
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.cpp
@@ -0,0 +1,732 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvginternalrectanglenode.h"
+#include "qsgopenvghelpers.h"
+#include <cmath>
+#include <VG/vgu.h>
+
+QSGOpenVGInternalRectangleNode::QSGOpenVGInternalRectangleNode()
+{
+ // Set Dummy material and geometry to avoid asserts
+ setMaterial((QSGMaterial*)1);
+ setGeometry((QSGGeometry*)1);
+ createVGResources();
+}
+
+QSGOpenVGInternalRectangleNode::~QSGOpenVGInternalRectangleNode()
+{
+ destroyVGResources();
+}
+
+
+void QSGOpenVGInternalRectangleNode::setRect(const QRectF &rect)
+{
+ m_rect = rect;
+ m_pathDirty = true;
+}
+
+void QSGOpenVGInternalRectangleNode::setColor(const QColor &color)
+{
+ m_fillColor = color;
+ m_fillDirty = true;
+}
+
+void QSGOpenVGInternalRectangleNode::setPenColor(const QColor &color)
+{
+ m_strokeColor = color;
+ m_strokeDirty = true;
+}
+
+void QSGOpenVGInternalRectangleNode::setPenWidth(qreal width)
+{
+ m_penWidth = width;
+ m_strokeDirty = true;
+ m_pathDirty = true;
+}
+
+//Move first stop by pos relative to seconds
+static QGradientStop interpolateStop(const QGradientStop &firstStop, const QGradientStop &secondStop, double newPos)
+{
+ double distance = secondStop.first - firstStop.first;
+ double distanceDelta = newPos - firstStop.first;
+ double modifierValue = distanceDelta / distance;
+ int redDelta = (secondStop.second.red() - firstStop.second.red()) * modifierValue;
+ int greenDelta = (secondStop.second.green() - firstStop.second.green()) * modifierValue;
+ int blueDelta = (secondStop.second.blue() - firstStop.second.blue()) * modifierValue;
+ int alphaDelta = (secondStop.second.alpha() - firstStop.second.alpha()) * modifierValue;
+
+ QGradientStop newStop;
+ newStop.first = newPos;
+ newStop.second = QColor(firstStop.second.red() + redDelta,
+ firstStop.second.green() + greenDelta,
+ firstStop.second.blue() + blueDelta,
+ firstStop.second.alpha() + alphaDelta);
+
+ return newStop;
+}
+
+void QSGOpenVGInternalRectangleNode::setGradientStops(const QGradientStops &stops)
+{
+
+ //normalize stops
+ bool needsNormalization = false;
+ for (const QGradientStop &stop : qAsConst(stops)) {
+ if (stop.first < 0.0 || stop.first > 1.0) {
+ needsNormalization = true;
+ continue;
+ }
+ }
+
+ if (needsNormalization) {
+ QGradientStops normalizedStops;
+ if (stops.count() == 1) {
+ //If there is only one stop, then the position does not matter
+ //It is just treated as a color
+ QGradientStop stop = stops.at(0);
+ stop.first = 0.0;
+ normalizedStops.append(stop);
+ } else {
+ //Clip stops to only the first below 0.0 and above 1.0
+ int below = -1;
+ int above = -1;
+ QVector<int> between;
+ for (int i = 0; i < stops.count(); ++i) {
+ if (stops.at(i).first < 0.0) {
+ below = i;
+ } else if (stops.at(i).first > 1.0) {
+ above = i;
+ break;
+ } else {
+ between.append(i);
+ }
+ }
+
+ //Interpoloate new color values for above and below
+ if (below != -1 ) {
+ //If there are more than one stops left, interpolate
+ if (below + 1 < stops.count()) {
+ normalizedStops.append(interpolateStop(stops.at(below), stops.at(below + 1), 0.0));
+ } else {
+ QGradientStop singleStop;
+ singleStop.first = 0.0;
+ singleStop.second = stops.at(below).second;
+ normalizedStops.append(singleStop);
+ }
+ }
+
+ for (int i = 0; i < between.count(); ++i)
+ normalizedStops.append(stops.at(between.at(i)));
+
+ if (above != -1) {
+ //If there stops before above, interpolate
+ if (above >= 1) {
+ normalizedStops.append(interpolateStop(stops.at(above), stops.at(above - 1), 1.0));
+ } else {
+ QGradientStop singleStop;
+ singleStop.first = 1.0;
+ singleStop.second = stops.at(above).second;
+ normalizedStops.append(singleStop);
+ }
+ }
+ }
+
+ m_gradientStops = normalizedStops;
+
+ } else {
+ m_gradientStops = stops;
+ }
+
+ m_fillDirty = true;
+}
+
+void QSGOpenVGInternalRectangleNode::setRadius(qreal radius)
+{
+ m_radius = radius;
+ m_pathDirty = true;
+}
+
+void QSGOpenVGInternalRectangleNode::setAligned(bool aligned)
+{
+ m_aligned = aligned;
+}
+
+void QSGOpenVGInternalRectangleNode::update()
+{
+}
+
+void QSGOpenVGInternalRectangleNode::render()
+{
+ // Set Transform
+ if (transform().isAffine()) {
+ // Use current transform matrix
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
+ vgLoadMatrix(transform().constData());
+ if (m_offscreenSurface) {
+ delete m_offscreenSurface;
+ m_offscreenSurface = nullptr;
+ }
+ } else {
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
+ vgLoadIdentity();
+ if (m_radius > 0) {
+ // Fallback to rendering to an image for rounded rects with perspective transforms
+ if (m_offscreenSurface == nullptr || m_offscreenSurface->size() != QSize(std::ceil(m_rect.width()), std::ceil(m_rect.height()))) {
+ delete m_offscreenSurface;
+ m_offscreenSurface = new QOpenVGOffscreenSurface(QSize(std::ceil(m_rect.width()), std::ceil(m_rect.height())));
+ }
+
+ m_offscreenSurface->makeCurrent();
+ } else if (m_offscreenSurface) {
+ delete m_offscreenSurface;
+ m_offscreenSurface = nullptr;
+ }
+ }
+
+
+ // If path is dirty
+ if (m_pathDirty) {
+ vgClearPath(m_rectanglePath, VG_PATH_CAPABILITY_APPEND_TO);
+ vgClearPath(m_borderPath, VG_PATH_CAPABILITY_APPEND_TO);
+
+ if (m_penWidth == 0) {
+ generateRectanglePath(m_rect, m_radius, m_rectanglePath);
+ } else {
+ generateRectangleAndBorderPaths(m_rect, m_penWidth, m_radius, m_rectanglePath, m_borderPath);
+ }
+
+ m_pathDirty = false;
+ }
+
+ //If fill is drity
+ if (m_fillDirty) {
+ if (m_gradientStops.isEmpty()) {
+ vgSetParameteri(m_rectanglePaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
+ vgSetParameterfv(m_rectanglePaint, VG_PAINT_COLOR, 4, QSGOpenVGHelpers::qColorToVGColor(m_fillColor, opacity()).constData());
+ } else {
+ // Linear Gradient
+ vgSetParameteri(m_rectanglePaint, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
+ const VGfloat verticalLinearGradient[] = {
+ 0.0f,
+ 0.0f,
+ 0.0f,
+ static_cast<VGfloat>(m_rect.height())
+ };
+ vgSetParameterfv(m_rectanglePaint, VG_PAINT_LINEAR_GRADIENT, 4, verticalLinearGradient);
+ vgSetParameteri(m_rectanglePaint, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
+ vgSetParameteri(m_rectanglePaint, VG_PAINT_COLOR_RAMP_PREMULTIPLIED, false);
+
+ QVector<VGfloat> stops;
+ for (const QGradientStop &stop : qAsConst(m_gradientStops)) {
+ // offset
+ stops.append(stop.first);
+ // color
+ stops.append(QSGOpenVGHelpers::qColorToVGColor(stop.second, opacity()));
+ }
+
+ vgSetParameterfv(m_rectanglePaint, VG_PAINT_COLOR_RAMP_STOPS, stops.length(), stops.constData());
+ }
+
+ m_fillDirty = false;
+ }
+
+ //If stroke is dirty
+ if (m_strokeDirty) {
+ vgSetParameteri(m_borderPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
+ vgSetParameterfv(m_borderPaint, VG_PAINT_COLOR, 4, QSGOpenVGHelpers::qColorToVGColor(m_strokeColor, opacity()).constData());
+
+ m_strokeDirty = false;
+ }
+
+ //Draw
+ if (m_penWidth > 0) {
+ vgSetPaint(m_borderPaint, VG_FILL_PATH);
+ vgDrawPath(m_borderPath, VG_FILL_PATH);
+ vgSetPaint(m_rectanglePaint, VG_FILL_PATH);
+ vgDrawPath(m_rectanglePath, VG_FILL_PATH);
+ } else {
+ vgSetPaint(m_rectanglePaint, VG_FILL_PATH);
+ vgDrawPath(m_rectanglePath, VG_FILL_PATH);
+ }
+
+ if (!transform().isAffine() && m_radius > 0) {
+ m_offscreenSurface->doneCurrent();
+ // Render offscreen surface
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
+ vgLoadMatrix(transform().constData());
+ vgDrawImage(m_offscreenSurface->image());
+ }
+}
+
+void QSGOpenVGInternalRectangleNode::setOpacity(float opacity)
+{
+ if (opacity != QSGOpenVGRenderable::opacity()) {
+ QSGOpenVGRenderable::setOpacity(opacity);
+ m_strokeDirty = true;
+ m_fillDirty = true;
+ }
+}
+
+void QSGOpenVGInternalRectangleNode::setTransform(const QOpenVGMatrix &transform)
+{
+ // if there transform matrix is not affine, regenerate the path
+ if (transform.isAffine())
+ m_pathDirty = true;
+
+ QSGOpenVGRenderable::setTransform(transform);
+}
+
+void QSGOpenVGInternalRectangleNode::createVGResources()
+{
+ m_rectanglePaint = vgCreatePaint();
+ m_borderPaint = vgCreatePaint();
+ m_rectanglePath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
+ VG_PATH_CAPABILITY_APPEND_TO);
+ m_borderPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
+ VG_PATH_CAPABILITY_APPEND_TO);
+}
+
+void QSGOpenVGInternalRectangleNode::destroyVGResources()
+{
+ if (m_offscreenSurface)
+ delete m_offscreenSurface;
+
+ vgDestroyPaint(m_rectanglePaint);
+ vgDestroyPaint(m_borderPaint);
+ vgDestroyPath(m_rectanglePath);
+ vgDestroyPath(m_borderPath);
+}
+
+void QSGOpenVGInternalRectangleNode::generateRectanglePath(const QRectF &rect, float radius, VGPath path) const
+{
+ if (radius == 0) {
+ // Generate a rectangle
+ if (transform().isAffine()) {
+ // Create command list
+ static const VGubyte rectCommands[] = {
+ VG_MOVE_TO_ABS,
+ VG_HLINE_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_HLINE_TO_REL,
+ VG_CLOSE_PATH
+ };
+
+ // Create command data
+ QVector<VGfloat> coordinates(5);
+ coordinates[0] = rect.x();
+ coordinates[1] = rect.y();
+ coordinates[2] = rect.width();
+ coordinates[3] = rect.height();
+ coordinates[4] = -rect.width();
+ vgAppendPathData(path, 5, rectCommands, coordinates.constData());
+ } else {
+ // Pre-transform path
+ static const VGubyte rectCommands[] = {
+ VG_MOVE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_CLOSE_PATH
+ };
+
+ QVector<VGfloat> coordinates(8);
+ const QPointF topLeft = transform().map(rect.topLeft());
+ const QPointF topRight = transform().map(rect.topRight());
+ const QPointF bottomLeft = transform().map(rect.bottomLeft());
+ const QPointF bottomRight = transform().map(rect.bottomRight());
+ coordinates[0] = bottomLeft.x();
+ coordinates[1] = bottomLeft.y();
+ coordinates[2] = bottomRight.x();
+ coordinates[3] = bottomRight.y();
+ coordinates[4] = topRight.x();
+ coordinates[5] = topRight.y();
+ coordinates[6] = topLeft.x();
+ coordinates[7] = topLeft.y();
+
+ vgAppendPathData(path, 5, rectCommands, coordinates.constData());
+ }
+ } else {
+ // Generate a rounded rectangle
+ //Radius should never exceeds half of the width or half of the height
+ float adjustedRadius = qMin((float)qMin(rect.width(), rect.height()) * 0.5f, radius);
+
+ // OpenVG expectes radius to be 2x what we expect
+ adjustedRadius *= 2;
+
+ // Create command list
+ static const VGubyte roundedRectCommands[] = {
+ VG_MOVE_TO_ABS,
+ VG_HLINE_TO_REL,
+ VG_SCCWARC_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_SCCWARC_TO_REL,
+ VG_HLINE_TO_REL,
+ VG_SCCWARC_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_SCCWARC_TO_REL,
+ VG_CLOSE_PATH
+ };
+
+ // Create command data
+ QVector<VGfloat> coordinates(26);
+
+ coordinates[0] = rect.x() + adjustedRadius / 2;
+ coordinates[1] = rect.y();
+
+ coordinates[2] = rect.width() - adjustedRadius;
+
+ coordinates[3] = adjustedRadius / 2;
+ coordinates[4] = adjustedRadius / 2;
+ coordinates[5] = 0;
+ coordinates[6] = adjustedRadius / 2;
+ coordinates[7] = adjustedRadius / 2;
+
+ coordinates[8] = rect.height() - adjustedRadius;
+
+ coordinates[9] = adjustedRadius / 2;
+ coordinates[10] = adjustedRadius / 2;
+ coordinates[11] = 0;
+ coordinates[12] = -adjustedRadius / 2;
+ coordinates[13] = adjustedRadius / 2;
+
+ coordinates[14] = -(rect.width() - adjustedRadius);
+
+ coordinates[15] = adjustedRadius / 2;
+ coordinates[16] = adjustedRadius / 2;
+ coordinates[17] = 0;
+ coordinates[18] = -adjustedRadius / 2;
+ coordinates[19] = -adjustedRadius / 2;
+
+ coordinates[20] = -(rect.height() - adjustedRadius);
+
+ coordinates[21] = adjustedRadius / 2;
+ coordinates[22] = adjustedRadius / 2;
+ coordinates[23] = 0;
+ coordinates[24] = adjustedRadius / 2;
+ coordinates[25] = -adjustedRadius / 2;
+
+ vgAppendPathData(path, 10, roundedRectCommands, coordinates.constData());
+ }
+}
+
+void QSGOpenVGInternalRectangleNode::generateBorderPath(const QRectF &rect, float borderWidth, float borderHeight, float radius, VGPath path) const
+{
+ if (radius == 0) {
+ // squared frame
+ if (transform().isAffine()) {
+ // Create command list
+ static const VGubyte squaredBorderCommands[] = {
+ VG_MOVE_TO_ABS,
+ VG_HLINE_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_HLINE_TO_REL,
+ VG_MOVE_TO_ABS,
+ VG_VLINE_TO_REL,
+ VG_HLINE_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_CLOSE_PATH
+ };
+
+ // Create command data
+ QVector<VGfloat> coordinates(10);
+ // Outside Square
+ coordinates[0] = rect.x();
+ coordinates[1] = rect.y();
+ coordinates[2] = rect.width();
+ coordinates[3] = rect.height();
+ coordinates[4] = -rect.width();
+ // Inside Square (opposite direction)
+ coordinates[5] = rect.x() + borderWidth;
+ coordinates[6] = rect.y() + borderHeight;
+ coordinates[7] = rect.height() - (borderHeight * 2);
+ coordinates[8] = rect.width() - (borderWidth * 2);
+ coordinates[9] = -(rect.height() - (borderHeight * 2));
+
+ vgAppendPathData(path, 9, squaredBorderCommands, coordinates.constData());
+ } else {
+ // persepective transform
+ static const VGubyte squaredBorderCommands[] = {
+ VG_MOVE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_MOVE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_CLOSE_PATH
+ };
+
+ QVector<VGfloat> coordinates(16);
+ QRectF insideRect = rect.marginsRemoved(QMarginsF(borderWidth, borderHeight, borderWidth, borderHeight));
+ QPointF outsideBottomLeft = transform().map(rect.bottomLeft());
+ QPointF outsideBottomRight = transform().map(rect.bottomRight());
+ QPointF outsideTopRight = transform().map(rect.topRight());
+ QPointF outsideTopLeft = transform().map(rect.topLeft());
+ QPointF insideBottomLeft = transform().map(insideRect.bottomLeft());
+ QPointF insideTopLeft = transform().map(insideRect.topLeft());
+ QPointF insideTopRight = transform().map(insideRect.topRight());
+ QPointF insideBottomRight = transform().map(insideRect.bottomRight());
+
+ // Outside
+ coordinates[0] = outsideBottomLeft.x();
+ coordinates[1] = outsideBottomLeft.y();
+ coordinates[2] = outsideBottomRight.x();
+ coordinates[3] = outsideBottomRight.y();
+ coordinates[4] = outsideTopRight.x();
+ coordinates[5] = outsideTopRight.y();
+ coordinates[6] = outsideTopLeft.x();
+ coordinates[7] = outsideTopLeft.y();
+ // Inside
+ coordinates[8] = insideBottomLeft.x();
+ coordinates[9] = insideBottomLeft.y();
+ coordinates[10] = insideTopLeft.x();
+ coordinates[11] = insideTopLeft.y();
+ coordinates[12] = insideTopRight.x();
+ coordinates[13] = insideTopRight.y();
+ coordinates[14] = insideBottomRight.x();
+ coordinates[15] = insideBottomRight.y();
+
+ vgAppendPathData(path, 9, squaredBorderCommands, coordinates.constData());
+ }
+ } else if (radius < qMax(borderWidth, borderHeight)){
+ // rounded outside, squared inside
+ // Create command list
+ static const VGubyte roundedRectCommands[] = {
+ VG_MOVE_TO_ABS,
+ VG_HLINE_TO_REL,
+ VG_SCCWARC_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_SCCWARC_TO_REL,
+ VG_HLINE_TO_REL,
+ VG_SCCWARC_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_SCCWARC_TO_REL,
+ VG_MOVE_TO_ABS,
+ VG_VLINE_TO_REL,
+ VG_HLINE_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_CLOSE_PATH
+ };
+
+ // Ajust for OpenVG's usage or radius
+ float adjustedRadius = radius * 2;
+
+ // Create command data
+ QVector<VGfloat> coordinates(31);
+ // Outside Rounded Rect
+ coordinates[0] = rect.x() + adjustedRadius / 2;
+ coordinates[1] = rect.y();
+
+ coordinates[2] = rect.width() - adjustedRadius;
+
+ coordinates[3] = adjustedRadius / 2;
+ coordinates[4] = adjustedRadius / 2;
+ coordinates[5] = 0;
+ coordinates[6] = adjustedRadius / 2;
+ coordinates[7] = adjustedRadius / 2;
+
+ coordinates[8] = rect.height() - adjustedRadius;
+
+ coordinates[9] = adjustedRadius / 2;
+ coordinates[10] = adjustedRadius / 2;
+ coordinates[11] = 0;
+ coordinates[12] = -adjustedRadius / 2;
+ coordinates[13] = adjustedRadius / 2;
+
+ coordinates[14] = -(rect.width() - adjustedRadius);
+
+ coordinates[15] = adjustedRadius / 2;
+ coordinates[16] = adjustedRadius / 2;
+ coordinates[17] = 0;
+ coordinates[18] = -adjustedRadius / 2;
+ coordinates[19] = -adjustedRadius / 2;
+
+ coordinates[20] = -(rect.height() - adjustedRadius);
+
+ coordinates[21] = adjustedRadius / 2;
+ coordinates[22] = adjustedRadius / 2;
+ coordinates[23] = 0;
+ coordinates[24] = adjustedRadius / 2;
+ coordinates[25] = -adjustedRadius / 2;
+
+ // Inside Square (opposite direction)
+ coordinates[26] = rect.x() + borderWidth;
+ coordinates[27] = rect.y() + borderHeight;
+ coordinates[28] = rect.height() - (borderHeight * 2);
+ coordinates[29] = rect.width() - (borderWidth * 2);
+ coordinates[30] = -(rect.height() - (borderHeight * 2));
+
+ vgAppendPathData(path, 14, roundedRectCommands, coordinates.constData());
+ } else {
+ // rounded outside, rounded inside
+
+ static const VGubyte roundedBorderCommands[] = {
+ // Outer
+ VG_MOVE_TO_ABS,
+ VG_HLINE_TO_REL,
+ VG_SCCWARC_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_SCCWARC_TO_REL,
+ VG_HLINE_TO_REL,
+ VG_SCCWARC_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_SCCWARC_TO_REL,
+ // Inner
+ VG_MOVE_TO_ABS,
+ VG_SCWARC_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_SCWARC_TO_REL,
+ VG_HLINE_TO_REL,
+ VG_SCWARC_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_SCWARC_TO_REL,
+ VG_HLINE_TO_REL,
+ VG_CLOSE_PATH
+ };
+
+ // Adjust for OpenVG's usage or radius
+ float adjustedRadius = radius * 2;
+ float adjustedInnerRadius = (radius - qMax(borderWidth, borderHeight)) * 2;
+
+ // Create command data
+ QVector<VGfloat> coordinates(52);
+
+ // Outer
+ coordinates[0] = rect.x() + adjustedRadius / 2;
+ coordinates[1] = rect.y();
+
+ coordinates[2] = rect.width() - adjustedRadius;
+
+ coordinates[3] = adjustedRadius / 2;
+ coordinates[4] = adjustedRadius / 2;
+ coordinates[5] = 0;
+ coordinates[6] = adjustedRadius / 2;
+ coordinates[7] = adjustedRadius / 2;
+
+ coordinates[8] = rect.height() - adjustedRadius;
+
+ coordinates[9] = adjustedRadius / 2;
+ coordinates[10] = adjustedRadius / 2;
+ coordinates[11] = 0;
+ coordinates[12] = -adjustedRadius / 2;
+ coordinates[13] = adjustedRadius / 2;
+
+ coordinates[14] = -(rect.width() - adjustedRadius);
+
+ coordinates[15] = adjustedRadius / 2;
+ coordinates[16] = adjustedRadius / 2;
+ coordinates[17] = 0;
+ coordinates[18] = -adjustedRadius / 2;
+ coordinates[19] = -adjustedRadius / 2;
+
+ coordinates[20] = -(rect.height() - adjustedRadius);
+
+ coordinates[21] = adjustedRadius / 2;
+ coordinates[22] = adjustedRadius / 2;
+ coordinates[23] = 0;
+ coordinates[24] = adjustedRadius / 2;
+ coordinates[25] = -adjustedRadius / 2;
+
+ // Inner
+ coordinates[26] = rect.width() - (adjustedInnerRadius / 2 + borderWidth);
+ coordinates[27] = rect.height() - borderHeight;
+
+ coordinates[28] = adjustedInnerRadius / 2;
+ coordinates[29] = adjustedInnerRadius / 2;
+ coordinates[30] = 0;
+ coordinates[31] = adjustedInnerRadius / 2;
+ coordinates[32] = -adjustedInnerRadius / 2;
+
+ coordinates[33] = -((rect.height() - borderHeight * 2) - adjustedInnerRadius);
+
+ coordinates[34] = adjustedInnerRadius / 2;
+ coordinates[35] = adjustedInnerRadius / 2;
+ coordinates[36] = 0;
+ coordinates[37] = -adjustedInnerRadius / 2;
+ coordinates[38] = -adjustedInnerRadius / 2;
+
+ coordinates[39] = -((rect.width() - borderWidth * 2) - adjustedInnerRadius);
+
+ coordinates[40] = adjustedInnerRadius / 2;
+ coordinates[41] = adjustedInnerRadius / 2;
+ coordinates[42] = 0;
+ coordinates[43] = -adjustedInnerRadius / 2;
+ coordinates[44] = adjustedInnerRadius / 2;
+
+ coordinates[45] = (rect.height() - borderHeight * 2) - adjustedInnerRadius;
+
+ coordinates[46] = adjustedInnerRadius / 2;
+ coordinates[47] = adjustedInnerRadius / 2;
+ coordinates[48] = 0;
+ coordinates[49] = adjustedInnerRadius / 2;
+ coordinates[50] = adjustedInnerRadius / 2;
+
+ coordinates[51] = (rect.width() - borderWidth * 2) - adjustedInnerRadius;
+
+ vgAppendPathData(path, 19, roundedBorderCommands, coordinates.constData());
+ }
+}
+
+void QSGOpenVGInternalRectangleNode::generateRectangleAndBorderPaths(const QRectF &rect, float penWidth, float radius, VGPath inside, VGPath outside) const
+{
+ //Borders can not be more than half the height/width of a rect
+ float borderWidth = qMin(penWidth, (float)rect.width() * 0.5f);
+ float borderHeight = qMin(penWidth, (float)rect.height() * 0.5f);
+
+ //Radius should never exceeds half of the width or half of the height
+ float adjustedRadius = qMin((float)qMin(rect.width(), rect.height()) * 0.5f, radius);
+
+ QRectF innerRect = rect;
+ innerRect.adjust(borderWidth, borderHeight, -borderWidth, -borderHeight);
+
+ if (radius == 0) {
+ // Regular rect with border
+ generateRectanglePath(innerRect, 0, inside);
+ generateBorderPath(rect, borderWidth, borderHeight, 0, outside);
+ } else {
+ // Rounded Rect with border
+ float innerRadius = radius - qMax(borderWidth, borderHeight);
+ if (innerRadius < 0)
+ innerRadius = 0.0f;
+
+ generateRectanglePath(innerRect, innerRadius, inside);
+ generateBorderPath(rect, borderWidth, borderHeight, adjustedRadius, outside);
+ }
+}
diff --git a/src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.h b/src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.h
new file mode 100644
index 0000000000..e8d25c94f8
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvginternalrectanglenode.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGINTERNALRECTANGLENODE_H
+#define QSGOPENVGINTERNALRECTANGLENODE_H
+
+#include <private/qsgadaptationlayer_p.h>
+#include "qsgopenvgrenderable.h"
+#include "qopenvgoffscreensurface.h"
+
+#include <VG/openvg.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGOpenVGInternalRectangleNode : public QSGInternalRectangleNode, public QSGOpenVGRenderable
+{
+public:
+ QSGOpenVGInternalRectangleNode();
+ ~QSGOpenVGInternalRectangleNode();
+
+ void setRect(const QRectF &rect) override;
+ void setColor(const QColor &color) override;
+ void setPenColor(const QColor &color) override;
+ void setPenWidth(qreal width) override;
+ void setGradientStops(const QGradientStops &stops) override;
+ void setRadius(qreal radius) override;
+ void setAligned(bool aligned) override;
+ void update() override;
+
+ void render() override;
+ void setOpacity(float opacity) override;
+ void setTransform(const QOpenVGMatrix &transform) override;
+
+private:
+ void createVGResources();
+ void destroyVGResources();
+
+ void generateRectanglePath(const QRectF &rect, float radius, VGPath path) const;
+ void generateRectangleAndBorderPaths(const QRectF &rect, float penWidth, float radius, VGPath inside, VGPath outside) const;
+ void generateBorderPath(const QRectF &rect, float borderWidth, float borderHeight, float radius, VGPath path) const;
+
+ bool m_pathDirty = true;
+ bool m_fillDirty = true;
+ bool m_strokeDirty = true;
+
+ QRectF m_rect;
+ QColor m_fillColor;
+ QColor m_strokeColor;
+ qreal m_penWidth = 0.0;
+ qreal m_radius = 0.0;
+ bool m_aligned = false;
+ QGradientStops m_gradientStops;
+
+ VGPath m_rectanglePath;
+ VGPath m_borderPath;
+ VGPaint m_rectanglePaint;
+ VGPaint m_borderPaint;
+
+ QOpenVGOffscreenSurface *m_offscreenSurface = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGINTERNALRECTANGLENODE_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvglayer.cpp b/src/plugins/scenegraph/openvg/qsgopenvglayer.cpp
new file mode 100644
index 0000000000..047539d431
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvglayer.cpp
@@ -0,0 +1,315 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvglayer.h"
+#include "qsgopenvgrenderer_p.h"
+#include "qsgopenvgcontext_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGLayer::QSGOpenVGLayer(QSGRenderContext *renderContext)
+ : m_item(nullptr)
+ , m_renderer(nullptr)
+ , m_device_pixel_ratio(1)
+ , m_mirrorHorizontal(false)
+ , m_mirrorVertical(false)
+ , m_live(true)
+ , m_grab(true)
+ , m_recursive(false)
+ , m_dirtyTexture(true)
+ , m_offscreenSurface(nullptr)
+ , m_secondaryOffscreenSurface(nullptr)
+{
+ m_context = static_cast<QSGOpenVGRenderContext*>(renderContext);
+}
+
+QSGOpenVGLayer::~QSGOpenVGLayer()
+{
+ invalidated();
+}
+
+int QSGOpenVGLayer::textureId() const
+{
+ if (m_offscreenSurface)
+ return static_cast<int>(m_offscreenSurface->image());
+ else
+ return 0;
+}
+
+QSize QSGOpenVGLayer::textureSize() const
+{
+ if (m_offscreenSurface) {
+ return m_offscreenSurface->size();
+ }
+
+ return QSize();
+}
+
+bool QSGOpenVGLayer::hasAlphaChannel() const
+{
+ return true;
+}
+
+bool QSGOpenVGLayer::hasMipmaps() const
+{
+ return false;
+}
+
+void QSGOpenVGLayer::bind()
+{
+}
+
+bool QSGOpenVGLayer::updateTexture()
+{
+ bool doGrab = (m_live || m_grab) && m_dirtyTexture;
+ if (doGrab)
+ grab();
+ if (m_grab)
+ emit scheduledUpdateCompleted();
+ m_grab = false;
+ return doGrab;
+}
+
+void QSGOpenVGLayer::setItem(QSGNode *item)
+{
+ if (item == m_item)
+ return;
+ m_item = item;
+
+ if (m_live && !m_item) {
+ delete m_offscreenSurface;
+ delete m_secondaryOffscreenSurface;
+ m_offscreenSurface = nullptr;
+ m_secondaryOffscreenSurface = nullptr;
+ }
+
+ markDirtyTexture();
+}
+
+void QSGOpenVGLayer::setRect(const QRectF &rect)
+{
+ if (rect == m_rect)
+ return;
+ m_rect = rect;
+ markDirtyTexture();
+}
+
+void QSGOpenVGLayer::setSize(const QSize &size)
+{
+ if (size == m_size)
+ return;
+ m_size = size;
+
+ if (m_live && m_size.isNull()) {
+ delete m_offscreenSurface;
+ delete m_secondaryOffscreenSurface;
+ m_offscreenSurface = nullptr;
+ m_secondaryOffscreenSurface = nullptr;
+ }
+
+ markDirtyTexture();
+}
+
+void QSGOpenVGLayer::scheduleUpdate()
+{
+ if (m_grab)
+ return;
+ m_grab = true;
+ if (m_dirtyTexture) {
+ emit updateRequested();
+ }
+}
+
+QImage QSGOpenVGLayer::toImage() const
+{
+ return m_offscreenSurface->readbackQImage();
+}
+
+void QSGOpenVGLayer::setLive(bool live)
+{
+ if (live == m_live)
+ return;
+ m_live = live;
+
+ if (m_live && (!m_item || m_size.isNull())) {
+ delete m_offscreenSurface;
+ delete m_secondaryOffscreenSurface;
+ m_offscreenSurface = nullptr;
+ m_secondaryOffscreenSurface = nullptr;
+ }
+
+ markDirtyTexture();
+}
+
+void QSGOpenVGLayer::setRecursive(bool recursive)
+{
+ m_recursive = recursive;
+}
+
+void QSGOpenVGLayer::setFormat(uint format)
+{
+ Q_UNUSED(format)
+}
+
+void QSGOpenVGLayer::setHasMipmaps(bool mipmap)
+{
+ Q_UNUSED(mipmap)
+}
+
+void QSGOpenVGLayer::setDevicePixelRatio(qreal ratio)
+{
+ m_device_pixel_ratio = ratio;
+}
+
+void QSGOpenVGLayer::setMirrorHorizontal(bool mirror)
+{
+ if (m_mirrorHorizontal == mirror)
+ return;
+ m_mirrorHorizontal = mirror;
+ markDirtyTexture();
+}
+
+void QSGOpenVGLayer::setMirrorVertical(bool mirror)
+{
+ if (m_mirrorVertical == mirror)
+ return;
+ m_mirrorVertical = mirror;
+ markDirtyTexture();
+}
+
+void QSGOpenVGLayer::markDirtyTexture()
+{
+ m_dirtyTexture = true;
+ if (m_live || m_grab) {
+ emit updateRequested();
+ }
+}
+
+void QSGOpenVGLayer::invalidated()
+{
+ delete m_offscreenSurface;
+ delete m_secondaryOffscreenSurface;
+ delete m_renderer;
+ m_renderer = nullptr;
+ m_offscreenSurface = nullptr;
+ m_secondaryOffscreenSurface = nullptr;
+}
+
+void QSGOpenVGLayer::grab()
+{
+ if (!m_item || m_size.isNull()) {
+ delete m_offscreenSurface;
+ delete m_secondaryOffscreenSurface;
+ m_offscreenSurface = nullptr;
+ m_secondaryOffscreenSurface = nullptr;
+ m_dirtyTexture = false;
+ return;
+ }
+ QSGNode *root = m_item;
+ while (root->firstChild() && root->type() != QSGNode::RootNodeType)
+ root = root->firstChild();
+ if (root->type() != QSGNode::RootNodeType)
+ return;
+
+ if (!m_renderer) {
+ m_renderer = new QSGOpenVGRenderer(m_context);
+ connect(m_renderer, SIGNAL(sceneGraphChanged()), this, SLOT(markDirtyTexture()));
+ }
+ m_renderer->setDevicePixelRatio(m_device_pixel_ratio);
+ m_renderer->setRootNode(static_cast<QSGRootNode *>(root));
+
+ bool deleteOffscreenSurfaceLater = false;
+ if (m_offscreenSurface == nullptr || m_offscreenSurface->size() != m_size ) {
+ if (m_recursive) {
+ deleteOffscreenSurfaceLater = true;
+ delete m_secondaryOffscreenSurface;
+ m_secondaryOffscreenSurface = new QOpenVGOffscreenSurface(m_size);
+ } else {
+ delete m_offscreenSurface;
+ delete m_secondaryOffscreenSurface;
+ m_offscreenSurface = new QOpenVGOffscreenSurface(m_size);
+ m_secondaryOffscreenSurface = nullptr;
+ }
+ }
+
+ if (m_recursive && !m_secondaryOffscreenSurface)
+ m_secondaryOffscreenSurface = new QOpenVGOffscreenSurface(m_size);
+
+ // Render texture.
+ root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip and opacity update.
+ m_renderer->nodeChanged(root, QSGNode::DirtyForceUpdate); // Force render list update.
+
+ m_dirtyTexture = false;
+
+ m_renderer->setDeviceRect(m_size);
+ m_renderer->setViewportRect(m_size);
+ QRect mirrored(m_mirrorHorizontal ? m_rect.right() * m_device_pixel_ratio : m_rect.left() * m_device_pixel_ratio,
+ m_mirrorVertical ? m_rect.top() * m_device_pixel_ratio : m_rect.bottom() * m_device_pixel_ratio,
+ m_mirrorHorizontal ? -m_rect.width() * m_device_pixel_ratio : m_rect.width() * m_device_pixel_ratio,
+ m_mirrorVertical ? m_rect.height() * m_device_pixel_ratio : -m_rect.height() * m_device_pixel_ratio);
+ m_renderer->setProjectionMatrixToRect(mirrored);
+ m_renderer->setClearColor(Qt::transparent);
+
+
+ if (m_recursive)
+ m_secondaryOffscreenSurface->makeCurrent();
+ else
+ m_offscreenSurface->makeCurrent();
+
+ m_renderer->renderScene();
+
+ // Make the previous surface and context active again
+ if (m_recursive) {
+ if (deleteOffscreenSurfaceLater) {
+ delete m_offscreenSurface;
+ m_offscreenSurface = new QOpenVGOffscreenSurface(m_size);
+ }
+ m_secondaryOffscreenSurface->doneCurrent();
+ qSwap(m_offscreenSurface, m_secondaryOffscreenSurface);
+ } else {
+ m_offscreenSurface->doneCurrent();
+ }
+
+ root->markDirty(QSGNode::DirtyForceUpdate); // Force matrix, clip, opacity and render list update.
+
+ if (m_recursive)
+ markDirtyTexture(); // Continuously update if 'live' and 'recursive'.
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvglayer.h b/src/plugins/scenegraph/openvg/qsgopenvglayer.h
new file mode 100644
index 0000000000..2af0bfb40f
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvglayer.h
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGLAYER_H
+#define QSGOPENVGLAYER_H
+
+#include <private/qsgadaptationlayer_p.h>
+#include <private/qsgcontext_p.h>
+
+#include "qopenvgcontext_p.h"
+#include "qopenvgoffscreensurface.h"
+
+QT_BEGIN_NAMESPACE
+
+class QSGOpenVGRenderer;
+class QSGOpenVGRenderContext;
+
+class QSGOpenVGLayer : public QSGLayer
+{
+public:
+ QSGOpenVGLayer(QSGRenderContext *renderContext);
+ ~QSGOpenVGLayer();
+
+ // QSGTexture interface
+public:
+ int textureId() const override;
+ QSize textureSize() const override;
+ bool hasAlphaChannel() const override;
+ bool hasMipmaps() const override;
+ void bind() override;
+
+ // QSGDynamicTexture interface
+public:
+ bool updateTexture() override;
+
+ // QSGLayer interface
+public:
+ void setItem(QSGNode *item) override;
+ void setRect(const QRectF &rect) override;
+ void setSize(const QSize &size) override;
+ void scheduleUpdate() override;
+ QImage toImage() const override;
+ void setLive(bool live) override;
+ void setRecursive(bool recursive) override;
+ void setFormat(uint format) override;
+ void setHasMipmaps(bool mipmap) override;
+ void setDevicePixelRatio(qreal ratio) override;
+ void setMirrorHorizontal(bool mirror) override;
+ void setMirrorVertical(bool mirror) override;
+
+public slots:
+ void markDirtyTexture() override;
+ void invalidated() override;
+
+private:
+ void grab();
+
+ QSGNode *m_item;
+ QSGOpenVGRenderContext *m_context;
+ QSGOpenVGRenderer *m_renderer;
+ QRectF m_rect;
+ QSize m_size;
+ qreal m_device_pixel_ratio;
+ bool m_mirrorHorizontal;
+ bool m_mirrorVertical;
+ bool m_live;
+ bool m_grab;
+ bool m_recursive;
+ bool m_dirtyTexture;
+
+ QOpenVGOffscreenSurface *m_offscreenSurface;
+ QOpenVGOffscreenSurface *m_secondaryOffscreenSurface;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGLAYER_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgnodevisitor.cpp b/src/plugins/scenegraph/openvg/qsgopenvgnodevisitor.cpp
new file mode 100644
index 0000000000..8aa179f705
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgnodevisitor.cpp
@@ -0,0 +1,275 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvgnodevisitor.h"
+#include "qsgopenvginternalrectanglenode.h"
+#include "qsgopenvginternalimagenode.h"
+#include "qsgopenvgpublicnodes.h"
+#include "qsgopenvgglyphnode_p.h"
+#include "qsgopenvgpainternode.h"
+#include "qsgopenvgspritenode.h"
+#include "qsgopenvgrenderable.h"
+
+#include "qopenvgcontext_p.h"
+
+#include <QtQuick/qsgsimplerectnode.h>
+#include <QtQuick/qsgsimpletexturenode.h>
+#include <QtQuick/qsgrendernode.h>
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGNodeVisitor::QSGOpenVGNodeVisitor()
+{
+ //Store the current matrix state
+ QVector<VGfloat> matrix(9);
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
+ vgGetMatrix(matrix.data());
+
+ m_transformStack.push(QOpenVGMatrix(matrix.constData()));
+
+ // Opacity
+ m_opacityState.push(1.0f);
+}
+
+bool QSGOpenVGNodeVisitor::visit(QSGTransformNode *node)
+{
+ const QVector<float> matrixData = { node->matrix().constData()[0], node->matrix().constData()[1], node->matrix().constData()[3],
+ node->matrix().constData()[4], node->matrix().constData()[5], node->matrix().constData()[7],
+ node->matrix().constData()[12], node->matrix().constData()[13], node->matrix().constData()[15] };
+ const QOpenVGMatrix matrix2d(matrixData.constData());
+
+ m_transformStack.push(m_transformStack.top() * matrix2d);
+ return true;
+}
+
+void QSGOpenVGNodeVisitor::endVisit(QSGTransformNode *)
+{
+ m_transformStack.pop();
+}
+
+bool QSGOpenVGNodeVisitor::visit(QSGClipNode *node)
+{
+ VGMaskOperation maskOperation = VG_INTERSECT_MASK;
+ if (m_clipStack.count() == 0) {
+ vgSeti(VG_MASKING, VG_TRUE);
+ vgMask(0,VG_FILL_MASK, 0, 0, VG_MAXINT, VG_MAXINT);
+ }
+
+ // Render clip node geometry to mask
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
+ vgLoadIdentity();
+ VGPath clipPath = generateClipPath(node->clipRect());
+ vgRenderToMask(clipPath, VG_FILL_PATH, maskOperation);
+
+ m_clipStack.push(clipPath);
+
+ return true;
+}
+
+void QSGOpenVGNodeVisitor::endVisit(QSGClipNode *)
+{
+ // Remove clip node geometry from mask
+ auto clipState = m_clipStack.pop();
+ vgDestroyPath(clipState);
+
+ if (m_clipStack.count() == 0) {
+ vgSeti(VG_MASKING, VG_FALSE);
+ } else {
+ // Recreate the mask
+ vgMask(0,VG_FILL_MASK, 0, 0, VG_MAXINT, VG_MAXINT);
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
+ vgLoadIdentity();
+ for (auto path : qAsConst(m_clipStack)) {
+ vgRenderToMask(path, VG_FILL_PATH, VG_INTERSECT_MASK);
+ }
+ }
+}
+
+bool QSGOpenVGNodeVisitor::visit(QSGGeometryNode *node)
+{
+ if (QSGSimpleRectNode *rectNode = dynamic_cast<QSGSimpleRectNode *>(node)) {
+ // TODO: Try and render the QSGSimpleRectNode
+ Q_UNUSED(rectNode)
+ return false;
+ } else if (QSGSimpleTextureNode *tn = dynamic_cast<QSGSimpleTextureNode *>(node)) {
+ // TODO: Try and render the QSGSimpleTextureNode
+ Q_UNUSED(tn)
+ return false;
+ } else if (QSGOpenVGNinePatchNode *nn = dynamic_cast<QSGOpenVGNinePatchNode *>(node)) {
+ renderRenderableNode(nn);
+ } else if (QSGOpenVGRectangleNode *rn = dynamic_cast<QSGOpenVGRectangleNode *>(node)) {
+ renderRenderableNode(rn);
+ } else if (QSGOpenVGImageNode *n = dynamic_cast<QSGOpenVGImageNode *>(node)) {
+ renderRenderableNode(n);
+ } else {
+ // We dont know, so skip
+ return false;
+ }
+
+ return true;
+}
+
+void QSGOpenVGNodeVisitor::endVisit(QSGGeometryNode *)
+{
+}
+
+bool QSGOpenVGNodeVisitor::visit(QSGOpacityNode *node)
+{
+ m_opacityState.push(m_opacityState.top() * node->opacity());
+ return true;
+}
+
+void QSGOpenVGNodeVisitor::endVisit(QSGOpacityNode *)
+{
+ m_opacityState.pop();
+}
+
+bool QSGOpenVGNodeVisitor::visit(QSGInternalImageNode *node)
+{
+ renderRenderableNode(static_cast<QSGOpenVGInternalImageNode*>(node));
+ return true;
+}
+
+void QSGOpenVGNodeVisitor::endVisit(QSGInternalImageNode *)
+{
+}
+
+bool QSGOpenVGNodeVisitor::visit(QSGPainterNode *node)
+{
+ renderRenderableNode(static_cast<QSGOpenVGPainterNode*>(node));
+ return true;
+}
+
+void QSGOpenVGNodeVisitor::endVisit(QSGPainterNode *)
+{
+}
+
+bool QSGOpenVGNodeVisitor::visit(QSGInternalRectangleNode *node)
+{
+ renderRenderableNode(static_cast<QSGOpenVGInternalRectangleNode*>(node));
+ return true;
+}
+
+void QSGOpenVGNodeVisitor::endVisit(QSGInternalRectangleNode *)
+{
+}
+
+bool QSGOpenVGNodeVisitor::visit(QSGGlyphNode *node)
+{
+ renderRenderableNode(static_cast<QSGOpenVGGlyphNode*>(node));
+ return true;
+}
+
+void QSGOpenVGNodeVisitor::endVisit(QSGGlyphNode *)
+{
+}
+
+bool QSGOpenVGNodeVisitor::visit(QSGRootNode *)
+{
+ return true;
+}
+
+void QSGOpenVGNodeVisitor::endVisit(QSGRootNode *)
+{
+}
+
+bool QSGOpenVGNodeVisitor::visit(QSGSpriteNode *node)
+{
+ renderRenderableNode(static_cast<QSGOpenVGSpriteNode*>(node));
+ return true;
+}
+
+void QSGOpenVGNodeVisitor::endVisit(QSGSpriteNode *)
+{
+}
+
+bool QSGOpenVGNodeVisitor::visit(QSGRenderNode *)
+{
+ return true;
+}
+
+void QSGOpenVGNodeVisitor::endVisit(QSGRenderNode *)
+{
+}
+
+VGPath QSGOpenVGNodeVisitor::generateClipPath(const QRectF &rect) const
+{
+ VGPath clipPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
+ VG_PATH_CAPABILITY_APPEND_TO);
+
+ // Create command list
+ static const VGubyte rectCommands[] = {
+ VG_MOVE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_CLOSE_PATH
+ };
+
+ const QOpenVGMatrix &transform = m_transformStack.top();
+
+ // Create command data
+ QVector<VGfloat> coordinates(8);
+ const QPointF topLeft = transform.map(rect.topLeft());
+ const QPointF topRight = transform.map(rect.topRight());
+ const QPointF bottomLeft = transform.map(rect.bottomLeft());
+ const QPointF bottomRight = transform.map(rect.bottomRight());
+ coordinates[0] = bottomLeft.x();
+ coordinates[1] = bottomLeft.y();
+ coordinates[2] = bottomRight.x();
+ coordinates[3] = bottomRight.y();
+ coordinates[4] = topRight.x();
+ coordinates[5] = topRight.y();
+ coordinates[6] = topLeft.x();
+ coordinates[7] = topLeft.y();
+
+ vgAppendPathData(clipPath, 5, rectCommands, coordinates.constData());
+ return clipPath;
+}
+
+void QSGOpenVGNodeVisitor::renderRenderableNode(QSGOpenVGRenderable *node)
+{
+ if (!node)
+ return;
+ node->setTransform(m_transformStack.top());
+ node->setOpacity(m_opacityState.top());
+ node->render();
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgnodevisitor.h b/src/plugins/scenegraph/openvg/qsgopenvgnodevisitor.h
new file mode 100644
index 0000000000..4805d63024
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgnodevisitor.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGNODEVISITOR_H
+#define QSGOPENVGNODEVISITOR_H
+
+#include <private/qsgadaptationlayer_p.h>
+#include <QtCore/QStack>
+
+#include "qopenvgmatrix.h"
+
+#include <VG/openvg.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGOpenVGRenderable;
+class QSGOpenVGNodeVisitor : public QSGNodeVisitorEx
+{
+public:
+ QSGOpenVGNodeVisitor();
+
+ bool visit(QSGTransformNode *) override;
+ void endVisit(QSGTransformNode *) override;
+ bool visit(QSGClipNode *) override;
+ void endVisit(QSGClipNode *) override;
+ bool visit(QSGGeometryNode *) override;
+ void endVisit(QSGGeometryNode *) override;
+ bool visit(QSGOpacityNode *) override;
+ void endVisit(QSGOpacityNode *) override;
+ bool visit(QSGInternalImageNode *) override;
+ void endVisit(QSGInternalImageNode *) override;
+ bool visit(QSGPainterNode *) override;
+ void endVisit(QSGPainterNode *) override;
+ bool visit(QSGInternalRectangleNode *) override;
+ void endVisit(QSGInternalRectangleNode *) override;
+ bool visit(QSGGlyphNode *) override;
+ void endVisit(QSGGlyphNode *) override;
+ bool visit(QSGRootNode *) override;
+ void endVisit(QSGRootNode *) override;
+ bool visit(QSGSpriteNode *) override;
+ void endVisit(QSGSpriteNode *) override;
+ bool visit(QSGRenderNode *) override;
+ void endVisit(QSGRenderNode *) override;
+
+private:
+ VGPath generateClipPath(const QRectF &rect) const;
+ void renderRenderableNode(QSGOpenVGRenderable *node);
+
+ QStack<QOpenVGMatrix> m_transformStack;
+ QStack<float> m_opacityState;
+ QStack<VGPath> m_clipStack;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGNODEVISITOR_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgpainternode.cpp b/src/plugins/scenegraph/openvg/qsgopenvgpainternode.cpp
new file mode 100644
index 0000000000..fb68ebf2bc
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgpainternode.cpp
@@ -0,0 +1,253 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvgpainternode.h"
+#include "qsgopenvgtexture.h"
+#include <qmath.h>
+
+#include <QtGui/QPainter>
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGPainterNode::QSGOpenVGPainterNode(QQuickPaintedItem *item)
+ : m_preferredRenderTarget(QQuickPaintedItem::Image)
+ , m_item(item)
+ , m_texture(nullptr)
+ , m_dirtyContents(false)
+ , m_opaquePainting(false)
+ , m_linear_filtering(false)
+ , m_smoothPainting(false)
+ , m_fillColor(Qt::transparent)
+ , m_contentsScale(1.0)
+ , m_dirtyGeometry(false)
+{
+ // Set Dummy material and geometry to avoid asserts
+ setMaterial((QSGMaterial*)1);
+ setGeometry((QSGGeometry*)1);
+}
+
+QSGOpenVGPainterNode::~QSGOpenVGPainterNode()
+{
+ delete m_texture;
+}
+
+void QSGOpenVGPainterNode::setPreferredRenderTarget(QQuickPaintedItem::RenderTarget)
+{
+}
+
+void QSGOpenVGPainterNode::setSize(const QSize &size)
+{
+ if (size == m_size)
+ return;
+
+ m_size = size;
+
+ m_dirtyGeometry = true;
+}
+
+void QSGOpenVGPainterNode::setDirty(const QRect &dirtyRect)
+{
+ m_dirtyContents = true;
+ m_dirtyRect = dirtyRect;
+ markDirty(DirtyMaterial);
+}
+
+void QSGOpenVGPainterNode::setOpaquePainting(bool opaque)
+{
+ if (opaque == m_opaquePainting)
+ return;
+
+ m_opaquePainting = opaque;
+}
+
+void QSGOpenVGPainterNode::setLinearFiltering(bool linearFiltering)
+{
+ if (linearFiltering == m_linear_filtering)
+ return;
+
+ m_linear_filtering = linearFiltering;
+}
+
+void QSGOpenVGPainterNode::setMipmapping(bool)
+{
+
+}
+
+void QSGOpenVGPainterNode::setSmoothPainting(bool s)
+{
+ if (s == m_smoothPainting)
+ return;
+
+ m_smoothPainting = s;
+}
+
+void QSGOpenVGPainterNode::setFillColor(const QColor &c)
+{
+ if (c == m_fillColor)
+ return;
+
+ m_fillColor = c;
+ markDirty(DirtyMaterial);
+}
+
+void QSGOpenVGPainterNode::setContentsScale(qreal s)
+{
+ if (s == m_contentsScale)
+ return;
+
+ m_contentsScale = s;
+ markDirty(DirtyMaterial);
+}
+
+void QSGOpenVGPainterNode::setFastFBOResizing(bool)
+{
+}
+
+void QSGOpenVGPainterNode::setTextureSize(const QSize &size)
+{
+ if (size == m_textureSize)
+ return;
+
+ m_textureSize = size;
+ m_dirtyGeometry = true;
+}
+
+QImage QSGOpenVGPainterNode::toImage() const
+{
+ return m_image;
+}
+
+void QSGOpenVGPainterNode::update()
+{
+ if (m_dirtyGeometry) {
+ if (!m_opaquePainting)
+ m_image = QImage(m_size, QImage::Format_ARGB32_Premultiplied);
+ else
+ m_image = QImage(m_size, QImage::Format_RGB32);
+ }
+
+ if (m_dirtyContents)
+ paint();
+
+ m_dirtyGeometry = false;
+ m_dirtyContents = false;
+}
+
+QSGTexture *QSGOpenVGPainterNode::texture() const
+{
+ return m_texture;
+}
+
+void QSGOpenVGPainterNode::render()
+{
+ if (!m_texture)
+ return;
+
+ // Set Draw Mode
+ if (opacity() < 1.0) {
+ //Transparent
+ vgSetPaint(opacityPaint(), VG_FILL_PATH);
+ vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
+ } else {
+ vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
+ }
+
+ if (m_linear_filtering)
+ vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_BETTER);
+ else
+ vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_NONANTIALIASED);
+
+ // Set Transform
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
+ vgLoadMatrix(transform().constData());
+
+ vgDrawImage(static_cast<VGImage>(m_texture->textureId()));
+}
+
+void QSGOpenVGPainterNode::paint()
+{
+ QRect dirtyRect = m_dirtyRect.isNull() ? QRect(0, 0, m_size.width(), m_size.height()) : m_dirtyRect;
+
+ QPainter painter;
+
+ painter.begin(&m_image);
+ if (m_smoothPainting) {
+ painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
+ }
+
+ QRect clipRect;
+
+ if (m_contentsScale == 1) {
+ qreal scaleX = m_textureSize.width() / (qreal) m_size.width();
+ qreal scaleY = m_textureSize.height() / (qreal) m_size.height();
+ painter.scale(scaleX, scaleY);
+ clipRect = dirtyRect;
+ } else {
+ painter.scale(m_contentsScale, m_contentsScale);
+
+ QRect sclip(qFloor(dirtyRect.x()/m_contentsScale),
+ qFloor(dirtyRect.y()/m_contentsScale),
+ qCeil(dirtyRect.width()/m_contentsScale+dirtyRect.x()/m_contentsScale-qFloor(dirtyRect.x()/m_contentsScale)),
+ qCeil(dirtyRect.height()/m_contentsScale+dirtyRect.y()/m_contentsScale-qFloor(dirtyRect.y()/m_contentsScale)));
+
+ clipRect = sclip;
+ }
+
+ if (!m_dirtyRect.isNull())
+ painter.setClipRect(clipRect);
+
+ painter.setCompositionMode(QPainter::CompositionMode_Source);
+ painter.fillRect(clipRect, m_fillColor);
+ painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
+
+ m_item->paint(&painter);
+ painter.end();
+
+ m_dirtyRect = QRect();
+
+ if (m_texture)
+ delete m_texture;
+
+ uint textureFlags = m_opaquePainting ? 0 : QSGRenderContext::CreateTexture_Alpha;
+ m_texture = new QSGOpenVGTexture(m_image, textureFlags);
+}
+
+QT_END_NAMESPACE
+
+
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgpainternode.h b/src/plugins/scenegraph/openvg/qsgopenvgpainternode.h
new file mode 100644
index 0000000000..1fe992115f
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgpainternode.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGPAINTERNODE_H
+#define QSGOPENVGPAINTERNODE_H
+
+#include <private/qsgadaptationlayer_p.h>
+#include <QtQuick/QQuickPaintedItem>
+#include "qsgopenvgrenderable.h"
+
+QT_BEGIN_NAMESPACE
+
+class QSGOpenVGTexture;
+
+class QSGOpenVGPainterNode : public QSGPainterNode, public QSGOpenVGRenderable
+{
+public:
+ QSGOpenVGPainterNode(QQuickPaintedItem *item);
+ ~QSGOpenVGPainterNode();
+
+ void setPreferredRenderTarget(QQuickPaintedItem::RenderTarget target) override;
+ void setSize(const QSize &size) override;
+ void setDirty(const QRect &dirtyRect) override;
+ void setOpaquePainting(bool opaque) override;
+ void setLinearFiltering(bool linearFiltering) override;
+ void setMipmapping(bool mipmapping) override;
+ void setSmoothPainting(bool s) override;
+ void setFillColor(const QColor &c) override;
+ void setContentsScale(qreal s) override;
+ void setFastFBOResizing(bool dynamic) override;
+ void setTextureSize(const QSize &size) override;
+ QImage toImage() const override;
+ void update() override;
+ QSGTexture *texture() const override;
+
+ void render() override;
+ void paint();
+
+private:
+ QQuickPaintedItem::RenderTarget m_preferredRenderTarget;
+
+ QQuickPaintedItem *m_item;
+ QSGOpenVGTexture *m_texture;
+ QImage m_image;
+
+ QSize m_size;
+ bool m_dirtyContents;
+ QRect m_dirtyRect;
+ bool m_opaquePainting;
+ bool m_linear_filtering;
+ bool m_smoothPainting;
+ QColor m_fillColor;
+ qreal m_contentsScale;
+ QSize m_textureSize;
+
+ bool m_dirtyGeometry;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGPAINTERNODE_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgpublicnodes.cpp b/src/plugins/scenegraph/openvg/qsgopenvgpublicnodes.cpp
new file mode 100644
index 0000000000..e45b79706b
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgpublicnodes.cpp
@@ -0,0 +1,398 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvgpublicnodes.h"
+#include "qsgopenvghelpers.h"
+#include <VG/openvg.h>
+#include <QtGui/QPixmap>
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGRectangleNode::QSGOpenVGRectangleNode()
+{
+ // Set Dummy material and geometry to avoid asserts
+ setMaterial((QSGMaterial*)1);
+ setGeometry((QSGGeometry*)1);
+
+ m_rectPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
+ VG_PATH_CAPABILITY_APPEND_TO);
+ m_rectPaint = vgCreatePaint();
+}
+
+QSGOpenVGRectangleNode::~QSGOpenVGRectangleNode()
+{
+ vgDestroyPaint(m_rectPaint);
+ vgDestroyPath(m_rectPath);
+}
+
+void QSGOpenVGRectangleNode::setRect(const QRectF &rect)
+{
+ m_rect = rect;
+ m_pathDirty = true;
+ markDirty(DirtyMaterial);
+}
+
+QRectF QSGOpenVGRectangleNode::rect() const
+{
+ return m_rect;
+}
+
+void QSGOpenVGRectangleNode::setColor(const QColor &color)
+{
+ m_color = color;
+ m_paintDirty = true;
+ markDirty(DirtyMaterial);
+}
+
+QColor QSGOpenVGRectangleNode::color() const
+{
+ return m_color;
+}
+
+void QSGOpenVGRectangleNode::setTransform(const QOpenVGMatrix &transform)
+{
+ // if there transform matrix is not affine, regenerate the path
+ if (transform.isAffine())
+ m_pathDirty = true;
+ markDirty(DirtyGeometry);
+
+ QSGOpenVGRenderable::setTransform(transform);
+}
+
+void QSGOpenVGRectangleNode::render()
+{
+ // Set Transform
+ if (transform().isAffine()) {
+ // Use current transform matrix
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
+ vgLoadMatrix(transform().constData());
+ } else {
+ // map the path's to handle the perspective matrix
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
+ vgLoadIdentity();
+ }
+
+ if (m_pathDirty) {
+ vgClearPath(m_rectPath, VG_PATH_CAPABILITY_APPEND_TO);
+
+ if (transform().isAffine()) {
+ // Create command list
+ static const VGubyte rectCommands[] = {
+ VG_MOVE_TO_ABS,
+ VG_HLINE_TO_REL,
+ VG_VLINE_TO_REL,
+ VG_HLINE_TO_REL,
+ VG_CLOSE_PATH
+ };
+
+ // Create command data
+ QVector<VGfloat> coordinates(5);
+ coordinates[0] = m_rect.x();
+ coordinates[1] = m_rect.y();
+ coordinates[2] = m_rect.width();
+ coordinates[3] = m_rect.height();
+ coordinates[4] = -m_rect.width();
+
+ vgAppendPathData(m_rectPath, 5, rectCommands, coordinates.constData());
+
+ } else {
+ // Pre-transform path
+ static const VGubyte rectCommands[] = {
+ VG_MOVE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_LINE_TO_ABS,
+ VG_CLOSE_PATH
+ };
+
+ QVector<VGfloat> coordinates(8);
+ const QPointF topLeft = transform().map(m_rect.topLeft());
+ const QPointF topRight = transform().map(m_rect.topRight());
+ const QPointF bottomLeft = transform().map(m_rect.bottomLeft());
+ const QPointF bottomRight = transform().map(m_rect.bottomRight());
+ coordinates[0] = bottomLeft.x();
+ coordinates[1] = bottomLeft.y();
+ coordinates[2] = bottomRight.x();
+ coordinates[3] = bottomRight.y();
+ coordinates[4] = topRight.x();
+ coordinates[5] = topRight.y();
+ coordinates[6] = topLeft.x();
+ coordinates[7] = topLeft.y();
+
+ vgAppendPathData(m_rectPath, 5, rectCommands, coordinates.constData());
+ }
+
+ m_pathDirty = false;
+ }
+
+ if (m_paintDirty) {
+ vgSetPaint(m_rectPaint, VG_FILL_PATH);
+ vgSetParameteri(m_rectPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
+ vgSetParameterfv(m_rectPaint, VG_PAINT_COLOR, 4, QSGOpenVGHelpers::qColorToVGColor(m_color).constData());
+
+ m_paintDirty = false;
+ }
+
+ vgSetPaint(m_rectPaint, VG_FILL_PATH);
+ vgDrawPath(m_rectPath, VG_FILL_PATH);
+
+}
+
+QSGOpenVGImageNode::QSGOpenVGImageNode()
+{
+ // Set Dummy material and geometry to avoid asserts
+ setMaterial((QSGMaterial*)1);
+ setGeometry((QSGGeometry*)1);
+
+}
+
+QSGOpenVGImageNode::~QSGOpenVGImageNode()
+{
+ if (m_owns) {
+ m_texture->deleteLater();
+ }
+}
+
+void QSGOpenVGImageNode::setRect(const QRectF &rect)
+{
+ m_rect = rect;
+ markDirty(DirtyMaterial);
+}
+
+QRectF QSGOpenVGImageNode::rect() const
+{
+ return m_rect;
+}
+
+void QSGOpenVGImageNode::setSourceRect(const QRectF &r)
+{
+ m_sourceRect = r;
+}
+
+QRectF QSGOpenVGImageNode::sourceRect() const
+{
+ return m_sourceRect;
+}
+
+void QSGOpenVGImageNode::setTexture(QSGTexture *texture)
+{
+ m_texture = texture;
+ markDirty(DirtyMaterial);
+}
+
+QSGTexture *QSGOpenVGImageNode::texture() const
+{
+ return m_texture;
+}
+
+void QSGOpenVGImageNode::setFiltering(QSGTexture::Filtering filtering)
+{
+ m_filtering = filtering;
+ markDirty(DirtyMaterial);
+}
+
+QSGTexture::Filtering QSGOpenVGImageNode::filtering() const
+{
+ return m_filtering;
+}
+
+void QSGOpenVGImageNode::setMipmapFiltering(QSGTexture::Filtering)
+{
+}
+
+QSGTexture::Filtering QSGOpenVGImageNode::mipmapFiltering() const
+{
+ return QSGTexture::None;
+}
+
+void QSGOpenVGImageNode::setTextureCoordinatesTransform(QSGImageNode::TextureCoordinatesTransformMode transformNode)
+{
+ if (m_transformMode == transformNode)
+ return;
+ m_transformMode = transformNode;
+ markDirty(DirtyGeometry);
+}
+
+QSGImageNode::TextureCoordinatesTransformMode QSGOpenVGImageNode::textureCoordinatesTransform() const
+{
+ return m_transformMode;
+}
+
+void QSGOpenVGImageNode::setOwnsTexture(bool owns)
+{
+ m_owns = owns;
+}
+
+bool QSGOpenVGImageNode::ownsTexture() const
+{
+ return m_owns;
+}
+
+void QSGOpenVGImageNode::render()
+{
+ if (!m_texture) {
+ return;
+ }
+
+ // Set Draw Mode
+ if (opacity() < 1.0) {
+ //Transparent
+ vgSetPaint(opacityPaint(), VG_FILL_PATH);
+ vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
+ } else {
+ vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
+ }
+
+ // Set Transform
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
+ vgLoadMatrix(transform().constData());
+
+ VGImage image = static_cast<VGImage>(m_texture->textureId());
+
+ //Apply the TextureCoordinateTransform Flag
+ if (m_transformMode != QSGImageNode::NoTransform) {
+ float translateX = 0.0f;
+ float translateY = 0.0f;
+ float scaleX = 1.0f;
+ float scaleY = 1.0f;
+
+ if (m_transformMode & QSGImageNode::MirrorHorizontally) {
+ translateX = m_rect.width();
+ scaleX = -1.0;
+ }
+
+ if (m_transformMode & QSGImageNode::MirrorVertically) {
+ translateY = m_rect.height();
+ scaleY = -1.0;
+ }
+
+ vgTranslate(translateX, translateY);
+ vgScale(scaleX, scaleY);
+ }
+
+ // If the the source rect is the same as the target rect
+ if (m_sourceRect == m_rect) {
+ vgDrawImage(image);
+ } else {
+ // Scale
+ float scaleX = m_rect.width() / m_sourceRect.width();
+ float scaleY = m_rect.height() / m_sourceRect.height();
+ vgScale(scaleX, scaleY);
+ VGImage subImage = vgChildImage(image, m_sourceRect.x(), m_sourceRect.y(), m_sourceRect.width(), m_sourceRect.height());
+ vgDrawImage(subImage);
+ vgDestroyImage(subImage);
+ }
+
+}
+
+QSGOpenVGNinePatchNode::QSGOpenVGNinePatchNode()
+{
+ // Set Dummy material and geometry to avoid asserts
+ setMaterial((QSGMaterial*)1);
+ setGeometry((QSGGeometry*)1);
+
+}
+
+void QSGOpenVGNinePatchNode::setTexture(QSGTexture *texture)
+{
+ m_texture = texture;
+ markDirty(DirtyMaterial);
+}
+
+void QSGOpenVGNinePatchNode::setBounds(const QRectF &bounds)
+{
+ if (m_bounds == bounds)
+ return;
+ m_bounds = bounds;
+ markDirty(DirtyGeometry);
+}
+
+void QSGOpenVGNinePatchNode::setDevicePixelRatio(qreal ratio)
+{
+ if (m_pixelRatio == ratio)
+ return;
+ m_pixelRatio = ratio;
+ markDirty(DirtyGeometry);
+}
+
+void QSGOpenVGNinePatchNode::setPadding(qreal left, qreal top, qreal right, qreal bottom)
+{
+ QMarginsF margins(left, top, right, bottom);
+ if (m_margins == margins)
+ return;
+ m_margins = margins;
+ markDirty(DirtyGeometry);
+}
+
+void QSGOpenVGNinePatchNode::update()
+{
+
+}
+
+void QSGOpenVGNinePatchNode::render()
+{
+ if (!m_texture)
+ return;
+
+ // Set Draw Mode
+ if (opacity() < 1.0) {
+ //Transparent
+ vgSetPaint(opacityPaint(), VG_FILL_PATH);
+ vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
+ } else {
+ vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
+ }
+
+ // Set Transform
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
+ vgLoadMatrix(transform().constData());
+
+ VGImage image = static_cast<VGImage>(m_texture->textureId());
+
+ //Draw borderImage
+ QSGOpenVGHelpers::qDrawBorderImage(image, m_texture->textureSize(), m_bounds, m_bounds.marginsRemoved(m_margins), QRectF(0, 0, 1, 1));
+}
+
+QRectF QSGOpenVGNinePatchNode::bounds() const
+{
+ return m_bounds;
+}
+
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgpublicnodes.h b/src/plugins/scenegraph/openvg/qsgopenvgpublicnodes.h
new file mode 100644
index 0000000000..8e12c27824
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgpublicnodes.h
@@ -0,0 +1,141 @@
+#ifndef QSGOPENVGPUBLICNODES_H
+#define QSGOPENVGPUBLICNODES_H
+
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtQuick/qsgrectanglenode.h>
+#include <QtQuick/qsgimagenode.h>
+#include <QtQuick/qsgninepatchnode.h>
+
+#include "qsgopenvgrenderable.h"
+
+QT_BEGIN_NAMESPACE
+
+class QSGOpenVGRectangleNode : public QSGRectangleNode, public QSGOpenVGRenderable
+{
+public:
+ QSGOpenVGRectangleNode();
+ ~QSGOpenVGRectangleNode();
+
+ void setRect(const QRectF &rect) override;
+ QRectF rect() const override;
+
+ void setColor(const QColor &color) override;
+ QColor color() const override;
+
+ void setTransform(const QOpenVGMatrix &transform) override;
+
+ void render() override;
+
+private:
+ QRectF m_rect;
+ QColor m_color;
+
+
+ bool m_pathDirty = true;
+ bool m_paintDirty = true;
+
+ VGPath m_rectPath;
+ VGPaint m_rectPaint;
+};
+
+class QSGOpenVGImageNode : public QSGImageNode, public QSGOpenVGRenderable
+{
+public:
+ QSGOpenVGImageNode();
+ ~QSGOpenVGImageNode();
+
+ void setRect(const QRectF &rect) override;
+ QRectF rect() const override;
+
+ void setSourceRect(const QRectF &r) override;
+ QRectF sourceRect() const override;
+
+ void setTexture(QSGTexture *texture) override;
+ QSGTexture *texture() const override;
+
+ void setFiltering(QSGTexture::Filtering filtering) override;
+ QSGTexture::Filtering filtering() const override;
+
+ void setMipmapFiltering(QSGTexture::Filtering) override;
+ QSGTexture::Filtering mipmapFiltering() const override;
+
+ void setTextureCoordinatesTransform(TextureCoordinatesTransformMode transformNode) override;
+ TextureCoordinatesTransformMode textureCoordinatesTransform() const override;
+
+ void setOwnsTexture(bool owns) override;
+ bool ownsTexture() const override;
+
+ void render() override;
+
+private:
+ QSGTexture *m_texture;
+ QRectF m_rect;
+ QRectF m_sourceRect;
+ bool m_owns;
+ QSGTexture::Filtering m_filtering;
+ TextureCoordinatesTransformMode m_transformMode;
+};
+
+class QSGOpenVGNinePatchNode : public QSGNinePatchNode, public QSGOpenVGRenderable
+{
+public:
+ QSGOpenVGNinePatchNode();
+
+ void setTexture(QSGTexture *texture) override;
+ void setBounds(const QRectF &bounds) override;
+ void setDevicePixelRatio(qreal ratio) override;
+ void setPadding(qreal left, qreal top, qreal right, qreal bottom) override;
+ void update() override;
+
+ void render() override;
+
+ QRectF bounds() const;
+
+private:
+ QSGTexture *m_texture;
+ QRectF m_bounds;
+ qreal m_pixelRatio;
+ QMarginsF m_margins;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGPUBLICNODES_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgrenderable.cpp b/src/plugins/scenegraph/openvg/qsgopenvgrenderable.cpp
new file mode 100644
index 0000000000..97d0be99c8
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgrenderable.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvgrenderable.h"
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGRenderable::QSGOpenVGRenderable()
+ : m_opacity(1.0f)
+{
+ m_opacityPaint = vgCreatePaint();
+}
+
+QSGOpenVGRenderable::~QSGOpenVGRenderable()
+{
+ vgDestroyPaint(m_opacityPaint);
+}
+
+void QSGOpenVGRenderable::setOpacity(float opacity)
+{
+ if (m_opacity == opacity)
+ return;
+
+ m_opacity = opacity;
+ VGfloat values[] = {
+ 1.0f, 1.0f, 1.0f, m_opacity
+ };
+ vgSetParameterfv(m_opacityPaint, VG_PAINT_COLOR, 4, values);
+}
+
+float QSGOpenVGRenderable::opacity() const
+{
+ return m_opacity;
+}
+
+VGPaint QSGOpenVGRenderable::opacityPaint() const
+{
+ return m_opacityPaint;
+}
+
+void QSGOpenVGRenderable::setTransform(const QOpenVGMatrix &transform)
+{
+ m_transform = transform;
+}
+
+const QOpenVGMatrix &QSGOpenVGRenderable::transform() const
+{
+ return m_transform;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgrenderable.h b/src/plugins/scenegraph/openvg/qsgopenvgrenderable.h
new file mode 100644
index 0000000000..a544ae743e
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgrenderable.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGRENDERABLE_H
+#define QSGOPENVGRENDERABLE_H
+
+#include <QtGlobal>
+
+#include <VG/openvg.h>
+
+#include "qopenvgmatrix.h"
+
+QT_BEGIN_NAMESPACE
+
+class QSGOpenVGRenderable
+{
+public:
+ QSGOpenVGRenderable();
+ virtual ~QSGOpenVGRenderable();
+
+ virtual void render() = 0;
+
+ virtual void setOpacity(float opacity);
+ float opacity() const;
+ VGPaint opacityPaint() const;
+
+ virtual void setTransform(const QOpenVGMatrix &transform);
+ const QOpenVGMatrix &transform() const;
+
+private:
+ float m_opacity;
+ VGPaint m_opacityPaint;
+ QOpenVGMatrix m_transform;
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGRENDERABLE_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgrenderer.cpp b/src/plugins/scenegraph/openvg/qsgopenvgrenderer.cpp
new file mode 100644
index 0000000000..acd4cf88dc
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgrenderer.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvgrenderer_p.h"
+#include "qsgopenvgcontext_p.h"
+#include "qsgopenvgnodevisitor.h"
+#include "qopenvgcontext_p.h"
+#include "qsgopenvghelpers.h"
+
+#include <QtGui/QWindow>
+
+#include <VG/openvg.h>
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGRenderer::QSGOpenVGRenderer(QSGRenderContext *context)
+ : QSGRenderer(context)
+{
+
+}
+
+QSGOpenVGRenderer::~QSGOpenVGRenderer()
+{
+
+}
+
+void QSGOpenVGRenderer::renderScene(uint fboId)
+{
+ Q_UNUSED(fboId)
+ class B : public QSGBindable
+ {
+ public:
+ void bind() const { }
+ } bindable;
+ QSGRenderer::renderScene(bindable);
+}
+
+void QSGOpenVGRenderer::render()
+{
+ //Clear the window geometry with the clear color
+ vgSetfv(VG_CLEAR_COLOR, 4, QSGOpenVGHelpers::qColorToVGColor(clearColor()).constData());
+ vgClear(0, 0, VG_MAXINT, VG_MAXINT);
+
+ // Visit each node to render scene
+ QSGOpenVGNodeVisitor rendererVisitor;
+ rendererVisitor.visitChildren(rootNode());
+}
+
+void QSGOpenVGRenderer::nodeChanged(QSGNode *node, QSGNode::DirtyState state)
+{
+ QSGRenderer::nodeChanged(node, state);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgrenderer_p.h b/src/plugins/scenegraph/openvg/qsgopenvgrenderer_p.h
new file mode 100644
index 0000000000..24cabd1b89
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgrenderer_p.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGRENDERER_H
+#define QSGOPENVGRENDERER_H
+
+#include <private/qsgrenderer_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGOpenVGRenderer : public QSGRenderer
+{
+public:
+ QSGOpenVGRenderer(QSGRenderContext *context);
+ virtual ~QSGOpenVGRenderer();
+
+ void nodeChanged(QSGNode *node, QSGNode::DirtyState state) override;
+
+ void renderScene(uint fboId = 0) final;
+ void render() final;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGRENDERER_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgrenderloop.cpp b/src/plugins/scenegraph/openvg/qsgopenvgrenderloop.cpp
new file mode 100644
index 0000000000..f7aa704095
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgrenderloop.cpp
@@ -0,0 +1,261 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvgrenderloop_p.h"
+#include "qsgopenvgcontext_p.h"
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QElapsedTimer>
+
+#include <private/qquickwindow_p.h>
+#include <private/qquickprofiler_p.h>
+
+#include "qopenvgcontext_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGRenderLoop::QSGOpenVGRenderLoop()
+ : vg(nullptr)
+{
+ sg = QSGContext::createDefaultContext();
+ rc = sg->createRenderContext();
+}
+
+QSGOpenVGRenderLoop::~QSGOpenVGRenderLoop()
+{
+ delete rc;
+ delete sg;
+}
+
+void QSGOpenVGRenderLoop::show(QQuickWindow *window)
+{
+ WindowData data;
+ data.updatePending = false;
+ data.grabOnly = false;
+ m_windows[window] = data;
+
+ maybeUpdate(window);
+}
+
+void QSGOpenVGRenderLoop::hide(QQuickWindow *window)
+{
+ QQuickWindowPrivate *cd = QQuickWindowPrivate::get(window);
+ cd->fireAboutToStop();
+}
+
+void QSGOpenVGRenderLoop::windowDestroyed(QQuickWindow *window)
+{
+ m_windows.remove(window);
+ hide(window);
+
+ QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
+ d->cleanupNodesOnShutdown();
+
+ if (m_windows.size() == 0) {
+ rc->invalidate();
+ delete vg;
+ vg = nullptr;
+ QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+ } else if (vg && window == vg->window()) {
+ vg->doneCurrent();
+ }
+}
+
+void QSGOpenVGRenderLoop::exposureChanged(QQuickWindow *window)
+{
+ if (window->isExposed()) {
+ m_windows[window].updatePending = true;
+ renderWindow(window);
+ }
+}
+
+QImage QSGOpenVGRenderLoop::grab(QQuickWindow *window)
+{
+ if (!m_windows.contains(window))
+ return QImage();
+
+ m_windows[window].grabOnly = true;
+
+ renderWindow(window);
+
+ QImage grabbed = grabContent;
+ grabContent = QImage();
+ return grabbed;
+}
+
+void QSGOpenVGRenderLoop::update(QQuickWindow *window)
+{
+ maybeUpdate(window);
+}
+
+void QSGOpenVGRenderLoop::handleUpdateRequest(QQuickWindow *window)
+{
+ renderWindow(window);
+}
+
+void QSGOpenVGRenderLoop::maybeUpdate(QQuickWindow *window)
+{
+ if (!m_windows.contains(window))
+ return;
+
+ m_windows[window].updatePending = true;
+ window->requestUpdate();
+}
+
+QAnimationDriver *QSGOpenVGRenderLoop::animationDriver() const
+{
+ return nullptr;
+}
+
+QSGContext *QSGOpenVGRenderLoop::sceneGraphContext() const
+{
+ return sg;
+}
+
+QSGRenderContext *QSGOpenVGRenderLoop::createRenderContext(QSGContext *) const
+{
+ return rc;
+}
+
+void QSGOpenVGRenderLoop::releaseResources(QQuickWindow *window)
+{
+ Q_UNUSED(window)
+}
+
+QSurface::SurfaceType QSGOpenVGRenderLoop::windowSurfaceType() const
+{
+ return QSurface::OpenVGSurface;
+}
+
+void QSGOpenVGRenderLoop::renderWindow(QQuickWindow *window)
+{
+ QQuickWindowPrivate *cd = QQuickWindowPrivate::get(window);
+ if (!cd->isRenderable() || !m_windows.contains(window))
+ return;
+
+ WindowData &data = const_cast<WindowData &>(m_windows[window]);
+
+ if (vg == nullptr) {
+ vg = new QOpenVGContext(window);
+ vg->makeCurrent();
+ cd->context->initialize(vg);
+ } else {
+ vg->makeCurrent();
+ }
+
+ bool alsoSwap = data.updatePending;
+ data.updatePending = false;
+
+ if (!data.grabOnly) {
+ // Event delivery/processing triggered the window to be deleted or stop rendering.
+ if (!m_windows.contains(window))
+ return;
+ }
+ QElapsedTimer renderTimer;
+ qint64 renderTime = 0, syncTime = 0, polishTime = 0;
+ bool profileFrames = QSG_OPENVG_LOG_TIME_RENDERLOOP().isDebugEnabled();
+ if (profileFrames)
+ renderTimer.start();
+ Q_QUICK_SG_PROFILE_START(QQuickProfiler::SceneGraphPolishFrame);
+
+ cd->polishItems();
+
+ if (profileFrames)
+ polishTime = renderTimer.nsecsElapsed();
+ Q_QUICK_SG_PROFILE_SWITCH(QQuickProfiler::SceneGraphPolishFrame,
+ QQuickProfiler::SceneGraphRenderLoopFrame,
+ QQuickProfiler::SceneGraphPolishPolish);
+
+ emit window->afterAnimating();
+
+ cd->syncSceneGraph();
+
+ if (profileFrames)
+ syncTime = renderTimer.nsecsElapsed();
+ Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRenderLoopFrame,
+ QQuickProfiler::SceneGraphRenderLoopSync);
+
+ // setup coordinate system for window
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
+ vgLoadIdentity();
+ vgTranslate(0.0f, window->size().height());
+ vgScale(1.0, -1.0);
+
+ cd->renderSceneGraph(window->size());
+
+ if (profileFrames)
+ renderTime = renderTimer.nsecsElapsed();
+ Q_QUICK_SG_PROFILE_RECORD(QQuickProfiler::SceneGraphRenderLoopFrame,
+ QQuickProfiler::SceneGraphRenderLoopRender);
+
+ if (data.grabOnly) {
+ grabContent = vg->readFramebuffer(window->size() * window->effectiveDevicePixelRatio());
+ data.grabOnly = false;
+ }
+
+ if (alsoSwap && window->isVisible()) {
+ vg->swapBuffers();
+ cd->fireFrameSwapped();
+ }
+
+ qint64 swapTime = 0;
+ if (profileFrames)
+ swapTime = renderTimer.nsecsElapsed();
+ Q_QUICK_SG_PROFILE_END(QQuickProfiler::SceneGraphRenderLoopFrame,
+ QQuickProfiler::SceneGraphRenderLoopSwap);
+
+ if (QSG_OPENVG_LOG_TIME_RENDERLOOP().isDebugEnabled()) {
+ static QTime lastFrameTime = QTime::currentTime();
+ qCDebug(QSG_OPENVG_LOG_TIME_RENDERLOOP,
+ "Frame rendered with 'basic' renderloop in %dms, polish=%d, sync=%d, render=%d, swap=%d, frameDelta=%d",
+ int(swapTime / 1000000),
+ int(polishTime / 1000000),
+ int((syncTime - polishTime) / 1000000),
+ int((renderTime - syncTime) / 1000000),
+ int((swapTime - renderTime) / 10000000),
+ int(lastFrameTime.msecsTo(QTime::currentTime())));
+ lastFrameTime = QTime::currentTime();
+ }
+
+ // Might have been set during syncSceneGraph()
+ if (data.updatePending)
+ maybeUpdate(window);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgrenderloop_p.h b/src/plugins/scenegraph/openvg/qsgopenvgrenderloop_p.h
new file mode 100644
index 0000000000..f35b689e00
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgrenderloop_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGRENDERLOOP_H
+#define QSGOPENVGRENDERLOOP_H
+
+#include <private/qsgrenderloop_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QOpenVGContext;
+
+class QSGOpenVGRenderLoop : public QSGRenderLoop
+{
+public:
+ QSGOpenVGRenderLoop();
+ ~QSGOpenVGRenderLoop();
+
+
+ void show(QQuickWindow *window) override;
+ void hide(QQuickWindow *window) override;
+
+ void windowDestroyed(QQuickWindow *window) override;
+
+ void renderWindow(QQuickWindow *window);
+ void exposureChanged(QQuickWindow *window) override;
+ QImage grab(QQuickWindow *window) override;
+
+ void maybeUpdate(QQuickWindow *window) override;
+ void update(QQuickWindow *window) override;
+ void handleUpdateRequest(QQuickWindow *window) override;
+
+ void releaseResources(QQuickWindow *) override;
+
+ QSurface::SurfaceType windowSurfaceType() const override;
+
+ QAnimationDriver *animationDriver() const override;
+
+ QSGContext *sceneGraphContext() const override;
+ QSGRenderContext *createRenderContext(QSGContext *) const override;
+
+ struct WindowData {
+ bool updatePending : 1;
+ bool grabOnly : 1;
+ };
+
+ QHash<QQuickWindow *, WindowData> m_windows;
+
+ QSGContext *sg;
+ QSGRenderContext *rc;
+ QOpenVGContext *vg;
+
+ QImage grabContent;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGRENDERLOOP_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgspritenode.cpp b/src/plugins/scenegraph/openvg/qsgopenvgspritenode.cpp
new file mode 100644
index 0000000000..fb24df7471
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgspritenode.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvgspritenode.h"
+#include "qsgopenvgtexture.h"
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGSpriteNode::QSGOpenVGSpriteNode()
+ : m_time(0.0f)
+{
+ // Set Dummy material and geometry to avoid asserts
+ setMaterial((QSGMaterial*)1);
+ setGeometry((QSGGeometry*)1);
+}
+
+QSGOpenVGSpriteNode::~QSGOpenVGSpriteNode()
+{
+
+}
+
+void QSGOpenVGSpriteNode::setTexture(QSGTexture *texture)
+{
+ m_texture = static_cast<QSGOpenVGTexture*>(texture);
+ markDirty(DirtyMaterial);
+}
+
+void QSGOpenVGSpriteNode::setTime(float time)
+{
+ if (m_time != time) {
+ m_time = time;
+ markDirty(DirtyMaterial);
+ }
+}
+
+void QSGOpenVGSpriteNode::setSourceA(const QPoint &source)
+{
+ if (m_sourceA != source) {
+ m_sourceA = source;
+ markDirty(DirtyMaterial);
+ }
+}
+
+void QSGOpenVGSpriteNode::setSourceB(const QPoint &source)
+{
+ if (m_sourceB != source) {
+ m_sourceB = source;
+ markDirty(DirtyMaterial);
+ }
+}
+
+void QSGOpenVGSpriteNode::setSpriteSize(const QSize &size)
+{
+ if (m_spriteSize != size) {
+ m_spriteSize = size;
+ markDirty(DirtyMaterial);
+ }
+}
+
+void QSGOpenVGSpriteNode::setSheetSize(const QSize &size)
+{
+ if (m_sheetSize != size) {
+ m_sheetSize = size;
+ markDirty(DirtyMaterial);
+ }
+}
+
+void QSGOpenVGSpriteNode::setSize(const QSizeF &size)
+{
+ if (m_size != size) {
+ m_size = size;
+ markDirty(DirtyGeometry);
+ }
+}
+
+void QSGOpenVGSpriteNode::setFiltering(QSGTexture::Filtering)
+{
+}
+
+void QSGOpenVGSpriteNode::update()
+{
+}
+
+void QSGOpenVGSpriteNode::render()
+{
+ if (!m_texture)
+ return;
+
+ VGImage image = static_cast<VGImage>(m_texture->textureId());
+
+ QRectF sourceRect(m_sourceA, m_spriteSize);
+ QRectF targetRect(0, 0, m_size.width(), m_size.height());
+
+ VGImage sourceImage = vgChildImage(image, sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height());
+
+ // Set Draw Mode
+ if (opacity() < 1.0) {
+ //Transparent
+ vgSetPaint(opacityPaint(), VG_FILL_PATH);
+ vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
+ } else {
+ vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
+ }
+
+ // Set Image Matrix
+ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
+ vgLoadMatrix(transform().constData());
+
+ if (sourceRect != targetRect) {
+ // Scale
+ float scaleX = targetRect.width() / sourceRect.width();
+ float scaleY = targetRect.height() / sourceRect.height();
+ vgScale(scaleX, scaleY);
+ }
+
+ vgDrawImage(sourceImage);
+
+ vgDestroyImage(sourceImage);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgspritenode.h b/src/plugins/scenegraph/openvg/qsgopenvgspritenode.h
new file mode 100644
index 0000000000..3ade2ef8ad
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgspritenode.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGSPRITENODE_H
+#define QSGOPENVGSPRITENODE_H
+
+#include <private/qsgadaptationlayer_p.h>
+#include "qsgopenvgrenderable.h"
+
+QT_BEGIN_NAMESPACE
+class QSGOpenVGTexture;
+class QSGOpenVGSpriteNode : public QSGSpriteNode, public QSGOpenVGRenderable
+{
+public:
+ QSGOpenVGSpriteNode();
+ ~QSGOpenVGSpriteNode();
+
+ void setTexture(QSGTexture *texture) override;
+ void setTime(float time) override;
+ void setSourceA(const QPoint &source) override;
+ void setSourceB(const QPoint &source) override;
+ void setSpriteSize(const QSize &size) override;
+ void setSheetSize(const QSize &size) override;
+ void setSize(const QSizeF &size) override;
+ void setFiltering(QSGTexture::Filtering filtering) override;
+ void update() override;
+
+ void render() override;
+
+private:
+ QSGOpenVGTexture *m_texture;
+ float m_time;
+ QPoint m_sourceA;
+ QPoint m_sourceB;
+ QSize m_spriteSize;
+ QSize m_sheetSize;
+ QSizeF m_size;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGSPRITENODE_H
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgtexture.cpp b/src/plugins/scenegraph/openvg/qsgopenvgtexture.cpp
new file mode 100644
index 0000000000..dd2fdc7020
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgtexture.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsgopenvgtexture.h"
+#include "qsgopenvghelpers.h"
+
+QT_BEGIN_NAMESPACE
+
+QSGOpenVGTexture::QSGOpenVGTexture(const QImage &image, uint flags)
+{
+ Q_UNUSED(flags)
+
+ VGImageFormat format = QSGOpenVGHelpers::qImageFormatToVGImageFormat(image.format());
+ m_image = vgCreateImage(format, image.width(), image.height(), VG_IMAGE_QUALITY_BETTER);
+
+ // Do Texture Upload
+ vgImageSubData(m_image, image.constBits(), image.bytesPerLine(), format, 0, 0, image.width(), image.height());
+}
+
+QSGOpenVGTexture::~QSGOpenVGTexture()
+{
+ vgDestroyImage(m_image);
+}
+
+int QSGOpenVGTexture::textureId() const
+{
+ return static_cast<int>(m_image);
+}
+
+QSize QSGOpenVGTexture::textureSize() const
+{
+ VGint imageWidth = vgGetParameteri(m_image, VG_IMAGE_WIDTH);
+ VGint imageHeight = vgGetParameteri(m_image, VG_IMAGE_HEIGHT);
+ return QSize(imageWidth, imageHeight);
+}
+
+bool QSGOpenVGTexture::hasAlphaChannel() const
+{
+ VGImageFormat format = static_cast<VGImageFormat>(vgGetParameteri(m_image, VG_IMAGE_FORMAT));
+
+ switch (format) {
+ case VG_sRGBA_8888:
+ case VG_sRGBA_8888_PRE:
+ case VG_sRGBA_5551:
+ case VG_sRGBA_4444:
+ case VG_lRGBA_8888:
+ case VG_lRGBA_8888_PRE:
+ case VG_A_8:
+ case VG_A_1:
+ case VG_A_4:
+ case VG_sARGB_8888:
+ case VG_sARGB_8888_PRE:
+ case VG_sARGB_1555:
+ case VG_sARGB_4444:
+ case VG_lARGB_8888:
+ case VG_lARGB_8888_PRE:
+ case VG_sBGRA_8888:
+ case VG_sBGRA_8888_PRE:
+ case VG_sBGRA_5551:
+ case VG_sBGRA_4444:
+ case VG_lBGRA_8888:
+ case VG_lBGRA_8888_PRE:
+ case VG_sABGR_8888:
+ case VG_sABGR_8888_PRE:
+ case VG_sABGR_1555:
+ case VG_sABGR_4444:
+ case VG_lABGR_8888:
+ case VG_lABGR_8888_PRE:
+ return true;
+ break;
+ default:
+ break;
+ }
+ return false;
+}
+
+bool QSGOpenVGTexture::hasMipmaps() const
+{
+ return false;
+}
+
+void QSGOpenVGTexture::bind()
+{
+ // No need to bind
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/scenegraph/openvg/qsgopenvgtexture.h b/src/plugins/scenegraph/openvg/qsgopenvgtexture.h
new file mode 100644
index 0000000000..523c9e690d
--- /dev/null
+++ b/src/plugins/scenegraph/openvg/qsgopenvgtexture.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGOPENVGTEXTURE_H
+#define QSGOPENVGTEXTURE_H
+
+#include <private/qsgtexture_p.h>
+
+#include <VG/openvg.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSGOpenVGTexture : public QSGTexture
+{
+public:
+ QSGOpenVGTexture(const QImage &image, uint flags);
+ ~QSGOpenVGTexture();
+
+ int textureId() const override;
+ QSize textureSize() const override;
+ bool hasAlphaChannel() const override;
+ bool hasMipmaps() const override;
+ void bind() override;
+
+private:
+ VGImage m_image;;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGOPENVGTEXTURE_H
diff --git a/src/plugins/scenegraph/scenegraph.pro b/src/plugins/scenegraph/scenegraph.pro
index a90e8d4814..39c0c0815c 100644
--- a/src/plugins/scenegraph/scenegraph.pro
+++ b/src/plugins/scenegraph/scenegraph.pro
@@ -1,3 +1,5 @@
TEMPLATE = subdirs
QT_FOR_CONFIG += quick
qtConfig(d3d12): SUBDIRS += d3d12
+qtConfig(openvg): SUBDIRS += openvg
+
diff --git a/src/qml/animations/qabstractanimationjob_p.h b/src/qml/animations/qabstractanimationjob_p.h
index efc86a5823..95a39b1301 100644
--- a/src/qml/animations/qabstractanimationjob_p.h
+++ b/src/qml/animations/qabstractanimationjob_p.h
@@ -218,11 +218,11 @@ public:
*/
static void updateAnimationTimer();
- void restartAnimationTimer();
- void updateAnimationsTime(qint64 timeStep);
+ void restartAnimationTimer() override;
+ void updateAnimationsTime(qint64 timeStep) override;
//useful for profiling/debugging
- int runningAnimationCount() { return animations.count(); }
+ int runningAnimationCount() override { return animations.count(); }
bool hasStartAnimationPending() const { return startAnimationPending; }
diff --git a/src/qml/animations/qanimationgroupjob_p.h b/src/qml/animations/qanimationgroupjob_p.h
index 9bcd63127a..26965c0264 100644
--- a/src/qml/animations/qanimationgroupjob_p.h
+++ b/src/qml/animations/qanimationgroupjob_p.h
@@ -75,7 +75,7 @@ public:
//called by QAbstractAnimationJob
virtual void uncontrolledAnimationFinished(QAbstractAnimationJob *animation);
protected:
- void topLevelAnimationLoopChanged();
+ void topLevelAnimationLoopChanged() override;
virtual void animationInserted(QAbstractAnimationJob*) { }
virtual void animationRemoved(QAbstractAnimationJob*, QAbstractAnimationJob*, QAbstractAnimationJob*);
diff --git a/src/qml/animations/qcontinuinganimationgroupjob_p.h b/src/qml/animations/qcontinuinganimationgroupjob_p.h
index f34a118cad..baf4ff1ae5 100644
--- a/src/qml/animations/qcontinuinganimationgroupjob_p.h
+++ b/src/qml/animations/qcontinuinganimationgroupjob_p.h
@@ -62,14 +62,14 @@ public:
QContinuingAnimationGroupJob();
~QContinuingAnimationGroupJob();
- int duration() const { return -1; }
+ int duration() const override { return -1; }
protected:
- void updateCurrentTime(int currentTime);
- void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState);
- void updateDirection(QAbstractAnimationJob::Direction direction);
- void uncontrolledAnimationFinished(QAbstractAnimationJob *animation);
- void debugAnimation(QDebug d) const;
+ void updateCurrentTime(int currentTime) override;
+ void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) override;
+ void updateDirection(QAbstractAnimationJob::Direction direction) override;
+ void uncontrolledAnimationFinished(QAbstractAnimationJob *animation) override;
+ void debugAnimation(QDebug d) const override;
};
QT_END_NAMESPACE
diff --git a/src/qml/animations/qparallelanimationgroupjob_p.h b/src/qml/animations/qparallelanimationgroupjob_p.h
index 3e914c3e76..358b95ce53 100644
--- a/src/qml/animations/qparallelanimationgroupjob_p.h
+++ b/src/qml/animations/qparallelanimationgroupjob_p.h
@@ -62,14 +62,14 @@ public:
QParallelAnimationGroupJob();
~QParallelAnimationGroupJob();
- int duration() const;
+ int duration() const override;
protected:
- void updateCurrentTime(int currentTime);
- void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState);
- void updateDirection(QAbstractAnimationJob::Direction direction);
- void uncontrolledAnimationFinished(QAbstractAnimationJob *animation);
- void debugAnimation(QDebug d) const;
+ void updateCurrentTime(int currentTime) override;
+ void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) override;
+ void updateDirection(QAbstractAnimationJob::Direction direction) override;
+ void uncontrolledAnimationFinished(QAbstractAnimationJob *animation) override;
+ void debugAnimation(QDebug d) const override;
private:
bool shouldAnimationStart(QAbstractAnimationJob *animation, bool startIfAtEnd) const;
diff --git a/src/qml/animations/qpauseanimationjob_p.h b/src/qml/animations/qpauseanimationjob_p.h
index 2967e1cf60..e228f46daa 100644
--- a/src/qml/animations/qpauseanimationjob_p.h
+++ b/src/qml/animations/qpauseanimationjob_p.h
@@ -62,12 +62,12 @@ public:
explicit QPauseAnimationJob(int duration = 250);
~QPauseAnimationJob();
- int duration() const;
+ int duration() const override;
void setDuration(int msecs);
protected:
- void updateCurrentTime(int);
- void debugAnimation(QDebug d) const;
+ void updateCurrentTime(int) override;
+ void debugAnimation(QDebug d) const override;
private:
//definition
diff --git a/src/qml/animations/qsequentialanimationgroupjob_p.h b/src/qml/animations/qsequentialanimationgroupjob_p.h
index bb481d1322..5fbafcb9ac 100644
--- a/src/qml/animations/qsequentialanimationgroupjob_p.h
+++ b/src/qml/animations/qsequentialanimationgroupjob_p.h
@@ -63,16 +63,16 @@ public:
QSequentialAnimationGroupJob();
~QSequentialAnimationGroupJob();
- int duration() const;
+ int duration() const override;
QAbstractAnimationJob *currentAnimation() const { return m_currentAnimation; }
protected:
- void updateCurrentTime(int);
- void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState);
- void updateDirection(QAbstractAnimationJob::Direction direction);
- void uncontrolledAnimationFinished(QAbstractAnimationJob *animation);
- void debugAnimation(QDebug d) const;
+ void updateCurrentTime(int) override;
+ void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) override;
+ void updateDirection(QAbstractAnimationJob::Direction direction) override;
+ void uncontrolledAnimationFinished(QAbstractAnimationJob *animation) override;
+ void debugAnimation(QDebug d) const override;
private:
struct AnimationIndex
@@ -91,8 +91,8 @@ private:
void setCurrentAnimation(QAbstractAnimationJob *anim, bool intermediate = false);
void activateCurrentAnimation(bool intermediate = false);
- void animationInserted(QAbstractAnimationJob *anim);
- void animationRemoved(QAbstractAnimationJob *anim,QAbstractAnimationJob*,QAbstractAnimationJob*);
+ void animationInserted(QAbstractAnimationJob *anim) override;
+ void animationRemoved(QAbstractAnimationJob *anim, QAbstractAnimationJob *, QAbstractAnimationJob *) override;
bool atEnd() const;
diff --git a/src/qml/compiler/compiler.pri b/src/qml/compiler/compiler.pri
index 1de5dfa6fa..fa66d3a6e3 100644
--- a/src/qml/compiler/compiler.pri
+++ b/src/qml/compiler/compiler.pri
@@ -39,7 +39,10 @@ SOURCES += \
unix: SOURCES += $$PWD/qv4compilationunitmapper_unix.cpp
else: SOURCES += $$PWD/qv4compilationunitmapper_win.cpp
-qtConfig(qml-interpreter) {
+qtConfig(private_tests): LIBS_PRIVATE += $$QMAKE_LIBS_DYNLOAD
+}
+
+qmldevtools_build|qtConfig(qml-interpreter) {
HEADERS += \
$$PWD/qv4instr_moth_p.h \
$$PWD/qv4isel_moth_p.h
@@ -48,6 +51,3 @@ qtConfig(qml-interpreter) {
$$PWD/qv4isel_moth.cpp
}
-
-qtConfig(private_tests): LIBS_PRIVATE += $$QMAKE_LIBS_DYNLOAD
-}
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp
index c0f953ca2c..8a7507c92e 100644
--- a/src/qml/compiler/qqmlirbuilder.cpp
+++ b/src/qml/compiler/qqmlirbuilder.cpp
@@ -362,10 +362,11 @@ bool IRBuilder::generateFromQml(const QString &code, const QString &url, Documen
QQmlJS::Parser parser(&output->jsParserEngine);
- if (! parser.parse() || !parser.diagnosticMessages().isEmpty()) {
-
+ const bool parseResult = parser.parse();
+ const auto diagnosticMessages = parser.diagnosticMessages();
+ if (!parseResult || !diagnosticMessages.isEmpty()) {
// Extract errors from the parser
- foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) {
+ for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) {
if (m.isWarning()) {
qWarning("%s:%d : %s", qPrintable(url), m.loc.startLine, qPrintable(m.message));
@@ -1018,7 +1019,8 @@ void IRBuilder::setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST
CompiledFunctionOrExpression *expr = New<CompiledFunctionOrExpression>();
expr->node = statement;
- expr->nameIndex = registerString(QStringLiteral("expression for ") + stringAt(binding->propertyNameIndex));
+ expr->nameIndex = registerString(QLatin1String("expression for ")
+ + stringAt(binding->propertyNameIndex));
expr->disableAcceleratedLookups = false;
const int index = bindingsTarget()->functionsAndExpressions->append(expr);
binding->value.compiledScriptIndex = index;
@@ -1246,7 +1248,7 @@ bool IRBuilder::resolveQualifiedId(QQmlJS::AST::UiQualifiedId **nameToResolve, O
// If it's a namespace, prepend the qualifier and we'll resolve it later to the correct type.
QString currentName = qualifiedIdElement->name.toString();
if (qualifiedIdElement->next) {
- foreach (const QV4::CompiledData::Import* import, _imports)
+ for (const QV4::CompiledData::Import* import : qAsConst(_imports))
if (import->qualifierIndex != emptyStringIndex
&& stringAt(import->qualifierIndex) == currentName) {
qualifiedIdElement = qualifiedIdElement->next;
@@ -1371,7 +1373,7 @@ QV4::CompiledData::Unit *QmlUnitGenerator::generate(Document &output, QQmlEngine
QHash<const Object*, quint32> objectOffsets;
int objectsSize = 0;
- foreach (Object *o, output.objects) {
+ for (Object *o : qAsConst(output.objects)) {
objectOffsets.insert(o, unitSize + importSize + objectOffsetTableSize + objectsSize);
objectsSize += QV4::CompiledData::Object::calculateSizeExcludingSignals(o->functionCount(), o->propertyCount(), o->aliasCount(), o->signalCount(), o->bindingCount(), o->namedObjectsInComponent.count);
@@ -1417,7 +1419,7 @@ QV4::CompiledData::Unit *QmlUnitGenerator::generate(Document &output, QQmlEngine
// write imports
char *importPtr = data + qmlUnit->offsetToImports;
- foreach (const QV4::CompiledData::Import *imp, output.imports) {
+ for (const QV4::CompiledData::Import *imp : qAsConst(output.imports)) {
QV4::CompiledData::Import *importToWrite = reinterpret_cast<QV4::CompiledData::Import*>(importPtr);
*importToWrite = *imp;
importPtr += sizeof(QV4::CompiledData::Import);
@@ -1522,7 +1524,7 @@ QV4::CompiledData::Unit *QmlUnitGenerator::generate(Document &output, QQmlEngine
}
// enable flag if we encountered pragma Singleton
- foreach (Pragma *p, output.pragmas) {
+ for (Pragma *p : qAsConst(output.pragmas)) {
if (p->type == Pragma::PragmaSingleton) {
qmlUnit->flags |= QV4::CompiledData::Unit::IsSingleton;
break;
@@ -1588,7 +1590,7 @@ QVector<int> JSCodeGen::generateJSCodeForFunctionsAndBindings(const QList<Compil
ScanFunctions scan(this, sourceCode, GlobalCode);
scan.enterEnvironment(0, QmlBinding);
scan.enterQmlScope(qmlRoot, QStringLiteral("context scope"));
- foreach (const CompiledFunctionOrExpression &f, functions) {
+ for (const CompiledFunctionOrExpression &f : functions) {
Q_ASSERT(f.node != qmlRoot);
QQmlJS::AST::FunctionDeclaration *function = QQmlJS::AST::cast<QQmlJS::AST::FunctionDeclaration*>(f.node);
@@ -1923,7 +1925,7 @@ QV4::IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int
// with the correct QML context.
// Look for IDs first.
- foreach (const IdMapping &mapping, _idObjects)
+ for (const IdMapping &mapping : qAsConst(_idObjects))
if (name == mapping.name) {
if (_function->isQmlBinding)
_function->idObjectDependencies.insert(mapping.idIndex);
@@ -2059,4 +2061,156 @@ QQmlPropertyData *PropertyResolver::signal(const QString &name, bool *notInRevis
return 0;
}
+IRLoader::IRLoader(const QV4::CompiledData::Unit *qmlData, QmlIR::Document *output)
+ : unit(qmlData)
+ , output(output)
+{
+ pool = output->jsParserEngine.pool();
+}
+
+void IRLoader::load()
+{
+ output->jsGenerator.stringTable.clear();
+ for (uint i = 0; i < unit->stringTableSize; ++i)
+ output->jsGenerator.stringTable.registerString(unit->stringAt(i));
+
+ for (quint32 i = 0; i < unit->nImports; ++i)
+ output->imports << unit->importAt(i);
+
+ if (unit->flags & QV4::CompiledData::Unit::IsSingleton) {
+ QmlIR::Pragma *p = New<QmlIR::Pragma>();
+ p->location = QV4::CompiledData::Location();
+ p->type = QmlIR::Pragma::PragmaSingleton;
+ output->pragmas << p;
+ }
+
+ output->indexOfRootObject = unit->indexOfRootObject;
+
+ for (uint i = 0; i < unit->nObjects; ++i) {
+ const QV4::CompiledData::Object *serializedObject = unit->objectAt(i);
+ QmlIR::Object *object = loadObject(serializedObject);
+ output->objects.append(object);
+ }
+}
+
+struct FakeExpression : public QQmlJS::AST::NullExpression
+{
+ FakeExpression(int start, int length)
+ : location(start, length)
+ {}
+
+ virtual QQmlJS::AST::SourceLocation firstSourceLocation() const
+ { return location; }
+
+ virtual QQmlJS::AST::SourceLocation lastSourceLocation() const
+ { return location; }
+
+private:
+ QQmlJS::AST::SourceLocation location;
+};
+
+QmlIR::Object *IRLoader::loadObject(const QV4::CompiledData::Object *serializedObject)
+{
+ QmlIR::Object *object = pool->New<QmlIR::Object>();
+ object->init(pool, serializedObject->inheritedTypeNameIndex, serializedObject->idNameIndex);
+
+ object->indexOfDefaultPropertyOrAlias = serializedObject->indexOfDefaultPropertyOrAlias;
+ object->defaultPropertyIsAlias = serializedObject->defaultPropertyIsAlias;
+
+ object->location = serializedObject->location;
+ object->locationOfIdProperty = serializedObject->locationOfIdProperty;
+
+ QVector<int> functionIndices;
+ functionIndices.reserve(serializedObject->nFunctions + serializedObject->nBindings / 2);
+
+ for (uint i = 0; i < serializedObject->nBindings; ++i) {
+ QmlIR::Binding *b = pool->New<QmlIR::Binding>();
+ *static_cast<QV4::CompiledData::Binding*>(b) = serializedObject->bindingTable()[i];
+ object->bindings->append(b);
+ if (b->type == QV4::CompiledData::Binding::Type_Script) {
+ functionIndices.append(b->value.compiledScriptIndex);
+ b->value.compiledScriptIndex = functionIndices.count() - 1;
+
+ QmlIR::CompiledFunctionOrExpression *foe = pool->New<QmlIR::CompiledFunctionOrExpression>();
+ foe->disableAcceleratedLookups = true;
+ foe->nameIndex = 0;
+
+ QQmlJS::AST::ExpressionNode *expr;
+
+ if (b->stringIndex != quint32(0)) {
+ const int start = output->code.length();
+ const QString script = output->stringAt(b->stringIndex);
+ const int length = script.length();
+ output->code.append(script);
+ expr = new (pool) FakeExpression(start, length);
+ } else
+ expr = new (pool) QQmlJS::AST::NullExpression();
+ foe->node = new (pool) QQmlJS::AST::ExpressionStatement(expr); // dummy
+ object->functionsAndExpressions->append(foe);
+ }
+ }
+
+ Q_ASSERT(object->functionsAndExpressions->count == functionIndices.count());
+
+ for (uint i = 0; i < serializedObject->nSignals; ++i) {
+ const QV4::CompiledData::Signal *serializedSignal = serializedObject->signalAt(i);
+ QmlIR::Signal *s = pool->New<QmlIR::Signal>();
+ s->nameIndex = serializedSignal->nameIndex;
+ s->location = serializedSignal->location;
+ s->parameters = pool->New<QmlIR::PoolList<QmlIR::SignalParameter> >();
+
+ for (uint i = 0; i < serializedSignal->nParameters; ++i) {
+ QmlIR::SignalParameter *p = pool->New<QmlIR::SignalParameter>();
+ *static_cast<QV4::CompiledData::Parameter*>(p) = *serializedSignal->parameterAt(i);
+ s->parameters->append(p);
+ }
+
+ object->qmlSignals->append(s);
+ }
+
+ const QV4::CompiledData::Property *serializedProperty = serializedObject->propertyTable();
+ for (uint i = 0; i < serializedObject->nProperties; ++i, ++serializedProperty) {
+ QmlIR::Property *p = pool->New<QmlIR::Property>();
+ *static_cast<QV4::CompiledData::Property*>(p) = *serializedProperty;
+ object->properties->append(p);
+ }
+
+ QQmlJS::Engine *jsParserEngine = &output->jsParserEngine;
+
+ const QV4::CompiledData::LEUInt32 *functionIdx = serializedObject->functionOffsetTable();
+ for (uint i = 0; i < serializedObject->nFunctions; ++i, ++functionIdx) {
+ QmlIR::Function *f = pool->New<QmlIR::Function>();
+ const QV4::CompiledData::Function *compiledFunction = unit->functionAt(*functionIdx);
+
+ functionIndices.append(*functionIdx);
+ f->index = functionIndices.count() - 1;
+ f->location = compiledFunction->location;
+ f->nameIndex = compiledFunction->nameIndex;
+
+ QQmlJS::AST::FormalParameterList *paramList = 0;
+ const QV4::CompiledData::LEUInt32 *formalNameIdx = compiledFunction->formalsTable();
+ for (uint i = 0; i < compiledFunction->nFormals; ++i, ++formalNameIdx) {
+ const QString formal = unit->stringAt(*formalNameIdx);
+ QStringRef paramNameRef = jsParserEngine->newStringRef(formal);
+
+ if (paramList)
+ paramList = new (pool) QQmlJS::AST::FormalParameterList(paramList, paramNameRef);
+ else
+ paramList = new (pool) QQmlJS::AST::FormalParameterList(paramNameRef);
+ }
+
+ if (paramList)
+ paramList = paramList->finish();
+
+ const QString name = unit->stringAt(compiledFunction->nameIndex);
+ f->functionDeclaration = new(pool) QQmlJS::AST::FunctionDeclaration(jsParserEngine->newStringRef(name), paramList, /*body*/0);
+
+ object->functions->append(f);
+ }
+
+ object->runtimeFunctionIndices.allocate(pool, functionIndices);
+
+ return object;
+}
+
#endif // V4_BOOTSTRAP
diff --git a/src/qml/compiler/qqmlirbuilder_p.h b/src/qml/compiler/qqmlirbuilder_p.h
index cc16dc2104..2022112e07 100644
--- a/src/qml/compiler/qqmlirbuilder_p.h
+++ b/src/qml/compiler/qqmlirbuilder_p.h
@@ -453,9 +453,9 @@ struct Q_QML_PRIVATE_EXPORT ScriptDirectivesCollector : public QQmlJS::Directive
QList<const QV4::CompiledData::Import *> imports;
bool hasPragmaLibrary;
- virtual void pragmaLibrary();
- virtual void importFile(const QString &jsfile, const QString &module, int lineNumber, int column);
- virtual void importModule(const QString &uri, const QString &version, const QString &module, int lineNumber, int column);
+ void pragmaLibrary() override;
+ void importFile(const QString &jsfile, const QString &module, int lineNumber, int column) override;
+ void importModule(const QString &uri, const QString &version, const QString &module, int lineNumber, int column) override;
};
struct Q_QML_PRIVATE_EXPORT IRBuilder : public QQmlJS::AST::Visitor
@@ -470,21 +470,21 @@ public:
using QQmlJS::AST::Visitor::visit;
using QQmlJS::AST::Visitor::endVisit;
- virtual bool visit(QQmlJS::AST::UiArrayMemberList *ast);
- virtual bool visit(QQmlJS::AST::UiImport *ast);
- virtual bool visit(QQmlJS::AST::UiPragma *ast);
- virtual bool visit(QQmlJS::AST::UiHeaderItemList *ast);
- virtual bool visit(QQmlJS::AST::UiObjectInitializer *ast);
- virtual bool visit(QQmlJS::AST::UiObjectMemberList *ast);
- virtual bool visit(QQmlJS::AST::UiParameterList *ast);
- virtual bool visit(QQmlJS::AST::UiProgram *);
- virtual bool visit(QQmlJS::AST::UiQualifiedId *ast);
- virtual bool visit(QQmlJS::AST::UiArrayBinding *ast);
- virtual bool visit(QQmlJS::AST::UiObjectBinding *ast);
- virtual bool visit(QQmlJS::AST::UiObjectDefinition *ast);
- virtual bool visit(QQmlJS::AST::UiPublicMember *ast);
- virtual bool visit(QQmlJS::AST::UiScriptBinding *ast);
- virtual bool visit(QQmlJS::AST::UiSourceElement *ast);
+ bool visit(QQmlJS::AST::UiArrayMemberList *ast) override;
+ bool visit(QQmlJS::AST::UiImport *ast) override;
+ bool visit(QQmlJS::AST::UiPragma *ast) override;
+ bool visit(QQmlJS::AST::UiHeaderItemList *ast) override;
+ bool visit(QQmlJS::AST::UiObjectInitializer *ast) override;
+ bool visit(QQmlJS::AST::UiObjectMemberList *ast) override;
+ bool visit(QQmlJS::AST::UiParameterList *ast) override;
+ bool visit(QQmlJS::AST::UiProgram *) override;
+ bool visit(QQmlJS::AST::UiQualifiedId *ast) override;
+ bool visit(QQmlJS::AST::UiArrayBinding *ast) override;
+ bool visit(QQmlJS::AST::UiObjectBinding *ast) override;
+ bool visit(QQmlJS::AST::UiObjectDefinition *ast) override;
+ bool visit(QQmlJS::AST::UiPublicMember *ast) override;
+ bool visit(QQmlJS::AST::UiScriptBinding *ast) override;
+ bool visit(QQmlJS::AST::UiSourceElement *ast) override;
void accept(QQmlJS::AST::Node *node);
@@ -602,8 +602,8 @@ struct Q_QML_PRIVATE_EXPORT JSCodeGen : public QQmlJS::Codegen
QVector<int> generateJSCodeForFunctionsAndBindings(const QList<CompiledFunctionOrExpression> &functions);
protected:
- virtual void beginFunctionBodyHook();
- virtual QV4::IR::Expr *fallbackNameLookup(const QString &name, int line, int col);
+ void beginFunctionBodyHook() override;
+ QV4::IR::Expr *fallbackNameLookup(const QString &name, int line, int col) override;
private:
QQmlPropertyData *lookupQmlCompliantProperty(QQmlPropertyCache *cache, const QString &name, bool *propertyExistsButForceNameLookup = 0);
@@ -622,6 +622,21 @@ private:
int _importedScriptsTemp;
};
+struct IRLoader {
+ IRLoader(const QV4::CompiledData::Unit *unit, QmlIR::Document *output);
+
+ void load();
+
+private:
+ QmlIR::Object *loadObject(const QV4::CompiledData::Object *serializedObject);
+
+ template <typename _Tp> _Tp *New() { return pool->New<_Tp>(); }
+
+ const QV4::CompiledData::Unit *unit;
+ QmlIR::Document *output;
+ QQmlJS::MemoryPool *pool;
+};
+
} // namespace QmlIR
QT_END_NAMESPACE
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp
index b7262e4333..109eb86c2e 100644
--- a/src/qml/compiler/qqmltypecompiler.cpp
+++ b/src/qml/compiler/qqmltypecompiler.cpp
@@ -57,12 +57,12 @@
QT_BEGIN_NAMESPACE
QQmlTypeCompiler::QQmlTypeCompiler(QQmlEnginePrivate *engine, QQmlTypeData *typeData,
- QmlIR::Document *parsedQML, const QQmlRefPointer<QQmlTypeNameCache> &importCache,
+ QmlIR::Document *parsedQML, const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache,
const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache)
: resolvedTypes(resolvedTypeCache)
, engine(engine)
, typeData(typeData)
- , importCache(importCache)
+ , typeNameCache(typeNameCache)
, document(parsedQML)
{
}
@@ -138,7 +138,7 @@ QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile()
sss.scan();
}
- QmlIR::JSCodeGen v4CodeGenerator(typeData->finalUrlString(), document->code, &document->jsModule, &document->jsParserEngine, document->program, importCache, &document->jsGenerator.stringTable);
+ QmlIR::JSCodeGen v4CodeGenerator(typeData->finalUrlString(), document->code, &document->jsModule, &document->jsParserEngine, document->program, typeNameCache, &document->jsGenerator.stringTable);
QQmlJSCodeGenerator jsCodeGen(this, &v4CodeGenerator);
if (!jsCodeGen.generateCodeForComponents())
return nullptr;
@@ -164,7 +164,7 @@ QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile()
QV4::CompiledData::CompilationUnit *compilationUnit = document->javaScriptCompilationUnit;
compilationUnit = document->javaScriptCompilationUnit;
- compilationUnit->importCache = importCache;
+ compilationUnit->typeNameCache = typeNameCache;
compilationUnit->resolvedTypes = resolvedTypes;
compilationUnit->propertyCaches = std::move(m_propertyCaches);
Q_ASSERT(compilationUnit->propertyCaches.count() == static_cast<int>(compilationUnit->data->nObjects));
@@ -471,7 +471,7 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio
QQmlJS::MemoryPool *pool = compiler->memoryPool();
QQmlJS::AST::FormalParameterList *paramList = 0;
- foreach (const QString &param, parameters) {
+ for (const QString &param : qAsConst(parameters)) {
QStringRef paramNameRef = compiler->newStringRef(param);
if (paramList)
@@ -1347,9 +1347,9 @@ bool QQmlJSCodeGenerator::compileJavaScriptCodeInObjectsRecursively(int objectIn
functionsToCompile << *foe;
}
const QVector<int> runtimeFunctionIndices = v4CodeGen->generateJSCodeForFunctionsAndBindings(functionsToCompile);
- QList<QQmlError> jsErrors = v4CodeGen->qmlErrors();
+ const QList<QQmlError> jsErrors = v4CodeGen->qmlErrors();
if (!jsErrors.isEmpty()) {
- foreach (const QQmlError &e, jsErrors)
+ for (const QQmlError &e : jsErrors)
compiler->recordError(e);
return false;
}
@@ -1728,7 +1728,7 @@ void QQmlIRFunctionCleanser::clean()
module->functions = newFunctions;
- foreach (QV4::IR::Function *function, module->functions) {
+ for (QV4::IR::Function *function : qAsConst(module->functions)) {
for (QV4::IR::BasicBlock *block : function->basicBlocks()) {
for (QV4::IR::Stmt *s : block->statements()) {
visit(s);
@@ -1736,7 +1736,7 @@ void QQmlIRFunctionCleanser::clean()
}
}
- foreach (QmlIR::Object *obj, *compiler->qmlObjects()) {
+ for (QmlIR::Object *obj : qAsConst(*compiler->qmlObjects())) {
for (int i = 0; i < obj->runtimeFunctionIndices.count; ++i)
obj->runtimeFunctionIndices[i] = newFunctionIndices[obj->runtimeFunctionIndices.at(i)];
}
diff --git a/src/qml/compiler/qqmltypecompiler_p.h b/src/qml/compiler/qqmltypecompiler_p.h
index de6abb4ced..2b59e7e42f 100644
--- a/src/qml/compiler/qqmltypecompiler_p.h
+++ b/src/qml/compiler/qqmltypecompiler_p.h
@@ -89,7 +89,7 @@ struct QQmlTypeCompiler
{
Q_DECLARE_TR_FUNCTIONS(QQmlTypeCompiler)
public:
- QQmlTypeCompiler(QQmlEnginePrivate *engine, QQmlTypeData *typeData, QmlIR::Document *document, const QQmlRefPointer<QQmlTypeNameCache> &importCache, const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache);
+ QQmlTypeCompiler(QQmlEnginePrivate *engine, QQmlTypeData *typeData, QmlIR::Document *document, const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache, const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache);
// --- interface used by QQmlPropertyCacheCreator
typedef QmlIR::Object CompiledObject;
@@ -139,7 +139,7 @@ private:
QList<QQmlError> errors;
QQmlEnginePrivate *engine;
QQmlTypeData *typeData;
- QQmlRefPointer<QQmlTypeNameCache> importCache;
+ QQmlRefPointer<QQmlTypeNameCache> typeNameCache;
QmlIR::Document *document;
// index is string index of type name (use obj->inheritedTypeNameIndex)
QHash<int, QQmlCustomParser*> customParsers;
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index e0def1021b..8d0126ebb3 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -73,6 +73,25 @@ static inline void setLocation(IR::Stmt *s, const SourceLocation &loc)
s->location = loc;
}
+static bool cjumpCanHandle(IR::AluOp op)
+{
+ switch (op) {
+ case IR::OpIn:
+ case IR::OpInstanceof:
+ case IR::OpEqual:
+ case IR::OpNotEqual:
+ case IR::OpGe:
+ case IR::OpGt:
+ case IR::OpLe:
+ case IR::OpLt:
+ case IR::OpStrictEqual:
+ case IR::OpStrictNotEqual:
+ return true;
+ default:
+ return false;
+ }
+}
+
Codegen::ScanFunctions::ScanFunctions(Codegen *cg, const QString &sourceCode, CompilationMode defaultProgramMode)
: _cg(cg)
, _sourceCode(sourceCode)
@@ -526,21 +545,21 @@ IR::Expr *Codegen::subscript(IR::Expr *base, IR::Expr *index)
if (hasError)
return 0;
- if (! base->asTemp() || base->asArgLocal()) {
+ if (! base->asTemp() && !base->asArgLocal()) {
const unsigned t = _block->newTemp();
move(_block->TEMP(t), base);
base = _block->TEMP(t);
}
- if (! index->asTemp() || index->asArgLocal()) {
+ if (! index->asTemp() && !index->asArgLocal() && !index->asConst()) {
const unsigned t = _block->newTemp();
move(_block->TEMP(t), index);
index = _block->TEMP(t);
}
Q_ASSERT(base->asTemp() || base->asArgLocal());
- Q_ASSERT(index->asTemp() || index->asArgLocal());
- return _block->SUBSCRIPT(base->asTemp(), index->asTemp());
+ Q_ASSERT(index->asTemp() || index->asArgLocal() || index->asConst());
+ return _block->SUBSCRIPT(base, index);
}
IR::Expr *Codegen::argument(IR::Expr *expr)
@@ -611,7 +630,7 @@ IR::Expr *Codegen::binop(IR::AluOp op, IR::Expr *left, IR::Expr *right, const AS
if (IR::Const *c1 = left->asConst()) {
if (IR::Const *c2 = right->asConst()) {
- if (c1->type == IR::NumberType && c2->type == IR::NumberType) {
+ if ((c1->type & IR::NumberType) && (c2->type & IR::NumberType)) {
switch (op) {
case IR::OpAdd: return _block->CONST(IR::NumberType, c1->value + c2->value);
case IR::OpAnd: return _block->CONST(IR::BoolType, c1->value ? c2->value : 0);
@@ -659,20 +678,20 @@ IR::Expr *Codegen::binop(IR::AluOp op, IR::Expr *left, IR::Expr *right, const AS
}
}
- if (!left->asTemp() && !left->asArgLocal()) {
+ if (!left->asTemp() && !left->asArgLocal() && !left->asConst()) {
const unsigned t = _block->newTemp();
setLocation(move(_block->TEMP(t), left), loc);
left = _block->TEMP(t);
}
- if (!right->asTemp() && !right->asArgLocal()) {
+ if (!right->asTemp() && !right->asArgLocal() && !right->asConst()) {
const unsigned t = _block->newTemp();
setLocation(move(_block->TEMP(t), right), loc);
right = _block->TEMP(t);
}
- Q_ASSERT(left->asTemp() || left->asArgLocal());
- Q_ASSERT(right->asTemp() || right->asArgLocal());
+ Q_ASSERT(left->asTemp() || left->asArgLocal() || left->asConst());
+ Q_ASSERT(right->asTemp() || right->asArgLocal() || right->asConst());
return _block->BINOP(op, left, right);
}
@@ -715,7 +734,7 @@ IR::Stmt *Codegen::cjump(IR::Expr *cond, IR::BasicBlock *iftrue, IR::BasicBlock
if (hasError)
return 0;
- if (! (cond->asTemp() || cond->asBinop())) {
+ if (! (cond->asTemp() || (cond->asBinop() && cjumpCanHandle(cond->asBinop()->op)) )) {
const unsigned t = _block->newTemp();
move(_block->TEMP(t), cond);
cond = _block->TEMP(t);
@@ -842,9 +861,16 @@ void Codegen::variableDeclaration(VariableDeclaration *ast)
Q_ASSERT(expr.code);
initializer = *expr;
- int initialized = _block->newTemp();
- move(_block->TEMP(initialized), initializer);
- move(identifier(ast->name.toString(), ast->identifierToken.startLine, ast->identifierToken.startColumn), _block->TEMP(initialized));
+ IR::Expr *lhs = identifier(ast->name.toString(), ast->identifierToken.startLine,
+ ast->identifierToken.startColumn);
+
+ if (lhs->asArgLocal()) {
+ move(lhs, initializer);
+ } else {
+ int initialized = _block->newTemp();
+ move(_block->TEMP(initialized), initializer);
+ move(lhs, _block->TEMP(initialized));
+ }
}
void Codegen::variableDeclarationList(VariableDeclarationList *ast)
@@ -1274,14 +1300,7 @@ bool Codegen::visit(BinaryExpression *ast)
if (_expr.accept(cx)) {
setLocation(cjump(binop(IR::binaryOperator(ast->op), left, *right, ast->operatorToken), _expr.iftrue, _expr.iffalse), ast->operatorToken);
} else {
- IR::Expr *e = binop(IR::binaryOperator(ast->op), left, *right, ast->operatorToken);
- if (e->asConst() || e->asString())
- _expr.code = e;
- else {
- const unsigned t = _block->newTemp();
- setLocation(move(_block->TEMP(t), e), ast->operatorToken);
- _expr.code = _block->TEMP(t);
- }
+ _expr.code = binop(IR::binaryOperator(ast->op), left, *right, ast->operatorToken);
}
break;
}
@@ -1307,14 +1326,7 @@ bool Codegen::visit(BinaryExpression *ast)
if (hasError)
return false;
- IR::Expr *e = binop(IR::binaryOperator(ast->op), left, *right, ast->operatorToken);
- if (e->asConst() || e->asString())
- _expr.code = e;
- else {
- const unsigned t = _block->newTemp();
- setLocation(move(_block->TEMP(t), e), ast->operatorToken);
- _expr.code = _block->TEMP(t);
- }
+ _expr.code = binop(IR::binaryOperator(ast->op), left, *right, ast->operatorToken);
break;
}
diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h
index 59199183bd..742ee79648 100644
--- a/src/qml/compiler/qv4codegen_p.h
+++ b/src/qml/compiler/qv4codegen_p.h
@@ -331,103 +331,103 @@ protected:
virtual void beginFunctionBodyHook() {}
// nodes
- virtual bool visit(AST::ArgumentList *ast);
- virtual bool visit(AST::CaseBlock *ast);
- virtual bool visit(AST::CaseClause *ast);
- virtual bool visit(AST::CaseClauses *ast);
- virtual bool visit(AST::Catch *ast);
- virtual bool visit(AST::DefaultClause *ast);
- virtual bool visit(AST::ElementList *ast);
- virtual bool visit(AST::Elision *ast);
- virtual bool visit(AST::Finally *ast);
- virtual bool visit(AST::FormalParameterList *ast);
- virtual bool visit(AST::FunctionBody *ast);
- virtual bool visit(AST::Program *ast);
- virtual bool visit(AST::PropertyNameAndValue *ast);
- virtual bool visit(AST::PropertyAssignmentList *ast);
- virtual bool visit(AST::PropertyGetterSetter *ast);
- virtual bool visit(AST::SourceElements *ast);
- virtual bool visit(AST::StatementList *ast);
- virtual bool visit(AST::UiArrayMemberList *ast);
- virtual bool visit(AST::UiImport *ast);
- virtual bool visit(AST::UiHeaderItemList *ast);
- virtual bool visit(AST::UiPragma *ast);
- virtual bool visit(AST::UiObjectInitializer *ast);
- virtual bool visit(AST::UiObjectMemberList *ast);
- virtual bool visit(AST::UiParameterList *ast);
- virtual bool visit(AST::UiProgram *ast);
- virtual bool visit(AST::UiQualifiedId *ast);
- virtual bool visit(AST::UiQualifiedPragmaId *ast);
- virtual bool visit(AST::VariableDeclaration *ast);
- virtual bool visit(AST::VariableDeclarationList *ast);
+ bool visit(AST::ArgumentList *ast) override;
+ bool visit(AST::CaseBlock *ast) override;
+ bool visit(AST::CaseClause *ast) override;
+ bool visit(AST::CaseClauses *ast) override;
+ bool visit(AST::Catch *ast) override;
+ bool visit(AST::DefaultClause *ast) override;
+ bool visit(AST::ElementList *ast) override;
+ bool visit(AST::Elision *ast) override;
+ bool visit(AST::Finally *ast) override;
+ bool visit(AST::FormalParameterList *ast) override;
+ bool visit(AST::FunctionBody *ast) override;
+ bool visit(AST::Program *ast) override;
+ bool visit(AST::PropertyNameAndValue *ast) override;
+ bool visit(AST::PropertyAssignmentList *ast) override;
+ bool visit(AST::PropertyGetterSetter *ast) override;
+ bool visit(AST::SourceElements *ast) override;
+ bool visit(AST::StatementList *ast) override;
+ bool visit(AST::UiArrayMemberList *ast) override;
+ bool visit(AST::UiImport *ast) override;
+ bool visit(AST::UiHeaderItemList *ast) override;
+ bool visit(AST::UiPragma *ast) override;
+ bool visit(AST::UiObjectInitializer *ast) override;
+ bool visit(AST::UiObjectMemberList *ast) override;
+ bool visit(AST::UiParameterList *ast) override;
+ bool visit(AST::UiProgram *ast) override;
+ bool visit(AST::UiQualifiedId *ast) override;
+ bool visit(AST::UiQualifiedPragmaId *ast) override;
+ bool visit(AST::VariableDeclaration *ast) override;
+ bool visit(AST::VariableDeclarationList *ast) override;
// expressions
- virtual bool visit(AST::Expression *ast);
- virtual bool visit(AST::ArrayLiteral *ast);
- virtual bool visit(AST::ArrayMemberExpression *ast);
- virtual bool visit(AST::BinaryExpression *ast);
- virtual bool visit(AST::CallExpression *ast);
- virtual bool visit(AST::ConditionalExpression *ast);
- virtual bool visit(AST::DeleteExpression *ast);
- virtual bool visit(AST::FalseLiteral *ast);
- virtual bool visit(AST::FieldMemberExpression *ast);
- virtual bool visit(AST::FunctionExpression *ast);
- virtual bool visit(AST::IdentifierExpression *ast);
- virtual bool visit(AST::NestedExpression *ast);
- virtual bool visit(AST::NewExpression *ast);
- virtual bool visit(AST::NewMemberExpression *ast);
- virtual bool visit(AST::NotExpression *ast);
- virtual bool visit(AST::NullExpression *ast);
- virtual bool visit(AST::NumericLiteral *ast);
- virtual bool visit(AST::ObjectLiteral *ast);
- virtual bool visit(AST::PostDecrementExpression *ast);
- virtual bool visit(AST::PostIncrementExpression *ast);
- virtual bool visit(AST::PreDecrementExpression *ast);
- virtual bool visit(AST::PreIncrementExpression *ast);
- virtual bool visit(AST::RegExpLiteral *ast);
- virtual bool visit(AST::StringLiteral *ast);
- virtual bool visit(AST::ThisExpression *ast);
- virtual bool visit(AST::TildeExpression *ast);
- virtual bool visit(AST::TrueLiteral *ast);
- virtual bool visit(AST::TypeOfExpression *ast);
- virtual bool visit(AST::UnaryMinusExpression *ast);
- virtual bool visit(AST::UnaryPlusExpression *ast);
- virtual bool visit(AST::VoidExpression *ast);
- virtual bool visit(AST::FunctionDeclaration *ast);
+ bool visit(AST::Expression *ast) override;
+ bool visit(AST::ArrayLiteral *ast) override;
+ bool visit(AST::ArrayMemberExpression *ast) override;
+ bool visit(AST::BinaryExpression *ast) override;
+ bool visit(AST::CallExpression *ast) override;
+ bool visit(AST::ConditionalExpression *ast) override;
+ bool visit(AST::DeleteExpression *ast) override;
+ bool visit(AST::FalseLiteral *ast) override;
+ bool visit(AST::FieldMemberExpression *ast) override;
+ bool visit(AST::FunctionExpression *ast) override;
+ bool visit(AST::IdentifierExpression *ast) override;
+ bool visit(AST::NestedExpression *ast) override;
+ bool visit(AST::NewExpression *ast) override;
+ bool visit(AST::NewMemberExpression *ast) override;
+ bool visit(AST::NotExpression *ast) override;
+ bool visit(AST::NullExpression *ast) override;
+ bool visit(AST::NumericLiteral *ast) override;
+ bool visit(AST::ObjectLiteral *ast) override;
+ bool visit(AST::PostDecrementExpression *ast) override;
+ bool visit(AST::PostIncrementExpression *ast) override;
+ bool visit(AST::PreDecrementExpression *ast) override;
+ bool visit(AST::PreIncrementExpression *ast) override;
+ bool visit(AST::RegExpLiteral *ast) override;
+ bool visit(AST::StringLiteral *ast) override;
+ bool visit(AST::ThisExpression *ast) override;
+ bool visit(AST::TildeExpression *ast) override;
+ bool visit(AST::TrueLiteral *ast) override;
+ bool visit(AST::TypeOfExpression *ast) override;
+ bool visit(AST::UnaryMinusExpression *ast) override;
+ bool visit(AST::UnaryPlusExpression *ast) override;
+ bool visit(AST::VoidExpression *ast) override;
+ bool visit(AST::FunctionDeclaration *ast) override;
// source elements
- virtual bool visit(AST::FunctionSourceElement *ast);
- virtual bool visit(AST::StatementSourceElement *ast);
+ bool visit(AST::FunctionSourceElement *ast) override;
+ bool visit(AST::StatementSourceElement *ast) override;
// statements
- virtual bool visit(AST::Block *ast);
- virtual bool visit(AST::BreakStatement *ast);
- virtual bool visit(AST::ContinueStatement *ast);
- virtual bool visit(AST::DebuggerStatement *ast);
- virtual bool visit(AST::DoWhileStatement *ast);
- virtual bool visit(AST::EmptyStatement *ast);
- virtual bool visit(AST::ExpressionStatement *ast);
- virtual bool visit(AST::ForEachStatement *ast);
- virtual bool visit(AST::ForStatement *ast);
- virtual bool visit(AST::IfStatement *ast);
- virtual bool visit(AST::LabelledStatement *ast);
- virtual bool visit(AST::LocalForEachStatement *ast);
- virtual bool visit(AST::LocalForStatement *ast);
- virtual bool visit(AST::ReturnStatement *ast);
- virtual bool visit(AST::SwitchStatement *ast);
- virtual bool visit(AST::ThrowStatement *ast);
- virtual bool visit(AST::TryStatement *ast);
- virtual bool visit(AST::VariableStatement *ast);
- virtual bool visit(AST::WhileStatement *ast);
- virtual bool visit(AST::WithStatement *ast);
+ bool visit(AST::Block *ast) override;
+ bool visit(AST::BreakStatement *ast) override;
+ bool visit(AST::ContinueStatement *ast) override;
+ bool visit(AST::DebuggerStatement *ast) override;
+ bool visit(AST::DoWhileStatement *ast) override;
+ bool visit(AST::EmptyStatement *ast) override;
+ bool visit(AST::ExpressionStatement *ast) override;
+ bool visit(AST::ForEachStatement *ast) override;
+ bool visit(AST::ForStatement *ast) override;
+ bool visit(AST::IfStatement *ast) override;
+ bool visit(AST::LabelledStatement *ast) override;
+ bool visit(AST::LocalForEachStatement *ast) override;
+ bool visit(AST::LocalForStatement *ast) override;
+ bool visit(AST::ReturnStatement *ast) override;
+ bool visit(AST::SwitchStatement *ast) override;
+ bool visit(AST::ThrowStatement *ast) override;
+ bool visit(AST::TryStatement *ast) override;
+ bool visit(AST::VariableStatement *ast) override;
+ bool visit(AST::WhileStatement *ast) override;
+ bool visit(AST::WithStatement *ast) override;
// ui object members
- virtual bool visit(AST::UiArrayBinding *ast);
- virtual bool visit(AST::UiObjectBinding *ast);
- virtual bool visit(AST::UiObjectDefinition *ast);
- virtual bool visit(AST::UiPublicMember *ast);
- virtual bool visit(AST::UiScriptBinding *ast);
- virtual bool visit(AST::UiSourceElement *ast);
+ bool visit(AST::UiArrayBinding *ast) override;
+ bool visit(AST::UiObjectBinding *ast) override;
+ bool visit(AST::UiObjectDefinition *ast) override;
+ bool visit(AST::UiPublicMember *ast) override;
+ bool visit(AST::UiScriptBinding *ast) override;
+ bool visit(AST::UiSourceElement *ast) override;
bool throwSyntaxErrorOnEvalOrArgumentsInStrictMode(QV4::IR::Expr* expr, const AST::SourceLocation &loc);
virtual void throwSyntaxError(const AST::SourceLocation &loc, const QString &detail);
@@ -486,39 +486,39 @@ protected:
void checkName(const QStringRef &name, const AST::SourceLocation &loc);
void checkForArguments(AST::FormalParameterList *parameters);
- virtual bool visit(AST::Program *ast);
- virtual void endVisit(AST::Program *);
+ bool visit(AST::Program *ast) override;
+ void endVisit(AST::Program *) override;
- virtual bool visit(AST::CallExpression *ast);
- virtual bool visit(AST::NewMemberExpression *ast);
- virtual bool visit(AST::ArrayLiteral *ast);
- virtual bool visit(AST::VariableDeclaration *ast);
- virtual bool visit(AST::IdentifierExpression *ast);
- virtual bool visit(AST::ExpressionStatement *ast);
- virtual bool visit(AST::FunctionExpression *ast);
+ bool visit(AST::CallExpression *ast) override;
+ bool visit(AST::NewMemberExpression *ast) override;
+ bool visit(AST::ArrayLiteral *ast) override;
+ bool visit(AST::VariableDeclaration *ast) override;
+ bool visit(AST::IdentifierExpression *ast) override;
+ bool visit(AST::ExpressionStatement *ast) override;
+ bool visit(AST::FunctionExpression *ast) override;
void enterFunction(AST::FunctionExpression *ast, bool enterName, bool isExpression = true);
- virtual void endVisit(AST::FunctionExpression *);
+ void endVisit(AST::FunctionExpression *) override;
- virtual bool visit(AST::ObjectLiteral *ast);
+ bool visit(AST::ObjectLiteral *ast) override;
- virtual bool visit(AST::PropertyGetterSetter *ast);
- virtual void endVisit(AST::PropertyGetterSetter *);
+ bool visit(AST::PropertyGetterSetter *ast) override;
+ void endVisit(AST::PropertyGetterSetter *) override;
- virtual bool visit(AST::FunctionDeclaration *ast);
- virtual void endVisit(AST::FunctionDeclaration *);
+ bool visit(AST::FunctionDeclaration *ast) override;
+ void endVisit(AST::FunctionDeclaration *) override;
- virtual bool visit(AST::WithStatement *ast);
+ bool visit(AST::WithStatement *ast) override;
- virtual bool visit(AST::DoWhileStatement *ast);
- virtual bool visit(AST::ForStatement *ast);
- virtual bool visit(AST::LocalForStatement *ast);
- virtual bool visit(AST::ForEachStatement *ast);
- virtual bool visit(AST::LocalForEachStatement *ast);
- virtual bool visit(AST::ThisExpression *ast);
+ bool visit(AST::DoWhileStatement *ast) override;
+ bool visit(AST::ForStatement *ast) override;
+ bool visit(AST::LocalForStatement *ast) override;
+ bool visit(AST::ForEachStatement *ast) override;
+ bool visit(AST::LocalForEachStatement *ast) override;
+ bool visit(AST::ThisExpression *ast) override;
- virtual bool visit(AST::Block *ast);
+ bool visit(AST::Block *ast) override;
protected:
void enterFunction(AST::Node *ast, const QString &name, AST::FormalParameterList *formals, AST::FunctionBody *body, AST::FunctionExpression *expr, bool isExpression);
@@ -544,8 +544,8 @@ public:
, engine(engine)
{}
- virtual void throwSyntaxError(const AST::SourceLocation &loc, const QString &detail);
- virtual void throwReferenceError(const AST::SourceLocation &loc, const QString &detail);
+ void throwSyntaxError(const AST::SourceLocation &loc, const QString &detail) override;
+ void throwReferenceError(const AST::SourceLocation &loc, const QString &detail) override;
private:
QV4::ExecutionEngine *engine;
};
diff --git a/src/qml/compiler/qv4compilationunitmapper_win.cpp b/src/qml/compiler/qv4compilationunitmapper_win.cpp
index 457b702ac3..37cac846a0 100644
--- a/src/qml/compiler/qv4compilationunitmapper_win.cpp
+++ b/src/qml/compiler/qv4compilationunitmapper_win.cpp
@@ -75,7 +75,6 @@ CompiledData::Unit *CompilationUnitMapper::open(const QString &cacheFileName, co
CloseHandle(handle);
});
-#if !defined(Q_OS_WINRT) || _MSC_VER >= 1900
CompiledData::Unit header;
DWORD bytesRead;
if (!ReadFile(handle, reinterpret_cast<char *>(&header), sizeof(header), &bytesRead, nullptr)) {
@@ -115,19 +114,12 @@ CompiledData::Unit *CompilationUnitMapper::open(const QString &cacheFileName, co
}
return reinterpret_cast<CompiledData::Unit*>(dataPtr);
-#else
- Q_UNUSED(sourcePath);
- *errorString = QStringLiteral("Compilation unit mapping not supported on WinRT 8.1");
- return nullptr;
-#endif
}
void CompilationUnitMapper::close()
{
-#if !defined(Q_OS_WINRT) || _MSC_VER >= 1900
if (dataPtr != nullptr)
UnmapViewOfFile(dataPtr);
-#endif
dataPtr = nullptr;
}
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index d8ff22e9ed..a8f065210b 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -52,7 +52,6 @@
#include "qv4compilationunitmapper_p.h"
#include <QQmlPropertyMap>
#include <QDateTime>
-#include <QSaveFile>
#include <QFile>
#include <QFileInfo>
#include <QScopedValueRollback>
@@ -62,6 +61,7 @@
#include <private/qqmlirbuilder_p.h>
#include <QCoreApplication>
#include <QCryptographicHash>
+#include <QSaveFile>
#include <algorithm>
@@ -77,6 +77,27 @@ namespace QV4 {
namespace CompiledData {
+#ifdef V4_BOOTSTRAP
+static QString cacheFilePath(const QString &localSourcePath)
+{
+ const QString localCachePath = localSourcePath + QLatin1Char('c');
+ return localCachePath;
+}
+#else
+static QString cacheFilePath(const QUrl &url)
+{
+ const QString localSourcePath = QQmlFile::urlToLocalFileOrQrc(url);
+ const QString localCachePath = localSourcePath + QLatin1Char('c');
+ if (QFileInfo(QFileInfo(localSourcePath).dir().absolutePath()).isWritable())
+ return localCachePath;
+ QCryptographicHash fileNameHash(QCryptographicHash::Sha1);
+ fileNameHash.addData(localSourcePath.toUtf8());
+ QString directory = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/qmlcache/");
+ QDir::root().mkpath(directory);
+ return directory + QString::fromUtf8(fileNameHash.result().toHex()) + QLatin1Char('.') + QFileInfo(localCachePath).completeSuffix();
+}
+#endif
+
#ifndef V4_BOOTSTRAP
CompilationUnit::CompilationUnit()
: data(0)
@@ -207,7 +228,7 @@ void CompilationUnit::unlink()
dependentScripts.at(ii)->release();
dependentScripts.clear();
- importCache = nullptr;
+ typeNameCache = nullptr;
qDeleteAll(resolvedTypes);
resolvedTypes.clear();
@@ -329,20 +350,68 @@ bool CompilationUnit::verifyChecksum(QQmlEngine *engine,
sizeof(data->dependencyMD5Checksum)) == 0;
}
-static QString cacheFilePath(const QUrl &url)
+bool CompilationUnit::loadFromDisk(const QUrl &url, EvalISelFactory *iselFactory, QString *errorString)
{
- const QString localSourcePath = QQmlFile::urlToLocalFileOrQrc(url);
- const QString localCachePath = localSourcePath + QLatin1Char('c');
- if (QFileInfo(QFileInfo(localSourcePath).dir().absolutePath()).isWritable())
- return localCachePath;
- QCryptographicHash fileNameHash(QCryptographicHash::Sha1);
- fileNameHash.addData(localSourcePath.toUtf8());
- QString directory = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/qmlcache/");
- QDir::root().mkpath(directory);
- return directory + QString::fromUtf8(fileNameHash.result().toHex()) + QLatin1Char('.') + QFileInfo(localCachePath).completeSuffix();
+ if (!QQmlFile::isLocalFile(url)) {
+ *errorString = QStringLiteral("File has to be a local file.");
+ return false;
+ }
+
+ const QString sourcePath = QQmlFile::urlToLocalFileOrQrc(url);
+ QScopedPointer<CompilationUnitMapper> cacheFile(new CompilationUnitMapper());
+
+ CompiledData::Unit *mappedUnit = cacheFile->open(cacheFilePath(url), sourcePath, errorString);
+ if (!mappedUnit)
+ return false;
+
+ const Unit * const oldDataPtr = (data && !(data->flags & QV4::CompiledData::Unit::StaticData)) ? data : nullptr;
+ QScopedValueRollback<const Unit *> dataPtrChange(data, mappedUnit);
+
+ if (sourcePath != QQmlFile::urlToLocalFileOrQrc(stringAt(data->sourceFileIndex))) {
+ *errorString = QStringLiteral("QML source file has moved to a different location.");
+ return false;
+ }
+
+ {
+ const QString foundArchitecture = stringAt(data->architectureIndex);
+ const QString expectedArchitecture = QSysInfo::buildAbi();
+ if (foundArchitecture != expectedArchitecture) {
+ *errorString = QString::fromUtf8("Architecture mismatch. Found %1 expected %2").arg(foundArchitecture).arg(expectedArchitecture);
+ return false;
+ }
+ }
+
+ {
+ const QString foundCodeGenerator = stringAt(data->codeGeneratorIndex);
+ const QString expectedCodeGenerator = iselFactory->codeGeneratorName;
+ if (foundCodeGenerator != expectedCodeGenerator) {
+ *errorString = QString::fromUtf8("Code generator mismatch. Found code generated by %1 but expected %2").arg(foundCodeGenerator).arg(expectedCodeGenerator);
+ return false;
+ }
+ }
+
+ if (!memoryMapCode(errorString))
+ return false;
+
+ dataPtrChange.commit();
+ free(const_cast<Unit*>(oldDataPtr));
+ backingFile.reset(cacheFile.take());
+ return true;
+}
+
+bool CompilationUnit::memoryMapCode(QString *errorString)
+{
+ *errorString = QStringLiteral("Missing code mapping backend");
+ return false;
}
+#endif // V4_BOOTSTRAP
+
+#if defined(V4_BOOTSTRAP)
+bool CompilationUnit::saveToDisk(const QString &unitUrl, QString *errorString)
+#else
bool CompilationUnit::saveToDisk(const QUrl &unitUrl, QString *errorString)
+#endif
{
errorString->clear();
@@ -351,10 +420,12 @@ bool CompilationUnit::saveToDisk(const QUrl &unitUrl, QString *errorString)
return false;
}
+#if !defined(V4_BOOTSTRAP)
if (!QQmlFile::isLocalFile(unitUrl)) {
*errorString = QStringLiteral("File has to be a local file.");
return false;
}
+#endif
#if QT_CONFIG(temporaryfile)
// Foo.qml -> Foo.qmlc
@@ -395,78 +466,105 @@ bool CompilationUnit::saveToDisk(const QUrl &unitUrl, QString *errorString)
#endif // QT_CONFIG(temporaryfile)
}
-bool CompilationUnit::loadFromDisk(const QUrl &url, EvalISelFactory *iselFactory, QString *errorString)
+void CompilationUnit::prepareCodeOffsetsForDiskStorage(Unit *unit)
{
- if (!QQmlFile::isLocalFile(url)) {
- *errorString = QStringLiteral("File has to be a local file.");
- return false;
- }
+ Q_UNUSED(unit);
+}
- const QString sourcePath = QQmlFile::urlToLocalFileOrQrc(url);
- QScopedPointer<CompilationUnitMapper> cacheFile(new CompilationUnitMapper());
+bool CompilationUnit::saveCodeToDisk(QIODevice *device, const Unit *unit, QString *errorString)
+{
+ Q_UNUSED(device);
+ Q_UNUSED(unit);
+ *errorString = QStringLiteral("Saving code to disk is not supported in this configuration");
+ return false;
+}
- CompiledData::Unit *mappedUnit = cacheFile->open(cacheFilePath(url), sourcePath, errorString);
- if (!mappedUnit)
- return false;
+Unit *CompilationUnit::createUnitData(QmlIR::Document *irDocument)
+{
+ if (!irDocument->javaScriptCompilationUnit->data)
+ return irDocument->jsGenerator.generateUnit(QV4::Compiler::JSUnitGenerator::GenerateWithoutStringTable);
- const Unit * const oldDataPtr = (data && !(data->flags & QV4::CompiledData::Unit::StaticData)) ? data : nullptr;
- QScopedValueRollback<const Unit *> dataPtrChange(data, mappedUnit);
+ QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit = irDocument->javaScriptCompilationUnit;
+ QV4::CompiledData::Unit *jsUnit = const_cast<QV4::CompiledData::Unit*>(irDocument->javaScriptCompilationUnit->data);
- if (sourcePath != QQmlFile::urlToLocalFileOrQrc(stringAt(data->sourceFileIndex))) {
- *errorString = QStringLiteral("QML source file has moved to a different location.");
- return false;
- }
+ QV4::Compiler::StringTableGenerator &stringTable = irDocument->jsGenerator.stringTable;
- {
- const QString foundArchitecture = stringAt(data->architectureIndex);
- const QString expectedArchitecture = QSysInfo::buildAbi();
- if (foundArchitecture != expectedArchitecture) {
- *errorString = QString::fromUtf8("Architecture mismatch. Found %1 expected %2").arg(foundArchitecture).arg(expectedArchitecture);
- return false;
+ // Collect signals that have had a change in signature (from onClicked to onClicked(mouse) for example)
+ // and now need fixing in the QV4::CompiledData. Also register strings at the same time, to finalize
+ // the string table.
+ QVector<quint32> changedSignals;
+ QVector<QQmlJS::AST::FormalParameterList*> changedSignalParameters;
+ for (QmlIR::Object *o: qAsConst(irDocument->objects)) {
+ for (QmlIR::Binding *binding = o->firstBinding(); binding; binding = binding->next) {
+ if (!(binding->flags & QV4::CompiledData::Binding::IsSignalHandlerExpression))
+ continue;
+
+ quint32 functionIndex = binding->value.compiledScriptIndex;
+ QmlIR::CompiledFunctionOrExpression *foe = o->functionsAndExpressions->slowAt(functionIndex);
+ if (!foe)
+ continue;
+
+ // save absolute index
+ changedSignals << o->runtimeFunctionIndices.at(functionIndex);
+
+ Q_ASSERT(foe->node);
+ Q_ASSERT(QQmlJS::AST::cast<QQmlJS::AST::FunctionDeclaration*>(foe->node));
+
+ QQmlJS::AST::FormalParameterList *parameters = QQmlJS::AST::cast<QQmlJS::AST::FunctionDeclaration*>(foe->node)->formals;
+ changedSignalParameters << parameters;
+
+ for (; parameters; parameters = parameters->next)
+ stringTable.registerString(parameters->name.toString());
}
}
- {
- const QString foundCodeGenerator = stringAt(data->codeGeneratorIndex);
- const QString expectedCodeGenerator = iselFactory->codeGeneratorName;
- if (foundCodeGenerator != expectedCodeGenerator) {
- *errorString = QString::fromUtf8("Code generator mismatch. Found code generated by %1 but expected %2").arg(foundCodeGenerator).arg(expectedCodeGenerator);
- return false;
+ QVector<quint32> signalParameterNameTable;
+ quint32 signalParameterNameTableOffset = jsUnit->unitSize;
+
+ // Update signal signatures
+ if (!changedSignals.isEmpty()) {
+ if (jsUnit == compilationUnit->data) {
+ char *unitCopy = (char*)malloc(jsUnit->unitSize);
+ memcpy(unitCopy, jsUnit, jsUnit->unitSize);
+ jsUnit = reinterpret_cast<QV4::CompiledData::Unit*>(unitCopy);
}
- }
- if (!memoryMapCode(errorString))
- return false;
+ for (int i = 0; i < changedSignals.count(); ++i) {
+ const uint functionIndex = changedSignals.at(i);
+ // The data is now read-write due to the copy above, so the const_cast is ok.
+ QV4::CompiledData::Function *function = const_cast<QV4::CompiledData::Function *>(jsUnit->functionAt(functionIndex));
+ Q_ASSERT(function->nFormals == quint32(0));
- dataPtrChange.commit();
- free(const_cast<Unit*>(oldDataPtr));
- backingFile.reset(cacheFile.take());
- return true;
-}
+ function->formalsOffset = signalParameterNameTableOffset - jsUnit->functionOffsetTable()[functionIndex];
-void CompilationUnit::prepareCodeOffsetsForDiskStorage(Unit *unit)
-{
- Q_UNUSED(unit);
-}
+ for (QQmlJS::AST::FormalParameterList *parameters = changedSignalParameters.at(i);
+ parameters; parameters = parameters->next) {
+ signalParameterNameTable.append(stringTable.getStringId(parameters->name.toString()));
+ function->nFormals = function->nFormals + 1;
+ }
-bool CompilationUnit::saveCodeToDisk(QIODevice *device, const Unit *unit, QString *errorString)
-{
- Q_UNUSED(device);
- Q_UNUSED(unit);
- *errorString = QStringLiteral("Saving code to disk is not supported in this configuration");
- return false;
-}
+ // Hack to ensure an activation is created.
+ function->flags |= QV4::CompiledData::Function::HasCatchOrWith | QV4::CompiledData::Function::HasDirectEval;
-bool CompilationUnit::memoryMapCode(QString *errorString)
-{
- *errorString = QStringLiteral("Missing code mapping backend");
- return false;
-}
-#endif // V4_BOOTSTRAP
+ signalParameterNameTableOffset += function->nFormals * sizeof(quint32);
+ }
+ }
-Unit *CompilationUnit::createUnitData(QmlIR::Document *irDocument)
-{
- return irDocument->jsGenerator.generateUnit(QV4::Compiler::JSUnitGenerator::GenerateWithoutStringTable);
+ if (!signalParameterNameTable.isEmpty()) {
+ Q_ASSERT(jsUnit != compilationUnit->data);
+ const uint signalParameterTableSize = signalParameterNameTable.count() * sizeof(quint32);
+ uint newSize = jsUnit->unitSize + signalParameterTableSize;
+ const uint oldSize = jsUnit->unitSize;
+ char *unitWithSignalParameters = (char*)realloc(jsUnit, newSize);
+ memcpy(unitWithSignalParameters + oldSize, signalParameterNameTable.constData(), signalParameterTableSize);
+ jsUnit = reinterpret_cast<QV4::CompiledData::Unit*>(unitWithSignalParameters);
+ jsUnit->unitSize = newSize;
+ }
+
+ if (jsUnit != compilationUnit->data)
+ jsUnit->flags &= ~QV4::CompiledData::Unit::StaticData;
+
+ return jsUnit;
}
QString Binding::valueAsString(const Unit *unit) const
@@ -629,7 +727,7 @@ static QByteArray ownLibraryChecksum()
if (checksumInitialized)
return libraryChecksum;
checksumInitialized = true;
-#if defined(Q_OS_UNIX) && !defined(QT_NO_DYNAMIC_CAST)
+#if defined(Q_OS_UNIX) && !defined(QT_NO_DYNAMIC_CAST) && !defined(Q_OS_INTEGRITY)
Dl_info libInfo;
if (dladdr(reinterpret_cast<const void *>(&ownLibraryChecksum), &libInfo) != 0) {
QFile library(QFile::decodeName(libInfo.dli_fname));
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h
index 2682365182..13a0c4b075 100644
--- a/src/qml/compiler/qv4compileddata_p.h
+++ b/src/qml/compiler/qv4compileddata_p.h
@@ -71,7 +71,7 @@
QT_BEGIN_NAMESPACE
// Bump this whenever the compiler data structures change in an incompatible way.
-#define QV4_DATA_STRUCTURE_VERSION 0x08
+#define QV4_DATA_STRUCTURE_VERSION 0x09
class QIODevice;
class QQmlPropertyCache;
@@ -133,7 +133,7 @@ struct Location
QJsonPrivate::qle_bitfield<20, 12> column;
};
- Location() { line = 0; column = 0; }
+ Location() { line.val = 0; column.val = 0; }
inline bool operator<(const Location &other) const {
return line < other.line ||
@@ -153,7 +153,7 @@ struct RegExp
QJsonPrivate::qle_bitfield<4, 28> stringIndex;
};
- RegExp() { flags = 0; stringIndex = 0; }
+ RegExp() { flags.val = 0; stringIndex.val = 0; }
};
struct Lookup
@@ -171,7 +171,7 @@ struct Lookup
QJsonPrivate::qle_bitfield<4, 28> nameIndex;
};
- Lookup() { type_and_flags = 0; nameIndex = 0; }
+ Lookup() { type_and_flags.val = 0; nameIndex.val = 0; }
};
struct JSClassMember
@@ -625,7 +625,8 @@ struct Unit
StaticData = 0x4, // Unit data persistent in memory?
IsSingleton = 0x8,
IsSharedLibrary = 0x10, // .pragma shared?
- ContainsMachineCode = 0x20 // used to determine if we need to mmap with execute permissions
+ ContainsMachineCode = 0x20, // used to determine if we need to mmap with execute permissions
+ PendingTypeCompilation = 0x40 // the QML data structures present are incomplete and require type compilation
};
LEUInt32 flags;
LEUInt32 stringTableSize;
@@ -777,31 +778,7 @@ struct TypeReferenceMap : QHash<int, TypeReference>
};
#ifndef V4_BOOTSTRAP
-struct ResolvedTypeReference
-{
- ResolvedTypeReference()
- : type(0)
- , majorVersion(0)
- , minorVersion(0)
- , isFullyDynamicType(false)
- {}
-
- QQmlType *type;
- QQmlRefPointer<QQmlPropertyCache> typePropertyCache;
- QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit;
-
- int majorVersion;
- int minorVersion;
- // Types such as QQmlPropertyMap can add properties dynamically at run-time and
- // therefore cannot have a property cache installed when instantiated.
- bool isFullyDynamicType;
-
- QQmlPropertyCache *propertyCache() const;
- QQmlPropertyCache *createPropertyCache(QQmlEngine *);
- bool addToHash(QCryptographicHash *hash, QQmlEngine *engine);
-
- void doDynamicTypeCheck();
-};
+struct ResolvedTypeReference;
// map from name index
// While this could be a hash, a map is chosen here to provide a stable
// order, which is used to calculating a check-sum on dependent meta-objects.
@@ -841,10 +818,14 @@ struct Q_QML_PRIVATE_EXPORT CompilationUnit : public QQmlRefCount
#ifndef V4_BOOTSTRAP
ExecutionEngine *engine;
+#endif
+
+ QV4::Heap::String **runtimeStrings; // Array
+
+#ifndef V4_BOOTSTRAP
QString fileName() const { return data->stringAt(data->sourceFileIndex); }
QUrl url() const { if (m_url.isNull) m_url = QUrl(fileName()); return m_url; }
- QV4::Heap::String **runtimeStrings; // Array
QV4::Lookup *runtimeLookups;
QV4::Value *runtimeRegularExpressions;
QV4::InternalClass **runtimeClasses;
@@ -855,7 +836,7 @@ struct Q_QML_PRIVATE_EXPORT CompilationUnit : public QQmlRefCount
QQmlPropertyCacheVector propertyCaches;
QQmlPropertyCache *rootPropertyCache() const { return propertyCaches.at(data->indexOfRootObject); }
- QQmlRefPointer<QQmlTypeNameCache> importCache;
+ QQmlRefPointer<QQmlTypeNameCache> typeNameCache;
// index is object index. This allows fast access to the
// property data when initializing bindings, avoiding expensive
@@ -918,17 +899,53 @@ struct Q_QML_PRIVATE_EXPORT CompilationUnit : public QQmlRefCount
void destroy() Q_DECL_OVERRIDE;
- bool saveToDisk(const QUrl &unitUrl, QString *errorString);
bool loadFromDisk(const QUrl &url, EvalISelFactory *iselFactory, QString *errorString);
protected:
virtual void linkBackendToEngine(QV4::ExecutionEngine *engine) = 0;
- virtual void prepareCodeOffsetsForDiskStorage(CompiledData::Unit *unit);
- virtual bool saveCodeToDisk(QIODevice *device, const CompiledData::Unit *unit, QString *errorString);
virtual bool memoryMapCode(QString *errorString);
#endif // V4_BOOTSTRAP
+
+public:
+#if defined(V4_BOOTSTRAP)
+ bool saveToDisk(const QString &unitUrl, QString *errorString);
+#else
+ bool saveToDisk(const QUrl &unitUrl, QString *errorString);
+#endif
+
+protected:
+ virtual void prepareCodeOffsetsForDiskStorage(CompiledData::Unit *unit);
+ virtual bool saveCodeToDisk(QIODevice *device, const CompiledData::Unit *unit, QString *errorString);
};
+#ifndef V4_BOOTSTRAP
+struct ResolvedTypeReference
+{
+ ResolvedTypeReference()
+ : type(0)
+ , majorVersion(0)
+ , minorVersion(0)
+ , isFullyDynamicType(false)
+ {}
+
+ QQmlType *type;
+ QQmlRefPointer<QQmlPropertyCache> typePropertyCache;
+ QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit;
+
+ int majorVersion;
+ int minorVersion;
+ // Types such as QQmlPropertyMap can add properties dynamically at run-time and
+ // therefore cannot have a property cache installed when instantiated.
+ bool isFullyDynamicType;
+
+ QQmlPropertyCache *propertyCache() const;
+ QQmlPropertyCache *createPropertyCache(QQmlEngine *);
+ bool addToHash(QCryptographicHash *hash, QQmlEngine *engine);
+
+ void doDynamicTypeCheck();
+};
+#endif
+
}
}
diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp
index e1ea3a9b88..9cfac4a676 100644
--- a/src/qml/compiler/qv4compiler.cpp
+++ b/src/qml/compiler/qv4compiler.cpp
@@ -212,7 +212,7 @@ int QV4::Compiler::JSUnitGenerator::registerJSClass(int count, IR::ExprList *arg
QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(GeneratorOption option)
{
registerString(irModule->fileName);
- foreach (QV4::IR::Function *f, irModule->functions) {
+ for (QV4::IR::Function *f : qAsConst(irModule->functions)) {
registerString(*f->name);
for (int i = 0; i < f->formals.size(); ++i)
registerString(*f->formals.at(i));
@@ -220,7 +220,7 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(GeneratorO
registerString(*f->locals.at(i));
}
- CompiledData::LEUInt32 *functionOffsets = reinterpret_cast<CompiledData::LEUInt32*>(alloca(irModule->functions.size() * sizeof(CompiledData::LEUInt32)));
+ Q_ALLOCA_VAR(CompiledData::LEUInt32, functionOffsets, irModule->functions.size() * sizeof(CompiledData::LEUInt32));
uint jsClassDataOffset = 0;
char *dataPtr;
@@ -244,7 +244,7 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(GeneratorO
}
CompiledData::Lookup *lookupsToWrite = reinterpret_cast<CompiledData::Lookup*>(dataPtr + unit->offsetToLookupTable);
- foreach (const CompiledData::Lookup &l, lookups)
+ for (const CompiledData::Lookup &l : qAsConst(lookups))
*lookupsToWrite++ = l;
CompiledData::RegExp *regexpTable = reinterpret_cast<CompiledData::RegExp *>(dataPtr + unit->offsetToRegexpTable);
diff --git a/src/qml/compiler/qv4instr_moth_p.h b/src/qml/compiler/qv4instr_moth_p.h
index ca4e0b73d4..53d9956315 100644
--- a/src/qml/compiler/qv4instr_moth_p.h
+++ b/src/qml/compiler/qv4instr_moth_p.h
@@ -52,10 +52,11 @@
//
#include <private/qv4global_p.h>
#include <private/qv4value_p.h>
-#include <private/qv4function_p.h>
#include <private/qv4runtime_p.h>
+#if !defined(V4_BOOTSTRAP)
QT_REQUIRE_CONFIG(qml_interpreter);
+#endif
QT_BEGIN_NAMESPACE
diff --git a/src/qml/compiler/qv4isel_moth.cpp b/src/qml/compiler/qv4isel_moth.cpp
index f2bd57ad8f..04844302d9 100644
--- a/src/qml/compiler/qv4isel_moth.cpp
+++ b/src/qml/compiler/qv4isel_moth.cpp
@@ -39,15 +39,15 @@
#include "qv4isel_util_p.h"
#include "qv4isel_moth_p.h"
-#include "qv4vme_moth_p.h"
#include "qv4ssa_p.h"
-#include <private/qv4debugging_p.h>
-#include <private/qv4function_p.h>
-#include <private/qv4regexpobject_p.h>
#include <private/qv4compileddata_p.h>
-#include <private/qqmlengine_p.h>
#include <wtf/MathExtras.h>
+#if !defined(V4_BOOTSTRAP)
+#include "qv4vme_moth_p.h"
+#include <private/qv4function_p.h>
+#endif
+
#undef USE_TYPE_INFO
using namespace QV4;
@@ -209,7 +209,7 @@ void InstructionSelection::run(int functionIndex)
ConvertTemps().toStackSlots(_function);
}
- QSet<IR::Jump *> removableJumps = opt.calculateOptionalJumps();
+ BitVector removableJumps = opt.calculateOptionalJumps();
qSwap(_removableJumps, removableJumps);
IR::Stmt *cs = 0;
@@ -297,7 +297,7 @@ QQmlRefPointer<QV4::CompiledData::CompilationUnit> InstructionSelection::backend
{
compilationUnit->codeRefs.resize(irModule->functions.size());
int i = 0;
- foreach (IR::Function *irFunction, irModule->functions)
+ for (IR::Function *irFunction : qAsConst(irModule->functions))
compilationUnit->codeRefs[i++] = codeRefs[irFunction];
QQmlRefPointer<QV4::CompiledData::CompilationUnit> result;
result.adopt(compilationUnit.take());
@@ -955,7 +955,7 @@ void InstructionSelection::visitJump(IR::Jump *s)
{
if (s->target == _nextBlock)
return;
- if (_removableJumps.contains(s))
+ if (_removableJumps.at(_block->index()))
return;
addDebugInstruction();
@@ -1185,8 +1185,11 @@ void InstructionSelection::callBuiltinPushWithScope(IR::Expr *arg)
void InstructionSelection::callBuiltinPopScope()
{
+ QT_WARNING_PUSH
+ QT_WARNING_DISABLE_GCC("-Wuninitialized")
Instruction::CallBuiltinPopScope call;
addInstruction(call);
+ QT_WARNING_POP
}
void InstructionSelection::callBuiltinDeclareVar(bool deletable, const QString &name)
@@ -1335,8 +1338,11 @@ void InstructionSelection::callBuiltinSetupArgumentObject(IR::Expr *result)
void QV4::Moth::InstructionSelection::callBuiltinConvertThisToObject()
{
+ QT_WARNING_PUSH
+ QT_WARNING_DISABLE_GCC("-Wuninitialized")
Instruction::CallBuiltinConvertThisToObject call;
addInstruction(call);
+ QT_WARNING_POP
}
ptrdiff_t InstructionSelection::addInstructionHelper(Instr::Type type, Instr &instr)
@@ -1425,6 +1431,8 @@ CompilationUnit::~CompilationUnit()
{
}
+#if !defined(V4_BOOTSTRAP)
+
void CompilationUnit::linkBackendToEngine(QV4::ExecutionEngine *engine)
{
#ifdef MOTH_THREADED_INTERPRETER
@@ -1461,6 +1469,31 @@ void CompilationUnit::linkBackendToEngine(QV4::ExecutionEngine *engine)
}
}
+bool CompilationUnit::memoryMapCode(QString *errorString)
+{
+ Q_UNUSED(errorString);
+ codeRefs.resize(data->functionTableSize);
+
+ const char *basePtr = reinterpret_cast<const char *>(data);
+
+ for (uint i = 0; i < data->functionTableSize; ++i) {
+ const CompiledData::Function *compiledFunction = data->functionAt(i);
+ const char *codePtr = const_cast<const char *>(reinterpret_cast<const char *>(basePtr + compiledFunction->codeOffset));
+#ifdef MOTH_THREADED_INTERPRETER
+ // for the threaded interpreter we need to make a copy of the data because it needs to be
+ // modified for the instruction handler addresses.
+ QByteArray code(codePtr, compiledFunction->codeSize);
+#else
+ QByteArray code = QByteArray::fromRawData(codePtr, compiledFunction->codeSize);
+#endif
+ codeRefs[i] = code;
+ }
+
+ return true;
+}
+
+#endif // V4_BOOTSTRAP
+
void CompilationUnit::prepareCodeOffsetsForDiskStorage(CompiledData::Unit *unit)
{
const int codeAlignment = 16;
@@ -1482,7 +1515,7 @@ bool CompilationUnit::saveCodeToDisk(QIODevice *device, const CompiledData::Unit
QByteArray padding;
-#ifdef MOTH_THREADED_INTERPRETER
+#if defined(MOTH_THREADED_INTERPRETER) && !defined(V4_BOOTSTRAP)
// Map from instruction label back to instruction type. Only needed when persisting
// already linked compilation units;
QHash<void*, int> reverseInstructionMapping;
@@ -1511,7 +1544,7 @@ bool CompilationUnit::saveCodeToDisk(QIODevice *device, const CompiledData::Unit
QByteArray code = codeRefs.at(i);
-#ifdef MOTH_THREADED_INTERPRETER
+#if defined(MOTH_THREADED_INTERPRETER) && !defined(V4_BOOTSTRAP)
if (!reverseInstructionMapping.isEmpty()) {
char *codePtr = code.data(); // detaches
int index = 0;
@@ -1541,29 +1574,6 @@ bool CompilationUnit::saveCodeToDisk(QIODevice *device, const CompiledData::Unit
return true;
}
-bool CompilationUnit::memoryMapCode(QString *errorString)
-{
- Q_UNUSED(errorString);
- codeRefs.resize(data->functionTableSize);
-
- const char *basePtr = reinterpret_cast<const char *>(data);
-
- for (uint i = 0; i < data->functionTableSize; ++i) {
- const CompiledData::Function *compiledFunction = data->functionAt(i);
- const char *codePtr = const_cast<const char *>(reinterpret_cast<const char *>(basePtr + compiledFunction->codeOffset));
-#ifdef MOTH_THREADED_INTERPRETER
- // for the threaded interpreter we need to make a copy of the data because it needs to be
- // modified for the instruction handler addresses.
- QByteArray code(codePtr, compiledFunction->codeSize);
-#else
- QByteArray code = QByteArray::fromRawData(codePtr, compiledFunction->codeSize);
-#endif
- codeRefs[i] = code;
- }
-
- return true;
-}
-
QQmlRefPointer<CompiledData::CompilationUnit> ISelFactory::createUnitForLoading()
{
QQmlRefPointer<CompiledData::CompilationUnit> result;
diff --git a/src/qml/compiler/qv4isel_moth_p.h b/src/qml/compiler/qv4isel_moth_p.h
index 74323a2912..41469f1985 100644
--- a/src/qml/compiler/qv4isel_moth_p.h
+++ b/src/qml/compiler/qv4isel_moth_p.h
@@ -54,11 +54,14 @@
#include <private/qv4global_p.h>
#include <private/qv4isel_p.h>
#include <private/qv4isel_util_p.h>
+#include <private/qv4util_p.h>
#include <private/qv4jsir_p.h>
#include <private/qv4value_p.h>
#include "qv4instr_moth_p.h"
+#if !defined(V4_BOOTSTRAP)
QT_REQUIRE_CONFIG(qml_interpreter);
+#endif
QT_BEGIN_NAMESPACE
@@ -68,10 +71,12 @@ namespace Moth {
struct CompilationUnit : public QV4::CompiledData::CompilationUnit
{
virtual ~CompilationUnit();
+#if !defined(V4_BOOTSTRAP)
void linkBackendToEngine(QV4::ExecutionEngine *engine) Q_DECL_OVERRIDE;
+ bool memoryMapCode(QString *errorString) Q_DECL_OVERRIDE;
+#endif
void prepareCodeOffsetsForDiskStorage(CompiledData::Unit *unit) Q_DECL_OVERRIDE;
bool saveCodeToDisk(QIODevice *device, const CompiledData::Unit *unit, QString *errorString) Q_DECL_OVERRIDE;
- bool memoryMapCode(QString *errorString) Q_DECL_OVERRIDE;
QVector<QByteArray> codeRefs;
@@ -85,68 +90,68 @@ public:
InstructionSelection(QQmlEnginePrivate *qmlEngine, QV4::ExecutableAllocator *execAllocator, IR::Module *module, QV4::Compiler::JSUnitGenerator *jsGenerator, EvalISelFactory *iselFactory);
~InstructionSelection();
- virtual void run(int functionIndex);
+ void run(int functionIndex) override;
protected:
- virtual QQmlRefPointer<CompiledData::CompilationUnit> backendCompileStep();
-
- virtual void visitJump(IR::Jump *);
- virtual void visitCJump(IR::CJump *);
- virtual void visitRet(IR::Ret *);
-
- virtual void callBuiltinInvalid(IR::Name *func, IR::ExprList *args, IR::Expr *result);
- virtual void callBuiltinTypeofQmlContextProperty(IR::Expr *base, IR::Member::MemberKind kind, int propertyIndex, IR::Expr *result);
- virtual void callBuiltinTypeofMember(IR::Expr *base, const QString &name, IR::Expr *result);
- virtual void callBuiltinTypeofSubscript(IR::Expr *base, IR::Expr *index, IR::Expr *result);
- virtual void callBuiltinTypeofName(const QString &name, IR::Expr *result);
- virtual void callBuiltinTypeofValue(IR::Expr *value, IR::Expr *result);
- virtual void callBuiltinDeleteMember(IR::Expr *base, const QString &name, IR::Expr *result);
- virtual void callBuiltinDeleteSubscript(IR::Expr *base, IR::Expr *index, IR::Expr *result);
- virtual void callBuiltinDeleteName(const QString &name, IR::Expr *result);
- virtual void callBuiltinDeleteValue(IR::Expr *result);
- virtual void callBuiltinThrow(IR::Expr *arg);
- virtual void callBuiltinReThrow();
- virtual void callBuiltinUnwindException(IR::Expr *);
- virtual void callBuiltinPushCatchScope(const QString &exceptionName);
- virtual void callBuiltinForeachIteratorObject(IR::Expr *arg, IR::Expr *result);
- virtual void callBuiltinForeachNextPropertyname(IR::Expr *arg, IR::Expr *result);
- virtual void callBuiltinPushWithScope(IR::Expr *arg);
- virtual void callBuiltinPopScope();
- virtual void callBuiltinDeclareVar(bool deletable, const QString &name);
- virtual void callBuiltinDefineArray(IR::Expr *result, IR::ExprList *args);
- virtual void callBuiltinDefineObjectLiteral(IR::Expr *result, int keyValuePairCount, IR::ExprList *keyValuePairs, IR::ExprList *arrayEntries, bool needSparseArray);
- virtual void callBuiltinSetupArgumentObject(IR::Expr *result);
- virtual void callBuiltinConvertThisToObject();
- virtual void callValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result);
- virtual void callQmlContextProperty(IR::Expr *base, IR::Member::MemberKind kind, int propertyIndex, IR::ExprList *args, IR::Expr *result);
- virtual void callProperty(IR::Expr *base, const QString &name, IR::ExprList *args, IR::Expr *result);
- virtual void callSubscript(IR::Expr *base, IR::Expr *index, IR::ExprList *args, IR::Expr *result);
- virtual void convertType(IR::Expr *source, IR::Expr *target);
- virtual void constructActivationProperty(IR::Name *func, IR::ExprList *args, IR::Expr *result);
- virtual void constructProperty(IR::Expr *base, const QString &name, IR::ExprList *args, IR::Expr *result);
- virtual void constructValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result);
- virtual void loadThisObject(IR::Expr *e);
- virtual void loadQmlContext(IR::Expr *e);
- virtual void loadQmlImportedScripts(IR::Expr *e);
- virtual void loadQmlSingleton(const QString &name, IR::Expr *e);
- virtual void loadConst(IR::Const *sourceConst, IR::Expr *e);
- virtual void loadString(const QString &str, IR::Expr *target);
- virtual void loadRegexp(IR::RegExp *sourceRegexp, IR::Expr *target);
- virtual void getActivationProperty(const IR::Name *name, IR::Expr *target);
- virtual void setActivationProperty(IR::Expr *source, const QString &targetName);
- virtual void initClosure(IR::Closure *closure, IR::Expr *target);
- virtual void getProperty(IR::Expr *base, const QString &name, IR::Expr *target);
- virtual void setProperty(IR::Expr *source, IR::Expr *targetBase, const QString &targetName);
- virtual void setQmlContextProperty(IR::Expr *source, IR::Expr *targetBase, IR::Member::MemberKind kind, int propertyIndex);
- virtual void setQObjectProperty(IR::Expr *source, IR::Expr *targetBase, int propertyIndex);
- virtual void getQmlContextProperty(IR::Expr *source, IR::Member::MemberKind kind, int index, bool captureRequired, IR::Expr *target);
- virtual void getQObjectProperty(IR::Expr *base, int propertyIndex, bool captureRequired, bool isSingleton, int attachedPropertiesId, IR::Expr *target);
- virtual void getElement(IR::Expr *base, IR::Expr *index, IR::Expr *target);
- virtual void setElement(IR::Expr *source, IR::Expr *targetBase, IR::Expr *targetIndex);
- virtual void copyValue(IR::Expr *source, IR::Expr *target);
- virtual void swapValues(IR::Expr *source, IR::Expr *target);
- virtual void unop(IR::AluOp oper, IR::Expr *source, IR::Expr *target);
- virtual void binop(IR::AluOp oper, IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target);
+ QQmlRefPointer<CompiledData::CompilationUnit> backendCompileStep() override;
+
+ void visitJump(IR::Jump *) override;
+ void visitCJump(IR::CJump *) override;
+ void visitRet(IR::Ret *) override;
+
+ void callBuiltinInvalid(IR::Name *func, IR::ExprList *args, IR::Expr *result) override;
+ void callBuiltinTypeofQmlContextProperty(IR::Expr *base, IR::Member::MemberKind kind, int propertyIndex, IR::Expr *result) override;
+ void callBuiltinTypeofMember(IR::Expr *base, const QString &name, IR::Expr *result) override;
+ void callBuiltinTypeofSubscript(IR::Expr *base, IR::Expr *index, IR::Expr *result) override;
+ void callBuiltinTypeofName(const QString &name, IR::Expr *result) override;
+ void callBuiltinTypeofValue(IR::Expr *value, IR::Expr *result) override;
+ void callBuiltinDeleteMember(IR::Expr *base, const QString &name, IR::Expr *result) override;
+ void callBuiltinDeleteSubscript(IR::Expr *base, IR::Expr *index, IR::Expr *result) override;
+ void callBuiltinDeleteName(const QString &name, IR::Expr *result) override;
+ void callBuiltinDeleteValue(IR::Expr *result) override;
+ void callBuiltinThrow(IR::Expr *arg) override;
+ void callBuiltinReThrow() override;
+ void callBuiltinUnwindException(IR::Expr *) override;
+ void callBuiltinPushCatchScope(const QString &exceptionName) override;
+ void callBuiltinForeachIteratorObject(IR::Expr *arg, IR::Expr *result) override;
+ void callBuiltinForeachNextPropertyname(IR::Expr *arg, IR::Expr *result) override;
+ void callBuiltinPushWithScope(IR::Expr *arg) override;
+ void callBuiltinPopScope() override;
+ void callBuiltinDeclareVar(bool deletable, const QString &name) override;
+ void callBuiltinDefineArray(IR::Expr *result, IR::ExprList *args) override;
+ void callBuiltinDefineObjectLiteral(IR::Expr *result, int keyValuePairCount, IR::ExprList *keyValuePairs, IR::ExprList *arrayEntries, bool needSparseArray) override;
+ void callBuiltinSetupArgumentObject(IR::Expr *result) override;
+ void callBuiltinConvertThisToObject() override;
+ void callValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result) override;
+ void callQmlContextProperty(IR::Expr *base, IR::Member::MemberKind kind, int propertyIndex, IR::ExprList *args, IR::Expr *result) override;
+ void callProperty(IR::Expr *base, const QString &name, IR::ExprList *args, IR::Expr *result) override;
+ void callSubscript(IR::Expr *base, IR::Expr *index, IR::ExprList *args, IR::Expr *result) override;
+ void convertType(IR::Expr *source, IR::Expr *target) override;
+ void constructActivationProperty(IR::Name *func, IR::ExprList *args, IR::Expr *result) override;
+ void constructProperty(IR::Expr *base, const QString &name, IR::ExprList *args, IR::Expr *result) override;
+ void constructValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result) override;
+ void loadThisObject(IR::Expr *e) override;
+ void loadQmlContext(IR::Expr *e) override;
+ void loadQmlImportedScripts(IR::Expr *e) override;
+ void loadQmlSingleton(const QString &name, IR::Expr *e) override;
+ void loadConst(IR::Const *sourceConst, IR::Expr *e) override;
+ void loadString(const QString &str, IR::Expr *target) override;
+ void loadRegexp(IR::RegExp *sourceRegexp, IR::Expr *target) override;
+ void getActivationProperty(const IR::Name *name, IR::Expr *target) override;
+ void setActivationProperty(IR::Expr *source, const QString &targetName) override;
+ void initClosure(IR::Closure *closure, IR::Expr *target) override;
+ void getProperty(IR::Expr *base, const QString &name, IR::Expr *target) override;
+ void setProperty(IR::Expr *source, IR::Expr *targetBase, const QString &targetName) override;
+ void setQmlContextProperty(IR::Expr *source, IR::Expr *targetBase, IR::Member::MemberKind kind, int propertyIndex) override;
+ void setQObjectProperty(IR::Expr *source, IR::Expr *targetBase, int propertyIndex) override;
+ void getQmlContextProperty(IR::Expr *source, IR::Member::MemberKind kind, int index, bool captureRequired, IR::Expr *target) override;
+ void getQObjectProperty(IR::Expr *base, int propertyIndex, bool captureRequired, bool isSingleton, int attachedPropertiesId, IR::Expr *target) override;
+ void getElement(IR::Expr *base, IR::Expr *index, IR::Expr *target) override;
+ void setElement(IR::Expr *source, IR::Expr *targetBase, IR::Expr *targetIndex) override;
+ void copyValue(IR::Expr *source, IR::Expr *target) override;
+ void swapValues(IR::Expr *source, IR::Expr *target) override;
+ void unop(IR::AluOp oper, IR::Expr *source, IR::Expr *target) override;
+ void binop(IR::AluOp oper, IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target) override;
private:
Param binopHelper(IR::AluOp oper, IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target);
@@ -199,7 +204,7 @@ private:
uchar *_codeNext;
uchar *_codeEnd;
- QSet<IR::Jump *> _removableJumps;
+ BitVector _removableJumps;
IR::Stmt *_currentStatement;
QScopedPointer<CompilationUnit> compilationUnit;
diff --git a/src/qml/compiler/qv4jsir_p.h b/src/qml/compiler/qv4jsir_p.h
index a614d3fe1c..23ebe0c962 100644
--- a/src/qml/compiler/qv4jsir_p.h
+++ b/src/qml/compiler/qv4jsir_p.h
@@ -315,20 +315,20 @@ struct Q_AUTOTEST_EXPORT Expr {
Expr(ExprKind exprKind): type(UnknownType), exprKind(exprKind) {}
bool isLValue() const;
- Const *asConst() { return as<Const>(); }
- String *asString() { return as<String>(); }
- RegExp *asRegExp() { return as<RegExp>(); }
- Name *asName() { return as<Name>(); }
- Temp *asTemp() { return as<Temp>(); }
- ArgLocal *asArgLocal() { return as<ArgLocal>(); }
- Closure *asClosure() { return as<Closure>(); }
- Convert *asConvert() { return as<Convert>(); }
- Unop *asUnop() { return as<Unop>(); }
- Binop *asBinop() { return as<Binop>(); }
- Call *asCall() { return as<Call>(); }
- New *asNew() { return as<New>(); }
- Subscript *asSubscript() { return as<Subscript>(); }
- Member *asMember() { return as<Member>(); }
+ Const *asConst();
+ String *asString();
+ RegExp *asRegExp();
+ Name *asName();
+ Temp *asTemp();
+ ArgLocal *asArgLocal();
+ Closure *asClosure();
+ Convert *asConvert();
+ Unop *asUnop();
+ Binop *asBinop();
+ Call *asCall();
+ New *asNew();
+ Subscript *asSubscript();
+ Member *asMember();
};
#define EXPR_VISIT_ALL_KINDS(e) \
@@ -783,12 +783,12 @@ struct Stmt {
Stmt *asTerminator();
- Exp *asExp() { return as<Exp>(); }
- Move *asMove() { return as<Move>(); }
- Jump *asJump() { return as<Jump>(); }
- CJump *asCJump() { return as<CJump>(); }
- Ret *asRet() { return as<Ret>(); }
- Phi *asPhi() { return as<Phi>(); }
+ Exp *asExp();
+ Move *asMove();
+ Jump *asJump();
+ CJump *asCJump();
+ Ret *asRet();
+ Phi *asPhi();
int id() const { return _id; }
@@ -1730,6 +1730,28 @@ inline Stmt *BasicBlock::RET(Expr *expr)
return s;
}
+inline Const *Expr::asConst() { return as<Const>(); }
+inline String *Expr::asString() { return as<String>(); }
+inline RegExp *Expr::asRegExp() { return as<RegExp>(); }
+inline Name *Expr::asName() { return as<Name>(); }
+inline Temp *Expr::asTemp() { return as<Temp>(); }
+inline ArgLocal *Expr::asArgLocal() { return as<ArgLocal>(); }
+inline Closure *Expr::asClosure() { return as<Closure>(); }
+inline Convert *Expr::asConvert() { return as<Convert>(); }
+inline Unop *Expr::asUnop() { return as<Unop>(); }
+inline Binop *Expr::asBinop() { return as<Binop>(); }
+inline Call *Expr::asCall() { return as<Call>(); }
+inline New *Expr::asNew() { return as<New>(); }
+inline Subscript *Expr::asSubscript() { return as<Subscript>(); }
+inline Member *Expr::asMember() { return as<Member>(); }
+
+inline Exp *Stmt::asExp() { return as<Exp>(); }
+inline Move *Stmt::asMove() { return as<Move>(); }
+inline Jump *Stmt::asJump() { return as<Jump>(); }
+inline CJump *Stmt::asCJump() { return as<CJump>(); }
+inline Ret *Stmt::asRet() { return as<Ret>(); }
+inline Phi *Stmt::asPhi() { return as<Phi>(); }
+
} // end of namespace IR
} // end of namespace QV4
diff --git a/src/qml/compiler/qv4ssa.cpp b/src/qml/compiler/qv4ssa.cpp
index 45ca56584f..cc542e94e7 100644
--- a/src/qml/compiler/qv4ssa.cpp
+++ b/src/qml/compiler/qv4ssa.cpp
@@ -1123,7 +1123,7 @@ public:
{
QVector<UntypedTemp> res;
res.reserve(tempCount());
- foreach (const DefUse &du, _defUses)
+ for (const DefUse &du : _defUses)
if (du.isValid())
res.append(UntypedTemp(du.temp));
return res;
@@ -1150,7 +1150,7 @@ public:
{
Q_ASSERT(static_cast<unsigned>(variable.index) < _defUses.size());
QVector<Stmt *> &uses = _defUses[variable.index].uses;
- foreach (Stmt *stmt, newUses)
+ for (Stmt *stmt : newUses)
if (std::find(uses.begin(), uses.end(), stmt) == uses.end())
uses.push_back(stmt);
}
@@ -1226,7 +1226,7 @@ public:
QVector<Stmt*> removeDefUses(Stmt *s)
{
QVector<Stmt*> defStmts;
- foreach (const Temp &usedVar, usedVars(s)) {
+ for (const Temp &usedVar : usedVars(s)) {
if (Stmt *ds = defStmt(usedVar))
defStmts += ds;
removeUse(s, usedVar);
@@ -1247,7 +1247,7 @@ public:
buf.open(QIODevice::WriteOnly);
QTextStream qout(&buf);
qout << "Defines and uses:" << endl;
- foreach (const DefUse &du, _defUses) {
+ for (const DefUse &du : _defUses) {
if (!du.isValid())
continue;
qout << '%' << du.temp.index;
@@ -1255,14 +1255,14 @@ public:
<< ", statement: " << du.defStmt->id()
<< endl;
qout << " uses:";
- foreach (Stmt *s, du.uses)
+ for (Stmt *s : du.uses)
qout << ' ' << s->id();
qout << endl;
}
qout << "Uses per statement:" << endl;
for (size_t i = 0, ei = _usesPerStatement.size(); i != ei; ++i) {
qout << " " << i << ":";
- foreach (const Temp &t, _usesPerStatement[i])
+ for (const Temp &t : _usesPerStatement[i])
qout << ' ' << t.index;
qout << endl;
}
@@ -1633,7 +1633,7 @@ bool hasPhiOnlyUses(Phi *phi, const DefUses &defUses, QBitArray &collectedPhis)
{
collectedPhis.setBit(phi->id());
- foreach (Stmt *use, defUses.uses(*phi->targetTemp)) {
+ for (Stmt *use : defUses.uses(*phi->targetTemp)) {
Phi *dependentPhi = use->asPhi();
if (!dependentPhi)
return false; // there is a use by a non-phi node
@@ -1679,7 +1679,7 @@ void cleanupPhis(DefUses &defUses)
const Temp &targetVar = *phi->targetTemp;
defUses.defStmtBlock(targetVar)->removeStatement(phi);
- foreach (const Temp &usedVar, defUses.usedVars(phi))
+ for (const Temp &usedVar : defUses.usedVars(phi))
defUses.removeUse(phi, usedVar);
defUses.removeDef(targetVar);
}
@@ -1729,7 +1729,7 @@ public:
worklist.assign(worklist.size(), false);
worklistSize = 0;
- foreach (Stmt *s, stmts) {
+ for (Stmt *s : stmts) {
if (!s)
continue;
@@ -1802,7 +1802,7 @@ public:
StatementWorklist &operator+=(const QVector<Stmt *> &stmts)
{
- foreach (Stmt *s, stmts)
+ for (Stmt *s : stmts)
this->operator+=(s);
return *this;
@@ -2091,7 +2091,7 @@ public:
theTemp = temp;
if (Stmt *defStmt = defUses.defStmt(temp.temp))
visit(defStmt);
- foreach (Stmt *use, defUses.uses(temp.temp))
+ for (Stmt *use : defUses.uses(temp.temp))
visit(use);
}
@@ -2245,7 +2245,7 @@ private:
it = ty;
if (DebugTypeInference) {
- foreach (Stmt *s, _defUses.uses(*t)) {
+ for (Stmt *s : _defUses.uses(*t)) {
QBuffer buf;
buf.open(QIODevice::WriteOnly);
QTextStream qout(&buf);
@@ -2605,7 +2605,7 @@ public:
}
PropagateTempTypes propagator(_defUses);
- foreach (const UntypedTemp &t, knownOk) {
+ for (const UntypedTemp &t : qAsConst(knownOk)) {
propagator.run(t, SInt32Type);
if (Stmt *defStmt = _defUses.defStmt(t.temp)) {
if (Move *m = defStmt->asMove()) {
@@ -2629,7 +2629,7 @@ private:
if (uses.isEmpty())
return false;
- foreach (Stmt *use, uses) {
+ for (Stmt *use : uses) {
if (Move *m = use->asMove()) {
Temp *targetTemp = m->target->asTemp();
@@ -2758,7 +2758,7 @@ public:
visit(s);
}
- foreach (const Conversion &conversion, _conversions) {
+ for (const Conversion &conversion : qAsConst(_conversions)) {
IR::Move *move = conversion.stmt->asMove();
// Note: isel only supports move into member when source is a temp, so convert
@@ -3165,7 +3165,8 @@ public:
std::vector<BasicBlock *> backedges;
backedges.reserve(4);
- foreach (BasicBlock *bb, dt.calculateDFNodeIterOrder()) {
+ const auto order = dt.calculateDFNodeIterOrder();
+ for (BasicBlock *bb : order) {
Q_ASSERT(!bb->isRemoved());
backedges.clear();
@@ -3188,12 +3189,12 @@ public:
if (!DebugLoopDetection)
return;
- foreach (LoopInfo *info, loopInfos) {
+ for (const LoopInfo *info : loopInfos) {
qDebug() << "Loop header:" << info->loopHeader->index()
<< "for loop" << quint64(info);
- foreach (BasicBlock *bb, info->loopBody)
+ for (BasicBlock *bb : info->loopBody)
qDebug() << " " << bb->index();
- foreach (LoopInfo *nested, info->nestedLoops)
+ for (LoopInfo *nested : info->nestedLoops)
qDebug() << " sub loop:" << quint64(nested);
qDebug() << " parent loop:" << quint64(info->parentLoop);
}
@@ -3277,15 +3278,15 @@ private:
findLoop(loopHeader)->loopBody.append(bb);
}
- foreach (LoopInfo *info, loopInfos) {
- if (BasicBlock *containingLoopHeader = info->loopHeader->containingGroup())
- findLoop(containingLoopHeader)->addNestedLoop(info);
+ for (int i = 0, size = loopInfos.size(); i < size; ++i) {
+ if (BasicBlock *containingLoopHeader = loopInfos.at(i)->loopHeader->containingGroup())
+ findLoop(containingLoopHeader)->addNestedLoop(loopInfos.at(i));
}
}
LoopInfo *findLoop(BasicBlock *loopHeader)
{
- foreach (LoopInfo *info, loopInfos) {
+ for (LoopInfo *info : qAsConst(loopInfos)) {
if (info->loopHeader == loopHeader)
return info;
}
@@ -3459,8 +3460,8 @@ public:
};
#ifndef QT_NO_DEBUG
-void checkCriticalEdges(QVector<BasicBlock *> basicBlocks) {
- foreach (BasicBlock *bb, basicBlocks) {
+void checkCriticalEdges(const QVector<BasicBlock *> &basicBlocks) {
+ for (BasicBlock *bb : basicBlocks) {
if (bb && bb->out.size() > 1) {
for (BasicBlock *bb2 : bb->out) {
if (bb2 && bb2->in.size() > 1) {
@@ -3606,7 +3607,7 @@ public:
if (Temp *r = _replacement->asTemp()) {
if (_defUses.defStmt(*r)->asPhi()) {
BasicBlock *replacementDefBlock = _defUses.defStmtBlock(*r);
- foreach (Stmt *use, uses) {
+ for (Stmt *use : uses) {
if (Phi *usePhi = use->asPhi()) {
if (_defUses.defStmtBlock(*usePhi->targetTemp) == replacementDefBlock)
return false;
@@ -3621,7 +3622,7 @@ public:
newUses->reserve(uses.size());
// qout << " " << uses.size() << " uses:"<<endl;
- foreach (Stmt *use, uses) {
+ for (Stmt *use : uses) {
// qout<<" ";use->dump(qout);qout<<"\n";
visit(use);
// qout<<" -> ";use->dump(qout);qout<<"\n";
@@ -3780,7 +3781,7 @@ void unlink(BasicBlock *from, BasicBlock *to, IR::Function *func, DefUses &defUs
return;
to->in.remove(idx);
- foreach (Stmt *outStmt, to->statements()) {
+ for (Stmt *outStmt : to->statements()) {
if (!outStmt)
continue;
if (Phi *phi = outStmt->asPhi()) {
@@ -3798,7 +3799,7 @@ void unlink(BasicBlock *from, BasicBlock *to, IR::Function *func, DefUses &defUs
static bool isReachable(BasicBlock *bb, const DominatorTree &dt)
{
- foreach (BasicBlock *in, bb->in) {
+ for (BasicBlock *in : bb->in) {
if (in->isRemoved())
continue;
if (dt.dominates(bb, in)) // a back-edge, not interesting
@@ -3968,13 +3969,13 @@ void cfg2dot(IR::Function *f, const QVector<LoopDetection::LoopInfo *> &loops =
struct Util {
QTextStream &qout;
Util(QTextStream &qout): qout(qout) {}
- void genLoop(LoopDetection::LoopInfo *loop)
+ void genLoop(const LoopDetection::LoopInfo *loop)
{
qout << " subgraph \"cluster" << quint64(loop) << "\" {\n";
qout << " L" << loop->loopHeader->index() << ";\n";
- foreach (BasicBlock *bb, loop->loopBody)
+ for (BasicBlock *bb : loop->loopBody)
qout << " L" << bb->index() << ";\n";
- foreach (LoopDetection::LoopInfo *nested, loop->nestedLoops)
+ for (LoopDetection::LoopInfo *nested : loop->nestedLoops)
genLoop(nested);
qout << " }\n";
}
@@ -3985,7 +3986,7 @@ void cfg2dot(IR::Function *f, const QVector<LoopDetection::LoopInfo *> &loops =
else name = QStringLiteral("%1").arg((unsigned long long)f);
qout << "digraph \"" << name << "\" { ordering=out;\n";
- foreach (LoopDetection::LoopInfo *l, loops) {
+ for (LoopDetection::LoopInfo *l : loops) {
if (l->parentLoop == 0)
Util(qout).genLoop(l);
}
@@ -4490,7 +4491,8 @@ public:
qout << "Life ranges:" << endl;
qout << "Intervals:" << endl;
- foreach (const LifeTimeInterval *range, _sortedIntervals->intervals()) {
+ const auto intervals = _sortedIntervals->intervals();
+ for (const LifeTimeInterval *range : intervals) {
range->dump(qout);
qout << endl;
}
@@ -4750,7 +4752,7 @@ private:
clonedStmt = phi;
phi->targetTemp = clone(p->targetTemp);
- foreach (Expr *in, p->incoming)
+ for (Expr *in : p->incoming)
phi->incoming.append(clone(in));
block->appendStatement(phi);
} else {
@@ -4780,7 +4782,7 @@ public:
void run(const QVector<LoopDetection::LoopInfo *> &loops)
{
- foreach (LoopDetection::LoopInfo *loopInfo, loops)
+ for (LoopDetection::LoopInfo *loopInfo : loops)
peelLoop(loopInfo);
}
@@ -4884,7 +4886,7 @@ private:
// The original loop is now peeled off, and won't jump back to the loop header. Meaning, it
// is not a loop anymore, so unmark it.
loop->loopHeader->markAsGroupStart(false);
- foreach (BasicBlock *bb, loop->loopBody)
+ for (BasicBlock *bb : qAsConst(loop->loopBody))
bb->setContainingGroup(loop->loopHeader->containingGroup());
// calculate the idoms in a separate loop, because addBasicBlock in the previous loop will
@@ -4902,7 +4904,7 @@ private:
}
BasicBlockSet siblings(f);
- foreach (BasicBlock *bb, loopExits)
+ for (BasicBlock *bb : qAsConst(loopExits))
dt.collectSiblings(bb, siblings);
dt.recalculateIDoms(siblings, loop->loopHeader);
@@ -5150,7 +5152,7 @@ void LifeTimeInterval::setFrom(int from) {
Q_ASSERT(from > 0);
if (_ranges.isEmpty()) { // this is the case where there is no use, only a define
- _ranges.prepend(Range(from, from));
+ _ranges.prepend(LifeTimeIntervalRange(from, from));
if (_end == InvalidPosition)
_end = from;
} else {
@@ -5164,17 +5166,17 @@ void LifeTimeInterval::addRange(int from, int to) {
Q_ASSERT(to >= from);
if (_ranges.isEmpty()) {
- _ranges.prepend(Range(from, to));
+ _ranges.prepend(LifeTimeIntervalRange(from, to));
_end = to;
return;
}
- Range *p = &_ranges.first();
+ LifeTimeIntervalRange *p = &_ranges.first();
if (to + 1 >= p->start && p->end + 1 >= from) {
p->start = qMin(p->start, from);
p->end = qMax(p->end, to);
while (_ranges.count() > 1) {
- Range *p1 = p + 1;
+ LifeTimeIntervalRange *p1 = p + 1;
if (p->end + 1 < p1->start || p1->end + 1 < p->start)
break;
p1->start = qMin(p->start, p1->start);
@@ -5184,10 +5186,10 @@ void LifeTimeInterval::addRange(int from, int to) {
}
} else {
if (to < p->start) {
- _ranges.prepend(Range(from, to));
+ _ranges.prepend(LifeTimeIntervalRange(from, to));
} else {
Q_ASSERT(from > _ranges.last().end);
- _ranges.push_back(Range(from, to));
+ _ranges.push_back(LifeTimeIntervalRange(from, to));
}
}
@@ -5233,7 +5235,7 @@ LifeTimeInterval LifeTimeInterval::split(int atPosition, int newStart)
} else {
// find the first range where the temp will get active again:
while (!newInterval._ranges.isEmpty()) {
- const Range &range = newInterval._ranges.first();
+ const LifeTimeIntervalRange &range = newInterval._ranges.first();
if (range.start > newStart) {
// The split position is before the start of the range. Either we managed to skip
// over the correct range, or we got an invalid split request. Either way, this
@@ -5549,14 +5551,30 @@ LifeTimeIntervals::Ptr Optimizer::lifeTimeIntervals() const
return lifeRanges.intervals();
}
-QSet<Jump *> Optimizer::calculateOptionalJumps()
+static int countPhis(BasicBlock *bb)
{
- QSet<Jump *> optional;
- QSet<BasicBlock *> reachableWithoutJump;
+ int count = 0;
+ for (Stmt *s : bb->statements()) {
+ if (s->isa<Phi>())
+ ++count;
+ else
+ break;
+ }
+ return count;
+}
+
+// Basic blocks can have only 1 terminator. This function returns a bit vector, where a 1 on a
+// certain index indicates that the terminator (jump) at the end of the basic block with that index
+// can be omitted.
+BitVector Optimizer::calculateOptionalJumps()
+{
const int maxSize = function->basicBlockCount();
- optional.reserve(maxSize);
- reachableWithoutJump.reserve(maxSize);
+ BitVector optional(maxSize, false);
+ if (maxSize < 2)
+ return optional;
+
+ BitVector reachableWithoutJump(maxSize, false);
for (int i = maxSize - 1; i >= 0; --i) {
BasicBlock *bb = function->basicBlock(i);
@@ -5564,17 +5582,17 @@ QSet<Jump *> Optimizer::calculateOptionalJumps()
continue;
if (Jump *jump = bb->statements().last()->asJump()) {
- if (reachableWithoutJump.contains(jump->target)) {
- if (bb->statements().size() > 1)
+ if (reachableWithoutJump.at(jump->target->index())) {
+ if (bb->statements().size() - countPhis(bb)> 1)
reachableWithoutJump.clear();
- optional.insert(jump);
- reachableWithoutJump.insert(bb);
+ optional.setBit(bb->index());
+ reachableWithoutJump.setBit(bb->index());
continue;
}
}
reachableWithoutJump.clear();
- reachableWithoutJump.insert(bb);
+ reachableWithoutJump.setBit(bb->index());
}
return optional;
@@ -5745,7 +5763,7 @@ QList<IR::Move *> MoveMapping::insertMoves(BasicBlock *bb, IR::Function *functio
newMoves.reserve(_moves.size());
int insertionPoint = atEnd ? bb->statements().size() - 1 : 0;
- foreach (const Move &m, _moves) {
+ for (const Move &m : _moves) {
IR::Move *move = function->NewStmt<IR::Move>();
move->init(clone(m.to, function), clone(m.from, function));
move->swap = m.needsSwap;
@@ -5764,7 +5782,7 @@ void MoveMapping::dump() const
QTextStream os(&buf);
IRPrinter printer(&os);
os << "Move mapping has " << _moves.size() << " moves..." << endl;
- foreach (const Move &m, _moves) {
+ for (const Move &m : _moves) {
os << "\t";
printer.print(m.to);
if (m.needsSwap)
diff --git a/src/qml/compiler/qv4ssa_p.h b/src/qml/compiler/qv4ssa_p.h
index 977739e5d2..24257e99e9 100644
--- a/src/qml/compiler/qv4ssa_p.h
+++ b/src/qml/compiler/qv4ssa_p.h
@@ -53,6 +53,7 @@
#include "qv4jsir_p.h"
#include "qv4isel_util_p.h"
+#include <private/qv4util_p.h>
#include <QtCore/QSharedPointer>
QT_BEGIN_NAMESPACE
@@ -62,20 +63,28 @@ class QQmlEnginePrivate;
namespace QV4 {
namespace IR {
-class Q_AUTOTEST_EXPORT LifeTimeInterval {
-public:
- struct Range {
- int start;
- int end;
+struct LifeTimeIntervalRange {
+ int start;
+ int end;
- Range(int start = InvalidPosition, int end = InvalidPosition)
- : start(start)
- , end(end)
- {}
+ LifeTimeIntervalRange(int start = -1, int end = -1)
+ : start(start)
+ , end(end)
+ {}
- bool covers(int position) const { return start <= position && position <= end; }
- };
- typedef QVarLengthArray<Range, 4> Ranges;
+ bool covers(int position) const { return start <= position && position <= end; }
+};
+} // IR namespace
+} // QV4 namespace
+
+Q_DECLARE_TYPEINFO(QV4::IR::LifeTimeIntervalRange, Q_PRIMITIVE_TYPE);
+
+namespace QV4 {
+namespace IR {
+
+class Q_AUTOTEST_EXPORT LifeTimeInterval {
+public:
+ typedef QVarLengthArray<LifeTimeIntervalRange, 4> Ranges;
private:
Temp _temp;
@@ -136,7 +145,7 @@ public:
// Validate the new range
if (_end != InvalidPosition) {
Q_ASSERT(!_ranges.isEmpty());
- for (const Range &range : qAsConst(_ranges)) {
+ for (const LifeTimeIntervalRange &range : qAsConst(_ranges)) {
Q_ASSERT(range.start >= 0);
Q_ASSERT(range.end >= 0);
Q_ASSERT(range.start <= range.end);
@@ -246,7 +255,7 @@ public:
LifeTimeIntervals::Ptr lifeTimeIntervals() const;
- QSet<IR::Jump *> calculateOptionalJumps();
+ BitVector calculateOptionalJumps();
static void showMeTheCode(Function *function, const char *marker);
@@ -341,7 +350,7 @@ public:
}
protected:
- virtual int allocateFreeSlot()
+ int allocateFreeSlot() override
{
for (int i = 0, ei = _slotIsInUse.size(); i != ei; ++i) {
if (!_slotIsInUse[i]) {
@@ -358,7 +367,7 @@ protected:
return -1;
}
- virtual void process(IR::Stmt *s)
+ void process(IR::Stmt *s) override
{
// qDebug("L%d statement %d:", _currentBasicBlock->index, s->id);
@@ -412,8 +421,8 @@ protected:
}
}
moves.order();
- QList<IR::Move *> newMoves = moves.insertMoves(_currentBasicBlock, _function, true);
- foreach (IR::Move *move, newMoves)
+ const QList<IR::Move *> newMoves = moves.insertMoves(_currentBasicBlock, _function, true);
+ for (IR::Move *move : newMoves)
visit(move);
}
}
@@ -438,13 +447,13 @@ protected:
// qDebug() << "\t - force activating temp" << t.index << "on slot" << _stackSlotForTemp[t.index];
}
- virtual void visitPhi(IR::Phi *phi)
+ void visitPhi(IR::Phi *phi) override
{
Q_UNUSED(phi);
#if !defined(QT_NO_DEBUG)
Q_ASSERT(_stackSlotForTemp.contains(phi->targetTemp->index));
Q_ASSERT(_slotIsInUse[_stackSlotForTemp[phi->targetTemp->index]]);
- foreach (IR::Expr *e, phi->incoming) {
+ for (IR::Expr *e : phi->incoming) {
if (IR::Temp *t = e->asTemp())
Q_ASSERT(_stackSlotForTemp.contains(t->index));
}
@@ -457,7 +466,6 @@ protected:
Q_DECLARE_TYPEINFO(QV4::IR::LifeTimeInterval, Q_MOVABLE_TYPE);
-Q_DECLARE_TYPEINFO(QV4::IR::LifeTimeInterval::Range, Q_PRIMITIVE_TYPE);
QT_END_NAMESPACE
diff --git a/src/qml/debugger/qqmldebug.cpp b/src/qml/debugger/qqmldebug.cpp
index b2c4b139ee..15230d75a5 100644
--- a/src/qml/debugger/qqmldebug.cpp
+++ b/src/qml/debugger/qqmldebug.cpp
@@ -84,7 +84,19 @@ QStringList QQmlDebuggingEnabler::inspectorServices()
*/
QStringList QQmlDebuggingEnabler::profilerServices()
{
- return QStringList() << QQmlProfilerService::s_key << QQmlEngineControlService::s_key;
+ return QStringList() << QQmlProfilerService::s_key << QQmlEngineControlService::s_key
+ << QDebugMessageService::s_key;
+}
+
+/*!
+ * Retrieves the plugin keys of the debug services designed to be used with a native debugger. The
+ * native debugger will communicate with these services by directly reading and writing the
+ * application's memory.
+ * \return List of plugin keys of debug services designed to be used with a native debugger.
+ */
+QStringList QQmlDebuggingEnabler::nativeDebuggerServices()
+{
+ return QStringList() << QQmlNativeDebugService::s_key;
}
/*!
diff --git a/src/qml/debugger/qqmldebug.h b/src/qml/debugger/qqmldebug.h
index fb41039867..6a0cfdc709 100644
--- a/src/qml/debugger/qqmldebug.h
+++ b/src/qml/debugger/qqmldebug.h
@@ -60,6 +60,7 @@ struct Q_QML_EXPORT QQmlDebuggingEnabler
static QStringList debuggerServices();
static QStringList inspectorServices();
static QStringList profilerServices();
+ static QStringList nativeDebuggerServices();
static void setServices(const QStringList &services);
diff --git a/src/qml/debugger/qqmldebugconnector.cpp b/src/qml/debugger/qqmldebugconnector.cpp
index dd34bb910f..8a16d56c45 100644
--- a/src/qml/debugger/qqmldebugconnector.cpp
+++ b/src/qml/debugger/qqmldebugconnector.cpp
@@ -126,6 +126,16 @@ QQmlDebugConnector *QQmlDebugConnector::instance()
params->instance = loadQQmlDebugConnector(params->pluginKey);
} else if (params->arguments.isEmpty()) {
return 0; // no explicit class name given and no command line arguments
+ } else if (params->arguments.startsWith(QLatin1String("connector:"))) {
+ static const int connectorBegin = int(strlen("connector:"));
+
+ int connectorEnd = params->arguments.indexOf(QLatin1Char(','), connectorBegin);
+ if (connectorEnd == -1)
+ connectorEnd = params->arguments.length();
+
+ params->instance = loadQQmlDebugConnector(params->arguments.mid(
+ connectorBegin,
+ connectorEnd - connectorBegin));
} else {
params->instance = loadQQmlDebugConnector(
params->arguments.startsWith(QLatin1String("native")) ?
@@ -134,9 +144,11 @@ QQmlDebugConnector *QQmlDebugConnector::instance()
}
if (params->instance) {
- foreach (const QJsonObject &object, metaDataForQQmlDebugService()) {
- foreach (const QJsonValue &key, object.value(QLatin1String("MetaData")).toObject()
- .value(QLatin1String("Keys")).toArray()) {
+ const auto metaData = metaDataForQQmlDebugService();
+ for (const QJsonObject &object : metaData) {
+ const auto keys = object.value(QLatin1String("MetaData")).toObject()
+ .value(QLatin1String("Keys")).toArray();
+ for (const QJsonValue &key : keys) {
QString keyString = key.toString();
if (params->services.isEmpty() || params->services.contains(keyString))
loadQQmlDebugService(keyString);
diff --git a/src/qml/debugger/qqmldebugserviceinterfaces_p.h b/src/qml/debugger/qqmldebugserviceinterfaces_p.h
index 99ec525f29..707ef1a937 100644
--- a/src/qml/debugger/qqmldebugserviceinterfaces_p.h
+++ b/src/qml/debugger/qqmldebugserviceinterfaces_p.h
@@ -209,14 +209,14 @@ protected:
class Q_QML_PRIVATE_EXPORT QQmlNativeDebugService : public QQmlDebugService
{
Q_OBJECT
+public:
+ static const QString s_key;
protected:
friend class QQmlDebugConnector;
QQmlNativeDebugService(float version, QObject *parent = 0)
: QQmlDebugService(s_key, version, parent) {}
-
- static const QString s_key;
};
#endif
diff --git a/src/qml/doc/src/cppintegration/data.qdoc b/src/qml/doc/src/cppintegration/data.qdoc
index ac6600f38c..4523ee39d8 100644
--- a/src/qml/doc/src/cppintegration/data.qdoc
+++ b/src/qml/doc/src/cppintegration/data.qdoc
@@ -167,9 +167,9 @@ additional features. See the \l {qtqml-javascript-hostenvironment.html}
The QML engine provides automatic type conversion between QVariantList and
JavaScript arrays, and between QVariantMap and JavaScript objects.
-For example, the function defined in QML below left expects two arguments, an
+For example, the function defined in QML below expects two arguments, an
array and an object, and prints their contents using the standard JavaScript
-syntax for array and object item access. The C++ code below right calls this
+syntax for array and object item access. The C++ code below calls this
function, passing a QVariantList and a QVariantMap, which are automatically
converted to JavaScript array and object values, repectively:
@@ -204,9 +204,9 @@ when it is passed to C++.
The QML engine provides automatic type conversion between QDateTime values and
JavaScript \c Date objects.
-For example, the function defined in QML below left expects a JavaScript
+For example, the function defined in QML below expects a JavaScript
\c Date object, and also returns a new \c Date object with the current date and
-time. The C++ code below right calls this function, passing a QDateTime value
+time. The C++ code below calls this function, passing a QDateTime value
that is automatically converted by the engine into a \c Date object when it is
passed to the \c readDate() function. In turn, the readDate() function returns
a \c Date object that is automatically converted into a QDateTime value when it
@@ -215,7 +215,7 @@ is received in C++:
\table
\header
\row
-
+\li QML
\li
\qml
// MyItem.qml
@@ -227,6 +227,7 @@ Item {
}
\endqml
\row
+\li C++
\li
\code
// C++
diff --git a/src/qml/doc/src/cppintegration/definetypes.qdoc b/src/qml/doc/src/cppintegration/definetypes.qdoc
index e06451b2bc..7d4a543089 100644
--- a/src/qml/doc/src/cppintegration/definetypes.qdoc
+++ b/src/qml/doc/src/cppintegration/definetypes.qdoc
@@ -282,6 +282,9 @@ int qmlRegisterRevision(const char *uri, int versionMajor, int versionMinor)
template<typename T, int metaObjectRevision>
int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason)
+
+template<typename T, typename E, int metaObjectRevision>
+int qmlRegisterExtendedUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason)
\endcode
For example, if \c BaseType is changed and now has a revision 1, you can
diff --git a/src/qml/doc/src/cppintegration/exposecppattributes.qdoc b/src/qml/doc/src/cppintegration/exposecppattributes.qdoc
index ed0d049564..3bffd2eb6f 100644
--- a/src/qml/doc/src/cppintegration/exposecppattributes.qdoc
+++ b/src/qml/doc/src/cppintegration/exposecppattributes.qdoc
@@ -390,8 +390,8 @@ that is a public slot:
\endcode
If an instance of \c MessageBoard was set as the context data for a file \c
-MyItem.qml, as shown below left, then \c MyItem.qml could invoke the two
-methods, as shown below right:
+MyItem.qml, then \c MyItem.qml could invoke the two methods as shown in the
+examples below:
\table
\row
diff --git a/src/qml/doc/src/cppintegration/topic.qdoc b/src/qml/doc/src/cppintegration/topic.qdoc
index a349fd0713..1aa3bb6ab5 100644
--- a/src/qml/doc/src/cppintegration/topic.qdoc
+++ b/src/qml/doc/src/cppintegration/topic.qdoc
@@ -30,7 +30,7 @@
\brief Description of how to integrate QML and C++ code
QML is designed to be easily extensible through C++ code. The classes in the \l {Qt QML} module
-enables QML objects to be loaded and manipulated from C++, and the nature of QML engine's
+enable QML objects to be loaded and manipulated from C++, and the nature of QML engine's
integration with Qt's \l{Meta Object System}{meta object system} enables C++ functionality to be
invoked directly from QML. This allows the development of hybrid applications which are implemented
with a mixture of QML, JavaScript and C++ code.
diff --git a/src/qml/doc/src/javascript/dynamicobjectcreation.qdoc b/src/qml/doc/src/javascript/dynamicobjectcreation.qdoc
index acd7188db7..fffa783851 100644
--- a/src/qml/doc/src/javascript/dynamicobjectcreation.qdoc
+++ b/src/qml/doc/src/javascript/dynamicobjectcreation.qdoc
@@ -143,7 +143,7 @@ If the string of QML imports files using relative paths, the path should be
relative to the file in which the parent object (the second argument to the
method) is defined.
-\important When building static QML applications, which is enforced on platforms like iOS,
+\important When building static QML applications,
QML files are scanned to detect import dependencies. That way, all
necessary plugins and resources are resolved at compile time.
However, only explicit import statements are considered (those found at
diff --git a/src/qml/doc/src/javascript/functionlist.qdoc b/src/qml/doc/src/javascript/functionlist.qdoc
index b9a25a2440..f5b1ed3cf1 100644
--- a/src/qml/doc/src/javascript/functionlist.qdoc
+++ b/src/qml/doc/src/javascript/functionlist.qdoc
@@ -143,6 +143,8 @@
\li toLocaleString()
\li concat([item1 [, item2 [, ...]]])
\li join(separator)
+ \li find(callbackfn [, thisArg]) // ECMAScript 6: Added in Qt 5.9
+ \li findIndex(callbackfn [, thisArg]) // ECMAScript 6: Added in Qt 5.9
\li pop()
\li push([item1 [, item2 [, ...]]])
\li reverse()
diff --git a/src/qml/doc/src/javascript/imports.qdoc b/src/qml/doc/src/javascript/imports.qdoc
index d4ce25c92b..489da08ada 100644
--- a/src/qml/doc/src/javascript/imports.qdoc
+++ b/src/qml/doc/src/javascript/imports.qdoc
@@ -56,10 +56,10 @@ import "jsfile.js" as Logic
\endcode
Imported JavaScript resources are always qualified using the "as" keyword. The
-qualifier for JavaScript resources must be unique, so there is always a
-one-to-one mapping between qualifiers and JavaScript files. (This also means
-qualifiers cannot be named the same as built-in JavaScript objects such as
-\c Date and \c Math).
+qualifier for JavaScript resources must start with an uppercase letter, and must
+be unique, so there is always a one-to-one mapping between qualifiers and JavaScript
+files. (This also means qualifiers cannot be named the same as built-in JavaScript
+objects such as \c Date and \c Math).
The functions defined in an imported JavaScript file are available to objects
defined in the importing QML document, via the
diff --git a/src/qml/doc/src/qmlfunctions.qdoc b/src/qml/doc/src/qmlfunctions.qdoc
index 8f9ac116d4..834684fe6d 100644
--- a/src/qml/doc/src/qmlfunctions.qdoc
+++ b/src/qml/doc/src/qmlfunctions.qdoc
@@ -548,3 +548,15 @@
in order to be found.
*/
+/*!
+ \since 5.9
+ \fn void qmlRegisterModule(const char* uri, int versionMajor, int versionMinor);
+ \relates QQmlEngine
+
+ This function registers a module in a particular \a uri with a version specified
+ in \a versionMajor and \a versionMinor.
+
+ This can be used to make a certain module version available, even if no types
+ are registered for that version. This is particularly useful for keeping the
+ versions of related modules in sync.
+*/
diff --git a/src/qml/doc/src/qmllanguageref/documents/networktransparency.qdoc b/src/qml/doc/src/qmllanguageref/documents/networktransparency.qdoc
index 7fa271c2d9..5cfd80f8a0 100644
--- a/src/qml/doc/src/qmllanguageref/documents/networktransparency.qdoc
+++ b/src/qml/doc/src/qmllanguageref/documents/networktransparency.qdoc
@@ -48,12 +48,8 @@ Image {
}
\endqml
-Network transparency is supported throughout QML, for example:
-
-\list
-\li Fonts - the \c source property of FontLoader is a URL
-\li WebViews - the \c url property of WebView (obviously!)
-\endlist
+Network transparency is supported throughout QML, for example, both the FontLoader
+and Image elements support loading resources from a remote server.
Even QML types themselves can be on the network - if the \l {Prototyping with qmlscene} is used to load
\tt http://example.com/mystuff/Hello.qml and that content refers to a type "World", the engine
diff --git a/src/qml/doc/src/qmllanguageref/syntax/objectattributes.qdoc b/src/qml/doc/src/qmllanguageref/syntax/objectattributes.qdoc
index 030eb72b5f..33f58dc1b9 100644
--- a/src/qml/doc/src/qmllanguageref/syntax/objectattributes.qdoc
+++ b/src/qml/doc/src/qmllanguageref/syntax/objectattributes.qdoc
@@ -630,7 +630,7 @@ a \l {MouseArea::}{clicked} signal that is emitted when the user clicks
within the mouse area.
An object can be notified through a \l{Signal handler attributes}
-{signal handler} whenever it a particular signal is emitted. A signal handler
+{signal handler} whenever a particular signal is emitted. A signal handler
is declared with the syntax \e on<Signal> where \e <Signal> is the name of the
signal, with the first letter capitalized. The signal handler must be declared
within the definition of the object that emits the signal, and the handler
diff --git a/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc b/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc
index ffbf2282a6..a486b47f03 100644
--- a/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc
+++ b/src/qml/doc/src/qmllanguageref/typesystem/basictypes.qdoc
@@ -324,6 +324,9 @@ property is only invoked when the property is reassigned to a different object v
\li Values in the list are accessed using the \c [index] syntax
\endlist
+ Values can be dynamically added to the list by using the \c push method,
+ as if it were a JavaScript Array
+
A \c list can only store QML objects, and cannot contain any
\l {QML Basic Types}{basic type} values. (To store basic types within a
list, use the \l var type instead.)
diff --git a/src/qml/jit/qv4assembler.cpp b/src/qml/jit/qv4assembler.cpp
index e1acc33f82..a2cb56abbe 100644
--- a/src/qml/jit/qv4assembler.cpp
+++ b/src/qml/jit/qv4assembler.cpp
@@ -39,11 +39,6 @@
#include "qv4isel_masm_p.h"
#include "qv4runtime_p.h"
-#include "qv4object_p.h"
-#include "qv4functionobject_p.h"
-#include "qv4regexpobject_p.h"
-#include "qv4lookup_p.h"
-#include "qv4function_p.h"
#include "qv4ssa_p.h"
#include "qv4regalloc_p.h"
#include "qv4assembler_p.h"
@@ -51,7 +46,13 @@
#include <assembler/LinkBuffer.h>
#include <WTFStubs.h>
+#if !defined(V4_BOOTSTRAP)
+#include "qv4function_p.h"
+#endif
+
#include <iostream>
+#include <QBuffer>
+#include <QCoreApplication>
#if ENABLE(ASSEMBLER)
@@ -66,6 +67,8 @@ CompilationUnit::~CompilationUnit()
{
}
+#if !defined(V4_BOOTSTRAP)
+
void CompilationUnit::linkBackendToEngine(ExecutionEngine *engine)
{
runtimeFunctions.resize(data->functionTableSize);
@@ -79,6 +82,26 @@ void CompilationUnit::linkBackendToEngine(ExecutionEngine *engine)
}
}
+bool CompilationUnit::memoryMapCode(QString *errorString)
+{
+ Q_UNUSED(errorString);
+ codeRefs.resize(data->functionTableSize);
+
+ const char *basePtr = reinterpret_cast<const char *>(data);
+
+ for (uint i = 0; i < data->functionTableSize; ++i) {
+ const CompiledData::Function *compiledFunction = data->functionAt(i);
+ void *codePtr = const_cast<void *>(reinterpret_cast<const void *>(basePtr + compiledFunction->codeOffset));
+ JSC::MacroAssemblerCodeRef codeRef = JSC::MacroAssemblerCodeRef::createSelfManagedCodeRef(JSC::MacroAssemblerCodePtr(codePtr));
+ JSC::ExecutableAllocator::makeExecutable(codePtr, compiledFunction->codeSize);
+ codeRefs[i] = codeRef;
+ }
+
+ return true;
+}
+
+#endif // !defined(V4_BOOTSTRAP)
+
void CompilationUnit::prepareCodeOffsetsForDiskStorage(CompiledData::Unit *unit)
{
const int codeAlignment = 16;
@@ -126,45 +149,31 @@ bool CompilationUnit::saveCodeToDisk(QIODevice *device, const CompiledData::Unit
return true;
}
-bool CompilationUnit::memoryMapCode(QString *errorString)
-{
- Q_UNUSED(errorString);
- codeRefs.resize(data->functionTableSize);
-
- const char *basePtr = reinterpret_cast<const char *>(data);
-
- for (uint i = 0; i < data->functionTableSize; ++i) {
- const CompiledData::Function *compiledFunction = data->functionAt(i);
- void *codePtr = const_cast<void *>(reinterpret_cast<const void *>(basePtr + compiledFunction->codeOffset));
- JSC::MacroAssemblerCodeRef codeRef = JSC::MacroAssemblerCodeRef::createSelfManagedCodeRef(JSC::MacroAssemblerCodePtr(codePtr));
- JSC::ExecutableAllocator::makeExecutable(codePtr, compiledFunction->codeSize);
- codeRefs[i] = codeRef;
- }
-
- return true;
-}
-
-const Assembler::VoidType Assembler::Void;
+template <typename TargetConfiguration>
+const typename Assembler<TargetConfiguration>::VoidType Assembler<TargetConfiguration>::Void;
-Assembler::Assembler(InstructionSelection *isel, IR::Function* function, QV4::ExecutableAllocator *executableAllocator)
+template <typename TargetConfiguration>
+Assembler<TargetConfiguration>::Assembler(QV4::Compiler::JSUnitGenerator *jsGenerator, IR::Function* function, QV4::ExecutableAllocator *executableAllocator)
: _function(function)
, _nextBlock(0)
, _executableAllocator(executableAllocator)
- , _isel(isel)
+ , _jsGenerator(jsGenerator)
{
_addrs.resize(_function->basicBlockCount());
_patches.resize(_function->basicBlockCount());
_labelPatches.resize(_function->basicBlockCount());
}
-void Assembler::registerBlock(IR::BasicBlock* block, IR::BasicBlock *nextBlock)
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::registerBlock(IR::BasicBlock* block, IR::BasicBlock *nextBlock)
{
_addrs[block->index()] = label();
catchBlock = block->catchBlock;
_nextBlock = nextBlock;
}
-void Assembler::jumpToBlock(IR::BasicBlock* current, IR::BasicBlock *target)
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::jumpToBlock(IR::BasicBlock* current, IR::BasicBlock *target)
{
Q_UNUSED(current);
@@ -172,12 +181,14 @@ void Assembler::jumpToBlock(IR::BasicBlock* current, IR::BasicBlock *target)
_patches[target->index()].push_back(jump());
}
-void Assembler::addPatch(IR::BasicBlock* targetBlock, Jump targetJump)
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::addPatch(IR::BasicBlock* targetBlock, Jump targetJump)
{
_patches[targetBlock->index()].push_back(targetJump);
}
-void Assembler::addPatch(DataLabelPtr patch, Label target)
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::addPatch(DataLabelPtr patch, Label target)
{
DataLabelPatch p;
p.dataLabel = patch;
@@ -185,37 +196,21 @@ void Assembler::addPatch(DataLabelPtr patch, Label target)
_dataLabelPatches.push_back(p);
}
-void Assembler::addPatch(DataLabelPtr patch, IR::BasicBlock *target)
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::addPatch(DataLabelPtr patch, IR::BasicBlock *target)
{
_labelPatches[target->index()].push_back(patch);
}
-void Assembler::generateCJumpOnNonZero(RegisterID reg, IR::BasicBlock *currentBlock,
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::generateCJumpOnNonZero(RegisterID reg, IR::BasicBlock *currentBlock,
IR::BasicBlock *trueBlock, IR::BasicBlock *falseBlock)
{
- generateCJumpOnCompare(NotEqual, reg, TrustedImm32(0), currentBlock, trueBlock, falseBlock);
+ generateCJumpOnCompare(RelationalCondition::NotEqual, reg, TrustedImm32(0), currentBlock, trueBlock, falseBlock);
}
-#ifdef QV4_USE_64_BIT_VALUE_ENCODING
-void Assembler::generateCJumpOnCompare(RelationalCondition cond,
- RegisterID left,
- TrustedImm64 right,
- IR::BasicBlock *currentBlock,
- IR::BasicBlock *trueBlock,
- IR::BasicBlock *falseBlock)
-{
- if (trueBlock == _nextBlock) {
- Jump target = branch64(invert(cond), left, right);
- addPatch(falseBlock, target);
- } else {
- Jump target = branch64(cond, left, right);
- addPatch(trueBlock, target);
- jumpToBlock(currentBlock, falseBlock);
- }
-}
-#endif
-
-void Assembler::generateCJumpOnCompare(RelationalCondition cond,
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::generateCJumpOnCompare(RelationalCondition cond,
RegisterID left,
TrustedImm32 right,
IR::BasicBlock *currentBlock,
@@ -232,7 +227,8 @@ void Assembler::generateCJumpOnCompare(RelationalCondition cond,
}
}
-void Assembler::generateCJumpOnCompare(RelationalCondition cond,
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::generateCJumpOnCompare(RelationalCondition cond,
RegisterID left,
RegisterID right,
IR::BasicBlock *currentBlock,
@@ -249,7 +245,8 @@ void Assembler::generateCJumpOnCompare(RelationalCondition cond,
}
}
-Assembler::Pointer Assembler::loadAddress(RegisterID tmp, IR::Expr *e)
+template <typename TargetConfiguration>
+typename Assembler<TargetConfiguration>::Pointer Assembler<TargetConfiguration>::loadAddress(RegisterID tmp, IR::Expr *e)
{
IR::Temp *t = e->asTemp();
if (t)
@@ -258,7 +255,8 @@ Assembler::Pointer Assembler::loadAddress(RegisterID tmp, IR::Expr *e)
return loadArgLocalAddress(tmp, e->asArgLocal());
}
-Assembler::Pointer Assembler::loadTempAddress(IR::Temp *t)
+template <typename TargetConfiguration>
+typename Assembler<TargetConfiguration>::Pointer Assembler<TargetConfiguration>::loadTempAddress(IR::Temp *t)
{
if (t->kind == IR::Temp::StackSlot)
return stackSlotPointer(t);
@@ -266,7 +264,8 @@ Assembler::Pointer Assembler::loadTempAddress(IR::Temp *t)
Q_UNREACHABLE();
}
-Assembler::Pointer Assembler::loadArgLocalAddress(RegisterID baseReg, IR::ArgLocal *al)
+template <typename TargetConfiguration>
+typename Assembler<TargetConfiguration>::Pointer Assembler<TargetConfiguration>::loadArgLocalAddress(RegisterID baseReg, IR::ArgLocal *al)
{
int32_t offset = 0;
int scope = al->scope;
@@ -296,55 +295,61 @@ Assembler::Pointer Assembler::loadArgLocalAddress(RegisterID baseReg, IR::ArgLoc
return Pointer(baseReg, offset);
}
-Assembler::Pointer Assembler::loadStringAddress(RegisterID reg, const QString &string)
+template <typename TargetConfiguration>
+typename Assembler<TargetConfiguration>::Pointer Assembler<TargetConfiguration>::loadStringAddress(RegisterID reg, const QString &string)
{
loadPtr(Address(Assembler::EngineRegister, qOffsetOf(QV4::ExecutionEngine, current)), Assembler::ScratchRegister);
loadPtr(Address(Assembler::ScratchRegister, qOffsetOf(QV4::Heap::ExecutionContext, compilationUnit)), Assembler::ScratchRegister);
loadPtr(Address(Assembler::ScratchRegister, qOffsetOf(QV4::CompiledData::CompilationUnit, runtimeStrings)), reg);
- const int id = _isel->registerString(string);
+ const int id = _jsGenerator->registerString(string);
return Pointer(reg, id * sizeof(QV4::String*));
}
-Assembler::Address Assembler::loadConstant(IR::Const *c, RegisterID baseReg)
+template <typename TargetConfiguration>
+typename Assembler<TargetConfiguration>::Address Assembler<TargetConfiguration>::loadConstant(IR::Const *c, RegisterID baseReg)
{
return loadConstant(convertToValue(c), baseReg);
}
-Assembler::Address Assembler::loadConstant(const Primitive &v, RegisterID baseReg)
+template <typename TargetConfiguration>
+typename Assembler<TargetConfiguration>::Address Assembler<TargetConfiguration>::loadConstant(const Primitive &v, RegisterID baseReg)
{
loadPtr(Address(Assembler::EngineRegister, qOffsetOf(QV4::ExecutionEngine, current)), baseReg);
loadPtr(Address(baseReg, qOffsetOf(QV4::Heap::ExecutionContext, constantTable)), baseReg);
- const int index = _isel->jsUnitGenerator()->registerConstant(v.asReturnedValue());
+ const int index = _jsGenerator->registerConstant(v.asReturnedValue());
return Address(baseReg, index * sizeof(QV4::Value));
}
-void Assembler::loadStringRef(RegisterID reg, const QString &string)
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::loadStringRef(RegisterID reg, const QString &string)
{
- const int id = _isel->registerString(string);
+ const int id = _jsGenerator->registerString(string);
move(TrustedImm32(id), reg);
}
-void Assembler::storeValue(QV4::Primitive value, IR::Expr *destination)
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::storeValue(QV4::Primitive value, IR::Expr *destination)
{
Address addr = loadAddress(ScratchRegister, destination);
storeValue(value, addr);
}
-void Assembler::enterStandardStackFrame(const RegisterInformation &regularRegistersToSave,
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::enterStandardStackFrame(const RegisterInformation &regularRegistersToSave,
const RegisterInformation &fpRegistersToSave)
{
platformEnterStandardStackFrame(this);
- move(StackPointerRegister, FramePointerRegister);
+ move(StackPointerRegister, JITTargetPlatform::FramePointerRegister);
const int frameSize = _stackLayout->calculateStackFrameSize();
subPtr(TrustedImm32(frameSize), StackPointerRegister);
- Address slotAddr(FramePointerRegister, 0);
+ Address slotAddr(JITTargetPlatform::FramePointerRegister, 0);
for (int i = 0, ei = fpRegistersToSave.size(); i < ei; ++i) {
Q_ASSERT(fpRegistersToSave.at(i).isFloatingPoint());
slotAddr.offset -= sizeof(double);
- JSC::MacroAssembler::storeDouble(fpRegistersToSave.at(i).reg<FPRegisterID>(), slotAddr);
+ TargetConfiguration::MacroAssembler::storeDouble(fpRegistersToSave.at(i).reg<FPRegisterID>(), slotAddr);
}
for (int i = 0, ei = regularRegistersToSave.size(); i < ei; ++i) {
Q_ASSERT(regularRegistersToSave.at(i).isRegularRegister());
@@ -353,10 +358,11 @@ void Assembler::enterStandardStackFrame(const RegisterInformation &regularRegist
}
}
-void Assembler::leaveStandardStackFrame(const RegisterInformation &regularRegistersToSave,
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::leaveStandardStackFrame(const RegisterInformation &regularRegistersToSave,
const RegisterInformation &fpRegistersToSave)
{
- Address slotAddr(FramePointerRegister, -regularRegistersToSave.size() * RegisterSize - fpRegistersToSave.size() * sizeof(double));
+ Address slotAddr(JITTargetPlatform::FramePointerRegister, -regularRegistersToSave.size() * RegisterSize - fpRegistersToSave.size() * sizeof(double));
// restore the callee saved registers
for (int i = regularRegistersToSave.size() - 1; i >= 0; --i) {
@@ -366,23 +372,14 @@ void Assembler::leaveStandardStackFrame(const RegisterInformation &regularRegist
}
for (int i = fpRegistersToSave.size() - 1; i >= 0; --i) {
Q_ASSERT(fpRegistersToSave.at(i).isFloatingPoint());
- JSC::MacroAssembler::loadDouble(slotAddr, fpRegistersToSave.at(i).reg<FPRegisterID>());
+ TargetConfiguration::MacroAssembler::loadDouble(slotAddr, fpRegistersToSave.at(i).reg<FPRegisterID>());
slotAddr.offset += sizeof(double);
}
Q_ASSERT(slotAddr.offset == 0);
const int frameSize = _stackLayout->calculateStackFrameSize();
- // Work around bug in ARMv7Assembler.h where add32(imm, sp, sp) doesn't
- // work well for large immediates.
-#if CPU(ARM_THUMB2)
- move(TrustedImm32(frameSize), JSC::ARMRegisters::r3);
- add32(JSC::ARMRegisters::r3, StackPointerRegister);
-#else
- addPtr(TrustedImm32(frameSize), StackPointerRegister);
-#endif
-
- platformLeaveStandardStackFrame(this);
+ platformLeaveStandardStackFrame(this, frameSize);
}
@@ -391,7 +388,8 @@ void Assembler::leaveStandardStackFrame(const RegisterInformation &regularRegist
// Try to load the source expression into the destination FP register. This assumes that two
// general purpose (integer) registers are available: the ScratchRegister and the
// ReturnValueRegister. It returns a Jump if no conversion can be performed.
-Assembler::Jump Assembler::genTryDoubleConversion(IR::Expr *src, Assembler::FPRegisterID dest)
+template <typename TargetConfiguration>
+typename Assembler<TargetConfiguration>::Jump Assembler<TargetConfiguration>::genTryDoubleConversion(IR::Expr *src, FPRegisterID dest)
{
switch (src->type) {
case IR::DoubleType:
@@ -434,11 +432,10 @@ Assembler::Jump Assembler::genTryDoubleConversion(IR::Expr *src, Assembler::FPRe
isNoInt.link(this);
#ifdef QV4_USE_64_BIT_VALUE_ENCODING
rshift32(TrustedImm32(Value::IsDoubleTag_Shift), ScratchRegister);
- Assembler::Jump isNoDbl = branch32(Equal, ScratchRegister, TrustedImm32(0));
+ Assembler::Jump isNoDbl = branch32(RelationalCondition::Equal, JITTargetPlatform::ScratchRegister, TrustedImm32(0));
#else
and32(Assembler::TrustedImm32(Value::NotDouble_Mask), Assembler::ScratchRegister);
- Assembler::Jump isNoDbl = branch32(Assembler::Equal, Assembler::ScratchRegister,
- Assembler::TrustedImm32(Value::NotDouble_Mask));
+ Assembler::Jump isNoDbl = branch32(RelationalCondition::Equal, JITTargetPlatform::ScratchRegister, TrustedImm32(Value::NotDouble_Mask));
#endif
toDoubleRegister(src, dest);
intDone.link(this);
@@ -446,10 +443,11 @@ Assembler::Jump Assembler::genTryDoubleConversion(IR::Expr *src, Assembler::FPRe
return isNoDbl;
}
-Assembler::Jump Assembler::branchDouble(bool invertCondition, IR::AluOp op,
+template <typename TargetConfiguration>
+typename Assembler<TargetConfiguration>::Jump Assembler<TargetConfiguration>::branchDouble(bool invertCondition, IR::AluOp op,
IR::Expr *left, IR::Expr *right)
{
- Assembler::DoubleCondition cond;
+ DoubleCondition cond;
switch (op) {
case IR::OpGt: cond = Assembler::DoubleGreaterThan; break;
case IR::OpLt: cond = Assembler::DoubleLessThan; break;
@@ -463,12 +461,13 @@ Assembler::Jump Assembler::branchDouble(bool invertCondition, IR::AluOp op,
Q_UNREACHABLE();
}
if (invertCondition)
- cond = JSC::MacroAssembler::invert(cond);
+ cond = TargetConfiguration::MacroAssembler::invert(cond);
- return JSC::MacroAssembler::branchDouble(cond, toDoubleRegister(left, FPGpr0), toDoubleRegister(right, FPGpr1));
+ return TargetConfiguration::MacroAssembler::branchDouble(cond, toDoubleRegister(left, FPGpr0), toDoubleRegister(right, JITTargetPlatform::FPGpr1));
}
-Assembler::Jump Assembler::branchInt32(bool invertCondition, IR::AluOp op, IR::Expr *left, IR::Expr *right)
+template <typename TargetConfiguration>
+typename Assembler<TargetConfiguration>::Jump Assembler<TargetConfiguration>::branchInt32(bool invertCondition, IR::AluOp op, IR::Expr *left, IR::Expr *right)
{
Assembler::RelationalCondition cond;
switch (op) {
@@ -484,16 +483,230 @@ Assembler::Jump Assembler::branchInt32(bool invertCondition, IR::AluOp op, IR::E
Q_UNREACHABLE();
}
if (invertCondition)
- cond = JSC::MacroAssembler::invert(cond);
+ cond = TargetConfiguration::MacroAssembler::invert(cond);
- return JSC::MacroAssembler::branch32(cond,
- toInt32Register(left, Assembler::ScratchRegister),
- toInt32Register(right, Assembler::ReturnValueRegister));
+ return TargetConfiguration::MacroAssembler::branch32(cond,
+ toInt32Register(left, Assembler::ScratchRegister),
+ toInt32Register(right, Assembler::ReturnValueRegister));
}
-void Assembler::setStackLayout(int maxArgCountForBuiltins, int regularRegistersToSave, int fpRegistersToSave)
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::setStackLayout(int maxArgCountForBuiltins, int regularRegistersToSave, int fpRegistersToSave)
{
_stackLayout.reset(new StackLayout(_function, maxArgCountForBuiltins, regularRegistersToSave, fpRegistersToSave));
}
+template <typename TargetConfiguration>
+void Assembler<TargetConfiguration>::returnFromFunction(IR::Ret *s, RegisterInformation regularRegistersToSave, RegisterInformation fpRegistersToSave)
+{
+ if (!s) {
+ // this only happens if the method doesn't have a return statement and can
+ // only exit through an exception
+ } else if (IR::Temp *t = s->expr->asTemp()) {
+ RegisterSizeDependentOps::setFunctionReturnValueFromTemp(this, t);
+ } else if (IR::Const *c = s->expr->asConst()) {
+ QV4::Primitive retVal = convertToValue(c);
+ RegisterSizeDependentOps::setFunctionReturnValueFromConst(this, retVal);
+ } else {
+ Q_UNREACHABLE();
+ Q_UNUSED(s);
+ }
+
+ Label leaveStackFrame = label();
+
+ const int locals = stackLayout().calculateJSStackFrameSize();
+ subPtr(TrustedImm32(sizeof(QV4::Value)*locals), JITTargetPlatform::LocalsRegister);
+ loadPtr(Address(JITTargetPlatform::EngineRegister, qOffsetOf(QV4::ExecutionEngine, current)), JITTargetPlatform::ScratchRegister);
+ loadPtr(Address(JITTargetPlatform::ScratchRegister, qOffsetOf(ExecutionContext::Data, engine)), JITTargetPlatform::ScratchRegister);
+ storePtr(JITTargetPlatform::LocalsRegister, Address(JITTargetPlatform::ScratchRegister, qOffsetOf(ExecutionEngine, jsStackTop)));
+
+ leaveStandardStackFrame(regularRegistersToSave, fpRegistersToSave);
+ ret();
+
+ exceptionReturnLabel = label();
+ QV4::Primitive retVal = Primitive::undefinedValue();
+ RegisterSizeDependentOps::setFunctionReturnValueFromConst(this, retVal);
+ jump(leaveStackFrame);
+}
+
+namespace {
+class QIODevicePrintStream: public FilePrintStream
+{
+ Q_DISABLE_COPY(QIODevicePrintStream)
+
+public:
+ explicit QIODevicePrintStream(QIODevice *dest)
+ : FilePrintStream(0)
+ , dest(dest)
+ , buf(4096, '0')
+ {
+ Q_ASSERT(dest);
+ }
+
+ ~QIODevicePrintStream()
+ {}
+
+ void vprintf(const char* format, va_list argList) WTF_ATTRIBUTE_PRINTF(2, 0)
+ {
+ const int written = qvsnprintf(buf.data(), buf.size(), format, argList);
+ if (written > 0)
+ dest->write(buf.constData(), written);
+ memset(buf.data(), 0, qMin(written, buf.size()));
+ }
+
+ void flush()
+ {}
+
+private:
+ QIODevice *dest;
+ QByteArray buf;
+};
+} // anonymous namespace
+
+static void printDisassembledOutputWithCalls(QByteArray processedOutput, const QHash<void*, const char*>& functions)
+{
+ for (QHash<void*, const char*>::ConstIterator it = functions.begin(), end = functions.end();
+ it != end; ++it) {
+ const QByteArray ptrString = "0x" + QByteArray::number(quintptr(it.key()), 16);
+ int idx = processedOutput.indexOf(ptrString);
+ if (idx < 0)
+ continue;
+ idx = processedOutput.lastIndexOf('\n', idx);
+ if (idx < 0)
+ continue;
+ processedOutput = processedOutput.insert(idx, QByteArrayLiteral(" ; call ") + it.value());
+ }
+
+ qDebug("%s", processedOutput.constData());
+}
+
+#if defined(Q_OS_LINUX)
+static FILE *pmap;
+
+static void qt_closePmap()
+{
+ if (pmap) {
+ fclose(pmap);
+ pmap = 0;
+ }
+}
+
+#endif
+
+template <typename TargetConfiguration>
+JSC::MacroAssemblerCodeRef Assembler<TargetConfiguration>::link(int *codeSize)
+{
+ Label endOfCode = label();
+
+ {
+ for (size_t i = 0, ei = _patches.size(); i != ei; ++i) {
+ Label target = _addrs.at(i);
+ Q_ASSERT(target.isSet());
+ for (Jump jump : qAsConst(_patches.at(i)))
+ jump.linkTo(target, this);
+ }
+ }
+
+ JSC::JSGlobalData dummy(_executableAllocator);
+ JSC::LinkBuffer<typename TargetConfiguration::MacroAssembler> linkBuffer(dummy, this, 0);
+
+ for (const DataLabelPatch &p : qAsConst(_dataLabelPatches))
+ linkBuffer.patch(p.dataLabel, linkBuffer.locationOf(p.target));
+
+ // link exception handlers
+ for (Jump jump : qAsConst(exceptionPropagationJumps))
+ linkBuffer.link(jump, linkBuffer.locationOf(exceptionReturnLabel));
+
+ {
+ for (size_t i = 0, ei = _labelPatches.size(); i != ei; ++i) {
+ Label target = _addrs.at(i);
+ Q_ASSERT(target.isSet());
+ for (DataLabelPtr label : _labelPatches.at(i))
+ linkBuffer.patch(label, linkBuffer.locationOf(target));
+ }
+ }
+
+ *codeSize = linkBuffer.offsetOf(endOfCode);
+
+ QByteArray name;
+
+ JSC::MacroAssemblerCodeRef codeRef;
+
+ static const bool showCode = qEnvironmentVariableIsSet("QV4_SHOW_ASM");
+ if (showCode) {
+ QHash<void*, const char*> functions;
+#ifndef QT_NO_DEBUG
+ for (CallInfo call : qAsConst(_callInfos))
+ functions[linkBuffer.locationOf(call.label).dataLocation()] = call.functionName;
+#endif
+
+ QBuffer buf;
+ buf.open(QIODevice::WriteOnly);
+ WTF::setDataFile(new QIODevicePrintStream(&buf));
+
+ name = _function->name->toUtf8();
+ if (name.isEmpty())
+ name = "IR::Function(0x" + QByteArray::number(quintptr(_function), 16) + ')';
+ codeRef = linkBuffer.finalizeCodeWithDisassembly("%s", name.data());
+
+ WTF::setDataFile(stderr);
+ printDisassembledOutputWithCalls(buf.data(), functions);
+ } else {
+ codeRef = linkBuffer.finalizeCodeWithoutDisassembly();
+ }
+
+#if defined(Q_OS_LINUX)
+ // This implements writing of JIT'd addresses so that perf can find the
+ // symbol names.
+ //
+ // Perf expects the mapping to be in a certain place and have certain
+ // content, for more information, see:
+ // https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt
+ static bool doProfile = !qEnvironmentVariableIsEmpty("QV4_PROFILE_WRITE_PERF_MAP");
+ static bool profileInitialized = false;
+ if (doProfile && !profileInitialized) {
+ profileInitialized = true;
+
+ char pname[PATH_MAX];
+ snprintf(pname, PATH_MAX - 1, "/tmp/perf-%lu.map",
+ (unsigned long)QCoreApplication::applicationPid());
+
+ pmap = fopen(pname, "w");
+ if (!pmap)
+ qWarning("QV4: Can't write %s, call stacks will not contain JavaScript function names", pname);
+
+ // make sure we clean up nicely
+ std::atexit(qt_closePmap);
+ }
+
+ if (pmap) {
+ // this may have been pre-populated, if QV4_SHOW_ASM was on
+ if (name.isEmpty()) {
+ name = _function->name->toUtf8();
+ if (name.isEmpty())
+ name = "IR::Function(0x" + QByteArray::number(quintptr(_function), 16) + ')';
+ }
+
+ fprintf(pmap, "%llx %x %.*s\n",
+ (long long unsigned int)codeRef.code().executableAddress(),
+ *codeSize,
+ name.length(),
+ name.constData());
+ fflush(pmap);
+ }
+#endif
+
+ return codeRef;
+}
+
+template class QV4::JIT::Assembler<DefaultAssemblerTargetConfiguration>;
+#if defined(V4_BOOTSTRAP)
+#if !CPU(ARM_THUMB2)
+template class QV4::JIT::Assembler<AssemblerTargetConfiguration<JSC::MacroAssemblerARMv7, NoOperatingSystemSpecialization>>;
+#endif
+#if !CPU(ARM64)
+template class QV4::JIT::Assembler<AssemblerTargetConfiguration<JSC::MacroAssemblerARM64, NoOperatingSystemSpecialization>>;
+#endif
+#endif
+
#endif
diff --git a/src/qml/jit/qv4assembler_p.h b/src/qml/jit/qv4assembler_p.h
index 94478cd9cd..fd65c9b3d2 100644
--- a/src/qml/jit/qv4assembler_p.h
+++ b/src/qml/jit/qv4assembler_p.h
@@ -55,7 +55,8 @@
#include "private/qv4isel_p.h"
#include "private/qv4isel_util_p.h"
#include "private/qv4value_p.h"
-#include "private/qv4lookup_p.h"
+#include "private/qv4context_p.h"
+#include "private/qv4engine_p.h"
#include "qv4targetplatform_p.h"
#include <config.h>
@@ -73,45 +74,670 @@ QT_BEGIN_NAMESPACE
namespace QV4 {
namespace JIT {
-class InstructionSelection;
-
struct CompilationUnit : public QV4::CompiledData::CompilationUnit
{
virtual ~CompilationUnit();
+#if !defined(V4_BOOTSTRAP)
void linkBackendToEngine(QV4::ExecutionEngine *engine) Q_DECL_OVERRIDE;
+ bool memoryMapCode(QString *errorString) Q_DECL_OVERRIDE;
+#endif
void prepareCodeOffsetsForDiskStorage(CompiledData::Unit *unit) Q_DECL_OVERRIDE;
bool saveCodeToDisk(QIODevice *device, const CompiledData::Unit *unit, QString *errorString) Q_DECL_OVERRIDE;
- bool memoryMapCode(QString *errorString) Q_DECL_OVERRIDE;
// Coderef + execution engine
QVector<JSC::MacroAssemblerCodeRef> codeRefs;
};
-struct LookupCall {
- JSC::MacroAssembler::Address addr;
- uint getterSetterOffset;
+template <typename PlatformAssembler, TargetOperatingSystemSpecialization Specialization>
+struct AssemblerTargetConfiguration
+{
+ typedef JSC::MacroAssembler<PlatformAssembler> MacroAssembler;
+ typedef TargetPlatform<PlatformAssembler, Specialization> Platform;
+ // More things coming here in the future, such as Target OS
+};
+
+#if CPU(ARM_THUMB2)
+typedef JSC::MacroAssemblerARMv7 DefaultPlatformMacroAssembler;
+typedef AssemblerTargetConfiguration<DefaultPlatformMacroAssembler, NoOperatingSystemSpecialization> DefaultAssemblerTargetConfiguration;
+#elif CPU(ARM64)
+typedef JSC::MacroAssemblerARM64 DefaultPlatformMacroAssembler;
+typedef AssemblerTargetConfiguration<DefaultPlatformMacroAssembler, NoOperatingSystemSpecialization> DefaultAssemblerTargetConfiguration;
+#elif CPU(ARM_TRADITIONAL)
+typedef JSC::MacroAssemblerARM DefaultPlatformMacroAssembler;
+typedef AssemblerTargetConfiguration<DefaultPlatformMacroAssembler, NoOperatingSystemSpecialization> DefaultAssemblerTargetConfiguration;
+#elif CPU(MIPS)
+typedef JSC::MacroAssemblerMIPS DefaultPlatformMacroAssembler;
+typedef AssemblerTargetConfiguration<DefaultPlatformMacroAssembler, NoOperatingSystemSpecialization> DefaultAssemblerTargetConfiguration;
+#elif CPU(X86)
+typedef JSC::MacroAssemblerX86 DefaultPlatformMacroAssembler;
+typedef AssemblerTargetConfiguration<DefaultPlatformMacroAssembler, NoOperatingSystemSpecialization> DefaultAssemblerTargetConfiguration;
+#elif CPU(X86_64)
+typedef JSC::MacroAssemblerX86_64 DefaultPlatformMacroAssembler;
+
+#if OS(WINDOWS)
+typedef AssemblerTargetConfiguration<DefaultPlatformMacroAssembler, WindowsSpecialization> DefaultAssemblerTargetConfiguration;
+#else
+typedef AssemblerTargetConfiguration<DefaultPlatformMacroAssembler, NoOperatingSystemSpecialization> DefaultAssemblerTargetConfiguration;
+#endif
- LookupCall(const JSC::MacroAssembler::Address &addr, uint getterSetterOffset)
- : addr(addr)
- , getterSetterOffset(getterSetterOffset)
- {}
+#elif CPU(SH4)
+typedef JSC::MacroAssemblerSH4 DefaultPlatformMacroAssembler;
+typedef AssemblerTargetConfiguration<DefaultPlatformMacroAssembler, NoOperatingSystemSpecialization> DefaultAssemblerTargetConfiguration;
+#endif
+
+#define isel_stringIfyx(s) #s
+#define isel_stringIfy(s) isel_stringIfyx(s)
+
+#define generateRuntimeCall(as, t, function, ...) \
+ as->generateFunctionCallImp(Runtime::Method_##function##_NeedsExceptionCheck, t, "Runtime::" isel_stringIfy(function), typename JITAssembler::RuntimeCall(qOffsetOf(QV4::Runtime, function)), __VA_ARGS__)
+
+
+template <typename JITAssembler, typename MacroAssembler, typename TargetPlatform, int RegisterSize>
+struct RegisterSizeDependentAssembler
+{
};
-struct RuntimeCall {
- JSC::MacroAssembler::Address addr;
+template <typename JITAssembler, typename MacroAssembler, typename TargetPlatform>
+struct RegisterSizeDependentAssembler<JITAssembler, MacroAssembler, TargetPlatform, 4>
+{
+ using RegisterID = typename JITAssembler::RegisterID;
+ using FPRegisterID = typename JITAssembler::FPRegisterID;
+ using RelationalCondition = typename JITAssembler::RelationalCondition;
+ using ResultCondition = typename JITAssembler::ResultCondition;
+ using Address = typename JITAssembler::Address;
+ using Pointer = typename JITAssembler::Pointer;
+ using TrustedImm32 = typename JITAssembler::TrustedImm32;
+ using TrustedImm64 = typename JITAssembler::TrustedImm64;
+ using Jump = typename JITAssembler::Jump;
+ using Label = typename JITAssembler::Label;
+
+ static void loadDouble(JITAssembler *as, Address addr, FPRegisterID dest)
+ {
+ as->MacroAssembler::loadDouble(addr, dest);
+ }
+
+ static void storeDouble(JITAssembler *as, FPRegisterID source, Address addr)
+ {
+ as->MacroAssembler::storeDouble(source, addr);
+ }
+
+ static void storeDouble(JITAssembler *as, FPRegisterID source, IR::Expr* target)
+ {
+ Pointer ptr = as->loadAddress(TargetPlatform::ScratchRegister, target);
+ as->storeDouble(source, ptr);
+ }
+
+ static void storeValue(JITAssembler *as, QV4::Primitive value, Address destination)
+ {
+ as->store32(TrustedImm32(value.int_32()), destination);
+ destination.offset += 4;
+ as->store32(TrustedImm32(value.tag()), destination);
+ }
+
+ template <typename Source, typename Destination>
+ static void copyValueViaRegisters(JITAssembler *as, Source source, Destination destination)
+ {
+ as->loadDouble(source, TargetPlatform::FPGpr0);
+ as->storeDouble(TargetPlatform::FPGpr0, destination);
+ }
+
+ static void loadDoubleConstant(JITAssembler *as, IR::Const *c, FPRegisterID target)
+ {
+ as->MacroAssembler::loadDouble(as->loadConstant(c, TargetPlatform::ScratchRegister), target);
+ }
+
+ static void storeReturnValue(JITAssembler *as, FPRegisterID dest)
+ {
+ as->moveIntsToDouble(TargetPlatform::LowReturnValueRegister, TargetPlatform::HighReturnValueRegister, dest, TargetPlatform::FPGpr0);
+ }
+
+ static void storeReturnValue(JITAssembler *as, const Pointer &dest)
+ {
+ Address destination = dest;
+ as->store32(TargetPlatform::LowReturnValueRegister, destination);
+ destination.offset += 4;
+ as->store32(TargetPlatform::HighReturnValueRegister, destination);
+ }
+
+ static void setFunctionReturnValueFromTemp(JITAssembler *as, IR::Temp *t)
+ {
+ const auto lowReg = TargetPlatform::LowReturnValueRegister;
+ const auto highReg = TargetPlatform::HighReturnValueRegister;
+
+ if (t->kind == IR::Temp::PhysicalRegister) {
+ switch (t->type) {
+ case IR::DoubleType:
+ as->moveDoubleToInts((FPRegisterID) t->index, lowReg, highReg);
+ break;
+ case IR::UInt32Type: {
+ RegisterID srcReg = (RegisterID) t->index;
+ Jump intRange = as->branch32(JITAssembler::GreaterThanOrEqual, srcReg, TrustedImm32(0));
+ as->convertUInt32ToDouble(srcReg, TargetPlatform::FPGpr0, TargetPlatform::ReturnValueRegister);
+ as->moveDoubleToInts(TargetPlatform::FPGpr0, lowReg, highReg);
+ Jump done = as->jump();
+ intRange.link(as);
+ as->move(srcReg, lowReg);
+ as->move(TrustedImm32(QV4::Value::Integer_Type_Internal), highReg);
+ done.link(as);
+ } break;
+ case IR::SInt32Type:
+ as->move((RegisterID) t->index, lowReg);
+ as->move(TrustedImm32(QV4::Value::Integer_Type_Internal), highReg);
+ break;
+ case IR::BoolType:
+ as->move((RegisterID) t->index, lowReg);
+ as->move(TrustedImm32(QV4::Value::Boolean_Type_Internal), highReg);
+ break;
+ default:
+ Q_UNREACHABLE();
+ }
+ } else {
+ Pointer addr = as->loadAddress(TargetPlatform::ScratchRegister, t);
+ as->load32(addr, lowReg);
+ addr.offset += 4;
+ as->load32(addr, highReg);
+ }
+ }
+
+ static void setFunctionReturnValueFromConst(JITAssembler *as, QV4::Primitive retVal)
+ {
+ as->move(TrustedImm32(retVal.int_32()), TargetPlatform::LowReturnValueRegister);
+ as->move(TrustedImm32(retVal.tag()), TargetPlatform::HighReturnValueRegister);
+ }
+
+ static void loadArgumentInRegister(JITAssembler *as, IR::Temp* temp, RegisterID dest, int argumentNumber)
+ {
+ Q_UNUSED(as);
+ Q_UNUSED(temp);
+ Q_UNUSED(dest);
+ Q_UNUSED(argumentNumber);
+ }
+
+ static void loadArgumentInRegister(JITAssembler *as, IR::ArgLocal* al, RegisterID dest, int argumentNumber)
+ {
+ Q_UNUSED(as);
+ Q_UNUSED(al);
+ Q_UNUSED(dest);
+ Q_UNUSED(argumentNumber);
+ }
+
+ static void loadArgumentInRegister(JITAssembler *as, IR::Const* c, RegisterID dest, int argumentNumber)
+ {
+ Q_UNUSED(as);
+ Q_UNUSED(c);
+ Q_UNUSED(dest);
+ Q_UNUSED(argumentNumber);
+ }
+
+ static void loadArgumentInRegister(JITAssembler *as, IR::Expr* expr, RegisterID dest, int argumentNumber)
+ {
+ Q_UNUSED(as);
+ Q_UNUSED(expr);
+ Q_UNUSED(dest);
+ Q_UNUSED(argumentNumber);
+ }
+
+ static void zeroRegister(JITAssembler *as, RegisterID reg)
+ {
+ as->move(TrustedImm32(0), reg);
+ }
+
+ static void zeroStackSlot(JITAssembler *as, int slot)
+ {
+ as->poke(TrustedImm32(0), slot);
+ }
+
+ static void generateCJumpOnUndefined(JITAssembler *as,
+ RelationalCondition cond, IR::Expr *right,
+ RegisterID scratchRegister, RegisterID tagRegister,
+ IR::BasicBlock *nextBlock, IR::BasicBlock *currentBlock,
+ IR::BasicBlock *trueBlock, IR::BasicBlock *falseBlock)
+ {
+ Pointer tagAddr = as->loadAddress(scratchRegister, right);
+ as->load32(tagAddr, tagRegister);
+ Jump j = as->branch32(JITAssembler::invert(cond), tagRegister, TrustedImm32(0));
+ as->addPatch(falseBlock, j);
+
+ tagAddr.offset += 4;
+ as->load32(tagAddr, tagRegister);
+ const TrustedImm32 tag(QV4::Value::Managed_Type_Internal);
+ Q_ASSERT(nextBlock == as->nextBlock());
+ Q_UNUSED(nextBlock);
+ as->generateCJumpOnCompare(cond, tagRegister, tag, currentBlock, trueBlock, falseBlock);
+ }
+
+ static void convertVarToSInt32(JITAssembler *as, IR::Expr *source, IR::Expr *target)
+ {
+ Q_ASSERT(source->type == IR::VarType);
+ // load the tag:
+ Pointer addr = as->loadAddress(TargetPlatform::ScratchRegister, source);
+ Pointer tagAddr = addr;
+ tagAddr.offset += 4;
+ as->load32(tagAddr, TargetPlatform::ReturnValueRegister);
+
+ // check if it's an int32:
+ Jump fallback = as->branch32(RelationalCondition::NotEqual, TargetPlatform::ReturnValueRegister,
+ TrustedImm32(Value::Integer_Type_Internal));
+ IR::Temp *targetTemp = target->asTemp();
+ if (!targetTemp || targetTemp->kind == IR::Temp::StackSlot) {
+ as->load32(addr, TargetPlatform::ReturnValueRegister);
+ Pointer targetAddr = as->loadAddress(TargetPlatform::ScratchRegister, target);
+ as->store32(TargetPlatform::ReturnValueRegister, targetAddr);
+ targetAddr.offset += 4;
+ as->store32(TrustedImm32(Value::Integer_Type_Internal), targetAddr);
+ } else {
+ as->load32(addr, (RegisterID) targetTemp->index);
+ }
+ Jump intDone = as->jump();
+
+ // not an int:
+ fallback.link(as);
+ generateRuntimeCall(as, TargetPlatform::ReturnValueRegister, toInt,
+ as->loadAddress(TargetPlatform::ScratchRegister, source));
+ as->storeInt32(TargetPlatform::ReturnValueRegister, target);
+
+ intDone.link(as);
+ }
+
+ static void loadManagedPointer(JITAssembler *as, RegisterID registerWithPtr, Pointer destAddr)
+ {
+ as->store32(registerWithPtr, destAddr);
+ destAddr.offset += 4;
+ as->store32(TrustedImm32(QV4::Value::Managed_Type_Internal_32), destAddr);
+ }
+
+ static Jump generateIsDoubleCheck(JITAssembler *as, RegisterID tagOrValueRegister)
+ {
+ as->and32(TrustedImm32(Value::NotDouble_Mask), tagOrValueRegister);
+ return as->branch32(RelationalCondition::NotEqual, tagOrValueRegister,
+ TrustedImm32(Value::NotDouble_Mask));
+ }
+
+ static void initializeLocalVariables(JITAssembler *as, int localsCount)
+ {
+ as->move(TrustedImm32(0), TargetPlatform::ReturnValueRegister);
+ as->move(TrustedImm32(localsCount), TargetPlatform::ScratchRegister);
+ Label loop = as->label();
+ as->store32(TargetPlatform::ReturnValueRegister, Address(TargetPlatform::LocalsRegister));
+ as->add32(TrustedImm32(4), TargetPlatform::LocalsRegister);
+ as->store32(TargetPlatform::ReturnValueRegister, Address(TargetPlatform::LocalsRegister));
+ as->add32(TrustedImm32(4), TargetPlatform::LocalsRegister);
+ Jump jump = as->branchSub32(ResultCondition::NonZero, TrustedImm32(1), TargetPlatform::ScratchRegister);
+ jump.linkTo(loop, as);
+ }
+};
+
+template <typename JITAssembler, typename MacroAssembler, typename TargetPlatform>
+struct RegisterSizeDependentAssembler<JITAssembler, MacroAssembler, TargetPlatform, 8>
+{
+ using RegisterID = typename JITAssembler::RegisterID;
+ using FPRegisterID = typename JITAssembler::FPRegisterID;
+ using Address = typename JITAssembler::Address;
+ using TrustedImm32 = typename JITAssembler::TrustedImm32;
+ using TrustedImm64 = typename JITAssembler::TrustedImm64;
+ using Pointer = typename JITAssembler::Pointer;
+ using RelationalCondition = typename JITAssembler::RelationalCondition;
+ using ResultCondition = typename JITAssembler::ResultCondition;
+ using BranchTruncateType = typename JITAssembler::BranchTruncateType;
+ using Jump = typename JITAssembler::Jump;
+ using Label = typename JITAssembler::Label;
+
+ static void loadDouble(JITAssembler *as, Address addr, FPRegisterID dest)
+ {
+ as->load64(addr, TargetPlatform::ReturnValueRegister);
+ as->move(TrustedImm64(QV4::Value::NaNEncodeMask), TargetPlatform::ScratchRegister);
+ as->xor64(TargetPlatform::ScratchRegister, TargetPlatform::ReturnValueRegister);
+ as->move64ToDouble(TargetPlatform::ReturnValueRegister, dest);
+ }
+
+ static void storeDouble(JITAssembler *as, FPRegisterID source, Address addr)
+ {
+ as->moveDoubleTo64(source, TargetPlatform::ReturnValueRegister);
+ as->move(TrustedImm64(QV4::Value::NaNEncodeMask), TargetPlatform::ScratchRegister);
+ as->xor64(TargetPlatform::ScratchRegister, TargetPlatform::ReturnValueRegister);
+ as->store64(TargetPlatform::ReturnValueRegister, addr);
+ }
+
+ static void storeDouble(JITAssembler *as, FPRegisterID source, IR::Expr* target)
+ {
+ as->moveDoubleTo64(source, TargetPlatform::ReturnValueRegister);
+ as->move(TrustedImm64(QV4::Value::NaNEncodeMask), TargetPlatform::ScratchRegister);
+ as->xor64(TargetPlatform::ScratchRegister, TargetPlatform::ReturnValueRegister);
+ Pointer ptr = as->loadAddress(TargetPlatform::ScratchRegister, target);
+ as->store64(TargetPlatform::ReturnValueRegister, ptr);
+ }
+
+ static void storeReturnValue(JITAssembler *as, FPRegisterID dest)
+ {
+ as->move(TrustedImm64(QV4::Value::NaNEncodeMask), TargetPlatform::ScratchRegister);
+ as->xor64(TargetPlatform::ScratchRegister, TargetPlatform::ReturnValueRegister);
+ as->move64ToDouble(TargetPlatform::ReturnValueRegister, dest);
+ }
+
+ static void storeReturnValue(JITAssembler *as, const Pointer &dest)
+ {
+ as->store64(TargetPlatform::ReturnValueRegister, dest);
+ }
+
+ static void setFunctionReturnValueFromTemp(JITAssembler *as, IR::Temp *t)
+ {
+ if (t->kind == IR::Temp::PhysicalRegister) {
+ if (t->type == IR::DoubleType) {
+ as->moveDoubleTo64((FPRegisterID) t->index,
+ TargetPlatform::ReturnValueRegister);
+ as->move(TrustedImm64(QV4::Value::NaNEncodeMask),
+ TargetPlatform::ScratchRegister);
+ as->xor64(TargetPlatform::ScratchRegister, TargetPlatform::ReturnValueRegister);
+ } else if (t->type == IR::UInt32Type) {
+ RegisterID srcReg = (RegisterID) t->index;
+ Jump intRange = as->branch32(RelationalCondition::GreaterThanOrEqual, srcReg, TrustedImm32(0));
+ as->convertUInt32ToDouble(srcReg, TargetPlatform::FPGpr0, TargetPlatform::ReturnValueRegister);
+ as->moveDoubleTo64(TargetPlatform::FPGpr0, TargetPlatform::ReturnValueRegister);
+ as->move(TrustedImm64(QV4::Value::NaNEncodeMask), TargetPlatform::ScratchRegister);
+ as->xor64(TargetPlatform::ScratchRegister, TargetPlatform::ReturnValueRegister);
+ Jump done = as->jump();
+ intRange.link(as);
+ as->zeroExtend32ToPtr(srcReg, TargetPlatform::ReturnValueRegister);
+ quint64 tag = QV4::Value::Integer_Type_Internal;
+ as->or64(TrustedImm64(tag << 32),
+ TargetPlatform::ReturnValueRegister);
+ done.link(as);
+ } else {
+ as->zeroExtend32ToPtr((RegisterID) t->index, TargetPlatform::ReturnValueRegister);
+ quint64 tag;
+ switch (t->type) {
+ case IR::SInt32Type:
+ tag = QV4::Value::Integer_Type_Internal;
+ break;
+ case IR::BoolType:
+ tag = QV4::Value::Boolean_Type_Internal;
+ break;
+ default:
+ tag = 31337; // bogus value
+ Q_UNREACHABLE();
+ }
+ as->or64(TrustedImm64(tag << 32),
+ TargetPlatform::ReturnValueRegister);
+ }
+ } else {
+ as->copyValue(TargetPlatform::ReturnValueRegister, t);
+ }
+ }
+
+ static void setFunctionReturnValueFromConst(JITAssembler *as, QV4::Primitive retVal)
+ {
+ as->move(TrustedImm64(retVal.rawValue()), TargetPlatform::ReturnValueRegister);
+ }
+
+ static void storeValue(JITAssembler *as, QV4::Primitive value, Address destination)
+ {
+ as->store64(TrustedImm64(value.rawValue()), destination);
+ }
+
+ template <typename Source, typename Destination>
+ static void copyValueViaRegisters(JITAssembler *as, Source source, Destination destination)
+ {
+ // Use ReturnValueRegister as "scratch" register because loadArgument
+ // and storeArgument are functions that may need a scratch register themselves.
+ loadArgumentInRegister(as, source, TargetPlatform::ReturnValueRegister, 0);
+ as->storeReturnValue(destination);
+ }
+
+ static void loadDoubleConstant(JITAssembler *as, IR::Const *c, FPRegisterID target)
+ {
+ Q_STATIC_ASSERT(sizeof(int64_t) == sizeof(double));
+ int64_t i;
+ memcpy(&i, &c->value, sizeof(double));
+ as->move(TrustedImm64(i), TargetPlatform::ReturnValueRegister);
+ as->move64ToDouble(TargetPlatform::ReturnValueRegister, target);
+ }
+
+ static void loadArgumentInRegister(JITAssembler *as, Address addressOfValue, RegisterID dest, int argumentNumber)
+ {
+ Q_UNUSED(argumentNumber);
+ as->load64(addressOfValue, dest);
+ }
+
+ static void loadArgumentInRegister(JITAssembler *as, IR::Temp* temp, RegisterID dest, int argumentNumber)
+ {
+ Q_UNUSED(argumentNumber);
+
+ if (temp) {
+ Pointer addr = as->loadTempAddress(temp);
+ as->load64(addr, dest);
+ } else {
+ QV4::Value undefined = QV4::Primitive::undefinedValue();
+ as->move(TrustedImm64(undefined.rawValue()), dest);
+ }
+ }
+
+ static void loadArgumentInRegister(JITAssembler *as, IR::ArgLocal* al, RegisterID dest, int argumentNumber)
+ {
+ Q_UNUSED(argumentNumber);
+
+ if (al) {
+ Pointer addr = as->loadArgLocalAddress(dest, al);
+ as->load64(addr, dest);
+ } else {
+ QV4::Value undefined = QV4::Primitive::undefinedValue();
+ as->move(TrustedImm64(undefined.rawValue()), dest);
+ }
+ }
+
+ static void loadArgumentInRegister(JITAssembler *as, IR::Const* c, RegisterID dest, int argumentNumber)
+ {
+ Q_UNUSED(argumentNumber);
+
+ QV4::Value v = convertToValue(c);
+ as->move(TrustedImm64(v.rawValue()), dest);
+ }
+
+ static void loadArgumentInRegister(JITAssembler *as, IR::Expr* expr, RegisterID dest, int argumentNumber)
+ {
+ Q_UNUSED(argumentNumber);
+
+ if (!expr) {
+ QV4::Value undefined = QV4::Primitive::undefinedValue();
+ as->move(TrustedImm64(undefined.rawValue()), dest);
+ } else if (IR::Temp *t = expr->asTemp()){
+ loadArgumentInRegister(as, t, dest, argumentNumber);
+ } else if (IR::ArgLocal *al = expr->asArgLocal()) {
+ loadArgumentInRegister(as, al, dest, argumentNumber);
+ } else if (IR::Const *c = expr->asConst()) {
+ loadArgumentInRegister(as, c, dest, argumentNumber);
+ } else {
+ Q_ASSERT(!"unimplemented expression type in loadArgument");
+ }
+ }
+
+ static void zeroRegister(JITAssembler *as, RegisterID reg)
+ {
+ as->move(TrustedImm64(0), reg);
+ }
+
+ static void zeroStackSlot(JITAssembler *as, int slot)
+ {
+ as->store64(TrustedImm64(0), as->addressForPoke(slot));
+ }
+
+ static void generateCJumpOnCompare(JITAssembler *as,
+ RelationalCondition cond,
+ RegisterID left,
+ TrustedImm64 right,
+ IR::BasicBlock *nextBlock,
+ IR::BasicBlock *currentBlock,
+ IR::BasicBlock *trueBlock,
+ IR::BasicBlock *falseBlock)
+ {
+ if (trueBlock == nextBlock) {
+ Jump target = as->branch64(as->invert(cond), left, right);
+ as->addPatch(falseBlock, target);
+ } else {
+ Jump target = as->branch64(cond, left, right);
+ as->addPatch(trueBlock, target);
+ as->jumpToBlock(currentBlock, falseBlock);
+ }
+ }
+
+ static void generateCJumpOnUndefined(JITAssembler *as,
+ RelationalCondition cond, IR::Expr *right,
+ RegisterID scratchRegister, RegisterID tagRegister,
+ IR::BasicBlock *nextBlock, IR::BasicBlock *currentBlock,
+ IR::BasicBlock *trueBlock, IR::BasicBlock *falseBlock)
+ {
+ Pointer addr = as->loadAddress(scratchRegister, right);
+ as->load64(addr, tagRegister);
+ const TrustedImm64 tag(0);
+ generateCJumpOnCompare(as, cond, tagRegister, tag, nextBlock, currentBlock, trueBlock, falseBlock);
+ }
+
+ static void convertVarToSInt32(JITAssembler *as, IR::Expr *source, IR::Expr *target)
+ {
+ Q_ASSERT(source->type == IR::VarType);
+ Pointer addr = as->loadAddress(TargetPlatform::ScratchRegister, source);
+ as->load64(addr, TargetPlatform::ScratchRegister);
+ as->move(TargetPlatform::ScratchRegister, TargetPlatform::ReturnValueRegister);
+
+ // check if it's integer convertible
+ as->urshift64(TrustedImm32(QV4::Value::IsIntegerConvertible_Shift), TargetPlatform::ScratchRegister);
+ Jump isIntConvertible = as->branch32(RelationalCondition::Equal, TargetPlatform::ScratchRegister, TrustedImm32(3));
+
+ // nope, not integer convertible, so check for a double:
+ as->urshift64(TrustedImm32(
+ QV4::Value::IsDoubleTag_Shift - QV4::Value::IsIntegerConvertible_Shift),
+ TargetPlatform::ScratchRegister);
+ Jump fallback = as->branch32(RelationalCondition::GreaterThan, TargetPlatform::ScratchRegister, TrustedImm32(0));
+
+ // it's a double
+ as->move(TrustedImm64(QV4::Value::NaNEncodeMask), TargetPlatform::ScratchRegister);
+ as->xor64(TargetPlatform::ScratchRegister, TargetPlatform::ReturnValueRegister);
+ as->move64ToDouble(TargetPlatform::ReturnValueRegister, TargetPlatform::FPGpr0);
+ Jump success =
+ as->branchTruncateDoubleToInt32(TargetPlatform::FPGpr0, TargetPlatform::ReturnValueRegister,
+ BranchTruncateType::BranchIfTruncateSuccessful);
+
+ // not an int:
+ fallback.link(as);
+ generateRuntimeCall(as, TargetPlatform::ReturnValueRegister, toInt,
+ as->loadAddress(TargetPlatform::ScratchRegister, source));
- inline RuntimeCall(uint offset = uint(INT_MIN));
- bool isValid() const { return addr.offset >= 0; }
+
+ isIntConvertible.link(as);
+ success.link(as);
+ IR::Temp *targetTemp = target->asTemp();
+ if (!targetTemp || targetTemp->kind == IR::Temp::StackSlot) {
+ Pointer targetAddr = as->loadAddress(TargetPlatform::ScratchRegister, target);
+ as->store32(TargetPlatform::ReturnValueRegister, targetAddr);
+ targetAddr.offset += 4;
+ as->store32(TrustedImm32(Value::Integer_Type_Internal), targetAddr);
+ } else {
+ as->storeInt32(TargetPlatform::ReturnValueRegister, target);
+ }
+ }
+
+ static void loadManagedPointer(JITAssembler *as, RegisterID registerWithPtr, Pointer destAddr)
+ {
+ as->store64(registerWithPtr, destAddr);
+ }
+
+ static Jump generateIsDoubleCheck(JITAssembler *as, RegisterID tagOrValueRegister)
+ {
+ as->rshift32(TrustedImm32(Value::IsDoubleTag_Shift), tagOrValueRegister);
+ return as->branch32(RelationalCondition::NotEqual, tagOrValueRegister,
+ TrustedImm32(0));
+ }
+
+ static void initializeLocalVariables(JITAssembler *as, int localsCount)
+ {
+ as->move(TrustedImm64(0), TargetPlatform::ReturnValueRegister);
+ as->move(TrustedImm32(localsCount), TargetPlatform::ScratchRegister);
+ Label loop = as->label();
+ as->store64(TargetPlatform::ReturnValueRegister, Address(TargetPlatform::LocalsRegister));
+ as->add64(TrustedImm32(8), TargetPlatform::LocalsRegister);
+ Jump jump = as->branchSub32(ResultCondition::NonZero, TrustedImm32(1), TargetPlatform::ScratchRegister);
+ jump.linkTo(loop, as);
+ }
};
-class Assembler : public JSC::MacroAssembler, public TargetPlatform
+template <typename TargetConfiguration>
+class Assembler : public TargetConfiguration::MacroAssembler, public TargetConfiguration::Platform
{
Q_DISABLE_COPY(Assembler)
public:
- Assembler(InstructionSelection *isel, IR::Function* function, QV4::ExecutableAllocator *executableAllocator);
+ Assembler(QV4::Compiler::JSUnitGenerator *jsGenerator, IR::Function* function, QV4::ExecutableAllocator *executableAllocator);
+
+ using MacroAssembler = typename TargetConfiguration::MacroAssembler;
+ using RegisterID = typename MacroAssembler::RegisterID;
+ using FPRegisterID = typename MacroAssembler::FPRegisterID;
+ using Address = typename MacroAssembler::Address;
+ using Label = typename MacroAssembler::Label;
+ using Jump = typename MacroAssembler::Jump;
+ using DataLabelPtr = typename MacroAssembler::DataLabelPtr;
+ using TrustedImm32 = typename MacroAssembler::TrustedImm32;
+ using TrustedImm64 = typename MacroAssembler::TrustedImm64;
+ using TrustedImmPtr = typename MacroAssembler::TrustedImmPtr;
+ using RelationalCondition = typename MacroAssembler::RelationalCondition;
+ using typename MacroAssembler::DoubleCondition;
+ using MacroAssembler::label;
+ using MacroAssembler::move;
+ using MacroAssembler::jump;
+ using MacroAssembler::add32;
+ using MacroAssembler::and32;
+ using MacroAssembler::store32;
+ using MacroAssembler::loadPtr;
+ using MacroAssembler::load32;
+ using MacroAssembler::branch32;
+ using MacroAssembler::subDouble;
+ using MacroAssembler::subPtr;
+ using MacroAssembler::addPtr;
+ using MacroAssembler::call;
+ using MacroAssembler::poke;
+ using MacroAssembler::branchTruncateDoubleToUint32;
+ using MacroAssembler::or32;
+ using MacroAssembler::moveDouble;
+ using MacroAssembler::convertUInt32ToDouble;
+ using MacroAssembler::invert;
+ using MacroAssembler::convertInt32ToDouble;
+ using MacroAssembler::rshift32;
+ using MacroAssembler::storePtr;
+ using MacroAssembler::ret;
+
+ using JITTargetPlatform = typename TargetConfiguration::Platform;
+ using JITTargetPlatform::RegisterArgumentCount;
+ using JITTargetPlatform::StackSpaceAllocatedUponFunctionEntry;
+ using JITTargetPlatform::RegisterSize;
+ using JITTargetPlatform::StackAlignment;
+ using JITTargetPlatform::ReturnValueRegister;
+ using JITTargetPlatform::StackPointerRegister;
+ using JITTargetPlatform::ScratchRegister;
+ using JITTargetPlatform::EngineRegister;
+ using JITTargetPlatform::StackShadowSpace;
+ using JITTargetPlatform::registerForArgument;
+ using JITTargetPlatform::FPGpr0;
+ using JITTargetPlatform::platformEnterStandardStackFrame;
+ using JITTargetPlatform::platformLeaveStandardStackFrame;
+
+ using RegisterSizeDependentOps = RegisterSizeDependentAssembler<Assembler<TargetConfiguration>, MacroAssembler, JITTargetPlatform, RegisterSize>;
+
+ struct LookupCall {
+ Address addr;
+ uint getterSetterOffset;
+
+ LookupCall(const Address &addr, uint getterSetterOffset)
+ : addr(addr)
+ , getterSetterOffset(getterSetterOffset)
+ {}
+ };
+
+ struct RuntimeCall {
+ Address addr;
+
+ inline RuntimeCall(uint offset = uint(INT_MIN));
+ bool isValid() const { return addr.offset >= 0; }
+ };
// Explicit type to allow distinguishing between
// pushing an address itself or the value it points
@@ -319,20 +945,29 @@ public:
void addPatch(DataLabelPtr patch, IR::BasicBlock *target);
void generateCJumpOnNonZero(RegisterID reg, IR::BasicBlock *currentBlock,
IR::BasicBlock *trueBlock, IR::BasicBlock *falseBlock);
-#ifdef QV4_USE_64_BIT_VALUE_ENCODING
- void generateCJumpOnCompare(RelationalCondition cond, RegisterID left, TrustedImm64 right,
- IR::BasicBlock *currentBlock, IR::BasicBlock *trueBlock,
- IR::BasicBlock *falseBlock);
-#endif
void generateCJumpOnCompare(RelationalCondition cond, RegisterID left, TrustedImm32 right,
IR::BasicBlock *currentBlock, IR::BasicBlock *trueBlock,
IR::BasicBlock *falseBlock);
void generateCJumpOnCompare(RelationalCondition cond, RegisterID left, RegisterID right,
IR::BasicBlock *currentBlock, IR::BasicBlock *trueBlock,
IR::BasicBlock *falseBlock);
- Jump genTryDoubleConversion(IR::Expr *src, Assembler::FPRegisterID dest);
- Assembler::Jump branchDouble(bool invertCondition, IR::AluOp op, IR::Expr *left, IR::Expr *right);
- Assembler::Jump branchInt32(bool invertCondition, IR::AluOp op, IR::Expr *left, IR::Expr *right);
+ void generateCJumpOnUndefined(RelationalCondition cond, IR::Expr *right,
+ RegisterID scratchRegister, RegisterID tagRegister,
+ IR::BasicBlock *currentBlock, IR::BasicBlock *trueBlock,
+ IR::BasicBlock *falseBlock)
+ {
+ RegisterSizeDependentOps::generateCJumpOnUndefined(this, cond, right, scratchRegister, tagRegister,
+ _nextBlock, currentBlock, trueBlock, falseBlock);
+ }
+
+ Jump generateIsDoubleCheck(RegisterID tagOrValueRegister)
+ {
+ return RegisterSizeDependentOps::generateIsDoubleCheck(this, tagOrValueRegister);
+ }
+
+ Jump genTryDoubleConversion(IR::Expr *src, FPRegisterID dest);
+ Jump branchDouble(bool invertCondition, IR::AluOp op, IR::Expr *left, IR::Expr *right);
+ Jump branchInt32(bool invertCondition, IR::AluOp op, IR::Expr *left, IR::Expr *right);
Pointer loadAddress(RegisterID tmp, IR::Expr *t);
Pointer loadTempAddress(IR::Temp *t);
@@ -396,7 +1031,7 @@ public:
void loadArgumentInRegister(PointerToValue temp, RegisterID dest, int argumentNumber)
{
if (!temp.value) {
- move(TrustedImmPtr(0), dest);
+ RegisterSizeDependentOps::zeroRegister(this, dest);
} else {
Pointer addr = toAddress(dest, temp.value, argumentNumber);
loadArgumentInRegister(addr, dest, argumentNumber);
@@ -415,70 +1050,31 @@ public:
loadArgumentInRegister(addr, dest, argumentNumber);
}
-#ifdef VALUE_FITS_IN_REGISTER
void loadArgumentInRegister(IR::Temp* temp, RegisterID dest, int argumentNumber)
{
- Q_UNUSED(argumentNumber);
-
- if (temp) {
- Pointer addr = loadTempAddress(temp);
- load64(addr, dest);
- } else {
- QV4::Value undefined = QV4::Primitive::undefinedValue();
- move(TrustedImm64(undefined.rawValue()), dest);
- }
+ RegisterSizeDependentOps::loadArgumentInRegister(this, temp, dest, argumentNumber);
}
void loadArgumentInRegister(IR::ArgLocal* al, RegisterID dest, int argumentNumber)
{
- Q_UNUSED(argumentNumber);
-
- if (al) {
- Pointer addr = loadArgLocalAddress(dest, al);
- load64(addr, dest);
- } else {
- QV4::Value undefined = QV4::Primitive::undefinedValue();
- move(TrustedImm64(undefined.rawValue()), dest);
- }
+ RegisterSizeDependentOps::loadArgumentInRegister(this, al, dest, argumentNumber);
}
void loadArgumentInRegister(IR::Const* c, RegisterID dest, int argumentNumber)
{
- Q_UNUSED(argumentNumber);
-
- QV4::Value v = convertToValue(c);
- move(TrustedImm64(v.rawValue()), dest);
+ RegisterSizeDependentOps::loadArgumentInRegister(this, c, dest, argumentNumber);
}
void loadArgumentInRegister(IR::Expr* expr, RegisterID dest, int argumentNumber)
{
- Q_UNUSED(argumentNumber);
-
- if (!expr) {
- QV4::Value undefined = QV4::Primitive::undefinedValue();
- move(TrustedImm64(undefined.rawValue()), dest);
- } else if (IR::Temp *t = expr->asTemp()){
- loadArgumentInRegister(t, dest, argumentNumber);
- } else if (IR::ArgLocal *al = expr->asArgLocal()) {
- loadArgumentInRegister(al, dest, argumentNumber);
- } else if (IR::Const *c = expr->asConst()) {
- loadArgumentInRegister(c, dest, argumentNumber);
- } else {
- Q_ASSERT(!"unimplemented expression type in loadArgument");
- }
- }
-#else
- void loadArgumentInRegister(IR::Expr*, RegisterID)
- {
- Q_ASSERT(!"unimplemented: expression in loadArgument");
+ RegisterSizeDependentOps::loadArgumentInRegister(this, expr, dest, argumentNumber);
}
-#endif
void loadArgumentInRegister(TrustedImm32 imm32, RegisterID dest, int argumentNumber)
{
Q_UNUSED(argumentNumber);
- xorPtr(dest, dest);
+ RegisterSizeDependentOps::zeroRegister(this, dest);
if (imm32.m_value)
move(imm32, dest);
}
@@ -499,55 +1095,13 @@ public:
void storeReturnValue(FPRegisterID dest)
{
-#ifdef VALUE_FITS_IN_REGISTER
- move(TrustedImm64(QV4::Value::NaNEncodeMask), ScratchRegister);
- xor64(ScratchRegister, ReturnValueRegister);
- move64ToDouble(ReturnValueRegister, dest);
-#elif defined(Q_PROCESSOR_ARM)
- moveIntsToDouble(JSC::ARMRegisters::r0, JSC::ARMRegisters::r1, dest, FPGpr0);
-#elif defined(Q_PROCESSOR_X86)
- moveIntsToDouble(JSC::X86Registers::eax, JSC::X86Registers::edx, dest, FPGpr0);
-#elif defined(Q_PROCESSOR_MIPS)
- moveIntsToDouble(JSC::MIPSRegisters::v0, JSC::MIPSRegisters::v1, dest, FPGpr0);
-#else
- subPtr(TrustedImm32(sizeof(QV4::Value)), StackPointerRegister);
- Pointer tmp(StackPointerRegister, 0);
- storeReturnValue(tmp);
- loadDouble(tmp, dest);
- addPtr(TrustedImm32(sizeof(QV4::Value)), StackPointerRegister);
-#endif
+ RegisterSizeDependentOps::storeReturnValue(this, dest);
}
-#ifdef VALUE_FITS_IN_REGISTER
- void storeReturnValue(const Pointer &dest)
- {
- store64(ReturnValueRegister, dest);
- }
-#elif defined(Q_PROCESSOR_X86)
void storeReturnValue(const Pointer &dest)
{
- Pointer destination = dest;
- store32(JSC::X86Registers::eax, destination);
- destination.offset += 4;
- store32(JSC::X86Registers::edx, destination);
+ RegisterSizeDependentOps::storeReturnValue(this, dest);
}
-#elif defined(Q_PROCESSOR_ARM)
- void storeReturnValue(const Pointer &dest)
- {
- Pointer destination = dest;
- store32(JSC::ARMRegisters::r0, destination);
- destination.offset += 4;
- store32(JSC::ARMRegisters::r1, destination);
- }
-#elif defined(Q_PROCESSOR_MIPS)
- void storeReturnValue(const Pointer &dest)
- {
- Pointer destination = dest;
- store32(JSC::MIPSRegisters::v0, destination);
- destination.offset += 4;
- store32(JSC::MIPSRegisters::v1, destination);
- }
-#endif
void storeReturnValue(IR::Expr *target)
{
@@ -609,7 +1163,7 @@ public:
Pointer ptr = toAddress(ScratchRegister, temp.value, argumentNumber);
loadArgumentOnStack<StackSlot>(ptr, argumentNumber);
} else {
- poke(TrustedImmPtr(0), StackSlot);
+ RegisterSizeDependentOps::zeroStackSlot(this, StackSlot);
}
}
@@ -648,38 +1202,18 @@ public:
moveDouble(source, (FPRegisterID) targetTemp->index);
return;
}
-#ifdef QV4_USE_64_BIT_VALUE_ENCODING
- moveDoubleTo64(source, ReturnValueRegister);
- move(TrustedImm64(QV4::Value::NaNEncodeMask), ScratchRegister);
- xor64(ScratchRegister, ReturnValueRegister);
- Pointer ptr = loadAddress(ScratchRegister, target);
- store64(ReturnValueRegister, ptr);
-#else
- Pointer ptr = loadAddress(ScratchRegister, target);
- storeDouble(source, ptr);
-#endif
+ RegisterSizeDependentOps::storeDouble(this, source, target);
}
-#ifdef QV4_USE_64_BIT_VALUE_ENCODING
- // We need to (de)mangle the double
+
void loadDouble(Address addr, FPRegisterID dest)
{
- load64(addr, ReturnValueRegister);
- move(TrustedImm64(QV4::Value::NaNEncodeMask), ScratchRegister);
- xor64(ScratchRegister, ReturnValueRegister);
- move64ToDouble(ReturnValueRegister, dest);
+ RegisterSizeDependentOps::loadDouble(this, addr, dest);
}
void storeDouble(FPRegisterID source, Address addr)
{
- moveDoubleTo64(source, ReturnValueRegister);
- move(TrustedImm64(QV4::Value::NaNEncodeMask), ScratchRegister);
- xor64(ScratchRegister, ReturnValueRegister);
- store64(ReturnValueRegister, addr);
+ RegisterSizeDependentOps::storeDouble(this, source, addr);
}
-#else
- using JSC::MacroAssembler::loadDouble;
- using JSC::MacroAssembler::storeDouble;
-#endif
template <typename Result, typename Source>
void copyValue(Result result, Source source);
@@ -691,8 +1225,15 @@ public:
{
Q_ASSERT(!source->asTemp() || source->asTemp()->kind != IR::Temp::PhysicalRegister);
Q_ASSERT(target.base != scratchRegister);
- JSC::MacroAssembler::loadDouble(loadAddress(scratchRegister, source), FPGpr0);
- JSC::MacroAssembler::storeDouble(FPGpr0, target);
+ TargetConfiguration::MacroAssembler::loadDouble(loadAddress(scratchRegister, source), FPGpr0);
+ TargetConfiguration::MacroAssembler::storeDouble(FPGpr0, target);
+ }
+
+ // The scratch register is used to calculate the temp address for the source.
+ void memcopyValue(IR::Expr *target, Pointer source, FPRegisterID fpScratchRegister, RegisterID scratchRegister)
+ {
+ TargetConfiguration::MacroAssembler::loadDouble(source, fpScratchRegister);
+ TargetConfiguration::MacroAssembler::storeDouble(fpScratchRegister, loadAddress(scratchRegister, target));
}
void storeValue(QV4::Primitive value, RegisterID destination)
@@ -704,13 +1245,7 @@ public:
void storeValue(QV4::Primitive value, Address destination)
{
-#ifdef VALUE_FITS_IN_REGISTER
- store64(TrustedImm64(value.rawValue()), destination);
-#else
- store32(TrustedImm32(value.int_32()), destination);
- destination.offset += 4;
- store32(TrustedImm32(value.tag()), destination);
-#endif
+ RegisterSizeDependentOps::storeValue(this, value, destination);
}
void storeValue(QV4::Primitive value, IR::Expr* temp);
@@ -722,7 +1257,7 @@ public:
void checkException() {
load32(Address(EngineRegister, qOffsetOf(QV4::ExecutionEngine, hasException)), ScratchRegister);
- Jump exceptionThrown = branch32(NotEqual, ScratchRegister, TrustedImm32(0));
+ Jump exceptionThrown = branch32(RelationalCondition::NotEqual, ScratchRegister, TrustedImm32(0));
if (catchBlock)
addPatch(catchBlock, exceptionThrown);
else
@@ -781,6 +1316,27 @@ public:
enum { Size = 0 };
};
+ template <typename T> bool prepareCall(T &)
+ { return true; }
+
+ bool prepareCall(LookupCall &lookupCall)
+ {
+ // IMPORTANT! See generateLookupCall in qv4isel_masm_p.h for details!
+
+ // load the table from the context
+ loadPtr(Address(EngineRegister, qOffsetOf(QV4::ExecutionEngine, current)), ScratchRegister);
+ loadPtr(Address(ScratchRegister, qOffsetOf(QV4::Heap::ExecutionContext, lookups)),
+ lookupCall.addr.base);
+ // pre-calculate the indirect address for the lookupCall table:
+ if (lookupCall.addr.offset)
+ addPtr(TrustedImm32(lookupCall.addr.offset), lookupCall.addr.base);
+ // store it as the first argument
+ loadArgumentOnStackOrRegister<0>(lookupCall.addr.base);
+ // set the destination addresses offset to the getterSetterOffset. The base is the lookupCall table's address
+ lookupCall.addr.offset = lookupCall.getterSetterOffset;
+ return false;
+ }
+
template <typename ArgRet, typename Callable, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6>
void generateFunctionCallImp(bool needsExceptionCheck, ArgRet r, const char* functionName, Callable function, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
{
@@ -813,12 +1369,11 @@ public:
loadArgumentOnStackOrRegister<2>(arg3);
loadArgumentOnStackOrRegister<1>(arg2);
- if (prepareCall(function, this))
+ if (prepareCall(function))
loadArgumentOnStackOrRegister<0>(arg1);
-#ifdef RESTORE_EBX_ON_CALL
- load32(ebxAddressOnStack(), JSC::X86Registers::ebx); // restore the GOT ptr
-#endif
+ if (JITTargetPlatform::gotRegister != -1)
+ load32(Address(JITTargetPlatform::FramePointerRegister, JITTargetPlatform::savedGOTRegisterSlotOnStack()), static_cast<RegisterID>(JITTargetPlatform::gotRegister)); // restore the GOT ptr
callAbsolute(functionName, function);
@@ -957,7 +1512,7 @@ public:
void storeUInt32(RegisterID reg, Pointer addr)
{
// The UInt32 representation in QV4::Value is really convoluted. See also toUInt32Register.
- Jump intRange = branch32(GreaterThanOrEqual, reg, TrustedImm32(0));
+ Jump intRange = branch32(RelationalCondition::GreaterThanOrEqual, reg, TrustedImm32(0));
convertUInt32ToDouble(reg, FPGpr0, ReturnValueRegister);
storeDouble(FPGpr0, addr);
Jump done = jump();
@@ -980,15 +1535,7 @@ public:
FPRegisterID toDoubleRegister(IR::Expr *e, FPRegisterID target = FPGpr0)
{
if (IR::Const *c = e->asConst()) {
-#ifdef QV4_USE_64_BIT_VALUE_ENCODING
- Q_STATIC_ASSERT(sizeof(int64_t) == sizeof(double));
- int64_t i;
- memcpy(&i, &c->value, sizeof(double));
- move(TrustedImm64(i), ReturnValueRegister);
- move64ToDouble(ReturnValueRegister, target);
-#else
- JSC::MacroAssembler::loadDouble(loadConstant(c, ScratchRegister), target);
-#endif
+ RegisterSizeDependentOps::loadDoubleConstant(this, c, target);
return target;
}
@@ -1047,7 +1594,7 @@ public:
Pointer tagAddr = addr;
tagAddr.offset += 4;
load32(tagAddr, scratchReg);
- Jump inIntRange = branch32(Equal, scratchReg, TrustedImm32(QV4::Value::Integer_Type_Internal));
+ Jump inIntRange = branch32(RelationalCondition::Equal, scratchReg, TrustedImm32(QV4::Value::Integer_Type_Internal));
// it's not in signed int range, so load it as a double, and truncate it down
loadDouble(addr, FPGpr0);
@@ -1065,10 +1612,21 @@ public:
return scratchReg;
}
+ void returnFromFunction(IR::Ret *s, RegisterInformation regularRegistersToSave, RegisterInformation fpRegistersToSave);
+
JSC::MacroAssemblerCodeRef link(int *codeSize);
void setStackLayout(int maxArgCountForBuiltins, int regularRegistersToSave, int fpRegistersToSave);
const StackLayout &stackLayout() const { return *_stackLayout.data(); }
+ void initializeLocalVariables()
+ {
+ const int locals = _stackLayout->calculateJSStackFrameSize();
+ if (locals <= 0)
+ return;
+ loadPtr(Address(JITTargetPlatform::EngineRegister, qOffsetOf(ExecutionEngine, jsStackTop)), JITTargetPlatform::LocalsRegister);
+ RegisterSizeDependentOps::initializeLocalVariables(this, locals);
+ storePtr(JITTargetPlatform::LocalsRegister, Address(JITTargetPlatform::EngineRegister, qOffsetOf(ExecutionEngine, jsStackTop)));
+ }
Label exceptionReturnLabel;
IR::BasicBlock * catchBlock;
@@ -1092,25 +1650,19 @@ private:
IR::BasicBlock *_nextBlock;
QV4::ExecutableAllocator *_executableAllocator;
- InstructionSelection *_isel;
+ QV4::Compiler::JSUnitGenerator *_jsGenerator;
};
+template <typename TargetConfiguration>
template <typename Result, typename Source>
-void Assembler::copyValue(Result result, Source source)
+void Assembler<TargetConfiguration>::copyValue(Result result, Source source)
{
-#ifdef VALUE_FITS_IN_REGISTER
- // Use ReturnValueRegister as "scratch" register because loadArgument
- // and storeArgument are functions that may need a scratch register themselves.
- loadArgumentInRegister(source, ReturnValueRegister, 0);
- storeReturnValue(result);
-#else
- loadDouble(source, FPGpr0);
- storeDouble(FPGpr0, result);
-#endif
+ RegisterSizeDependentOps::copyValueViaRegisters(this, source, result);
}
+template <typename TargetConfiguration>
template <typename Result>
-void Assembler::copyValue(Result result, IR::Expr* source)
+void Assembler<TargetConfiguration>::copyValue(Result result, IR::Expr* source)
{
if (source->type == IR::BoolType) {
RegisterID reg = toInt32Register(source, ScratchRegister);
@@ -1124,15 +1676,7 @@ void Assembler::copyValue(Result result, IR::Expr* source)
} else if (source->type == IR::DoubleType) {
storeDouble(toDoubleRegister(source), result);
} else if (source->asTemp() || source->asArgLocal()) {
-#ifdef VALUE_FITS_IN_REGISTER
- // Use ReturnValueRegister as "scratch" register because loadArgument
- // and storeArgument are functions that may need a scratch register themselves.
- loadArgumentInRegister(source, ReturnValueRegister, 0);
- storeReturnValue(result);
-#else
- loadDouble(source, FPGpr0);
- storeDouble(FPGpr0, result);
-#endif
+ RegisterSizeDependentOps::copyValueViaRegisters(this, source, result);
} else if (IR::Const *c = source->asConst()) {
QV4::Primitive v = convertToValue(c);
storeValue(v, result);
@@ -1141,34 +1685,12 @@ void Assembler::copyValue(Result result, IR::Expr* source)
}
}
-inline RuntimeCall::RuntimeCall(uint offset)
+template <typename TargetConfiguration>
+inline Assembler<TargetConfiguration>::RuntimeCall::RuntimeCall(uint offset)
: addr(Assembler::EngineRegister, offset + qOffsetOf(QV4::ExecutionEngine, runtime))
{
}
-
-
-template <typename T> inline bool prepareCall(T &, Assembler *)
-{ return true; }
-
-template <> inline bool prepareCall(LookupCall &lookupCall, Assembler *as)
-{
- // IMPORTANT! See generateLookupCall in qv4isel_masm_p.h for details!
-
- // load the table from the context
- as->loadPtr(Assembler::Address(Assembler::EngineRegister, qOffsetOf(QV4::ExecutionEngine, current)), Assembler::ScratchRegister);
- as->loadPtr(Assembler::Address(Assembler::ScratchRegister, qOffsetOf(QV4::Heap::ExecutionContext, lookups)),
- lookupCall.addr.base);
- // pre-calculate the indirect address for the lookupCall table:
- if (lookupCall.addr.offset)
- as->addPtr(Assembler::TrustedImm32(lookupCall.addr.offset), lookupCall.addr.base);
- // store it as the first argument
- as->loadArgumentOnStackOrRegister<0>(lookupCall.addr.base);
- // set the destination addresses offset to the getterSetterOffset. The base is the lookupCall table's address
- lookupCall.addr.offset = lookupCall.getterSetterOffset;
- return false;
-}
-
} // end of namespace JIT
} // end of namespace QV4
diff --git a/src/qml/jit/qv4binop.cpp b/src/qml/jit/qv4binop.cpp
index 9c535bb0bb..22067bbb13 100644
--- a/src/qml/jit/qv4binop.cpp
+++ b/src/qml/jit/qv4binop.cpp
@@ -41,8 +41,128 @@
#if ENABLE(ASSEMBLER)
-using namespace QV4;
-using namespace JIT;
+QT_BEGIN_NAMESPACE
+
+namespace QV4 {
+namespace JIT {
+
+template <typename JITAssembler>
+struct ArchitectureSpecificBinaryOperation
+{
+ using FPRegisterID = typename JITAssembler::FPRegisterID;
+
+ static bool doubleAdd(JITAssembler *as, IR::Expr *lhs, IR::Expr *rhs, FPRegisterID targetReg)
+ {
+ Q_UNUSED(as);
+ Q_UNUSED(lhs);
+ Q_UNUSED(rhs);
+ Q_UNUSED(targetReg);
+ return false;
+ }
+ static bool doubleMul(JITAssembler *as, IR::Expr *lhs, IR::Expr *rhs, FPRegisterID targetReg)
+ {
+ Q_UNUSED(as);
+ Q_UNUSED(lhs);
+ Q_UNUSED(rhs);
+ Q_UNUSED(targetReg);
+ return false;
+ }
+ static bool doubleSub(JITAssembler *as, IR::Expr *lhs, IR::Expr *rhs, FPRegisterID targetReg)
+ {
+ Q_UNUSED(as);
+ Q_UNUSED(lhs);
+ Q_UNUSED(rhs);
+ Q_UNUSED(targetReg);
+ return false;
+ }
+ static bool doubleDiv(JITAssembler *as, IR::Expr *lhs, IR::Expr *rhs, FPRegisterID targetReg)
+ {
+ Q_UNUSED(as);
+ Q_UNUSED(lhs);
+ Q_UNUSED(rhs);
+ Q_UNUSED(targetReg);
+ return false;
+ }
+};
+
+#if CPU(X86)
+template <>
+struct ArchitectureSpecificBinaryOperation<Assembler<AssemblerTargetConfiguration<JSC::MacroAssemblerX86, NoOperatingSystemSpecialization>>>
+{
+ using JITAssembler = Assembler<AssemblerTargetConfiguration<JSC::MacroAssemblerX86, NoOperatingSystemSpecialization>>;
+ using FPRegisterID = JITAssembler::FPRegisterID;
+ using Address = JITAssembler::Address;
+
+ static bool doubleAdd(JITAssembler *as, IR::Expr *lhs, IR::Expr *rhs, FPRegisterID targetReg)
+ {
+ if (IR::Const *c = rhs->asConst()) { // Y = X + constant -> Y = X; Y += [constant-address]
+ as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
+ Address addr = as->loadConstant(c, JITAssembler::ScratchRegister);
+ as->addDouble(addr, targetReg);
+ return true;
+ }
+ if (IR::Temp *t = rhs->asTemp()) { // Y = X + [temp-memory-address] -> Y = X; Y += [temp-memory-address]
+ if (t->kind != IR::Temp::PhysicalRegister) {
+ as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
+ as->addDouble(as->loadTempAddress(t), targetReg);
+ return true;
+ }
+ }
+ return false;
+ }
+ static bool doubleMul(JITAssembler *as, IR::Expr *lhs, IR::Expr *rhs, FPRegisterID targetReg)
+ {
+ if (IR::Const *c = rhs->asConst()) { // Y = X * constant -> Y = X; Y *= [constant-address]
+ as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
+ Address addr = as->loadConstant(c, JITAssembler::ScratchRegister);
+ as->mulDouble(addr, targetReg);
+ return true;
+ }
+ if (IR::Temp *t = rhs->asTemp()) { // Y = X * [temp-memory-address] -> Y = X; Y *= [temp-memory-address]
+ if (t->kind != IR::Temp::PhysicalRegister) {
+ as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
+ as->mulDouble(as->loadTempAddress(t), targetReg);
+ return true;
+ }
+ }
+ return false;
+ }
+ static bool doubleSub(JITAssembler *as, IR::Expr *lhs, IR::Expr *rhs, FPRegisterID targetReg)
+ {
+ if (IR::Const *c = rhs->asConst()) { // Y = X - constant -> Y = X; Y -= [constant-address]
+ as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
+ Address addr = as->loadConstant(c, JITAssembler::ScratchRegister);
+ as->subDouble(addr, targetReg);
+ return true;
+ }
+ if (IR::Temp *t = rhs->asTemp()) { // Y = X - [temp-memory-address] -> Y = X; Y -= [temp-memory-address]
+ if (t->kind != IR::Temp::PhysicalRegister) {
+ as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
+ as->subDouble(as->loadTempAddress(t), targetReg);
+ return true;
+ }
+ }
+ return false;
+ }
+ static bool doubleDiv(JITAssembler *as, IR::Expr *lhs, IR::Expr *rhs, FPRegisterID targetReg)
+ {
+ if (IR::Const *c = rhs->asConst()) { // Y = X / constant -> Y = X; Y /= [constant-address]
+ as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
+ Address addr = as->loadConstant(c, JITAssembler::ScratchRegister);
+ as->divDouble(addr, targetReg);
+ return true;
+ }
+ if (IR::Temp *t = rhs->asTemp()) { // Y = X / [temp-memory-address] -> Y = X; Y /= [temp-memory-address]
+ if (t->kind != IR::Temp::PhysicalRegister) {
+ as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
+ as->divDouble(as->loadTempAddress(t), targetReg);
+ return true;
+ }
+ }
+ return false;
+ }
+};
+#endif
#define OP(op) \
{ "Runtime::" isel_stringIfy(op), offsetof(QV4::Runtime, op), INT_MIN, 0, 0, QV4::Runtime::Method_##op##_NeedsExceptionCheck }
@@ -57,7 +177,8 @@ using namespace JIT;
#define NULL_OP \
{ 0, 0, 0, 0, 0, false }
-const Binop::OpInfo Binop::operations[IR::LastAluOp + 1] = {
+template <typename JITAssembler>
+const typename Binop<JITAssembler>::OpInfo Binop<JITAssembler>::operations[IR::LastAluOp + 1] = {
NULL_OP, // OpInvalid
NULL_OP, // OpIfTrue
NULL_OP, // OpNot
@@ -67,20 +188,20 @@ const Binop::OpInfo Binop::operations[IR::LastAluOp + 1] = {
NULL_OP, // OpIncrement
NULL_OP, // OpDecrement
- INLINE_OP(bitAnd, &Binop::inline_and32, &Binop::inline_and32), // OpBitAnd
- INLINE_OP(bitOr, &Binop::inline_or32, &Binop::inline_or32), // OpBitOr
- INLINE_OP(bitXor, &Binop::inline_xor32, &Binop::inline_xor32), // OpBitXor
+ INLINE_OP(bitAnd, &Binop<JITAssembler>::inline_and32, &Binop<JITAssembler>::inline_and32), // OpBitAnd
+ INLINE_OP(bitOr, &Binop<JITAssembler>::inline_or32, &Binop<JITAssembler>::inline_or32), // OpBitOr
+ INLINE_OP(bitXor, &Binop<JITAssembler>::inline_xor32, &Binop<JITAssembler>::inline_xor32), // OpBitXor
- INLINE_OPCONTEXT(add, &Binop::inline_add32, &Binop::inline_add32), // OpAdd
- INLINE_OP(sub, &Binop::inline_sub32, &Binop::inline_sub32), // OpSub
- INLINE_OP(mul, &Binop::inline_mul32, &Binop::inline_mul32), // OpMul
+ INLINE_OPCONTEXT(add, &Binop<JITAssembler>::inline_add32, &Binop<JITAssembler>::inline_add32), // OpAdd
+ INLINE_OP(sub, &Binop<JITAssembler>::inline_sub32, &Binop<JITAssembler>::inline_sub32), // OpSub
+ INLINE_OP(mul, &Binop<JITAssembler>::inline_mul32, &Binop<JITAssembler>::inline_mul32), // OpMul
OP(div), // OpDiv
OP(mod), // OpMod
- INLINE_OP(shl, &Binop::inline_shl32, &Binop::inline_shl32), // OpLShift
- INLINE_OP(shr, &Binop::inline_shr32, &Binop::inline_shr32), // OpRShift
- INLINE_OP(ushr, &Binop::inline_ushr32, &Binop::inline_ushr32), // OpURShift
+ INLINE_OP(shl, &Binop<JITAssembler>::inline_shl32, &Binop<JITAssembler>::inline_shl32), // OpLShift
+ INLINE_OP(shr, &Binop<JITAssembler>::inline_shr32, &Binop<JITAssembler>::inline_shr32), // OpRShift
+ INLINE_OP(ushr, &Binop<JITAssembler>::inline_ushr32, &Binop<JITAssembler>::inline_ushr32), // OpURShift
OP(greaterThan), // OpGt
OP(lessThan), // OpLt
@@ -100,7 +221,8 @@ const Binop::OpInfo Binop::operations[IR::LastAluOp + 1] = {
-void Binop::generate(IR::Expr *lhs, IR::Expr *rhs, IR::Expr *target)
+template <typename JITAssembler>
+void Binop<JITAssembler>::generate(IR::Expr *lhs, IR::Expr *rhs, IR::Expr *target)
{
if (op != IR::OpMod
&& lhs->type == IR::DoubleType && rhs->type == IR::DoubleType) {
@@ -112,7 +234,7 @@ void Binop::generate(IR::Expr *lhs, IR::Expr *rhs, IR::Expr *target)
return;
}
- Assembler::Jump done;
+ Jump done;
if (lhs->type != IR::StringType && rhs->type != IR::StringType)
done = genInlineBinop(lhs, rhs, target);
@@ -125,17 +247,17 @@ void Binop::generate(IR::Expr *lhs, IR::Expr *rhs, IR::Expr *target)
info = stringAdd;
}
- RuntimeCall fallBack(info.fallbackImplementation);
- RuntimeCall context(info.contextImplementation);
+ typename JITAssembler::RuntimeCall fallBack(info.fallbackImplementation);
+ typename JITAssembler::RuntimeCall context(info.contextImplementation);
if (fallBack.isValid()) {
as->generateFunctionCallImp(info.needsExceptionCheck, target, info.name, fallBack,
- Assembler::PointerToValue(lhs),
- Assembler::PointerToValue(rhs));
+ PointerToValue(lhs),
+ PointerToValue(rhs));
} else if (context.isValid()) {
as->generateFunctionCallImp(info.needsExceptionCheck, target, info.name, context,
- Assembler::EngineRegister,
- Assembler::PointerToValue(lhs),
- Assembler::PointerToValue(rhs));
+ JITAssembler::EngineRegister,
+ PointerToValue(lhs),
+ PointerToValue(rhs));
} else {
Q_ASSERT(!"unreachable");
}
@@ -145,122 +267,73 @@ void Binop::generate(IR::Expr *lhs, IR::Expr *rhs, IR::Expr *target)
}
-void Binop::doubleBinop(IR::Expr *lhs, IR::Expr *rhs, IR::Expr *target)
+template <typename JITAssembler>
+void Binop<JITAssembler>::doubleBinop(IR::Expr *lhs, IR::Expr *rhs, IR::Expr *target)
{
IR::Temp *targetTemp = target->asTemp();
- Assembler::FPRegisterID targetReg;
+ FPRegisterID targetReg;
if (targetTemp && targetTemp->kind == IR::Temp::PhysicalRegister)
- targetReg = (Assembler::FPRegisterID) targetTemp->index;
+ targetReg = (FPRegisterID) targetTemp->index;
else
- targetReg = Assembler::FPGpr0;
+ targetReg = JITAssembler::FPGpr0;
switch (op) {
case IR::OpAdd:
if (lhs->asConst())
std::swap(lhs, rhs); // Y = constant + X -> Y = X + constant
-#if CPU(X86)
- if (IR::Const *c = rhs->asConst()) { // Y = X + constant -> Y = X; Y += [constant-address]
- as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
- Assembler::Address addr = as->loadConstant(c, Assembler::ScratchRegister);
- as->addDouble(addr, targetReg);
+ if (ArchitectureSpecificBinaryOperation<JITAssembler>::doubleAdd(as, lhs, rhs, targetReg))
break;
- }
- if (IR::Temp *t = rhs->asTemp()) { // Y = X + [temp-memory-address] -> Y = X; Y += [temp-memory-address]
- if (t->kind != IR::Temp::PhysicalRegister) {
- as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
- as->addDouble(as->loadTempAddress(t), targetReg);
- break;
- }
- }
-#endif
- as->addDouble(as->toDoubleRegister(lhs, Assembler::FPGpr0), as->toDoubleRegister(rhs, Assembler::FPGpr1), targetReg);
+
+ as->addDouble(as->toDoubleRegister(lhs, JITAssembler::FPGpr0), as->toDoubleRegister(rhs, JITAssembler::FPGpr1), targetReg);
break;
case IR::OpMul:
if (lhs->asConst())
std::swap(lhs, rhs); // Y = constant * X -> Y = X * constant
-#if CPU(X86)
- if (IR::Const *c = rhs->asConst()) { // Y = X * constant -> Y = X; Y *= [constant-address]
- as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
- Assembler::Address addr = as->loadConstant(c, Assembler::ScratchRegister);
- as->mulDouble(addr, targetReg);
+ if (ArchitectureSpecificBinaryOperation<JITAssembler>::doubleMul(as, lhs, rhs, targetReg))
break;
- }
- if (IR::Temp *t = rhs->asTemp()) { // Y = X * [temp-memory-address] -> Y = X; Y *= [temp-memory-address]
- if (t->kind != IR::Temp::PhysicalRegister) {
- as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
- as->mulDouble(as->loadTempAddress(t), targetReg);
- break;
- }
- }
-#endif
- as->mulDouble(as->toDoubleRegister(lhs, Assembler::FPGpr0), as->toDoubleRegister(rhs, Assembler::FPGpr1), targetReg);
+
+ as->mulDouble(as->toDoubleRegister(lhs, JITAssembler::FPGpr0), as->toDoubleRegister(rhs, JITAssembler::FPGpr1), targetReg);
break;
case IR::OpSub:
-#if CPU(X86)
- if (IR::Const *c = rhs->asConst()) { // Y = X - constant -> Y = X; Y -= [constant-address]
- as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
- Assembler::Address addr = as->loadConstant(c, Assembler::ScratchRegister);
- as->subDouble(addr, targetReg);
+ if (ArchitectureSpecificBinaryOperation<JITAssembler>::doubleSub(as, lhs, rhs, targetReg))
break;
- }
- if (IR::Temp *t = rhs->asTemp()) { // Y = X - [temp-memory-address] -> Y = X; Y -= [temp-memory-address]
- if (t->kind != IR::Temp::PhysicalRegister) {
- as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
- as->subDouble(as->loadTempAddress(t), targetReg);
- break;
- }
- }
-#endif
+
if (rhs->asTemp() && rhs->asTemp()->kind == IR::Temp::PhysicalRegister
&& targetTemp
&& targetTemp->kind == IR::Temp::PhysicalRegister
&& targetTemp->index == rhs->asTemp()->index) { // Y = X - Y -> Tmp = Y; Y = X - Tmp
- as->moveDouble(as->toDoubleRegister(rhs, Assembler::FPGpr1), Assembler::FPGpr1);
- as->subDouble(as->toDoubleRegister(lhs, Assembler::FPGpr0), Assembler::FPGpr1, targetReg);
+ as->moveDouble(as->toDoubleRegister(rhs, JITAssembler::FPGpr1), JITAssembler::FPGpr1);
+ as->subDouble(as->toDoubleRegister(lhs, JITAssembler::FPGpr0), JITAssembler::FPGpr1, targetReg);
break;
}
- as->subDouble(as->toDoubleRegister(lhs, Assembler::FPGpr0), as->toDoubleRegister(rhs, Assembler::FPGpr1), targetReg);
+ as->subDouble(as->toDoubleRegister(lhs, JITAssembler::FPGpr0), as->toDoubleRegister(rhs, JITAssembler::FPGpr1), targetReg);
break;
case IR::OpDiv:
-#if CPU(X86)
- if (IR::Const *c = rhs->asConst()) { // Y = X / constant -> Y = X; Y /= [constant-address]
- as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
- Assembler::Address addr = as->loadConstant(c, Assembler::ScratchRegister);
- as->divDouble(addr, targetReg);
+ if (ArchitectureSpecificBinaryOperation<JITAssembler>::doubleDiv(as, lhs, rhs, targetReg))
break;
- }
- if (IR::Temp *t = rhs->asTemp()) { // Y = X / [temp-memory-address] -> Y = X; Y /= [temp-memory-address]
- if (t->kind != IR::Temp::PhysicalRegister) {
- as->moveDouble(as->toDoubleRegister(lhs, targetReg), targetReg);
- as->divDouble(as->loadTempAddress(t), targetReg);
- break;
- }
- }
-#endif
if (rhs->asTemp() && rhs->asTemp()->kind == IR::Temp::PhysicalRegister
&& targetTemp
&& targetTemp->kind == IR::Temp::PhysicalRegister
&& targetTemp->index == rhs->asTemp()->index) { // Y = X / Y -> Tmp = Y; Y = X / Tmp
- as->moveDouble(as->toDoubleRegister(rhs, Assembler::FPGpr1), Assembler::FPGpr1);
- as->divDouble(as->toDoubleRegister(lhs, Assembler::FPGpr0), Assembler::FPGpr1, targetReg);
+ as->moveDouble(as->toDoubleRegister(rhs, JITAssembler::FPGpr1), JITAssembler::FPGpr1);
+ as->divDouble(as->toDoubleRegister(lhs, JITAssembler::FPGpr0), JITAssembler::FPGpr1, targetReg);
break;
}
- as->divDouble(as->toDoubleRegister(lhs, Assembler::FPGpr0), as->toDoubleRegister(rhs, Assembler::FPGpr1), targetReg);
+ as->divDouble(as->toDoubleRegister(lhs, JITAssembler::FPGpr0), as->toDoubleRegister(rhs, JITAssembler::FPGpr1), targetReg);
break;
default: {
- Q_ASSERT(target->type == IR::BoolType);
- Assembler::Jump trueCase = as->branchDouble(false, op, lhs, rhs);
+ Jump trueCase = as->branchDouble(false, op, lhs, rhs);
as->storeBool(false, target);
- Assembler::Jump done = as->jump();
+ Jump done = as->jump();
trueCase.link(as);
as->storeBool(true, target);
done.link(as);
@@ -271,8 +344,8 @@ void Binop::doubleBinop(IR::Expr *lhs, IR::Expr *rhs, IR::Expr *target)
as->storeDouble(targetReg, target);
}
-
-bool Binop::int32Binop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target)
+template <typename JITAssembler>
+bool Binop<JITAssembler>::int32Binop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target)
{
Q_ASSERT(leftSource->type == IR::SInt32Type);
Q_ASSERT(rightSource->type == IR::SInt32Type);
@@ -305,13 +378,13 @@ bool Binop::int32Binop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *ta
bool inplaceOpWithAddress = false;
IR::Temp *targetTemp = target->asTemp();
- Assembler::RegisterID targetReg = Assembler::ReturnValueRegister;
+ RegisterID targetReg = JITAssembler::ReturnValueRegister;
if (targetTemp && targetTemp->kind == IR::Temp::PhysicalRegister) {
IR::Temp *rhs = rightSource->asTemp();
if (!rhs || rhs->kind != IR::Temp::PhysicalRegister || rhs->index != targetTemp->index) {
// We try to load leftSource into the target's register, but we can't do that if
// the target register is the same as rightSource.
- targetReg = (Assembler::RegisterID) targetTemp->index;
+ targetReg = (RegisterID) targetTemp->index;
} else if (rhs && rhs->kind == IR::Temp::PhysicalRegister && targetTemp->index == rhs->index) {
// However, if the target register is the same as the rightSource register, we can flip
// the operands for certain operations.
@@ -323,7 +396,7 @@ bool Binop::int32Binop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *ta
case IR::OpMul:
// X = Y op X -> X = X op Y (or rephrased: X op= Y (so an in-place operation))
std::swap(leftSource, rightSource);
- targetReg = (Assembler::RegisterID) targetTemp->index;
+ targetReg = (RegisterID) targetTemp->index;
break;
case IR::OpLShift:
@@ -368,13 +441,13 @@ bool Binop::int32Binop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *ta
&& targetTemp->kind == IR::Temp::PhysicalRegister
&& targetTemp->index == rightSource->asTemp()->index) {
// X = Y - X -> Tmp = X; X = Y; X -= Tmp
- targetReg = (Assembler::RegisterID) targetTemp->index;
- as->move(targetReg, Assembler::ScratchRegister);
+ targetReg = (RegisterID) targetTemp->index;
+ as->move(targetReg, JITAssembler::ScratchRegister);
as->move(as->toInt32Register(leftSource, targetReg), targetReg);
- as->sub32(Assembler::ScratchRegister, targetReg);
+ as->sub32(JITAssembler::ScratchRegister, targetReg);
} else {
as->move(as->toInt32Register(leftSource, targetReg), targetReg);
- as->sub32(as->toInt32Register(rightSource, Assembler::ScratchRegister), targetReg);
+ as->sub32(as->toInt32Register(rightSource, JITAssembler::ScratchRegister), targetReg);
}
as->storeInt32(targetReg, target);
return true;
@@ -384,7 +457,7 @@ bool Binop::int32Binop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *ta
case IR::OpURShift:
if (IR::Const *c = rightSource->asConst()) {
if ((QV4::Primitive::toUInt32(c->value) & 0x1f) == 0) {
- Assembler::RegisterID r = as->toInt32Register(leftSource, targetReg);
+ RegisterID r = as->toInt32Register(leftSource, targetReg);
as->storeInt32(r, target);
return true;
}
@@ -395,10 +468,10 @@ bool Binop::int32Binop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *ta
break;
}
- Assembler::RegisterID l = as->toInt32Register(leftSource, targetReg);
+ RegisterID l = as->toInt32Register(leftSource, targetReg);
if (IR::Const *c = rightSource->asConst()) { // All cases of Y = X op Const
- Assembler::TrustedImm32 r(int(c->value));
- Assembler::TrustedImm32 ur(QV4::Primitive::toUInt32(c->value) & 0x1f);
+ TrustedImm32 r(int(c->value));
+ TrustedImm32 ur(QV4::Primitive::toUInt32(c->value) & 0x1f);
switch (op) {
case IR::OpBitAnd: as->and32(r, l, targetReg); break;
@@ -419,7 +492,7 @@ bool Binop::int32Binop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *ta
return false;
}
} else if (inplaceOpWithAddress) { // All cases of X = X op [address-of-Y]
- Assembler::Pointer rhsAddr = as->loadAddress(Assembler::ScratchRegister, rightSource);
+ Pointer rhsAddr = as->loadAddress(JITAssembler::ScratchRegister, rightSource);
switch (op) {
case IR::OpBitAnd: as->and32(rhsAddr, targetReg); break;
case IR::OpBitOr: as->or32 (rhsAddr, targetReg); break;
@@ -433,7 +506,7 @@ bool Binop::int32Binop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *ta
return false;
}
} else { // All cases of Z = X op Y
- Assembler::RegisterID r = as->toInt32Register(rightSource, Assembler::ScratchRegister);
+ RegisterID r = as->toInt32Register(rightSource, JITAssembler::ScratchRegister);
switch (op) {
case IR::OpBitAnd: as->and32(l, r, targetReg); break;
case IR::OpBitOr: as->or32 (l, r, targetReg); break;
@@ -452,18 +525,18 @@ bool Binop::int32Binop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *ta
// Not all CPUs accept shifts over more than 31 bits, and some CPUs (like ARM) will do
// surprising stuff when shifting over 0 bits.
#define CHECK_RHS(op) { \
- as->and32(Assembler::TrustedImm32(0x1f), r, Assembler::ScratchRegister); \
- Assembler::Jump notZero = as->branch32(Assembler::NotEqual, Assembler::ScratchRegister, Assembler::TrustedImm32(0)); \
+ as->and32(TrustedImm32(0x1f), r, JITAssembler::ScratchRegister); \
+ Jump notZero = as->branch32(RelationalCondition::NotEqual, JITAssembler::ScratchRegister, TrustedImm32(0)); \
as->move(l, targetReg); \
- Assembler::Jump done = as->jump(); \
+ Jump done = as->jump(); \
notZero.link(as); \
op; \
done.link(as); \
}
- case IR::OpLShift: CHECK_RHS(as->lshift32(l, Assembler::ScratchRegister, targetReg)); break;
- case IR::OpRShift: CHECK_RHS(as->rshift32(l, Assembler::ScratchRegister, targetReg)); break;
+ case IR::OpLShift: CHECK_RHS(as->lshift32(l, JITAssembler::ScratchRegister, targetReg)); break;
+ case IR::OpRShift: CHECK_RHS(as->rshift32(l, JITAssembler::ScratchRegister, targetReg)); break;
case IR::OpURShift:
- CHECK_RHS(as->urshift32(l, Assembler::ScratchRegister, targetReg));
+ CHECK_RHS(as->urshift32(l, JITAssembler::ScratchRegister, targetReg));
as->storeUInt32(targetReg, target);
// IMPORTANT: do NOT do a break here! The stored type of an urshift is different from the other binary operations!
return true;
@@ -481,19 +554,21 @@ bool Binop::int32Binop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *ta
return true;
}
-static inline Assembler::FPRegisterID getFreeFPReg(IR::Expr *shouldNotOverlap, unsigned hint)
+template <typename JITAssembler>
+inline typename JITAssembler::FPRegisterID getFreeFPReg(IR::Expr *shouldNotOverlap, unsigned hint)
{
if (IR::Temp *t = shouldNotOverlap->asTemp())
if (t->type == IR::DoubleType)
if (t->kind == IR::Temp::PhysicalRegister)
if (t->index == hint)
- return Assembler::FPRegisterID(hint + 1);
- return Assembler::FPRegisterID(hint);
+ return typename JITAssembler::FPRegisterID(hint + 1);
+ return typename JITAssembler::FPRegisterID(hint);
}
-Assembler::Jump Binop::genInlineBinop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target)
+template <typename JITAssembler>
+typename JITAssembler::Jump Binop<JITAssembler>::genInlineBinop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target)
{
- Assembler::Jump done;
+ Jump done;
// Try preventing a call for a few common binary operations. This is used in two cases:
// - no register allocation was performed (not available for the platform, or the IR was
@@ -505,10 +580,10 @@ Assembler::Jump Binop::genInlineBinop(IR::Expr *leftSource, IR::Expr *rightSourc
// register.
switch (op) {
case IR::OpAdd: {
- Assembler::FPRegisterID lReg = getFreeFPReg(rightSource, 2);
- Assembler::FPRegisterID rReg = getFreeFPReg(leftSource, 4);
- Assembler::Jump leftIsNoDbl = as->genTryDoubleConversion(leftSource, lReg);
- Assembler::Jump rightIsNoDbl = as->genTryDoubleConversion(rightSource, rReg);
+ FPRegisterID lReg = getFreeFPReg<JITAssembler>(rightSource, 2);
+ FPRegisterID rReg = getFreeFPReg<JITAssembler>(leftSource, 4);
+ Jump leftIsNoDbl = as->genTryDoubleConversion(leftSource, lReg);
+ Jump rightIsNoDbl = as->genTryDoubleConversion(rightSource, rReg);
as->addDouble(rReg, lReg);
as->storeDouble(lReg, target);
@@ -520,10 +595,10 @@ Assembler::Jump Binop::genInlineBinop(IR::Expr *leftSource, IR::Expr *rightSourc
rightIsNoDbl.link(as);
} break;
case IR::OpMul: {
- Assembler::FPRegisterID lReg = getFreeFPReg(rightSource, 2);
- Assembler::FPRegisterID rReg = getFreeFPReg(leftSource, 4);
- Assembler::Jump leftIsNoDbl = as->genTryDoubleConversion(leftSource, lReg);
- Assembler::Jump rightIsNoDbl = as->genTryDoubleConversion(rightSource, rReg);
+ FPRegisterID lReg = getFreeFPReg<JITAssembler>(rightSource, 2);
+ FPRegisterID rReg = getFreeFPReg<JITAssembler>(leftSource, 4);
+ Jump leftIsNoDbl = as->genTryDoubleConversion(leftSource, lReg);
+ Jump rightIsNoDbl = as->genTryDoubleConversion(rightSource, rReg);
as->mulDouble(rReg, lReg);
as->storeDouble(lReg, target);
@@ -535,10 +610,10 @@ Assembler::Jump Binop::genInlineBinop(IR::Expr *leftSource, IR::Expr *rightSourc
rightIsNoDbl.link(as);
} break;
case IR::OpSub: {
- Assembler::FPRegisterID lReg = getFreeFPReg(rightSource, 2);
- Assembler::FPRegisterID rReg = getFreeFPReg(leftSource, 4);
- Assembler::Jump leftIsNoDbl = as->genTryDoubleConversion(leftSource, lReg);
- Assembler::Jump rightIsNoDbl = as->genTryDoubleConversion(rightSource, rReg);
+ FPRegisterID lReg = getFreeFPReg<JITAssembler>(rightSource, 2);
+ FPRegisterID rReg = getFreeFPReg<JITAssembler>(leftSource, 4);
+ Jump leftIsNoDbl = as->genTryDoubleConversion(leftSource, lReg);
+ Jump rightIsNoDbl = as->genTryDoubleConversion(rightSource, rReg);
as->subDouble(rReg, lReg);
as->storeDouble(lReg, target);
@@ -550,10 +625,10 @@ Assembler::Jump Binop::genInlineBinop(IR::Expr *leftSource, IR::Expr *rightSourc
rightIsNoDbl.link(as);
} break;
case IR::OpDiv: {
- Assembler::FPRegisterID lReg = getFreeFPReg(rightSource, 2);
- Assembler::FPRegisterID rReg = getFreeFPReg(leftSource, 4);
- Assembler::Jump leftIsNoDbl = as->genTryDoubleConversion(leftSource, lReg);
- Assembler::Jump rightIsNoDbl = as->genTryDoubleConversion(rightSource, rReg);
+ FPRegisterID lReg = getFreeFPReg<JITAssembler>(rightSource, 2);
+ FPRegisterID rReg = getFreeFPReg<JITAssembler>(leftSource, 4);
+ Jump leftIsNoDbl = as->genTryDoubleConversion(leftSource, lReg);
+ Jump rightIsNoDbl = as->genTryDoubleConversion(rightSource, rReg);
as->divDouble(rReg, lReg);
as->storeDouble(lReg, target);
@@ -571,4 +646,20 @@ Assembler::Jump Binop::genInlineBinop(IR::Expr *leftSource, IR::Expr *rightSourc
return done;
}
+template struct QV4::JIT::Binop<QV4::JIT::Assembler<DefaultAssemblerTargetConfiguration>>;
+#if defined(V4_BOOTSTRAP)
+#if !CPU(ARM_THUMB2)
+template struct QV4::JIT::Binop<QV4::JIT::Assembler<AssemblerTargetConfiguration<JSC::MacroAssemblerARMv7, NoOperatingSystemSpecialization>>>;
+#endif
+#if !CPU(ARM64)
+template struct QV4::JIT::Binop<QV4::JIT::Assembler<AssemblerTargetConfiguration<JSC::MacroAssemblerARM64, NoOperatingSystemSpecialization>>>;
+#endif
+#endif
+
+} // end of namespace JIT
+} // end of namespace QV4
+
+QT_END_NAMESPACE
+
+
#endif
diff --git a/src/qml/jit/qv4binop_p.h b/src/qml/jit/qv4binop_p.h
index 37601f54ba..d2d9ba7753 100644
--- a/src/qml/jit/qv4binop_p.h
+++ b/src/qml/jit/qv4binop_p.h
@@ -61,19 +61,30 @@ QT_BEGIN_NAMESPACE
namespace QV4 {
namespace JIT {
+template <typename JITAssembler>
struct Binop {
- Binop(Assembler *assembler, IR::AluOp operation)
+ Binop(JITAssembler *assembler, IR::AluOp operation)
: as(assembler)
, op(operation)
{}
+ using Jump = typename JITAssembler::Jump;
+ using Address = typename JITAssembler::Address;
+ using RegisterID = typename JITAssembler::RegisterID;
+ using FPRegisterID = typename JITAssembler::FPRegisterID;
+ using TrustedImm32 = typename JITAssembler::TrustedImm32;
+ using ResultCondition = typename JITAssembler::ResultCondition;
+ using RelationalCondition = typename JITAssembler::RelationalCondition;
+ using Pointer = typename JITAssembler::Pointer;
+ using PointerToValue = typename JITAssembler::PointerToValue;
+
void generate(IR::Expr *lhs, IR::Expr *rhs, IR::Expr *target);
void doubleBinop(IR::Expr *lhs, IR::Expr *rhs, IR::Expr *target);
bool int32Binop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target);
- Assembler::Jump genInlineBinop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target);
+ Jump genInlineBinop(IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target);
- typedef Assembler::Jump (Binop::*MemRegOp)(Assembler::Address, Assembler::RegisterID);
- typedef Assembler::Jump (Binop::*ImmRegOp)(Assembler::TrustedImm32, Assembler::RegisterID);
+ typedef Jump (Binop::*MemRegOp)(Address, RegisterID);
+ typedef Jump (Binop::*ImmRegOp)(TrustedImm32, RegisterID);
struct OpInfo {
const char *name;
@@ -88,150 +99,150 @@ struct Binop {
static const OpInfo &operation(IR::AluOp operation)
{ return operations[operation]; }
- Assembler::Jump inline_add32(Assembler::Address addr, Assembler::RegisterID reg)
+ Jump inline_add32(Address addr, RegisterID reg)
{
#if HAVE(ALU_OPS_WITH_MEM_OPERAND)
- return as->branchAdd32(Assembler::Overflow, addr, reg);
+ return as->branchAdd32(ResultCondition::Overflow, addr, reg);
#else
- as->load32(addr, Assembler::ScratchRegister);
- return as->branchAdd32(Assembler::Overflow, Assembler::ScratchRegister, reg);
+ as->load32(addr, JITAssembler::ScratchRegister);
+ return as->branchAdd32(ResultCondition::Overflow, JITAssembler::ScratchRegister, reg);
#endif
}
- Assembler::Jump inline_add32(Assembler::TrustedImm32 imm, Assembler::RegisterID reg)
+ Jump inline_add32(TrustedImm32 imm, RegisterID reg)
{
- return as->branchAdd32(Assembler::Overflow, imm, reg);
+ return as->branchAdd32(ResultCondition::Overflow, imm, reg);
}
- Assembler::Jump inline_sub32(Assembler::Address addr, Assembler::RegisterID reg)
+ Jump inline_sub32(Address addr, RegisterID reg)
{
#if HAVE(ALU_OPS_WITH_MEM_OPERAND)
- return as->branchSub32(Assembler::Overflow, addr, reg);
+ return as->branchSub32(ResultCondition::Overflow, addr, reg);
#else
- as->load32(addr, Assembler::ScratchRegister);
- return as->branchSub32(Assembler::Overflow, Assembler::ScratchRegister, reg);
+ as->load32(addr, JITAssembler::ScratchRegister);
+ return as->branchSub32(ResultCondition::Overflow, JITAssembler::ScratchRegister, reg);
#endif
}
- Assembler::Jump inline_sub32(Assembler::TrustedImm32 imm, Assembler::RegisterID reg)
+ Jump inline_sub32(TrustedImm32 imm, RegisterID reg)
{
- return as->branchSub32(Assembler::Overflow, imm, reg);
+ return as->branchSub32(ResultCondition::Overflow, imm, reg);
}
- Assembler::Jump inline_mul32(Assembler::Address addr, Assembler::RegisterID reg)
+ Jump inline_mul32(Address addr, RegisterID reg)
{
#if HAVE(ALU_OPS_WITH_MEM_OPERAND)
- return as->branchMul32(Assembler::Overflow, addr, reg);
+ return as->branchMul32(JITAssembler::Overflow, addr, reg);
#else
- as->load32(addr, Assembler::ScratchRegister);
- return as->branchMul32(Assembler::Overflow, Assembler::ScratchRegister, reg);
+ as->load32(addr, JITAssembler::ScratchRegister);
+ return as->branchMul32(ResultCondition::Overflow, JITAssembler::ScratchRegister, reg);
#endif
}
- Assembler::Jump inline_mul32(Assembler::TrustedImm32 imm, Assembler::RegisterID reg)
+ Jump inline_mul32(TrustedImm32 imm, RegisterID reg)
{
- return as->branchMul32(Assembler::Overflow, imm, reg, reg);
+ return as->branchMul32(ResultCondition::Overflow, imm, reg, reg);
}
- Assembler::Jump inline_shl32(Assembler::Address addr, Assembler::RegisterID reg)
+ Jump inline_shl32(Address addr, RegisterID reg)
{
- as->load32(addr, Assembler::ScratchRegister);
- as->and32(Assembler::TrustedImm32(0x1f), Assembler::ScratchRegister);
- as->lshift32(Assembler::ScratchRegister, reg);
- return Assembler::Jump();
+ as->load32(addr, JITAssembler::ScratchRegister);
+ as->and32(TrustedImm32(0x1f), JITAssembler::ScratchRegister);
+ as->lshift32(JITAssembler::ScratchRegister, reg);
+ return Jump();
}
- Assembler::Jump inline_shl32(Assembler::TrustedImm32 imm, Assembler::RegisterID reg)
+ Jump inline_shl32(TrustedImm32 imm, RegisterID reg)
{
imm.m_value &= 0x1f;
as->lshift32(imm, reg);
- return Assembler::Jump();
+ return Jump();
}
- Assembler::Jump inline_shr32(Assembler::Address addr, Assembler::RegisterID reg)
+ Jump inline_shr32(Address addr, RegisterID reg)
{
- as->load32(addr, Assembler::ScratchRegister);
- as->and32(Assembler::TrustedImm32(0x1f), Assembler::ScratchRegister);
- as->rshift32(Assembler::ScratchRegister, reg);
- return Assembler::Jump();
+ as->load32(addr, JITAssembler::ScratchRegister);
+ as->and32(TrustedImm32(0x1f), JITAssembler::ScratchRegister);
+ as->rshift32(JITAssembler::ScratchRegister, reg);
+ return Jump();
}
- Assembler::Jump inline_shr32(Assembler::TrustedImm32 imm, Assembler::RegisterID reg)
+ Jump inline_shr32(TrustedImm32 imm, RegisterID reg)
{
imm.m_value &= 0x1f;
as->rshift32(imm, reg);
- return Assembler::Jump();
+ return Jump();
}
- Assembler::Jump inline_ushr32(Assembler::Address addr, Assembler::RegisterID reg)
+ Jump inline_ushr32(Address addr, RegisterID reg)
{
- as->load32(addr, Assembler::ScratchRegister);
- as->and32(Assembler::TrustedImm32(0x1f), Assembler::ScratchRegister);
- as->urshift32(Assembler::ScratchRegister, reg);
- return as->branchTest32(Assembler::Signed, reg, reg);
+ as->load32(addr, JITAssembler::ScratchRegister);
+ as->and32(TrustedImm32(0x1f), JITAssembler::ScratchRegister);
+ as->urshift32(JITAssembler::ScratchRegister, reg);
+ return as->branchTest32(ResultCondition::Signed, reg, reg);
}
- Assembler::Jump inline_ushr32(Assembler::TrustedImm32 imm, Assembler::RegisterID reg)
+ Jump inline_ushr32(TrustedImm32 imm, RegisterID reg)
{
imm.m_value &= 0x1f;
as->urshift32(imm, reg);
- return as->branchTest32(Assembler::Signed, reg, reg);
+ return as->branchTest32(ResultCondition::Signed, reg, reg);
}
- Assembler::Jump inline_and32(Assembler::Address addr, Assembler::RegisterID reg)
+ Jump inline_and32(Address addr, RegisterID reg)
{
#if HAVE(ALU_OPS_WITH_MEM_OPERAND)
as->and32(addr, reg);
#else
- as->load32(addr, Assembler::ScratchRegister);
- as->and32(Assembler::ScratchRegister, reg);
+ as->load32(addr, JITAssembler::ScratchRegister);
+ as->and32(JITAssembler::ScratchRegister, reg);
#endif
- return Assembler::Jump();
+ return Jump();
}
- Assembler::Jump inline_and32(Assembler::TrustedImm32 imm, Assembler::RegisterID reg)
+ Jump inline_and32(TrustedImm32 imm, RegisterID reg)
{
as->and32(imm, reg);
- return Assembler::Jump();
+ return Jump();
}
- Assembler::Jump inline_or32(Assembler::Address addr, Assembler::RegisterID reg)
+ Jump inline_or32(Address addr, RegisterID reg)
{
#if HAVE(ALU_OPS_WITH_MEM_OPERAND)
as->or32(addr, reg);
#else
- as->load32(addr, Assembler::ScratchRegister);
- as->or32(Assembler::ScratchRegister, reg);
+ as->load32(addr, JITAssembler::ScratchRegister);
+ as->or32(JITAssembler::ScratchRegister, reg);
#endif
- return Assembler::Jump();
+ return Jump();
}
- Assembler::Jump inline_or32(Assembler::TrustedImm32 imm, Assembler::RegisterID reg)
+ Jump inline_or32(TrustedImm32 imm, RegisterID reg)
{
as->or32(imm, reg);
- return Assembler::Jump();
+ return Jump();
}
- Assembler::Jump inline_xor32(Assembler::Address addr, Assembler::RegisterID reg)
+ Jump inline_xor32(Address addr, RegisterID reg)
{
#if HAVE(ALU_OPS_WITH_MEM_OPERAND)
as->xor32(addr, reg);
#else
- as->load32(addr, Assembler::ScratchRegister);
- as->xor32(Assembler::ScratchRegister, reg);
+ as->load32(addr, JITAssembler::ScratchRegister);
+ as->xor32(JITAssembler::ScratchRegister, reg);
#endif
- return Assembler::Jump();
+ return Jump();
}
- Assembler::Jump inline_xor32(Assembler::TrustedImm32 imm, Assembler::RegisterID reg)
+ Jump inline_xor32(TrustedImm32 imm, RegisterID reg)
{
as->xor32(imm, reg);
- return Assembler::Jump();
+ return Jump();
}
- Assembler *as;
+ JITAssembler *as;
IR::AluOp op;
};
diff --git a/src/qml/jit/qv4isel_masm.cpp b/src/qml/jit/qv4isel_masm.cpp
index 6b8264d801..69d6951bb9 100644
--- a/src/qml/jit/qv4isel_masm.cpp
+++ b/src/qml/jit/qv4isel_masm.cpp
@@ -39,11 +39,7 @@
#include "qv4isel_masm_p.h"
#include "qv4runtime_p.h"
-#include "qv4object_p.h"
-#include "qv4functionobject_p.h"
-#include "qv4regexpobject_p.h"
#include "qv4lookup_p.h"
-#include "qv4function_p.h"
#include "qv4ssa_p.h"
#include "qv4regalloc_p.h"
#include "qv4assembler_p.h"
@@ -68,183 +64,8 @@ using namespace QV4;
using namespace QV4::JIT;
-namespace {
-class QIODevicePrintStream: public FilePrintStream
-{
- Q_DISABLE_COPY(QIODevicePrintStream)
-
-public:
- explicit QIODevicePrintStream(QIODevice *dest)
- : FilePrintStream(0)
- , dest(dest)
- , buf(4096, '0')
- {
- Q_ASSERT(dest);
- }
-
- ~QIODevicePrintStream()
- {}
-
- void vprintf(const char* format, va_list argList) WTF_ATTRIBUTE_PRINTF(2, 0)
- {
- const int written = qvsnprintf(buf.data(), buf.size(), format, argList);
- if (written > 0)
- dest->write(buf.constData(), written);
- memset(buf.data(), 0, qMin(written, buf.size()));
- }
-
- void flush()
- {}
-
-private:
- QIODevice *dest;
- QByteArray buf;
-};
-} // anonymous namespace
-
-static void printDisassembledOutputWithCalls(QByteArray processedOutput, const QHash<void*, const char*>& functions)
-{
- for (QHash<void*, const char*>::ConstIterator it = functions.begin(), end = functions.end();
- it != end; ++it) {
- QByteArray ptrString = QByteArray::number(quintptr(it.key()), 16);
- ptrString.prepend("0x");
- int idx = processedOutput.indexOf(ptrString);
- if (idx < 0)
- continue;
- idx = processedOutput.lastIndexOf('\n', idx);
- if (idx < 0)
- continue;
- processedOutput = processedOutput.insert(idx, QByteArrayLiteral(" ; call ") + it.value());
- }
-
- qDebug("%s", processedOutput.constData());
-}
-
-#if defined(Q_OS_LINUX)
-static FILE *pmap;
-
-static void qt_closePmap()
-{
- if (pmap) {
- fclose(pmap);
- pmap = 0;
- }
-}
-
-#endif
-
-JSC::MacroAssemblerCodeRef Assembler::link(int *codeSize)
-{
- Label endOfCode = label();
-
- {
- for (size_t i = 0, ei = _patches.size(); i != ei; ++i) {
- Label target = _addrs.at(i);
- Q_ASSERT(target.isSet());
- for (Jump jump : qAsConst(_patches.at(i)))
- jump.linkTo(target, this);
- }
- }
-
- JSC::JSGlobalData dummy(_executableAllocator);
- JSC::LinkBuffer linkBuffer(dummy, this, 0);
-
- for (const DataLabelPatch &p : qAsConst(_dataLabelPatches))
- linkBuffer.patch(p.dataLabel, linkBuffer.locationOf(p.target));
-
- // link exception handlers
- for (Jump jump : qAsConst(exceptionPropagationJumps))
- linkBuffer.link(jump, linkBuffer.locationOf(exceptionReturnLabel));
-
- {
- for (size_t i = 0, ei = _labelPatches.size(); i != ei; ++i) {
- Label target = _addrs.at(i);
- Q_ASSERT(target.isSet());
- for (DataLabelPtr label : _labelPatches.at(i))
- linkBuffer.patch(label, linkBuffer.locationOf(target));
- }
- }
-
- *codeSize = linkBuffer.offsetOf(endOfCode);
-
- QByteArray name;
-
- JSC::MacroAssemblerCodeRef codeRef;
-
- static const bool showCode = qEnvironmentVariableIsSet("QV4_SHOW_ASM");
- if (showCode) {
- QHash<void*, const char*> functions;
-#ifndef QT_NO_DEBUG
- for (CallInfo call : qAsConst(_callInfos))
- functions[linkBuffer.locationOf(call.label).dataLocation()] = call.functionName;
-#endif
-
- QBuffer buf;
- buf.open(QIODevice::WriteOnly);
- WTF::setDataFile(new QIODevicePrintStream(&buf));
-
- name = _function->name->toUtf8();
- if (name.isEmpty()) {
- name = QByteArray::number(quintptr(_function), 16);
- name.prepend("IR::Function(0x");
- name.append(')');
- }
- codeRef = linkBuffer.finalizeCodeWithDisassembly("%s", name.data());
-
- WTF::setDataFile(stderr);
- printDisassembledOutputWithCalls(buf.data(), functions);
- } else {
- codeRef = linkBuffer.finalizeCodeWithoutDisassembly();
- }
-
-#if defined(Q_OS_LINUX)
- // This implements writing of JIT'd addresses so that perf can find the
- // symbol names.
- //
- // Perf expects the mapping to be in a certain place and have certain
- // content, for more information, see:
- // https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt
- static bool doProfile = !qEnvironmentVariableIsEmpty("QV4_PROFILE_WRITE_PERF_MAP");
- static bool profileInitialized = false;
- if (doProfile && !profileInitialized) {
- profileInitialized = true;
-
- char pname[PATH_MAX];
- snprintf(pname, PATH_MAX - 1, "/tmp/perf-%lu.map",
- (unsigned long)QCoreApplication::applicationPid());
-
- pmap = fopen(pname, "w");
- if (!pmap)
- qWarning("QV4: Can't write %s, call stacks will not contain JavaScript function names", pname);
-
- // make sure we clean up nicely
- std::atexit(qt_closePmap);
- }
-
- if (pmap) {
- // this may have been pre-populated, if QV4_SHOW_ASM was on
- if (name.isEmpty()) {
- name = _function->name->toUtf8();
- if (name.isEmpty()) {
- name = QByteArray::number(quintptr(_function), 16);
- name.prepend("IR::Function(0x");
- name.append(')');
- }
- }
-
- fprintf(pmap, "%llx %x %.*s\n",
- (long long unsigned int)codeRef.code().executableAddress(),
- *codeSize,
- name.length(),
- name.constData());
- fflush(pmap);
- }
-#endif
-
- return codeRef;
-}
-
-InstructionSelection::InstructionSelection(QQmlEnginePrivate *qmlEngine, QV4::ExecutableAllocator *execAllocator, IR::Module *module, Compiler::JSUnitGenerator *jsGenerator, EvalISelFactory *iselFactory)
+template <typename JITAssembler>
+InstructionSelection<JITAssembler>::InstructionSelection(QQmlEnginePrivate *qmlEngine, QV4::ExecutableAllocator *execAllocator, IR::Module *module, Compiler::JSUnitGenerator *jsGenerator, EvalISelFactory *iselFactory)
: EvalInstructionSelection(execAllocator, module, jsGenerator, iselFactory)
, _block(0)
, _as(0)
@@ -255,12 +76,14 @@ InstructionSelection::InstructionSelection(QQmlEnginePrivate *qmlEngine, QV4::Ex
module->unitFlags |= QV4::CompiledData::Unit::ContainsMachineCode;
}
-InstructionSelection::~InstructionSelection()
+template <typename JITAssembler>
+InstructionSelection<JITAssembler>::~InstructionSelection()
{
delete _as;
}
-void InstructionSelection::run(int functionIndex)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::run(int functionIndex)
{
IR::Function *function = irModule->functions[functionIndex];
qSwap(_function, function);
@@ -269,8 +92,8 @@ void InstructionSelection::run(int functionIndex)
opt.run(qmlEngine);
static const bool withRegisterAllocator = qEnvironmentVariableIsEmpty("QV4_NO_REGALLOC");
- if (Assembler::RegAllocIsSupported && opt.isInSSA() && withRegisterAllocator) {
- RegisterAllocator regalloc(Assembler::getRegisterInfo());
+ if (JITTargetPlatform::RegAllocIsSupported && opt.isInSSA() && withRegisterAllocator) {
+ RegisterAllocator regalloc(JITTargetPlatform::getRegisterInfo());
regalloc.run(_function, opt);
calculateRegistersToSave(regalloc.usedRegisters());
} else {
@@ -279,49 +102,24 @@ void InstructionSelection::run(int functionIndex)
opt.convertOutOfSSA();
ConvertTemps().toStackSlots(_function);
IR::Optimizer::showMeTheCode(_function, "After stack slot allocation");
- calculateRegistersToSave(Assembler::getRegisterInfo()); // FIXME: this saves all registers. We can probably do with a subset: those that are not used by the register allocator.
+ calculateRegistersToSave(JITTargetPlatform::getRegisterInfo()); // FIXME: this saves all registers. We can probably do with a subset: those that are not used by the register allocator.
}
- QSet<IR::Jump *> removableJumps = opt.calculateOptionalJumps();
+ BitVector removableJumps = opt.calculateOptionalJumps();
qSwap(_removableJumps, removableJumps);
- Assembler* oldAssembler = _as;
- _as = new Assembler(this, _function, executableAllocator);
+ JITAssembler* oldAssembler = _as;
+ _as = new JITAssembler(jsGenerator, _function, executableAllocator);
_as->setStackLayout(6, // 6 == max argc for calls to built-ins with an argument array
regularRegistersToSave.size(),
fpRegistersToSave.size());
_as->enterStandardStackFrame(regularRegistersToSave, fpRegistersToSave);
-#ifdef ARGUMENTS_IN_REGISTERS
- _as->move(_as->registerForArgument(0), Assembler::EngineRegister);
-#else
- _as->loadPtr(addressForArgument(0), Assembler::EngineRegister);
-#endif
-
- const int locals = _as->stackLayout().calculateJSStackFrameSize();
- if (locals > 0) {
- _as->loadPtr(Address(Assembler::EngineRegister, qOffsetOf(ExecutionEngine, jsStackTop)), Assembler::LocalsRegister);
-#ifdef VALUE_FITS_IN_REGISTER
- _as->move(Assembler::TrustedImm64(0), Assembler::ReturnValueRegister);
- _as->move(Assembler::TrustedImm32(locals), Assembler::ScratchRegister);
- Assembler::Label loop = _as->label();
- _as->store64(Assembler::ReturnValueRegister, Assembler::Address(Assembler::LocalsRegister));
- _as->add64(Assembler::TrustedImm32(8), Assembler::LocalsRegister);
- Assembler::Jump jump = _as->branchSub32(Assembler::NonZero, Assembler::TrustedImm32(1), Assembler::ScratchRegister);
- jump.linkTo(loop, _as);
-#else
- _as->move(Assembler::TrustedImm32(0), Assembler::ReturnValueRegister);
- _as->move(Assembler::TrustedImm32(locals), Assembler::ScratchRegister);
- Assembler::Label loop = _as->label();
- _as->store32(Assembler::ReturnValueRegister, Assembler::Address(Assembler::LocalsRegister));
- _as->add32(Assembler::TrustedImm32(4), Assembler::LocalsRegister);
- _as->store32(Assembler::ReturnValueRegister, Assembler::Address(Assembler::LocalsRegister));
- _as->add32(Assembler::TrustedImm32(4), Assembler::LocalsRegister);
- Assembler::Jump jump = _as->branchSub32(Assembler::NonZero, Assembler::TrustedImm32(1), Assembler::ScratchRegister);
- jump.linkTo(loop, _as);
-#endif
- _as->storePtr(Assembler::LocalsRegister, Address(Assembler::EngineRegister, qOffsetOf(ExecutionEngine, jsStackTop)));
- }
+ if (JITTargetPlatform::RegisterArgumentCount > 0)
+ _as->move(_as->registerForArgument(0), JITTargetPlatform::EngineRegister);
+ else
+ _as->loadPtr(addressForArgument(0), JITTargetPlatform::EngineRegister);
+ _as->initializeLocalVariables();
int lastLine = 0;
for (int i = 0, ei = _function->basicBlockCount(); i != ei; ++i) {
@@ -334,9 +132,9 @@ void InstructionSelection::run(int functionIndex)
for (IR::Stmt *s : _block->statements()) {
if (s->location.isValid()) {
if (int(s->location.startLine) != lastLine) {
- _as->loadPtr(Address(Assembler::EngineRegister, qOffsetOf(QV4::ExecutionEngine, current)), Assembler::ScratchRegister);
- Assembler::Address lineAddr(Assembler::ScratchRegister, qOffsetOf(QV4::ExecutionContext::Data, lineNumber));
- _as->store32(Assembler::TrustedImm32(s->location.startLine), lineAddr);
+ _as->loadPtr(Address(JITTargetPlatform::EngineRegister, qOffsetOf(QV4::ExecutionEngine, current)), JITTargetPlatform::ScratchRegister);
+ Address lineAddr(JITTargetPlatform::ScratchRegister, qOffsetOf(QV4::ExecutionContext::Data, lineNumber));
+ _as->store32(TrustedImm32(s->location.startLine), lineAddr);
lastLine = s->location.startLine;
}
}
@@ -357,165 +155,187 @@ void InstructionSelection::run(int functionIndex)
qSwap(_removableJumps, removableJumps);
}
-QQmlRefPointer<QV4::CompiledData::CompilationUnit> InstructionSelection::backendCompileStep()
+template <typename JITAssembler>
+QQmlRefPointer<QV4::CompiledData::CompilationUnit> InstructionSelection<JITAssembler>::backendCompileStep()
{
QQmlRefPointer<QV4::CompiledData::CompilationUnit> result;
result.adopt(compilationUnit.take());
return result;
}
-void InstructionSelection::callBuiltinInvalid(IR::Name *func, IR::ExprList *args, IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinInvalid(IR::Name *func, IR::ExprList *args, IR::Expr *result)
{
prepareCallData(args, 0);
if (useFastLookups && func->global) {
uint index = registerGlobalGetterLookup(*func->id);
- generateRuntimeCall(result, callGlobalLookup,
- Assembler::EngineRegister,
- Assembler::TrustedImm32(index),
+ generateRuntimeCall(_as, result, callGlobalLookup,
+ JITTargetPlatform::EngineRegister,
+ TrustedImm32(index),
baseAddressForCallData());
} else {
- generateRuntimeCall(result, callActivationProperty,
- Assembler::EngineRegister,
- Assembler::StringToIndex(*func->id),
+ generateRuntimeCall(_as, result, callActivationProperty,
+ JITTargetPlatform::EngineRegister,
+ StringToIndex(*func->id),
baseAddressForCallData());
}
}
-void InstructionSelection::callBuiltinTypeofQmlContextProperty(IR::Expr *base,
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinTypeofQmlContextProperty(IR::Expr *base,
IR::Member::MemberKind kind,
int propertyIndex, IR::Expr *result)
{
if (kind == IR::Member::MemberOfQmlScopeObject) {
- generateRuntimeCall(result, typeofScopeObjectProperty, Assembler::EngineRegister,
- Assembler::PointerToValue(base),
- Assembler::TrustedImm32(propertyIndex));
+ generateRuntimeCall(_as, result, typeofScopeObjectProperty, JITTargetPlatform::EngineRegister,
+ PointerToValue(base),
+ TrustedImm32(propertyIndex));
} else if (kind == IR::Member::MemberOfQmlContextObject) {
- generateRuntimeCall(result, typeofContextObjectProperty,
- Assembler::EngineRegister, Assembler::PointerToValue(base),
- Assembler::TrustedImm32(propertyIndex));
+ generateRuntimeCall(_as, result, typeofContextObjectProperty,
+ JITTargetPlatform::EngineRegister, PointerToValue(base),
+ TrustedImm32(propertyIndex));
} else {
Q_UNREACHABLE();
}
}
-void InstructionSelection::callBuiltinTypeofMember(IR::Expr *base, const QString &name,
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinTypeofMember(IR::Expr *base, const QString &name,
IR::Expr *result)
{
- generateRuntimeCall(result, typeofMember, Assembler::EngineRegister,
- Assembler::PointerToValue(base), Assembler::StringToIndex(name));
+ generateRuntimeCall(_as, result, typeofMember, JITTargetPlatform::EngineRegister,
+ PointerToValue(base), StringToIndex(name));
}
-void InstructionSelection::callBuiltinTypeofSubscript(IR::Expr *base, IR::Expr *index,
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinTypeofSubscript(IR::Expr *base, IR::Expr *index,
IR::Expr *result)
{
- generateRuntimeCall(result, typeofElement,
- Assembler::EngineRegister,
- Assembler::PointerToValue(base), Assembler::PointerToValue(index));
+ generateRuntimeCall(_as, result, typeofElement,
+ JITTargetPlatform::EngineRegister,
+ PointerToValue(base), PointerToValue(index));
}
-void InstructionSelection::callBuiltinTypeofName(const QString &name, IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinTypeofName(const QString &name, IR::Expr *result)
{
- generateRuntimeCall(result, typeofName, Assembler::EngineRegister,
- Assembler::StringToIndex(name));
+ generateRuntimeCall(_as, result, typeofName, JITTargetPlatform::EngineRegister,
+ StringToIndex(name));
}
-void InstructionSelection::callBuiltinTypeofValue(IR::Expr *value, IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinTypeofValue(IR::Expr *value, IR::Expr *result)
{
- generateRuntimeCall(result, typeofValue, Assembler::EngineRegister,
- Assembler::PointerToValue(value));
+ generateRuntimeCall(_as, result, typeofValue, JITTargetPlatform::EngineRegister,
+ PointerToValue(value));
}
-void InstructionSelection::callBuiltinDeleteMember(IR::Expr *base, const QString &name, IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinDeleteMember(IR::Expr *base, const QString &name, IR::Expr *result)
{
- generateRuntimeCall(result, deleteMember, Assembler::EngineRegister,
- Assembler::Reference(base), Assembler::StringToIndex(name));
+ generateRuntimeCall(_as, result, deleteMember, JITTargetPlatform::EngineRegister,
+ Reference(base), StringToIndex(name));
}
-void InstructionSelection::callBuiltinDeleteSubscript(IR::Expr *base, IR::Expr *index,
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinDeleteSubscript(IR::Expr *base, IR::Expr *index,
IR::Expr *result)
{
- generateRuntimeCall(result, deleteElement, Assembler::EngineRegister,
- Assembler::Reference(base), Assembler::PointerToValue(index));
+ generateRuntimeCall(_as, result, deleteElement, JITTargetPlatform::EngineRegister,
+ Reference(base), PointerToValue(index));
}
-void InstructionSelection::callBuiltinDeleteName(const QString &name, IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinDeleteName(const QString &name, IR::Expr *result)
{
- generateRuntimeCall(result, deleteName, Assembler::EngineRegister,
- Assembler::StringToIndex(name));
+ generateRuntimeCall(_as, result, deleteName, JITTargetPlatform::EngineRegister,
+ StringToIndex(name));
}
-void InstructionSelection::callBuiltinDeleteValue(IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinDeleteValue(IR::Expr *result)
{
_as->storeValue(Primitive::fromBoolean(false), result);
}
-void InstructionSelection::callBuiltinThrow(IR::Expr *arg)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinThrow(IR::Expr *arg)
{
- generateRuntimeCall(Assembler::ReturnValueRegister, throwException, Assembler::EngineRegister,
- Assembler::PointerToValue(arg));
+ generateRuntimeCall(_as, JITTargetPlatform::ReturnValueRegister, throwException, JITTargetPlatform::EngineRegister,
+ PointerToValue(arg));
}
-void InstructionSelection::callBuiltinReThrow()
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinReThrow()
{
_as->jumpToExceptionHandler();
}
-void InstructionSelection::callBuiltinUnwindException(IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinUnwindException(IR::Expr *result)
{
- generateRuntimeCall(result, unwindException, Assembler::EngineRegister);
+ generateRuntimeCall(_as, result, unwindException, JITTargetPlatform::EngineRegister);
}
-void InstructionSelection::callBuiltinPushCatchScope(const QString &exceptionName)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinPushCatchScope(const QString &exceptionName)
{
- generateRuntimeCall(Assembler::Void, pushCatchScope, Assembler::EngineRegister, Assembler::StringToIndex(exceptionName));
+ generateRuntimeCall(_as, JITAssembler::Void, pushCatchScope, JITTargetPlatform::EngineRegister, StringToIndex(exceptionName));
}
-void InstructionSelection::callBuiltinForeachIteratorObject(IR::Expr *arg, IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinForeachIteratorObject(IR::Expr *arg, IR::Expr *result)
{
Q_ASSERT(arg);
Q_ASSERT(result);
- generateRuntimeCall(result, foreachIterator, Assembler::EngineRegister, Assembler::PointerToValue(arg));
+ generateRuntimeCall(_as, result, foreachIterator, JITTargetPlatform::EngineRegister, PointerToValue(arg));
}
-void InstructionSelection::callBuiltinForeachNextPropertyname(IR::Expr *arg, IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinForeachNextPropertyname(IR::Expr *arg, IR::Expr *result)
{
Q_ASSERT(arg);
Q_ASSERT(result);
- generateRuntimeCall(result, foreachNextPropertyName, Assembler::Reference(arg));
+ generateRuntimeCall(_as, result, foreachNextPropertyName, Reference(arg));
}
-void InstructionSelection::callBuiltinPushWithScope(IR::Expr *arg)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinPushWithScope(IR::Expr *arg)
{
Q_ASSERT(arg);
- generateRuntimeCall(Assembler::Void, pushWithScope, Assembler::Reference(arg), Assembler::EngineRegister);
+ generateRuntimeCall(_as, JITAssembler::Void, pushWithScope, Reference(arg), JITTargetPlatform::EngineRegister);
}
-void InstructionSelection::callBuiltinPopScope()
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinPopScope()
{
- generateRuntimeCall(Assembler::Void, popScope, Assembler::EngineRegister);
+ generateRuntimeCall(_as, JITAssembler::Void, popScope, JITTargetPlatform::EngineRegister);
}
-void InstructionSelection::callBuiltinDeclareVar(bool deletable, const QString &name)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinDeclareVar(bool deletable, const QString &name)
{
- generateRuntimeCall(Assembler::Void, declareVar, Assembler::EngineRegister,
- Assembler::TrustedImm32(deletable), Assembler::StringToIndex(name));
+ generateRuntimeCall(_as, JITAssembler::Void, declareVar, JITTargetPlatform::EngineRegister,
+ TrustedImm32(deletable), StringToIndex(name));
}
-void InstructionSelection::callBuiltinDefineArray(IR::Expr *result, IR::ExprList *args)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinDefineArray(IR::Expr *result, IR::ExprList *args)
{
Q_ASSERT(result);
int length = prepareVariableArguments(args);
- generateRuntimeCall(result, arrayLiteral, Assembler::EngineRegister,
- baseAddressForCallArguments(), Assembler::TrustedImm32(length));
+ generateRuntimeCall(_as, result, arrayLiteral, JITTargetPlatform::EngineRegister,
+ baseAddressForCallArguments(), TrustedImm32(length));
}
-void InstructionSelection::callBuiltinDefineObjectLiteral(IR::Expr *result, int keyValuePairCount, IR::ExprList *keyValuePairs, IR::ExprList *arrayEntries, bool needSparseArray)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinDefineObjectLiteral(IR::Expr *result, int keyValuePairCount, IR::ExprList *keyValuePairs, IR::ExprList *arrayEntries, bool needSparseArray)
{
Q_ASSERT(result);
@@ -591,81 +411,83 @@ void InstructionSelection::callBuiltinDefineObjectLiteral(IR::Expr *result, int
it = it->next;
}
- generateRuntimeCall(result, objectLiteral, Assembler::EngineRegister,
- baseAddressForCallArguments(), Assembler::TrustedImm32(classId),
- Assembler::TrustedImm32(arrayValueCount), Assembler::TrustedImm32(arrayGetterSetterCount | (needSparseArray << 30)));
+ generateRuntimeCall(_as, result, objectLiteral, JITTargetPlatform::EngineRegister,
+ baseAddressForCallArguments(), TrustedImm32(classId),
+ TrustedImm32(arrayValueCount), TrustedImm32(arrayGetterSetterCount | (needSparseArray << 30)));
}
-void InstructionSelection::callBuiltinSetupArgumentObject(IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinSetupArgumentObject(IR::Expr *result)
{
- generateRuntimeCall(result, setupArgumentsObject, Assembler::EngineRegister);
+ generateRuntimeCall(_as, result, setupArgumentsObject, JITTargetPlatform::EngineRegister);
}
-void InstructionSelection::callBuiltinConvertThisToObject()
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callBuiltinConvertThisToObject()
{
- generateRuntimeCall(Assembler::Void, convertThisToObject, Assembler::EngineRegister);
+ generateRuntimeCall(_as, JITAssembler::Void, convertThisToObject, JITTargetPlatform::EngineRegister);
}
-void InstructionSelection::callValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result)
{
Q_ASSERT(value);
prepareCallData(args, 0);
if (value->asConst())
- generateRuntimeCall(result, callValue, Assembler::EngineRegister,
- Assembler::PointerToValue(value),
+ generateRuntimeCall(_as, result, callValue, JITTargetPlatform::EngineRegister,
+ PointerToValue(value),
baseAddressForCallData());
else
- generateRuntimeCall(result, callValue, Assembler::EngineRegister,
- Assembler::Reference(value),
+ generateRuntimeCall(_as, result, callValue, JITTargetPlatform::EngineRegister,
+ Reference(value),
baseAddressForCallData());
}
-void InstructionSelection::loadThisObject(IR::Expr *temp)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::loadThisObject(IR::Expr *temp)
{
- _as->loadPtr(Address(Assembler::EngineRegister, qOffsetOf(QV4::ExecutionEngine, current)), Assembler::ScratchRegister);
- _as->loadPtr(Address(Assembler::ScratchRegister, qOffsetOf(ExecutionContext::Data, callData)), Assembler::ScratchRegister);
-#if defined(VALUE_FITS_IN_REGISTER)
- _as->load64(Pointer(Assembler::ScratchRegister, qOffsetOf(CallData, thisObject)),
- Assembler::ReturnValueRegister);
- _as->storeReturnValue(temp);
-#else
- _as->copyValue(temp, Pointer(Assembler::ScratchRegister, qOffsetOf(CallData, thisObject)));
-#endif
+ _as->loadPtr(Address(JITTargetPlatform::EngineRegister, qOffsetOf(QV4::ExecutionEngine, current)), JITTargetPlatform::ScratchRegister);
+ _as->loadPtr(Address(JITTargetPlatform::ScratchRegister, qOffsetOf(ExecutionContext::Data, callData)), JITTargetPlatform::ScratchRegister);
+ _as->copyValue(temp, Address(JITTargetPlatform::ScratchRegister, qOffsetOf(CallData, thisObject)));
}
-void InstructionSelection::loadQmlContext(IR::Expr *temp)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::loadQmlContext(IR::Expr *temp)
{
- generateRuntimeCall(temp, getQmlContext, Assembler::EngineRegister);
+ generateRuntimeCall(_as, temp, getQmlContext, JITTargetPlatform::EngineRegister);
}
-void InstructionSelection::loadQmlImportedScripts(IR::Expr *temp)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::loadQmlImportedScripts(IR::Expr *temp)
{
- generateRuntimeCall(temp, getQmlImportedScripts, Assembler::EngineRegister);
+ generateRuntimeCall(_as, temp, getQmlImportedScripts, JITTargetPlatform::EngineRegister);
}
-void InstructionSelection::loadQmlSingleton(const QString &name, IR::Expr *temp)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::loadQmlSingleton(const QString &name, IR::Expr *temp)
{
- generateRuntimeCall(temp, getQmlSingleton, Assembler::EngineRegister, Assembler::StringToIndex(name));
+ generateRuntimeCall(_as, temp, getQmlSingleton, JITTargetPlatform::EngineRegister, StringToIndex(name));
}
-void InstructionSelection::loadConst(IR::Const *sourceConst, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::loadConst(IR::Const *sourceConst, IR::Expr *target)
{
if (IR::Temp *targetTemp = target->asTemp()) {
if (targetTemp->kind == IR::Temp::PhysicalRegister) {
if (targetTemp->type == IR::DoubleType) {
Q_ASSERT(sourceConst->type == IR::DoubleType);
- _as->toDoubleRegister(sourceConst, (Assembler::FPRegisterID) targetTemp->index);
+ _as->toDoubleRegister(sourceConst, (FPRegisterID) targetTemp->index);
} else if (targetTemp->type == IR::SInt32Type) {
Q_ASSERT(sourceConst->type == IR::SInt32Type);
- _as->toInt32Register(sourceConst, (Assembler::RegisterID) targetTemp->index);
+ _as->toInt32Register(sourceConst, (RegisterID) targetTemp->index);
} else if (targetTemp->type == IR::UInt32Type) {
Q_ASSERT(sourceConst->type == IR::UInt32Type);
- _as->toUInt32Register(sourceConst, (Assembler::RegisterID) targetTemp->index);
+ _as->toUInt32Register(sourceConst, (RegisterID) targetTemp->index);
} else if (targetTemp->type == IR::BoolType) {
Q_ASSERT(sourceConst->type == IR::BoolType);
- _as->move(Assembler::TrustedImm32(convertToValue(sourceConst).int_32()),
- (Assembler::RegisterID) targetTemp->index);
+ _as->move(TrustedImm32(convertToValue(sourceConst).int_32()),
+ (RegisterID) targetTemp->index);
} else {
Q_UNREACHABLE();
}
@@ -676,147 +498,155 @@ void InstructionSelection::loadConst(IR::Const *sourceConst, IR::Expr *target)
_as->storeValue(convertToValue(sourceConst), target);
}
-void InstructionSelection::loadString(const QString &str, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::loadString(const QString &str, IR::Expr *target)
{
- Pointer srcAddr = _as->loadStringAddress(Assembler::ReturnValueRegister, str);
- _as->loadPtr(srcAddr, Assembler::ReturnValueRegister);
- Pointer destAddr = _as->loadAddress(Assembler::ScratchRegister, target);
-#ifdef QV4_USE_64_BIT_VALUE_ENCODING
- _as->store64(Assembler::ReturnValueRegister, destAddr);
-#else
- _as->store32(Assembler::ReturnValueRegister, destAddr);
- destAddr.offset += 4;
- _as->store32(Assembler::TrustedImm32(QV4::Value::Managed_Type_Internal), destAddr);
-#endif
+ Pointer srcAddr = _as->loadStringAddress(JITTargetPlatform::ReturnValueRegister, str);
+ _as->loadPtr(srcAddr, JITTargetPlatform::ReturnValueRegister);
+ Pointer destAddr = _as->loadAddress(JITTargetPlatform::ScratchRegister, target);
+ JITAssembler::RegisterSizeDependentOps::loadManagedPointer(_as, JITTargetPlatform::ReturnValueRegister, destAddr);
}
-void InstructionSelection::loadRegexp(IR::RegExp *sourceRegexp, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::loadRegexp(IR::RegExp *sourceRegexp, IR::Expr *target)
{
int id = registerRegExp(sourceRegexp);
- generateRuntimeCall(target, regexpLiteral, Assembler::EngineRegister, Assembler::TrustedImm32(id));
+ generateRuntimeCall(_as, target, regexpLiteral, JITTargetPlatform::EngineRegister, TrustedImm32(id));
}
-void InstructionSelection::getActivationProperty(const IR::Name *name, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::getActivationProperty(const IR::Name *name, IR::Expr *target)
{
if (useFastLookups && name->global) {
uint index = registerGlobalGetterLookup(*name->id);
- generateLookupCall(target, index, qOffsetOf(QV4::Lookup, globalGetter), Assembler::EngineRegister, Assembler::Void);
+ generateLookupCall(target, index, qOffsetOf(QV4::Lookup, globalGetter), JITTargetPlatform::EngineRegister, JITAssembler::Void);
return;
}
- generateRuntimeCall(target, getActivationProperty, Assembler::EngineRegister, Assembler::StringToIndex(*name->id));
+ generateRuntimeCall(_as, target, getActivationProperty, JITTargetPlatform::EngineRegister, StringToIndex(*name->id));
}
-void InstructionSelection::setActivationProperty(IR::Expr *source, const QString &targetName)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::setActivationProperty(IR::Expr *source, const QString &targetName)
{
// ### should use a lookup call here
- generateRuntimeCall(Assembler::Void, setActivationProperty,
- Assembler::EngineRegister, Assembler::StringToIndex(targetName), Assembler::PointerToValue(source));
+ generateRuntimeCall(_as, JITAssembler::Void, setActivationProperty,
+ JITTargetPlatform::EngineRegister, StringToIndex(targetName), PointerToValue(source));
}
-void InstructionSelection::initClosure(IR::Closure *closure, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::initClosure(IR::Closure *closure, IR::Expr *target)
{
int id = closure->value;
- generateRuntimeCall(target, closure, Assembler::EngineRegister, Assembler::TrustedImm32(id));
+ generateRuntimeCall(_as, target, closure, JITTargetPlatform::EngineRegister, TrustedImm32(id));
}
-void InstructionSelection::getProperty(IR::Expr *base, const QString &name, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::getProperty(IR::Expr *base, const QString &name, IR::Expr *target)
{
if (useFastLookups) {
uint index = registerGetterLookup(name);
- generateLookupCall(target, index, qOffsetOf(QV4::Lookup, getter), Assembler::EngineRegister, Assembler::PointerToValue(base), Assembler::Void);
+ generateLookupCall(target, index, qOffsetOf(QV4::Lookup, getter), JITTargetPlatform::EngineRegister, PointerToValue(base), JITAssembler::Void);
} else {
- generateRuntimeCall(target, getProperty, Assembler::EngineRegister,
- Assembler::PointerToValue(base), Assembler::StringToIndex(name));
+ generateRuntimeCall(_as, target, getProperty, JITTargetPlatform::EngineRegister,
+ PointerToValue(base), StringToIndex(name));
}
}
-void InstructionSelection::getQmlContextProperty(IR::Expr *base, IR::Member::MemberKind kind, int index, bool captureRequired, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::getQmlContextProperty(IR::Expr *base, IR::Member::MemberKind kind, int index, bool captureRequired, IR::Expr *target)
{
if (kind == IR::Member::MemberOfQmlScopeObject)
- generateRuntimeCall(target, getQmlScopeObjectProperty, Assembler::EngineRegister, Assembler::PointerToValue(base), Assembler::TrustedImm32(index), Assembler::TrustedImm32(captureRequired));
+ generateRuntimeCall(_as, target, getQmlScopeObjectProperty, JITTargetPlatform::EngineRegister, PointerToValue(base), TrustedImm32(index), TrustedImm32(captureRequired));
else if (kind == IR::Member::MemberOfQmlContextObject)
- generateRuntimeCall(target, getQmlContextObjectProperty, Assembler::EngineRegister, Assembler::PointerToValue(base), Assembler::TrustedImm32(index), Assembler::TrustedImm32(captureRequired));
+ generateRuntimeCall(_as, target, getQmlContextObjectProperty, JITTargetPlatform::EngineRegister, PointerToValue(base), TrustedImm32(index), TrustedImm32(captureRequired));
else if (kind == IR::Member::MemberOfIdObjectsArray)
- generateRuntimeCall(target, getQmlIdObject, Assembler::EngineRegister, Assembler::PointerToValue(base), Assembler::TrustedImm32(index));
+ generateRuntimeCall(_as, target, getQmlIdObject, JITTargetPlatform::EngineRegister, PointerToValue(base), TrustedImm32(index));
else
Q_ASSERT(false);
}
-void InstructionSelection::getQObjectProperty(IR::Expr *base, int propertyIndex, bool captureRequired, bool isSingleton, int attachedPropertiesId, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::getQObjectProperty(IR::Expr *base, int propertyIndex, bool captureRequired, bool isSingleton, int attachedPropertiesId, IR::Expr *target)
{
if (attachedPropertiesId != 0)
- generateRuntimeCall(target, getQmlAttachedProperty, Assembler::EngineRegister, Assembler::TrustedImm32(attachedPropertiesId), Assembler::TrustedImm32(propertyIndex));
+ generateRuntimeCall(_as, target, getQmlAttachedProperty, JITTargetPlatform::EngineRegister, TrustedImm32(attachedPropertiesId), TrustedImm32(propertyIndex));
else if (isSingleton)
- generateRuntimeCall(target, getQmlSingletonQObjectProperty, Assembler::EngineRegister, Assembler::PointerToValue(base), Assembler::TrustedImm32(propertyIndex),
- Assembler::TrustedImm32(captureRequired));
+ generateRuntimeCall(_as, target, getQmlSingletonQObjectProperty, JITTargetPlatform::EngineRegister, PointerToValue(base), TrustedImm32(propertyIndex),
+ TrustedImm32(captureRequired));
else
- generateRuntimeCall(target, getQmlQObjectProperty, Assembler::EngineRegister, Assembler::PointerToValue(base), Assembler::TrustedImm32(propertyIndex),
- Assembler::TrustedImm32(captureRequired));
+ generateRuntimeCall(_as, target, getQmlQObjectProperty, JITTargetPlatform::EngineRegister, PointerToValue(base), TrustedImm32(propertyIndex),
+ TrustedImm32(captureRequired));
}
-void InstructionSelection::setProperty(IR::Expr *source, IR::Expr *targetBase,
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::setProperty(IR::Expr *source, IR::Expr *targetBase,
const QString &targetName)
{
if (useFastLookups) {
uint index = registerSetterLookup(targetName);
- generateLookupCall(Assembler::Void, index, qOffsetOf(QV4::Lookup, setter),
- Assembler::EngineRegister,
- Assembler::PointerToValue(targetBase),
- Assembler::PointerToValue(source));
+ generateLookupCall(JITAssembler::Void, index, qOffsetOf(QV4::Lookup, setter),
+ JITTargetPlatform::EngineRegister,
+ PointerToValue(targetBase),
+ PointerToValue(source));
} else {
- generateRuntimeCall(Assembler::Void, setProperty, Assembler::EngineRegister,
- Assembler::PointerToValue(targetBase), Assembler::StringToIndex(targetName),
- Assembler::PointerToValue(source));
+ generateRuntimeCall(_as, JITAssembler::Void, setProperty, JITTargetPlatform::EngineRegister,
+ PointerToValue(targetBase), StringToIndex(targetName),
+ PointerToValue(source));
}
}
-void InstructionSelection::setQmlContextProperty(IR::Expr *source, IR::Expr *targetBase, IR::Member::MemberKind kind, int propertyIndex)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::setQmlContextProperty(IR::Expr *source, IR::Expr *targetBase, IR::Member::MemberKind kind, int propertyIndex)
{
if (kind == IR::Member::MemberOfQmlScopeObject)
- generateRuntimeCall(Assembler::Void, setQmlScopeObjectProperty, Assembler::EngineRegister, Assembler::PointerToValue(targetBase),
- Assembler::TrustedImm32(propertyIndex), Assembler::PointerToValue(source));
+ generateRuntimeCall(_as, JITAssembler::Void, setQmlScopeObjectProperty, JITTargetPlatform::EngineRegister, PointerToValue(targetBase),
+ TrustedImm32(propertyIndex), PointerToValue(source));
else if (kind == IR::Member::MemberOfQmlContextObject)
- generateRuntimeCall(Assembler::Void, setQmlContextObjectProperty, Assembler::EngineRegister, Assembler::PointerToValue(targetBase),
- Assembler::TrustedImm32(propertyIndex), Assembler::PointerToValue(source));
+ generateRuntimeCall(_as, JITAssembler::Void, setQmlContextObjectProperty, JITTargetPlatform::EngineRegister, PointerToValue(targetBase),
+ TrustedImm32(propertyIndex), PointerToValue(source));
else
Q_ASSERT(false);
}
-void InstructionSelection::setQObjectProperty(IR::Expr *source, IR::Expr *targetBase, int propertyIndex)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::setQObjectProperty(IR::Expr *source, IR::Expr *targetBase, int propertyIndex)
{
- generateRuntimeCall(Assembler::Void, setQmlQObjectProperty, Assembler::EngineRegister, Assembler::PointerToValue(targetBase),
- Assembler::TrustedImm32(propertyIndex), Assembler::PointerToValue(source));
+ generateRuntimeCall(_as, JITAssembler::Void, setQmlQObjectProperty, JITTargetPlatform::EngineRegister, PointerToValue(targetBase),
+ TrustedImm32(propertyIndex), PointerToValue(source));
}
-void InstructionSelection::getElement(IR::Expr *base, IR::Expr *index, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::getElement(IR::Expr *base, IR::Expr *index, IR::Expr *target)
{
if (useFastLookups) {
uint lookup = registerIndexedGetterLookup();
generateLookupCall(target, lookup, qOffsetOf(QV4::Lookup, indexedGetter),
- Assembler::PointerToValue(base),
- Assembler::PointerToValue(index));
+ PointerToValue(base),
+ PointerToValue(index));
return;
}
- generateRuntimeCall(target, getElement, Assembler::EngineRegister,
- Assembler::PointerToValue(base), Assembler::PointerToValue(index));
+ generateRuntimeCall(_as, target, getElement, JITTargetPlatform::EngineRegister,
+ PointerToValue(base), PointerToValue(index));
}
-void InstructionSelection::setElement(IR::Expr *source, IR::Expr *targetBase, IR::Expr *targetIndex)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::setElement(IR::Expr *source, IR::Expr *targetBase, IR::Expr *targetIndex)
{
if (useFastLookups) {
uint lookup = registerIndexedSetterLookup();
- generateLookupCall(Assembler::Void, lookup, qOffsetOf(QV4::Lookup, indexedSetter),
- Assembler::PointerToValue(targetBase), Assembler::PointerToValue(targetIndex),
- Assembler::PointerToValue(source));
+ generateLookupCall(JITAssembler::Void, lookup, qOffsetOf(QV4::Lookup, indexedSetter),
+ PointerToValue(targetBase), PointerToValue(targetIndex),
+ PointerToValue(source));
return;
}
- generateRuntimeCall(Assembler::Void, setElement, Assembler::EngineRegister,
- Assembler::PointerToValue(targetBase), Assembler::PointerToValue(targetIndex),
- Assembler::PointerToValue(source));
+ generateRuntimeCall(_as, JITAssembler::Void, setElement, JITTargetPlatform::EngineRegister,
+ PointerToValue(targetBase), PointerToValue(targetIndex),
+ PointerToValue(source));
}
-void InstructionSelection::copyValue(IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::copyValue(IR::Expr *source, IR::Expr *target)
{
IR::Temp *sourceTemp = source->asTemp();
IR::Temp *targetTemp = target->asTemp();
@@ -831,25 +661,25 @@ void InstructionSelection::copyValue(IR::Expr *source, IR::Expr *target)
if (sourceTemp && sourceTemp->kind == IR::Temp::PhysicalRegister) {
if (targetTemp && targetTemp->kind == IR::Temp::PhysicalRegister) {
if (sourceTemp->type == IR::DoubleType)
- _as->moveDouble((Assembler::FPRegisterID) sourceTemp->index,
- (Assembler::FPRegisterID) targetTemp->index);
+ _as->moveDouble((FPRegisterID) sourceTemp->index,
+ (FPRegisterID) targetTemp->index);
else
- _as->move((Assembler::RegisterID) sourceTemp->index,
- (Assembler::RegisterID) targetTemp->index);
+ _as->move((RegisterID) sourceTemp->index,
+ (RegisterID) targetTemp->index);
return;
} else {
switch (sourceTemp->type) {
case IR::DoubleType:
- _as->storeDouble((Assembler::FPRegisterID) sourceTemp->index, target);
+ _as->storeDouble((FPRegisterID) sourceTemp->index, target);
break;
case IR::SInt32Type:
- _as->storeInt32((Assembler::RegisterID) sourceTemp->index, target);
+ _as->storeInt32((RegisterID) sourceTemp->index, target);
break;
case IR::UInt32Type:
- _as->storeUInt32((Assembler::RegisterID) sourceTemp->index, target);
+ _as->storeUInt32((RegisterID) sourceTemp->index, target);
break;
case IR::BoolType:
- _as->storeBool((Assembler::RegisterID) sourceTemp->index, target);
+ _as->storeBool((RegisterID) sourceTemp->index, target);
break;
default:
Q_ASSERT(!"Unreachable");
@@ -861,19 +691,19 @@ void InstructionSelection::copyValue(IR::Expr *source, IR::Expr *target)
switch (targetTemp->type) {
case IR::DoubleType:
Q_ASSERT(source->type == IR::DoubleType);
- _as->toDoubleRegister(source, (Assembler::FPRegisterID) targetTemp->index);
+ _as->toDoubleRegister(source, (FPRegisterID) targetTemp->index);
return;
case IR::BoolType:
Q_ASSERT(source->type == IR::BoolType);
- _as->toInt32Register(source, (Assembler::RegisterID) targetTemp->index);
+ _as->toInt32Register(source, (RegisterID) targetTemp->index);
return;
case IR::SInt32Type:
Q_ASSERT(source->type == IR::SInt32Type);
- _as->toInt32Register(source, (Assembler::RegisterID) targetTemp->index);
+ _as->toInt32Register(source, (RegisterID) targetTemp->index);
return;
case IR::UInt32Type:
Q_ASSERT(source->type == IR::UInt32Type);
- _as->toUInt32Register(source, (Assembler::RegisterID) targetTemp->index);
+ _as->toUInt32Register(source, (RegisterID) targetTemp->index);
return;
default:
Q_ASSERT(!"Unreachable");
@@ -882,10 +712,11 @@ void InstructionSelection::copyValue(IR::Expr *source, IR::Expr *target)
}
// The target is not a physical register, nor is the source. So we can do a memory-to-memory copy:
- _as->memcopyValue(_as->loadAddress(Assembler::ReturnValueRegister, target), source, Assembler::ScratchRegister);
+ _as->memcopyValue(_as->loadAddress(JITTargetPlatform::ReturnValueRegister, target), source, JITTargetPlatform::ScratchRegister);
}
-void InstructionSelection::swapValues(IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::swapValues(IR::Expr *source, IR::Expr *target)
{
IR::Temp *sourceTemp = source->asTemp();
IR::Temp *targetTemp = target->asTemp();
@@ -895,26 +726,27 @@ void InstructionSelection::swapValues(IR::Expr *source, IR::Expr *target)
Q_ASSERT(sourceTemp->type == targetTemp->type);
if (sourceTemp->type == IR::DoubleType) {
- _as->moveDouble((Assembler::FPRegisterID) targetTemp->index, Assembler::FPGpr0);
- _as->moveDouble((Assembler::FPRegisterID) sourceTemp->index,
- (Assembler::FPRegisterID) targetTemp->index);
- _as->moveDouble(Assembler::FPGpr0, (Assembler::FPRegisterID) sourceTemp->index);
+ _as->moveDouble((FPRegisterID) targetTemp->index, JITTargetPlatform::FPGpr0);
+ _as->moveDouble((FPRegisterID) sourceTemp->index,
+ (FPRegisterID) targetTemp->index);
+ _as->moveDouble(JITTargetPlatform::FPGpr0, (FPRegisterID) sourceTemp->index);
} else {
- _as->swap((Assembler::RegisterID) sourceTemp->index,
- (Assembler::RegisterID) targetTemp->index);
+ _as->swap((RegisterID) sourceTemp->index,
+ (RegisterID) targetTemp->index);
}
return;
}
} else if (!sourceTemp || sourceTemp->kind == IR::Temp::StackSlot) {
if (!targetTemp || targetTemp->kind == IR::Temp::StackSlot) {
// Note: a swap for two stack-slots can involve different types.
- Assembler::Pointer sAddr = _as->loadAddress(Assembler::ScratchRegister, source);
- Assembler::Pointer tAddr = _as->loadAddress(Assembler::ReturnValueRegister, target);
+ Pointer sAddr = _as->loadAddress(JITTargetPlatform::ScratchRegister, source);
+ Pointer tAddr = _as->loadAddress(JITTargetPlatform::ReturnValueRegister, target);
// use the implementation in JSC::MacroAssembler, as it doesn't do bit swizzling
- _as->JSC::MacroAssembler::loadDouble(sAddr, Assembler::FPGpr0);
- _as->JSC::MacroAssembler::loadDouble(tAddr, Assembler::FPGpr1);
- _as->JSC::MacroAssembler::storeDouble(Assembler::FPGpr1, sAddr);
- _as->JSC::MacroAssembler::storeDouble(Assembler::FPGpr0, tAddr);
+ auto platformAs = static_cast<typename JITAssembler::MacroAssembler*>(_as);
+ platformAs->loadDouble(sAddr, JITTargetPlatform::FPGpr0);
+ platformAs->loadDouble(tAddr, JITTargetPlatform::FPGpr1);
+ platformAs->storeDouble(JITTargetPlatform::FPGpr1, sAddr);
+ platformAs->storeDouble(JITTargetPlatform::FPGpr0, tAddr);
return;
}
}
@@ -925,18 +757,18 @@ void InstructionSelection::swapValues(IR::Expr *source, IR::Expr *target)
Q_ASSERT(memExpr);
Q_ASSERT(regTemp);
- Assembler::Pointer addr = _as->loadAddress(Assembler::ReturnValueRegister, memExpr);
+ Pointer addr = _as->loadAddress(JITTargetPlatform::ReturnValueRegister, memExpr);
if (regTemp->type == IR::DoubleType) {
- _as->loadDouble(addr, Assembler::FPGpr0);
- _as->storeDouble((Assembler::FPRegisterID) regTemp->index, addr);
- _as->moveDouble(Assembler::FPGpr0, (Assembler::FPRegisterID) regTemp->index);
+ _as->loadDouble(addr, JITTargetPlatform::FPGpr0);
+ _as->storeDouble((FPRegisterID) regTemp->index, addr);
+ _as->moveDouble(JITTargetPlatform::FPGpr0, (FPRegisterID) regTemp->index);
} else if (regTemp->type == IR::UInt32Type) {
- _as->toUInt32Register(addr, Assembler::ScratchRegister);
- _as->storeUInt32((Assembler::RegisterID) regTemp->index, addr);
- _as->move(Assembler::ScratchRegister, (Assembler::RegisterID) regTemp->index);
+ _as->toUInt32Register(addr, JITTargetPlatform::ScratchRegister);
+ _as->storeUInt32((RegisterID) regTemp->index, addr);
+ _as->move(JITTargetPlatform::ScratchRegister, (RegisterID) regTemp->index);
} else {
- _as->load32(addr, Assembler::ScratchRegister);
- _as->store32((Assembler::RegisterID) regTemp->index, addr);
+ _as->load32(addr, JITTargetPlatform::ScratchRegister);
+ _as->store32((RegisterID) regTemp->index, addr);
if (regTemp->type != memExpr->type) {
addr.offset += 4;
quint32 tag;
@@ -951,55 +783,59 @@ void InstructionSelection::swapValues(IR::Expr *source, IR::Expr *target)
tag = 31337; // bogus value
Q_UNREACHABLE();
}
- _as->store32(Assembler::TrustedImm32(tag), addr);
+ _as->store32(TrustedImm32(tag), addr);
}
- _as->move(Assembler::ScratchRegister, (Assembler::RegisterID) regTemp->index);
+ _as->move(JITTargetPlatform::ScratchRegister, (RegisterID) regTemp->index);
}
}
#define setOp(op, opName, operation) \
do { \
- op = RuntimeCall(qOffsetOf(QV4::Runtime, operation)); opName = "Runtime::" isel_stringIfy(operation); \
+ op = typename JITAssembler::RuntimeCall(qOffsetOf(QV4::Runtime, operation)); opName = "Runtime::" isel_stringIfy(operation); \
needsExceptionCheck = QV4::Runtime::Method_##operation##_NeedsExceptionCheck; \
} while (0)
#define setOpContext(op, opName, operation) \
do { \
- opContext = RuntimeCall(qOffsetOf(QV4::Runtime, operation)); opName = "Runtime::" isel_stringIfy(operation); \
+ opContext = typename JITAssembler::RuntimeCall(qOffsetOf(QV4::Runtime, operation)); opName = "Runtime::" isel_stringIfy(operation); \
needsExceptionCheck = QV4::Runtime::Method_##operation##_NeedsExceptionCheck; \
} while (0)
-void InstructionSelection::unop(IR::AluOp oper, IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::unop(IR::AluOp oper, IR::Expr *source, IR::Expr *target)
{
- QV4::JIT::Unop unop(_as, oper);
+ QV4::JIT::Unop<JITAssembler> unop(_as, oper);
unop.generate(source, target);
}
-void InstructionSelection::binop(IR::AluOp oper, IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::binop(IR::AluOp oper, IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target)
{
- QV4::JIT::Binop binop(_as, oper);
+ QV4::JIT::Binop<JITAssembler> binop(_as, oper);
binop.generate(leftSource, rightSource, target);
}
-void InstructionSelection::callQmlContextProperty(IR::Expr *base, IR::Member::MemberKind kind, int propertyIndex, IR::ExprList *args, IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callQmlContextProperty(IR::Expr *base, IR::Member::MemberKind kind, int propertyIndex, IR::ExprList *args, IR::Expr *result)
{
prepareCallData(args, base);
if (kind == IR::Member::MemberOfQmlScopeObject)
- generateRuntimeCall(result, callQmlScopeObjectProperty,
- Assembler::EngineRegister,
- Assembler::TrustedImm32(propertyIndex),
+ generateRuntimeCall(_as, result, callQmlScopeObjectProperty,
+ JITTargetPlatform::EngineRegister,
+ TrustedImm32(propertyIndex),
baseAddressForCallData());
else if (kind == IR::Member::MemberOfQmlContextObject)
- generateRuntimeCall(result, callQmlContextObjectProperty,
- Assembler::EngineRegister,
- Assembler::TrustedImm32(propertyIndex),
+ generateRuntimeCall(_as, result, callQmlContextObjectProperty,
+ JITTargetPlatform::EngineRegister,
+ TrustedImm32(propertyIndex),
baseAddressForCallData());
else
Q_ASSERT(false);
}
-void InstructionSelection::callProperty(IR::Expr *base, const QString &name, IR::ExprList *args,
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callProperty(IR::Expr *base, const QString &name, IR::ExprList *args,
IR::Expr *result)
{
Q_ASSERT(base != 0);
@@ -1008,29 +844,31 @@ void InstructionSelection::callProperty(IR::Expr *base, const QString &name, IR:
if (useFastLookups) {
uint index = registerGetterLookup(name);
- generateRuntimeCall(result, callPropertyLookup,
- Assembler::EngineRegister,
- Assembler::TrustedImm32(index),
+ generateRuntimeCall(_as, result, callPropertyLookup,
+ JITTargetPlatform::EngineRegister,
+ TrustedImm32(index),
baseAddressForCallData());
} else {
- generateRuntimeCall(result, callProperty, Assembler::EngineRegister,
- Assembler::StringToIndex(name),
+ generateRuntimeCall(_as, result, callProperty, JITTargetPlatform::EngineRegister,
+ StringToIndex(name),
baseAddressForCallData());
}
}
-void InstructionSelection::callSubscript(IR::Expr *base, IR::Expr *index, IR::ExprList *args,
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::callSubscript(IR::Expr *base, IR::Expr *index, IR::ExprList *args,
IR::Expr *result)
{
Q_ASSERT(base != 0);
prepareCallData(args, base);
- generateRuntimeCall(result, callElement, Assembler::EngineRegister,
- Assembler::PointerToValue(index),
+ generateRuntimeCall(_as, result, callElement, JITTargetPlatform::EngineRegister,
+ PointerToValue(index),
baseAddressForCallData());
}
-void InstructionSelection::convertType(IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::convertType(IR::Expr *source, IR::Expr *target)
{
switch (target->type) {
case IR::DoubleType:
@@ -1051,7 +889,8 @@ void InstructionSelection::convertType(IR::Expr *source, IR::Expr *target)
}
}
-void InstructionSelection::convertTypeSlowPath(IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::convertTypeSlowPath(IR::Expr *source, IR::Expr *target)
{
Q_ASSERT(target->type != IR::BoolType);
@@ -1061,7 +900,8 @@ void InstructionSelection::convertTypeSlowPath(IR::Expr *source, IR::Expr *targe
copyValue(source, target);
}
-void InstructionSelection::convertTypeToDouble(IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::convertTypeToDouble(IR::Expr *source, IR::Expr *target)
{
switch (source->type) {
case IR::SInt32Type:
@@ -1073,51 +913,37 @@ void InstructionSelection::convertTypeToDouble(IR::Expr *source, IR::Expr *targe
convertUIntToDouble(source, target);
break;
case IR::UndefinedType:
- _as->loadDouble(_as->loadAddress(Assembler::ScratchRegister, source), Assembler::FPGpr0);
- _as->storeDouble(Assembler::FPGpr0, target);
+ _as->loadDouble(_as->loadAddress(JITTargetPlatform::ScratchRegister, source), JITTargetPlatform::FPGpr0);
+ _as->storeDouble(JITTargetPlatform::FPGpr0, target);
break;
case IR::StringType:
case IR::VarType: {
// load the tag:
- Assembler::Pointer tagAddr = _as->loadAddress(Assembler::ScratchRegister, source);
+ Pointer tagAddr = _as->loadAddress(JITTargetPlatform::ScratchRegister, source);
tagAddr.offset += 4;
- _as->load32(tagAddr, Assembler::ScratchRegister);
+ _as->load32(tagAddr, JITTargetPlatform::ScratchRegister);
// check if it's an int32:
- Assembler::Jump isNoInt = _as->branch32(Assembler::NotEqual, Assembler::ScratchRegister,
- Assembler::TrustedImm32(Value::Integer_Type_Internal));
+ Jump isNoInt = _as->branch32(RelationalCondition::NotEqual, JITTargetPlatform::ScratchRegister,
+ TrustedImm32(Value::Integer_Type_Internal));
convertIntToDouble(source, target);
- Assembler::Jump intDone = _as->jump();
+ Jump intDone = _as->jump();
// not an int, check if it's NOT a double:
isNoInt.link(_as);
-#ifdef QV4_USE_64_BIT_VALUE_ENCODING
- _as->rshift32(Assembler::TrustedImm32(Value::IsDoubleTag_Shift), Assembler::ScratchRegister);
- Assembler::Jump isDbl = _as->branch32(Assembler::NotEqual, Assembler::ScratchRegister,
- Assembler::TrustedImm32(0));
-#else
- _as->and32(Assembler::TrustedImm32(Value::NotDouble_Mask), Assembler::ScratchRegister);
- Assembler::Jump isDbl = _as->branch32(Assembler::NotEqual, Assembler::ScratchRegister,
- Assembler::TrustedImm32(Value::NotDouble_Mask));
-#endif
+ Jump isDbl = _as->generateIsDoubleCheck(JITTargetPlatform::ScratchRegister);
- generateRuntimeCall(target, toDouble, Assembler::PointerToValue(source));
- Assembler::Jump noDoubleDone = _as->jump();
+ generateRuntimeCall(_as, target, toDouble, PointerToValue(source));
+ Jump noDoubleDone = _as->jump();
// it is a double:
isDbl.link(_as);
- Assembler::Pointer addr2 = _as->loadAddress(Assembler::ScratchRegister, source);
+ Pointer addr2 = _as->loadAddress(JITTargetPlatform::ScratchRegister, source);
IR::Temp *targetTemp = target->asTemp();
if (!targetTemp || targetTemp->kind == IR::Temp::StackSlot) {
-#if Q_PROCESSOR_WORDSIZE == 8
- _as->load64(addr2, Assembler::ScratchRegister);
- _as->store64(Assembler::ScratchRegister, _as->loadAddress(Assembler::ReturnValueRegister, target));
-#else
- _as->loadDouble(addr2, Assembler::FPGpr0);
- _as->storeDouble(Assembler::FPGpr0, _as->loadAddress(Assembler::ReturnValueRegister, target));
-#endif
+ _as->memcopyValue(target, addr2, JITTargetPlatform::FPGpr0, JITTargetPlatform::ReturnValueRegister);
} else {
- _as->loadDouble(addr2, (Assembler::FPRegisterID) targetTemp->index);
+ _as->loadDouble(addr2, (FPRegisterID) targetTemp->index);
}
noDoubleDone.link(_as);
@@ -1129,7 +955,8 @@ void InstructionSelection::convertTypeToDouble(IR::Expr *source, IR::Expr *targe
}
}
-void InstructionSelection::convertTypeToBool(IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::convertTypeToBool(IR::Expr *source, IR::Expr *target)
{
IR::Temp *sourceTemp = source->asTemp();
switch (source->type) {
@@ -1141,16 +968,16 @@ void InstructionSelection::convertTypeToBool(IR::Expr *source, IR::Expr *target)
// The source is in a register if the register allocator is used. If the register
// allocator was not used, then that means that we can use any register for to
// load the double into.
- Assembler::FPRegisterID reg;
+ FPRegisterID reg;
if (sourceTemp && sourceTemp->kind == IR::Temp::PhysicalRegister)
- reg = (Assembler::FPRegisterID) sourceTemp->index;
+ reg = (FPRegisterID) sourceTemp->index;
else
- reg = _as->toDoubleRegister(source, (Assembler::FPRegisterID) 1);
- Assembler::Jump nonZero = _as->branchDoubleNonZero(reg, Assembler::FPGpr0);
+ reg = _as->toDoubleRegister(source, (FPRegisterID) 1);
+ Jump nonZero = _as->branchDoubleNonZero(reg, JITTargetPlatform::FPGpr0);
// it's 0, so false:
_as->storeBool(false, target);
- Assembler::Jump done = _as->jump();
+ Jump done = _as->jump();
// it's non-zero, so true:
nonZero.link(_as);
@@ -1164,283 +991,220 @@ void InstructionSelection::convertTypeToBool(IR::Expr *source, IR::Expr *target)
_as->storeBool(false, target);
break;
case IR::StringType:
- generateRuntimeCall(Assembler::ReturnValueRegister, toBoolean,
- Assembler::PointerToValue(source));
- _as->storeBool(Assembler::ReturnValueRegister, target);
+ generateRuntimeCall(_as, JITTargetPlatform::ReturnValueRegister, toBoolean,
+ PointerToValue(source));
+ _as->storeBool(JITTargetPlatform::ReturnValueRegister, target);
case IR::VarType:
default:
- Assembler::Pointer addr = _as->loadAddress(Assembler::ScratchRegister, source);
- Assembler::Pointer tagAddr = addr;
+ Pointer addr = _as->loadAddress(JITTargetPlatform::ScratchRegister, source);
+ Pointer tagAddr = addr;
tagAddr.offset += 4;
- _as->load32(tagAddr, Assembler::ReturnValueRegister);
+ _as->load32(tagAddr, JITTargetPlatform::ReturnValueRegister);
// checkif it's a bool:
- Assembler::Jump notBool = _as->branch32(Assembler::NotEqual, Assembler::ReturnValueRegister,
- Assembler::TrustedImm32(Value::Boolean_Type_Internal));
- _as->load32(addr, Assembler::ReturnValueRegister);
- Assembler::Jump boolDone = _as->jump();
+ Jump notBool = _as->branch32(RelationalCondition::NotEqual, JITTargetPlatform::ReturnValueRegister,
+ TrustedImm32(Value::Boolean_Type_Internal));
+ _as->load32(addr, JITTargetPlatform::ReturnValueRegister);
+ Jump boolDone = _as->jump();
// check if it's an int32:
notBool.link(_as);
- Assembler::Jump fallback = _as->branch32(Assembler::NotEqual, Assembler::ReturnValueRegister,
- Assembler::TrustedImm32(Value::Integer_Type_Internal));
- _as->load32(addr, Assembler::ReturnValueRegister);
- Assembler::Jump isZero = _as->branch32(Assembler::Equal, Assembler::ReturnValueRegister,
- Assembler::TrustedImm32(0));
- _as->move(Assembler::TrustedImm32(1), Assembler::ReturnValueRegister);
- Assembler::Jump intDone = _as->jump();
+ Jump fallback = _as->branch32(RelationalCondition::NotEqual, JITTargetPlatform::ReturnValueRegister,
+ TrustedImm32(Value::Integer_Type_Internal));
+ _as->load32(addr, JITTargetPlatform::ReturnValueRegister);
+ Jump isZero = _as->branch32(RelationalCondition::Equal, JITTargetPlatform::ReturnValueRegister,
+ TrustedImm32(0));
+ _as->move(TrustedImm32(1), JITTargetPlatform::ReturnValueRegister);
+ Jump intDone = _as->jump();
// not an int:
fallback.link(_as);
- generateRuntimeCall(Assembler::ReturnValueRegister, toBoolean,
- Assembler::PointerToValue(source));
+ generateRuntimeCall(_as, JITTargetPlatform::ReturnValueRegister, toBoolean,
+ PointerToValue(source));
isZero.link(_as);
intDone.link(_as);
boolDone.link(_as);
- _as->storeBool(Assembler::ReturnValueRegister, target);
+ _as->storeBool(JITTargetPlatform::ReturnValueRegister, target);
break;
}
}
-void InstructionSelection::convertTypeToSInt32(IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::convertTypeToSInt32(IR::Expr *source, IR::Expr *target)
{
switch (source->type) {
case IR::VarType: {
-
-#ifdef QV4_USE_64_BIT_VALUE_ENCODING
- Assembler::Pointer addr = _as->loadAddress(Assembler::ScratchRegister, source);
- _as->load64(addr, Assembler::ScratchRegister);
- _as->move(Assembler::ScratchRegister, Assembler::ReturnValueRegister);
-
- // check if it's integer convertible
- _as->urshift64(Assembler::TrustedImm32(QV4::Value::IsIntegerConvertible_Shift), Assembler::ScratchRegister);
- Assembler::Jump isIntConvertible = _as->branch32(Assembler::Equal, Assembler::ScratchRegister, Assembler::TrustedImm32(3));
-
- // nope, not integer convertible, so check for a double:
- _as->urshift64(Assembler::TrustedImm32(
- QV4::Value::IsDoubleTag_Shift - QV4::Value::IsIntegerConvertible_Shift),
- Assembler::ScratchRegister);
- Assembler::Jump fallback = _as->branch32(Assembler::GreaterThan, Assembler::ScratchRegister, Assembler::TrustedImm32(0));
-
- // it's a double
- _as->move(Assembler::TrustedImm64(QV4::Value::NaNEncodeMask), Assembler::ScratchRegister);
- _as->xor64(Assembler::ScratchRegister, Assembler::ReturnValueRegister);
- _as->move64ToDouble(Assembler::ReturnValueRegister, Assembler::FPGpr0);
- Assembler::Jump success =
- _as->branchTruncateDoubleToInt32(Assembler::FPGpr0, Assembler::ReturnValueRegister,
- Assembler::BranchIfTruncateSuccessful);
-
- // not an int:
- fallback.link(_as);
- generateRuntimeCall(Assembler::ReturnValueRegister, toInt,
- _as->loadAddress(Assembler::ScratchRegister, source));
-
- isIntConvertible.link(_as);
- success.link(_as);
- IR::Temp *targetTemp = target->asTemp();
- if (!targetTemp || targetTemp->kind == IR::Temp::StackSlot) {
- Assembler::Pointer targetAddr = _as->loadAddress(Assembler::ScratchRegister, target);
- _as->store32(Assembler::ReturnValueRegister, targetAddr);
- targetAddr.offset += 4;
- _as->store32(Assembler::TrustedImm32(Value::Integer_Type_Internal), targetAddr);
- } else {
- _as->storeInt32(Assembler::ReturnValueRegister, target);
- }
-#else
- // load the tag:
- Assembler::Pointer addr = _as->loadAddress(Assembler::ScratchRegister, source);
- Assembler::Pointer tagAddr = addr;
- tagAddr.offset += 4;
- _as->load32(tagAddr, Assembler::ReturnValueRegister);
-
- // check if it's an int32:
- Assembler::Jump fallback = _as->branch32(Assembler::NotEqual, Assembler::ReturnValueRegister,
- Assembler::TrustedImm32(Value::Integer_Type_Internal));
- IR::Temp *targetTemp = target->asTemp();
- if (!targetTemp || targetTemp->kind == IR::Temp::StackSlot) {
- _as->load32(addr, Assembler::ReturnValueRegister);
- Assembler::Pointer targetAddr = _as->loadAddress(Assembler::ScratchRegister, target);
- _as->store32(Assembler::ReturnValueRegister, targetAddr);
- targetAddr.offset += 4;
- _as->store32(Assembler::TrustedImm32(Value::Integer_Type_Internal), targetAddr);
- } else {
- _as->load32(addr, (Assembler::RegisterID) targetTemp->index);
- }
- Assembler::Jump intDone = _as->jump();
-
- // not an int:
- fallback.link(_as);
- generateRuntimeCall(Assembler::ReturnValueRegister, toInt,
- _as->loadAddress(Assembler::ScratchRegister, source));
- _as->storeInt32(Assembler::ReturnValueRegister, target);
-
- intDone.link(_as);
-#endif
-
+ JITAssembler::RegisterSizeDependentOps::convertVarToSInt32(_as, source, target);
} break;
case IR::DoubleType: {
- Assembler::Jump success =
+ Jump success =
_as->branchTruncateDoubleToInt32(_as->toDoubleRegister(source),
- Assembler::ReturnValueRegister,
- Assembler::BranchIfTruncateSuccessful);
- generateRuntimeCall(Assembler::ReturnValueRegister, doubleToInt,
- Assembler::PointerToValue(source));
+ JITTargetPlatform::ReturnValueRegister,
+ BranchTruncateType::BranchIfTruncateSuccessful);
+ generateRuntimeCall(_as, JITTargetPlatform::ReturnValueRegister, doubleToInt,
+ PointerToValue(source));
success.link(_as);
- _as->storeInt32(Assembler::ReturnValueRegister, target);
+ _as->storeInt32(JITTargetPlatform::ReturnValueRegister, target);
} break;
case IR::UInt32Type:
- _as->storeInt32(_as->toUInt32Register(source, Assembler::ReturnValueRegister), target);
+ _as->storeInt32(_as->toUInt32Register(source, JITTargetPlatform::ReturnValueRegister), target);
break;
case IR::NullType:
case IR::UndefinedType:
- _as->move(Assembler::TrustedImm32(0), Assembler::ReturnValueRegister);
- _as->storeInt32(Assembler::ReturnValueRegister, target);
+ _as->move(TrustedImm32(0), JITTargetPlatform::ReturnValueRegister);
+ _as->storeInt32(JITTargetPlatform::ReturnValueRegister, target);
break;
case IR::BoolType:
- _as->storeInt32(_as->toInt32Register(source, Assembler::ReturnValueRegister), target);
+ _as->storeInt32(_as->toInt32Register(source, JITTargetPlatform::ReturnValueRegister), target);
break;
case IR::StringType:
default:
- generateRuntimeCall(Assembler::ReturnValueRegister, toInt,
- _as->loadAddress(Assembler::ScratchRegister, source));
- _as->storeInt32(Assembler::ReturnValueRegister, target);
+ generateRuntimeCall(_as, JITTargetPlatform::ReturnValueRegister, toInt,
+ _as->loadAddress(JITTargetPlatform::ScratchRegister, source));
+ _as->storeInt32(JITTargetPlatform::ReturnValueRegister, target);
break;
} // switch (source->type)
}
-void InstructionSelection::convertTypeToUInt32(IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::convertTypeToUInt32(IR::Expr *source, IR::Expr *target)
{
switch (source->type) {
case IR::VarType: {
// load the tag:
- Assembler::Pointer tagAddr = _as->loadAddress(Assembler::ScratchRegister, source);
+ Pointer tagAddr = _as->loadAddress(JITTargetPlatform::ScratchRegister, source);
tagAddr.offset += 4;
- _as->load32(tagAddr, Assembler::ScratchRegister);
+ _as->load32(tagAddr, JITTargetPlatform::ScratchRegister);
// check if it's an int32:
- Assembler::Jump isNoInt = _as->branch32(Assembler::NotEqual, Assembler::ScratchRegister,
- Assembler::TrustedImm32(Value::Integer_Type_Internal));
- Assembler::Pointer addr = _as->loadAddress(Assembler::ScratchRegister, source);
- _as->storeUInt32(_as->toInt32Register(addr, Assembler::ScratchRegister), target);
- Assembler::Jump intDone = _as->jump();
+ Jump isNoInt = _as->branch32(RelationalCondition::NotEqual, JITTargetPlatform::ScratchRegister,
+ TrustedImm32(Value::Integer_Type_Internal));
+ Pointer addr = _as->loadAddress(JITTargetPlatform::ScratchRegister, source);
+ _as->storeUInt32(_as->toInt32Register(addr, JITTargetPlatform::ScratchRegister), target);
+ Jump intDone = _as->jump();
// not an int:
isNoInt.link(_as);
- generateRuntimeCall(Assembler::ReturnValueRegister, toUInt,
- _as->loadAddress(Assembler::ScratchRegister, source));
- _as->storeInt32(Assembler::ReturnValueRegister, target);
+ generateRuntimeCall(_as, JITTargetPlatform::ReturnValueRegister, toUInt,
+ _as->loadAddress(JITTargetPlatform::ScratchRegister, source));
+ _as->storeInt32(JITTargetPlatform::ReturnValueRegister, target);
intDone.link(_as);
} break;
case IR::DoubleType: {
- Assembler::FPRegisterID reg = _as->toDoubleRegister(source);
- Assembler::Jump success =
- _as->branchTruncateDoubleToUint32(reg, Assembler::ReturnValueRegister,
- Assembler::BranchIfTruncateSuccessful);
- generateRuntimeCall(Assembler::ReturnValueRegister, doubleToUInt,
- Assembler::PointerToValue(source));
+ FPRegisterID reg = _as->toDoubleRegister(source);
+ Jump success =
+ _as->branchTruncateDoubleToUint32(reg, JITTargetPlatform::ReturnValueRegister,
+ BranchTruncateType::BranchIfTruncateSuccessful);
+ generateRuntimeCall(_as, JITTargetPlatform::ReturnValueRegister, doubleToUInt,
+ PointerToValue(source));
success.link(_as);
- _as->storeUInt32(Assembler::ReturnValueRegister, target);
+ _as->storeUInt32(JITTargetPlatform::ReturnValueRegister, target);
} break;
case IR::NullType:
case IR::UndefinedType:
- _as->move(Assembler::TrustedImm32(0), Assembler::ReturnValueRegister);
- _as->storeUInt32(Assembler::ReturnValueRegister, target);
+ _as->move(TrustedImm32(0), JITTargetPlatform::ReturnValueRegister);
+ _as->storeUInt32(JITTargetPlatform::ReturnValueRegister, target);
break;
case IR::StringType:
- generateRuntimeCall(Assembler::ReturnValueRegister, toUInt,
- Assembler::PointerToValue(source));
- _as->storeUInt32(Assembler::ReturnValueRegister, target);
+ generateRuntimeCall(_as, JITTargetPlatform::ReturnValueRegister, toUInt,
+ PointerToValue(source));
+ _as->storeUInt32(JITTargetPlatform::ReturnValueRegister, target);
break;
case IR::SInt32Type:
case IR::BoolType:
- _as->storeUInt32(_as->toInt32Register(source, Assembler::ReturnValueRegister), target);
+ _as->storeUInt32(_as->toInt32Register(source, JITTargetPlatform::ReturnValueRegister), target);
break;
default:
break;
} // switch (source->type)
}
-void InstructionSelection::constructActivationProperty(IR::Name *func, IR::ExprList *args, IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::constructActivationProperty(IR::Name *func, IR::ExprList *args, IR::Expr *result)
{
Q_ASSERT(func != 0);
prepareCallData(args, 0);
if (useFastLookups && func->global) {
uint index = registerGlobalGetterLookup(*func->id);
- generateRuntimeCall(result, constructGlobalLookup,
- Assembler::EngineRegister,
- Assembler::TrustedImm32(index), baseAddressForCallData());
+ generateRuntimeCall(_as, result, constructGlobalLookup,
+ JITTargetPlatform::EngineRegister,
+ TrustedImm32(index), baseAddressForCallData());
return;
}
- generateRuntimeCall(result, constructActivationProperty,
- Assembler::EngineRegister,
- Assembler::StringToIndex(*func->id),
+ generateRuntimeCall(_as, result, constructActivationProperty,
+ JITTargetPlatform::EngineRegister,
+ StringToIndex(*func->id),
baseAddressForCallData());
}
-void InstructionSelection::constructProperty(IR::Expr *base, const QString &name, IR::ExprList *args, IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::constructProperty(IR::Expr *base, const QString &name, IR::ExprList *args, IR::Expr *result)
{
prepareCallData(args, base);
if (useFastLookups) {
uint index = registerGetterLookup(name);
- generateRuntimeCall(result, constructPropertyLookup,
- Assembler::EngineRegister,
- Assembler::TrustedImm32(index),
+ generateRuntimeCall(_as, result, constructPropertyLookup,
+ JITTargetPlatform::EngineRegister,
+ TrustedImm32(index),
baseAddressForCallData());
return;
}
- generateRuntimeCall(result, constructProperty, Assembler::EngineRegister,
- Assembler::StringToIndex(name),
+ generateRuntimeCall(_as, result, constructProperty, JITTargetPlatform::EngineRegister,
+ StringToIndex(name),
baseAddressForCallData());
}
-void InstructionSelection::constructValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::constructValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result)
{
Q_ASSERT(value != 0);
prepareCallData(args, 0);
- generateRuntimeCall(result, constructValue,
- Assembler::EngineRegister,
- Assembler::Reference(value),
+ generateRuntimeCall(_as, result, constructValue,
+ JITTargetPlatform::EngineRegister,
+ Reference(value),
baseAddressForCallData());
}
-void InstructionSelection::visitJump(IR::Jump *s)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::visitJump(IR::Jump *s)
{
- if (!_removableJumps.contains(s))
+ if (!_removableJumps.at(_block->index()))
_as->jumpToBlock(_block, s->target);
}
-void InstructionSelection::visitCJump(IR::CJump *s)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::visitCJump(IR::CJump *s)
{
IR::Temp *t = s->cond->asTemp();
if (t || s->cond->asArgLocal()) {
- Assembler::RegisterID reg;
+ RegisterID reg;
if (t && t->kind == IR::Temp::PhysicalRegister) {
Q_ASSERT(t->type == IR::BoolType);
- reg = (Assembler::RegisterID) t->index;
+ reg = (RegisterID) t->index;
} else if (t && t->kind == IR::Temp::StackSlot && t->type == IR::BoolType) {
- reg = Assembler::ReturnValueRegister;
+ reg = JITTargetPlatform::ReturnValueRegister;
_as->toInt32Register(t, reg);
} else {
- Address temp = _as->loadAddress(Assembler::ScratchRegister, s->cond);
+ Address temp = _as->loadAddress(JITTargetPlatform::ScratchRegister, s->cond);
Address tag = temp;
tag.offset += QV4::Value::tagOffset();
- Assembler::Jump booleanConversion = _as->branch32(Assembler::NotEqual, tag, Assembler::TrustedImm32(QV4::Value::Boolean_Type_Internal));
+ Jump booleanConversion = _as->branch32(RelationalCondition::NotEqual, tag, TrustedImm32(QV4::Value::Boolean_Type_Internal));
Address data = temp;
data.offset += QV4::Value::valueOffset();
- _as->load32(data, Assembler::ReturnValueRegister);
- Assembler::Jump testBoolean = _as->jump();
+ _as->load32(data, JITTargetPlatform::ReturnValueRegister);
+ Jump testBoolean = _as->jump();
booleanConversion.link(_as);
- reg = Assembler::ReturnValueRegister;
- generateRuntimeCall(reg, toBoolean, Assembler::Reference(s->cond));
+ reg = JITTargetPlatform::ReturnValueRegister;
+ generateRuntimeCall(_as, reg, toBoolean, Reference(s->cond));
testBoolean.link(_as);
}
@@ -1450,9 +1214,9 @@ void InstructionSelection::visitCJump(IR::CJump *s)
} else if (IR::Const *c = s->cond->asConst()) {
// TODO: SSA optimization for constant condition evaluation should remove this.
// See also visitCJump() in RegAllocInfo.
- generateRuntimeCall(Assembler::ReturnValueRegister, toBoolean,
- Assembler::PointerToValue(c));
- _as->generateCJumpOnNonZero(Assembler::ReturnValueRegister, _block, s->iftrue, s->iffalse);
+ generateRuntimeCall(_as, JITTargetPlatform::ReturnValueRegister, toBoolean,
+ PointerToValue(c));
+ _as->generateCJumpOnNonZero(JITTargetPlatform::ReturnValueRegister, _block, s->iftrue, s->iffalse);
return;
} else if (IR::Binop *b = s->cond->asBinop()) {
if (b->left->type == IR::DoubleType && b->right->type == IR::DoubleType
@@ -1472,8 +1236,8 @@ void InstructionSelection::visitCJump(IR::CJump *s)
return;
}
- RuntimeCall op;
- RuntimeCall opContext;
+ typename JITAssembler::RuntimeCall op;
+ typename JITAssembler::RuntimeCall opContext;
const char *opName = 0;
bool needsExceptionCheck;
switch (b->op) {
@@ -1497,165 +1261,30 @@ void InstructionSelection::visitCJump(IR::CJump *s)
// elimination (which isn't there either) would remove the whole else block.
if (opContext.isValid())
_as->generateFunctionCallImp(needsExceptionCheck,
- Assembler::ReturnValueRegister, opName, opContext,
- Assembler::EngineRegister,
- Assembler::PointerToValue(b->left),
- Assembler::PointerToValue(b->right));
+ JITTargetPlatform::ReturnValueRegister, opName, opContext,
+ JITTargetPlatform::EngineRegister,
+ PointerToValue(b->left),
+ PointerToValue(b->right));
else
_as->generateFunctionCallImp(needsExceptionCheck,
- Assembler::ReturnValueRegister, opName, op,
- Assembler::PointerToValue(b->left),
- Assembler::PointerToValue(b->right));
+ JITTargetPlatform::ReturnValueRegister, opName, op,
+ PointerToValue(b->left),
+ PointerToValue(b->right));
- _as->generateCJumpOnNonZero(Assembler::ReturnValueRegister, _block, s->iftrue, s->iffalse);
+ _as->generateCJumpOnNonZero(JITTargetPlatform::ReturnValueRegister, _block, s->iftrue, s->iffalse);
return;
}
Q_UNREACHABLE();
}
-void InstructionSelection::visitRet(IR::Ret *s)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::visitRet(IR::Ret *s)
{
- if (!s) {
- // this only happens if the method doesn't have a return statement and can
- // only exit through an exception
- } else if (IR::Temp *t = s->expr->asTemp()) {
-#if CPU(X86) || CPU(ARM) || CPU(MIPS)
-
-# if CPU(X86)
- Assembler::RegisterID lowReg = JSC::X86Registers::eax;
- Assembler::RegisterID highReg = JSC::X86Registers::edx;
-# elif CPU(MIPS)
- Assembler::RegisterID lowReg = JSC::MIPSRegisters::v0;
- Assembler::RegisterID highReg = JSC::MIPSRegisters::v1;
-# else // CPU(ARM)
- Assembler::RegisterID lowReg = JSC::ARMRegisters::r0;
- Assembler::RegisterID highReg = JSC::ARMRegisters::r1;
-# endif
-
- if (t->kind == IR::Temp::PhysicalRegister) {
- switch (t->type) {
- case IR::DoubleType:
- _as->moveDoubleToInts((Assembler::FPRegisterID) t->index, lowReg, highReg);
- break;
- case IR::UInt32Type: {
- Assembler::RegisterID srcReg = (Assembler::RegisterID) t->index;
- Assembler::Jump intRange = _as->branch32(Assembler::GreaterThanOrEqual, srcReg, Assembler::TrustedImm32(0));
- _as->convertUInt32ToDouble(srcReg, Assembler::FPGpr0, Assembler::ReturnValueRegister);
- _as->moveDoubleToInts(Assembler::FPGpr0, lowReg, highReg);
- Assembler::Jump done = _as->jump();
- intRange.link(_as);
- _as->move(srcReg, lowReg);
- _as->move(Assembler::TrustedImm32(QV4::Value::Integer_Type_Internal), highReg);
- done.link(_as);
- } break;
- case IR::SInt32Type:
- _as->move((Assembler::RegisterID) t->index, lowReg);
- _as->move(Assembler::TrustedImm32(QV4::Value::Integer_Type_Internal), highReg);
- break;
- case IR::BoolType:
- _as->move((Assembler::RegisterID) t->index, lowReg);
- _as->move(Assembler::TrustedImm32(QV4::Value::Boolean_Type_Internal), highReg);
- break;
- default:
- Q_UNREACHABLE();
- }
- } else {
- Pointer addr = _as->loadAddress(Assembler::ScratchRegister, t);
- _as->load32(addr, lowReg);
- addr.offset += 4;
- _as->load32(addr, highReg);
- }
-#else
- if (t->kind == IR::Temp::PhysicalRegister) {
- if (t->type == IR::DoubleType) {
- _as->moveDoubleTo64((Assembler::FPRegisterID) t->index,
- Assembler::ReturnValueRegister);
- _as->move(Assembler::TrustedImm64(QV4::Value::NaNEncodeMask),
- Assembler::ScratchRegister);
- _as->xor64(Assembler::ScratchRegister, Assembler::ReturnValueRegister);
- } else if (t->type == IR::UInt32Type) {
- Assembler::RegisterID srcReg = (Assembler::RegisterID) t->index;
- Assembler::Jump intRange = _as->branch32(Assembler::GreaterThanOrEqual, srcReg, Assembler::TrustedImm32(0));
- _as->convertUInt32ToDouble(srcReg, Assembler::FPGpr0, Assembler::ReturnValueRegister);
- _as->moveDoubleTo64(Assembler::FPGpr0, Assembler::ReturnValueRegister);
- _as->move(Assembler::TrustedImm64(QV4::Value::NaNEncodeMask), Assembler::ScratchRegister);
- _as->xor64(Assembler::ScratchRegister, Assembler::ReturnValueRegister);
- Assembler::Jump done = _as->jump();
- intRange.link(_as);
- _as->zeroExtend32ToPtr(srcReg, Assembler::ReturnValueRegister);
- quint64 tag = QV4::Value::Integer_Type_Internal;
- _as->or64(Assembler::TrustedImm64(tag << 32),
- Assembler::ReturnValueRegister);
- done.link(_as);
- } else {
- _as->zeroExtend32ToPtr((Assembler::RegisterID) t->index, Assembler::ReturnValueRegister);
- quint64 tag;
- switch (t->type) {
- case IR::SInt32Type:
- tag = QV4::Value::Integer_Type_Internal;
- break;
- case IR::BoolType:
- tag = QV4::Value::Boolean_Type_Internal;
- break;
- default:
- tag = 31337; // bogus value
- Q_UNREACHABLE();
- }
- _as->or64(Assembler::TrustedImm64(tag << 32),
- Assembler::ReturnValueRegister);
- }
- } else {
- _as->copyValue(Assembler::ReturnValueRegister, t);
- }
-#endif
- } else if (IR::Const *c = s->expr->asConst()) {
- QV4::Primitive retVal = convertToValue(c);
-#if CPU(X86)
- _as->move(Assembler::TrustedImm32(retVal.int_32()), JSC::X86Registers::eax);
- _as->move(Assembler::TrustedImm32(retVal.tag()), JSC::X86Registers::edx);
-#elif CPU(ARM)
- _as->move(Assembler::TrustedImm32(retVal.int_32()), JSC::ARMRegisters::r0);
- _as->move(Assembler::TrustedImm32(retVal.tag()), JSC::ARMRegisters::r1);
-#elif CPU(MIPS)
- _as->move(Assembler::TrustedImm32(retVal.int_32()), JSC::MIPSRegisters::v0);
- _as->move(Assembler::TrustedImm32(retVal.tag()), JSC::MIPSRegisters::v1);
-#else
- _as->move(Assembler::TrustedImm64(retVal.rawValue()), Assembler::ReturnValueRegister);
-#endif
- } else {
- Q_UNREACHABLE();
- Q_UNUSED(s);
- }
-
- Assembler::Label leaveStackFrame = _as->label();
-
- const int locals = _as->stackLayout().calculateJSStackFrameSize();
- _as->subPtr(Assembler::TrustedImm32(sizeof(QV4::Value)*locals), Assembler::LocalsRegister);
- _as->loadPtr(Address(Assembler::EngineRegister, qOffsetOf(QV4::ExecutionEngine, current)), Assembler::ScratchRegister);
- _as->loadPtr(Address(Assembler::ScratchRegister, qOffsetOf(ExecutionContext::Data, engine)), Assembler::ScratchRegister);
- _as->storePtr(Assembler::LocalsRegister, Address(Assembler::ScratchRegister, qOffsetOf(ExecutionEngine, jsStackTop)));
-
- _as->leaveStandardStackFrame(regularRegistersToSave, fpRegistersToSave);
- _as->ret();
-
- _as->exceptionReturnLabel = _as->label();
- QV4::Primitive retVal = Primitive::undefinedValue();
-#if CPU(X86)
- _as->move(Assembler::TrustedImm32(retVal.int_32()), JSC::X86Registers::eax);
- _as->move(Assembler::TrustedImm32(retVal.tag()), JSC::X86Registers::edx);
-#elif CPU(ARM)
- _as->move(Assembler::TrustedImm32(retVal.int_32()), JSC::ARMRegisters::r0);
- _as->move(Assembler::TrustedImm32(retVal.tag()), JSC::ARMRegisters::r1);
-#elif CPU(MIPS)
- _as->move(Assembler::TrustedImm32(retVal.int_32()), JSC::MIPSRegisters::v0);
- _as->move(Assembler::TrustedImm32(retVal.tag()), JSC::MIPSRegisters::v1);
-#else
- _as->move(Assembler::TrustedImm64(retVal.rawValue()), Assembler::ReturnValueRegister);
-#endif
- _as->jump(leaveStackFrame);
+ _as->returnFromFunction(s, regularRegistersToSave, fpRegistersToSave);
}
-int InstructionSelection::prepareVariableArguments(IR::ExprList* args)
+template <typename JITAssembler>
+int InstructionSelection<JITAssembler>::prepareVariableArguments(IR::ExprList* args)
{
int argc = 0;
for (IR::ExprList *it = args; it; it = it->next) {
@@ -1668,7 +1297,7 @@ int InstructionSelection::prepareVariableArguments(IR::ExprList* args)
Q_ASSERT(arg != 0);
Pointer dst(_as->stackLayout().argumentAddressForCall(i));
if (arg->asTemp() && arg->asTemp()->kind != IR::Temp::PhysicalRegister)
- _as->memcopyValue(dst, arg->asTemp(), Assembler::ScratchRegister);
+ _as->memcopyValue(dst, arg->asTemp(), JITTargetPlatform::ScratchRegister);
else
_as->copyValue(dst, arg);
}
@@ -1676,7 +1305,8 @@ int InstructionSelection::prepareVariableArguments(IR::ExprList* args)
return argc;
}
-int InstructionSelection::prepareCallData(IR::ExprList* args, IR::Expr *thisObject)
+template <typename JITAssembler>
+int InstructionSelection<JITAssembler>::prepareCallData(IR::ExprList* args, IR::Expr *thisObject)
{
int argc = 0;
for (IR::ExprList *it = args; it; it = it->next) {
@@ -1684,9 +1314,9 @@ int InstructionSelection::prepareCallData(IR::ExprList* args, IR::Expr *thisObje
}
Pointer p = _as->stackLayout().callDataAddress(qOffsetOf(CallData, tag));
- _as->store32(Assembler::TrustedImm32(QV4::Value::Integer_Type_Internal), p);
+ _as->store32(TrustedImm32(QV4::Value::Integer_Type_Internal), p);
p = _as->stackLayout().callDataAddress(qOffsetOf(CallData, argc));
- _as->store32(Assembler::TrustedImm32(argc), p);
+ _as->store32(TrustedImm32(argc), p);
p = _as->stackLayout().callDataAddress(qOffsetOf(CallData, thisObject));
if (!thisObject)
_as->storeValue(QV4::Primitive::undefinedValue(), p);
@@ -1699,25 +1329,24 @@ int InstructionSelection::prepareCallData(IR::ExprList* args, IR::Expr *thisObje
Q_ASSERT(arg != 0);
Pointer dst(_as->stackLayout().argumentAddressForCall(i));
if (arg->asTemp() && arg->asTemp()->kind != IR::Temp::PhysicalRegister)
- _as->memcopyValue(dst, arg->asTemp(), Assembler::ScratchRegister);
+ _as->memcopyValue(dst, arg->asTemp(), JITTargetPlatform::ScratchRegister);
else
_as->copyValue(dst, arg);
}
return argc;
}
-void InstructionSelection::calculateRegistersToSave(const RegisterInformation &used)
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::calculateRegistersToSave(const RegisterInformation &used)
{
regularRegistersToSave.clear();
fpRegistersToSave.clear();
- for (const RegisterInfo &ri : Assembler::getRegisterInfo()) {
-#if defined(RESTORE_EBX_ON_CALL)
- if (ri.isRegularRegister() && ri.reg<JSC::X86Registers::RegisterID>() == JSC::X86Registers::ebx) {
+ for (const RegisterInfo &ri : JITTargetPlatform::getRegisterInfo()) {
+ if (JITTargetPlatform::gotRegister != -1 && ri.isRegularRegister() && ri.reg<RegisterID>() == JITTargetPlatform::gotRegister) {
regularRegistersToSave.append(ri);
continue;
}
-#endif // RESTORE_EBX_ON_CALL
if (ri.isCallerSaved())
continue;
if (ri.isRegularRegister()) {
@@ -1740,35 +1369,38 @@ bool operator==(const Primitive &v1, const Primitive &v2)
} // QV4 namespace
QT_END_NAMESPACE
-bool InstructionSelection::visitCJumpDouble(IR::AluOp op, IR::Expr *left, IR::Expr *right,
+template <typename JITAssembler>
+bool InstructionSelection<JITAssembler>::visitCJumpDouble(IR::AluOp op, IR::Expr *left, IR::Expr *right,
IR::BasicBlock *iftrue, IR::BasicBlock *iffalse)
{
if (_as->nextBlock() == iftrue) {
- Assembler::Jump target = _as->branchDouble(true, op, left, right);
+ Jump target = _as->branchDouble(true, op, left, right);
_as->addPatch(iffalse, target);
} else {
- Assembler::Jump target = _as->branchDouble(false, op, left, right);
+ Jump target = _as->branchDouble(false, op, left, right);
_as->addPatch(iftrue, target);
_as->jumpToBlock(_block, iffalse);
}
return true;
}
-bool InstructionSelection::visitCJumpSInt32(IR::AluOp op, IR::Expr *left, IR::Expr *right,
+template <typename JITAssembler>
+bool InstructionSelection<JITAssembler>::visitCJumpSInt32(IR::AluOp op, IR::Expr *left, IR::Expr *right,
IR::BasicBlock *iftrue, IR::BasicBlock *iffalse)
{
if (_as->nextBlock() == iftrue) {
- Assembler::Jump target = _as->branchInt32(true, op, left, right);
+ Jump target = _as->branchInt32(true, op, left, right);
_as->addPatch(iffalse, target);
} else {
- Assembler::Jump target = _as->branchInt32(false, op, left, right);
+ Jump target = _as->branchInt32(false, op, left, right);
_as->addPatch(iftrue, target);
_as->jumpToBlock(_block, iffalse);
}
return true;
}
-void InstructionSelection::visitCJumpStrict(IR::Binop *binop, IR::BasicBlock *trueBlock,
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::visitCJumpStrict(IR::Binop *binop, IR::BasicBlock *trueBlock,
IR::BasicBlock *falseBlock)
{
Q_ASSERT(binop->op == IR::OpStrictEqual || binop->op == IR::OpStrictNotEqual);
@@ -1783,15 +1415,16 @@ void InstructionSelection::visitCJumpStrict(IR::Binop *binop, IR::BasicBlock *tr
IR::Expr *left = binop->left;
IR::Expr *right = binop->right;
- generateRuntimeCall(Assembler::ReturnValueRegister, compareStrictEqual,
- Assembler::PointerToValue(left), Assembler::PointerToValue(right));
- _as->generateCJumpOnCompare(binop->op == IR::OpStrictEqual ? Assembler::NotEqual : Assembler::Equal,
- Assembler::ReturnValueRegister, Assembler::TrustedImm32(0),
+ generateRuntimeCall(_as, JITTargetPlatform::ReturnValueRegister, compareStrictEqual,
+ PointerToValue(left), PointerToValue(right));
+ _as->generateCJumpOnCompare(binop->op == IR::OpStrictEqual ? RelationalCondition::NotEqual : RelationalCondition::Equal,
+ JITTargetPlatform::ReturnValueRegister, TrustedImm32(0),
_block, trueBlock, falseBlock);
}
// Only load the non-null temp.
-bool InstructionSelection::visitCJumpStrictNull(IR::Binop *binop,
+template <typename JITAssembler>
+bool InstructionSelection<JITAssembler>::visitCJumpStrictNull(IR::Binop *binop,
IR::BasicBlock *trueBlock,
IR::BasicBlock *falseBlock)
{
@@ -1816,19 +1449,20 @@ bool InstructionSelection::visitCJumpStrictNull(IR::Binop *binop,
return true;
}
- Assembler::Pointer tagAddr = _as->loadAddress(Assembler::ScratchRegister, varSrc);
+ Pointer tagAddr = _as->loadAddress(JITTargetPlatform::ScratchRegister, varSrc);
tagAddr.offset += 4;
- const Assembler::RegisterID tagReg = Assembler::ScratchRegister;
+ const RegisterID tagReg = JITTargetPlatform::ScratchRegister;
_as->load32(tagAddr, tagReg);
- Assembler::RelationalCondition cond = binop->op == IR::OpStrictEqual ? Assembler::Equal
- : Assembler::NotEqual;
- const Assembler::TrustedImm32 tag(QV4::Value::Null_Type_Internal);
+ RelationalCondition cond = binop->op == IR::OpStrictEqual ? RelationalCondition::Equal
+ : RelationalCondition::NotEqual;
+ const TrustedImm32 tag(QV4::Value::Null_Type_Internal);
_as->generateCJumpOnCompare(cond, tagReg, tag, _block, trueBlock, falseBlock);
return true;
}
-bool InstructionSelection::visitCJumpStrictUndefined(IR::Binop *binop,
+template <typename JITAssembler>
+bool InstructionSelection<JITAssembler>::visitCJumpStrictUndefined(IR::Binop *binop,
IR::BasicBlock *trueBlock,
IR::BasicBlock *falseBlock)
{
@@ -1853,28 +1487,15 @@ bool InstructionSelection::visitCJumpStrictUndefined(IR::Binop *binop,
return true;
}
- Assembler::RelationalCondition cond = binop->op == IR::OpStrictEqual ? Assembler::Equal
- : Assembler::NotEqual;
- const Assembler::RegisterID tagReg = Assembler::ReturnValueRegister;
-#ifdef QV4_USE_64_BIT_VALUE_ENCODING
- Assembler::Pointer addr = _as->loadAddress(Assembler::ScratchRegister, varSrc);
- _as->load64(addr, tagReg);
- const Assembler::TrustedImm64 tag(0);
-#else // !QV4_USE_64_BIT_VALUE_ENCODING
- Assembler::Pointer tagAddr = _as->loadAddress(Assembler::ScratchRegister, varSrc);
- _as->load32(tagAddr, tagReg);
- Assembler::Jump j = _as->branch32(Assembler::invert(cond), tagReg, Assembler::TrustedImm32(0));
- _as->addPatch(falseBlock, j);
-
- tagAddr.offset += 4;
- _as->load32(tagAddr, tagReg);
- const Assembler::TrustedImm32 tag(QV4::Value::Managed_Type_Internal);
-#endif
- _as->generateCJumpOnCompare(cond, tagReg, tag, _block, trueBlock, falseBlock);
+ RelationalCondition cond = binop->op == IR::OpStrictEqual ? RelationalCondition::Equal
+ : RelationalCondition::NotEqual;
+ const RegisterID tagReg = JITTargetPlatform::ReturnValueRegister;
+ _as->generateCJumpOnUndefined(cond, varSrc, JITTargetPlatform::ScratchRegister, tagReg, _block, trueBlock, falseBlock);
return true;
}
-bool InstructionSelection::visitCJumpStrictBool(IR::Binop *binop, IR::BasicBlock *trueBlock,
+template <typename JITAssembler>
+bool InstructionSelection<JITAssembler>::visitCJumpStrictBool(IR::Binop *binop, IR::BasicBlock *trueBlock,
IR::BasicBlock *falseBlock)
{
IR::Expr *boolSrc = 0, *otherSrc = 0;
@@ -1888,13 +1509,20 @@ bool InstructionSelection::visitCJumpStrictBool(IR::Binop *binop, IR::BasicBlock
// neither operands are statically typed as bool, so bail out.
return false;
}
+ if (otherSrc->type == IR::UnknownType) {
+ // Ok, we really need to call into the runtime.
+ // (This case doesn't happen when the optimizer ran, because everything will be typed (yes,
+ // possibly as "var" meaning anything), but it does happen for $0===true, which is generated
+ // for things where the optimizer didn't run (like functions with a try block).)
+ return false;
+ }
- Assembler::RelationalCondition cond = binop->op == IR::OpStrictEqual ? Assembler::Equal
- : Assembler::NotEqual;
+ RelationalCondition cond = binop->op == IR::OpStrictEqual ? RelationalCondition::Equal
+ : RelationalCondition::NotEqual;
if (otherSrc->type == IR::BoolType) { // both are boolean
- Assembler::RegisterID one = _as->toBoolRegister(boolSrc, Assembler::ReturnValueRegister);
- Assembler::RegisterID two = _as->toBoolRegister(otherSrc, Assembler::ScratchRegister);
+ RegisterID one = _as->toBoolRegister(boolSrc, JITTargetPlatform::ReturnValueRegister);
+ RegisterID two = _as->toBoolRegister(otherSrc, JITTargetPlatform::ScratchRegister);
_as->generateCJumpOnCompare(cond, one, two, _block, trueBlock, falseBlock);
return true;
}
@@ -1904,13 +1532,13 @@ bool InstructionSelection::visitCJumpStrictBool(IR::Binop *binop, IR::BasicBlock
return true;
}
- Assembler::Pointer otherAddr = _as->loadAddress(Assembler::ReturnValueRegister, otherSrc);
+ Pointer otherAddr = _as->loadAddress(JITTargetPlatform::ReturnValueRegister, otherSrc);
otherAddr.offset += 4; // tag address
// check if the tag of the var operand is indicates 'boolean'
- _as->load32(otherAddr, Assembler::ScratchRegister);
- Assembler::Jump noBool = _as->branch32(Assembler::NotEqual, Assembler::ScratchRegister,
- Assembler::TrustedImm32(QV4::Value::Boolean_Type_Internal));
+ _as->load32(otherAddr, JITTargetPlatform::ScratchRegister);
+ Jump noBool = _as->branch32(RelationalCondition::NotEqual, JITTargetPlatform::ScratchRegister,
+ TrustedImm32(QV4::Value::Boolean_Type_Internal));
if (binop->op == IR::OpStrictEqual)
_as->addPatch(falseBlock, noBool);
else
@@ -1918,14 +1546,15 @@ bool InstructionSelection::visitCJumpStrictBool(IR::Binop *binop, IR::BasicBlock
// ok, both are boolean, so let's load them and compare them.
otherAddr.offset -= 4; // int_32 address
- _as->load32(otherAddr, Assembler::ReturnValueRegister);
- Assembler::RegisterID boolReg = _as->toBoolRegister(boolSrc, Assembler::ScratchRegister);
- _as->generateCJumpOnCompare(cond, boolReg, Assembler::ReturnValueRegister, _block, trueBlock,
+ _as->load32(otherAddr, JITTargetPlatform::ReturnValueRegister);
+ RegisterID boolReg = _as->toBoolRegister(boolSrc, JITTargetPlatform::ScratchRegister);
+ _as->generateCJumpOnCompare(cond, boolReg, JITTargetPlatform::ReturnValueRegister, _block, trueBlock,
falseBlock);
return true;
}
-bool InstructionSelection::visitCJumpNullUndefined(IR::Type nullOrUndef, IR::Binop *binop,
+template <typename JITAssembler>
+bool InstructionSelection<JITAssembler>::visitCJumpNullUndefined(IR::Type nullOrUndef, IR::Binop *binop,
IR::BasicBlock *trueBlock,
IR::BasicBlock *falseBlock)
{
@@ -1952,18 +1581,18 @@ bool InstructionSelection::visitCJumpNullUndefined(IR::Type nullOrUndef, IR::Bin
return true;
}
- Assembler::Pointer tagAddr = _as->loadAddress(Assembler::ScratchRegister, varSrc);
+ Pointer tagAddr = _as->loadAddress(JITTargetPlatform::ScratchRegister, varSrc);
tagAddr.offset += 4;
- const Assembler::RegisterID tagReg = Assembler::ReturnValueRegister;
+ const RegisterID tagReg = JITTargetPlatform::ReturnValueRegister;
_as->load32(tagAddr, tagReg);
if (binop->op == IR::OpNotEqual)
qSwap(trueBlock, falseBlock);
- Assembler::Jump isNull = _as->branch32(Assembler::Equal, tagReg, Assembler::TrustedImm32(int(QV4::Value::Null_Type_Internal)));
- Assembler::Jump isNotUndefinedTag = _as->branch32(Assembler::NotEqual, tagReg, Assembler::TrustedImm32(int(QV4::Value::Managed_Type_Internal)));
+ Jump isNull = _as->branch32(RelationalCondition::Equal, tagReg, TrustedImm32(int(QV4::Value::Null_Type_Internal)));
+ Jump isNotUndefinedTag = _as->branch32(RelationalCondition::NotEqual, tagReg, TrustedImm32(int(QV4::Value::Managed_Type_Internal)));
tagAddr.offset -= 4;
_as->load32(tagAddr, tagReg);
- Assembler::Jump isNotUndefinedValue = _as->branch32(Assembler::NotEqual, tagReg, Assembler::TrustedImm32(0));
+ Jump isNotUndefinedValue = _as->branch32(RelationalCondition::NotEqual, tagReg, TrustedImm32(0));
_as->addPatch(trueBlock, isNull);
_as->addPatch(falseBlock, isNotUndefinedTag);
_as->addPatch(falseBlock, isNotUndefinedValue);
@@ -1973,7 +1602,8 @@ bool InstructionSelection::visitCJumpNullUndefined(IR::Type nullOrUndef, IR::Bin
}
-void InstructionSelection::visitCJumpEqual(IR::Binop *binop, IR::BasicBlock *trueBlock,
+template <typename JITAssembler>
+void InstructionSelection<JITAssembler>::visitCJumpEqual(IR::Binop *binop, IR::BasicBlock *trueBlock,
IR::BasicBlock *falseBlock)
{
Q_ASSERT(binop->op == IR::OpEqual || binop->op == IR::OpNotEqual);
@@ -1984,18 +1614,55 @@ void InstructionSelection::visitCJumpEqual(IR::Binop *binop, IR::BasicBlock *tru
IR::Expr *left = binop->left;
IR::Expr *right = binop->right;
- generateRuntimeCall(Assembler::ReturnValueRegister, compareEqual,
- Assembler::PointerToValue(left), Assembler::PointerToValue(right));
- _as->generateCJumpOnCompare(binop->op == IR::OpEqual ? Assembler::NotEqual : Assembler::Equal,
- Assembler::ReturnValueRegister, Assembler::TrustedImm32(0),
+ generateRuntimeCall(_as, JITTargetPlatform::ReturnValueRegister, compareEqual,
+ PointerToValue(left), PointerToValue(right));
+ _as->generateCJumpOnCompare(binop->op == IR::OpEqual ? RelationalCondition::NotEqual : RelationalCondition::Equal,
+ JITTargetPlatform::ReturnValueRegister, TrustedImm32(0),
_block, trueBlock, falseBlock);
}
-QQmlRefPointer<CompiledData::CompilationUnit> ISelFactory::createUnitForLoading()
+template <typename JITAssembler>
+QQmlRefPointer<CompiledData::CompilationUnit> ISelFactory<JITAssembler>::createUnitForLoading()
{
QQmlRefPointer<CompiledData::CompilationUnit> result;
result.adopt(new JIT::CompilationUnit);
return result;
}
+QT_BEGIN_NAMESPACE
+namespace QV4 { namespace JIT {
+template class Q_QML_EXPORT InstructionSelection<>;
+template class Q_QML_EXPORT ISelFactory<>;
+#if defined(V4_BOOTSTRAP)
+
+Q_QML_EXPORT QV4::EvalISelFactory *createISelForArchitecture(const QString &architecture)
+{
+ using ARMv7CrossAssembler = QV4::JIT::Assembler<AssemblerTargetConfiguration<JSC::MacroAssemblerARMv7, NoOperatingSystemSpecialization>>;
+ using ARM64CrossAssembler = QV4::JIT::Assembler<AssemblerTargetConfiguration<JSC::MacroAssemblerARM64, NoOperatingSystemSpecialization>>;
+
+ if (architecture == QLatin1String("armv7"))
+ return new ISelFactory<ARMv7CrossAssembler>;
+ else if (architecture == QLatin1String("armv8"))
+ return new ISelFactory<ARM64CrossAssembler>;
+
+ QString hostArch;
+#if CPU(ARM_THUMB2)
+ hostArch = QStringLiteral("armv7");
+#elif CPU(MIPS)
+ hostArch = QStringLiteral("mips");
+#elif CPU(X86)
+ hostArch = QStringLiteral("x86");
+#elif CPU(X86_64)
+ hostArch = QStringLiteral("x86_64");
+#endif
+ if (!hostArch.isEmpty() && architecture == hostArch)
+ return new ISelFactory<>;
+
+ return nullptr;
+}
+
+#endif
+} }
+QT_END_NAMESPACE
+
#endif // ENABLE(ASSEMBLER)
diff --git a/src/qml/jit/qv4isel_masm_p.h b/src/qml/jit/qv4isel_masm_p.h
index b6ddd3c1c9..5c046cb397 100644
--- a/src/qml/jit/qv4isel_masm_p.h
+++ b/src/qml/jit/qv4isel_masm_p.h
@@ -54,6 +54,7 @@
#include "private/qv4jsir_p.h"
#include "private/qv4isel_p.h"
#include "private/qv4isel_util_p.h"
+#include "private/qv4util_p.h"
#include "private/qv4value_p.h"
#include "private/qv4lookup_p.h"
@@ -71,6 +72,7 @@ QT_BEGIN_NAMESPACE
namespace QV4 {
namespace JIT {
+template <typename JITAssembler = Assembler<DefaultAssemblerTargetConfiguration>>
class Q_QML_EXPORT InstructionSelection:
protected IR::IRDecoder,
public EvalInstructionSelection
@@ -79,74 +81,87 @@ public:
InstructionSelection(QQmlEnginePrivate *qmlEngine, QV4::ExecutableAllocator *execAllocator, IR::Module *module, QV4::Compiler::JSUnitGenerator *jsGenerator, EvalISelFactory *iselFactory);
~InstructionSelection();
- virtual void run(int functionIndex);
+ void run(int functionIndex) override;
protected:
- virtual QQmlRefPointer<QV4::CompiledData::CompilationUnit> backendCompileStep();
-
- virtual void callBuiltinInvalid(IR::Name *func, IR::ExprList *args, IR::Expr *result);
- virtual void callBuiltinTypeofQmlContextProperty(IR::Expr *base, IR::Member::MemberKind kind, int propertyIndex, IR::Expr *result);
- virtual void callBuiltinTypeofMember(IR::Expr *base, const QString &name, IR::Expr *result);
- virtual void callBuiltinTypeofSubscript(IR::Expr *base, IR::Expr *index, IR::Expr *result);
- virtual void callBuiltinTypeofName(const QString &name, IR::Expr *result);
- virtual void callBuiltinTypeofValue(IR::Expr *value, IR::Expr *result);
- virtual void callBuiltinDeleteMember(IR::Expr *base, const QString &name, IR::Expr *result);
- virtual void callBuiltinDeleteSubscript(IR::Expr *base, IR::Expr *index, IR::Expr *result);
- virtual void callBuiltinDeleteName(const QString &name, IR::Expr *result);
- virtual void callBuiltinDeleteValue(IR::Expr *result);
- virtual void callBuiltinThrow(IR::Expr *arg);
- virtual void callBuiltinReThrow();
- virtual void callBuiltinUnwindException(IR::Expr *);
- virtual void callBuiltinPushCatchScope(const QString &exceptionName);
- virtual void callBuiltinForeachIteratorObject(IR::Expr *arg, IR::Expr *result);
- virtual void callBuiltinForeachNextPropertyname(IR::Expr *arg, IR::Expr *result);
- virtual void callBuiltinPushWithScope(IR::Expr *arg);
- virtual void callBuiltinPopScope();
- virtual void callBuiltinDeclareVar(bool deletable, const QString &name);
- virtual void callBuiltinDefineArray(IR::Expr *result, IR::ExprList *args);
- virtual void callBuiltinDefineObjectLiteral(IR::Expr *result, int keyValuePairCount, IR::ExprList *keyValuePairs, IR::ExprList *arrayEntries, bool needSparseArray);
- virtual void callBuiltinSetupArgumentObject(IR::Expr *result);
- virtual void callBuiltinConvertThisToObject();
- virtual void callValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result);
- virtual void callQmlContextProperty(IR::Expr *base, IR::Member::MemberKind kind, int propertyIndex, IR::ExprList *args, IR::Expr *result);
- virtual void callProperty(IR::Expr *base, const QString &name, IR::ExprList *args, IR::Expr *result);
- virtual void callSubscript(IR::Expr *base, IR::Expr *index, IR::ExprList *args, IR::Expr *result);
- virtual void convertType(IR::Expr *source, IR::Expr *target);
- virtual void loadThisObject(IR::Expr *temp);
- virtual void loadQmlContext(IR::Expr *target);
- virtual void loadQmlImportedScripts(IR::Expr *target);
- virtual void loadQmlSingleton(const QString &name, IR::Expr *target);
- virtual void loadConst(IR::Const *sourceConst, IR::Expr *target);
- virtual void loadString(const QString &str, IR::Expr *target);
- virtual void loadRegexp(IR::RegExp *sourceRegexp, IR::Expr *target);
- virtual void getActivationProperty(const IR::Name *name, IR::Expr *target);
- virtual void setActivationProperty(IR::Expr *source, const QString &targetName);
- virtual void initClosure(IR::Closure *closure, IR::Expr *target);
- virtual void getProperty(IR::Expr *base, const QString &name, IR::Expr *target);
- virtual void getQmlContextProperty(IR::Expr *source, IR::Member::MemberKind kind, int index, bool captureRequired, IR::Expr *target);
- virtual void getQObjectProperty(IR::Expr *base, int propertyIndex, bool captureRequired, bool isSingleton, int attachedPropertiesId, IR::Expr *target);
- virtual void setProperty(IR::Expr *source, IR::Expr *targetBase, const QString &targetName);
- virtual void setQmlContextProperty(IR::Expr *source, IR::Expr *targetBase, IR::Member::MemberKind kind, int propertyIndex);
- virtual void setQObjectProperty(IR::Expr *source, IR::Expr *targetBase, int propertyIndex);
- virtual void getElement(IR::Expr *base, IR::Expr *index, IR::Expr *target);
- virtual void setElement(IR::Expr *source, IR::Expr *targetBase, IR::Expr *targetIndex);
- virtual void copyValue(IR::Expr *source, IR::Expr *target);
- virtual void swapValues(IR::Expr *source, IR::Expr *target);
- virtual void unop(IR::AluOp oper, IR::Expr *sourceTemp, IR::Expr *target);
- virtual void binop(IR::AluOp oper, IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target);
-
- typedef Assembler::Address Address;
- typedef Assembler::Pointer Pointer;
-
-#if !defined(ARGUMENTS_IN_REGISTERS)
+ QQmlRefPointer<QV4::CompiledData::CompilationUnit> backendCompileStep() override;
+
+ void callBuiltinInvalid(IR::Name *func, IR::ExprList *args, IR::Expr *result) override;
+ void callBuiltinTypeofQmlContextProperty(IR::Expr *base, IR::Member::MemberKind kind, int propertyIndex, IR::Expr *result) override;
+ void callBuiltinTypeofMember(IR::Expr *base, const QString &name, IR::Expr *result) override;
+ void callBuiltinTypeofSubscript(IR::Expr *base, IR::Expr *index, IR::Expr *result) override;
+ void callBuiltinTypeofName(const QString &name, IR::Expr *result) override;
+ void callBuiltinTypeofValue(IR::Expr *value, IR::Expr *result) override;
+ void callBuiltinDeleteMember(IR::Expr *base, const QString &name, IR::Expr *result) override;
+ void callBuiltinDeleteSubscript(IR::Expr *base, IR::Expr *index, IR::Expr *result) override;
+ void callBuiltinDeleteName(const QString &name, IR::Expr *result) override;
+ void callBuiltinDeleteValue(IR::Expr *result) override;
+ void callBuiltinThrow(IR::Expr *arg) override;
+ void callBuiltinReThrow() override;
+ void callBuiltinUnwindException(IR::Expr *) override;
+ void callBuiltinPushCatchScope(const QString &exceptionName) override;
+ void callBuiltinForeachIteratorObject(IR::Expr *arg, IR::Expr *result) override;
+ void callBuiltinForeachNextPropertyname(IR::Expr *arg, IR::Expr *result) override;
+ void callBuiltinPushWithScope(IR::Expr *arg) override;
+ void callBuiltinPopScope() override;
+ void callBuiltinDeclareVar(bool deletable, const QString &name) override;
+ void callBuiltinDefineArray(IR::Expr *result, IR::ExprList *args) override;
+ void callBuiltinDefineObjectLiteral(IR::Expr *result, int keyValuePairCount, IR::ExprList *keyValuePairs, IR::ExprList *arrayEntries, bool needSparseArray) override;
+ void callBuiltinSetupArgumentObject(IR::Expr *result) override;
+ void callBuiltinConvertThisToObject() override;
+ void callValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result) override;
+ void callQmlContextProperty(IR::Expr *base, IR::Member::MemberKind kind, int propertyIndex, IR::ExprList *args, IR::Expr *result) override;
+ void callProperty(IR::Expr *base, const QString &name, IR::ExprList *args, IR::Expr *result) override;
+ void callSubscript(IR::Expr *base, IR::Expr *index, IR::ExprList *args, IR::Expr *result) override;
+ void convertType(IR::Expr *source, IR::Expr *target) override;
+ void loadThisObject(IR::Expr *temp) override;
+ void loadQmlContext(IR::Expr *target) override;
+ void loadQmlImportedScripts(IR::Expr *target) override;
+ void loadQmlSingleton(const QString &name, IR::Expr *target) override;
+ void loadConst(IR::Const *sourceConst, IR::Expr *target) override;
+ void loadString(const QString &str, IR::Expr *target) override;
+ void loadRegexp(IR::RegExp *sourceRegexp, IR::Expr *target) override;
+ void getActivationProperty(const IR::Name *name, IR::Expr *target) override;
+ void setActivationProperty(IR::Expr *source, const QString &targetName) override;
+ void initClosure(IR::Closure *closure, IR::Expr *target) override;
+ void getProperty(IR::Expr *base, const QString &name, IR::Expr *target) override;
+ void getQmlContextProperty(IR::Expr *source, IR::Member::MemberKind kind, int index, bool captureRequired, IR::Expr *target) override;
+ void getQObjectProperty(IR::Expr *base, int propertyIndex, bool captureRequired, bool isSingleton, int attachedPropertiesId, IR::Expr *target) override;
+ void setProperty(IR::Expr *source, IR::Expr *targetBase, const QString &targetName) override;
+ void setQmlContextProperty(IR::Expr *source, IR::Expr *targetBase, IR::Member::MemberKind kind, int propertyIndex) override;
+ void setQObjectProperty(IR::Expr *source, IR::Expr *targetBase, int propertyIndex) override;
+ void getElement(IR::Expr *base, IR::Expr *index, IR::Expr *target) override;
+ void setElement(IR::Expr *source, IR::Expr *targetBase, IR::Expr *targetIndex) override;
+ void copyValue(IR::Expr *source, IR::Expr *target) override;
+ void swapValues(IR::Expr *source, IR::Expr *target) override;
+ void unop(IR::AluOp oper, IR::Expr *sourceTemp, IR::Expr *target) override;
+ void binop(IR::AluOp oper, IR::Expr *leftSource, IR::Expr *rightSource, IR::Expr *target) override;
+
+ using Address = typename JITAssembler::Address;
+ using Pointer = typename JITAssembler::Pointer;
+ using PointerToValue = typename JITAssembler::PointerToValue;
+ using RegisterID = typename JITAssembler::RegisterID;
+ using FPRegisterID = typename JITAssembler::FPRegisterID;
+ using ResultCondition = typename JITAssembler::ResultCondition;
+ using TrustedImm32 = typename JITAssembler::TrustedImm32;
+ using TrustedImm64 = typename JITAssembler::TrustedImm64;
+ using Label = typename JITAssembler::Label;
+ using Jump = typename JITAssembler::Jump;
+ using StringToIndex = typename JITAssembler::StringToIndex;
+ using Reference = typename JITAssembler::Reference;
+ using RelationalCondition = typename JITAssembler::RelationalCondition;
+ using BranchTruncateType = typename JITAssembler::BranchTruncateType;
+ using RuntimeCall = typename JITAssembler::RuntimeCall;
+
+ using JITTargetPlatform = typename JITAssembler::JITTargetPlatform;
+
Address addressForArgument(int index) const
{
// FramePointerRegister points to its old value on the stack, and above
// it we have the return address, hence the need to step over two
// values before reaching the first argument.
- return Address(Assembler::FramePointerRegister, (index + 2) * sizeof(void*));
+ return Address(JITTargetPlatform::FramePointerRegister, (index + 2) * sizeof(void*));
}
-#endif
Pointer baseAddressForCallArguments()
{
@@ -158,13 +173,13 @@ protected:
return _as->stackLayout().callDataAddress();
}
- virtual void constructActivationProperty(IR::Name *func, IR::ExprList *args, IR::Expr *result);
- virtual void constructProperty(IR::Expr *base, const QString &name, IR::ExprList *args, IR::Expr*result);
- virtual void constructValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result);
+ void constructActivationProperty(IR::Name *func, IR::ExprList *args, IR::Expr *result) override;
+ void constructProperty(IR::Expr *base, const QString &name, IR::ExprList *args, IR::Expr*result) override;
+ void constructValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result) override;
- virtual void visitJump(IR::Jump *);
- virtual void visitCJump(IR::CJump *);
- virtual void visitRet(IR::Ret *);
+ void visitJump(IR::Jump *) override;
+ void visitCJump(IR::CJump *) override;
+ void visitRet(IR::Ret *) override;
bool visitCJumpDouble(IR::AluOp op, IR::Expr *left, IR::Expr *right,
IR::BasicBlock *iftrue, IR::BasicBlock *iffalse);
@@ -191,61 +206,55 @@ private:
if (targetTemp->kind == IR::Temp::PhysicalRegister) {
if (IR::Temp *sourceTemp = source->asTemp()) {
if (sourceTemp->kind == IR::Temp::PhysicalRegister) {
- _as->convertInt32ToDouble((Assembler::RegisterID) sourceTemp->index,
- (Assembler::FPRegisterID) targetTemp->index);
+ _as->convertInt32ToDouble((RegisterID) sourceTemp->index,
+ (FPRegisterID) targetTemp->index);
} else {
- _as->convertInt32ToDouble(_as->loadAddress(Assembler::ReturnValueRegister, sourceTemp),
- (Assembler::FPRegisterID) targetTemp->index);
+ _as->convertInt32ToDouble(_as->loadAddress(JITTargetPlatform::ReturnValueRegister, sourceTemp),
+ (FPRegisterID) targetTemp->index);
}
} else {
- _as->convertInt32ToDouble(_as->toInt32Register(source, Assembler::ScratchRegister),
- (Assembler::FPRegisterID) targetTemp->index);
+ _as->convertInt32ToDouble(_as->toInt32Register(source, JITTargetPlatform::ScratchRegister),
+ (FPRegisterID) targetTemp->index);
}
return;
}
}
- _as->convertInt32ToDouble(_as->toInt32Register(source, Assembler::ScratchRegister),
- Assembler::FPGpr0);
- _as->storeDouble(Assembler::FPGpr0, _as->loadAddress(Assembler::ReturnValueRegister, target));
+ _as->convertInt32ToDouble(_as->toInt32Register(source, JITTargetPlatform::ScratchRegister),
+ JITTargetPlatform::FPGpr0);
+ _as->storeDouble(JITTargetPlatform::FPGpr0, _as->loadAddress(JITTargetPlatform::ReturnValueRegister, target));
}
void convertUIntToDouble(IR::Expr *source, IR::Expr *target)
{
- Assembler::RegisterID tmpReg = Assembler::ScratchRegister;
- Assembler::RegisterID reg = _as->toInt32Register(source, tmpReg);
+ RegisterID tmpReg = JITTargetPlatform::ScratchRegister;
+ RegisterID reg = _as->toInt32Register(source, tmpReg);
if (IR::Temp *targetTemp = target->asTemp()) {
if (targetTemp->kind == IR::Temp::PhysicalRegister) {
- _as->convertUInt32ToDouble(reg, (Assembler::FPRegisterID) targetTemp->index, tmpReg);
+ _as->convertUInt32ToDouble(reg, (FPRegisterID) targetTemp->index, tmpReg);
return;
}
}
_as->convertUInt32ToDouble(_as->toUInt32Register(source, tmpReg),
- Assembler::FPGpr0, tmpReg);
- _as->storeDouble(Assembler::FPGpr0, _as->loadAddress(tmpReg, target));
+ JITTargetPlatform::FPGpr0, tmpReg);
+ _as->storeDouble(JITTargetPlatform::FPGpr0, _as->loadAddress(tmpReg, target));
}
void convertIntToBool(IR::Expr *source, IR::Expr *target)
{
- Assembler::RegisterID reg = Assembler::ScratchRegister;
+ RegisterID reg = JITTargetPlatform::ScratchRegister;
if (IR::Temp *targetTemp = target->asTemp())
if (targetTemp->kind == IR::Temp::PhysicalRegister)
- reg = (Assembler::RegisterID) targetTemp->index;
+ reg = (RegisterID) targetTemp->index;
_as->move(_as->toInt32Register(source, reg), reg);
- _as->compare32(Assembler::NotEqual, reg, Assembler::TrustedImm32(0), reg);
+ _as->compare32(RelationalCondition::NotEqual, reg, TrustedImm32(0), reg);
_as->storeBool(reg, target);
}
- #define isel_stringIfyx(s) #s
- #define isel_stringIfy(s) isel_stringIfyx(s)
-
- #define generateRuntimeCall(t, function, ...) \
- _as->generateFunctionCallImp(Runtime::Method_##function##_NeedsExceptionCheck, t, "Runtime::" isel_stringIfy(function), RuntimeCall(qOffsetOf(QV4::Runtime, function)), __VA_ARGS__)
-
int prepareVariableArguments(IR::ExprList* args);
int prepareCallData(IR::ExprList* args, IR::Expr *thisObject);
@@ -258,22 +267,22 @@ private:
// goes into the same register as the return value (currently only ARM), the prepareCall
// will combine loading the looupAddr into the register and calculating the indirect call
// address.
- Assembler::Pointer lookupAddr(Assembler::ReturnValueRegister, index * sizeof(QV4::Lookup));
+ Pointer lookupAddr(JITTargetPlatform::ReturnValueRegister, index * sizeof(QV4::Lookup));
_as->generateFunctionCallImp(true, retval, "lookup getter/setter",
- LookupCall(lookupAddr, getterSetterOffset), lookupAddr,
+ typename JITAssembler::LookupCall(lookupAddr, getterSetterOffset), lookupAddr,
arg1, arg2, arg3);
}
template <typename Retval, typename Arg1, typename Arg2>
void generateLookupCall(Retval retval, uint index, uint getterSetterOffset, Arg1 arg1, Arg2 arg2)
{
- generateLookupCall(retval, index, getterSetterOffset, arg1, arg2, Assembler::VoidType());
+ generateLookupCall(retval, index, getterSetterOffset, arg1, arg2, typename JITAssembler::VoidType());
}
IR::BasicBlock *_block;
- QSet<IR::Jump *> _removableJumps;
- Assembler* _as;
+ BitVector _removableJumps;
+ JITAssembler* _as;
QScopedPointer<CompilationUnit> compilationUnit;
QQmlEnginePrivate *qmlEngine;
@@ -281,13 +290,14 @@ private:
RegisterInformation fpRegistersToSave;
};
+template <typename JITAssembler = Assembler<DefaultAssemblerTargetConfiguration>>
class Q_QML_EXPORT ISelFactory: public EvalISelFactory
{
public:
ISelFactory() : EvalISelFactory(QStringLiteral("jit")) {}
virtual ~ISelFactory() {}
EvalInstructionSelection *create(QQmlEnginePrivate *qmlEngine, QV4::ExecutableAllocator *execAllocator, IR::Module *module, QV4::Compiler::JSUnitGenerator *jsGenerator) Q_DECL_OVERRIDE Q_DECL_FINAL
- { return new InstructionSelection(qmlEngine, execAllocator, module, jsGenerator, this); }
+ { return new InstructionSelection<JITAssembler>(qmlEngine, execAllocator, module, jsGenerator, this); }
bool jitCompileRegexps() const Q_DECL_OVERRIDE Q_DECL_FINAL
{ return true; }
QQmlRefPointer<CompiledData::CompilationUnit> createUnitForLoading() Q_DECL_OVERRIDE Q_DECL_FINAL;
diff --git a/src/qml/jit/qv4regalloc.cpp b/src/qml/jit/qv4regalloc.cpp
index d49fae3096..8eafaaaa8a 100644
--- a/src/qml/jit/qv4regalloc.cpp
+++ b/src/qml/jit/qv4regalloc.cpp
@@ -272,32 +272,32 @@ public:
}
protected: // IRDecoder
- virtual void callBuiltinInvalid(IR::Name *, IR::ExprList *, IR::Expr *) {}
- virtual void callBuiltinTypeofQmlContextProperty(IR::Expr *, IR::Member::MemberKind, int, IR::Expr *) {}
- virtual void callBuiltinTypeofMember(IR::Expr *, const QString &, IR::Expr *) {}
- virtual void callBuiltinTypeofSubscript(IR::Expr *, IR::Expr *, IR::Expr *) {}
- virtual void callBuiltinTypeofName(const QString &, IR::Expr *) {}
- virtual void callBuiltinTypeofValue(IR::Expr *, IR::Expr *) {}
- virtual void callBuiltinDeleteMember(IR::Expr *, const QString &, IR::Expr *) {}
- virtual void callBuiltinDeleteSubscript(IR::Expr *, IR::Expr *, IR::Expr *) {}
- virtual void callBuiltinDeleteName(const QString &, IR::Expr *) {}
- virtual void callBuiltinDeleteValue(IR::Expr *) {}
- virtual void callBuiltinThrow(IR::Expr *) {}
- virtual void callBuiltinReThrow() {}
- virtual void callBuiltinUnwindException(IR::Expr *) {}
- virtual void callBuiltinPushCatchScope(const QString &) {};
- virtual void callBuiltinForeachIteratorObject(IR::Expr *, IR::Expr *) {}
+ void callBuiltinInvalid(IR::Name *, IR::ExprList *, IR::Expr *) override {}
+ void callBuiltinTypeofQmlContextProperty(IR::Expr *, IR::Member::MemberKind, int, IR::Expr *) override {}
+ void callBuiltinTypeofMember(IR::Expr *, const QString &, IR::Expr *) override {}
+ void callBuiltinTypeofSubscript(IR::Expr *, IR::Expr *, IR::Expr *) override {}
+ void callBuiltinTypeofName(const QString &, IR::Expr *) override {}
+ void callBuiltinTypeofValue(IR::Expr *, IR::Expr *) override {}
+ void callBuiltinDeleteMember(IR::Expr *, const QString &, IR::Expr *) override {}
+ void callBuiltinDeleteSubscript(IR::Expr *, IR::Expr *, IR::Expr *) override {}
+ void callBuiltinDeleteName(const QString &, IR::Expr *) override {}
+ void callBuiltinDeleteValue(IR::Expr *) override {}
+ void callBuiltinThrow(IR::Expr *) override {}
+ void callBuiltinReThrow() override {}
+ void callBuiltinUnwindException(IR::Expr *) override {}
+ void callBuiltinPushCatchScope(const QString &) override {};
+ void callBuiltinForeachIteratorObject(IR::Expr *, IR::Expr *) override {}
virtual void callBuiltinForeachNextProperty(IR::Temp *, IR::Temp *) {}
- virtual void callBuiltinForeachNextPropertyname(IR::Expr *, IR::Expr *) {}
- virtual void callBuiltinPushWithScope(IR::Expr *) {}
- virtual void callBuiltinPopScope() {}
- virtual void callBuiltinDeclareVar(bool , const QString &) {}
- virtual void callBuiltinDefineArray(IR::Expr *, IR::ExprList *) {}
- virtual void callBuiltinDefineObjectLiteral(IR::Expr *, int, IR::ExprList *, IR::ExprList *, bool) {}
- virtual void callBuiltinSetupArgumentObject(IR::Expr *) {}
- virtual void callBuiltinConvertThisToObject() {}
+ void callBuiltinForeachNextPropertyname(IR::Expr *, IR::Expr *) override {}
+ void callBuiltinPushWithScope(IR::Expr *) override {}
+ void callBuiltinPopScope() override {}
+ void callBuiltinDeclareVar(bool , const QString &) override {}
+ void callBuiltinDefineArray(IR::Expr *, IR::ExprList *) override {}
+ void callBuiltinDefineObjectLiteral(IR::Expr *, int, IR::ExprList *, IR::ExprList *, bool) override {}
+ void callBuiltinSetupArgumentObject(IR::Expr *) override {}
+ void callBuiltinConvertThisToObject() override {}
- virtual void callValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result)
+ void callValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result) override
{
addDef(result);
if (IR::Temp *tempValue = value->asTemp())
@@ -306,7 +306,8 @@ protected: // IRDecoder
addCall();
}
- virtual void callQmlContextProperty(IR::Expr *base, IR::Member::MemberKind /*kind*/, int propertyIndex, IR::ExprList *args, IR::Expr *result)
+ void callQmlContextProperty(IR::Expr *base, IR::Member::MemberKind /*kind*/, int propertyIndex,
+ IR::ExprList *args, IR::Expr *result) override
{
Q_UNUSED(propertyIndex)
@@ -316,8 +317,8 @@ protected: // IRDecoder
addCall();
}
- virtual void callProperty(IR::Expr *base, const QString &name, IR::ExprList *args,
- IR::Expr *result)
+ void callProperty(IR::Expr *base, const QString &name, IR::ExprList *args,
+ IR::Expr *result) override
{
Q_UNUSED(name)
@@ -327,8 +328,8 @@ protected: // IRDecoder
addCall();
}
- virtual void callSubscript(IR::Expr *base, IR::Expr *index, IR::ExprList *args,
- IR::Expr *result)
+ void callSubscript(IR::Expr *base, IR::Expr *index, IR::ExprList *args,
+ IR::Expr *result) override
{
addDef(result);
addUses(base->asTemp(), Use::CouldHaveRegister);
@@ -337,7 +338,7 @@ protected: // IRDecoder
addCall();
}
- virtual void convertType(IR::Expr *source, IR::Expr *target)
+ void convertType(IR::Expr *source, IR::Expr *target) override
{
addDef(target);
@@ -410,14 +411,14 @@ protected: // IRDecoder
addHint(target->asTemp(), sourceTemp);
}
- virtual void constructActivationProperty(IR::Name *, IR::ExprList *args, IR::Expr *result)
+ void constructActivationProperty(IR::Name *, IR::ExprList *args, IR::Expr *result) override
{
addDef(result);
addUses(args, Use::CouldHaveRegister);
addCall();
}
- virtual void constructProperty(IR::Expr *base, const QString &, IR::ExprList *args, IR::Expr *result)
+ void constructProperty(IR::Expr *base, const QString &, IR::ExprList *args, IR::Expr *result) override
{
addDef(result);
addUses(base, Use::CouldHaveRegister);
@@ -425,7 +426,7 @@ protected: // IRDecoder
addCall();
}
- virtual void constructValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result)
+ void constructValue(IR::Expr *value, IR::ExprList *args, IR::Expr *result) override
{
addDef(result);
addUses(value, Use::CouldHaveRegister);
@@ -433,24 +434,24 @@ protected: // IRDecoder
addCall();
}
- virtual void loadThisObject(IR::Expr *temp)
+ void loadThisObject(IR::Expr *temp) override
{
addDef(temp);
}
- virtual void loadQmlContext(IR::Expr *temp)
+ void loadQmlContext(IR::Expr *temp) override
{
addDef(temp);
addCall();
}
- virtual void loadQmlImportedScripts(IR::Expr *temp)
+ void loadQmlImportedScripts(IR::Expr *temp) override
{
addDef(temp);
addCall();
}
- virtual void loadQmlSingleton(const QString &/*name*/, Expr *temp)
+ void loadQmlSingleton(const QString &/*name*/, Expr *temp) override
{
Q_UNUSED(temp);
@@ -458,21 +459,21 @@ protected: // IRDecoder
addCall();
}
- virtual void loadConst(IR::Const *sourceConst, Expr *targetTemp)
+ void loadConst(IR::Const *sourceConst, Expr *targetTemp) override
{
Q_UNUSED(sourceConst);
addDef(targetTemp);
}
- virtual void loadString(const QString &str, Expr *targetTemp)
+ void loadString(const QString &str, Expr *targetTemp) override
{
Q_UNUSED(str);
addDef(targetTemp);
}
- virtual void loadRegexp(IR::RegExp *sourceRegexp, Expr *targetTemp)
+ void loadRegexp(IR::RegExp *sourceRegexp, Expr *targetTemp) override
{
Q_UNUSED(sourceRegexp);
@@ -480,19 +481,19 @@ protected: // IRDecoder
addCall();
}
- virtual void getActivationProperty(const IR::Name *, Expr *temp)
+ void getActivationProperty(const IR::Name *, Expr *temp) override
{
addDef(temp);
addCall();
}
- virtual void setActivationProperty(IR::Expr *source, const QString &)
+ void setActivationProperty(IR::Expr *source, const QString &) override
{
addUses(source->asTemp(), Use::CouldHaveRegister);
addCall();
}
- virtual void initClosure(IR::Closure *closure, Expr *target)
+ void initClosure(IR::Closure *closure, Expr *target) override
{
Q_UNUSED(closure);
@@ -500,49 +501,52 @@ protected: // IRDecoder
addCall();
}
- virtual void getProperty(IR::Expr *base, const QString &, Expr *target)
+ void getProperty(IR::Expr *base, const QString &, Expr *target) override
{
addDef(target);
addUses(base->asTemp(), Use::CouldHaveRegister);
addCall();
}
- virtual void setProperty(IR::Expr *source, IR::Expr *targetBase, const QString &)
+ void setProperty(IR::Expr *source, IR::Expr *targetBase, const QString &) override
{
addUses(source->asTemp(), Use::CouldHaveRegister);
addUses(targetBase->asTemp(), Use::CouldHaveRegister);
addCall();
}
- virtual void setQmlContextProperty(IR::Expr *source, IR::Expr *targetBase, IR::Member::MemberKind /*kind*/, int /*propertyIndex*/)
+ void setQmlContextProperty(IR::Expr *source, IR::Expr *targetBase,
+ IR::Member::MemberKind /*kind*/, int /*propertyIndex*/) override
{
addUses(source->asTemp(), Use::CouldHaveRegister);
addUses(targetBase->asTemp(), Use::CouldHaveRegister);
addCall();
}
- virtual void setQObjectProperty(IR::Expr *source, IR::Expr *targetBase, int /*propertyIndex*/)
+ void setQObjectProperty(IR::Expr *source, IR::Expr *targetBase, int /*propertyIndex*/) override
{
addUses(source->asTemp(), Use::CouldHaveRegister);
addUses(targetBase->asTemp(), Use::CouldHaveRegister);
addCall();
}
- virtual void getQmlContextProperty(IR::Expr *base, IR::Member::MemberKind /*kind*/, int /*index*/, bool /*captureRequired*/, IR::Expr *target)
+ void getQmlContextProperty(IR::Expr *base, IR::Member::MemberKind /*kind*/, int /*index*/,
+ bool /*captureRequired*/, IR::Expr *target) override
{
addDef(target);
addUses(base->asTemp(), Use::CouldHaveRegister);
addCall();
}
- virtual void getQObjectProperty(IR::Expr *base, int /*propertyIndex*/, bool /*captureRequired*/, bool /*isSingleton*/, int /*attachedPropertiesId*/, IR::Expr *target)
+ void getQObjectProperty(IR::Expr *base, int /*propertyIndex*/, bool /*captureRequired*/,
+ bool /*isSingleton*/, int /*attachedPropertiesId*/, IR::Expr *target) override
{
addDef(target);
addUses(base->asTemp(), Use::CouldHaveRegister);
addCall();
}
- virtual void getElement(IR::Expr *base, IR::Expr *index, Expr *target)
+ void getElement(IR::Expr *base, IR::Expr *index, Expr *target) override
{
addDef(target);
addUses(base->asTemp(), Use::CouldHaveRegister);
@@ -550,7 +554,7 @@ protected: // IRDecoder
addCall();
}
- virtual void setElement(IR::Expr *source, IR::Expr *targetBase, IR::Expr *targetIndex)
+ void setElement(IR::Expr *source, IR::Expr *targetBase, IR::Expr *targetIndex) override
{
addUses(source->asTemp(), Use::CouldHaveRegister);
addUses(targetBase->asTemp(), Use::CouldHaveRegister);
@@ -558,7 +562,7 @@ protected: // IRDecoder
addCall();
}
- virtual void copyValue(Expr *source, Expr *target)
+ void copyValue(Expr *source, Expr *target) override
{
addDef(target);
Temp *sourceTemp = source->asTemp();
@@ -570,13 +574,13 @@ protected: // IRDecoder
addHint(targetTemp, sourceTemp);
}
- virtual void swapValues(Expr *, Expr *)
+ void swapValues(Expr *, Expr *) override
{
// Inserted by the register allocator, so it cannot occur here.
Q_UNREACHABLE();
}
- virtual void unop(AluOp oper, Expr *source, Expr *target)
+ void unop(AluOp oper, Expr *source, Expr *target) override
{
addDef(target);
@@ -612,7 +616,7 @@ protected: // IRDecoder
}
}
- virtual void binop(AluOp oper, Expr *leftSource, Expr *rightSource, Expr *target)
+ void binop(AluOp oper, Expr *leftSource, Expr *rightSource, Expr *target) override
{
bool needsCall = true;
@@ -675,8 +679,8 @@ protected: // IRDecoder
}
}
- virtual void visitJump(IR::Jump *) {}
- virtual void visitCJump(IR::CJump *s)
+ void visitJump(IR::Jump *) override {}
+ void visitCJump(IR::CJump *s) override
{
if (Temp *t = s->cond->asTemp()) {
#if 0 // TODO: change masm to generate code
@@ -696,10 +700,10 @@ protected: // IRDecoder
}
}
- virtual void visitRet(IR::Ret *s)
+ void visitRet(IR::Ret *s) override
{ addUses(s->expr->asTemp(), Use::CouldHaveRegister); }
- virtual void visitPhi(IR::Phi *s)
+ void visitPhi(IR::Phi *s) override
{
addDef(s->targetTemp, true);
for (int i = 0, ei = s->incoming.size(); i < ei; ++i) {
@@ -716,7 +720,7 @@ protected: // IRDecoder
}
protected:
- virtual void callBuiltin(IR::Call *c, IR::Expr *result)
+ void callBuiltin(IR::Call *c, IR::Expr *result) override
{
addDef(result);
addUses(c->base, Use::CouldHaveRegister);
@@ -1091,12 +1095,12 @@ private:
if (_info->def(it->temp()) != successorStart && !it->isSplitFromInterval()) {
const int successorEnd = successor->terminator()->id();
const int idx = successor->in.indexOf(predecessor);
- foreach (const Use &use, _info->uses(it->temp())) {
+ for (const Use &use : _info->uses(it->temp)) {
if (use.pos == static_cast<unsigned>(successorStart)) {
// only check the current edge, not all other possible ones. This is
// important for phi nodes: they have uses that are only valid when
// coming in over a specific edge.
- foreach (Stmt *s, successor->statements()) {
+ for (Stmt *s : successor->statements()) {
if (Phi *phi = s->asPhi()) {
Q_ASSERT(it->temp().index != phi->targetTemp->index);
Q_ASSERT(phi->d->incoming[idx]->asTemp() == 0
@@ -1527,7 +1531,7 @@ static inline int indexOfRangeCoveringPosition(const LifeTimeInterval::Ranges &r
return -1;
}
-static inline int intersectionPosition(const LifeTimeInterval::Range &one, const LifeTimeInterval::Range &two)
+static inline int intersectionPosition(const LifeTimeIntervalRange &one, const LifeTimeIntervalRange &two)
{
if (one.covers(two.start))
return two.start;
@@ -1573,7 +1577,7 @@ static void longestAvailableReg(int *nextUses, int nextUseCount, int &reg, int &
#define CALLOC_ON_STACK(ty, ptr, sz, val) \
Q_ASSERT(sz > 0); \
- ty *ptr = reinterpret_cast<ty *>(alloca(sizeof(ty) * (sz))); \
+ Q_ALLOCA_VAR(ty, ptr, sizeof(ty) * (sz)); \
for (ty *it = ptr, *eit = ptr + (sz); it != eit; ++it) \
*it = val;
@@ -1785,9 +1789,9 @@ int RegisterAllocator::nextIntersection(const LifeTimeInterval &current,
return -1;
for (int currentEnd = currentRanges.size(); currentIt < currentEnd; ++currentIt) {
- const LifeTimeInterval::Range currentRange = currentRanges.at(currentIt);
+ const LifeTimeIntervalRange currentRange = currentRanges.at(currentIt);
for (int anotherIt = anotherItStart, anotherEnd = anotherRanges.size(); anotherIt < anotherEnd; ++anotherIt) {
- const LifeTimeInterval::Range anotherRange = anotherRanges.at(anotherIt);
+ const LifeTimeIntervalRange anotherRange = anotherRanges.at(anotherIt);
if (anotherRange.start > currentRange.end)
break;
int intersectPos = intersectionPosition(currentRange, anotherRange);
diff --git a/src/qml/jit/qv4targetplatform_p.h b/src/qml/jit/qv4targetplatform_p.h
index 7e265258d5..fcc600eb2e 100644
--- a/src/qml/jit/qv4targetplatform_p.h
+++ b/src/qml/jit/qv4targetplatform_p.h
@@ -63,6 +63,11 @@ QT_BEGIN_NAMESPACE
namespace QV4 {
namespace JIT {
+enum TargetOperatingSystemSpecialization {
+ NoOperatingSystemSpecialization,
+ WindowsSpecialization
+};
+
// The TargetPlatform class describes how the stack and the registers work on a CPU+ABI combination.
//
// All combinations have a separate definition, guarded by #ifdefs. The exceptions are:
@@ -79,25 +84,38 @@ namespace JIT {
// a call, we add a load it right before emitting the call instruction.
//
// NOTE: When adding new architecture, do not forget to whitelist it in qv4global_p.h!
+template <typename PlatformAssembler, TargetOperatingSystemSpecialization specialization = NoOperatingSystemSpecialization>
class TargetPlatform
{
-public:
+};
+
#if CPU(X86) && (OS(LINUX) || OS(WINDOWS) || OS(QNX) || OS(FREEBSD) || defined(Q_OS_IOS))
- enum { RegAllocIsSupported = 1 };
+template <>
+class TargetPlatform<JSC::MacroAssemblerX86, NoOperatingSystemSpecialization>
+{
+public:
+ using PlatformAssembler = JSC::MacroAssemblerX86;
+ using RegisterID = PlatformAssembler::RegisterID;
+ using FPRegisterID = PlatformAssembler::FPRegisterID;
+ using TrustedImm32 = PlatformAssembler::TrustedImm32;
- static const JSC::MacroAssembler::RegisterID FramePointerRegister = JSC::X86Registers::ebp;
- static const JSC::MacroAssembler::RegisterID StackPointerRegister = JSC::X86Registers::esp;
- static const JSC::MacroAssembler::RegisterID LocalsRegister = JSC::X86Registers::edi;
- static const JSC::MacroAssembler::RegisterID EngineRegister = JSC::X86Registers::esi;
- static const JSC::MacroAssembler::RegisterID ReturnValueRegister = JSC::X86Registers::eax;
- static const JSC::MacroAssembler::RegisterID ScratchRegister = JSC::X86Registers::ecx;
- static const JSC::MacroAssembler::FPRegisterID FPGpr0 = JSC::X86Registers::xmm0;
- static const JSC::MacroAssembler::FPRegisterID FPGpr1 = JSC::X86Registers::xmm1;
+ enum { RegAllocIsSupported = 1 };
- static RegisterInformation getPlatformRegisterInfo()
+ static const RegisterID FramePointerRegister = JSC::X86Registers::ebp;
+ static const RegisterID StackPointerRegister = JSC::X86Registers::esp;
+ static const RegisterID LocalsRegister = JSC::X86Registers::edi;
+ static const RegisterID EngineRegister = JSC::X86Registers::esi;
+ static const RegisterID ReturnValueRegister = JSC::X86Registers::eax;
+ static const RegisterID ScratchRegister = JSC::X86Registers::ecx;
+ static const FPRegisterID FPGpr0 = JSC::X86Registers::xmm0;
+ static const FPRegisterID FPGpr1 = JSC::X86Registers::xmm1;
+ static const RegisterID LowReturnValueRegister = JSC::X86Registers::eax;
+ static const RegisterID HighReturnValueRegister = JSC::X86Registers::edx;
+
+ static RegisterInformation getRegisterInfo()
{
typedef RegisterInfo RI;
- return RegisterInformation()
+ static RegisterInformation info = RegisterInformation()
<< RI(JSC::X86Registers::edx, QStringLiteral("edx"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
<< RI(JSC::X86Registers::ebx, QStringLiteral("ebx"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
<< RI(JSC::X86Registers::edi, QStringLiteral("edi"), RI::RegularRegister, RI::CalleeSaved, RI::Predefined)
@@ -109,28 +127,31 @@ public:
<< RI(JSC::X86Registers::xmm6, QStringLiteral("xmm6"), RI::FloatingPointRegister, RI::CallerSaved, RI::RegAlloc)
<< RI(JSC::X86Registers::xmm7, QStringLiteral("xmm7"), RI::FloatingPointRegister, RI::CallerSaved, RI::RegAlloc)
;
+ return info;
}
# define HAVE_ALU_OPS_WITH_MEM_OPERAND 1
-# undef VALUE_FITS_IN_REGISTER
static const int RegisterSize = 4;
-# undef ARGUMENTS_IN_REGISTERS
static const int RegisterArgumentCount = 0;
- static JSC::MacroAssembler::RegisterID registerForArgument(int) { Q_UNREACHABLE(); }
+ static RegisterID registerForArgument(int) { Q_UNREACHABLE(); }
static const int StackAlignment = 16;
static const int StackShadowSpace = 0;
static const int StackSpaceAllocatedUponFunctionEntry = RegisterSize; // Return address is pushed onto stack by the CPU.
- static void platformEnterStandardStackFrame(JSC::MacroAssembler *as) { as->push(FramePointerRegister); }
- static void platformLeaveStandardStackFrame(JSC::MacroAssembler *as) { as->pop(FramePointerRegister); }
+ static void platformEnterStandardStackFrame(PlatformAssembler *as) { as->push(FramePointerRegister); }
+ static void platformLeaveStandardStackFrame(PlatformAssembler *as, int frameSize)
+ {
+ if (frameSize > 0)
+ as->add32(TrustedImm32(frameSize), StackPointerRegister);
+ as->pop(FramePointerRegister);
+ }
#if OS(WINDOWS) || OS(QNX) || \
((OS(LINUX) || OS(FREEBSD)) && (defined(__PIC__) || defined(__PIE__)))
-#define RESTORE_EBX_ON_CALL
- static JSC::MacroAssembler::Address ebxAddressOnStack()
- {
+ static const int gotRegister = JSC::X86Registers::ebx;
+ static int savedGOTRegisterSlotOnStack() {
static int ebxIdx = -1;
if (ebxIdx == -1) {
int calleeSaves = 0;
@@ -146,34 +167,47 @@ public:
Q_ASSERT(ebxIdx >= 0);
ebxIdx += 1;
}
- return JSC::MacroAssembler::Address(FramePointerRegister, ebxIdx * -int(sizeof(void*)));
+ return ebxIdx * -int(sizeof(void*));
}
+#else
+ static const int gotRegister = -1;
+ static int savedGOTRegisterSlotOnStack() { return -1; }
#endif
-
-#endif // Windows on x86
+};
+#endif // x86
#if CPU(X86_64) && (OS(LINUX) || OS(MAC_OS_X) || OS(FREEBSD) || OS(QNX) || defined(Q_OS_IOS))
+template <>
+class TargetPlatform<JSC::MacroAssemblerX86_64, NoOperatingSystemSpecialization>
+{
+public:
+ using PlatformAssembler = JSC::MacroAssemblerX86_64;
+ using RegisterID = PlatformAssembler::RegisterID;
+ using FPRegisterID = PlatformAssembler::FPRegisterID;
+ using TrustedImm32 = PlatformAssembler::TrustedImm32;
+
enum { RegAllocIsSupported = 1 };
- static const JSC::MacroAssembler::RegisterID FramePointerRegister = JSC::X86Registers::ebp;
- static const JSC::MacroAssembler::RegisterID StackPointerRegister = JSC::X86Registers::esp;
- static const JSC::MacroAssembler::RegisterID LocalsRegister = JSC::X86Registers::r12;
- static const JSC::MacroAssembler::RegisterID EngineRegister = JSC::X86Registers::r14;
- static const JSC::MacroAssembler::RegisterID ReturnValueRegister = JSC::X86Registers::eax;
- static const JSC::MacroAssembler::RegisterID ScratchRegister = JSC::X86Registers::r10;
- static const JSC::MacroAssembler::FPRegisterID FPGpr0 = JSC::X86Registers::xmm0;
- static const JSC::MacroAssembler::FPRegisterID FPGpr1 = JSC::X86Registers::xmm1;
+ static const RegisterID FramePointerRegister = JSC::X86Registers::ebp;
+ static const RegisterID StackPointerRegister = JSC::X86Registers::esp;
+ static const RegisterID LocalsRegister = JSC::X86Registers::r12;
+ static const RegisterID EngineRegister = JSC::X86Registers::r14;
+ static const RegisterID ReturnValueRegister = JSC::X86Registers::eax;
+ static const RegisterID ScratchRegister = JSC::X86Registers::r10;
+ static const FPRegisterID FPGpr0 = JSC::X86Registers::xmm0;
+ static const FPRegisterID FPGpr1 = JSC::X86Registers::xmm1;
- static RegisterInformation getPlatformRegisterInfo()
+ static RegisterInformation getRegisterInfo()
{
typedef RegisterInfo RI;
- return RegisterInformation()
+ static RegisterInformation info = RegisterInformation()
<< RI(JSC::X86Registers::ebx, QStringLiteral("rbx"), RI::RegularRegister, RI::CalleeSaved, RI::RegAlloc)
<< RI(JSC::X86Registers::edi, QStringLiteral("rdi"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
<< RI(JSC::X86Registers::esi, QStringLiteral("rsi"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
<< RI(JSC::X86Registers::edx, QStringLiteral("rdx"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
<< RI(JSC::X86Registers::r9, QStringLiteral("r9"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
<< RI(JSC::X86Registers::r8, QStringLiteral("r8"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
+ // r11 is used as scratch register by the macro assembler
<< RI(JSC::X86Registers::r12, QStringLiteral("r12"), RI::RegularRegister, RI::CalleeSaved, RI::Predefined)
<< RI(JSC::X86Registers::r13, QStringLiteral("r13"), RI::RegularRegister, RI::CalleeSaved, RI::RegAlloc)
<< RI(JSC::X86Registers::r14, QStringLiteral("r14"), RI::RegularRegister, RI::CalleeSaved, RI::Predefined)
@@ -185,17 +219,16 @@ public:
<< RI(JSC::X86Registers::xmm6, QStringLiteral("xmm6"), RI::FloatingPointRegister, RI::CallerSaved, RI::RegAlloc)
<< RI(JSC::X86Registers::xmm7, QStringLiteral("xmm7"), RI::FloatingPointRegister, RI::CallerSaved, RI::RegAlloc)
;
+ return info;
}
#define HAVE_ALU_OPS_WITH_MEM_OPERAND 1
-#define VALUE_FITS_IN_REGISTER
static const int RegisterSize = 8;
-#define ARGUMENTS_IN_REGISTERS
static const int RegisterArgumentCount = 6;
- static JSC::MacroAssembler::RegisterID registerForArgument(int index)
+ static RegisterID registerForArgument(int index)
{
- static JSC::MacroAssembler::RegisterID regs[RegisterArgumentCount] = {
+ static RegisterID regs[RegisterArgumentCount] = {
JSC::X86Registers::edi,
JSC::X86Registers::esi,
JSC::X86Registers::edx,
@@ -210,51 +243,72 @@ public:
static const int StackAlignment = 16;
static const int StackShadowSpace = 0;
static const int StackSpaceAllocatedUponFunctionEntry = RegisterSize; // Return address is pushed onto stack by the CPU.
- static void platformEnterStandardStackFrame(JSC::MacroAssembler *as) { as->push(FramePointerRegister); }
- static void platformLeaveStandardStackFrame(JSC::MacroAssembler *as) { as->pop(FramePointerRegister); }
+ static void platformEnterStandardStackFrame(PlatformAssembler *as) { as->push(FramePointerRegister); }
+ static void platformLeaveStandardStackFrame(PlatformAssembler *as, int frameSize)
+ {
+ if (frameSize > 0)
+ as->add64(TrustedImm32(frameSize), StackPointerRegister);
+ as->pop(FramePointerRegister);
+ }
+
+ static const int gotRegister = -1;
+ static int savedGOTRegisterSlotOnStack() { return -1; }
+};
#endif // Linux/MacOS on x86_64
#if CPU(X86_64) && OS(WINDOWS)
- // Register allocation is not (yet) supported on win64, because the ABI related stack handling
- // is not completely implemented. Specifically, the saving of xmm registers, and the saving of
- // incoming function parameters to the shadow space is missing.
- enum { RegAllocIsSupported = 0 };
-
- static const JSC::MacroAssembler::RegisterID FramePointerRegister = JSC::X86Registers::ebp;
- static const JSC::MacroAssembler::RegisterID StackPointerRegister = JSC::X86Registers::esp;
- static const JSC::MacroAssembler::RegisterID LocalsRegister = JSC::X86Registers::r12;
- static const JSC::MacroAssembler::RegisterID EngineRegister = JSC::X86Registers::r14;
- static const JSC::MacroAssembler::RegisterID ReturnValueRegister = JSC::X86Registers::eax;
- static const JSC::MacroAssembler::RegisterID ScratchRegister = JSC::X86Registers::r10;
- static const JSC::MacroAssembler::FPRegisterID FPGpr0 = JSC::X86Registers::xmm0;
- static const JSC::MacroAssembler::FPRegisterID FPGpr1 = JSC::X86Registers::xmm1;
-
- static RegisterInformation getPlatformRegisterInfo()
+template <>
+class TargetPlatform<JSC::MacroAssemblerX86_64, WindowsSpecialization>
+{
+public:
+ using PlatformAssembler = JSC::MacroAssemblerX86_64;
+ using RegisterID = PlatformAssembler::RegisterID;
+ using FPRegisterID = PlatformAssembler::FPRegisterID;
+ using TrustedImm32 = PlatformAssembler::TrustedImm32;
+
+ enum { RegAllocIsSupported = 1 };
+
+ static const RegisterID FramePointerRegister = JSC::X86Registers::ebp;
+ static const RegisterID StackPointerRegister = JSC::X86Registers::esp;
+ static const RegisterID LocalsRegister = JSC::X86Registers::r12;
+ static const RegisterID EngineRegister = JSC::X86Registers::r14;
+ static const RegisterID ReturnValueRegister = JSC::X86Registers::eax;
+ static const RegisterID ScratchRegister = JSC::X86Registers::r10;
+ static const FPRegisterID FPGpr0 = JSC::X86Registers::xmm0;
+ static const FPRegisterID FPGpr1 = JSC::X86Registers::xmm1;
+
+ static RegisterInformation getRegisterInfo()
{
typedef RegisterInfo RI;
- return RegisterInformation()
- << RI(JSC::X86Registers::ebx, QStringLiteral("rbx"), RI::RegularRegister, RI::CalleeSaved, RI::Predefined)
- << RI(JSC::X86Registers::edi, QStringLiteral("rdi"), RI::RegularRegister, RI::CalleeSaved, RI::Predefined)
- << RI(JSC::X86Registers::esi, QStringLiteral("rsi"), RI::RegularRegister, RI::CalleeSaved, RI::Predefined)
- << RI(JSC::X86Registers::edx, QStringLiteral("rdx"), RI::RegularRegister, RI::CallerSaved, RI::Predefined)
- << RI(JSC::X86Registers::r9, QStringLiteral("r9"), RI::RegularRegister, RI::CallerSaved, RI::Predefined)
- << RI(JSC::X86Registers::r8, QStringLiteral("r8"), RI::RegularRegister, RI::CallerSaved, RI::Predefined)
+ static RegisterInformation info = RegisterInformation()
+ << RI(JSC::X86Registers::ebx, QStringLiteral("rbx"), RI::RegularRegister, RI::CalleeSaved, RI::RegAlloc)
+ << RI(JSC::X86Registers::edi, QStringLiteral("rdi"), RI::RegularRegister, RI::CalleeSaved, RI::RegAlloc)
+ << RI(JSC::X86Registers::esi, QStringLiteral("rsi"), RI::RegularRegister, RI::CalleeSaved, RI::RegAlloc)
+ << RI(JSC::X86Registers::edx, QStringLiteral("rdx"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
+ << RI(JSC::X86Registers::r8, QStringLiteral("r8"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
+ << RI(JSC::X86Registers::r9, QStringLiteral("r9"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
+ // r11 is used as scratch register by the macro assembler
<< RI(JSC::X86Registers::r12, QStringLiteral("r12"), RI::RegularRegister, RI::CalleeSaved, RI::Predefined)
- << RI(JSC::X86Registers::r13, QStringLiteral("r13"), RI::RegularRegister, RI::CalleeSaved, RI::Predefined)
+ << RI(JSC::X86Registers::r13, QStringLiteral("r13"), RI::RegularRegister, RI::CalleeSaved, RI::RegAlloc)
<< RI(JSC::X86Registers::r14, QStringLiteral("r14"), RI::RegularRegister, RI::CalleeSaved, RI::Predefined)
- << RI(JSC::X86Registers::r15, QStringLiteral("r15"), RI::RegularRegister, RI::CalleeSaved, RI::Predefined)
+ << RI(JSC::X86Registers::r15, QStringLiteral("r15"), RI::RegularRegister, RI::CalleeSaved, RI::RegAlloc)
+ << RI(JSC::X86Registers::xmm2, QStringLiteral("xmm2"), RI::FloatingPointRegister, RI::CallerSaved, RI::RegAlloc)
+ << RI(JSC::X86Registers::xmm3, QStringLiteral("xmm3"), RI::FloatingPointRegister, RI::CallerSaved, RI::RegAlloc)
+ << RI(JSC::X86Registers::xmm4, QStringLiteral("xmm4"), RI::FloatingPointRegister, RI::CallerSaved, RI::RegAlloc)
+ << RI(JSC::X86Registers::xmm5, QStringLiteral("xmm5"), RI::FloatingPointRegister, RI::CallerSaved, RI::RegAlloc)
+ << RI(JSC::X86Registers::xmm6, QStringLiteral("xmm6"), RI::FloatingPointRegister, RI::CalleeSaved, RI::RegAlloc)
+ << RI(JSC::X86Registers::xmm7, QStringLiteral("xmm7"), RI::FloatingPointRegister, RI::CalleeSaved, RI::RegAlloc)
;
+ return info;
}
#define HAVE_ALU_OPS_WITH_MEM_OPERAND 1
-#define VALUE_FITS_IN_REGISTER
static const int RegisterSize = 8;
-#define ARGUMENTS_IN_REGISTERS
static const int RegisterArgumentCount = 4;
- static JSC::MacroAssembler::RegisterID registerForArgument(int index)
+ static RegisterID registerForArgument(int index)
{
- static JSC::MacroAssembler::RegisterID regs[RegisterArgumentCount] = {
+ static RegisterID regs[RegisterArgumentCount] = {
JSC::X86Registers::ecx,
JSC::X86Registers::edx,
JSC::X86Registers::r8,
@@ -262,16 +316,34 @@ public:
};
Q_ASSERT(index >= 0 && index < RegisterArgumentCount);
return regs[index];
- };
+ }
static const int StackAlignment = 16;
static const int StackShadowSpace = 32;
static const int StackSpaceAllocatedUponFunctionEntry = RegisterSize; // Return address is pushed onto stack by the CPU.
- static void platformEnterStandardStackFrame(JSC::MacroAssembler *as) { as->push(FramePointerRegister); }
- static void platformLeaveStandardStackFrame(JSC::MacroAssembler *as) { as->pop(FramePointerRegister); }
+ static void platformEnterStandardStackFrame(PlatformAssembler *as) { as->push(FramePointerRegister); }
+ static void platformLeaveStandardStackFrame(PlatformAssembler *as, int frameSize)
+ {
+ if (frameSize > 0)
+ as->add64(TrustedImm32(frameSize), StackPointerRegister);
+ as->pop(FramePointerRegister);
+ }
+
+ static const int gotRegister = -1;
+ static int savedGOTRegisterSlotOnStack() { return -1; }
+};
#endif // Windows on x86_64
-#if CPU(ARM)
+#if CPU(ARM) || defined(V4_BOOTSTRAP)
+template <>
+class TargetPlatform<JSC::MacroAssemblerARMv7, NoOperatingSystemSpecialization>
+{
+public:
+ using PlatformAssembler = JSC::MacroAssemblerARMv7;
+ using RegisterID = PlatformAssembler::RegisterID;
+ using FPRegisterID = PlatformAssembler::FPRegisterID;
+ using TrustedImm32 = PlatformAssembler::TrustedImm32;
+
enum { RegAllocIsSupported = 1 };
// The AAPCS specifies that the platform ABI has to define the usage of r9. Known are:
@@ -287,23 +359,25 @@ public:
// is used for the subroutine: r7 for Thumb or Thumb2, and r11 for ARM. We assign the constants
// accordingly, and assign the locals-register to the "other" register.
#if CPU(ARM_THUMB2)
- static const JSC::MacroAssembler::RegisterID FramePointerRegister = JSC::ARMRegisters::r7;
- static const JSC::MacroAssembler::RegisterID LocalsRegister = JSC::ARMRegisters::r11;
+ static const RegisterID FramePointerRegister = JSC::ARMRegisters::r7;
+ static const RegisterID LocalsRegister = JSC::ARMRegisters::r11;
#else // Thumbs down
- static const JSC::MacroAssembler::RegisterID FramePointerRegister = JSC::ARMRegisters::r11;
- static const JSC::MacroAssembler::RegisterID LocalsRegister = JSC::ARMRegisters::r7;
+ static const RegisterID FramePointerRegister = JSC::ARMRegisters::r11;
+ static const RegisterID LocalsRegister = JSC::ARMRegisters::r7;
#endif
- static const JSC::MacroAssembler::RegisterID StackPointerRegister = JSC::ARMRegisters::r13;
- static const JSC::MacroAssembler::RegisterID ScratchRegister = JSC::ARMRegisters::r5;
- static const JSC::MacroAssembler::RegisterID EngineRegister = JSC::ARMRegisters::r10;
- static const JSC::MacroAssembler::RegisterID ReturnValueRegister = JSC::ARMRegisters::r0;
- static const JSC::MacroAssembler::FPRegisterID FPGpr0 = JSC::ARMRegisters::d0;
- static const JSC::MacroAssembler::FPRegisterID FPGpr1 = JSC::ARMRegisters::d1;
-
- static RegisterInformation getPlatformRegisterInfo()
+ static const RegisterID StackPointerRegister = JSC::ARMRegisters::r13;
+ static const RegisterID ScratchRegister = JSC::ARMRegisters::r5;
+ static const RegisterID EngineRegister = JSC::ARMRegisters::r10;
+ static const RegisterID ReturnValueRegister = JSC::ARMRegisters::r0;
+ static const FPRegisterID FPGpr0 = JSC::ARMRegisters::d0;
+ static const FPRegisterID FPGpr1 = JSC::ARMRegisters::d1;
+ static const RegisterID LowReturnValueRegister = JSC::ARMRegisters::r0;
+ static const RegisterID HighReturnValueRegister = JSC::ARMRegisters::r1;
+
+ static RegisterInformation getRegisterInfo()
{
typedef RegisterInfo RI;
- return RegisterInformation()
+ static RegisterInformation info = RegisterInformation()
<< RI(JSC::ARMRegisters::r0, QStringLiteral("r0"), RI::RegularRegister, RI::CallerSaved, RI::Predefined)
<< RI(JSC::ARMRegisters::r1, QStringLiteral("r1"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
<< RI(JSC::ARMRegisters::r2, QStringLiteral("r2"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
@@ -336,17 +410,16 @@ public:
<< RI(JSC::ARMRegisters::d14, QStringLiteral("d14"), RI::FloatingPointRegister, RI::CalleeSaved, RI::RegAlloc)
<< RI(JSC::ARMRegisters::d15, QStringLiteral("d15"), RI::FloatingPointRegister, RI::CalleeSaved, RI::RegAlloc)
;
+ return info;
}
#undef HAVE_ALU_OPS_WITH_MEM_OPERAND
-#undef VALUE_FITS_IN_REGISTER
static const int RegisterSize = 4;
-#define ARGUMENTS_IN_REGISTERS
static const int RegisterArgumentCount = 4;
- static JSC::MacroAssembler::RegisterID registerForArgument(int index)
+ static RegisterID registerForArgument(int index)
{
- static JSC::MacroAssembler::RegisterID regs[RegisterArgumentCount] = {
+ static RegisterID regs[RegisterArgumentCount] = {
JSC::ARMRegisters::r0,
JSC::ARMRegisters::r1,
JSC::ARMRegisters::r2,
@@ -361,35 +434,54 @@ public:
static const int StackShadowSpace = 0;
static const int StackSpaceAllocatedUponFunctionEntry = 1 * RegisterSize; // Registers saved in platformEnterStandardStackFrame below.
- static void platformEnterStandardStackFrame(JSC::MacroAssembler *as)
+ static void platformEnterStandardStackFrame(PlatformAssembler *as)
{
as->push(JSC::ARMRegisters::lr);
as->push(FramePointerRegister);
}
- static void platformLeaveStandardStackFrame(JSC::MacroAssembler *as)
+ static void platformLeaveStandardStackFrame(PlatformAssembler *as, int frameSize)
{
+ if (frameSize > 0) {
+ // Work around bug in ARMv7Assembler.h where add32(imm, sp, sp) doesn't
+ // work well for large immediates.
+ as->move(TrustedImm32(frameSize), JSC::ARMRegisters::r3);
+ as->add32(JSC::ARMRegisters::r3, StackPointerRegister);
+ }
as->pop(FramePointerRegister);
as->pop(JSC::ARMRegisters::lr);
}
+
+ static const int gotRegister = -1;
+ static int savedGOTRegisterSlotOnStack() { return -1; }
+};
#endif // ARM (32 bit)
-#if CPU(ARM64)
+#if CPU(ARM64) || defined(V4_BOOTSTRAP)
+template <>
+class TargetPlatform<JSC::MacroAssemblerARM64, NoOperatingSystemSpecialization>
+{
+public:
+ using PlatformAssembler = JSC::MacroAssemblerARM64;
+ using RegisterID = PlatformAssembler::RegisterID;
+ using FPRegisterID = PlatformAssembler::FPRegisterID;
+ using TrustedImm32 = PlatformAssembler::TrustedImm32;
+
enum { RegAllocIsSupported = 1 };
- static const JSC::MacroAssembler::RegisterID FramePointerRegister = JSC::ARM64Registers::fp;
- static const JSC::MacroAssembler::RegisterID LocalsRegister = JSC::ARM64Registers::x28;
- static const JSC::MacroAssembler::RegisterID StackPointerRegister = JSC::ARM64Registers::sp;
- static const JSC::MacroAssembler::RegisterID ScratchRegister = JSC::ARM64Registers::x9;
- static const JSC::MacroAssembler::RegisterID EngineRegister = JSC::ARM64Registers::x27;
- static const JSC::MacroAssembler::RegisterID ReturnValueRegister = JSC::ARM64Registers::x0;
- static const JSC::MacroAssembler::FPRegisterID FPGpr0 = JSC::ARM64Registers::q0;
- static const JSC::MacroAssembler::FPRegisterID FPGpr1 = JSC::ARM64Registers::q1;
+ static const RegisterID FramePointerRegister = JSC::ARM64Registers::fp;
+ static const RegisterID LocalsRegister = JSC::ARM64Registers::x28;
+ static const RegisterID StackPointerRegister = JSC::ARM64Registers::sp;
+ static const RegisterID ScratchRegister = JSC::ARM64Registers::x9;
+ static const RegisterID EngineRegister = JSC::ARM64Registers::x27;
+ static const RegisterID ReturnValueRegister = JSC::ARM64Registers::x0;
+ static const FPRegisterID FPGpr0 = JSC::ARM64Registers::q0;
+ static const FPRegisterID FPGpr1 = JSC::ARM64Registers::q1;
- static RegisterInformation getPlatformRegisterInfo()
+ static RegisterInformation getRegisterInfo()
{
typedef RegisterInfo RI;
- return RegisterInformation()
+ static RegisterInformation info = RegisterInformation()
<< RI(JSC::ARM64Registers::x0, QStringLiteral("x0"), RI::RegularRegister, RI::CallerSaved, RI::Predefined)
<< RI(JSC::ARM64Registers::x1, QStringLiteral("x1"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
<< RI(JSC::ARM64Registers::x2, QStringLiteral("x2"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
@@ -447,17 +539,16 @@ public:
<< RI(JSC::ARM64Registers::q30, QStringLiteral("q30"), RI::FloatingPointRegister, RI::CallerSaved, RI::RegAlloc)
<< RI(JSC::ARM64Registers::q31, QStringLiteral("q31"), RI::FloatingPointRegister, RI::CallerSaved, RI::RegAlloc)
;
+ return info;
}
#undef HAVE_ALU_OPS_WITH_MEM_OPERAND
-#define VALUE_FITS_IN_REGISTER
static const int RegisterSize = 8;
-#define ARGUMENTS_IN_REGISTERS
static const int RegisterArgumentCount = 8;
- static JSC::MacroAssembler::RegisterID registerForArgument(int index)
+ static RegisterID registerForArgument(int index)
{
- static JSC::MacroAssembler::RegisterID regs[RegisterArgumentCount] = {
+ static RegisterID regs[RegisterArgumentCount] = {
JSC::ARM64Registers::x0,
JSC::ARM64Registers::x1,
JSC::ARM64Registers::x2,
@@ -476,33 +567,49 @@ public:
static const int StackShadowSpace = 0;
static const int StackSpaceAllocatedUponFunctionEntry = 1 * RegisterSize; // Registers saved in platformEnterStandardStackFrame below.
- static void platformEnterStandardStackFrame(JSC::MacroAssembler *as)
+ static void platformEnterStandardStackFrame(PlatformAssembler *as)
{
as->pushPair(FramePointerRegister, JSC::ARM64Registers::lr);
}
- static void platformLeaveStandardStackFrame(JSC::MacroAssembler *as)
+ static void platformLeaveStandardStackFrame(PlatformAssembler *as, int frameSize)
{
+ if (frameSize > 0)
+ as->add64(TrustedImm32(frameSize), StackPointerRegister);
as->popPair(FramePointerRegister, JSC::ARM64Registers::lr);
}
+
+ static const int gotRegister = -1;
+ static int savedGOTRegisterSlotOnStack() { return -1; }
+};
#endif // ARM64
#if defined(Q_PROCESSOR_MIPS_32) && defined(Q_OS_LINUX)
+template <>
+class TargetPlatform<JSC::MacroAssemblerMIPS, NoOperatingSystemSpecialization>
+{
+public:
+ using PlatformAssembler = JSC::MacroAssemblerMIPS;
+ using RegisterID = PlatformAssembler::RegisterID;
+ using FPRegisterID = PlatformAssembler::FPRegisterID;
+ using TrustedImm32 = PlatformAssembler::TrustedImm32;
enum { RegAllocIsSupported = 1 };
- static const JSC::MacroAssembler::RegisterID FramePointerRegister = JSC::MIPSRegisters::fp;
- static const JSC::MacroAssembler::RegisterID StackPointerRegister = JSC::MIPSRegisters::sp;
- static const JSC::MacroAssembler::RegisterID LocalsRegister = JSC::MIPSRegisters::s0;
- static const JSC::MacroAssembler::RegisterID EngineRegister = JSC::MIPSRegisters::s1;
- static const JSC::MacroAssembler::RegisterID ReturnValueRegister = JSC::MIPSRegisters::v0;
- static const JSC::MacroAssembler::RegisterID ScratchRegister = JSC::MIPSRegisters::s2;
- static const JSC::MacroAssembler::FPRegisterID FPGpr0 = JSC::MIPSRegisters::f0;
- static const JSC::MacroAssembler::FPRegisterID FPGpr1 = JSC::MIPSRegisters::f2;
-
- static RegisterInformation getPlatformRegisterInfo()
+ static const RegisterID FramePointerRegister = JSC::MIPSRegisters::fp;
+ static const RegisterID StackPointerRegister = JSC::MIPSRegisters::sp;
+ static const RegisterID LocalsRegister = JSC::MIPSRegisters::s0;
+ static const RegisterID EngineRegister = JSC::MIPSRegisters::s1;
+ static const RegisterID ReturnValueRegister = JSC::MIPSRegisters::v0;
+ static const RegisterID ScratchRegister = JSC::MIPSRegisters::s2;
+ static const FPRegisterID FPGpr0 = JSC::MIPSRegisters::f0;
+ static const FPRegisterID FPGpr1 = JSC::MIPSRegisters::f2;
+ static const RegisterID LowReturnValueRegister = JSC::MIPSRegisters::v0;
+ static const RegisterID HighReturnValueRegister = JSC::MIPSRegisters::v1;
+
+ static RegisterInformation getRegisterInfo()
{
typedef RegisterInfo RI;
- return RegisterInformation()
+ static RegisterInformation info = RegisterInformation()
// Note: t0, t1, t2, t3 and f16 are already used by MacroAssemblerMIPS.
<< RI(JSC::MIPSRegisters::t4, QStringLiteral("t4"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
<< RI(JSC::MIPSRegisters::t5, QStringLiteral("t5"), RI::RegularRegister, RI::CallerSaved, RI::RegAlloc)
@@ -524,17 +631,16 @@ public:
<< RI(JSC::MIPSRegisters::f26, QStringLiteral("f26"), RI::FloatingPointRegister, RI::CalleeSaved, RI::RegAlloc)
<< RI(JSC::MIPSRegisters::f28, QStringLiteral("f28"), RI::FloatingPointRegister, RI::CalleeSaved, RI::RegAlloc)
;
+ return info;
}
#undef HAVE_ALU_OPS_WITH_MEM_OPERAND
-#undef VALUE_FITS_IN_REGISTER
static const int RegisterSize = 4;
-#define ARGUMENTS_IN_REGISTERS
static const int RegisterArgumentCount = 4;
- static JSC::MacroAssembler::RegisterID registerForArgument(int index)
+ static RegisterID registerForArgument(int index)
{
- static JSC::MacroAssembler::RegisterID regs[RegisterArgumentCount] = {
+ static RegisterID regs[RegisterArgumentCount] = {
JSC::MIPSRegisters::a0,
JSC::MIPSRegisters::a1,
JSC::MIPSRegisters::a2,
@@ -549,27 +655,25 @@ public:
static const int StackShadowSpace = 4 * RegisterSize; // Stack space for 4 argument registers.
static const int StackSpaceAllocatedUponFunctionEntry = 1 * RegisterSize; // Registers saved in platformEnterStandardStackFrame below.
- static void platformEnterStandardStackFrame(JSC::MacroAssembler *as)
+ static void platformEnterStandardStackFrame(PlatformAssembler *as)
{
as->push(JSC::MIPSRegisters::ra);
as->push(FramePointerRegister);
}
- static void platformLeaveStandardStackFrame(JSC::MacroAssembler *as)
+ static void platformLeaveStandardStackFrame(PlatformAssembler *as, int frameSize)
{
+ if (frameSize > 0)
+ as->add32(TrustedImm32(frameSize), StackPointerRegister);
as->pop(FramePointerRegister);
as->pop(JSC::MIPSRegisters::ra);
}
-#endif // Linux on MIPS (32 bit)
-public: // utility functions
- static const RegisterInformation getRegisterInfo()
- {
- static const RegisterInformation info = getPlatformRegisterInfo();
- return info;
- }
+ static const int gotRegister = -1;
+ static int savedGOTRegisterSlotOnStack() { return -1; }
};
+#endif // Linux on MIPS (32 bit)
} // JIT namespace
} // QV4 namespace
diff --git a/src/qml/jit/qv4unop.cpp b/src/qml/jit/qv4unop.cpp
index 799103849b..76c6457d67 100644
--- a/src/qml/jit/qv4unop.cpp
+++ b/src/qml/jit/qv4unop.cpp
@@ -48,14 +48,15 @@ using namespace JIT;
#define stringIfy(s) stringIfyx(s)
#define setOp(operation) \
do { \
- call = RuntimeCall(qOffsetOf(QV4::Runtime, operation)); name = "Runtime::" stringIfy(operation); \
+ call = typename JITAssembler::RuntimeCall(qOffsetOf(QV4::Runtime, operation)); name = "Runtime::" stringIfy(operation); \
needsExceptionCheck = Runtime::Method_##operation##_NeedsExceptionCheck; \
} while (0)
-void Unop::generate(IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void Unop<JITAssembler>::generate(IR::Expr *source, IR::Expr *target)
{
bool needsExceptionCheck;
- RuntimeCall call;
+ typename JITAssembler::RuntimeCall call;
const char *name = 0;
switch (op) {
case IR::OpNot:
@@ -75,17 +76,18 @@ void Unop::generate(IR::Expr *source, IR::Expr *target)
} // switch
Q_ASSERT(call.isValid());
- _as->generateFunctionCallImp(needsExceptionCheck, target, name, call, Assembler::PointerToValue(source));
+ _as->generateFunctionCallImp(needsExceptionCheck, target, name, call, PointerToValue(source));
}
-void Unop::generateUMinus(IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void Unop<JITAssembler>::generateUMinus(IR::Expr *source, IR::Expr *target)
{
IR::Temp *targetTemp = target->asTemp();
if (source->type == IR::SInt32Type) {
- Assembler::RegisterID tReg = Assembler::ScratchRegister;
+ typename JITAssembler::RegisterID tReg = JITAssembler::ScratchRegister;
if (targetTemp && targetTemp->kind == IR::Temp::PhysicalRegister)
- tReg = (Assembler::RegisterID) targetTemp->index;
- Assembler::RegisterID sReg = _as->toInt32Register(source, tReg);
+ tReg = (typename JITAssembler::RegisterID) targetTemp->index;
+ typename JITAssembler::RegisterID sReg = _as->toInt32Register(source, tReg);
_as->move(sReg, tReg);
_as->neg32(tReg);
if (!targetTemp || targetTemp->kind != IR::Temp::PhysicalRegister)
@@ -93,26 +95,27 @@ void Unop::generateUMinus(IR::Expr *source, IR::Expr *target)
return;
}
- generateRuntimeCall(target, uMinus, Assembler::PointerToValue(source));
+ generateRuntimeCall(_as, target, uMinus, PointerToValue(source));
}
-void Unop::generateNot(IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void Unop<JITAssembler>::generateNot(IR::Expr *source, IR::Expr *target)
{
IR::Temp *targetTemp = target->asTemp();
if (source->type == IR::BoolType) {
- Assembler::RegisterID tReg = Assembler::ScratchRegister;
+ typename JITAssembler::RegisterID tReg = JITAssembler::ScratchRegister;
if (targetTemp && targetTemp->kind == IR::Temp::PhysicalRegister)
- tReg = (Assembler::RegisterID) targetTemp->index;
- _as->xor32(Assembler::TrustedImm32(0x1), _as->toInt32Register(source, tReg), tReg);
+ tReg = (typename JITAssembler::RegisterID) targetTemp->index;
+ _as->xor32(TrustedImm32(0x1), _as->toInt32Register(source, tReg), tReg);
if (!targetTemp || targetTemp->kind != IR::Temp::PhysicalRegister)
_as->storeBool(tReg, target);
return;
} else if (source->type == IR::SInt32Type) {
- Assembler::RegisterID tReg = Assembler::ScratchRegister;
+ typename JITAssembler::RegisterID tReg = JITAssembler::ScratchRegister;
if (targetTemp && targetTemp->kind == IR::Temp::PhysicalRegister)
- tReg = (Assembler::RegisterID) targetTemp->index;
- _as->compare32(Assembler::Equal,
- _as->toInt32Register(source, Assembler::ScratchRegister), Assembler::TrustedImm32(0),
+ tReg = (typename JITAssembler::RegisterID) targetTemp->index;
+ _as->compare32(RelationalCondition::Equal,
+ _as->toInt32Register(source, JITAssembler::ScratchRegister), TrustedImm32(0),
tReg);
if (!targetTemp || targetTemp->kind != IR::Temp::PhysicalRegister)
_as->storeBool(tReg, target);
@@ -122,22 +125,33 @@ void Unop::generateNot(IR::Expr *source, IR::Expr *target)
}
// ## generic implementation testing for int/bool
- generateRuntimeCall(target, uNot, Assembler::PointerToValue(source));
+ generateRuntimeCall(_as, target, uNot, PointerToValue(source));
}
-void Unop::generateCompl(IR::Expr *source, IR::Expr *target)
+template <typename JITAssembler>
+void Unop<JITAssembler>::generateCompl(IR::Expr *source, IR::Expr *target)
{
IR::Temp *targetTemp = target->asTemp();
if (source->type == IR::SInt32Type) {
- Assembler::RegisterID tReg = Assembler::ScratchRegister;
+ typename JITAssembler::RegisterID tReg = JITAssembler::ScratchRegister;
if (targetTemp && targetTemp->kind == IR::Temp::PhysicalRegister)
- tReg = (Assembler::RegisterID) targetTemp->index;
- _as->xor32(Assembler::TrustedImm32(0xffffffff), _as->toInt32Register(source, tReg), tReg);
+ tReg = (typename JITAssembler::RegisterID) targetTemp->index;
+ _as->xor32(TrustedImm32(0xffffffff), _as->toInt32Register(source, tReg), tReg);
if (!targetTemp || targetTemp->kind != IR::Temp::PhysicalRegister)
_as->storeInt32(tReg, target);
return;
}
- generateRuntimeCall(target, complement, Assembler::PointerToValue(source));
+ generateRuntimeCall(_as, target, complement, PointerToValue(source));
}
+template struct QV4::JIT::Unop<QV4::JIT::Assembler<DefaultAssemblerTargetConfiguration>>;
+#if defined(V4_BOOTSTRAP)
+#if !CPU(ARM_THUMB2)
+template struct QV4::JIT::Unop<QV4::JIT::Assembler<AssemblerTargetConfiguration<JSC::MacroAssemblerARMv7, NoOperatingSystemSpecialization>>>;
+#endif
+#if !CPU(ARM64)
+template struct QV4::JIT::Unop<QV4::JIT::Assembler<AssemblerTargetConfiguration<JSC::MacroAssemblerARM64, NoOperatingSystemSpecialization>>>;
+#endif
+#endif
+
#endif
diff --git a/src/qml/jit/qv4unop_p.h b/src/qml/jit/qv4unop_p.h
index 1141a84913..fb68f80eec 100644
--- a/src/qml/jit/qv4unop_p.h
+++ b/src/qml/jit/qv4unop_p.h
@@ -60,21 +60,25 @@ QT_BEGIN_NAMESPACE
namespace QV4 {
namespace JIT {
-class Assembler;
-
+template <typename JITAssembler>
struct Unop {
- Unop(Assembler *assembler, IR::AluOp operation)
+ Unop(JITAssembler *assembler, IR::AluOp operation)
: _as(assembler)
, op(operation)
{}
+ using RelationalCondition = typename JITAssembler::RelationalCondition;
+ using PointerToValue = typename JITAssembler::PointerToValue;
+ using RuntimeCall = typename JITAssembler::RuntimeCall;
+ using TrustedImm32 = typename JITAssembler::TrustedImm32;
+
void generate(IR::Expr *source, IR::Expr *target);
void generateUMinus(IR::Expr *source, IR::Expr *target);
void generateNot(IR::Expr *source, IR::Expr *target);
void generateCompl(IR::Expr *source, IR::Expr *target);
- Assembler *_as;
+ JITAssembler *_as;
IR::AluOp op;
};
diff --git a/src/qml/jsruntime/jsruntime.pri b/src/qml/jsruntime/jsruntime.pri
index 0c55200c64..955cf585e4 100644
--- a/src/qml/jsruntime/jsruntime.pri
+++ b/src/qml/jsruntime/jsruntime.pri
@@ -35,7 +35,6 @@ SOURCES += \
$$PWD/qv4regexp.cpp \
$$PWD/qv4serialize.cpp \
$$PWD/qv4script.cpp \
- $$PWD/qv4executableallocator.cpp \
$$PWD/qv4sequenceobject.cpp \
$$PWD/qv4include.cpp \
$$PWD/qv4qobjectwrapper.cpp \
@@ -83,7 +82,6 @@ HEADERS += \
$$PWD/qv4serialize_p.h \
$$PWD/qv4script_p.h \
$$PWD/qv4scopedvalue_p.h \
- $$PWD/qv4util_p.h \
$$PWD/qv4executableallocator_p.h \
$$PWD/qv4sequenceobject_p.h \
$$PWD/qv4include_p.h \
@@ -108,12 +106,14 @@ HEADERS += \
$$PWD/qv4runtimeapi_p.h \
$$PWD/qv4value_p.h \
$$PWD/qv4string_p.h \
+ $$PWD/qv4util_p.h \
$$PWD/qv4value_p.h
SOURCES += \
$$PWD/qv4runtime.cpp \
$$PWD/qv4string.cpp \
- $$PWD/qv4value.cpp
+ $$PWD/qv4value.cpp \
+ $$PWD/qv4executableallocator.cpp
valgrind {
DEFINES += V4_USE_VALGRIND
diff --git a/src/qml/jsruntime/qv4argumentsobject.cpp b/src/qml/jsruntime/qv4argumentsobject.cpp
index 5a190d6690..9354bcb1a3 100644
--- a/src/qml/jsruntime/qv4argumentsobject.cpp
+++ b/src/qml/jsruntime/qv4argumentsobject.cpp
@@ -88,10 +88,12 @@ void ArgumentsObject::fullyCreate()
Scope scope(engine());
Scoped<MemberData> md(scope, d()->mappedArguments);
- d()->mappedArguments = md->allocate(engine(), numAccessors);
- for (uint i = 0; i < numAccessors; ++i) {
- d()->mappedArguments->data[i] = context()->callData->args[i];
- arraySet(i, context()->engine->argumentsAccessors + i, Attr_Accessor);
+ if (numAccessors) {
+ d()->mappedArguments = md->allocate(engine(), numAccessors);
+ for (uint i = 0; i < numAccessors; ++i) {
+ d()->mappedArguments->data[i] = context()->callData->args[i];
+ arraySet(i, context()->engine->argumentsAccessors + i, Attr_Accessor);
+ }
}
arrayPut(numAccessors, context()->callData->args + numAccessors, argCount - numAccessors);
for (uint i = numAccessors; i < argCount; ++i)
diff --git a/src/qml/jsruntime/qv4arraybuffer.cpp b/src/qml/jsruntime/qv4arraybuffer.cpp
index 23075aa78c..ffe9aa846f 100644
--- a/src/qml/jsruntime/qv4arraybuffer.cpp
+++ b/src/qml/jsruntime/qv4arraybuffer.cpp
@@ -81,16 +81,19 @@ void ArrayBufferCtor::call(const Managed *that, Scope &scope, CallData *callData
construct(that, scope, callData);
}
-ReturnedValue ArrayBufferCtor::method_isView(CallContext *ctx)
+void ArrayBufferCtor::method_isView(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<TypedArray> a(scope, ctx->argument(0));
- if (!!a)
- return Encode(true);
- QV4::Scoped<DataView> v(scope, ctx->argument(0));
- if (!!v)
- return Encode(true);
- return Encode(false);
+ QV4::Scoped<TypedArray> a(scope, callData->argument(0));
+ if (!!a) {
+ scope.result = Encode(true);
+ return;
+ }
+ QV4::Scoped<DataView> v(scope, callData->argument(0));
+ if (!!v) {
+ scope.result = Encode(true);
+ return;
+ }
+ scope.result = Encode(false);
}
@@ -160,54 +163,48 @@ void ArrayBufferPrototype::init(ExecutionEngine *engine, Object *ctor)
defineDefaultProperty(QStringLiteral("toString"), method_toString, 0);
}
-ReturnedValue ArrayBufferPrototype::method_get_byteLength(CallContext *ctx)
+void ArrayBufferPrototype::method_get_byteLength(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<ArrayBuffer> v(scope, ctx->thisObject());
+ Scoped<ArrayBuffer> v(scope, callData->thisObject);
if (!v)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
- return Encode(v->d()->data->size);
+ scope.result = Encode(v->d()->data->size);
}
-ReturnedValue ArrayBufferPrototype::method_slice(CallContext *ctx)
+void ArrayBufferPrototype::method_slice(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<ArrayBuffer> a(scope, ctx->thisObject());
+ Scoped<ArrayBuffer> a(scope, callData->thisObject);
if (!a)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
- double start = ctx->argc() > 0 ? ctx->args()[0].toInteger() : 0;
- double end = (ctx->argc() < 2 || ctx->args()[1].isUndefined()) ?
- a->d()->data->size : ctx->args()[1].toInteger();
- if (scope.engine->hasException)
- return Encode::undefined();
+ double start = callData->argc > 0 ? callData->args[0].toInteger() : 0;
+ double end = (callData->argc < 2 || callData->args[1].isUndefined()) ?
+ a->d()->data->size : callData->args[1].toInteger();
+ CHECK_EXCEPTION();
double first = (start < 0) ? qMax(a->d()->data->size + start, 0.) : qMin(start, (double)a->d()->data->size);
double final = (end < 0) ? qMax(a->d()->data->size + end, 0.) : qMin(end, (double)a->d()->data->size);
ScopedFunctionObject constructor(scope, a->get(scope.engine->id_constructor()));
if (!constructor)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedCallData callData(scope, 1);
+ ScopedCallData cData(scope, 1);
double newLen = qMax(final - first, 0.);
- callData->args[0] = QV4::Encode(newLen);
- constructor->construct(scope, callData);
- QV4::Scoped<ArrayBuffer> newBuffer(scope, scope.result.asReturnedValue());
+ cData->args[0] = QV4::Encode(newLen);
+ constructor->construct(scope, cData);
+ QV4::Scoped<ArrayBuffer> newBuffer(scope, scope.result);
if (!newBuffer || newBuffer->d()->data->size < (int)newLen)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
memcpy(newBuffer->d()->data->data(), a->d()->data->data() + (uint)first, newLen);
-
- return newBuffer.asReturnedValue();
}
-ReturnedValue ArrayBufferPrototype::method_toString(CallContext *ctx)
+void ArrayBufferPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<ArrayBuffer> a(scope, ctx->thisObject());
+ Scoped<ArrayBuffer> a(scope, callData->thisObject);
if (!a)
- return Encode::undefined();
- return Encode(ctx->engine()->newString(QString::fromUtf8(a->asByteArray())));
+ RETURN_UNDEFINED();
+ scope.result = scope.engine->newString(QString::fromUtf8(a->asByteArray()));
}
diff --git a/src/qml/jsruntime/qv4arraybuffer_p.h b/src/qml/jsruntime/qv4arraybuffer_p.h
index bc56d1ea31..4f7926d3dc 100644
--- a/src/qml/jsruntime/qv4arraybuffer_p.h
+++ b/src/qml/jsruntime/qv4arraybuffer_p.h
@@ -81,7 +81,7 @@ struct ArrayBufferCtor: FunctionObject
static void construct(const Managed *m, Scope &scope, CallData *callData);
static void call(const Managed *that, Scope &scope, CallData *callData);
- static ReturnedValue method_isView(CallContext *ctx);
+ static void method_isView(const BuiltinFunction *, Scope &scope, CallData *callData);
};
@@ -104,9 +104,9 @@ struct ArrayBufferPrototype: Object
{
void init(ExecutionEngine *engine, Object *ctor);
- static ReturnedValue method_get_byteLength(CallContext *ctx);
- static ReturnedValue method_slice(CallContext *ctx);
- static ReturnedValue method_toString(CallContext *ctx);
+ static void method_get_byteLength(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_slice(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData);
};
diff --git a/src/qml/jsruntime/qv4arraydata.cpp b/src/qml/jsruntime/qv4arraydata.cpp
index bfeb3d4699..d8a7de5466 100644
--- a/src/qml/jsruntime/qv4arraydata.cpp
+++ b/src/qml/jsruntime/qv4arraydata.cpp
@@ -237,8 +237,14 @@ void ArrayData::ensureAttributes(Object *o)
void SimpleArrayData::markObjects(Heap::Base *d, ExecutionEngine *e)
{
Heap::SimpleArrayData *dd = static_cast<Heap::SimpleArrayData *>(d);
- for (uint i = 0; i < dd->len; ++i)
- dd->arrayData[dd->mappedIndex(i)].mark(e);
+ uint end = dd->offset + dd->len;
+ if (end > dd->alloc) {
+ for (uint i = 0; i < end - dd->alloc; ++i)
+ dd->arrayData[i].mark(e);
+ end = dd->alloc;
+ }
+ for (uint i = dd->offset; i < end; ++i)
+ dd->arrayData[i].mark(e);
}
ReturnedValue SimpleArrayData::get(const Heap::ArrayData *d, uint index)
diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp
index 659ede7552..759354f4e2 100644
--- a/src/qml/jsruntime/qv4arrayobject.cpp
+++ b/src/qml/jsruntime/qv4arrayobject.cpp
@@ -44,6 +44,7 @@
#include "qv4argumentsobject_p.h"
#include "qv4runtime_p.h"
#include "qv4string_p.h"
+#include <QtCore/qscopedvaluerollback.h>
using namespace QV4;
@@ -96,6 +97,8 @@ void ArrayPrototype::init(ExecutionEngine *engine, Object *ctor)
defineDefaultProperty(engine->id_toString(), method_toString, 0);
defineDefaultProperty(QStringLiteral("toLocaleString"), method_toLocaleString, 0);
defineDefaultProperty(QStringLiteral("concat"), method_concat, 1);
+ defineDefaultProperty(QStringLiteral("find"), method_find, 1);
+ defineDefaultProperty(QStringLiteral("findIndex"), method_findIndex, 1);
defineDefaultProperty(QStringLiteral("join"), method_join, 1);
defineDefaultProperty(QStringLiteral("pop"), method_pop, 0);
defineDefaultProperty(QStringLiteral("push"), method_push, 1);
@@ -116,42 +119,40 @@ void ArrayPrototype::init(ExecutionEngine *engine, Object *ctor)
defineDefaultProperty(QStringLiteral("reduceRight"), method_reduceRight, 1);
}
-ReturnedValue ArrayPrototype::method_isArray(CallContext *ctx)
+void ArrayPrototype::method_isArray(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- bool isArray = ctx->argc() && ctx->args()[0].as<ArrayObject>();
- return Encode(isArray);
+ bool isArray = callData->argc && callData->args[0].as<ArrayObject>();
+ scope.result = Encode(isArray);
}
-ReturnedValue ArrayPrototype::method_toString(CallContext *ctx)
+void ArrayPrototype::method_toString(const BuiltinFunction *builtin, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->thisObject(), ScopedObject::Convert);
- if (ctx->d()->engine->hasException)
- return Encode::undefined();
- ScopedString s(scope, ctx->d()->engine->newString(QStringLiteral("join")));
+ ScopedObject o(scope, callData->thisObject, ScopedObject::Convert);
+ CHECK_EXCEPTION();
+ ScopedString s(scope, scope.engine->newString(QStringLiteral("join")));
ScopedFunctionObject f(scope, o->get(s));
if (!!f) {
ScopedCallData d(scope, 0);
- d->thisObject = ctx->thisObject();
+ d->thisObject = callData->thisObject;
f->call(scope, d);
- return scope.result.asReturnedValue();
+ return;
}
- return ObjectPrototype::method_toString(ctx);
+ ObjectPrototype::method_toString(builtin, scope, callData);
}
-ReturnedValue ArrayPrototype::method_toLocaleString(CallContext *ctx)
+void ArrayPrototype::method_toLocaleString(const BuiltinFunction *builtin, Scope &scope, CallData *callData)
{
- return method_toString(ctx);
+ return method_toString(builtin, scope, callData);
}
-ReturnedValue ArrayPrototype::method_concat(CallContext *ctx)
+void ArrayPrototype::method_concat(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject result(scope, ctx->d()->engine->newArrayObject());
-
- ScopedObject thisObject(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject thisObject(scope, callData->thisObject.toObject(scope.engine));
if (!thisObject)
- return Encode::undefined();
+ RETURN_UNDEFINED();
+
+ ScopedArrayObject result(scope, scope.engine->newArrayObject());
+
if (thisObject->isArrayObject()) {
result->copyArrayData(thisObject);
} else {
@@ -161,9 +162,9 @@ ReturnedValue ArrayPrototype::method_concat(CallContext *ctx)
ScopedArrayObject elt(scope);
ScopedObject eltAsObj(scope);
ScopedValue entry(scope);
- for (int i = 0; i < ctx->argc(); ++i) {
- eltAsObj = ctx->args()[i];
- elt = ctx->args()[i];
+ for (int i = 0; i < callData->argc; ++i) {
+ eltAsObj = callData->args[i];
+ elt = callData->args[i];
if (elt) {
uint n = elt->getLength();
uint newLen = ArrayData::append(result, elt, n);
@@ -175,21 +176,90 @@ ReturnedValue ArrayPrototype::method_concat(CallContext *ctx)
result->putIndexed(startIndex + i, entry);
}
} else {
- result->arraySet(result->getLength(), ctx->args()[i]);
+ result->arraySet(result->getLength(), callData->args[i]);
}
}
- return result.asReturnedValue();
+ scope.result = result;
}
-ReturnedValue ArrayPrototype::method_join(CallContext *ctx)
+void ArrayPrototype::method_find(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedValue arg(scope, ctx->argument(0));
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
+ if (!instance)
+ RETURN_UNDEFINED();
+
+ uint len = instance->getLength();
+
+ ScopedFunctionObject callback(scope, callData->argument(0));
+ if (!callback)
+ THROW_TYPE_ERROR();
+
+ ScopedCallData cData(scope, 3);
+ cData->thisObject = callData->argument(1);
+ cData->args[2] = instance;
+
+ ScopedValue v(scope);
+
+ for (uint k = 0; k < len; ++k) {
+ v = instance->getIndexed(k);
+ CHECK_EXCEPTION();
+
+ cData->args[0] = v;
+ cData->args[1] = Primitive::fromDouble(k);
+ callback->call(scope, cData);
+
+ CHECK_EXCEPTION();
+ if (scope.result.toBoolean())
+ RETURN_RESULT(v);
+ }
+ RETURN_UNDEFINED();
+}
+
+void ArrayPrototype::method_findIndex(const BuiltinFunction *, Scope &scope, CallData *callData)
+{
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return ctx->d()->engine->newString()->asReturnedValue();
+ RETURN_UNDEFINED();
+
+ uint len = instance->getLength();
+
+ ScopedFunctionObject callback(scope, callData->argument(0));
+ if (!callback)
+ THROW_TYPE_ERROR();
+
+ ScopedCallData cData(scope, 3);
+ cData->thisObject = callData->argument(1);
+ cData->args[2] = instance;
+
+ ScopedValue v(scope);
+
+ for (uint k = 0; k < len; ++k) {
+ v = instance->getIndexed(k);
+ CHECK_EXCEPTION();
+
+ cData->args[0] = v;
+ cData->args[1] = Primitive::fromDouble(k);
+ callback->call(scope, cData);
+
+ CHECK_EXCEPTION();
+ if (scope.result.toBoolean())
+ RETURN_RESULT(Encode(k));
+ }
+
+ RETURN_RESULT(Encode(-1));
+}
+
+void ArrayPrototype::method_join(const BuiltinFunction *, Scope &scope, CallData *callData)
+{
+ ScopedValue arg(scope, callData->argument(0));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
+
+ if (!instance) {
+ scope.result = scope.engine->newString();
+ return;
+ }
QString r4;
if (arg->isUndefined())
@@ -197,11 +267,13 @@ ReturnedValue ArrayPrototype::method_join(CallContext *ctx)
else
r4 = arg->toQString();
- ScopedValue length(scope, instance->get(ctx->d()->engine->id_length()));
+ ScopedValue length(scope, instance->get(scope.engine->id_length()));
const quint32 r2 = length->isUndefined() ? 0 : length->toUInt32();
- if (!r2)
- return ctx->d()->engine->newString()->asReturnedValue();
+ if (!r2) {
+ scope.result = scope.engine->newString();
+ return;
+ }
QString R;
@@ -213,8 +285,7 @@ ReturnedValue ArrayPrototype::method_join(CallContext *ctx)
R += r4;
e = a->getIndexed(i);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
if (!e->isNullOrUndefined())
R += e->toQString();
}
@@ -222,7 +293,7 @@ ReturnedValue ArrayPrototype::method_join(CallContext *ctx)
//
// crazy!
//
- ScopedString name(scope, ctx->d()->engine->newString(QStringLiteral("0")));
+ ScopedString name(scope, scope.engine->newString(QStringLiteral("0")));
ScopedValue r6(scope, instance->get(name));
if (!r6->isNullOrUndefined())
R = r6->toQString();
@@ -233,99 +304,98 @@ ReturnedValue ArrayPrototype::method_join(CallContext *ctx)
name = Primitive::fromDouble(k).toString(scope.engine);
r12 = instance->get(name);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
if (!r12->isNullOrUndefined())
R += r12->toQString();
}
}
- return ctx->d()->engine->newString(R)->asReturnedValue();
+ scope.result = scope.engine->newString(R);
}
-ReturnedValue ArrayPrototype::method_pop(CallContext *ctx)
+void ArrayPrototype::method_pop(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
+
uint len = instance->getLength();
if (!len) {
if (!instance->isArrayObject())
- instance->put(ctx->d()->engine->id_length(), ScopedValue(scope, Primitive::fromInt32(0)));
- return Encode::undefined();
+ instance->put(scope.engine->id_length(), ScopedValue(scope, Primitive::fromInt32(0)));
+ RETURN_UNDEFINED();
}
ScopedValue result(scope, instance->getIndexed(len - 1));
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
instance->deleteIndexedProperty(len - 1);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
+
if (instance->isArrayObject())
instance->setArrayLength(len - 1);
else
- instance->put(ctx->d()->engine->id_length(), ScopedValue(scope, Primitive::fromDouble(len - 1)));
- return result->asReturnedValue();
+ instance->put(scope.engine->id_length(), ScopedValue(scope, Primitive::fromDouble(len - 1)));
+ scope.result = result;
}
-ReturnedValue ArrayPrototype::method_push(CallContext *ctx)
+void ArrayPrototype::method_push(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
instance->arrayCreate();
Q_ASSERT(instance->arrayData());
uint len = instance->getLength();
- if (len + ctx->argc() < len) {
+ if (len + callData->argc < len) {
// ughh...
double l = len;
ScopedString s(scope);
- for (int i = 0; i < ctx->argc(); ++i) {
+ for (int i = 0; i < callData->argc; ++i) {
s = Primitive::fromDouble(l + i).toString(scope.engine);
- instance->put(s, ctx->args()[i]);
+ instance->put(s, callData->args[i]);
}
- double newLen = l + ctx->argc();
+ double newLen = l + callData->argc;
if (!instance->isArrayObject())
- instance->put(ctx->d()->engine->id_length(), ScopedValue(scope, Primitive::fromDouble(newLen)));
+ instance->put(scope.engine->id_length(), ScopedValue(scope, Primitive::fromDouble(newLen)));
else {
- ScopedString str(scope, ctx->d()->engine->newString(QStringLiteral("Array.prototype.push: Overflow")));
- return ctx->engine()->throwRangeError(str);
+ ScopedString str(scope, scope.engine->newString(QStringLiteral("Array.prototype.push: Overflow")));
+ scope.result = scope.engine->throwRangeError(str);
+ return;
}
- return Encode(newLen);
+ scope.result = Encode(newLen);
+ return;
}
- if (!ctx->argc())
+ if (!callData->argc)
;
else if (!instance->protoHasArray() && instance->arrayData()->length() <= len && instance->arrayData()->type == Heap::ArrayData::Simple) {
- instance->arrayData()->vtable()->putArray(instance, len, ctx->args(), ctx->argc());
+ instance->arrayData()->vtable()->putArray(instance, len, callData->args, callData->argc);
len = instance->arrayData()->length();
} else {
- for (int i = 0; i < ctx->argc(); ++i)
- instance->putIndexed(len + i, ctx->args()[i]);
- len += ctx->argc();
+ for (int i = 0; i < callData->argc; ++i)
+ instance->putIndexed(len + i, callData->args[i]);
+ len += callData->argc;
}
if (instance->isArrayObject())
instance->setArrayLengthUnchecked(len);
else
- instance->put(ctx->d()->engine->id_length(), ScopedValue(scope, Primitive::fromDouble(len)));
+ instance->put(scope.engine->id_length(), ScopedValue(scope, Primitive::fromDouble(len)));
- return Encode(len);
+ scope.result = Encode(len);
}
-ReturnedValue ArrayPrototype::method_reverse(CallContext *ctx)
+void ArrayPrototype::method_reverse(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
+
uint length = instance->getLength();
int lo = 0, hi = length - 1;
@@ -336,28 +406,25 @@ ReturnedValue ArrayPrototype::method_reverse(CallContext *ctx)
bool loExists, hiExists;
lval = instance->getIndexed(lo, &loExists);
hval = instance->getIndexed(hi, &hiExists);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
if (hiExists)
instance->putIndexed(lo, hval);
else
instance->deleteIndexedProperty(lo);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
if (loExists)
instance->putIndexed(hi, lval);
else
instance->deleteIndexedProperty(hi);
}
- return instance.asReturnedValue();
+ scope.result = instance;
}
-ReturnedValue ArrayPrototype::method_shift(CallContext *ctx)
+void ArrayPrototype::method_shift(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
instance->arrayCreate();
Q_ASSERT(instance->arrayData());
@@ -366,54 +433,46 @@ ReturnedValue ArrayPrototype::method_shift(CallContext *ctx)
if (!len) {
if (!instance->isArrayObject())
- instance->put(ctx->d()->engine->id_length(), ScopedValue(scope, Primitive::fromInt32(0)));
- return Encode::undefined();
+ instance->put(scope.engine->id_length(), ScopedValue(scope, Primitive::fromInt32(0)));
+ RETURN_UNDEFINED();
}
- ScopedValue result(scope);
-
if (!instance->protoHasArray() && !instance->arrayData()->attrs && instance->arrayData()->length() <= len && instance->arrayData()->type != Heap::ArrayData::Custom) {
- result = instance->arrayData()->vtable()->pop_front(instance);
+ scope.result = instance->arrayData()->vtable()->pop_front(instance);
} else {
- result = instance->getIndexed(0);
- if (scope.hasException())
- return Encode::undefined();
+ scope.result = instance->getIndexed(0);
+ CHECK_EXCEPTION();
ScopedValue v(scope);
// do it the slow way
for (uint k = 1; k < len; ++k) {
bool exists;
v = instance->getIndexed(k, &exists);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
if (exists)
instance->putIndexed(k - 1, v);
else
instance->deleteIndexedProperty(k - 1);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
}
instance->deleteIndexedProperty(len - 1);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
}
if (instance->isArrayObject())
instance->setArrayLengthUnchecked(len - 1);
else
- instance->put(ctx->d()->engine->id_length(), ScopedValue(scope, Primitive::fromDouble(len - 1)));
- return result->asReturnedValue();
+ instance->put(scope.engine->id_length(), ScopedValue(scope, Primitive::fromDouble(len - 1)));
}
-ReturnedValue ArrayPrototype::method_slice(CallContext *ctx)
+void ArrayPrototype::method_slice(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject o(scope, callData->thisObject.toObject(scope.engine));
if (!o)
- return Encode::undefined();
+ RETURN_UNDEFINED();
- ScopedArrayObject result(scope, ctx->d()->engine->newArrayObject());
+ ScopedArrayObject result(scope, scope.engine->newArrayObject());
uint len = o->getLength();
- double s = ScopedValue(scope, ctx->argument(0))->toInteger();
+ double s = ScopedValue(scope, callData->argument(0))->toInteger();
uint start;
if (s < 0)
start = (uint)qMax(len + s, 0.);
@@ -422,8 +481,8 @@ ReturnedValue ArrayPrototype::method_slice(CallContext *ctx)
else
start = (uint) s;
uint end = len;
- if (ctx->argc() > 1 && !ctx->args()[1].isUndefined()) {
- double e = ctx->args()[1].toInteger();
+ if (callData->argc > 1 && !callData->args[1].isUndefined()) {
+ double e = callData->args[1].toInteger();
if (e < 0)
end = (uint)qMax(len + e, 0.);
else if (e > len)
@@ -437,115 +496,107 @@ ReturnedValue ArrayPrototype::method_slice(CallContext *ctx)
for (uint i = start; i < end; ++i) {
bool exists;
v = o->getIndexed(i, &exists);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
if (exists)
result->arraySet(n, v);
++n;
}
- return result.asReturnedValue();
+ scope.result = result;
}
-ReturnedValue ArrayPrototype::method_sort(CallContext *ctx)
+void ArrayPrototype::method_sort(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
uint len = instance->getLength();
- ScopedValue comparefn(scope, ctx->argument(0));
+ ScopedValue comparefn(scope, callData->argument(0));
ArrayData::sort(scope.engine, instance, comparefn, len);
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
}
-ReturnedValue ArrayPrototype::method_splice(CallContext *ctx)
+void ArrayPrototype::method_splice(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
+
uint len = instance->getLength();
- ScopedArrayObject newArray(scope, ctx->d()->engine->newArrayObject());
+ ScopedArrayObject newArray(scope, scope.engine->newArrayObject());
- double rs = ScopedValue(scope, ctx->argument(0))->toInteger();
+ double rs = ScopedValue(scope, callData->argument(0))->toInteger();
uint start;
if (rs < 0)
start = (uint) qMax(0., len + rs);
else
start = (uint) qMin(rs, (double)len);
- uint deleteCount = (uint)qMin(qMax(ScopedValue(scope, ctx->argument(1))->toInteger(), 0.), (double)(len - start));
+ uint deleteCount = (uint)qMin(qMax(ScopedValue(scope, callData->argument(1))->toInteger(), 0.), (double)(len - start));
newArray->arrayReserve(deleteCount);
ScopedValue v(scope);
for (uint i = 0; i < deleteCount; ++i) {
bool exists;
v = instance->getIndexed(start + i, &exists);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
if (exists)
newArray->arrayPut(i, v);
}
newArray->setArrayLengthUnchecked(deleteCount);
- uint itemCount = ctx->argc() < 2 ? 0 : ctx->argc() - 2;
+ uint itemCount = callData->argc < 2 ? 0 : callData->argc - 2;
if (itemCount < deleteCount) {
for (uint k = start; k < len - deleteCount; ++k) {
bool exists;
v = instance->getIndexed(k + deleteCount, &exists);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
if (exists)
instance->putIndexed(k + itemCount, v);
else
instance->deleteIndexedProperty(k + itemCount);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
}
for (uint k = len; k > len - deleteCount + itemCount; --k) {
instance->deleteIndexedProperty(k - 1);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
}
} else if (itemCount > deleteCount) {
uint k = len - deleteCount;
while (k > start) {
bool exists;
v = instance->getIndexed(k + deleteCount - 1, &exists);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
if (exists)
instance->putIndexed(k + itemCount - 1, v);
else
instance->deleteIndexedProperty(k + itemCount - 1);
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
--k;
}
}
for (uint i = 0; i < itemCount; ++i) {
- instance->putIndexed(start + i, ctx->args()[i + 2]);
- if (scope.hasException())
- return Encode::undefined();
+ instance->putIndexed(start + i, callData->args[i + 2]);
+ CHECK_EXCEPTION();
}
- ctx->d()->strictMode = true;
- instance->put(ctx->d()->engine->id_length(), ScopedValue(scope, Primitive::fromDouble(len - deleteCount + itemCount)));
+ bool wasStrict = scope.engine->current->strictMode;
+ scope.engine->current->strictMode = true;
+ instance->put(scope.engine->id_length(), ScopedValue(scope, Primitive::fromDouble(len - deleteCount + itemCount)));
- return newArray.asReturnedValue();
+ scope.result = newArray;
+ scope.engine->current->strictMode = wasStrict;
}
-ReturnedValue ArrayPrototype::method_unshift(CallContext *ctx)
+void ArrayPrototype::method_unshift(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
instance->arrayCreate();
Q_ASSERT(instance->arrayData());
@@ -554,50 +605,52 @@ ReturnedValue ArrayPrototype::method_unshift(CallContext *ctx)
if (!instance->protoHasArray() && !instance->arrayData()->attrs && instance->arrayData()->length() <= len &&
instance->arrayData()->type != Heap::ArrayData::Custom) {
- instance->arrayData()->vtable()->push_front(instance, ctx->args(), ctx->argc());
+ instance->arrayData()->vtable()->push_front(instance, callData->args, callData->argc);
} else {
ScopedValue v(scope);
for (uint k = len; k > 0; --k) {
bool exists;
v = instance->getIndexed(k - 1, &exists);
if (exists)
- instance->putIndexed(k + ctx->argc() - 1, v);
+ instance->putIndexed(k + callData->argc - 1, v);
else
- instance->deleteIndexedProperty(k + ctx->argc() - 1);
+ instance->deleteIndexedProperty(k + callData->argc - 1);
}
- for (int i = 0; i < ctx->argc(); ++i)
- instance->putIndexed(i, ctx->args()[i]);
+ for (int i = 0; i < callData->argc; ++i)
+ instance->putIndexed(i, callData->args[i]);
}
- uint newLen = len + ctx->argc();
+ uint newLen = len + callData->argc;
if (instance->isArrayObject())
instance->setArrayLengthUnchecked(newLen);
else
- instance->put(ctx->d()->engine->id_length(), ScopedValue(scope, Primitive::fromDouble(newLen)));
+ instance->put(scope.engine->id_length(), ScopedValue(scope, Primitive::fromDouble(newLen)));
- return Encode(newLen);
+ scope.result = Encode(newLen);
}
-ReturnedValue ArrayPrototype::method_indexOf(CallContext *ctx)
+void ArrayPrototype::method_indexOf(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
-
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
+
uint len = instance->getLength();
- if (!len)
- return Encode(-1);
+ if (!len) {
+ scope.result = Encode(-1);
+ return;
+ }
- ScopedValue searchValue(scope, ctx->argument(0));
+ ScopedValue searchValue(scope, callData->argument(0));
uint fromIndex = 0;
- if (ctx->argc() >= 2) {
- double f = ctx->args()[1].toInteger();
- if (scope.hasException())
- return Encode::undefined();
- if (f >= len)
- return Encode(-1);
+ if (callData->argc >= 2) {
+ double f = callData->args[1].toInteger();
+ CHECK_EXCEPTION();
+ if (f >= len) {
+ scope.result = Encode(-1);
+ return;
+ }
if (f < 0)
f = qMax(len + f, 0.);
fromIndex = (uint) f;
@@ -608,10 +661,13 @@ ReturnedValue ArrayPrototype::method_indexOf(CallContext *ctx)
for (uint k = fromIndex; k < len; ++k) {
bool exists;
v = instance->getIndexed(k, &exists);
- if (exists && RuntimeHelpers::strictEqual(v, searchValue))
- return Encode(k);
+ if (exists && RuntimeHelpers::strictEqual(v, searchValue)) {
+ scope.result = Encode(k);
+ return;
+ }
}
- return Encode(-1);
+ scope.result = Encode(-1);
+ return;
}
ScopedValue value(scope);
@@ -622,13 +678,15 @@ ReturnedValue ArrayPrototype::method_indexOf(CallContext *ctx)
for (uint i = fromIndex; i < len; ++i) {
bool exists;
value = instance->getIndexed(i, &exists);
- if (scope.hasException())
- return Encode::undefined();
- if (exists && RuntimeHelpers::strictEqual(value, searchValue))
- return Encode(i);
+ CHECK_EXCEPTION();
+ if (exists && RuntimeHelpers::strictEqual(value, searchValue)) {
+ scope.result = Encode(i);
+ return;
+ }
}
} else if (!instance->arrayData()) {
- return Encode(-1);
+ scope.result = Encode(-1);
+ return;
} else {
Q_ASSERT(instance->arrayType() == Heap::ArrayData::Simple || instance->arrayType() == Heap::ArrayData::Complex);
Heap::SimpleArrayData *sa = instance->d()->arrayData.cast<Heap::SimpleArrayData>();
@@ -637,45 +695,48 @@ ReturnedValue ArrayPrototype::method_indexOf(CallContext *ctx)
uint idx = fromIndex;
while (idx < len) {
value = sa->data(idx);
- if (scope.hasException())
- return Encode::undefined();
- if (RuntimeHelpers::strictEqual(value, searchValue))
- return Encode(idx);
+ CHECK_EXCEPTION();
+ if (RuntimeHelpers::strictEqual(value, searchValue)) {
+ scope.result = Encode(idx);
+ return;
+ }
++idx;
}
}
- return Encode(-1);
+ scope.result = Encode(-1);
}
-ReturnedValue ArrayPrototype::method_lastIndexOf(CallContext *ctx)
+void ArrayPrototype::method_lastIndexOf(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
-
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
+
uint len = instance->getLength();
- if (!len)
- return Encode(-1);
+ if (!len) {
+ scope.result = Encode(-1);
+ return;
+ }
ScopedValue searchValue(scope);
uint fromIndex = len;
- if (ctx->argc() >= 1)
- searchValue = ctx->argument(0);
+ if (callData->argc >= 1)
+ searchValue = callData->argument(0);
else
searchValue = Primitive::undefinedValue();
- if (ctx->argc() >= 2) {
- double f = ctx->args()[1].toInteger();
- if (scope.hasException())
- return Encode::undefined();
+ if (callData->argc >= 2) {
+ double f = callData->args[1].toInteger();
+ CHECK_EXCEPTION();
if (f > 0)
f = qMin(f, (double)(len - 1));
else if (f < 0) {
f = len + f;
- if (f < 0)
- return Encode(-1);
+ if (f < 0) {
+ scope.result = Encode(-1);
+ return;
+ }
}
fromIndex = (uint) f + 1;
}
@@ -685,30 +746,30 @@ ReturnedValue ArrayPrototype::method_lastIndexOf(CallContext *ctx)
--k;
bool exists;
v = instance->getIndexed(k, &exists);
- if (scope.hasException())
- return Encode::undefined();
- if (exists && RuntimeHelpers::strictEqual(v, searchValue))
- return Encode(k);
+ CHECK_EXCEPTION();
+ if (exists && RuntimeHelpers::strictEqual(v, searchValue)) {
+ scope.result = Encode(k);
+ return;
+ }
}
- return Encode(-1);
+ scope.result = Encode(-1);
}
-ReturnedValue ArrayPrototype::method_every(CallContext *ctx)
+void ArrayPrototype::method_every(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
uint len = instance->getLength();
- ScopedFunctionObject callback(scope, ctx->argument(0));
+ ScopedFunctionObject callback(scope, callData->argument(0));
if (!callback)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedCallData callData(scope, 3);
- callData->args[2] = instance;
- callData->thisObject = ctx->argument(1);
+ ScopedCallData cData(scope, 3);
+ cData->args[2] = instance;
+ cData->thisObject = callData->argument(1);
ScopedValue v(scope);
bool ok = true;
@@ -718,30 +779,29 @@ ReturnedValue ArrayPrototype::method_every(CallContext *ctx)
if (!exists)
continue;
- callData->args[0] = v;
- callData->args[1] = Primitive::fromDouble(k);
- callback->call(scope, callData);
+ cData->args[0] = v;
+ cData->args[1] = Primitive::fromDouble(k);
+ callback->call(scope, cData);
ok = scope.result.toBoolean();
}
- return Encode(ok);
+ scope.result = Encode(ok);
}
-ReturnedValue ArrayPrototype::method_some(CallContext *ctx)
+void ArrayPrototype::method_some(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
uint len = instance->getLength();
- ScopedFunctionObject callback(scope, ctx->argument(0));
+ ScopedFunctionObject callback(scope, callData->argument(0));
if (!callback)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedCallData callData(scope, 3);
- callData->thisObject = ctx->argument(1);
- callData->args[2] = instance;
+ ScopedCallData cData(scope, 3);
+ cData->thisObject = callData->argument(1);
+ cData->args[2] = instance;
ScopedValue v(scope);
for (uint k = 0; k < len; ++k) {
@@ -750,31 +810,32 @@ ReturnedValue ArrayPrototype::method_some(CallContext *ctx)
if (!exists)
continue;
- callData->args[0] = v;
- callData->args[1] = Primitive::fromDouble(k);
- callback->call(scope, callData);
- if (scope.result.toBoolean())
- return Encode(true);
+ cData->args[0] = v;
+ cData->args[1] = Primitive::fromDouble(k);
+ callback->call(scope, cData);
+ if (scope.result.toBoolean()) {
+ scope.result = Encode(true);
+ return;
+ }
}
- return Encode(false);
+ scope.result = Encode(false);
}
-ReturnedValue ArrayPrototype::method_forEach(CallContext *ctx)
+void ArrayPrototype::method_forEach(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
uint len = instance->getLength();
- ScopedFunctionObject callback(scope, ctx->argument(0));
+ ScopedFunctionObject callback(scope, callData->argument(0));
if (!callback)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedCallData callData(scope, 3);
- callData->thisObject = ctx->argument(1);
- callData->args[2] = instance;
+ ScopedCallData cData(scope, 3);
+ cData->thisObject = callData->argument(1);
+ cData->args[2] = instance;
ScopedValue v(scope);
for (uint k = 0; k < len; ++k) {
@@ -783,33 +844,32 @@ ReturnedValue ArrayPrototype::method_forEach(CallContext *ctx)
if (!exists)
continue;
- callData->args[0] = v;
- callData->args[1] = Primitive::fromDouble(k);
- callback->call(scope, callData);
+ cData->args[0] = v;
+ cData->args[1] = Primitive::fromDouble(k);
+ callback->call(scope, cData);
}
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
-ReturnedValue ArrayPrototype::method_map(CallContext *ctx)
+void ArrayPrototype::method_map(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
uint len = instance->getLength();
- ScopedFunctionObject callback(scope, ctx->argument(0));
+ ScopedFunctionObject callback(scope, callData->argument(0));
if (!callback)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedArrayObject a(scope, ctx->d()->engine->newArrayObject());
+ ScopedArrayObject a(scope, scope.engine->newArrayObject());
a->arrayReserve(len);
a->setArrayLengthUnchecked(len);
- ScopedCallData callData(scope, 3);
- callData->thisObject = ctx->argument(1);
- callData->args[2] = instance;
+ ScopedCallData cData(scope, 3);
+ cData->thisObject = callData->argument(1);
+ cData->args[2] = instance;
ScopedValue v(scope);
for (uint k = 0; k < len; ++k) {
@@ -818,33 +878,32 @@ ReturnedValue ArrayPrototype::method_map(CallContext *ctx)
if (!exists)
continue;
- callData->args[0] = v;
- callData->args[1] = Primitive::fromDouble(k);
- callback->call(scope, callData);
+ cData->args[0] = v;
+ cData->args[1] = Primitive::fromDouble(k);
+ callback->call(scope, cData);
a->arraySet(k, scope.result);
}
- return a.asReturnedValue();
+ scope.result = a.asReturnedValue();
}
-ReturnedValue ArrayPrototype::method_filter(CallContext *ctx)
+void ArrayPrototype::method_filter(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
uint len = instance->getLength();
- ScopedFunctionObject callback(scope, ctx->argument(0));
+ ScopedFunctionObject callback(scope, callData->argument(0));
if (!callback)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedArrayObject a(scope, ctx->d()->engine->newArrayObject());
+ ScopedArrayObject a(scope, scope.engine->newArrayObject());
a->arrayReserve(len);
- ScopedCallData callData(scope, 3);
- callData->thisObject = ctx->argument(1);
- callData->args[2] = instance;
+ ScopedCallData cData(scope, 3);
+ cData->thisObject = callData->argument(1);
+ cData->args[2] = instance;
ScopedValue v(scope);
@@ -855,35 +914,34 @@ ReturnedValue ArrayPrototype::method_filter(CallContext *ctx)
if (!exists)
continue;
- callData->args[0] = v;
- callData->args[1] = Primitive::fromDouble(k);
- callback->call(scope, callData);
+ cData->args[0] = v;
+ cData->args[1] = Primitive::fromDouble(k);
+ callback->call(scope, cData);
if (scope.result.toBoolean()) {
a->arraySet(to, v);
++to;
}
}
- return a.asReturnedValue();
+ scope.result = a.asReturnedValue();
}
-ReturnedValue ArrayPrototype::method_reduce(CallContext *ctx)
+void ArrayPrototype::method_reduce(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
uint len = instance->getLength();
- ScopedFunctionObject callback(scope, ctx->argument(0));
+ ScopedFunctionObject callback(scope, callData->argument(0));
if (!callback)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
uint k = 0;
ScopedValue v(scope);
- if (ctx->argc() > 1) {
- scope.result = ctx->argument(1);
+ if (callData->argc > 1) {
+ scope.result = callData->argument(1);
} else {
bool kPresent = false;
while (k < len && !kPresent) {
@@ -893,51 +951,50 @@ ReturnedValue ArrayPrototype::method_reduce(CallContext *ctx)
++k;
}
if (!kPresent)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
}
- ScopedCallData callData(scope, 4);
- callData->thisObject = Primitive::undefinedValue();
- callData->args[0] = scope.result;
- callData->args[3] = instance;
+ ScopedCallData cData(scope, 4);
+ cData->thisObject = Primitive::undefinedValue();
+ cData->args[0] = scope.result;
+ cData->args[3] = instance;
while (k < len) {
bool kPresent;
v = instance->getIndexed(k, &kPresent);
if (kPresent) {
- callData->args[0] = scope.result;
- callData->args[1] = v;
- callData->args[2] = Primitive::fromDouble(k);
- callback->call(scope, callData);
+ cData->args[0] = scope.result;
+ cData->args[1] = v;
+ cData->args[2] = Primitive::fromDouble(k);
+ callback->call(scope, cData);
}
++k;
}
- return scope.result.asReturnedValue();
}
-ReturnedValue ArrayPrototype::method_reduceRight(CallContext *ctx)
+void ArrayPrototype::method_reduceRight(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject instance(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
if (!instance)
- return Encode::undefined();
+ RETURN_UNDEFINED();
uint len = instance->getLength();
- ScopedFunctionObject callback(scope, ctx->argument(0));
+ ScopedFunctionObject callback(scope, callData->argument(0));
if (!callback)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (len == 0) {
- if (ctx->argc() == 1)
- return ctx->engine()->throwTypeError();
- return ctx->argument(1);
+ if (callData->argc == 1)
+ THROW_TYPE_ERROR();
+ scope.result = callData->argument(1);
+ return;
}
uint k = len;
ScopedValue v(scope);
- if (ctx->argc() > 1) {
- scope.result = ctx->argument(1);
+ if (callData->argc > 1) {
+ scope.result = callData->argument(1);
} else {
bool kPresent = false;
while (k > 0 && !kPresent) {
@@ -947,24 +1004,24 @@ ReturnedValue ArrayPrototype::method_reduceRight(CallContext *ctx)
--k;
}
if (!kPresent)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
}
- ScopedCallData callData(scope, 4);
- callData->thisObject = Primitive::undefinedValue();
- callData->args[3] = instance;
+ ScopedCallData cData(scope, 4);
+ cData->thisObject = Primitive::undefinedValue();
+ cData->args[3] = instance;
while (k > 0) {
bool kPresent;
v = instance->getIndexed(k - 1, &kPresent);
if (kPresent) {
- callData->args[0] = scope.result;
- callData->args[1] = v;
- callData->args[2] = Primitive::fromDouble(k - 1);
- callback->call(scope, callData);
+ cData->args[0] = scope.result;
+ cData->args[1] = v;
+ cData->args[2] = Primitive::fromDouble(k - 1);
+ callback->call(scope, cData);
}
--k;
}
- return scope.result.asReturnedValue();
+ scope.result = scope.result.asReturnedValue();
}
diff --git a/src/qml/jsruntime/qv4arrayobject_p.h b/src/qml/jsruntime/qv4arrayobject_p.h
index 9a05bb8681..689752433b 100644
--- a/src/qml/jsruntime/qv4arrayobject_p.h
+++ b/src/qml/jsruntime/qv4arrayobject_p.h
@@ -78,28 +78,30 @@ struct ArrayPrototype: ArrayObject
{
void init(ExecutionEngine *engine, Object *ctor);
- static ReturnedValue method_isArray(CallContext *ctx);
- static ReturnedValue method_toString(CallContext *ctx);
- static ReturnedValue method_toLocaleString(CallContext *ctx);
- static ReturnedValue method_concat(CallContext *ctx);
- static ReturnedValue method_join(CallContext *ctx);
- static ReturnedValue method_pop(CallContext *ctx);
- static ReturnedValue method_push(CallContext *ctx);
- static ReturnedValue method_reverse(CallContext *ctx);
- static ReturnedValue method_shift(CallContext *ctx);
- static ReturnedValue method_slice(CallContext *ctx);
- static ReturnedValue method_sort(CallContext *ctx);
- static ReturnedValue method_splice(CallContext *ctx);
- static ReturnedValue method_unshift(CallContext *ctx);
- static ReturnedValue method_indexOf(CallContext *ctx);
- static ReturnedValue method_lastIndexOf(CallContext *ctx);
- static ReturnedValue method_every(CallContext *ctx);
- static ReturnedValue method_some(CallContext *ctx);
- static ReturnedValue method_forEach(CallContext *ctx);
- static ReturnedValue method_map(CallContext *ctx);
- static ReturnedValue method_filter(CallContext *ctx);
- static ReturnedValue method_reduce(CallContext *ctx);
- static ReturnedValue method_reduceRight(CallContext *ctx);
+ static void method_isArray(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_toString(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_toLocaleString(const BuiltinFunction *builtin, Scope &, CallData *callData);
+ static void method_concat(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_find(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_findIndex(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_join(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_pop(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_push(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_reverse(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_shift(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_slice(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_sort(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_splice(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_unshift(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_indexOf(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_lastIndexOf(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_every(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_some(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_forEach(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_map(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_filter(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_reduce(const BuiltinFunction *, Scope &, CallData *callData);
+ static void method_reduceRight(const BuiltinFunction *, Scope &, CallData *callData);
};
diff --git a/src/qml/jsruntime/qv4booleanobject.cpp b/src/qml/jsruntime/qv4booleanobject.cpp
index 8047993266..601066110f 100644
--- a/src/qml/jsruntime/qv4booleanobject.cpp
+++ b/src/qml/jsruntime/qv4booleanobject.cpp
@@ -73,29 +73,31 @@ void BooleanPrototype::init(ExecutionEngine *engine, Object *ctor)
defineDefaultProperty(engine->id_valueOf(), method_valueOf);
}
-ReturnedValue BooleanPrototype::method_toString(CallContext *ctx)
+void BooleanPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
bool result;
- if (ctx->thisObject().isBoolean()) {
- result = ctx->thisObject().booleanValue();
+ if (callData->thisObject.isBoolean()) {
+ result = callData->thisObject.booleanValue();
} else {
- const BooleanObject *thisObject = ctx->thisObject().as<BooleanObject>();
+ const BooleanObject *thisObject = callData->thisObject.as<BooleanObject>();
if (!thisObject)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
result = thisObject->value();
}
- return Encode(ctx->d()->engine->newString(QLatin1String(result ? "true" : "false")));
+ scope.result = scope.engine->newString(QLatin1String(result ? "true" : "false"));
}
-ReturnedValue BooleanPrototype::method_valueOf(CallContext *ctx)
+void BooleanPrototype::method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->thisObject().isBoolean())
- return ctx->thisObject().asReturnedValue();
+ if (callData->thisObject.isBoolean()) {
+ scope.result = callData->thisObject.asReturnedValue();
+ return;
+ }
- const BooleanObject *thisObject = ctx->thisObject().as<BooleanObject>();
+ const BooleanObject *thisObject = callData->thisObject.as<BooleanObject>();
if (!thisObject)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- return Encode(thisObject->value());
+ scope.result = Encode(thisObject->value());
}
diff --git a/src/qml/jsruntime/qv4booleanobject_p.h b/src/qml/jsruntime/qv4booleanobject_p.h
index 4c2f3c09e7..9c8b1d67f1 100644
--- a/src/qml/jsruntime/qv4booleanobject_p.h
+++ b/src/qml/jsruntime/qv4booleanobject_p.h
@@ -78,8 +78,8 @@ struct BooleanPrototype: BooleanObject
{
void init(ExecutionEngine *engine, Object *ctor);
- static ReturnedValue method_toString(CallContext *ctx);
- static ReturnedValue method_valueOf(CallContext *ctx);
+ static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData);
};
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp
index 544d39339b..60b90e4bf0 100644
--- a/src/qml/jsruntime/qv4context.cpp
+++ b/src/qml/jsruntime/qv4context.cpp
@@ -95,6 +95,17 @@ Heap::CallContext *ExecutionContext::newCallContext(Function *function, CallData
return c;
}
+Heap::CallContext *Heap::CallContext::createSimpleContext(ExecutionEngine *v4)
+{
+ Heap::CallContext *ctxt = v4->memoryManager->allocSimpleCallContext(v4);
+ return ctxt;
+}
+
+void Heap::CallContext::freeSimpleCallContext()
+{
+ engine->memoryManager->freeSimpleCallContext();
+}
+
Heap::WithContext *ExecutionContext::newWithContext(Heap::Object *with)
{
return d()->engine->memoryManager->alloc<WithContext>(d(), with);
@@ -325,26 +336,27 @@ void QV4::ExecutionContext::simpleCall(Scope &scope, CallData *callData, Functio
ExecutionContextSaver ctxSaver(scope);
- CallContext::Data ctx = CallContext::Data::createOnStack(scope.engine);
+ CallContext::Data *ctx = scope.engine->memoryManager->allocSimpleCallContext(scope.engine);
- ctx.strictMode = function->isStrict();
- ctx.callData = callData;
- ctx.v4Function = function;
- ctx.compilationUnit = function->compilationUnit;
- ctx.lookups = function->compilationUnit->runtimeLookups;
- ctx.constantTable = function->compilationUnit->constants;
- ctx.outer = this->d();
- ctx.locals = scope.alloc(function->compiledFunction->nLocals);
+ ctx->strictMode = function->isStrict();
+ ctx->callData = callData;
+ ctx->v4Function = function;
+ ctx->compilationUnit = function->compilationUnit;
+ ctx->lookups = function->compilationUnit->runtimeLookups;
+ ctx->constantTable = function->compilationUnit->constants;
+ ctx->outer = this->d();
+ ctx->locals = scope.alloc(function->compiledFunction->nLocals);
for (int i = callData->argc; i < (int)function->nFormals; ++i)
callData->args[i] = Encode::undefined();
- scope.engine->pushContext(&ctx);
- Q_ASSERT(scope.engine->current == &ctx);
+ scope.engine->pushContext(ctx);
+ Q_ASSERT(scope.engine->current == ctx);
scope.result = Q_V4_PROFILE(scope.engine, function);
if (function->hasQmlDependencies)
QQmlPropertyCapture::registerQmlDependencies(function->compiledFunction, scope);
+ scope.engine->memoryManager->freeSimpleCallContext();
}
void ExecutionContext::setProperty(String *name, const Value &value)
diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h
index c985fdb24d..bcfee2e1f8 100644
--- a/src/qml/jsruntime/qv4context_p.h
+++ b/src/qml/jsruntime/qv4context_p.h
@@ -109,14 +109,8 @@ struct ExecutionContext : Base {
{
Base::init();
- callData = nullptr;
this->engine = engine;
- outer = nullptr;
- lookups = nullptr;
- constantTable = nullptr;
- compilationUnit = nullptr;
type = t;
- strictMode = false;
lineNumber = -1;
}
@@ -135,15 +129,12 @@ struct ExecutionContext : Base {
V4_ASSERT_IS_TRIVIAL(ExecutionContext)
struct CallContext : ExecutionContext {
- static CallContext createOnStack(ExecutionEngine *v4);
+ static CallContext *createSimpleContext(ExecutionEngine *v4);
+ void freeSimpleCallContext();
void init(ExecutionEngine *engine, ContextType t = Type_SimpleCallContext)
{
ExecutionContext::init(engine, t);
- function = 0;
- v4Function = 0;
- locals = 0;
- activation = 0;
}
inline unsigned int formalParameterCount() const;
@@ -247,6 +238,7 @@ struct Q_QML_EXPORT CallContext : public ExecutionContext
inline ReturnedValue argument(int i) const;
bool needsOwnArguments() const;
+
};
inline ReturnedValue CallContext::argument(int i) const {
@@ -289,16 +281,6 @@ inline const WithContext *ExecutionContext::asWithContext() const
return d()->type == Heap::ExecutionContext::Type_WithContext ? static_cast<const WithContext *>(this) : 0;
}
-inline Heap::CallContext Heap::CallContext::createOnStack(ExecutionEngine *v4)
-{
- Heap::CallContext ctxt;
- memset(&ctxt, 0, sizeof(Heap::CallContext));
- ctxt.mm_data = 0;
- ctxt.setVtable(QV4::CallContext::staticVTable());
- ctxt.init(v4);
- return ctxt;
-}
-
} // namespace QV4
QT_END_NAMESPACE
diff --git a/src/qml/jsruntime/qv4dataview.cpp b/src/qml/jsruntime/qv4dataview.cpp
index db8376272d..a810b38f24 100644
--- a/src/qml/jsruntime/qv4dataview.cpp
+++ b/src/qml/jsruntime/qv4dataview.cpp
@@ -129,90 +129,84 @@ void DataViewPrototype::init(ExecutionEngine *engine, Object *ctor)
defineDefaultProperty(QStringLiteral("setUInt32"), method_set<unsigned int>, 0);
}
-ReturnedValue DataViewPrototype::method_get_buffer(CallContext *ctx)
+void DataViewPrototype::method_get_buffer(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<DataView> v(scope, ctx->thisObject());
+ Scoped<DataView> v(scope, callData->thisObject);
if (!v)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
- return Encode(v->d()->buffer->asReturnedValue());
+ scope.result = v->d()->buffer;
}
-ReturnedValue DataViewPrototype::method_get_byteLength(CallContext *ctx)
+void DataViewPrototype::method_get_byteLength(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<DataView> v(scope, ctx->thisObject());
+ Scoped<DataView> v(scope, callData->thisObject);
if (!v)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
- return Encode(v->d()->byteLength);
+ scope.result = Encode(v->d()->byteLength);
}
-ReturnedValue DataViewPrototype::method_get_byteOffset(CallContext *ctx)
+void DataViewPrototype::method_get_byteOffset(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<DataView> v(scope, ctx->thisObject());
+ Scoped<DataView> v(scope, callData->thisObject);
if (!v)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
- return Encode(v->d()->byteOffset);
+ scope.result = Encode(v->d()->byteOffset);
}
template <typename T>
-ReturnedValue DataViewPrototype::method_getChar(CallContext *ctx)
+void DataViewPrototype::method_getChar(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<DataView> v(scope, ctx->thisObject());
- if (!v || ctx->argc() < 1)
- return scope.engine->throwTypeError();
- double l = ctx->args()[0].toNumber();
+ Scoped<DataView> v(scope, callData->thisObject);
+ if (!v || callData->argc < 1)
+ THROW_TYPE_ERROR();
+ double l = callData->args[0].toNumber();
uint idx = (uint)l;
if (l != idx || idx + sizeof(T) > v->d()->byteLength)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
idx += v->d()->byteOffset;
T t = T(v->d()->buffer->data->data()[idx]);
- return Encode((int)t);
+ scope.result = Encode((int)t);
}
template <typename T>
-ReturnedValue DataViewPrototype::method_get(CallContext *ctx)
+void DataViewPrototype::method_get(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<DataView> v(scope, ctx->thisObject());
- if (!v || ctx->argc() < 1)
- return scope.engine->throwTypeError();
- double l = ctx->args()[0].toNumber();
+ Scoped<DataView> v(scope, callData->thisObject);
+ if (!v || callData->argc < 1)
+ THROW_TYPE_ERROR();
+ double l = callData->args[0].toNumber();
uint idx = (uint)l;
if (l != idx || idx + sizeof(T) > v->d()->byteLength)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
idx += v->d()->byteOffset;
- bool littleEndian = ctx->argc() < 2 ? false : ctx->args()[1].toBoolean();
+ bool littleEndian = callData->argc < 2 ? false : callData->args[1].toBoolean();
T t = littleEndian
? qFromLittleEndian<T>((uchar *)v->d()->buffer->data->data() + idx)
: qFromBigEndian<T>((uchar *)v->d()->buffer->data->data() + idx);
- return Encode(t);
+ scope.result = Encode(t);
}
template <typename T>
-ReturnedValue DataViewPrototype::method_getFloat(CallContext *ctx)
+void DataViewPrototype::method_getFloat(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<DataView> v(scope, ctx->thisObject());
- if (!v || ctx->argc() < 1)
- return scope.engine->throwTypeError();
- double l = ctx->args()[0].toNumber();
+ Scoped<DataView> v(scope, callData->thisObject);
+ if (!v || callData->argc < 1)
+ THROW_TYPE_ERROR();
+ double l = callData->args[0].toNumber();
uint idx = (uint)l;
if (l != idx || idx + sizeof(T) > v->d()->byteLength)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
idx += v->d()->byteOffset;
- bool littleEndian = ctx->argc() < 2 ? false : ctx->args()[1].toBoolean();
+ bool littleEndian = callData->argc < 2 ? false : callData->args[1].toBoolean();
if (sizeof(T) == 4) {
// float
@@ -223,7 +217,7 @@ ReturnedValue DataViewPrototype::method_getFloat(CallContext *ctx)
u.i = littleEndian
? qFromLittleEndian<uint>((uchar *)v->d()->buffer->data->data() + idx)
: qFromBigEndian<uint>((uchar *)v->d()->buffer->data->data() + idx);
- return Encode(u.f);
+ scope.result = Encode(u.f);
} else {
Q_ASSERT(sizeof(T) == 8);
union {
@@ -233,69 +227,66 @@ ReturnedValue DataViewPrototype::method_getFloat(CallContext *ctx)
u.i = littleEndian
? qFromLittleEndian<quint64>((uchar *)v->d()->buffer->data->data() + idx)
: qFromBigEndian<quint64>((uchar *)v->d()->buffer->data->data() + idx);
- return Encode(u.d);
+ scope.result = Encode(u.d);
}
}
template <typename T>
-ReturnedValue DataViewPrototype::method_setChar(CallContext *ctx)
+void DataViewPrototype::method_setChar(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<DataView> v(scope, ctx->thisObject());
- if (!v || ctx->argc() < 1)
- return scope.engine->throwTypeError();
- double l = ctx->args()[0].toNumber();
+ Scoped<DataView> v(scope, callData->thisObject);
+ if (!v || callData->argc < 1)
+ THROW_TYPE_ERROR();
+ double l = callData->args[0].toNumber();
uint idx = (uint)l;
if (l != idx || idx + sizeof(T) > v->d()->byteLength)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
idx += v->d()->byteOffset;
- int val = ctx->argc() >= 2 ? ctx->args()[1].toInt32() : 0;
+ int val = callData->argc >= 2 ? callData->args[1].toInt32() : 0;
v->d()->buffer->data->data()[idx] = (char)val;
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
template <typename T>
-ReturnedValue DataViewPrototype::method_set(CallContext *ctx)
+void DataViewPrototype::method_set(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<DataView> v(scope, ctx->thisObject());
- if (!v || ctx->argc() < 1)
- return scope.engine->throwTypeError();
- double l = ctx->args()[0].toNumber();
+ Scoped<DataView> v(scope, callData->thisObject);
+ if (!v || callData->argc < 1)
+ THROW_TYPE_ERROR();
+ double l = callData->args[0].toNumber();
uint idx = (uint)l;
if (l != idx || idx + sizeof(T) > v->d()->byteLength)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
idx += v->d()->byteOffset;
- int val = ctx->argc() >= 2 ? ctx->args()[1].toInt32() : 0;
+ int val = callData->argc >= 2 ? callData->args[1].toInt32() : 0;
- bool littleEndian = ctx->argc() < 3 ? false : ctx->args()[2].toBoolean();
+ bool littleEndian = callData->argc < 3 ? false : callData->args[2].toBoolean();
if (littleEndian)
qToLittleEndian<T>(val, (uchar *)v->d()->buffer->data->data() + idx);
else
qToBigEndian<T>(val, (uchar *)v->d()->buffer->data->data() + idx);
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
template <typename T>
-ReturnedValue DataViewPrototype::method_setFloat(CallContext *ctx)
+void DataViewPrototype::method_setFloat(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<DataView> v(scope, ctx->thisObject());
- if (!v || ctx->argc() < 1)
- return scope.engine->throwTypeError();
- double l = ctx->args()[0].toNumber();
+ Scoped<DataView> v(scope, callData->thisObject);
+ if (!v || callData->argc < 1)
+ THROW_TYPE_ERROR();
+ double l = callData->args[0].toNumber();
uint idx = (uint)l;
if (l != idx || idx + sizeof(T) > v->d()->byteLength)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
idx += v->d()->byteOffset;
- double val = ctx->argc() >= 2 ? ctx->args()[1].toNumber() : qt_qnan();
- bool littleEndian = ctx->argc() < 3 ? false : ctx->args()[2].toBoolean();
+ double val = callData->argc >= 2 ? callData->args[1].toNumber() : qt_qnan();
+ bool littleEndian = callData->argc < 3 ? false : callData->args[2].toBoolean();
if (sizeof(T) == 4) {
// float
@@ -320,5 +311,5 @@ ReturnedValue DataViewPrototype::method_setFloat(CallContext *ctx)
else
qToBigEndian(u.i, (uchar *)v->d()->buffer->data->data() + idx);
}
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
diff --git a/src/qml/jsruntime/qv4dataview_p.h b/src/qml/jsruntime/qv4dataview_p.h
index 246124394a..11cc0a6bd9 100644
--- a/src/qml/jsruntime/qv4dataview_p.h
+++ b/src/qml/jsruntime/qv4dataview_p.h
@@ -92,21 +92,21 @@ struct DataViewPrototype: Object
{
void init(ExecutionEngine *engine, Object *ctor);
- static ReturnedValue method_get_buffer(CallContext *ctx);
- static ReturnedValue method_get_byteLength(CallContext *ctx);
- static ReturnedValue method_get_byteOffset(CallContext *ctx);
+ static void method_get_buffer(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_byteLength(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_byteOffset(const BuiltinFunction *, Scope &scope, CallData *callData);
template <typename T>
- static ReturnedValue method_getChar(CallContext *ctx);
+ static void method_getChar(const BuiltinFunction *, Scope &scope, CallData *callData);
template <typename T>
- static ReturnedValue method_get(CallContext *ctx);
+ static void method_get(const BuiltinFunction *, Scope &scope, CallData *callData);
template <typename T>
- static ReturnedValue method_getFloat(CallContext *ctx);
+ static void method_getFloat(const BuiltinFunction *, Scope &scope, CallData *callData);
template <typename T>
- static ReturnedValue method_setChar(CallContext *ctx);
+ static void method_setChar(const BuiltinFunction *, Scope &scope, CallData *callData);
template <typename T>
- static ReturnedValue method_set(CallContext *ctx);
+ static void method_set(const BuiltinFunction *, Scope &scope, CallData *callData);
template <typename T>
- static ReturnedValue method_setFloat(CallContext *ctx);
+ static void method_setFloat(const BuiltinFunction *, Scope &scope, CallData *callData);
};
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp
index 8cc6a25fea..b90c335b1c 100644
--- a/src/qml/jsruntime/qv4dateobject.cpp
+++ b/src/qml/jsruntime/qv4dateobject.cpp
@@ -780,435 +780,435 @@ void DatePrototype::init(ExecutionEngine *engine, Object *ctor)
defineDefaultProperty(QStringLiteral("toJSON"), method_toJSON, 1);
}
-double DatePrototype::getThisDate(ExecutionContext *ctx)
+double DatePrototype::getThisDate(Scope &scope, CallData *callData)
{
- if (DateObject *thisObject = ctx->thisObject().as<DateObject>())
+ if (DateObject *thisObject = callData->thisObject.as<DateObject>())
return thisObject->date();
else {
- ctx->engine()->throwTypeError();
+ scope.engine->throwTypeError();
return 0;
}
}
-ReturnedValue DatePrototype::method_parse(CallContext *ctx)
+void DatePrototype::method_parse(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (!ctx->argc())
- return Encode(qt_qnan());
- return Encode(ParseString(ctx->args()[0].toQString()));
+ if (!callData->argc)
+ scope.result = Encode(qt_qnan());
+ else
+ scope.result = Encode(ParseString(callData->args[0].toQString()));
}
-ReturnedValue DatePrototype::method_UTC(CallContext *ctx)
+void DatePrototype::method_UTC(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- const int numArgs = ctx->argc();
+ const int numArgs = callData->argc;
if (numArgs >= 2) {
- double year = ctx->args()[0].toNumber();
- double month = ctx->args()[1].toNumber();
- double day = numArgs >= 3 ? ctx->args()[2].toNumber() : 1;
- double hours = numArgs >= 4 ? ctx->args()[3].toNumber() : 0;
- double mins = numArgs >= 5 ? ctx->args()[4].toNumber() : 0;
- double secs = numArgs >= 6 ? ctx->args()[5].toNumber() : 0;
- double ms = numArgs >= 7 ? ctx->args()[6].toNumber() : 0;
+ double year = callData->args[0].toNumber();
+ double month = callData->args[1].toNumber();
+ double day = numArgs >= 3 ? callData->args[2].toNumber() : 1;
+ double hours = numArgs >= 4 ? callData->args[3].toNumber() : 0;
+ double mins = numArgs >= 5 ? callData->args[4].toNumber() : 0;
+ double secs = numArgs >= 6 ? callData->args[5].toNumber() : 0;
+ double ms = numArgs >= 7 ? callData->args[6].toNumber() : 0;
if (year >= 0 && year <= 99)
year += 1900;
double t = MakeDate(MakeDay(year, month, day),
MakeTime(hours, mins, secs, ms));
- return Encode(TimeClip(t));
+ scope.result = Encode(TimeClip(t));
+ return;
}
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
-ReturnedValue DatePrototype::method_now(CallContext *ctx)
+void DatePrototype::method_now(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Q_UNUSED(ctx);
+ Q_UNUSED(callData);
double t = currentTime();
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_toString(CallContext *ctx)
+void DatePrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- return ctx->d()->engine->newString(ToString(t))->asReturnedValue();
+ double t = getThisDate(scope, callData);
+ scope.result = scope.engine->newString(ToString(t));
}
-ReturnedValue DatePrototype::method_toDateString(CallContext *ctx)
+void DatePrototype::method_toDateString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- return ctx->d()->engine->newString(ToDateString(t))->asReturnedValue();
+ double t = getThisDate(scope, callData);
+ scope.result = scope.engine->newString(ToDateString(t));
}
-ReturnedValue DatePrototype::method_toTimeString(CallContext *ctx)
+void DatePrototype::method_toTimeString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- return ctx->d()->engine->newString(ToTimeString(t))->asReturnedValue();
+ double t = getThisDate(scope, callData);
+ scope.result = scope.engine->newString(ToTimeString(t));
}
-ReturnedValue DatePrototype::method_toLocaleString(CallContext *ctx)
+void DatePrototype::method_toLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- return ctx->d()->engine->newString(ToLocaleString(t))->asReturnedValue();
+ double t = getThisDate(scope, callData);
+ scope.result = scope.engine->newString(ToLocaleString(t));
}
-ReturnedValue DatePrototype::method_toLocaleDateString(CallContext *ctx)
+void DatePrototype::method_toLocaleDateString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- return ctx->d()->engine->newString(ToLocaleDateString(t))->asReturnedValue();
+ double t = getThisDate(scope, callData);
+ scope.result = scope.engine->newString(ToLocaleDateString(t));
}
-ReturnedValue DatePrototype::method_toLocaleTimeString(CallContext *ctx)
+void DatePrototype::method_toLocaleTimeString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- return ctx->d()->engine->newString(ToLocaleTimeString(t))->asReturnedValue();
+ double t = getThisDate(scope, callData);
+ scope.result = scope.engine->newString(ToLocaleTimeString(t));
}
-ReturnedValue DatePrototype::method_valueOf(CallContext *ctx)
+void DatePrototype::method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- return Encode(t);
+ double t = getThisDate(scope, callData);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getTime(CallContext *ctx)
+void DatePrototype::method_getTime(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- return Encode(t);
+ double t = getThisDate(scope, callData);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getYear(CallContext *ctx)
+void DatePrototype::method_getYear(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = YearFromTime(LocalTime(t)) - 1900;
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getFullYear(CallContext *ctx)
+void DatePrototype::method_getFullYear(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = YearFromTime(LocalTime(t));
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getUTCFullYear(CallContext *ctx)
+void DatePrototype::method_getUTCFullYear(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = YearFromTime(t);
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getMonth(CallContext *ctx)
+void DatePrototype::method_getMonth(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = MonthFromTime(LocalTime(t));
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getUTCMonth(CallContext *ctx)
+void DatePrototype::method_getUTCMonth(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = MonthFromTime(t);
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getDate(CallContext *ctx)
+void DatePrototype::method_getDate(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = DateFromTime(LocalTime(t));
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getUTCDate(CallContext *ctx)
+void DatePrototype::method_getUTCDate(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = DateFromTime(t);
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getDay(CallContext *ctx)
+void DatePrototype::method_getDay(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = WeekDay(LocalTime(t));
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getUTCDay(CallContext *ctx)
+void DatePrototype::method_getUTCDay(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = WeekDay(t);
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getHours(CallContext *ctx)
+void DatePrototype::method_getHours(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = HourFromTime(LocalTime(t));
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getUTCHours(CallContext *ctx)
+void DatePrototype::method_getUTCHours(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = HourFromTime(t);
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getMinutes(CallContext *ctx)
+void DatePrototype::method_getMinutes(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = MinFromTime(LocalTime(t));
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getUTCMinutes(CallContext *ctx)
+void DatePrototype::method_getUTCMinutes(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = MinFromTime(t);
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getSeconds(CallContext *ctx)
+void DatePrototype::method_getSeconds(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = SecFromTime(LocalTime(t));
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getUTCSeconds(CallContext *ctx)
+void DatePrototype::method_getUTCSeconds(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = SecFromTime(t);
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getMilliseconds(CallContext *ctx)
+void DatePrototype::method_getMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = msFromTime(LocalTime(t));
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getUTCMilliseconds(CallContext *ctx)
+void DatePrototype::method_getUTCMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = msFromTime(t);
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_getTimezoneOffset(CallContext *ctx)
+void DatePrototype::method_getTimezoneOffset(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double t = getThisDate(ctx);
- if (! std::isnan(t))
+ double t = getThisDate(scope, callData);
+ if (!std::isnan(t))
t = (t - LocalTime(t)) / msPerMinute;
- return Encode(t);
+ scope.result = Encode(t);
}
-ReturnedValue DatePrototype::method_setTime(CallContext *ctx)
+void DatePrototype::method_setTime(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<DateObject> self(scope, ctx->thisObject());
+ Scoped<DateObject> self(scope, callData->thisObject);
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- double t = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
+ double t = callData->argc ? callData->args[0].toNumber() : qt_qnan();
self->setDate(TimeClip(t));
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setMilliseconds(CallContext *ctx)
+void DatePrototype::method_setMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<DateObject> self(scope, ctx->thisObject());
+ Scoped<DateObject> self(scope, callData->thisObject);
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = LocalTime(self->date());
- double ms = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
+ double ms = callData->argc ? callData->args[0].toNumber() : qt_qnan();
self->setDate(TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms)))));
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setUTCMilliseconds(CallContext *ctx)
+void DatePrototype::method_setUTCMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = self->date();
- double ms = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
+ double ms = callData->argc ? callData->args[0].toNumber() : qt_qnan();
self->setDate(TimeClip(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms))));
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setSeconds(CallContext *ctx)
+void DatePrototype::method_setSeconds(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = LocalTime(self->date());
- double sec = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
- double ms = (ctx->argc() < 2) ? msFromTime(t) : ctx->args()[1].toNumber();
+ double sec = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ double ms = (callData->argc < 2) ? msFromTime(t) : callData->args[1].toNumber();
t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), sec, ms))));
self->setDate(t);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setUTCSeconds(CallContext *ctx)
+void DatePrototype::method_setUTCSeconds(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = self->date();
- double sec = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
- double ms = (ctx->argc() < 2) ? msFromTime(t) : ctx->args()[1].toNumber();
+ double sec = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ double ms = (callData->argc < 2) ? msFromTime(t) : callData->args[1].toNumber();
t = TimeClip(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), sec, ms)));
self->setDate(t);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setMinutes(CallContext *ctx)
+void DatePrototype::method_setMinutes(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = LocalTime(self->date());
- double min = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
- double sec = (ctx->argc() < 2) ? SecFromTime(t) : ctx->args()[1].toNumber();
- double ms = (ctx->argc() < 3) ? msFromTime(t) : ctx->args()[2].toNumber();
+ double min = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ double sec = (callData->argc < 2) ? SecFromTime(t) : callData->args[1].toNumber();
+ double ms = (callData->argc < 3) ? msFromTime(t) : callData->args[2].toNumber();
t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), min, sec, ms))));
self->setDate(t);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setUTCMinutes(CallContext *ctx)
+void DatePrototype::method_setUTCMinutes(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = self->date();
- double min = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
- double sec = (ctx->argc() < 2) ? SecFromTime(t) : ctx->args()[1].toNumber();
- double ms = (ctx->argc() < 3) ? msFromTime(t) : ctx->args()[2].toNumber();
+ double min = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ double sec = (callData->argc < 2) ? SecFromTime(t) : callData->args[1].toNumber();
+ double ms = (callData->argc < 3) ? msFromTime(t) : callData->args[2].toNumber();
t = TimeClip(MakeDate(Day(t), MakeTime(HourFromTime(t), min, sec, ms)));
self->setDate(t);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setHours(CallContext *ctx)
+void DatePrototype::method_setHours(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = LocalTime(self->date());
- double hour = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
- double min = (ctx->argc() < 2) ? MinFromTime(t) : ctx->args()[1].toNumber();
- double sec = (ctx->argc() < 3) ? SecFromTime(t) : ctx->args()[2].toNumber();
- double ms = (ctx->argc() < 4) ? msFromTime(t) : ctx->args()[3].toNumber();
+ double hour = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ double min = (callData->argc < 2) ? MinFromTime(t) : callData->args[1].toNumber();
+ double sec = (callData->argc < 3) ? SecFromTime(t) : callData->args[2].toNumber();
+ double ms = (callData->argc < 4) ? msFromTime(t) : callData->args[3].toNumber();
t = TimeClip(UTC(MakeDate(Day(t), MakeTime(hour, min, sec, ms))));
self->setDate(t);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setUTCHours(CallContext *ctx)
+void DatePrototype::method_setUTCHours(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = self->date();
- double hour = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
- double min = (ctx->argc() < 2) ? MinFromTime(t) : ctx->args()[1].toNumber();
- double sec = (ctx->argc() < 3) ? SecFromTime(t) : ctx->args()[2].toNumber();
- double ms = (ctx->argc() < 4) ? msFromTime(t) : ctx->args()[3].toNumber();
+ double hour = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ double min = (callData->argc < 2) ? MinFromTime(t) : callData->args[1].toNumber();
+ double sec = (callData->argc < 3) ? SecFromTime(t) : callData->args[2].toNumber();
+ double ms = (callData->argc < 4) ? msFromTime(t) : callData->args[3].toNumber();
t = TimeClip(MakeDate(Day(t), MakeTime(hour, min, sec, ms)));
self->setDate(t);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setDate(CallContext *ctx)
+void DatePrototype::method_setDate(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = LocalTime(self->date());
- double date = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
+ double date = callData->argc ? callData->args[0].toNumber() : qt_qnan();
t = TimeClip(UTC(MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), date), TimeWithinDay(t))));
self->setDate(t);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setUTCDate(CallContext *ctx)
+void DatePrototype::method_setUTCDate(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = self->date();
- double date = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
+ double date = callData->argc ? callData->args[0].toNumber() : qt_qnan();
t = TimeClip(MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), date), TimeWithinDay(t)));
self->setDate(t);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setMonth(CallContext *ctx)
+void DatePrototype::method_setMonth(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = LocalTime(self->date());
- double month = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
- double date = (ctx->argc() < 2) ? DateFromTime(t) : ctx->args()[1].toNumber();
+ double month = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ double date = (callData->argc < 2) ? DateFromTime(t) : callData->args[1].toNumber();
t = TimeClip(UTC(MakeDate(MakeDay(YearFromTime(t), month, date), TimeWithinDay(t))));
self->setDate(t);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setUTCMonth(CallContext *ctx)
+void DatePrototype::method_setUTCMonth(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = self->date();
- double month = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
- double date = (ctx->argc() < 2) ? DateFromTime(t) : ctx->args()[1].toNumber();
+ double month = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ double date = (callData->argc < 2) ? DateFromTime(t) : callData->args[1].toNumber();
t = TimeClip(MakeDate(MakeDay(YearFromTime(t), month, date), TimeWithinDay(t)));
self->setDate(t);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setYear(CallContext *ctx)
+void DatePrototype::method_setYear(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = self->date();
if (std::isnan(t))
t = 0;
else
t = LocalTime(t);
- double year = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
+ double year = callData->argc ? callData->args[0].toNumber() : qt_qnan();
double r;
if (std::isnan(year)) {
r = qt_qnan();
@@ -1220,49 +1220,49 @@ ReturnedValue DatePrototype::method_setYear(CallContext *ctx)
r = TimeClip(r);
}
self->setDate(r);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setUTCFullYear(CallContext *ctx)
+void DatePrototype::method_setUTCFullYear(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = self->date();
- double year = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
- double month = (ctx->argc() < 2) ? MonthFromTime(t) : ctx->args()[1].toNumber();
- double date = (ctx->argc() < 3) ? DateFromTime(t) : ctx->args()[2].toNumber();
+ double year = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ double month = (callData->argc < 2) ? MonthFromTime(t) : callData->args[1].toNumber();
+ double date = (callData->argc < 3) ? DateFromTime(t) : callData->args[2].toNumber();
t = TimeClip(MakeDate(MakeDay(year, month, date), TimeWithinDay(t)));
self->setDate(t);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_setFullYear(CallContext *ctx)
+void DatePrototype::method_setFullYear(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = LocalTime(self->date());
if (std::isnan(t))
t = 0;
- double year = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
- double month = (ctx->argc() < 2) ? MonthFromTime(t) : ctx->args()[1].toNumber();
- double date = (ctx->argc() < 3) ? DateFromTime(t) : ctx->args()[2].toNumber();
+ double year = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ double month = (callData->argc < 2) ? MonthFromTime(t) : callData->args[1].toNumber();
+ double date = (callData->argc < 3) ? DateFromTime(t) : callData->args[2].toNumber();
t = TimeClip(UTC(MakeDate(MakeDay(year, month, date), TimeWithinDay(t))));
self->setDate(t);
- return Encode(self->date());
+ scope.result = Encode(self->date());
}
-ReturnedValue DatePrototype::method_toUTCString(CallContext *ctx)
+void DatePrototype::method_toUTCString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = self->date();
- return ctx->d()->engine->newString(ToUTCString(t))->asReturnedValue();
+ scope.result = scope.engine->newString(ToUTCString(t));
}
static void addZeroPrefixedInt(QString &str, int num, int nDigits)
@@ -1278,21 +1278,21 @@ static void addZeroPrefixedInt(QString &str, int num, int nDigits)
}
}
-ReturnedValue DatePrototype::method_toISOString(CallContext *ctx)
+void DatePrototype::method_toISOString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- DateObject *self = ctx->thisObject().as<DateObject>();
+ DateObject *self = callData->thisObject.as<DateObject>();
if (!self)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
double t = self->date();
if (!std::isfinite(t))
- return ctx->engine()->throwRangeError(ctx->thisObject());
+ RETURN_RESULT(scope.engine->throwRangeError(callData->thisObject));
QString result;
int year = (int)YearFromTime(t);
if (year < 0 || year > 9999) {
if (qAbs(year) >= 1000000)
- return ctx->d()->engine->newString(QStringLiteral("Invalid Date"))->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("Invalid Date")));
result += year < 0 ? QLatin1Char('-') : QLatin1Char('+');
year = qAbs(year);
addZeroPrefixedInt(result, year, 6);
@@ -1313,32 +1313,29 @@ ReturnedValue DatePrototype::method_toISOString(CallContext *ctx)
addZeroPrefixedInt(result, msFromTime(t), 3);
result += QLatin1Char('Z');
- return ctx->d()->engine->newString(result)->asReturnedValue();
+ scope.result = scope.engine->newString(result);
}
-ReturnedValue DatePrototype::method_toJSON(CallContext *ctx)
+void DatePrototype::method_toJSON(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject O(scope, ctx->thisObject().toObject(scope.engine));
- if (scope.hasException())
- return Encode::undefined();
+ ScopedObject O(scope, callData->thisObject.toObject(scope.engine));
+ CHECK_EXCEPTION();
ScopedValue tv(scope, RuntimeHelpers::toPrimitive(O, NUMBER_HINT));
if (tv->isNumber() && !std::isfinite(tv->toNumber()))
- return Encode::null();
+ RETURN_RESULT(Encode::null());
- ScopedString s(scope, ctx->d()->engine->newString(QStringLiteral("toISOString")));
+ ScopedString s(scope, scope.engine->newString(QStringLiteral("toISOString")));
ScopedValue v(scope, O->get(s));
FunctionObject *toIso = v->as<FunctionObject>();
if (!toIso)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedCallData callData(scope);
- callData->thisObject = ctx->thisObject();
- toIso->call(scope, callData);
- return scope.result.asReturnedValue();
+ ScopedCallData cData(scope);
+ cData->thisObject = callData->thisObject;
+ toIso->call(scope, cData);
}
void DatePrototype::timezoneUpdated()
diff --git a/src/qml/jsruntime/qv4dateobject_p.h b/src/qml/jsruntime/qv4dateobject_p.h
index 835f6adbe0..a56d17f9b1 100644
--- a/src/qml/jsruntime/qv4dateobject_p.h
+++ b/src/qml/jsruntime/qv4dateobject_p.h
@@ -116,57 +116,57 @@ struct DatePrototype: DateObject
{
void init(ExecutionEngine *engine, Object *ctor);
- static double getThisDate(ExecutionContext *ctx);
-
- static ReturnedValue method_parse(CallContext *ctx);
- static ReturnedValue method_UTC(CallContext *ctx);
- static ReturnedValue method_now(CallContext *ctx);
-
- static ReturnedValue method_toString(CallContext *ctx);
- static ReturnedValue method_toDateString(CallContext *ctx);
- static ReturnedValue method_toTimeString(CallContext *ctx);
- static ReturnedValue method_toLocaleString(CallContext *ctx);
- static ReturnedValue method_toLocaleDateString(CallContext *ctx);
- static ReturnedValue method_toLocaleTimeString(CallContext *ctx);
- static ReturnedValue method_valueOf(CallContext *ctx);
- static ReturnedValue method_getTime(CallContext *ctx);
- static ReturnedValue method_getYear(CallContext *ctx);
- static ReturnedValue method_getFullYear(CallContext *ctx);
- static ReturnedValue method_getUTCFullYear(CallContext *ctx);
- static ReturnedValue method_getMonth(CallContext *ctx);
- static ReturnedValue method_getUTCMonth(CallContext *ctx);
- static ReturnedValue method_getDate(CallContext *ctx);
- static ReturnedValue method_getUTCDate(CallContext *ctx);
- static ReturnedValue method_getDay(CallContext *ctx);
- static ReturnedValue method_getUTCDay(CallContext *ctx);
- static ReturnedValue method_getHours(CallContext *ctx);
- static ReturnedValue method_getUTCHours(CallContext *ctx);
- static ReturnedValue method_getMinutes(CallContext *ctx);
- static ReturnedValue method_getUTCMinutes(CallContext *ctx);
- static ReturnedValue method_getSeconds(CallContext *ctx);
- static ReturnedValue method_getUTCSeconds(CallContext *ctx);
- static ReturnedValue method_getMilliseconds(CallContext *ctx);
- static ReturnedValue method_getUTCMilliseconds(CallContext *ctx);
- static ReturnedValue method_getTimezoneOffset(CallContext *ctx);
- static ReturnedValue method_setTime(CallContext *ctx);
- static ReturnedValue method_setMilliseconds(CallContext *ctx);
- static ReturnedValue method_setUTCMilliseconds(CallContext *ctx);
- static ReturnedValue method_setSeconds(CallContext *ctx);
- static ReturnedValue method_setUTCSeconds(CallContext *ctx);
- static ReturnedValue method_setMinutes(CallContext *ctx);
- static ReturnedValue method_setUTCMinutes(CallContext *ctx);
- static ReturnedValue method_setHours(CallContext *ctx);
- static ReturnedValue method_setUTCHours(CallContext *ctx);
- static ReturnedValue method_setDate(CallContext *ctx);
- static ReturnedValue method_setUTCDate(CallContext *ctx);
- static ReturnedValue method_setMonth(CallContext *ctx);
- static ReturnedValue method_setUTCMonth(CallContext *ctx);
- static ReturnedValue method_setYear(CallContext *ctx);
- static ReturnedValue method_setFullYear(CallContext *ctx);
- static ReturnedValue method_setUTCFullYear(CallContext *ctx);
- static ReturnedValue method_toUTCString(CallContext *ctx);
- static ReturnedValue method_toISOString(CallContext *ctx);
- static ReturnedValue method_toJSON(CallContext *ctx);
+ static double getThisDate(Scope &scope, CallData *callData);
+
+ static void method_parse(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_UTC(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_now(const BuiltinFunction *, Scope &scope, CallData *callData);
+
+ static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toDateString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toTimeString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toLocaleDateString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toLocaleTimeString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getTime(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getYear(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getFullYear(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getUTCFullYear(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getMonth(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getUTCMonth(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getDate(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getUTCDate(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getDay(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getUTCDay(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getHours(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getUTCHours(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getMinutes(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getUTCMinutes(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getSeconds(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getUTCSeconds(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getUTCMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getTimezoneOffset(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setTime(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setUTCMilliseconds(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setSeconds(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setUTCSeconds(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setMinutes(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setUTCMinutes(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setHours(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setUTCHours(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setDate(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setUTCDate(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setMonth(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setUTCMonth(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setYear(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setFullYear(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_setUTCFullYear(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toUTCString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toISOString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toJSON(const BuiltinFunction *, Scope &scope, CallData *callData);
static void timezoneUpdated();
};
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 8c4c39b774..f925c9184c 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -91,7 +91,9 @@
#if USE(PTHREADS)
# include <pthread.h>
+#if !defined(Q_OS_INTEGRITY)
# include <sys/resource.h>
+#endif
#if HAVE(PTHREAD_NP_H)
# include <pthread_np.h>
#endif
@@ -168,7 +170,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
if (forceMoth) {
factory = new Moth::ISelFactory;
} else {
- factory = new JIT::ISelFactory;
+ factory = new JIT::ISelFactory<>;
jitDisabled = false;
}
#else // !V4_ENABLE_JIT
@@ -256,6 +258,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
arrayClass = emptyClass->addMember(id_length(), Attr_NotConfigurable|Attr_NotEnumerable);
jsObjects[ArrayProto] = memoryManager->allocObject<ArrayPrototype>(arrayClass, objectPrototype());
+ jsObjects[PropertyListProto] = memoryManager->allocObject<PropertyListPrototype>();
InternalClass *argsClass = emptyClass->addMember(id_length(), Attr_NotEnumerable);
argumentsObjectClass = argsClass->addMember(id_callee(), Attr_Data|Attr_NotEnumerable);
@@ -358,6 +361,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
static_cast<NumberPrototype *>(numberPrototype())->init(this, numberCtor());
static_cast<BooleanPrototype *>(booleanPrototype())->init(this, booleanCtor());
static_cast<ArrayPrototype *>(arrayPrototype())->init(this, arrayCtor());
+ static_cast<PropertyListPrototype *>(propertyListPrototype())->init(this);
static_cast<DatePrototype *>(datePrototype())->init(this, dateCtor());
static_cast<FunctionPrototype *>(functionPrototype())->init(this, functionCtor());
static_cast<RegExpPrototype *>(regExpPrototype())->init(this, regExpCtor());
@@ -460,7 +464,7 @@ ExecutionEngine::~ExecutionEngine()
QSet<QV4::CompiledData::CompilationUnit*> remainingUnits;
qSwap(compilationUnits, remainingUnits);
- foreach (QV4::CompiledData::CompilationUnit *unit, remainingUnits)
+ for (QV4::CompiledData::CompilationUnit *unit : qAsConst(remainingUnits))
unit->unlink();
emptyClass->destroy();
@@ -1041,7 +1045,7 @@ ReturnedValue ExecutionEngine::throwURIError(const Value &msg)
ReturnedValue ExecutionEngine::throwUnimplemented(const QString &message)
{
Scope scope(this);
- ScopedValue v(scope, newString(QStringLiteral("Unimplemented ") + message));
+ ScopedValue v(scope, newString(QLatin1String("Unimplemented ") + message));
v = newErrorObject(v);
return throwError(v);
}
@@ -1109,7 +1113,7 @@ static QVariant toVariant(QV4::ExecutionEngine *e, const QV4::Value &value, int
if (typeHint == qMetaTypeId<QJSValue>())
return QVariant::fromValue(QJSValue(e, value.asReturnedValue()));
- if (value.as<Object>()) {
+ if (value.as<QV4::Object>()) {
QV4::ScopedObject object(scope, value);
if (typeHint == QMetaType::QJsonObject
&& !value.as<ArrayObject>() && !value.as<FunctionObject>()) {
@@ -1755,7 +1759,7 @@ bool ExecutionEngine::metaTypeFromJS(const Value *value, int type, void *data)
return false;
}
-static bool convertToNativeQObject(QV4::ExecutionEngine *e, const Value &value, const QByteArray &targetType, void **result)
+static bool convertToNativeQObject(QV4::ExecutionEngine *e, const QV4::Value &value, const QByteArray &targetType, void **result)
{
if (!targetType.endsWith('*'))
return false;
@@ -1770,7 +1774,7 @@ static bool convertToNativeQObject(QV4::ExecutionEngine *e, const Value &value,
return false;
}
-static QObject *qtObjectFromJS(QV4::ExecutionEngine *engine, const Value &value)
+static QObject *qtObjectFromJS(QV4::ExecutionEngine *engine, const QV4::Value &value)
{
if (!value.isObject())
return 0;
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index 1c20ad30aa..69aa389c44 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -157,6 +157,7 @@ public:
IntegerNull, // Has to come after the RootContext to make the context stack safe
ObjectProto,
ArrayProto,
+ PropertyListProto,
StringProto,
NumberProto,
BooleanProto,
@@ -225,6 +226,7 @@ public:
Object *objectPrototype() const { return reinterpret_cast<Object *>(jsObjects + ObjectProto); }
Object *arrayPrototype() const { return reinterpret_cast<Object *>(jsObjects + ArrayProto); }
+ Object *propertyListPrototype() const { return reinterpret_cast<Object *>(jsObjects + PropertyListProto); }
Object *stringPrototype() const { return reinterpret_cast<Object *>(jsObjects + StringProto); }
Object *numberPrototype() const { return reinterpret_cast<Object *>(jsObjects + NumberProto); }
Object *booleanPrototype() const { return reinterpret_cast<Object *>(jsObjects + BooleanProto); }
diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp
index 597ded6ae1..f290bc5136 100644
--- a/src/qml/jsruntime/qv4errorobject.cpp
+++ b/src/qml/jsruntime/qv4errorobject.cpp
@@ -153,12 +153,11 @@ const char *ErrorObject::className(Heap::ErrorObject::ErrorType t)
Q_UNREACHABLE();
}
-ReturnedValue ErrorObject::method_get_stack(CallContext *ctx)
+void ErrorObject::method_get_stack(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<ErrorObject> This(scope, ctx->thisObject());
+ Scoped<ErrorObject> This(scope, callData->thisObject);
if (!This)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (!This->d()->stack) {
QString trace;
for (int i = 0; i < This->d()->stackTrace->count(); ++i) {
@@ -169,9 +168,9 @@ ReturnedValue ErrorObject::method_get_stack(CallContext *ctx)
if (frame.line >= 0)
trace += QLatin1Char(':') + QString::number(frame.line);
}
- This->d()->stack = ctx->d()->engine->newString(trace);
+ This->d()->stack = scope.engine->newString(trace);
}
- return This->d()->stack->asReturnedValue();
+ scope.result = This->d()->stack;
}
void ErrorObject::markObjects(Heap::Base *that, ExecutionEngine *e)
@@ -335,22 +334,20 @@ void ErrorPrototype::init(ExecutionEngine *engine, Object *ctor, Object *obj, He
obj->defineDefaultProperty(engine->id_toString(), method_toString, 0);
}
-ReturnedValue ErrorPrototype::method_toString(CallContext *ctx)
+void ErrorPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
-
- Object *o = ctx->thisObject().as<Object>();
+ Object *o = callData->thisObject.as<Object>();
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedValue name(scope, o->get(ctx->d()->engine->id_name()));
+ ScopedValue name(scope, o->get(scope.engine->id_name()));
QString qname;
if (name->isUndefined())
qname = QStringLiteral("Error");
else
qname = name->toQString();
- ScopedString s(scope, ctx->d()->engine->newString(QStringLiteral("message")));
+ ScopedString s(scope, scope.engine->newString(QStringLiteral("message")));
ScopedValue message(scope, o->get(s));
QString qmessage;
if (!message->isUndefined())
@@ -365,5 +362,5 @@ ReturnedValue ErrorPrototype::method_toString(CallContext *ctx)
str = qname + QLatin1String(": ") + qmessage;
}
- return ctx->d()->engine->newString(str)->asReturnedValue();
+ scope.result = scope.engine->newString(str)->asReturnedValue();
}
diff --git a/src/qml/jsruntime/qv4errorobject_p.h b/src/qml/jsruntime/qv4errorobject_p.h
index 2b3ab25e2d..9ba9f05234 100644
--- a/src/qml/jsruntime/qv4errorobject_p.h
+++ b/src/qml/jsruntime/qv4errorobject_p.h
@@ -172,7 +172,7 @@ struct ErrorObject: Object {
static const char *className(Heap::ErrorObject::ErrorType t);
- static ReturnedValue method_get_stack(CallContext *ctx);
+ static void method_get_stack(const BuiltinFunction *, Scope &scope, CallData *callData);
static void markObjects(Heap::Base *that, ExecutionEngine *e);
};
@@ -282,7 +282,7 @@ struct ErrorPrototype : ErrorObject
void init(ExecutionEngine *engine, Object *ctor) { init(engine, ctor, this, Heap::ErrorObject::Error); }
static void init(ExecutionEngine *engine, Object *ctor, Object *obj, Heap::ErrorObject::ErrorType t);
- static ReturnedValue method_toString(CallContext *ctx);
+ static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData);
};
struct EvalErrorPrototype : ErrorObject
diff --git a/src/qml/jsruntime/qv4executableallocator.cpp b/src/qml/jsruntime/qv4executableallocator.cpp
index 6fe25f192d..64ac1267ce 100644
--- a/src/qml/jsruntime/qv4executableallocator.cpp
+++ b/src/qml/jsruntime/qv4executableallocator.cpp
@@ -147,7 +147,7 @@ ExecutableAllocator::ExecutableAllocator()
ExecutableAllocator::~ExecutableAllocator()
{
- foreach (ChunkOfPages *chunk, chunks) {
+ for (ChunkOfPages *chunk : qAsConst(chunks)) {
for (Allocation *allocation = chunk->firstAllocation; allocation; allocation = allocation->next)
if (!allocation->free)
allocation->invalidate();
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 64f7b98618..b2d89220ea 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -270,23 +270,22 @@ void FunctionPrototype::init(ExecutionEngine *engine, Object *ctor)
}
-ReturnedValue FunctionPrototype::method_toString(CallContext *ctx)
+void FunctionPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- FunctionObject *fun = ctx->thisObject().as<FunctionObject>();
+ FunctionObject *fun = callData->thisObject.as<FunctionObject>();
if (!fun)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- return ctx->d()->engine->newString(QStringLiteral("function() { [code] }"))->asReturnedValue();
+ scope.result = scope.engine->newString(QStringLiteral("function() { [code] }"));
}
-ReturnedValue FunctionPrototype::method_apply(CallContext *ctx)
+void FunctionPrototype::method_apply(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- FunctionObject *o = ctx->thisObject().as<FunctionObject>();
+ FunctionObject *o = callData->thisObject.as<FunctionObject>();
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- Scope scope(ctx);
- ScopedValue arg(scope, ctx->argument(1));
+ ScopedValue arg(scope, callData->argument(1));
ScopedObject arr(scope, arg);
@@ -294,75 +293,71 @@ ReturnedValue FunctionPrototype::method_apply(CallContext *ctx)
if (!arr) {
len = 0;
if (!arg->isNullOrUndefined())
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
} else {
len = arr->getLength();
}
- ScopedCallData callData(scope, len);
+ ScopedCallData cData(scope, len);
if (len) {
if (ArgumentsObject::isNonStrictArgumentsObject(arr) && !arr->cast<ArgumentsObject>()->fullyCreated()) {
QV4::ArgumentsObject *a = arr->cast<ArgumentsObject>();
int l = qMin(len, (uint)a->d()->context->callData->argc);
- memcpy(callData->args, a->d()->context->callData->args, l*sizeof(Value));
+ memcpy(cData->args, a->d()->context->callData->args, l*sizeof(Value));
for (quint32 i = l; i < len; ++i)
- callData->args[i] = Primitive::undefinedValue();
+ cData->args[i] = Primitive::undefinedValue();
} else if (arr->arrayType() == Heap::ArrayData::Simple && !arr->protoHasArray()) {
auto sad = static_cast<Heap::SimpleArrayData *>(arr->arrayData());
uint alen = sad ? sad->len : 0;
if (alen > len)
alen = len;
for (uint i = 0; i < alen; ++i)
- callData->args[i] = sad->data(i);
+ cData->args[i] = sad->data(i);
for (quint32 i = alen; i < len; ++i)
- callData->args[i] = Primitive::undefinedValue();
+ cData->args[i] = Primitive::undefinedValue();
} else {
for (quint32 i = 0; i < len; ++i)
- callData->args[i] = arr->getIndexed(i);
+ cData->args[i] = arr->getIndexed(i);
}
}
- callData->thisObject = ctx->argument(0);
- o->call(scope, callData);
- return scope.result.asReturnedValue();
+ cData->thisObject = callData->argument(0);
+ o->call(scope, cData);
}
-ReturnedValue FunctionPrototype::method_call(CallContext *ctx)
+void FunctionPrototype::method_call(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- FunctionObject *o = ctx->thisObject().as<FunctionObject>();
+ FunctionObject *o = callData->thisObject.as<FunctionObject>();
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- Scope scope(ctx);
- ScopedCallData callData(scope, ctx->argc() ? ctx->argc() - 1 : 0);
- if (ctx->argc()) {
- for (int i = 1; i < ctx->argc(); ++i)
- callData->args[i - 1] = ctx->args()[i];
+ ScopedCallData cData(scope, callData->argc ? callData->argc - 1 : 0);
+ if (callData->argc) {
+ for (int i = 1; i < callData->argc; ++i)
+ cData->args[i - 1] = callData->args[i];
}
- callData->thisObject = ctx->argument(0);
+ cData->thisObject = callData->argument(0);
- o->call(scope, callData);
- return scope.result.asReturnedValue();
+ o->call(scope, cData);
}
-ReturnedValue FunctionPrototype::method_bind(CallContext *ctx)
+void FunctionPrototype::method_bind(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- FunctionObject *target = ctx->thisObject().as<FunctionObject>();
+ FunctionObject *target = callData->thisObject.as<FunctionObject>();
if (!target)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- Scope scope(ctx);
- ScopedValue boundThis(scope, ctx->argument(0));
+ ScopedValue boundThis(scope, callData->argument(0));
Scoped<MemberData> boundArgs(scope, (Heap::MemberData *)0);
- if (ctx->argc() > 1) {
- boundArgs = MemberData::allocate(scope.engine, ctx->argc() - 1);
- boundArgs->d()->size = ctx->argc() - 1;
- memcpy(boundArgs->data(), ctx->args() + 1, (ctx->argc() - 1)*sizeof(Value));
+ if (callData->argc > 1) {
+ boundArgs = MemberData::allocate(scope.engine, callData->argc - 1);
+ boundArgs->d()->size = callData->argc - 1;
+ memcpy(boundArgs->data(), callData->args + 1, (callData->argc - 1)*sizeof(Value));
}
ExecutionContext *global = scope.engine->rootContext();
- return BoundFunction::create(global, target, boundThis, boundArgs)->asReturnedValue();
+ scope.result = BoundFunction::create(global, target, boundThis, boundArgs);
}
DEFINE_OBJECT_VTABLE(ScriptFunction);
@@ -459,22 +454,22 @@ Heap::Object *ScriptFunction::protoForConstructor() const
-DEFINE_OBJECT_VTABLE(BuiltinFunction);
+DEFINE_OBJECT_VTABLE(OldBuiltinFunction);
-void Heap::BuiltinFunction::init(QV4::ExecutionContext *scope, QV4::String *name, ReturnedValue (*code)(QV4::CallContext *))
+void Heap::OldBuiltinFunction::init(QV4::ExecutionContext *scope, QV4::String *name, ReturnedValue (*code)(QV4::CallContext *))
{
Heap::FunctionObject::init(scope, name);
this->code = code;
}
-void BuiltinFunction::construct(const Managed *f, Scope &scope, CallData *)
+void OldBuiltinFunction::construct(const Managed *f, Scope &scope, CallData *)
{
- scope.result = static_cast<const BuiltinFunction *>(f)->internalClass()->engine->throwTypeError();
+ scope.result = static_cast<const OldBuiltinFunction *>(f)->internalClass()->engine->throwTypeError();
}
-void BuiltinFunction::call(const Managed *that, Scope &scope, CallData *callData)
+void OldBuiltinFunction::call(const Managed *that, Scope &scope, CallData *callData)
{
- const BuiltinFunction *f = static_cast<const BuiltinFunction *>(that);
+ const OldBuiltinFunction *f = static_cast<const OldBuiltinFunction *>(that);
ExecutionEngine *v4 = scope.engine;
if (v4->hasException) {
scope.result = Encode::undefined();
@@ -484,15 +479,41 @@ void BuiltinFunction::call(const Managed *that, Scope &scope, CallData *callData
ExecutionContextSaver ctxSaver(scope);
- CallContext::Data ctx = CallContext::Data::createOnStack(v4);
- ctx.strictMode = f->scope()->strictMode; // ### needed? scope or parent context?
- ctx.callData = callData;
- v4->pushContext(&ctx);
- Q_ASSERT(v4->current == &ctx);
+ CallContext::Data *ctx = v4->memoryManager->allocSimpleCallContext(v4);
+ ctx->strictMode = f->scope()->strictMode; // ### needed? scope or parent context?
+ ctx->callData = callData;
+ v4->pushContext(ctx);
+ Q_ASSERT(v4->current == ctx);
scope.result = f->d()->code(static_cast<QV4::CallContext *>(v4->currentContext));
+ v4->memoryManager->freeSimpleCallContext();
+}
+
+DEFINE_OBJECT_VTABLE(BuiltinFunction);
+
+void Heap::BuiltinFunction::init(QV4::ExecutionContext *scope, QV4::String *name, void (*code)(const QV4::BuiltinFunction *, Scope &, CallData *))
+{
+ Heap::FunctionObject::init(scope, name);
+ this->code = code;
+}
+
+void BuiltinFunction::construct(const Managed *f, Scope &scope, CallData *)
+{
+ scope.result = static_cast<const BuiltinFunction *>(f)->internalClass()->engine->throwTypeError();
+}
+
+void BuiltinFunction::call(const Managed *that, Scope &scope, CallData *callData)
+{
+ const BuiltinFunction *f = static_cast<const BuiltinFunction *>(that);
+ ExecutionEngine *v4 = scope.engine;
+ if (v4->hasException) {
+ scope.result = Encode::undefined();
+ return;
+ }
+ f->d()->code(f, scope, callData);
}
+
void IndexedBuiltinFunction::call(const Managed *that, Scope &scope, CallData *callData)
{
const IndexedBuiltinFunction *f = static_cast<const IndexedBuiltinFunction *>(that);
@@ -505,13 +526,14 @@ void IndexedBuiltinFunction::call(const Managed *that, Scope &scope, CallData *c
ExecutionContextSaver ctxSaver(scope);
- CallContext::Data ctx = CallContext::Data::createOnStack(v4);
- ctx.strictMode = f->scope()->strictMode; // ### needed? scope or parent context?
- ctx.callData = callData;
- v4->pushContext(&ctx);
- Q_ASSERT(v4->current == &ctx);
+ CallContext::Data *ctx = v4->memoryManager->allocSimpleCallContext(v4);
+ ctx->strictMode = f->scope()->strictMode; // ### needed? scope or parent context?
+ ctx->callData = callData;
+ v4->pushContext(ctx);
+ Q_ASSERT(v4->current == ctx);
scope.result = f->d()->code(static_cast<QV4::CallContext *>(v4->currentContext), f->d()->index);
+ v4->memoryManager->freeSimpleCallContext();
}
DEFINE_OBJECT_VTABLE(IndexedBuiltinFunction);
diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h
index a02e89e883..45d7485f1b 100644
--- a/src/qml/jsruntime/qv4functionobject_p.h
+++ b/src/qml/jsruntime/qv4functionobject_p.h
@@ -61,6 +61,8 @@ struct QQmlSourceLocation;
namespace QV4 {
+struct BuiltinFunction;
+
namespace Heap {
struct Q_QML_PRIVATE_EXPORT FunctionObject : Object {
@@ -93,11 +95,16 @@ struct FunctionPrototype : FunctionObject {
void init();
};
-struct Q_QML_EXPORT BuiltinFunction : FunctionObject {
+struct Q_QML_EXPORT OldBuiltinFunction : FunctionObject {
void init(QV4::ExecutionContext *scope, QV4::String *name, ReturnedValue (*code)(QV4::CallContext *));
ReturnedValue (*code)(QV4::CallContext *);
};
+struct Q_QML_EXPORT BuiltinFunction : FunctionObject {
+ void init(QV4::ExecutionContext *scope, QV4::String *name, void (*code)(const QV4::BuiltinFunction *, Scope &, CallData *));
+ void (*code)(const QV4::BuiltinFunction *, Scope &, CallData *);
+};
+
struct IndexedBuiltinFunction : FunctionObject {
inline void init(QV4::ExecutionContext *scope, uint index, ReturnedValue (*code)(QV4::CallContext *ctx, uint index));
ReturnedValue (*code)(QV4::CallContext *, uint index);
@@ -177,16 +184,27 @@ struct FunctionPrototype: FunctionObject
void init(ExecutionEngine *engine, Object *ctor);
- static ReturnedValue method_toString(CallContext *ctx);
- static ReturnedValue method_apply(CallContext *ctx);
- static ReturnedValue method_call(CallContext *ctx);
- static ReturnedValue method_bind(CallContext *ctx);
+ static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_apply(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_call(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_bind(const BuiltinFunction *, Scope &scope, CallData *callData);
};
-struct Q_QML_EXPORT BuiltinFunction: FunctionObject {
+struct Q_QML_EXPORT OldBuiltinFunction : FunctionObject {
+ V4_OBJECT2(OldBuiltinFunction, FunctionObject)
+
+ static void construct(const Managed *, Scope &scope, CallData *);
+ static void call(const Managed *that, Scope &scope, CallData *callData);
+};
+
+struct Q_QML_EXPORT BuiltinFunction : FunctionObject {
V4_OBJECT2(BuiltinFunction, FunctionObject)
- static Heap::BuiltinFunction *create(ExecutionContext *scope, String *name, ReturnedValue (*code)(CallContext *))
+ static Heap::OldBuiltinFunction *create(ExecutionContext *scope, String *name, ReturnedValue (*code)(CallContext *))
+ {
+ return scope->engine()->memoryManager->allocObject<OldBuiltinFunction>(scope, name, code);
+ }
+ static Heap::BuiltinFunction *create(ExecutionContext *scope, String *name, void (*code)(const BuiltinFunction *, Scope &, CallData *))
{
return scope->engine()->memoryManager->allocObject<BuiltinFunction>(scope, name, code);
}
diff --git a/src/qml/jsruntime/qv4global_p.h b/src/qml/jsruntime/qv4global_p.h
index c37ad1668d..66861bf697 100644
--- a/src/qml/jsruntime/qv4global_p.h
+++ b/src/qml/jsruntime/qv4global_p.h
@@ -97,19 +97,19 @@ inline double trunc(double d) { return d > 0 ? floor(d) : ceil(d); }
//
// NOTE: This should match the logic in qv4targetplatform_p.h!
-#if defined(Q_PROCESSOR_X86) && !defined(__ILP32__) \
+#if defined(Q_PROCESSOR_X86) && (QT_POINTER_SIZE == 4) \
&& (defined(Q_OS_WIN) || defined(Q_OS_LINUX) || defined(Q_OS_QNX) || defined(Q_OS_FREEBSD))
# define V4_ENABLE_JIT
-#elif defined(Q_PROCESSOR_X86_64) && !defined(__ILP32__) \
+#elif defined(Q_PROCESSOR_X86_64) && (QT_POINTER_SIZE == 8) \
&& (defined(Q_OS_WIN) || defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_FREEBSD))
# define V4_ENABLE_JIT
-#elif defined(Q_PROCESSOR_ARM_32)
+#elif defined(Q_PROCESSOR_ARM_32) && (QT_POINTER_SIZE == 4)
# if defined(thumb2) || defined(__thumb2__) || ((defined(__thumb) || defined(__thumb__)) && __TARGET_ARCH_THUMB-0 == 4)
# define V4_ENABLE_JIT
# elif defined(__ARM_ARCH_ISA_THUMB) && __ARM_ARCH_ISA_THUMB == 2 // clang 3.5 and later will set this if the core supports the Thumb-2 ISA.
# define V4_ENABLE_JIT
# endif
-#elif defined(Q_PROCESSOR_ARM_64)
+#elif defined(Q_PROCESSOR_ARM_64) && (QT_POINTER_SIZE == 8)
# if defined(Q_OS_LINUX)
# define V4_ENABLE_JIT
# endif
@@ -208,6 +208,7 @@ struct StringObject;
struct ArrayObject;
struct DateObject;
struct FunctionObject;
+struct BuiltinFunction;
struct ErrorObject;
struct ArgumentsObject;
struct Managed;
diff --git a/src/qml/jsruntime/qv4globalobject.cpp b/src/qml/jsruntime/qv4globalobject.cpp
index af92ce1ad8..1bc91f832b 100644
--- a/src/qml/jsruntime/qv4globalobject.cpp
+++ b/src/qml/jsruntime/qv4globalobject.cpp
@@ -423,18 +423,15 @@ static inline int toInt(const QChar &qc, int R)
}
// parseInt [15.1.2.2]
-ReturnedValue GlobalFunctions::method_parseInt(CallContext *ctx)
+void GlobalFunctions::method_parseInt(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedValue inputString(scope, ctx->argument(0));
- ScopedValue radix(scope, ctx->argument(1));
+ ScopedValue inputString(scope, callData->argument(0));
+ ScopedValue radix(scope, callData->argument(1));
int R = radix->isUndefined() ? 0 : radix->toInt32();
// [15.1.2.2] step by step:
QString trimmed = inputString->toQString().trimmed(); // 1 + 2
-
- if (ctx->d()->engine->hasException)
- return Encode::undefined();
+ CHECK_EXCEPTION();
const QChar *pos = trimmed.constData();
const QChar *end = pos + trimmed.length();
@@ -449,7 +446,7 @@ ReturnedValue GlobalFunctions::method_parseInt(CallContext *ctx)
bool stripPrefix = true; // 7
if (R) { // 8
if (R < 2 || R > 36)
- return Encode(std::numeric_limits<double>::quiet_NaN()); // 8a
+ RETURN_RESULT(Encode(std::numeric_limits<double>::quiet_NaN())); // 8a
if (R != 16)
stripPrefix = false; // 8b
} else { // 9
@@ -466,13 +463,13 @@ ReturnedValue GlobalFunctions::method_parseInt(CallContext *ctx)
// 11: Z is progressively built below
// 13: this is handled by the toInt function
if (pos == end) // 12
- return Encode(std::numeric_limits<double>::quiet_NaN());
+ RETURN_RESULT(Encode(std::numeric_limits<double>::quiet_NaN()));
bool overflow = false;
qint64 v_overflow = 0;
unsigned overflow_digit_count = 0;
int d = toInt(*pos++, R);
if (d == -1)
- return Encode(std::numeric_limits<double>::quiet_NaN());
+ RETURN_RESULT(Encode(std::numeric_limits<double>::quiet_NaN()));
qint64 v = d;
while (pos != end) {
d = toInt(*pos++, R);
@@ -499,155 +496,148 @@ ReturnedValue GlobalFunctions::method_parseInt(CallContext *ctx)
if (overflow) {
double result = (double) v_overflow * pow(static_cast<double>(R), static_cast<double>(overflow_digit_count));
result += v;
- return Encode(sign * result);
+ RETURN_RESULT(Encode(sign * result));
} else {
- return Encode(sign * (double) v); // 15
+ RETURN_RESULT(Encode(sign * (double) v)); // 15
}
}
// parseFloat [15.1.2.3]
-ReturnedValue GlobalFunctions::method_parseFloat(CallContext *ctx)
+void GlobalFunctions::method_parseFloat(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
-
// [15.1.2.3] step by step:
- ScopedString inputString(scope, ctx->argument(0), ScopedString::Convert);
- if (scope.engine->hasException)
- return Encode::undefined();
+ ScopedString inputString(scope, callData->argument(0), ScopedString::Convert);
+ CHECK_EXCEPTION();
QString trimmed = inputString->toQString().trimmed(); // 2
// 4:
if (trimmed.startsWith(QLatin1String("Infinity"))
|| trimmed.startsWith(QLatin1String("+Infinity")))
- return Encode(Q_INFINITY);
+ RETURN_RESULT(Encode(Q_INFINITY));
if (trimmed.startsWith(QLatin1String("-Infinity")))
- return Encode(-Q_INFINITY);
+ RETURN_RESULT(Encode(-Q_INFINITY));
QByteArray ba = trimmed.toLatin1();
bool ok;
const char *begin = ba.constData();
const char *end = 0;
double d = qstrtod(begin, &end, &ok);
if (end - begin == 0)
- return Encode(std::numeric_limits<double>::quiet_NaN()); // 3
+ RETURN_RESULT(Encode(std::numeric_limits<double>::quiet_NaN())); // 3
else
- return Encode(d);
+ RETURN_RESULT(Encode(d));
}
/// isNaN [15.1.2.4]
-ReturnedValue GlobalFunctions::method_isNaN(CallContext *ctx)
+void GlobalFunctions::method_isNaN(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (!ctx->argc())
+ if (!callData->argc)
// undefined gets converted to NaN
- return Encode(true);
+ RETURN_RESULT(Encode(true));
- if (ctx->args()[0].integerCompatible())
- return Encode(false);
+ if (callData->args[0].integerCompatible())
+ RETURN_RESULT(Encode(false));
- double d = ctx->args()[0].toNumber();
- return Encode((bool)std::isnan(d));
+ double d = callData->args[0].toNumber();
+ RETURN_RESULT(Encode((bool)std::isnan(d)));
}
/// isFinite [15.1.2.5]
-ReturnedValue GlobalFunctions::method_isFinite(CallContext *ctx)
+void GlobalFunctions::method_isFinite(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (!ctx->argc())
+ if (!callData->argc)
// undefined gets converted to NaN
- return Encode(false);
+ RETURN_RESULT(Encode(false));
- if (ctx->args()[0].integerCompatible())
- return Encode(true);
+ if (callData->args[0].integerCompatible())
+ RETURN_RESULT(Encode(true));
- double d = ctx->args()[0].toNumber();
- return Encode((bool)std::isfinite(d));
+ double d = callData->args[0].toNumber();
+ RETURN_RESULT(Encode((bool)std::isfinite(d)));
}
/// decodeURI [15.1.3.1]
-ReturnedValue GlobalFunctions::method_decodeURI(CallContext *context)
+void GlobalFunctions::method_decodeURI(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (context->argc() == 0)
- return Encode::undefined();
+ if (callData->argc == 0)
+ RETURN_UNDEFINED();
- QString uriString = context->args()[0].toQString();
+ QString uriString = callData->args[0].toQString();
bool ok;
QString out = decode(uriString, DecodeNonReserved, &ok);
if (!ok) {
- Scope scope(context);
- ScopedString s(scope, context->d()->engine->newString(QStringLiteral("malformed URI sequence")));
- return context->engine()->throwURIError(s);
+ ScopedString s(scope, scope.engine->newString(QStringLiteral("malformed URI sequence")));
+ RETURN_RESULT(scope.engine->throwURIError(s));
}
- return context->d()->engine->newString(out)->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(out));
}
/// decodeURIComponent [15.1.3.2]
-ReturnedValue GlobalFunctions::method_decodeURIComponent(CallContext *context)
+void GlobalFunctions::method_decodeURIComponent(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (context->argc() == 0)
- return Encode::undefined();
+ if (callData->argc == 0)
+ RETURN_UNDEFINED();
- QString uriString = context->args()[0].toQString();
+ QString uriString = callData->args[0].toQString();
bool ok;
QString out = decode(uriString, DecodeAll, &ok);
if (!ok) {
- Scope scope(context);
- ScopedString s(scope, context->d()->engine->newString(QStringLiteral("malformed URI sequence")));
- return context->engine()->throwURIError(s);
+ ScopedString s(scope, scope.engine->newString(QStringLiteral("malformed URI sequence")));
+ RETURN_RESULT(scope.engine->throwURIError(s));
}
- return context->d()->engine->newString(out)->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(out));
}
/// encodeURI [15.1.3.3]
-ReturnedValue GlobalFunctions::method_encodeURI(CallContext *context)
+void GlobalFunctions::method_encodeURI(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (context->argc() == 0)
- return Encode::undefined();
+ if (callData->argc == 0)
+ RETURN_UNDEFINED();
- QString uriString = context->args()[0].toQString();
+ QString uriString = callData->args[0].toQString();
bool ok;
QString out = encode(uriString, uriUnescapedReserved, &ok);
if (!ok) {
- Scope scope(context);
- ScopedString s(scope, context->d()->engine->newString(QStringLiteral("malformed URI sequence")));
- return context->engine()->throwURIError(s);
+ ScopedString s(scope, scope.engine->newString(QStringLiteral("malformed URI sequence")));
+ RETURN_RESULT(scope.engine->throwURIError(s));
}
- return context->d()->engine->newString(out)->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(out));
}
/// encodeURIComponent [15.1.3.4]
-ReturnedValue GlobalFunctions::method_encodeURIComponent(CallContext *context)
+void GlobalFunctions::method_encodeURIComponent(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (context->argc() == 0)
- return Encode::undefined();
+ if (callData->argc == 0)
+ RETURN_UNDEFINED();
- QString uriString = context->args()[0].toQString();
+ QString uriString = callData->args[0].toQString();
bool ok;
QString out = encode(uriString, uriUnescaped, &ok);
if (!ok) {
- Scope scope(context);
- ScopedString s(scope, context->d()->engine->newString(QStringLiteral("malformed URI sequence")));
- return context->engine()->throwURIError(s);
+ ScopedString s(scope, scope.engine->newString(QStringLiteral("malformed URI sequence")));
+ RETURN_RESULT(scope.engine->throwURIError(s));
}
- return context->d()->engine->newString(out)->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(out));
}
-ReturnedValue GlobalFunctions::method_escape(CallContext *context)
+void GlobalFunctions::method_escape(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (!context->argc())
- return context->d()->engine->newString(QStringLiteral("undefined"))->asReturnedValue();
+ if (!callData->argc)
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("undefined")));
- QString str = context->args()[0].toQString();
- return context->d()->engine->newString(escape(str))->asReturnedValue();
+ QString str = callData->args[0].toQString();
+ RETURN_RESULT(scope.engine->newString(escape(str)));
}
-ReturnedValue GlobalFunctions::method_unescape(CallContext *context)
+void GlobalFunctions::method_unescape(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (!context->argc())
- return context->d()->engine->newString(QStringLiteral("undefined"))->asReturnedValue();
+ if (!callData->argc)
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("undefined")));
- QString str = context->args()[0].toQString();
- return context->d()->engine->newString(unescape(str))->asReturnedValue();
+ QString str = callData->args[0].toQString();
+ RETURN_RESULT(scope.engine->newString(unescape(str)));
}
diff --git a/src/qml/jsruntime/qv4globalobject_p.h b/src/qml/jsruntime/qv4globalobject_p.h
index e8b3a92d34..273f1ba7ea 100644
--- a/src/qml/jsruntime/qv4globalobject_p.h
+++ b/src/qml/jsruntime/qv4globalobject_p.h
@@ -76,16 +76,16 @@ struct Q_QML_EXPORT EvalFunction : FunctionObject
struct GlobalFunctions
{
- static ReturnedValue method_parseInt(CallContext *context);
- static ReturnedValue method_parseFloat(CallContext *context);
- static ReturnedValue method_isNaN(CallContext *context);
- static ReturnedValue method_isFinite(CallContext *ctx);
- static ReturnedValue method_decodeURI(CallContext *context);
- static ReturnedValue method_decodeURIComponent(CallContext *context);
- static ReturnedValue method_encodeURI(CallContext *context);
- static ReturnedValue method_encodeURIComponent(CallContext *context);
- static ReturnedValue method_escape(CallContext *context);
- static ReturnedValue method_unescape(CallContext *context);
+ static void method_parseInt(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_parseFloat(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_isNaN(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_isFinite(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_decodeURI(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_decodeURIComponent(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_encodeURI(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_encodeURIComponent(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_escape(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_unescape(const BuiltinFunction *, Scope &scope, CallData *callData);
};
}
diff --git a/src/qml/jsruntime/qv4include.cpp b/src/qml/jsruntime/qv4include.cpp
index 1d393cf0aa..f033eb2d2d 100644
--- a/src/qml/jsruntime/qv4include.cpp
+++ b/src/qml/jsruntime/qv4include.cpp
@@ -195,23 +195,22 @@ void QV4Include::finished()
/*
Documented in qv8engine.cpp
*/
-QV4::ReturnedValue QV4Include::method_include(QV4::CallContext *ctx)
+void QV4Include::method_include(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- if (!ctx->argc())
- return QV4::Encode::undefined();
+ if (!callData->argc)
+ RETURN_UNDEFINED();
- QV4::Scope scope(ctx->engine());
QQmlContextData *context = scope.engine->callingQmlContext();
if (!context || !context->isJSContext)
- V4THROW_ERROR("Qt.include(): Can only be called from JavaScript files");
+ RETURN_RESULT(scope.engine->throwError(QString::fromUtf8("Qt.include(): Can only be called from JavaScript files")));
QV4::ScopedValue callbackFunction(scope, QV4::Primitive::undefinedValue());
- if (ctx->argc() >= 2 && ctx->args()[1].as<QV4::FunctionObject>())
- callbackFunction = ctx->args()[1];
+ if (callData->argc >= 2 && callData->args[1].as<QV4::FunctionObject>())
+ callbackFunction = callData->args[1];
#if QT_CONFIG(qml_network)
- QUrl url(scope.engine->resolvedUrl(ctx->args()[0].toQStringNoThrow()));
+ QUrl url(scope.engine->resolvedUrl(callData->args[0].toQStringNoThrow()));
if (scope.engine->qmlEngine() && scope.engine->qmlEngine()->urlInterceptor())
url = scope.engine->qmlEngine()->urlInterceptor()->intercept(url, QQmlAbstractUrlInterceptor::JavaScriptFile);
@@ -261,12 +260,12 @@ QV4::ReturnedValue QV4Include::method_include(QV4::CallContext *ctx)
callback(callbackFunction, result);
}
- return result->asReturnedValue();
+ scope.result = result;
#else
QV4::ScopedValue result(scope);
result = resultValue(scope.engine, NetworkError);
callback(callbackFunction, result);
- return result->asReturnedValue();
+ scope.result = result;
#endif
}
diff --git a/src/qml/jsruntime/qv4include_p.h b/src/qml/jsruntime/qv4include_p.h
index 4c601a5e7b..5908d6bfde 100644
--- a/src/qml/jsruntime/qv4include_p.h
+++ b/src/qml/jsruntime/qv4include_p.h
@@ -77,7 +77,7 @@ public:
Exception = 3
};
- static QV4::ReturnedValue method_include(QV4::CallContext *ctx);
+ static void method_include(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
private Q_SLOTS:
void finished();
diff --git a/src/qml/jsruntime/qv4internalclass.cpp b/src/qml/jsruntime/qv4internalclass.cpp
index d17da9af0c..bac71b4537 100644
--- a/src/qml/jsruntime/qv4internalclass.cpp
+++ b/src/qml/jsruntime/qv4internalclass.cpp
@@ -128,48 +128,22 @@ InternalClass::InternalClass(const QV4::InternalClass &other)
static void insertHoleIntoPropertyData(Object *object, int idx)
{
- int inlineSize = object->d()->inlineMemberSize;
int icSize = object->internalClass()->size;
- int from = qMax(idx, inlineSize);
+ int from = idx;
int to = from + 1;
- if (from < icSize) {
+ if (from < icSize)
memmove(object->propertyData(to), object->propertyData(from),
(icSize - from - 1) * sizeof(Value));
- }
- if (from == idx)
- return;
- if (inlineSize < icSize)
- *object->propertyData(inlineSize) = *object->propertyData(inlineSize - 1);
- from = idx;
- to = from + 1;
- if (from < inlineSize - 1) {
- memmove(object->propertyData(to), object->propertyData(from),
- (inlineSize - from - 1) * sizeof(Value));
- }
}
static void removeFromPropertyData(Object *object, int idx, bool accessor = false)
{
- int inlineSize = object->d()->inlineMemberSize;
int delta = (accessor ? 2 : 1);
int oldSize = object->internalClass()->size + delta;
int to = idx;
int from = to + delta;
- if (from < inlineSize) {
- memmove(object->propertyData(to), object->d()->propertyData(from), (inlineSize - from)*sizeof(Value));
- to = inlineSize - delta;
- from = inlineSize;
- }
- if (to < inlineSize && from < oldSize) {
- Q_ASSERT(from >= inlineSize);
- memcpy(object->propertyData(to), object->d()->propertyData(from), (inlineSize - to)*sizeof(Value));
- to = inlineSize;
- from = inlineSize + delta;
- }
- if (from < oldSize) {
- Q_ASSERT(to >= inlineSize && from > to);
+ if (from < oldSize)
memmove(object->propertyData(to), object->d()->propertyData(from), (oldSize - to)*sizeof(Value));
- }
}
void InternalClass::changeMember(Object *object, String *string, PropertyAttributes data, uint *index)
diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp
index d79e6242ba..1d571f53f3 100644
--- a/src/qml/jsruntime/qv4jsonobject.cpp
+++ b/src/qml/jsruntime/qv4jsonobject.cpp
@@ -883,10 +883,9 @@ void Heap::JsonObject::init()
}
-ReturnedValue JsonObject::method_parse(CallContext *ctx)
+void JsonObject::method_parse(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedValue v(scope, ctx->argument(0));
+ ScopedValue v(scope, callData->argument(0));
QString jtext = v->toQString();
DEBUG << "parsing source = " << jtext;
@@ -895,19 +894,17 @@ ReturnedValue JsonObject::method_parse(CallContext *ctx)
ScopedValue result(scope, parser.parse(&error));
if (error.error != QJsonParseError::NoError) {
DEBUG << "parse error" << error.errorString();
- return ctx->engine()->throwSyntaxError(QStringLiteral("JSON.parse: Parse error"));
+ RETURN_RESULT(scope.engine->throwSyntaxError(QStringLiteral("JSON.parse: Parse error")));
}
- return result->asReturnedValue();
+ scope.result = result;
}
-ReturnedValue JsonObject::method_stringify(CallContext *ctx)
+void JsonObject::method_stringify(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
-
Stringify stringify(scope.engine);
- ScopedObject o(scope, ctx->argument(1));
+ ScopedObject o(scope, callData->argument(1));
if (o) {
stringify.replacerFunction = o->as<FunctionObject>();
if (o->isArrayObject()) {
@@ -932,7 +929,7 @@ ReturnedValue JsonObject::method_stringify(CallContext *ctx)
}
}
- ScopedValue s(scope, ctx->argument(2));
+ ScopedValue s(scope, callData->argument(2));
if (NumberObject *n = s->as<NumberObject>())
s = Encode(n->value());
else if (StringObject *so = s->as<StringObject>())
@@ -945,11 +942,11 @@ ReturnedValue JsonObject::method_stringify(CallContext *ctx)
}
- ScopedValue arg0(scope, ctx->argument(0));
+ ScopedValue arg0(scope, callData->argument(0));
QString result = stringify.Str(QString(), arg0);
if (result.isEmpty() || scope.engine->hasException)
- return Encode::undefined();
- return ctx->d()->engine->newString(result)->asReturnedValue();
+ RETURN_UNDEFINED();
+ scope.result = scope.engine->newString(result);
}
diff --git a/src/qml/jsruntime/qv4jsonobject_p.h b/src/qml/jsruntime/qv4jsonobject_p.h
index 43248a214d..a73ce1c74e 100644
--- a/src/qml/jsruntime/qv4jsonobject_p.h
+++ b/src/qml/jsruntime/qv4jsonobject_p.h
@@ -88,8 +88,8 @@ private:
typedef QSet<ObjectItem> V4ObjectSet;
public:
- static ReturnedValue method_parse(CallContext *ctx);
- static ReturnedValue method_stringify(CallContext *ctx);
+ static void method_parse(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_stringify(const BuiltinFunction *, Scope &scope, CallData *callData);
static ReturnedValue fromJsonValue(ExecutionEngine *engine, const QJsonValue &value);
static ReturnedValue fromJsonObject(ExecutionEngine *engine, const QJsonObject &object);
diff --git a/src/qml/jsruntime/qv4lookup_p.h b/src/qml/jsruntime/qv4lookup_p.h
index 52f54e25f5..c5ee92fedd 100644
--- a/src/qml/jsruntime/qv4lookup_p.h
+++ b/src/qml/jsruntime/qv4lookup_p.h
@@ -54,8 +54,11 @@
#include "qv4runtime_p.h"
#include "qv4engine_p.h"
#include "qv4context_p.h"
+
+#if !defined(V4_BOOTSTRAP)
#include "qv4object_p.h"
#include "qv4internalclass_p.h"
+#endif
QT_BEGIN_NAMESPACE
diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp
index e03b2762cc..2d9d81c64b 100644
--- a/src/qml/jsruntime/qv4mathobject.cpp
+++ b/src/qml/jsruntime/qv4mathobject.cpp
@@ -92,160 +92,160 @@ static Q_ALWAYS_INLINE double copySign(double x, double y)
return ::copysign(x, y);
}
-ReturnedValue MathObject::method_abs(CallContext *context)
+void MathObject::method_abs(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (!context->argc())
- return Encode(qt_qnan());
+ if (!callData->argc)
+ RETURN_RESULT(Encode(qt_qnan()));
- if (context->args()[0].isInteger()) {
- int i = context->args()[0].integerValue();
- return Encode(i < 0 ? - i : i);
+ if (callData->args[0].isInteger()) {
+ int i = callData->args[0].integerValue();
+ RETURN_RESULT(Encode(i < 0 ? - i : i));
}
- double v = context->args()[0].toNumber();
+ double v = callData->args[0].toNumber();
if (v == 0) // 0 | -0
- return Encode(0);
+ RETURN_RESULT(Encode(0));
- return Encode(v < 0 ? -v : v);
+ RETURN_RESULT(Encode(v < 0 ? -v : v));
}
-ReturnedValue MathObject::method_acos(CallContext *context)
+void MathObject::method_acos(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : 2;
+ double v = callData->argc ? callData->args[0].toNumber() : 2;
if (v > 1)
- return Encode(qt_qnan());
+ RETURN_RESULT(Encode(qt_qnan()));
- return Encode(std::acos(v));
+ RETURN_RESULT(Encode(std::acos(v)));
}
-ReturnedValue MathObject::method_asin(CallContext *context)
+void MathObject::method_asin(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : 2;
+ double v = callData->argc ? callData->args[0].toNumber() : 2;
if (v > 1)
- return Encode(qt_qnan());
+ RETURN_RESULT(Encode(qt_qnan()));
else
- return Encode(std::asin(v));
+ RETURN_RESULT(Encode(std::asin(v)));
}
-ReturnedValue MathObject::method_atan(CallContext *context)
+void MathObject::method_atan(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
+ double v = callData->argc ? callData->args[0].toNumber() : qt_qnan();
if (v == 0.0)
- return Encode(v);
+ RETURN_RESULT(Encode(v));
else
- return Encode(std::atan(v));
+ RETURN_RESULT(Encode(std::atan(v)));
}
-ReturnedValue MathObject::method_atan2(CallContext *context)
+void MathObject::method_atan2(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v1 = context->argc() ? context->args()[0].toNumber() : qt_qnan();
- double v2 = context->argc() > 1 ? context->args()[1].toNumber() : qt_qnan();
+ double v1 = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ double v2 = callData->argc > 1 ? callData->args[1].toNumber() : qt_qnan();
if ((v1 < 0) && qt_is_finite(v1) && qt_is_inf(v2) && (copySign(1.0, v2) == 1.0))
- return Encode(copySign(0, -1.0));
+ RETURN_RESULT(Encode(copySign(0, -1.0)));
if ((v1 == 0.0) && (v2 == 0.0)) {
if ((copySign(1.0, v1) == 1.0) && (copySign(1.0, v2) == -1.0)) {
- return Encode(M_PI);
+ RETURN_RESULT(Encode(M_PI));
} else if ((copySign(1.0, v1) == -1.0) && (copySign(1.0, v2) == -1.0)) {
- return Encode(-M_PI);
+ RETURN_RESULT(Encode(-M_PI));
}
}
- return Encode(std::atan2(v1, v2));
+ RETURN_RESULT(Encode(std::atan2(v1, v2)));
}
-ReturnedValue MathObject::method_ceil(CallContext *context)
+void MathObject::method_ceil(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
+ double v = callData->argc ? callData->args[0].toNumber() : qt_qnan();
if (v < 0.0 && v > -1.0)
- return Encode(copySign(0, -1.0));
+ RETURN_RESULT(Encode(copySign(0, -1.0)));
else
- return Encode(std::ceil(v));
+ RETURN_RESULT(Encode(std::ceil(v)));
}
-ReturnedValue MathObject::method_cos(CallContext *context)
+void MathObject::method_cos(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
- return Encode(std::cos(v));
+ double v = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ RETURN_RESULT(Encode(std::cos(v)));
}
-ReturnedValue MathObject::method_exp(CallContext *context)
+void MathObject::method_exp(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
+ double v = callData->argc ? callData->args[0].toNumber() : qt_qnan();
if (qt_is_inf(v)) {
if (copySign(1.0, v) == -1.0)
- return Encode(0);
+ RETURN_RESULT(Encode(0));
else
- return Encode(qt_inf());
+ RETURN_RESULT(Encode(qt_inf()));
} else {
- return Encode(std::exp(v));
+ RETURN_RESULT(Encode(std::exp(v)));
}
}
-ReturnedValue MathObject::method_floor(CallContext *context)
+void MathObject::method_floor(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
- return Encode(std::floor(v));
+ double v = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ RETURN_RESULT(Encode(std::floor(v)));
}
-ReturnedValue MathObject::method_log(CallContext *context)
+void MathObject::method_log(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
+ double v = callData->argc ? callData->args[0].toNumber() : qt_qnan();
if (v < 0)
- return Encode(qt_qnan());
+ RETURN_RESULT(Encode(qt_qnan()));
else
- return Encode(std::log(v));
+ RETURN_RESULT(Encode(std::log(v)));
}
-ReturnedValue MathObject::method_max(CallContext *context)
+void MathObject::method_max(const BuiltinFunction *, Scope &scope, CallData *callData)
{
double mx = -qt_inf();
- for (int i = 0; i < context->argc(); ++i) {
- double x = context->args()[i].toNumber();
+ for (int i = 0; i < callData->argc; ++i) {
+ double x = callData->args[i].toNumber();
if (x > mx || std::isnan(x))
mx = x;
}
- return Encode(mx);
+ RETURN_RESULT(Encode(mx));
}
-ReturnedValue MathObject::method_min(CallContext *context)
+void MathObject::method_min(const BuiltinFunction *, Scope &scope, CallData *callData)
{
double mx = qt_inf();
- for (int i = 0; i < context->argc(); ++i) {
- double x = context->args()[i].toNumber();
+ for (int i = 0; i < callData->argc; ++i) {
+ double x = callData->args[i].toNumber();
if ((x == 0 && mx == x && copySign(1.0, x) == -1.0)
|| (x < mx) || std::isnan(x)) {
mx = x;
}
}
- return Encode(mx);
+ RETURN_RESULT(Encode(mx));
}
-ReturnedValue MathObject::method_pow(CallContext *context)
+void MathObject::method_pow(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double x = context->argc() > 0 ? context->args()[0].toNumber() : qt_qnan();
- double y = context->argc() > 1 ? context->args()[1].toNumber() : qt_qnan();
+ double x = callData->argc > 0 ? callData->args[0].toNumber() : qt_qnan();
+ double y = callData->argc > 1 ? callData->args[1].toNumber() : qt_qnan();
if (std::isnan(y))
- return Encode(qt_qnan());
+ RETURN_RESULT(Encode(qt_qnan()));
if (y == 0) {
- return Encode(1);
+ RETURN_RESULT(Encode(1));
} else if (((x == 1) || (x == -1)) && std::isinf(y)) {
- return Encode(qt_qnan());
+ RETURN_RESULT(Encode(qt_qnan()));
} else if (((x == 0) && copySign(1.0, x) == 1.0) && (y < 0)) {
- return Encode(qInf());
+ RETURN_RESULT(Encode(qInf()));
} else if ((x == 0) && copySign(1.0, x) == -1.0) {
if (y < 0) {
if (std::fmod(-y, 2.0) == 1.0)
- return Encode(-qt_inf());
+ RETURN_RESULT(Encode(-qt_inf()));
else
- return Encode(qt_inf());
+ RETURN_RESULT(Encode(qt_inf()));
} else if (y > 0) {
if (std::fmod(y, 2.0) == 1.0)
- return Encode(copySign(0, -1.0));
+ RETURN_RESULT(Encode(copySign(0, -1.0)));
else
- return Encode(0);
+ RETURN_RESULT(Encode(0));
}
}
@@ -253,78 +253,78 @@ ReturnedValue MathObject::method_pow(CallContext *context)
else if (qt_is_inf(x) && copySign(1.0, x) == -1.0) {
if (y > 0) {
if (std::fmod(y, 2.0) == 1.0)
- return Encode(-qt_inf());
+ RETURN_RESULT(Encode(-qt_inf()));
else
- return Encode(qt_inf());
+ RETURN_RESULT(Encode(qt_inf()));
} else if (y < 0) {
if (std::fmod(-y, 2.0) == 1.0)
- return Encode(copySign(0, -1.0));
+ RETURN_RESULT(Encode(copySign(0, -1.0)));
else
- return Encode(0);
+ RETURN_RESULT(Encode(0));
}
}
#endif
else {
- return Encode(std::pow(x, y));
+ RETURN_RESULT(Encode(std::pow(x, y)));
}
// ###
- return Encode(qt_qnan());
+ RETURN_RESULT(Encode(qt_qnan()));
}
Q_GLOBAL_STATIC(QThreadStorage<bool *>, seedCreatedStorage);
-ReturnedValue MathObject::method_random(CallContext *context)
+void MathObject::method_random(const BuiltinFunction *, Scope &scope, CallData *)
{
if (!seedCreatedStorage()->hasLocalData()) {
int msecs = QTime(0,0,0).msecsTo(QTime::currentTime());
Q_ASSERT(msecs >= 0);
- qsrand(uint(uint(msecs) ^ reinterpret_cast<quintptr>(context)));
+ qsrand(uint(uint(msecs) ^ reinterpret_cast<quintptr>(scope.engine)));
seedCreatedStorage()->setLocalData(new bool(true));
}
// rand()/qrand() return a value where the upperbound is RAND_MAX inclusive. So, instead of
// dividing by RAND_MAX (which would return 0..RAND_MAX inclusive), we divide by RAND_MAX + 1.
qint64 upperLimit = qint64(RAND_MAX) + 1;
- return Encode(qrand() / double(upperLimit));
+ RETURN_RESULT(Encode(qrand() / double(upperLimit)));
}
-ReturnedValue MathObject::method_round(CallContext *context)
+void MathObject::method_round(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
+ double v = callData->argc ? callData->args[0].toNumber() : qt_qnan();
v = copySign(std::floor(v + 0.5), v);
- return Encode(v);
+ RETURN_RESULT(Encode(v));
}
-ReturnedValue MathObject::method_sign(CallContext *context)
+void MathObject::method_sign(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
+ double v = callData->argc ? callData->args[0].toNumber() : qt_qnan();
if (std::isnan(v))
- return Encode(qt_qnan());
+ RETURN_RESULT(Encode(qt_qnan()));
if (qIsNull(v))
- return v;
+ RETURN_RESULT(Encode(v));
- return Encode(std::signbit(v) ? -1 : 1);
+ RETURN_RESULT(Encode(std::signbit(v) ? -1 : 1));
}
-ReturnedValue MathObject::method_sin(CallContext *context)
+void MathObject::method_sin(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
- return Encode(std::sin(v));
+ double v = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ RETURN_RESULT(Encode(std::sin(v)));
}
-ReturnedValue MathObject::method_sqrt(CallContext *context)
+void MathObject::method_sqrt(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
- return Encode(std::sqrt(v));
+ double v = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+ RETURN_RESULT(Encode(std::sqrt(v)));
}
-ReturnedValue MathObject::method_tan(CallContext *context)
+void MathObject::method_tan(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- double v = context->argc() ? context->args()[0].toNumber() : qt_qnan();
+ double v = callData->argc ? callData->args[0].toNumber() : qt_qnan();
if (v == 0.0)
- return Encode(v);
+ RETURN_RESULT(Encode(v));
else
- return Encode(std::tan(v));
+ RETURN_RESULT(Encode(std::tan(v)));
}
diff --git a/src/qml/jsruntime/qv4mathobject_p.h b/src/qml/jsruntime/qv4mathobject_p.h
index f6b1a4395f..e617712905 100644
--- a/src/qml/jsruntime/qv4mathobject_p.h
+++ b/src/qml/jsruntime/qv4mathobject_p.h
@@ -69,25 +69,25 @@ struct MathObject: Object
V4_OBJECT2(MathObject, Object)
Q_MANAGED_TYPE(MathObject)
- static ReturnedValue method_abs(CallContext *context);
- static ReturnedValue method_acos(CallContext *context);
- static ReturnedValue method_asin(CallContext *context);
- static ReturnedValue method_atan(CallContext *context);
- static ReturnedValue method_atan2(CallContext *context);
- static ReturnedValue method_ceil(CallContext *context);
- static ReturnedValue method_cos(CallContext *context);
- static ReturnedValue method_exp(CallContext *context);
- static ReturnedValue method_floor(CallContext *context);
- static ReturnedValue method_log(CallContext *context);
- static ReturnedValue method_max(CallContext *context);
- static ReturnedValue method_min(CallContext *context);
- static ReturnedValue method_pow(CallContext *context);
- static ReturnedValue method_random(CallContext *context);
- static ReturnedValue method_round(CallContext *context);
- static ReturnedValue method_sign(CallContext *context);
- static ReturnedValue method_sin(CallContext *context);
- static ReturnedValue method_sqrt(CallContext *context);
- static ReturnedValue method_tan(CallContext *context);
+ static void method_abs(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_acos(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_asin(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_atan(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_atan2(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_ceil(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_cos(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_exp(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_floor(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_log(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_max(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_min(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_pow(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_random(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_round(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_sign(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_sin(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_sqrt(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_tan(const BuiltinFunction *, Scope &scope, CallData *callData);
};
}
diff --git a/src/qml/jsruntime/qv4memberdata.cpp b/src/qml/jsruntime/qv4memberdata.cpp
index d5f75415cc..db45c77472 100644
--- a/src/qml/jsruntime/qv4memberdata.cpp
+++ b/src/qml/jsruntime/qv4memberdata.cpp
@@ -55,13 +55,14 @@ void MemberData::markObjects(Heap::Base *that, ExecutionEngine *e)
Heap::MemberData *MemberData::allocate(ExecutionEngine *e, uint n, Heap::MemberData *old)
{
Q_ASSERT(!old || old->size < n);
+ Q_ASSERT(n);
- uint alloc = sizeof(Heap::MemberData) + (n)*sizeof(Value);
+ size_t alloc = MemoryManager::align(sizeof(Heap::MemberData) + (n - 1)*sizeof(Value));
Heap::MemberData *m = e->memoryManager->allocManaged<MemberData>(alloc);
if (old)
- memcpy(m, old, sizeof(Heap::MemberData) + old->size * sizeof(Value));
+ memcpy(m, old, sizeof(Heap::MemberData) + (old->size - 1)* sizeof(Value));
else
m->init();
- m->size = n;
+ m->size = static_cast<uint>((alloc - sizeof(Heap::MemberData) + sizeof(Value))/sizeof(Value));
return m;
}
diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp
index 5b5aa29d55..09644c161d 100644
--- a/src/qml/jsruntime/qv4numberobject.cpp
+++ b/src/qml/jsruntime/qv4numberobject.cpp
@@ -63,7 +63,9 @@ NumberLocale::NumberLocale() : QLocale(QLocale::C),
// -128 means shortest string that can accurately represent the number.
defaultDoublePrecision(0xffffff80)
{
- setNumberOptions(QLocale::OmitGroupSeparator | QLocale::OmitLeadingZeroInExponent);
+ setNumberOptions(QLocale::OmitGroupSeparator |
+ QLocale::OmitLeadingZeroInExponent |
+ QLocale::IncludeTrailingZeroesAfterDot);
}
const NumberLocale *NumberLocale::instance()
@@ -118,61 +120,71 @@ QT_WARNING_POP
defineDefaultProperty(QStringLiteral("toPrecision"), method_toPrecision);
}
-inline ReturnedValue thisNumberValue(ExecutionContext *ctx)
+inline ReturnedValue thisNumberValue(Scope &scope, CallData *callData)
{
- if (ctx->thisObject().isNumber())
- return ctx->thisObject().asReturnedValue();
- NumberObject *n = ctx->thisObject().as<NumberObject>();
- if (!n)
- return ctx->engine()->throwTypeError();
+ if (callData->thisObject.isNumber())
+ return callData->thisObject.asReturnedValue();
+ NumberObject *n = callData->thisObject.as<NumberObject>();
+ if (!n) {
+ scope.engine->throwTypeError();
+ return Encode::undefined();
+ }
return Encode(n->value());
}
-inline double thisNumber(ExecutionContext *ctx)
+inline double thisNumber(Scope &scope, CallData *callData)
{
- if (ctx->thisObject().isNumber())
- return ctx->thisObject().asDouble();
- NumberObject *n = ctx->thisObject().as<NumberObject>();
- if (!n)
- return ctx->engine()->throwTypeError();
+ if (callData->thisObject.isNumber())
+ return callData->thisObject.asDouble();
+ NumberObject *n = callData->thisObject.as<NumberObject>();
+ if (!n) {
+ scope.engine->throwTypeError();
+ return 0;
+ }
return n->value();
}
-ReturnedValue NumberPrototype::method_isFinite(CallContext *ctx)
+void NumberPrototype::method_isFinite(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (!ctx->argc())
- return Encode(false);
+ if (!callData->argc) {
+ scope.result = Encode(false);
+ return;
+ }
- double v = ctx->args()[0].toNumber();
- return Encode(!std::isnan(v) && !qt_is_inf(v));
+ double v = callData->args[0].toNumber();
+ scope.result = Encode(!std::isnan(v) && !qt_is_inf(v));
}
-ReturnedValue NumberPrototype::method_isNaN(CallContext *ctx)
+void NumberPrototype::method_isNaN(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (!ctx->argc())
- return Encode(false);
+ if (!callData->argc) {
+ scope.result = Encode(false);
+ return;
+ }
- double v = ctx->args()[0].toNumber();
- return Encode(std::isnan(v));
+ double v = callData->args[0].toNumber();
+ scope.result = Encode(std::isnan(v));
}
-ReturnedValue NumberPrototype::method_toString(CallContext *ctx)
+void NumberPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- double num = thisNumber(ctx);
- if (scope.engine->hasException)
- return Encode::undefined();
+ double num = thisNumber(scope, callData);
+ CHECK_EXCEPTION();
- if (ctx->argc() && !ctx->args()[0].isUndefined()) {
- int radix = ctx->args()[0].toInt32();
- if (radix < 2 || radix > 36)
- return ctx->engine()->throwError(QStringLiteral("Number.prototype.toString: %0 is not a valid radix")
+ if (callData->argc && !callData->args[0].isUndefined()) {
+ int radix = callData->args[0].toInt32();
+ if (radix < 2 || radix > 36) {
+ scope.result = scope.engine->throwError(QStringLiteral("Number.prototype.toString: %0 is not a valid radix")
.arg(radix));
+ return;
+ }
if (std::isnan(num)) {
- return scope.engine->newString(QStringLiteral("NaN"))->asReturnedValue();
+ scope.result = scope.engine->newString(QStringLiteral("NaN"));
+ return;
} else if (qt_is_inf(num)) {
- return scope.engine->newString(QLatin1String(num < 0 ? "-Infinity" : "Infinity"))->asReturnedValue();
+ scope.result = scope.engine->newString(QLatin1String(num < 0 ? "-Infinity" : "Infinity"));
+ return;
}
if (radix != 10) {
@@ -202,45 +214,43 @@ ReturnedValue NumberPrototype::method_toString(CallContext *ctx)
}
if (negative)
str.prepend(QLatin1Char('-'));
- return scope.engine->newString(str)->asReturnedValue();
+ scope.result = scope.engine->newString(str);
+ return;
}
}
- return Primitive::fromDouble(num).toString(scope.engine)->asReturnedValue();
+ scope.result = Primitive::fromDouble(num).toString(scope.engine);
}
-ReturnedValue NumberPrototype::method_toLocaleString(CallContext *ctx)
+void NumberPrototype::method_toLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedValue v(scope, thisNumberValue(ctx));
- ScopedString str(scope, v->toString(scope.engine));
- if (scope.engine->hasException)
- return Encode::undefined();
- return str.asReturnedValue();
+ ScopedValue v(scope, thisNumberValue(scope, callData));
+ scope.result = v->toString(scope.engine);
+ CHECK_EXCEPTION();
}
-ReturnedValue NumberPrototype::method_valueOf(CallContext *ctx)
+void NumberPrototype::method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- return thisNumberValue(ctx);
+ scope.result = thisNumberValue(scope, callData);
}
-ReturnedValue NumberPrototype::method_toFixed(CallContext *ctx)
+void NumberPrototype::method_toFixed(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- double v = thisNumber(ctx);
- if (scope.engine->hasException)
- return Encode::undefined();
+ double v = thisNumber(scope, callData);
+ CHECK_EXCEPTION();
double fdigits = 0;
- if (ctx->argc() > 0)
- fdigits = ctx->args()[0].toInteger();
+ if (callData->argc > 0)
+ fdigits = callData->args[0].toInteger();
if (std::isnan(fdigits))
fdigits = 0;
- if (fdigits < 0 || fdigits > 20)
- return ctx->engine()->throwRangeError(ctx->thisObject());
+ if (fdigits < 0 || fdigits > 20) {
+ scope.result = scope.engine->throwRangeError(callData->thisObject);
+ return;
+ }
QString str;
if (std::isnan(v))
@@ -249,66 +259,50 @@ ReturnedValue NumberPrototype::method_toFixed(CallContext *ctx)
str = QString::fromLatin1(v < 0 ? "-Infinity" : "Infinity");
else if (v < 1.e21)
str = NumberLocale::instance()->toString(v, 'f', int(fdigits));
- else
- return RuntimeHelpers::stringFromNumber(ctx->engine(), v)->asReturnedValue();
- return scope.engine->newString(str)->asReturnedValue();
+ else {
+ scope.result = RuntimeHelpers::stringFromNumber(scope.engine, v);
+ return;
+ }
+ scope.result = scope.engine->newString(str);
}
-ReturnedValue NumberPrototype::method_toExponential(CallContext *ctx)
+void NumberPrototype::method_toExponential(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- double d = thisNumber(ctx);
- if (scope.engine->hasException)
- return Encode::undefined();
+ double d = thisNumber(scope, callData);
+ CHECK_EXCEPTION();
int fdigits = NumberLocale::instance()->defaultDoublePrecision;
- if (ctx->argc() && !ctx->args()[0].isUndefined()) {
- fdigits = ctx->args()[0].toInt32();
+ if (callData->argc && !callData->args[0].isUndefined()) {
+ fdigits = callData->args[0].toInt32();
if (fdigits < 0 || fdigits > 20) {
ScopedString error(scope, scope.engine->newString(QStringLiteral("Number.prototype.toExponential: fractionDigits out of range")));
- return ctx->engine()->throwRangeError(error);
+ scope.result = scope.engine->throwRangeError(error);
+ return;
}
}
QString result = NumberLocale::instance()->toString(d, 'e', fdigits);
- return scope.engine->newString(result)->asReturnedValue();
+ scope.result = scope.engine->newString(result);
}
-ReturnedValue NumberPrototype::method_toPrecision(CallContext *ctx)
+void NumberPrototype::method_toPrecision(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedValue v(scope, thisNumberValue(ctx));
- if (scope.engine->hasException)
- return Encode::undefined();
+ ScopedValue v(scope, thisNumberValue(scope, callData));
+ CHECK_EXCEPTION();
- if (!ctx->argc() || ctx->args()[0].isUndefined())
- return Encode(v->toString(scope.engine));
+ if (!callData->argc || callData->args[0].isUndefined()) {
+ scope.result = v->toString(scope.engine);
+ return;
+ }
- int precision = ctx->args()[0].toInt32();
+ int precision = callData->args[0].toInt32();
if (precision < 1 || precision > 21) {
ScopedString error(scope, scope.engine->newString(QStringLiteral("Number.prototype.toPrecision: precision out of range")));
- return ctx->engine()->throwRangeError(error);
+ scope.result = scope.engine->throwRangeError(error);
+ return;
}
- // TODO: Once we get a NumberOption to retain trailing zeroes, replace the code below with:
- // QString result = NumberLocale::instance()->toString(v->asDouble(), 'g', precision);
- QByteArray format = "%#." + QByteArray::number(precision) + "g";
- QString result = QString::asprintf(format.constData(), v->asDouble());
- if (result.endsWith(QLatin1Char('.'))) {
- // This is 'f' notation, not 'e'.
- result.chop(1);
- } else {
- int ePos = result.indexOf(QLatin1Char('e'));
- if (ePos != -1) {
- Q_ASSERT(ePos + 2 < result.length()); // always '+' or '-', and number, after 'e'
- Q_ASSERT(ePos > 0); // 'e' is not the first character
-
- if (result.at(ePos + 2) == QLatin1Char('0')) // Drop leading zeroes in exponent
- result = result.remove(ePos + 2, 1);
- if (result.at(ePos - 1) == QLatin1Char('.')) // Drop trailing dots before 'e'
- result = result.remove(ePos - 1, 1);
- }
- }
- return scope.engine->newString(result)->asReturnedValue();
+ QString result = NumberLocale::instance()->toString(v->asDouble(), 'g', precision);
+ scope.result = scope.engine->newString(result);
}
diff --git a/src/qml/jsruntime/qv4numberobject_p.h b/src/qml/jsruntime/qv4numberobject_p.h
index 6022b3a029..364b866a16 100644
--- a/src/qml/jsruntime/qv4numberobject_p.h
+++ b/src/qml/jsruntime/qv4numberobject_p.h
@@ -87,14 +87,14 @@ struct NumberPrototype: NumberObject
{
void init(ExecutionEngine *engine, Object *ctor);
- static ReturnedValue method_isFinite(CallContext *ctx);
- static ReturnedValue method_isNaN(CallContext *ctx);
- static ReturnedValue method_toString(CallContext *ctx);
- static ReturnedValue method_toLocaleString(CallContext *ctx);
- static ReturnedValue method_valueOf(CallContext *ctx);
- static ReturnedValue method_toFixed(CallContext *ctx);
- static ReturnedValue method_toExponential(CallContext *ctx);
- static ReturnedValue method_toPrecision(CallContext *ctx);
+ static void method_isFinite(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_isNaN(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toFixed(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toExponential(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toPrecision(const BuiltinFunction *, Scope &scope, CallData *callData);
};
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp
index 8acca16dd0..12157af728 100644
--- a/src/qml/jsruntime/qv4object.cpp
+++ b/src/qml/jsruntime/qv4object.cpp
@@ -61,9 +61,9 @@ DEFINE_OBJECT_VTABLE(Object);
void Object::setInternalClass(InternalClass *ic)
{
d()->internalClass = ic;
- if ((ic->size > d()->inlineMemberSize && !d()->memberData) ||
- (d()->memberData && d()->memberData->size < ic->size - d()->inlineMemberSize))
- d()->memberData = MemberData::allocate(ic->engine, ic->size - d()->inlineMemberSize, d()->memberData);
+ bool hasMD = d()->memberData != nullptr;
+ if ((!hasMD && ic->size) || (hasMD && d()->memberData->size < ic->size))
+ d()->memberData = MemberData::allocate(ic->engine, ic->size, d()->memberData);
}
void Object::getProperty(uint index, Property *p, PropertyAttributes *attrs) const
@@ -167,6 +167,17 @@ void Object::defineDefaultProperty(const QString &name, ReturnedValue (*code)(Ca
defineDefaultProperty(s, function);
}
+void Object::defineDefaultProperty(const QString &name, void (*code)(const BuiltinFunction *, Scope &, CallData *), int argumentCount)
+{
+ ExecutionEngine *e = engine();
+ Scope scope(e);
+ ScopedString s(scope, e->newIdentifier(name));
+ ExecutionContext *global = e->rootContext();
+ ScopedFunctionObject function(scope, BuiltinFunction::create(global, s, code));
+ function->defineReadonlyProperty(e->id_length(), Primitive::fromInt32(argumentCount));
+ defineDefaultProperty(s, function);
+}
+
void Object::defineDefaultProperty(String *name, ReturnedValue (*code)(CallContext *), int argumentCount)
{
ExecutionEngine *e = engine();
@@ -177,6 +188,16 @@ void Object::defineDefaultProperty(String *name, ReturnedValue (*code)(CallConte
defineDefaultProperty(name, function);
}
+void Object::defineDefaultProperty(String *name, void (*code)(const BuiltinFunction *, Scope &, CallData *), int argumentCount)
+{
+ ExecutionEngine *e = engine();
+ Scope scope(e);
+ ExecutionContext *global = e->rootContext();
+ ScopedFunctionObject function(scope, BuiltinFunction::create(global, name, code));
+ function->defineReadonlyProperty(e->id_length(), Primitive::fromInt32(argumentCount));
+ defineDefaultProperty(name, function);
+}
+
void Object::defineAccessorProperty(const QString &name, ReturnedValue (*getter)(CallContext *), ReturnedValue (*setter)(CallContext *))
{
ExecutionEngine *e = engine();
@@ -196,6 +217,27 @@ void Object::defineAccessorProperty(String *name, ReturnedValue (*getter)(CallCo
insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
}
+void Object::defineAccessorProperty(const QString &name, void (*getter)(const BuiltinFunction *, Scope &, CallData *),
+ void (*setter)(const BuiltinFunction *, Scope &, CallData *))
+{
+ ExecutionEngine *e = engine();
+ Scope scope(e);
+ ScopedString s(scope, e->newIdentifier(name));
+ defineAccessorProperty(s, getter, setter);
+}
+
+void Object::defineAccessorProperty(String *name, void (*getter)(const BuiltinFunction *, Scope &, CallData *),
+ void (*setter)(const BuiltinFunction *, Scope &, CallData *))
+{
+ ExecutionEngine *v4 = engine();
+ QV4::Scope scope(v4);
+ ScopedProperty p(scope);
+ ExecutionContext *global = v4->rootContext();
+ p->setGetter(ScopedFunctionObject(scope, (getter ? BuiltinFunction::create(global, name, getter) : 0)));
+ p->setSetter(ScopedFunctionObject(scope, (setter ? BuiltinFunction::create(global, name, setter) : 0)));
+ insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
+}
+
void Object::defineReadonlyProperty(const QString &name, const Value &value)
{
QV4::ExecutionEngine *e = engine();
@@ -213,12 +255,6 @@ void Object::markObjects(Heap::Base *that, ExecutionEngine *e)
{
Heap::Object *o = static_cast<Heap::Object *>(that);
- if (o->inlineMemberSize) {
- Value *v = o->propertyData(0);
- for (uint i = 0; i < o->inlineMemberSize; ++i)
- v[i].mark(e);
- }
-
if (o->memberData)
o->memberData->mark(e);
if (o->arrayData)
@@ -1120,6 +1156,49 @@ uint Object::getLength(const Managed *m)
return v->toUInt32();
}
+// 'var' is 'V' in 15.3.5.3.
+ReturnedValue Object::instanceOf(const Object *typeObject, const Value &var)
+{
+ QV4::ExecutionEngine *engine = typeObject->internalClass()->engine;
+
+ // 15.3.5.3, Assume F is a Function object.
+ const FunctionObject *function = typeObject->as<FunctionObject>();
+ if (!function)
+ return engine->throwTypeError();
+
+ Heap::FunctionObject *f = function->d();
+ if (function->isBoundFunction())
+ f = function->cast<BoundFunction>()->target();
+
+ // 15.3.5.3, 1: HasInstance can only be used on an object
+ const Object *lhs = var.as<Object>();
+ if (!lhs)
+ return Encode(false);
+
+ // 15.3.5.3, 2
+ const Object *o = f->protoProperty();
+ if (!o) // 15.3.5.3, 3
+ return engine->throwTypeError();
+
+ Heap::Object *v = lhs->d();
+
+ // 15.3.5.3, 4
+ while (v) {
+ // 15.3.5.3, 4, a
+ v = v->prototype;
+
+ // 15.3.5.3, 4, b
+ if (!v)
+ break; // will return false
+
+ // 15.3.5.3, 4, c
+ else if (o->d() == v)
+ return Encode(true);
+ }
+
+ return Encode(false);
+}
+
bool Object::setArrayLength(uint newLen)
{
Q_ASSERT(isArrayObject());
diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h
index 6c679deb10..6a543ae1a8 100644
--- a/src/qml/jsruntime/qv4object_p.h
+++ b/src/qml/jsruntime/qv4object_p.h
@@ -63,17 +63,17 @@ QT_BEGIN_NAMESPACE
namespace QV4 {
+struct BuiltinFunction;
+
namespace Heap {
struct Object : Base {
void init() { Base::init(); }
void destroy() { Base::destroy(); }
- const Value *propertyData(uint index) const { if (index < inlineMemberSize) return reinterpret_cast<const Value *>(this) + inlineMemberOffset + index; return memberData->data + index - inlineMemberSize; }
- Value *propertyData(uint index) { if (index < inlineMemberSize) return reinterpret_cast<Value *>(this) + inlineMemberOffset + index; return memberData->data + index - inlineMemberSize; }
+ const Value *propertyData(uint index) const { return memberData->data + index; }
+ Value *propertyData(uint index) { return memberData->data + index; }
- uint inlineMemberOffset;
- uint inlineMemberSize;
InternalClass *internalClass;
Pointer<Object> prototype;
Pointer<MemberData> memberData;
@@ -140,6 +140,7 @@ struct ObjectVTable
void (*setLookup)(Managed *m, Lookup *l, const Value &v);
uint (*getLength)(const Managed *m);
void (*advanceIterator)(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes);
+ ReturnedValue (*instanceOf)(const Object *typeObject, const Value &var);
};
#define DEFINE_OBJECT_VTABLE_BASE(classname) \
@@ -159,7 +160,8 @@ const QV4::ObjectVTable classname::static_vtbl = \
getLookup, \
setLookup, \
getLength, \
- advanceIterator \
+ advanceIterator, \
+ instanceOf \
}
#define DEFINE_OBJECT_VTABLE(classname) \
@@ -238,9 +240,15 @@ struct Q_QML_EXPORT Object: Managed {
}
void defineDefaultProperty(const QString &name, const Value &value);
void defineDefaultProperty(const QString &name, ReturnedValue (*code)(CallContext *), int argumentCount = 0);
+ void defineDefaultProperty(const QString &name, void (*code)(const BuiltinFunction *, Scope &, CallData *), int argumentCount = 0);
void defineDefaultProperty(String *name, ReturnedValue (*code)(CallContext *), int argumentCount = 0);
+ void defineDefaultProperty(String *name, void (*code)(const BuiltinFunction *, Scope &, CallData *), int argumentCount = 0);
void defineAccessorProperty(const QString &name, ReturnedValue (*getter)(CallContext *), ReturnedValue (*setter)(CallContext *));
void defineAccessorProperty(String *name, ReturnedValue (*getter)(CallContext *), ReturnedValue (*setter)(CallContext *));
+ void defineAccessorProperty(const QString &name, void (*getter)(const BuiltinFunction *, Scope &, CallData *),
+ void (*setter)(const BuiltinFunction *, Scope &, CallData *));
+ void defineAccessorProperty(String *name, void (*getter)(const BuiltinFunction *, Scope &, CallData *),
+ void (*setter)(const BuiltinFunction *, Scope &, CallData *));
/* Fixed: Writable: false, Enumerable: false, Configurable: false */
void defineReadonlyProperty(const QString &name, const Value &value);
void defineReadonlyProperty(String *name, const Value &value);
@@ -345,6 +353,8 @@ public:
void advanceIterator(ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes)
{ vtable()->advanceIterator(this, it, name, index, p, attributes); }
uint getLength() const { return vtable()->getLength(this); }
+ ReturnedValue instanceOf(const Value &var) const
+ { return vtable()->instanceOf(this, var); }
inline void construct(Scope &scope, CallData *d) const
{ return vtable()->construct(this, scope, d); }
@@ -366,6 +376,7 @@ protected:
static void setLookup(Managed *m, Lookup *l, const Value &v);
static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes);
static uint getLength(const Managed *m);
+ static ReturnedValue instanceOf(const Object *typeObject, const Value &var);
private:
ReturnedValue internalGet(String *name, bool *hasProperty) const;
diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp
index 8191083544..97dbe24339 100644
--- a/src/qml/jsruntime/qv4objectproto.cpp
+++ b/src/qml/jsruntime/qv4objectproto.cpp
@@ -121,100 +121,100 @@ void ObjectPrototype::init(ExecutionEngine *v4, Object *ctor)
insertMember(v4->id___proto__(), p, Attr_Accessor|Attr_NotEnumerable);
}
-ReturnedValue ObjectPrototype::method_getPrototypeOf(CallContext *ctx)
+void ObjectPrototype::method_getPrototypeOf(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->argument(0));
+ ScopedObject o(scope, callData->argument(0));
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
ScopedObject p(scope, o->prototype());
- return !!p ? p->asReturnedValue() : Encode::null();
+ scope.result = !!p ? p->asReturnedValue() : Encode::null();
}
-ReturnedValue ObjectPrototype::method_getOwnPropertyDescriptor(CallContext *ctx)
+void ObjectPrototype::method_getOwnPropertyDescriptor(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject O(scope, ctx->argument(0));
- if (!O)
- return ctx->engine()->throwTypeError();
+ ScopedObject O(scope, callData->argument(0));
+ if (!O) {
+ scope.result = scope.engine->throwTypeError();
+ return;
+ }
if (ArgumentsObject::isNonStrictArgumentsObject(O))
static_cast<ArgumentsObject *>(O.getPointer())->fullyCreate();
- ScopedValue v(scope, ctx->argument(1));
+ ScopedValue v(scope, callData->argument(1));
ScopedString name(scope, v->toString(scope.engine));
- if (scope.hasException())
- return Encode::undefined();
+ CHECK_EXCEPTION();
+
PropertyAttributes attrs;
ScopedProperty desc(scope);
O->getOwnProperty(name, &attrs, desc);
- return fromPropertyDescriptor(scope.engine, desc, attrs);
+ scope.result = fromPropertyDescriptor(scope.engine, desc, attrs);
}
-ReturnedValue ObjectPrototype::method_getOwnPropertyNames(CallContext *context)
+void ObjectPrototype::method_getOwnPropertyNames(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(context);
- ScopedObject O(scope, context->argument(0));
- if (!O)
- return context->engine()->throwTypeError();
+ ScopedObject O(scope, callData->argument(0));
+ if (!O) {
+ scope.result = scope.engine->throwTypeError();
+ return;
+ }
- ScopedArrayObject array(scope, getOwnPropertyNames(context->d()->engine, context->args()[0]));
- return array.asReturnedValue();
+ scope.result = getOwnPropertyNames(scope.engine, callData->args[0]);
}
-ReturnedValue ObjectPrototype::method_create(CallContext *ctx)
+void ObjectPrototype::method_create(const BuiltinFunction *builtin, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedValue O(scope, ctx->argument(0));
- if (!O->isObject() && !O->isNull())
- return ctx->engine()->throwTypeError();
+ ScopedValue O(scope, callData->argument(0));
+ if (!O->isObject() && !O->isNull()) {
+ scope.result = scope.engine->throwTypeError();
+ return;
+ }
- ScopedObject newObject(scope, ctx->d()->engine->newObject());
+ ScopedObject newObject(scope, scope.engine->newObject());
newObject->setPrototype(O->as<Object>());
- if (ctx->argc() > 1 && !ctx->args()[1].isUndefined()) {
- ctx->d()->callData->args[0] = newObject.asReturnedValue();
- return method_defineProperties(ctx);
+ if (callData->argc > 1 && !callData->args[1].isUndefined()) {
+ callData->args[0] = newObject;
+ method_defineProperties(builtin, scope, callData);
+ return;
}
- return newObject.asReturnedValue();
+ scope.result = newObject;
}
-ReturnedValue ObjectPrototype::method_defineProperty(CallContext *ctx)
+void ObjectPrototype::method_defineProperty(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject O(scope, ctx->argument(0));
- if (!O)
- return ctx->engine()->throwTypeError();
+ ScopedObject O(scope, callData->argument(0));
+ if (!O) {
+ scope.result = scope.engine->throwTypeError();
+ return;
+ }
- ScopedString name(scope, ctx->argument(1), ScopedString::Convert);
- if (scope.engine->hasException)
- return Encode::undefined();
+ ScopedString name(scope, callData->argument(1), ScopedString::Convert);
+ CHECK_EXCEPTION();
- ScopedValue attributes(scope, ctx->argument(2));
+ ScopedValue attributes(scope, callData->argument(2));
ScopedProperty pd(scope);
PropertyAttributes attrs;
toPropertyDescriptor(scope.engine, attributes, pd, &attrs);
- if (scope.engine->hasException)
- return Encode::undefined();
+ CHECK_EXCEPTION();
if (!O->__defineOwnProperty__(scope.engine, name, pd, attrs))
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- return O.asReturnedValue();
+ scope.result = O;
}
-ReturnedValue ObjectPrototype::method_defineProperties(CallContext *ctx)
+void ObjectPrototype::method_defineProperties(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject O(scope, ctx->argument(0));
+ ScopedObject O(scope, callData->argument(0));
if (!O)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
+
+ ScopedObject o(scope, callData->argument(1), ScopedObject::Convert);
+ CHECK_EXCEPTION();
- ScopedObject o(scope, ctx->argument(1), ScopedObject::Convert);
- if (scope.engine->hasException)
- return Encode::undefined();
ScopedValue val(scope);
ObjectIterator it(scope, o, ObjectIterator::EnumerableOnly);
@@ -230,26 +230,24 @@ ReturnedValue ObjectPrototype::method_defineProperties(CallContext *ctx)
PropertyAttributes nattrs;
val = o->getValue(pd->value, attrs);
toPropertyDescriptor(scope.engine, val, n, &nattrs);
- if (scope.engine->hasException)
- return Encode::undefined();
+ CHECK_EXCEPTION();
bool ok;
if (name)
ok = O->__defineOwnProperty__(scope.engine, name, n, nattrs);
else
ok = O->__defineOwnProperty__(scope.engine, index, n, nattrs);
if (!ok)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
}
- return O.asReturnedValue();
+ scope.result = O;
}
-ReturnedValue ObjectPrototype::method_seal(CallContext *ctx)
+void ObjectPrototype::method_seal(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->argument(0));
+ ScopedObject o(scope, callData->argument(0));
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
o->setInternalClass(o->internalClass()->sealed());
@@ -261,15 +259,14 @@ ReturnedValue ObjectPrototype::method_seal(CallContext *ctx)
}
}
- return o.asReturnedValue();
+ scope.result = o;
}
-ReturnedValue ObjectPrototype::method_freeze(CallContext *ctx)
+void ObjectPrototype::method_freeze(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->argument(0));
+ ScopedObject o(scope, callData->argument(0));
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (ArgumentsObject::isNonStrictArgumentsObject(o))
static_cast<ArgumentsObject *>(o.getPointer())->fullyCreate();
@@ -285,96 +282,111 @@ ReturnedValue ObjectPrototype::method_freeze(CallContext *ctx)
o->arrayData()->attrs[i].setWritable(false);
}
}
- return o.asReturnedValue();
+ scope.result = o;
}
-ReturnedValue ObjectPrototype::method_preventExtensions(CallContext *ctx)
+void ObjectPrototype::method_preventExtensions(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->argument(0));
+ ScopedObject o(scope, callData->argument(0));
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
o->setInternalClass(o->internalClass()->nonExtensible());
- return o.asReturnedValue();
+ scope.result = o;
}
-ReturnedValue ObjectPrototype::method_isSealed(CallContext *ctx)
+void ObjectPrototype::method_isSealed(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->argument(0));
+ ScopedObject o(scope, callData->argument(0));
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- if (o->isExtensible())
- return Encode(false);
+ if (o->isExtensible()) {
+ scope.result = Encode(false);
+ return;
+ }
- if (o->internalClass() != o->internalClass()->sealed())
- return Encode(false);
+ if (o->internalClass() != o->internalClass()->sealed()) {
+ scope.result = Encode(false);
+ return;
+ }
- if (!o->arrayData() || !o->arrayData()->length())
- return Encode(true);
+ if (!o->arrayData() || !o->arrayData()->length()) {
+ scope.result = Encode(true);
+ return;
+ }
Q_ASSERT(o->arrayData() && o->arrayData()->length());
- if (!o->arrayData()->attrs)
- return Encode(false);
+ if (!o->arrayData()->attrs) {
+ scope.result = Encode(false);
+ return;
+ }
for (uint i = 0; i < o->arrayData()->alloc; ++i) {
if (!o->arrayData()->isEmpty(i))
- if (o->arrayData()->attributes(i).isConfigurable())
- return Encode(false);
+ if (o->arrayData()->attributes(i).isConfigurable()) {
+ scope.result = Encode(false);
+ return;
+ }
}
- return Encode(true);
+ scope.result = Encode(true);
}
-ReturnedValue ObjectPrototype::method_isFrozen(CallContext *ctx)
+void ObjectPrototype::method_isFrozen(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->argument(0));
+ ScopedObject o(scope, callData->argument(0));
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- if (o->isExtensible())
- return Encode(false);
+ if (o->isExtensible()) {
+ scope.result = Encode(false);
+ return;
+ }
- if (o->internalClass() != o->internalClass()->frozen())
- return Encode(false);
+ if (o->internalClass() != o->internalClass()->frozen()) {
+ scope.result = Encode(false);
+ return;
+ }
- if (!o->arrayData() || !o->arrayData()->length())
- return Encode(true);
+ if (!o->arrayData() || !o->arrayData()->length()) {
+ scope.result = Encode(true);
+ return;
+ }
Q_ASSERT(o->arrayData() && o->arrayData()->length());
- if (!o->arrayData()->attrs)
- return Encode(false);
+ if (!o->arrayData()->attrs) {
+ scope.result = Encode(false);
+ return;
+ }
for (uint i = 0; i < o->arrayData()->alloc; ++i) {
if (!o->arrayData()->isEmpty(i))
- if (o->arrayData()->attributes(i).isConfigurable() || o->arrayData()->attributes(i).isWritable())
- return Encode(false);
+ if (o->arrayData()->attributes(i).isConfigurable() || o->arrayData()->attributes(i).isWritable()) {
+ scope.result = Encode(false);
+ return;
+ }
}
- return Encode(true);
+ scope.result = Encode(true);
}
-ReturnedValue ObjectPrototype::method_isExtensible(CallContext *ctx)
+void ObjectPrototype::method_isExtensible(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->argument(0));
+ ScopedObject o(scope, callData->argument(0));
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- return Encode((bool)o->isExtensible());
+ scope.result = Encode((bool)o->isExtensible());
}
-ReturnedValue ObjectPrototype::method_keys(CallContext *ctx)
+void ObjectPrototype::method_keys(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->argument(0));
+ ScopedObject o(scope, callData->argument(0));
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedArrayObject a(scope, ctx->d()->engine->newArrayObject());
+ ScopedArrayObject a(scope, scope.engine->newArrayObject());
ObjectIterator it(scope, o, ObjectIterator::EnumerableOnly);
ScopedValue name(scope);
@@ -385,175 +397,159 @@ ReturnedValue ObjectPrototype::method_keys(CallContext *ctx)
a->push_back(name);
}
- return a.asReturnedValue();
+ scope.result = a;
}
-ReturnedValue ObjectPrototype::method_toString(CallContext *ctx)
+void ObjectPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- if (ctx->thisObject().isUndefined()) {
- return ctx->d()->engine->newString(QStringLiteral("[object Undefined]"))->asReturnedValue();
- } else if (ctx->thisObject().isNull()) {
- return ctx->d()->engine->newString(QStringLiteral("[object Null]"))->asReturnedValue();
+ if (callData->thisObject.isUndefined()) {
+ scope.result = scope.engine->newString(QStringLiteral("[object Undefined]"));
+ } else if (callData->thisObject.isNull()) {
+ scope.result = scope.engine->newString(QStringLiteral("[object Null]"));
} else {
- ScopedObject obj(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject obj(scope, callData->thisObject.toObject(scope.engine));
QString className = obj->className();
- return ctx->d()->engine->newString(QStringLiteral("[object %1]").arg(className))->asReturnedValue();
+ scope.result = scope.engine->newString(QStringLiteral("[object %1]").arg(className));
}
}
-ReturnedValue ObjectPrototype::method_toLocaleString(CallContext *ctx)
+void ObjectPrototype::method_toLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->thisObject().toObject(scope.engine));
+ ScopedObject o(scope, callData->thisObject.toObject(scope.engine));
if (!o)
- return Encode::undefined();
- ScopedFunctionObject f(scope, o->get(ctx->d()->engine->id_toString()));
+ RETURN_UNDEFINED();
+
+ ScopedFunctionObject f(scope, o->get(scope.engine->id_toString()));
if (!f)
- return ctx->engine()->throwTypeError();
- ScopedCallData callData(scope);
- callData->thisObject = o;
+ THROW_TYPE_ERROR();
+ ScopedCallData cData(scope);
+ cData->thisObject = o;
f->call(scope, callData);
- return scope.result.asReturnedValue();
}
-ReturnedValue ObjectPrototype::method_valueOf(CallContext *ctx)
+void ObjectPrototype::method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedValue v(scope, ctx->thisObject().toObject(scope.engine));
- if (ctx->d()->engine->hasException)
- return Encode::undefined();
- return v->asReturnedValue();
+ scope.result = callData->thisObject.toObject(scope.engine);
}
-ReturnedValue ObjectPrototype::method_hasOwnProperty(CallContext *ctx)
+void ObjectPrototype::method_hasOwnProperty(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedString P(scope, ctx->argument(0), ScopedString::Convert);
- if (scope.engine->hasException)
- return Encode::undefined();
- ScopedObject O(scope, ctx->thisObject(), ScopedObject::Convert);
- if (scope.engine->hasException)
- return Encode::undefined();
+ ScopedString P(scope, callData->argument(0), ScopedString::Convert);
+ CHECK_EXCEPTION();
+ ScopedObject O(scope, callData->thisObject, ScopedObject::Convert);
+ CHECK_EXCEPTION();
bool r = O->hasOwnProperty(P);
if (!r)
r = !O->query(P).isEmpty();
- return Encode(r);
+ scope.result = Encode(r);
}
-ReturnedValue ObjectPrototype::method_isPrototypeOf(CallContext *ctx)
+void ObjectPrototype::method_isPrototypeOf(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject V(scope, ctx->argument(0));
- if (!V)
- return Encode(false);
+ ScopedObject V(scope, callData->argument(0));
+ if (!V) {
+ scope.result = Encode(false);
+ return;
+ }
- ScopedObject O(scope, ctx->thisObject(), ScopedObject::Convert);
- if (scope.engine->hasException)
- return Encode::undefined();
+ ScopedObject O(scope, callData->thisObject, ScopedObject::Convert);
+ CHECK_EXCEPTION();
ScopedObject proto(scope, V->prototype());
while (proto) {
- if (O->d() == proto->d())
- return Encode(true);
+ if (O->d() == proto->d()) {
+ scope.result = Encode(true);
+ return;
+ }
proto = proto->prototype();
}
- return Encode(false);
+ scope.result = Encode(false);
}
-ReturnedValue ObjectPrototype::method_propertyIsEnumerable(CallContext *ctx)
+void ObjectPrototype::method_propertyIsEnumerable(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedString p(scope, ctx->argument(0), ScopedString::Convert);
- if (scope.engine->hasException)
- return Encode::undefined();
+ ScopedString p(scope, callData->argument(0), ScopedString::Convert);
+ CHECK_EXCEPTION();
- ScopedObject o(scope, ctx->thisObject(), ScopedObject::Convert);
- if (scope.engine->hasException)
- return Encode::undefined();
+ ScopedObject o(scope, callData->thisObject, ScopedObject::Convert);
+ CHECK_EXCEPTION();
PropertyAttributes attrs;
o->getOwnProperty(p, &attrs);
- return Encode(attrs.isEnumerable());
+ scope.result = Encode(attrs.isEnumerable());
}
-ReturnedValue ObjectPrototype::method_defineGetter(CallContext *ctx)
+void ObjectPrototype::method_defineGetter(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() < 2)
- return ctx->engine()->throwTypeError();
+ if (callData->argc < 2)
+ THROW_TYPE_ERROR();
- Scope scope(ctx);
- ScopedFunctionObject f(scope, ctx->argument(1));
+ ScopedFunctionObject f(scope, callData->argument(1));
if (!f)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedString prop(scope, ctx->argument(0), ScopedString::Convert);
- if (scope.engine->hasException)
- return Encode::undefined();
+ ScopedString prop(scope, callData->argument(0), ScopedString::Convert);
+ CHECK_EXCEPTION();
- ScopedObject o(scope, ctx->thisObject());
+ ScopedObject o(scope, callData->thisObject);
if (!o) {
- if (!ctx->thisObject().isUndefined())
- return Encode::undefined();
- o = ctx->d()->engine->globalObject;
+ if (!callData->thisObject.isUndefined())
+ RETURN_UNDEFINED();
+ o = scope.engine->globalObject;
}
ScopedProperty pd(scope);
pd->value = f;
pd->set = Primitive::emptyValue();
o->__defineOwnProperty__(scope.engine, prop, pd, Attr_Accessor);
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
-ReturnedValue ObjectPrototype::method_defineSetter(CallContext *ctx)
+void ObjectPrototype::method_defineSetter(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() < 2)
- return ctx->engine()->throwTypeError();
+ if (callData->argc < 2)
+ THROW_TYPE_ERROR();
- Scope scope(ctx);
- ScopedFunctionObject f(scope, ctx->argument(1));
+ ScopedFunctionObject f(scope, callData->argument(1));
if (!f)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedString prop(scope, ctx->argument(0), ScopedString::Convert);
- if (scope.engine->hasException)
- return Encode::undefined();
+ ScopedString prop(scope, callData->argument(0), ScopedString::Convert);
+ CHECK_EXCEPTION();
- ScopedObject o(scope, ctx->thisObject());
+ ScopedObject o(scope, callData->thisObject);
if (!o) {
- if (!ctx->thisObject().isUndefined())
- return Encode::undefined();
- o = ctx->d()->engine->globalObject;
+ if (!callData->thisObject.isUndefined())
+ RETURN_UNDEFINED();
+ o = scope.engine->globalObject;
}
ScopedProperty pd(scope);
pd->value = Primitive::emptyValue();
pd->set = f;
o->__defineOwnProperty__(scope.engine, prop, pd, Attr_Accessor);
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
-ReturnedValue ObjectPrototype::method_get_proto(CallContext *ctx)
+void ObjectPrototype::method_get_proto(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->thisObject().as<Object>());
+ ScopedObject o(scope, callData->thisObject.as<Object>());
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- return o->prototype()->asReturnedValue();
+ scope.result = o->prototype();
}
-ReturnedValue ObjectPrototype::method_set_proto(CallContext *ctx)
+void ObjectPrototype::method_set_proto(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedObject o(scope, ctx->thisObject());
- if (!o || !ctx->argc())
- return ctx->engine()->throwTypeError();
+ ScopedObject o(scope, callData->thisObject);
+ if (!o || !callData->argc)
+ THROW_TYPE_ERROR();
- if (ctx->args()[0].isNull()) {
+ if (callData->args[0].isNull()) {
o->setPrototype(0);
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
- ScopedObject p(scope, ctx->args()[0]);
+ ScopedObject p(scope, callData->args[0]);
bool ok = false;
if (!!p) {
if (o->prototype() == p->d()) {
@@ -562,9 +558,11 @@ ReturnedValue ObjectPrototype::method_set_proto(CallContext *ctx)
ok = o->setPrototype(p);
}
}
- if (!ok)
- return ctx->engine()->throwTypeError(QStringLiteral("Cyclic __proto__ value"));
- return Encode::undefined();
+ if (!ok) {
+ scope.result = scope.engine->throwTypeError(QStringLiteral("Cyclic __proto__ value"));
+ return;
+ }
+ RETURN_UNDEFINED();
}
void ObjectPrototype::toPropertyDescriptor(ExecutionEngine *engine, const Value &v, Property *desc, PropertyAttributes *attrs)
diff --git a/src/qml/jsruntime/qv4objectproto_p.h b/src/qml/jsruntime/qv4objectproto_p.h
index e3d85782d5..1db8615511 100644
--- a/src/qml/jsruntime/qv4objectproto_p.h
+++ b/src/qml/jsruntime/qv4objectproto_p.h
@@ -78,32 +78,32 @@ struct ObjectPrototype: Object
{
void init(ExecutionEngine *engine, Object *ctor);
- static ReturnedValue method_getPrototypeOf(CallContext *ctx);
- static ReturnedValue method_getOwnPropertyDescriptor(CallContext *ctx);
- static ReturnedValue method_getOwnPropertyNames(CallContext *context);
- static ReturnedValue method_create(CallContext *ctx);
- static ReturnedValue method_defineProperty(CallContext *ctx);
- static ReturnedValue method_defineProperties(CallContext *ctx);
- static ReturnedValue method_seal(CallContext *ctx);
- static ReturnedValue method_freeze(CallContext *ctx);
- static ReturnedValue method_preventExtensions(CallContext *ctx);
- static ReturnedValue method_isSealed(CallContext *ctx);
- static ReturnedValue method_isFrozen(CallContext *ctx);
- static ReturnedValue method_isExtensible(CallContext *ctx);
- static ReturnedValue method_keys(CallContext *ctx);
-
- static ReturnedValue method_toString(CallContext *ctx);
- static ReturnedValue method_toLocaleString(CallContext *ctx);
- static ReturnedValue method_valueOf(CallContext *ctx);
- static ReturnedValue method_hasOwnProperty(CallContext *ctx);
- static ReturnedValue method_isPrototypeOf(CallContext *ctx);
- static ReturnedValue method_propertyIsEnumerable(CallContext *ctx);
-
- static ReturnedValue method_defineGetter(CallContext *ctx);
- static ReturnedValue method_defineSetter(CallContext *ctx);
-
- static ReturnedValue method_get_proto(CallContext *ctx);
- static ReturnedValue method_set_proto(CallContext *ctx);
+ static void method_getPrototypeOf(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getOwnPropertyDescriptor(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_getOwnPropertyNames(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_create(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_defineProperty(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_defineProperties(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_seal(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_freeze(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_preventExtensions(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_isSealed(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_isFrozen(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_isExtensible(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_keys(const BuiltinFunction *, Scope &scope, CallData *callData);
+
+ static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_hasOwnProperty(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_isPrototypeOf(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_propertyIsEnumerable(const BuiltinFunction *, Scope &scope, CallData *callData);
+
+ static void method_defineGetter(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_defineSetter(const BuiltinFunction *, Scope &scope, CallData *callData);
+
+ static void method_get_proto(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_set_proto(const BuiltinFunction *, Scope &scope, CallData *callData);
static void toPropertyDescriptor(ExecutionEngine *engine, const Value &v, Property *desc, PropertyAttributes *attrs);
static ReturnedValue fromPropertyDescriptor(ExecutionEngine *engine, const Property *desc, PropertyAttributes attrs);
diff --git a/src/qml/jsruntime/qv4profiling.cpp b/src/qml/jsruntime/qv4profiling.cpp
index 349ec48e06..8862cbef8e 100644
--- a/src/qml/jsruntime/qv4profiling.cpp
+++ b/src/qml/jsruntime/qv4profiling.cpp
@@ -96,7 +96,7 @@ void Profiler::reportData(bool trackLocations)
FunctionLocationHash locations;
properties.reserve(m_data.size());
- foreach (const FunctionCall &call, m_data) {
+ for (const FunctionCall &call : qAsConst(m_data)) {
properties.append(call.properties());
Function *function = call.function();
SentMarker &marker = m_sentLocations[reinterpret_cast<quintptr>(function)];
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index 5f66b56a42..346ca62a6f 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -673,18 +673,24 @@ void QObjectWrapper::advanceIterator(Managed *m, ObjectIterator *it, Value *name
QObjectWrapper *that = static_cast<QObjectWrapper*>(m);
- if (that->d()->object()) {
- const QMetaObject *mo = that->d()->object()->metaObject();
+ QObject *thatObject = that->d()->object();
+ if (thatObject && !QQmlData::wasDeleted(thatObject)) {
+ const QMetaObject *mo = thatObject->metaObject();
// These indices don't apply to gadgets, so don't block them.
const bool preventDestruction = mo->superClass() || mo == &QObject::staticMetaObject;
const int propertyCount = mo->propertyCount();
if (it->arrayIndex < static_cast<uint>(propertyCount)) {
- Scope scope(that->engine());
- ScopedString propName(scope, that->engine()->newString(QString::fromUtf8(mo->property(it->arrayIndex).name())));
+ ExecutionEngine *thatEngine = that->engine();
+ Scope scope(thatEngine);
+ const QMetaProperty property = mo->property(it->arrayIndex);
+ ScopedString propName(scope, thatEngine->newString(QString::fromUtf8(property.name())));
name->setM(propName->d());
++it->arrayIndex;
*attributes = QV4::Attr_Data;
- p->value = that->get(propName);
+
+ QQmlPropertyData local;
+ local.load(property);
+ p->value = that->getProperty(thatEngine, thatObject, &local);
return;
}
const int methodCount = mo->methodCount();
@@ -694,11 +700,15 @@ void QObjectWrapper::advanceIterator(Managed *m, ObjectIterator *it, Value *name
++it->arrayIndex;
if (method.access() == QMetaMethod::Private || (preventDestruction && (index == deleteLaterIdx || index == destroyedIdx1 || index == destroyedIdx2)))
continue;
- Scope scope(that->engine());
- ScopedString methodName(scope, that->engine()->newString(QString::fromUtf8(method.name())));
+ ExecutionEngine *thatEngine = that->engine();
+ Scope scope(thatEngine);
+ ScopedString methodName(scope, thatEngine->newString(QString::fromUtf8(method.name())));
name->setM(methodName->d());
*attributes = QV4::Attr_Data;
- p->value = that->get(methodName);
+
+ QQmlPropertyData local;
+ local.load(method);
+ p->value = that->getProperty(thatEngine, thatObject, &local);
return;
}
}
@@ -826,40 +836,39 @@ struct QObjectSlotDispatcher : public QtPrivate::QSlotObjectBase
} // namespace QV4
-ReturnedValue QObjectWrapper::method_connect(CallContext *ctx)
+void QObjectWrapper::method_connect(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() == 0)
- V4THROW_ERROR("Function.prototype.connect: no arguments given");
+ if (callData->argc == 0)
+ THROW_GENERIC_ERROR("Function.prototype.connect: no arguments given");
- QPair<QObject *, int> signalInfo = extractQtSignal(ctx->thisObject());
+ QPair<QObject *, int> signalInfo = extractQtSignal(callData->thisObject);
QObject *signalObject = signalInfo.first;
int signalIndex = signalInfo.second; // in method range, not signal range!
if (signalIndex < 0)
- V4THROW_ERROR("Function.prototype.connect: this object is not a signal");
+ THROW_GENERIC_ERROR("Function.prototype.connect: this object is not a signal");
if (!signalObject)
- V4THROW_ERROR("Function.prototype.connect: cannot connect to deleted QObject");
+ THROW_GENERIC_ERROR("Function.prototype.connect: cannot connect to deleted QObject");
if (signalObject->metaObject()->method(signalIndex).methodType() != QMetaMethod::Signal)
- V4THROW_ERROR("Function.prototype.connect: this object is not a signal");
+ THROW_GENERIC_ERROR("Function.prototype.connect: this object is not a signal");
- QV4::Scope scope(ctx);
QV4::ScopedFunctionObject f(scope);
QV4::ScopedValue thisObject (scope, QV4::Encode::undefined());
- if (ctx->argc() == 1) {
- f = ctx->args()[0];
- } else if (ctx->argc() >= 2) {
- thisObject = ctx->args()[0];
- f = ctx->args()[1];
+ if (callData->argc == 1) {
+ f = callData->args[0];
+ } else if (callData->argc >= 2) {
+ thisObject = callData->args[0];
+ f = callData->args[1];
}
if (!f)
- V4THROW_ERROR("Function.prototype.connect: target is not a function");
+ THROW_GENERIC_ERROR("Function.prototype.connect: target is not a function");
if (!thisObject->isUndefined() && !thisObject->isObject())
- V4THROW_ERROR("Function.prototype.connect: target this is not an object");
+ THROW_GENERIC_ERROR("Function.prototype.connect: target this is not an object");
QV4::QObjectSlotDispatcher *slot = new QV4::QObjectSlotDispatcher;
slot->signalIndex = signalIndex;
@@ -874,49 +883,47 @@ ReturnedValue QObjectWrapper::method_connect(CallContext *ctx)
}
QObjectPrivate::connect(signalObject, signalIndex, slot, Qt::AutoConnection);
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
-ReturnedValue QObjectWrapper::method_disconnect(CallContext *ctx)
+void QObjectWrapper::method_disconnect(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() == 0)
- V4THROW_ERROR("Function.prototype.disconnect: no arguments given");
-
- QV4::Scope scope(ctx);
+ if (callData->argc == 0)
+ THROW_GENERIC_ERROR("Function.prototype.disconnect: no arguments given");
- QPair<QObject *, int> signalInfo = extractQtSignal(ctx->thisObject());
+ QPair<QObject *, int> signalInfo = extractQtSignal(callData->thisObject);
QObject *signalObject = signalInfo.first;
int signalIndex = signalInfo.second;
if (signalIndex == -1)
- V4THROW_ERROR("Function.prototype.disconnect: this object is not a signal");
+ THROW_GENERIC_ERROR("Function.prototype.disconnect: this object is not a signal");
if (!signalObject)
- V4THROW_ERROR("Function.prototype.disconnect: cannot disconnect from deleted QObject");
+ THROW_GENERIC_ERROR("Function.prototype.disconnect: cannot disconnect from deleted QObject");
if (signalIndex < 0 || signalObject->metaObject()->method(signalIndex).methodType() != QMetaMethod::Signal)
- V4THROW_ERROR("Function.prototype.disconnect: this object is not a signal");
+ THROW_GENERIC_ERROR("Function.prototype.disconnect: this object is not a signal");
QV4::ScopedFunctionObject functionValue(scope);
QV4::ScopedValue functionThisValue(scope, QV4::Encode::undefined());
- if (ctx->argc() == 1) {
- functionValue = ctx->args()[0];
- } else if (ctx->argc() >= 2) {
- functionThisValue = ctx->args()[0];
- functionValue = ctx->args()[1];
+ if (callData->argc == 1) {
+ functionValue = callData->args[0];
+ } else if (callData->argc >= 2) {
+ functionThisValue = callData->args[0];
+ functionValue = callData->args[1];
}
if (!functionValue)
- V4THROW_ERROR("Function.prototype.disconnect: target is not a function");
+ THROW_GENERIC_ERROR("Function.prototype.disconnect: target is not a function");
if (!functionThisValue->isUndefined() && !functionThisValue->isObject())
- V4THROW_ERROR("Function.prototype.disconnect: target this is not an object");
+ THROW_GENERIC_ERROR("Function.prototype.disconnect: target this is not an object");
QPair<QObject *, int> functionData = QObjectMethod::extractQtMethod(functionValue);
void *a[] = {
- ctx->d()->engine,
+ scope.engine,
functionValue.ptr,
functionThisValue.ptr,
functionData.first,
@@ -925,7 +932,7 @@ ReturnedValue QObjectWrapper::method_disconnect(CallContext *ctx)
QObjectPrivate::disconnect(signalObject, signalIndex, reinterpret_cast<void**>(&a));
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
static void markChildQObjectsRecursively(QObject *parent, QV4::ExecutionEngine *e)
@@ -1306,9 +1313,8 @@ static QV4::ReturnedValue CallPrecise(const QQmlObjectOrGadget &object, const QQ
int returnType = object.methodReturnType(data, &unknownTypeError);
if (returnType == QMetaType::UnknownType) {
- QString typeName = QString::fromLatin1(unknownTypeError);
- QString error = QStringLiteral("Unknown method return type: %1").arg(typeName);
- return engine->throwError(error);
+ return engine->throwError(QLatin1String("Unknown method return type: ")
+ + QLatin1String(unknownTypeError));
}
if (data.hasArguments()) {
@@ -1323,9 +1329,8 @@ static QV4::ReturnedValue CallPrecise(const QQmlObjectOrGadget &object, const QQ
args = object.methodParameterTypes(data.coreIndex(), &storage, &unknownTypeError);
if (!args) {
- QString typeName = QString::fromLatin1(unknownTypeError);
- QString error = QStringLiteral("Unknown method parameter type: %1").arg(typeName);
- return engine->throwError(error);
+ return engine->throwError(QLatin1String("Unknown method parameter type: ")
+ + QLatin1String(unknownTypeError));
}
if (args[0] > callArgs->argc) {
@@ -1914,8 +1919,8 @@ ReturnedValue QMetaObjectWrapper::constructInternal(CallData * callData) const {
ExecutionEngine *v4 = engine();
const QMetaObject* mo = d()->metaObject;
if (d()->constructorCount == 0) {
- return v4->throwTypeError(QStringLiteral("%1 has no invokable constructor")
- .arg(QLatin1String(mo->className())));
+ return v4->throwTypeError(QLatin1String(mo->className())
+ + QLatin1String(" has no invokable constructor"));
}
Scope scope(v4);
diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h
index c7c4f4dd77..b09e06cec5 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper_p.h
+++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h
@@ -197,8 +197,8 @@ protected:
static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes);
static void markObjects(Heap::Base *that, QV4::ExecutionEngine *e);
- static ReturnedValue method_connect(CallContext *ctx);
- static ReturnedValue method_disconnect(CallContext *ctx);
+ static void method_connect(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_disconnect(const BuiltinFunction *, Scope &scope, CallData *callData);
private:
Q_NEVER_INLINE static ReturnedValue wrap_slowPath(ExecutionEngine *engine, QObject *object);
diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp
index 218695624b..0894d0c25b 100644
--- a/src/qml/jsruntime/qv4regexpobject.cpp
+++ b/src/qml/jsruntime/qv4regexpobject.cpp
@@ -307,7 +307,8 @@ void RegExpCtor::markObjects(Heap::Base *that, ExecutionEngine *e)
{
RegExpCtor::Data *This = static_cast<RegExpCtor::Data *>(that);
This->lastMatch.mark(e);
- This->lastInput->mark(e);
+ if (This->lastInput)
+ This->lastInput->mark(e);
FunctionObject::markObjects(that, e);
}
@@ -348,34 +349,33 @@ void RegExpPrototype::init(ExecutionEngine *engine, Object *constructor)
defineDefaultProperty(QStringLiteral("compile"), method_compile, 2);
}
-ReturnedValue RegExpPrototype::method_exec(CallContext *ctx)
+void RegExpPrototype::method_exec(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<RegExpObject> r(scope, ctx->thisObject().as<RegExpObject>());
+ Scoped<RegExpObject> r(scope, callData->thisObject.as<RegExpObject>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedValue arg(scope, ctx->argument(0));
+ ScopedValue arg(scope, callData->argument(0));
ScopedString str(scope, arg->toString(scope.engine));
if (scope.hasException())
- return Encode::undefined();
+ RETURN_UNDEFINED();
QString s = str->toQString();
int offset = r->global() ? r->lastIndexProperty()->toInt32() : 0;
if (offset < 0 || offset > s.length()) {
*r->lastIndexProperty() = Primitive::fromInt32(0);
- return Encode::null();
+ RETURN_RESULT(Encode::null());
}
- uint* matchOffsets = (uint*)alloca(r->value()->captureCount() * 2 * sizeof(uint));
+ Q_ALLOCA_VAR(uint, matchOffsets, r->value()->captureCount() * 2 * sizeof(uint));
const int result = Scoped<RegExp>(scope, r->value())->match(s, offset, matchOffsets);
- Scoped<RegExpCtor> regExpCtor(scope, ctx->d()->engine->regExpCtor());
+ Scoped<RegExpCtor> regExpCtor(scope, scope.engine->regExpCtor());
regExpCtor->d()->clearLastMatch();
if (result == -1) {
*r->lastIndexProperty() = Primitive::fromInt32(0);
- return Encode::null();
+ RETURN_RESULT(Encode::null());
}
// fill in result data
@@ -386,7 +386,7 @@ ReturnedValue RegExpPrototype::method_exec(CallContext *ctx)
for (int i = 0; i < len; ++i) {
int start = matchOffsets[i * 2];
int end = matchOffsets[i * 2 + 1];
- v = (start != -1) ? ctx->d()->engine->newString(s.mid(start, end - start))->asReturnedValue() : Encode::undefined();
+ v = (start != -1) ? scope.engine->newString(s.mid(start, end - start))->asReturnedValue() : Encode::undefined();
array->arrayPut(i, v);
}
array->setArrayLengthUnchecked(len);
@@ -402,84 +402,75 @@ ReturnedValue RegExpPrototype::method_exec(CallContext *ctx)
if (r->global())
*r->lastIndexProperty() = Primitive::fromInt32(matchOffsets[1]);
- return array.asReturnedValue();
+ scope.result = array;
}
-ReturnedValue RegExpPrototype::method_test(CallContext *ctx)
+void RegExpPrototype::method_test(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedValue r(scope, method_exec(ctx));
- return Encode(!r->isNull());
+ method_exec(b, scope, callData);
+ scope.result = Encode(!scope.result.isNull());
}
-ReturnedValue RegExpPrototype::method_toString(CallContext *ctx)
+void RegExpPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<RegExpObject> r(scope, ctx->thisObject().as<RegExpObject>());
+ Scoped<RegExpObject> r(scope, callData->thisObject.as<RegExpObject>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- return ctx->d()->engine->newString(r->toString())->asReturnedValue();
+ scope.result = scope.engine->newString(r->toString());
}
-ReturnedValue RegExpPrototype::method_compile(CallContext *ctx)
+void RegExpPrototype::method_compile(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<RegExpObject> r(scope, ctx->thisObject().as<RegExpObject>());
+ Scoped<RegExpObject> r(scope, callData->thisObject.as<RegExpObject>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- ScopedCallData callData(scope, ctx->argc());
- memcpy(callData->args, ctx->args(), ctx->argc()*sizeof(Value));
+ ScopedCallData cData(scope, callData->argc);
+ memcpy(cData->args, callData->args, callData->argc*sizeof(Value));
- ctx->d()->engine->regExpCtor()->as<FunctionObject>()->construct(scope, callData);
+ scope.engine->regExpCtor()->as<FunctionObject>()->construct(scope, cData);
Scoped<RegExpObject> re(scope, scope.result.asReturnedValue());
r->d()->value = re->value();
r->d()->global = re->global();
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
template <int index>
-ReturnedValue RegExpPrototype::method_get_lastMatch_n(CallContext *ctx)
+void RegExpPrototype::method_get_lastMatch_n(const BuiltinFunction *, Scope &scope, CallData *)
{
- Scope scope(ctx);
- ScopedArrayObject lastMatch(scope, static_cast<RegExpCtor*>(ctx->d()->engine->regExpCtor())->lastMatch());
- ScopedValue result(scope, lastMatch ? lastMatch->getIndexed(index) : Encode::undefined());
- if (result->isUndefined())
- return ctx->d()->engine->newString()->asReturnedValue();
- return result->asReturnedValue();
+ ScopedArrayObject lastMatch(scope, static_cast<RegExpCtor*>(scope.engine->regExpCtor())->lastMatch());
+ scope.result = lastMatch ? lastMatch->getIndexed(index) : Encode::undefined();
+ if (scope.result.isUndefined())
+ scope.result = scope.engine->newString();
}
-ReturnedValue RegExpPrototype::method_get_lastParen(CallContext *ctx)
+void RegExpPrototype::method_get_lastParen(const BuiltinFunction *, Scope &scope, CallData *)
{
- Scope scope(ctx);
- ScopedArrayObject lastMatch(scope, static_cast<RegExpCtor*>(ctx->d()->engine->regExpCtor())->lastMatch());
- ScopedValue result(scope, lastMatch ? lastMatch->getIndexed(lastMatch->getLength() - 1) : Encode::undefined());
- if (result->isUndefined())
- return ctx->d()->engine->newString()->asReturnedValue();
- return result->asReturnedValue();
+ ScopedArrayObject lastMatch(scope, static_cast<RegExpCtor*>(scope.engine->regExpCtor())->lastMatch());
+ scope.result = lastMatch ? lastMatch->getIndexed(lastMatch->getLength() - 1) : Encode::undefined();
+ if (scope.result.isUndefined())
+ scope.result = scope.engine->newString();
}
-ReturnedValue RegExpPrototype::method_get_input(CallContext *ctx)
+void RegExpPrototype::method_get_input(const BuiltinFunction *, Scope &scope, CallData *)
{
- return static_cast<RegExpCtor*>(ctx->d()->engine->regExpCtor())->lastInput()->asReturnedValue();
+ scope.result = static_cast<RegExpCtor*>(scope.engine->regExpCtor())->lastInput();
}
-ReturnedValue RegExpPrototype::method_get_leftContext(CallContext *ctx)
+void RegExpPrototype::method_get_leftContext(const BuiltinFunction *, Scope &scope, CallData *)
{
- Scope scope(ctx);
- Scoped<RegExpCtor> regExpCtor(scope, ctx->d()->engine->regExpCtor());
+ Scoped<RegExpCtor> regExpCtor(scope, scope.engine->regExpCtor());
QString lastInput = regExpCtor->lastInput()->toQString();
- return ctx->d()->engine->newString(lastInput.left(regExpCtor->lastMatchStart()))->asReturnedValue();
+ scope.result = scope.engine->newString(lastInput.left(regExpCtor->lastMatchStart()));
}
-ReturnedValue RegExpPrototype::method_get_rightContext(CallContext *ctx)
+void RegExpPrototype::method_get_rightContext(const BuiltinFunction *, Scope &scope, CallData *)
{
- Scope scope(ctx);
- Scoped<RegExpCtor> regExpCtor(scope, ctx->d()->engine->regExpCtor());
+ Scoped<RegExpCtor> regExpCtor(scope, scope.engine->regExpCtor());
QString lastInput = regExpCtor->lastInput()->toQString();
- return ctx->d()->engine->newString(lastInput.mid(regExpCtor->lastMatchEnd()))->asReturnedValue();
+ scope.result = scope.engine->newString(lastInput.mid(regExpCtor->lastMatchEnd()));
}
QT_END_NAMESPACE
diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h
index 2c82cfdfd1..c0c7dfa78a 100644
--- a/src/qml/jsruntime/qv4regexpobject_p.h
+++ b/src/qml/jsruntime/qv4regexpobject_p.h
@@ -149,17 +149,17 @@ struct RegExpPrototype: RegExpObject
{
void init(ExecutionEngine *engine, Object *ctor);
- static ReturnedValue method_exec(CallContext *ctx);
- static ReturnedValue method_test(CallContext *ctx);
- static ReturnedValue method_toString(CallContext *ctx);
- static ReturnedValue method_compile(CallContext *ctx);
+ static void method_exec(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_test(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_compile(const BuiltinFunction *, Scope &scope, CallData *callData);
template <int index>
- static ReturnedValue method_get_lastMatch_n(CallContext *ctx);
- static ReturnedValue method_get_lastParen(CallContext *ctx);
- static ReturnedValue method_get_input(CallContext *ctx);
- static ReturnedValue method_get_leftContext(CallContext *ctx);
- static ReturnedValue method_get_rightContext(CallContext *ctx);
+ static void method_get_lastMatch_n(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_lastParen(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_input(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_leftContext(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_rightContext(const BuiltinFunction *, Scope &scope, CallData *callData);
};
}
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 57ad181030..6590054bf3 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -176,7 +176,7 @@ struct RuntimeCounters::Data {
}
std::sort(lines.begin(), lines.end(), Line::less);
outs << lines.size() << " counters:" << endl;
- foreach (const Line &line, lines)
+ for (const Line &line : qAsConst(lines))
outs << qSetFieldWidth(10) << line.count << qSetFieldWidth(0)
<< " | " << line.func
<< " | " << pretty(line.tag1)
@@ -343,35 +343,15 @@ ReturnedValue Runtime::method_deleteName(ExecutionEngine *engine, int nameIndex)
return Encode(engine->currentContext->deleteProperty(name));
}
-QV4::ReturnedValue Runtime::method_instanceof(ExecutionEngine *engine, const Value &left, const Value &right)
+QV4::ReturnedValue Runtime::method_instanceof(ExecutionEngine *engine, const Value &lval, const Value &rval)
{
- const FunctionObject *function = right.as<FunctionObject>();
- if (!function)
- return engine->throwTypeError();
-
- Heap::FunctionObject *f = function->d();
- if (function->isBoundFunction())
- f = function->cast<BoundFunction>()->target();
-
- const Object *o = left.as<Object>();
- if (!o)
- return Encode(false);
- Heap::Object *v = o->d();
-
- o = f->protoProperty();
- if (!o)
- return engine->throwTypeError();
-
- while (v) {
- v = v->prototype;
-
- if (!v)
- break;
- else if (o->d() == v)
- return Encode(true);
- }
+ // 11.8.6, 5: rval must be an Object
+ const Object *rhs = rval.as<Object>();
+ if (!rhs)
+ return engine->throwTypeError();
- return Encode(false);
+ // 11.8.6, 7: call "HasInstance", which we term instanceOf, and return the result.
+ return rhs->instanceOf(lval);
}
QV4::ReturnedValue Runtime::method_in(ExecutionEngine *engine, const Value &left, const Value &right)
@@ -499,6 +479,7 @@ Heap::String *RuntimeHelpers::convertToString(ExecutionEngine *engine, const Val
{
Scope scope(engine);
ScopedValue prim(scope, RuntimeHelpers::toPrimitive(value, STRING_HINT));
+ Q_ASSERT(!prim->isManaged() || prim->isString());
return RuntimeHelpers::convertToString(engine, prim);
}
case Value::Integer_Type:
@@ -1283,12 +1264,16 @@ ReturnedValue Runtime::method_unwindException(ExecutionEngine *engine)
*/
void Runtime::method_pushWithScope(const Value &o, NoThrowEngine *engine)
{
- engine->pushContext(engine->currentContext->newWithContext(o.toObject(engine)));
+ QV4::Value *v = engine->jsAlloca(1);
+ Heap::Object *withObject = o.toObject(engine);
+ *v = withObject;
+ engine->pushContext(engine->currentContext->newWithContext(withObject));
Q_ASSERT(engine->jsStackTop == engine->currentContext + 2);
}
void Runtime::method_pushCatchScope(NoThrowEngine *engine, int exceptionVarNameIndex)
{
+ engine->jsAlloca(1); // keep this symmetric with pushWithScope
ExecutionContext *c = engine->currentContext;
engine->pushContext(c->newCatchContext(c->d()->compilationUnit->runtimeStrings[exceptionVarNameIndex], engine->catchException(0)));
Q_ASSERT(engine->jsStackTop == engine->currentContext + 2);
@@ -1298,7 +1283,7 @@ void Runtime::method_popScope(NoThrowEngine *engine)
{
Q_ASSERT(engine->jsStackTop == engine->currentContext + 2);
engine->popContext();
- engine->jsStackTop -= 2;
+ engine->jsStackTop -= 3;
}
void Runtime::method_declareVar(ExecutionEngine *engine, bool deletable, int nameIndex)
diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h
index 4e627e003f..6775028272 100644
--- a/src/qml/jsruntime/qv4scopedvalue_p.h
+++ b/src/qml/jsruntime/qv4scopedvalue_p.h
@@ -68,6 +68,38 @@ namespace QV4 {
struct ScopedValue;
+#define CHECK_EXCEPTION() \
+ do { \
+ if (scope.hasException()) { \
+ scope.result = QV4::Encode::undefined(); \
+ return; \
+ } \
+ } while (false)
+
+#define RETURN_UNDEFINED() \
+ do { \
+ scope.result = QV4::Encode::undefined(); \
+ return; \
+ } while (false)
+
+#define RETURN_RESULT(r) \
+ do { \
+ scope.result = r; \
+ return; \
+ } while (false)
+
+#define THROW_TYPE_ERROR() \
+ do { \
+ scope.result = scope.engine->throwTypeError(); \
+ return; \
+ } while (false)
+
+#define THROW_GENERIC_ERROR(str) \
+ do { \
+ scope.result = scope.engine->throwError(QString::fromUtf8(str)); \
+ return; \
+ } while (false)
+
struct Scope {
inline Scope(ExecutionContext *ctx)
: engine(ctx->d()->engine)
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index fe8f8474e4..62145f36cc 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -97,7 +97,8 @@ void Script::parse()
const bool parsed = parser.parseProgram();
- foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) {
+ const auto diagnosticMessages = parser.diagnosticMessages();
+ for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) {
if (m.isError()) {
valueScope.engine->throwSyntaxError(m.message, sourceFile, m.loc.startLine, m.loc.startColumn);
return;
@@ -201,7 +202,8 @@ QQmlRefPointer<QV4::CompiledData::CompilationUnit> Script::precompile(IR::Module
QList<QQmlError> errors;
- foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) {
+ const auto diagnosticMessages = parser.diagnosticMessages();
+ for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) {
if (m.isWarning()) {
qWarning("%s:%d : %s", qPrintable(url.toString()), m.loc.startLine, qPrintable(m.message));
continue;
diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp
index 58da7b9f68..8ce10e326d 100644
--- a/src/qml/jsruntime/qv4sequenceobject.cpp
+++ b/src/qml/jsruntime/qv4sequenceobject.cpp
@@ -404,28 +404,28 @@ public:
struct CompareFunctor
{
- CompareFunctor(QV4::ExecutionContext *ctx, const QV4::Value &compareFn)
- : m_ctx(ctx), m_compareFn(&compareFn)
+ CompareFunctor(QV4::ExecutionEngine *v4, const QV4::Value &compareFn)
+ : m_v4(v4), m_compareFn(&compareFn)
{}
bool operator()(typename Container::value_type lhs, typename Container::value_type rhs)
{
- QV4::Scope scope(m_ctx);
+ QV4::Scope scope(m_v4);
ScopedObject compare(scope, m_compareFn);
ScopedCallData callData(scope, 2);
- callData->args[0] = convertElementToValue(this->m_ctx->d()->engine, lhs);
- callData->args[1] = convertElementToValue(this->m_ctx->d()->engine, rhs);
- callData->thisObject = this->m_ctx->d()->engine->globalObject;
+ callData->args[0] = convertElementToValue(m_v4, lhs);
+ callData->args[1] = convertElementToValue(m_v4, rhs);
+ callData->thisObject = m_v4->globalObject;
compare->call(scope, callData);
return scope.result.toNumber() < 0;
}
private:
- QV4::ExecutionContext *m_ctx;
+ QV4::ExecutionEngine *m_v4;
const QV4::Value *m_compareFn;
};
- void sort(QV4::CallContext *ctx)
+ void sort(const BuiltinFunction *, Scope &scope, CallData *callData)
{
if (d()->isReference) {
if (!d()->object)
@@ -433,9 +433,8 @@ public:
loadReference();
}
- QV4::Scope scope(ctx);
- if (ctx->argc() == 1 && ctx->args()[0].as<FunctionObject>()) {
- CompareFunctor cf(ctx, ctx->args()[0]);
+ if (callData->argc == 1 && callData->args[0].as<FunctionObject>()) {
+ CompareFunctor cf(scope.engine, callData->args[0]);
std::sort(d()->container->begin(), d()->container->end(), cf);
} else {
DefaultCompareFunctor cf;
@@ -446,45 +445,43 @@ public:
storeReference();
}
- static QV4::ReturnedValue method_get_length(QV4::CallContext *ctx)
+ static void method_get_length(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQmlSequence<Container> > This(scope, ctx->thisObject().as<QQmlSequence<Container> >());
+ QV4::Scoped<QQmlSequence<Container> > This(scope, callData->thisObject.as<QQmlSequence<Container> >());
if (!This)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (This->d()->isReference) {
if (!This->d()->object)
- return QV4::Encode(0);
+ RETURN_RESULT(Encode(0));
This->loadReference();
}
- return QV4::Encode(This->d()->container->count());
+ RETURN_RESULT(Encode(This->d()->container->count()));
}
- static QV4::ReturnedValue method_set_length(QV4::CallContext* ctx)
+ static void method_set_length(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQmlSequence<Container> > This(scope, ctx->thisObject().as<QQmlSequence<Container> >());
+ QV4::Scoped<QQmlSequence<Container> > This(scope, callData->thisObject.as<QQmlSequence<Container> >());
if (!This)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- quint32 newLength = ctx->args()[0].toUInt32();
+ quint32 newLength = callData->args[0].toUInt32();
/* Qt containers have int (rather than uint) allowable indexes. */
if (newLength > INT_MAX) {
generateWarning(scope.engine, QLatin1String("Index out of range during length set"));
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
/* Read the sequence from the QObject property if we're a reference */
if (This->d()->isReference) {
if (!This->d()->object)
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
This->loadReference();
}
/* Determine whether we need to modify the sequence */
qint32 newCount = static_cast<qint32>(newLength);
qint32 count = This->d()->container->count();
if (newCount == count) {
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
} else if (newCount > count) {
/* according to ECMA262r3 we need to insert */
/* undefined values increasing length to newLength. */
@@ -506,7 +503,7 @@ public:
/* write back. already checked that object is non-null, so skip that check here. */
This->storeReference();
}
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
QVariant toVariant() const
@@ -625,26 +622,25 @@ void SequencePrototype::init()
}
#undef REGISTER_QML_SEQUENCE_METATYPE
-QV4::ReturnedValue SequencePrototype::method_sort(QV4::CallContext *ctx)
+void SequencePrototype::method_sort(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::ScopedObject o(scope, ctx->thisObject());
+ QV4::ScopedObject o(scope, callData->thisObject);
if (!o || !o->isListType())
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- if (ctx->argc() >= 2)
- return o.asReturnedValue();
+ if (callData->argc >= 2)
+ RETURN_RESULT(o);
#define CALL_SORT(SequenceElementType, SequenceElementTypeName, SequenceType, DefaultValue) \
if (QQml##SequenceElementTypeName##List *s = o->as<QQml##SequenceElementTypeName##List>()) { \
- s->sort(ctx); \
+ s->sort(b, scope, callData); \
} else
FOREACH_QML_SEQUENCE_TYPE(CALL_SORT)
#undef CALL_SORT
{}
- return o.asReturnedValue();
+ RETURN_RESULT(o);
}
#define IS_SEQUENCE(unused1, unused2, SequenceType, unused3) \
diff --git a/src/qml/jsruntime/qv4sequenceobject_p.h b/src/qml/jsruntime/qv4sequenceobject_p.h
index c0416ad639..6f96b9f760 100644
--- a/src/qml/jsruntime/qv4sequenceobject_p.h
+++ b/src/qml/jsruntime/qv4sequenceobject_p.h
@@ -67,12 +67,12 @@ struct SequencePrototype : public QV4::Object
{
void init();
- static ReturnedValue method_valueOf(QV4::CallContext *ctx)
+ static void method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- return ctx->thisObject().toString(ctx->engine())->asReturnedValue();
+ scope.result = callData->thisObject.toString(scope.engine);
}
- static ReturnedValue method_sort(QV4::CallContext *ctx);
+ static void method_sort(const BuiltinFunction *, Scope &scope, CallData *callData);
static bool isSequenceType(int sequenceTypeId);
static ReturnedValue newSequence(QV4::ExecutionEngine *engine, int sequenceTypeId, QObject *object, int propertyIndex, bool *succeeded);
diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp
index 1efd8cb714..cde2131aab 100644
--- a/src/qml/jsruntime/qv4string.cpp
+++ b/src/qml/jsruntime/qv4string.cpp
@@ -102,6 +102,7 @@ void Heap::String::init(MemoryManager *mm, String *l, String *r)
stringHash = UINT_MAX;
largestSubLength = qMax(l->largestSubLength, r->largestSubLength);
len = l->len + r->len;
+ Q_ASSERT(largestSubLength <= len);
if (!l->largestSubLength && l->len > largestSubLength)
largestSubLength = l->len;
@@ -113,6 +114,15 @@ void Heap::String::init(MemoryManager *mm, String *l, String *r)
simplifyString();
}
+void Heap::String::destroy() {
+ if (!largestSubLength) {
+ mm->changeUnmanagedHeapSizeUsage(qptrdiff(-text->size) * (int)sizeof(QChar));
+ if (!text->ref.deref())
+ QStringData::deallocate(text);
+ }
+ Base::destroy();
+}
+
uint String::toUInt(bool *ok) const
{
*ok = true;
@@ -151,7 +161,7 @@ void Heap::String::simplifyString() const
text->ref.ref();
identifier = 0;
largestSubLength = 0;
- mm->growUnmanagedHeapSizeUsage(size_t(text->size) * sizeof(QChar));
+ mm->changeUnmanagedHeapSizeUsage(qptrdiff(text->size) * (qptrdiff)sizeof(QChar));
}
void Heap::String::append(const String *data, QChar *ch)
diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h
index 4890a85724..5b0fd292d6 100644
--- a/src/qml/jsruntime/qv4string_p.h
+++ b/src/qml/jsruntime/qv4string_p.h
@@ -73,11 +73,7 @@ struct Q_QML_PRIVATE_EXPORT String : Base {
#ifndef V4_BOOTSTRAP
void init(MemoryManager *mm, const QString &text);
void init(MemoryManager *mm, String *l, String *n);
- void destroy() {
- if (!largestSubLength && !text->ref.deref())
- QStringData::deallocate(text);
- Base::destroy();
- }
+ void destroy();
void simplifyString() const;
int length() const {
Q_ASSERT((largestSubLength &&
diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp
index 6fbf1c3c85..1596f4b0fa 100644
--- a/src/qml/jsruntime/qv4stringobject.cpp
+++ b/src/qml/jsruntime/qv4stringobject.cpp
@@ -214,10 +214,9 @@ void StringPrototype::init(ExecutionEngine *engine, Object *ctor)
defineDefaultProperty(QStringLiteral("trim"), method_trim);
}
-static QString getThisString(ExecutionContext *ctx)
+static QString getThisString(Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- ScopedValue t(scope, ctx->thisObject());
+ ScopedValue t(scope, callData->thisObject);
if (String *s = t->stringValue())
return s->toQString();
if (StringObject *thisString = t->as<StringObject>())
@@ -229,158 +228,146 @@ static QString getThisString(ExecutionContext *ctx)
return t->toQString();
}
-ReturnedValue StringPrototype::method_toString(CallContext *context)
+void StringPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (context->thisObject().isString())
- return context->thisObject().asReturnedValue();
+ if (callData->thisObject.isString())
+ RETURN_RESULT(callData->thisObject);
- StringObject *o = context->thisObject().as<StringObject>();
+ StringObject *o = callData->thisObject.as<StringObject>();
if (!o)
- return context->engine()->throwTypeError();
- return Encode(o->d()->string);
+ THROW_TYPE_ERROR();
+ scope.result = o->d()->string;
}
-ReturnedValue StringPrototype::method_charAt(CallContext *context)
+void StringPrototype::method_charAt(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- const QString str = getThisString(context);
- if (context->d()->engine->hasException)
- return Encode::undefined();
+ const QString str = getThisString(scope, callData);
+ CHECK_EXCEPTION();
int pos = 0;
- if (context->argc() > 0)
- pos = (int) context->args()[0].toInteger();
+ if (callData->argc > 0)
+ pos = (int) callData->args[0].toInteger();
QString result;
if (pos >= 0 && pos < str.length())
result += str.at(pos);
- return context->d()->engine->newString(result)->asReturnedValue();
+ scope.result = scope.engine->newString(result);
}
-ReturnedValue StringPrototype::method_charCodeAt(CallContext *context)
+void StringPrototype::method_charCodeAt(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- const QString str = getThisString(context);
- if (context->d()->engine->hasException)
- return Encode::undefined();
+ const QString str = getThisString(scope, callData);
+ CHECK_EXCEPTION();
int pos = 0;
- if (context->argc() > 0)
- pos = (int) context->args()[0].toInteger();
+ if (callData->argc > 0)
+ pos = (int) callData->args[0].toInteger();
if (pos >= 0 && pos < str.length())
- return Encode(str.at(pos).unicode());
+ RETURN_RESULT(Encode(str.at(pos).unicode()));
- return Encode(qt_qnan());
+ scope.result = Encode(qt_qnan());
}
-ReturnedValue StringPrototype::method_concat(CallContext *context)
+void StringPrototype::method_concat(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(context);
-
- QString value = getThisString(context);
- if (scope.engine->hasException)
- return Encode::undefined();
+ QString value = getThisString(scope, callData);
+ CHECK_EXCEPTION();
ScopedString s(scope);
- for (int i = 0; i < context->argc(); ++i) {
- s = context->args()[i].toString(scope.engine);
- if (scope.hasException())
- return Encode::undefined();
+ for (int i = 0; i < callData->argc; ++i) {
+ s = callData->args[i].toString(scope.engine);
+ CHECK_EXCEPTION();
+
Q_ASSERT(s->isString());
value += s->toQString();
}
- return context->d()->engine->newString(value)->asReturnedValue();
+ scope.result = scope.engine->newString(value);
}
-ReturnedValue StringPrototype::method_endsWith(CallContext *context)
+void StringPrototype::method_endsWith(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QString value = getThisString(context);
- if (context->d()->engine->hasException)
- return Encode::undefined();
+ QString value = getThisString(scope, callData);
+ CHECK_EXCEPTION();
QString searchString;
- if (context->argc()) {
- if (context->args()[0].as<RegExpObject>())
- return context->engine()->throwTypeError();
- searchString = context->args()[0].toQString();
+ if (callData->argc) {
+ if (callData->args[0].as<RegExpObject>())
+ THROW_TYPE_ERROR();
+ searchString = callData->args[0].toQString();
}
int pos = value.length();
- if (context->argc() > 1)
- pos = (int) context->args()[1].toInteger();
+ if (callData->argc > 1)
+ pos = (int) callData->args[1].toInteger();
if (pos == value.length())
- return Encode(value.endsWith(searchString));
+ RETURN_RESULT(Encode(value.endsWith(searchString)));
QStringRef stringToSearch = value.leftRef(pos);
- return Encode(stringToSearch.endsWith(searchString));
+ scope.result = Encode(stringToSearch.endsWith(searchString));
}
-ReturnedValue StringPrototype::method_indexOf(CallContext *context)
+void StringPrototype::method_indexOf(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QString value = getThisString(context);
- if (context->d()->engine->hasException)
- return Encode::undefined();
+ QString value = getThisString(scope, callData);
+ CHECK_EXCEPTION();
QString searchString;
- if (context->argc())
- searchString = context->args()[0].toQString();
+ if (callData->argc)
+ searchString = callData->args[0].toQString();
int pos = 0;
- if (context->argc() > 1)
- pos = (int) context->args()[1].toInteger();
+ if (callData->argc > 1)
+ pos = (int) callData->args[1].toInteger();
int index = -1;
if (! value.isEmpty())
index = value.indexOf(searchString, qMin(qMax(pos, 0), value.length()));
- return Encode(index);
+ scope.result = Encode(index);
}
-ReturnedValue StringPrototype::method_includes(CallContext *context)
+void StringPrototype::method_includes(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QString value = getThisString(context);
- if (context->d()->engine->hasException)
- return Encode::undefined();
+ QString value = getThisString(scope, callData);
+ CHECK_EXCEPTION();
QString searchString;
- if (context->argc()) {
- if (context->args()[0].as<RegExpObject>())
- return context->engine()->throwTypeError();
- searchString = context->args()[0].toQString();
+ if (callData->argc) {
+ if (callData->args[0].as<RegExpObject>())
+ THROW_TYPE_ERROR();
+ searchString = callData->args[0].toQString();
}
int pos = 0;
- if (context->argc() > 1) {
- Scope scope(context);
- ScopedValue posArg(scope, context->argument(1));
+ if (callData->argc > 1) {
+ ScopedValue posArg(scope, callData->argument(1));
pos = (int) posArg->toInteger();
if (!posArg->isInteger() && posArg->isNumber() && qIsInf(posArg->toNumber()))
pos = value.length();
}
if (pos == 0)
- return Encode(value.contains(searchString));
+ RETURN_RESULT(Encode(value.contains(searchString)));
QStringRef stringToSearch = value.midRef(pos);
- return Encode(stringToSearch.contains(searchString));
+ scope.result = Encode(stringToSearch.contains(searchString));
}
-ReturnedValue StringPrototype::method_lastIndexOf(CallContext *context)
+void StringPrototype::method_lastIndexOf(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(context);
-
- const QString value = getThisString(context);
- if (scope.engine->hasException)
- return Encode::undefined();
+ const QString value = getThisString(scope, callData);
+ CHECK_EXCEPTION();
QString searchString;
- if (context->argc())
- searchString = context->args()[0].toQString();
+ if (callData->argc)
+ searchString = callData->args[0].toQString();
- ScopedValue posArg(scope, context->argument(1));
+ ScopedValue posArg(scope, callData->argument(1));
double position = RuntimeHelpers::toNumber(posArg);
if (std::isnan(position))
position = +qInf();
@@ -391,43 +378,40 @@ ReturnedValue StringPrototype::method_lastIndexOf(CallContext *context)
if (!searchString.isEmpty() && pos == value.length())
--pos;
if (searchString.isNull() && pos == 0)
- return Encode(-1);
+ RETURN_RESULT(Encode(-1));
int index = value.lastIndexOf(searchString, pos);
- return Encode(index);
+ scope.result = Encode(index);
}
-ReturnedValue StringPrototype::method_localeCompare(CallContext *context)
+void StringPrototype::method_localeCompare(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(context);
- const QString value = getThisString(context);
- if (scope.engine->hasException)
- return Encode::undefined();
+ const QString value = getThisString(scope, callData);
+ CHECK_EXCEPTION();
- ScopedValue v(scope, context->argument(0));
+ ScopedValue v(scope, callData->argument(0));
const QString that = v->toQString();
- return Encode(QString::localeAwareCompare(value, that));
+ scope.result = Encode(QString::localeAwareCompare(value, that));
}
-ReturnedValue StringPrototype::method_match(CallContext *context)
+void StringPrototype::method_match(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (context->thisObject().isUndefined() || context->thisObject().isNull())
- return context->engine()->throwTypeError();
+ if (callData->thisObject.isUndefined() || callData->thisObject.isNull())
+ THROW_TYPE_ERROR();
- Scope scope(context);
- ScopedString s(scope, context->thisObject().toString(scope.engine));
+ ScopedString s(scope, callData->thisObject.toString(scope.engine));
- ScopedValue regexp(scope, context->argument(0));
+ ScopedValue regexp(scope, callData->argument(0));
Scoped<RegExpObject> rx(scope, regexp);
if (!rx) {
ScopedCallData callData(scope, 1);
callData->args[0] = regexp;
- context->d()->engine->regExpCtor()->construct(scope, callData);
+ scope.engine->regExpCtor()->construct(scope, callData);
rx = scope.result.asReturnedValue();
}
if (!rx)
// ### CHECK
- return context->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
bool global = rx->global();
@@ -435,24 +419,24 @@ ReturnedValue StringPrototype::method_match(CallContext *context)
ScopedString execString(scope, scope.engine->newString(QStringLiteral("exec")));
ScopedFunctionObject exec(scope, scope.engine->regExpPrototype()->get(execString));
- ScopedCallData callData(scope, 1);
- callData->thisObject = rx;
- callData->args[0] = s;
+ ScopedCallData cData(scope, 1);
+ cData->thisObject = rx;
+ cData->args[0] = s;
if (!global) {
- exec->call(scope, callData);
- return scope.result.asReturnedValue();
+ exec->call(scope, cData);
+ return;
}
- ScopedString lastIndex(scope, context->d()->engine->newString(QStringLiteral("lastIndex")));
+ ScopedString lastIndex(scope, scope.engine->newString(QStringLiteral("lastIndex")));
rx->put(lastIndex, ScopedValue(scope, Primitive::fromInt32(0)));
- ScopedArrayObject a(scope, context->d()->engine->newArrayObject());
+ ScopedArrayObject a(scope, scope.engine->newArrayObject());
double previousLastIndex = 0;
uint n = 0;
ScopedValue matchStr(scope);
ScopedValue index(scope);
while (1) {
- exec->call(scope, callData);
+ exec->call(scope, cData);
if (scope.result.isNull())
break;
assert(scope.result.isObject());
@@ -469,10 +453,9 @@ ReturnedValue StringPrototype::method_match(CallContext *context)
++n;
}
if (!n)
- return Encode::null();
-
- return a.asReturnedValue();
-
+ scope.result = Encode::null();
+ else
+ scope.result = a;
}
static void appendReplacementString(QString *result, const QString &input, const QString& replaceValue, uint* matchOffsets, int captureCount)
@@ -521,14 +504,13 @@ static void appendReplacementString(QString *result, const QString &input, const
}
}
-ReturnedValue StringPrototype::method_replace(CallContext *ctx)
+void StringPrototype::method_replace(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
QString string;
- if (StringObject *thisString = ctx->thisObject().as<StringObject>())
+ if (StringObject *thisString = callData->thisObject.as<StringObject>())
string = thisString->d()->string->toQString();
else
- string = ctx->thisObject().toQString();
+ string = callData->thisObject.toQString();
int numCaptures = 0;
int numStringMatches = 0;
@@ -537,7 +519,7 @@ ReturnedValue StringPrototype::method_replace(CallContext *ctx)
uint _matchOffsets[64];
uint *matchOffsets = _matchOffsets;
- ScopedValue searchValue(scope, ctx->argument(0));
+ ScopedValue searchValue(scope, callData->argument(0));
Scoped<RegExpObject> regExp(scope, searchValue);
if (regExp) {
uint offset = 0;
@@ -580,7 +562,7 @@ ReturnedValue StringPrototype::method_replace(CallContext *ctx)
}
QString result;
- ScopedValue replaceValue(scope, ctx->argument(1));
+ ScopedValue replaceValue(scope, callData->argument(1));
ScopedFunctionObject searchCallback(scope, replaceValue);
if (!!searchCallback) {
result.reserve(string.length() + 10*numStringMatches);
@@ -595,14 +577,14 @@ ReturnedValue StringPrototype::method_replace(CallContext *ctx)
uint end = matchOffsets[idx + 1];
entry = Primitive::undefinedValue();
if (start != JSC::Yarr::offsetNoMatch && end != JSC::Yarr::offsetNoMatch)
- entry = ctx->d()->engine->newString(string.mid(start, end - start));
+ entry = scope.engine->newString(string.mid(start, end - start));
callData->args[k] = entry;
}
uint matchStart = matchOffsets[i * numCaptures * 2];
Q_ASSERT(matchStart >= static_cast<uint>(lastEnd));
uint matchEnd = matchOffsets[i * numCaptures * 2 + 1];
callData->args[numCaptures] = Primitive::fromUInt32(matchStart);
- callData->args[numCaptures + 1] = ctx->d()->engine->newString(string);
+ callData->args[numCaptures + 1] = scope.engine->newString(string);
searchCallback->call(scope, callData);
result += string.midRef(lastEnd, matchStart - lastEnd);
@@ -632,45 +614,44 @@ ReturnedValue StringPrototype::method_replace(CallContext *ctx)
if (matchOffsets != _matchOffsets)
free(matchOffsets);
- return ctx->d()->engine->newString(result)->asReturnedValue();
+ scope.result = scope.engine->newString(result);
}
-ReturnedValue StringPrototype::method_search(CallContext *ctx)
+void StringPrototype::method_search(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- QString string = getThisString(ctx);
- scope.result = ctx->argument(0);
- if (scope.engine->hasException)
- return Encode::undefined();
+ QString string = getThisString(scope, callData);
+ scope.result = callData->argument(0);
+ CHECK_EXCEPTION();
+
Scoped<RegExpObject> regExp(scope, scope.result.as<RegExpObject>());
if (!regExp) {
ScopedCallData callData(scope, 1);
callData->args[0] = scope.result;
- ctx->d()->engine->regExpCtor()->construct(scope, callData);
- if (scope.engine->hasException)
- return Encode::undefined();
+ scope.engine->regExpCtor()->construct(scope, callData);
+ CHECK_EXCEPTION();
+
regExp = scope.result.as<RegExpObject>();
Q_ASSERT(regExp);
}
Scoped<RegExp> re(scope, regExp->value());
- uint* matchOffsets = (uint*)alloca(regExp->value()->captureCount() * 2 * sizeof(uint));
+ Q_ALLOCA_VAR(uint, matchOffsets, regExp->value()->captureCount() * 2 * sizeof(uint));
uint result = re->match(string, /*offset*/0, matchOffsets);
if (result == JSC::Yarr::offsetNoMatch)
- return Encode(-1);
- return Encode(result);
+ scope.result = Encode(-1);
+ else
+ scope.result = Encode(result);
}
-ReturnedValue StringPrototype::method_slice(CallContext *ctx)
+void StringPrototype::method_slice(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- const QString text = getThisString(ctx);
- if (ctx->d()->engine->hasException)
- return Encode::undefined();
+ const QString text = getThisString(scope, callData);
+ CHECK_EXCEPTION();
const double length = text.length();
- double start = ctx->argc() ? ctx->args()[0].toInteger() : 0;
- double end = (ctx->argc() < 2 || ctx->args()[1].isUndefined())
- ? length : ctx->args()[1].toInteger();
+ double start = callData->argc ? callData->args[0].toInteger() : 0;
+ double end = (callData->argc < 2 || callData->args[1].isUndefined())
+ ? length : callData->args[1].toInteger();
if (start < 0)
start = qMax(length + start, 0.);
@@ -686,54 +667,52 @@ ReturnedValue StringPrototype::method_slice(CallContext *ctx)
const int intEnd = int(end);
int count = qMax(0, intEnd - intStart);
- return ctx->d()->engine->newString(text.mid(intStart, count))->asReturnedValue();
+ scope.result = scope.engine->newString(text.mid(intStart, count));
}
-ReturnedValue StringPrototype::method_split(CallContext *ctx)
+void StringPrototype::method_split(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- QString text = getThisString(ctx);
- if (scope.engine->hasException)
- return Encode::undefined();
+ QString text = getThisString(scope, callData);
+ CHECK_EXCEPTION();
- ScopedValue separatorValue(scope, ctx->argument(0));
- ScopedValue limitValue(scope, ctx->argument(1));
+ ScopedValue separatorValue(scope, callData->argument(0));
+ ScopedValue limitValue(scope, callData->argument(1));
- ScopedArrayObject array(scope, ctx->d()->engine->newArrayObject());
+ ScopedArrayObject array(scope, scope.engine->newArrayObject());
if (separatorValue->isUndefined()) {
if (limitValue->isUndefined()) {
- ScopedString s(scope, ctx->d()->engine->newString(text));
+ ScopedString s(scope, scope.engine->newString(text));
array->push_back(s);
- return array.asReturnedValue();
+ RETURN_RESULT(array);
}
- return ctx->d()->engine->newString(text.left(limitValue->toInteger()))->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(text.left(limitValue->toInteger())));
}
uint limit = limitValue->isUndefined() ? UINT_MAX : limitValue->toUInt32();
if (limit == 0)
- return array.asReturnedValue();
+ RETURN_RESULT(array);
Scoped<RegExpObject> re(scope, separatorValue);
if (re) {
if (re->value()->pattern->isEmpty()) {
re = (RegExpObject *)0;
- separatorValue = ctx->d()->engine->newString();
+ separatorValue = scope.engine->newString();
}
}
ScopedString s(scope);
if (re) {
uint offset = 0;
- uint* matchOffsets = (uint*)alloca(re->value()->captureCount() * 2 * sizeof(uint));
+ Q_ALLOCA_VAR(uint, matchOffsets, re->value()->captureCount() * 2 * sizeof(uint));
while (true) {
Scoped<RegExp> regexp(scope, re->value());
uint result = regexp->match(text, offset, matchOffsets);
if (result == JSC::Yarr::offsetNoMatch)
break;
- array->push_back((s = ctx->d()->engine->newString(text.mid(offset, matchOffsets[0] - offset))));
+ array->push_back((s = scope.engine->newString(text.mid(offset, matchOffsets[0] - offset))));
offset = qMax(offset + 1, matchOffsets[1]);
if (array->getLength() >= limit)
@@ -742,72 +721,70 @@ ReturnedValue StringPrototype::method_split(CallContext *ctx)
for (int i = 1; i < re->value()->captureCount(); ++i) {
uint start = matchOffsets[i * 2];
uint end = matchOffsets[i * 2 + 1];
- array->push_back((s = ctx->d()->engine->newString(text.mid(start, end - start))));
+ array->push_back((s = scope.engine->newString(text.mid(start, end - start))));
if (array->getLength() >= limit)
break;
}
}
if (array->getLength() < limit)
- array->push_back((s = ctx->d()->engine->newString(text.mid(offset))));
+ array->push_back((s = scope.engine->newString(text.mid(offset))));
} else {
QString separator = separatorValue->toQString();
if (separator.isEmpty()) {
for (uint i = 0; i < qMin(limit, uint(text.length())); ++i)
- array->push_back((s = ctx->d()->engine->newString(text.mid(i, 1))));
- return array.asReturnedValue();
+ array->push_back((s = scope.engine->newString(text.mid(i, 1))));
+ RETURN_RESULT(array);
}
int start = 0;
int end;
while ((end = text.indexOf(separator, start)) != -1) {
- array->push_back((s = ctx->d()->engine->newString(text.mid(start, end - start))));
+ array->push_back((s = scope.engine->newString(text.mid(start, end - start))));
start = end + separator.size();
if (array->getLength() >= limit)
break;
}
if (array->getLength() < limit && start != -1)
- array->push_back((s = ctx->d()->engine->newString(text.mid(start))));
+ array->push_back((s = scope.engine->newString(text.mid(start))));
}
- return array.asReturnedValue();
+ RETURN_RESULT(array);
}
-ReturnedValue StringPrototype::method_startsWith(CallContext *context)
+void StringPrototype::method_startsWith(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QString value = getThisString(context);
- if (context->d()->engine->hasException)
- return Encode::undefined();
+ QString value = getThisString(scope, callData);
+ CHECK_EXCEPTION();
QString searchString;
- if (context->argc()) {
- if (context->args()[0].as<RegExpObject>())
- return context->engine()->throwTypeError();
- searchString = context->args()[0].toQString();
+ if (callData->argc) {
+ if (callData->args[0].as<RegExpObject>())
+ THROW_TYPE_ERROR();
+ searchString = callData->args[0].toQString();
}
int pos = 0;
- if (context->argc() > 1)
- pos = (int) context->args()[1].toInteger();
+ if (callData->argc > 1)
+ pos = (int) callData->args[1].toInteger();
if (pos == 0)
- return Encode(value.startsWith(searchString));
+ RETURN_RESULT(Encode(value.startsWith(searchString)));
QStringRef stringToSearch = value.midRef(pos);
- return Encode(stringToSearch.startsWith(searchString));
+ RETURN_RESULT(Encode(stringToSearch.startsWith(searchString)));
}
-ReturnedValue StringPrototype::method_substr(CallContext *context)
+void StringPrototype::method_substr(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- const QString value = getThisString(context);
- if (context->d()->engine->hasException)
- return Encode::undefined();
+ const QString value = getThisString(scope, callData);
+ CHECK_EXCEPTION();
double start = 0;
- if (context->argc() > 0)
- start = context->args()[0].toInteger();
+ if (callData->argc > 0)
+ start = callData->args[0].toInteger();
double length = +qInf();
- if (context->argc() > 1)
- length = context->args()[1].toInteger();
+ if (callData->argc > 1)
+ length = callData->args[1].toInteger();
double count = value.length();
if (start < 0)
@@ -817,24 +794,23 @@ ReturnedValue StringPrototype::method_substr(CallContext *context)
qint32 x = Primitive::toInt32(start);
qint32 y = Primitive::toInt32(length);
- return context->d()->engine->newString(value.mid(x, y))->asReturnedValue();
+ scope.result = scope.engine->newString(value.mid(x, y));
}
-ReturnedValue StringPrototype::method_substring(CallContext *context)
+void StringPrototype::method_substring(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QString value = getThisString(context);
- if (context->d()->engine->hasException)
- return Encode::undefined();
+ QString value = getThisString(scope, callData);
+ CHECK_EXCEPTION();
+
int length = value.length();
double start = 0;
double end = length;
- if (context->argc() > 0)
- start = context->args()[0].toInteger();
+ if (callData->argc > 0)
+ start = callData->args[0].toInteger();
- Scope scope(context);
- ScopedValue endValue(scope, context->argument(1));
+ ScopedValue endValue(scope, callData->argument(1));
if (!endValue->isUndefined())
end = endValue->toInteger();
@@ -858,51 +834,50 @@ ReturnedValue StringPrototype::method_substring(CallContext *context)
qint32 x = (int)start;
qint32 y = (int)(end - start);
- return context->d()->engine->newString(value.mid(x, y))->asReturnedValue();
+ scope.result = scope.engine->newString(value.mid(x, y));
}
-ReturnedValue StringPrototype::method_toLowerCase(CallContext *ctx)
+void StringPrototype::method_toLowerCase(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QString value = getThisString(ctx);
- if (ctx->d()->engine->hasException)
- return Encode::undefined();
- return ctx->d()->engine->newString(value.toLower())->asReturnedValue();
+ QString value = getThisString(scope, callData);
+ CHECK_EXCEPTION();
+
+ scope.result = scope.engine->newString(value.toLower());
}
-ReturnedValue StringPrototype::method_toLocaleLowerCase(CallContext *ctx)
+void StringPrototype::method_toLocaleLowerCase(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- return method_toLowerCase(ctx);
+ method_toLowerCase(b, scope, callData);
}
-ReturnedValue StringPrototype::method_toUpperCase(CallContext *ctx)
+void StringPrototype::method_toUpperCase(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QString value = getThisString(ctx);
- if (ctx->d()->engine->hasException)
- return Encode::undefined();
- return ctx->d()->engine->newString(value.toUpper())->asReturnedValue();
+ QString value = getThisString(scope, callData);
+ CHECK_EXCEPTION();
+
+ scope.result = scope.engine->newString(value.toUpper());
}
-ReturnedValue StringPrototype::method_toLocaleUpperCase(CallContext *ctx)
+void StringPrototype::method_toLocaleUpperCase(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- return method_toUpperCase(ctx);
+ return method_toUpperCase(b, scope, callData);
}
-ReturnedValue StringPrototype::method_fromCharCode(CallContext *context)
+void StringPrototype::method_fromCharCode(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QString str(context->argc(), Qt::Uninitialized);
+ QString str(callData->argc, Qt::Uninitialized);
QChar *ch = str.data();
- for (int i = 0; i < context->argc(); ++i) {
- *ch = QChar(context->args()[i].toUInt16());
+ for (int i = 0; i < callData->argc; ++i) {
+ *ch = QChar(callData->args[i].toUInt16());
++ch;
}
- return context->d()->engine->newString(str)->asReturnedValue();
+ scope.result = scope.engine->newString(str);
}
-ReturnedValue StringPrototype::method_trim(CallContext *ctx)
+void StringPrototype::method_trim(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QString s = getThisString(ctx);
- if (ctx->d()->engine->hasException)
- return Encode::undefined();
+ QString s = getThisString(scope, callData);
+ CHECK_EXCEPTION();
const QChar *chars = s.constData();
int start, end;
@@ -915,5 +890,5 @@ ReturnedValue StringPrototype::method_trim(CallContext *ctx)
break;
}
- return ctx->d()->engine->newString(QString(chars + start, end - start + 1))->asReturnedValue();
+ scope.result = scope.engine->newString(QString(chars + start, end - start + 1));
}
diff --git a/src/qml/jsruntime/qv4stringobject_p.h b/src/qml/jsruntime/qv4stringobject_p.h
index b9f9d44fe8..0ee7a6ece9 100644
--- a/src/qml/jsruntime/qv4stringobject_p.h
+++ b/src/qml/jsruntime/qv4stringobject_p.h
@@ -111,29 +111,29 @@ struct StringPrototype: StringObject
{
void init(ExecutionEngine *engine, Object *ctor);
- static ReturnedValue method_toString(CallContext *context);
- static ReturnedValue method_charAt(CallContext *context);
- static ReturnedValue method_charCodeAt(CallContext *context);
- static ReturnedValue method_concat(CallContext *context);
- static ReturnedValue method_endsWith(CallContext *ctx);
- static ReturnedValue method_indexOf(CallContext *context);
- static ReturnedValue method_includes(CallContext *context);
- static ReturnedValue method_lastIndexOf(CallContext *context);
- static ReturnedValue method_localeCompare(CallContext *context);
- static ReturnedValue method_match(CallContext *context);
- static ReturnedValue method_replace(CallContext *ctx);
- static ReturnedValue method_search(CallContext *ctx);
- static ReturnedValue method_slice(CallContext *ctx);
- static ReturnedValue method_split(CallContext *ctx);
- static ReturnedValue method_startsWith(CallContext *ctx);
- static ReturnedValue method_substr(CallContext *context);
- static ReturnedValue method_substring(CallContext *context);
- static ReturnedValue method_toLowerCase(CallContext *ctx);
- static ReturnedValue method_toLocaleLowerCase(CallContext *ctx);
- static ReturnedValue method_toUpperCase(CallContext *ctx);
- static ReturnedValue method_toLocaleUpperCase(CallContext *ctx);
- static ReturnedValue method_fromCharCode(CallContext *context);
- static ReturnedValue method_trim(CallContext *ctx);
+ static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_charAt(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_charCodeAt(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_concat(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_endsWith(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_indexOf(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_includes(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_lastIndexOf(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_localeCompare(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_match(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_replace(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_search(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_slice(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_split(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_startsWith(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_substr(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_substring(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toLowerCase(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toLocaleLowerCase(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toUpperCase(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toLocaleUpperCase(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_fromCharCode(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_trim(const BuiltinFunction *, Scope &scope, CallData *callData);
};
}
diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp
index 009c573bf8..cecd1e6958 100644
--- a/src/qml/jsruntime/qv4typedarray.cpp
+++ b/src/qml/jsruntime/qv4typedarray.cpp
@@ -438,79 +438,74 @@ void TypedArrayPrototype::init(ExecutionEngine *engine, TypedArrayCtor *ctor)
defineDefaultProperty(QStringLiteral("subarray"), method_subarray, 0);
}
-ReturnedValue TypedArrayPrototype::method_get_buffer(CallContext *ctx)
+void TypedArrayPrototype::method_get_buffer(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<TypedArray> v(scope, ctx->thisObject());
+ Scoped<TypedArray> v(scope, callData->thisObject);
if (!v)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
- return Encode(v->d()->buffer->asReturnedValue());
+ scope.result = v->d()->buffer;
}
-ReturnedValue TypedArrayPrototype::method_get_byteLength(CallContext *ctx)
+void TypedArrayPrototype::method_get_byteLength(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<TypedArray> v(scope, ctx->thisObject());
+ Scoped<TypedArray> v(scope, callData->thisObject);
if (!v)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
- return Encode(v->d()->byteLength);
+ scope.result = Encode(v->d()->byteLength);
}
-ReturnedValue TypedArrayPrototype::method_get_byteOffset(CallContext *ctx)
+void TypedArrayPrototype::method_get_byteOffset(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<TypedArray> v(scope, ctx->thisObject());
+ Scoped<TypedArray> v(scope, callData->thisObject);
if (!v)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
- return Encode(v->d()->byteOffset);
+ scope.result = Encode(v->d()->byteOffset);
}
-ReturnedValue TypedArrayPrototype::method_get_length(CallContext *ctx)
+void TypedArrayPrototype::method_get_length(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<TypedArray> v(scope, ctx->thisObject());
+ Scoped<TypedArray> v(scope, callData->thisObject);
if (!v)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
- return Encode(v->d()->byteLength/v->d()->type->bytesPerElement);
+ scope.result = Encode(v->d()->byteLength/v->d()->type->bytesPerElement);
}
-ReturnedValue TypedArrayPrototype::method_set(CallContext *ctx)
+void TypedArrayPrototype::method_set(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<TypedArray> a(scope, ctx->thisObject());
+ Scoped<TypedArray> a(scope, callData->thisObject);
if (!a)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
Scoped<ArrayBuffer> buffer(scope, a->d()->buffer);
if (!buffer)
scope.engine->throwTypeError();
- double doffset = ctx->argc() >= 2 ? ctx->args()[1].toInteger() : 0;
+ double doffset = callData->argc >= 2 ? callData->args[1].toInteger() : 0;
if (scope.engine->hasException)
- return Encode::undefined();
+ RETURN_UNDEFINED();
if (doffset < 0 || doffset >= UINT_MAX)
- return scope.engine->throwRangeError(QStringLiteral("TypedArray.set: out of range"));
+ RETURN_RESULT(scope.engine->throwRangeError(QStringLiteral("TypedArray.set: out of range")));
uint offset = (uint)doffset;
uint elementSize = a->d()->type->bytesPerElement;
- Scoped<TypedArray> srcTypedArray(scope, ctx->args()[0]);
+ Scoped<TypedArray> srcTypedArray(scope, callData->args[0]);
if (!srcTypedArray) {
// src is a regular object
- ScopedObject o(scope, ctx->args()[0].toObject(scope.engine));
+ ScopedObject o(scope, callData->args[0].toObject(scope.engine));
if (scope.engine->hasException || !o)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
double len = ScopedValue(scope, o->get(scope.engine->id_length()))->toNumber();
uint l = (uint)len;
if (scope.engine->hasException || l != len)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
if (offset + l > a->length())
- return scope.engine->throwRangeError(QStringLiteral("TypedArray.set: out of range"));
+ RETURN_RESULT(scope.engine->throwRangeError(QStringLiteral("TypedArray.set: out of range")));
uint idx = 0;
char *b = buffer->d()->data->data() + a->d()->byteOffset + offset*elementSize;
@@ -519,28 +514,28 @@ ReturnedValue TypedArrayPrototype::method_set(CallContext *ctx)
val = o->getIndexed(idx);
a->d()->type->write(scope.engine, b, 0, val);
if (scope.engine->hasException)
- return Encode::undefined();
+ RETURN_UNDEFINED();
++idx;
b += elementSize;
}
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
// src is a typed array
Scoped<ArrayBuffer> srcBuffer(scope, srcTypedArray->d()->buffer);
if (!srcBuffer)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
uint l = srcTypedArray->length();
if (offset + l > a->length())
- return scope.engine->throwRangeError(QStringLiteral("TypedArray.set: out of range"));
+ RETURN_RESULT(scope.engine->throwRangeError(QStringLiteral("TypedArray.set: out of range")));
char *dest = buffer->d()->data->data() + a->d()->byteOffset + offset*elementSize;
const char *src = srcBuffer->d()->data->data() + srcTypedArray->d()->byteOffset;
if (srcTypedArray->d()->type == a->d()->type) {
// same type of typed arrays, use memmove (as srcbuffer and buffer could be the same)
memmove(dest, src, srcTypedArray->d()->byteLength);
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
char *srcCopy = 0;
@@ -564,28 +559,27 @@ ReturnedValue TypedArrayPrototype::method_set(CallContext *ctx)
if (srcCopy)
delete [] srcCopy;
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
-ReturnedValue TypedArrayPrototype::method_subarray(CallContext *ctx)
+void TypedArrayPrototype::method_subarray(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<TypedArray> a(scope, ctx->thisObject());
+ Scoped<TypedArray> a(scope, callData->thisObject);
if (!a)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
Scoped<ArrayBuffer> buffer(scope, a->d()->buffer);
if (!buffer)
- return scope.engine->throwTypeError();
+ THROW_TYPE_ERROR();
int len = a->length();
- double b = ctx->argc() > 0 ? ctx->args()[0].toInteger() : 0;
+ double b = callData->argc > 0 ? callData->args[0].toInteger() : 0;
if (b < 0)
b = len + b;
uint begin = (uint)qBound(0., b, (double)len);
- double e = ctx->argc() < 2 || ctx->args()[1].isUndefined() ? len : ctx->args()[1].toInteger();
+ double e = callData->argc < 2 || callData->args[1].isUndefined() ? len : callData->args[1].toInteger();
if (e < 0)
e = len + e;
uint end = (uint)qBound(0., e, (double)len);
@@ -593,18 +587,17 @@ ReturnedValue TypedArrayPrototype::method_subarray(CallContext *ctx)
end = begin;
if (scope.engine->hasException)
- return Encode::undefined();
+ RETURN_UNDEFINED();
int newLen = end - begin;
ScopedFunctionObject constructor(scope, a->get(scope.engine->id_constructor()));
if (!constructor)
- return scope.engine->throwTypeError();
-
- ScopedCallData callData(scope, 3);
- callData->args[0] = buffer;
- callData->args[1] = Encode(a->d()->byteOffset + begin*a->d()->type->bytesPerElement);
- callData->args[2] = Encode(newLen);
- constructor->construct(scope, callData);
- return scope.result.asReturnedValue();
+ THROW_TYPE_ERROR();
+
+ ScopedCallData cData(scope, 3);
+ cData->args[0] = buffer;
+ cData->args[1] = Encode(a->d()->byteOffset + begin*a->d()->type->bytesPerElement);
+ cData->args[2] = Encode(newLen);
+ constructor->construct(scope, cData);
}
diff --git a/src/qml/jsruntime/qv4typedarray_p.h b/src/qml/jsruntime/qv4typedarray_p.h
index 0112d2e4a1..eefed2db4b 100644
--- a/src/qml/jsruntime/qv4typedarray_p.h
+++ b/src/qml/jsruntime/qv4typedarray_p.h
@@ -151,13 +151,13 @@ struct TypedArrayPrototype : Object
void init(ExecutionEngine *engine, TypedArrayCtor *ctor);
- static ReturnedValue method_get_buffer(CallContext *ctx);
- static ReturnedValue method_get_byteLength(CallContext *ctx);
- static ReturnedValue method_get_byteOffset(CallContext *ctx);
- static ReturnedValue method_get_length(CallContext *ctx);
+ static void method_get_buffer(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_byteLength(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_byteOffset(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_length(const BuiltinFunction *, Scope &scope, CallData *callData);
- static ReturnedValue method_set(CallContext *ctx);
- static ReturnedValue method_subarray(CallContext *ctx);
+ static void method_set(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_subarray(const BuiltinFunction *, Scope &scope, CallData *callData);
};
inline void
diff --git a/src/qml/jsruntime/qv4util_p.h b/src/qml/jsruntime/qv4util_p.h
index 59c12c5e46..2669a3e4bf 100644
--- a/src/qml/jsruntime/qv4util_p.h
+++ b/src/qml/jsruntime/qv4util_p.h
@@ -90,6 +90,9 @@ public:
: bits(size, value)
{}
+ void clear()
+ { bits = std::vector<bool>(bits.size(), false); }
+
void reserve(int size)
{ bits.reserve(size); }
@@ -153,6 +156,9 @@ public:
: bits(size, value)
{}
+ void clear()
+ { bits = QBitArray(bits.size(), false); }
+
void reserve(int size)
{ Q_UNUSED(size); }
diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h
index 816b8fb11b..4ff0565f9b 100644
--- a/src/qml/jsruntime/qv4value_p.h
+++ b/src/qml/jsruntime/qv4value_p.h
@@ -254,34 +254,47 @@ public:
Q_ASSERT(isDouble()); return Double_Type;
}
-#ifndef QV4_USE_64_BIT_VALUE_ENCODING
+ // Shared between 32-bit and 64-bit encoding
+ enum {
+ Tag_Shift = 32
+ };
+
+ // Used only by 64-bit encoding
+ static const quint64 NaNEncodeMask = 0xfffc000000000000ll;
+ enum {
+ IsDouble_Shift = 64-14,
+ IsManagedOrUndefined_Shift = 64-15,
+ IsIntegerConvertible_Shift = 64-16,
+ IsDoubleTag_Shift = IsDouble_Shift - Tag_Shift,
+ Managed_Type_Internal_64 = 0
+ };
+ static const quint64 Immediate_Mask_64 = 0x00020000u; // bit 49
+
+ // Used only by 32-bit encoding
enum Masks {
SilentNaNBit = 0x00040000,
- NaN_Mask = 0x7ff80000,
NotDouble_Mask = 0x7ffa0000,
- Immediate_Mask = NotDouble_Mask | 0x00020000u | SilentNaNBit,
- Tag_Shift = 32
};
+ static const quint64 Immediate_Mask_32 = NotDouble_Mask | 0x00020000u | SilentNaNBit;
enum {
- Managed_Type_Internal = NotDouble_Mask
+ Managed_Type_Internal_32 = NotDouble_Mask
};
-#else
- static const quint64 NaNEncodeMask = 0xfffc000000000000ll;
- static const quint64 Immediate_Mask = 0x00020000u; // bit 49
- enum Masks {
- NaN_Mask = 0x7ff80000,
+#ifdef QV4_USE_64_BIT_VALUE_ENCODING
+ enum {
+ Managed_Type_Internal = Managed_Type_Internal_64
};
+ static const quint64 Immediate_Mask = Immediate_Mask_64;
+#else
enum {
- IsDouble_Shift = 64-14,
- IsManagedOrUndefined_Shift = 64-15,
- IsIntegerConvertible_Shift = 64-16,
- Tag_Shift = 32,
- IsDoubleTag_Shift = IsDouble_Shift - Tag_Shift,
- Managed_Type_Internal = 0
+ Managed_Type_Internal = Managed_Type_Internal_32
};
+ static const quint64 Immediate_Mask = Immediate_Mask_32;
#endif
+ enum {
+ NaN_Mask = 0x7ff80000,
+ };
enum ValueTypeInternal {
Empty_Type_Internal = Immediate_Mask | 0,
ConvertibleToInt = Immediate_Mask | 0x10000u, // bit 48
@@ -544,7 +557,7 @@ inline bool Value::asArrayIndex(uint &idx) const
}
double d = doubleValue();
idx = (uint)d;
- return (idx == d);
+ return (idx == d && idx != UINT_MAX);
}
#endif
diff --git a/src/qml/jsruntime/qv4variantobject.cpp b/src/qml/jsruntime/qv4variantobject.cpp
index b26dd27913..5cab4c5386 100644
--- a/src/qml/jsruntime/qv4variantobject.cpp
+++ b/src/qml/jsruntime/qv4variantobject.cpp
@@ -113,64 +113,68 @@ void VariantPrototype::init()
defineDefaultProperty(engine()->id_toString(), method_toString, 0);
}
-QV4::ReturnedValue VariantPrototype::method_preserve(CallContext *ctx)
+void VariantPrototype::method_preserve(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<VariantObject> o(scope, ctx->thisObject().as<QV4::VariantObject>());
+ Scoped<VariantObject> o(scope, callData->thisObject.as<QV4::VariantObject>());
if (o && o->d()->isScarce())
o->d()->addVmePropertyReference();
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
-QV4::ReturnedValue VariantPrototype::method_destroy(CallContext *ctx)
+void VariantPrototype::method_destroy(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<VariantObject> o(scope, ctx->thisObject().as<QV4::VariantObject>());
+ Scoped<VariantObject> o(scope, callData->thisObject.as<QV4::VariantObject>());
if (o) {
if (o->d()->isScarce())
o->d()->addVmePropertyReference();
o->d()->data() = QVariant();
}
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
-QV4::ReturnedValue VariantPrototype::method_toString(CallContext *ctx)
+void VariantPrototype::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<VariantObject> o(scope, ctx->thisObject().as<QV4::VariantObject>());
+ Scoped<VariantObject> o(scope, callData->thisObject.as<QV4::VariantObject>());
if (!o)
- return Encode::undefined();
+ RETURN_UNDEFINED();
QString result = o->d()->data().toString();
- if (result.isEmpty() && !o->d()->data().canConvert(QVariant::String))
- result = QStringLiteral("QVariant(%0)").arg(QString::fromLatin1(o->d()->data().typeName()));
- return Encode(ctx->d()->engine->newString(result));
+ if (result.isEmpty() && !o->d()->data().canConvert(QVariant::String)) {
+ result = QLatin1String("QVariant(")
+ + QLatin1String(o->d()->data().typeName())
+ + QLatin1Char(')');
+ }
+ scope.result = scope.engine->newString(result);
}
-QV4::ReturnedValue VariantPrototype::method_valueOf(CallContext *ctx)
+void VariantPrototype::method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- Scoped<VariantObject> o(scope, ctx->thisObject().as<QV4::VariantObject>());
+ Scoped<VariantObject> o(scope, callData->thisObject.as<QV4::VariantObject>());
if (o) {
QVariant v = o->d()->data();
switch (v.type()) {
case QVariant::Invalid:
- return Encode::undefined();
+ scope.result = Encode::undefined();
+ return;
case QVariant::String:
- return Encode(ctx->d()->engine->newString(v.toString()));
+ scope.result = scope.engine->newString(v.toString());
+ return;
case QVariant::Int:
- return Encode(v.toInt());
+ scope.result = Encode(v.toInt());
+ return;
case QVariant::Double:
case QVariant::UInt:
- return Encode(v.toDouble());
+ scope.result = Encode(v.toDouble());
+ return;
case QVariant::Bool:
- return Encode(v.toBool());
+ scope.result = Encode(v.toBool());
+ return;
default:
if (QMetaType::typeFlags(v.userType()) & QMetaType::IsEnumeration)
- return Encode(v.toInt());
+ RETURN_RESULT(Encode(v.toInt()));
break;
}
}
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
}
QT_END_NAMESPACE
diff --git a/src/qml/jsruntime/qv4variantobject_p.h b/src/qml/jsruntime/qv4variantobject_p.h
index 9a04069c12..ef51b6632d 100644
--- a/src/qml/jsruntime/qv4variantobject_p.h
+++ b/src/qml/jsruntime/qv4variantobject_p.h
@@ -107,10 +107,10 @@ struct VariantPrototype : VariantObject
public:
void init();
- static ReturnedValue method_preserve(CallContext *ctx);
- static ReturnedValue method_destroy(CallContext *ctx);
- static ReturnedValue method_toString(CallContext *ctx);
- static ReturnedValue method_valueOf(CallContext *ctx);
+ static void method_preserve(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_destroy(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_valueOf(const BuiltinFunction *, Scope &scope, CallData *callData);
};
}
diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp
index 622359a7d9..be2772c23f 100644
--- a/src/qml/jsruntime/qv4vme_moth.cpp
+++ b/src/qml/jsruntime/qv4vme_moth.cpp
@@ -347,6 +347,10 @@ Param traceParam(const Param &param)
goto catchException; \
VALUE(param) = tmp; \
}
+// qv4scopedvalue_p.h also defines a CHECK_EXCEPTION macro
+#ifdef CHECK_EXCEPTION
+#undef CHECK_EXCEPTION
+#endif
#define CHECK_EXCEPTION \
if (engine->hasException) \
goto catchException
@@ -398,7 +402,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code
}
}
- QV4::Value **scopes = static_cast<QV4::Value **>(alloca(sizeof(QV4::Value *)*(2 + 2*scopeDepth)));
+ Q_ALLOCA_VAR(QV4::Value*, scopes, sizeof(QV4::Value *)*(2 + 2*scopeDepth));
{
scopes[0] = const_cast<QV4::Value *>(context->d()->compilationUnit->constants);
// stack gets setup in push instruction
@@ -953,8 +957,6 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code
return QV4::Encode::undefined();
code = exceptionHandler;
}
-
-
}
#ifdef MOTH_THREADED_INTERPRETER
diff --git a/src/qml/memory/memory.pri b/src/qml/memory/memory.pri
index 04b7566ccc..38fadbf23f 100644
--- a/src/qml/memory/memory.pri
+++ b/src/qml/memory/memory.pri
@@ -6,8 +6,8 @@ SOURCES += \
$$PWD/qv4mm.cpp \
HEADERS += \
- $$PWD/qv4mm_p.h
-
+ $$PWD/qv4mm_p.h \
+ $$PWD/qv4mmdefs_p.h
}
HEADERS += \
diff --git a/src/qml/memory/qv4heap_p.h b/src/qml/memory/qv4heap_p.h
index 5a3797f397..8285ef4de7 100644
--- a/src/qml/memory/qv4heap_p.h
+++ b/src/qml/memory/qv4heap_p.h
@@ -52,6 +52,7 @@
#include <QtCore/QString>
#include <private/qv4global_p.h>
+#include <private/qv4mmdefs_p.h>
#include <QSharedPointer>
// To check if Heap::Base::init is called (meaning, all subclasses did their init and called their
@@ -90,43 +91,31 @@ namespace Heap {
struct Q_QML_EXPORT Base {
void *operator new(size_t) = delete;
- quintptr mm_data; // vtable and markbit
+ const VTable *vt;
inline ReturnedValue asReturnedValue() const;
inline void mark(QV4::ExecutionEngine *engine);
- enum {
- MarkBit = 0x1,
- NotInUse = 0x2,
- PointerMask = ~0x3
- };
-
- void setVtable(const VTable *v) {
- Q_ASSERT(!(mm_data & MarkBit));
- mm_data = reinterpret_cast<quintptr>(v);
- }
- VTable *vtable() const {
- return reinterpret_cast<VTable *>(mm_data & PointerMask);
- }
+ void setVtable(const VTable *v) { vt = v; }
+ const VTable *vtable() const { return vt; }
inline bool isMarked() const {
- return mm_data & MarkBit;
+ const HeapItem *h = reinterpret_cast<const HeapItem *>(this);
+ Chunk *c = h->chunk();
+ Q_ASSERT(!Chunk::testBit(c->extendsBitmap, h - c->realBase()));
+ return Chunk::testBit(c->blackBitmap, h - c->realBase());
}
inline void setMarkBit() {
- mm_data |= MarkBit;
- }
- inline void clearMarkBit() {
- mm_data &= ~MarkBit;
+ const HeapItem *h = reinterpret_cast<const HeapItem *>(this);
+ Chunk *c = h->chunk();
+ Q_ASSERT(!Chunk::testBit(c->extendsBitmap, h - c->realBase()));
+ return Chunk::setBit(c->blackBitmap, h - c->realBase());
}
inline bool inUse() const {
- return !(mm_data & NotInUse);
- }
-
- Base *nextFree() {
- return reinterpret_cast<Base *>(mm_data & PointerMask);
- }
- void setNextFree(Base *m) {
- mm_data = (reinterpret_cast<quintptr>(m) | NotInUse);
+ const HeapItem *h = reinterpret_cast<const HeapItem *>(this);
+ Chunk *c = h->chunk();
+ Q_ASSERT(!Chunk::testBit(c->extendsBitmap, h - c->realBase()));
+ return Chunk::testBit(c->objectBitmap, h - c->realBase());
}
void *operator new(size_t, Managed *m) { return m; }
diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp
index 8732b02685..a829e902fb 100644
--- a/src/qml/memory/qv4mm.cpp
+++ b/src/qml/memory/qv4mm.cpp
@@ -42,8 +42,12 @@
#include "qv4objectproto_p.h"
#include "qv4mm_p.h"
#include "qv4qobjectwrapper_p.h"
+#include <QtCore/qalgorithms.h>
+#include <QtCore/private/qnumeric_p.h>
#include <qqmlengine.h>
+#include "PageReservation.h"
#include "PageAllocation.h"
+#include "PageAllocationAligned.h"
#include "StdLibExtras.h"
#include <QElapsedTimer>
@@ -56,6 +60,14 @@
#include "qv4alloca_p.h"
#include "qv4profiling_p.h"
+#define MM_DEBUG 0
+
+#if MM_DEBUG
+#define DEBUG qDebug() << "MM:"
+#else
+#define DEBUG if (1) ; else qDebug() << "MM:"
+#endif
+
#ifdef V4_USE_VALGRIND
#include <valgrind/valgrind.h>
#include <valgrind/memcheck.h>
@@ -79,319 +91,653 @@ using namespace WTF;
QT_BEGIN_NAMESPACE
-static uint maxShiftValue()
-{
- static uint result = 0;
- if (!result) {
- result = 6;
- if (Q_UNLIKELY(qEnvironmentVariableIsSet(QV4_MM_MAXBLOCK_SHIFT))) {
- bool ok;
- const uint overrideValue = qgetenv(QV4_MM_MAXBLOCK_SHIFT).toUInt(&ok);
- if (ok && overrideValue <= 11 && overrideValue > 0)
- result = overrideValue;
+namespace QV4 {
+
+enum {
+ MinSlotsGCLimit = QV4::Chunk::AvailableSlots*16,
+ GCOverallocation = 200 /* Max overallocation by the GC in % */
+};
+
+struct MemorySegment {
+ enum {
+ NumChunks = 8*sizeof(quint64),
+ SegmentSize = NumChunks*Chunk::ChunkSize,
+ };
+
+ MemorySegment(size_t size)
+ {
+ size += Chunk::ChunkSize; // make sure we can get enough 64k aligment memory
+ if (size < SegmentSize)
+ size = SegmentSize;
+
+ pageReservation = PageReservation::reserve(size, OSAllocator::JSGCHeapPages);
+ base = reinterpret_cast<Chunk *>((reinterpret_cast<quintptr>(pageReservation.base()) + Chunk::ChunkSize - 1) & ~(Chunk::ChunkSize - 1));
+ nChunks = NumChunks;
+ if (base != pageReservation.base())
+ --nChunks;
+ }
+ MemorySegment(MemorySegment &&other) {
+ qSwap(pageReservation, other.pageReservation);
+ qSwap(base, other.base);
+ qSwap(nChunks, other.nChunks);
+ qSwap(allocatedMap, other.allocatedMap);
+ }
+
+ ~MemorySegment() {
+ if (base)
+ pageReservation.deallocate();
+ }
+
+ void setBit(size_t index) {
+ Q_ASSERT(index < nChunks);
+ quint64 bit = static_cast<quint64>(1) << index;
+// qDebug() << " setBit" << hex << index << (index & (Bits - 1)) << bit;
+ allocatedMap |= bit;
+ }
+ void clearBit(size_t index) {
+ Q_ASSERT(index < nChunks);
+ quint64 bit = static_cast<quint64>(1) << index;
+// qDebug() << " setBit" << hex << index << (index & (Bits - 1)) << bit;
+ allocatedMap &= ~bit;
+ }
+ bool testBit(size_t index) const {
+ Q_ASSERT(index < nChunks);
+ quint64 bit = static_cast<quint64>(1) << index;
+ return (allocatedMap & bit);
+ }
+
+ Chunk *allocate(size_t size);
+ void free(Chunk *chunk, size_t size) {
+ DEBUG << "freeing chunk" << chunk;
+ size_t index = static_cast<size_t>(chunk - base);
+ size_t end = index + (size - 1)/Chunk::ChunkSize + 1;
+ while (index < end) {
+ Q_ASSERT(testBit(index));
+ clearBit(index);
+ ++index;
}
+
+ size_t pageSize = WTF::pageSize();
+ size = (size + pageSize - 1) & ~(pageSize - 1);
+ pageReservation.decommit(chunk, size);
+ }
+
+ bool contains(Chunk *c) const {
+ return c >= base && c < base + nChunks;
}
- return result;
-}
-static std::size_t maxChunkSizeValue()
+ PageReservation pageReservation;
+ Chunk *base = 0;
+ quint64 allocatedMap = 0;
+ uint nChunks = 0;
+};
+
+Chunk *MemorySegment::allocate(size_t size)
{
- static std::size_t result = 0;
- if (!result) {
- result = 32 * 1024;
- if (Q_UNLIKELY(qEnvironmentVariableIsSet(QV4_MM_MAX_CHUNK_SIZE))) {
- bool ok;
- const std::size_t overrideValue = qgetenv(QV4_MM_MAX_CHUNK_SIZE).toUInt(&ok);
- if (ok)
- result = overrideValue;
+ size_t requiredChunks = (size + sizeof(Chunk) - 1)/sizeof(Chunk);
+ uint sequence = 0;
+ Chunk *candidate = 0;
+ for (uint i = 0; i < nChunks; ++i) {
+ if (!testBit(i)) {
+ if (!candidate)
+ candidate = base + i;
+ ++sequence;
+ } else {
+ candidate = 0;
+ sequence = 0;
+ }
+ if (sequence == requiredChunks) {
+ pageReservation.commit(candidate, size);
+ for (uint i = 0; i < requiredChunks; ++i)
+ setBit(candidate - base + i);
+ DEBUG << "allocated chunk " << candidate << hex << size;
+ return candidate;
}
}
- return result;
+ return 0;
}
-using namespace QV4;
-
-struct MemoryManager::Data
-{
- const size_t pageSize;
-
- struct ChunkHeader {
- Heap::Base freeItems;
- ChunkHeader *nextNonFull;
- char *itemStart;
- char *itemEnd;
- unsigned itemSize;
- };
+struct ChunkAllocator {
+ ChunkAllocator() {}
- ExecutionEngine *engine;
+ size_t requiredChunkSize(size_t size) {
+ size += Chunk::HeaderSize; // space required for the Chunk header
+ size_t pageSize = WTF::pageSize();
+ size = (size + pageSize - 1) & ~(pageSize - 1); // align to page sizes
+ if (size < Chunk::ChunkSize)
+ size = Chunk::ChunkSize;
+ return size;
+ }
- std::size_t maxChunkSize;
- std::vector<PageAllocation> heapChunks;
- std::size_t unmanagedHeapSize; // the amount of bytes of heap that is not managed by the memory manager, but which is held onto by managed items.
- std::size_t unmanagedHeapSizeGCLimit;
+ Chunk *allocate(size_t size = 0);
+ void free(Chunk *chunk, size_t size = 0);
- struct LargeItem {
- LargeItem *next;
- size_t size;
- void *data;
+ std::vector<MemorySegment> memorySegments;
+};
- Heap::Base *heapObject() {
- return reinterpret_cast<Heap::Base *>(&data);
+Chunk *ChunkAllocator::allocate(size_t size)
+{
+ size = requiredChunkSize(size);
+ for (auto &m : memorySegments) {
+ if (~m.allocatedMap) {
+ Chunk *c = m.allocate(size);
+ if (c)
+ return c;
}
- };
+ }
- LargeItem *largeItems;
- std::size_t totalLargeItemsAllocated;
+ // allocate a new segment
+ memorySegments.push_back(MemorySegment(size));
+ Chunk *c = memorySegments.back().allocate(size);
+ Q_ASSERT(c);
+ return c;
+}
- enum { MaxItemSize = 512 };
- ChunkHeader *nonFullChunks[MaxItemSize/16];
- uint nChunks[MaxItemSize/16];
- uint availableItems[MaxItemSize/16];
- uint allocCount[MaxItemSize/16];
- int totalItems;
- int totalAlloc;
- uint maxShift;
+void ChunkAllocator::free(Chunk *chunk, size_t size)
+{
+ size = requiredChunkSize(size);
+ for (auto &m : memorySegments) {
+ if (m.contains(chunk)) {
+ m.free(chunk, size);
+ return;
+ }
+ }
+ Q_ASSERT(false);
+}
- bool gcBlocked;
- bool aggressiveGC;
- bool gcStats;
- bool unused; // suppress padding warning
- // statistics:
-#ifdef DETAILED_MM_STATS
- QVector<unsigned> allocSizeCounters;
-#endif // DETAILED_MM_STATS
+void Chunk::sweep()
+{
+ // DEBUG << "sweeping chunk" << this << (*freeList);
+ HeapItem *o = realBase();
+ for (uint i = 0; i < Chunk::EntriesInBitmap; ++i) {
+ Q_ASSERT((grayBitmap[i] | blackBitmap[i]) == blackBitmap[i]); // check that we don't have gray only objects
+ quintptr toFree = objectBitmap[i] ^ blackBitmap[i];
+ Q_ASSERT((toFree & objectBitmap[i]) == toFree); // check all black objects are marked as being used
+ quintptr e = extendsBitmap[i];
+ // DEBUG << hex << " index=" << i << toFree;
+ while (toFree) {
+ uint index = qCountTrailingZeroBits(toFree);
+ quintptr bit = (static_cast<quintptr>(1) << index);
+
+ toFree ^= bit; // mask out freed slot
+ // DEBUG << " index" << hex << index << toFree;
+
+ // remove all extends slots that have been freed
+ // this is a bit of bit trickery.
+ quintptr mask = (bit << 1) - 1; // create a mask of 1's to the right of and up to the current bit
+ quintptr objmask = e | mask; // or'ing mask with e gives all ones until the end of the current object
+ quintptr result = objmask + 1;
+ Q_ASSERT(qCountTrailingZeroBits(result) - index != 0); // ensure we freed something
+ result |= mask; // ensure we don't clear stuff to the right of the current object
+ e &= result;
+
+ HeapItem *itemToFree = o + index;
+ Heap::Base *b = *itemToFree;
+ if (b->vtable()->destroy) {
+ b->vtable()->destroy(b);
+ b->_checkIsDestroyed();
+ }
+ }
+ objectBitmap[i] = blackBitmap[i];
+ blackBitmap[i] = 0;
+ extendsBitmap[i] = e;
+ o += Chunk::Bits;
+ }
+ // DEBUG << "swept chunk" << this << "freed" << slotsFreed << "slots.";
+}
- Data()
- : pageSize(WTF::pageSize())
- , engine(0)
- , maxChunkSize(maxChunkSizeValue())
- , unmanagedHeapSize(0)
- , unmanagedHeapSizeGCLimit(MIN_UNMANAGED_HEAPSIZE_GC_LIMIT)
- , largeItems(0)
- , totalLargeItemsAllocated(0)
- , totalItems(0)
- , totalAlloc(0)
- , maxShift(maxShiftValue())
- , gcBlocked(false)
- , aggressiveGC(!qEnvironmentVariableIsEmpty("QV4_MM_AGGRESSIVE_GC"))
- , gcStats(!qEnvironmentVariableIsEmpty(QV4_MM_STATS))
- {
- memset(nonFullChunks, 0, sizeof(nonFullChunks));
- memset(nChunks, 0, sizeof(nChunks));
- memset(availableItems, 0, sizeof(availableItems));
- memset(allocCount, 0, sizeof(allocCount));
+void Chunk::freeAll()
+{
+ // DEBUG << "sweeping chunk" << this << (*freeList);
+ HeapItem *o = realBase();
+ for (uint i = 0; i < Chunk::EntriesInBitmap; ++i) {
+ quintptr toFree = objectBitmap[i];
+ quintptr e = extendsBitmap[i];
+ // DEBUG << hex << " index=" << i << toFree;
+ while (toFree) {
+ uint index = qCountTrailingZeroBits(toFree);
+ quintptr bit = (static_cast<quintptr>(1) << index);
+
+ toFree ^= bit; // mask out freed slot
+ // DEBUG << " index" << hex << index << toFree;
+
+ // remove all extends slots that have been freed
+ // this is a bit of bit trickery.
+ quintptr mask = (bit << 1) - 1; // create a mask of 1's to the right of and up to the current bit
+ quintptr objmask = e | mask; // or'ing mask with e gives all ones until the end of the current object
+ quintptr result = objmask + 1;
+ Q_ASSERT(qCountTrailingZeroBits(result) - index != 0); // ensure we freed something
+ result |= mask; // ensure we don't clear stuff to the right of the current object
+ e &= result;
+
+ HeapItem *itemToFree = o + index;
+ Heap::Base *b = *itemToFree;
+ if (b->vtable()->destroy) {
+ b->vtable()->destroy(b);
+ b->_checkIsDestroyed();
+ }
+ }
+ objectBitmap[i] = 0;
+ blackBitmap[i] = 0;
+ extendsBitmap[i] = e;
+ o += Chunk::Bits;
}
+ // DEBUG << "swept chunk" << this << "freed" << slotsFreed << "slots.";
+}
- ~Data()
- {
- for (std::vector<PageAllocation>::iterator i = heapChunks.begin(), ei = heapChunks.end(); i != ei; ++i) {
- Q_V4_PROFILE_DEALLOC(engine, i->size(), Profiling::HeapPage);
- i->deallocate();
+void Chunk::sortIntoBins(HeapItem **bins, uint nBins)
+{
+// qDebug() << "sortIntoBins:";
+ HeapItem *base = realBase();
+#if QT_POINTER_SIZE == 8
+ const int start = 0;
+#else
+ const int start = 1;
+#endif
+#ifndef QT_NO_DEBUG
+ uint freeSlots = 0;
+ uint allocatedSlots = 0;
+#endif
+ for (int i = start; i < EntriesInBitmap; ++i) {
+ quintptr usedSlots = (objectBitmap[i]|extendsBitmap[i]);
+#if QT_POINTER_SIZE == 8
+ if (!i)
+ usedSlots |= (static_cast<quintptr>(1) << (HeaderSize/SlotSize)) - 1;
+#endif
+#ifndef QT_NO_DEBUG
+ allocatedSlots += qPopulationCount(usedSlots);
+// qDebug() << hex << " i=" << i << "used=" << usedSlots;
+#endif
+ while (1) {
+ uint index = qCountTrailingZeroBits(usedSlots + 1);
+ if (index == Bits)
+ break;
+ uint freeStart = i*Bits + index;
+ usedSlots &= ~((static_cast<quintptr>(1) << index) - 1);
+ while (!usedSlots) {
+ ++i;
+ if (i == EntriesInBitmap) {
+ usedSlots = (quintptr)-1;
+ break;
+ }
+ usedSlots = (objectBitmap[i]|extendsBitmap[i]);
+#ifndef QT_NO_DEBUG
+ allocatedSlots += qPopulationCount(usedSlots);
+// qDebug() << hex << " i=" << i << "used=" << usedSlots;
+#endif
+ }
+ HeapItem *freeItem = base + freeStart;
+
+ index = qCountTrailingZeroBits(usedSlots);
+ usedSlots |= (quintptr(1) << index) - 1;
+ uint freeEnd = i*Bits + index;
+ uint nSlots = freeEnd - freeStart;
+#ifndef QT_NO_DEBUG
+// qDebug() << hex << " got free slots from" << freeStart << "to" << freeEnd << "n=" << nSlots << "usedSlots=" << usedSlots;
+ freeSlots += nSlots;
+#endif
+ Q_ASSERT(freeEnd > freeStart && freeEnd <= NumSlots);
+ freeItem->freeData.availableSlots = nSlots;
+ uint bin = qMin(nBins - 1, nSlots);
+ freeItem->freeData.next = bins[bin];
+ bins[bin] = freeItem;
}
}
-};
+#ifndef QT_NO_DEBUG
+ Q_ASSERT(freeSlots + allocatedSlots == (EntriesInBitmap - start) * 8 * sizeof(quintptr));
+#endif
+}
-namespace {
-bool sweepChunk(MemoryManager::Data::ChunkHeader *header, uint *itemsInUse, ExecutionEngine *engine, std::size_t *unmanagedHeapSize)
+template<typename T>
+StackAllocator<T>::StackAllocator(ChunkAllocator *chunkAlloc)
+ : chunkAllocator(chunkAlloc)
{
- Q_ASSERT(unmanagedHeapSize);
+ chunks.push_back(chunkAllocator->allocate());
+ firstInChunk = chunks.back()->first();
+ nextFree = firstInChunk;
+ lastInChunk = firstInChunk + (Chunk::AvailableSlots - 1)/requiredSlots*requiredSlots;
+}
- bool isEmpty = true;
- Heap::Base *tail = &header->freeItems;
-// qDebug("chunkStart @ %p, size=%x, pos=%x", header->itemStart, header->itemSize, header->itemSize>>4);
-#ifdef V4_USE_VALGRIND
- VALGRIND_DISABLE_ERROR_REPORTING;
-#endif
- for (char *item = header->itemStart; item <= header->itemEnd; item += header->itemSize) {
- Heap::Base *m = reinterpret_cast<Heap::Base *>(item);
-// qDebug("chunk @ %p, in use: %s, mark bit: %s",
-// item, (m->inUse() ? "yes" : "no"), (m->isMarked() ? "true" : "false"));
-
- Q_ASSERT(qintptr(item) % 16 == 0);
-
- if (m->isMarked()) {
- Q_ASSERT(m->inUse());
- m->clearMarkBit();
- isEmpty = false;
- ++(*itemsInUse);
- } else {
- if (m->inUse()) {
-// qDebug() << "-- collecting it." << m << tail << m->nextFree();
-#ifdef V4_USE_VALGRIND
- VALGRIND_ENABLE_ERROR_REPORTING;
+template<typename T>
+void StackAllocator<T>::freeAll()
+{
+ for (auto c : chunks)
+ chunkAllocator->free(c);
+}
+
+template<typename T>
+void StackAllocator<T>::nextChunk() {
+ Q_ASSERT(nextFree == lastInChunk);
+ ++currentChunk;
+ if (currentChunk >= chunks.size()) {
+ Chunk *newChunk = chunkAllocator->allocate();
+ chunks.push_back(newChunk);
+ }
+ firstInChunk = chunks.at(currentChunk)->first();
+ nextFree = firstInChunk;
+ lastInChunk = firstInChunk + (Chunk::AvailableSlots - 1)/requiredSlots*requiredSlots;
+}
+
+template<typename T>
+void QV4::StackAllocator<T>::prevChunk() {
+ Q_ASSERT(nextFree == firstInChunk);
+ Q_ASSERT(chunks.at(currentChunk) == nextFree->chunk());
+ Q_ASSERT(currentChunk > 0);
+ --currentChunk;
+ firstInChunk = chunks.at(currentChunk)->first();
+ lastInChunk = firstInChunk + (Chunk::AvailableSlots - 1)/requiredSlots*requiredSlots;
+ nextFree = lastInChunk;
+}
+
+template struct StackAllocator<Heap::CallContext>;
+
+
+HeapItem *BlockAllocator::allocate(size_t size, bool forceAllocation) {
+ Q_ASSERT((size % Chunk::SlotSize) == 0);
+ size_t slotsRequired = size >> Chunk::SlotSizeShift;
+#if MM_DEBUG
+ ++allocations[bin];
#endif
- if (std::size_t(header->itemSize) == MemoryManager::align(sizeof(Heap::String)) && m->vtable()->isString) {
- std::size_t heapBytes = static_cast<Heap::String *>(m)->retainedTextSize();
- Q_ASSERT(*unmanagedHeapSize >= heapBytes);
-// qDebug() << "-- it's a string holding on to" << heapBytes << "bytes";
- *unmanagedHeapSize -= heapBytes;
- }
- if (m->vtable()->destroy) {
- m->vtable()->destroy(m);
- m->_checkIsDestroyed();
+ HeapItem **last;
+
+ HeapItem *m;
+
+ if (slotsRequired < NumBins - 1) {
+ m = freeBins[slotsRequired];
+ if (m) {
+ freeBins[slotsRequired] = m->freeData.next;
+ goto done;
+ }
+ }
+
+ if (nFree >= slotsRequired) {
+ // use bump allocation
+ Q_ASSERT(nextFree);
+ m = nextFree;
+ nextFree += slotsRequired;
+ nFree -= slotsRequired;
+ goto done;
+ }
+
+ // DEBUG << "No matching bin found for item" << size << bin;
+ // search last bin for a large enough item
+ last = &freeBins[NumBins - 1];
+ while ((m = *last)) {
+ if (m->freeData.availableSlots >= slotsRequired) {
+ *last = m->freeData.next; // take it out of the list
+
+ size_t remainingSlots = m->freeData.availableSlots - slotsRequired;
+ // DEBUG << "found large free slots of size" << m->freeData.availableSlots << m << "remaining" << remainingSlots;
+ if (remainingSlots == 0)
+ goto done;
+
+ HeapItem *remainder = m + slotsRequired;
+ if (remainingSlots > nFree) {
+ if (nFree) {
+ size_t bin = binForSlots(nFree);
+ nextFree->freeData.next = freeBins[bin];
+ nextFree->freeData.availableSlots = nFree;
+ freeBins[bin] = nextFree;
}
+ nextFree = remainder;
+ nFree = remainingSlots;
+ } else {
+ remainder->freeData.availableSlots = remainingSlots;
+ size_t binForRemainder = binForSlots(remainingSlots);
+ remainder->freeData.next = freeBins[binForRemainder];
+ freeBins[binForRemainder] = remainder;
+ }
+ goto done;
+ }
+ last = &m->freeData.next;
+ }
- memset(m, 0, sizeof(Heap::Base));
-#ifdef V4_USE_VALGRIND
- VALGRIND_DISABLE_ERROR_REPORTING;
- VALGRIND_MEMPOOL_FREE(engine->memoryManager, m);
-#endif
-#ifdef V4_USE_HEAPTRACK
- heaptrack_report_free(m);
-#endif
- Q_V4_PROFILE_DEALLOC(engine, header->itemSize, Profiling::SmallItem);
- ++(*itemsInUse);
+ if (slotsRequired < NumBins - 1) {
+ // check if we can split up another slot
+ for (size_t i = slotsRequired + 1; i < NumBins - 1; ++i) {
+ m = freeBins[i];
+ if (m) {
+ freeBins[i] = m->freeData.next; // take it out of the list
+// qDebug() << "got item" << slotsRequired << "from slot" << i;
+ size_t remainingSlots = i - slotsRequired;
+ Q_ASSERT(remainingSlots < NumBins - 1);
+ HeapItem *remainder = m + slotsRequired;
+ remainder->freeData.availableSlots = remainingSlots;
+ remainder->freeData.next = freeBins[remainingSlots];
+ freeBins[remainingSlots] = remainder;
+ goto done;
}
- // Relink all free blocks to rewrite references to any released chunk.
- tail->setNextFree(m);
- tail = m;
}
}
- tail->setNextFree(0);
-#ifdef V4_USE_VALGRIND
- VALGRIND_ENABLE_ERROR_REPORTING;
+
+ if (!m) {
+ if (!forceAllocation)
+ return 0;
+ Chunk *newChunk = chunkAllocator->allocate();
+ chunks.push_back(newChunk);
+ nextFree = newChunk->first();
+ nFree = Chunk::AvailableSlots;
+ m = nextFree;
+ nextFree += slotsRequired;
+ nFree -= slotsRequired;
+ }
+
+done:
+ m->setAllocatedSlots(slotsRequired);
+ // DEBUG << " " << hex << m->chunk() << m->chunk()->objectBitmap[0] << m->chunk()->extendsBitmap[0] << (m - m->chunk()->realBase());
+ return m;
+}
+
+void BlockAllocator::sweep()
+{
+ nextFree = 0;
+ nFree = 0;
+ memset(freeBins, 0, sizeof(freeBins));
+
+// qDebug() << "BlockAlloc: sweep";
+ usedSlotsAfterLastSweep = 0;
+ for (auto c : chunks) {
+ c->sweep();
+ c->sortIntoBins(freeBins, NumBins);
+// qDebug() << "used slots in chunk" << c << ":" << c->nUsedSlots();
+ usedSlotsAfterLastSweep += c->nUsedSlots();
+ }
+}
+
+void BlockAllocator::freeAll()
+{
+ for (auto c : chunks) {
+ c->freeAll();
+ chunkAllocator->free(c);
+ }
+}
+
+#if MM_DEBUG
+void BlockAllocator::stats() {
+ DEBUG << "MM stats:";
+ QString s;
+ for (int i = 0; i < 10; ++i) {
+ uint c = 0;
+ HeapItem *item = freeBins[i];
+ while (item) {
+ ++c;
+ item = item->freeData.next;
+ }
+ s += QString::number(c) + QLatin1String(", ");
+ }
+ HeapItem *item = freeBins[NumBins - 1];
+ uint c = 0;
+ while (item) {
+ ++c;
+ item = item->freeData.next;
+ }
+ s += QLatin1String("..., ") + QString::number(c);
+ DEBUG << "bins:" << s;
+ QString a;
+ for (int i = 0; i < 10; ++i)
+ a += QString::number(allocations[i]) + QLatin1String(", ");
+ a += QLatin1String("..., ") + QString::number(allocations[NumBins - 1]);
+ DEBUG << "allocs:" << a;
+ memset(allocations, 0, sizeof(allocations));
+}
#endif
- return isEmpty;
+
+
+HeapItem *HugeItemAllocator::allocate(size_t size) {
+ Chunk *c = chunkAllocator->allocate(size);
+ chunks.push_back(HugeChunk{c, size});
+ Chunk::setBit(c->objectBitmap, c->first() - c->realBase());
+ return c->first();
+}
+
+static void freeHugeChunk(ChunkAllocator *chunkAllocator, const HugeItemAllocator::HugeChunk &c)
+{
+ HeapItem *itemToFree = c.chunk->first();
+ Heap::Base *b = *itemToFree;
+ if (b->vtable()->destroy) {
+ b->vtable()->destroy(b);
+ b->_checkIsDestroyed();
+ }
+ chunkAllocator->free(c.chunk, c.size);
+}
+
+void HugeItemAllocator::sweep() {
+ auto isBlack = [this] (const HugeChunk &c) {
+ bool b = c.chunk->first()->isBlack();
+ Chunk::clearBit(c.chunk->blackBitmap, c.chunk->first() - c.chunk->realBase());
+ if (!b)
+ freeHugeChunk(chunkAllocator, c);
+ return !b;
+ };
+
+ auto newEnd = std::remove_if(chunks.begin(), chunks.end(), isBlack);
+ chunks.erase(newEnd, chunks.end());
+}
+
+void HugeItemAllocator::freeAll()
+{
+ for (auto &c : chunks) {
+ freeHugeChunk(chunkAllocator, c);
+ }
}
-} // namespace
MemoryManager::MemoryManager(ExecutionEngine *engine)
: engine(engine)
- , m_d(new Data)
+ , chunkAllocator(new ChunkAllocator)
+ , stackAllocator(chunkAllocator)
+ , blockAllocator(chunkAllocator)
+ , hugeItemAllocator(chunkAllocator)
, m_persistentValues(new PersistentValueStorage(engine))
, m_weakValues(new PersistentValueStorage(engine))
+ , unmanagedHeapSizeGCLimit(MIN_UNMANAGED_HEAPSIZE_GC_LIMIT)
+ , aggressiveGC(!qEnvironmentVariableIsEmpty("QV4_MM_AGGRESSIVE_GC"))
+ , gcStats(!qEnvironmentVariableIsEmpty(QV4_MM_STATS))
{
#ifdef V4_USE_VALGRIND
VALGRIND_CREATE_MEMPOOL(this, 0, true);
#endif
- m_d->engine = engine;
}
-Heap::Base *MemoryManager::allocData(std::size_t size, std::size_t unmanagedSize)
-{
- if (m_d->aggressiveGC)
- runGC();
-#ifdef DETAILED_MM_STATS
- willAllocate(size);
-#endif // DETAILED_MM_STATS
+#ifndef QT_NO_DEBUG
+static size_t lastAllocRequestedSlots = 0;
+#endif
- Q_ASSERT(size >= 16);
- Q_ASSERT(size % 16 == 0);
+Heap::Base *MemoryManager::allocString(std::size_t unmanagedSize)
+{
+ const size_t stringSize = align(sizeof(Heap::String));
+#ifndef QT_NO_DEBUG
+ lastAllocRequestedSlots = stringSize >> Chunk::SlotSizeShift;
+#endif
-// qDebug() << "unmanagedHeapSize:" << m_d->unmanagedHeapSize << "limit:" << m_d->unmanagedHeapSizeGCLimit << "unmanagedSize:" << unmanagedSize;
- m_d->unmanagedHeapSize += unmanagedSize;
bool didGCRun = false;
- if (m_d->unmanagedHeapSize > m_d->unmanagedHeapSizeGCLimit) {
+ if (aggressiveGC) {
+ runGC();
+ didGCRun = true;
+ }
+
+ unmanagedHeapSize += unmanagedSize;
+ if (unmanagedHeapSize > unmanagedHeapSizeGCLimit) {
runGC();
- if (3*m_d->unmanagedHeapSizeGCLimit <= 4*m_d->unmanagedHeapSize)
+ if (3*unmanagedHeapSizeGCLimit <= 4*unmanagedHeapSize)
// more than 75% full, raise limit
- m_d->unmanagedHeapSizeGCLimit = std::max(m_d->unmanagedHeapSizeGCLimit, m_d->unmanagedHeapSize) * 2;
- else if (m_d->unmanagedHeapSize * 4 <= m_d->unmanagedHeapSizeGCLimit)
+ unmanagedHeapSizeGCLimit = std::max(unmanagedHeapSizeGCLimit, unmanagedHeapSize) * 2;
+ else if (unmanagedHeapSize * 4 <= unmanagedHeapSizeGCLimit)
// less than 25% full, lower limit
- m_d->unmanagedHeapSizeGCLimit = qMax(MIN_UNMANAGED_HEAPSIZE_GC_LIMIT, m_d->unmanagedHeapSizeGCLimit/2);
+ unmanagedHeapSizeGCLimit = qMax(MIN_UNMANAGED_HEAPSIZE_GC_LIMIT, unmanagedHeapSizeGCLimit/2);
didGCRun = true;
}
- size_t pos = size >> 4;
-
- // doesn't fit into a small bucket
- if (size >= MemoryManager::Data::MaxItemSize) {
- if (!didGCRun && m_d->totalLargeItemsAllocated > 8 * 1024 * 1024)
+ HeapItem *m = blockAllocator.allocate(stringSize);
+ if (!m) {
+ if (!didGCRun && shouldRunGC())
runGC();
-
- // we use malloc for this
- const size_t totalSize = size + sizeof(MemoryManager::Data::LargeItem);
- Q_V4_PROFILE_ALLOC(engine, totalSize, Profiling::LargeItem);
- MemoryManager::Data::LargeItem *item =
- static_cast<MemoryManager::Data::LargeItem *>(malloc(totalSize));
- memset(item, 0, totalSize);
- item->next = m_d->largeItems;
- item->size = size;
- m_d->largeItems = item;
- m_d->totalLargeItemsAllocated += size;
- return item->heapObject();
+ m = blockAllocator.allocate(stringSize, true);
}
- Heap::Base *m = 0;
- Data::ChunkHeader *header = m_d->nonFullChunks[pos];
- if (header) {
- m = header->freeItems.nextFree();
- goto found;
- }
+ memset(m, 0, stringSize);
+ return *m;
+}
+
+Heap::Base *MemoryManager::allocData(std::size_t size)
+{
+#ifndef QT_NO_DEBUG
+ lastAllocRequestedSlots = size >> Chunk::SlotSizeShift;
+#endif
- // try to free up space, otherwise allocate
- if (!didGCRun && m_d->allocCount[pos] > (m_d->availableItems[pos] >> 1) && m_d->totalAlloc > (m_d->totalItems >> 1) && !m_d->aggressiveGC) {
+ bool didRunGC = false;
+ if (aggressiveGC) {
runGC();
- header = m_d->nonFullChunks[pos];
- if (header) {
- m = header->freeItems.nextFree();
- goto found;
- }
+ didRunGC = true;
}
+#ifdef DETAILED_MM_STATS
+ willAllocate(size);
+#endif // DETAILED_MM_STATS
- // no free item available, allocate a new chunk
- {
- // allocate larger chunks at a time to avoid excessive GC, but cap at maximum chunk size (2MB by default)
- uint shift = ++m_d->nChunks[pos];
- if (shift > m_d->maxShift)
- shift = m_d->maxShift;
- std::size_t allocSize = m_d->maxChunkSize*(size_t(1) << shift);
- allocSize = roundUpToMultipleOf(m_d->pageSize, allocSize);
- Q_V4_PROFILE_ALLOC(engine, allocSize, Profiling::HeapPage);
- PageAllocation allocation = PageAllocation::allocate(allocSize, OSAllocator::JSGCHeapPages);
- m_d->heapChunks.push_back(allocation);
-
- header = reinterpret_cast<Data::ChunkHeader *>(allocation.base());
- Q_ASSERT(size <= UINT_MAX);
- header->itemSize = unsigned(size);
- header->itemStart = reinterpret_cast<char *>(allocation.base()) + roundUpToMultipleOf(16, sizeof(Data::ChunkHeader));
- header->itemEnd = reinterpret_cast<char *>(allocation.base()) + allocation.size() - header->itemSize;
-
- header->nextNonFull = m_d->nonFullChunks[pos];
- m_d->nonFullChunks[pos] = header;
-
- Heap::Base *last = &header->freeItems;
- for (char *item = header->itemStart; item <= header->itemEnd; item += header->itemSize) {
- Heap::Base *o = reinterpret_cast<Heap::Base *>(item);
- last->setNextFree(o);
- last = o;
+ Q_ASSERT(size >= Chunk::SlotSize);
+ Q_ASSERT(size % Chunk::SlotSize == 0);
- }
- last->setNextFree(0);
- m = header->freeItems.nextFree();
- Q_ASSERT(header->itemEnd >= header->itemStart);
- const size_t increase = quintptr(header->itemEnd - header->itemStart) / header->itemSize;
- m_d->availableItems[pos] += uint(increase);
- m_d->totalItems += int(increase);
-#ifdef V4_USE_VALGRIND
- VALGRIND_MAKE_MEM_NOACCESS(allocation.base(), allocSize);
- VALGRIND_MEMPOOL_ALLOC(this, header, sizeof(Data::ChunkHeader));
-#endif
-#ifdef V4_USE_HEAPTRACK
- heaptrack_report_alloc(header, sizeof(Data::ChunkHeader));
-#endif
+// qDebug() << "unmanagedHeapSize:" << unmanagedHeapSize << "limit:" << unmanagedHeapSizeGCLimit << "unmanagedSize:" << unmanagedSize;
+
+ if (size > Chunk::DataSize)
+ return *hugeItemAllocator.allocate(size);
+
+ HeapItem *m = blockAllocator.allocate(size);
+ if (!m) {
+ if (!didRunGC && shouldRunGC())
+ runGC();
+ m = blockAllocator.allocate(size, true);
}
- found:
-#ifdef V4_USE_VALGRIND
- VALGRIND_MEMPOOL_ALLOC(this, m, size);
-#endif
-#ifdef V4_USE_HEAPTRACK
- heaptrack_report_alloc(m, size);
-#endif
- Q_V4_PROFILE_ALLOC(engine, size, Profiling::SmallItem);
+ memset(m, 0, size);
+ return *m;
+}
- ++m_d->allocCount[pos];
- ++m_d->totalAlloc;
- header->freeItems.setNextFree(m->nextFree());
- if (!header->freeItems.nextFree())
- m_d->nonFullChunks[pos] = header->nextNonFull;
- return m;
+Heap::Object *MemoryManager::allocObjectWithMemberData(std::size_t size, uint nMembers)
+{
+ Heap::Object *o = static_cast<Heap::Object *>(allocData(size));
+
+ // ### Could optimize this and allocate both in one go through the block allocator
+ if (nMembers) {
+ std::size_t memberSize = align(sizeof(Heap::MemberData) + (nMembers - 1)*sizeof(Value));
+// qDebug() << "allocating member data for" << o << nMembers << memberSize;
+ Heap::Base *m;
+ if (memberSize > Chunk::DataSize)
+ m = *hugeItemAllocator.allocate(memberSize);
+ else
+ m = *blockAllocator.allocate(memberSize, true);
+ memset(m, 0, memberSize);
+ o->memberData = static_cast<Heap::MemberData *>(m);
+ o->memberData->setVtable(MemberData::staticVTable());
+ o->memberData->size = static_cast<uint>((memberSize - sizeof(Heap::MemberData) + sizeof(Value))/sizeof(Value));
+ o->memberData->init();
+// qDebug() << " got" << o->memberData << o->memberData->size;
+ }
+ return o;
}
static void drainMarkStack(QV4::ExecutionEngine *engine, Value *markBase)
@@ -495,156 +841,120 @@ void MemoryManager::sweep(bool lastSweep)
}
}
- bool *chunkIsEmpty = static_cast<bool *>(alloca(m_d->heapChunks.size() * sizeof(bool)));
- uint itemsInUse[MemoryManager::Data::MaxItemSize/16];
- memset(itemsInUse, 0, sizeof(itemsInUse));
- memset(m_d->nonFullChunks, 0, sizeof(m_d->nonFullChunks));
-
- for (size_t i = 0; i < m_d->heapChunks.size(); ++i) {
- Data::ChunkHeader *header = reinterpret_cast<Data::ChunkHeader *>(m_d->heapChunks[i].base());
- chunkIsEmpty[i] = sweepChunk(header, &itemsInUse[header->itemSize >> 4], engine, &m_d->unmanagedHeapSize);
- }
-
- std::vector<PageAllocation>::iterator chunkIter = m_d->heapChunks.begin();
- for (size_t i = 0; i < m_d->heapChunks.size(); ++i) {
- Q_ASSERT(chunkIter != m_d->heapChunks.end());
- Data::ChunkHeader *header = reinterpret_cast<Data::ChunkHeader *>(chunkIter->base());
- const size_t pos = header->itemSize >> 4;
- Q_ASSERT(header->itemEnd >= header->itemStart);
- const size_t decrease = quintptr(header->itemEnd - header->itemStart) / header->itemSize;
-
- // Release that chunk if it could have been spared since the last GC run without any difference.
- if (chunkIsEmpty[i] && m_d->availableItems[pos] - decrease >= itemsInUse[pos]) {
- Q_V4_PROFILE_DEALLOC(engine, chunkIter->size(), Profiling::HeapPage);
-#ifdef V4_USE_VALGRIND
- VALGRIND_MEMPOOL_FREE(this, header);
-#endif
-#ifdef V4_USE_HEAPTRACK
- heaptrack_report_free(header);
-#endif
- --m_d->nChunks[pos];
- m_d->availableItems[pos] -= uint(decrease);
- m_d->totalItems -= int(decrease);
- chunkIter->deallocate();
- chunkIter = m_d->heapChunks.erase(chunkIter);
- continue;
- } else if (header->freeItems.nextFree()) {
- header->nextNonFull = m_d->nonFullChunks[pos];
- m_d->nonFullChunks[pos] = header;
- }
- ++chunkIter;
- }
-
- Data::LargeItem *i = m_d->largeItems;
- Data::LargeItem **last = &m_d->largeItems;
- while (i) {
- Heap::Base *m = i->heapObject();
- Q_ASSERT(m->inUse());
- if (m->isMarked()) {
- m->clearMarkBit();
- last = &i->next;
- i = i->next;
- continue;
- }
- if (m->vtable()->destroy)
- m->vtable()->destroy(m);
+ blockAllocator.sweep();
+ hugeItemAllocator.sweep();
+}
- *last = i->next;
- Q_V4_PROFILE_DEALLOC(engine, i->size + sizeof(Data::LargeItem), Profiling::LargeItem);
- free(i);
- i = *last;
- }
+bool MemoryManager::shouldRunGC() const
+{
+ size_t total = blockAllocator.totalSlots();
+ size_t usedSlots = blockAllocator.usedSlotsAfterLastSweep;
+ if (total > MinSlotsGCLimit && usedSlots * GCOverallocation < total * 100)
+ return true;
+ return false;
+}
- // some execution contexts are allocated on the stack, make sure we clear their markBit as well
- if (!lastSweep) {
- QV4::ExecutionContext *ctx = engine->currentContext;
- while (ctx) {
- ctx->d()->clearMarkBit();
- ctx = engine->parentContext(ctx);
+size_t dumpBins(BlockAllocator *b, bool printOutput = true)
+{
+ size_t totalFragmentedSlots = 0;
+ if (printOutput)
+ qDebug() << "Fragmentation map:";
+ for (uint i = 0; i < BlockAllocator::NumBins; ++i) {
+ uint nEntries = 0;
+ HeapItem *h = b->freeBins[i];
+ while (h) {
+ ++nEntries;
+ totalFragmentedSlots += h->freeData.availableSlots;
+ h = h->freeData.next;
}
+ if (printOutput)
+ qDebug() << " number of entries in slot" << i << ":" << nEntries;
}
+ if (printOutput)
+ qDebug() << " total mem in bins" << totalFragmentedSlots*Chunk::SlotSize;
+ return totalFragmentedSlots*Chunk::SlotSize;
}
void MemoryManager::runGC()
{
- if (m_d->gcBlocked) {
+ if (gcBlocked) {
// qDebug() << "Not running GC.";
return;
}
- QScopedValueRollback<bool> gcBlocker(m_d->gcBlocked, true);
+ QScopedValueRollback<bool> gcBlocker(gcBlocked, true);
- if (!m_d->gcStats) {
+ if (!gcStats) {
+// uint oldUsed = allocator.usedMem();
mark();
sweep();
+// DEBUG << "RUN GC: allocated:" << allocator.allocatedMem() << "used before" << oldUsed << "used now" << allocator.usedMem();
} else {
+ bool triggeredByUnmanagedHeap = (unmanagedHeapSize > unmanagedHeapSizeGCLimit);
+ size_t oldUnmanagedSize = unmanagedHeapSize;
const size_t totalMem = getAllocatedMem();
+ const size_t usedBefore = getUsedMem();
+ const size_t largeItemsBefore = getLargeItemsMem();
+
+ qDebug() << "========== GC ==========";
+#ifndef QT_NO_DEBUG
+ qDebug() << " Triggered by alloc request of" << lastAllocRequestedSlots << "slots.";
+#endif
+ qDebug() << "Allocated" << totalMem << "bytes in" << blockAllocator.chunks.size() << "chunks";
+ qDebug() << "Fragmented memory before GC" << (totalMem - usedBefore);
+ dumpBins(&blockAllocator);
QElapsedTimer t;
t.start();
mark();
qint64 markTime = t.restart();
- const size_t usedBefore = getUsedMem();
- const size_t largeItemsBefore = getLargeItemsMem();
- size_t chunksBefore = m_d->heapChunks.size();
sweep();
const size_t usedAfter = getUsedMem();
const size_t largeItemsAfter = getLargeItemsMem();
qint64 sweepTime = t.elapsed();
- qDebug() << "========== GC ==========";
+ if (triggeredByUnmanagedHeap) {
+ qDebug() << "triggered by unmanaged heap:";
+ qDebug() << " old unmanaged heap size:" << oldUnmanagedSize;
+ qDebug() << " new unmanaged heap:" << unmanagedHeapSize;
+ qDebug() << " unmanaged heap limit:" << unmanagedHeapSizeGCLimit;
+ }
+ size_t memInBins = dumpBins(&blockAllocator);
qDebug() << "Marked object in" << markTime << "ms.";
qDebug() << "Sweeped object in" << sweepTime << "ms.";
- qDebug() << "Allocated" << totalMem << "bytes in" << m_d->heapChunks.size() << "chunks.";
qDebug() << "Used memory before GC:" << usedBefore;
qDebug() << "Used memory after GC:" << usedAfter;
qDebug() << "Freed up bytes:" << (usedBefore - usedAfter);
- qDebug() << "Released chunks:" << (chunksBefore - m_d->heapChunks.size());
- qDebug() << "Large item memory before GC:" << largeItemsBefore;
- qDebug() << "Large item memory after GC:" << largeItemsAfter;
- qDebug() << "Large item memory freed up:" << (largeItemsBefore - largeItemsAfter);
+ size_t lost = blockAllocator.allocatedMem() - memInBins - usedAfter;
+ if (lost)
+ qDebug() << "!!!!!!!!!!!!!!!!!!!!! LOST MEM:" << lost << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
+ if (largeItemsBefore || largeItemsAfter) {
+ qDebug() << "Large item memory before GC:" << largeItemsBefore;
+ qDebug() << "Large item memory after GC:" << largeItemsAfter;
+ qDebug() << "Large item memory freed up:" << (largeItemsBefore - largeItemsAfter);
+ }
qDebug() << "======== End GC ========";
}
- memset(m_d->allocCount, 0, sizeof(m_d->allocCount));
- m_d->totalAlloc = 0;
- m_d->totalLargeItemsAllocated = 0;
+ if (aggressiveGC) {
+ // ensure we don't 'loose' any memory
+ Q_ASSERT(blockAllocator.allocatedMem() == getUsedMem() + dumpBins(&blockAllocator, false));
+ }
}
size_t MemoryManager::getUsedMem() const
{
- size_t usedMem = 0;
- for (std::vector<PageAllocation>::const_iterator i = m_d->heapChunks.cbegin(), ei = m_d->heapChunks.cend(); i != ei; ++i) {
- Data::ChunkHeader *header = reinterpret_cast<Data::ChunkHeader *>(i->base());
- for (char *item = header->itemStart; item <= header->itemEnd; item += header->itemSize) {
- Heap::Base *m = reinterpret_cast<Heap::Base *>(item);
- Q_ASSERT(qintptr(item) % 16 == 0);
- if (m->inUse())
- usedMem += header->itemSize;
- }
- }
- return usedMem;
+ return blockAllocator.usedMem();
}
size_t MemoryManager::getAllocatedMem() const
{
- size_t total = 0;
- for (size_t i = 0; i < m_d->heapChunks.size(); ++i)
- total += m_d->heapChunks.at(i).size();
- return total;
+ return blockAllocator.allocatedMem() + hugeItemAllocator.usedMem();
}
size_t MemoryManager::getLargeItemsMem() const
{
- size_t total = 0;
- for (const Data::LargeItem *i = m_d->largeItems; i != 0; i = i->next)
- total += i->size;
- return total;
-}
-
-void MemoryManager::growUnmanagedHeapSizeUsage(size_t delta)
-{
- m_d->unmanagedHeapSize += delta;
+ return hugeItemAllocator.usedMem();
}
MemoryManager::~MemoryManager()
@@ -652,23 +962,26 @@ MemoryManager::~MemoryManager()
delete m_persistentValues;
sweep(/*lastSweep*/true);
+ blockAllocator.freeAll();
+ hugeItemAllocator.freeAll();
+ stackAllocator.freeAll();
delete m_weakValues;
#ifdef V4_USE_VALGRIND
VALGRIND_DESTROY_MEMPOOL(this);
#endif
+ delete chunkAllocator;
}
-
void MemoryManager::dumpStats() const
{
#ifdef DETAILED_MM_STATS
std::cerr << "=================" << std::endl;
std::cerr << "Allocation stats:" << std::endl;
std::cerr << "Requests for each chunk size:" << std::endl;
- for (int i = 0; i < m_d->allocSizeCounters.size(); ++i) {
- if (unsigned count = m_d->allocSizeCounters[i]) {
+ for (int i = 0; i < allocSizeCounters.size(); ++i) {
+ if (unsigned count = allocSizeCounters[i]) {
std::cerr << "\t" << (i << 4) << " bytes chunks: " << count << std::endl;
}
}
@@ -679,7 +992,7 @@ void MemoryManager::dumpStats() const
void MemoryManager::willAllocate(std::size_t size)
{
unsigned alignedSize = (size + 15) >> 4;
- QVector<unsigned> &counters = m_d->allocSizeCounters;
+ QVector<unsigned> &counters = allocSizeCounters;
if ((unsigned) counters.size() < alignedSize + 1)
counters.resize(alignedSize + 1);
counters[alignedSize]++;
@@ -699,4 +1012,7 @@ void MemoryManager::collectFromJSStack() const
++v;
}
}
+
+} // namespace QV4
+
QT_END_NAMESPACE
diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h
index 86a0ba2735..00daf8a622 100644
--- a/src/qml/memory/qv4mm_p.h
+++ b/src/qml/memory/qv4mm_p.h
@@ -55,6 +55,7 @@
#include <private/qv4value_p.h>
#include <private/qv4scopedvalue_p.h>
#include <private/qv4object_p.h>
+#include <private/qv4mmdefs_p.h>
#include <QVector>
//#define DETAILED_MM_STATS
@@ -63,35 +64,166 @@
#define QV4_MM_MAX_CHUNK_SIZE "QV4_MM_MAX_CHUNK_SIZE"
#define QV4_MM_STATS "QV4_MM_STATS"
+#define MM_DEBUG 0
+
QT_BEGIN_NAMESPACE
namespace QV4 {
-struct GCDeletable;
+struct ChunkAllocator;
+
+template<typename T>
+struct StackAllocator {
+ Q_STATIC_ASSERT(sizeof(T) < Chunk::DataSize);
+ static const uint requiredSlots = (sizeof(T) + sizeof(HeapItem) - 1)/sizeof(HeapItem);
+
+ StackAllocator(ChunkAllocator *chunkAlloc);
+
+ T *allocate() {
+ T *m = nextFree->as<T>();
+ if (Q_UNLIKELY(nextFree == lastInChunk)) {
+ nextChunk();
+ } else {
+ nextFree += requiredSlots;
+ }
+#if MM_DEBUG
+ Chunk *c = m->chunk();
+ Chunk::setBit(c->objectBitmap, m - c->realBase());
+#endif
+ return m;
+ }
+ void free() {
+#if MM_DEBUG
+ Chunk::clearBit(item->chunk()->objectBitmap, item - item->chunk()->realBase());
+#endif
+ if (Q_UNLIKELY(nextFree == firstInChunk)) {
+ prevChunk();
+ } else {
+ nextFree -= requiredSlots;
+ }
+ }
+
+ void nextChunk();
+ void prevChunk();
+
+ void freeAll();
+
+ ChunkAllocator *chunkAllocator;
+ HeapItem *nextFree = 0;
+ HeapItem *firstInChunk = 0;
+ HeapItem *lastInChunk = 0;
+ std::vector<Chunk *> chunks;
+ uint currentChunk = 0;
+};
+
+struct BlockAllocator {
+ BlockAllocator(ChunkAllocator *chunkAllocator)
+ : chunkAllocator(chunkAllocator)
+ {
+ memset(freeBins, 0, sizeof(freeBins));
+#if MM_DEBUG
+ memset(allocations, 0, sizeof(allocations));
+#endif
+ }
+
+ enum { NumBins = 8 };
+
+ static inline size_t binForSlots(size_t nSlots) {
+ return nSlots >= NumBins ? NumBins - 1 : nSlots;
+ }
+
+#if MM_DEBUG
+ void stats();
+#endif
+
+ HeapItem *allocate(size_t size, bool forceAllocation = false);
+
+ size_t totalSlots() const {
+ return Chunk::AvailableSlots*chunks.size();
+ }
+
+ size_t allocatedMem() const {
+ return chunks.size()*Chunk::DataSize;
+ }
+ size_t usedMem() const {
+ uint used = 0;
+ for (auto c : chunks)
+ used += c->nUsedSlots()*Chunk::SlotSize;
+ return used;
+ }
+
+ void sweep();
+ void freeAll();
+
+ // bump allocations
+ HeapItem *nextFree = 0;
+ size_t nFree = 0;
+ size_t usedSlotsAfterLastSweep = 0;
+ HeapItem *freeBins[NumBins];
+ ChunkAllocator *chunkAllocator;
+ std::vector<Chunk *> chunks;
+#if MM_DEBUG
+ uint allocations[NumBins];
+#endif
+};
+
+struct HugeItemAllocator {
+ HugeItemAllocator(ChunkAllocator *chunkAllocator)
+ : chunkAllocator(chunkAllocator)
+ {}
+
+ HeapItem *allocate(size_t size);
+ void sweep();
+ void freeAll();
+
+ size_t usedMem() const {
+ size_t used = 0;
+ for (const auto &c : chunks)
+ used += c.size;
+ return used;
+ }
+
+ ChunkAllocator *chunkAllocator;
+ struct HugeChunk {
+ Chunk *chunk;
+ size_t size;
+ };
+
+ std::vector<HugeChunk> chunks;
+};
+
class Q_QML_EXPORT MemoryManager
{
Q_DISABLE_COPY(MemoryManager);
public:
- struct Data;
-
-public:
MemoryManager(ExecutionEngine *engine);
~MemoryManager();
// TODO: this is only for 64bit (and x86 with SSE/AVX), so exend it for other architectures to be slightly more efficient (meaning, align on 8-byte boundaries).
// Note: all occurrences of "16" in alloc/dealloc are also due to the alignment.
- static inline std::size_t align(std::size_t size)
- { return (size + 15) & ~0xf; }
+ Q_DECL_CONSTEXPR static inline std::size_t align(std::size_t size)
+ { return (size + Chunk::SlotSize - 1) & ~(Chunk::SlotSize - 1); }
+
+ QV4::Heap::CallContext *allocSimpleCallContext(QV4::ExecutionEngine *v4)
+ {
+ Heap::CallContext *ctxt = stackAllocator.allocate();
+ memset(ctxt, 0, sizeof(Heap::CallContext));
+ ctxt->setVtable(QV4::CallContext::staticVTable());
+ ctxt->init(v4);
+ return ctxt;
+
+ }
+ void freeSimpleCallContext()
+ { stackAllocator.free(); }
template<typename ManagedType>
- inline typename ManagedType::Data *allocManaged(std::size_t size, std::size_t unmanagedSize = 0)
+ inline typename ManagedType::Data *allocManaged(std::size_t size)
{
V4_ASSERT_IS_TRIVIAL(typename ManagedType::Data)
size = align(size);
- Heap::Base *o = allocData(size, unmanagedSize);
- memset(o, 0, size);
+ Heap::Base *o = allocData(size);
o->setVtable(ManagedType::staticVTable());
return static_cast<typename ManagedType::Data *>(o);
}
@@ -99,35 +231,31 @@ public:
template <typename ObjectType>
typename ObjectType::Data *allocateObject(InternalClass *ic)
{
- const int size = (sizeof(typename ObjectType::Data) + (sizeof(Value) - 1)) & ~(sizeof(Value) - 1);
- typename ObjectType::Data *o = allocManaged<ObjectType>(size + ic->size*sizeof(Value));
+ Heap::Object *o = allocObjectWithMemberData(align(sizeof(typename ObjectType::Data)), ic->size);
+ o->setVtable(ObjectType::staticVTable());
o->internalClass = ic;
- o->inlineMemberSize = ic->size;
- o->inlineMemberOffset = size/sizeof(Value);
- return o;
+ return static_cast<typename ObjectType::Data *>(o);
}
template <typename ObjectType>
typename ObjectType::Data *allocateObject()
{
InternalClass *ic = ObjectType::defaultInternalClass(engine);
- const int size = (sizeof(typename ObjectType::Data) + (sizeof(Value) - 1)) & ~(sizeof(Value) - 1);
- typename ObjectType::Data *o = allocManaged<ObjectType>(size + ic->size*sizeof(Value));
+ Heap::Object *o = allocObjectWithMemberData(align(sizeof(typename ObjectType::Data)), ic->size);
+ o->setVtable(ObjectType::staticVTable());
Object *prototype = ObjectType::defaultPrototype(engine);
o->internalClass = ic;
o->prototype = prototype->d();
- o->inlineMemberSize = ic->size;
- o->inlineMemberOffset = size/sizeof(Value);
- return o;
+ return static_cast<typename ObjectType::Data *>(o);
}
template <typename ManagedType, typename Arg1>
typename ManagedType::Data *allocWithStringData(std::size_t unmanagedSize, Arg1 arg1)
{
- Scope scope(engine);
- Scoped<ManagedType> t(scope, allocManaged<ManagedType>(sizeof(typename ManagedType::Data), unmanagedSize));
- t->d_unchecked()->init(this, arg1);
- return t->d();
+ typename ManagedType::Data *o = reinterpret_cast<typename ManagedType::Data *>(allocString(unmanagedSize));
+ o->setVtable(ManagedType::staticVTable());
+ o->init(this, arg1);
+ return o;
}
template <typename ObjectType>
@@ -297,12 +425,15 @@ public:
size_t getAllocatedMem() const;
size_t getLargeItemsMem() const;
- void growUnmanagedHeapSizeUsage(size_t delta); // called when a JS object grows itself. Specifically: Heap::String::append
+ // called when a JS object grows itself. Specifically: Heap::String::append
+ void changeUnmanagedHeapSizeUsage(qptrdiff delta) { unmanagedHeapSize += delta; }
+
protected:
/// expects size to be aligned
- // TODO: try to inline
- Heap::Base *allocData(std::size_t size, std::size_t unmanagedSize);
+ Heap::Base *allocString(std::size_t unmanagedSize);
+ Heap::Base *allocData(std::size_t size);
+ Heap::Object *allocObjectWithMemberData(std::size_t size, uint nMembers);
#ifdef DETAILED_MM_STATS
void willAllocate(std::size_t size);
@@ -312,13 +443,24 @@ private:
void collectFromJSStack() const;
void mark();
void sweep(bool lastSweep = false);
+ bool shouldRunGC() const;
public:
QV4::ExecutionEngine *engine;
- QScopedPointer<Data> m_d;
+ ChunkAllocator *chunkAllocator;
+ StackAllocator<Heap::CallContext> stackAllocator;
+ BlockAllocator blockAllocator;
+ HugeItemAllocator hugeItemAllocator;
PersistentValueStorage *m_persistentValues;
PersistentValueStorage *m_weakValues;
QVector<Value *> m_pendingFreedObjectWrapperValue;
+
+ std::size_t unmanagedHeapSize = 0; // the amount of bytes of heap that is not managed by the memory manager, but which is held onto by managed items.
+ std::size_t unmanagedHeapSizeGCLimit;
+
+ bool gcBlocked = false;
+ bool aggressiveGC = false;
+ bool gcStats = false;
};
}
diff --git a/src/qml/memory/qv4mmdefs_p.h b/src/qml/memory/qv4mmdefs_p.h
new file mode 100644
index 0000000000..588ae21ee0
--- /dev/null
+++ b/src/qml/memory/qv4mmdefs_p.h
@@ -0,0 +1,262 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QV4MMDEFS_P_H
+#define QV4MMDEFS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qv4global_p.h>
+#include <QtCore/qalgorithms.h>
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QV4 {
+
+/*
+ * Chunks are the basic structure containing GC managed objects.
+ *
+ * Chunks are 64k aligned in memory, so that retrieving the Chunk pointer from a Heap object
+ * is a simple masking operation. Each Chunk has 4 bitmaps for managing purposes,
+ * and 32byte wide slots for the objects following afterwards.
+ *
+ * The gray and black bitmaps are used for mark/sweep.
+ * The object bitmap has a bit set if this location represents the start of a Heap object.
+ * The extends bitmap denotes the extend of an object. It has a cleared bit at the start of the object
+ * and a set bit for all following slots used by the object.
+ *
+ * Free memory has both used and extends bits set to 0.
+ *
+ * This gives the following operations when allocating an object of size s:
+ * Find s/Alignment consecutive free slots in the chunk. Set the object bit for the first
+ * slot to 1. Set the extends bits for all following slots to 1.
+ *
+ * All used slots can be found by object|extents.
+ *
+ * When sweeping, simply copy the black bits over to the object bits.
+ *
+ */
+struct HeapItem;
+struct Chunk {
+ enum {
+ ChunkSize = 64*1024,
+ ChunkShift = 16,
+ SlotSize = 32,
+ SlotSizeShift = 5,
+ NumSlots = ChunkSize/SlotSize,
+ BitmapSize = NumSlots/8,
+ HeaderSize = 4*BitmapSize,
+ DataSize = ChunkSize - HeaderSize,
+ AvailableSlots = DataSize/SlotSize,
+#if QT_POINTER_SIZE == 8
+ Bits = 64,
+ BitShift = 6,
+#else
+ Bits = 32,
+ BitShift = 5,
+#endif
+ EntriesInBitmap = BitmapSize/sizeof(quintptr)
+ };
+ quintptr grayBitmap[BitmapSize/sizeof(quintptr)];
+ quintptr blackBitmap[BitmapSize/sizeof(quintptr)];
+ quintptr objectBitmap[BitmapSize/sizeof(quintptr)];
+ quintptr extendsBitmap[BitmapSize/sizeof(quintptr)];
+ char data[ChunkSize - HeaderSize];
+
+ HeapItem *realBase();
+ HeapItem *first();
+
+ static void setBit(quintptr *bitmap, size_t index) {
+// Q_ASSERT(index >= HeaderSize/SlotSize && index < ChunkSize/SlotSize);
+ bitmap += index >> BitShift;
+ quintptr bit = static_cast<quintptr>(1) << (index & (Bits - 1));
+ *bitmap |= bit;
+ }
+ static void clearBit(quintptr *bitmap, size_t index) {
+// Q_ASSERT(index >= HeaderSize/SlotSize && index < ChunkSize/SlotSize);
+ bitmap += index >> BitShift;
+ quintptr bit = static_cast<quintptr>(1) << (index & (Bits - 1));
+ *bitmap &= ~bit;
+ }
+ static bool testBit(quintptr *bitmap, size_t index) {
+// Q_ASSERT(index >= HeaderSize/SlotSize && index < ChunkSize/SlotSize);
+ bitmap += index >> BitShift;
+ quintptr bit = static_cast<quintptr>(1) << (index & (Bits - 1));
+ return (*bitmap & bit);
+ }
+ static void setBits(quintptr *bitmap, size_t index, size_t nBits) {
+// Q_ASSERT(index >= HeaderSize/SlotSize && index + nBits <= ChunkSize/SlotSize);
+ if (!nBits)
+ return;
+ bitmap += index >> BitShift;
+ index &= (Bits - 1);
+ while (1) {
+ size_t bitsToSet = qMin(nBits, Bits - index);
+ quintptr mask = static_cast<quintptr>(-1) >> (Bits - bitsToSet) << index;
+ *bitmap |= mask;
+ nBits -= bitsToSet;
+ if (!nBits)
+ return;
+ index = 0;
+ ++bitmap;
+ }
+ }
+ static bool hasNonZeroBit(quintptr *bitmap) {
+ for (uint i = 0; i < EntriesInBitmap; ++i)
+ if (bitmap[i])
+ return true;
+ return false;
+ }
+ static uint lowestNonZeroBit(quintptr *bitmap) {
+ for (uint i = 0; i < EntriesInBitmap; ++i) {
+ if (bitmap[i]) {
+ quintptr b = bitmap[i];
+ return i*Bits + qCountTrailingZeroBits(b);
+ }
+ }
+ return 0;
+ }
+
+ uint nFreeSlots() const {
+ return AvailableSlots - nUsedSlots();
+ }
+ uint nUsedSlots() const {
+ uint usedSlots = 0;
+ for (uint i = 0; i < EntriesInBitmap; ++i) {
+ quintptr used = objectBitmap[i] | extendsBitmap[i];
+ usedSlots += qPopulationCount(used);
+ }
+ return usedSlots;
+ }
+
+ void sweep();
+ void freeAll();
+
+ void sortIntoBins(HeapItem **bins, uint nBins);
+};
+
+struct HeapItem {
+ union {
+ struct {
+ HeapItem *next;
+ size_t availableSlots;
+ } freeData;
+ quint64 payload[Chunk::SlotSize/sizeof(quint64)];
+ };
+ operator Heap::Base *() { return reinterpret_cast<Heap::Base *>(this); }
+
+ template<typename T>
+ T *as() { return static_cast<T *>(reinterpret_cast<Heap::Base *>(this)); }
+
+ Chunk *chunk() const {
+ return reinterpret_cast<Chunk *>(reinterpret_cast<quintptr>(this) >> Chunk::ChunkShift << Chunk::ChunkShift);
+ }
+
+ bool isGray() const {
+ Chunk *c = chunk();
+ uint index = this - c->realBase();
+ return Chunk::testBit(c->grayBitmap, index);
+ }
+ bool isBlack() const {
+ Chunk *c = chunk();
+ uint index = this - c->realBase();
+ return Chunk::testBit(c->blackBitmap, index);
+ }
+ bool isInUse() const {
+ Chunk *c = chunk();
+ uint index = this - c->realBase();
+ return Chunk::testBit(c->objectBitmap, index);
+ }
+
+ void setAllocatedSlots(size_t nSlots) {
+// Q_ASSERT(size && !(size % sizeof(HeapItem)));
+ Chunk *c = chunk();
+ size_t index = this - c->realBase();
+// Q_ASSERT(!Chunk::testBit(c->objectBitmap, index));
+ Chunk::setBit(c->objectBitmap, index);
+ Chunk::setBits(c->extendsBitmap, index + 1, nSlots - 1);
+// for (uint i = index + 1; i < nBits - 1; ++i)
+// Q_ASSERT(Chunk::testBit(c->extendsBitmap, i));
+// Q_ASSERT(!Chunk::testBit(c->extendsBitmap, index));
+ }
+
+ // Doesn't report correctly for huge items
+ size_t size() const {
+ Chunk *c = chunk();
+ uint index = this - c->realBase();
+ Q_ASSERT(Chunk::testBit(c->objectBitmap, index));
+ // ### optimize me
+ uint end = index + 1;
+ while (end < Chunk::NumSlots && Chunk::testBit(c->extendsBitmap, end))
+ ++end;
+ return (end - index)*sizeof(HeapItem);
+ }
+};
+
+inline HeapItem *Chunk::realBase()
+{
+ return reinterpret_cast<HeapItem *>(this);
+}
+
+inline HeapItem *Chunk::first()
+{
+ return reinterpret_cast<HeapItem *>(data);
+}
+
+Q_STATIC_ASSERT(sizeof(Chunk) == Chunk::ChunkSize);
+Q_STATIC_ASSERT((1 << Chunk::ChunkShift) == Chunk::ChunkSize);
+Q_STATIC_ASSERT(1 << Chunk::SlotSizeShift == Chunk::SlotSize);
+Q_STATIC_ASSERT(sizeof(HeapItem) == Chunk::SlotSize);
+Q_STATIC_ASSERT(QT_POINTER_SIZE*8 == Chunk::Bits);
+Q_STATIC_ASSERT((1 << Chunk::BitShift) == Chunk::Bits);
+
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h
index adb87c6c4e..9b06bf3d31 100644
--- a/src/qml/parser/qqmljsast_p.h
+++ b/src/qml/parser/qqmljsast_p.h
@@ -253,7 +253,7 @@ class QML_PARSER_EXPORT ExpressionNode: public Node
public:
ExpressionNode() {}
- virtual ExpressionNode *expressionCast();
+ ExpressionNode *expressionCast() override;
};
class QML_PARSER_EXPORT Statement: public Node
@@ -261,7 +261,7 @@ class QML_PARSER_EXPORT Statement: public Node
public:
Statement() {}
- virtual Statement *statementCast();
+ Statement *statementCast() override;
};
class QML_PARSER_EXPORT NestedExpression: public ExpressionNode
@@ -273,12 +273,12 @@ public:
: expression(expression)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return lparenToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return rparenToken; }
// attributes
@@ -294,12 +294,12 @@ public:
ThisExpression() { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return thisToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return thisToken; }
// attributes
@@ -314,12 +314,12 @@ public:
IdentifierExpression(const QStringRef &n):
name (n) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return identifierToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return identifierToken; }
// attributes
@@ -334,12 +334,12 @@ public:
NullExpression() { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return nullToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return nullToken; }
// attributes
@@ -353,12 +353,12 @@ public:
TrueLiteral() { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return trueToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return trueToken; }
// attributes
@@ -372,12 +372,12 @@ public:
FalseLiteral() { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return falseToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return falseToken; }
// attributes
@@ -392,12 +392,12 @@ public:
NumericLiteral(double v):
value(v) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return literalToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return literalToken; }
// attributes:
@@ -413,12 +413,12 @@ public:
StringLiteral(const QStringRef &v):
value (v) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return literalToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return literalToken; }
// attributes:
@@ -434,12 +434,12 @@ public:
RegExpLiteral(const QStringRef &p, int f):
pattern (p), flags (f) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return literalToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return literalToken; }
// attributes:
@@ -465,12 +465,12 @@ public:
elements (elts), elision (e)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return lbracketToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return rbracketToken; }
// attributes
@@ -492,12 +492,12 @@ public:
ObjectLiteral(PropertyAssignmentList *plist):
properties (plist) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return lbraceToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return rbraceToken; }
// attributes
@@ -521,12 +521,12 @@ public:
previous->next = this;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return commaToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return next ? next->lastSourceLocation() : commaToken; }
inline Elision *finish ()
@@ -565,16 +565,16 @@ public:
return front;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{
if (elision)
return elision->firstSourceLocation();
return expression->firstSourceLocation();
}
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{
if (next)
return next->lastSourceLocation();
@@ -595,10 +595,10 @@ public:
PropertyName() { kind = K; }
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return propertyNameToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return propertyNameToken; }
virtual QString asString() const = 0;
@@ -642,12 +642,12 @@ public:
return front;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return assignment->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return next ? next->lastSourceLocation() : assignment->lastSourceLocation(); }
// attributes
@@ -665,12 +665,12 @@ public:
: PropertyAssignment(n), value(v)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return name->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return value->lastSourceLocation(); }
// attributes
@@ -697,12 +697,12 @@ public:
: PropertyAssignment(n), type(Setter), formals(f), functionBody (b)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return getSetToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return rbraceToken; }
// attributes
@@ -724,9 +724,9 @@ public:
IdentifierPropertyName(const QStringRef &n):
id (n) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual QString asString() const { return id.toString(); }
+ QString asString() const override { return id.toString(); }
// attributes
QStringRef id;
@@ -740,9 +740,9 @@ public:
StringLiteralPropertyName(const QStringRef &n):
id (n) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual QString asString() const { return id.toString(); }
+ QString asString() const override { return id.toString(); }
// attributes
QStringRef id;
@@ -756,9 +756,9 @@ public:
NumericLiteralPropertyName(double n):
id (n) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual QString asString() const { return QString::number(id, 'g', 16); }
+ QString asString() const override { return QString::number(id, 'g', 16); }
// attributes
double id;
@@ -773,12 +773,12 @@ public:
base (b), expression (e)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return base->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return rbracketToken; }
// attributes
@@ -797,12 +797,12 @@ public:
base (b), name (n)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return base->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return identifierToken; }
// attributes
@@ -821,12 +821,12 @@ public:
base (b), arguments (a)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return newToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return rparenToken; }
// attributes
@@ -845,12 +845,12 @@ public:
NewExpression(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return newToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return expression->lastSourceLocation(); }
// attributes
@@ -867,12 +867,12 @@ public:
base (b), arguments (a)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return base->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return rparenToken; }
// attributes
@@ -899,12 +899,12 @@ public:
previous->next = this;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return expression->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{
if (next)
return next->lastSourceLocation();
@@ -932,12 +932,12 @@ public:
PostIncrementExpression(ExpressionNode *b):
base (b) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return base->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return incrementToken; }
// attributes
@@ -953,12 +953,12 @@ public:
PostDecrementExpression(ExpressionNode *b):
base (b) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return base->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return decrementToken; }
// attributes
@@ -974,12 +974,12 @@ public:
DeleteExpression(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return deleteToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return expression->lastSourceLocation(); }
// attributes
@@ -995,12 +995,12 @@ public:
VoidExpression(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return voidToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return expression->lastSourceLocation(); }
// attributes
@@ -1016,12 +1016,12 @@ public:
TypeOfExpression(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return typeofToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return expression->lastSourceLocation(); }
// attributes
@@ -1037,12 +1037,12 @@ public:
PreIncrementExpression(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return incrementToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return expression->lastSourceLocation(); }
// attributes
@@ -1058,12 +1058,12 @@ public:
PreDecrementExpression(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return decrementToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return expression->lastSourceLocation(); }
// attributes
@@ -1079,12 +1079,12 @@ public:
UnaryPlusExpression(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return plusToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return expression->lastSourceLocation(); }
// attributes
@@ -1100,12 +1100,12 @@ public:
UnaryMinusExpression(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return minusToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return expression->lastSourceLocation(); }
// attributes
@@ -1121,12 +1121,12 @@ public:
TildeExpression(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return tildeToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return expression->lastSourceLocation(); }
// attributes
@@ -1142,12 +1142,12 @@ public:
NotExpression(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return notToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return expression->lastSourceLocation(); }
// attributes
@@ -1164,14 +1164,14 @@ public:
left (l), op (o), right (r)
{ kind = K; }
- virtual BinaryExpression *binaryExpressionCast();
+ BinaryExpression *binaryExpressionCast() override;
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return left->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return right->lastSourceLocation(); }
// attributes
@@ -1190,12 +1190,12 @@ public:
expression (e), ok (t), ko (f)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return expression->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return ko->lastSourceLocation(); }
// attributes
@@ -1214,12 +1214,12 @@ public:
Expression(ExpressionNode *l, ExpressionNode *r):
left (l), right (r) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return left->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return right->lastSourceLocation(); }
// attributes
@@ -1236,12 +1236,12 @@ public:
Block(StatementList *slist):
statements (slist) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return lbraceToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return rbraceToken; }
// attributes
@@ -1267,12 +1267,12 @@ public:
previous->next = this;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return statement->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return next ? next->lastSourceLocation() : statement->lastSourceLocation(); }
inline StatementList *finish ()
@@ -1296,12 +1296,12 @@ public:
declarations (vlist)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return declarationKindToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
// attributes
@@ -1319,12 +1319,12 @@ public:
name (n), expression (e), readOnly(false)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return identifierToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return expression ? expression->lastSourceLocation() : identifierToken; }
// attributes
@@ -1351,12 +1351,12 @@ public:
previous->next = this;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return declaration->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{
if (next)
return next->lastSourceLocation();
@@ -1388,12 +1388,12 @@ public:
EmptyStatement() { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return semicolonToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
// attributes
@@ -1408,12 +1408,12 @@ public:
ExpressionStatement(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return expression->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
// attributes
@@ -1430,12 +1430,12 @@ public:
expression (e), ok (t), ko (f)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return ifToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{
if (ko)
return ko->lastSourceLocation();
@@ -1462,12 +1462,12 @@ public:
statement (stmt), expression (e)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return doToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
// attributes
@@ -1489,12 +1489,12 @@ public:
expression (e), statement (stmt)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return whileToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statement->lastSourceLocation(); }
// attributes
@@ -1514,12 +1514,12 @@ public:
initialiser (i), condition (c), expression (e), statement (stmt)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return forToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statement->lastSourceLocation(); }
// attributes
@@ -1543,12 +1543,12 @@ public:
declarations (vlist), condition (c), expression (e), statement (stmt)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return forToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statement->lastSourceLocation(); }
// attributes
@@ -1573,12 +1573,12 @@ public:
initialiser (i), expression (e), statement (stmt)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return forToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statement->lastSourceLocation(); }
// attributes
@@ -1600,12 +1600,12 @@ public:
declaration (v), expression (e), statement (stmt)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return forToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statement->lastSourceLocation(); }
// attributes
@@ -1627,12 +1627,12 @@ public:
ContinueStatement(const QStringRef &l = QStringRef()):
label (l) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return continueToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
// attributes
@@ -1650,12 +1650,12 @@ public:
BreakStatement(const QStringRef &l):
label (l) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return breakToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
// attributes
@@ -1673,12 +1673,12 @@ public:
ReturnStatement(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return returnToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
// attributes
@@ -1696,12 +1696,12 @@ public:
expression (e), statement (stmt)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return withToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statement->lastSourceLocation(); }
// attributes
@@ -1721,12 +1721,12 @@ public:
clauses (c), defaultClause (d), moreClauses (r)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return lbraceToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return rbraceToken; }
// attributes
@@ -1746,12 +1746,12 @@ public:
expression (e), block (b)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return switchToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return block->rbraceToken; }
// attributes
@@ -1771,12 +1771,12 @@ public:
expression (e), statements (slist)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return caseToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statements ? statements->lastSourceLocation() : colonToken; }
// attributes
@@ -1803,12 +1803,12 @@ public:
previous->next = this;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return clause->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return next ? next->lastSourceLocation() : clause->lastSourceLocation(); }
inline CaseClauses *finish ()
@@ -1832,12 +1832,12 @@ public:
statements (slist)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return defaultToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statements ? statements->lastSourceLocation() : colonToken; }
// attributes
@@ -1855,12 +1855,12 @@ public:
label (l), statement (stmt)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return identifierToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statement->lastSourceLocation(); }
// attributes
@@ -1878,12 +1878,12 @@ public:
ThrowStatement(ExpressionNode *e):
expression (e) { kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return throwToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
// attributes
@@ -1901,12 +1901,12 @@ public:
name (n), statement (stmt)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return catchToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statement->lastSourceLocation(); }
// attributes
@@ -1927,12 +1927,12 @@ public:
statement (stmt)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return finallyToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statement ? statement->lastSourceLocation() : finallyToken; }
// attributes
@@ -1957,12 +1957,12 @@ public:
statement (stmt), catchExpression (c), finallyExpression (0)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return tryToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{
if (finallyExpression)
return finallyExpression->statement->rbraceToken;
@@ -1988,12 +1988,12 @@ public:
name (n), formals (f), body (b)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return functionToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return rbraceToken; }
// attributes
@@ -2017,7 +2017,7 @@ public:
FunctionExpression(n, f, b)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
};
class QML_PARSER_EXPORT FormalParameterList: public Node
@@ -2037,12 +2037,12 @@ public:
previous->next = this;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return identifierToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return next ? next->lastSourceLocation() : identifierToken; }
inline FormalParameterList *finish ()
@@ -2085,12 +2085,12 @@ public:
previous->next = this;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return element->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return next ? next->lastSourceLocation() : element->lastSourceLocation(); }
inline SourceElements *finish ()
@@ -2114,12 +2114,12 @@ public:
elements (elts)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return elements ? elements->firstSourceLocation() : SourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return elements ? elements->lastSourceLocation() : SourceLocation(); }
// attributes
@@ -2135,12 +2135,12 @@ public:
elements (elts)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return elements ? elements->firstSourceLocation() : SourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return elements ? elements->lastSourceLocation() : SourceLocation(); }
// attributes
@@ -2156,12 +2156,12 @@ public:
declaration (f)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return declaration->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return declaration->lastSourceLocation(); }
// attributes
@@ -2177,12 +2177,12 @@ public:
statement (stmt)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return statement->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statement->lastSourceLocation(); }
// attributes
@@ -2197,12 +2197,12 @@ public:
DebuggerStatement()
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return debuggerToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
// attributes
@@ -2234,12 +2234,12 @@ public:
return head;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return identifierToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return next ? next->lastSourceLocation() : identifierToken; }
// attributes
@@ -2261,12 +2261,12 @@ public:
: importUri(uri)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return importToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
// attributes
@@ -2284,10 +2284,10 @@ public:
class QML_PARSER_EXPORT UiObjectMember: public Node
{
public:
- virtual SourceLocation firstSourceLocation() const = 0;
- virtual SourceLocation lastSourceLocation() const = 0;
+ SourceLocation firstSourceLocation() const override = 0;
+ SourceLocation lastSourceLocation() const override = 0;
- virtual UiObjectMember *uiObjectMemberCast();
+ UiObjectMember *uiObjectMemberCast() override;
};
class QML_PARSER_EXPORT UiObjectMemberList: public Node
@@ -2307,12 +2307,12 @@ public:
previous->next = this;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return member->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return next ? next->lastSourceLocation() : member->lastSourceLocation(); }
UiObjectMemberList *finish()
@@ -2351,12 +2351,12 @@ public:
return head;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return identifierToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return next ? next->lastSourceLocation() : identifierToken; }
// attributes
@@ -2374,12 +2374,12 @@ public:
: pragmaType(type)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return pragmaToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return semicolonToken; }
// attributes
@@ -2424,12 +2424,12 @@ public:
return head;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return headerItem->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return next ? next->lastSourceLocation() : headerItem->lastSourceLocation(); }
// attributes
@@ -2446,9 +2446,9 @@ public:
: headers(headers), members(members)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{
if (headers)
return headers->firstSourceLocation();
@@ -2457,7 +2457,7 @@ public:
return SourceLocation();
}
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{
if (members)
return members->lastSourceLocation();
@@ -2488,12 +2488,12 @@ public:
previous->next = this;
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return member->firstSourceLocation(); }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return next ? next->lastSourceLocation() : member->lastSourceLocation(); }
UiArrayMemberList *finish()
@@ -2518,12 +2518,12 @@ public:
: members(members)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return lbraceToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return rbraceToken; }
// attributes
@@ -2549,12 +2549,12 @@ public:
previous->next = this;
}
- virtual void accept0(Visitor *);
+ void accept0(Visitor *) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return propertyTypeToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return next ? next->lastSourceLocation() : identifierToken; }
inline UiParameterList *finish ()
@@ -2589,9 +2589,9 @@ public:
: type(Property), memberType(memberType), name(name), statement(statement), binding(0), isDefaultMember(false), isReadonlyMember(false), parameters(0)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{
if (defaultToken.isValid())
return defaultToken;
@@ -2601,7 +2601,7 @@ public:
return propertyToken;
}
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{
if (binding)
return binding->lastSourceLocation();
@@ -2641,12 +2641,12 @@ public:
: qualifiedTypeNameId(qualifiedTypeNameId), initializer(initializer)
{ kind = K; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return qualifiedTypeNameId->identifierToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return initializer->rbraceToken; }
// attributes
@@ -2663,7 +2663,7 @@ public:
: sourceElement(sourceElement)
{ kind = K; }
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{
if (FunctionDeclaration *funDecl = cast<FunctionDeclaration *>(sourceElement))
return funDecl->firstSourceLocation();
@@ -2673,7 +2673,7 @@ public:
return SourceLocation();
}
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{
if (FunctionDeclaration *funDecl = cast<FunctionDeclaration *>(sourceElement))
return funDecl->lastSourceLocation();
@@ -2683,7 +2683,7 @@ public:
return SourceLocation();
}
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
// attributes
@@ -2704,7 +2704,7 @@ public:
hasOnToken(false)
{ kind = K; }
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{
if (hasOnToken && qualifiedTypeNameId)
return qualifiedTypeNameId->identifierToken;
@@ -2712,10 +2712,10 @@ public:
return qualifiedId->identifierToken;
}
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return initializer->rbraceToken; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
// attributes
@@ -2737,13 +2737,13 @@ public:
statement(statement)
{ kind = K; }
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return qualifiedId->identifierToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return statement->lastSourceLocation(); }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
// attributes
UiQualifiedId *qualifiedId;
@@ -2762,13 +2762,13 @@ public:
members(members)
{ kind = K; }
- virtual SourceLocation firstSourceLocation() const
+ SourceLocation firstSourceLocation() const override
{ return qualifiedId->identifierToken; }
- virtual SourceLocation lastSourceLocation() const
+ SourceLocation lastSourceLocation() const override
{ return rbracketToken; }
- virtual void accept0(Visitor *visitor);
+ void accept0(Visitor *visitor) override;
// attributes
UiQualifiedId *qualifiedId;
diff --git a/src/qml/qml.pro b/src/qml/qml.pro
index 826a074701..8f9e4b7f83 100644
--- a/src/qml/qml.pro
+++ b/src/qml/qml.pro
@@ -14,6 +14,8 @@ solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2
# Ensure this gcc optimization is switched off for mips platforms to avoid trouble with JIT.
gcc:isEqual(QT_ARCH, "mips"): QMAKE_CXXFLAGS += -fno-reorder-blocks
+DEFINES += QT_NO_FOREACH
+
exists("qqml_enable_gcov") {
QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -fno-elide-constructors
LIBS_PRIVATE += -lgcov
diff --git a/src/qml/qml/ftw/qqmlthread.cpp b/src/qml/qml/ftw/qqmlthread.cpp
index 1523817c9e..ffa6e29290 100644
--- a/src/qml/qml/ftw/qqmlthread.cpp
+++ b/src/qml/qml/ftw/qqmlthread.cpp
@@ -55,7 +55,7 @@ public:
QQmlThreadPrivate(QQmlThread *);
QQmlThread *q;
- virtual void run();
+ void run() override;
inline void lock() { _mutex.lock(); }
inline void unlock() { _mutex.unlock(); }
@@ -81,12 +81,12 @@ public:
void threadEvent();
protected:
- virtual bool event(QEvent *);
+ bool event(QEvent *) override;
private:
struct MainObject : public QObject {
MainObject(QQmlThreadPrivate *p);
- virtual bool event(QEvent *e);
+ bool event(QEvent *e) override;
QQmlThreadPrivate *p;
};
MainObject m_mainObject;
diff --git a/src/qml/qml/ftw/qqmlthread_p.h b/src/qml/qml/ftw/qqmlthread_p.h
index 9f180b1f14..295235e255 100644
--- a/src/qml/qml/ftw/qqmlthread_p.h
+++ b/src/qml/qml/ftw/qqmlthread_p.h
@@ -142,7 +142,7 @@ void QQmlThread::callMethodInThread(void (O::*Member)())
struct I : public Message {
void (O::*Member)();
I(void (O::*Member)()) : Member(Member) {}
- virtual void call(QQmlThread *thread) {
+ void call(QQmlThread *thread) override {
O *me = static_cast<O *>(thread);
(me->*Member)();
}
@@ -157,7 +157,7 @@ void QQmlThread::callMethodInThread(void (O::*Member)(V), const T &arg)
void (O::*Member)(V);
T arg;
I(void (O::*Member)(V), const T &arg) : Member(Member), arg(arg) {}
- virtual void call(QQmlThread *thread) {
+ void call(QQmlThread *thread) override {
O *me = static_cast<O *>(thread);
(me->*Member)(arg);
}
@@ -173,7 +173,7 @@ void QQmlThread::callMethodInThread(void (O::*Member)(V, V2), const T &arg, cons
T arg;
T2 arg2;
I(void (O::*Member)(V, V2), const T &arg, const T2 &arg2) : Member(Member), arg(arg), arg2(arg2) {}
- virtual void call(QQmlThread *thread) {
+ void call(QQmlThread *thread) override {
O *me = static_cast<O *>(thread);
(me->*Member)(arg, arg2);
}
@@ -187,7 +187,7 @@ void QQmlThread::callMethodInMain(void (O::*Member)())
struct I : public Message {
void (O::*Member)();
I(void (O::*Member)()) : Member(Member) {}
- virtual void call(QQmlThread *thread) {
+ void call(QQmlThread *thread) override {
O *me = static_cast<O *>(thread);
(me->*Member)();
}
@@ -202,7 +202,7 @@ void QQmlThread::callMethodInMain(void (O::*Member)(V), const T &arg)
void (O::*Member)(V);
T arg;
I(void (O::*Member)(V), const T &arg) : Member(Member), arg(arg) {}
- virtual void call(QQmlThread *thread) {
+ void call(QQmlThread *thread) override {
O *me = static_cast<O *>(thread);
(me->*Member)(arg);
}
@@ -218,7 +218,7 @@ void QQmlThread::callMethodInMain(void (O::*Member)(V, V2), const T &arg, const
T arg;
T2 arg2;
I(void (O::*Member)(V, V2), const T &arg, const T2 &arg2) : Member(Member), arg(arg), arg2(arg2) {}
- virtual void call(QQmlThread *thread) {
+ void call(QQmlThread *thread) override {
O *me = static_cast<O *>(thread);
(me->*Member)(arg, arg2);
}
@@ -232,7 +232,7 @@ void QQmlThread::postMethodToThread(void (O::*Member)())
struct I : public Message {
void (O::*Member)();
I(void (O::*Member)()) : Member(Member) {}
- virtual void call(QQmlThread *thread) {
+ void call(QQmlThread *thread) override {
O *me = static_cast<O *>(thread);
(me->*Member)();
}
@@ -247,7 +247,7 @@ void QQmlThread::postMethodToThread(void (O::*Member)(V), const T &arg)
void (O::*Member)(V);
T arg;
I(void (O::*Member)(V), const T &arg) : Member(Member), arg(arg) {}
- virtual void call(QQmlThread *thread) {
+ void call(QQmlThread *thread) override {
O *me = static_cast<O *>(thread);
(me->*Member)(arg);
}
@@ -263,7 +263,7 @@ void QQmlThread::postMethodToThread(void (O::*Member)(V, V2), const T &arg, cons
T arg;
T2 arg2;
I(void (O::*Member)(V, V2), const T &arg, const T2 &arg2) : Member(Member), arg(arg), arg2(arg2) {}
- virtual void call(QQmlThread *thread) {
+ void call(QQmlThread *thread) override {
O *me = static_cast<O *>(thread);
(me->*Member)(arg, arg2);
}
@@ -277,7 +277,7 @@ void QQmlThread::postMethodToMain(void (O::*Member)())
struct I : public Message {
void (O::*Member)();
I(void (O::*Member)()) : Member(Member) {}
- virtual void call(QQmlThread *thread) {
+ void call(QQmlThread *thread) override {
O *me = static_cast<O *>(thread);
(me->*Member)();
}
@@ -292,7 +292,7 @@ void QQmlThread::postMethodToMain(void (O::*Member)(V), const T &arg)
void (O::*Member)(V);
T arg;
I(void (O::*Member)(V), const T &arg) : Member(Member), arg(arg) {}
- virtual void call(QQmlThread *thread) {
+ void call(QQmlThread *thread) override {
O *me = static_cast<O *>(thread);
(me->*Member)(arg);
}
@@ -308,7 +308,7 @@ void QQmlThread::postMethodToMain(void (O::*Member)(V, V2), const T &arg, const
T arg;
T2 arg2;
I(void (O::*Member)(V, V2), const T &arg, const T2 &arg2) : Member(Member), arg(arg), arg2(arg2) {}
- virtual void call(QQmlThread *thread) {
+ void call(QQmlThread *thread) override {
O *me = static_cast<O *>(thread);
(me->*Member)(arg, arg2);
}
diff --git a/src/qml/qml/qqml.h b/src/qml/qml/qqml.h
index 39764b8001..ddb4af0b81 100644
--- a/src/qml/qml/qqml.h
+++ b/src/qml/qml/qqml.h
@@ -238,6 +238,44 @@ int qmlRegisterExtendedUncreatableType(const char *uri, int versionMajor, int ve
return QQmlPrivate::qmlregister(QQmlPrivate::TypeRegistration, &type);
}
+template<typename T, typename E, int metaObjectRevision>
+int qmlRegisterExtendedUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason)
+{
+ QML_GETTYPENAMES
+
+ QQmlAttachedPropertiesFunc attached = QQmlPrivate::attachedPropertiesFunc<E>();
+ const QMetaObject * attachedMetaObject = QQmlPrivate::attachedPropertiesMetaObject<E>();
+ if (!attached) {
+ attached = QQmlPrivate::attachedPropertiesFunc<T>();
+ attachedMetaObject = QQmlPrivate::attachedPropertiesMetaObject<T>();
+ }
+
+ QQmlPrivate::RegisterType type = {
+ 1,
+
+ qRegisterNormalizedMetaType<T *>(pointerName.constData()),
+ qRegisterNormalizedMetaType<QQmlListProperty<T> >(listName.constData()),
+ 0,
+ Q_NULLPTR,
+ reason,
+
+ uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
+
+ attached,
+ attachedMetaObject,
+
+ QQmlPrivate::StaticCastSelector<T,QQmlParserStatus>::cast(),
+ QQmlPrivate::StaticCastSelector<T,QQmlPropertyValueSource>::cast(),
+ QQmlPrivate::StaticCastSelector<T,QQmlPropertyValueInterceptor>::cast(),
+
+ QQmlPrivate::createParent<E>, &E::staticMetaObject,
+
+ Q_NULLPTR,
+ metaObjectRevision
+ };
+
+ return QQmlPrivate::qmlregister(QQmlPrivate::TypeRegistration, &type);
+}
Q_QML_EXPORT int qmlRegisterUncreatableMetaObject(const QMetaObject &staticMetaObject, const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason);
@@ -526,6 +564,7 @@ QT_WARNING_POP
//The C++ version of protected namespaces in qmldir
Q_QML_EXPORT bool qmlProtectModule(const char* uri, int majVersion);
+Q_QML_EXPORT void qmlRegisterModule(const char *uri, int versionMajor, int versionMinor);
template<typename T>
QObject *qmlAttachedPropertiesObject(const QObject *obj, bool create = true)
diff --git a/src/qml/qml/qqmlabstractbinding.cpp b/src/qml/qml/qqmlabstractbinding.cpp
index 39d609454f..b1c320afd4 100644
--- a/src/qml/qml/qqmlabstractbinding.cpp
+++ b/src/qml/qml/qqmlabstractbinding.cpp
@@ -191,7 +191,7 @@ void QQmlAbstractBinding::removeFromObject()
void QQmlAbstractBinding::printBindingLoopError(QQmlProperty &prop)
{
- qmlInfo(prop.object()) << QString(QLatin1String("Binding loop detected for property \"%1\"")).arg(prop.name());
+ qmlWarning(prop.object()) << QString(QLatin1String("Binding loop detected for property \"%1\"")).arg(prop.name());
}
QString QQmlAbstractBinding::expression() const
diff --git a/src/qml/qml/qqmlabstracturlinterceptor.h b/src/qml/qml/qqmlabstracturlinterceptor.h
index dfb8a46027..665b37fb3a 100644
--- a/src/qml/qml/qqmlabstracturlinterceptor.h
+++ b/src/qml/qml/qqmlabstracturlinterceptor.h
@@ -47,7 +47,6 @@ QT_BEGIN_NAMESPACE
class Q_QML_EXPORT QQmlAbstractUrlInterceptor
{
- Q_FLAGS(InterceptionPoint)
public:
enum DataType { //Matches QQmlDataBlob::Type
QmlFile = 0,
diff --git a/src/qml/qml/qqmlapplicationengine.cpp b/src/qml/qml/qqmlapplicationengine.cpp
index 21a1a13687..a10dda166c 100644
--- a/src/qml/qml/qqmlapplicationengine.cpp
+++ b/src/qml/qml/qqmlapplicationengine.cpp
@@ -66,8 +66,6 @@ void QQmlApplicationEnginePrivate::cleanUp()
void QQmlApplicationEnginePrivate::init()
{
Q_Q(QQmlApplicationEngine);
- q->connect(&statusMapper, SIGNAL(mapped(QObject*)),
- q, SLOT(_q_finishLoad(QObject*)));
q->connect(q, SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit()));
q->connect(q, &QQmlApplicationEngine::exit, QCoreApplication::instance(), &QCoreApplication::exit);
#if QT_CONFIG(translation)
@@ -113,20 +111,15 @@ void QQmlApplicationEnginePrivate::startLoad(const QUrl &url, const QByteArray &
c->loadUrl(url);
if (!c->isLoading()) {
- _q_finishLoad(c);
+ finishLoad(c);
return;
}
- statusMapper.setMapping(c, c);
- q->connect(c, SIGNAL(statusChanged(QQmlComponent::Status)),
- &statusMapper, SLOT(map()));
+ QObject::connect(c, &QQmlComponent::statusChanged, q, [this, c] { this->finishLoad(c); });
}
-void QQmlApplicationEnginePrivate::_q_finishLoad(QObject *o)
+void QQmlApplicationEnginePrivate::finishLoad(QQmlComponent *c)
{
Q_Q(QQmlApplicationEngine);
- QQmlComponent *c = qobject_cast<QQmlComponent *>(o);
- if (!c)
- return;
switch (c->status()) {
case QQmlComponent::Error:
qWarning() << "QQmlApplicationEngine failed to load component";
@@ -190,9 +183,14 @@ void QQmlApplicationEnginePrivate::_q_finishLoad(QObject *o)
/*!
\fn QQmlApplicationEngine::objectCreated(QObject *object, const QUrl &url)
- This signal is emitted when an object finishes loading. If loading was successful, \a object contains a pointer to the loaded object.
- Otherwise the pointer is NULL. The \a url loaded is also provided, note that if a QString file path was initially passed to the
- QQmlApplicationEngine, this url will be the equivalent of QUrl::fromLocalFile(filePath).
+ This signal is emitted when an object finishes loading. If loading was
+ successful, \a object contains a pointer to the loaded object, otherwise
+ the pointer is NULL.
+
+ The \a url to the component the \a object came from is also provided.
+
+ \note If the path to the component was provided as a QString containing a
+ relative path, the \a url will contain a fully resolved path to the file.
*/
/*!
@@ -226,7 +224,7 @@ QQmlApplicationEngine::QQmlApplicationEngine(const QUrl &url, QObject *parent)
This is provided as a convenience, and is the same as using the empty constructor and calling load afterwards.
*/
QQmlApplicationEngine::QQmlApplicationEngine(const QString &filePath, QObject *parent)
- : QQmlApplicationEngine(QUrl::fromLocalFile(filePath), parent)
+ : QQmlApplicationEngine(QUrl::fromUserInput(filePath, QLatin1String("."), QUrl::AssumeLocalFile), parent)
{
}
@@ -265,7 +263,7 @@ void QQmlApplicationEngine::load(const QUrl &url)
void QQmlApplicationEngine::load(const QString &filePath)
{
Q_D(QQmlApplicationEngine);
- d->startLoad(QUrl::fromLocalFile(filePath));
+ d->startLoad(QUrl::fromUserInput(filePath, QLatin1String("."), QUrl::AssumeLocalFile));
}
/*!
@@ -287,14 +285,27 @@ void QQmlApplicationEngine::loadData(const QByteArray &data, const QUrl &url)
Returns a list of all the root objects instantiated by the
QQmlApplicationEngine. This will only contain objects loaded via load() or a
convenience constructor.
+
+ \note In Qt versions prior to 5.9, this function is marked as non-\c{const}.
*/
-QList<QObject *> QQmlApplicationEngine::rootObjects()
+QList<QObject *> QQmlApplicationEngine::rootObjects() const
{
- Q_D(QQmlApplicationEngine);
+ Q_D(const QQmlApplicationEngine);
return d->objects;
}
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+/*!
+ \overload
+ \internal
+*/
+QList<QObject *> QQmlApplicationEngine::rootObjects()
+{
+ return qAsConst(*this).rootObjects();
+}
+#endif // < Qt 6
+
QT_END_NAMESPACE
#include "moc_qqmlapplicationengine.cpp"
diff --git a/src/qml/qml/qqmlapplicationengine.h b/src/qml/qml/qqmlapplicationengine.h
index ff7dce5f8b..6c57f46c72 100644
--- a/src/qml/qml/qqmlapplicationengine.h
+++ b/src/qml/qml/qqmlapplicationengine.h
@@ -58,7 +58,11 @@ public:
QQmlApplicationEngine(const QString &filePath, QObject *parent = Q_NULLPTR);
~QQmlApplicationEngine();
- QList<QObject*> rootObjects();
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ QList<QObject*> rootObjects(); // ### Qt 6: remove
+#endif
+ QList<QObject*> rootObjects() const;
+
public Q_SLOTS:
void load(const QUrl &url);
void load(const QString &filePath);
@@ -70,7 +74,6 @@ Q_SIGNALS:
private:
Q_DISABLE_COPY(QQmlApplicationEngine)
Q_DECLARE_PRIVATE(QQmlApplicationEngine)
- Q_PRIVATE_SLOT(d_func(), void _q_finishLoad(QObject*))
};
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmlapplicationengine_p.h b/src/qml/qml/qqmlapplicationengine_p.h
index 8c342a43a9..4795170bed 100644
--- a/src/qml/qml/qqmlapplicationengine_p.h
+++ b/src/qml/qml/qqmlapplicationengine_p.h
@@ -42,7 +42,6 @@
#include "qqmlapplicationengine.h"
#include "qqmlengine_p.h"
-#include <QSignalMapper>
#include <QCoreApplication>
#include <QFileInfo>
#include <QLibraryInfo>
@@ -73,9 +72,8 @@ public:
void startLoad(const QUrl &url, const QByteArray &data = QByteArray(), bool dataFlag = false);
void loadTranslations(const QUrl &rootFile);
- void _q_finishLoad(QObject *component);
+ void finishLoad(QQmlComponent *component);
QList<QObject *> objects;
- QSignalMapper statusMapper;
QObject *appObj;
#if QT_CONFIG(translation)
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp
index 7505c47a25..62288a5845 100644
--- a/src/qml/qml/qqmlbinding.cpp
+++ b/src/qml/qml/qqmlbinding.cpp
@@ -420,7 +420,7 @@ QVariant QQmlBinding::evaluate()
return scope.engine->toVariant(scope.result, qMetaTypeId<QList<QObject*> >());
}
-QString QQmlBinding::expressionIdentifier()
+QString QQmlBinding::expressionIdentifier() const
{
auto f = function();
QString url = f->sourceFile();
diff --git a/src/qml/qml/qqmlbinding_p.h b/src/qml/qml/qqmlbinding_p.h
index af95bbb5db..0f2fb329f5 100644
--- a/src/qml/qml/qqmlbinding_p.h
+++ b/src/qml/qml/qqmlbinding_p.h
@@ -97,8 +97,8 @@ public:
QVariant evaluate();
- QString expressionIdentifier() Q_DECL_OVERRIDE;
- void expressionChanged() Q_DECL_OVERRIDE;
+ QString expressionIdentifier() const override;
+ void expressionChanged() override;
protected:
virtual void doUpdate(const DeleteWatcher &watcher,
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index 1fdb0d2e25..19ece44beb 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -91,7 +91,7 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index,
function += QQmlPropertyCache::signalParameterStringForJS(v4, signal.parameterNames(), &error);
if (!error.isEmpty()) {
- qmlInfo(scopeObject()) << error;
+ qmlWarning(scopeObject()) << error;
return;
}
} else
@@ -129,7 +129,7 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index,
QString error;
QQmlPropertyCache::signalParameterStringForJS(engine, signalParameters, &error);
if (!error.isEmpty()) {
- qmlInfo(scopeObject()) << error;
+ qmlWarning(scopeObject()) << error;
return;
}
runtimeFunction->updateInternalClass(engine, signalParameters);
@@ -154,7 +154,7 @@ QQmlBoundSignalExpression::~QQmlBoundSignalExpression()
{
}
-QString QQmlBoundSignalExpression::expressionIdentifier()
+QString QQmlBoundSignalExpression::expressionIdentifier() const
{
QQmlSourceLocation loc = sourceLocation();
return loc.sourceFile + QLatin1Char(':') + QString::number(loc.line);
diff --git a/src/qml/qml/qqmlboundsignal_p.h b/src/qml/qml/qqmlboundsignal_p.h
index 173c0f7288..3a0b8aed59 100644
--- a/src/qml/qml/qqmlboundsignal_p.h
+++ b/src/qml/qml/qqmlboundsignal_p.h
@@ -79,8 +79,8 @@ public:
QQmlContextData *ctxt, QObject *scope, QV4::Function *runtimeFunction);
// inherited from QQmlJavaScriptExpression.
- virtual QString expressionIdentifier();
- virtual void expressionChanged();
+ QString expressionIdentifier() const override;
+ void expressionChanged() override;
// evaluation of a bound signal expression doesn't return any value
void evaluate(void **a);
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp
index 15e09f0b85..a04f47e6a4 100644
--- a/src/qml/qml/qqmlcomponent.cpp
+++ b/src/qml/qml/qqmlcomponent.cpp
@@ -374,7 +374,7 @@ QQmlComponent::~QQmlComponent()
if (isError()) {
qWarning() << "This may have been caused by one of the following errors:";
- foreach (const QQmlError &error, d->state.errors)
+ for (const QQmlError &error : qAsConst(d->state.errors))
qWarning().nospace().noquote() << QLatin1String(" ") << error;
}
@@ -707,7 +707,7 @@ QString QQmlComponent::errorString() const
QString ret;
if(!isError())
return ret;
- foreach(const QQmlError &e, d->state.errors) {
+ for (const QQmlError &e : d->state.errors) {
ret += e.url().toString() + QLatin1Char(':') +
QString::number(e.line()) + QLatin1Char(' ') +
e.description() + QLatin1Char('\n');
@@ -1063,11 +1063,11 @@ struct QmlIncubatorObject : public QV4::Object
V4_OBJECT2(QmlIncubatorObject, Object)
V4_NEEDS_DESTROY
- static QV4::ReturnedValue method_get_statusChanged(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_statusChanged(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_status(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_object(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_forceCompletion(QV4::CallContext *ctx);
+ static void method_get_statusChanged(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_set_statusChanged(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_status(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_object(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_forceCompletion(const BuiltinFunction *, Scope &scope, CallData *callData);
static void markObjects(QV4::Heap::Base *that, QV4::ExecutionEngine *e);
@@ -1087,13 +1087,13 @@ public:
, incubatorObject(inc)
{}
- virtual void statusChanged(Status s) {
+ void statusChanged(Status s) override {
QV4::Scope scope(incubatorObject->internalClass->engine);
QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject);
i->statusChanged(s);
}
- virtual void setInitialState(QObject *o) {
+ void setInitialState(QObject *o) override {
QV4::Scope scope(incubatorObject->internalClass->engine);
QV4::Scoped<QV4::QmlIncubatorObject> i(scope, incubatorObject);
i->setInitialState(o);
@@ -1233,7 +1233,7 @@ void QQmlComponent::createObject(QQmlV4Function *args)
if (args->length() >= 2) {
QV4::ScopedValue v(scope, (*args)[1]);
if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
- qmlInfo(this) << tr("createObject: value is not an object");
+ qmlWarning(this) << tr("createObject: value is not an object");
args->setReturnValue(QV4::Encode::null());
return;
}
@@ -1350,7 +1350,7 @@ void QQmlComponent::incubateObject(QQmlV4Function *args)
QV4::ScopedValue v(scope, (*args)[1]);
if (v->isNull()) {
} else if (!v->as<QV4::Object>() || v->as<QV4::ArrayObject>()) {
- qmlInfo(this) << tr("createObject: value is not an object");
+ qmlWarning(this) << tr("createObject: value is not an object");
args->setReturnValue(QV4::Encode::null());
return;
} else {
@@ -1415,58 +1415,53 @@ QQmlComponentExtension::QQmlComponentExtension(QV4::ExecutionEngine *v4)
incubationProto.set(v4, proto);
}
-QV4::ReturnedValue QV4::QmlIncubatorObject::method_get_object(QV4::CallContext *ctx)
+void QV4::QmlIncubatorObject::method_get_object(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QmlIncubatorObject> o(scope, ctx->thisObject().as<QmlIncubatorObject>());
+ QV4::Scoped<QmlIncubatorObject> o(scope, callData->thisObject.as<QmlIncubatorObject>());
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- return QV4::QObjectWrapper::wrap(ctx->d()->engine, o->d()->incubator->object());
+ scope.result = QV4::QObjectWrapper::wrap(scope.engine, o->d()->incubator->object());
}
-QV4::ReturnedValue QV4::QmlIncubatorObject::method_forceCompletion(QV4::CallContext *ctx)
+void QV4::QmlIncubatorObject::method_forceCompletion(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QmlIncubatorObject> o(scope, ctx->thisObject().as<QmlIncubatorObject>());
+ QV4::Scoped<QmlIncubatorObject> o(scope, callData->thisObject.as<QmlIncubatorObject>());
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
o->d()->incubator->forceCompletion();
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
-QV4::ReturnedValue QV4::QmlIncubatorObject::method_get_status(QV4::CallContext *ctx)
+void QV4::QmlIncubatorObject::method_get_status(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QmlIncubatorObject> o(scope, ctx->thisObject().as<QmlIncubatorObject>());
+ QV4::Scoped<QmlIncubatorObject> o(scope, callData->thisObject.as<QmlIncubatorObject>());
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- return QV4::Encode(o->d()->incubator->status());
+ scope.result = QV4::Encode(o->d()->incubator->status());
}
-QV4::ReturnedValue QV4::QmlIncubatorObject::method_get_statusChanged(QV4::CallContext *ctx)
+void QV4::QmlIncubatorObject::method_get_statusChanged(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QmlIncubatorObject> o(scope, ctx->thisObject().as<QmlIncubatorObject>());
+ QV4::Scoped<QmlIncubatorObject> o(scope, callData->thisObject.as<QmlIncubatorObject>());
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- return o->d()->statusChanged.asReturnedValue();
+ scope.result = o->d()->statusChanged;
}
-QV4::ReturnedValue QV4::QmlIncubatorObject::method_set_statusChanged(QV4::CallContext *ctx)
+void QV4::QmlIncubatorObject::method_set_statusChanged(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QmlIncubatorObject> o(scope, ctx->thisObject().as<QmlIncubatorObject>());
- if (!o || ctx->argc() < 1)
- return ctx->engine()->throwTypeError();
+ QV4::Scoped<QmlIncubatorObject> o(scope, callData->thisObject.as<QmlIncubatorObject>());
+ if (!o || callData->argc < 1)
+ THROW_TYPE_ERROR();
+ o->d()->statusChanged = callData->args[0];
- o->d()->statusChanged = ctx->args()[0];
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
QQmlComponentExtension::~QQmlComponentExtension()
diff --git a/src/qml/qml/qqmlcomponent_p.h b/src/qml/qml/qqmlcomponent_p.h
index 3a84e724da..d01a987acc 100644
--- a/src/qml/qml/qqmlcomponent_p.h
+++ b/src/qml/qml/qqmlcomponent_p.h
@@ -89,8 +89,8 @@ public:
static void setInitialProperties(QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext, const QV4::Value &o, const QV4::Value &v);
QQmlTypeData *typeData;
- virtual void typeDataReady(QQmlTypeData *);
- virtual void typeDataProgress(QQmlTypeData *, qreal);
+ void typeDataReady(QQmlTypeData *) override;
+ void typeDataProgress(QQmlTypeData *, qreal) override;
void fromTypeData(QQmlTypeData *data);
diff --git a/src/qml/qml/qqmlcontext_p.h b/src/qml/qml/qqmlcontext_p.h
index 62cd3d4877..4d2bb72352 100644
--- a/src/qml/qml/qqmlcontext_p.h
+++ b/src/qml/qml/qqmlcontext_p.h
@@ -197,7 +197,7 @@ public:
{
inline ContextGuard();
inline ContextGuard &operator=(QObject *obj);
- inline void objectDestroyed(QObject *);
+ inline void objectDestroyed(QObject *) override;
inline bool wasSet() const;
@@ -235,7 +235,7 @@ public:
inline QQmlGuardedContextData(QQmlContextData *);
inline ~QQmlGuardedContextData();
- inline QQmlContextData *contextData();
+ inline QQmlContextData *contextData() const;
inline void setContextData(QQmlContextData *);
inline bool isNull() const { return !m_contextData; }
@@ -285,7 +285,7 @@ void QQmlGuardedContextData::setContextData(QQmlContextData *contextData)
}
}
-QQmlContextData *QQmlGuardedContextData::contextData()
+QQmlContextData *QQmlGuardedContextData::contextData() const
{
return m_contextData;
}
diff --git a/src/qml/qml/qqmlcustomparser.cpp b/src/qml/qml/qqmlcustomparser.cpp
index 85c91a592a..0b0bbef795 100644
--- a/src/qml/qml/qqmlcustomparser.cpp
+++ b/src/qml/qml/qqmlcustomparser.cpp
@@ -83,7 +83,7 @@ QT_BEGIN_NAMESPACE
by \a data, which is a block of data previously returned by a call
to compile().
- Errors should be reported using qmlInfo(object).
+ Errors should be reported using qmlWarning(object).
The \a object will be an instance of the TypeClass specified by QML_REGISTER_CUSTOM_TYPE.
*/
diff --git a/src/qml/qml/qqmldelayedcallqueue.cpp b/src/qml/qml/qqmldelayedcallqueue.cpp
index 7552e1e82b..d5d2c9a28d 100644
--- a/src/qml/qml/qqmldelayedcallqueue.cpp
+++ b/src/qml/qml/qqmldelayedcallqueue.cpp
@@ -105,17 +105,15 @@ void QQmlDelayedCallQueue::init(QV4::ExecutionEngine* engine)
m_tickedMethod = metaObject.method(methodIndex);
}
-QV4::ReturnedValue QQmlDelayedCallQueue::addUniquelyAndExecuteLater(QV4::CallContext *ctx)
+void QQmlDelayedCallQueue::addUniquelyAndExecuteLater(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- const QV4::CallData *callData = ctx->d()->callData;
-
if (callData->argc == 0)
- V4THROW_ERROR("Qt.callLater: no arguments given");
+ THROW_GENERIC_ERROR("Qt.callLater: no arguments given");
const QV4::FunctionObject *func = callData->args[0].as<QV4::FunctionObject>();
if (!func)
- V4THROW_ERROR("Qt.callLater: first argument not a function or signal");
+ THROW_GENERIC_ERROR("Qt.callLater: first argument not a function or signal");
QPair<QObject *, int> functionData = QV4::QObjectMethod::extractQtMethod(func);
@@ -171,7 +169,7 @@ QV4::ReturnedValue QQmlDelayedCallQueue::addUniquelyAndExecuteLater(QV4::CallCon
m_tickedMethod.invoke(this, Qt::QueuedConnection);
m_callbackOutstanding = true;
}
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
void QQmlDelayedCallQueue::storeAnyArguments(DelayedFunctionCall &dfc, const QV4::CallData *callData, int offset, QV4::ExecutionEngine *engine)
diff --git a/src/qml/qml/qqmldelayedcallqueue_p.h b/src/qml/qml/qqmldelayedcallqueue_p.h
index ef899170a2..cffde4f0c0 100644
--- a/src/qml/qml/qqmldelayedcallqueue_p.h
+++ b/src/qml/qml/qqmldelayedcallqueue_p.h
@@ -70,7 +70,7 @@ public:
void init(QV4::ExecutionEngine *);
- QV4::ReturnedValue addUniquelyAndExecuteLater(QV4::CallContext *ctx);
+ void addUniquelyAndExecuteLater(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
public Q_SLOTS:
void ticked();
diff --git a/src/qml/qml/qqmldirparser.cpp b/src/qml/qml/qqmldirparser.cpp
index fde7cc4cef..4cca8a4d58 100644
--- a/src/qml/qml/qqmldirparser.cpp
+++ b/src/qml/qml/qqmldirparser.cpp
@@ -188,6 +188,15 @@ bool QQmlDirParser::parse(const QString &source)
_plugins.append(entry);
+ } else if (sections[0] == QLatin1String("classname")) {
+ if (sectionCount < 2) {
+ reportError(lineNumber, 0,
+ QStringLiteral("classname directive requires an argument, but %1 were provided").arg(sectionCount - 1));
+
+ continue;
+ }
+
+ // Ignore these. qmlimportscanner uses them.
} else if (sections[0] == QLatin1String("internal")) {
if (sectionCount != 3) {
reportError(lineNumber, 0,
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index c800641f1c..86ad84b9c1 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -65,6 +65,7 @@
#include <QtCore/qmetaobject.h>
#include <QDebug>
#include <QtCore/qcoreapplication.h>
+#include <QtCore/qcryptographichash.h>
#include <QtCore/qdir.h>
#include <QtCore/qmutex.h>
#include <QtCore/qthread.h>
@@ -436,7 +437,6 @@ The following functions are also on the Qt object.
\list
\li \c "android" - Android
- \li \c "blackberry" - BlackBerry OS
\li \c "ios" - iOS
\li \c "tvos" - tvOS
\li \c "linux" - Linux
@@ -444,7 +444,6 @@ The following functions are also on the Qt object.
\li \c "unix" - Other Unix-based OS
\li \c "windows" - Windows
\li \c "winrt" - WinRT / UWP
- \li \c "winphone" - Windows Phone
\endlist
\endtable
*/
@@ -537,6 +536,10 @@ The following functions are also on the Qt object.
\li This is the application name set on the QCoreApplication instance. This property can be written
to in order to set the application name.
\row
+ \li \c application.displayName (since Qt 5.9)
+ \li This is the application display name set on the QGuiApplication instance. This property can be written
+ to in order to set the application display name.
+ \row
\li \c application.version
\li This is the application version set on the QCoreApplication instance. This property can be written
to in order to set the application version.
@@ -554,6 +557,18 @@ The following functions are also on the Qt object.
\li This read-only property can be used to determine whether or not the
platform supports multiple windows. Some embedded platforms do not support
multiple windows, for example.
+
+ \row
+ \li \c application.screens
+ \li An array containing the descriptions of all connected screens. The
+ elements of the array are objects with the same properties as the
+ \l{Screen} attached object. In practice the array corresponds to the screen
+ list returned by QGuiApplication::screens(). In addition to examining
+ properties like name, width, height, etc., the array elements can also be
+ assigned to the screen property of Window items, thus serving as an
+ alternative to the C++ side's QWindow::setScreen(). This property has been
+ added in Qt 5.9.
+
\endtable
The object also has one signal, aboutToQuit(), which is the same as \l QCoreApplication::aboutToQuit().
@@ -570,6 +585,8 @@ The following functions are also on the Qt object.
\li application.layoutDirection
\li application.font
\endlist
+
+ \sa Screen, Window, Window.screen
*/
/*!
@@ -1006,8 +1023,8 @@ QQmlEngine::~QQmlEngine()
// we do this here and not in the private dtor since otherwise a crash can
// occur (if we are the QObject parent of the QObject singleton instance)
// XXX TODO: performance -- store list of singleton types separately?
- QList<QQmlType*> singletonTypes = QQmlMetaType::qmlSingletonTypes();
- foreach (QQmlType *currType, singletonTypes)
+ const QList<QQmlType*> singletonTypes = QQmlMetaType::qmlSingletonTypes();
+ for (QQmlType *currType : singletonTypes)
currType->singletonInstanceInfo()->destroy(this);
delete d->rootContext;
@@ -1896,9 +1913,29 @@ void QQmlEnginePrivate::sendExit(int retCode)
static void dumpwarning(const QQmlError &error)
{
- QMessageLogger(error.url().toString().toLatin1().constData(),
- error.line(), 0).warning().nospace()
- << qPrintable(error.toString());
+ switch (error.messageType()) {
+ case QtDebugMsg:
+ QMessageLogger(error.url().toString().toLatin1().constData(),
+ error.line(), 0).debug().nospace()
+ << qPrintable(error.toString());
+ break;
+ case QtInfoMsg:
+ QMessageLogger(error.url().toString().toLatin1().constData(),
+ error.line(), 0).info().nospace()
+ << qPrintable(error.toString());
+ break;
+ case QtWarningMsg:
+ case QtFatalMsg: // fatal does not support streaming, and furthermore, is actually fatal. Probably not desirable for QML.
+ QMessageLogger(error.url().toString().toLatin1().constData(),
+ error.line(), 0).warning().nospace()
+ << qPrintable(error.toString());
+ break;
+ case QtCriticalMsg:
+ QMessageLogger(error.url().toString().toLatin1().constData(),
+ error.line(), 0).critical().nospace()
+ << qPrintable(error.toString());
+ break;
+ }
}
static void dumpwarning(const QList<QQmlError> &errors)
@@ -2111,8 +2148,7 @@ bool QQmlEngine::importPlugin(const QString &filePath, const QString &uri, QList
Returns the directory where SQL and other offline
storage is placed.
- QQuickWebView and the SQL databases created with openDatabase()
- are stored here.
+ The SQL databases created with openDatabase() are stored here.
The default is QML/OfflineStorage in the platform-standard
user application data directory.
@@ -2143,6 +2179,27 @@ QString QQmlEngine::offlineStoragePath() const
return d->offlineStoragePath;
}
+/*!
+ Returns the file path where a \l{QtQuick.LocalStorage}{Local Storage}
+ database with the identifier \a databaseName is (or would be) located.
+
+ \sa LocalStorage.openDatabaseSync()
+ \since 5.9
+*/
+QString QQmlEngine::offlineStorageDatabaseFilePath(const QString &databaseName) const
+{
+ Q_D(const QQmlEngine);
+ QCryptographicHash md5(QCryptographicHash::Md5);
+ md5.addData(databaseName.toUtf8());
+ return d->offlineStorageDatabaseDirectory() + QLatin1String(md5.result().toHex());
+}
+
+QString QQmlEnginePrivate::offlineStorageDatabaseDirectory() const
+{
+ Q_Q(const QQmlEngine);
+ return q->offlineStoragePath() + QDir::separator() + QLatin1String("Databases") + QDir::separator();
+}
+
QQmlPropertyCache *QQmlEnginePrivate::createCache(QQmlType *type, int minorVersion)
{
QList<QQmlType *> types;
diff --git a/src/qml/qml/qqmlengine.h b/src/qml/qml/qqmlengine.h
index 2c0c39d0b4..8cada954fe 100644
--- a/src/qml/qml/qqmlengine.h
+++ b/src/qml/qml/qqmlengine.h
@@ -136,6 +136,7 @@ public:
void setOfflineStoragePath(const QString& dir);
QString offlineStoragePath() const;
+ QString offlineStorageDatabaseFilePath(const QString &databaseName) const;
QUrl baseUrl() const;
void setBaseUrl(const QUrl &);
@@ -151,7 +152,7 @@ public:
static ObjectOwnership objectOwnership(QObject *);
protected:
QQmlEngine(QQmlEnginePrivate &dd, QObject *p);
- virtual bool event(QEvent *);
+ bool event(QEvent *) override;
Q_SIGNALS:
void quit();
diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h
index 916566b6c7..1bdeacd524 100644
--- a/src/qml/qml/qqmlengine_p.h
+++ b/src/qml/qml/qqmlengine_p.h
@@ -205,6 +205,7 @@ public:
inline void deleteInEngineThread(T *);
template<typename T>
inline static void deleteInEngineThread(QQmlEngine *, T *);
+ QString offlineStorageDatabaseDirectory() const;
// These methods may be called from the loader thread
inline QQmlPropertyCache *cache(QQmlType *, int);
diff --git a/src/qml/qml/qqmlerror.cpp b/src/qml/qml/qqmlerror.cpp
index 0a6c7b4960..7a1e02eec6 100644
--- a/src/qml/qml/qqmlerror.cpp
+++ b/src/qml/qml/qqmlerror.cpp
@@ -85,11 +85,12 @@ public:
QString description;
quint16 line;
quint16 column;
+ QtMsgType messageType;
QObject *object;
};
QQmlErrorPrivate::QQmlErrorPrivate()
-: line(0), column(0), object()
+: line(0), column(0), messageType(QtMsgType::QtWarningMsg), object()
{
}
@@ -119,12 +120,14 @@ QQmlError &QQmlError::operator=(const QQmlError &other)
delete d;
d = 0;
} else {
- if (!d) d = new QQmlErrorPrivate;
+ if (!d)
+ d = new QQmlErrorPrivate;
d->url = other.d->url;
d->description = other.d->description;
d->line = other.d->line;
d->column = other.d->column;
d->object = other.d->object;
+ d->messageType = other.d->messageType;
}
return *this;
}
@@ -150,8 +153,9 @@ bool QQmlError::isValid() const
*/
QUrl QQmlError::url() const
{
- if (d) return d->url;
- else return QUrl();
+ if (d)
+ return d->url;
+ return QUrl();
}
/*!
@@ -159,7 +163,8 @@ QUrl QQmlError::url() const
*/
void QQmlError::setUrl(const QUrl &url)
{
- if (!d) d = new QQmlErrorPrivate;
+ if (!d)
+ d = new QQmlErrorPrivate;
d->url = url;
}
@@ -168,8 +173,9 @@ void QQmlError::setUrl(const QUrl &url)
*/
QString QQmlError::description() const
{
- if (d) return d->description;
- else return QString();
+ if (d)
+ return d->description;
+ return QString();
}
/*!
@@ -177,7 +183,8 @@ QString QQmlError::description() const
*/
void QQmlError::setDescription(const QString &description)
{
- if (!d) d = new QQmlErrorPrivate;
+ if (!d)
+ d = new QQmlErrorPrivate;
d->description = description;
}
@@ -186,8 +193,9 @@ void QQmlError::setDescription(const QString &description)
*/
int QQmlError::line() const
{
- if (d) return qmlSourceCoordinate(d->line);
- else return -1;
+ if (d)
+ return qmlSourceCoordinate(d->line);
+ return -1;
}
/*!
@@ -195,7 +203,8 @@ int QQmlError::line() const
*/
void QQmlError::setLine(int line)
{
- if (!d) d = new QQmlErrorPrivate;
+ if (!d)
+ d = new QQmlErrorPrivate;
d->line = qmlSourceCoordinate(line);
}
@@ -204,8 +213,9 @@ void QQmlError::setLine(int line)
*/
int QQmlError::column() const
{
- if (d) return qmlSourceCoordinate(d->column);
- else return -1;
+ if (d)
+ return qmlSourceCoordinate(d->column);
+ return -1;
}
/*!
@@ -213,7 +223,8 @@ int QQmlError::column() const
*/
void QQmlError::setColumn(int column)
{
- if (!d) d = new QQmlErrorPrivate;
+ if (!d)
+ d = new QQmlErrorPrivate;
d->column = qmlSourceCoordinate(column);
}
@@ -225,8 +236,9 @@ void QQmlError::setColumn(int column)
*/
QObject *QQmlError::object() const
{
- if (d) return d->object;
- else return 0;
+ if (d)
+ return d->object;
+ return 0;
}
/*!
@@ -234,11 +246,37 @@ QObject *QQmlError::object() const
*/
void QQmlError::setObject(QObject *object)
{
- if (!d) d = new QQmlErrorPrivate;
+ if (!d)
+ d = new QQmlErrorPrivate;
d->object = object;
}
/*!
+ \since 5.9
+
+ Returns the message type.
+ */
+QtMsgType QQmlError::messageType() const
+{
+ if (d)
+ return d->messageType;
+ return QtMsgType::QtWarningMsg;
+}
+
+/*!
+ \since 5.9
+
+ Sets the \a messageType for this message. The message type determines which
+ QDebug handlers are responsible for recieving the message.
+ */
+void QQmlError::setMessageType(QtMsgType messageType)
+{
+ if (!d)
+ d = new QQmlErrorPrivate;
+ d->messageType = messageType;
+}
+
+/*!
Returns the error as a human readable string.
*/
QString QQmlError::toString() const
diff --git a/src/qml/qml/qqmlerror.h b/src/qml/qml/qqmlerror.h
index e4c42223cf..ef529e3828 100644
--- a/src/qml/qml/qqmlerror.h
+++ b/src/qml/qml/qqmlerror.h
@@ -47,6 +47,7 @@
QT_BEGIN_NAMESPACE
+// ### Qt 6: should this be called QQmlMessage, since it can have a message type?
class QDebug;
class QQmlErrorPrivate;
class Q_QML_EXPORT QQmlError
@@ -69,6 +70,8 @@ public:
void setColumn(int);
QObject *object() const;
void setObject(QObject *);
+ QtMsgType messageType() const;
+ void setMessageType(QtMsgType messageType);
QString toString() const;
private:
diff --git a/src/qml/qml/qqmlexpression.cpp b/src/qml/qml/qqmlexpression.cpp
index adfa1c2674..b70db5ed86 100644
--- a/src/qml/qml/qqmlexpression.cpp
+++ b/src/qml/qml/qqmlexpression.cpp
@@ -437,7 +437,7 @@ void QQmlExpressionPrivate::expressionChanged()
emit q->valueChanged();
}
-QString QQmlExpressionPrivate::expressionIdentifier()
+QString QQmlExpressionPrivate::expressionIdentifier() const
{
return QLatin1Char('"') + expression + QLatin1Char('"');
}
diff --git a/src/qml/qml/qqmlexpression_p.h b/src/qml/qml/qqmlexpression_p.h
index 809a57b169..44342a957b 100644
--- a/src/qml/qml/qqmlexpression_p.h
+++ b/src/qml/qml/qqmlexpression_p.h
@@ -85,8 +85,8 @@ public:
bool expressionFunctionValid:1;
// Inherited from QQmlJavaScriptExpression
- virtual QString expressionIdentifier();
- virtual void expressionChanged();
+ QString expressionIdentifier() const override;
+ void expressionChanged() override;
QString expression;
diff --git a/src/qml/qml/qqmlextensionplugin.h b/src/qml/qml/qqmlextensionplugin.h
index de482d0352..c0915c0abe 100644
--- a/src/qml/qml/qqmlextensionplugin.h
+++ b/src/qml/qml/qqmlextensionplugin.h
@@ -63,8 +63,8 @@ public:
QUrl baseUrl() const;
- virtual void registerTypes(const char *uri) = 0;
- virtual void initializeEngine(QQmlEngine *engine, const char *uri);
+ void registerTypes(const char *uri) override = 0;
+ void initializeEngine(QQmlEngine *engine, const char *uri) override;
private:
Q_DISABLE_COPY(QQmlExtensionPlugin)
diff --git a/src/qml/qml/qqmlfileselector_p.h b/src/qml/qml/qqmlfileselector_p.h
index 57ef194c10..a7360f83d9 100644
--- a/src/qml/qml/qqmlfileselector_p.h
+++ b/src/qml/qml/qqmlfileselector_p.h
@@ -80,7 +80,7 @@ public:
QQmlFileSelectorInterceptor(QQmlFileSelectorPrivate* pd);
QQmlFileSelectorPrivate* d;
protected:
- virtual QUrl intercept(const QUrl &path, DataType type);
+ QUrl intercept(const QUrl &path, DataType type) override;
};
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index f2cbf5a94f..c07d5c740a 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -1,5 +1,6 @@
/****************************************************************************
**
+** Copyright (C) 2017 Crimson AS <info@crimson.no>
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
@@ -57,6 +58,7 @@
#include <QtCore/qjsonarray.h>
#include <algorithm>
+#include <functional>
QT_BEGIN_NAMESPACE
@@ -129,42 +131,74 @@ bool isPathAbsolute(const QString &path)
#endif
}
-// If the type does not already exist as a file import, add the type and return the new type
-QQmlType *getTypeForUrl(const QString &urlString, const QHashedStringRef& typeName,
+/*
+ \internal
+
+ Fetches the QQmlType instance registered for \a urlString, creating a
+ registration for it if it is not already registered, using the associated
+ \a typeName, \a isCompositeSingleton, \a majorVersion and \a minorVersion
+ details.
+
+ Errors (if there are any) are placed into \a errors, if it is nonzero. Note
+ that errors are treated as fatal if \a errors is not set.
+*/
+QQmlType *fetchOrCreateTypeForUrl(const QString &urlString, const QHashedStringRef& typeName,
bool isCompositeSingleton, QList<QQmlError> *errors,
int majorVersion=-1, int minorVersion=-1)
{
- QUrl url(urlString);
+ QUrl url(urlString); // ### unfortunate (costly) conversion
QQmlType *ret = QQmlMetaType::qmlType(url);
- if (!ret) { //QQmlType not yet existing for composite or composite singleton type
- int dot = typeName.indexOf(QLatin1Char('.'));
- QHashedStringRef unqualifiedtype = dot < 0 ? typeName : QHashedStringRef(typeName.constData() + dot + 1, typeName.length() - dot - 1);
-
- //XXX: The constData of the string ref is pointing somewhere unsafe in qmlregister, so we need to create a temporary copy
- QByteArray buf(unqualifiedtype.toString().toUtf8());
-
- if (isCompositeSingleton) {
- QQmlPrivate::RegisterCompositeSingletonType reg = {
- url,
- "", //Empty URI indicates loaded via file imports
- majorVersion,
- minorVersion,
- buf.constData()
- };
- ret = QQmlMetaType::qmlTypeFromIndex(QQmlPrivate::qmlregister(QQmlPrivate::CompositeSingletonRegistration, &reg));
- } else {
- QQmlPrivate::RegisterCompositeType reg = {
- url,
- "", //Empty URI indicates loaded via file imports
- majorVersion,
- minorVersion,
- buf.constData()
- };
- ret = QQmlMetaType::qmlTypeFromIndex(QQmlPrivate::qmlregister(QQmlPrivate::CompositeRegistration, &reg));
- }
+ if (ret)
+ return ret;
+
+ int dot = typeName.indexOf(QLatin1Char('.'));
+ QHashedStringRef unqualifiedtype = dot < 0 ? typeName : QHashedStringRef(typeName.constData() + dot + 1, typeName.length() - dot - 1);
+
+ // We need a pointer, but we were passed a string. Take a copy so we
+ // can guarentee it will live long enough to reach qmlregister.
+ QByteArray buf(unqualifiedtype.toString().toUtf8());
+
+ // Register the type. Note that the URI parameters here are empty; for
+ // file type imports, we do not place them in a URI as we don't
+ // necessarily have a good and unique one (picture a library import,
+ // which may be found in multiple plugin locations on disk), but there
+ // are other reasons for this too.
+ //
+ // By not putting them in a URI, we prevent the types from being
+ // registered on a QQmlTypeModule; this is important, as once types are
+ // placed on there, they cannot be easily removed, meaning if the
+ // developer subsequently loads a different import (meaning different
+ // types) with the same URI (using, say, a different plugin path), it is
+ // very undesirable that we continue to associate the types from the
+ // "old" URI with that new module.
+ //
+ // Not having URIs also means that the types cannot be found by name
+ // etc, the only way to look them up is through QQmlImports -- for
+ // better or worse.
+ if (isCompositeSingleton) {
+ QQmlPrivate::RegisterCompositeSingletonType reg = {
+ url,
+ "", // uri
+ majorVersion,
+ minorVersion,
+ buf.constData()
+ };
+ ret = QQmlMetaType::qmlTypeFromIndex(QQmlPrivate::qmlregister(QQmlPrivate::CompositeSingletonRegistration, &reg));
+ } else {
+ QQmlPrivate::RegisterCompositeType reg = {
+ url,
+ "", // uri
+ majorVersion,
+ minorVersion,
+ buf.constData()
+ };
+ ret = QQmlMetaType::qmlTypeFromIndex(QQmlPrivate::qmlregister(QQmlPrivate::CompositeRegistration, &reg));
}
- if (!ret) {//Usually when a type name is "found" but invalid
- //qDebug() << ret << urlString << QQmlMetaType::qmlType(url);
+
+ // This means that the type couldn't be found by URL, but could not be
+ // registered either, meaning we most likely were passed some kind of bad
+ // data.
+ if (!ret) {
if (!errors) // Cannot list errors properly, just quit
qFatal("%s", QQmlMetaType::typeRegistrationFailures().join('\n').toLatin1().constData());
QQmlError error;
@@ -203,44 +237,38 @@ void qmlClearEnginePlugins()
typedef QPair<QStaticPlugin, QJsonArray> StaticPluginPair;
#endif
-class QQmlImportNamespace
-{
-public:
- QQmlImportNamespace() : nextNamespace(0) {}
- ~QQmlImportNamespace() { qDeleteAll(imports); }
-
- struct Import {
- QString uri;
- QString url;
- int majversion;
- int minversion;
- bool isLibrary;
- QQmlDirComponents qmlDirComponents;
- QQmlDirScripts qmlDirScripts;
-
- bool setQmldirContent(const QString &resolvedUrl, const QQmlTypeLoader::QmldirContent *qmldir,
- QQmlImportNamespace *nameSpace, QList<QQmlError> *errors);
-
- static QQmlDirScripts getVersionedScripts(const QQmlDirScripts &qmldirscripts, int vmaj, int vmin);
-
- bool resolveType(QQmlTypeLoader *typeLoader, const QHashedStringRef &type,
- int *vmajor, int *vminor, QQmlType** type_return,
- QString *base = 0, bool *typeRecursionDetected = 0) const;
- };
- QList<Import *> imports;
+/*!
+ \internal
+ \class QQmlImportInstance
- Import *findImport(const QString &uri);
+ A QQmlImportType represents a single import of a document, held within a
+ namespace.
- bool resolveType(QQmlTypeLoader *typeLoader, const QHashedStringRef& type,
- int *vmajor, int *vminor, QQmlType** type_return,
- QString *base = 0, QList<QQmlError> *errors = 0);
+ \note The uri here may not necessarily be unique (e.g. for file imports).
- // Prefix when used as a qualified import. Otherwise empty.
- QHashedString prefix;
+ \note Version numbers may be -1 for file imports: this means that no
+ version was specified as part of the import. Type resolution will be
+ responsible for attempting to find the "best" possible version.
+*/
- // Used by QQmlImportsPrivate::qualifiedSets
- QQmlImportNamespace *nextNamespace;
-};
+/*!
+ \internal
+ \class QQmlImportNamespace
+
+ A QQmlImportNamespace is a way of seperating imports into a local namespace.
+
+ Within a QML document, there is at least one namespace (the
+ "unqualified set") where imports without a qualifier are placed, i.e:
+
+ import QtQuick 2.6
+
+ will have a single namespace (the unqualified set) containing a single import
+ for QtQuick 2.6. However, there may be others if an import statement gives
+ a qualifier, i.e the following will result in an additional new
+ QQmlImportNamespace in the qualified set:
+
+ import MyFoo 1.0 as Foo
+*/
class QQmlImportsPrivate
{
@@ -272,9 +300,12 @@ public:
QString base;
int ref;
+ // storage of data related to imports without a namespace
mutable QQmlImportNamespace unqualifiedset;
QQmlImportNamespace *findQualifiedNamespace(const QHashedStringRef &) const;
+
+ // storage of data related to imports with a namespace
mutable QFieldList<QQmlImportNamespace, &QQmlImportNamespace::nextNamespace> qualifiedSets;
QQmlTypeLoader *typeLoader;
@@ -283,21 +314,21 @@ public:
QQmlImportDatabase *database,
QString *outQmldirFilePath, QString *outUrl);
- static bool validateQmldirVersion(const QQmlTypeLoader::QmldirContent *qmldir, const QString &uri, int vmaj, int vmin,
+ static bool validateQmldirVersion(const QQmlTypeLoaderQmldirContent *qmldir, const QString &uri, int vmaj, int vmin,
QList<QQmlError> *errors);
bool importExtension(const QString &absoluteFilePath, const QString &uri,
int vmaj, int vmin,
QQmlImportDatabase *database,
- const QQmlTypeLoader::QmldirContent *qmldir,
+ const QQmlTypeLoaderQmldirContent *qmldir,
QList<QQmlError> *errors);
bool getQmldirContent(const QString &qmldirIdentifier, const QString &uri,
- const QQmlTypeLoader::QmldirContent **qmldir, QList<QQmlError> *errors);
+ const QQmlTypeLoaderQmldirContent **qmldir, QList<QQmlError> *errors);
QString resolvedUri(const QString &dir_arg, QQmlImportDatabase *database);
- QQmlImportNamespace::Import *addImportToNamespace(QQmlImportNamespace *nameSpace,
+ QQmlImportInstance *addImportToNamespace(QQmlImportNamespace *nameSpace,
const QString &uri, const QString &url,
int vmaj, int vmin, QV4::CompiledData::Import::ImportType type,
QList<QQmlError> *errors, bool lowPrecedence = false);
@@ -362,12 +393,22 @@ QUrl QQmlImports::baseUrl() const
return d->baseUrl;
}
+/*
+ \internal
+
+ This method is responsible for populating data of all types visible in this
+ document's imports into the \a cache for resolution elsewhere (e.g. in JS,
+ or when loading additional types).
+
+ \note This is for C++ types only. Composite types are handled separately,
+ as they do not have a QQmlTypeModule.
+*/
void QQmlImports::populateCache(QQmlTypeNameCache *cache) const
{
const QQmlImportNamespace &set = d->unqualifiedset;
for (int ii = set.imports.count() - 1; ii >= 0; --ii) {
- const QQmlImportNamespace::Import *import = set.imports.at(ii);
+ const QQmlImportInstance *import = set.imports.at(ii);
QQmlTypeModule *module = QQmlMetaType::typeModule(import->uri, import->majversion);
if (module) {
cache->m_anonymousImports.append(QQmlTypeModuleVersion(module, import->minversion));
@@ -378,11 +419,14 @@ void QQmlImports::populateCache(QQmlTypeNameCache *cache) const
const QQmlImportNamespace &set = *ns;
+ // positioning is important; we must create the namespace even if there is no module.
+ QQmlTypeNameCache::Import &typeimport = cache->m_namedImports[set.prefix];
+ typeimport.m_qualifier = set.prefix;
+
for (int ii = set.imports.count() - 1; ii >= 0; --ii) {
- const QQmlImportNamespace::Import *import = set.imports.at(ii);
+ const QQmlImportInstance *import = set.imports.at(ii);
QQmlTypeModule *module = QQmlMetaType::typeModule(import->uri, import->majversion);
if (module) {
- QQmlTypeNameCache::Import &typeimport = cache->m_namedImports[set.prefix];
typeimport.modules.append(QQmlTypeModuleVersion(module, import->minversion));
}
}
@@ -411,7 +455,7 @@ void findCompositeSingletons(const QQmlImportNamespace &set, QList<QQmlImports::
typedef QQmlDirComponents::const_iterator ConstIterator;
for (int ii = set.imports.count() - 1; ii >= 0; --ii) {
- const QQmlImportNamespace::Import *import = set.imports.at(ii);
+ const QQmlImportInstance *import = set.imports.at(ii);
const QQmlDirComponents &components = import->qmlDirComponents;
@@ -429,6 +473,15 @@ void findCompositeSingletons(const QQmlImportNamespace &set, QList<QQmlImports::
}
}
+/*
+ \internal
+
+ Returns a list of all composite singletons present in this document's
+ imports.
+
+ This information is used by QQmlTypeLoader to ensure that composite singletons
+ are marked as dependencies during type loading.
+*/
QList<QQmlImports::CompositeSingletonReference> QQmlImports::resolvedCompositeSingletons() const
{
QList<QQmlImports::CompositeSingletonReference> compositeSingletons;
@@ -444,6 +497,12 @@ QList<QQmlImports::CompositeSingletonReference> QQmlImports::resolvedCompositeSi
return compositeSingletons;
}
+/*
+ \internal
+
+ Returns a list of scripts imported by this document. This is used by
+ QQmlTypeLoader to properly handle dependencies on imported scripts.
+*/
QList<QQmlImports::ScriptReference> QQmlImports::resolvedScripts() const
{
QList<QQmlImports::ScriptReference> scripts;
@@ -451,9 +510,9 @@ QList<QQmlImports::ScriptReference> QQmlImports::resolvedScripts() const
const QQmlImportNamespace &set = d->unqualifiedset;
for (int ii = set.imports.count() - 1; ii >= 0; --ii) {
- const QQmlImportNamespace::Import *import = set.imports.at(ii);
+ const QQmlImportInstance *import = set.imports.at(ii);
- foreach (const QQmlDirParser::Script &script, import->qmlDirScripts) {
+ for (const QQmlDirParser::Script &script : import->qmlDirScripts) {
ScriptReference ref;
ref.nameSpace = script.nameSpace;
ref.location = QUrl(import->url).resolved(QUrl(script.fileName));
@@ -465,9 +524,9 @@ QList<QQmlImports::ScriptReference> QQmlImports::resolvedScripts() const
const QQmlImportNamespace &set = *ns;
for (int ii = set.imports.count() - 1; ii >= 0; --ii) {
- const QQmlImportNamespace::Import *import = set.imports.at(ii);
+ const QQmlImportInstance *import = set.imports.at(ii);
- foreach (const QQmlDirParser::Script &script, import->qmlDirScripts) {
+ for (const QQmlDirParser::Script &script : import->qmlDirScripts) {
ScriptReference ref;
ref.nameSpace = script.nameSpace;
ref.qualifier = set.prefix;
@@ -589,7 +648,7 @@ bool QQmlImports::resolveType(const QHashedStringRef &type,
return false;
}
-bool QQmlImportNamespace::Import::setQmldirContent(const QString &resolvedUrl, const QQmlTypeLoader::QmldirContent *qmldir, QQmlImportNamespace *nameSpace, QList<QQmlError> *errors)
+bool QQmlImportInstance::setQmldirContent(const QString &resolvedUrl, const QQmlTypeLoaderQmldirContent *qmldir, QQmlImportNamespace *nameSpace, QList<QQmlError> *errors)
{
Q_ASSERT(resolvedUrl.endsWith(Slash));
url = resolvedUrl;
@@ -599,7 +658,7 @@ bool QQmlImportNamespace::Import::setQmldirContent(const QString &resolvedUrl, c
const QQmlDirScripts &scripts = qmldir->scripts();
if (!scripts.isEmpty()) {
// Verify that we haven't imported these scripts already
- for (QList<QQmlImportNamespace::Import *>::const_iterator it = nameSpace->imports.constBegin();
+ for (QList<QQmlImportInstance *>::const_iterator it = nameSpace->imports.constBegin();
it != nameSpace->imports.constEnd(); ++it) {
if ((*it != this) && ((*it)->uri == uri)) {
QQmlError error;
@@ -615,7 +674,7 @@ bool QQmlImportNamespace::Import::setQmldirContent(const QString &resolvedUrl, c
return true;
}
-QQmlDirScripts QQmlImportNamespace::Import::getVersionedScripts(const QQmlDirScripts &qmldirscripts, int vmaj, int vmin)
+QQmlDirScripts QQmlImportInstance::getVersionedScripts(const QQmlDirScripts &qmldirscripts, int vmaj, int vmin)
{
QMap<QString, QQmlDirParser::Script> versioned;
@@ -651,7 +710,7 @@ bool QQmlImports::resolveType(QQmlImportNamespace* ns, const QHashedStringRef &t
return ns->resolveType(d->typeLoader,type,vmaj,vmin,type_return);
}
-bool QQmlImportNamespace::Import::resolveType(QQmlTypeLoader *typeLoader,
+bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader,
const QHashedStringRef& type, int *vmajor, int *vminor,
QQmlType** type_return, QString *base, bool *typeRecursionDetected) const
{
@@ -682,15 +741,17 @@ bool QQmlImportNamespace::Import::resolveType(QQmlTypeLoader *typeLoader,
if ((candidate == end) ||
(c.majorVersion > candidate->majorVersion) ||
((c.majorVersion == candidate->majorVersion) && (c.minorVersion > candidate->minorVersion))) {
- componentUrl = resolveLocalUrl(QString(url + c.typeName + dotqml_string), c.fileName);
- if (c.internal && base) {
- if (resolveLocalUrl(*base, c.fileName) != componentUrl)
- continue; // failed attempt to access an internal type
- }
- if (base && (*base == componentUrl)) {
- if (typeRecursionDetected)
- *typeRecursionDetected = true;
- continue; // no recursion
+ if (base) {
+ componentUrl = resolveLocalUrl(QString(url + c.typeName + dotqml_string), c.fileName);
+ if (c.internal) {
+ if (resolveLocalUrl(*base, c.fileName) != componentUrl)
+ continue; // failed attempt to access an internal type
+ }
+ if (*base == componentUrl) {
+ if (typeRecursionDetected)
+ *typeRecursionDetected = true;
+ continue; // no recursion
+ }
}
// This is our best candidate so far
@@ -701,9 +762,11 @@ bool QQmlImportNamespace::Import::resolveType(QQmlTypeLoader *typeLoader,
}
if (candidate != end) {
+ if (!base) // ensure we have a componentUrl
+ componentUrl = resolveLocalUrl(QString(url + candidate->typeName + dotqml_string), candidate->fileName);
int major = vmajor ? *vmajor : -1;
int minor = vminor ? *vminor : -1;
- QQmlType *returnType = getTypeForUrl(componentUrl, type, isCompositeSingleton, 0,
+ QQmlType *returnType = fetchOrCreateTypeForUrl(componentUrl, type, isCompositeSingleton, 0,
major, minor);
if (type_return)
*type_return = returnType;
@@ -731,7 +794,7 @@ bool QQmlImportNamespace::Import::resolveType(QQmlTypeLoader *typeLoader,
if (typeRecursionDetected)
*typeRecursionDetected = true;
} else {
- QQmlType *returnType = getTypeForUrl(qmlUrl, type, false, 0);
+ QQmlType *returnType = fetchOrCreateTypeForUrl(qmlUrl, type, false, 0);
if (type_return)
*type_return = returnType;
return returnType != 0;
@@ -776,7 +839,7 @@ bool QQmlImportsPrivate::resolveType(const QHashedStringRef& type, int *vmajor,
return true;
if (s->imports.count() == 1 && !s->imports.at(0)->isLibrary && type_return && s != &unqualifiedset) {
// qualified, and only 1 url
- *type_return = getTypeForUrl(resolveLocalUrl(s->imports.at(0)->url, unqualifiedtype.toString() + QLatin1String(".qml")), type, false, errors);
+ *type_return = fetchOrCreateTypeForUrl(resolveLocalUrl(s->imports.at(0)->url, unqualifiedtype.toString() + QLatin1String(".qml")), type, false, errors);
return (*type_return != 0);
}
}
@@ -784,14 +847,13 @@ bool QQmlImportsPrivate::resolveType(const QHashedStringRef& type, int *vmajor,
return false;
}
-QQmlImportNamespace::Import *QQmlImportNamespace::findImport(const QString &uri)
+QQmlImportInstance *QQmlImportNamespace::findImport(const QString &uri) const
{
- for (QList<Import *>::iterator it = imports.begin(), end = imports.end(); it != end; ++it) {
- if ((*it)->uri == uri)
- return *it;
+ for (QQmlImportInstance *import : imports) {
+ if (import->uri == uri)
+ return import;
}
-
- return 0;
+ return nullptr;
}
bool QQmlImportNamespace::resolveType(QQmlTypeLoader *typeLoader, const QHashedStringRef &type,
@@ -800,13 +862,13 @@ bool QQmlImportNamespace::resolveType(QQmlTypeLoader *typeLoader, const QHashedS
{
bool typeRecursionDetected = false;
for (int i=0; i<imports.count(); ++i) {
- const Import *import = imports.at(i);
+ const QQmlImportInstance *import = imports.at(i);
if (import->resolveType(typeLoader, type, vmajor, vminor, type_return,
base, &typeRecursionDetected)) {
if (qmlCheckTypes()) {
// check for type clashes
for (int j = i+1; j<imports.count(); ++j) {
- const Import *import2 = imports.at(j);
+ const QQmlImportInstance *import2 = imports.at(j);
if (import2->resolveType(typeLoader, type, vmajor, vminor, 0, base)) {
if (errors) {
QString u1 = import->url;
@@ -898,6 +960,21 @@ static QStringList versionUriList(const QString &uri, int vmaj, int vmin)
}
#if QT_CONFIG(library)
+static QVector<QStaticPlugin> makePlugins()
+{
+ QVector<QStaticPlugin> plugins;
+ // To avoid traversing all static plugins for all imports, we cut down
+ // the list the first time called to only contain QML plugins:
+ const auto staticPlugins = QPluginLoader::staticPlugins();
+ for (const QStaticPlugin &plugin : staticPlugins) {
+ if (plugin.metaData().value(QLatin1String("IID")).toString()
+ == QLatin1String(QQmlExtensionInterface_iid)) {
+ plugins.append(plugin);
+ }
+ }
+ return plugins;
+}
+
/*!
Get all static plugins that are QML plugins and has a meta data URI that matches with one of
\a versionUris, which is a list of all possible versioned URI combinations - see versionUriList()
@@ -906,17 +983,8 @@ static QStringList versionUriList(const QString &uri, int vmaj, int vmin)
bool QQmlImportsPrivate::populatePluginPairVector(QVector<StaticPluginPair> &result, const QString &uri, const QStringList &versionUris,
const QString &qmldirPath, QList<QQmlError> *errors)
{
- static QVector<QStaticPlugin> plugins;
- if (plugins.isEmpty()) {
- // To avoid traversing all static plugins for all imports, we cut down
- // the list the first time called to only contain QML plugins:
- foreach (const QStaticPlugin &plugin, QPluginLoader::staticPlugins()) {
- if (plugin.metaData().value(QLatin1String("IID")).toString() == QLatin1String(QQmlExtensionInterface_iid))
- plugins.append(plugin);
- }
- }
-
- foreach (const QStaticPlugin &plugin, plugins) {
+ static const QVector<QStaticPlugin> plugins = makePlugins();
+ for (const QStaticPlugin &plugin : plugins) {
// Since a module can list more than one plugin, we keep iterating even after we found a match.
if (QQmlExtensionPlugin *instance = qobject_cast<QQmlExtensionPlugin *>(plugin.instance())) {
const QJsonArray metaTagsUriList = plugin.metaData().value(QLatin1String("uri")).toArray();
@@ -931,7 +999,7 @@ bool QQmlImportsPrivate::populatePluginPairVector(QVector<StaticPluginPair> &res
return false;
}
// A plugin can be set up to handle multiple URIs, so go through the list:
- foreach (const QJsonValue &metaTagUri, metaTagsUriList) {
+ for (const QJsonValue &metaTagUri : metaTagsUriList) {
if (versionUris.contains(metaTagUri.toString())) {
result.append(qMakePair(plugin, metaTagsUriList));
break;
@@ -943,10 +1011,12 @@ bool QQmlImportsPrivate::populatePluginPairVector(QVector<StaticPluginPair> &res
}
#endif
+#if defined(QT_SHARED) || !QT_CONFIG(library)
static inline QString msgCannotLoadPlugin(const QString &uri, const QString &why)
{
return QQmlImportDatabase::tr("plugin cannot be loaded for module \"%1\": %2").arg(uri, why);
}
+#endif
/*!
Import an extension defined by a qmldir file.
@@ -957,7 +1027,7 @@ bool QQmlImportsPrivate::importExtension(const QString &qmldirFilePath,
const QString &uri,
int vmaj, int vmin,
QQmlImportDatabase *database,
- const QQmlTypeLoader::QmldirContent *qmldir,
+ const QQmlTypeLoaderQmldirContent *qmldir,
QList<QQmlError> *errors)
{
#if QT_CONFIG(library)
@@ -998,7 +1068,8 @@ bool QQmlImportsPrivate::importExtension(const QString &qmldirFilePath,
int staticPluginsFound = 0;
#if defined(QT_SHARED)
- foreach (const QQmlDirParser::Plugin &plugin, qmldir->plugins()) {
+ const auto qmldirPlugins = qmldir->plugins();
+ for (const QQmlDirParser::Plugin &plugin : qmldirPlugins) {
QString resolvedFilePath = database->resolvePlugin(typeLoader, qmldirPath, plugin.path, plugin.name);
if (!resolvedFilePath.isEmpty()) {
dynamicPluginsFound++;
@@ -1032,8 +1103,8 @@ bool QQmlImportsPrivate::importExtension(const QString &qmldirFilePath,
const QString basePath = QFileInfo(qmldirPath).absoluteFilePath();
for (const QString &versionUri : versionUris) {
- foreach (const StaticPluginPair &pair, pluginPairs) {
- foreach (const QJsonValue &metaTagUri, pair.second) {
+ for (const StaticPluginPair &pair : qAsConst(pluginPairs)) {
+ for (const QJsonValue &metaTagUri : pair.second) {
if (versionUri == metaTagUri.toString()) {
staticPluginsFound++;
QObject *instance = pair.first.instance();
@@ -1092,7 +1163,7 @@ bool QQmlImportsPrivate::importExtension(const QString &qmldirFilePath,
}
bool QQmlImportsPrivate::getQmldirContent(const QString &qmldirIdentifier, const QString &uri,
- const QQmlTypeLoader::QmldirContent **qmldir, QList<QQmlError> *errors)
+ const QQmlTypeLoaderQmldirContent **qmldir, QList<QQmlError> *errors)
{
Q_ASSERT(errors);
Q_ASSERT(qmldir);
@@ -1117,20 +1188,16 @@ bool QQmlImportsPrivate::getQmldirContent(const QString &qmldirIdentifier, const
QString QQmlImportsPrivate::resolvedUri(const QString &dir_arg, QQmlImportDatabase *database)
{
- struct I { static bool greaterThan(const QString &s1, const QString &s2) {
- return s1 > s2;
- } };
-
QString dir = dir_arg;
if (dir.endsWith(Slash) || dir.endsWith(Backslash))
dir.chop(1);
QStringList paths = database->fileImportPath;
if (!paths.isEmpty())
- std::sort(paths.begin(), paths.end(), I::greaterThan); // Ensure subdirs preceed their parents.
+ std::sort(paths.begin(), paths.end(), std::greater<QString>()); // Ensure subdirs preceed their parents.
QString stableRelativePath = dir;
- foreach(const QString &path, paths) {
+ for (const QString &path : qAsConst(paths)) {
if (dir.startsWith(path)) {
stableRelativePath = dir.mid(path.length()+1);
break;
@@ -1221,7 +1288,7 @@ bool QQmlImportsPrivate::locateQmldir(const QString &uri, int vmaj, int vmin, QQ
return false;
}
-bool QQmlImportsPrivate::validateQmldirVersion(const QQmlTypeLoader::QmldirContent *qmldir, const QString &uri, int vmaj, int vmin,
+bool QQmlImportsPrivate::validateQmldirVersion(const QQmlTypeLoaderQmldirContent *qmldir, const QString &uri, int vmaj, int vmin,
QList<QQmlError> *errors)
{
int lowest_min = INT_MAX;
@@ -1304,7 +1371,7 @@ QQmlImportNamespace *QQmlImportsPrivate::importNamespace(const QString &prefix)
return nameSpace;
}
-QQmlImportNamespace::Import *QQmlImportsPrivate::addImportToNamespace(QQmlImportNamespace *nameSpace,
+QQmlImportInstance *QQmlImportsPrivate::addImportToNamespace(QQmlImportNamespace *nameSpace,
const QString &uri, const QString &url, int vmaj, int vmin,
QV4::CompiledData::Import::ImportType type,
QList<QQmlError> *errors, bool lowPrecedence)
@@ -1314,7 +1381,7 @@ QQmlImportNamespace::Import *QQmlImportsPrivate::addImportToNamespace(QQmlImport
Q_UNUSED(errors);
Q_ASSERT(url.isEmpty() || url.endsWith(Slash));
- QQmlImportNamespace::Import *import = new QQmlImportNamespace::Import;
+ QQmlImportInstance *import = new QQmlImportInstance;
import->uri = uri;
import->url = url;
import->majversion = vmaj;
@@ -1340,11 +1407,11 @@ bool QQmlImportsPrivate::addLibraryImport(const QString& uri, const QString &pre
QQmlImportNamespace *nameSpace = importNamespace(prefix);
Q_ASSERT(nameSpace);
- QQmlImportNamespace::Import *inserted = addImportToNamespace(nameSpace, uri, qmldirUrl, vmaj, vmin, QV4::CompiledData::Import::ImportLibrary, errors);
+ QQmlImportInstance *inserted = addImportToNamespace(nameSpace, uri, qmldirUrl, vmaj, vmin, QV4::CompiledData::Import::ImportLibrary, errors);
Q_ASSERT(inserted);
if (!incomplete) {
- const QQmlTypeLoader::QmldirContent *qmldir = 0;
+ const QQmlTypeLoaderQmldirContent *qmldir = 0;
if (!qmldirIdentifier.isEmpty()) {
if (!getQmldirContent(qmldirIdentifier, uri, &qmldir, errors))
@@ -1441,11 +1508,11 @@ bool QQmlImportsPrivate::addFileImport(const QString& uri, const QString &prefix
if (!url.endsWith(Slash) && !url.endsWith(Backslash))
url += Slash;
- QQmlImportNamespace::Import *inserted = addImportToNamespace(nameSpace, importUri, url, vmaj, vmin, QV4::CompiledData::Import::ImportFile, errors, isImplicitImport);
+ QQmlImportInstance *inserted = addImportToNamespace(nameSpace, importUri, url, vmaj, vmin, QV4::CompiledData::Import::ImportFile, errors, isImplicitImport);
Q_ASSERT(inserted);
if (!incomplete && !qmldirIdentifier.isEmpty()) {
- const QQmlTypeLoader::QmldirContent *qmldir = 0;
+ const QQmlTypeLoaderQmldirContent *qmldir = 0;
if (!getQmldirContent(qmldirIdentifier, importUri, &qmldir, errors))
return false;
@@ -1468,8 +1535,8 @@ bool QQmlImportsPrivate::updateQmldirContent(const QString &uri, const QString &
QQmlImportNamespace *nameSpace = importNamespace(prefix);
Q_ASSERT(nameSpace);
- if (QQmlImportNamespace::Import *import = nameSpace->findImport(uri)) {
- const QQmlTypeLoader::QmldirContent *qmldir = 0;
+ if (QQmlImportInstance *import = nameSpace->findImport(uri)) {
+ const QQmlTypeLoaderQmldirContent *qmldir = 0;
if (!getQmldirContent(qmldirIdentifier, uri, &qmldir, errors))
return false;
@@ -1671,8 +1738,7 @@ QString QQmlImportDatabase::resolvePlugin(QQmlTypeLoader *typeLoader,
if (!qmldirPluginPathIsRelative)
searchPaths.prepend(qmldirPluginPath);
- foreach (const QString &pluginPath, searchPaths) {
-
+ for (const QString &pluginPath : qAsConst(searchPaths)) {
QString resolvedPath;
if (pluginPath == QLatin1String(".")) {
if (qmldirPluginPathIsRelative && !qmldirPluginPath.isEmpty() && qmldirPluginPath != QLatin1String("."))
@@ -1694,7 +1760,7 @@ QString QQmlImportDatabase::resolvePlugin(QQmlTypeLoader *typeLoader,
resolvedPath += Slash;
resolvedPath += prefix + baseName;
- foreach (const QString &suffix, suffixes) {
+ for (const QString &suffix : suffixes) {
const QString absolutePath = typeLoader->absoluteFilePath(resolvedPath + suffix);
if (!absolutePath.isEmpty())
return absolutePath;
@@ -1836,7 +1902,7 @@ QStringList QQmlImportDatabase::importPathList(PathType type) const
return fileImportPath;
QStringList list;
- foreach (const QString &path, fileImportPath) {
+ for (const QString &path : fileImportPath) {
bool localPath = isPathAbsolute(path) || QQmlFile::isLocalFile(path);
if (localPath == (type == Local))
list.append(path);
@@ -1930,7 +1996,7 @@ bool QQmlImportDatabase::registerPluginTypes(QObject *instance, const QString &b
if (!registrationFailures.isEmpty()) {
if (errors) {
- foreach (const QString &failure, registrationFailures) {
+ for (const QString &failure : qAsConst(registrationFailures)) {
QQmlError error;
error.setDescription(failure);
errors->prepend(error);
diff --git a/src/qml/qml/qqmlimport_p.h b/src/qml/qml/qqmlimport_p.h
index 0e7848730f..7c691a468c 100644
--- a/src/qml/qml/qqmlimport_p.h
+++ b/src/qml/qml/qqmlimport_p.h
@@ -68,6 +68,48 @@ class QQmlImportNamespace;
class QQmlImportsPrivate;
class QQmlImportDatabase;
class QQmlTypeLoader;
+class QQmlTypeLoaderQmldirContent;
+
+struct QQmlImportInstance
+{
+ QString uri; // e.g. QtQuick
+ QString url; // the base path of the import
+ int majversion; // the major version imported
+ int minversion; // the minor version imported
+ bool isLibrary; // true means that this is not a file import
+ QQmlDirComponents qmlDirComponents; // a copy of the components listed in the qmldir
+ QQmlDirScripts qmlDirScripts; // a copy of the scripts in the qmldir
+
+ bool setQmldirContent(const QString &resolvedUrl, const QQmlTypeLoaderQmldirContent *qmldir,
+ QQmlImportNamespace *nameSpace, QList<QQmlError> *errors);
+
+ static QQmlDirScripts getVersionedScripts(const QQmlDirScripts &qmldirscripts, int vmaj, int vmin);
+
+ bool resolveType(QQmlTypeLoader *typeLoader, const QHashedStringRef &type,
+ int *vmajor, int *vminor, QQmlType** type_return,
+ QString *base = 0, bool *typeRecursionDetected = 0) const;
+};
+
+class QQmlImportNamespace
+{
+public:
+ QQmlImportNamespace() : nextNamespace(0) {}
+ ~QQmlImportNamespace() { qDeleteAll(imports); }
+
+ QList<QQmlImportInstance *> imports;
+
+ QQmlImportInstance *findImport(const QString &uri) const;
+
+ bool resolveType(QQmlTypeLoader *typeLoader, const QHashedStringRef& type,
+ int *vmajor, int *vminor, QQmlType** type_return,
+ QString *base = 0, QList<QQmlError> *errors = 0);
+
+ // Prefix when used as a qualified import. Otherwise empty.
+ QHashedString prefix;
+
+ // Used by QQmlImportsPrivate::qualifiedSets
+ QQmlImportNamespace *nextNamespace;
+};
class Q_QML_PRIVATE_EXPORT QQmlImports
{
diff --git a/src/qml/qml/qqmlincubator.cpp b/src/qml/qml/qqmlincubator.cpp
index 0ce769aaea..54d0b240f5 100644
--- a/src/qml/qml/qqmlincubator.cpp
+++ b/src/qml/qml/qqmlincubator.cpp
@@ -206,7 +206,7 @@ public:
}
protected:
- virtual void timerEvent(QTimerEvent *) {
+ void timerEvent(QTimerEvent *) override {
incubateFor(5);
}
};
@@ -380,6 +380,23 @@ finishIncubate:
}
}
+void QQmlIncubatorPrivate::cancel(QObject *object, QQmlContext *context)
+{
+ if (!context)
+ context = qmlContext(object);
+ if (!context)
+ return;
+
+ QQmlContextData *data = QQmlContextData::get(context);
+ QQmlIncubatorPrivate *p = (QQmlIncubatorPrivate *)data->activeVMEData;
+ if (!p)
+ return;
+
+ p->vmeGuard.unguard(object);
+ if (!p->creator.isNull())
+ p->creator->cancel(object);
+}
+
/*!
Incubate objects for \a msecs, or until there are no more objects to incubate.
*/
diff --git a/src/qml/qml/qqmlincubator_p.h b/src/qml/qml/qqmlincubator_p.h
index ecf3b6d2ca..758e0a29f6 100644
--- a/src/qml/qml/qqmlincubator_p.h
+++ b/src/qml/qml/qqmlincubator_p.h
@@ -40,6 +40,8 @@
#ifndef QQMLINCUBATOR_P_H
#define QQMLINCUBATOR_P_H
+#include "qqmlincubator.h"
+
#include <private/qintrusivelist_p.h>
#include <private/qqmlvme_p.h>
#include <private/qrecursionwatcher_p.h>
@@ -100,6 +102,9 @@ public:
void forceCompletion(QQmlInstantiationInterrupt &i);
void incubate(QQmlInstantiationInterrupt &i);
+
+ // used by Qt Quick Controls 2
+ Q_QML_PRIVATE_EXPORT static void cancel(QObject *object, QQmlContext *context = 0);
};
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmlinfo.cpp b/src/qml/qml/qqmlinfo.cpp
index 5b6e02d5b1..dae15e2eca 100644
--- a/src/qml/qml/qqmlinfo.cpp
+++ b/src/qml/qml/qqmlinfo.cpp
@@ -50,13 +50,45 @@
QT_BEGIN_NAMESPACE
/*!
+ \fn QQmlInfo QtQml::qmlDebug(const QObject *object)
+ \relates QQmlEngine
+ \since 5.9
+
+ Prints debug messages that include the file and line number for the
+ specified QML \a object.
+
+ When QML types produce logging messages, it improves traceability
+ if they include the QML file and line number on which the
+ particular instance was instantiated.
+
+ To include the file and line number, an object must be passed. If
+ the file and line number is not available for that instance
+ (either it was not instantiated by the QML engine or location
+ information is disabled), "unknown location" will be used instead.
+
+ For example,
+
+ \code
+ qmlDebug(object) << "Internal state: 42";
+ \endcode
+
+ prints
+
+ \code
+ QML MyCustomType (unknown location): Internal state: 42
+ \endcode
+
+ \sa QtQml::qmlInfo, QtQml::qmlWarning
+*/
+
+/*!
\fn QQmlInfo QtQml::qmlInfo(const QObject *object)
\relates QQmlEngine
- Prints warning messages that include the file and line number for the
+ Prints informational messages that include the file and line number for the
specified QML \a object.
- When QML types display warning messages, it improves traceability
+ When QML types produce logging messages, it improves traceability
if they include the QML file and line number on which the
particular instance was instantiated.
@@ -76,14 +108,58 @@ QT_BEGIN_NAMESPACE
\code
QML MyCustomType (unknown location): component property is a write-once property
\endcode
+
+ \note In versions prior to Qt 5.9, qmlInfo reported messages using a warning
+ QtMsgType. For Qt 5.9 and above, qmlInfo uses an info QtMsgType. To send
+ warnings, use qmlWarning.
+
+ \sa QtQml::qmlDebug, QtQml::qmlWarning
+*/
+
+
+/*!
+ \fn QQmlInfo QtQml::qmlWarning(const QObject *object)
+ \relates QQmlEngine
+ \since 5.9
+
+ Prints warning messages that include the file and line number for the
+ specified QML \a object.
+
+ When QML types produce logging messages, it improves traceability
+ if they include the QML file and line number on which the
+ particular instance was instantiated.
+
+ To include the file and line number, an object must be passed. If
+ the file and line number is not available for that instance
+ (either it was not instantiated by the QML engine or location
+ information is disabled), "unknown location" will be used instead.
+
+ For example,
+
+ \code
+ qmlInfo(object) << tr("property cannot be set to 0");
+ \endcode
+
+ prints
+
+ \code
+ QML MyCustomType (unknown location): property cannot be set to 0
+ \endcode
+
+ \sa QtQml::qmlDebug, QtQml::qmlInfo
*/
class QQmlInfoPrivate
{
public:
- QQmlInfoPrivate() : ref (1), object(0) {}
+ QQmlInfoPrivate(QtMsgType type)
+ : ref (1)
+ , msgType(type)
+ , object(nullptr)
+ {}
int ref;
+ QtMsgType msgType;
const QObject *object;
QString buffer;
QList<QQmlError> errors;
@@ -110,6 +186,7 @@ QQmlInfo::~QQmlInfo()
if (!d->buffer.isEmpty()) {
QQmlError error;
+ error.setMessageType(d->msgType);
QObject *object = const_cast<QObject *>(d->object);
@@ -139,28 +216,32 @@ QQmlInfo::~QQmlInfo()
namespace QtQml {
-QQmlInfo qmlInfo(const QObject *me)
-{
- QQmlInfoPrivate *d = new QQmlInfoPrivate;
- d->object = me;
- return QQmlInfo(d);
-}
+#define MESSAGE_FUNCS(FuncName, MessageLevel) \
+ QQmlInfo FuncName(const QObject *me) \
+ { \
+ QQmlInfoPrivate *d = new QQmlInfoPrivate(MessageLevel); \
+ d->object = me; \
+ return QQmlInfo(d); \
+ } \
+ QQmlInfo FuncName(const QObject *me, const QQmlError &error) \
+ { \
+ QQmlInfoPrivate *d = new QQmlInfoPrivate(MessageLevel); \
+ d->object = me; \
+ d->errors << error; \
+ return QQmlInfo(d); \
+ } \
+ QQmlInfo FuncName(const QObject *me, const QList<QQmlError> &errors) \
+ { \
+ QQmlInfoPrivate *d = new QQmlInfoPrivate(MessageLevel); \
+ d->object = me; \
+ d->errors = errors; \
+ return QQmlInfo(d); \
+ }
-QQmlInfo qmlInfo(const QObject *me, const QQmlError &error)
-{
- QQmlInfoPrivate *d = new QQmlInfoPrivate;
- d->object = me;
- d->errors << error;
- return QQmlInfo(d);
-}
+MESSAGE_FUNCS(qmlDebug, QtMsgType::QtDebugMsg)
+MESSAGE_FUNCS(qmlInfo, QtMsgType::QtInfoMsg)
+MESSAGE_FUNCS(qmlWarning, QtMsgType::QtWarningMsg)
-QQmlInfo qmlInfo(const QObject *me, const QList<QQmlError> &errors)
-{
- QQmlInfoPrivate *d = new QQmlInfoPrivate;
- d->object = me;
- d->errors = errors;
- return QQmlInfo(d);
-}
} // namespace QtQml
diff --git a/src/qml/qml/qqmlinfo.h b/src/qml/qml/qqmlinfo.h
index ab0281a688..673125632e 100644
--- a/src/qml/qml/qqmlinfo.h
+++ b/src/qml/qml/qqmlinfo.h
@@ -48,11 +48,19 @@ QT_BEGIN_NAMESPACE
class QQmlInfo;
+// declared in namespace to avoid symbol conflicts with QtDeclarative
namespace QtQml {
- // declared in namespace to avoid symbol conflicts with QtDeclarative
+ Q_QML_EXPORT QQmlInfo qmlDebug(const QObject *me);
+ Q_QML_EXPORT QQmlInfo qmlDebug(const QObject *me, const QQmlError &error);
+ Q_QML_EXPORT QQmlInfo qmlDebug(const QObject *me, const QList<QQmlError> &errors);
+
Q_QML_EXPORT QQmlInfo qmlInfo(const QObject *me);
Q_QML_EXPORT QQmlInfo qmlInfo(const QObject *me, const QQmlError &error);
Q_QML_EXPORT QQmlInfo qmlInfo(const QObject *me, const QList<QQmlError> &errors);
+
+ Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me);
+ Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me, const QQmlError &error);
+ Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me, const QList<QQmlError> &errors);
}
QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wheader-hygiene")
@@ -93,9 +101,15 @@ public:
#endif
private:
+ friend Q_QML_EXPORT QQmlInfo QtQml::qmlDebug(const QObject *me);
+ friend Q_QML_EXPORT QQmlInfo QtQml::qmlDebug(const QObject *me, const QQmlError &error);
+ friend Q_QML_EXPORT QQmlInfo QtQml::qmlDebug(const QObject *me, const QList<QQmlError> &errors);
friend Q_QML_EXPORT QQmlInfo QtQml::qmlInfo(const QObject *me);
friend Q_QML_EXPORT QQmlInfo QtQml::qmlInfo(const QObject *me, const QQmlError &error);
friend Q_QML_EXPORT QQmlInfo QtQml::qmlInfo(const QObject *me, const QList<QQmlError> &errors);
+ friend Q_QML_EXPORT QQmlInfo QtQml::qmlWarning(const QObject *me);
+ friend Q_QML_EXPORT QQmlInfo QtQml::qmlWarning(const QObject *me, const QQmlError &error);
+ friend Q_QML_EXPORT QQmlInfo QtQml::qmlWarning(const QObject *me, const QList<QQmlError> &errors);
QQmlInfo(QQmlInfoPrivate *);
QQmlInfoPrivate *d;
diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h
index 0724038382..646cc5ab3d 100644
--- a/src/qml/qml/qqmljavascriptexpression_p.h
+++ b/src/qml/qml/qqmljavascriptexpression_p.h
@@ -100,7 +100,7 @@ public:
QQmlJavaScriptExpression();
virtual ~QQmlJavaScriptExpression();
- virtual QString expressionIdentifier() = 0;
+ virtual QString expressionIdentifier() const = 0;
virtual void expressionChanged() = 0;
void evaluate(QV4::CallData *callData, bool *isUndefined, QV4::Scope &scope);
diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp
index 8aa107dc17..d94f7c56e4 100644
--- a/src/qml/qml/qqmllistwrapper.cpp
+++ b/src/qml/qml/qqmllistwrapper.cpp
@@ -165,4 +165,29 @@ void QmlListWrapper::advanceIterator(Managed *m, ObjectIterator *it, Value *name
return QV4::Object::advanceIterator(m, it, name, index, p, attrs);
}
+void PropertyListPrototype::init(ExecutionEngine *)
+{
+ defineDefaultProperty(QStringLiteral("push"), method_push, 1);
+}
+
+void PropertyListPrototype::method_push(const BuiltinFunction *, Scope &scope, CallData *callData)
+{
+ ScopedObject instance(scope, callData->thisObject.toObject(scope.engine));
+ if (!instance)
+ RETURN_UNDEFINED();
+ QmlListWrapper *w = instance->as<QmlListWrapper>();
+ if (!w)
+ RETURN_UNDEFINED();
+ if (!w->d()->property().append)
+ THROW_GENERIC_ERROR("List doesn't define an Append function");
+
+ QV4::ScopedObject so(scope);
+ for (int i = 0; i < callData->argc; ++i)
+ {
+ so = callData->args[i].toObject(scope.engine);
+ if (QV4::QObjectWrapper *wrapper = so->as<QV4::QObjectWrapper>())
+ w->d()->property().append(&w->d()->property(), wrapper->object() );
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmllistwrapper_p.h b/src/qml/qml/qqmllistwrapper_p.h
index d01b332159..b914c681f2 100644
--- a/src/qml/qml/qqmllistwrapper_p.h
+++ b/src/qml/qml/qqmllistwrapper_p.h
@@ -86,6 +86,7 @@ struct Q_QML_EXPORT QmlListWrapper : Object
{
V4_OBJECT2(QmlListWrapper, Object)
V4_NEEDS_DESTROY
+ V4_PROTOTYPE(propertyListPrototype)
static ReturnedValue create(ExecutionEngine *engine, QObject *object, int propId, int propType);
static ReturnedValue create(ExecutionEngine *engine, const QQmlListProperty<QObject> &prop, int propType);
@@ -98,6 +99,13 @@ struct Q_QML_EXPORT QmlListWrapper : Object
static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes);
};
+struct PropertyListPrototype : Object
+{
+ void init(ExecutionEngine *engine);
+
+ static void method_push(const BuiltinFunction *, Scope &, CallData *callData);
+};
+
}
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp
index 3876e774c3..712da78807 100644
--- a/src/qml/qml/qqmllocale.cpp
+++ b/src/qml/qml/qqmllocale.cpp
@@ -56,10 +56,17 @@ using namespace QV4;
DEFINE_OBJECT_VTABLE(QQmlLocaleData);
+#define THROW_ERROR(string) \
+ do { \
+ scope.result = scope.engine->throwError(QString::fromUtf8(string)); \
+ return; \
+ } while (false)
+
+
#define GET_LOCALE_DATA_RESOURCE(OBJECT) \
QV4::Scoped<QQmlLocaleData> r(scope, OBJECT.as<QQmlLocaleData>()); \
if (!r) \
- V4THROW_ERROR("Not a valid Locale object")
+ THROW_ERROR("Not a valid Locale object")
static bool isLocaleObject(const QV4::Value &val)
{
@@ -80,215 +87,219 @@ void QQmlDateExtension::registerExtension(QV4::ExecutionEngine *engine)
engine->dateCtor()->defineDefaultProperty(QStringLiteral("timeZoneUpdated"), method_timeZoneUpdated);
}
-QV4::ReturnedValue QQmlDateExtension::method_toLocaleString(QV4::CallContext *ctx)
+void QQmlDateExtension::method_toLocaleString(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- if (ctx->argc() > 2)
- return QV4::DatePrototype::method_toLocaleString(ctx);
-
- QV4::Scope scope(ctx);
+ if (callData->argc > 2) {
+ QV4::DatePrototype::method_toLocaleString(b, scope, callData);
+ return;
+ }
- QV4::DateObject *date = ctx->thisObject().as<DateObject>();
- if (!date)
- return QV4::DatePrototype::method_toLocaleString(ctx);
+ QV4::DateObject *date = callData->thisObject.as<DateObject>();
+ if (!date) {
+ QV4::DatePrototype::method_toLocaleString(b, scope, callData);
+ return;
+ }
QDateTime dt = date->toQDateTime();
- if (ctx->argc() == 0) {
+ if (callData->argc == 0) {
// Use QLocale for standard toLocaleString() function
QLocale locale;
- return ctx->d()->engine->newString(locale.toString(dt))->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(locale.toString(dt)));
}
- if (!isLocaleObject(ctx->args()[0]))
- return QV4::DatePrototype::method_toLocaleString(ctx); // Use the default Date toLocaleString()
+ if (!isLocaleObject(callData->args[0])) {
+ QV4::DatePrototype::method_toLocaleString(b, scope, callData); // Use the default Date toLocaleString()
+ return;
+ }
- GET_LOCALE_DATA_RESOURCE(ctx->args()[0]);
+ GET_LOCALE_DATA_RESOURCE(callData->args[0]);
QLocale::FormatType enumFormat = QLocale::LongFormat;
QString formattedDt;
- if (ctx->argc() == 2) {
- if (String *s = ctx->args()[1].stringValue()) {
+ if (callData->argc == 2) {
+ if (String *s = callData->args[1].stringValue()) {
QString format = s->toQString();
formattedDt = r->d()->locale->toString(dt, format);
- } else if (ctx->args()[1].isNumber()) {
- quint32 intFormat = ctx->args()[1].toNumber();
+ } else if (callData->args[1].isNumber()) {
+ quint32 intFormat = callData->args[1].toNumber();
QLocale::FormatType format = QLocale::FormatType(intFormat);
formattedDt = r->d()->locale->toString(dt, format);
} else {
- V4THROW_ERROR("Locale: Date.toLocaleString(): Invalid datetime format");
+ THROW_ERROR("Locale: Date.toLocaleString(): Invalid datetime format");
}
} else {
formattedDt = r->d()->locale->toString(dt, enumFormat);
}
- return ctx->d()->engine->newString(formattedDt)->asReturnedValue();
+ scope.result = scope.engine->newString(formattedDt);
}
-QV4::ReturnedValue QQmlDateExtension::method_toLocaleTimeString(QV4::CallContext *ctx)
+void QQmlDateExtension::method_toLocaleTimeString(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- if (ctx->argc() > 2)
- return QV4::DatePrototype::method_toLocaleTimeString(ctx);
-
- QV4::Scope scope(ctx);
+ if (callData->argc > 2) {
+ QV4::DatePrototype::method_toLocaleTimeString(b, scope, callData);
+ return;
+ }
- QV4::DateObject *date = ctx->thisObject().as<DateObject>();
- if (!date)
- return QV4::DatePrototype::method_toLocaleTimeString(ctx);
+ QV4::DateObject *date = callData->thisObject.as<DateObject>();
+ if (!date) {
+ QV4::DatePrototype::method_toLocaleTimeString(b, scope, callData);
+ return;
+ }
QDateTime dt = date->toQDateTime();
QTime time = dt.time();
- if (ctx->argc() == 0) {
+ if (callData->argc == 0) {
// Use QLocale for standard toLocaleString() function
QLocale locale;
- return ctx->d()->engine->newString(locale.toString(time))->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(locale.toString(time)));
}
- if (!isLocaleObject(ctx->args()[0]))
- return QV4::DatePrototype::method_toLocaleTimeString(ctx); // Use the default Date toLocaleTimeString()
+ if (!isLocaleObject(callData->args[0]))
+ return QV4::DatePrototype::method_toLocaleTimeString(b, scope, callData); // Use the default Date toLocaleTimeString()
- GET_LOCALE_DATA_RESOURCE(ctx->args()[0]);
+ GET_LOCALE_DATA_RESOURCE(callData->args[0]);
QLocale::FormatType enumFormat = QLocale::LongFormat;
QString formattedTime;
- if (ctx->argc() == 2) {
- if (String *s = ctx->args()[1].stringValue()) {
+ if (callData->argc == 2) {
+ if (String *s = callData->args[1].stringValue()) {
QString format = s->toQString();
formattedTime = r->d()->locale->toString(time, format);
- } else if (ctx->args()[1].isNumber()) {
- quint32 intFormat = ctx->args()[1].toNumber();
+ } else if (callData->args[1].isNumber()) {
+ quint32 intFormat = callData->args[1].toNumber();
QLocale::FormatType format = QLocale::FormatType(intFormat);
formattedTime = r->d()->locale->toString(time, format);
} else {
- V4THROW_ERROR("Locale: Date.toLocaleTimeString(): Invalid time format");
+ THROW_ERROR("Locale: Date.toLocaleTimeString(): Invalid time format");
}
} else {
formattedTime = r->d()->locale->toString(time, enumFormat);
}
- return ctx->d()->engine->newString(formattedTime)->asReturnedValue();
+ scope.result = scope.engine->newString(formattedTime);
}
-QV4::ReturnedValue QQmlDateExtension::method_toLocaleDateString(QV4::CallContext *ctx)
+void QQmlDateExtension::method_toLocaleDateString(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- if (ctx->argc() > 2)
- return QV4::DatePrototype::method_toLocaleDateString(ctx);
-
- QV4::Scope scope(ctx);
+ if (callData->argc > 2) {
+ QV4::DatePrototype::method_toLocaleDateString(b, scope, callData);
+ return;
+ }
- QV4::DateObject *dateObj = ctx->thisObject().as<DateObject>();
- if (!dateObj)
- return QV4::DatePrototype::method_toLocaleDateString(ctx);
+ QV4::DateObject *dateObj = callData->thisObject.as<DateObject>();
+ if (!dateObj) {
+ QV4::DatePrototype::method_toLocaleDateString(b, scope, callData);
+ return;
+ }
QDateTime dt = dateObj->toQDateTime();
QDate date = dt.date();
- if (ctx->argc() == 0) {
+ if (callData->argc == 0) {
// Use QLocale for standard toLocaleString() function
QLocale locale;
- return ctx->d()->engine->newString(locale.toString(date))->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(locale.toString(date)));
}
- if (!isLocaleObject(ctx->args()[0]))
- return QV4::DatePrototype::method_toLocaleDateString(ctx); // Use the default Date toLocaleDateString()
+ if (!isLocaleObject(callData->args[0]))
+ return QV4::DatePrototype::method_toLocaleDateString(b, scope, callData); // Use the default Date toLocaleDateString()
- GET_LOCALE_DATA_RESOURCE(ctx->args()[0]);
+ GET_LOCALE_DATA_RESOURCE(callData->args[0]);
QLocale::FormatType enumFormat = QLocale::LongFormat;
QString formattedDate;
- if (ctx->argc() == 2) {
- if (String *s = ctx->args()[1].stringValue()) {
+ if (callData->argc == 2) {
+ if (String *s = callData->args[1].stringValue()) {
QString format = s->toQString();
formattedDate = r->d()->locale->toString(date, format);
- } else if (ctx->args()[1].isNumber()) {
- quint32 intFormat = ctx->args()[1].toNumber();
+ } else if (callData->args[1].isNumber()) {
+ quint32 intFormat = callData->args[1].toNumber();
QLocale::FormatType format = QLocale::FormatType(intFormat);
formattedDate = r->d()->locale->toString(date, format);
} else {
- V4THROW_ERROR("Locale: Date.loLocaleDateString(): Invalid date format");
+ THROW_ERROR("Locale: Date.loLocaleDateString(): Invalid date format");
}
} else {
formattedDate = r->d()->locale->toString(date, enumFormat);
}
- return ctx->d()->engine->newString(formattedDate)->asReturnedValue();
+ scope.result = scope.engine->newString(formattedDate);
}
-QV4::ReturnedValue QQmlDateExtension::method_fromLocaleString(QV4::CallContext *ctx)
+void QQmlDateExtension::method_fromLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::ExecutionEngine * const engine = ctx->d()->engine;
- if (ctx->argc() == 1) {
- if (String *s = ctx->args()[0].stringValue()) {
+ QV4::ExecutionEngine * const engine = scope.engine;
+ if (callData->argc == 1) {
+ if (String *s = callData->args[0].stringValue()) {
QLocale locale;
QString dateString = s->toQString();
QDateTime dt = locale.toDateTime(dateString);
- return QV4::Encode(engine->newDateObject(dt));
+ RETURN_RESULT(engine->newDateObject(dt));
}
}
- QV4::Scope scope(ctx);
-
- if (ctx->argc() < 1 || ctx->argc() > 3 || !isLocaleObject(ctx->args()[0]))
- V4THROW_ERROR("Locale: Date.fromLocaleString(): Invalid arguments");
+ if (callData->argc < 1 || callData->argc > 3 || !isLocaleObject(callData->args[0]))
+ THROW_ERROR("Locale: Date.fromLocaleString(): Invalid arguments");
- GET_LOCALE_DATA_RESOURCE(ctx->args()[0]);
+ GET_LOCALE_DATA_RESOURCE(callData->args[0]);
QLocale::FormatType enumFormat = QLocale::LongFormat;
QDateTime dt;
- QString dateString = ctx->args()[1].toQStringNoThrow();
- if (ctx->argc() == 3) {
- if (String *s = ctx->args()[2].stringValue()) {
+ QString dateString = callData->args[1].toQStringNoThrow();
+ if (callData->argc == 3) {
+ if (String *s = callData->args[2].stringValue()) {
QString format = s->toQString();
dt = r->d()->locale->toDateTime(dateString, format);
- } else if (ctx->args()[2].isNumber()) {
- quint32 intFormat = ctx->args()[2].toNumber();
+ } else if (callData->args[2].isNumber()) {
+ quint32 intFormat = callData->args[2].toNumber();
QLocale::FormatType format = QLocale::FormatType(intFormat);
dt = r->d()->locale->toDateTime(dateString, format);
} else {
- V4THROW_ERROR("Locale: Date.fromLocaleString(): Invalid datetime format");
+ THROW_ERROR("Locale: Date.fromLocaleString(): Invalid datetime format");
}
} else {
dt = r->d()->locale->toDateTime(dateString, enumFormat);
}
- return QV4::Encode(engine->newDateObject(dt));
+ scope.result = engine->newDateObject(dt);
}
-QV4::ReturnedValue QQmlDateExtension::method_fromLocaleTimeString(QV4::CallContext *ctx)
+void QQmlDateExtension::method_fromLocaleTimeString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::ExecutionEngine * const engine = ctx->d()->engine;
+ QV4::ExecutionEngine * const engine = scope.engine;
- if (ctx->argc() == 1) {
- if (String *s = ctx->args()[0].stringValue()) {
+ if (callData->argc == 1) {
+ if (String *s = callData->args[0].stringValue()) {
QLocale locale;
QString timeString = s->toQString();
QTime time = locale.toTime(timeString);
QDateTime dt = QDateTime::currentDateTime();
dt.setTime(time);
- return QV4::Encode(engine->newDateObject(dt));
+ RETURN_RESULT(engine->newDateObject(dt));
}
}
- if (ctx->argc() < 1 || ctx->argc() > 3 || !isLocaleObject(ctx->args()[0]))
- V4THROW_ERROR("Locale: Date.fromLocaleTimeString(): Invalid arguments");
-
- QV4::Scope scope(ctx);
+ if (callData->argc < 1 || callData->argc > 3 || !isLocaleObject(callData->args[0]))
+ THROW_ERROR("Locale: Date.fromLocaleTimeString(): Invalid arguments");
- GET_LOCALE_DATA_RESOURCE(ctx->args()[0]);
+ GET_LOCALE_DATA_RESOURCE(callData->args[0]);
QLocale::FormatType enumFormat = QLocale::LongFormat;
QTime tm;
- QString dateString = ctx->args()[1].toQStringNoThrow();
- if (ctx->argc() == 3) {
- if (String *s = ctx->args()[2].stringValue()) {
+ QString dateString = callData->args[1].toQStringNoThrow();
+ if (callData->argc == 3) {
+ if (String *s = callData->args[2].stringValue()) {
QString format = s->toQString();
tm = r->d()->locale->toTime(dateString, format);
- } else if (ctx->args()[2].isNumber()) {
- quint32 intFormat = ctx->args()[2].toNumber();
+ } else if (callData->args[2].isNumber()) {
+ quint32 intFormat = callData->args[2].toNumber();
QLocale::FormatType format = QLocale::FormatType(intFormat);
tm = r->d()->locale->toTime(dateString, format);
} else {
- V4THROW_ERROR("Locale: Date.fromLocaleTimeString(): Invalid datetime format");
+ THROW_ERROR("Locale: Date.fromLocaleTimeString(): Invalid datetime format");
}
} else {
tm = r->d()->locale->toTime(dateString, enumFormat);
@@ -300,58 +311,56 @@ QV4::ReturnedValue QQmlDateExtension::method_fromLocaleTimeString(QV4::CallConte
dt.setTime(tm);
}
- return QV4::Encode(engine->newDateObject(dt));
+ RETURN_RESULT(engine->newDateObject(dt));
}
-QV4::ReturnedValue QQmlDateExtension::method_fromLocaleDateString(QV4::CallContext *ctx)
+void QQmlDateExtension::method_fromLocaleDateString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::ExecutionEngine * const engine = ctx->d()->engine;
+ QV4::ExecutionEngine * const engine = scope.engine;
- if (ctx->argc() == 1) {
- if (String *s = ctx->args()[0].stringValue()) {
+ if (callData->argc == 1) {
+ if (String *s = callData->args[0].stringValue()) {
QLocale locale;
QString dateString = s->toQString();
QDate date = locale.toDate(dateString);
- return QV4::Encode(engine->newDateObject(QDateTime(date)));
+ RETURN_RESULT(engine->newDateObject(QDateTime(date)));
}
}
- if (ctx->argc() < 1 || ctx->argc() > 3 || !isLocaleObject(ctx->args()[0]))
- V4THROW_ERROR("Locale: Date.fromLocaleDateString(): Invalid arguments");
+ if (callData->argc < 1 || callData->argc > 3 || !isLocaleObject(callData->args[0]))
+ THROW_ERROR("Locale: Date.fromLocaleDateString(): Invalid arguments");
- QV4::Scope scope(ctx);
-
- GET_LOCALE_DATA_RESOURCE(ctx->args()[0]);
+ GET_LOCALE_DATA_RESOURCE(callData->args[0]);
QLocale::FormatType enumFormat = QLocale::LongFormat;
QDate dt;
- QString dateString = ctx->args()[1].toQStringNoThrow();
- if (ctx->argc() == 3) {
- if (String *s = ctx->args()[2].stringValue()) {
+ QString dateString = callData->args[1].toQStringNoThrow();
+ if (callData->argc == 3) {
+ if (String *s = callData->args[2].stringValue()) {
QString format = s->toQString();
dt = r->d()->locale->toDate(dateString, format);
- } else if (ctx->args()[2].isNumber()) {
- quint32 intFormat = ctx->args()[2].toNumber();
+ } else if (callData->args[2].isNumber()) {
+ quint32 intFormat = callData->args[2].toNumber();
QLocale::FormatType format = QLocale::FormatType(intFormat);
dt = r->d()->locale->toDate(dateString, format);
} else {
- V4THROW_ERROR("Locale: Date.fromLocaleDateString(): Invalid datetime format");
+ THROW_ERROR("Locale: Date.fromLocaleDateString(): Invalid datetime format");
}
} else {
dt = r->d()->locale->toDate(dateString, enumFormat);
}
- return QV4::Encode(engine->newDateObject(QDateTime(dt)));
+ RETURN_RESULT(engine->newDateObject(QDateTime(dt)));
}
-QV4::ReturnedValue QQmlDateExtension::method_timeZoneUpdated(QV4::CallContext *ctx)
+void QQmlDateExtension::method_timeZoneUpdated(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 0)
- V4THROW_ERROR("Locale: Date.timeZoneUpdated(): Invalid arguments");
+ if (callData->argc != 0)
+ THROW_ERROR("Locale: Date.timeZoneUpdated(): Invalid arguments");
QV4::DatePrototype::timezoneUpdated();
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
//-----------------
@@ -364,148 +373,143 @@ void QQmlNumberExtension::registerExtension(QV4::ExecutionEngine *engine)
engine->numberCtor()->defineDefaultProperty(QStringLiteral("fromLocaleString"), method_fromLocaleString);
}
-QV4::ReturnedValue QQmlNumberExtension::method_toLocaleString(QV4::CallContext *ctx)
+void QQmlNumberExtension::method_toLocaleString(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- if (ctx->argc() > 3)
- V4THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments");
+ if (callData->argc > 3)
+ THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments");
- double number = ctx->thisObject().toNumber();
+ double number = callData->thisObject.toNumber();
- if (ctx->argc() == 0) {
+ if (callData->argc == 0) {
// Use QLocale for standard toLocaleString() function
QLocale locale;
- return ctx->d()->engine->newString(locale.toString(number))->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(locale.toString(number)));
}
- if (!isLocaleObject(ctx->args()[0]))
- return QV4::NumberPrototype::method_toLocaleString(ctx); // Use the default Number toLocaleString()
-
- QV4::Scope scope(ctx);
+ if (!isLocaleObject(callData->args[0])) {
+ QV4::NumberPrototype::method_toLocaleString(b, scope, callData); // Use the default Number toLocaleString()
+ return;
+ }
- GET_LOCALE_DATA_RESOURCE(ctx->args()[0]);
+ GET_LOCALE_DATA_RESOURCE(callData->args[0]);
quint16 format = 'f';
- if (ctx->argc() > 1) {
- if (!ctx->args()[1].isString())
- V4THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments");
- QString fs = ctx->args()[1].toQString();
+ if (callData->argc > 1) {
+ if (!callData->args[1].isString())
+ THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments");
+ QString fs = callData->args[1].toQString();
if (fs.length())
format = fs.at(0).unicode();
}
int prec = 2;
- if (ctx->argc() > 2) {
- if (!ctx->args()[2].isNumber())
- V4THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments");
- prec = ctx->args()[2].toInt32();
+ if (callData->argc > 2) {
+ if (!callData->args[2].isNumber())
+ THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments");
+ prec = callData->args[2].toInt32();
}
- return ctx->d()->engine->newString(r->d()->locale->toString(number, (char)format, prec))->asReturnedValue();
+ scope.result = scope.engine->newString(r->d()->locale->toString(number, (char)format, prec));
}
-QV4::ReturnedValue QQmlNumberExtension::method_toLocaleCurrencyString(QV4::CallContext *ctx)
+void QQmlNumberExtension::method_toLocaleCurrencyString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() > 2)
- V4THROW_ERROR("Locale: Number.toLocaleCurrencyString(): Invalid arguments");
+ if (callData->argc > 2)
+ THROW_ERROR("Locale: Number.toLocaleCurrencyString(): Invalid arguments");
- double number = ctx->thisObject().toNumber();
+ double number = callData->thisObject.toNumber();
- if (ctx->argc() == 0) {
+ if (callData->argc == 0) {
// Use QLocale for standard toLocaleString() function
QLocale locale;
- return ctx->d()->engine->newString(locale.toString(number))->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(locale.toString(number)));
}
- if (!isLocaleObject(ctx->args()[0]))
- V4THROW_ERROR("Locale: Number.toLocaleCurrencyString(): Invalid arguments");
-
- QV4::Scope scope(ctx);
+ if (!isLocaleObject(callData->args[0]))
+ THROW_ERROR("Locale: Number.toLocaleCurrencyString(): Invalid arguments");
- GET_LOCALE_DATA_RESOURCE(ctx->args()[0]);
+ GET_LOCALE_DATA_RESOURCE(callData->args[0]);
QString symbol;
- if (ctx->argc() > 1) {
- if (!ctx->args()[1].isString())
- V4THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments");
- symbol = ctx->args()[1].toQStringNoThrow();
+ if (callData->argc > 1) {
+ if (!callData->args[1].isString())
+ THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments");
+ symbol = callData->args[1].toQStringNoThrow();
}
- return ctx->d()->engine->newString(r->d()->locale->toCurrencyString(number, symbol))->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(r->d()->locale->toCurrencyString(number, symbol)));
}
-QV4::ReturnedValue QQmlNumberExtension::method_fromLocaleString(QV4::CallContext *ctx)
+void QQmlNumberExtension::method_fromLocaleString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() < 1 || ctx->argc() > 2)
- V4THROW_ERROR("Locale: Number.fromLocaleString(): Invalid arguments");
+ if (callData->argc < 1 || callData->argc > 2)
+ THROW_ERROR("Locale: Number.fromLocaleString(): Invalid arguments");
int numberIdx = 0;
QLocale locale;
- QV4::Scope scope(ctx);
-
- if (ctx->argc() == 2) {
- if (!isLocaleObject(ctx->args()[0]))
- V4THROW_ERROR("Locale: Number.fromLocaleString(): Invalid arguments");
+ if (callData->argc == 2) {
+ if (!isLocaleObject(callData->args[0]))
+ THROW_ERROR("Locale: Number.fromLocaleString(): Invalid arguments");
- GET_LOCALE_DATA_RESOURCE(ctx->args()[0]);
+ GET_LOCALE_DATA_RESOURCE(callData->args[0]);
locale = *r->d()->locale;
numberIdx = 1;
}
- QString ns = ctx->args()[numberIdx].toQString();
+ QString ns = callData->args[numberIdx].toQString();
if (!ns.length())
- return QV4::Encode(Q_QNAN);
+ RETURN_RESULT(QV4::Encode(Q_QNAN));
bool ok = false;
double val = locale.toDouble(ns, &ok);
if (!ok)
- V4THROW_ERROR("Locale: Number.fromLocaleString(): Invalid format")
+ THROW_ERROR("Locale: Number.fromLocaleString(): Invalid format");
- return QV4::Encode(val);
+ scope.result = QV4::Encode(val);
}
//--------------
// Locale object
-QV4::ReturnedValue QQmlLocaleData::method_get_firstDayOfWeek(QV4::CallContext *ctx)
+void QQmlLocaleData::method_get_firstDayOfWeek(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QLocale *locale = getThisLocale(ctx);
+ QLocale *locale = getThisLocale(scope, callData);
if (!locale)
- return QV4::Encode::undefined();
+ return;
int fdow = int(locale->firstDayOfWeek());
if (fdow == 7)
fdow = 0; // Qt::Sunday = 7, but Sunday is 0 in JS Date
- return QV4::Encode(fdow);
+ scope.result = QV4::Encode(fdow);
}
-QV4::ReturnedValue QQmlLocaleData::method_get_measurementSystem(QV4::CallContext *ctx)
+void QQmlLocaleData::method_get_measurementSystem(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QLocale *locale = getThisLocale(ctx);
+ QLocale *locale = getThisLocale(scope, callData);
if (!locale)
- return QV4::Encode::undefined();
- return QV4::Encode(locale->measurementSystem());
+ return;
+ scope.result = QV4::Encode(locale->measurementSystem());
}
-QV4::ReturnedValue QQmlLocaleData::method_get_textDirection(QV4::CallContext *ctx)
+void QQmlLocaleData::method_get_textDirection(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QLocale *locale = getThisLocale(ctx);
+ QLocale *locale = getThisLocale(scope, callData);
if (!locale)
- return QV4::Encode::undefined();
+ return;
- return QV4::Encode(locale->textDirection());
+ scope.result = QV4::Encode(locale->textDirection());
}
-QV4::ReturnedValue QQmlLocaleData::method_get_weekDays(QV4::CallContext *ctx)
+void QQmlLocaleData::method_get_weekDays(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::Scope scope(ctx);
- QLocale *locale = getThisLocale(ctx);
+ QLocale *locale = getThisLocale(scope, callData);
if (!locale)
- return QV4::Encode::undefined();
+ return;
QList<Qt::DayOfWeek> days = locale->weekdays();
- QV4::ScopedArrayObject result(scope, ctx->d()->engine->newArrayObject());
+ QV4::ScopedArrayObject result(scope, scope.engine->newArrayObject());
result->arrayReserve(days.size());
for (int i = 0; i < days.size(); ++i) {
int day = days.at(i);
@@ -515,59 +519,58 @@ QV4::ReturnedValue QQmlLocaleData::method_get_weekDays(QV4::CallContext *ctx)
}
result->setArrayLengthUnchecked(days.size());
- return result.asReturnedValue();
+ scope.result = result.asReturnedValue();
}
-QV4::ReturnedValue QQmlLocaleData::method_get_uiLanguages(QV4::CallContext *ctx)
+void QQmlLocaleData::method_get_uiLanguages(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::Scope scope(ctx);
- QLocale *locale = getThisLocale(ctx);
+ QLocale *locale = getThisLocale(scope, callData);
if (!locale)
- return QV4::Encode::undefined();
+ return;
QStringList langs = locale->uiLanguages();
- QV4::ScopedArrayObject result(scope, ctx->d()->engine->newArrayObject());
+ QV4::ScopedArrayObject result(scope, scope.engine->newArrayObject());
result->arrayReserve(langs.size());
QV4::ScopedValue v(scope);
for (int i = 0; i < langs.size(); ++i)
- result->arrayPut(i, (v = ctx->d()->engine->newString(langs.at(i))));
+ result->arrayPut(i, (v = scope.engine->newString(langs.at(i))));
result->setArrayLengthUnchecked(langs.size());
- return result.asReturnedValue();
+ scope.result = result.asReturnedValue();
}
-QV4::ReturnedValue QQmlLocaleData::method_currencySymbol(QV4::CallContext *ctx)
+void QQmlLocaleData::method_currencySymbol(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QLocale *locale = getThisLocale(ctx);
+ QLocale *locale = getThisLocale(scope, callData);
if (!locale)
- return QV4::Encode::undefined();
+ return;
- if (ctx->argc() > 1)
- V4THROW_ERROR("Locale: currencySymbol(): Invalid arguments");
+ if (callData->argc > 1)
+ THROW_ERROR("Locale: currencySymbol(): Invalid arguments");
QLocale::CurrencySymbolFormat format = QLocale::CurrencySymbol;
- if (ctx->argc() == 1) {
- quint32 intFormat = ctx->args()[0].toNumber();
+ if (callData->argc == 1) {
+ quint32 intFormat = callData->args[0].toNumber();
format = QLocale::CurrencySymbolFormat(intFormat);
}
- return ctx->d()->engine->newString(locale->currencySymbol(format))->asReturnedValue();
+ scope.result = scope.engine->newString(locale->currencySymbol(format));
}
#define LOCALE_FORMAT(FUNC) \
-QV4::ReturnedValue QQmlLocaleData::method_ ##FUNC (QV4::CallContext *ctx) { \
- QLocale *locale = getThisLocale(ctx); \
+void QQmlLocaleData::method_ ##FUNC (const BuiltinFunction *, Scope &scope, CallData *callData) { \
+ QLocale *locale = getThisLocale(scope, callData); \
if (!locale) \
- return QV4::Encode::undefined(); \
- if (ctx->argc() > 1) \
- V4THROW_ERROR("Locale: " #FUNC "(): Invalid arguments"); \
+ return; \
+ if (callData->argc > 1) \
+ THROW_ERROR("Locale: " #FUNC "(): Invalid arguments"); \
QLocale::FormatType format = QLocale::LongFormat;\
- if (ctx->argc() == 1) { \
- quint32 intFormat = ctx->args()[0].toUInt32(); \
+ if (callData->argc == 1) { \
+ quint32 intFormat = callData->args[0].toUInt32(); \
format = QLocale::FormatType(intFormat); \
} \
- return ctx->engine()->newString(locale-> FUNC (format))->asReturnedValue(); \
+ scope.result = scope.engine->newString(locale-> FUNC (format)); \
}
LOCALE_FORMAT(dateTimeFormat)
@@ -576,57 +579,57 @@ LOCALE_FORMAT(dateFormat)
// +1 added to idx because JS is 0-based, whereas QLocale months begin at 1.
#define LOCALE_FORMATTED_MONTHNAME(VARIABLE) \
-QV4::ReturnedValue QQmlLocaleData::method_ ## VARIABLE (QV4::CallContext *ctx) {\
- QLocale *locale = getThisLocale(ctx); \
+void QQmlLocaleData::method_ ## VARIABLE (const BuiltinFunction *, Scope &scope, CallData *callData) {\
+ QLocale *locale = getThisLocale(scope, callData); \
if (!locale) \
- return QV4::Encode::undefined(); \
- if (ctx->argc() < 1 || ctx->argc() > 2) \
- V4THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \
+ return; \
+ if (callData->argc < 1 || callData->argc > 2) \
+ THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \
QLocale::FormatType enumFormat = QLocale::LongFormat; \
- int idx = ctx->args()[0].toInt32() + 1; \
+ int idx = callData->args[0].toInt32() + 1; \
if (idx < 1 || idx > 12) \
- V4THROW_ERROR("Locale: Invalid month"); \
+ THROW_ERROR("Locale: Invalid month"); \
QString name; \
- if (ctx->argc() == 2) { \
- if (ctx->args()[1].isNumber()) { \
- quint32 intFormat = ctx->args()[1].toUInt32(); \
+ if (callData->argc == 2) { \
+ if (callData->args[1].isNumber()) { \
+ quint32 intFormat = callData->args[1].toUInt32(); \
QLocale::FormatType format = QLocale::FormatType(intFormat); \
name = locale-> VARIABLE(idx, format); \
} else { \
- V4THROW_ERROR("Locale: Invalid datetime format"); \
+ THROW_ERROR("Locale: Invalid datetime format"); \
} \
} else { \
name = locale-> VARIABLE(idx, enumFormat); \
} \
- return ctx->engine()->newString(name)->asReturnedValue(); \
+ scope.result = scope.engine->newString(name); \
}
// 0 -> 7 as Qt::Sunday is 7, but Sunday is 0 in JS Date
#define LOCALE_FORMATTED_DAYNAME(VARIABLE) \
-QV4::ReturnedValue QQmlLocaleData::method_ ## VARIABLE (QV4::CallContext *ctx) {\
- QLocale *locale = getThisLocale(ctx); \
+void QQmlLocaleData::method_ ## VARIABLE (const BuiltinFunction *, Scope &scope, CallData *callData) {\
+ QLocale *locale = getThisLocale(scope, callData); \
if (!locale) \
- return QV4::Encode::undefined(); \
- if (ctx->argc() < 1 || ctx->argc() > 2) \
- V4THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \
+ return; \
+ if (callData->argc < 1 || callData->argc > 2) \
+ THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \
QLocale::FormatType enumFormat = QLocale::LongFormat; \
- int idx = ctx->args()[0].toInt32(); \
+ int idx = callData->args[0].toInt32(); \
if (idx < 0 || idx > 7) \
- V4THROW_ERROR("Locale: Invalid day"); \
+ THROW_ERROR("Locale: Invalid day"); \
if (idx == 0) idx = 7; \
QString name; \
- if (ctx->argc() == 2) { \
- if (ctx->args()[1].isNumber()) { \
- quint32 intFormat = ctx->args()[1].toUInt32(); \
+ if (callData->argc == 2) { \
+ if (callData->args[1].isNumber()) { \
+ quint32 intFormat = callData->args[1].toUInt32(); \
QLocale::FormatType format = QLocale::FormatType(intFormat); \
name = locale-> VARIABLE(idx, format); \
} else { \
- V4THROW_ERROR("Locale: Invalid datetime format"); \
+ THROW_ERROR("Locale: Invalid datetime format"); \
} \
} else { \
name = locale-> VARIABLE(idx, enumFormat); \
} \
- return ctx->engine()->newString(name)->asReturnedValue(); \
+ scope.result = scope.engine->newString(name); \
}
LOCALE_FORMATTED_MONTHNAME(monthName)
@@ -634,12 +637,12 @@ LOCALE_FORMATTED_MONTHNAME(standaloneMonthName)
LOCALE_FORMATTED_DAYNAME(dayName)
LOCALE_FORMATTED_DAYNAME(standaloneDayName)
-#define LOCALE_STRING_PROPERTY(VARIABLE) QV4::ReturnedValue QQmlLocaleData::method_get_ ## VARIABLE (QV4::CallContext* ctx) \
+#define LOCALE_STRING_PROPERTY(VARIABLE) void QQmlLocaleData::method_get_ ## VARIABLE (const BuiltinFunction *, Scope &scope, CallData *callData) \
{ \
- QLocale *locale = getThisLocale(ctx); \
+ QLocale *locale = getThisLocale(scope, callData); \
if (!locale) \
- return QV4::Encode::undefined(); \
- return ctx->engine()->newString(locale-> VARIABLE())->asReturnedValue();\
+ return; \
+ scope.result = scope.engine->newString(locale-> VARIABLE());\
}
LOCALE_STRING_PROPERTY(name)
@@ -830,18 +833,22 @@ void QQmlLocale::registerStringLocaleCompare(QV4::ExecutionEngine *engine)
engine->stringPrototype()->defineDefaultProperty(QStringLiteral("localeCompare"), method_localeCompare);
}
-QV4::ReturnedValue QQmlLocale::method_localeCompare(QV4::CallContext *ctx)
+void QQmlLocale::method_localeCompare(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1 || (!ctx->args()[0].isString() && !ctx->args()[0].as<StringObject>()))
- return QV4::StringPrototype::method_localeCompare(ctx);
+ if (callData->argc != 1 || (!callData->args[0].isString() && !callData->args[0].as<StringObject>())) {
+ QV4::StringPrototype::method_localeCompare(b, scope, callData);
+ return;
+ }
- if (!ctx->thisObject().isString() && !ctx->thisObject().as<StringObject>())
- return QV4::StringPrototype::method_localeCompare(ctx);
+ if (!callData->thisObject.isString() && !callData->thisObject.as<StringObject>()) {
+ QV4::StringPrototype::method_localeCompare(b, scope, callData);
+ return;
+ }
- QString thisString = ctx->thisObject().toQStringNoThrow();
- QString thatString = ctx->args()[0].toQStringNoThrow();
+ QString thisString = callData->thisObject.toQStringNoThrow();
+ QString thatString = callData->args[0].toQStringNoThrow();
- return QV4::Encode(QString::localeAwareCompare(thisString, thatString));
+ scope.result = QV4::Encode(QString::localeAwareCompare(thisString, thatString));
}
/*!
diff --git a/src/qml/qml/qqmllocale_p.h b/src/qml/qml/qqmllocale_p.h
index 275f58db7d..1a2ffc72b0 100644
--- a/src/qml/qml/qqmllocale_p.h
+++ b/src/qml/qml/qqmllocale_p.h
@@ -67,13 +67,13 @@ public:
static void registerExtension(QV4::ExecutionEngine *engine);
private:
- static QV4::ReturnedValue method_toLocaleString(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_toLocaleTimeString(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_toLocaleDateString(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_fromLocaleString(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_fromLocaleTimeString(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_fromLocaleDateString(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_timeZoneUpdated(QV4::CallContext *ctx);
+ static void method_toLocaleString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_toLocaleTimeString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_toLocaleDateString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_fromLocaleString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_fromLocaleTimeString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_fromLocaleDateString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_timeZoneUpdated(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
};
@@ -83,9 +83,9 @@ public:
static void registerExtension(QV4::ExecutionEngine *engine);
private:
- static QV4::ReturnedValue method_toLocaleString(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_fromLocaleString(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_toLocaleCurrencyString(QV4::CallContext *ctx);
+ static void method_toLocaleString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_fromLocaleString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_toLocaleCurrencyString(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
};
@@ -135,7 +135,7 @@ public:
private:
QQmlLocale();
- static QV4::ReturnedValue method_localeCompare(QV4::CallContext *ctx);
+ static void method_localeCompare(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
};
namespace QV4 {
@@ -158,43 +158,43 @@ struct QQmlLocaleData : public QV4::Object
V4_OBJECT2(QQmlLocaleData, Object)
V4_NEEDS_DESTROY
- static QLocale *getThisLocale(QV4::CallContext *ctx) {
- QV4::Object *o = ctx->thisObject().as<Object>();
+ static QLocale *getThisLocale(QV4::Scope &scope, QV4::CallData *callData) {
+ QV4::Object *o = callData->thisObject.as<Object>();
QQmlLocaleData *thisObject = o ? o->as<QQmlLocaleData>() : 0;
if (!thisObject) {
- ctx->engine()->throwTypeError();
+ scope.engine->throwTypeError();
return 0;
}
return thisObject->d()->locale;
}
- static QV4::ReturnedValue method_currencySymbol(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_dateTimeFormat(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_timeFormat(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_dateFormat(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_monthName(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_standaloneMonthName(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_dayName(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_standaloneDayName(QV4::CallContext *ctx);
-
- static QV4::ReturnedValue method_get_firstDayOfWeek(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_measurementSystem(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_textDirection(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_weekDays(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_uiLanguages(QV4::CallContext *ctx);
-
- static QV4::ReturnedValue method_get_name(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_nativeLanguageName(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_nativeCountryName(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_decimalPoint(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_groupSeparator(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_percent(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_zeroDigit(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_negativeSign(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_positiveSign(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_exponential(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_amText(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_pmText(QV4::CallContext *ctx);
+ static void method_currencySymbol(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_dateTimeFormat(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_timeFormat(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_dateFormat(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_monthName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_standaloneMonthName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_dayName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_standaloneDayName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+
+ static void method_get_firstDayOfWeek(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_measurementSystem(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_textDirection(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_weekDays(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_uiLanguages(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+
+ static void method_get_name(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_nativeLanguageName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_nativeCountryName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_decimalPoint(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_groupSeparator(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_percent(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_zeroDigit(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_negativeSign(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_positiveSign(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_exponential(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_amText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_pmText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
};
}
diff --git a/src/qml/qml/qqmlloggingcategory.cpp b/src/qml/qml/qqmlloggingcategory.cpp
index fd8fb477c7..764b874131 100644
--- a/src/qml/qml/qqmlloggingcategory.cpp
+++ b/src/qml/qml/qqmlloggingcategory.cpp
@@ -112,13 +112,13 @@ void QQmlLoggingCategory::componentComplete()
{
m_initialized = true;
if (m_name.isNull())
- qmlInfo(this) << QString(QLatin1String("Declaring the name of the LoggingCategory is mandatory and cannot be changed later !"));
+ qmlWarning(this) << QLatin1String("Declaring the name of the LoggingCategory is mandatory and cannot be changed later !");
}
void QQmlLoggingCategory::setName(const QString &name)
{
if (m_initialized) {
- qmlInfo(this) << QString(QLatin1String("The name of a LoggingCategory cannot be changed after the Item is created"));
+ qmlWarning(this) << QLatin1String("The name of a LoggingCategory cannot be changed after the Item is created");
return;
}
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index 51964a7d11..bd6b9a1599 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -79,7 +79,7 @@ struct QQmlMetaTypeData
Files urlToNonFileImportType; // For non-file imported composite and composite
// singleton types. This way we can locate any
// of them by url, even if it was registered as
- // a module via qmlRegisterCompositeType.
+ // a module via QQmlPrivate::RegisterCompositeType
typedef QHash<const QMetaObject *, QQmlType *> MetaObjects;
MetaObjects metaObjectToType;
typedef QHash<int, QQmlMetaType::StringConverter> StringConverters;
@@ -1049,7 +1049,7 @@ void QQmlTypeModulePrivate::add(QQmlType *type)
list.append(type);
}
-QQmlType *QQmlTypeModule::type(const QHashedStringRef &name, int minor)
+QQmlType *QQmlTypeModule::type(const QHashedStringRef &name, int minor) const
{
QMutexLocker lock(metaTypeDataLock());
@@ -1063,7 +1063,7 @@ QQmlType *QQmlTypeModule::type(const QHashedStringRef &name, int minor)
return 0;
}
-QQmlType *QQmlTypeModule::type(const QV4::String *name, int minor)
+QQmlType *QQmlTypeModule::type(const QV4::String *name, int minor) const
{
QMutexLocker lock(metaTypeDataLock());
@@ -1268,6 +1268,19 @@ bool checkRegistration(QQmlType::RegistrationType typeType, QQmlMetaTypeData *da
}
// NOTE: caller must hold a QMutexLocker on "data"
+QQmlTypeModule *getTypeModule(const QHashedString &uri, int majorVersion, QQmlMetaTypeData *data)
+{
+ QQmlMetaTypeData::VersionedUri versionedUri(uri, majorVersion);
+ QQmlTypeModule *module = data->uriToModule.value(versionedUri);
+ if (!module) {
+ module = new QQmlTypeModule;
+ module->d->uri = versionedUri;
+ data->uriToModule.insert(versionedUri, module);
+ }
+ return module;
+}
+
+// NOTE: caller must hold a QMutexLocker on "data"
void addTypeToData(QQmlType* type, QQmlMetaTypeData *data)
{
if (!type->elementName().isEmpty())
@@ -1293,13 +1306,8 @@ void addTypeToData(QQmlType* type, QQmlMetaTypeData *data)
if (!type->module().isEmpty()) {
const QHashedString &mod = type->module();
- QQmlMetaTypeData::VersionedUri versionedUri(mod, type->majorVersion());
- QQmlTypeModule *module = data->uriToModule.value(versionedUri);
- if (!module) {
- module = new QQmlTypeModule;
- module->d->uri = versionedUri;
- data->uriToModule.insert(versionedUri, module);
- }
+ QQmlTypeModule *module = getTypeModule(mod, type->majorVersion(), data);
+ Q_ASSERT(module);
module->d->add(type);
}
}
@@ -1442,13 +1450,27 @@ bool qmlProtectModule(const char *uri, int majVersion)
return false;
}
-bool QQmlMetaType::namespaceContainsRegistrations(const QString &uri, int majorVersion)
+//From qqml.h
+void qmlRegisterModule(const char *uri, int versionMajor, int versionMinor)
{
+ QMutexLocker lock(metaTypeDataLock());
QQmlMetaTypeData *data = metaTypeData();
+ QQmlTypeModule *module = getTypeModule(QString::fromUtf8(uri), versionMajor, data);
+ Q_ASSERT(module);
+
+ QQmlTypeModulePrivate *p = QQmlTypeModulePrivate::get(module);
+ p->minMinorVersion = qMin(p->minMinorVersion, versionMinor);
+ p->maxMinorVersion = qMax(p->maxMinorVersion, versionMinor);
+}
+
+bool QQmlMetaType::namespaceContainsRegistrations(const QString &uri, int majorVersion)
+{
+ const QQmlMetaTypeData *data = metaTypeData();
+
// Has any type previously been installed to this namespace?
QHashedString nameSpace(uri);
- foreach (const QQmlType *type, data->types)
+ for (const QQmlType *type : data->types)
if (type->module() == nameSpace && type->majorVersion() == majorVersion)
return true;
@@ -1957,7 +1979,7 @@ QString QQmlMetaType::prettyTypeName(const QObject *object)
marker = typeName.indexOf(QLatin1String("_QML_"));
if (marker != -1) {
- typeName = typeName.left(marker) + QLatin1Char('*');
+ typeName = typeName.leftRef(marker) + QLatin1Char('*');
type = QQmlMetaType::qmlType(QMetaType::type(typeName.toLatin1()));
if (type) {
typeName = type->qmlTypeName();
diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h
index 9afe4825dc..2b615e645a 100644
--- a/src/qml/qml/qqmlmetatype_p.h
+++ b/src/qml/qml/qqmlmetatype_p.h
@@ -259,13 +259,14 @@ public:
int minimumMinorVersion() const;
int maximumMinorVersion() const;
- QQmlType *type(const QHashedStringRef &, int);
- QQmlType *type(const QV4::String *, int);
+ QQmlType *type(const QHashedStringRef &, int) const;
+ QQmlType *type(const QV4::String *, int) const;
QList<QQmlType*> singletonTypes(int) const;
private:
//Used by register functions and creates the QQmlTypeModule for them
+ friend QQmlTypeModule *getTypeModule(const QHashedString &uri, int majorVersion, QQmlMetaTypeData *data);
friend void addTypeToData(QQmlType* type, QQmlMetaTypeData *data);
friend struct QQmlMetaTypeData;
friend Q_QML_EXPORT void qmlClearTypeRegistrations();
diff --git a/src/qml/qml/qqmlnotifier_p.h b/src/qml/qml/qqmlnotifier_p.h
index 14024c0113..dad79e0e55 100644
--- a/src/qml/qml/qqmlnotifier_p.h
+++ b/src/qml/qml/qqmlnotifier_p.h
@@ -96,9 +96,9 @@ public:
inline QQmlNotifierEndpoint(Callback callback);
inline ~QQmlNotifierEndpoint();
- inline bool isConnected();
- inline bool isConnected(QObject *source, int sourceSignal);
- inline bool isConnected(QQmlNotifier *);
+ inline bool isConnected() const;
+ inline bool isConnected(QObject *source, int sourceSignal) const;
+ inline bool isConnected(QQmlNotifier *) const;
void connect(QObject *source, int sourceSignal, QQmlEngine *engine);
inline void connect(QQmlNotifier *);
@@ -164,7 +164,7 @@ QQmlNotifierEndpoint::~QQmlNotifierEndpoint()
disconnect();
}
-bool QQmlNotifierEndpoint::isConnected()
+bool QQmlNotifierEndpoint::isConnected() const
{
return prev != 0;
}
@@ -173,13 +173,13 @@ bool QQmlNotifierEndpoint::isConnected()
\a sourceSignal MUST be in the signal index range (see QObjectPrivate::signalIndex()).
This is different from QMetaMethod::methodIndex().
*/
-bool QQmlNotifierEndpoint::isConnected(QObject *source, int sourceSignal)
+bool QQmlNotifierEndpoint::isConnected(QObject *source, int sourceSignal) const
{
return this->sourceSignal != -1 && senderAsObject() == source &&
this->sourceSignal == sourceSignal;
}
-bool QQmlNotifierEndpoint::isConnected(QQmlNotifier *notifier)
+bool QQmlNotifierEndpoint::isConnected(QQmlNotifier *notifier) const
{
return sourceSignal == -1 && senderAsNotifier() == notifier;
}
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index 09936f6e7a..85fbd86dc4 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -170,7 +170,7 @@ QObject *QQmlObjectCreator::create(int subComponentIndex, QObject *parent, QQmlI
context = new QQmlContextData;
context->isInternal = true;
- context->imports = compilationUnit->importCache;
+ context->imports = compilationUnit->typeNameCache;
context->initFromTypeCompilationUnit(compilationUnit, subComponentIndex);
context->setParent(parentContext);
@@ -1150,7 +1150,7 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo
if (customParser && obj->flags & QV4::CompiledData::Object::HasCustomParserBindings) {
customParser->engine = QQmlEnginePrivate::get(engine);
- customParser->imports = compilationUnit->importCache;
+ customParser->imports = compilationUnit->typeNameCache;
QList<const QV4::CompiledData::Binding *> bindings;
const QV4::CompiledData::Object *obj = qmlUnit->objectAt(index);
@@ -1270,6 +1270,21 @@ QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interru
return sharedState->rootContext;
}
+void QQmlObjectCreator::cancel(QObject *object)
+{
+ int last = sharedState->allCreatedObjects.count() - 1;
+ int i = last;
+ while (i >= 0) {
+ if (sharedState->allCreatedObjects.at(i) == object) {
+ if (i < last)
+ qSwap(sharedState->allCreatedObjects[i], sharedState->allCreatedObjects[last]);
+ sharedState->allCreatedObjects.pop();
+ break;
+ }
+ --i;
+ }
+}
+
void QQmlObjectCreator::clear()
{
if (phase == Done || phase == Finalizing || phase == Startup)
diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h
index e3312f9df5..982324be3c 100644
--- a/src/qml/qml/qqmlobjectcreator_p.h
+++ b/src/qml/qml/qqmlobjectcreator_p.h
@@ -90,15 +90,16 @@ public:
QObject *create(int subComponentIndex = -1, QObject *parent = 0, QQmlInstantiationInterrupt *interrupt = 0);
bool populateDeferredProperties(QObject *instance);
QQmlContextData *finalize(QQmlInstantiationInterrupt &interrupt);
+ void cancel(QObject *object);
void clear();
- QQmlComponentAttached **componentAttachment() { return &sharedState->componentAttached; }
+ QQmlComponentAttached **componentAttachment() const { return &sharedState->componentAttached; }
- QList<QQmlEnginePrivate::FinalizeCallback> *finalizeCallbacks() { return &sharedState->finalizeCallbacks; }
+ QList<QQmlEnginePrivate::FinalizeCallback> *finalizeCallbacks() const { return &sharedState->finalizeCallbacks; }
QList<QQmlError> errors;
- QQmlContextData *parentContextData() { return parentContext.contextData(); }
+ QQmlContextData *parentContextData() const { return parentContext.contextData(); }
QFiniteStack<QPointer<QObject> > &allCreatedObjects() const { return sharedState->allCreatedObjects; }
private:
diff --git a/src/qml/qml/qqmlopenmetaobject_p.h b/src/qml/qml/qqmlopenmetaobject_p.h
index f1562131fc..4bb92489a5 100644
--- a/src/qml/qml/qqmlopenmetaobject_p.h
+++ b/src/qml/qml/qqmlopenmetaobject_p.h
@@ -83,7 +83,7 @@ public:
protected:
virtual void propertyCreated(int, QMetaPropertyBuilder &);
- virtual void clear();
+ void clear() override;
private:
QQmlOpenMetaObjectTypePrivate *d;
@@ -122,8 +122,8 @@ public:
void emitPropertyNotification(const QByteArray &propertyName);
protected:
- virtual int metaCall(QObject *o, QMetaObject::Call _c, int _id, void **_a);
- virtual int createProperty(const char *, const char *);
+ int metaCall(QObject *o, QMetaObject::Call _c, int _id, void **_a) override;
+ int createProperty(const char *, const char *) override;
virtual void propertyRead(int);
virtual void propertyWrite(int);
diff --git a/src/qml/qml/qqmlplatform.cpp b/src/qml/qml/qqmlplatform.cpp
index a47a0ab4a4..64ca208f1b 100644
--- a/src/qml/qml/qqmlplatform.cpp
+++ b/src/qml/qml/qqmlplatform.cpp
@@ -59,16 +59,12 @@ QString QQmlPlatform::os()
{
#if defined(Q_OS_ANDROID)
return QStringLiteral("android");
-#elif defined(Q_OS_BLACKBERRY)
- return QStringLiteral("blackberry");
#elif defined(Q_OS_IOS)
return QStringLiteral("ios");
#elif defined(Q_OS_TVOS)
return QStringLiteral("tvos");
#elif defined(Q_OS_MAC)
return QStringLiteral("osx");
-#elif defined(Q_OS_WINPHONE)
- return QStringLiteral("winphone");
#elif defined(Q_OS_WINRT)
return QStringLiteral("winrt");
#elif defined(Q_OS_WIN)
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 7df8336f51..ca522c29af 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -285,7 +285,7 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
QQmlPropertyData local;
QQmlPropertyData *property =
- QQmlPropertyCache::property(engine, currentObject, pathName.toString(), context, local);
+ QQmlPropertyCache::property(engine, currentObject, pathName, context, local);
if (!property) return; // Not a property
if (property->isFunction())
@@ -350,7 +350,7 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
// Try property
if (signalName.endsWith(QLatin1String("Changed"))) {
- QString propName = signalName.mid(0, signalName.length() - 7);
+ const QStringRef propName = signalName.midRef(0, signalName.length() - 7);
QQmlPropertyData *d = ddata->propertyCache->property(propName, currentObject, context);
while (d && d->isFunction())
d = ddata->propertyCache->overrideData(d);
@@ -374,14 +374,13 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
}
// Property
- const QString terminalString = terminal.toString();
QQmlPropertyData local;
QQmlPropertyData *property =
- QQmlPropertyCache::property(engine, currentObject, terminalString, context, local);
+ QQmlPropertyCache::property(engine, currentObject, terminal, context, local);
if (property && !property->isFunction()) {
object = currentObject;
core = *property;
- nameCache = terminalString;
+ nameCache = terminal.toString();
isNameCached = true;
}
}
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp
index a110dccee2..88ce2fa1b9 100644
--- a/src/qml/qml/qqmlpropertycache.cpp
+++ b/src/qml/qml/qqmlpropertycache.cpp
@@ -76,7 +76,8 @@ public:
int argumentsValid:1;
QList<QByteArray> *names;
- int arguments[0];
+
+ int arguments[1];
};
// Flags that do *NOT* depend on the property's QMetaProperty::userType() and thus are quick
@@ -193,7 +194,7 @@ void QQmlPropertyData::load(const QMetaMethod &m)
if (m.parameterCount()) {
_flags.hasArguments = true;
- if ((m.parameterCount() == 1) && (m.parameterTypes().first() == "QQmlV4Function*")) {
+ if ((m.parameterCount() == 1) && (m.parameterTypes().constFirst() == "QQmlV4Function*")) {
_flags.isV4Function = true;
}
}
@@ -228,7 +229,7 @@ void QQmlPropertyData::lazyLoad(const QMetaMethod &m)
const int paramCount = m.parameterCount();
if (paramCount) {
_flags.hasArguments = true;
- if ((paramCount == 1) && (m.parameterTypes().first() == "QQmlV4Function*")) {
+ if ((paramCount == 1) && (m.parameterTypes().constFirst() == "QQmlV4Function*")) {
_flags.isV4Function = true;
}
}
@@ -269,8 +270,8 @@ QQmlPropertyCache::~QQmlPropertyCache()
QQmlPropertyCacheMethodArguments *args = argumentsCache;
while (args) {
QQmlPropertyCacheMethodArguments *next = args->next;
- if (args->signalParameterStringForJS) delete args->signalParameterStringForJS;
- if (args->names) delete args->names;
+ delete args->signalParameterStringForJS;
+ delete args->names;
free(args);
args = next;
}
@@ -919,7 +920,7 @@ static int EnumType(const QMetaObject *metaobj, const QByteArray &str, int type)
QQmlPropertyCacheMethodArguments *QQmlPropertyCache::createArgumentsObject(int argc, const QList<QByteArray> &names)
{
typedef QQmlPropertyCacheMethodArguments A;
- A *args = static_cast<A *>(malloc(sizeof(A) + (argc + 1) * sizeof(int)));
+ A *args = static_cast<A *>(malloc(sizeof(A) + (argc) * sizeof(int)));
args->arguments[0] = argc;
args->argumentsValid = false;
args->signalParameterStringForJS = 0;
@@ -978,7 +979,8 @@ int QQmlPropertyCache::originalClone(QObject *object, int index)
return index;
}
-QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject, const QString &property)
+template<typename T>
+static QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject, const T& propertyName)
{
Q_ASSERT(metaObject);
@@ -995,8 +997,6 @@ QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject, const QS
// These indices don't apply to gadgets, so don't block them.
const bool preventDestruction = metaObject->superClass() || metaObject == &QObject::staticMetaObject;
- const QByteArray propertyName = property.toUtf8();
-
int methodCount = metaObject->methodCount();
for (int ii = methodCount - 1; ii >= 0; --ii) {
if (preventDestruction && (ii == destroyedIdx1 || ii == destroyedIdx2 || ii == deleteLaterIdx))
@@ -1038,14 +1038,19 @@ QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject, const QS
return rv;
}
-inline const QString &qQmlPropertyCacheToString(const QString &string)
+static inline const char *qQmlPropertyCacheToString(QLatin1String string)
{
- return string;
+ return string.data();
}
-inline QString qQmlPropertyCacheToString(const QV4::String *string)
+static inline QByteArray qQmlPropertyCacheToString(const QStringRef &string)
{
- return string->toQString();
+ return string.toUtf8();
+}
+
+static inline QByteArray qQmlPropertyCacheToString(const QV4::String *string)
+{
+ return string->toQString().toUtf8();
}
template<typename T>
@@ -1090,10 +1095,10 @@ QQmlPropertyCache::property(QJSEngine *engine, QObject *obj, const QV4::String *
}
QQmlPropertyData *
-QQmlPropertyCache::property(QJSEngine *engine, QObject *obj,
- const QString &name, QQmlContextData *context, QQmlPropertyData &local)
+QQmlPropertyCache::property(QJSEngine *engine, QObject *obj, const QStringRef &name,
+ QQmlContextData *context, QQmlPropertyData &local)
{
- return qQmlPropertyCacheProperty<const QString &>(engine, obj, name, context, local);
+ return qQmlPropertyCacheProperty<const QStringRef &>(engine, obj, name, context, local);
}
QQmlPropertyData *
diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h
index 60414188a5..64be1cb206 100644
--- a/src/qml/qml/qqmlpropertycache_p.h
+++ b/src/qml/qml/qqmlpropertycache_p.h
@@ -406,13 +406,19 @@ public:
inline QQmlPropertyData *overrideData(QQmlPropertyData *) const;
inline bool isAllowedInRevision(QQmlPropertyData *) const;
- static QQmlPropertyData *property(QJSEngine *, QObject *, const QString &,
+ static QQmlPropertyData *property(QJSEngine *, QObject *, const QStringRef &,
QQmlContextData *, QQmlPropertyData &);
static QQmlPropertyData *property(QJSEngine *, QObject *, const QLatin1String &,
QQmlContextData *, QQmlPropertyData &);
static QQmlPropertyData *property(QJSEngine *, QObject *, const QV4::String *,
QQmlContextData *, QQmlPropertyData &);
+ static QQmlPropertyData *property(QJSEngine *engine, QObject *obj, const QString &name,
+ QQmlContextData *context, QQmlPropertyData &local)
+ {
+ return property(engine, obj, QStringRef(&name), context, local);
+ }
+
//see QMetaObjectPrivate::originalClone
int originalClone(int index);
static int originalClone(QObject *, int index);
@@ -441,8 +447,8 @@ public:
QByteArray checksum(bool *ok);
protected:
- virtual void destroy();
- virtual void clear();
+ void destroy() override;
+ void clear() override;
private:
friend class QQmlEnginePrivate;
@@ -474,7 +480,7 @@ private:
void updateRecur(const QMetaObject *);
template<typename K>
- QQmlPropertyData *findNamedProperty(const K &key)
+ QQmlPropertyData *findNamedProperty(const K &key) const
{
StringCache::mapped_type *it = stringCache.value(key);
return it ? it->second : 0;
diff --git a/src/qml/qml/qqmlproxymetaobject_p.h b/src/qml/qml/qqmlproxymetaobject_p.h
index 7083f88fa7..2b7a980361 100644
--- a/src/qml/qml/qqmlproxymetaobject_p.h
+++ b/src/qml/qml/qqmlproxymetaobject_p.h
@@ -74,10 +74,10 @@ public:
};
QQmlProxyMetaObject(QObject *, QList<ProxyData> *);
- virtual ~QQmlProxyMetaObject();
+ ~QQmlProxyMetaObject();
protected:
- virtual int metaCall(QObject *o, QMetaObject::Call _c, int _id, void **_a);
+ int metaCall(QObject *o, QMetaObject::Call _c, int _id, void **_a) override;
private:
QList<ProxyData> *metaObjects;
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index 7ad18c8efb..f4f04e12c0 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -165,7 +165,7 @@ public:
void initializeEngine(QQmlExtensionInterface *, const char *);
protected:
- virtual void shutdownThread();
+ void shutdownThread() override;
private:
void loadThread(QQmlDataBlob *b);
@@ -1362,8 +1362,9 @@ bool QQmlTypeLoader::Blob::updateQmldir(QQmlQmldirData *data, const QV4::Compile
if (!importQualifier.isEmpty()) {
// Does this library contain any qualified scripts?
QUrl libraryUrl(qmldirUrl);
- const QmldirContent *qmldir = typeLoader()->qmldirContent(qmldirIdentifier);
- foreach (const QQmlDirParser::Script &script, qmldir->scripts()) {
+ const QQmlTypeLoaderQmldirContent *qmldir = typeLoader()->qmldirContent(qmldirIdentifier);
+ const auto qmldirScripts = qmldir->scripts();
+ for (const QQmlDirParser::Script &script : qmldirScripts) {
QUrl scriptUrl = libraryUrl.resolved(QUrl(script.fileName));
QQmlScriptBlob *blob = typeLoader()->getScript(scriptUrl);
addDependency(blob);
@@ -1409,8 +1410,9 @@ bool QQmlTypeLoader::Blob::addImport(const QV4::CompiledData::Import *import, QL
if (!importQualifier.isEmpty()) {
// Does this library contain any qualified scripts?
QUrl libraryUrl(qmldirUrl);
- const QmldirContent *qmldir = typeLoader()->qmldirContent(qmldirFilePath);
- foreach (const QQmlDirParser::Script &script, qmldir->scripts()) {
+ const QQmlTypeLoaderQmldirContent *qmldir = typeLoader()->qmldirContent(qmldirFilePath);
+ const auto qmldirScripts = qmldir->scripts();
+ for (const QQmlDirParser::Script &script : qmldirScripts) {
QUrl scriptUrl = libraryUrl.resolved(QUrl(script.fileName));
QQmlScriptBlob *blob = typeLoader()->getScript(scriptUrl);
addDependency(blob);
@@ -1537,57 +1539,57 @@ bool QQmlTypeLoader::Blob::qmldirDataAvailable(QQmlQmldirData *data, QList<QQmlE
}
-QQmlTypeLoader::QmldirContent::QmldirContent()
+QQmlTypeLoaderQmldirContent::QQmlTypeLoaderQmldirContent()
{
}
-bool QQmlTypeLoader::QmldirContent::hasError() const
+bool QQmlTypeLoaderQmldirContent::hasError() const
{
return m_parser.hasError();
}
-QList<QQmlError> QQmlTypeLoader::QmldirContent::errors(const QString &uri) const
+QList<QQmlError> QQmlTypeLoaderQmldirContent::errors(const QString &uri) const
{
return m_parser.errors(uri);
}
-QString QQmlTypeLoader::QmldirContent::typeNamespace() const
+QString QQmlTypeLoaderQmldirContent::typeNamespace() const
{
return m_parser.typeNamespace();
}
-void QQmlTypeLoader::QmldirContent::setContent(const QString &location, const QString &content)
+void QQmlTypeLoaderQmldirContent::setContent(const QString &location, const QString &content)
{
m_location = location;
m_parser.parse(content);
}
-void QQmlTypeLoader::QmldirContent::setError(const QQmlError &error)
+void QQmlTypeLoaderQmldirContent::setError(const QQmlError &error)
{
m_parser.setError(error);
}
-QQmlDirComponents QQmlTypeLoader::QmldirContent::components() const
+QQmlDirComponents QQmlTypeLoaderQmldirContent::components() const
{
return m_parser.components();
}
-QQmlDirScripts QQmlTypeLoader::QmldirContent::scripts() const
+QQmlDirScripts QQmlTypeLoaderQmldirContent::scripts() const
{
return m_parser.scripts();
}
-QQmlDirPlugins QQmlTypeLoader::QmldirContent::plugins() const
+QQmlDirPlugins QQmlTypeLoaderQmldirContent::plugins() const
{
return m_parser.plugins();
}
-QString QQmlTypeLoader::QmldirContent::pluginLocation() const
+QString QQmlTypeLoaderQmldirContent::pluginLocation() const
{
return m_location;
}
-bool QQmlTypeLoader::QmldirContent::designerSupported() const
+bool QQmlTypeLoaderQmldirContent::designerSupported() const
{
return m_parser.designerSupported();
}
@@ -1615,7 +1617,7 @@ QQmlTypeLoader::~QQmlTypeLoader()
invalidate();
}
-QQmlImportDatabase *QQmlTypeLoader::importDatabase()
+QQmlImportDatabase *QQmlTypeLoader::importDatabase() const
{
return &QQmlEnginePrivate::get(engine())->importDatabase;
}
@@ -1859,13 +1861,13 @@ bool QQmlTypeLoader::directoryExists(const QString &path)
/*!
-Return a QmldirContent for absoluteFilePath. The QmldirContent may be cached.
+Return a QQmlTypeLoaderQmldirContent for absoluteFilePath. The QQmlTypeLoaderQmldirContent may be cached.
\a filePath is a local file path.
It can also be a remote path for a remote directory import, but it will have been cached by now in this case.
*/
-const QQmlTypeLoader::QmldirContent *QQmlTypeLoader::qmldirContent(const QString &filePathIn)
+const QQmlTypeLoaderQmldirContent *QQmlTypeLoader::qmldirContent(const QString &filePathIn)
{
QUrl url(filePathIn); //May already contain http scheme
if (url.scheme() == QLatin1String("http") || url.scheme() == QLatin1String("https"))
@@ -1881,10 +1883,10 @@ const QQmlTypeLoader::QmldirContent *QQmlTypeLoader::qmldirContent(const QString
else
filePath = url.path();
- QmldirContent *qmldir;
- QmldirContent **val = m_importQmlDirCache.value(filePath);
+ QQmlTypeLoaderQmldirContent *qmldir;
+ QQmlTypeLoaderQmldirContent **val = m_importQmlDirCache.value(filePath);
if (!val) {
- qmldir = new QmldirContent;
+ qmldir = new QQmlTypeLoaderQmldirContent;
#define ERROR(description) { QQmlError e; e.setDescription(description); qmldir->setError(e); }
#define NOT_READABLE_ERROR QString(QLatin1String("module \"$$URI$$\" definition \"%1\" not readable"))
@@ -1914,12 +1916,12 @@ const QQmlTypeLoader::QmldirContent *QQmlTypeLoader::qmldirContent(const QString
void QQmlTypeLoader::setQmldirContent(const QString &url, const QString &content)
{
- QmldirContent *qmldir;
- QmldirContent **val = m_importQmlDirCache.value(url);
+ QQmlTypeLoaderQmldirContent *qmldir;
+ QQmlTypeLoaderQmldirContent **val = m_importQmlDirCache.value(url);
if (val) {
qmldir = *val;
} else {
- qmldir = new QmldirContent;
+ qmldir = new QQmlTypeLoaderQmldirContent;
m_importQmlDirCache.insert(url, qmldir);
}
@@ -2073,6 +2075,11 @@ bool QQmlTypeData::tryLoadFromDiskCache()
}
}
+ if (unit->data->flags & QV4::CompiledData::Unit::PendingTypeCompilation) {
+ restoreIR(unit);
+ return true;
+ }
+
m_compiledData = unit;
for (int i = 0, count = m_compiledData->objectCount(); i < count; ++i)
@@ -2125,11 +2132,11 @@ bool QQmlTypeData::tryLoadFromDiskCache()
return true;
}
-void QQmlTypeData::createTypeAndPropertyCaches(const QQmlRefPointer<QQmlTypeNameCache> &importCache,
+void QQmlTypeData::createTypeAndPropertyCaches(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache,
const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache)
{
Q_ASSERT(m_compiledData);
- m_compiledData->importCache = importCache;
+ m_compiledData->typeNameCache = typeNameCache;
m_compiledData->resolvedTypes = resolvedTypeCache;
QQmlEnginePrivate * const engine = QQmlEnginePrivate::get(typeLoader()->engine());
@@ -2215,10 +2222,10 @@ void QQmlTypeData::done()
}
}
- QQmlRefPointer<QQmlTypeNameCache> importCache;
+ QQmlRefPointer<QQmlTypeNameCache> typeNameCache;
QV4::CompiledData::ResolvedTypeReferenceMap resolvedTypeCache;
{
- QQmlCompileError error = buildTypeResolutionCaches(&importCache, &resolvedTypeCache);
+ QQmlCompileError error = buildTypeResolutionCaches(&typeNameCache, &resolvedTypeCache);
if (error.isSet()) {
setError(error);
return;
@@ -2238,9 +2245,9 @@ void QQmlTypeData::done()
if (!m_document.isNull()) {
// Compile component
- compile(importCache, resolvedTypeCache);
+ compile(typeNameCache, resolvedTypeCache);
} else {
- createTypeAndPropertyCaches(importCache, resolvedTypeCache);
+ createTypeAndPropertyCaches(typeNameCache, resolvedTypeCache);
}
if (isError())
@@ -2301,7 +2308,7 @@ void QQmlTypeData::done()
qualifier = qualifier.mid(lastDotIndex+1);
}
- m_compiledData->importCache->add(qualifier.toString(), scriptIndex, enclosingNamespace);
+ m_compiledData->typeNameCache->add(qualifier.toString(), scriptIndex, enclosingNamespace);
QQmlScriptData *scriptData = script.script->scriptData();
scriptData->addref();
m_compiledData->dependentScripts << scriptData;
@@ -2381,7 +2388,7 @@ bool QQmlTypeData::loadFromSource()
if (!compiler.generateFromQml(code, finalUrlString(), m_document.data())) {
QList<QQmlError> errors;
errors.reserve(compiler.errors.count());
- foreach (const QQmlJS::DiagnosticMessage &msg, compiler.errors) {
+ for (const QQmlJS::DiagnosticMessage &msg : qAsConst(compiler.errors)) {
QQmlError e;
e.setUrl(finalUrl());
e.setLine(msg.loc.startLine);
@@ -2395,6 +2402,15 @@ bool QQmlTypeData::loadFromSource()
return true;
}
+void QQmlTypeData::restoreIR(QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit)
+{
+ m_document.reset(new QmlIR::Document(isDebugging()));
+ QmlIR::IRLoader loader(unit->data, m_document.data());
+ loader.load();
+ m_document->javaScriptCompilationUnit = unit;
+ continueLoadFromIR();
+}
+
void QQmlTypeData::continueLoadFromIR()
{
m_typeReferences.collectFromObjects(m_document->objects.constBegin(), m_document->objects.constEnd());
@@ -2426,7 +2442,7 @@ void QQmlTypeData::continueLoadFromIR()
QList<QQmlError> errors;
- foreach (const QV4::CompiledData::Import *import, m_document->imports) {
+ for (const QV4::CompiledData::Import *import : qAsConst(m_document->imports)) {
if (!addImport(import, &errors)) {
Q_ASSERT(errors.size());
QQmlError error(errors.takeFirst());
@@ -2487,12 +2503,12 @@ QString QQmlTypeData::stringAt(int index) const
return m_document->jsGenerator.stringTable.stringForIndex(index);
}
-void QQmlTypeData::compile(const QQmlRefPointer<QQmlTypeNameCache> &importCache, const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache)
+void QQmlTypeData::compile(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache, const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache)
{
Q_ASSERT(m_compiledData.isNull());
QQmlEnginePrivate * const enginePrivate = QQmlEnginePrivate::get(typeLoader()->engine());
- QQmlTypeCompiler compiler(enginePrivate, this, m_document.data(), importCache, resolvedTypeCache);
+ QQmlTypeCompiler compiler(enginePrivate, this, m_document.data(), typeNameCache, resolvedTypeCache);
m_compiledData = compiler.compile();
if (!m_compiledData) {
setError(compiler.compilationErrors());
@@ -2516,8 +2532,8 @@ void QQmlTypeData::compile(const QQmlRefPointer<QQmlTypeNameCache> &importCache,
void QQmlTypeData::resolveTypes()
{
// Add any imported scripts to our resolved set
- foreach (const QQmlImports::ScriptReference &script, m_importCache.resolvedScripts())
- {
+ const auto resolvedScripts = m_importCache.resolvedScripts();
+ for (const QQmlImports::ScriptReference &script : resolvedScripts) {
QQmlScriptBlob *blob = typeLoader()->getScript(script.location);
addDependency(blob);
@@ -2537,7 +2553,8 @@ void QQmlTypeData::resolveTypes()
}
// Lets handle resolved composite singleton types
- foreach (const QQmlImports::CompositeSingletonReference &csRef, m_importCache.resolvedCompositeSingletons()) {
+ const auto resolvedCompositeSingletons = m_importCache.resolvedCompositeSingletons();
+ for (const QQmlImports::CompositeSingletonReference &csRef : resolvedCompositeSingletons) {
TypeReference ref;
QString typeName;
if (!csRef.prefix.isEmpty()) {
@@ -2572,50 +2589,11 @@ void QQmlTypeData::resolveTypes()
int majorVersion = -1;
int minorVersion = -1;
- QQmlImportNamespace *typeNamespace = 0;
- QList<QQmlError> errors;
const QString name = stringAt(unresolvedRef.key());
- bool typeFound = m_importCache.resolveType(name, &ref.type,
- &majorVersion, &minorVersion, &typeNamespace, &errors);
- if (!typeNamespace && !typeFound && !m_implicitImportLoaded) {
- // Lazy loading of implicit import
- if (loadImplicitImport()) {
- // Try again to find the type
- errors.clear();
- typeFound = m_importCache.resolveType(name, &ref.type,
- &majorVersion, &minorVersion, &typeNamespace, &errors);
- } else {
- return; //loadImplicitImport() hit an error, and called setError already
- }
- }
-
- if ((!typeFound || typeNamespace) && reportErrors) {
- // Known to not be a type:
- // - known to be a namespace (Namespace {})
- // - type with unknown namespace (UnknownNamespace.SomeType {})
- QQmlError error;
- if (typeNamespace) {
- error.setDescription(QQmlTypeLoader::tr("Namespace %1 cannot be used as a type").arg(name));
- } else {
- if (errors.size()) {
- error = errors.takeFirst();
- } else {
- // this should not be possible!
- // Description should come from error provided by addImport() function.
- error.setDescription(QQmlTypeLoader::tr("Unreported error adding script import to import database"));
- }
- error.setUrl(m_importCache.baseUrl());
- error.setDescription(QQmlTypeLoader::tr("%1 %2").arg(name).arg(error.description()));
- }
- error.setLine(unresolvedRef->location.line);
- error.setColumn(unresolvedRef->location.column);
-
- errors.prepend(error);
- setError(errors);
+ if (!resolveType(name, majorVersion, minorVersion, ref, unresolvedRef->location.line, unresolvedRef->location.column, reportErrors) && reportErrors)
return;
- }
if (ref.type && ref.type->isComposite()) {
ref.typeData = typeLoader()->getType(ref.type->sourceUrl());
@@ -2634,20 +2612,20 @@ void QQmlTypeData::resolveTypes()
}
QQmlCompileError QQmlTypeData::buildTypeResolutionCaches(
- QQmlRefPointer<QQmlTypeNameCache> *importCache,
+ QQmlRefPointer<QQmlTypeNameCache> *typeNameCache,
QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypeCache
) const
{
- importCache->adopt(new QQmlTypeNameCache);
+ typeNameCache->adopt(new QQmlTypeNameCache(m_importCache));
for (const QString &ns: m_namespaces)
- (*importCache)->add(ns);
+ (*typeNameCache)->add(ns);
// Add any Composite Singletons that were used to the import cache
for (const QQmlTypeData::TypeReference &singleton: m_compositeSingletons)
- (*importCache)->add(singleton.type->qmlTypeName(), singleton.type->sourceUrl(), singleton.prefix);
+ (*typeNameCache)->add(singleton.type->qmlTypeName(), singleton.type->sourceUrl(), singleton.prefix);
- m_importCache.populateCache(*importCache);
+ m_importCache.populateCache(*typeNameCache);
QQmlEnginePrivate * const engine = QQmlEnginePrivate::get(typeLoader()->engine());
@@ -2684,7 +2662,7 @@ QQmlCompileError QQmlTypeData::buildTypeResolutionCaches(
return noError;
}
-bool QQmlTypeData::resolveType(const QString &typeName, int &majorVersion, int &minorVersion, TypeReference &ref)
+bool QQmlTypeData::resolveType(const QString &typeName, int &majorVersion, int &minorVersion, TypeReference &ref, int lineNumber, int columnNumber, bool reportErrors)
{
QQmlImportNamespace *typeNamespace = 0;
QList<QQmlError> errors;
@@ -2703,7 +2681,7 @@ bool QQmlTypeData::resolveType(const QString &typeName, int &majorVersion, int &
}
}
- if (!typeFound || typeNamespace) {
+ if ((!typeFound || typeNamespace) && reportErrors) {
// Known to not be a type:
// - known to be a namespace (Namespace {})
// - type with unknown namespace (UnknownNamespace.SomeType {})
@@ -2722,6 +2700,11 @@ bool QQmlTypeData::resolveType(const QString &typeName, int &majorVersion, int &
error.setDescription(QQmlTypeLoader::tr("%1 %2").arg(typeName).arg(error.description()));
}
+ if (lineNumber != -1)
+ error.setLine(lineNumber);
+ if (columnNumber != -1)
+ error.setColumn(columnNumber);
+
errors.prepend(error);
setError(errors);
return false;
@@ -2741,7 +2724,7 @@ void QQmlTypeData::scriptImported(QQmlScriptBlob *blob, const QV4::CompiledData:
}
QQmlScriptData::QQmlScriptData()
- : importCache(0)
+ : typeNameCache(0)
, m_loaded(false)
, m_program(0)
{
@@ -2798,8 +2781,8 @@ QV4::ReturnedValue QQmlScriptData::scriptValueForContext(QQmlContextData *parent
// For backward compatibility, if there are no imports, we need to use the
// imports from the parent context. See QTBUG-17518.
- if (!importCache->isEmpty()) {
- ctxt->imports = importCache;
+ if (!typeNameCache->isEmpty()) {
+ ctxt->imports = typeNameCache;
} else if (effectiveCtxt) {
ctxt->imports = effectiveCtxt->imports;
ctxt->importedScripts = effectiveCtxt->importedScripts;
@@ -2854,9 +2837,9 @@ QV4::ReturnedValue QQmlScriptData::scriptValueForContext(QQmlContextData *parent
void QQmlScriptData::clear()
{
- if (importCache) {
- importCache->release();
- importCache = 0;
+ if (typeNameCache) {
+ typeNameCache->release();
+ typeNameCache = 0;
}
for (int ii = 0; ii < scripts.count(); ++ii)
@@ -2887,7 +2870,7 @@ QQmlScriptData *QQmlScriptBlob::scriptData() const
struct EmptyCompilationUnit : public QV4::CompiledData::CompilationUnit
{
- virtual void linkBackendToEngine(QV4::ExecutionEngine *) {}
+ void linkBackendToEngine(QV4::ExecutionEngine *) override {}
};
void QQmlScriptBlob::dataReceived(const Data &data)
@@ -2977,7 +2960,7 @@ void QQmlScriptBlob::done()
}
}
- m_scriptData->importCache = new QQmlTypeNameCache();
+ m_scriptData->typeNameCache = new QQmlTypeNameCache(m_importCache);
QSet<QString> ns;
@@ -2989,13 +2972,13 @@ void QQmlScriptBlob::done()
if (!script.nameSpace.isNull()) {
if (!ns.contains(script.nameSpace)) {
ns.insert(script.nameSpace);
- m_scriptData->importCache->add(script.nameSpace);
+ m_scriptData->typeNameCache->add(script.nameSpace);
}
}
- m_scriptData->importCache->add(script.qualifier, scriptIndex, script.nameSpace);
+ m_scriptData->typeNameCache->add(script.qualifier, scriptIndex, script.nameSpace);
}
- m_importCache.populateCache(m_scriptData->importCache);
+ m_importCache.populateCache(m_scriptData->typeNameCache);
}
QString QQmlScriptBlob::stringAt(int index) const
diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h
index 53cf4234e1..915b1bcc4c 100644
--- a/src/qml/qml/qqmltypeloader_p.h
+++ b/src/qml/qml/qqmltypeloader_p.h
@@ -218,6 +218,34 @@ private:
class QQmlTypeLoaderThread;
+class QQmlTypeLoaderQmldirContent
+{
+private:
+ friend class QQmlTypeLoader;
+ QQmlTypeLoaderQmldirContent();
+
+ void setContent(const QString &location, const QString &content);
+ void setError(const QQmlError &);
+
+public:
+ bool hasError() const;
+ QList<QQmlError> errors(const QString &uri) const;
+
+ QString typeNamespace() const;
+
+ QQmlDirComponents components() const;
+ QQmlDirScripts scripts() const;
+ QQmlDirPlugins plugins() const;
+
+ QString pluginLocation() const;
+
+ bool designerSupported() const;
+
+private:
+ QQmlDirParser m_parser;
+ QString m_location;
+};
+
class Q_AUTOTEST_EXPORT QQmlTypeLoader
{
Q_DECLARE_TR_FUNCTIONS(QQmlTypeLoader)
@@ -243,8 +271,8 @@ public:
virtual void scriptImported(QQmlScriptBlob *, const QV4::CompiledData::Location &, const QString &, const QString &) {}
- virtual void dependencyError(QQmlDataBlob *);
- virtual void dependencyComplete(QQmlDataBlob *);
+ void dependencyError(QQmlDataBlob *) override;
+ void dependencyComplete(QQmlDataBlob *) override;
protected:
virtual QString stringAt(int) const { return QString(); }
@@ -256,38 +284,10 @@ public:
QList<QQmlQmldirData *> m_qmldirs;
};
- class QmldirContent
- {
- private:
- friend class QQmlTypeLoader;
- QmldirContent();
-
- void setContent(const QString &location, const QString &content);
- void setError(const QQmlError &);
-
- public:
- bool hasError() const;
- QList<QQmlError> errors(const QString &uri) const;
-
- QString typeNamespace() const;
-
- QQmlDirComponents components() const;
- QQmlDirScripts scripts() const;
- QQmlDirPlugins plugins() const;
-
- QString pluginLocation() const;
-
- bool designerSupported() const;
-
- private:
- QQmlDirParser m_parser;
- QString m_location;
- };
-
QQmlTypeLoader(QQmlEngine *);
~QQmlTypeLoader();
- QQmlImportDatabase *importDatabase();
+ QQmlImportDatabase *importDatabase() const;
QQmlTypeData *getType(const QUrl &url, Mode mode = PreferSynchronous);
QQmlTypeData *getType(const QByteArray &, const QUrl &url, Mode mode = PreferSynchronous);
@@ -298,7 +298,7 @@ public:
QString absoluteFilePath(const QString &path);
bool directoryExists(const QString &path);
- const QmldirContent *qmldirContent(const QString &filePath);
+ const QQmlTypeLoaderQmldirContent *qmldirContent(const QString &filePath);
void setQmldirContent(const QString &filePath, const QString &content);
void clearCache();
@@ -363,7 +363,7 @@ private:
typedef QHash<QUrl, QQmlQmldirData *> QmldirCache;
typedef QStringHash<bool> StringSet;
typedef QStringHash<StringSet*> ImportDirCache;
- typedef QStringHash<QmldirContent *> ImportQmlDirCache;
+ typedef QStringHash<QQmlTypeLoaderQmldirContent *> ImportQmlDirCache;
QQmlEngine *m_engine;
QQmlTypeLoaderThread *m_thread;
@@ -434,31 +434,32 @@ public:
void unregisterCallback(TypeDataCallback *);
protected:
- virtual void done();
- virtual void completed();
- virtual void dataReceived(const Data &);
- virtual void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit *unit);
- virtual void allDependenciesDone();
- virtual void downloadProgressChanged(qreal);
+ void done() override;
+ void completed() override;
+ void dataReceived(const Data &) override;
+ void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit *unit) override;
+ void allDependenciesDone() override;
+ void downloadProgressChanged(qreal) override;
- virtual QString stringAt(int index) const;
+ QString stringAt(int index) const override;
private:
bool tryLoadFromDiskCache();
bool loadFromSource();
+ void restoreIR(QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit);
void continueLoadFromIR();
void resolveTypes();
QQmlCompileError buildTypeResolutionCaches(
- QQmlRefPointer<QQmlTypeNameCache> *importCache,
+ QQmlRefPointer<QQmlTypeNameCache> *typeNameCache,
QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypeCache
) const;
- void compile(const QQmlRefPointer<QQmlTypeNameCache> &importCache,
+ void compile(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache,
const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache);
- void createTypeAndPropertyCaches(const QQmlRefPointer<QQmlTypeNameCache> &importCache,
+ void createTypeAndPropertyCaches(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache,
const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache);
- bool resolveType(const QString &typeName, int &majorVersion, int &minorVersion, TypeReference &ref);
+ bool resolveType(const QString &typeName, int &majorVersion, int &minorVersion, TypeReference &ref, int lineNumber = -1, int columnNumber = -1, bool reportErrors = true);
- virtual void scriptImported(QQmlScriptBlob *blob, const QV4::CompiledData::Location &location, const QString &qualifier, const QString &nameSpace);
+ void scriptImported(QQmlScriptBlob *blob, const QV4::CompiledData::Location &location, const QString &qualifier, const QString &nameSpace) override;
qint64 m_sourceTimeStamp = 0;
@@ -504,13 +505,13 @@ public:
QUrl url;
QString urlString;
- QQmlTypeNameCache *importCache;
+ QQmlTypeNameCache *typeNameCache;
QList<QQmlScriptBlob *> scripts;
QV4::ReturnedValue scriptValueForContext(QQmlContextData *parentCtxt);
protected:
- virtual void clear(); // From QQmlCleanup
+ void clear() override; // From QQmlCleanup
private:
friend class QQmlScriptBlob;
@@ -546,14 +547,14 @@ public:
QQmlScriptData *scriptData() const;
protected:
- virtual void dataReceived(const Data &);
- virtual void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit *unit);
- virtual void done();
+ void dataReceived(const Data &) override;
+ void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit *unit) override;
+ void done() override;
- virtual QString stringAt(int index) const;
+ QString stringAt(int index) const override;
private:
- virtual void scriptImported(QQmlScriptBlob *blob, const QV4::CompiledData::Location &location, const QString &qualifier, const QString &nameSpace);
+ void scriptImported(QQmlScriptBlob *blob, const QV4::CompiledData::Location &location, const QString &qualifier, const QString &nameSpace) override;
void initializeFromCompilationUnit(QV4::CompiledData::CompilationUnit *unit);
QList<ScriptReference> m_scripts;
@@ -577,8 +578,8 @@ public:
void setPriority(int);
protected:
- virtual void dataReceived(const Data &);
- virtual void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit*);
+ void dataReceived(const Data &) override;
+ void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit*) override;
private:
QString m_content;
diff --git a/src/qml/qml/qqmltypenamecache.cpp b/src/qml/qml/qqmltypenamecache.cpp
index 34e1fc87f2..c8e2b92c29 100644
--- a/src/qml/qml/qqmltypenamecache.cpp
+++ b/src/qml/qml/qqmltypenamecache.cpp
@@ -43,7 +43,8 @@
QT_BEGIN_NAMESPACE
-QQmlTypeNameCache::QQmlTypeNameCache()
+QQmlTypeNameCache::QQmlTypeNameCache(const QQmlImports &importCache)
+ : m_imports(importCache)
{
}
@@ -70,6 +71,7 @@ void QQmlTypeNameCache::add(const QHashedString &name, int importedScriptIndex,
{
Import import;
import.scriptIndex = importedScriptIndex;
+ import.m_qualifier = name;
if (nameSpace.length() != 0) {
Import *i = m_namedImports.value(nameSpace);
@@ -84,7 +86,7 @@ void QQmlTypeNameCache::add(const QHashedString &name, int importedScriptIndex,
m_namedImports.insert(name, import);
}
-QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedStringRef &name)
+QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedStringRef &name) const
{
Result result = query(m_namedImports, name);
@@ -94,11 +96,23 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedStringRef &name)
if (!result.isValid())
result = query(m_anonymousCompositeSingletons, name);
+ if (!result.isValid()) {
+ // Look up anonymous types from the imports of this document
+ QQmlImportNamespace *typeNamespace = 0;
+ QList<QQmlError> errors;
+ QQmlType *t = 0;
+ bool typeFound = m_imports.resolveType(name, &t, 0, 0, &typeNamespace, &errors);
+ if (typeFound) {
+ return Result(t);
+ }
+
+ }
+
return result;
}
QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedStringRef &name,
- const void *importNamespace)
+ const void *importNamespace) const
{
Q_ASSERT(importNamespace);
const Import *i = static_cast<const Import *>(importNamespace);
@@ -109,10 +123,24 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedStringRef &name,
if (!result.isValid())
result = query(i->compositeSingletons, name);
+ if (!result.isValid()) {
+ // Look up types from the imports of this document
+ // ### it would be nice if QQmlImports allowed us to resolve a namespace
+ // first, and then types on it.
+ QString qualifiedTypeName = i->m_qualifier + QLatin1Char('.') + name.toString();
+ QQmlImportNamespace *typeNamespace = 0;
+ QList<QQmlError> errors;
+ QQmlType *t = 0;
+ bool typeFound = m_imports.resolveType(qualifiedTypeName, &t, 0, 0, &typeNamespace, &errors);
+ if (typeFound) {
+ return Result(t);
+ }
+ }
+
return result;
}
-QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name)
+QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name) const
{
Result result = query(m_namedImports, name);
@@ -122,10 +150,23 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name)
if (!result.isValid())
result = query(m_anonymousCompositeSingletons, name);
+ if (!result.isValid()) {
+ // Look up anonymous types from the imports of this document
+ QString typeName = name->toQStringNoThrow();
+ QQmlImportNamespace *typeNamespace = 0;
+ QList<QQmlError> errors;
+ QQmlType *t = 0;
+ bool typeFound = m_imports.resolveType(typeName, &t, 0, 0, &typeNamespace, &errors);
+ if (typeFound) {
+ return Result(t);
+ }
+
+ }
+
return result;
}
-QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name, const void *importNamespace)
+QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name, const void *importNamespace) const
{
Q_ASSERT(importNamespace);
const Import *i = static_cast<const Import *>(importNamespace);
@@ -143,6 +184,20 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name, cons
if (!r.isValid())
r = query(i->compositeSingletons, name);
+ if (!r.isValid()) {
+ // Look up types from the imports of this document
+ // ### it would be nice if QQmlImports allowed us to resolve a namespace
+ // first, and then types on it.
+ QString qualifiedTypeName = i->m_qualifier + QLatin1Char('.') + name->toQStringNoThrow();
+ QQmlImportNamespace *typeNamespace = 0;
+ QList<QQmlError> errors;
+ QQmlType *t = 0;
+ bool typeFound = m_imports.resolveType(qualifiedTypeName, &t, 0, 0, &typeNamespace, &errors);
+ if (typeFound) {
+ return Result(t);
+ }
+ }
+
return r;
}
diff --git a/src/qml/qml/qqmltypenamecache_p.h b/src/qml/qml/qqmltypenamecache_p.h
index 7591075102..7cdcbe91b6 100644
--- a/src/qml/qml/qqmltypenamecache_p.h
+++ b/src/qml/qml/qqmltypenamecache_p.h
@@ -56,6 +56,7 @@
#include "qqmlmetatype_p.h"
#include <private/qhashedstring_p.h>
+#include <private/qqmlimport_p.h>
#include <QtCore/qvector.h>
@@ -66,7 +67,7 @@ class QQmlEngine;
class QQmlTypeNameCache : public QQmlRefCount
{
public:
- QQmlTypeNameCache();
+ QQmlTypeNameCache(const QQmlImports &imports);
virtual ~QQmlTypeNameCache();
inline bool isEmpty() const;
@@ -87,10 +88,10 @@ public:
const void *importNamespace;
int scriptIndex;
};
- Result query(const QHashedStringRef &);
- Result query(const QHashedStringRef &, const void *importNamespace);
- Result query(const QV4::String *);
- Result query(const QV4::String *, const void *importNamespace);
+ Result query(const QHashedStringRef &) const;
+ Result query(const QHashedStringRef &, const void *importNamespace) const;
+ Result query(const QV4::String *) const;
+ Result query(const QV4::String *, const void *importNamespace) const;
private:
friend class QQmlImports;
@@ -105,13 +106,17 @@ private:
// Or, imported compositeSingletons
QStringHash<QUrl> compositeSingletons;
+
+ // The qualifier of this import
+ QString m_qualifier;
};
template<typename Key>
- Result query(const QStringHash<Import> &imports, Key key)
+ Result query(const QStringHash<Import> &imports, Key key) const
{
Import *i = imports.value(key);
if (i) {
+ Q_ASSERT(!i->m_qualifier.isEmpty());
if (i->scriptIndex != -1) {
return Result(i->scriptIndex);
} else {
@@ -123,7 +128,7 @@ private:
}
template<typename Key>
- Result query(const QStringHash<QUrl> &urls, Key key)
+ Result query(const QStringHash<QUrl> &urls, Key key) const
{
QUrl *url = urls.value(key);
if (url) {
@@ -136,7 +141,7 @@ private:
}
template<typename Key>
- Result typeSearch(const QVector<QQmlTypeModuleVersion> &modules, Key key)
+ Result typeSearch(const QVector<QQmlTypeModuleVersion> &modules, Key key) const
{
QVector<QQmlTypeModuleVersion>::const_iterator end = modules.constEnd();
for (QVector<QQmlTypeModuleVersion>::const_iterator it = modules.constBegin(); it != end; ++it) {
@@ -151,6 +156,7 @@ private:
QMap<const Import *, QStringHash<Import> > m_namespacedImports;
QVector<QQmlTypeModuleVersion> m_anonymousImports;
QStringHash<QUrl> m_anonymousCompositeSingletons;
+ QQmlImports m_imports;
};
QQmlTypeNameCache::Result::Result()
diff --git a/src/qml/qml/qqmlvaluetype_p.h b/src/qml/qml/qqmlvaluetype_p.h
index 11e1dfdb00..0502a5d665 100644
--- a/src/qml/qml/qqmlvaluetype_p.h
+++ b/src/qml/qml/qqmlvaluetype_p.h
@@ -74,9 +74,9 @@ public:
void setValue(const QVariant &);
// ---- dynamic meta object data interface
- virtual QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *);
- virtual void objectDestroyed(QObject *);
- virtual int metaCall(QObject *obj, QMetaObject::Call type, int _id, void **argv);
+ QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *) override;
+ void objectDestroyed(QObject *) override;
+ int metaCall(QObject *obj, QMetaObject::Call type, int _id, void **argv) override;
// ----
private:
diff --git a/src/qml/qml/qqmlvaluetypeproxybinding.cpp b/src/qml/qml/qqmlvaluetypeproxybinding.cpp
index 56f073121e..4e2e7b06c7 100644
--- a/src/qml/qml/qqmlvaluetypeproxybinding.cpp
+++ b/src/qml/qml/qqmlvaluetypeproxybinding.cpp
@@ -72,7 +72,7 @@ bool QQmlValueTypeProxyBinding::isValueTypeProxy() const
return true;
}
-QQmlAbstractBinding *QQmlValueTypeProxyBinding::binding(QQmlPropertyIndex propertyIndex)
+QQmlAbstractBinding *QQmlValueTypeProxyBinding::binding(QQmlPropertyIndex propertyIndex) const
{
QQmlAbstractBinding *binding = m_bindings.data();
diff --git a/src/qml/qml/qqmlvaluetypeproxybinding_p.h b/src/qml/qml/qqmlvaluetypeproxybinding_p.h
index 9a487d6992..92b5470f39 100644
--- a/src/qml/qml/qqmlvaluetypeproxybinding_p.h
+++ b/src/qml/qml/qqmlvaluetypeproxybinding_p.h
@@ -60,11 +60,11 @@ class QQmlValueTypeProxyBinding : public QQmlAbstractBinding
public:
QQmlValueTypeProxyBinding(QObject *o, QQmlPropertyIndex coreIndex);
- QQmlAbstractBinding *binding(QQmlPropertyIndex targetPropertyIndex);
+ QQmlAbstractBinding *binding(QQmlPropertyIndex targetPropertyIndex) const;
void removeBindings(quint32 mask);
- virtual void setEnabled(bool, QQmlPropertyData::WriteFlags);
- virtual bool isValueTypeProxy() const;
+ void setEnabled(bool, QQmlPropertyData::WriteFlags) override;
+ bool isValueTypeProxy() const override;
protected:
~QQmlValueTypeProxyBinding();
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp
index bbef62186a..41bb85c351 100644
--- a/src/qml/qml/qqmlvaluetypewrapper.cpp
+++ b/src/qml/qml/qqmlvaluetypewrapper.cpp
@@ -274,9 +274,9 @@ void QQmlValueTypeWrapper::advanceIterator(Managed *m, ObjectIterator *it, Value
QV4::Object::advanceIterator(m, it, name, index, p, attributes);
}
-bool QQmlValueTypeWrapper::isEqual(const QVariant& value)
+bool QQmlValueTypeWrapper::isEqual(const QVariant& value) const
{
- if (QQmlValueTypeReference *ref = as<QQmlValueTypeReference>())
+ if (const QQmlValueTypeReference *ref = as<const QQmlValueTypeReference>())
if (!ref->readReferenceValue())
return false;
return (value == d()->toVariant());
@@ -290,9 +290,11 @@ int QQmlValueTypeWrapper::typeId() const
bool QQmlValueTypeWrapper::write(QObject *target, int propertyIndex) const
{
bool destructGadgetOnExit = false;
+ Q_ALLOCA_DECLARE(void, gadget);
if (const QQmlValueTypeReference *ref = as<const QQmlValueTypeReference>()) {
if (!d()->gadgetPtr) {
- d()->gadgetPtr = alloca(d()->valueType->metaType.sizeOf());
+ Q_ALLOCA_ASSIGN(void, gadget, d()->valueType->metaType.sizeOf());
+ d()->gadgetPtr = gadget;
d()->valueType->metaType.construct(d()->gadgetPtr, 0);
destructGadgetOnExit = true;
}
@@ -312,18 +314,18 @@ bool QQmlValueTypeWrapper::write(QObject *target, int propertyIndex) const
return true;
}
-ReturnedValue QQmlValueTypeWrapper::method_toString(CallContext *ctx)
+void QQmlValueTypeWrapper::method_toString(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Object *o = ctx->thisObject().as<Object>();
+ Object *o = callData->thisObject.as<Object>();
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
QQmlValueTypeWrapper *w = o->as<QQmlValueTypeWrapper>();
if (!w)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (QQmlValueTypeReference *ref = w->as<QQmlValueTypeReference>())
if (!ref->readReferenceValue())
- return Encode::undefined();
+ RETURN_UNDEFINED();
QString result;
// Prepare a buffer to pass to QMetaType::convert()
@@ -346,7 +348,7 @@ ReturnedValue QQmlValueTypeWrapper::method_toString(CallContext *ctx)
}
result += QLatin1Char(')');
}
- return Encode(ctx->engine()->newString(result));
+ scope.result = scope.engine->newString(result);
}
ReturnedValue QQmlValueTypeWrapper::get(const Managed *m, String *name, bool *hasProperty)
diff --git a/src/qml/qml/qqmlvaluetypewrapper_p.h b/src/qml/qml/qqmlvaluetypewrapper_p.h
index b8ca5a16f4..87f9116056 100644
--- a/src/qml/qml/qqmlvaluetypewrapper_p.h
+++ b/src/qml/qml/qqmlvaluetypewrapper_p.h
@@ -101,7 +101,7 @@ public:
QVariant toVariant() const;
bool toGadget(void *data) const;
- bool isEqual(const QVariant& value);
+ bool isEqual(const QVariant& value) const;
int typeId() const;
bool write(QObject *target, int propertyIndex) const;
@@ -111,7 +111,7 @@ public:
static PropertyAttributes query(const Managed *, String *name);
static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes);
- static QV4::ReturnedValue method_toString(CallContext *ctx);
+ static void method_toString(const BuiltinFunction *, Scope &scope, CallData *callData);
static void initProto(ExecutionEngine *v4);
};
diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp
index 72d4ab7e8f..c60f4edc80 100644
--- a/src/qml/qml/qqmlvme.cpp
+++ b/src/qml/qml/qqmlvme.cpp
@@ -120,6 +120,18 @@ void QQmlVMEGuard::guard(QQmlObjectCreator *creator)
m_contexts[0] = creator->parentContextData();
}
+void QQmlVMEGuard::unguard(QObject *object)
+{
+ for (int ii = 0; ii < m_objectCount; ++ii) {
+ if (m_objects[ii] == object) {
+ if (ii < m_objectCount - 1)
+ ::memmove((void *) m_objects[ii], (void *) m_objects[ii + 1], sizeof(QPointer<QObject> *));
+ delete m_objects[--m_objectCount];
+ break;
+ }
+ }
+}
+
void QQmlVMEGuard::clear()
{
delete [] m_objects;
diff --git a/src/qml/qml/qqmlvme_p.h b/src/qml/qml/qqmlvme_p.h
index 99d63380ad..9585b5b6df 100644
--- a/src/qml/qml/qqmlvme_p.h
+++ b/src/qml/qml/qqmlvme_p.h
@@ -131,6 +131,7 @@ public:
~QQmlVMEGuard();
void guard(QQmlObjectCreator *);
+ void unguard(QObject *);
void clear();
bool isOK() const;
diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp
index d2cbb99b6a..490a4e19ab 100644
--- a/src/qml/qml/qqmlvmemetaobject.cpp
+++ b/src/qml/qml/qqmlvmemetaobject.cpp
@@ -325,9 +325,12 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj,
if (compiledObject->nProperties || compiledObject->nFunctions) {
Q_ASSERT(cache && cache->engine);
QV4::ExecutionEngine *v4 = cache->engine;
- QV4::Heap::MemberData *data = QV4::MemberData::allocate(v4, compiledObject->nProperties + compiledObject->nFunctions);
- propertyAndMethodStorage.set(v4, data);
- std::fill(data->data, data->data + data->size, QV4::Encode::undefined());
+ uint size = compiledObject->nProperties + compiledObject->nFunctions;
+ if (size) {
+ QV4::Heap::MemberData *data = QV4::MemberData::allocate(v4, size);
+ propertyAndMethodStorage.set(v4, data);
+ std::fill(data->data, data->data + data->size, QV4::Encode::undefined());
+ }
// Need JS wrapper to ensure properties/methods are marked.
ensureQObjectWrapper();
@@ -343,7 +346,7 @@ QQmlVMEMetaObject::~QQmlVMEMetaObject()
qDeleteAll(varObjectGuards);
}
-QV4::MemberData *QQmlVMEMetaObject::propertyAndMethodStorageAsMemberData()
+QV4::MemberData *QQmlVMEMetaObject::propertyAndMethodStorageAsMemberData() const
{
if (propertyAndMethodStorage.isUndefined()) {
if (propertyAndMethodStorage.valueRef())
@@ -442,7 +445,7 @@ void QQmlVMEMetaObject::writeProperty(int id, QObject* v)
guard->setGuardedValue(v, this, id);
}
-int QQmlVMEMetaObject::readPropertyAsInt(int id)
+int QQmlVMEMetaObject::readPropertyAsInt(int id) const
{
QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
if (!md)
@@ -455,7 +458,7 @@ int QQmlVMEMetaObject::readPropertyAsInt(int id)
return sv->integerValue();
}
-bool QQmlVMEMetaObject::readPropertyAsBool(int id)
+bool QQmlVMEMetaObject::readPropertyAsBool(int id) const
{
QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
if (!md)
@@ -468,7 +471,7 @@ bool QQmlVMEMetaObject::readPropertyAsBool(int id)
return sv->booleanValue();
}
-double QQmlVMEMetaObject::readPropertyAsDouble(int id)
+double QQmlVMEMetaObject::readPropertyAsDouble(int id) const
{
QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
if (!md)
@@ -481,7 +484,7 @@ double QQmlVMEMetaObject::readPropertyAsDouble(int id)
return sv->doubleValue();
}
-QString QQmlVMEMetaObject::readPropertyAsString(int id)
+QString QQmlVMEMetaObject::readPropertyAsString(int id) const
{
QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
if (!md)
@@ -494,7 +497,7 @@ QString QQmlVMEMetaObject::readPropertyAsString(int id)
return QString();
}
-QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id)
+QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id) const
{
QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
if (!md)
@@ -508,7 +511,7 @@ QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id)
return v->d()->data().value<QUrl>();
}
-QDate QQmlVMEMetaObject::readPropertyAsDate(int id)
+QDate QQmlVMEMetaObject::readPropertyAsDate(int id) const
{
QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
if (!md)
@@ -536,7 +539,7 @@ QDateTime QQmlVMEMetaObject::readPropertyAsDateTime(int id)
return v->d()->data().value<QDateTime>();
}
-QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id)
+QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) const
{
QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
if (!md)
@@ -550,7 +553,7 @@ QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id)
return v->d()->data().value<QSizeF>();
}
-QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id)
+QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id) const
{
QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
if (!md)
@@ -564,7 +567,7 @@ QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id)
return v->d()->data().value<QPointF>();
}
-QObject* QQmlVMEMetaObject::readPropertyAsQObject(int id)
+QObject* QQmlVMEMetaObject::readPropertyAsQObject(int id) const
{
QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
if (!md)
@@ -578,7 +581,7 @@ QObject* QQmlVMEMetaObject::readPropertyAsQObject(int id)
return wrapper->object();
}
-QList<QObject *> *QQmlVMEMetaObject::readPropertyAsList(int id)
+QList<QObject *> *QQmlVMEMetaObject::readPropertyAsList(int id) const
{
QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
if (!md)
@@ -594,7 +597,7 @@ QList<QObject *> *QQmlVMEMetaObject::readPropertyAsList(int id)
return static_cast<QList<QObject *> *>(v->d()->data().data());
}
-QRectF QQmlVMEMetaObject::readPropertyAsRectF(int id)
+QRectF QQmlVMEMetaObject::readPropertyAsRectF(int id) const
{
QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
if (!md)
@@ -976,7 +979,7 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void *
#pragma optimize("", on)
#endif
-QV4::ReturnedValue QQmlVMEMetaObject::method(int index)
+QV4::ReturnedValue QQmlVMEMetaObject::method(int index) const
{
if (!ctxt || !ctxt->isValid() || !compiledObject) {
qWarning("QQmlVMEMetaObject: Internal error - attempted to evaluate a function in an invalid context");
@@ -990,7 +993,7 @@ QV4::ReturnedValue QQmlVMEMetaObject::method(int index)
return (md->data() + index + compiledObject->nProperties)->asReturnedValue();
}
-QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id)
+QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id) const
{
Q_ASSERT(compiledObject && compiledObject->propertyTable()[id].type == QV4::CompiledData::Property::Var);
@@ -1000,7 +1003,7 @@ QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id)
return QV4::Primitive::undefinedValue().asReturnedValue();
}
-QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id)
+QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) const
{
QV4::MemberData *md = propertyAndMethodStorageAsMemberData();
if (md) {
@@ -1107,7 +1110,7 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value)
}
}
-QV4::ReturnedValue QQmlVMEMetaObject::vmeMethod(int index)
+QV4::ReturnedValue QQmlVMEMetaObject::vmeMethod(int index) const
{
if (index < methodOffset()) {
Q_ASSERT(parentVMEMetaObject());
@@ -1139,7 +1142,7 @@ void QQmlVMEMetaObject::setVmeMethod(int index, const QV4::Value &function)
*(md->data() + methodIndex + compiledObject->nProperties) = function;
}
-QV4::ReturnedValue QQmlVMEMetaObject::vmeProperty(int index)
+QV4::ReturnedValue QQmlVMEMetaObject::vmeProperty(int index) const
{
if (index < propOffset()) {
Q_ASSERT(parentVMEMetaObject());
diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h
index 031bfdfb9b..bb6fede7c8 100644
--- a/src/qml/qml/qqmlvmemetaobject_p.h
+++ b/src/qml/qml/qqmlvmemetaobject_p.h
@@ -83,7 +83,7 @@ public:
inline QQmlVMEVariantQObjectPtr();
inline ~QQmlVMEVariantQObjectPtr();
- inline void objectDestroyed(QObject *);
+ inline void objectDestroyed(QObject *) override;
inline void setGuardedValue(QObject *obj, QQmlVMEMetaObject *target, int index);
QQmlVMEMetaObject *m_target;
@@ -148,9 +148,9 @@ public:
~QQmlVMEMetaObject();
bool aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const;
- QV4::ReturnedValue vmeMethod(int index);
+ QV4::ReturnedValue vmeMethod(int index) const;
void setVmeMethod(int index, const QV4::Value &function);
- QV4::ReturnedValue vmeProperty(int index);
+ QV4::ReturnedValue vmeProperty(int index) const;
void setVMEProperty(int index, const QV4::Value &v);
void connectAliasSignal(int index, bool indexInSignalRange);
@@ -174,20 +174,20 @@ public:
QQmlVMEMetaObjectEndpoint *aliasEndpoints;
QV4::WeakValue propertyAndMethodStorage;
- QV4::MemberData *propertyAndMethodStorageAsMemberData();
-
- int readPropertyAsInt(int id);
- bool readPropertyAsBool(int id);
- double readPropertyAsDouble(int id);
- QString readPropertyAsString(int id);
- QSizeF readPropertyAsSizeF(int id);
- QPointF readPropertyAsPointF(int id);
- QUrl readPropertyAsUrl(int id);
- QDate readPropertyAsDate(int id);
+ QV4::MemberData *propertyAndMethodStorageAsMemberData() const;
+
+ int readPropertyAsInt(int id) const;
+ bool readPropertyAsBool(int id) const;
+ double readPropertyAsDouble(int id) const;
+ QString readPropertyAsString(int id) const;
+ QSizeF readPropertyAsSizeF(int id) const;
+ QPointF readPropertyAsPointF(int id) const;
+ QUrl readPropertyAsUrl(int id) const;
+ QDate readPropertyAsDate(int id) const;
QDateTime readPropertyAsDateTime(int id);
- QRectF readPropertyAsRectF(int id);
- QObject *readPropertyAsQObject(int id);
- QList<QObject *> *readPropertyAsList(int id);
+ QRectF readPropertyAsRectF(int id) const;
+ QObject *readPropertyAsQObject(int id) const;
+ QList<QObject *> *readPropertyAsList(int id) const;
void writeProperty(int id, int v);
void writeProperty(int id, bool v);
@@ -207,11 +207,11 @@ public:
void connectAlias(int aliasId);
- QV4::ReturnedValue method(int);
+ QV4::ReturnedValue method(int) const;
- QV4::ReturnedValue readVarProperty(int);
+ QV4::ReturnedValue readVarProperty(int) const;
void writeVarProperty(int, const QV4::Value &);
- QVariant readPropertyAsVariant(int);
+ QVariant readPropertyAsVariant(int) const;
void writeProperty(int, const QVariant &);
inline QQmlVMEMetaObject *parentVMEMetaObject() const;
diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp
index 47751aa2c6..d0d9f080da 100644
--- a/src/qml/qml/qqmlxmlhttprequest.cpp
+++ b/src/qml/qml/qqmlxmlhttprequest.cpp
@@ -71,10 +71,12 @@ using namespace QV4;
#if QT_CONFIG(xmlstreamreader) && QT_CONFIG(qml_network)
-#define V4THROW_REFERENCE(string) { \
- ScopedObject error(scope, ctx->engine()->newReferenceErrorObject(QStringLiteral(string))); \
- return ctx->engine()->throwError(error); \
- }
+#define V4THROW_REFERENCE(string) \
+ do { \
+ ScopedObject error(scope, scope.engine->newReferenceErrorObject(QStringLiteral(string))); \
+ scope.result = scope.engine->throwError(error); \
+ return; \
+ } while (false)
QT_BEGIN_NAMESPACE
@@ -274,25 +276,25 @@ public:
static void initClass(ExecutionEngine *engine);
// JS API
- static ReturnedValue method_get_nodeName(CallContext *ctx);
- static ReturnedValue method_get_nodeValue(CallContext *ctx);
- static ReturnedValue method_get_nodeType(CallContext *ctx);
- static ReturnedValue method_get_namespaceUri(CallContext *ctx);
-
- static ReturnedValue method_get_parentNode(CallContext *ctx);
- static ReturnedValue method_get_childNodes(CallContext *ctx);
- static ReturnedValue method_get_firstChild(CallContext *ctx);
- static ReturnedValue method_get_lastChild(CallContext *ctx);
- static ReturnedValue method_get_previousSibling(CallContext *ctx);
- static ReturnedValue method_get_nextSibling(CallContext *ctx);
- static ReturnedValue method_get_attributes(CallContext *ctx);
-
- //static ReturnedValue ownerDocument(CallContext *ctx);
- //static ReturnedValue namespaceURI(CallContext *ctx);
- //static ReturnedValue prefix(CallContext *ctx);
- //static ReturnedValue localName(CallContext *ctx);
- //static ReturnedValue baseURI(CallContext *ctx);
- //static ReturnedValue textContent(CallContext *ctx);
+ static void method_get_nodeName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_nodeValue(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_nodeType(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_namespaceUri(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+
+ static void method_get_parentNode(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_childNodes(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_firstChild(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_lastChild(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_previousSibling(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_nextSibling(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_attributes(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+
+ //static void ownerDocument(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ //static void namespaceURI(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ //static void prefix(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ //static void localName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ //static void baseURI(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ //static void textContent(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
static ReturnedValue getProto(ExecutionEngine *v4);
@@ -353,12 +355,12 @@ class Attr : public Node
{
public:
// JS API
- static ReturnedValue method_name(CallContext *ctx);
-// static ReturnedValue specified(CallContext *);
- static ReturnedValue method_value(CallContext *ctx);
- static ReturnedValue method_ownerElement(CallContext *ctx);
-// static ReturnedValue schemaTypeInfo(CallContext *);
-// static ReturnedValue isId(CallContext *c);
+ static void method_name(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+// static void specified(CallContext *);
+ static void method_value(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_ownerElement(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+// static void schemaTypeInfo(CallContext *);
+// static void isId(CallContext *c);
// C++ API
static ReturnedValue prototype(ExecutionEngine *);
@@ -368,7 +370,7 @@ class CharacterData : public Node
{
public:
// JS API
- static ReturnedValue method_length(CallContext *ctx);
+ static void method_length(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
// C++ API
static ReturnedValue prototype(ExecutionEngine *v4);
@@ -378,8 +380,8 @@ class Text : public CharacterData
{
public:
// JS API
- static ReturnedValue method_isElementContentWhitespace(CallContext *ctx);
- static ReturnedValue method_wholeText(CallContext *ctx);
+ static void method_isElementContentWhitespace(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_wholeText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
// C++ API
static ReturnedValue prototype(ExecutionEngine *);
@@ -396,10 +398,10 @@ class Document : public Node
{
public:
// JS API
- static ReturnedValue method_xmlVersion(CallContext *ctx);
- static ReturnedValue method_xmlEncoding(CallContext *ctx);
- static ReturnedValue method_xmlStandalone(CallContext *ctx);
- static ReturnedValue method_documentElement(CallContext *ctx);
+ static void method_xmlVersion(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_xmlEncoding(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_xmlStandalone(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_documentElement(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
// C++ API
static ReturnedValue prototype(ExecutionEngine *);
@@ -418,12 +420,11 @@ void NodeImpl::release()
document->release();
}
-ReturnedValue NodePrototype::method_get_nodeName(CallContext *ctx)
+void NodePrototype::method_get_nodeName(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
QString name;
switch (r->d()->d->type) {
@@ -440,15 +441,14 @@ ReturnedValue NodePrototype::method_get_nodeName(CallContext *ctx)
name = r->d()->d->name;
break;
}
- return Encode(ctx->d()->engine->newString(name));
+ scope.result = Encode(scope.engine->newString(name));
}
-ReturnedValue NodePrototype::method_get_nodeValue(CallContext *ctx)
+void NodePrototype::method_get_nodeValue(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (r->d()->d->type == NodeImpl::Document ||
r->d()->d->type == NodeImpl::DocumentFragment ||
@@ -457,135 +457,128 @@ ReturnedValue NodePrototype::method_get_nodeValue(CallContext *ctx)
r->d()->d->type == NodeImpl::Entity ||
r->d()->d->type == NodeImpl::EntityReference ||
r->d()->d->type == NodeImpl::Notation)
- return Encode::null();
+ RETURN_RESULT(Encode::null());
- return Encode(ctx->d()->engine->newString(r->d()->d->data));
+ scope.result = Encode(scope.engine->newString(r->d()->d->data));
}
-ReturnedValue NodePrototype::method_get_nodeType(CallContext *ctx)
+void NodePrototype::method_get_nodeType(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- return Encode(r->d()->d->type);
+ scope.result = Encode(r->d()->d->type);
}
-ReturnedValue NodePrototype::method_get_namespaceUri(CallContext *ctx)
+void NodePrototype::method_get_namespaceUri(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- return Encode(ctx->d()->engine->newString(r->d()->d->namespaceUri));
+ scope.result = Encode(scope.engine->newString(r->d()->d->namespaceUri));
}
-ReturnedValue NodePrototype::method_get_parentNode(CallContext *ctx)
+void NodePrototype::method_get_parentNode(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (r->d()->d->parent)
- return Node::create(scope.engine, r->d()->d->parent);
+ scope.result = Node::create(scope.engine, r->d()->d->parent);
else
- return Encode::null();
+ scope.result = Encode::null();
}
-ReturnedValue NodePrototype::method_get_childNodes(CallContext *ctx)
+void NodePrototype::method_get_childNodes(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
- return NodeList::create(scope.engine, r->d()->d);
+ scope.result = NodeList::create(scope.engine, r->d()->d);
}
-ReturnedValue NodePrototype::method_get_firstChild(CallContext *ctx)
+void NodePrototype::method_get_firstChild(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (r->d()->d->children.isEmpty())
- return Encode::null();
+ scope.result = Encode::null();
else
- return Node::create(scope.engine, r->d()->d->children.constFirst());
+ scope.result = Node::create(scope.engine, r->d()->d->children.constFirst());
}
-ReturnedValue NodePrototype::method_get_lastChild(CallContext *ctx)
+void NodePrototype::method_get_lastChild(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (r->d()->d->children.isEmpty())
- return Encode::null();
+ scope.result = Encode::null();
else
- return Node::create(scope.engine, r->d()->d->children.constLast());
+ scope.result = Node::create(scope.engine, r->d()->d->children.constLast());
}
-ReturnedValue NodePrototype::method_get_previousSibling(CallContext *ctx)
+void NodePrototype::method_get_previousSibling(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (!r->d()->d->parent)
- return Encode::null();
+ RETURN_RESULT(Encode::null());
for (int ii = 0; ii < r->d()->d->parent->children.count(); ++ii) {
if (r->d()->d->parent->children.at(ii) == r->d()->d) {
if (ii == 0)
- return Encode::null();
+ scope.result = Encode::null();
else
- return Node::create(scope.engine, r->d()->d->parent->children.at(ii - 1));
+ scope.result = Node::create(scope.engine, r->d()->d->parent->children.at(ii - 1));
+ return;
}
}
- return Encode::null();
+ scope.result = Encode::null();
}
-ReturnedValue NodePrototype::method_get_nextSibling(CallContext *ctx)
+void NodePrototype::method_get_nextSibling(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (!r->d()->d->parent)
- return Encode::null();
+ RETURN_RESULT(Encode::null());
for (int ii = 0; ii < r->d()->d->parent->children.count(); ++ii) {
if (r->d()->d->parent->children.at(ii) == r->d()->d) {
if ((ii + 1) == r->d()->d->parent->children.count())
- return Encode::null();
+ scope.result = Encode::null();
else
- return Node::create(scope.engine, r->d()->d->parent->children.at(ii + 1));
+ scope.result = Node::create(scope.engine, r->d()->d->parent->children.at(ii + 1));
+ return;
}
}
- return Encode::null();
+ scope.result = Encode::null();
}
-ReturnedValue NodePrototype::method_get_attributes(CallContext *ctx)
+void NodePrototype::method_get_attributes(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (r->d()->d->type != NodeImpl::Element)
- return Encode::null();
+ scope.result = Encode::null();
else
- return NamedNodeMap::create(scope.engine, r->d()->d, r->d()->d->attributes);
+ scope.result = NamedNodeMap::create(scope.engine, r->d()->d, r->d()->d->attributes);
}
ReturnedValue NodePrototype::getProto(ExecutionEngine *v4)
@@ -666,44 +659,40 @@ ReturnedValue Attr::prototype(ExecutionEngine *engine)
return d->attrPrototype.value();
}
-ReturnedValue Attr::method_name(CallContext *ctx)
+void Attr::method_name(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return Encode::undefined();
+ RETURN_UNDEFINED();
- return QV4::Encode(scope.engine->newString(r->d()->d->name));
+ scope.result = scope.engine->newString(r->d()->d->name);
}
-ReturnedValue Attr::method_value(CallContext *ctx)
+void Attr::method_value(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return Encode::undefined();
+ RETURN_UNDEFINED();
- return QV4::Encode(scope.engine->newString(r->d()->d->data));
+ scope.result = scope.engine->newString(r->d()->d->data);
}
-ReturnedValue Attr::method_ownerElement(CallContext *ctx)
+void Attr::method_ownerElement(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return Encode::undefined();
+ RETURN_UNDEFINED();
- return Node::create(scope.engine, r->d()->d->parent);
+ scope.result = Node::create(scope.engine, r->d()->d->parent);
}
-ReturnedValue CharacterData::method_length(CallContext *ctx)
+void CharacterData::method_length(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return Encode::undefined();
+ RETURN_UNDEFINED();
- return Encode(r->d()->d->data.length());
+ scope.result = Encode(r->d()->d->data.length());
}
ReturnedValue CharacterData::prototype(ExecutionEngine *v4)
@@ -722,23 +711,22 @@ ReturnedValue CharacterData::prototype(ExecutionEngine *v4)
return d->characterDataPrototype.value();
}
-ReturnedValue Text::method_isElementContentWhitespace(CallContext *ctx)
+void Text::method_isElementContentWhitespace(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
- if (!r) return Encode::undefined();
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
+ if (!r)
+ RETURN_UNDEFINED();
- return Encode(QStringRef(&r->d()->d->data).trimmed().isEmpty());
+ scope.result = Encode(QStringRef(&r->d()->d->data).trimmed().isEmpty());
}
-ReturnedValue Text::method_wholeText(CallContext *ctx)
+void Text::method_wholeText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r)
- return Encode::undefined();
+ RETURN_UNDEFINED();
- return QV4::Encode(scope.engine->newString(r->d()->d->data));
+ scope.result = scope.engine->newString(r->d()->d->data);
}
ReturnedValue Text::prototype(ExecutionEngine *v4)
@@ -830,7 +818,8 @@ ReturnedValue Document::load(ExecutionEngine *v4, const QByteArray &data)
}
nodeStack.append(node);
- foreach (const QXmlStreamAttribute &a, reader.attributes()) {
+ const auto attributes = reader.attributes();
+ for (const QXmlStreamAttribute &a : attributes) {
NodeImpl *attr = new NodeImpl;
attr->document = document;
attr->type = NodeImpl::Attr;
@@ -963,44 +952,40 @@ ReturnedValue NodeList::create(ExecutionEngine *v4, NodeImpl *data)
return (v4->memoryManager->allocObject<NodeList>(data))->asReturnedValue();
}
-ReturnedValue Document::method_documentElement(CallContext *ctx)
+void Document::method_documentElement(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r || r->d()->d->type != NodeImpl::Document)
- return Encode::undefined();
+ RETURN_UNDEFINED();
- return Node::create(scope.engine, static_cast<DocumentImpl *>(r->d()->d)->root);
+ scope.result = Node::create(scope.engine, static_cast<DocumentImpl *>(r->d()->d)->root);
}
-ReturnedValue Document::method_xmlStandalone(CallContext *ctx)
+void Document::method_xmlStandalone(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r || r->d()->d->type != NodeImpl::Document)
- return Encode::undefined();
+ RETURN_UNDEFINED();
- return Encode(static_cast<DocumentImpl *>(r->d()->d)->isStandalone);
+ scope.result = Encode(static_cast<DocumentImpl *>(r->d()->d)->isStandalone);
}
-ReturnedValue Document::method_xmlVersion(CallContext *ctx)
+void Document::method_xmlVersion(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r || r->d()->d->type != NodeImpl::Document)
- return Encode::undefined();
+ RETURN_UNDEFINED();
- return QV4::Encode(scope.engine->newString(static_cast<DocumentImpl *>(r->d()->d)->version));
+ scope.result = scope.engine->newString(static_cast<DocumentImpl *>(r->d()->d)->version);
}
-ReturnedValue Document::method_xmlEncoding(CallContext *ctx)
+void Document::method_xmlEncoding(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<Node> r(scope, ctx->thisObject().as<Node>());
+ Scoped<Node> r(scope, callData->thisObject.as<Node>());
if (!r || r->d()->d->type != NodeImpl::Document)
- return Encode::undefined();
+ RETURN_UNDEFINED();
- return QV4::Encode(scope.engine->newString(static_cast<DocumentImpl *>(r->d()->d)->encoding));
+ scope.result = scope.engine->newString(static_cast<DocumentImpl *>(r->d()->d)->encoding);
}
class QQmlXMLHttpRequest : public QObject
@@ -1184,10 +1169,10 @@ QString QQmlXMLHttpRequest::headers() const
void QQmlXMLHttpRequest::fillHeadersList()
{
- QList<QByteArray> headerList = m_network->rawHeaderList();
+ const QList<QByteArray> headerList = m_network->rawHeaderList();
m_headersList.clear();
- foreach (const QByteArray &header, headerList) {
+ for (const QByteArray &header : headerList) {
HeaderPair pair (header.toLower(), m_network->rawHeader(header));
if (pair.first == "set-cookie" ||
pair.first == "set-cookie2")
@@ -1445,7 +1430,7 @@ void QQmlXMLHttpRequest::finished()
void QQmlXMLHttpRequest::readEncoding()
{
- foreach (const HeaderPair &header, m_headersList) {
+ for (const HeaderPair &header : qAsConst(m_headersList)) {
if (header.first == "content-type") {
int separatorIdx = header.second.indexOf(';');
if (separatorIdx == -1) {
@@ -1656,21 +1641,21 @@ struct QQmlXMLHttpRequestCtor : public FunctionObject
void setupProto();
- static ReturnedValue method_open(CallContext *ctx);
- static ReturnedValue method_setRequestHeader(CallContext *ctx);
- static ReturnedValue method_send(CallContext *ctx);
- static ReturnedValue method_abort(CallContext *ctx);
- static ReturnedValue method_getResponseHeader(CallContext *ctx);
- static ReturnedValue method_getAllResponseHeaders(CallContext *ctx);
-
- static ReturnedValue method_get_readyState(CallContext *ctx);
- static ReturnedValue method_get_status(CallContext *ctx);
- static ReturnedValue method_get_statusText(CallContext *ctx);
- static ReturnedValue method_get_responseText(CallContext *ctx);
- static ReturnedValue method_get_responseXML(CallContext *ctx);
- static ReturnedValue method_get_response(CallContext *ctx);
- static ReturnedValue method_get_responseType(CallContext *ctx);
- static ReturnedValue method_set_responseType(CallContext *ctx);
+ static void method_open(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_setRequestHeader(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_send(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_abort(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_getResponseHeader(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_getAllResponseHeaders(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+
+ static void method_get_readyState(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_status(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_statusText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_responseText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_responseXML(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_response(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_responseType(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_responseType(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
};
}
@@ -1732,19 +1717,18 @@ void QQmlXMLHttpRequestCtor::setupProto()
// XMLHttpRequest methods
-ReturnedValue QQmlXMLHttpRequestCtor::method_open(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_open(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
- if (ctx->argc() < 2 || ctx->argc() > 5)
- V4THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count");
+ if (callData->argc < 2 || callData->argc > 5)
+ THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count");
// Argument 0 - Method
- QString method = ctx->args()[0].toQStringNoThrow().toUpper();
+ QString method = callData->args[0].toQStringNoThrow().toUpper();
if (method != QLatin1String("GET") &&
method != QLatin1String("PUT") &&
method != QLatin1String("HEAD") &&
@@ -1753,26 +1737,26 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_open(CallContext *ctx)
method != QLatin1String("OPTIONS") &&
method != QLatin1String("PROPFIND") &&
method != QLatin1String("PATCH"))
- V4THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Unsupported HTTP method type");
+ THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Unsupported HTTP method type");
// Argument 1 - URL
- QUrl url = QUrl(ctx->args()[1].toQStringNoThrow());
+ QUrl url = QUrl(callData->args[1].toQStringNoThrow());
if (url.isRelative())
url = scope.engine->callingQmlContext()->resolvedUrl(url);
bool async = true;
// Argument 2 - async (optional)
- if (ctx->argc() > 2) {
- async = ctx->args()[2].booleanValue();
+ if (callData->argc > 2) {
+ async = callData->args[2].booleanValue();
}
// Argument 3/4 - user/pass (optional)
QString username, password;
- if (ctx->argc() > 3)
- username = ctx->args()[3].toQStringNoThrow();
- if (ctx->argc() > 4)
- password = ctx->args()[4].toQStringNoThrow();
+ if (callData->argc > 3)
+ username = callData->args[3].toQStringNoThrow();
+ if (callData->argc > 4)
+ password = callData->args[4].toQStringNoThrow();
// Clear the fragment (if any)
url.setFragment(QString());
@@ -1781,25 +1765,24 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_open(CallContext *ctx)
if (!username.isNull()) url.setUserName(username);
if (!password.isNull()) url.setPassword(password);
- return r->open(w, scope.engine->callingQmlContext(), method, url, async ? QQmlXMLHttpRequest::AsynchronousLoad : QQmlXMLHttpRequest::SynchronousLoad);
+ scope.result = r->open(w, scope.engine->callingQmlContext(), method, url, async ? QQmlXMLHttpRequest::AsynchronousLoad : QQmlXMLHttpRequest::SynchronousLoad);
}
-ReturnedValue QQmlXMLHttpRequestCtor::method_setRequestHeader(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_setRequestHeader(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
- if (ctx->argc() != 2)
- V4THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count");
+ if (callData->argc != 2)
+ THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count");
if (r->readyState() != QQmlXMLHttpRequest::Opened || r->sendFlag())
- V4THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state");
+ THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state");
- QString name = ctx->args()[0].toQStringNoThrow();
- QString value = ctx->args()[1].toQStringNoThrow();
+ QString name = callData->args[0].toQStringNoThrow();
+ QString value = callData->args[1].toQStringNoThrow();
// ### Check that name and value are well formed
@@ -1824,148 +1807,139 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_setRequestHeader(CallContext *ctx)
nameUpper == QLatin1String("VIA") ||
nameUpper.startsWith(QLatin1String("PROXY-")) ||
nameUpper.startsWith(QLatin1String("SEC-")))
- return Encode::undefined();
+ RETURN_UNDEFINED();
r->addHeader(name, value);
- return Encode::undefined();
+ RETURN_UNDEFINED();
}
-ReturnedValue QQmlXMLHttpRequestCtor::method_send(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_send(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
if (r->readyState() != QQmlXMLHttpRequest::Opened ||
r->sendFlag())
- V4THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state");
+ THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state");
QByteArray data;
- if (ctx->argc() > 0)
- data = ctx->args()[0].toQStringNoThrow().toUtf8();
+ if (callData->argc > 0)
+ data = callData->args[0].toQStringNoThrow().toUtf8();
- return r->send(w, scope.engine->callingQmlContext(), data);
+ scope.result = r->send(w, scope.engine->callingQmlContext(), data);
}
-ReturnedValue QQmlXMLHttpRequestCtor::method_abort(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_abort(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
- return r->abort(w, scope.engine->callingQmlContext());
+ scope.result = r->abort(w, scope.engine->callingQmlContext());
}
-ReturnedValue QQmlXMLHttpRequestCtor::method_getResponseHeader(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_getResponseHeader(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
- if (ctx->argc() != 1)
- V4THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count");
+ if (callData->argc != 1)
+ THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count");
if (r->readyState() != QQmlXMLHttpRequest::Loading &&
r->readyState() != QQmlXMLHttpRequest::Done &&
r->readyState() != QQmlXMLHttpRequest::HeadersReceived)
- V4THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state");
+ THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state");
- return QV4::Encode(scope.engine->newString(r->header(ctx->args()[0].toQStringNoThrow())));
+ scope.result = scope.engine->newString(r->header(callData->args[0].toQStringNoThrow()));
}
-ReturnedValue QQmlXMLHttpRequestCtor::method_getAllResponseHeaders(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_getAllResponseHeaders(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
- if (ctx->argc() != 0)
- V4THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count");
+ if (callData->argc != 0)
+ THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count");
if (r->readyState() != QQmlXMLHttpRequest::Loading &&
r->readyState() != QQmlXMLHttpRequest::Done &&
r->readyState() != QQmlXMLHttpRequest::HeadersReceived)
- V4THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state");
+ THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state");
- return QV4::Encode(scope.engine->newString(r->headers()));
+ scope.result = scope.engine->newString(r->headers());
}
// XMLHttpRequest properties
-ReturnedValue QQmlXMLHttpRequestCtor::method_get_readyState(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_get_readyState(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
- return Encode(r->readyState());
+ scope.result = Encode(r->readyState());
}
-ReturnedValue QQmlXMLHttpRequestCtor::method_get_status(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_get_status(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
if (r->readyState() == QQmlXMLHttpRequest::Unsent ||
r->readyState() == QQmlXMLHttpRequest::Opened)
- V4THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state");
+ THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state");
if (r->errorFlag())
- return Encode(0);
+ scope.result = Encode(0);
else
- return Encode(r->replyStatus());
+ scope.result = Encode(r->replyStatus());
}
-ReturnedValue QQmlXMLHttpRequestCtor::method_get_statusText(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_get_statusText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
if (r->readyState() == QQmlXMLHttpRequest::Unsent ||
r->readyState() == QQmlXMLHttpRequest::Opened)
- V4THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state");
+ THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state");
if (r->errorFlag())
- return QV4::Encode(scope.engine->newString(QString()));
+ scope.result = scope.engine->newString(QString());
else
- return QV4::Encode(scope.engine->newString(r->replyStatusText()));
+ scope.result = scope.engine->newString(r->replyStatusText());
}
-ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseText(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_get_responseText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
if (r->readyState() != QQmlXMLHttpRequest::Loading &&
r->readyState() != QQmlXMLHttpRequest::Done)
- return QV4::Encode(scope.engine->newString(QString()));
+ scope.result = scope.engine->newString(QString());
else
- return QV4::Encode(scope.engine->newString(r->responseBody()));
+ scope.result = scope.engine->newString(r->responseBody());
}
-ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseXML(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_get_responseXML(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
@@ -1973,66 +1947,63 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseXML(CallContext *ctx)
if (!r->receivedXml() ||
(r->readyState() != QQmlXMLHttpRequest::Loading &&
r->readyState() != QQmlXMLHttpRequest::Done)) {
- return Encode::null();
+ scope.result = Encode::null();
} else {
if (r->responseType().isEmpty())
r->setResponseType(QLatin1String("document"));
- return r->xmlResponseBody(scope.engine);
+ scope.result = r->xmlResponseBody(scope.engine);
}
}
-ReturnedValue QQmlXMLHttpRequestCtor::method_get_response(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_get_response(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
if (r->readyState() != QQmlXMLHttpRequest::Loading &&
r->readyState() != QQmlXMLHttpRequest::Done)
- return QV4::Encode(scope.engine->newString(QString()));
+ RETURN_RESULT(scope.engine->newString(QString()));
const QString& responseType = r->responseType();
if (responseType.compare(QLatin1String("text"), Qt::CaseInsensitive) == 0 || responseType.isEmpty()) {
- return QV4::Encode(scope.engine->newString(r->responseBody()));
+ RETURN_RESULT(scope.engine->newString(r->responseBody()));
} else if (responseType.compare(QLatin1String("arraybuffer"), Qt::CaseInsensitive) == 0) {
- return QV4::Encode(scope.engine->newArrayBuffer(r->rawResponseBody()));
+ RETURN_RESULT(scope.engine->newArrayBuffer(r->rawResponseBody()));
} else if (responseType.compare(QLatin1String("json"), Qt::CaseInsensitive) == 0) {
- return r->jsonResponseBody(scope.engine);
+ RETURN_RESULT(r->jsonResponseBody(scope.engine));
} else if (responseType.compare(QLatin1String("document"), Qt::CaseInsensitive) == 0) {
- return r->xmlResponseBody(scope.engine);
+ RETURN_RESULT(r->xmlResponseBody(scope.engine));
} else {
- return QV4::Encode(scope.engine->newString(QString()));
+ RETURN_RESULT(scope.engine->newString(QString()));
}
}
-ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseType(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_get_responseType(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
- return QV4::Encode(scope.engine->newString(r->responseType()));
+ scope.result = scope.engine->newString(r->responseType());
}
-ReturnedValue QQmlXMLHttpRequestCtor::method_set_responseType(CallContext *ctx)
+void QQmlXMLHttpRequestCtor::method_set_responseType(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- Scope scope(ctx);
- Scoped<QQmlXMLHttpRequestWrapper> w(scope, ctx->thisObject().as<QQmlXMLHttpRequestWrapper>());
+ Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>());
if (!w)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
- if (ctx->argc() < 1)
- V4THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count");
+ if (callData->argc < 1)
+ THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count");
// Argument 0 - response type
- r->setResponseType(ctx->args()[0].toQStringNoThrow());
+ r->setResponseType(callData->args[0].toQStringNoThrow());
- return Encode::undefined();
+ scope.result = Encode::undefined();
}
void qt_rem_qmlxmlhttprequest(ExecutionEngine * /* engine */, void *d)
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
index 19dc100f40..d359a0f62f 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
@@ -85,6 +85,12 @@ using namespace QV4;
DEFINE_OBJECT_VTABLE(QtObject);
+#define THROW_TYPE_ERROR_WITH_MESSAGE(msg) \
+ do { \
+ scope.result = scope.engine->throwTypeError(QString::fromUtf8(msg)); \
+ return; \
+ } while (false)
+
struct StaticQtMetaObject : public QObject
{
static const QMetaObject *get()
@@ -223,12 +229,12 @@ void QtObject::advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint
\qmlmethod bool Qt::isQtObject(object)
Returns true if \c object is a valid reference to a Qt or QML object, otherwise false.
*/
-ReturnedValue QtObject::method_isQtObject(QV4::CallContext *ctx)
+void QtObject::method_isQtObject(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() == 0)
- return QV4::Encode(false);
+ if (callData->argc == 0)
+ RETURN_RESULT(QV4::Encode(false));
- return QV4::Encode(ctx->args()[0].as<QV4::QObjectWrapper>() != 0);
+ scope.result = QV4::Encode(callData->args[0].as<QV4::QObjectWrapper>() != 0);
}
/*!
@@ -237,16 +243,16 @@ ReturnedValue QtObject::method_isQtObject(QV4::CallContext *ctx)
Returns a color with the specified \c red, \c green, \c blue and \c alpha components.
All components should be in the range 0-1 inclusive.
*/
-ReturnedValue QtObject::method_rgba(QV4::CallContext *ctx)
+void QtObject::method_rgba(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- int argCount = ctx->argc();
+ int argCount = callData->argc;
if (argCount < 3 || argCount > 4)
- V4THROW_ERROR("Qt.rgba(): Invalid arguments");
+ THROW_GENERIC_ERROR("Qt.rgba(): Invalid arguments");
- double r = ctx->args()[0].toNumber();
- double g = ctx->args()[1].toNumber();
- double b = ctx->args()[2].toNumber();
- double a = (argCount == 4) ? ctx->args()[3].toNumber() : 1;
+ double r = callData->args[0].toNumber();
+ double g = callData->args[1].toNumber();
+ double b = callData->args[2].toNumber();
+ double a = (argCount == 4) ? callData->args[3].toNumber() : 1;
if (r < 0.0) r=0.0;
if (r > 1.0) r=1.0;
@@ -257,7 +263,7 @@ ReturnedValue QtObject::method_rgba(QV4::CallContext *ctx)
if (a < 0.0) a=0.0;
if (a > 1.0) a=1.0;
- return ctx->engine()->fromVariant(QQml_colorProvider()->fromRgbF(r, g, b, a));
+ scope.result = scope.engine->fromVariant(QQml_colorProvider()->fromRgbF(r, g, b, a));
}
/*!
@@ -266,16 +272,16 @@ ReturnedValue QtObject::method_rgba(QV4::CallContext *ctx)
Returns a color with the specified \c hue, \c saturation, \c lightness and \c alpha components.
All components should be in the range 0-1 inclusive.
*/
-ReturnedValue QtObject::method_hsla(QV4::CallContext *ctx)
+void QtObject::method_hsla(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- int argCount = ctx->argc();
+ int argCount = callData->argc;
if (argCount < 3 || argCount > 4)
- V4THROW_ERROR("Qt.hsla(): Invalid arguments");
+ THROW_GENERIC_ERROR("Qt.hsla(): Invalid arguments");
- double h = ctx->args()[0].toNumber();
- double s = ctx->args()[1].toNumber();
- double l = ctx->args()[2].toNumber();
- double a = (argCount == 4) ? ctx->args()[3].toNumber() : 1;
+ double h = callData->args[0].toNumber();
+ double s = callData->args[1].toNumber();
+ double l = callData->args[2].toNumber();
+ double a = (argCount == 4) ? callData->args[3].toNumber() : 1;
if (h < 0.0) h=0.0;
if (h > 1.0) h=1.0;
@@ -286,7 +292,7 @@ ReturnedValue QtObject::method_hsla(QV4::CallContext *ctx)
if (a < 0.0) a=0.0;
if (a > 1.0) a=1.0;
- return ctx->engine()->fromVariant(QQml_colorProvider()->fromHslF(h, s, l, a));
+ scope.result = scope.engine->fromVariant(QQml_colorProvider()->fromHslF(h, s, l, a));
}
/*!
@@ -297,23 +303,23 @@ All components should be in the range 0-1 inclusive.
\since 5.5
*/
-ReturnedValue QtObject::method_hsva(QV4::CallContext *ctx)
+void QtObject::method_hsva(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- int argCount = ctx->argc();
+ int argCount = callData->argc;
if (argCount < 3 || argCount > 4)
- V4THROW_ERROR("Qt.hsva(): Invalid arguments");
+ THROW_GENERIC_ERROR("Qt.hsva(): Invalid arguments");
- double h = ctx->args()[0].toNumber();
- double s = ctx->args()[1].toNumber();
- double v = ctx->args()[2].toNumber();
- double a = (argCount == 4) ? ctx->args()[3].toNumber() : 1;
+ double h = callData->args[0].toNumber();
+ double s = callData->args[1].toNumber();
+ double v = callData->args[2].toNumber();
+ double a = (argCount == 4) ? callData->args[3].toNumber() : 1;
h = qBound(0.0, h, 1.0);
s = qBound(0.0, s, 1.0);
v = qBound(0.0, v, 1.0);
a = qBound(0.0, a, 1.0);
- return ctx->engine()->fromVariant(QQml_colorProvider()->fromHsvF(h, s, v, a));
+ scope.result = scope.engine->fromVariant(QQml_colorProvider()->fromHsvF(h, s, v, a));
}
/*!
@@ -324,35 +330,35 @@ may be either color values or string values. If a string value is supplied it
must be convertible to a color, as described for the \l{colorbasictypedocs}{color}
basic type.
*/
-ReturnedValue QtObject::method_colorEqual(QV4::CallContext *ctx)
+void QtObject::method_colorEqual(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 2)
- V4THROW_ERROR("Qt.colorEqual(): Invalid arguments");
+ if (callData->argc != 2)
+ THROW_GENERIC_ERROR("Qt.colorEqual(): Invalid arguments");
bool ok = false;
- QVariant lhs = ctx->d()->engine->toVariant(ctx->args()[0], -1);
+ QVariant lhs = scope.engine->toVariant(callData->args[0], -1);
if (lhs.userType() == QVariant::String) {
lhs = QQmlStringConverters::colorFromString(lhs.toString(), &ok);
if (!ok) {
- V4THROW_ERROR("Qt.colorEqual(): Invalid color name");
+ THROW_GENERIC_ERROR("Qt.colorEqual(): Invalid color name");
}
} else if (lhs.userType() != QVariant::Color) {
- V4THROW_ERROR("Qt.colorEqual(): Invalid arguments");
+ THROW_GENERIC_ERROR("Qt.colorEqual(): Invalid arguments");
}
- QVariant rhs = ctx->engine()->toVariant(ctx->args()[1], -1);
+ QVariant rhs = scope.engine->toVariant(callData->args[1], -1);
if (rhs.userType() == QVariant::String) {
rhs = QQmlStringConverters::colorFromString(rhs.toString(), &ok);
if (!ok) {
- V4THROW_ERROR("Qt.colorEqual(): Invalid color name");
+ THROW_GENERIC_ERROR("Qt.colorEqual(): Invalid color name");
}
} else if (rhs.userType() != QVariant::Color) {
- V4THROW_ERROR("Qt.colorEqual(): Invalid arguments");
+ THROW_GENERIC_ERROR("Qt.colorEqual(): Invalid arguments");
}
bool equal = (lhs == rhs);
- return QV4::Encode(equal);
+ scope.result = QV4::Encode(equal);
}
/*!
@@ -362,47 +368,47 @@ Returns a \c rect with the top-left corner at \c x, \c y and the specified \c wi
The returned object has \c x, \c y, \c width and \c height attributes with the given values.
*/
-ReturnedValue QtObject::method_rect(QV4::CallContext *ctx)
+void QtObject::method_rect(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 4)
- V4THROW_ERROR("Qt.rect(): Invalid arguments");
+ if (callData->argc != 4)
+ THROW_GENERIC_ERROR("Qt.rect(): Invalid arguments");
- double x = ctx->args()[0].toNumber();
- double y = ctx->args()[1].toNumber();
- double w = ctx->args()[2].toNumber();
- double h = ctx->args()[3].toNumber();
+ double x = callData->args[0].toNumber();
+ double y = callData->args[1].toNumber();
+ double w = callData->args[2].toNumber();
+ double h = callData->args[3].toNumber();
- return ctx->engine()->fromVariant(QVariant::fromValue(QRectF(x, y, w, h)));
+ scope.result = scope.engine->fromVariant(QVariant::fromValue(QRectF(x, y, w, h)));
}
/*!
\qmlmethod point Qt::point(int x, int y)
Returns a Point with the specified \c x and \c y coordinates.
*/
-ReturnedValue QtObject::method_point(QV4::CallContext *ctx)
+void QtObject::method_point(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 2)
- V4THROW_ERROR("Qt.point(): Invalid arguments");
+ if (callData->argc != 2)
+ THROW_GENERIC_ERROR("Qt.point(): Invalid arguments");
- double x = ctx->args()[0].toNumber();
- double y = ctx->args()[1].toNumber();
+ double x = callData->args[0].toNumber();
+ double y = callData->args[1].toNumber();
- return ctx->engine()->fromVariant(QVariant::fromValue(QPointF(x, y)));
+ scope.result = scope.engine->fromVariant(QVariant::fromValue(QPointF(x, y)));
}
/*!
\qmlmethod Qt::size(int width, int height)
Returns a Size with the specified \c width and \c height.
*/
-ReturnedValue QtObject::method_size(QV4::CallContext *ctx)
+void QtObject::method_size(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 2)
- V4THROW_ERROR("Qt.size(): Invalid arguments");
+ if (callData->argc != 2)
+ THROW_GENERIC_ERROR("Qt.size(): Invalid arguments");
- double w = ctx->args()[0].toNumber();
- double h = ctx->args()[1].toNumber();
+ double w = callData->args[0].toNumber();
+ double h = callData->args[1].toNumber();
- return ctx->engine()->fromVariant(QVariant::fromValue(QSizeF(w, h)));
+ scope.result = scope.engine->fromVariant(QVariant::fromValue(QSizeF(w, h)));
}
/*!
@@ -413,17 +419,17 @@ key-value pairs where valid keys are the \l{fontbasictypedocs}{font} type's
subproperty names, and the values are valid values for each subproperty.
Invalid keys will be ignored.
*/
-ReturnedValue QtObject::method_font(QV4::CallContext *ctx)
+void QtObject::method_font(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1 || !ctx->args()[0].isObject())
- V4THROW_ERROR("Qt.font(): Invalid arguments");
+ if (callData->argc != 1 || !callData->args[0].isObject())
+ THROW_GENERIC_ERROR("Qt.font(): Invalid arguments");
- QV4::ExecutionEngine *v4 = ctx->d()->engine;
+ QV4::ExecutionEngine *v4 = scope.engine;
bool ok = false;
- QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QFont, QQmlV4Handle(ctx->args()[0]), v4, &ok);
+ QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QFont, QQmlV4Handle(callData->args[0]), v4, &ok);
if (!ok)
- V4THROW_ERROR("Qt.font(): Invalid argument: no valid font subproperties specified");
- return ctx->engine()->fromVariant(v);
+ THROW_GENERIC_ERROR("Qt.font(): Invalid argument: no valid font subproperties specified");
+ scope.result = scope.engine->fromVariant(v);
}
@@ -432,73 +438,73 @@ ReturnedValue QtObject::method_font(QV4::CallContext *ctx)
\qmlmethod Qt::vector2d(real x, real y)
Returns a Vector2D with the specified \c x and \c y.
*/
-ReturnedValue QtObject::method_vector2d(QV4::CallContext *ctx)
+void QtObject::method_vector2d(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 2)
- V4THROW_ERROR("Qt.vector2d(): Invalid arguments");
+ if (callData->argc != 2)
+ THROW_GENERIC_ERROR("Qt.vector2d(): Invalid arguments");
float xy[3]; // qvector2d uses float internally
- xy[0] = ctx->args()[0].toNumber();
- xy[1] = ctx->args()[1].toNumber();
+ xy[0] = callData->args[0].toNumber();
+ xy[1] = callData->args[1].toNumber();
const void *params[] = { xy };
- return ctx->engine()->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector2D, 1, params));
+ scope.result = scope.engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector2D, 1, params));
}
/*!
\qmlmethod Qt::vector3d(real x, real y, real z)
Returns a Vector3D with the specified \c x, \c y and \c z.
*/
-ReturnedValue QtObject::method_vector3d(QV4::CallContext *ctx)
+void QtObject::method_vector3d(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 3)
- V4THROW_ERROR("Qt.vector3d(): Invalid arguments");
+ if (callData->argc != 3)
+ THROW_GENERIC_ERROR("Qt.vector3d(): Invalid arguments");
float xyz[3]; // qvector3d uses float internally
- xyz[0] = ctx->args()[0].toNumber();
- xyz[1] = ctx->args()[1].toNumber();
- xyz[2] = ctx->args()[2].toNumber();
+ xyz[0] = callData->args[0].toNumber();
+ xyz[1] = callData->args[1].toNumber();
+ xyz[2] = callData->args[2].toNumber();
const void *params[] = { xyz };
- return ctx->engine()->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector3D, 1, params));
+ scope.result = scope.engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector3D, 1, params));
}
/*!
\qmlmethod Qt::vector4d(real x, real y, real z, real w)
Returns a Vector4D with the specified \c x, \c y, \c z and \c w.
*/
-ReturnedValue QtObject::method_vector4d(QV4::CallContext *ctx)
+void QtObject::method_vector4d(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 4)
- V4THROW_ERROR("Qt.vector4d(): Invalid arguments");
+ if (callData->argc != 4)
+ THROW_GENERIC_ERROR("Qt.vector4d(): Invalid arguments");
float xyzw[4]; // qvector4d uses float internally
- xyzw[0] = ctx->args()[0].toNumber();
- xyzw[1] = ctx->args()[1].toNumber();
- xyzw[2] = ctx->args()[2].toNumber();
- xyzw[3] = ctx->args()[3].toNumber();
+ xyzw[0] = callData->args[0].toNumber();
+ xyzw[1] = callData->args[1].toNumber();
+ xyzw[2] = callData->args[2].toNumber();
+ xyzw[3] = callData->args[3].toNumber();
const void *params[] = { xyzw };
- return ctx->engine()->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector4D, 1, params));
+ scope.result = scope.engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector4D, 1, params));
}
/*!
\qmlmethod Qt::quaternion(real scalar, real x, real y, real z)
Returns a Quaternion with the specified \c scalar, \c x, \c y, and \c z.
*/
-ReturnedValue QtObject::method_quaternion(QV4::CallContext *ctx)
+void QtObject::method_quaternion(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 4)
- V4THROW_ERROR("Qt.quaternion(): Invalid arguments");
+ if (callData->argc != 4)
+ THROW_GENERIC_ERROR("Qt.quaternion(): Invalid arguments");
qreal sxyz[4]; // qquaternion uses qreal internally
- sxyz[0] = ctx->args()[0].toNumber();
- sxyz[1] = ctx->args()[1].toNumber();
- sxyz[2] = ctx->args()[2].toNumber();
- sxyz[3] = ctx->args()[3].toNumber();
+ sxyz[0] = callData->args[0].toNumber();
+ sxyz[1] = callData->args[1].toNumber();
+ sxyz[2] = callData->args[2].toNumber();
+ sxyz[3] = callData->args[3].toNumber();
const void *params[] = { sxyz };
- return ctx->engine()->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QQuaternion, 1, params));
+ scope.result = scope.engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QQuaternion, 1, params));
}
/*!
@@ -510,44 +516,47 @@ matrix values.
Finally, the function may be called with no arguments and the resulting
matrix will be the identity matrix.
*/
-ReturnedValue QtObject::method_matrix4x4(QV4::CallContext *ctx)
+void QtObject::method_matrix4x4(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- QV4::ExecutionEngine *v4 = ctx->d()->engine;
+ QV4::ExecutionEngine *v4 = scope.engine;
- if (ctx->argc() == 0)
- return ctx->engine()->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QMatrix4x4, 0, Q_NULLPTR));
+ if (callData->argc == 0) {
+ scope.result = scope.engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QMatrix4x4, 0, Q_NULLPTR));
+ return;
+ }
- if (ctx->argc() == 1 && ctx->args()[0].isObject()) {
+ if (callData->argc == 1 && callData->args[0].isObject()) {
bool ok = false;
- QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QMatrix4x4, QQmlV4Handle(ctx->args()[0]), v4, &ok);
+ QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QMatrix4x4, QQmlV4Handle(callData->args[0]), v4, &ok);
if (!ok)
- V4THROW_ERROR("Qt.matrix4x4(): Invalid argument: not a valid matrix4x4 values array");
- return ctx->engine()->fromVariant(v);
+ THROW_GENERIC_ERROR("Qt.matrix4x4(): Invalid argument: not a valid matrix4x4 values array");
+ scope.result = scope.engine->fromVariant(v);
+ return;
}
- if (ctx->argc() != 16)
- V4THROW_ERROR("Qt.matrix4x4(): Invalid arguments");
+ if (callData->argc != 16)
+ THROW_GENERIC_ERROR("Qt.matrix4x4(): Invalid arguments");
qreal vals[16]; // qmatrix4x4 uses qreal internally
- vals[0] = ctx->args()[0].toNumber();
- vals[1] = ctx->args()[1].toNumber();
- vals[2] = ctx->args()[2].toNumber();
- vals[3] = ctx->args()[3].toNumber();
- vals[4] = ctx->args()[4].toNumber();
- vals[5] = ctx->args()[5].toNumber();
- vals[6] = ctx->args()[6].toNumber();
- vals[7] = ctx->args()[7].toNumber();
- vals[8] = ctx->args()[8].toNumber();
- vals[9] = ctx->args()[9].toNumber();
- vals[10] = ctx->args()[10].toNumber();
- vals[11] = ctx->args()[11].toNumber();
- vals[12] = ctx->args()[12].toNumber();
- vals[13] = ctx->args()[13].toNumber();
- vals[14] = ctx->args()[14].toNumber();
- vals[15] = ctx->args()[15].toNumber();
+ vals[0] = callData->args[0].toNumber();
+ vals[1] = callData->args[1].toNumber();
+ vals[2] = callData->args[2].toNumber();
+ vals[3] = callData->args[3].toNumber();
+ vals[4] = callData->args[4].toNumber();
+ vals[5] = callData->args[5].toNumber();
+ vals[6] = callData->args[6].toNumber();
+ vals[7] = callData->args[7].toNumber();
+ vals[8] = callData->args[8].toNumber();
+ vals[9] = callData->args[9].toNumber();
+ vals[10] = callData->args[10].toNumber();
+ vals[11] = callData->args[11].toNumber();
+ vals[12] = callData->args[12].toNumber();
+ vals[13] = callData->args[13].toNumber();
+ vals[14] = callData->args[14].toNumber();
+ vals[15] = callData->args[15].toNumber();
const void *params[] = { vals };
- return ctx->engine()->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QMatrix4x4, 1, params));
+ scope.result = scope.engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QMatrix4x4, 1, params));
}
/*!
@@ -564,27 +573,29 @@ by factor and converts the color back to RGB.
If \c factor is not supplied, returns a color 50% lighter than \c baseColor (factor 1.5).
*/
-ReturnedValue QtObject::method_lighter(QV4::CallContext *ctx)
+void QtObject::method_lighter(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1 && ctx->argc() != 2)
- V4THROW_ERROR("Qt.lighter(): Invalid arguments");
+ if (callData->argc != 1 && callData->argc != 2)
+ THROW_GENERIC_ERROR("Qt.lighter(): Invalid arguments");
- QVariant v = ctx->engine()->toVariant(ctx->args()[0], -1);
+ QVariant v = scope.engine->toVariant(callData->args[0], -1);
if (v.userType() == QVariant::String) {
bool ok = false;
v = QQmlStringConverters::colorFromString(v.toString(), &ok);
if (!ok) {
- return QV4::Encode::null();
+ scope.result = QV4::Encode::null();
+ return;
}
} else if (v.userType() != QVariant::Color) {
- return QV4::Encode::null();
+ scope.result = QV4::Encode::null();
+ return;
}
qreal factor = 1.5;
- if (ctx->argc() == 2)
- factor = ctx->args()[1].toNumber();
+ if (callData->argc == 2)
+ factor = callData->args[1].toNumber();
- return ctx->engine()->fromVariant(QQml_colorProvider()->lighter(v, factor));
+ scope.result = scope.engine->fromVariant(QQml_colorProvider()->lighter(v, factor));
}
/*!
@@ -602,27 +613,29 @@ by factor and converts the color back to RGB.
If \c factor is not supplied, returns a color 50% darker than \c baseColor (factor 2.0).
*/
-ReturnedValue QtObject::method_darker(QV4::CallContext *ctx)
+void QtObject::method_darker(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1 && ctx->argc() != 2)
- V4THROW_ERROR("Qt.darker(): Invalid arguments");
+ if (callData->argc != 1 && callData->argc != 2)
+ THROW_GENERIC_ERROR("Qt.darker(): Invalid arguments");
- QVariant v = ctx->engine()->toVariant(ctx->args()[0], -1);
+ QVariant v = scope.engine->toVariant(callData->args[0], -1);
if (v.userType() == QVariant::String) {
bool ok = false;
v = QQmlStringConverters::colorFromString(v.toString(), &ok);
if (!ok) {
- return QV4::Encode::null();
+ scope.result = QV4::Encode::null();
+ return;
}
} else if (v.userType() != QVariant::Color) {
- return QV4::Encode::null();
+ scope.result = QV4::Encode::null();
+ return;
}
qreal factor = 2.0;
- if (ctx->argc() == 2)
- factor = ctx->args()[1].toNumber();
+ if (callData->argc == 2)
+ factor = callData->args[1].toNumber();
- return ctx->engine()->fromVariant(QQml_colorProvider()->darker(v, factor));
+ scope.result = scope.engine->fromVariant(QQml_colorProvider()->darker(v, factor));
}
/*!
@@ -649,36 +662,40 @@ ReturnedValue QtObject::method_darker(QV4::CallContext *ctx)
Tint is most useful when a subtle change is intended to be conveyed due to some event; you can then use tinting to more effectively tune the visible color.
*/
-ReturnedValue QtObject::method_tint(QV4::CallContext *ctx)
+void QtObject::method_tint(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 2)
- V4THROW_ERROR("Qt.tint(): Invalid arguments");
+ if (callData->argc != 2)
+ THROW_GENERIC_ERROR("Qt.tint(): Invalid arguments");
// base color
- QVariant v1 = ctx->engine()->toVariant(ctx->args()[0], -1);
+ QVariant v1 = scope.engine->toVariant(callData->args[0], -1);
if (v1.userType() == QVariant::String) {
bool ok = false;
v1 = QQmlStringConverters::colorFromString(v1.toString(), &ok);
if (!ok) {
- return QV4::Encode::null();
+ scope.result = QV4::Encode::null();
+ return;
}
} else if (v1.userType() != QVariant::Color) {
- return QV4::Encode::null();
+ scope.result = QV4::Encode::null();
+ return;
}
// tint color
- QVariant v2 = ctx->engine()->toVariant(ctx->args()[1], -1);
+ QVariant v2 = scope.engine->toVariant(callData->args[1], -1);
if (v2.userType() == QVariant::String) {
bool ok = false;
v2 = QQmlStringConverters::colorFromString(v2.toString(), &ok);
if (!ok) {
- return QV4::Encode::null();
+ scope.result = QV4::Encode::null();
+ return;
}
} else if (v2.userType() != QVariant::Color) {
- return QV4::Encode::null();
+ scope.result = QV4::Encode::null();
+ return;
}
- return ctx->engine()->fromVariant(QQml_colorProvider()->tint(v1, v2));
+ scope.result = scope.engine->fromVariant(QQml_colorProvider()->tint(v1, v2));
}
/*!
@@ -697,32 +714,31 @@ If \a format is not specified, \a date is formatted using
\sa Locale
*/
-ReturnedValue QtObject::method_formatDate(QV4::CallContext *ctx)
+void QtObject::method_formatDate(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() < 1 || ctx->argc() > 2)
- V4THROW_ERROR("Qt.formatDate(): Invalid arguments");
- QV4::Scope scope(ctx);
+ if (callData->argc < 1 || callData->argc > 2)
+ THROW_GENERIC_ERROR("Qt.formatDate(): Invalid arguments");
Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
- QDate date = ctx->engine()->toVariant(ctx->args()[0], -1).toDateTime().date();
+ QDate date = scope.engine->toVariant(callData->args[0], -1).toDateTime().date();
QString formattedDate;
- if (ctx->argc() == 2) {
- QV4::ScopedString s(scope, ctx->args()[1]);
+ if (callData->argc == 2) {
+ QV4::ScopedString s(scope, callData->args[1]);
if (s) {
QString format = s->toQString();
formattedDate = date.toString(format);
- } else if (ctx->args()[1].isNumber()) {
- quint32 intFormat = ctx->args()[1].asDouble();
+ } else if (callData->args[1].isNumber()) {
+ quint32 intFormat = callData->args[1].asDouble();
Qt::DateFormat format = Qt::DateFormat(intFormat);
formattedDate = date.toString(format);
} else {
- V4THROW_ERROR("Qt.formatDate(): Invalid date format");
+ THROW_GENERIC_ERROR("Qt.formatDate(): Invalid date format");
}
} else {
formattedDate = date.toString(enumFormat);
}
- return ctx->d()->engine->newString(formattedDate)->asReturnedValue();
+ scope.result = scope.engine->newString(formattedDate);
}
/*!
@@ -740,38 +756,37 @@ If \a format is not specified, \a time is formatted using
\sa Locale
*/
-ReturnedValue QtObject::method_formatTime(QV4::CallContext *ctx)
+void QtObject::method_formatTime(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() < 1 || ctx->argc() > 2)
- V4THROW_ERROR("Qt.formatTime(): Invalid arguments");
- QV4::Scope scope(ctx);
+ if (callData->argc < 1 || callData->argc > 2)
+ THROW_GENERIC_ERROR("Qt.formatTime(): Invalid arguments");
- QVariant argVariant = ctx->engine()->toVariant(ctx->args()[0], -1);
+ QVariant argVariant = scope.engine->toVariant(callData->args[0], -1);
QTime time;
- if (ctx->args()[0].as<DateObject>() || (argVariant.type() == QVariant::String))
+ if (callData->args[0].as<DateObject>() || (argVariant.type() == QVariant::String))
time = argVariant.toDateTime().time();
else // if (argVariant.type() == QVariant::Time), or invalid.
time = argVariant.toTime();
Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
QString formattedTime;
- if (ctx->argc() == 2) {
- QV4::ScopedString s(scope, ctx->args()[1]);
+ if (callData->argc == 2) {
+ QV4::ScopedString s(scope, callData->args[1]);
if (s) {
QString format = s->toQString();
formattedTime = time.toString(format);
- } else if (ctx->args()[1].isNumber()) {
- quint32 intFormat = ctx->args()[1].asDouble();
+ } else if (callData->args[1].isNumber()) {
+ quint32 intFormat = callData->args[1].asDouble();
Qt::DateFormat format = Qt::DateFormat(intFormat);
formattedTime = time.toString(format);
} else {
- V4THROW_ERROR("Qt.formatTime(): Invalid time format");
+ THROW_GENERIC_ERROR("Qt.formatTime(): Invalid time format");
}
} else {
formattedTime = time.toString(enumFormat);
}
- return ctx->d()->engine->newString(formattedTime)->asReturnedValue();
+ scope.result = scope.engine->newString(formattedTime);
}
/*!
@@ -864,32 +879,31 @@ with the \a format values below to produce the following results:
\sa Locale
*/
-ReturnedValue QtObject::method_formatDateTime(QV4::CallContext *ctx)
+void QtObject::method_formatDateTime(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() < 1 || ctx->argc() > 2)
- V4THROW_ERROR("Qt.formatDateTime(): Invalid arguments");
- QV4::Scope scope(ctx);
+ if (callData->argc < 1 || callData->argc > 2)
+ THROW_GENERIC_ERROR("Qt.formatDateTime(): Invalid arguments");
Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
- QDateTime dt = ctx->engine()->toVariant(ctx->args()[0], -1).toDateTime();
+ QDateTime dt = scope.engine->toVariant(callData->args[0], -1).toDateTime();
QString formattedDt;
- if (ctx->argc() == 2) {
- QV4::ScopedString s(scope, ctx->args()[1]);
+ if (callData->argc == 2) {
+ QV4::ScopedString s(scope, callData->args[1]);
if (s) {
QString format = s->toQString();
formattedDt = dt.toString(format);
- } else if (ctx->args()[1].isNumber()) {
- quint32 intFormat = ctx->args()[1].asDouble();
+ } else if (callData->args[1].isNumber()) {
+ quint32 intFormat = callData->args[1].asDouble();
Qt::DateFormat format = Qt::DateFormat(intFormat);
formattedDt = dt.toString(format);
} else {
- V4THROW_ERROR("Qt.formatDateTime(): Invalid datetime format");
+ THROW_GENERIC_ERROR("Qt.formatDateTime(): Invalid datetime format");
}
} else {
formattedDt = dt.toString(enumFormat);
}
- return ctx->d()->engine->newString(formattedDt)->asReturnedValue();
+ scope.result = scope.engine->newString(formattedDt);
}
/*!
@@ -903,90 +917,94 @@ ReturnedValue QtObject::method_formatDateTime(QV4::CallContext *ctx)
still fail to launch or fail to open the requested URL. This result will not be reported back
to the application.
*/
-ReturnedValue QtObject::method_openUrlExternally(QV4::CallContext *ctx)
+void QtObject::method_openUrlExternally(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1)
- return QV4::Encode(false);
+ if (callData->argc != 1) {
+ scope.result = QV4::Encode(false);
+ return;
+ }
- QUrl url(Value::fromReturnedValue(method_resolvedUrl(ctx)).toQStringNoThrow());
- return ctx->engine()->fromVariant(QQml_guiProvider()->openUrlExternally(url));
+ method_resolvedUrl(b, scope, callData);
+ QUrl url(scope.result.toQStringNoThrow());
+ scope.result = scope.engine->fromVariant(QQml_guiProvider()->openUrlExternally(url));
}
/*!
\qmlmethod url Qt::resolvedUrl(url url)
Returns \a url resolved relative to the URL of the caller.
*/
-ReturnedValue QtObject::method_resolvedUrl(QV4::CallContext *ctx)
+void QtObject::method_resolvedUrl(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- ExecutionEngine *v4 = ctx->engine();
+ ExecutionEngine *v4 = scope.engine;
- QUrl url = v4->toVariant(ctx->args()[0], -1).toUrl();
+ QUrl url = v4->toVariant(callData->args[0], -1).toUrl();
QQmlEngine *e = v4->qmlEngine();
QQmlEnginePrivate *p = 0;
if (e) p = QQmlEnginePrivate::get(e);
if (p) {
QQmlContextData *ctxt = v4->callingQmlContext();
if (ctxt)
- return v4->newString(ctxt->resolvedUrl(url).toString())->asReturnedValue();
+ scope.result = v4->newString(ctxt->resolvedUrl(url).toString());
else
- return v4->newString(url.toString())->asReturnedValue();
+ scope.result = v4->newString(url.toString());
+ return;
}
- return v4->newString(e->baseUrl().resolved(url).toString())->asReturnedValue();
+ scope.result = v4->newString(e->baseUrl().resolved(url).toString());
}
/*!
\qmlmethod list<string> Qt::fontFamilies()
Returns a list of the font families available to the application.
*/
-ReturnedValue QtObject::method_fontFamilies(CallContext *ctx)
+void QtObject::method_fontFamilies(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 0)
- V4THROW_ERROR("Qt.fontFamilies(): Invalid arguments");
+ if (callData->argc != 0)
+ THROW_GENERIC_ERROR("Qt.fontFamilies(): Invalid arguments");
- return ctx->engine()->fromVariant(QVariant(QQml_guiProvider()->fontFamilies()));
+ scope.result = scope.engine->fromVariant(QVariant(QQml_guiProvider()->fontFamilies()));
}
/*!
\qmlmethod string Qt::md5(data)
Returns a hex string of the md5 hash of \c data.
*/
-ReturnedValue QtObject::method_md5(CallContext *ctx)
+void QtObject::method_md5(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1)
- V4THROW_ERROR("Qt.md5(): Invalid arguments");
+ if (callData->argc != 1)
+ THROW_GENERIC_ERROR("Qt.md5(): Invalid arguments");
- QByteArray data = ctx->args()[0].toQStringNoThrow().toUtf8();
+ QByteArray data = callData->args[0].toQStringNoThrow().toUtf8();
QByteArray result = QCryptographicHash::hash(data, QCryptographicHash::Md5);
- return ctx->d()->engine->newString(QLatin1String(result.toHex()))->asReturnedValue();
+ scope.result = scope.engine->newString(QLatin1String(result.toHex()));
}
/*!
\qmlmethod string Qt::btoa(data)
Binary to ASCII - this function returns a base64 encoding of \c data.
*/
-ReturnedValue QtObject::method_btoa(CallContext *ctx)
+void QtObject::method_btoa(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1)
- V4THROW_ERROR("Qt.btoa(): Invalid arguments");
+ if (callData->argc != 1)
+ THROW_GENERIC_ERROR("Qt.btoa(): Invalid arguments");
- QByteArray data = ctx->args()[0].toQStringNoThrow().toUtf8();
+ QByteArray data = callData->args[0].toQStringNoThrow().toUtf8();
- return ctx->d()->engine->newString(QLatin1String(data.toBase64()))->asReturnedValue();
+ scope.result = scope.engine->newString(QLatin1String(data.toBase64()));
}
/*!
\qmlmethod string Qt::atob(data)
ASCII to binary - this function decodes the base64 encoded \a data string and returns it.
*/
-ReturnedValue QtObject::method_atob(CallContext *ctx)
+void QtObject::method_atob(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1)
- V4THROW_ERROR("Qt.atob(): Invalid arguments");
+ if (callData->argc != 1)
+ THROW_GENERIC_ERROR("Qt.atob(): Invalid arguments");
- QByteArray data = ctx->args()[0].toQStringNoThrow().toLatin1();
+ QByteArray data = callData->args[0].toQStringNoThrow().toLatin1();
- return ctx->d()->engine->newString(QString::fromUtf8(QByteArray::fromBase64(data)))->asReturnedValue();
+ scope.result = scope.engine->newString(QString::fromUtf8(QByteArray::fromBase64(data)));
}
/*!
@@ -998,10 +1016,10 @@ QQmlEngine::quit() signal to the QCoreApplication::quit() slot.
\sa exit()
*/
-ReturnedValue QtObject::method_quit(CallContext *ctx)
+void QtObject::method_quit(const BuiltinFunction *, Scope &scope, CallData *)
{
- QQmlEnginePrivate::get(ctx->engine()->qmlEngine())->sendQuit();
- return QV4::Encode::undefined();
+ QQmlEnginePrivate::get(scope.engine->qmlEngine())->sendQuit();
+ scope.result = Encode::undefined();
}
/*!
@@ -1015,15 +1033,15 @@ ReturnedValue QtObject::method_quit(CallContext *ctx)
\sa quit()
*/
-ReturnedValue QtObject::method_exit(CallContext *ctx)
+void QtObject::method_exit(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1)
- V4THROW_ERROR("Qt.exit(): Invalid arguments");
+ if (callData->argc != 1)
+ THROW_GENERIC_ERROR("Qt.exit(): Invalid arguments");
- int retCode = ctx->args()[0].toNumber();
+ int retCode = callData->args[0].toNumber();
- QQmlEnginePrivate::get(ctx->engine()->qmlEngine())->sendExit(retCode);
- return QV4::Encode::undefined();
+ QQmlEnginePrivate::get(scope.engine->qmlEngine())->sendExit(retCode);
+ scope.result = QV4::Encode::undefined();
}
/*!
@@ -1050,11 +1068,10 @@ If this is the case, consider using \l{QtQml::Qt::createComponent()}{Qt.createCo
See \l {Dynamic QML Object Creation from JavaScript} for more information on using this function.
*/
-ReturnedValue QtObject::method_createQmlObject(CallContext *ctx)
+void QtObject::method_createQmlObject(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- Scope scope(ctx);
- if (ctx->argc() < 2 || ctx->argc() > 3)
- V4THROW_ERROR("Qt.createQmlObject(): Invalid arguments");
+ if (callData->argc < 2 || callData->argc > 3)
+ THROW_GENERIC_ERROR("Qt.createQmlObject(): Invalid arguments");
struct Error {
static ReturnedValue create(QV4::ExecutionEngine *v4, const QList<QQmlError> &errors) {
@@ -1085,7 +1102,7 @@ ReturnedValue QtObject::method_createQmlObject(CallContext *ctx)
}
};
- QV8Engine *v8engine = ctx->d()->engine->v8Engine;
+ QV8Engine *v8engine = scope.engine->v8Engine;
QQmlEngine *engine = v8engine->engine();
QQmlContextData *context = scope.engine->callingQmlContext();
@@ -1097,13 +1114,13 @@ ReturnedValue QtObject::method_createQmlObject(CallContext *ctx)
effectiveContext = context->asQQmlContext();
Q_ASSERT(effectiveContext);
- QString qml = ctx->args()[0].toQStringNoThrow();
+ QString qml = callData->args[0].toQStringNoThrow();
if (qml.isEmpty())
- return QV4::Encode::null();
+ RETURN_RESULT(Encode::null());
QUrl url;
- if (ctx->argc() > 2)
- url = QUrl(ctx->args()[2].toQStringNoThrow());
+ if (callData->argc > 2)
+ url = QUrl(callData->args[2].toQStringNoThrow());
else
url = QUrl(QLatin1String("inline"));
@@ -1111,11 +1128,11 @@ ReturnedValue QtObject::method_createQmlObject(CallContext *ctx)
url = context->resolvedUrl(url);
QObject *parentArg = 0;
- QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, ctx->args()[1]);
+ QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, callData->args[1]);
if (!!qobjectWrapper)
parentArg = qobjectWrapper->object();
if (!parentArg)
- V4THROW_ERROR("Qt.createQmlObject(): Missing parent object");
+ THROW_GENERIC_ERROR("Qt.createQmlObject(): Missing parent object");
QQmlTypeData *typeData = QQmlEnginePrivate::get(engine)->typeLoader.getType(
qml.toUtf8(), url, QQmlTypeLoader::Synchronous);
@@ -1126,12 +1143,12 @@ ReturnedValue QtObject::method_createQmlObject(CallContext *ctx)
componentPrivate->progress = 1.0;
if (component.isError()) {
- ScopedValue v(scope, Error::create(ctx->d()->engine, component.errors()));
- return ctx->engine()->throwError(v);
+ ScopedValue v(scope, Error::create(scope.engine, component.errors()));
+ RETURN_RESULT(scope.engine->throwError(v));
}
if (!component.isReady())
- V4THROW_ERROR("Qt.createQmlObject(): Component is not ready");
+ THROW_GENERIC_ERROR("Qt.createQmlObject(): Component is not ready");
QObject *obj = component.beginCreate(effectiveContext);
if (obj) {
@@ -1150,13 +1167,14 @@ ReturnedValue QtObject::method_createQmlObject(CallContext *ctx)
component.completeCreate();
if (component.isError()) {
- ScopedValue v(scope, Error::create(ctx->d()->engine, component.errors()));
- return ctx->engine()->throwError(v);
+ ScopedValue v(scope, Error::create(scope.engine, component.errors()));
+ scope.result = scope.engine->throwError(v);
+ return;
}
Q_ASSERT(obj);
- return QV4::QObjectWrapper::wrap(ctx->d()->engine, obj);
+ scope.result = QV4::QObjectWrapper::wrap(scope.engine, obj);
}
/*!
@@ -1203,14 +1221,12 @@ See \l {Dynamic QML Object Creation from JavaScript} for more information on usi
To create a QML object from an arbitrary string of QML (instead of a file),
use \l{QtQml::Qt::createQmlObject()}{Qt.createQmlObject()}.
*/
-ReturnedValue QtObject::method_createComponent(CallContext *ctx)
+void QtObject::method_createComponent(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() < 1 || ctx->argc() > 3)
- return ctx->engine()->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments"));
+ if (callData->argc < 1 || callData->argc > 3)
+ THROW_GENERIC_ERROR("Qt.createComponent(): Invalid arguments");
- Scope scope(ctx);
-
- QV8Engine *v8engine = ctx->d()->engine->v8Engine;
+ QV8Engine *v8engine = scope.engine->v8Engine;
QQmlEngine *engine = v8engine->engine();
QQmlContextData *context = scope.engine->callingQmlContext();
@@ -1219,41 +1235,41 @@ ReturnedValue QtObject::method_createComponent(CallContext *ctx)
if (context->isPragmaLibraryContext)
effectiveContext = 0;
- QString arg = ctx->args()[0].toQStringNoThrow();
+ QString arg = callData->args[0].toQStringNoThrow();
if (arg.isEmpty())
- return QV4::Encode::null();
+ RETURN_RESULT(QV4::Encode::null());
QQmlComponent::CompilationMode compileMode = QQmlComponent::PreferSynchronous;
QObject *parentArg = 0;
int consumedCount = 1;
- if (ctx->argc() > 1) {
- ScopedValue lastArg(scope, ctx->args()[ctx->argc()-1]);
+ if (callData->argc > 1) {
+ ScopedValue lastArg(scope, callData->args[callData->argc-1]);
// The second argument could be the mode enum
- if (ctx->args()[1].isInteger()) {
- int mode = ctx->args()[1].integerValue();
+ if (callData->args[1].isInteger()) {
+ int mode = callData->args[1].integerValue();
if (mode != int(QQmlComponent::PreferSynchronous) && mode != int(QQmlComponent::Asynchronous))
- return ctx->engine()->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments"));
+ THROW_GENERIC_ERROR("Qt.createComponent(): Invalid arguments");
compileMode = QQmlComponent::CompilationMode(mode);
consumedCount += 1;
} else {
// The second argument could be the parent only if there are exactly two args
- if ((ctx->argc() != 2) || !(lastArg->isObject() || lastArg->isNull()))
- return ctx->engine()->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments"));
+ if ((callData->argc != 2) || !(lastArg->isObject() || lastArg->isNull()))
+ THROW_GENERIC_ERROR("Qt.createComponent(): Invalid arguments");
}
- if (consumedCount < ctx->argc()) {
+ if (consumedCount < callData->argc) {
if (lastArg->isObject()) {
Scoped<QObjectWrapper> qobjectWrapper(scope, lastArg);
if (qobjectWrapper)
parentArg = qobjectWrapper->object();
if (!parentArg)
- return ctx->engine()->throwError(QStringLiteral("Qt.createComponent(): Invalid parent object"));
+ THROW_GENERIC_ERROR("Qt.createComponent(): Invalid parent object");
} else if (lastArg->isNull()) {
parentArg = 0;
} else {
- return ctx->engine()->throwError(QStringLiteral("Qt.createComponent(): Invalid parent object"));
+ THROW_GENERIC_ERROR("Qt.createComponent(): Invalid parent object");
}
}
}
@@ -1264,7 +1280,7 @@ ReturnedValue QtObject::method_createComponent(CallContext *ctx)
QQmlData::get(c, true)->explicitIndestructibleSet = false;
QQmlData::get(c)->indestructible = false;
- return QV4::QObjectWrapper::wrap(ctx->d()->engine, c);
+ scope.result = QV4::QObjectWrapper::wrap(scope.engine, c);
}
/*!
@@ -1287,18 +1303,18 @@ ReturnedValue QtObject::method_createComponent(CallContext *ctx)
\sa Locale
*/
-ReturnedValue QtObject::method_locale(CallContext *ctx)
+void QtObject::method_locale(const BuiltinFunction *, Scope &scope, CallData *callData)
{
QString code;
- if (ctx->argc() > 1)
- V4THROW_ERROR("locale() requires 0 or 1 argument");
- if (ctx->argc() == 1 && !ctx->args()[0].isString())
- V4THROW_TYPE("locale(): argument (locale code) must be a string");
+ if (callData->argc > 1)
+ THROW_GENERIC_ERROR("locale() requires 0 or 1 argument");
+ if (callData->argc == 1 && !callData->args[0].isString())
+ THROW_TYPE_ERROR_WITH_MESSAGE("locale(): argument (locale code) must be a string");
- if (ctx->argc() == 1)
- code = ctx->args()[0].toQStringNoThrow();
+ if (callData->argc == 1)
+ code = callData->args[0].toQStringNoThrow();
- return QQmlLocale::locale(ctx->engine(), code);
+ scope.result = QQmlLocale::locale(scope.engine, code);
}
void Heap::QQmlBindingFunction::init(const QV4::FunctionObject *originalFunction)
@@ -1360,62 +1376,62 @@ DEFINE_OBJECT_VTABLE(QQmlBindingFunction);
\since 5.0
*/
-ReturnedValue QtObject::method_binding(CallContext *ctx)
+void QtObject::method_binding(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1)
- V4THROW_ERROR("binding() requires 1 argument");
- const QV4::FunctionObject *f = ctx->args()[0].as<FunctionObject>();
+ if (callData->argc != 1)
+ THROW_GENERIC_ERROR("binding() requires 1 argument");
+ const QV4::FunctionObject *f = callData->args[0].as<FunctionObject>();
if (!f)
- V4THROW_TYPE("binding(): argument (binding expression) must be a function");
+ THROW_TYPE_ERROR_WITH_MESSAGE("binding(): argument (binding expression) must be a function");
- return (ctx->d()->engine->memoryManager->allocObject<QQmlBindingFunction>(f))->asReturnedValue();
+ scope.result = scope.engine->memoryManager->allocObject<QQmlBindingFunction>(f);
}
-ReturnedValue QtObject::method_get_platform(CallContext *ctx)
+void QtObject::method_get_platform(const BuiltinFunction *, Scope &scope, CallData *callData)
{
// ### inefficient. Should be just a value based getter
- Object *o = ctx->thisObject().as<Object>();
+ Object *o = callData->thisObject.as<Object>();
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
QtObject *qt = o->as<QtObject>();
if (!qt)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (!qt->d()->platform)
// Only allocate a platform object once
- qt->d()->platform = new QQmlPlatform(ctx->d()->engine->jsEngine());
+ qt->d()->platform = new QQmlPlatform(scope.engine->jsEngine());
- return QV4::QObjectWrapper::wrap(ctx->d()->engine, qt->d()->platform);
+ scope.result = QV4::QObjectWrapper::wrap(scope.engine, qt->d()->platform);
}
-ReturnedValue QtObject::method_get_application(CallContext *ctx)
+void QtObject::method_get_application(const BuiltinFunction *, Scope &scope, CallData *callData)
{
// ### inefficient. Should be just a value based getter
- Object *o = ctx->thisObject().as<Object>();
+ Object *o = callData->thisObject.as<Object>();
if (!o)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
QtObject *qt = o->as<QtObject>();
if (!qt)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (!qt->d()->application)
// Only allocate an application object once
- qt->d()->application = QQml_guiProvider()->application(ctx->d()->engine->jsEngine());
+ qt->d()->application = QQml_guiProvider()->application(scope.engine->jsEngine());
- return QV4::QObjectWrapper::wrap(ctx->d()->engine, qt->d()->application);
+ scope.result = QV4::QObjectWrapper::wrap(scope.engine, qt->d()->application);
}
-ReturnedValue QtObject::method_get_inputMethod(CallContext *ctx)
+void QtObject::method_get_inputMethod(const BuiltinFunction *, Scope &scope, CallData *)
{
QObject *o = QQml_guiProvider()->inputMethod();
- return QV4::QObjectWrapper::wrap(ctx->d()->engine, o);
+ scope.result = QV4::QObjectWrapper::wrap(scope.engine, o);
}
-ReturnedValue QtObject::method_get_styleHints(CallContext *ctx)
+void QtObject::method_get_styleHints(const BuiltinFunction *, Scope &scope, CallData *)
{
QObject *o = QQml_guiProvider()->styleHints();
- return QV4::QObjectWrapper::wrap(ctx->d()->engine, o);
+ scope.result = QV4::QObjectWrapper::wrap(scope.engine, o);
}
@@ -1475,35 +1491,35 @@ static QString jsStack(QV4::ExecutionEngine *engine) {
return stack;
}
-static QV4::ReturnedValue writeToConsole(ConsoleLogTypes logType, CallContext *ctx,
- bool printStack = false)
+static void writeToConsole(const BuiltinFunction *, Scope &scope, CallData *callData,
+ ConsoleLogTypes logType, bool printStack = false)
{
QLoggingCategory *loggingCategory = 0;
QString result;
- QV4::ExecutionEngine *v4 = ctx->d()->engine;
+ QV4::ExecutionEngine *v4 = scope.engine;
int start = 0;
- if (ctx->argc() > 0) {
- if (const QObjectWrapper* wrapper = ctx->args()[0].as<QObjectWrapper>()) {
+ if (callData->argc > 0) {
+ if (const QObjectWrapper* wrapper = callData->args[0].as<QObjectWrapper>()) {
if (QQmlLoggingCategory* category = qobject_cast<QQmlLoggingCategory*>(wrapper->object())) {
if (category->category())
loggingCategory = category->category();
else
- V4THROW_ERROR("A QmlLoggingCatgory was provided without a valid name");
+ THROW_GENERIC_ERROR("A QmlLoggingCatgory was provided without a valid name");
start = 1;
}
}
}
- for (int i = start; i < ctx->argc(); ++i) {
+ for (int i = start; i < callData->argc; ++i) {
if (i != start)
result.append(QLatin1Char(' '));
- if (ctx->args()[i].as<ArrayObject>())
- result += QLatin1Char('[') + ctx->args()[i].toQStringNoThrow() + QLatin1Char(']');
+ if (callData->args[i].as<ArrayObject>())
+ result += QLatin1Char('[') + callData->args[i].toQStringNoThrow() + QLatin1Char(']');
else
- result.append(ctx->args()[i].toQStringNoThrow());
+ result.append(callData->args[i].toQStringNoThrow());
}
if (printStack)
@@ -1540,32 +1556,32 @@ static QV4::ReturnedValue writeToConsole(ConsoleLogTypes logType, CallContext *c
break;
}
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
DEFINE_OBJECT_VTABLE(ConsoleObject);
-QV4::ReturnedValue ConsoleObject::method_error(CallContext *ctx)
+void ConsoleObject::method_error(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- return writeToConsole(Error, ctx);
+ writeToConsole(b, scope, callData, Error);
}
-QV4::ReturnedValue ConsoleObject::method_log(CallContext *ctx)
+void ConsoleObject::method_log(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
//console.log
//console.debug
//print
- return writeToConsole(Log, ctx);
+ writeToConsole(b, scope, callData, Log);
}
-QV4::ReturnedValue ConsoleObject::method_info(CallContext *ctx)
+void ConsoleObject::method_info(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- return writeToConsole(Info, ctx);
+ writeToConsole(b, scope, callData, Info);
}
-QV4::ReturnedValue ConsoleObject::method_profile(CallContext *ctx)
+void ConsoleObject::method_profile(const BuiltinFunction *, Scope &scope, CallData *)
{
- QV4::ExecutionEngine *v4 = ctx->d()->engine;
+ QV4::ExecutionEngine *v4 = scope.engine;
QV4::StackFrame frame = v4->currentStackFrame();
const QByteArray baSource = frame.source.toUtf8();
@@ -1579,12 +1595,12 @@ QV4::ReturnedValue ConsoleObject::method_profile(CallContext *ctx)
logger.debug("Profiling started.");
}
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
-QV4::ReturnedValue ConsoleObject::method_profileEnd(CallContext *ctx)
+void ConsoleObject::method_profileEnd(const BuiltinFunction *, Scope &scope, CallData *)
{
- QV4::ExecutionEngine *v4 = ctx->d()->engine;
+ QV4::ExecutionEngine *v4 = scope.engine;
QV4::StackFrame frame = v4->currentStackFrame();
const QByteArray baSource = frame.source.toUtf8();
@@ -1599,46 +1615,46 @@ QV4::ReturnedValue ConsoleObject::method_profileEnd(CallContext *ctx)
logger.debug("Profiling ended.");
}
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
-QV4::ReturnedValue ConsoleObject::method_time(CallContext *ctx)
+void ConsoleObject::method_time(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1)
- V4THROW_ERROR("console.time(): Invalid arguments");
+ if (callData->argc != 1)
+ THROW_GENERIC_ERROR("console.time(): Invalid arguments");
- QV8Engine *v8engine = ctx->d()->engine->v8Engine;
+ QV8Engine *v8engine = scope.engine->v8Engine;
- QString name = ctx->args()[0].toQStringNoThrow();
+ QString name = callData->args[0].toQStringNoThrow();
v8engine->startTimer(name);
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
-QV4::ReturnedValue ConsoleObject::method_timeEnd(CallContext *ctx)
+void ConsoleObject::method_timeEnd(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1)
- V4THROW_ERROR("console.timeEnd(): Invalid arguments");
+ if (callData->argc != 1)
+ THROW_GENERIC_ERROR("console.timeEnd(): Invalid arguments");
- QV8Engine *v8engine = ctx->d()->engine->v8Engine;
+ QV8Engine *v8engine = scope.engine->v8Engine;
- QString name = ctx->args()[0].toQStringNoThrow();
+ QString name = callData->args[0].toQStringNoThrow();
bool wasRunning;
qint64 elapsed = v8engine->stopTimer(name, &wasRunning);
if (wasRunning) {
qDebug("%s: %llims", qPrintable(name), elapsed);
}
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
-QV4::ReturnedValue ConsoleObject::method_count(CallContext *ctx)
+void ConsoleObject::method_count(const BuiltinFunction *, Scope &scope, CallData *callData)
{
// first argument: name to print. Ignore any additional arguments
QString name;
- if (ctx->argc() > 0)
- name = ctx->args()[0].toQStringNoThrow();
+ if (callData->argc > 0)
+ name = callData->args[0].toQStringNoThrow();
- QV4::ExecutionEngine *v4 = ctx->d()->engine;
- QV8Engine *v8engine = ctx->d()->engine->v8Engine;
+ QV4::ExecutionEngine *v4 = scope.engine;
+ QV8Engine *v8engine = scope.engine->v8Engine;
QV4::StackFrame frame = v4->currentStackFrame();
@@ -1651,15 +1667,15 @@ QV4::ReturnedValue ConsoleObject::method_count(CallContext *ctx)
qPrintable(frame.function))
.debug("%s", qPrintable(message));
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
-QV4::ReturnedValue ConsoleObject::method_trace(CallContext *ctx)
+void ConsoleObject::method_trace(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 0)
- V4THROW_ERROR("console.trace(): Invalid arguments");
+ if (callData->argc != 0)
+ THROW_GENERIC_ERROR("console.trace(): Invalid arguments");
- QV4::ExecutionEngine *v4 = ctx->d()->engine;
+ QV4::ExecutionEngine *v4 = scope.engine;
QString stack = jsStack(v4);
@@ -1668,28 +1684,28 @@ QV4::ReturnedValue ConsoleObject::method_trace(CallContext *ctx)
frame.function.toUtf8().constData())
.debug("%s", qPrintable(stack));
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
-QV4::ReturnedValue ConsoleObject::method_warn(CallContext *ctx)
+void ConsoleObject::method_warn(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- return writeToConsole(Warn, ctx);
+ return writeToConsole(b, scope, callData, Warn);
}
-QV4::ReturnedValue ConsoleObject::method_assert(CallContext *ctx)
+void ConsoleObject::method_assert(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() == 0)
- V4THROW_ERROR("console.assert(): Missing argument");
+ if (callData->argc == 0)
+ THROW_GENERIC_ERROR("console.assert(): Missing argument");
- QV4::ExecutionEngine *v4 = ctx->d()->engine;
+ QV4::ExecutionEngine *v4 = scope.engine;
- if (!ctx->args()[0].toBoolean()) {
+ if (!callData->args[0].toBoolean()) {
QString message;
- for (int i = 1; i < ctx->argc(); ++i) {
+ for (int i = 1; i < callData->argc; ++i) {
if (i != 1)
message.append(QLatin1Char(' '));
- message.append(ctx->args()[i].toQStringNoThrow());
+ message.append(callData->args[i].toQStringNoThrow());
}
QString stack = jsStack(v4);
@@ -1700,17 +1716,17 @@ QV4::ReturnedValue ConsoleObject::method_assert(CallContext *ctx)
.critical("%s\n%s",qPrintable(message), qPrintable(stack));
}
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
-QV4::ReturnedValue ConsoleObject::method_exception(CallContext *ctx)
+void ConsoleObject::method_exception(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- if (ctx->argc() == 0)
- V4THROW_ERROR("console.exception(): Missing argument");
+ if (callData->argc == 0)
+ THROW_GENERIC_ERROR("console.exception(): Missing argument");
- writeToConsole(Error, ctx, true);
+ writeToConsole(b, scope, callData, Error, true);
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
@@ -1766,38 +1782,38 @@ void QV4::GlobalExtensions::init(Object *globalObject, QJSEngine::Extensions ext
\sa {Internationalization and Localization with Qt Quick}
*/
-ReturnedValue GlobalExtensions::method_qsTranslate(CallContext *ctx)
-{
- if (ctx->argc() < 2)
- V4THROW_ERROR("qsTranslate() requires at least two arguments");
- if (!ctx->args()[0].isString())
- V4THROW_ERROR("qsTranslate(): first argument (context) must be a string");
- if (!ctx->args()[1].isString())
- V4THROW_ERROR("qsTranslate(): second argument (sourceText) must be a string");
- if ((ctx->argc() > 2) && !ctx->args()[2].isString())
- V4THROW_ERROR("qsTranslate(): third argument (disambiguation) must be a string");
-
- QString context = ctx->args()[0].toQStringNoThrow();
- QString text = ctx->args()[1].toQStringNoThrow();
+void GlobalExtensions::method_qsTranslate(const BuiltinFunction *, Scope &scope, CallData *callData)
+{
+ if (callData->argc < 2)
+ THROW_GENERIC_ERROR("qsTranslate() requires at least two arguments");
+ if (!callData->args[0].isString())
+ THROW_GENERIC_ERROR("qsTranslate(): first argument (context) must be a string");
+ if (!callData->args[1].isString())
+ THROW_GENERIC_ERROR("qsTranslate(): second argument (sourceText) must be a string");
+ if ((callData->argc > 2) && !callData->args[2].isString())
+ THROW_GENERIC_ERROR("qsTranslate(): third argument (disambiguation) must be a string");
+
+ QString context = callData->args[0].toQStringNoThrow();
+ QString text = callData->args[1].toQStringNoThrow();
QString comment;
- if (ctx->argc() > 2) comment = ctx->args()[2].toQStringNoThrow();
+ if (callData->argc > 2) comment = callData->args[2].toQStringNoThrow();
int i = 3;
- if (ctx->argc() > i && ctx->args()[i].isString()) {
+ if (callData->argc > i && callData->args[i].isString()) {
qWarning("qsTranslate(): specifying the encoding as fourth argument is deprecated");
++i;
}
int n = -1;
- if (ctx->argc() > i)
- n = ctx->args()[i].toInt32();
+ if (callData->argc > i)
+ n = callData->args[i].toInt32();
QString result = QCoreApplication::translate(context.toUtf8().constData(),
text.toUtf8().constData(),
comment.toUtf8().constData(),
n);
- return ctx->d()->engine->newString(result)->asReturnedValue();
+ scope.result = scope.engine->newString(result);
}
/*!
@@ -1822,11 +1838,12 @@ ReturnedValue GlobalExtensions::method_qsTranslate(CallContext *ctx)
\sa {Internationalization and Localization with Qt Quick}
*/
-ReturnedValue GlobalExtensions::method_qsTranslateNoOp(CallContext *ctx)
+void GlobalExtensions::method_qsTranslateNoOp(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() < 2)
- return QV4::Encode::undefined();
- return ctx->args()[1].asReturnedValue();
+ if (callData->argc < 2)
+ scope.result = QV4::Encode::undefined();
+ else
+ scope.result = callData->args[1];
}
/*!
@@ -1846,18 +1863,17 @@ ReturnedValue GlobalExtensions::method_qsTranslateNoOp(CallContext *ctx)
\sa {Internationalization and Localization with Qt Quick}
*/
-ReturnedValue GlobalExtensions::method_qsTr(CallContext *ctx)
-{
- if (ctx->argc() < 1)
- V4THROW_ERROR("qsTr() requires at least one argument");
- if (!ctx->args()[0].isString())
- V4THROW_ERROR("qsTr(): first argument (sourceText) must be a string");
- if ((ctx->argc() > 1) && !ctx->args()[1].isString())
- V4THROW_ERROR("qsTr(): second argument (disambiguation) must be a string");
- if ((ctx->argc() > 2) && !ctx->args()[2].isNumber())
- V4THROW_ERROR("qsTr(): third argument (n) must be a number");
-
- Scope scope(ctx);
+void GlobalExtensions::method_qsTr(const BuiltinFunction *, Scope &scope, CallData *callData)
+{
+ if (callData->argc < 1)
+ THROW_GENERIC_ERROR("qsTr() requires at least one argument");
+ if (!callData->args[0].isString())
+ THROW_GENERIC_ERROR("qsTr(): first argument (sourceText) must be a string");
+ if ((callData->argc > 1) && !callData->args[1].isString())
+ THROW_GENERIC_ERROR("qsTr(): second argument (disambiguation) must be a string");
+ if ((callData->argc > 2) && !callData->args[2].isNumber())
+ THROW_GENERIC_ERROR("qsTr(): third argument (n) must be a number");
+
QString context;
if (QQmlContextData *ctxt = scope.engine->callingQmlContext()) {
QString path = ctxt->urlString();
@@ -1866,7 +1882,7 @@ ReturnedValue GlobalExtensions::method_qsTr(CallContext *ctx)
int length = lastDot - (lastSlash + 1);
context = (lastSlash > -1) ? path.mid(lastSlash + 1, (length > -1) ? length : -1) : QString();
} else {
- ExecutionContext *parentCtx = scope.engine->parentContext(ctx);
+ ExecutionContext *parentCtx = scope.engine->currentContext;
// The first non-empty source URL in the call stack determines the translation context.
while (!!parentCtx && context.isEmpty()) {
if (QV4::CompiledData::CompilationUnit *unit = parentCtx->d()->compilationUnit) {
@@ -1885,18 +1901,18 @@ ReturnedValue GlobalExtensions::method_qsTr(CallContext *ctx)
}
}
- QString text = ctx->args()[0].toQStringNoThrow();
+ QString text = callData->args[0].toQStringNoThrow();
QString comment;
- if (ctx->argc() > 1)
- comment = ctx->args()[1].toQStringNoThrow();
+ if (callData->argc > 1)
+ comment = callData->args[1].toQStringNoThrow();
int n = -1;
- if (ctx->argc() > 2)
- n = ctx->args()[2].toInt32();
+ if (callData->argc > 2)
+ n = callData->args[2].toInt32();
QString result = QCoreApplication::translate(context.toUtf8().constData(), text.toUtf8().constData(),
comment.toUtf8().constData(), n);
- return ctx->d()->engine->newString(result)->asReturnedValue();
+ scope.result = scope.engine->newString(result);
}
/*!
@@ -1921,11 +1937,12 @@ ReturnedValue GlobalExtensions::method_qsTr(CallContext *ctx)
\sa {Internationalization and Localization with Qt Quick}
*/
-ReturnedValue GlobalExtensions::method_qsTrNoOp(CallContext *ctx)
+void GlobalExtensions::method_qsTrNoOp(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() < 1)
- return QV4::Encode::undefined();
- return ctx->args()[0].asReturnedValue();
+ if (callData->argc < 1)
+ scope.result = QV4::Encode::undefined();
+ else
+ scope.result = callData->args[0];
}
/*!
@@ -1958,20 +1975,20 @@ ReturnedValue GlobalExtensions::method_qsTrNoOp(CallContext *ctx)
\sa QT_TRID_NOOP(), {Internationalization and Localization with Qt Quick}
*/
-ReturnedValue GlobalExtensions::method_qsTrId(CallContext *ctx)
+void GlobalExtensions::method_qsTrId(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() < 1)
- V4THROW_ERROR("qsTrId() requires at least one argument");
- if (!ctx->args()[0].isString())
- V4THROW_TYPE("qsTrId(): first argument (id) must be a string");
- if (ctx->argc() > 1 && !ctx->args()[1].isNumber())
- V4THROW_TYPE("qsTrId(): second argument (n) must be a number");
+ if (callData->argc < 1)
+ THROW_GENERIC_ERROR("qsTrId() requires at least one argument");
+ if (!callData->args[0].isString())
+ THROW_TYPE_ERROR_WITH_MESSAGE("qsTrId(): first argument (id) must be a string");
+ if (callData->argc > 1 && !callData->args[1].isNumber())
+ THROW_TYPE_ERROR_WITH_MESSAGE("qsTrId(): second argument (n) must be a number");
int n = -1;
- if (ctx->argc() > 1)
- n = ctx->args()[1].toInt32();
+ if (callData->argc > 1)
+ n = callData->args[1].toInt32();
- return ctx->d()->engine->newString(qtTrId(ctx->args()[0].toQStringNoThrow().toUtf8().constData(), n))->asReturnedValue();
+ scope.result = scope.engine->newString(qtTrId(callData->args[0].toQStringNoThrow().toUtf8().constData(), n));
}
/*!
@@ -1990,41 +2007,41 @@ ReturnedValue GlobalExtensions::method_qsTrId(CallContext *ctx)
\sa qsTrId(), {Internationalization and Localization with Qt Quick}
*/
-ReturnedValue GlobalExtensions::method_qsTrIdNoOp(CallContext *ctx)
+void GlobalExtensions::method_qsTrIdNoOp(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() < 1)
- return QV4::Encode::undefined();
- return ctx->args()[0].asReturnedValue();
+ if (callData->argc < 1)
+ scope.result = QV4::Encode::undefined();
+ else
+ scope.result = callData->args[0];
}
#endif // translation
-QV4::ReturnedValue GlobalExtensions::method_gc(CallContext *ctx)
+void GlobalExtensions::method_gc(const BuiltinFunction *, Scope &scope, CallData *)
{
- ctx->d()->engine->memoryManager->runGC();
+ scope.engine->memoryManager->runGC();
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
-ReturnedValue GlobalExtensions::method_string_arg(CallContext *ctx)
+void GlobalExtensions::method_string_arg(const BuiltinFunction *, Scope &scope, CallData *callData)
{
- if (ctx->argc() != 1)
- V4THROW_ERROR("String.arg(): Invalid arguments");
+ if (callData->argc != 1)
+ THROW_GENERIC_ERROR("String.arg(): Invalid arguments");
- QString value = ctx->thisObject().toQString();
+ QString value = callData->thisObject.toQString();
- QV4::Scope scope(ctx);
- QV4::ScopedValue arg(scope, ctx->args()[0]);
+ QV4::ScopedValue arg(scope, callData->args[0]);
if (arg->isInteger())
- return ctx->d()->engine->newString(value.arg(arg->integerValue()))->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(value.arg(arg->integerValue())));
else if (arg->isDouble())
- return ctx->d()->engine->newString(value.arg(arg->doubleValue()))->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(value.arg(arg->doubleValue())));
else if (arg->isBoolean())
- return ctx->d()->engine->newString(value.arg(arg->booleanValue()))->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(value.arg(arg->booleanValue())));
- return ctx->d()->engine->newString(value.arg(arg->toQString()))->asReturnedValue();
+ RETURN_RESULT(scope.engine->newString(value.arg(arg->toQString())));
}
/*!
@@ -2047,10 +2064,10 @@ be passed on to the function invoked. Note that if redundant calls
are eliminated, then only the last set of arguments will be passed to the
function.
*/
-ReturnedValue QtObject::method_callLater(CallContext *ctx)
+void QtObject::method_callLater(const BuiltinFunction *b, Scope &scope, CallData *callData)
{
- QV8Engine *v8engine = ctx->engine()->v8Engine;
- return v8engine->delayedCallQueue()->addUniquelyAndExecuteLater(ctx);
+ QV8Engine *v8engine = scope.engine->v8Engine;
+ v8engine->delayedCallQueue()->addUniquelyAndExecuteLater(b, scope, callData);
}
QT_END_NAMESPACE
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h
index fe43532647..21613b7c10 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h
@@ -93,45 +93,45 @@ struct QtObject : Object
static ReturnedValue get(const Managed *m, String *name, bool *hasProperty);
static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes);
- static ReturnedValue method_isQtObject(CallContext *ctx);
- static ReturnedValue method_rgba(CallContext *ctx);
- static ReturnedValue method_hsla(CallContext *ctx);
- static ReturnedValue method_hsva(CallContext *ctx);
- static ReturnedValue method_colorEqual(CallContext *ctx);
- static ReturnedValue method_font(CallContext *ctx);
- static ReturnedValue method_rect(CallContext *ctx);
- static ReturnedValue method_point(CallContext *ctx);
- static ReturnedValue method_size(CallContext *ctx);
- static ReturnedValue method_vector2d(CallContext *ctx);
- static ReturnedValue method_vector3d(CallContext *ctx);
- static ReturnedValue method_vector4d(CallContext *ctx);
- static ReturnedValue method_quaternion(CallContext *ctx);
- static ReturnedValue method_matrix4x4(CallContext *ctx);
- static ReturnedValue method_lighter(CallContext *ctx);
- static ReturnedValue method_darker(CallContext *ctx);
- static ReturnedValue method_tint(CallContext *ctx);
- static ReturnedValue method_formatDate(CallContext *ctx);
- static ReturnedValue method_formatTime(CallContext *ctx);
- static ReturnedValue method_formatDateTime(CallContext *ctx);
- static ReturnedValue method_openUrlExternally(CallContext *ctx);
- static ReturnedValue method_fontFamilies(CallContext *ctx);
- static ReturnedValue method_md5(CallContext *ctx);
- static ReturnedValue method_btoa(CallContext *ctx);
- static ReturnedValue method_atob(CallContext *ctx);
- static ReturnedValue method_quit(CallContext *ctx);
- static ReturnedValue method_exit(CallContext *ctx);
- static ReturnedValue method_resolvedUrl(CallContext *ctx);
- static ReturnedValue method_createQmlObject(CallContext *ctx);
- static ReturnedValue method_createComponent(CallContext *ctx);
- static ReturnedValue method_locale(CallContext *ctx);
- static ReturnedValue method_binding(CallContext *ctx);
-
- static ReturnedValue method_get_platform(CallContext *ctx);
- static ReturnedValue method_get_application(CallContext *ctx);
- static ReturnedValue method_get_inputMethod(CallContext *ctx);
- static ReturnedValue method_get_styleHints(CallContext *ctx);
-
- static ReturnedValue method_callLater(CallContext *ctx);
+ static void method_isQtObject(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_rgba(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_hsla(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_hsva(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_colorEqual(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_font(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_rect(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_point(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_size(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_vector2d(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_vector3d(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_vector4d(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_quaternion(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_matrix4x4(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_lighter(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_darker(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_tint(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_formatDate(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_formatTime(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_formatDateTime(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_openUrlExternally(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_fontFamilies(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_md5(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_btoa(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_atob(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_quit(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_exit(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_resolvedUrl(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_createQmlObject(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_createComponent(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_locale(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_binding(const BuiltinFunction *, Scope &scope, CallData *callData);
+
+ static void method_get_platform(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_application(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_inputMethod(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_get_styleHints(const BuiltinFunction *, Scope &scope, CallData *callData);
+
+ static void method_callLater(const BuiltinFunction *, Scope &scope, CallData *callData);
private:
void addAll();
@@ -142,18 +142,18 @@ struct ConsoleObject : Object
{
V4_OBJECT2(ConsoleObject, Object)
- static ReturnedValue method_error(CallContext *ctx);
- static ReturnedValue method_log(CallContext *ctx);
- static ReturnedValue method_info(CallContext *ctx);
- static ReturnedValue method_profile(CallContext *ctx);
- static ReturnedValue method_profileEnd(CallContext *ctx);
- static ReturnedValue method_time(CallContext *ctx);
- static ReturnedValue method_timeEnd(CallContext *ctx);
- static ReturnedValue method_count(CallContext *ctx);
- static ReturnedValue method_trace(CallContext *ctx);
- static ReturnedValue method_warn(CallContext *ctx);
- static ReturnedValue method_assert(CallContext *ctx);
- static ReturnedValue method_exception(CallContext *ctx);
+ static void method_error(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_log(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_info(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_profile(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_profileEnd(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_time(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_timeEnd(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_count(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_trace(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_warn(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_assert(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_exception(const BuiltinFunction *, Scope &scope, CallData *callData);
};
@@ -161,17 +161,17 @@ struct Q_QML_PRIVATE_EXPORT GlobalExtensions {
static void init(Object *globalObject, QJSEngine::Extensions extensions);
#if QT_CONFIG(translation)
- static ReturnedValue method_qsTranslate(CallContext *ctx);
- static ReturnedValue method_qsTranslateNoOp(CallContext *ctx);
- static ReturnedValue method_qsTr(CallContext *ctx);
- static ReturnedValue method_qsTrNoOp(CallContext *ctx);
- static ReturnedValue method_qsTrId(CallContext *ctx);
- static ReturnedValue method_qsTrIdNoOp(CallContext *ctx);
+ static void method_qsTranslate(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_qsTranslateNoOp(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_qsTr(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_qsTrNoOp(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_qsTrId(const BuiltinFunction *, Scope &scope, CallData *callData);
+ static void method_qsTrIdNoOp(const BuiltinFunction *, Scope &scope, CallData *callData);
#endif
- static ReturnedValue method_gc(CallContext *ctx);
+ static void method_gc(const BuiltinFunction *, Scope &scope, CallData *callData);
// on String:prototype
- static ReturnedValue method_string_arg(CallContext *ctx);
+ static void method_string_arg(const BuiltinFunction *, Scope &scope, CallData *callData);
};
diff --git a/src/qml/qml/v8/qv4domerrors_p.h b/src/qml/qml/v8/qv4domerrors_p.h
index faa9dd8bc7..a9bdbe01ae 100644
--- a/src/qml/qml/v8/qv4domerrors_p.h
+++ b/src/qml/qml/v8/qv4domerrors_p.h
@@ -74,11 +74,12 @@ QT_BEGIN_NAMESPACE
#define DOMEXCEPTION_VALIDATION_ERR 16
#define DOMEXCEPTION_TYPE_MISMATCH_ERR 17
-#define V4THROW_DOM(error, string) { \
+#define THROW_DOM(error, string) { \
QV4::ScopedValue v(scope, scope.engine->newString(QStringLiteral(string))); \
QV4::ScopedObject ex(scope, scope.engine->newErrorObject(v)); \
ex->put(QV4::ScopedString(scope, scope.engine->newIdentifier(QStringLiteral("code"))), QV4::ScopedValue(scope, QV4::Primitive::fromInt32(error))); \
- return ctx->engine()->throwError(ex); \
+ scope.result = scope.engine->throwError(ex); \
+ return; \
}
namespace QV4 {
diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h
index 0cbe34fd30..3bd3517968 100644
--- a/src/qml/qml/v8/qv8engine_p.h
+++ b/src/qml/qml/v8/qv8engine_p.h
@@ -117,7 +117,7 @@ class QQmlV4Function
{
public:
int length() const { return callData->argc; }
- QV4::ReturnedValue operator[](int idx) { return (idx < callData->argc ? callData->args[idx].asReturnedValue() : QV4::Encode::undefined()); }
+ QV4::ReturnedValue operator[](int idx) const { return (idx < callData->argc ? callData->args[idx].asReturnedValue() : QV4::Encode::undefined()); }
void setReturnValue(QV4::ReturnedValue rv) { *retVal = rv; }
QV4::ExecutionEngine *v4engine() const { return e; }
private:
@@ -181,9 +181,9 @@ public:
QV4::ReturnedValue global();
QQmlDelayedCallQueue *delayedCallQueue() { return &m_delayedCallQueue; }
- void *xmlHttpRequestData() { return m_xmlHttpRequestData; }
+ void *xmlHttpRequestData() const { return m_xmlHttpRequestData; }
- Deletable *listModelData() { return m_listModelData; }
+ Deletable *listModelData() const { return m_listModelData; }
void setListModelData(Deletable *d) { if (m_listModelData) delete m_listModelData; m_listModelData = d; }
void freezeObject(const QV4::Value &value);
diff --git a/src/qml/qtqmlglobal_p.h b/src/qml/qtqmlglobal_p.h
index 63585fd62e..026be5a703 100644
--- a/src/qml/qtqmlglobal_p.h
+++ b/src/qml/qtqmlglobal_p.h
@@ -55,6 +55,46 @@
#include <QtQml/private/qtqml-config_p.h>
#include <QtQml/qtqmlglobal.h>
+// Define Q_ALLOCA_VAR macro to be used instead of #ifdeffing
+// the occurrences of alloca() in case it's not supported.
+// Q_ALLOCA_DECLARE and Q_ALLOCA_ASSIGN macros separate
+// memory allocation from the declaration and RAII.
+#define Q_ALLOCA_VAR(type, name, size) \
+ Q_ALLOCA_DECLARE(type, name); \
+ Q_ALLOCA_ASSIGN(type, name, size)
+
+#if QT_CONFIG(alloca)
+
+#define Q_ALLOCA_DECLARE(type, name) \
+ type *name = 0
+
+#define Q_ALLOCA_ASSIGN(type, name, size) \
+ name = static_cast<type*>(alloca(size))
+
+#else
+QT_BEGIN_NAMESPACE
+class Qt_AllocaWrapper
+{
+public:
+ Qt_AllocaWrapper() { m_data = 0; }
+ ~Qt_AllocaWrapper() { free(m_data); }
+ void *data() { return m_data; }
+ void allocate(int size) { m_data = malloc(size); }
+private:
+ void *m_data;
+};
+QT_END_NAMESPACE
+
+#define Q_ALLOCA_DECLARE(type, name) \
+ Qt_AllocaWrapper _qt_alloca_##name; \
+ type *name = 0
+
+#define Q_ALLOCA_ASSIGN(type, name, size) \
+ _qt_alloca_##name.allocate(size); \
+ name = static_cast<type*>(_qt_alloca_##name.data())
+
+#endif
+
#if defined(QT_BUILD_QMLDEVTOOLS_LIB) || defined(QT_QMLDEVTOOLS_LIB)
# define Q_QML_PRIVATE_EXPORT
#else
diff --git a/src/qml/types/qqmlbind.cpp b/src/qml/types/qqmlbind.cpp
index a545fe57ca..2ded9c13c8 100644
--- a/src/qml/types/qqmlbind.cpp
+++ b/src/qml/types/qqmlbind.cpp
@@ -82,12 +82,12 @@ void QQmlBindPrivate::validate(QObject *binding) const
return;
if (!prop.isValid()) {
- qmlInfo(binding) << "Property '" << propName << "' does not exist on " << QQmlMetaType::prettyTypeName(obj) << ".";
+ qmlWarning(binding) << "Property '" << propName << "' does not exist on " << QQmlMetaType::prettyTypeName(obj) << ".";
return;
}
if (!prop.isWritable()) {
- qmlInfo(binding) << "Property '" << propName << "' on " << QQmlMetaType::prettyTypeName(obj) << " is read-only.";
+ qmlWarning(binding) << "Property '" << propName << "' on " << QQmlMetaType::prettyTypeName(obj) << " is read-only.";
return;
}
}
diff --git a/src/qml/types/qqmlbind_p.h b/src/qml/types/qqmlbind_p.h
index 77939a40bc..c9dd14b58a 100644
--- a/src/qml/types/qqmlbind_p.h
+++ b/src/qml/types/qqmlbind_p.h
@@ -90,9 +90,9 @@ public:
void setDelayed(bool);
protected:
- virtual void setTarget(const QQmlProperty &);
- virtual void classBegin();
- virtual void componentComplete();
+ void setTarget(const QQmlProperty &) override;
+ void classBegin() override;
+ void componentComplete() override;
private:
void prepareEval();
diff --git a/src/qml/types/qqmlconnections.cpp b/src/qml/types/qqmlconnections.cpp
index 755345cc1b..870aeaa6e2 100644
--- a/src/qml/types/qqmlconnections.cpp
+++ b/src/qml/types/qqmlconnections.cpp
@@ -168,7 +168,7 @@ void QQmlConnections::setTarget(QObject *obj)
if (d->targetSet && d->target == obj)
return;
d->targetSet = true; // even if setting to 0, it is *set*
- foreach (QQmlBoundSignal *s, d->boundsignals) {
+ for (QQmlBoundSignal *s : qAsConst(d->boundsignals)) {
// It is possible that target is being changed due to one of our signal
// handlers -> use deleteLater().
if (s->isNotifying())
@@ -204,7 +204,7 @@ void QQmlConnections::setEnabled(bool enabled)
d->enabled = enabled;
- foreach (QQmlBoundSignal *s, d->boundsignals)
+ for (QQmlBoundSignal *s : qAsConst(d->boundsignals))
s->setEnabled(d->enabled);
emit enabledChanged();
@@ -278,7 +278,7 @@ void QQmlConnections::connectSignals()
QQmlContextData *ctxtdata = ddata ? ddata->outerContext : 0;
const QV4::CompiledData::Unit *qmlUnit = d->compilationUnit->data;
- foreach (const QV4::CompiledData::Binding *binding, d->bindings) {
+ for (const QV4::CompiledData::Binding *binding : qAsConst(d->bindings)) {
Q_ASSERT(binding->type == QV4::CompiledData::Binding::Type_Script);
QString propName = qmlUnit->stringAt(binding->propertyNameIndex);
@@ -295,7 +295,7 @@ void QQmlConnections::connectSignals()
d->boundsignals += signal;
} else {
if (!d->ignoreUnknownSignals)
- qmlInfo(this) << tr("Cannot assign to non-existent property \"%1\"").arg(propName);
+ qmlWarning(this) << tr("Cannot assign to non-existent property \"%1\"").arg(propName);
}
}
}
diff --git a/src/qml/types/qqmlconnections_p.h b/src/qml/types/qqmlconnections_p.h
index d454affba8..580b6522de 100644
--- a/src/qml/types/qqmlconnections_p.h
+++ b/src/qml/types/qqmlconnections_p.h
@@ -91,15 +91,15 @@ Q_SIGNALS:
private:
void connectSignals();
- void classBegin();
- void componentComplete();
+ void classBegin() override;
+ void componentComplete() override;
};
class QQmlConnectionsParser : public QQmlCustomParser
{
public:
- virtual void verifyBindings(const QV4::CompiledData::Unit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &props);
- virtual void applyBindings(QObject *object, QV4::CompiledData::CompilationUnit *compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings);
+ void verifyBindings(const QV4::CompiledData::Unit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &props) override;
+ void applyBindings(QObject *object, QV4::CompiledData::CompilationUnit *compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) override;
};
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index d9a8b1d179..a5878dcffd 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -264,7 +264,7 @@ QQmlDelegateModel::~QQmlDelegateModel()
{
Q_D(QQmlDelegateModel);
- foreach (QQmlDelegateModelItem *cacheItem, d->m_cache) {
+ for (QQmlDelegateModelItem *cacheItem : qAsConst(d->m_cache)) {
if (cacheItem->object) {
delete cacheItem->object;
@@ -310,7 +310,7 @@ void QQmlDelegateModel::componentComplete()
--d->m_groupCount;
--i;
} else if (name.at(0).isUpper()) {
- qmlInfo(d->m_groups[i]) << QQmlDelegateModelGroup::tr("Group names must start with a lower case letter");
+ qmlWarning(d->m_groups[i]) << QQmlDelegateModelGroup::tr("Group names must start with a lower case letter");
d->m_groups[i] = d->m_groups[d->m_groupCount - 1];
--d->m_groupCount;
--i;
@@ -404,7 +404,7 @@ void QQmlDelegateModel::setDelegate(QQmlComponent *delegate)
{
Q_D(QQmlDelegateModel);
if (d->m_transaction) {
- qmlInfo(this) << tr("The delegate of a DelegateModel cannot be changed within onUpdated.");
+ qmlWarning(this) << tr("The delegate of a DelegateModel cannot be changed within onUpdated.");
return;
}
bool wasValid = d->m_delegate != 0;
@@ -610,7 +610,7 @@ void QQmlDelegateModelPrivate::group_append(
if (d->m_complete)
return;
if (d->m_groupCount == Compositor::MaximumGroupCount) {
- qmlInfo(d->q_func()) << QQmlDelegateModel::tr("The maximum number of supported DelegateModelGroups is 8");
+ qmlWarning(d->q_func()) << QQmlDelegateModel::tr("The maximum number of supported DelegateModelGroups is 8");
return;
}
d->m_groups[d->m_groupCount] = group;
@@ -719,7 +719,7 @@ void QQmlDelegateModel::setFilterGroup(const QString &group)
Q_D(QQmlDelegateModel);
if (d->m_transaction) {
- qmlInfo(this) << tr("The group of a DelegateModel cannot be changed within onChanged");
+ qmlWarning(this) << tr("The group of a DelegateModel cannot be changed within onChanged");
return;
}
@@ -764,7 +764,8 @@ void QQmlDelegateModelPrivate::updateFilterGroup()
emit q->countChanged();
if (m_parts) {
- foreach (QQmlPartsModel *model, m_parts->models)
+ auto partsCopy = m_parts->models; // deliberate; this may alter m_parts
+ for (QQmlPartsModel *model : qAsConst(partsCopy))
model->updateFilterGroup(m_compositorGroup, changeSet);
}
}
@@ -889,7 +890,7 @@ void QQmlDelegateModelPrivate::incubatorStatusChanged(QQDMIncubationTask *incuba
emitCreatedItem(incubationTask, cacheItem->object);
cacheItem->releaseObject();
} else if (status == QQmlIncubator::Error) {
- qmlInfo(q, m_delegate->errors()) << "Error creating delegate";
+ qmlWarning(q, m_delegate->errors()) << "Error creating delegate";
}
if (!cacheItem->isObjectReferenced()) {
@@ -1133,7 +1134,7 @@ void QQmlDelegateModelPrivate::itemsChanged(const QVector<Compositor::Change> &c
QVarLengthArray<QVector<QQmlChangeSet::Change>, Compositor::MaximumGroupCount> translatedChanges(m_groupCount);
- foreach (const Compositor::Change &change, changes) {
+ for (const Compositor::Change &change : changes) {
for (int i = 1; i < m_groupCount; ++i) {
if (change.inGroup(i)) {
translatedChanges[i].append(QQmlChangeSet::Change(change.index[i], change.count));
@@ -1182,7 +1183,7 @@ void QQmlDelegateModelPrivate::itemsInserted(
for (int i = 1; i < m_groupCount; ++i)
inserted[i] = 0;
- foreach (const Compositor::Insert &insert, inserts) {
+ for (const Compositor::Insert &insert : inserts) {
for (; cacheIndex < insert.cacheIndex; ++cacheIndex)
incrementIndexes(m_cache.at(cacheIndex), m_groupCount, inserted);
@@ -1274,7 +1275,7 @@ void QQmlDelegateModelPrivate::itemsRemoved(
for (int i = 1; i < m_groupCount; ++i)
removed[i] = 0;
- foreach (const Compositor::Remove &remove, removes) {
+ for (const Compositor::Remove &remove : removes) {
for (; cacheIndex < remove.cacheIndex; ++cacheIndex)
incrementIndexes(m_cache.at(cacheIndex), m_groupCount, removed);
@@ -1472,7 +1473,8 @@ void QQmlDelegateModelPrivate::emitChanges()
for (int i = 1; i < m_groupCount; ++i)
QQmlDelegateModelGroupPrivate::get(m_groups[i])->emitModelUpdated(reset);
- foreach (QQmlDelegateModelItem *cacheItem, m_cache) {
+ auto cacheCopy = m_cache; // deliberate; emitChanges may alter m_cache
+ for (QQmlDelegateModelItem *cacheItem : qAsConst(cacheCopy)) {
if (cacheItem->attached)
cacheItem->attached->emitChanges();
}
@@ -1645,7 +1647,7 @@ bool QQmlDelegateModelPrivate::insert(Compositor::insert_iterator &before, const
cacheItem->groups = groups | Compositor::UnresolvedFlag | Compositor::CacheFlag;
// Must be before the new object is inserted into the cache or its indexes will be adjusted too.
- itemsInserted(QVector<Compositor::Insert>() << Compositor::Insert(before, 1, cacheItem->groups & ~Compositor::CacheFlag));
+ itemsInserted(QVector<Compositor::Insert>(1, Compositor::Insert(before, 1, cacheItem->groups & ~Compositor::CacheFlag)));
before = m_compositor.insert(before, 0, 0, 1, cacheItem->groups);
m_cache.insert(before.cacheIndex, cacheItem);
@@ -1756,7 +1758,7 @@ void QQmlDelegateModelItemMetaType::initializePrototype()
int QQmlDelegateModelItemMetaType::parseGroups(const QStringList &groups) const
{
int groupFlags = 0;
- foreach (const QString &groupName, groups) {
+ for (const QString &groupName : groups) {
int index = groupNames.indexOf(groupName);
if (index != -1)
groupFlags |= 2 << index;
@@ -1793,24 +1795,26 @@ int QQmlDelegateModelItemMetaType::parseGroups(const QV4::Value &groups) const
return groupFlags;
}
-QV4::ReturnedValue QQmlDelegateModelItem::get_model(QV4::CallContext *ctx)
+void QQmlDelegateModelItem::get_model(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQmlDelegateModelItemObject> o(scope, ctx->thisObject().as<QQmlDelegateModelItemObject>());
- if (!o)
- return ctx->engine()->throwTypeError(QStringLiteral("Not a valid VisualData object"));
+ QV4::Scoped<QQmlDelegateModelItemObject> o(scope, callData->thisObject.as<QQmlDelegateModelItemObject>());
+ if (!o) {
+ scope.result = scope.engine->throwTypeError(QStringLiteral("Not a valid VisualData object"));
+ return;
+ }
if (!o->d()->item->metaType->model)
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
- return o->d()->item->get();
+ scope.result = o->d()->item->get();
}
-QV4::ReturnedValue QQmlDelegateModelItem::get_groups(QV4::CallContext *ctx)
+void QQmlDelegateModelItem::get_groups(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQmlDelegateModelItemObject> o(scope, ctx->thisObject().as<QQmlDelegateModelItemObject>());
- if (!o)
- return ctx->engine()->throwTypeError(QStringLiteral("Not a valid VisualData object"));
+ QV4::Scoped<QQmlDelegateModelItemObject> o(scope, callData->thisObject.as<QQmlDelegateModelItemObject>());
+ if (!o) {
+ scope.result = scope.engine->throwTypeError(QStringLiteral("Not a valid VisualData object"));
+ return;
+ }
QStringList groups;
for (int i = 1; i < o->d()->item->metaType->groupCount; ++i) {
@@ -1818,27 +1822,29 @@ QV4::ReturnedValue QQmlDelegateModelItem::get_groups(QV4::CallContext *ctx)
groups.append(o->d()->item->metaType->groupNames.at(i - 1));
}
- return scope.engine->fromVariant(groups);
+ scope.result = scope.engine->fromVariant(groups);
}
-QV4::ReturnedValue QQmlDelegateModelItem::set_groups(QV4::CallContext *ctx)
+void QQmlDelegateModelItem::set_groups(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQmlDelegateModelItemObject> o(scope, ctx->thisObject().as<QQmlDelegateModelItemObject>());
- if (!o)
- return ctx->engine()->throwTypeError(QStringLiteral("Not a valid VisualData object"));
- if (!ctx->argc())
- return ctx->engine()->throwTypeError();
+ QV4::Scoped<QQmlDelegateModelItemObject> o(scope, callData->thisObject.as<QQmlDelegateModelItemObject>());
+ if (!o) {
+ scope.result = scope.engine->throwTypeError(QStringLiteral("Not a valid VisualData object"));
+ return;
+ }
+
+ if (!callData->argc)
+ THROW_TYPE_ERROR();
if (!o->d()->item->metaType->model)
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
QQmlDelegateModelPrivate *model = QQmlDelegateModelPrivate::get(o->d()->item->metaType->model);
- const int groupFlags = model->m_cacheMetaType->parseGroups(ctx->args()[0]);
+ const int groupFlags = model->m_cacheMetaType->parseGroups(callData->args[0]);
const int cacheIndex = model->m_cache.indexOf(o->d()->item);
Compositor::iterator it = model->m_compositor.find(Compositor::Cache, cacheIndex);
model->setGroups(it, 1, Compositor::Cache, groupFlags);
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
QV4::ReturnedValue QQmlDelegateModelItem::get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &)
@@ -2459,7 +2465,7 @@ QQmlV4Handle QQmlDelegateModelGroup::get(int index)
if (!model->m_context || !model->m_context->isValid()) {
return QQmlV4Handle(QV4::Encode::undefined());
} else if (index < 0 || index >= model->m_compositor.count(d->group)) {
- qmlInfo(this) << tr("get: index out of range");
+ qmlWarning(this) << tr("get: index out of range");
return QQmlV4Handle(QV4::Encode::undefined());
}
@@ -2552,7 +2558,7 @@ void QQmlDelegateModelGroup::insert(QQmlV4Function *args)
QV4::ScopedValue v(scope, (*args)[i]);
if (d->parseIndex(v, &index, &group)) {
if (index < 0 || index > model->m_compositor.count(group)) {
- qmlInfo(this) << tr("insert: index out of range");
+ qmlWarning(this) << tr("insert: index out of range");
return;
}
if (++i == args->length())
@@ -2637,7 +2643,7 @@ void QQmlDelegateModelGroup::create(QQmlV4Function *args)
}
}
if (index < 0 || index >= model->m_compositor.count(group)) {
- qmlInfo(this) << tr("create: index out of range");
+ qmlWarning(this) << tr("create: index out of range");
return;
}
@@ -2690,22 +2696,22 @@ void QQmlDelegateModelGroup::resolve(QQmlV4Function *args)
QV4::ScopedValue v(scope, (*args)[0]);
if (d->parseIndex(v, &from, &fromGroup)) {
if (from < 0 || from >= model->m_compositor.count(fromGroup)) {
- qmlInfo(this) << tr("resolve: from index out of range");
+ qmlWarning(this) << tr("resolve: from index out of range");
return;
}
} else {
- qmlInfo(this) << tr("resolve: from index invalid");
+ qmlWarning(this) << tr("resolve: from index invalid");
return;
}
v = (*args)[1];
if (d->parseIndex(v, &to, &toGroup)) {
if (to < 0 || to >= model->m_compositor.count(toGroup)) {
- qmlInfo(this) << tr("resolve: to index out of range");
+ qmlWarning(this) << tr("resolve: to index out of range");
return;
}
} else {
- qmlInfo(this) << tr("resolve: to index invalid");
+ qmlWarning(this) << tr("resolve: to index invalid");
return;
}
@@ -2713,11 +2719,11 @@ void QQmlDelegateModelGroup::resolve(QQmlV4Function *args)
Compositor::iterator toIt = model->m_compositor.find(toGroup, to);
if (!fromIt->isUnresolved()) {
- qmlInfo(this) << tr("resolve: from is not an unresolved item");
+ qmlWarning(this) << tr("resolve: from is not an unresolved item");
return;
}
if (!toIt->list) {
- qmlInfo(this) << tr("resolve: to is not a model item");
+ qmlWarning(this) << tr("resolve: to is not a model item");
return;
}
@@ -2735,12 +2741,12 @@ void QQmlDelegateModelGroup::resolve(QQmlV4Function *args)
from += 1;
model->itemsMoved(
- QVector<Compositor::Remove>() << Compositor::Remove(fromIt, 1, unresolvedFlags, 0),
- QVector<Compositor::Insert>() << Compositor::Insert(toIt, 1, unresolvedFlags, 0));
+ QVector<Compositor::Remove>(1, Compositor::Remove(fromIt, 1, unresolvedFlags, 0)),
+ QVector<Compositor::Insert>(1, Compositor::Insert(toIt, 1, unresolvedFlags, 0)));
model->itemsInserted(
- QVector<Compositor::Insert>() << Compositor::Insert(toIt, 1, (resolvedFlags & ~unresolvedFlags) | Compositor::CacheFlag));
+ QVector<Compositor::Insert>(1, Compositor::Insert(toIt, 1, (resolvedFlags & ~unresolvedFlags) | Compositor::CacheFlag)));
toIt.incrementIndexes(1, resolvedFlags | unresolvedFlags);
- model->itemsRemoved(QVector<Compositor::Remove>() << Compositor::Remove(toIt, 1, resolvedFlags));
+ model->itemsRemoved(QVector<Compositor::Remove>(1, Compositor::Remove(toIt, 1, resolvedFlags)));
model->m_compositor.setFlags(toGroup, to, 1, unresolvedFlags & ~Compositor::UnresolvedFlag);
model->m_compositor.clearFlags(fromGroup, from, 1, unresolvedFlags);
@@ -2787,7 +2793,7 @@ void QQmlDelegateModelGroup::remove(QQmlV4Function *args)
QV4::Scope scope(args->v4engine());
QV4::ScopedValue v(scope, (*args)[0]);
if (!d->parseIndex(v, &index, &group)) {
- qmlInfo(this) << tr("remove: invalid index");
+ qmlWarning(this) << tr("remove: invalid index");
return;
}
@@ -2799,11 +2805,11 @@ void QQmlDelegateModelGroup::remove(QQmlV4Function *args)
QQmlDelegateModelPrivate *model = QQmlDelegateModelPrivate::get(d->model);
if (index < 0 || index >= model->m_compositor.count(group)) {
- qmlInfo(this) << tr("remove: index out of range");
+ qmlWarning(this) << tr("remove: index out of range");
} else if (count != 0) {
Compositor::iterator it = model->m_compositor.find(group, index);
if (count < 0 || count > model->m_compositor.count(d->group) - it.index[d->group]) {
- qmlInfo(this) << tr("remove: invalid count");
+ qmlWarning(this) << tr("remove: invalid count");
} else {
model->removeGroups(it, count, d->group, 1 << d->group);
}
@@ -2858,11 +2864,11 @@ void QQmlDelegateModelGroup::addGroups(QQmlV4Function *args)
QQmlDelegateModelPrivate *model = QQmlDelegateModelPrivate::get(d->model);
if (index < 0 || index >= model->m_compositor.count(group)) {
- qmlInfo(this) << tr("addGroups: index out of range");
+ qmlWarning(this) << tr("addGroups: index out of range");
} else if (count != 0) {
Compositor::iterator it = model->m_compositor.find(group, index);
if (count < 0 || count > model->m_compositor.count(d->group) - it.index[d->group]) {
- qmlInfo(this) << tr("addGroups: invalid count");
+ qmlWarning(this) << tr("addGroups: invalid count");
} else {
model->addGroups(it, count, d->group, groups);
}
@@ -2888,11 +2894,11 @@ void QQmlDelegateModelGroup::removeGroups(QQmlV4Function *args)
QQmlDelegateModelPrivate *model = QQmlDelegateModelPrivate::get(d->model);
if (index < 0 || index >= model->m_compositor.count(group)) {
- qmlInfo(this) << tr("removeGroups: index out of range");
+ qmlWarning(this) << tr("removeGroups: index out of range");
} else if (count != 0) {
Compositor::iterator it = model->m_compositor.find(group, index);
if (count < 0 || count > model->m_compositor.count(d->group) - it.index[d->group]) {
- qmlInfo(this) << tr("removeGroups: invalid count");
+ qmlWarning(this) << tr("removeGroups: invalid count");
} else {
model->removeGroups(it, count, d->group, groups);
}
@@ -2918,11 +2924,11 @@ void QQmlDelegateModelGroup::setGroups(QQmlV4Function *args)
QQmlDelegateModelPrivate *model = QQmlDelegateModelPrivate::get(d->model);
if (index < 0 || index >= model->m_compositor.count(group)) {
- qmlInfo(this) << tr("setGroups: index out of range");
+ qmlWarning(this) << tr("setGroups: index out of range");
} else if (count != 0) {
Compositor::iterator it = model->m_compositor.find(group, index);
if (count < 0 || count > model->m_compositor.count(d->group) - it.index[d->group]) {
- qmlInfo(this) << tr("setGroups: invalid count");
+ qmlWarning(this) << tr("setGroups: invalid count");
} else {
model->setGroups(it, count, d->group, groups);
}
@@ -2957,13 +2963,13 @@ void QQmlDelegateModelGroup::move(QQmlV4Function *args)
QV4::Scope scope(args->v4engine());
QV4::ScopedValue v(scope, (*args)[0]);
if (!d->parseIndex(v, &from, &fromGroup)) {
- qmlInfo(this) << tr("move: invalid from index");
+ qmlWarning(this) << tr("move: invalid from index");
return;
}
v = (*args)[1];
if (!d->parseIndex(v, &to, &toGroup)) {
- qmlInfo(this) << tr("move: invalid to index");
+ qmlWarning(this) << tr("move: invalid to index");
return;
}
@@ -2976,11 +2982,11 @@ void QQmlDelegateModelGroup::move(QQmlV4Function *args)
QQmlDelegateModelPrivate *model = QQmlDelegateModelPrivate::get(d->model);
if (count < 0) {
- qmlInfo(this) << tr("move: invalid count");
+ qmlWarning(this) << tr("move: invalid count");
} else if (from < 0 || from + count > model->m_compositor.count(fromGroup)) {
- qmlInfo(this) << tr("move: from index out of range");
+ qmlWarning(this) << tr("move: from index out of range");
} else if (!model->m_compositor.verifyMoveTo(fromGroup, from, toGroup, to, count, d->group)) {
- qmlInfo(this) << tr("move: to index out of range");
+ qmlWarning(this) << tr("move: to index out of range");
} else if (count > 0) {
QVector<Compositor::Remove> removes;
QVector<Compositor::Insert> inserts;
@@ -3038,7 +3044,7 @@ QString QQmlPartsModel::filterGroup() const
void QQmlPartsModel::setFilterGroup(const QString &group)
{
if (QQmlDelegateModelPrivate::get(m_model)->m_transaction) {
- qmlInfo(this) << tr("The group of a DelegateModel cannot be changed within onChanged");
+ qmlWarning(this) << tr("The group of a DelegateModel cannot be changed within onChanged");
return;
}
@@ -3151,7 +3157,7 @@ QObject *QQmlPartsModel::object(int index, bool asynchronous)
model->release(object);
if (!model->m_delegateValidated) {
if (object)
- qmlInfo(model->m_delegate) << tr("Delegate component must be Package type.");
+ qmlWarning(model->m_delegate) << tr("Delegate component must be Package type.");
model->m_delegateValidated = true;
}
@@ -3232,28 +3238,25 @@ struct QQmlDelegateModelGroupChange : QV4::Object
return e->memoryManager->allocObject<QQmlDelegateModelGroupChange>();
}
- static QV4::ReturnedValue method_get_index(QV4::CallContext *ctx) {
- QV4::Scope scope(ctx);
- QV4::Scoped<QQmlDelegateModelGroupChange> that(scope, ctx->thisObject().as<QQmlDelegateModelGroupChange>());
+ static void method_get_index(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData) {
+ QV4::Scoped<QQmlDelegateModelGroupChange> that(scope, callData->thisObject.as<QQmlDelegateModelGroupChange>());
if (!that)
- return ctx->engine()->throwTypeError();
- return QV4::Encode(that->d()->change.index);
+ THROW_TYPE_ERROR();
+ scope.result = QV4::Encode(that->d()->change.index);
}
- static QV4::ReturnedValue method_get_count(QV4::CallContext *ctx) {
- QV4::Scope scope(ctx);
- QV4::Scoped<QQmlDelegateModelGroupChange> that(scope, ctx->thisObject().as<QQmlDelegateModelGroupChange>());
+ static void method_get_count(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData) {
+ QV4::Scoped<QQmlDelegateModelGroupChange> that(scope, callData->thisObject.as<QQmlDelegateModelGroupChange>());
if (!that)
- return ctx->engine()->throwTypeError();
- return QV4::Encode(that->d()->change.count);
+ THROW_TYPE_ERROR();
+ scope.result = QV4::Encode(that->d()->change.count);
}
- static QV4::ReturnedValue method_get_moveId(QV4::CallContext *ctx) {
- QV4::Scope scope(ctx);
- QV4::Scoped<QQmlDelegateModelGroupChange> that(scope, ctx->thisObject().as<QQmlDelegateModelGroupChange>());
+ static void method_get_moveId(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData) {
+ QV4::Scoped<QQmlDelegateModelGroupChange> that(scope, callData->thisObject.as<QQmlDelegateModelGroupChange>());
if (!that)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
if (that->d()->change.moveId < 0)
- return QV4::Encode::undefined();
- return QV4::Encode(that->d()->change.moveId);
+ RETURN_UNDEFINED();
+ scope.result = QV4::Encode(that->d()->change.moveId);
}
};
diff --git a/src/qml/types/qqmldelegatemodel_p.h b/src/qml/types/qqmldelegatemodel_p.h
index 2986ec7ce5..186144d107 100644
--- a/src/qml/types/qqmldelegatemodel_p.h
+++ b/src/qml/types/qqmldelegatemodel_p.h
@@ -90,10 +90,10 @@ class Q_QML_PRIVATE_EXPORT QQmlDelegateModel : public QQmlInstanceModel, public
public:
QQmlDelegateModel();
QQmlDelegateModel(QQmlContext *, QObject *parent=0);
- virtual ~QQmlDelegateModel();
+ ~QQmlDelegateModel();
- void classBegin();
- void componentComplete();
+ void classBegin() override;
+ void componentComplete() override;
QVariant model() const;
void setModel(const QVariant &);
@@ -107,15 +107,15 @@ public:
Q_INVOKABLE QVariant modelIndex(int idx) const;
Q_INVOKABLE QVariant parentModelIndex() const;
- int count() const;
- bool isValid() const { return delegate() != 0; }
- QObject *object(int index, bool asynchronous=false);
- ReleaseFlags release(QObject *object);
- void cancel(int index);
- virtual QString stringValue(int index, const QString &role);
- virtual void setWatchedRoles(const QList<QByteArray> &roles);
+ int count() const override;
+ bool isValid() const override { return delegate() != 0; }
+ QObject *object(int index, bool asynchronous = false) override;
+ ReleaseFlags release(QObject *object) override;
+ void cancel(int index) override;
+ QString stringValue(int index, const QString &role) override;
+ void setWatchedRoles(const QList<QByteArray> &roles) override;
- int indexOf(QObject *object, QObject *objectContext) const;
+ int indexOf(QObject *object, QObject *objectContext) const override;
QString filterGroup() const;
void setFilterGroup(const QString &group);
@@ -126,7 +126,7 @@ public:
QQmlListProperty<QQmlDelegateModelGroup> groups();
QObject *parts();
- bool event(QEvent *);
+ bool event(QEvent *) override;
static QQmlDelegateModelAttached *qmlAttachedProperties(QObject *obj);
diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h
index 7d97358b3d..cb4a1f79ba 100644
--- a/src/qml/types/qqmldelegatemodel_p_p.h
+++ b/src/qml/types/qqmldelegatemodel_p_p.h
@@ -131,9 +131,9 @@ public:
virtual void setValue(const QString &role, const QVariant &value) { Q_UNUSED(role); Q_UNUSED(value); }
virtual bool resolveIndex(const QQmlAdaptorModel &, int) { return false; }
- static QV4::ReturnedValue get_model(QV4::CallContext *ctx);
- static QV4::ReturnedValue get_groups(QV4::CallContext *ctx);
- static QV4::ReturnedValue set_groups(QV4::CallContext *ctx);
+ static void get_model(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void get_groups(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void set_groups(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
static QV4::ReturnedValue get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &);
static QV4::ReturnedValue set_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &arg);
static QV4::ReturnedValue get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &arg);
@@ -190,8 +190,8 @@ public:
, incubating(0)
, vdm(l) {}
- virtual void statusChanged(Status);
- virtual void setInitialState(QObject *);
+ void statusChanged(Status) override;
+ void setInitialState(QObject *) override;
QQmlDelegateModelItem *incubating;
QQmlDelegateModelPrivate *vdm;
@@ -294,7 +294,7 @@ public:
const QVector<Compositor::Remove> &removes, const QVector<Compositor::Insert> &inserts);
void itemsChanged(const QVector<Compositor::Change> &changes);
void emitChanges();
- void emitModelUpdated(const QQmlChangeSet &changeSet, bool reset);
+ void emitModelUpdated(const QQmlChangeSet &changeSet, bool reset) override;
bool insert(Compositor::insert_iterator &before, const QV4::Value &object, int groups);
@@ -355,21 +355,21 @@ public:
void updateFilterGroup();
void updateFilterGroup(Compositor::Group group, const QQmlChangeSet &changeSet);
- int count() const;
- bool isValid() const;
- QObject *object(int index, bool asynchronous=false);
- ReleaseFlags release(QObject *item);
- QString stringValue(int index, const QString &role);
+ int count() const override;
+ bool isValid() const override;
+ QObject *object(int index, bool asynchronous = false) override;
+ ReleaseFlags release(QObject *item) override;
+ QString stringValue(int index, const QString &role) override;
QList<QByteArray> watchedRoles() const { return m_watchedRoles; }
- void setWatchedRoles(const QList<QByteArray> &roles);
+ void setWatchedRoles(const QList<QByteArray> &roles) override;
- int indexOf(QObject *item, QObject *objectContext) const;
+ int indexOf(QObject *item, QObject *objectContext) const override;
- void emitModelUpdated(const QQmlChangeSet &changeSet, bool reset);
+ void emitModelUpdated(const QQmlChangeSet &changeSet, bool reset) override;
- void createdPackage(int index, QQuickPackage *package);
- void initPackage(int index, QQuickPackage *package);
- void destroyingPackage(QQuickPackage *package);
+ void createdPackage(int index, QQuickPackage *package) override;
+ void initPackage(int index, QQuickPackage *package) override;
+ void destroyingPackage(QQuickPackage *package) override;
Q_SIGNALS:
void filterGroupChanged();
@@ -392,8 +392,8 @@ public:
QQmlDelegateModelPartsMetaObject(QObject *parent)
: QQmlOpenMetaObject(parent) {}
- virtual void propertyCreated(int, QMetaPropertyBuilder &);
- virtual QVariant initialValue(int);
+ void propertyCreated(int, QMetaPropertyBuilder &) override;
+ QVariant initialValue(int) override;
};
class QQmlDelegateModelParts : public QObject
@@ -413,8 +413,8 @@ public:
QQmlDelegateModelItemMetaType *metaType, QMetaObject *metaObject);
~QQmlDelegateModelAttachedMetaObject();
- void objectDestroyed(QObject *);
- int metaCall(QObject *, QMetaObject::Call, int _id, void **);
+ void objectDestroyed(QObject *) override;
+ int metaCall(QObject *, QMetaObject::Call, int _id, void **) override;
private:
QQmlDelegateModelItemMetaType * const metaType;
diff --git a/src/qml/types/qqmlinstantiator.cpp b/src/qml/types/qqmlinstantiator.cpp
index 0cec39790d..2de5875deb 100644
--- a/src/qml/types/qqmlinstantiator.cpp
+++ b/src/qml/types/qqmlinstantiator.cpp
@@ -155,7 +155,8 @@ void QQmlInstantiatorPrivate::_q_modelUpdated(const QQmlChangeSet &changeSet, bo
int difference = 0;
QHash<int, QVector<QPointer<QObject> > > moved;
- foreach (const QQmlChangeSet::Change &remove, changeSet.removes()) {
+ const QVector<QQmlChangeSet::Change> &removes = changeSet.removes();
+ for (const QQmlChangeSet::Change &remove : removes) {
int index = qMin(remove.index, objects.count());
int count = qMin(remove.index + remove.count, objects.count()) - index;
if (remove.isMove()) {
@@ -174,7 +175,8 @@ void QQmlInstantiatorPrivate::_q_modelUpdated(const QQmlChangeSet &changeSet, bo
difference -= remove.count;
}
- foreach (const QQmlChangeSet::Change &insert, changeSet.inserts()) {
+ const QVector<QQmlChangeSet::Change> &inserts = changeSet.inserts();
+ for (const QQmlChangeSet::Change &insert : inserts) {
int index = qMin(insert.index, objects.count());
if (insert.isMove()) {
QVector<QPointer<QObject> > movedObjects = moved.value(insert.moveId);
diff --git a/src/qml/types/qqmlinstantiator_p.h b/src/qml/types/qqmlinstantiator_p.h
index dff69ee6b3..ee18daa48c 100644
--- a/src/qml/types/qqmlinstantiator_p.h
+++ b/src/qml/types/qqmlinstantiator_p.h
@@ -72,7 +72,7 @@ class Q_AUTOTEST_EXPORT QQmlInstantiator : public QObject, public QQmlParserStat
public:
QQmlInstantiator(QObject *parent = 0);
- virtual ~QQmlInstantiator();
+ ~QQmlInstantiator();
bool isActive() const;
void setActive(bool newVal);
@@ -92,8 +92,8 @@ public:
Q_INVOKABLE QObject *objectAt(int index) const;
- void classBegin();
- void componentComplete();
+ void classBegin() override;
+ void componentComplete() override;
Q_SIGNALS:
void modelChanged();
diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp
index 8574a4784c..5e2ff9b15b 100644
--- a/src/qml/types/qqmllistmodel.cpp
+++ b/src/qml/types/qqmllistmodel.cpp
@@ -99,7 +99,7 @@ const ListLayout::Role &ListLayout::getRoleOrCreate(const QString &key, Role::Da
if (node) {
const Role &r = *node->value;
if (type != r.type)
- qmlInfo(0) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(r.name).arg(roleTypeName(type)).arg(roleTypeName(r.type));
+ qmlWarning(0) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(r.name).arg(roleTypeName(type)).arg(roleTypeName(r.type));
return r;
}
@@ -112,7 +112,7 @@ const ListLayout::Role &ListLayout::getRoleOrCreate(QV4::String *key, Role::Data
if (node) {
const Role &r = *node->value;
if (type != r.type)
- qmlInfo(0) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(r.name).arg(roleTypeName(type)).arg(roleTypeName(r.type));
+ qmlWarning(0) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(r.name).arg(roleTypeName(type)).arg(roleTypeName(r.type));
return r;
}
@@ -226,14 +226,14 @@ const ListLayout::Role *ListLayout::getRoleOrCreate(const QString &key, const QV
}
if (type == Role::Invalid) {
- qmlInfo(0) << "Can't create role for unsupported data type";
+ qmlWarning(0) << "Can't create role for unsupported data type";
return 0;
}
return &getRoleOrCreate(key, type);
}
-const ListLayout::Role *ListLayout::getExistingRole(const QString &key)
+const ListLayout::Role *ListLayout::getExistingRole(const QString &key) const
{
Role *r = 0;
QStringHash<Role *>::Node *node = roleHash.findNode(key);
@@ -242,7 +242,7 @@ const ListLayout::Role *ListLayout::getExistingRole(const QString &key)
return r;
}
-const ListLayout::Role *ListLayout::getExistingRole(QV4::String *key)
+const ListLayout::Role *ListLayout::getExistingRole(QV4::String *key) const
{
Role *r = 0;
QStringHash<Role *>::Node *node = roleHash.findNode(key);
@@ -603,11 +603,8 @@ int ListModel::setOrCreateProperty(int elementIndex, const QString &key, const Q
ModelNodeMetaObject *cache = e->objectCache();
- if (roleIndex != -1 && cache) {
- QVector<int> roles;
- roles << roleIndex;
- cache->updateValues(roles);
- }
+ if (roleIndex != -1 && cache)
+ cache->updateValues(QVector<int>(1, roleIndex));
}
}
@@ -1204,7 +1201,7 @@ int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::Value &d
}
roleIndex = setListProperty(role, subModel);
} else {
- qmlInfo(0) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(role.name).arg(roleTypeName(role.type)).arg(roleTypeName(ListLayout::Role::List));
+ qmlWarning(0) << QStringLiteral("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(role.name).arg(roleTypeName(role.type)).arg(roleTypeName(ListLayout::Role::List));
}
} else if (d.isBoolean()) {
roleIndex = setBoolProperty(role, d.booleanValue());
@@ -1270,10 +1267,12 @@ void ModelNodeMetaObject::updateValues()
{
const int roleCount = m_model->m_listModel->roleCount();
if (!m_initialized) {
- int *changedRoles = reinterpret_cast<int *>(alloca(roleCount * sizeof(int)));
- for (int i = 0; i < roleCount; ++i)
- changedRoles[i] = i;
- emitDirectNotifies(changedRoles, roleCount);
+ if (roleCount) {
+ Q_ALLOCA_VAR(int, changedRoles, roleCount * sizeof(int));
+ for (int i = 0; i < roleCount; ++i)
+ changedRoles[i] = i;
+ emitDirectNotifies(changedRoles, roleCount);
+ }
return;
}
for (int i=0 ; i < roleCount ; ++i) {
@@ -1312,11 +1311,8 @@ void ModelNodeMetaObject::propertyWritten(int index)
QV4::ScopedValue v(scope, scope.engine->fromVariant(value));
int roleIndex = m_model->m_listModel->setExistingProperty(m_elementIndex, propName, v, scope.engine);
- if (roleIndex != -1) {
- QVector<int> roles;
- roles << roleIndex;
- m_model->emitItemsChanged(m_elementIndex, 1, roles);
- }
+ if (roleIndex != -1)
+ m_model->emitItemsChanged(m_elementIndex, 1, QVector<int>(1, roleIndex));
}
// Does the emission of the notifiers when we haven't created the meta-object yet
@@ -1345,11 +1341,8 @@ void ModelObject::put(Managed *m, String *name, const Value &value)
const int elementIndex = that->d()->m_elementIndex;
const QString propName = name->toQString();
int roleIndex = that->d()->m_model->m_listModel->setExistingProperty(elementIndex, propName, value, eng);
- if (roleIndex != -1) {
- QVector<int> roles;
- roles << roleIndex;
- that->d()->m_model->emitItemsChanged(elementIndex, 1, roles);
- }
+ if (roleIndex != -1)
+ that->d()->m_model->emitItemsChanged(elementIndex, 1, QVector<int>(1, roleIndex));
ModelNodeMetaObject *mo = ModelNodeMetaObject::get(that->object());
if (mo->initialized())
@@ -1543,14 +1536,10 @@ void DynamicRoleModelNodeMetaObject::propertyWritten(int index)
}
int elementIndex = parentModel->m_modelObjects.indexOf(m_owner);
- int roleIndex = parentModel->m_roles.indexOf(QString::fromLatin1(name(index).constData()));
-
- if (elementIndex != -1 && roleIndex != -1) {
-
- QVector<int> roles;
- roles << roleIndex;
-
- parentModel->emitItemsChanged(elementIndex, 1, roles);
+ if (elementIndex != -1) {
+ int roleIndex = parentModel->m_roles.indexOf(QString::fromLatin1(name(index).constData()));
+ if (roleIndex != -1)
+ parentModel->emitItemsChanged(elementIndex, 1, QVector<int>(1, roleIndex));
}
}
@@ -1919,14 +1908,14 @@ bool QQmlListModel::setData(const QModelIndex &index, const QVariant &value, int
if (m_dynamicRoles) {
const QByteArray property = m_roles.at(role).toUtf8();
if (m_modelObjects[row]->setValue(property, value)) {
- emitItemsChanged(row, 1, QVector<int>() << role);
+ emitItemsChanged(row, 1, QVector<int>(1, role));
return true;
}
} else {
const ListLayout::Role &r = m_listModel->getExistingRole(role);
const int roleIndex = m_listModel->setOrCreateProperty(row, r.name, value);
if (roleIndex != -1) {
- emitItemsChanged(row, 1, QVector<int>() << role);
+ emitItemsChanged(row, 1, QVector<int>(1, role));
return true;
}
}
@@ -1997,18 +1986,18 @@ void QQmlListModel::setDynamicRoles(bool enableDynamicRoles)
if (m_mainThread && m_agent == 0) {
if (enableDynamicRoles) {
if (m_layout->roleCount())
- qmlInfo(this) << tr("unable to enable dynamic roles as this model is not empty!");
+ qmlWarning(this) << tr("unable to enable dynamic roles as this model is not empty!");
else
m_dynamicRoles = true;
} else {
if (m_roles.count()) {
- qmlInfo(this) << tr("unable to enable static roles as this model is not empty!");
+ qmlWarning(this) << tr("unable to enable static roles as this model is not empty!");
} else {
m_dynamicRoles = false;
}
}
} else {
- qmlInfo(this) << tr("dynamic role setting must be made from the main thread, before any worker scripts are created");
+ qmlWarning(this) << tr("dynamic role setting must be made from the main thread, before any worker scripts are created");
}
}
@@ -2061,7 +2050,7 @@ void QQmlListModel::remove(QQmlV4Function *args)
int removeCount = (argLength == 2 ? QV4::ScopedValue(scope, (*args)[1])->toInt32() : 1);
if (index < 0 || index+removeCount > count() || removeCount <= 0) {
- qmlInfo(this) << tr("remove: indices [%1 - %2] out of range [0 - %3]").arg(index).arg(index+removeCount).arg(count());
+ qmlWarning(this) << tr("remove: indices [%1 - %2] out of range [0 - %3]").arg(index).arg(index+removeCount).arg(count());
return;
}
@@ -2077,7 +2066,7 @@ void QQmlListModel::remove(QQmlV4Function *args)
emitItemsRemoved(index, removeCount);
} else {
- qmlInfo(this) << tr("remove: incorrect number of arguments");
+ qmlWarning(this) << tr("remove: incorrect number of arguments");
}
}
@@ -2105,7 +2094,7 @@ void QQmlListModel::insert(QQmlV4Function *args)
int index = arg0->toInt32();
if (index < 0 || index > count()) {
- qmlInfo(this) << tr("insert: index %1 out of range").arg(index);
+ qmlWarning(this) << tr("insert: index %1 out of range").arg(index);
return;
}
@@ -2137,10 +2126,10 @@ void QQmlListModel::insert(QQmlV4Function *args)
emitItemsInserted(index, 1);
} else {
- qmlInfo(this) << tr("insert: value is not an object");
+ qmlWarning(this) << tr("insert: value is not an object");
}
} else {
- qmlInfo(this) << tr("insert: value is not an object");
+ qmlWarning(this) << tr("insert: value is not an object");
}
}
@@ -2163,7 +2152,7 @@ void QQmlListModel::move(int from, int to, int n)
if (n==0 || from==to)
return;
if (!canMove(from, to, n)) {
- qmlInfo(this) << tr("move: out of range");
+ qmlWarning(this) << tr("move: out of range");
return;
}
@@ -2252,10 +2241,10 @@ void QQmlListModel::append(QQmlV4Function *args)
emitItemsInserted(index, 1);
} else {
- qmlInfo(this) << tr("append: value is not an object");
+ qmlWarning(this) << tr("append: value is not an object");
}
} else {
- qmlInfo(this) << tr("append: value is not an object");
+ qmlWarning(this) << tr("append: value is not an object");
}
}
@@ -2334,11 +2323,11 @@ void QQmlListModel::set(int index, const QQmlV4Handle &handle)
QV4::ScopedObject object(scope, handle);
if (!object) {
- qmlInfo(this) << tr("set: value is not an object");
+ qmlWarning(this) << tr("set: value is not an object");
return;
}
if (index > count() || index < 0) {
- qmlInfo(this) << tr("set: index %1 out of range").arg(index);
+ qmlWarning(this) << tr("set: index %1 out of range").arg(index);
return;
}
@@ -2384,7 +2373,7 @@ void QQmlListModel::set(int index, const QQmlV4Handle &handle)
void QQmlListModel::setProperty(int index, const QString& property, const QVariant& value)
{
if (count() == 0 || index >= count() || index < 0) {
- qmlInfo(this) << tr("set: index %1 out of range").arg(index);
+ qmlWarning(this) << tr("set: index %1 out of range").arg(index);
return;
}
@@ -2394,20 +2383,12 @@ void QQmlListModel::setProperty(int index, const QString& property, const QVaria
roleIndex = m_roles.count();
m_roles.append(property);
}
- if (m_modelObjects[index]->setValue(property.toUtf8(), value)) {
- QVector<int> roles;
- roles << roleIndex;
- emitItemsChanged(index, 1, roles);
- }
+ if (m_modelObjects[index]->setValue(property.toUtf8(), value))
+ emitItemsChanged(index, 1, QVector<int>(1, roleIndex));
} else {
int roleIndex = m_listModel->setOrCreateProperty(index, property, value);
- if (roleIndex != -1) {
-
- QVector<int> roles;
- roles << roleIndex;
-
- emitItemsChanged(index, 1, roles);
- }
+ if (roleIndex != -1)
+ emitItemsChanged(index, 1, QVector<int>(1, roleIndex));
}
}
@@ -2422,7 +2403,7 @@ void QQmlListModel::sync()
// This is just a dummy method to make it look like sync() exists in
// ListModel (and not just QQmlListModelWorkerAgent) and to let
// us document sync().
- qmlInfo(this) << "List sync() can only be called from a WorkerScript";
+ qmlWarning(this) << "List sync() can only be called from a WorkerScript";
}
bool QQmlListModelParser::verifyProperty(const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding)
@@ -2536,7 +2517,7 @@ void QQmlListModelParser::verifyBindings(const QV4::CompiledData::Unit *qmlUnit,
{
listElementTypeName = QString(); // unknown
- foreach (const QV4::CompiledData::Binding *binding, bindings) {
+ for (const QV4::CompiledData::Binding *binding : bindings) {
QString propName = qmlUnit->stringAt(binding->propertyNameIndex);
if (!propName.isEmpty()) { // isn't default property
error(binding, QQmlListModel::tr("ListModel: undefined property '%1'").arg(propName));
@@ -2557,14 +2538,14 @@ void QQmlListModelParser::applyBindings(QObject *obj, QV4::CompiledData::Compila
bool setRoles = false;
- foreach (const QV4::CompiledData::Binding *binding, bindings) {
+ for (const QV4::CompiledData::Binding *binding : bindings) {
if (binding->type != QV4::CompiledData::Binding::Type_Object)
continue;
setRoles |= applyProperty(qmlUnit, binding, rv->m_listModel, /*outter element index*/-1);
}
if (setRoles == false)
- qmlInfo(obj) << "All ListElement declarations are empty, no roles can be created unless dynamicRoles is set.";
+ qmlWarning(obj) << "All ListElement declarations are empty, no roles can be created unless dynamicRoles is set.";
}
bool QQmlListModelParser::definesEmptyList(const QString &s)
diff --git a/src/qml/types/qqmllistmodel_p.h b/src/qml/types/qqmllistmodel_p.h
index 220b0e54b5..b750d30676 100644
--- a/src/qml/types/qqmllistmodel_p.h
+++ b/src/qml/types/qqmllistmodel_p.h
@@ -85,11 +85,11 @@ public:
QQmlListModel(QObject *parent=0);
~QQmlListModel();
- QModelIndex index(int row, int column, const QModelIndex &parent) const;
- int rowCount(const QModelIndex &parent) const;
- QVariant data(const QModelIndex &index, int role) const;
- bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
- QHash<int,QByteArray> roleNames() const;
+ QModelIndex index(int row, int column, const QModelIndex &parent) const override;
+ int rowCount(const QModelIndex &parent) const override;
+ QVariant data(const QModelIndex &index, int role) const override;
+ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
+ QHash<int,QByteArray> roleNames() const override;
QVariant data(int index, int role) const;
int count() const;
@@ -195,7 +195,7 @@ private:
// returns true if a role was set
bool applyProperty(const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding, ListModel *model, int outterElementIndex);
- bool definesEmptyList(const QString &);
+ static bool definesEmptyList(const QString &);
QString listElementTypeName;
};
diff --git a/src/qml/types/qqmllistmodel_p_p.h b/src/qml/types/qqmllistmodel_p_p.h
index 5ff8b9671f..cdce78e542 100644
--- a/src/qml/types/qqmllistmodel_p_p.h
+++ b/src/qml/types/qqmllistmodel_p_p.h
@@ -71,8 +71,8 @@ public:
bool m_enabled;
protected:
- void propertyWrite(int index);
- void propertyWritten(int index);
+ void propertyWrite(int index) override;
+ void propertyWritten(int index) override;
private:
DynamicRoleModelNode *m_owner;
@@ -88,7 +88,7 @@ public:
void updateValues(const QVariantMap &object, QVector<int> &roles);
- QVariant getValue(const QString &name)
+ QVariant getValue(const QString &name) const
{
return m_meta->value(name.toUtf8());
}
@@ -124,7 +124,7 @@ public:
ModelNodeMetaObject(QObject *object, QQmlListModel *model, int elementIndex);
~ModelNodeMetaObject();
- virtual QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *object);
+ QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *object) override;
static ModelNodeMetaObject *get(QObject *obj);
@@ -138,7 +138,7 @@ public:
bool initialized() const { return m_initialized; }
protected:
- void propertyWritten(int index);
+ void propertyWritten(int index) override;
private:
using QQmlOpenMetaObject::setValue;
@@ -232,9 +232,9 @@ public:
const Role &getRoleOrCreate(QV4::String *key, Role::DataType type);
const Role &getRoleOrCreate(const QString &key, Role::DataType type);
- const Role &getExistingRole(int index) { return *roles.at(index); }
- const Role *getExistingRole(const QString &key);
- const Role *getExistingRole(QV4::String *key);
+ const Role &getExistingRole(int index) const { return *roles.at(index); }
+ const Role *getExistingRole(const QString &key) const;
+ const Role *getExistingRole(QV4::String *key) const;
int roleCount() const { return roles.count(); }
@@ -340,12 +340,12 @@ public:
return m_layout->roleCount();
}
- const ListLayout::Role &getExistingRole(int index)
+ const ListLayout::Role &getExistingRole(int index) const
{
return m_layout->getExistingRole(index);
}
- const ListLayout::Role *getExistingRole(QV4::String *key)
+ const ListLayout::Role *getExistingRole(QV4::String *key) const
{
return m_layout->getExistingRole(key);
}
diff --git a/src/qml/types/qqmllistmodelworkeragent_p.h b/src/qml/types/qqmllistmodelworkeragent_p.h
index 1a891c0f25..5a39651bf7 100644
--- a/src/qml/types/qqmllistmodelworkeragent_p.h
+++ b/src/qml/types/qqmllistmodelworkeragent_p.h
@@ -108,7 +108,7 @@ public:
void modelDestroyed();
protected:
- virtual bool event(QEvent *);
+ bool event(QEvent *) override;
private:
friend class QQuickWorkerScriptEnginePrivate;
diff --git a/src/qml/types/qqmlobjectmodel.cpp b/src/qml/types/qqmlobjectmodel.cpp
index 8c8005fb69..21205f4490 100644
--- a/src/qml/types/qqmlobjectmodel.cpp
+++ b/src/qml/types/qqmlobjectmodel.cpp
@@ -154,7 +154,7 @@ public:
void clear() {
Q_Q(QQmlObjectModel);
- foreach (const Item &child, children)
+ for (const Item &child : qAsConst(children))
emit q->destroyingItem(child.item);
remove(0, children.count());
}
@@ -373,7 +373,7 @@ void QQmlObjectModel::insert(int index, QObject *object)
{
Q_D(QQmlObjectModel);
if (index < 0 || index > count()) {
- qmlInfo(this) << tr("insert: index %1 out of range").arg(index);
+ qmlWarning(this) << tr("insert: index %1 out of range").arg(index);
return;
}
d->insert(index, object);
@@ -400,7 +400,7 @@ void QQmlObjectModel::move(int from, int to, int n)
if (n <= 0 || from == to)
return;
if (from < 0 || to < 0 || from + n > count() || to + n > count()) {
- qmlInfo(this) << tr("move: out of range");
+ qmlWarning(this) << tr("move: out of range");
return;
}
d->move(from, to, n);
@@ -418,7 +418,7 @@ void QQmlObjectModel::remove(int index, int n)
{
Q_D(QQmlObjectModel);
if (index < 0 || n <= 0 || index + n > count()) {
- qmlInfo(this) << tr("remove: indices [%1 - %2] out of range [0 - %3]").arg(index).arg(index+n).arg(count());
+ qmlWarning(this) << tr("remove: indices [%1 - %2] out of range [0 - %3]").arg(index).arg(index+n).arg(count());
return;
}
d->remove(index, n);
diff --git a/src/qml/types/qqmlobjectmodel_p.h b/src/qml/types/qqmlobjectmodel_p.h
index 97a56344d4..fc4c03874f 100644
--- a/src/qml/types/qqmlobjectmodel_p.h
+++ b/src/qml/types/qqmlobjectmodel_p.h
@@ -109,16 +109,16 @@ class Q_QML_PRIVATE_EXPORT QQmlObjectModel : public QQmlInstanceModel
public:
QQmlObjectModel(QObject *parent=0);
- virtual ~QQmlObjectModel() {}
+ ~QQmlObjectModel() {}
- virtual int count() const;
- virtual bool isValid() const;
- virtual QObject *object(int index, bool asynchronous=false);
- virtual ReleaseFlags release(QObject *object);
- virtual QString stringValue(int index, const QString &role);
- virtual void setWatchedRoles(const QList<QByteArray> &) {}
+ int count() const override;
+ bool isValid() const override;
+ QObject *object(int index, bool asynchronous = false) override;
+ ReleaseFlags release(QObject *object) override;
+ QString stringValue(int index, const QString &role) override;
+ void setWatchedRoles(const QList<QByteArray> &) override {}
- virtual int indexOf(QObject *object, QObject *objectContext) const;
+ int indexOf(QObject *object, QObject *objectContext) const override;
QQmlListProperty<QObject> children();
diff --git a/src/qml/types/qqmltimer.cpp b/src/qml/types/qqmltimer.cpp
index 889274b43e..7efdac4c22 100644
--- a/src/qml/types/qqmltimer.cpp
+++ b/src/qml/types/qqmltimer.cpp
@@ -60,8 +60,8 @@ public:
: interval(1000), running(false), repeating(false), triggeredOnStart(false)
, classBegun(false), componentComplete(false), firstTick(true), awaitingTick(false) {}
- virtual void animationFinished(QAbstractAnimationJob *);
- virtual void animationCurrentLoopChanged(QAbstractAnimationJob *) { maybeTick(); }
+ void animationFinished(QAbstractAnimationJob *) override;
+ void animationCurrentLoopChanged(QAbstractAnimationJob *) override { maybeTick(); }
void maybeTick() {
Q_Q(QQmlTimer);
diff --git a/src/qml/types/qqmltimer_p.h b/src/qml/types/qqmltimer_p.h
index 7ea2f098bf..7739dad2a6 100644
--- a/src/qml/types/qqmltimer_p.h
+++ b/src/qml/types/qqmltimer_p.h
@@ -87,10 +87,10 @@ public:
void setTriggeredOnStart(bool triggeredOnStart);
protected:
- void classBegin();
- void componentComplete();
+ void classBegin() override;
+ void componentComplete() override;
- bool event(QEvent *);
+ bool event(QEvent *) override;
public Q_SLOTS:
void start();
diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp
index e095eabce8..f35e17c34d 100644
--- a/src/qml/types/qquickworkerscript.cpp
+++ b/src/qml/types/qquickworkerscript.cpp
@@ -144,7 +144,7 @@ public:
void init();
#if QT_CONFIG(qml_network)
- virtual QNetworkAccessManager *networkAccessManager();
+ QNetworkAccessManager *networkAccessManager() override;
#endif
QQuickWorkerScriptEnginePrivate *p;
@@ -185,13 +185,13 @@ public:
int m_nextId;
- static QV4::ReturnedValue method_sendMessage(QV4::CallContext *ctx);
+ static void method_sendMessage(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
signals:
void stopThread();
protected:
- virtual bool event(QEvent *);
+ bool event(QEvent *) override;
private:
void processMessage(int, const QByteArray &);
@@ -292,14 +292,13 @@ QQuickWorkerScriptEnginePrivate::QQuickWorkerScriptEnginePrivate(QQmlEngine *eng
{
}
-QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::method_sendMessage(QV4::CallContext *ctx)
+void QQuickWorkerScriptEnginePrivate::method_sendMessage(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- WorkerEngine *engine = (WorkerEngine*)ctx->engine()->v8Engine;
+ WorkerEngine *engine = (WorkerEngine*)scope.engine->v8Engine;
- int id = ctx->argc() > 1 ? ctx->args()[1].toInt32() : 0;
+ int id = callData->argc > 1 ? callData->args[1].toInt32() : 0;
- QV4::Scope scope(ctx);
- QV4::ScopedValue v(scope, ctx->argument(2));
+ QV4::ScopedValue v(scope, callData->argument(2));
QByteArray data = QV4::Serialize::serialize(v, scope.engine);
QMutexLocker locker(&engine->p->m_lock);
@@ -307,7 +306,7 @@ QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::method_sendMessage(QV4::Call
if (script && script->owner)
QCoreApplication::postEvent(script->owner, new WorkerDataEvent(0, data));
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::getWorker(WorkerScript *script)
diff --git a/src/qml/types/qquickworkerscript_p.h b/src/qml/types/qquickworkerscript_p.h
index de6f3dc324..dce3acc3e1 100644
--- a/src/qml/types/qquickworkerscript_p.h
+++ b/src/qml/types/qquickworkerscript_p.h
@@ -68,7 +68,7 @@ class QQuickWorkerScriptEngine : public QThread
Q_OBJECT
public:
QQuickWorkerScriptEngine(QQmlEngine *parent = 0);
- virtual ~QQuickWorkerScriptEngine();
+ ~QQuickWorkerScriptEngine();
int registerWorkerScript(QQuickWorkerScript *);
void removeWorkerScript(int);
@@ -76,7 +76,7 @@ public:
void sendMessage(int, const QByteArray &);
protected:
- virtual void run();
+ void run() override;
private:
QQuickWorkerScriptEnginePrivate *d;
@@ -92,7 +92,7 @@ class Q_AUTOTEST_EXPORT QQuickWorkerScript : public QObject, public QQmlParserSt
Q_INTERFACES(QQmlParserStatus)
public:
QQuickWorkerScript(QObject *parent = 0);
- virtual ~QQuickWorkerScript();
+ ~QQuickWorkerScript();
QUrl source() const;
void setSource(const QUrl &);
@@ -105,9 +105,9 @@ Q_SIGNALS:
void message(const QQmlV4Handle &messageObject);
protected:
- virtual void classBegin();
- virtual void componentComplete();
- virtual bool event(QEvent *);
+ void classBegin() override;
+ void componentComplete() override;
+ bool event(QEvent *) override;
private:
QQuickWorkerScriptEngine *engine();
diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp
index 5fc2444b7c..b9d312d41f 100644
--- a/src/qml/util/qqmladaptormodel.cpp
+++ b/src/qml/util/qqmladaptormodel.cpp
@@ -146,7 +146,7 @@ public:
bool changed = roles.isEmpty() && !watchedRoles.isEmpty();
if (!changed && !watchedRoles.isEmpty() && watchedRoleIds.isEmpty()) {
QList<int> roleIds;
- foreach (const QByteArray &r, watchedRoles) {
+ for (const QByteArray &r : watchedRoles) {
QHash<QByteArray, int>::const_iterator it = roleNames.find(r);
if (it != roleNames.end())
roleIds << it.value();
@@ -190,7 +190,7 @@ public:
VDMModelDelegateDataType *dataType = const_cast<VDMModelDelegateDataType *>(this);
dataType->watchedRoleIds.clear();
- foreach (const QByteArray &oldRole, oldRoles)
+ for (const QByteArray &oldRole : oldRoles)
dataType->watchedRoles.removeOne(oldRole);
dataType->watchedRoles += newRoles;
}
diff --git a/src/qml/util/qqmladaptormodel_p.h b/src/qml/util/qqmladaptormodel_p.h
index 8e400f9146..78d964236e 100644
--- a/src/qml/util/qqmladaptormodel_p.h
+++ b/src/qml/util/qqmladaptormodel_p.h
@@ -143,7 +143,7 @@ public:
inline void fetchMore() { return accessors->fetchMore(*this); }
protected:
- void objectDestroyed(QObject *);
+ void objectDestroyed(QObject *) override;
};
class QQmlAdaptorModelProxyInterface
diff --git a/src/qml/util/qqmlchangeset.cpp b/src/qml/util/qqmlchangeset.cpp
index 088ac5e8c0..79e3332331 100644
--- a/src/qml/util/qqmlchangeset.cpp
+++ b/src/qml/util/qqmlchangeset.cpp
@@ -558,9 +558,15 @@ void QQmlChangeSet::change(QVector<Change> *changes)
QDebug operator <<(QDebug debug, const QQmlChangeSet &set)
{
debug.nospace() << "QQmlChangeSet(";
- foreach (const QQmlChangeSet::Change &remove, set.removes()) debug << remove;
- foreach (const QQmlChangeSet::Change &insert, set.inserts()) debug << insert;
- foreach (const QQmlChangeSet::Change &change, set.changes()) debug << change;
+ const QVector<QQmlChangeSet::Change> &removes = set.removes();
+ for (const QQmlChangeSet::Change &remove : removes)
+ debug << remove;
+ const QVector<QQmlChangeSet::Change> &inserts = set.inserts();
+ for (const QQmlChangeSet::Change &insert : inserts)
+ debug << insert;
+ const QVector<QQmlChangeSet::Change> &changes = set.changes();
+ for (const QQmlChangeSet::Change &change : changes)
+ debug << change;
return debug.nospace() << ')';
}
diff --git a/src/qml/util/qqmllistcompositor.cpp b/src/qml/util/qqmllistcompositor.cpp
index 4cfdf77b2a..05a4eaac39 100644
--- a/src/qml/util/qqmllistcompositor.cpp
+++ b/src/qml/util/qqmllistcompositor.cpp
@@ -964,7 +964,7 @@ void QQmlListCompositor::listItemsInserted(
it.incrementIndexes(it->count);
continue;
}
- foreach (const QQmlChangeSet::Change &insertion, insertions) {
+ for (const QQmlChangeSet::Change &insertion : insertions) {
int offset = insertion.index - it->index;
if ((offset > 0 && offset < it->count)
|| (offset == 0 && it->prepend())
@@ -1301,7 +1301,7 @@ void QQmlListCompositor::listItemsChanged(
} else if (!it->inGroup()) {
continue;
}
- foreach (const QQmlChangeSet::Change &change, changes) {
+ for (const QQmlChangeSet::Change &change : changes) {
const int offset = change.index - it->index;
if (offset + change.count > 0 && offset < it->count) {
const int changeOffset = qMax(0, offset);
diff --git a/src/qml/util/qqmlpropertymap.cpp b/src/qml/util/qqmlpropertymap.cpp
index 69d3fc25e1..6e6554f2c3 100644
--- a/src/qml/util/qqmlpropertymap.cpp
+++ b/src/qml/util/qqmlpropertymap.cpp
@@ -54,10 +54,10 @@ public:
QQmlPropertyMapMetaObject(QQmlPropertyMap *obj, QQmlPropertyMapPrivate *objPriv, const QMetaObject *staticMetaObject);
protected:
- virtual QVariant propertyWriteValue(int, const QVariant &);
- virtual void propertyWritten(int index);
- virtual void propertyCreated(int, QMetaPropertyBuilder &);
- virtual int createProperty(const char *, const char *);
+ QVariant propertyWriteValue(int, const QVariant &) override;
+ void propertyWritten(int index) override;
+ void propertyCreated(int, QMetaPropertyBuilder &) override;
+ int createProperty(const char *, const char *) override;
const QString &propertyName(int index);
diff --git a/src/qmldebug/qqmlenginecontrolclient_p.h b/src/qmldebug/qqmlenginecontrolclient_p.h
index 6affc46ffc..9b4ea3acb1 100644
--- a/src/qmldebug/qqmlenginecontrolclient_p.h
+++ b/src/qmldebug/qqmlenginecontrolclient_p.h
@@ -78,7 +78,7 @@ protected:
QQmlEngineControlClient(QQmlEngineControlClientPrivate &dd);
private:
- void messageReceived(const QByteArray &);
+ void messageReceived(const QByteArray &) override;
};
QT_END_NAMESPACE
diff --git a/src/qmldebug/qqmlprofilerclient_p.h b/src/qmldebug/qqmlprofilerclient_p.h
index b4054ed0d9..a328cad26c 100644
--- a/src/qmldebug/qqmlprofilerclient_p.h
+++ b/src/qmldebug/qqmlprofilerclient_p.h
@@ -73,7 +73,7 @@ protected:
QQmlProfilerClient(QQmlProfilerClientPrivate &dd);
private:
- virtual void messageReceived(const QByteArray &message);
+ void messageReceived(const QByteArray &message) override;
virtual void traceStarted(qint64 time, int engineId);
virtual void traceFinished(qint64 time, int engineId);
diff --git a/src/qmldevtools/qmldevtools.pro b/src/qmldevtools/qmldevtools.pro
index acd5c9729b..ec5d73044f 100644
--- a/src/qmldevtools/qmldevtools.pro
+++ b/src/qmldevtools/qmldevtools.pro
@@ -18,5 +18,6 @@ include(../qml/parser/parser.pri)
include(../qml/jsruntime/jsruntime.pri)
include(../qml/compiler/compiler.pri)
include(../qml/memory/memory.pri)
+include(../qml/jit/jit.pri)
load(qt_module)
diff --git a/src/qmldevtools/qtqmldevtoolsglobal_p.h b/src/qmldevtools/qtqmldevtoolsglobal_p.h
index 5c803a4b32..5cb8a9275a 100644
--- a/src/qmldevtools/qtqmldevtoolsglobal_p.h
+++ b/src/qmldevtools/qtqmldevtoolsglobal_p.h
@@ -53,10 +53,21 @@
#include <QtCore/qglobal.h>
+// All host systems are assumed to have alloca().
+#define Q_ALLOCA_VAR(type, name, size) \
+ type *name = static_cast<type*>(alloca(size))
+
QT_BEGIN_NAMESPACE
#define Q_QML_EXPORT
#define Q_QML_PRIVATE_EXPORT
+/* Some classes built into QtQmlDevTools are marked Q_AUTOTEST_EXPORT but we
+ have nothing to export in this static library */
+#if defined(Q_AUTOTEST_EXPORT)
+#undef Q_AUTOTEST_EXPORT
+#endif
+#define Q_AUTOTEST_EXPORT
+
QT_END_NAMESPACE
#endif // QTQMLGLOBAL_P_H
diff --git a/src/qmltest/qmltest.pro b/src/qmltest/qmltest.pro
index 9852861334..d13e162ff4 100644
--- a/src/qmltest/qmltest.pro
+++ b/src/qmltest/qmltest.pro
@@ -2,7 +2,7 @@ TARGET = QtQuickTest
DEFINES += QT_NO_URL_CAST_FROM_STRING QT_NO_FOREACH
QT = core testlib-private
-QT_PRIVATE = quick qml-private gui core-private
+QT_PRIVATE = quick qml-private gui core-private gui-private
# Testlib is only a private dependency, which results in our users not
# inheriting testlibs's MODULE_CONFIG transitively. Make it explicit.
diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp
index 70733da121..f62f66170e 100644
--- a/src/qmltest/quicktest.cpp
+++ b/src/qmltest/quicktest.cpp
@@ -373,9 +373,6 @@ int quick_test_main(int argc, char **argv, const char *name, const char *sourceD
// and then wait for quit indication.
view->setFramePosition(QPoint(50, 50));
if (view->size().isEmpty()) { // Avoid hangs with empty windows.
- qWarning().nospace()
- << "Test '" << QDir::toNativeSeparators(path) << "' has invalid size "
- << view->size() << ", resizing.";
view->resize(200, 200);
}
view->show();
diff --git a/src/qmltest/quicktestevent.cpp b/src/qmltest/quicktestevent.cpp
index 3d6365503d..dc7b917bc4 100644
--- a/src/qmltest/quicktestevent.cpp
+++ b/src/qmltest/quicktestevent.cpp
@@ -42,6 +42,7 @@
#include <QtQml/qqml.h>
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickwindow.h>
+#include <qpa/qwindowsysteminterface.h>
QT_BEGIN_NAMESPACE
@@ -128,7 +129,7 @@ namespace QtQuickTest
static void mouseEvent(MouseAction action, QWindow *window,
QObject *item, Qt::MouseButton button,
- Qt::KeyboardModifiers stateKey, QPointF _pos, int delay=-1)
+ Qt::KeyboardModifiers stateKey, const QPointF &_pos, int delay=-1)
{
QTEST_ASSERT(window);
QTEST_ASSERT(item);
@@ -326,6 +327,10 @@ bool QuickTestEvent::mouseMove
QWindow *QuickTestEvent::eventWindow(QObject *item)
{
+ QWindow * window = qobject_cast<QWindow *>(item);
+ if (window)
+ return window;
+
QQuickItem *quickItem = qobject_cast<QQuickItem *>(item);
if (quickItem)
return quickItem->window();
@@ -343,4 +348,96 @@ QWindow *QuickTestEvent::activeWindow()
return eventWindow();
}
+QQuickTouchEventSequence::QQuickTouchEventSequence(QuickTestEvent *testEvent, QObject *item)
+ : QObject(testEvent)
+ , m_sequence(QTest::touchEvent(testEvent->eventWindow(item), testEvent->touchDevice()))
+ , m_testEvent(testEvent)
+{
+}
+
+QObject *QQuickTouchEventSequence::press(int touchId, QObject *item, qreal x, qreal y)
+{
+ QWindow *view = m_testEvent->eventWindow(item);
+ if (view) {
+ QPointF pos(x, y);
+ QQuickItem *quickItem = qobject_cast<QQuickItem *>(item);
+ if (quickItem) {
+ pos = quickItem->mapToScene(pos);
+ }
+ m_sequence.press(touchId, pos.toPoint(), view);
+ }
+ return this;
+}
+
+QObject *QQuickTouchEventSequence::move(int touchId, QObject *item, qreal x, qreal y)
+{
+ QWindow *view = m_testEvent->eventWindow(item);
+ if (view) {
+ QPointF pos(x, y);
+ QQuickItem *quickItem = qobject_cast<QQuickItem *>(item);
+ if (quickItem) {
+ pos = quickItem->mapToScene(pos);
+ }
+ m_sequence.move(touchId, pos.toPoint(), view);
+ }
+ return this;
+}
+
+QObject *QQuickTouchEventSequence::release(int touchId, QObject *item, qreal x, qreal y)
+{
+ QWindow *view = m_testEvent->eventWindow(item);
+ if (view) {
+ QPointF pos(x, y);
+ QQuickItem *quickItem = qobject_cast<QQuickItem *>(item);
+ if (quickItem) {
+ pos = quickItem->mapToScene(pos);
+ }
+ m_sequence.release(touchId, pos.toPoint(), view);
+ }
+ return this;
+}
+
+QObject *QQuickTouchEventSequence::stationary(int touchId)
+{
+ m_sequence.stationary(touchId);
+ return this;
+}
+
+QObject *QQuickTouchEventSequence::commit()
+{
+ m_sequence.commit();
+ return this;
+}
+
+/*!
+ Return a simulated touchscreen, creating one if necessary
+
+ \internal
+*/
+
+QTouchDevice *QuickTestEvent::touchDevice()
+{
+ static QTouchDevice *device(nullptr);
+
+ if (!device) {
+ device = new QTouchDevice;
+ device->setType(QTouchDevice::TouchScreen);
+ QWindowSystemInterface::registerTouchDevice(device);
+ }
+ return device;
+}
+
+/*!
+ Creates a new QQuickTouchEventSequence.
+
+ If valid, \a item determines the QWindow that touch events are sent to.
+ Test code should use touchEvent() from the QML TestCase type.
+
+ \internal
+*/
+QQuickTouchEventSequence *QuickTestEvent::touchEvent(QObject *item)
+{
+ return new QQuickTouchEventSequence(this, item);
+}
+
QT_END_NAMESPACE
diff --git a/src/qmltest/quicktestevent_p.h b/src/qmltest/quicktestevent_p.h
index 1f6de7ed28..89065b8880 100644
--- a/src/qmltest/quicktestevent_p.h
+++ b/src/qmltest/quicktestevent_p.h
@@ -54,8 +54,28 @@
#include <QtQuickTest/quicktestglobal.h>
#include <QtCore/qobject.h>
#include <QtGui/QWindow>
+#include <QtTest/qtesttouch.h>
+
QT_BEGIN_NAMESPACE
+class QuickTestEvent;
+class Q_QUICK_TEST_EXPORT QQuickTouchEventSequence : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QQuickTouchEventSequence(QuickTestEvent *testEvent, QObject *item = nullptr);
+public slots:
+ QObject* press(int touchId, QObject *item, qreal x, qreal y);
+ QObject* move(int touchId, QObject *item, qreal x, qreal y);
+ QObject* release(int touchId, QObject *item, qreal x, qreal y);
+ QObject* stationary(int touchId);
+ QObject* commit();
+
+private:
+ QTest::QTouchEventSequence m_sequence;
+ QuickTestEvent * const m_testEvent;
+};
+
class Q_QUICK_TEST_EXPORT QuickTestEvent : public QObject
{
Q_OBJECT
@@ -91,9 +111,13 @@ public Q_SLOTS:
int modifiers, int xDelta, int yDelta, int delay);
#endif
+ QQuickTouchEventSequence *touchEvent(QObject *item = nullptr);
private:
QWindow *eventWindow(QObject *item = 0);
QWindow *activeWindow();
+ QTouchDevice *touchDevice();
+
+ friend class QQuickTouchEventSequence;
};
QT_END_NAMESPACE
diff --git a/src/qmltest/quicktestresult.cpp b/src/qmltest/quicktestresult.cpp
index dd78b82dcb..02d925d37d 100644
--- a/src/qmltest/quicktestresult.cpp
+++ b/src/qmltest/quicktestresult.cpp
@@ -524,7 +524,7 @@ void QuickTestResult::stringify(QQmlV4Function *args)
if (result.isEmpty()) {
QString tmp = value->toQStringNoThrow();
if (value->as<QV4::ArrayObject>())
- result.append(QString::fromLatin1("[%1]").arg(tmp));
+ result += QLatin1Char('[') + tmp + QLatin1Char(']');
else
result.append(tmp);
}
diff --git a/src/quick/accessible/qaccessiblequickitem.cpp b/src/quick/accessible/qaccessiblequickitem.cpp
index 897e1143d5..fbde5d354d 100644
--- a/src/quick/accessible/qaccessiblequickitem.cpp
+++ b/src/quick/accessible/qaccessiblequickitem.cpp
@@ -269,8 +269,8 @@ void QAccessibleQuickItem::doAction(const QString &actionName)
return;
// Look for and call the accessible[actionName]Action() function on the item.
// This allows for overriding the default action handling.
- const QByteArray functionName = QByteArrayLiteral("accessible") + actionName.toLatin1() + QByteArrayLiteral("Action");
- if (object()->metaObject()->indexOfMethod(QByteArray(functionName + QByteArrayLiteral("()"))) != -1) {
+ const QByteArray functionName = "accessible" + actionName.toLatin1() + "Action";
+ if (object()->metaObject()->indexOfMethod(QByteArray(functionName + "()")) != -1) {
QMetaObject::invokeMethod(object(), functionName);
return;
}
diff --git a/src/quick/accessible/qaccessiblequickview_p.h b/src/quick/accessible/qaccessiblequickview_p.h
index fcd0bec85e..39ffcaf39c 100644
--- a/src/quick/accessible/qaccessiblequickview_p.h
+++ b/src/quick/accessible/qaccessiblequickview_p.h
@@ -63,21 +63,21 @@ class QAccessibleQuickWindow : public QAccessibleObject
public:
QAccessibleQuickWindow(QQuickWindow *object);
- QAccessibleInterface *parent() const;
- QAccessibleInterface *child(int index) const;
+ QAccessibleInterface *parent() const override;
+ QAccessibleInterface *child(int index) const override;
QAccessibleInterface *focusChild() const override;
- QAccessible::Role role() const;
- QAccessible::State state() const;
- QRect rect() const;
+ QAccessible::Role role() const override;
+ QAccessible::State state() const override;
+ QRect rect() const override;
- int childCount() const;
- int indexOfChild(const QAccessibleInterface *iface) const;
- QString text(QAccessible::Text text) const;
- QAccessibleInterface *childAt(int x, int y) const;
+ int childCount() const override;
+ int indexOfChild(const QAccessibleInterface *iface) const override;
+ QString text(QAccessible::Text text) const override;
+ QAccessibleInterface *childAt(int x, int y) const override;
private:
- QQuickWindow *window() const { return static_cast<QQuickWindow*>(object()); }
+ QQuickWindow *window() const override { return static_cast<QQuickWindow*>(object()); }
QList<QQuickItem *> rootItems() const;
};
diff --git a/src/quick/designer/qqmldesignermetaobject_p.h b/src/quick/designer/qqmldesignermetaobject_p.h
index 01512f6af0..3c02c0d3f5 100644
--- a/src/quick/designer/qqmldesignermetaobject_p.h
+++ b/src/quick/designer/qqmldesignermetaobject_p.h
@@ -74,7 +74,7 @@ protected:
void createNewDynamicProperty(const QString &name);
int openMetaCall(QObject *o, QMetaObject::Call _c, int _id, void **_a);
- int metaCall(QObject *o, QMetaObject::Call _c, int _id, void **_a);
+ int metaCall(QObject *o, QMetaObject::Call _c, int _id, void **_a) override;
void notifyPropertyChange(int id);
void setValue(int id, const QVariant &value);
QVariant propertyWriteValue(int, const QVariant &);
diff --git a/src/quick/designer/qquickdesignerwindowmanager_p.h b/src/quick/designer/qquickdesignerwindowmanager_p.h
index 09e15dad73..5322b6c421 100644
--- a/src/quick/designer/qquickdesignerwindowmanager_p.h
+++ b/src/quick/designer/qquickdesignerwindowmanager_p.h
@@ -75,24 +75,24 @@ class QQuickDesignerWindowManager : public QSGRenderLoop
public:
QQuickDesignerWindowManager();
- void show(QQuickWindow *window);
- void hide(QQuickWindow *window);
+ void show(QQuickWindow *window) override;
+ void hide(QQuickWindow *window) override;
- void windowDestroyed(QQuickWindow *window);
+ void windowDestroyed(QQuickWindow *window) override;
void makeOpenGLContext(QQuickWindow *window);
- void exposureChanged(QQuickWindow *window);
- QImage grab(QQuickWindow *window);
+ void exposureChanged(QQuickWindow *window) override;
+ QImage grab(QQuickWindow *window) override;
- void maybeUpdate(QQuickWindow *window);
- void update(QQuickWindow *window); // identical for this implementation.
+ void maybeUpdate(QQuickWindow *window) override;
+ void update(QQuickWindow *window) override; // identical for this implementation.
- void releaseResources(QQuickWindow *) { }
+ void releaseResources(QQuickWindow *) override { }
- QAnimationDriver *animationDriver() const { return 0; }
+ QAnimationDriver *animationDriver() const override { return nullptr; }
- QSGContext *sceneGraphContext() const;
- QSGRenderContext *createRenderContext(QSGContext *) const { return m_renderContext.data(); }
+ QSGContext *sceneGraphContext() const override;
+ QSGRenderContext *createRenderContext(QSGContext *) const override { return m_renderContext.data(); }
static void createOpenGLContext(QQuickWindow *window);
diff --git a/src/quick/doc/images/touchpoint-metrics.png b/src/quick/doc/images/touchpoint-metrics.png
new file mode 100644
index 0000000000..9b0bf22e25
--- /dev/null
+++ b/src/quick/doc/images/touchpoint-metrics.png
Binary files differ
diff --git a/src/quick/doc/snippets/qml/listview/listview.qml b/src/quick/doc/snippets/qml/listview/listview.qml
index 31896626a4..ecb5fea076 100644
--- a/src/quick/doc/snippets/qml/listview/listview.qml
+++ b/src/quick/doc/snippets/qml/listview/listview.qml
@@ -146,4 +146,19 @@ ListView {
}
//![isCurrentItem]
+//![flickBothDirections]
+ListView {
+ width: 180; height: 200
+
+ contentWidth: 320
+ flickableDirection: Flickable.AutoFlickDirection
+
+ model: ContactModel {}
+ delegate: Row {
+ Text { text: '<b>Name:</b> ' + name; width: 160 }
+ Text { text: '<b>Number:</b> ' + number; width: 160 }
+ }
+}
+//![flickBothDirections]
+
}
diff --git a/src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc b/src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc
index c9ad9d8065..d80c72e0f1 100644
--- a/src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc
+++ b/src/quick/doc/src/concepts/visualcanvas/adaptations.qdoc
@@ -54,6 +54,8 @@ The supported backends are the following
\li Direct3D 12 - Requested by the string \c{"d3d12"} or the enum value QSGRendererInterface::Direct3D12.
+\li OpenVG - Requested by the string \c{"openvg"} or the enum value QSGRendererInterface::OpenVG.
+
\endlist
When in doubt which backend is in use, enable basic scenegraph information
@@ -88,6 +90,14 @@ running on Windows 10, both for Win32 and UWP applications. The details for
this adaptation are available here:
\l{qtquick-visualcanvas-adaptations-d3d12.html}{Direct3D 12 Adaptation}
+\section1 OpenVG
+
+The OpenVG adaptation is an alternative renderer for \l {Qt Quick} 2 that will
+renderer the contents of the scene graph using OpenVG commands to provide
+hardware-acclerated 2D vector and raster graphics. The details for this
+adaptation are available here:
+\l{qtquick-visualcanvas-scenegraph-openvg.html}{OpenVG Adaptation}
+
*/
@@ -383,3 +393,73 @@ between the frames). By default blocking present is disabled.
\endlist
*/
+
+/*!
+\title Qt Quick OpenVG Adaptation
+\page qtquick-visualcanvas-adaptations-openvg.html
+
+The OpenVG adaptation is an alternative renderer for \l {Qt Quick} 2 that will
+renderer the contents of the scene graph using OpenVG commands to provide
+hardware-acclerated 2D vector and raster graphics. Much like the Software
+adaptation, some features and optimizations are no longer available. Most
+Qt Quick 2 applications will run without modification though any attempts to
+use unsupported features will be ignored.
+
+\section2 EGL Requirement
+Unlike the defualt OpenGL Renderer, there is no built in support for acquiring
+an OpenVG context. This means that the renderer has the responsbility of
+requesting and managing the the current context. To do this EGL has to be used
+directly in the OpenVG renderer. This means that the OpenVG renderer is only
+usable with platform plugins that support creating QWindows with support for
+QSurfaceFormat::OpenVG. From this window, the renderer can get an EGLSurface
+which can be used with an EGLContext to render OpenVG content.
+
+\section2 Renderer
+The OpenVG Renderer works by using the OpenVG API to send commands and data to
+a Vector GPU which will render the scenegraph in an accelerated manner, offloading
+graphics rendering from the CPU. Many operations like the rendering of rectangles
+and fonts glyphs ideal for OpenVG because these can be represented as paths which
+are stroked and filled. Rendering scenegraph items that would typically involve
+textures are handled in the OpenVG renderer by using VGImage. In addition when
+rendering to offscreen surfaces (like when using Layers), the scene subtree is
+rendered to a VGImage which can be reused in the scene.
+
+\section2 Render Loop
+The OpenVG Renderer mirrors the behavior of the Basic render loop and will execute
+all OpenVG commands in a single thread.
+
+See the \l{qtquick-visualcanvas-scenegraph.html}{Scene Graph page} for more
+information on render loops
+
+\section2 Shader Effects
+ShaderEffect components in QtQuick 2 can not be rendered by the OpenVG adaptation.
+While it is possible to user ShaderEffectSource and QML Item Layers (which are both
+offscreen surfaces), it is not actually possible to apply shader effects to them
+via the ShaderEffect item. This is because OpenVG lacks an API for applying per
+vertex and per fragment shader operations. It may be possible however to take
+advantage of Image Filter operations in the OpenVG API to get similar effects to
+what is provided by ShaderEffects in custom items. To integrate custom OpenVG
+rendering, use QSGRenderNode in combination with QSGRendererInterface.
+
+\section2 Qt Graphical Effects Module
+\l {Qt Graphical Effects} uses ShaderEffect items to render effects. If you use
+graphical effects from this module, then you should not hide the source
+item so that the original item can still be rendered.
+
+\section2 Particle Effects
+It is not possible to render particle effects with the OpenVG adaptation. Whenever
+possible, remove particles completely from the scene. Otherwise they will still
+require some processing, even though they are not visible.
+
+\section2 Rendering Text
+The text rendering with the OpenVG adaptation is based on rendering the glpyh
+paths, and does not use the distance fields technique used by the OpenGL backend.
+
+\section2 Perspective Transforms
+The OpenVG API does not allow paths to be transformed with non-affine transforms,
+while it is possible with Qt Quick. This means that rendering components using
+paths like Rectangles and Text, when applying perspective transforms the OpenVG
+backend will first render to a VGImage before applying transformations. This uses
+more memory at runtime and is a slower path so avoid doing this if necessary.
+
+*/
diff --git a/src/quick/items/checksync.pl b/src/quick/items/checksync.pl
deleted file mode 100755
index c9771bb10c..0000000000
--- a/src/quick/items/checksync.pl
+++ /dev/null
@@ -1,106 +0,0 @@
-#!/usr/bin/perl
-#############################################################################
-##
-## Copyright (C) 2016 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of the Declarative module of the Qt Toolkit.
-##
-## $QT_BEGIN_LICENSE:LGPL$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU Lesser General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU Lesser
-## General Public License version 3 as published by the Free Software
-## Foundation and appearing in the file LICENSE.LGPL3 included in the
-## packaging of this file. Please review the following information to
-## ensure the GNU Lesser General Public License version 3 requirements
-## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 2.0 or (at your option) the GNU General
-## Public license version 3 or any later version approved by the KDE Free
-## Qt Foundation. The licenses are as published by the Free Software
-## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-2.0.html and
-## https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
-
-use strict;
-use warnings;
-
-die "Usage: $0 <QML directory>" if (@ARGV != 1);
-
-my @excludes;
-open (SYNCEXCLUDES, "<", "syncexcludes");
-while (<SYNCEXCLUDES>) {
- if (/^([a-zA-Z0-9\._]+)/) {
- my $exclude = $1;
- push (@excludes, $exclude);
- }
-}
-
-my $portdir = ".";
-my $qmldir = $ARGV[0];
-
-opendir (PORTDIR, $portdir) or die "Cannot open port directory";
-opendir (QMLDIR, $qmldir) or die "Cannot open QML directory";
-
-my @portfiles = readdir(PORTDIR);
-my @qmlfiles = readdir(QMLDIR);
-
-closedir(PORTDIR);
-closedir(QMLDIR);
-
-foreach my $qmlfile (@qmlfiles) {
- if ($qmlfile =~ /^qdeclarative.*\.cpp$/ or $qmlfile =~ /qdeclarative.*\.h$/) {
-
- if (grep { $_ eq $qmlfile} @excludes) {
- next;
- }
-
- my $portfile = $qmlfile;
- $portfile =~ s/^qdeclarative/qsg/;
-
- if (grep { $_ eq $portfile} @portfiles) {
-
- open (PORTFILE, "<", "$portdir/$portfile") or die("Cannot open $portdir/$portfile for reading");
-
- my $firstline = <PORTFILE>;
-
- close (PORTFILE);
-
- if ($firstline and $firstline =~ /^\/\/ Commit: ([a-z0-9]+)/) {
- my $sha1 = $1;
- my $commitSha1 = "";
-
- my $output = `cd $qmldir; git log $qmlfile | head -n 1`;
- if ($output =~ /commit ([a-z0-9]+)/) {
- $commitSha1 = $1;
- }
-
- if ($commitSha1 eq $sha1) {
- print ("$portfile: OK\n");
- } else {
- print ("$portfile: OUT OF DATE\n");
- }
- } else {
- print ("$portfile: OUT OF DATE\n");
- }
- } else {
- print ("$portfile: MISSING\n");
- }
- }
-}
diff --git a/src/quick/items/context2d/qquickcanvasitem.cpp b/src/quick/items/context2d/qquickcanvasitem.cpp
index 28e9173bf7..1167f408f5 100644
--- a/src/quick/items/context2d/qquickcanvasitem.cpp
+++ b/src/quick/items/context2d/qquickcanvasitem.cpp
@@ -354,7 +354,7 @@ void QQuickCanvasItem::setContextType(const QString &contextType)
return;
if (d->context) {
- qmlInfo(this) << "Canvas already initialized with a different context type";
+ qmlWarning(this) << "Canvas already initialized with a different context type";
return;
}
@@ -517,7 +517,7 @@ void QQuickCanvasItem::setRenderTarget(QQuickCanvasItem::RenderTarget target)
Q_D(QQuickCanvasItem);
if (d->renderTarget != target) {
if (d->context) {
- qmlInfo(this) << "Canvas:renderTarget not changeble once context is active.";
+ qmlWarning(this) << "Canvas:renderTarget not changeble once context is active.";
return;
}
@@ -561,7 +561,7 @@ void QQuickCanvasItem::setRenderStrategy(QQuickCanvasItem::RenderStrategy strate
Q_D(QQuickCanvasItem);
if (d->renderStrategy != strategy) {
if (d->context) {
- qmlInfo(this) << "Canvas:renderStrategy not changeable once context is active.";
+ qmlWarning(this) << "Canvas:renderStrategy not changeable once context is active.";
return;
}
d->renderStrategy = strategy;
@@ -640,6 +640,17 @@ void QQuickCanvasItem::releaseResources()
}
}
+bool QQuickCanvasItem::event(QEvent *event)
+{
+ switch (event->type()) {
+ case QEvent::PolishRequest:
+ polish();
+ return true;
+ default:
+ return QQuickItem::event(event);
+ }
+}
+
void QQuickCanvasItem::invalidateSceneGraph()
{
Q_D(QQuickCanvasItem);
@@ -651,6 +662,12 @@ void QQuickCanvasItem::invalidateSceneGraph()
d->textureProvider = 0;
}
+void QQuickCanvasItem::schedulePolish()
+{
+ auto polishRequestEvent = new QEvent(QEvent::PolishRequest);
+ QCoreApplication::postEvent(this, polishRequestEvent);
+}
+
void QQuickCanvasItem::componentComplete()
{
QQuickItem::componentComplete();
@@ -839,13 +856,13 @@ void QQuickCanvasItem::getContext(QQmlV4Function *args)
QV4::Scope scope(args->v4engine());
QV4::ScopedString str(scope, (*args)[0]);
if (!str) {
- qmlInfo(this) << "getContext should be called with a string naming the required context type";
+ qmlWarning(this) << "getContext should be called with a string naming the required context type";
args->setReturnValue(QV4::Encode::null());
return;
}
if (!d->available) {
- qmlInfo(this) << "Unable to use getContext() at this time, please wait for available: true";
+ qmlWarning(this) << "Unable to use getContext() at this time, please wait for available: true";
args->setReturnValue(QV4::Encode::null());
return;
}
@@ -858,7 +875,7 @@ void QQuickCanvasItem::getContext(QQmlV4Function *args)
return;
}
- qmlInfo(this) << "Canvas already initialized with a different context type";
+ qmlWarning(this) << "Canvas already initialized with a different context type";
args->setReturnValue(QV4::Encode::null());
return;
}
@@ -881,7 +898,7 @@ void QQuickCanvasItem::requestAnimationFrame(QQmlV4Function *args)
QV4::Scope scope(args->v4engine());
QV4::ScopedFunctionObject f(scope, (*args)[0]);
if (!f) {
- qmlInfo(this) << "requestAnimationFrame should be called with an animation callback function";
+ qmlWarning(this) << "requestAnimationFrame should be called with an animation callback function";
args->setReturnValue(QV4::Encode::null());
return;
}
@@ -892,8 +909,9 @@ void QQuickCanvasItem::requestAnimationFrame(QQmlV4Function *args)
d->animationCallbacks.insert(++id, QV4::PersistentValue(scope.engine, f->asReturnedValue()));
+ // QTBUG-55778: Calling polish directly here can lead to a polish loop
if (isVisible())
- polish();
+ schedulePolish();
args->setReturnValue(QV4::Encode(id));
}
@@ -909,7 +927,7 @@ void QQuickCanvasItem::cancelRequestAnimationFrame(QQmlV4Function *args)
QV4::Scope scope(args->v4engine());
QV4::ScopedValue v(scope, (*args)[0]);
if (!v->isInteger()) {
- qmlInfo(this) << "cancelRequestAnimationFrame should be called with an animation callback id";
+ qmlWarning(this) << "cancelRequestAnimationFrame should be called with an animation callback id";
args->setReturnValue(QV4::Encode::null());
return;
}
@@ -1094,6 +1112,27 @@ QImage QQuickCanvasItem::toImage(const QRectF& rect) const
return QImage();
}
+static const char* mimeToType(const QString &mime)
+{
+ const QLatin1String imagePrefix("image/");
+ if (!mime.startsWith(imagePrefix))
+ return nullptr;
+ const QStringRef mimeExt = mime.midRef(imagePrefix.size());
+ if (mimeExt == QLatin1String("png"))
+ return "png";
+ else if (mimeExt == QLatin1String("bmp"))
+ return "bmp";
+ else if (mimeExt == QLatin1String("jpeg"))
+ return "jpeg";
+ else if (mimeExt == QLatin1String("x-portable-pixmap"))
+ return "ppm";
+ else if (mimeExt == QLatin1String("tiff"))
+ return "tiff";
+ else if (mimeExt == QLatin1String("xpm"))
+ return "xpm";
+ return nullptr;
+}
+
/*!
\qmlmethod string QtQuick::Canvas::toDataURL(string mimeType)
@@ -1111,27 +1150,14 @@ QString QQuickCanvasItem::toDataURL(const QString& mimeType) const
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
- QString mime = mimeType.toLower();
- QString type;
- if (mime == QLatin1String("image/png")) {
- type = QStringLiteral("PNG");
- } else if (mime == QLatin1String("image/bmp"))
- type = QStringLiteral("BMP");
- else if (mime == QLatin1String("image/jpeg"))
- type = QStringLiteral("JPEG");
- else if (mime == QLatin1String("image/x-portable-pixmap"))
- type = QStringLiteral("PPM");
- else if (mime == QLatin1String("image/tiff"))
- type = QStringLiteral("TIFF");
- else if (mime == QLatin1String("image/xpm"))
- type = QStringLiteral("XPM");
- else
+ const QString mime = mimeType.toLower();
+ const char* type = mimeToType(mime);
+ if (!type)
return QStringLiteral("data:,");
- image.save(&buffer, type.toLatin1());
+ image.save(&buffer, type);
buffer.close();
- QString dataUrl = QStringLiteral("data:%1;base64,%2");
- return dataUrl.arg(mime).arg(QLatin1String(ba.toBase64().constData()));
+ return QLatin1String("data:") + mime + QLatin1String(";base64,") + QLatin1String(ba.toBase64().constData());
}
return QStringLiteral("data:,");
}
diff --git a/src/quick/items/context2d/qquickcanvasitem_p.h b/src/quick/items/context2d/qquickcanvasitem_p.h
index 8196debef1..217ae9bb69 100644
--- a/src/quick/items/context2d/qquickcanvasitem_p.h
+++ b/src/quick/items/context2d/qquickcanvasitem_p.h
@@ -182,6 +182,7 @@ private Q_SLOTS:
void sceneGraphInitialized();
void checkAnimationCallbacks();
void invalidateSceneGraph();
+ void schedulePolish();
protected:
void componentComplete() Q_DECL_OVERRIDE;
@@ -190,12 +191,13 @@ protected:
QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) Q_DECL_OVERRIDE;
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
void releaseResources() Q_DECL_OVERRIDE;
+ bool event(QEvent *event) Q_DECL_OVERRIDE;
private:
Q_DECLARE_PRIVATE(QQuickCanvasItem)
Q_INVOKABLE void delayedCreate();
bool createContext(const QString &contextType);
void initializeContext(QQuickCanvasContext *context, const QVariantMap &args = QVariantMap());
- QRect tiledRect(const QRectF &window, const QSize &tileSize);
+ static QRect tiledRect(const QRectF &window, const QSize &tileSize);
bool isPaintConnected();
};
diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp
index bcaedd67b4..e25cc5ccbe 100644
--- a/src/quick/items/context2d/qquickcontext2d.cpp
+++ b/src/quick/items/context2d/qquickcontext2d.cpp
@@ -129,10 +129,10 @@ Q_CORE_EXPORT double qstrtod(const char *s00, char const **se, bool *ok);
#define DEGREES(t) ((t) * 180.0 / M_PI)
#define CHECK_CONTEXT(r) if (!r || !r->d()->context || !r->d()->context->bufferValid()) \
- V4THROW_ERROR("Not a Context2D object");
+ THROW_GENERIC_ERROR("Not a Context2D object");
#define CHECK_CONTEXT_SETTER(r) if (!r || !r->d()->context || !r->d()->context->bufferValid()) \
- V4THROW_ERROR("Not a Context2D object");
+ THROW_GENERIC_ERROR("Not a Context2D object");
#define qClamp(val, min, max) qMin(qMax(val, min), max)
#define CHECK_RGBA(c) (c == '-' || c == '.' || (c >=0 && c <= 9))
QColor qt_color_from_string(const QV4::Value &name)
@@ -537,45 +537,45 @@ struct QQuickJSContext2D : public QV4::Object
{
V4_OBJECT2(QQuickJSContext2D, QV4::Object)
- static QV4::ReturnedValue method_get_globalAlpha(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_globalAlpha(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_globalCompositeOperation(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_globalCompositeOperation(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_fillStyle(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_fillStyle(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_fillRule(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_fillRule(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_strokeStyle(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_strokeStyle(QV4::CallContext *ctx);
-
- static QV4::ReturnedValue method_get_lineCap(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_lineCap(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_lineJoin(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_lineJoin(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_lineWidth(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_lineWidth(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_miterLimit(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_miterLimit(QV4::CallContext *ctx);
-
- static QV4::ReturnedValue method_get_shadowBlur(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_shadowBlur(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_shadowColor(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_shadowColor(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_shadowOffsetX(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_shadowOffsetX(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_shadowOffsetY(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_shadowOffsetY(QV4::CallContext *ctx);
+ static void method_get_globalAlpha(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_globalAlpha(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_globalCompositeOperation(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_globalCompositeOperation(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_fillStyle(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_fillStyle(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_fillRule(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_fillRule(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_strokeStyle(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_strokeStyle(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+
+ static void method_get_lineCap(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_lineCap(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_lineJoin(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_lineJoin(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_lineWidth(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_lineWidth(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_miterLimit(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_miterLimit(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+
+ static void method_get_shadowBlur(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_shadowBlur(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_shadowColor(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_shadowColor(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_shadowOffsetX(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_shadowOffsetX(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_shadowOffsetY(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_shadowOffsetY(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
// should these two be on the proto?
- static QV4::ReturnedValue method_get_path(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_path(QV4::CallContext *ctx);
-
- static QV4::ReturnedValue method_get_font(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_font(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_textAlign(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_textAlign(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_textBaseline(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_set_textBaseline(QV4::CallContext *ctx);
+ static void method_get_path(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_path(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+
+ static void method_get_font(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_font(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_textAlign(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_textAlign(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_textBaseline(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_set_textBaseline(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
};
DEFINE_OBJECT_VTABLE(QQuickJSContext2D);
@@ -638,50 +638,50 @@ public:
return o->d();
}
- static QV4::ReturnedValue method_get_canvas(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_restore(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_reset(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_save(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_rotate(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_scale(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_translate(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_setTransform(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_transform(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_resetTransform(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_shear(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_createLinearGradient(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_createRadialGradient(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_createConicalGradient(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_createPattern(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_clearRect(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_fillRect(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_strokeRect(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_arc(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_arcTo(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_beginPath(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_bezierCurveTo(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_clip(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_closePath(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_fill(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_lineTo(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_moveTo(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_quadraticCurveTo(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_rect(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_roundedRect(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_ellipse(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_text(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_stroke(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_isPointInPath(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_drawFocusRing(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_setCaretSelectionRect(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_caretBlinkRate(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_fillText(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_strokeText(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_measureText(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_drawImage(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_createImageData(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_getImageData(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_putImageData(QV4::CallContext *ctx);
+ static void method_get_canvas(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_restore(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_reset(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_save(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_rotate(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_scale(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_translate(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_setTransform(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_transform(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_resetTransform(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_shear(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_createLinearGradient(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_createRadialGradient(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_createConicalGradient(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_createPattern(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_clearRect(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_fillRect(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_strokeRect(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_arc(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_arcTo(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_beginPath(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_bezierCurveTo(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_clip(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_closePath(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_fill(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_lineTo(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_moveTo(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_quadraticCurveTo(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_rect(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_roundedRect(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_ellipse(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_text(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_stroke(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_isPointInPath(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_drawFocusRing(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_setCaretSelectionRect(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_caretBlinkRate(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_fillText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_strokeText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_measureText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_drawImage(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_createImageData(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_getImageData(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_putImageData(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
};
@@ -693,7 +693,7 @@ struct QQuickContext2DStyle : public QV4::Object
V4_OBJECT2(QQuickContext2DStyle, QV4::Object)
V4_NEEDS_DESTROY
- static QV4::ReturnedValue gradient_proto_addColorStop(QV4::CallContext *ctx);
+ static void gradient_proto_addColorStop(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
};
@@ -903,7 +903,7 @@ struct QQuickJSContext2DPixelData : public QV4::Object
static QV4::ReturnedValue getIndexed(const QV4::Managed *m, uint index, bool *hasProperty);
static void putIndexed(QV4::Managed *m, uint index, const QV4::Value &value);
- static QV4::ReturnedValue proto_get_length(QV4::CallContext *ctx);
+ static void proto_get_length(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
};
void QV4::Heap::QQuickJSContext2DPixelData::init()
@@ -921,9 +921,9 @@ struct QQuickJSContext2DImageData : public QV4::Object
{
V4_OBJECT2(QQuickJSContext2DImageData, QV4::Object)
- static QV4::ReturnedValue method_get_width(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_height(QV4::CallContext *ctx);
- static QV4::ReturnedValue method_get_data(QV4::CallContext *ctx);
+ static void method_get_width(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_height(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
+ static void method_get_data(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData);
static void markObjects(QV4::Heap::Base *that, QV4::ExecutionEngine *engine) {
static_cast<QQuickJSContext2DImageData::Data *>(that)->pixelData.mark(engine);
@@ -975,13 +975,12 @@ static QV4::ReturnedValue qt_create_image_data(qreal w, qreal h, QV4::ExecutionE
This property is read only.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_get_canvas(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_get_canvas(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- return QV4::QObjectWrapper::wrap(scope.engine, r->d()->context->canvas());
+ scope.result = QV4::QObjectWrapper::wrap(scope.engine, r->d()->context->canvas());
}
/*!
@@ -990,29 +989,27 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_get_canvas(QV4::CallContex
\sa save()
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_restore(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_restore(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
r->d()->context->popState();
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject.asReturnedValue();
}
/*!
\qmlmethod object QtQuick::Context2D::reset()
Resets the context state and properties to the default values.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_reset(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_reset(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
r->d()->context->reset();
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject.asReturnedValue();
}
/*!
@@ -1045,15 +1042,14 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_reset(QV4::CallContext *ct
The current path is NOT part of the drawing state. The path can be reset by
invoking the beginPath() method.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_save(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_save(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
r->d()->context->pushState();
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
}
// transformations
@@ -1074,15 +1070,14 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_save(QV4::CallContext *ctx
where the \a angle of rotation is in radians.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_rotate(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_rotate(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- if (ctx->argc() >= 1)
- r->d()->context->rotate(ctx->args()[0].toNumber());
- return ctx->thisObject().asReturnedValue();
+ if (callData->argc >= 1)
+ r->d()->context->rotate(callData->args[0].toNumber());
+ scope.result = callData->thisObject;
}
/*!
@@ -1102,16 +1097,16 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_rotate(QV4::CallContext *c
\image qml-item-canvas-scale.png
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_scale(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_scale(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- if (ctx->argc() >= 2)
- r->d()->context->scale(ctx->args()[0].toNumber(), ctx->args()[1].toNumber());
- return ctx->thisObject().asReturnedValue();
+ if (callData->argc >= 2)
+ r->d()->context->scale(callData->args[0].toNumber(), callData->args[1].toNumber());
+ scope.result = callData->thisObject;
+
}
/*!
@@ -1148,22 +1143,22 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_scale(QV4::CallContext *ct
\sa transform()
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_setTransform(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_setTransform(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- if (ctx->argc() >= 6)
- r->d()->context->setTransform( ctx->args()[0].toNumber()
- , ctx->args()[1].toNumber()
- , ctx->args()[2].toNumber()
- , ctx->args()[3].toNumber()
- , ctx->args()[4].toNumber()
- , ctx->args()[5].toNumber());
+ if (callData->argc >= 6)
+ r->d()->context->setTransform( callData->args[0].toNumber()
+ , callData->args[1].toNumber()
+ , callData->args[2].toNumber()
+ , callData->args[3].toNumber()
+ , callData->args[4].toNumber()
+ , callData->args[5].toNumber());
+
+ scope.result = callData->thisObject;
- return ctx->thisObject().asReturnedValue();
}
/*!
@@ -1177,21 +1172,21 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_setTransform(QV4::CallCont
\sa setTransform()
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_transform(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_transform(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- if (ctx->argc() >= 6)
- r->d()->context->transform( ctx->args()[0].toNumber()
- , ctx->args()[1].toNumber()
- , ctx->args()[2].toNumber()
- , ctx->args()[3].toNumber()
- , ctx->args()[4].toNumber()
- , ctx->args()[5].toNumber());
+ if (callData->argc >= 6)
+ r->d()->context->transform( callData->args[0].toNumber()
+ , callData->args[1].toNumber()
+ , callData->args[2].toNumber()
+ , callData->args[3].toNumber()
+ , callData->args[4].toNumber()
+ , callData->args[5].toNumber());
+
+ scope.result = callData->thisObject;
- return ctx->thisObject().asReturnedValue();
}
/*!
@@ -1203,15 +1198,15 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_transform(QV4::CallContext
Translating the origin enables you to draw patterns of different objects on the canvas
without having to measure the coordinates manually for each shape.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_translate(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_translate(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- if (ctx->argc() >= 2)
- r->d()->context->translate(ctx->args()[0].toNumber(), ctx->args()[1].toNumber());
- return ctx->thisObject().asReturnedValue();
+ if (callData->argc >= 2)
+ r->d()->context->translate(callData->args[0].toNumber(), callData->args[1].toNumber());
+ scope.result = callData->thisObject;
+
}
@@ -1223,15 +1218,15 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_translate(QV4::CallContext
\sa transform(), setTransform(), reset()
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_resetTransform(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_resetTransform(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
r->d()->context->setTransform(1, 0, 0, 1, 0, 0);
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
+
}
@@ -1241,16 +1236,16 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_resetTransform(QV4::CallCo
Shears the transformation matrix by \a sh in the horizontal direction and
\a sv in the vertical direction.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_shear(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_shear(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- if (ctx->argc() >= 2)
- r->d()->context->shear(ctx->args()[0].toNumber(), ctx->args()[1].toNumber());
+ if (callData->argc >= 2)
+ r->d()->context->shear(callData->args[0].toNumber(), callData->args[1].toNumber());
+
+ scope.result = callData->thisObject;
- return ctx->thisObject().asReturnedValue();
}
// compositing
@@ -1261,31 +1256,30 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_shear(QV4::CallContext *ct
The value must be in the range from \c 0.0 (fully transparent) to \c 1.0 (fully opaque).
The default value is \c 1.0.
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_globalAlpha(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_globalAlpha(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- return QV4::Encode(r->d()->context->state.globalAlpha);
+ scope.result = QV4::Encode(r->d()->context->state.globalAlpha);
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_globalAlpha(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_globalAlpha(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT_SETTER(r)
- double globalAlpha = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
+ double globalAlpha = callData->argc ? callData->args[0].toNumber() : qt_qnan();
+
+ scope.result = QV4::Encode::undefined();
if (!qt_is_finite(globalAlpha))
- return QV4::Encode::undefined();
+ return;
if (globalAlpha >= 0.0 && globalAlpha <= 1.0 && r->d()->context->state.globalAlpha != globalAlpha) {
r->d()->context->state.globalAlpha = globalAlpha;
r->d()->context->buffer()->setGlobalAlpha(r->d()->context->state.globalAlpha);
}
- return QV4::Encode::undefined();
}
/*!
@@ -1314,34 +1308,33 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_globalAlpha(QV4::CallContext *c
extension composition modes are provided as "vendorName-operationName" syntax, for example: QPainter::CompositionMode_Exclusion is provided as
"qt-exclusion".
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_globalCompositeOperation(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_globalCompositeOperation(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- return QV4::Encode(scope.engine->newString(qt_composite_mode_to_string(r->d()->context->state.globalCompositeOperation)));
+ scope.result = scope.engine->newString(qt_composite_mode_to_string(r->d()->context->state.globalCompositeOperation));
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_globalCompositeOperation(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_globalCompositeOperation(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT_SETTER(r)
- if (!ctx->argc())
- return ctx->engine()->throwTypeError();
+ if (!callData->argc)
+ THROW_TYPE_ERROR();
- QString mode = ctx->args()[0].toQString();
+ scope.result = QV4::Encode::undefined();
+
+ QString mode = callData->args[0].toQString();
QPainter::CompositionMode cm = qt_composite_mode_from_string(mode);
if (cm == QPainter::CompositionMode_SourceOver && mode != QLatin1String("source-over"))
- return QV4::Encode::undefined();
+ return;
if (cm != r->d()->context->state.globalCompositeOperation) {
r->d()->context->state.globalCompositeOperation = cm;
r->d()->context->buffer()->setGlobalCompositeOperation(cm);
}
- return QV4::Encode::undefined();
}
// colors and styles
@@ -1367,34 +1360,32 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_globalCompositeOperation(QV4::C
\sa createPattern()
\sa strokeStyle
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_fillStyle(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_fillStyle(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
QColor color = r->d()->context->state.fillStyle.color();
if (color.isValid()) {
if (color.alpha() == 255)
- return QV4::Encode(scope.engine->newString(color.name()));
+ RETURN_RESULT(scope.engine->newString(color.name()));
QString alphaString = QString::number(color.alphaF(), 'f');
while (alphaString.endsWith(QLatin1Char('0')))
alphaString.chop(1);
if (alphaString.endsWith(QLatin1Char('.')))
alphaString += QLatin1Char('0');
QString str = QString::fromLatin1("rgba(%1, %2, %3, %4)").arg(color.red()).arg(color.green()).arg(color.blue()).arg(alphaString);
- return QV4::Encode(scope.engine->newString(str));
+ RETURN_RESULT(scope.engine->newString(str));
}
- return r->d()->context->m_fillStyle.value();
+ scope.result = r->d()->context->m_fillStyle.value();
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_fillStyle(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_fillStyle(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT_SETTER(r)
- QV4::ScopedValue value(scope, ctx->argument(0));
+ QV4::ScopedValue value(scope, callData->argument(0));
if (value->as<Object>()) {
QColor color = scope.engine->toVariant(value, qMetaTypeId<QColor>()).value<QColor>();
@@ -1420,7 +1411,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_fillStyle(QV4::CallContext *ctx
r->d()->context->m_fillStyle.set(scope.engine, value);
}
}
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
/*!
\qmlproperty enumeration QtQuick::Context2D::fillRule
@@ -1434,22 +1425,20 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_fillStyle(QV4::CallContext *ctx
\sa fillStyle
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_fillRule(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_fillRule(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- return scope.engine->fromVariant(r->d()->context->state.fillRule);
+ scope.result = scope.engine->fromVariant(r->d()->context->state.fillRule);
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_fillRule(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_fillRule(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT_SETTER(r)
- QV4::ScopedValue value(scope, ctx->argument(0));
+ QV4::ScopedValue value(scope, callData->argument(0));
if ((value->isString() && value->toQString() == QLatin1String("WindingFill"))
|| (value->isInt32() && value->integerValue() == Qt::WindingFill)) {
@@ -1461,7 +1450,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_fillRule(QV4::CallContext *ctx)
//error
}
r->d()->context->m_path.setFillRule(r->d()->context->state.fillRule);
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
/*!
\qmlproperty variant QtQuick::Context2D::strokeStyle
@@ -1476,34 +1465,32 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_fillRule(QV4::CallContext *ctx)
\sa createPattern()
\sa fillStyle
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_strokeStyle(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_strokeStyle(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
QColor color = r->d()->context->state.strokeStyle.color();
if (color.isValid()) {
if (color.alpha() == 255)
- return QV4::Encode(scope.engine->newString(color.name()));
+ RETURN_RESULT(scope.engine->newString(color.name()));
QString alphaString = QString::number(color.alphaF(), 'f');
while (alphaString.endsWith(QLatin1Char('0')))
alphaString.chop(1);
if (alphaString.endsWith(QLatin1Char('.')))
alphaString += QLatin1Char('0');
QString str = QString::fromLatin1("rgba(%1, %2, %3, %4)").arg(color.red()).arg(color.green()).arg(color.blue()).arg(alphaString);
- return QV4::Encode(scope.engine->newString(str));
+ RETURN_RESULT(scope.engine->newString(str));
}
- return r->d()->context->m_strokeStyle.value();
+ scope.result = r->d()->context->m_strokeStyle.value();
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_strokeStyle(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_strokeStyle(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT_SETTER(r)
- QV4::ScopedValue value(scope, ctx->argument(0));
+ QV4::ScopedValue value(scope, callData->argument(0));
if (value->as<Object>()) {
QColor color = scope.engine->toVariant(value, qMetaTypeId<QColor>()).value<QColor>();
@@ -1530,7 +1517,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_strokeStyle(QV4::CallContext *c
r->d()->context->m_strokeStyle.set(scope.engine, value);
}
}
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
/*!
@@ -1550,23 +1537,22 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_strokeStyle(QV4::CallContext *c
\sa strokeStyle
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_createLinearGradient(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_createLinearGradient(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- if (ctx->argc() >= 4) {
- qreal x0 = ctx->args()[0].toNumber();
- qreal y0 = ctx->args()[1].toNumber();
- qreal x1 = ctx->args()[2].toNumber();
- qreal y1 = ctx->args()[3].toNumber();
+ if (callData->argc >= 4) {
+ qreal x0 = callData->args[0].toNumber();
+ qreal y0 = callData->args[1].toNumber();
+ qreal x1 = callData->args[2].toNumber();
+ qreal y1 = callData->args[3].toNumber();
if (!qt_is_finite(x0)
|| !qt_is_finite(y0)
|| !qt_is_finite(x1)
|| !qt_is_finite(y1)) {
- V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createLinearGradient(): Incorrect arguments")
+ THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createLinearGradient(): Incorrect arguments")
}
QQuickContext2DEngineData *ed = engineData(scope.engine);
@@ -1574,10 +1560,11 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createLinearGradient(QV4::
QV4::ScopedObject p(scope, ed->gradientProto.value());
gradient->setPrototype(p);
*gradient->d()->brush = QLinearGradient(x0, y0, x1, y1);
- return gradient.asReturnedValue();
+ RETURN_RESULT(gradient);
}
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
+
}
/*!
@@ -1593,19 +1580,18 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createLinearGradient(QV4::
\sa strokeStyle
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_createRadialGradient(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_createRadialGradient(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- if (ctx->argc() >= 6) {
- qreal x0 = ctx->args()[0].toNumber();
- qreal y0 = ctx->args()[1].toNumber();
- qreal r0 = ctx->args()[2].toNumber();
- qreal x1 = ctx->args()[3].toNumber();
- qreal y1 = ctx->args()[4].toNumber();
- qreal r1 = ctx->args()[5].toNumber();
+ if (callData->argc >= 6) {
+ qreal x0 = callData->args[0].toNumber();
+ qreal y0 = callData->args[1].toNumber();
+ qreal r0 = callData->args[2].toNumber();
+ qreal x1 = callData->args[3].toNumber();
+ qreal y1 = callData->args[4].toNumber();
+ qreal r1 = callData->args[5].toNumber();
if (!qt_is_finite(x0)
|| !qt_is_finite(y0)
@@ -1613,11 +1599,11 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createRadialGradient(QV4::
|| !qt_is_finite(r0)
|| !qt_is_finite(r1)
|| !qt_is_finite(y1)) {
- V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createRadialGradient(): Incorrect arguments")
+ THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createRadialGradient(): Incorrect arguments")
}
if (r0 < 0 || r1 < 0)
- V4THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createRadialGradient(): Incorrect arguments")
+ THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createRadialGradient(): Incorrect arguments")
QQuickContext2DEngineData *ed = engineData(scope.engine);
@@ -1625,10 +1611,11 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createRadialGradient(QV4::
QV4::ScopedObject p(scope, ed->gradientProto.value());
gradient->setPrototype(p);
*gradient->d()->brush = QRadialGradient(QPointF(x1, y1), r0+r1, QPointF(x0, y0));
- return gradient.asReturnedValue();
+ RETURN_RESULT(gradient);
}
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
+
}
/*!
@@ -1644,22 +1631,21 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createRadialGradient(QV4::
\sa strokeStyle
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_createConicalGradient(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_createConicalGradient(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- if (ctx->argc() >= 3) {
- qreal x = ctx->args()[0].toNumber();
- qreal y = ctx->args()[1].toNumber();
- qreal angle = DEGREES(ctx->args()[2].toNumber());
+ if (callData->argc >= 3) {
+ qreal x = callData->args[0].toNumber();
+ qreal y = callData->args[1].toNumber();
+ qreal angle = DEGREES(callData->args[2].toNumber());
if (!qt_is_finite(x) || !qt_is_finite(y)) {
- V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createConicalGradient(): Incorrect arguments");
+ THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createConicalGradient(): Incorrect arguments");
}
if (!qt_is_finite(angle)) {
- V4THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createConicalGradient(): Incorrect arguments");
+ THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createConicalGradient(): Incorrect arguments");
}
QQuickContext2DEngineData *ed = engineData(scope.engine);
@@ -1668,10 +1654,11 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createConicalGradient(QV4:
QV4::ScopedObject p(scope, ed->gradientProto.value());
gradient->setPrototype(p);
*gradient->d()->brush = QConicalGradient(x, y, angle);
- return gradient.asReturnedValue();
+ RETURN_RESULT(gradient);
}
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
+
}
/*!
\qmlmethod variant QtQuick::Context2D::createPattern(color color, enumeration patternMode)
@@ -1716,18 +1703,17 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createConicalGradient(QV4:
\sa strokeStyle
\sa fillStyle
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_createPattern(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_createPattern(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 2) {
+ if (callData->argc >= 2) {
QV4::Scoped<QQuickContext2DStyle> pattern(scope, scope.engine->memoryManager->allocObject<QQuickContext2DStyle>());
- QColor color = scope.engine->toVariant(ctx->args()[0], qMetaTypeId<QColor>()).value<QColor>();
+ QColor color = scope.engine->toVariant(callData->args[0], qMetaTypeId<QColor>()).value<QColor>();
if (color.isValid()) {
- int patternMode = ctx->args()[1].toInt32();
+ int patternMode = callData->args[1].toInt32();
Qt::BrushStyle style = Qt::SolidPattern;
if (patternMode >= 0 && patternMode < Qt::LinearGradientPattern) {
style = static_cast<Qt::BrushStyle>(patternMode);
@@ -1736,20 +1722,20 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createPattern(QV4::CallCon
} else {
QImage patternTexture;
- if (const QV4::Object *o = ctx->args()[0].as<Object>()) {
+ if (const QV4::Object *o = callData->args[0].as<Object>()) {
QV4::ScopedString s(scope, scope.engine->newString(QStringLiteral("data")));
QV4::Scoped<QQuickJSContext2DPixelData> pixelData(scope, o->get(s));
if (!!pixelData) {
patternTexture = *pixelData->d()->image;
}
} else {
- patternTexture = r->d()->context->createPixmap(QUrl(ctx->args()[0].toQStringNoThrow()))->image();
+ patternTexture = r->d()->context->createPixmap(QUrl(callData->args[0].toQStringNoThrow()))->image();
}
if (!patternTexture.isNull()) {
pattern->d()->brush->setTextureImage(patternTexture);
- QString repetition = ctx->args()[1].toQStringNoThrow();
+ QString repetition = callData->args[1].toQStringNoThrow();
if (repetition == QLatin1String("repeat") || repetition.isEmpty()) {
pattern->d()->patternRepeatX = true;
pattern->d()->patternRepeatY = true;
@@ -1769,10 +1755,10 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createPattern(QV4::CallCon
}
}
- return pattern.asReturnedValue();
+ RETURN_RESULT(pattern);
}
- return QV4::Encode::undefined();
+ scope.result = QV4::Encode::undefined();
}
// line styles
@@ -1787,31 +1773,29 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_createPattern(QV4::CallCon
\endlist
Other values are ignored.
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_lineCap(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_lineCap(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
switch (r->d()->context->state.lineCap) {
case Qt::RoundCap:
- return QV4::Encode(scope.engine->newString(QStringLiteral("round")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("round")));
case Qt::SquareCap:
- return QV4::Encode(scope.engine->newString(QStringLiteral("square")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("square")));
case Qt::FlatCap:
default:
break;
}
- return QV4::Encode(scope.engine->newString(QStringLiteral("butt")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("butt")));
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_lineCap(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_lineCap(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT_SETTER(r)
- QString lineCap = ctx->args()[0].toQString();
+ QString lineCap = callData->args[0].toQString();
Qt::PenCapStyle cap;
if (lineCap == QLatin1String("round"))
cap = Qt::RoundCap;
@@ -1820,13 +1804,13 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_lineCap(QV4::CallContext *ctx)
else if (lineCap == QLatin1String("square"))
cap = Qt::SquareCap;
else
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
if (cap != r->d()->context->state.lineCap) {
r->d()->context->state.lineCap = cap;
r->d()->context->buffer()->setLineCap(cap);
}
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
/*!
@@ -1843,34 +1827,32 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_lineCap(QV4::CallContext *ctx)
\endlist
Other values are ignored.
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_lineJoin(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_lineJoin(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
switch (r->d()->context->state.lineJoin) {
case Qt::RoundJoin:
- return QV4::Encode(scope.engine->newString(QStringLiteral("round")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("round")));
case Qt::BevelJoin:
- return QV4::Encode(scope.engine->newString(QStringLiteral("bevel")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("bevel")));
case Qt::MiterJoin:
default:
break;
}
- return QV4::Encode(scope.engine->newString(QStringLiteral("miter")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("miter")));
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_lineJoin(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_lineJoin(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT_SETTER(r)
- if (!ctx->argc())
- return ctx->engine()->throwTypeError();
+ if (!callData->argc)
+ THROW_TYPE_ERROR();
- QString lineJoin = ctx->args()[0].toQString();
+ QString lineJoin = callData->args[0].toQString();
Qt::PenJoinStyle join;
if (lineJoin == QLatin1String("round"))
join = Qt::RoundJoin;
@@ -1879,41 +1861,39 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_lineJoin(QV4::CallContext *ctx)
else if (lineJoin == QLatin1String("miter"))
join = Qt::SvgMiterJoin;
else
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
if (join != r->d()->context->state.lineJoin) {
r->d()->context->state.lineJoin = join;
r->d()->context->buffer()->setLineJoin(join);
}
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
/*!
\qmlproperty real QtQuick::Context2D::lineWidth
Holds the current line width. Values that are not finite values greater than zero are ignored.
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_lineWidth(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_lineWidth(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- return QV4::Encode(r->d()->context->state.lineWidth);
+ RETURN_RESULT(QV4::Encode(r->d()->context->state.lineWidth));
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_lineWidth(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_lineWidth(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT_SETTER(r)
- qreal w = ctx->argc() ? ctx->args()[0].toNumber() : -1;
+ qreal w = callData->argc ? callData->args[0].toNumber() : -1;
if (w > 0 && qt_is_finite(w) && w != r->d()->context->state.lineWidth) {
r->d()->context->state.lineWidth = w;
r->d()->context->buffer()->setLineWidth(w);
}
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
/*!
@@ -1921,28 +1901,26 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_lineWidth(QV4::CallContext *ctx
Holds the current miter limit ratio.
The default miter limit value is 10.0.
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_miterLimit(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_miterLimit(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- return QV4::Encode(r->d()->context->state.miterLimit);
+ RETURN_RESULT(QV4::Encode(r->d()->context->state.miterLimit));
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_miterLimit(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_miterLimit(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT_SETTER(r)
- qreal ml = ctx->argc() ? ctx->args()[0].toNumber() : -1;
+ qreal ml = callData->argc ? callData->args[0].toNumber() : -1;
if (ml > 0 && qt_is_finite(ml) && ml != r->d()->context->state.miterLimit) {
r->d()->context->state.miterLimit = ml;
r->d()->context->buffer()->setMiterLimit(ml);
}
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
// shadows
@@ -1950,58 +1928,54 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_miterLimit(QV4::CallContext *ct
\qmlproperty real QtQuick::Context2D::shadowBlur
Holds the current level of blur applied to shadows
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_shadowBlur(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_shadowBlur(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- return QV4::Encode(r->d()->context->state.shadowBlur);
+ RETURN_RESULT(QV4::Encode(r->d()->context->state.shadowBlur));
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_shadowBlur(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_shadowBlur(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT_SETTER(r)
- qreal blur = ctx->argc() ? ctx->args()[0].toNumber() : -1;
+ qreal blur = callData->argc ? callData->args[0].toNumber() : -1;
if (blur > 0 && qt_is_finite(blur) && blur != r->d()->context->state.shadowBlur) {
r->d()->context->state.shadowBlur = blur;
r->d()->context->buffer()->setShadowBlur(blur);
}
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
/*!
\qmlproperty string QtQuick::Context2D::shadowColor
Holds the current shadow color.
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_shadowColor(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_shadowColor(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- return QV4::Encode(scope.engine->newString(r->d()->context->state.shadowColor.name()));
+ RETURN_RESULT(scope.engine->newString(r->d()->context->state.shadowColor.name()));
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_shadowColor(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_shadowColor(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT_SETTER(r)
QColor color;
- if (ctx->argc())
- color = qt_color_from_string(ctx->args()[0]);
+ if (callData->argc)
+ color = qt_color_from_string(callData->args[0]);
if (color.isValid() && color != r->d()->context->state.shadowColor) {
r->d()->context->state.shadowColor = color;
r->d()->context->buffer()->setShadowColor(color);
}
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
@@ -2011,27 +1985,25 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_shadowColor(QV4::CallContext *c
\sa shadowOffsetY
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_shadowOffsetX(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_shadowOffsetX(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- return QV4::Encode(r->d()->context->state.shadowOffsetX);
+ RETURN_RESULT(QV4::Encode(r->d()->context->state.shadowOffsetX));
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_shadowOffsetX(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_shadowOffsetX(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT_SETTER(r)
- qreal offsetX = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
+ qreal offsetX = callData->argc ? callData->args[0].toNumber() : qt_qnan();
if (qt_is_finite(offsetX) && offsetX != r->d()->context->state.shadowOffsetX) {
r->d()->context->state.shadowOffsetX = offsetX;
r->d()->context->buffer()->setShadowOffsetX(offsetX);
}
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
/*!
\qmlproperty qreal QtQuick::Context2D::shadowOffsetY
@@ -2039,45 +2011,41 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_shadowOffsetX(QV4::CallContext
\sa shadowOffsetX
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_shadowOffsetY(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_shadowOffsetY(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- return QV4::Encode(r->d()->context->state.shadowOffsetY);
+ RETURN_RESULT(QV4::Encode(r->d()->context->state.shadowOffsetY));
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_shadowOffsetY(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_shadowOffsetY(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT_SETTER(r)
- qreal offsetY = ctx->argc() ? ctx->args()[0].toNumber() : qt_qnan();
+ qreal offsetY = callData->argc ? callData->args[0].toNumber() : qt_qnan();
if (qt_is_finite(offsetY) && offsetY != r->d()->context->state.shadowOffsetY) {
r->d()->context->state.shadowOffsetY = offsetY;
r->d()->context->buffer()->setShadowOffsetY(offsetY);
}
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
-QV4::ReturnedValue QQuickJSContext2D::method_get_path(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_path(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- return r->d()->context->m_v4path.value();
+ scope.result = r->d()->context->m_v4path.value();
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_path(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_path(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT_SETTER(r)
- QV4::ScopedValue value(scope, ctx->argument(0));
+ QV4::ScopedValue value(scope, callData->argument(0));
r->d()->context->beginPath();
QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, value);
if (!!qobjectWrapper) {
@@ -2088,7 +2056,7 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_path(QV4::CallContext *ctx)
QQuickSvgParser::parsePathDataFast(path, r->d()->context->m_path);
}
r->d()->context->m_v4path.set(scope.engine, value);
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
//rects
@@ -2096,20 +2064,20 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_path(QV4::CallContext *ctx)
\qmlmethod object QtQuick::Context2D::clearRect(real x, real y, real w, real h)
Clears all pixels on the canvas in the given rectangle to transparent black.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_clearRect(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_clearRect(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 4)
- r->d()->context->clearRect(ctx->args()[0].toNumber(),
- ctx->args()[1].toNumber(),
- ctx->args()[2].toNumber(),
- ctx->args()[3].toNumber());
+ if (callData->argc >= 4)
+ r->d()->context->clearRect(callData->args[0].toNumber(),
+ callData->args[1].toNumber(),
+ callData->args[2].toNumber(),
+ callData->args[3].toNumber());
+
+ scope.result = callData->thisObject;
- return ctx->thisObject().asReturnedValue();
}
/*!
\qmlmethod object QtQuick::Context2D::fillRect(real x, real y, real w, real h)
@@ -2117,15 +2085,15 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_clearRect(QV4::CallContext
\sa fillStyle
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_fillRect(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_fillRect(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 4)
- r->d()->context->fillRect(ctx->args()[0].toNumber(), ctx->args()[1].toNumber(), ctx->args()[2].toNumber(), ctx->args()[3].toNumber());
- return ctx->thisObject().asReturnedValue();
+ if (callData->argc >= 4)
+ r->d()->context->fillRect(callData->args[0].toNumber(), callData->args[1].toNumber(), callData->args[2].toNumber(), callData->args[3].toNumber());
+ scope.result = callData->thisObject;
+
}
/*!
@@ -2138,16 +2106,16 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_fillRect(QV4::CallContext
\sa lineJoin
\sa miterLimit
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_strokeRect(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_strokeRect(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 4)
- r->d()->context->strokeRect(ctx->args()[0].toNumber(), ctx->args()[1].toNumber(), ctx->args()[2].toNumber(), ctx->args()[3].toNumber());
+ if (callData->argc >= 4)
+ r->d()->context->strokeRect(callData->args[0].toNumber(), callData->args[1].toNumber(), callData->args[2].toNumber(), callData->args[3].toNumber());
+
+ scope.result = callData->thisObject;
- return ctx->thisObject().asReturnedValue();
}
// Complex shapes (paths) API
@@ -2171,32 +2139,32 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_strokeRect(QV4::CallContex
\sa arcTo, {http://www.w3.org/TR/2dcontext/#dom-context-2d-arc}{W3C's 2D
Context Standard for arc()}
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_arc(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_arc(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 5) {
+ if (callData->argc >= 5) {
bool antiClockwise = false;
- if (ctx->argc() == 6)
- antiClockwise = ctx->args()[5].toBoolean();
+ if (callData->argc == 6)
+ antiClockwise = callData->args[5].toBoolean();
- qreal radius = ctx->args()[2].toNumber();
+ qreal radius = callData->args[2].toNumber();
if (qt_is_finite(radius) && radius < 0)
- V4THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "Incorrect argument radius");
+ THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "Incorrect argument radius");
- r->d()->context->arc(ctx->args()[0].toNumber(),
- ctx->args()[1].toNumber(),
+ r->d()->context->arc(callData->args[0].toNumber(),
+ callData->args[1].toNumber(),
radius,
- ctx->args()[3].toNumber(),
- ctx->args()[4].toNumber(),
+ callData->args[3].toNumber(),
+ callData->args[4].toNumber(),
antiClockwise);
}
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
+
}
/*!
@@ -2222,26 +2190,26 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_arc(QV4::CallContext *ctx)
\sa arc, {http://www.w3.org/TR/2dcontext/#dom-context-2d-arcto}{W3C's 2D
Context Standard for arcTo()}
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_arcTo(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_arcTo(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 5) {
- qreal radius = ctx->args()[4].toNumber();
+ if (callData->argc >= 5) {
+ qreal radius = callData->args[4].toNumber();
if (qt_is_finite(radius) && radius < 0)
- V4THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "Incorrect argument radius");
+ THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "Incorrect argument radius");
- r->d()->context->arcTo(ctx->args()[0].toNumber(),
- ctx->args()[1].toNumber(),
- ctx->args()[2].toNumber(),
- ctx->args()[3].toNumber(),
+ r->d()->context->arcTo(callData->args[0].toNumber(),
+ callData->args[1].toNumber(),
+ callData->args[2].toNumber(),
+ callData->args[3].toNumber(),
radius);
}
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
+
}
/*!
@@ -2249,15 +2217,15 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_arcTo(QV4::CallContext *ct
Resets the current path to a new path.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_beginPath(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_beginPath(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
r->d()->context->beginPath();
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
+
}
/*!
@@ -2279,28 +2247,26 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_beginPath(QV4::CallContext
\sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-beziercurveto}{W3C 2d context standard for bezierCurveTo}
\sa {http://www.openrise.com/lab/FlowerPower/}{The beautiful flower demo by using bezierCurveTo}
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_bezierCurveTo(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_bezierCurveTo(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
+ scope.result = callData->thisObject;
- if (ctx->argc() >= 6) {
- qreal cp1x = ctx->args()[0].toNumber();
- qreal cp1y = ctx->args()[1].toNumber();
- qreal cp2x = ctx->args()[2].toNumber();
- qreal cp2y = ctx->args()[3].toNumber();
- qreal x = ctx->args()[4].toNumber();
- qreal y = ctx->args()[5].toNumber();
+ if (callData->argc >= 6) {
+ qreal cp1x = callData->args[0].toNumber();
+ qreal cp1y = callData->args[1].toNumber();
+ qreal cp2x = callData->args[2].toNumber();
+ qreal cp2y = callData->args[3].toNumber();
+ qreal x = callData->args[4].toNumber();
+ qreal y = callData->args[5].toNumber();
if (!qt_is_finite(cp1x) || !qt_is_finite(cp1y) || !qt_is_finite(cp2x) || !qt_is_finite(cp2y) || !qt_is_finite(x) || !qt_is_finite(y))
- return ctx->thisObject().asReturnedValue();
+ return;
r->d()->context->bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
}
-
- return ctx->thisObject().asReturnedValue();
}
/*!
@@ -2327,14 +2293,13 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_bezierCurveTo(QV4::CallCon
\sa fill()
\sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-clip}{W3C 2d context standard for clip}
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_clip(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_clip(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
r->d()->context->clip();
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
}
/*!
@@ -2344,16 +2309,15 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_clip(QV4::CallContext *ctx
\sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-closepath}{W3C 2d context standard for closePath}
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_closePath(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_closePath(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
r->d()->context->closePath();
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
}
/*!
@@ -2365,13 +2329,12 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_closePath(QV4::CallContext
\sa fillStyle
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_fill(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_fill(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r);
r->d()->context->fill();
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
}
/*!
@@ -2379,24 +2342,22 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_fill(QV4::CallContext *ctx
Draws a line from the current position to the point (x, y).
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_lineTo(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_lineTo(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
+ scope.result = callData->thisObject;
- if (ctx->argc() >= 2) {
- qreal x = ctx->args()[0].toNumber();
- qreal y = ctx->args()[1].toNumber();
+ if (callData->argc >= 2) {
+ qreal x = callData->args[0].toNumber();
+ qreal y = callData->args[1].toNumber();
if (!qt_is_finite(x) || !qt_is_finite(y))
- return ctx->thisObject().asReturnedValue();
+ return;
r->d()->context->lineTo(x, y);
}
-
- return ctx->thisObject().asReturnedValue();
}
/*!
@@ -2404,21 +2365,21 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_lineTo(QV4::CallContext *c
Creates a new subpath with the given point.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_moveTo(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_moveTo(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 2) {
- qreal x = ctx->args()[0].toNumber();
- qreal y = ctx->args()[1].toNumber();
+ scope.result = callData->thisObject;
+
+ if (callData->argc >= 2) {
+ qreal x = callData->args[0].toNumber();
+ qreal y = callData->args[1].toNumber();
if (!qt_is_finite(x) || !qt_is_finite(y))
- return ctx->thisObject().asReturnedValue();
+ return;
r->d()->context->moveTo(x, y);
}
- return ctx->thisObject().asReturnedValue();
}
/*!
@@ -2428,25 +2389,24 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_moveTo(QV4::CallContext *c
See \l{http://www.w3.org/TR/2dcontext/#dom-context-2d-quadraticcurveto}{W3C 2d context standard for quadraticCurveTo}
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_quadraticCurveTo(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_quadraticCurveTo(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 4) {
- qreal cpx = ctx->args()[0].toNumber();
- qreal cpy = ctx->args()[1].toNumber();
- qreal x = ctx->args()[2].toNumber();
- qreal y = ctx->args()[3].toNumber();
+ scope.result = callData->thisObject;
+
+ if (callData->argc >= 4) {
+ qreal cpx = callData->args[0].toNumber();
+ qreal cpy = callData->args[1].toNumber();
+ qreal x = callData->args[2].toNumber();
+ qreal y = callData->args[3].toNumber();
if (!qt_is_finite(cpx) || !qt_is_finite(cpy) || !qt_is_finite(x) || !qt_is_finite(y))
- return ctx->thisObject().asReturnedValue();
+ return;
r->d()->context->quadraticCurveTo(cpx, cpy, x, y);
}
-
- return ctx->thisObject().asReturnedValue();
}
/*!
@@ -2454,15 +2414,15 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_quadraticCurveTo(QV4::Call
Adds a rectangle at position (\c x, \c y), with the given width \c w and height \c h, as a closed subpath.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_rect(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_rect(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 4)
- r->d()->context->rect(ctx->args()[0].toNumber(), ctx->args()[1].toNumber(), ctx->args()[2].toNumber(), ctx->args()[3].toNumber());
- return ctx->thisObject().asReturnedValue();
+ if (callData->argc >= 4)
+ r->d()->context->rect(callData->args[0].toNumber(), callData->args[1].toNumber(), callData->args[2].toNumber(), callData->args[3].toNumber());
+ scope.result = callData->thisObject;
+
}
/*!
@@ -2471,20 +2431,20 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_rect(QV4::CallContext *ctx
Adds the given rectangle rect with rounded corners to the path. The \c xRadius and \c yRadius arguments specify the radius of the
ellipses defining the corners of the rounded rectangle.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_roundedRect(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_roundedRect(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 6)
- r->d()->context->roundedRect(ctx->args()[0].toNumber()
- , ctx->args()[1].toNumber()
- , ctx->args()[2].toNumber()
- , ctx->args()[3].toNumber()
- , ctx->args()[4].toNumber()
- , ctx->args()[5].toNumber());
- return ctx->thisObject().asReturnedValue();
+ if (callData->argc >= 6)
+ r->d()->context->roundedRect(callData->args[0].toNumber()
+ , callData->args[1].toNumber()
+ , callData->args[2].toNumber()
+ , callData->args[3].toNumber()
+ , callData->args[4].toNumber()
+ , callData->args[5].toNumber());
+ scope.result = callData->thisObject;
+
}
/*!
@@ -2495,17 +2455,17 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_roundedRect(QV4::CallConte
The ellipse is composed of a clockwise curve, starting and finishing at zero degrees (the 3 o'clock position).
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_ellipse(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_ellipse(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 4)
- r->d()->context->ellipse(ctx->args()[0].toNumber(), ctx->args()[1].toNumber(), ctx->args()[2].toNumber(), ctx->args()[3].toNumber());
+ if (callData->argc >= 4)
+ r->d()->context->ellipse(callData->args[0].toNumber(), callData->args[1].toNumber(), callData->args[2].toNumber(), callData->args[3].toNumber());
+
+ scope.result = callData->thisObject;
- return ctx->thisObject().asReturnedValue();
}
/*!
@@ -2514,21 +2474,22 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_ellipse(QV4::CallContext *
Adds the given \c text to the path as a set of closed subpaths created from the current context font supplied.
The subpaths are positioned so that the left end of the text's baseline lies at the point specified by (\c x, \c y).
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_text(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_text(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 3) {
- qreal x = ctx->args()[1].toNumber();
- qreal y = ctx->args()[2].toNumber();
+ scope.result = callData->thisObject;
+
+ if (callData->argc >= 3) {
+ qreal x = callData->args[1].toNumber();
+ qreal y = callData->args[2].toNumber();
if (!qt_is_finite(x) || !qt_is_finite(y))
- return ctx->thisObject().asReturnedValue();
- r->d()->context->text(ctx->args()[0].toQStringNoThrow(), x, y);
+ return;
+ r->d()->context->text(callData->args[0].toQStringNoThrow(), x, y);
}
- return ctx->thisObject().asReturnedValue();
+
}
/*!
@@ -2540,14 +2501,14 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_text(QV4::CallContext *ctx
\sa strokeStyle
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_stroke(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_stroke(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
r->d()->context->stroke();
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
+
}
/*!
@@ -2557,37 +2518,30 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_stroke(QV4::CallContext *c
\sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-ispointinpath}{W3C 2d context standard for isPointInPath}
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_isPointInPath(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_isPointInPath(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
bool pointInPath = false;
- if (ctx->argc() >= 2)
- pointInPath = r->d()->context->isPointInPath(ctx->args()[0].toNumber(), ctx->args()[1].toNumber());
- return QV4::Primitive::fromBoolean(pointInPath).asReturnedValue();
+ if (callData->argc >= 2)
+ pointInPath = r->d()->context->isPointInPath(callData->args[0].toNumber(), callData->args[1].toNumber());
+ scope.result = QV4::Primitive::fromBoolean(pointInPath).asReturnedValue();
}
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_drawFocusRing(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_drawFocusRing(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *)
{
- QV4::Scope scope(ctx);
-
- V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "Context2D::drawFocusRing is not supported");
+ THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "Context2D::drawFocusRing is not supported");
}
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_setCaretSelectionRect(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_setCaretSelectionRect(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *)
{
- QV4::Scope scope(ctx);
-
- V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "Context2D::setCaretSelectionRect is not supported");
+ THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "Context2D::setCaretSelectionRect is not supported");
}
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_caretBlinkRate(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_caretBlinkRate(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *)
{
- QV4::Scope scope(ctx);
-
- V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "Context2D::caretBlinkRate is not supported");
+ THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "Context2D::caretBlinkRate is not supported");
}
/*!
@@ -2613,29 +2567,27 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_caretBlinkRate(QV4::CallCo
The default font value is "10px sans-serif".
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_font(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_font(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- return QV4::Encode(scope.engine->newString(r->d()->context->state.font.toString()));
+ RETURN_RESULT(scope.engine->newString(r->d()->context->state.font.toString()));
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_font(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_font(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT_SETTER(r)
- QV4::ScopedString s(scope, ctx->argument(0), QV4::ScopedString::Convert);
+ QV4::ScopedString s(scope, callData->argument(0), QV4::ScopedString::Convert);
if (scope.engine->hasException)
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
QFont font = qt_font_from_string(s->toQString(), r->d()->context->state.font);
if (font != r->d()->context->state.font) {
r->d()->context->state.font = font;
}
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
/*!
@@ -2652,37 +2604,35 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_font(QV4::CallContext *ctx)
\endlist
Other values are ignored. The default value is "start".
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_textAlign(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_textAlign(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
switch (r->d()->context->state.textAlign) {
case QQuickContext2D::End:
- return QV4::Encode(scope.engine->newString(QStringLiteral("end")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("end")));
case QQuickContext2D::Left:
- return QV4::Encode(scope.engine->newString(QStringLiteral("left")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("left")));
case QQuickContext2D::Right:
- return QV4::Encode(scope.engine->newString(QStringLiteral("right")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("right")));
case QQuickContext2D::Center:
- return QV4::Encode(scope.engine->newString(QStringLiteral("center")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("center")));
case QQuickContext2D::Start:
default:
break;
}
- return QV4::Encode(scope.engine->newString(QStringLiteral("start")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("start")));
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_textAlign(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_textAlign(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT_SETTER(r)
- QV4::ScopedString s(scope, ctx->argument(0), QV4::ScopedString::Convert);
+ QV4::ScopedString s(scope, callData->argument(0), QV4::ScopedString::Convert);
if (scope.engine->hasException)
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
QString textAlign = s->toQString();
QQuickContext2D::TextAlignType ta;
@@ -2697,12 +2647,12 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_textAlign(QV4::CallContext *ctx
else if (textAlign == QLatin1String("center"))
ta = QQuickContext2D::Center;
else
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
if (ta != r->d()->context->state.textAlign)
r->d()->context->state.textAlign = ta;
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
/*!
@@ -2720,36 +2670,34 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_textAlign(QV4::CallContext *ctx
\endlist
Other values are ignored. The default value is "alphabetic".
*/
-QV4::ReturnedValue QQuickJSContext2D::method_get_textBaseline(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_get_textBaseline(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
switch (r->d()->context->state.textBaseline) {
case QQuickContext2D::Hanging:
- return QV4::Encode(scope.engine->newString(QStringLiteral("hanging")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("hanging")));
case QQuickContext2D::Top:
- return QV4::Encode(scope.engine->newString(QStringLiteral("top")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("top")));
case QQuickContext2D::Bottom:
- return QV4::Encode(scope.engine->newString(QStringLiteral("bottom")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("bottom")));
case QQuickContext2D::Middle:
- return QV4::Encode(scope.engine->newString(QStringLiteral("middle")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("middle")));
case QQuickContext2D::Alphabetic:
default:
break;
}
- return QV4::Encode(scope.engine->newString(QStringLiteral("alphabetic")));
+ RETURN_RESULT(scope.engine->newString(QStringLiteral("alphabetic")));
}
-QV4::ReturnedValue QQuickJSContext2D::method_set_textBaseline(QV4::CallContext *ctx)
+void QQuickJSContext2D::method_set_textBaseline(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT_SETTER(r)
- QV4::ScopedString s(scope, ctx->argument(0), QV4::ScopedString::Convert);
+ QV4::ScopedString s(scope, callData->argument(0), QV4::ScopedString::Convert);
if (scope.engine->hasException)
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
QString textBaseline = s->toQString();
QQuickContext2D::TextBaseLineType tb;
@@ -2764,12 +2712,12 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_textBaseline(QV4::CallContext *
else if (textBaseline == QLatin1String("middle"))
tb = QQuickContext2D::Middle;
else
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
if (tb != r->d()->context->state.textBaseline)
r->d()->context->state.textBaseline = tb;
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
/*!
@@ -2780,21 +2728,21 @@ QV4::ReturnedValue QQuickJSContext2D::method_set_textBaseline(QV4::CallContext *
\sa textBaseline
\sa strokeText
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_fillText(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_fillText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 3) {
- qreal x = ctx->args()[1].toNumber();
- qreal y = ctx->args()[2].toNumber();
+ scope.result = callData->thisObject;
+
+ if (callData->argc >= 3) {
+ qreal x = callData->args[1].toNumber();
+ qreal y = callData->args[2].toNumber();
if (!qt_is_finite(x) || !qt_is_finite(y))
- return ctx->thisObject().asReturnedValue();
- QPainterPath textPath = r->d()->context->createTextGlyphs(x, y, ctx->args()[0].toQStringNoThrow());
+ return;
+ QPainterPath textPath = r->d()->context->createTextGlyphs(x, y, callData->args[0].toQStringNoThrow());
r->d()->context->buffer()->fill(textPath);
}
- return ctx->thisObject().asReturnedValue();
}
/*!
\qmlmethod object QtQuick::Context2D::strokeText(text, x, y)
@@ -2804,15 +2752,15 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_fillText(QV4::CallContext
\sa textBaseline
\sa fillText
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_strokeText(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_strokeText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 3)
- r->d()->context->drawText(ctx->args()[0].toQStringNoThrow(), ctx->args()[1].toNumber(), ctx->args()[2].toNumber(), false);
- return ctx->thisObject().asReturnedValue();
+ if (callData->argc >= 3)
+ r->d()->context->drawText(callData->args[0].toQStringNoThrow(), callData->args[1].toNumber(), callData->args[2].toNumber(), false);
+ scope.result = callData->thisObject;
+
}
/*!
@@ -2821,21 +2769,20 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_strokeText(QV4::CallContex
Returns an object with a \c width property, whose value is equivalent to
calling \l {QFontMetrics::width()} with the given \a text in the current font.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_measureText(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_measureText(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
- if (ctx->argc() >= 1) {
+ if (callData->argc >= 1) {
QFontMetrics fm(r->d()->context->state.font);
- uint width = fm.width(ctx->args()[0].toQStringNoThrow());
+ uint width = fm.width(callData->args[0].toQStringNoThrow());
QV4::ScopedObject tm(scope, scope.engine->newObject());
tm->put(QV4::ScopedString(scope, scope.engine->newIdentifier(QStringLiteral("width"))).getPointer(),
QV4::ScopedValue(scope, QV4::Primitive::fromDouble(width)));
- return tm.asReturnedValue();
+ RETURN_RESULT(tm);
}
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
// drawing images
@@ -2897,28 +2844,29 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_measureText(QV4::CallConte
\sa {http://www.w3.org/TR/2dcontext/#dom-context-2d-drawimage}{W3C 2d context standard for drawImage}
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_drawImage(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_drawImage(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject);
CHECK_CONTEXT(r)
+ scope.result = callData->thisObject;
+
qreal sx, sy, sw, sh, dx, dy, dw, dh;
- if (!ctx->argc())
- return ctx->thisObject().asReturnedValue();
+ if (!callData->argc)
+ return;
//FIXME:This function should be moved to QQuickContext2D::drawImage(...)
if (!r->d()->context->state.invertibleCTM)
- return ctx->thisObject().asReturnedValue();
+ return;
QQmlRefPointer<QQuickCanvasPixmap> pixmap;
- QV4::ScopedValue arg(scope, ctx->args()[0]);
+ QV4::ScopedValue arg(scope, callData->args[0]);
if (arg->isString()) {
QUrl url(arg->toQString());
if (!url.isValid())
- V4THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
+ THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
pixmap = r->d()->context->createPixmap(url);
} else if (arg->isObject()) {
@@ -2931,7 +2879,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_drawImage(QV4::CallContext
if (!img.isNull())
pixmap.adopt(new QQuickCanvasPixmap(img));
} else {
- V4THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
+ THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
}
} else {
QV4::Scoped<QQuickJSContext2DImageData> imageData(scope, arg);
@@ -2940,44 +2888,44 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_drawImage(QV4::CallContext
if (pix && !pix->d()->image->isNull()) {
pixmap.adopt(new QQuickCanvasPixmap(*pix->d()->image));
} else {
- V4THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
+ THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
}
} else {
QUrl url(arg->toQStringNoThrow());
if (url.isValid())
pixmap = r->d()->context->createPixmap(url);
else
- V4THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
+ THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
}
}
} else {
- V4THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
+ THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "drawImage(), type mismatch");
}
if (pixmap.isNull() || !pixmap->isValid())
- return ctx->thisObject().asReturnedValue();
-
- if (ctx->argc() >= 9) {
- sx = ctx->args()[1].toNumber();
- sy = ctx->args()[2].toNumber();
- sw = ctx->args()[3].toNumber();
- sh = ctx->args()[4].toNumber();
- dx = ctx->args()[5].toNumber();
- dy = ctx->args()[6].toNumber();
- dw = ctx->args()[7].toNumber();
- dh = ctx->args()[8].toNumber();
- } else if (ctx->argc() >= 5) {
+ return;
+
+ if (callData->argc >= 9) {
+ sx = callData->args[1].toNumber();
+ sy = callData->args[2].toNumber();
+ sw = callData->args[3].toNumber();
+ sh = callData->args[4].toNumber();
+ dx = callData->args[5].toNumber();
+ dy = callData->args[6].toNumber();
+ dw = callData->args[7].toNumber();
+ dh = callData->args[8].toNumber();
+ } else if (callData->argc >= 5) {
sx = 0;
sy = 0;
sw = pixmap->width();
sh = pixmap->height();
- dx = ctx->args()[1].toNumber();
- dy = ctx->args()[2].toNumber();
- dw = ctx->args()[3].toNumber();
- dh = ctx->args()[4].toNumber();
- } else if (ctx->argc() >= 3) {
- dx = ctx->args()[1].toNumber();
- dy = ctx->args()[2].toNumber();
+ dx = callData->args[1].toNumber();
+ dy = callData->args[2].toNumber();
+ dw = callData->args[3].toNumber();
+ dh = callData->args[4].toNumber();
+ } else if (callData->argc >= 3) {
+ dx = callData->args[1].toNumber();
+ dy = callData->args[2].toNumber();
sx = 0;
sy = 0;
sw = pixmap->width();
@@ -2985,7 +2933,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_drawImage(QV4::CallContext
dw = sw;
dh = sh;
} else {
- return ctx->thisObject().asReturnedValue();
+ return;
}
if (!qt_is_finite(sx)
@@ -2996,7 +2944,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_drawImage(QV4::CallContext
|| !qt_is_finite(dy)
|| !qt_is_finite(dw)
|| !qt_is_finite(dh))
- return ctx->thisObject().asReturnedValue();
+ return;
if (sx < 0
|| sy < 0
@@ -3005,12 +2953,10 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_drawImage(QV4::CallContext
|| sx + sw > pixmap->width()
|| sy + sh > pixmap->height()
|| sx + sw < 0 || sy + sh < 0) {
- V4THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "drawImage(), index size error");
+ THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "drawImage(), index size error");
}
r->d()->context->buffer()->drawPixmap(pixmap, QRectF(sx, sy, sw, sh), QRectF(dx, dy, dw, dh));
-
- return ctx->thisObject().asReturnedValue();
}
// pixel manipulation
@@ -3037,45 +2983,40 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_drawImage(QV4::CallContext
\qmlproperty int QtQuick::CanvasImageData::width
Holds the actual width dimension of the data in the ImageData object, in device pixels.
*/
-QV4::ReturnedValue QQuickJSContext2DImageData::method_get_width(QV4::CallContext *ctx)
+void QQuickJSContext2DImageData::method_get_width(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2DImageData> imageData(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2DImageData> imageData(scope, callData->thisObject);
if (!imageData)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
QV4::Scoped<QQuickJSContext2DPixelData> r(scope, imageData->d()->pixelData.as<QQuickJSContext2DPixelData>());
- if (!r)
- return QV4::Encode(0);
- return QV4::Encode(r->d()->image->width());
+ int width = r ? r->d()->image->width() : 0;
+ scope.result = QV4::Encode(width);
}
/*!
\qmlproperty int QtQuick::CanvasImageData::height
Holds the actual height dimension of the data in the ImageData object, in device pixels.
*/
-QV4::ReturnedValue QQuickJSContext2DImageData::method_get_height(QV4::CallContext *ctx)
+void QQuickJSContext2DImageData::method_get_height(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2DImageData> imageData(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2DImageData> imageData(scope, callData->thisObject);
if (!imageData)
- return ctx->engine()->throwTypeError();
+ THROW_TYPE_ERROR();
QV4::Scoped<QQuickJSContext2DPixelData> r(scope, imageData->d()->pixelData.as<QQuickJSContext2DPixelData>());
- if (!r)
- return QV4::Encode(0);
- return QV4::Encode(r->d()->image->height());
+ int height = r ? r->d()->image->height() : 0;
+ scope.result = QV4::Encode(height);
}
/*!
\qmlproperty object QtQuick::CanvasImageData::data
Holds the one-dimensional array containing the data in RGBA order, as integers in the range 0 to 255.
*/
-QV4::ReturnedValue QQuickJSContext2DImageData::method_get_data(QV4::CallContext *ctx)
+void QQuickJSContext2DImageData::method_get_data(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2DImageData> imageData(scope, ctx->thisObject());
+ QV4::Scoped<QQuickJSContext2DImageData> imageData(scope, callData->thisObject);
if (!imageData)
- return ctx->engine()->throwTypeError();
- return imageData->d()->pixelData.asReturnedValue();
+ THROW_TYPE_ERROR();
+ scope.result = imageData->d()->pixelData;
}
/*!
@@ -3096,14 +3037,13 @@ QV4::ReturnedValue QQuickJSContext2DImageData::method_get_data(QV4::CallContext
The length attribute of a CanvasPixelArray object must return this h×w×4 number value.
This property is read only.
*/
-QV4::ReturnedValue QQuickJSContext2DPixelData::proto_get_length(QV4::CallContext *ctx)
+void QQuickJSContext2DPixelData::proto_get_length(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2DPixelData> r(scope, ctx->thisObject().as<QQuickJSContext2DPixelData>());
+ QV4::Scoped<QQuickJSContext2DPixelData> r(scope, callData->thisObject.as<QQuickJSContext2DPixelData>());
if (!r || r->d()->image->isNull())
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
- return QV4::Encode(r->d()->image->width() * r->d()->image->height() * 4);
+ RETURN_RESULT(QV4::Encode(r->d()->image->width() * r->d()->image->height() * 4));
}
QV4::ReturnedValue QQuickJSContext2DPixelData::getIndexed(const QV4::Managed *m, uint index, bool *hasProperty)
@@ -3192,108 +3132,107 @@ void QQuickJSContext2DPixelData::putIndexed(QV4::Managed *m, uint index, const Q
\sa Canvas::loadImage(), QtQuick::Canvas::unloadImage(),
QtQuick::Canvas::isImageLoaded
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_createImageData(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_createImageData(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- if (ctx->argc() == 1) {
- QV4::ScopedValue arg0(scope, ctx->args()[0]);
+ if (callData->argc == 1) {
+ QV4::ScopedValue arg0(scope, callData->args[0]);
QV4::Scoped<QQuickJSContext2DImageData> imgData(scope, arg0);
if (!!imgData) {
QV4::Scoped<QQuickJSContext2DPixelData> pa(scope, imgData->d()->pixelData.as<QQuickJSContext2DPixelData>());
if (pa) {
qreal w = pa->d()->image->width();
qreal h = pa->d()->image->height();
- return qt_create_image_data(w, h, scope.engine, QImage());
+ RETURN_RESULT(qt_create_image_data(w, h, scope.engine, QImage()));
}
} else if (arg0->isString()) {
QImage image = r->d()->context->createPixmap(QUrl(arg0->toQStringNoThrow()))->image();
- return qt_create_image_data(image.width(), image.height(), scope.engine, image);
+ RETURN_RESULT(qt_create_image_data(image.width(), image.height(), scope.engine, image));
}
- } else if (ctx->argc() == 2) {
- qreal w = ctx->args()[0].toNumber();
- qreal h = ctx->args()[1].toNumber();
+ } else if (callData->argc == 2) {
+ qreal w = callData->args[0].toNumber();
+ qreal h = callData->args[1].toNumber();
if (!qt_is_finite(w) || !qt_is_finite(h))
- V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createImageData(): invalid arguments");
+ THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "createImageData(): invalid arguments");
if (w > 0 && h > 0)
- return qt_create_image_data(w, h, scope.engine, QImage());
+ RETURN_RESULT(qt_create_image_data(w, h, scope.engine, QImage()));
else
- V4THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createImageData(): invalid arguments");
+ THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "createImageData(): invalid arguments");
}
- return QV4::Encode::undefined();
+ RETURN_UNDEFINED();
}
/*!
\qmlmethod CanvasImageData QtQuick::Context2D::getImageData(real sx, real sy, real sw, real sh)
Returns an CanvasImageData object containing the image data for the given rectangle of the canvas.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_getImageData(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_getImageData(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- if (ctx->argc() >= 4) {
- qreal x = ctx->args()[0].toNumber();
- qreal y = ctx->args()[1].toNumber();
- qreal w = ctx->args()[2].toNumber();
- qreal h = ctx->args()[3].toNumber();
+ if (callData->argc >= 4) {
+ qreal x = callData->args[0].toNumber();
+ qreal y = callData->args[1].toNumber();
+ qreal w = callData->args[2].toNumber();
+ qreal h = callData->args[3].toNumber();
if (!qt_is_finite(x) || !qt_is_finite(y) || !qt_is_finite(w) || !qt_is_finite(h))
- V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "getImageData(): Invalid arguments");
+ THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "getImageData(): Invalid arguments");
if (w <= 0 || h <= 0)
- V4THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "getImageData(): Invalid arguments");
+ THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "getImageData(): Invalid arguments");
QImage image = r->d()->context->canvas()->toImage(QRectF(x, y, w, h));
- return qt_create_image_data(w, h, scope.engine, image);
+ RETURN_RESULT(qt_create_image_data(w, h, scope.engine, image));
}
- return QV4::Encode::null();
+ scope.result = QV4::Encode::null();
}
/*!
\qmlmethod object QtQuick::Context2D::putImageData(CanvasImageData imageData, real dx, real dy, real dirtyX, real dirtyY, real dirtyWidth, real dirtyHeight)
Paints the data from the given ImageData object onto the canvas. If a dirty rectangle (\a dirtyX, \a dirtyY, \a dirtyWidth, \a dirtyHeight) is provided, only the pixels from that rectangle are painted.
*/
-QV4::ReturnedValue QQuickJSContext2DPrototype::method_putImageData(QV4::CallContext *ctx)
+void QQuickJSContext2DPrototype::method_putImageData(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickJSContext2D> r(scope, ctx->thisObject().as<QQuickJSContext2D>());
+ QV4::Scoped<QQuickJSContext2D> r(scope, callData->thisObject.as<QQuickJSContext2D>());
CHECK_CONTEXT(r)
- if (ctx->argc() < 7)
- return QV4::Encode::undefined();
+ if (callData->argc < 7)
+ RETURN_UNDEFINED();
- QV4::ScopedValue arg0(scope, ctx->args()[0]);
+ QV4::ScopedValue arg0(scope, callData->args[0]);
if (!arg0->isObject())
- V4THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "Context2D::putImageData, the image data type mismatch");
+ THROW_DOM(DOMEXCEPTION_TYPE_MISMATCH_ERR, "Context2D::putImageData, the image data type mismatch");
- qreal dx = ctx->args()[1].toNumber();
- qreal dy = ctx->args()[2].toNumber();
+ qreal dx = callData->args[1].toNumber();
+ qreal dy = callData->args[2].toNumber();
qreal w, h, dirtyX, dirtyY, dirtyWidth, dirtyHeight;
if (!qt_is_finite(dx) || !qt_is_finite(dy))
- V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "putImageData() : Invalid arguments");
+ THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "putImageData() : Invalid arguments");
+
+ scope.result = callData->thisObject;
QV4::Scoped<QQuickJSContext2DImageData> imageData(scope, arg0);
if (!imageData)
- return ctx->thisObject().asReturnedValue();
+ return;
QV4::Scoped<QQuickJSContext2DPixelData> pixelArray(scope, imageData->d()->pixelData.as<QQuickJSContext2DPixelData>());
if (pixelArray) {
w = pixelArray->d()->image->width();
h = pixelArray->d()->image->height();
- if (ctx->argc() == 7) {
- dirtyX = ctx->args()[3].toNumber();
- dirtyY = ctx->args()[4].toNumber();
- dirtyWidth = ctx->args()[5].toNumber();
- dirtyHeight = ctx->args()[6].toNumber();
+ if (callData->argc == 7) {
+ dirtyX = callData->args[3].toNumber();
+ dirtyY = callData->args[4].toNumber();
+ dirtyWidth = callData->args[5].toNumber();
+ dirtyHeight = callData->args[6].toNumber();
if (!qt_is_finite(dirtyX) || !qt_is_finite(dirtyY) || !qt_is_finite(dirtyWidth) || !qt_is_finite(dirtyHeight))
- V4THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "putImageData() : Invalid arguments");
+ THROW_DOM(DOMEXCEPTION_NOT_SUPPORTED_ERR, "putImageData() : Invalid arguments");
if (dirtyWidth < 0) {
@@ -3325,7 +3264,7 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_putImageData(QV4::CallCont
}
if (dirtyWidth <=0 || dirtyHeight <= 0)
- return ctx->thisObject().asReturnedValue();
+ return;
} else {
dirtyX = 0;
dirtyY = 0;
@@ -3336,7 +3275,6 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_putImageData(QV4::CallCont
QImage image = pixelArray->d()->image->copy(dirtyX, dirtyY, dirtyWidth, dirtyHeight);
r->d()->context->buffer()->drawImage(image, QRectF(dirtyX, dirtyY, dirtyWidth, dirtyHeight), QRectF(dx, dy, dirtyWidth, dirtyHeight));
}
- return ctx->thisObject().asReturnedValue();
}
/*!
@@ -3359,39 +3297,38 @@ QV4::ReturnedValue QQuickJSContext2DPrototype::method_putImageData(QV4::CallCont
gradient.addColorStop(0.7, 'rgba(0, 255, 255, 1');
\endcode
*/
-QV4::ReturnedValue QQuickContext2DStyle::gradient_proto_addColorStop(QV4::CallContext *ctx)
+void QQuickContext2DStyle::gradient_proto_addColorStop(const QV4::BuiltinFunction *, QV4::Scope &scope, QV4::CallData *callData)
{
- QV4::Scope scope(ctx);
- QV4::Scoped<QQuickContext2DStyle> style(scope, ctx->thisObject().as<QQuickContext2DStyle>());
+ QV4::Scoped<QQuickContext2DStyle> style(scope, callData->thisObject.as<QQuickContext2DStyle>());
if (!style)
- V4THROW_ERROR("Not a CanvasGradient object");
+ THROW_GENERIC_ERROR("Not a CanvasGradient object");
- if (ctx->argc() == 2) {
+ if (callData->argc == 2) {
if (!style->d()->brush->gradient())
- V4THROW_ERROR("Not a valid CanvasGradient object, can't get the gradient information");
+ THROW_GENERIC_ERROR("Not a valid CanvasGradient object, can't get the gradient information");
QGradient gradient = *(style->d()->brush->gradient());
- qreal pos = ctx->args()[0].toNumber();
+ qreal pos = callData->args[0].toNumber();
QColor color;
- if (ctx->args()[1].as<Object>()) {
- color = scope.engine->toVariant(ctx->args()[1], qMetaTypeId<QColor>()).value<QColor>();
+ if (callData->args[1].as<Object>()) {
+ color = scope.engine->toVariant(callData->args[1], qMetaTypeId<QColor>()).value<QColor>();
} else {
- color = qt_color_from_string(ctx->args()[1]);
+ color = qt_color_from_string(callData->args[1]);
}
if (pos < 0.0 || pos > 1.0 || !qt_is_finite(pos)) {
- V4THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "CanvasGradient: parameter offset out of range");
+ THROW_DOM(DOMEXCEPTION_INDEX_SIZE_ERR, "CanvasGradient: parameter offset out of range");
}
if (color.isValid()) {
gradient.setColorAt(pos, color);
} else {
- V4THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "CanvasGradient: parameter color is not a valid color string");
+ THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "CanvasGradient: parameter color is not a valid color string");
}
*style->d()->brush = gradient;
}
- return ctx->thisObject().asReturnedValue();
+ scope.result = callData->thisObject;
}
void QQuickContext2D::scale(qreal x, qreal y)
diff --git a/src/quick/items/context2d/qquickcontext2d_p.h b/src/quick/items/context2d/qquickcontext2d_p.h
index e897263b6f..334bf08329 100644
--- a/src/quick/items/context2d/qquickcontext2d_p.h
+++ b/src/quick/items/context2d/qquickcontext2d_p.h
@@ -184,17 +184,17 @@ public:
QQuickContext2D(QObject *parent = 0);
~QQuickContext2D();
- QStringList contextNames() const;
- void init(QQuickCanvasItem *canvasItem, const QVariantMap &args);
- void prepare(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth, bool antialiasing);
- void flush();
+ QStringList contextNames() const override;
+ void init(QQuickCanvasItem *canvasItem, const QVariantMap &args) override;
+ void prepare(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth, bool antialiasing) override;
+ void flush() override;
void sync();
QThread *thread() const { return m_thread; }
QQuickContext2DTexture *texture() const;
- QImage toImage(const QRectF& bounds);
+ QImage toImage(const QRectF& bounds) override;
- QV4::ReturnedValue v4value() const;
- void setV4Engine(QV4::ExecutionEngine *eng);
+ QV4::ReturnedValue v4value() const override;
+ void setV4Engine(QV4::ExecutionEngine *eng) override;
QQuickCanvasItem* canvas() const { return m_canvas; }
QQuickContext2DCommandBuffer* buffer() const { return m_buffer; }
@@ -243,8 +243,8 @@ public:
QPainterPath createTextGlyphs(qreal x, qreal y, const QString& text);
QQmlRefPointer<QQuickCanvasPixmap> createPixmap(const QUrl& url);
- QOpenGLContext *glContext() { return m_glContext; }
- QSurface *surface() { return m_surface.data(); }
+ QOpenGLContext *glContext() const { return m_glContext; }
+ QSurface *surface() const { return m_surface.data(); }
void setGrabbedImage(const QImage& grab);
State state;
diff --git a/src/quick/items/context2d/qquickcontext2dcommandbuffer_p.h b/src/quick/items/context2d/qquickcontext2dcommandbuffer_p.h
index 3663e49f10..2a1ac7304e 100644
--- a/src/quick/items/context2d/qquickcontext2dcommandbuffer_p.h
+++ b/src/quick/items/context2d/qquickcontext2dcommandbuffer_p.h
@@ -71,7 +71,7 @@ public:
void reset();
void clear();
- inline int size() {return commands.size();}
+ inline int size() const { return commands.size(); }
inline bool isEmpty() const {return commands.isEmpty(); }
inline bool hasNext() const {return cmdIdx < commands.size(); }
inline QQuickContext2D::PaintCommand takeNextCommand() { return commands.at(cmdIdx++); }
@@ -249,7 +249,7 @@ public:
void replay(QPainter* painter, QQuickContext2D::State& state, const QVector2D &scaleFactor);
private:
- QPen makePen(const QQuickContext2D::State& state);
+ static QPen makePen(const QQuickContext2D::State& state);
void setPainterState(QPainter* painter, const QQuickContext2D::State& state, const QPen& pen);
int cmdIdx;
int intIdx;
diff --git a/src/quick/items/context2d/qquickcontext2dtexture_p.h b/src/quick/items/context2d/qquickcontext2dtexture_p.h
index 04d7b40ab7..97135816a2 100644
--- a/src/quick/items/context2d/qquickcontext2dtexture_p.h
+++ b/src/quick/items/context2d/qquickcontext2dtexture_p.h
@@ -124,7 +124,7 @@ public:
// Called during sync() on the scene graph thread while GUI is blocked.
virtual QSGTexture *textureForNextFrame(QSGTexture *lastFrame, QQuickWindow *window) = 0;
- bool event(QEvent *e);
+ bool event(QEvent *e) override;
#if QT_CONFIG(opengl)
void initializeOpenGL(QOpenGLContext *gl, QOffscreenSurface *s) {
m_gl = gl;
@@ -225,17 +225,17 @@ public:
QQuickContext2DImageTexture();
~QQuickContext2DImageTexture();
- virtual QQuickCanvasItem::RenderTarget renderTarget() const;
+ QQuickCanvasItem::RenderTarget renderTarget() const override;
- virtual QQuickContext2DTile* createTile() const;
- virtual QPaintDevice* beginPainting();
- virtual void endPainting();
- virtual void compositeTile(QQuickContext2DTile* tile);
+ QQuickContext2DTile* createTile() const override;
+ QPaintDevice* beginPainting() override;
+ void endPainting() override;
+ void compositeTile(QQuickContext2DTile* tile) override;
- virtual QSGTexture *textureForNextFrame(QSGTexture *lastFrame, QQuickWindow *window);
+ QSGTexture *textureForNextFrame(QSGTexture *lastFrame, QQuickWindow *window) override;
public Q_SLOTS:
- virtual void grabImage(const QRectF& region = QRectF());
+ void grabImage(const QRectF& region = QRectF()) override;
private:
QImage m_image;
diff --git a/src/quick/items/context2d/qquickcontext2dtile_p.h b/src/quick/items/context2d/qquickcontext2dtile_p.h
index e7eed7b086..d5255edcfc 100644
--- a/src/quick/items/context2d/qquickcontext2dtile_p.h
+++ b/src/quick/items/context2d/qquickcontext2dtile_p.h
@@ -93,12 +93,12 @@ class QQuickContext2DFBOTile : public QQuickContext2DTile
public:
QQuickContext2DFBOTile();
~QQuickContext2DFBOTile();
- virtual void setRect(const QRect& r);
+ virtual void setRect(const QRect& r) override;
QOpenGLFramebufferObject* fbo() const {return m_fbo;}
- void drawFinished();
+ void drawFinished() override;
protected:
- void aboutToDraw();
+ void aboutToDraw() override;
private:
@@ -110,7 +110,7 @@ class QQuickContext2DImageTile : public QQuickContext2DTile
public:
QQuickContext2DImageTile();
~QQuickContext2DImageTile();
- void setRect(const QRect& r);
+ void setRect(const QRect& r) override;
const QImage& image() const {return m_image;}
private:
QImage m_image;
diff --git a/src/quick/items/qquickaccessibleattached_p.h b/src/quick/items/qquickaccessibleattached_p.h
index c8538745cc..215a1e5db6 100644
--- a/src/quick/items/qquickaccessibleattached_p.h
+++ b/src/quick/items/qquickaccessibleattached_p.h
@@ -203,7 +203,7 @@ public:
return object;
}
- QAccessible::State state() { return m_state; }
+ QAccessible::State state() const { return m_state; }
bool ignored() const;
bool doAction(const QString &actionName);
void availableActions(QStringList *actions) const;
diff --git a/src/quick/items/qquickanchors.cpp b/src/quick/items/qquickanchors.cpp
index a069f1ece3..c0bec7d716 100644
--- a/src/quick/items/qquickanchors.cpp
+++ b/src/quick/items/qquickanchors.cpp
@@ -214,7 +214,7 @@ void QQuickAnchorsPrivate::fillChanged()
--updatingFill;
} else {
// ### Make this certain :)
- qmlInfo(item) << QQuickAnchors::tr("Possible anchor loop detected on fill.");
+ qmlWarning(item) << QQuickAnchors::tr("Possible anchor loop detected on fill.");
}
}
@@ -243,7 +243,7 @@ void QQuickAnchorsPrivate::centerInChanged()
--updatingCenterIn;
} else {
// ### Make this certain :)
- qmlInfo(item) << QQuickAnchors::tr("Possible anchor loop detected on centerIn.");
+ qmlWarning(item) << QQuickAnchors::tr("Possible anchor loop detected on centerIn.");
}
}
@@ -285,7 +285,7 @@ void QQuickAnchorsPrivate::clearItem(QQuickItem *item)
}
}
-QQuickGeometryChange QQuickAnchorsPrivate::calculateDependency(QQuickItem *controlItem)
+QQuickGeometryChange QQuickAnchorsPrivate::calculateDependency(QQuickItem *controlItem) const
{
QQuickGeometryChange dependency;
@@ -529,7 +529,7 @@ void QQuickAnchors::setFill(QQuickItem *f)
return;
}
if (f != readParentItem(d->item) && readParentItem(f) != readParentItem(d->item)){
- qmlInfo(d->item) << tr("Cannot anchor to an item that isn't a parent or sibling.");
+ qmlWarning(d->item) << tr("Cannot anchor to an item that isn't a parent or sibling.");
return;
}
QQuickItem *oldFill = d->fill;
@@ -565,7 +565,7 @@ void QQuickAnchors::setCenterIn(QQuickItem* c)
return;
}
if (c != readParentItem(d->item) && readParentItem(c) != readParentItem(d->item)){
- qmlInfo(d->item) << tr("Cannot anchor to an item that isn't a parent or sibling.");
+ qmlWarning(d->item) << tr("Cannot anchor to an item that isn't a parent or sibling.");
return;
}
QQuickItem *oldCI = d->centerIn;
@@ -588,7 +588,7 @@ bool QQuickAnchorsPrivate::calcStretch(QQuickItem *edge1Item,
qreal offset1,
qreal offset2,
QQuickAnchors::Anchor line,
- qreal &stretch)
+ qreal &stretch) const
{
bool edge1IsParent = (edge1Item == readParentItem(item));
bool edge2IsParent = (edge2Item == readParentItem(item));
@@ -619,7 +619,7 @@ void QQuickAnchorsPrivate::updateVerticalAnchors()
if (Q_UNLIKELY(updatingVerticalAnchor > 1)) {
// ### Make this certain :)
- qmlInfo(item) << QQuickAnchors::tr("Possible anchor loop detected on vertical anchor.");
+ qmlWarning(item) << QQuickAnchors::tr("Possible anchor loop detected on vertical anchor.");
return;
}
@@ -794,7 +794,7 @@ void QQuickAnchorsPrivate::updateHorizontalAnchors()
--updatingHorizontalAnchor;
} else {
// ### Make this certain :)
- qmlInfo(item) << QQuickAnchors::tr("Possible anchor loop detected on horizontal anchor.");
+ qmlWarning(item) << QQuickAnchors::tr("Possible anchor loop detected on horizontal anchor.");
}
}
@@ -1329,7 +1329,7 @@ bool QQuickAnchorsPrivate::checkHValid() const
if (usedAnchors & QQuickAnchors::LeftAnchor &&
usedAnchors & QQuickAnchors::RightAnchor &&
usedAnchors & QQuickAnchors::HCenterAnchor) {
- qmlInfo(item) << QQuickAnchors::tr("Cannot specify left, right, and horizontalCenter anchors at the same time.");
+ qmlWarning(item) << QQuickAnchors::tr("Cannot specify left, right, and horizontalCenter anchors at the same time.");
return false;
}
@@ -1339,17 +1339,17 @@ bool QQuickAnchorsPrivate::checkHValid() const
bool QQuickAnchorsPrivate::checkHAnchorValid(QQuickAnchorLine anchor) const
{
if (!anchor.item) {
- qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to a null item.");
+ qmlWarning(item) << QQuickAnchors::tr("Cannot anchor to a null item.");
return false;
} else if (anchor.anchorLine & QQuickAnchors::Vertical_Mask) {
- qmlInfo(item) << QQuickAnchors::tr("Cannot anchor a horizontal edge to a vertical edge.");
+ qmlWarning(item) << QQuickAnchors::tr("Cannot anchor a horizontal edge to a vertical edge.");
return false;
} else if (anchor.item != readParentItem(item)
&& readParentItem(anchor.item) != readParentItem(item)) {
- qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to an item that isn't a parent or sibling.");
+ qmlWarning(item) << QQuickAnchors::tr("Cannot anchor to an item that isn't a parent or sibling.");
return false;
} else if (anchor.item == item) {
- qmlInfo(item) << QQuickAnchors::tr("Cannot anchor item to self.");
+ qmlWarning(item) << QQuickAnchors::tr("Cannot anchor item to self.");
return false;
}
@@ -1361,13 +1361,13 @@ bool QQuickAnchorsPrivate::checkVValid() const
if (usedAnchors & QQuickAnchors::TopAnchor &&
usedAnchors & QQuickAnchors::BottomAnchor &&
usedAnchors & QQuickAnchors::VCenterAnchor) {
- qmlInfo(item) << QQuickAnchors::tr("Cannot specify top, bottom, and verticalCenter anchors at the same time.");
+ qmlWarning(item) << QQuickAnchors::tr("Cannot specify top, bottom, and verticalCenter anchors at the same time.");
return false;
} else if (usedAnchors & QQuickAnchors::BaselineAnchor &&
(usedAnchors & QQuickAnchors::TopAnchor ||
usedAnchors & QQuickAnchors::BottomAnchor ||
usedAnchors & QQuickAnchors::VCenterAnchor)) {
- qmlInfo(item) << QQuickAnchors::tr("Baseline anchor cannot be used in conjunction with top, bottom, or verticalCenter anchors.");
+ qmlWarning(item) << QQuickAnchors::tr("Baseline anchor cannot be used in conjunction with top, bottom, or verticalCenter anchors.");
return false;
}
@@ -1377,17 +1377,17 @@ bool QQuickAnchorsPrivate::checkVValid() const
bool QQuickAnchorsPrivate::checkVAnchorValid(QQuickAnchorLine anchor) const
{
if (!anchor.item) {
- qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to a null item.");
+ qmlWarning(item) << QQuickAnchors::tr("Cannot anchor to a null item.");
return false;
} else if (anchor.anchorLine & QQuickAnchors::Horizontal_Mask) {
- qmlInfo(item) << QQuickAnchors::tr("Cannot anchor a vertical edge to a horizontal edge.");
+ qmlWarning(item) << QQuickAnchors::tr("Cannot anchor a vertical edge to a horizontal edge.");
return false;
} else if (anchor.item != readParentItem(item)
&& readParentItem(anchor.item) != readParentItem(item)) {
- qmlInfo(item) << QQuickAnchors::tr("Cannot anchor to an item that isn't a parent or sibling.");
+ qmlWarning(item) << QQuickAnchors::tr("Cannot anchor to an item that isn't a parent or sibling.");
return false;
} else if (anchor.item == item){
- qmlInfo(item) << QQuickAnchors::tr("Cannot anchor item to self.");
+ qmlWarning(item) << QQuickAnchors::tr("Cannot anchor item to self.");
return false;
}
diff --git a/src/quick/items/qquickanchors_p_p.h b/src/quick/items/qquickanchors_p_p.h
index 0373b1f824..906f607302 100644
--- a/src/quick/items/qquickanchors_p_p.h
+++ b/src/quick/items/qquickanchors_p_p.h
@@ -124,7 +124,7 @@ public:
void clearItem(QQuickItem *);
- QQuickGeometryChange calculateDependency(QQuickItem *);
+ QQuickGeometryChange calculateDependency(QQuickItem *) const;
void addDepend(QQuickItem *);
void remDepend(QQuickItem *);
bool isItemComplete() const;
@@ -150,7 +150,7 @@ public:
bool checkVAnchorValid(QQuickAnchorLine anchor) const;
bool calcStretch(QQuickItem *edge1Item, QQuickAnchors::Anchor edge1Line,
QQuickItem *edge2Item, QQuickAnchors::Anchor edge2Line,
- qreal offset1, qreal offset2, QQuickAnchors::Anchor line, qreal &stretch);
+ qreal offset1, qreal offset2, QQuickAnchors::Anchor line, qreal &stretch) const;
bool isMirrored() const;
void updateHorizontalAnchors();
diff --git a/src/quick/items/qquickanimatedimage.cpp b/src/quick/items/qquickanimatedimage.cpp
index 81c649dbd5..22ea4774be 100644
--- a/src/quick/items/qquickanimatedimage.cpp
+++ b/src/quick/items/qquickanimatedimage.cpp
@@ -67,7 +67,7 @@ QQuickPixmap* QQuickAnimatedImagePrivate::infoForCurrentFrame(QQmlEngine *engine
.arg(current));
}
if (!requestedUrl.isEmpty()) {
- if (QQuickPixmap::isCached(requestedUrl, QSize()))
+ if (QQuickPixmap::isCached(requestedUrl, QSize(), QQuickImageProviderOptions()))
pixmap = new QQuickPixmap(engine, requestedUrl);
else
pixmap = new QQuickPixmap(requestedUrl, _movie->currentImage());
@@ -371,7 +371,7 @@ void QQuickAnimatedImage::movieRequestFinished()
#endif
if (!d->_movie->isValid()) {
- qmlInfo(this) << "Error Reading Animated Image File " << d->url.toString();
+ qmlWarning(this) << "Error Reading Animated Image File " << d->url.toString();
delete d->_movie;
d->_movie = 0;
d->setImage(QImage());
diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp
index 8aeef4ef4a..76c2146ddb 100644
--- a/src/quick/items/qquickanimatedsprite.cpp
+++ b/src/quick/items/qquickanimatedsprite.cpp
@@ -626,7 +626,7 @@ QSGSpriteNode* QQuickAnimatedSprite::initNode()
Q_D(QQuickAnimatedSprite);
if (!d->m_spriteEngine) {
- qmlInfo(this) << "No sprite engine...";
+ qmlWarning(this) << "No sprite engine...";
return nullptr;
} else if (d->m_spriteEngine->status() == QQuickPixmap::Null) {
d->m_spriteEngine->startAssemblingImage();
diff --git a/src/quick/items/qquickborderimage.cpp b/src/quick/items/qquickborderimage.cpp
index 67b99bfbc6..28d834f9e2 100644
--- a/src/quick/items/qquickborderimage.cpp
+++ b/src/quick/items/qquickborderimage.cpp
@@ -515,7 +515,7 @@ void QQuickBorderImage::requestFinished()
QSize impsize = d->pix.implicitSize();
if (d->pix.isError()) {
d->status = Error;
- qmlInfo(this) << d->pix.error();
+ qmlWarning(this) << d->pix.error();
if (d->progress != 0) {
d->progress = 0;
emit progressChanged(d->progress);
diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp
index 7a112e840a..e5969eed7f 100644
--- a/src/quick/items/qquickdrag.cpp
+++ b/src/quick/items/qquickdrag.cpp
@@ -307,7 +307,7 @@ void QQuickDragAttached::setActive(bool active)
Q_D(QQuickDragAttached);
if (d->active != active) {
if (d->inEvent)
- qmlInfo(this) << "active cannot be changed from within a drag event handler";
+ qmlWarning(this) << "active cannot be changed from within a drag event handler";
else if (active) {
if (d->dragType == QQuickDrag::Internal) {
d->start(d->supportedActions);
@@ -629,7 +629,7 @@ void QQuickDragAttached::start(QQmlV4Function *args)
{
Q_D(QQuickDragAttached);
if (d->inEvent) {
- qmlInfo(this) << "start() cannot be called from within a drag event handler";
+ qmlWarning(this) << "start() cannot be called from within a drag event handler";
return;
}
@@ -675,7 +675,7 @@ int QQuickDragAttached::drop()
Qt::DropAction acceptedAction = Qt::IgnoreAction;
if (d->inEvent) {
- qmlInfo(this) << "drop() cannot be called from within a drag event handler";
+ qmlWarning(this) << "drop() cannot be called from within a drag event handler";
return acceptedAction;
}
@@ -722,7 +722,7 @@ void QQuickDragAttached::cancel()
Q_D(QQuickDragAttached);
if (d->inEvent) {
- qmlInfo(this) << "cancel() cannot be called from within a drag event handler";
+ qmlWarning(this) << "cancel() cannot be called from within a drag event handler";
return;
}
@@ -809,12 +809,12 @@ void QQuickDragAttached::startDrag(QQmlV4Function *args)
Q_D(QQuickDragAttached);
if (d->inEvent) {
- qmlInfo(this) << "startDrag() cannot be called from within a drag event handler";
+ qmlWarning(this) << "startDrag() cannot be called from within a drag event handler";
return;
}
if (!d->active) {
- qmlInfo(this) << "startDrag() drag must be active";
+ qmlWarning(this) << "startDrag() drag must be active";
return;
}
diff --git a/src/quick/items/qquickdrag_p.h b/src/quick/items/qquickdrag_p.h
index cc6318a4a3..357f72b3e7 100644
--- a/src/quick/items/qquickdrag_p.h
+++ b/src/quick/items/qquickdrag_p.h
@@ -77,7 +77,7 @@ class QQuickDragGrabber
QIntrusiveListNode node;
protected:
- void objectDestroyed(QQuickItem *) { delete this; }
+ void objectDestroyed(QQuickItem *) override { delete this; }
};
typedef QIntrusiveList<Item, &Item::node> ItemList;
@@ -290,7 +290,7 @@ public:
Q_INVOKABLE int drop();
- bool event(QEvent *event);
+ bool event(QEvent *event) override;
public Q_SLOTS:
void start(QQmlV4Function *);
diff --git a/src/quick/items/qquickdroparea.cpp b/src/quick/items/qquickdroparea.cpp
index 84c44c6541..b314390915 100644
--- a/src/quick/items/qquickdroparea.cpp
+++ b/src/quick/items/qquickdroparea.cpp
@@ -513,7 +513,7 @@ void QQuickDropArea::dropEvent(QDropEvent *event)
easily be translated into a QByteArray. \a format should be one contained in the \l formats property.
*/
-QObject *QQuickDropEvent::source()
+QObject *QQuickDropEvent::source() const
{
if (const QQuickDragMimeData *dragMime = qobject_cast<const QQuickDragMimeData *>(event->mimeData()))
return dragMime->source();
diff --git a/src/quick/items/qquickdroparea_p.h b/src/quick/items/qquickdroparea_p.h
index ccde2bcd19..0c4c072db7 100644
--- a/src/quick/items/qquickdroparea_p.h
+++ b/src/quick/items/qquickdroparea_p.h
@@ -86,7 +86,7 @@ public:
qreal x() const { return event->pos().x(); }
qreal y() const { return event->pos().y(); }
- QObject *source();
+ QObject *source() const;
Qt::DropActions supportedActions() const { return event->possibleActions(); }
Qt::DropActions proposedAction() const { return event->proposedAction(); }
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp
index 70d95ccdf8..b6c45c40a8 100644
--- a/src/quick/items/qquickevents.cpp
+++ b/src/quick/items/qquickevents.cpp
@@ -946,7 +946,7 @@ Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug dbg, const QQuickEventPoint *eve
dbg << "QQuickEventPoint(valid:" << event->isValid() << " accepted:" << event->isAccepted()
<< " state:";
QtDebugUtils::formatQEnum(dbg, event->state());
- dbg << " scenePos:" << event->scenePos() << " id:" << event->pointId()
+ dbg << " scenePos:" << event->scenePos() << " id:" << hex << event->pointId() << dec
<< " timeHeld:" << event->timeHeld() << ')';
return dbg;
}
diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp
index 537367b3a3..d97c731157 100644
--- a/src/quick/items/qquickflickable.cpp
+++ b/src/quick/items/qquickflickable.cpp
@@ -277,7 +277,7 @@ void QQuickFlickablePrivate::init()
Returns the amount to overshoot by given a velocity.
Will be roughly in range 0 - size/4
*/
-qreal QQuickFlickablePrivate::overShootDistance(qreal size)
+qreal QQuickFlickablePrivate::overShootDistance(qreal size) const
{
if (maxVelocity <= 0)
return 0.0;
@@ -874,9 +874,9 @@ bool QQuickFlickable::isAtYBeginning() const
}
\endcode
*/
-QQuickItem *QQuickFlickable::contentItem()
+QQuickItem *QQuickFlickable::contentItem() const
{
- Q_D(QQuickFlickable);
+ Q_D(const QQuickFlickable);
return d->contentItem;
}
@@ -951,7 +951,7 @@ void QQuickFlickable::setPixelAligned(bool align)
}
}
-qint64 QQuickFlickablePrivate::computeCurrentTime(QInputEvent *event)
+qint64 QQuickFlickablePrivate::computeCurrentTime(QInputEvent *event) const
{
if (0 != event->timestamp())
return event->timestamp();
@@ -960,7 +960,7 @@ qint64 QQuickFlickablePrivate::computeCurrentTime(QInputEvent *event)
return timer.elapsed();
}
-qreal QQuickFlickablePrivate::devicePixelRatio()
+qreal QQuickFlickablePrivate::devicePixelRatio() const
{
return (window ? window->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
}
@@ -1570,12 +1570,52 @@ void QQuickFlickablePrivate::replayDelayedPress()
//XXX pixelAligned ignores the global position of the Flickable, i.e. assumes Flickable itself is pixel aligned.
void QQuickFlickablePrivate::setViewportX(qreal x)
{
- contentItem->setX(pixelAligned ? -Round(-x) : x);
+ Q_Q(QQuickFlickable);
+ if (pixelAligned)
+ x = -Round(-x);
+
+ contentItem->setX(x);
+ if (contentItem->x() != x)
+ return; // reentered
+
+ const qreal maxX = q->maxXExtent();
+ const qreal minX = q->minXExtent();
+
+ qreal overshoot = 0.0;
+ if (x <= maxX)
+ overshoot = maxX - x;
+ else if (x >= minX)
+ overshoot = minX - x;
+
+ if (overshoot != hData.overshoot) {
+ hData.overshoot = overshoot;
+ emit q->horizontalOvershootChanged();
+ }
}
void QQuickFlickablePrivate::setViewportY(qreal y)
{
- contentItem->setY(pixelAligned ? -Round(-y) : y);
+ Q_Q(QQuickFlickable);
+ if (pixelAligned)
+ y = -Round(-y);
+
+ contentItem->setY(y);
+ if (contentItem->y() != y)
+ return; // reentered
+
+ const qreal maxY = q->maxYExtent();
+ const qreal minY = q->minYExtent();
+
+ qreal overshoot = 0.0;
+ if (y <= maxY)
+ overshoot = maxY - y;
+ else if (y >= minY)
+ overshoot = minY - y;
+
+ if (overshoot != vData.overshoot) {
+ vData.overshoot = overshoot;
+ emit q->verticalOvershootChanged();
+ }
}
void QQuickFlickable::timerEvent(QTimerEvent *event)
@@ -1841,6 +1881,8 @@ QQmlListProperty<QQuickItem> QQuickFlickable::flickableChildren()
beyond the boundary of the Flickable, and can overshoot the
boundary when flicked.
\endlist
+
+ \sa horizontalOvershoot, verticalOvershoot
*/
QQuickFlickable::BoundsBehavior QQuickFlickable::boundsBehavior() const
{
@@ -2641,4 +2683,38 @@ void QQuickFlickablePrivate::updateVelocity()
emit q->verticalVelocityChanged();
}
+/*!
+ \qmlproperty real QtQuick::Flickable::horizontalOvershoot
+ \since 5.9
+
+ This property holds the horizontal overshoot, that is, the horizontal distance by
+ which the contents has been dragged or flicked past the bounds of the flickable.
+ The value is negative when the content is dragged or flicked beyond the beginning,
+ and positive when beyond the end; \c 0.0 otherwise.
+
+ \sa verticalOvershoot, boundsBehavior
+*/
+qreal QQuickFlickable::horizontalOvershoot() const
+{
+ Q_D(const QQuickFlickable);
+ return d->hData.overshoot;
+}
+
+/*!
+ \qmlproperty real QtQuick::Flickable::verticalOvershoot
+ \since 5.9
+
+ This property holds the vertical overshoot, that is, the vertical distance by
+ which the contents has been dragged or flicked past the bounds of the flickable.
+ The value is negative when the content is dragged or flicked beyond the beginning,
+ and positive when beyond the end; \c 0.0 otherwise.
+
+ \sa horizontalOvershoot, boundsBehavior
+*/
+qreal QQuickFlickable::verticalOvershoot() const
+{
+ Q_D(const QQuickFlickable);
+ return d->vData.overshoot;
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/items/qquickflickable_p.h b/src/quick/items/qquickflickable_p.h
index 62733bda1c..52cade1472 100644
--- a/src/quick/items/qquickflickable_p.h
+++ b/src/quick/items/qquickflickable_p.h
@@ -106,12 +106,13 @@ class Q_QUICK_PRIVATE_EXPORT QQuickFlickable : public QQuickItem
Q_PROPERTY(bool pixelAligned READ pixelAligned WRITE setPixelAligned NOTIFY pixelAlignedChanged)
+ Q_PROPERTY(qreal horizontalOvershoot READ horizontalOvershoot NOTIFY horizontalOvershootChanged REVISION 9)
+ Q_PROPERTY(qreal verticalOvershoot READ verticalOvershoot NOTIFY verticalOvershootChanged REVISION 9)
+
Q_PROPERTY(QQmlListProperty<QObject> flickableData READ flickableData)
Q_PROPERTY(QQmlListProperty<QQuickItem> flickableChildren READ flickableChildren)
Q_CLASSINFO("DefaultProperty", "flickableData")
- Q_FLAGS(BoundsBehavior)
-
public:
QQuickFlickable(QQuickItem *parent=0);
~QQuickFlickable();
@@ -126,6 +127,7 @@ public:
DragAndOvershootBounds = DragOverBounds | OvershootBounds
};
Q_DECLARE_FLAGS(BoundsBehavior, BoundsBehaviorFlag)
+ Q_FLAG(BoundsBehavior)
BoundsBehavior boundsBehavior() const;
void setBoundsBehavior(BoundsBehavior);
@@ -190,7 +192,7 @@ public:
bool isAtYEnd() const;
bool isAtYBeginning() const;
- QQuickItem *contentItem();
+ QQuickItem *contentItem() const;
enum FlickableDirection { AutoFlickDirection=0x0, HorizontalFlick=0x1, VerticalFlick=0x2, HorizontalAndVerticalFlick=0x3,
AutoFlickIfNeeded=0xc };
@@ -201,6 +203,9 @@ public:
bool pixelAligned() const;
void setPixelAligned(bool align);
+ qreal horizontalOvershoot() const;
+ qreal verticalOvershoot() const;
+
Q_INVOKABLE void resizeContent(qreal w, qreal h, QPointF center);
Q_INVOKABLE void returnToBounds();
Q_INVOKABLE void flick(qreal xVelocity, qreal yVelocity);
@@ -243,6 +248,8 @@ Q_SIGNALS:
void dragStarted();
void dragEnded();
void pixelAlignedChanged();
+ Q_REVISION(9) void horizontalOvershootChanged();
+ Q_REVISION(9) void verticalOvershootChanged();
protected:
bool childMouseEventFilter(QQuickItem *, QEvent *) Q_DECL_OVERRIDE;
@@ -286,6 +293,7 @@ protected:
private:
Q_DISABLE_COPY(QQuickFlickable)
Q_DECLARE_PRIVATE(QQuickFlickable)
+ friend class QQuickFlickableContentItem;
friend class QQuickFlickableVisibleArea;
friend class QQuickFlickableReboundTransition;
};
diff --git a/src/quick/items/qquickflickable_p_p.h b/src/quick/items/qquickflickable_p_p.h
index ac1e39d829..1ceff22dfc 100644
--- a/src/quick/items/qquickflickable_p_p.h
+++ b/src/quick/items/qquickflickable_p_p.h
@@ -101,7 +101,7 @@ public:
: move(fp, func)
, transitionToBounds(0)
, viewSize(-1), lastPos(0), previousDragDelta(0), velocity(0), startMargin(0), endMargin(0)
- , origin(0)
+ , origin(0), overshoot(0)
, transitionTo(0)
, continuousFlickVelocity(0), velocityTime(), vTime(0)
, smoothVelocity(fp), atEnd(false), atBeginning(true)
@@ -148,6 +148,7 @@ public:
qreal startMargin;
qreal endMargin;
qreal origin;
+ qreal overshoot;
qreal transitionTo;
qreal continuousFlickVelocity;
QElapsedTimer velocityTime;
@@ -192,7 +193,7 @@ public:
void setViewportX(qreal x);
void setViewportY(qreal y);
- qreal overShootDistance(qreal size);
+ qreal overShootDistance(qreal size) const;
void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &) Q_DECL_OVERRIDE;
@@ -260,8 +261,8 @@ public:
const QVector2D &deltas, bool overThreshold, bool momentum,
bool velocitySensitiveOverBounds, const QVector2D &velocity);
- qint64 computeCurrentTime(QInputEvent *event);
- qreal devicePixelRatio();
+ qint64 computeCurrentTime(QInputEvent *event) const;
+ qreal devicePixelRatio() const;
// flickableData property
static void data_append(QQmlListProperty<QObject> *, QObject *);
diff --git a/src/quick/items/qquickflickablebehavior_p.h b/src/quick/items/qquickflickablebehavior_p.h
index 3377728d3f..ae7fe71359 100644
--- a/src/quick/items/qquickflickablebehavior_p.h
+++ b/src/quick/items/qquickflickablebehavior_p.h
@@ -75,20 +75,12 @@
// The default maximum velocity of a flick.
#ifndef QML_FLICK_DEFAULTMAXVELOCITY
-#ifdef Q_OS_BLACKBERRY
-#define QML_FLICK_DEFAULTMAXVELOCITY 10000
-#else
-#define QML_FLICK_DEFAULTMAXVELOCITY 2500
-#endif
+# define QML_FLICK_DEFAULTMAXVELOCITY 2500
#endif
// The default deceleration of a flick.
#ifndef QML_FLICK_DEFAULTDECELERATION
-#ifdef Q_OS_BLACKBERRY
-#define QML_FLICK_DEFAULTDECELERATION 5000
-#else
-#define QML_FLICK_DEFAULTDECELERATION 1500
-#endif
+# define QML_FLICK_DEFAULTDECELERATION 1500
#endif
// How much faster to decelerate when overshooting
diff --git a/src/quick/items/qquickflipable.cpp b/src/quick/items/qquickflipable.cpp
index 342e6c07b8..f452893528 100644
--- a/src/quick/items/qquickflipable.cpp
+++ b/src/quick/items/qquickflipable.cpp
@@ -143,7 +143,7 @@ QQuickFlipable::~QQuickFlipable()
The front and back sides of the flipable.
*/
-QQuickItem *QQuickFlipable::front()
+QQuickItem *QQuickFlipable::front() const
{
Q_D(const QQuickFlipable);
return d->front;
@@ -153,7 +153,7 @@ void QQuickFlipable::setFront(QQuickItem *front)
{
Q_D(QQuickFlipable);
if (d->front) {
- qmlInfo(this) << tr("front is a write-once property");
+ qmlWarning(this) << tr("front is a write-once property");
return;
}
d->front = front;
@@ -175,7 +175,7 @@ void QQuickFlipable::setBack(QQuickItem *back)
{
Q_D(QQuickFlipable);
if (d->back) {
- qmlInfo(this) << tr("back is a write-once property");
+ qmlWarning(this) << tr("back is a write-once property");
return;
}
if (back == 0)
diff --git a/src/quick/items/qquickflipable_p.h b/src/quick/items/qquickflipable_p.h
index 17a74d1f7a..a76977d4ac 100644
--- a/src/quick/items/qquickflipable_p.h
+++ b/src/quick/items/qquickflipable_p.h
@@ -77,7 +77,7 @@ public:
QQuickFlipable(QQuickItem *parent=0);
~QQuickFlipable();
- QQuickItem *front();
+ QQuickItem *front() const;
void setFront(QQuickItem *);
QQuickItem *back();
diff --git a/src/quick/items/qquickgenericshadereffect.cpp b/src/quick/items/qquickgenericshadereffect.cpp
index 9714f39663..2f8d71fc11 100644
--- a/src/quick/items/qquickgenericshadereffect.cpp
+++ b/src/quick/items/qquickgenericshadereffect.cpp
@@ -510,9 +510,9 @@ void QQuickGenericShaderEffect::updateShaderVars(Shader shaderType)
QSGShaderEffectNode::VariableData &vd(m_shaders[shaderType].varData[i]);
const bool isSpecial = v.name.startsWith("qt_"); // special names not mapped to properties
if (isSpecial) {
- if (v.name == QByteArrayLiteral("qt_Opacity"))
+ if (v.name == "qt_Opacity")
vd.specialType = QSGShaderEffectNode::VariableData::Opacity;
- else if (v.name == QByteArrayLiteral("qt_Matrix"))
+ else if (v.name == "qt_Matrix")
vd.specialType = QSGShaderEffectNode::VariableData::Matrix;
else if (v.name.startsWith("qt_SubRect_"))
vd.specialType = QSGShaderEffectNode::VariableData::SubRect;
diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp
index 14ea43f123..e6a7a0acd0 100644
--- a/src/quick/items/qquickgridview.cpp
+++ b/src/quick/items/qquickgridview.cpp
@@ -66,19 +66,19 @@ public:
{
}
- qreal position() const Q_DECL_OVERRIDE {
+ qreal position() const override {
return rowPos();
}
- qreal endPosition() const Q_DECL_OVERRIDE {
+ qreal endPosition() const override {
return endRowPos();
}
- qreal size() const Q_DECL_OVERRIDE {
+ qreal size() const override {
return view->flow() == QQuickGridView::FlowLeftToRight ? view->cellHeight() : view->cellWidth();
}
- qreal sectionSize() const Q_DECL_OVERRIDE {
+ qreal sectionSize() const override {
return 0.0;
}
@@ -122,7 +122,7 @@ public:
void setPosition(qreal col, qreal row, bool immediate = false) {
moveTo(pointForPosition(col, row), immediate);
}
- bool contains(qreal x, qreal y) const Q_DECL_OVERRIDE {
+ bool contains(qreal x, qreal y) const override {
return (x >= itemX() && x < itemX() + view->cellWidth() &&
y >= itemY() && y < itemY() + view->cellHeight());
}
@@ -159,13 +159,13 @@ class QQuickGridViewPrivate : public QQuickItemViewPrivate
Q_DECLARE_PUBLIC(QQuickGridView)
public:
- Qt::Orientation layoutOrientation() const Q_DECL_OVERRIDE;
- bool isContentFlowReversed() const Q_DECL_OVERRIDE;
+ Qt::Orientation layoutOrientation() const override;
+ bool isContentFlowReversed() const override;
- qreal positionAt(int index) const Q_DECL_OVERRIDE;
- qreal endPositionAt(int index) const Q_DECL_OVERRIDE;
- qreal originPosition() const Q_DECL_OVERRIDE;
- qreal lastPosition() const Q_DECL_OVERRIDE;
+ qreal positionAt(int index) const override;
+ qreal endPositionAt(int index) const override;
+ qreal originPosition() const override;
+ qreal lastPosition() const override;
qreal rowSize() const;
qreal colSize() const;
@@ -179,43 +179,43 @@ public:
void resetColumns();
- bool addVisibleItems(qreal fillFrom, qreal fillTo, qreal bufferFrom, qreal bufferTo, bool doBuffer) Q_DECL_OVERRIDE;
- bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) Q_DECL_OVERRIDE;
+ bool addVisibleItems(qreal fillFrom, qreal fillTo, qreal bufferFrom, qreal bufferTo, bool doBuffer) override;
+ bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) override;
void removeItem(FxViewItem *item);
- FxViewItem *newViewItem(int index, QQuickItem *item) Q_DECL_OVERRIDE;
- void initializeViewItem(FxViewItem *item) Q_DECL_OVERRIDE;
- void repositionItemAt(FxViewItem *item, int index, qreal sizeBuffer) Q_DECL_OVERRIDE;
- void repositionPackageItemAt(QQuickItem *item, int index) Q_DECL_OVERRIDE;
- void resetFirstItemPosition(qreal pos = 0.0) Q_DECL_OVERRIDE;
- void adjustFirstItem(qreal forwards, qreal backwards, int changeBeforeVisible) Q_DECL_OVERRIDE;
-
- void createHighlight() Q_DECL_OVERRIDE;
- void updateHighlight() Q_DECL_OVERRIDE;
- void resetHighlightPosition() Q_DECL_OVERRIDE;
-
- void setPosition(qreal pos) Q_DECL_OVERRIDE;
- void layoutVisibleItems(int fromModelIndex = 0) Q_DECL_OVERRIDE;
- bool applyInsertionChange(const QQmlChangeSet::Change &insert, ChangeResult *changeResult, QList<FxViewItem *> *addedItems, QList<MovedItem> *movingIntoView) Q_DECL_OVERRIDE;
- void translateAndTransitionItemsAfter(int afterModelIndex, const ChangeResult &insertionResult, const ChangeResult &removalResult) Q_DECL_OVERRIDE;
- bool needsRefillForAddedOrRemovedIndex(int index) const Q_DECL_OVERRIDE;
-
- qreal headerSize() const Q_DECL_OVERRIDE;
- qreal footerSize() const Q_DECL_OVERRIDE;
- bool showHeaderForIndex(int index) const Q_DECL_OVERRIDE;
- bool showFooterForIndex(int index) const Q_DECL_OVERRIDE;
- void updateHeader() Q_DECL_OVERRIDE;
- void updateFooter() Q_DECL_OVERRIDE;
-
- void changedVisibleIndex(int newIndex) Q_DECL_OVERRIDE;
- void initializeCurrentItem() Q_DECL_OVERRIDE;
-
- void updateViewport() Q_DECL_OVERRIDE;
- void fixupPosition() Q_DECL_OVERRIDE;
- void fixup(AxisData &data, qreal minExtent, qreal maxExtent) Q_DECL_OVERRIDE;
+ FxViewItem *newViewItem(int index, QQuickItem *item) override;
+ void initializeViewItem(FxViewItem *item) override;
+ void repositionItemAt(FxViewItem *item, int index, qreal sizeBuffer) override;
+ void repositionPackageItemAt(QQuickItem *item, int index) override;
+ void resetFirstItemPosition(qreal pos = 0.0) override;
+ void adjustFirstItem(qreal forwards, qreal backwards, int changeBeforeVisible) override;
+
+ void createHighlight() override;
+ void updateHighlight() override;
+ void resetHighlightPosition() override;
+
+ void setPosition(qreal pos) override;
+ void layoutVisibleItems(int fromModelIndex = 0) override;
+ bool applyInsertionChange(const QQmlChangeSet::Change &insert, ChangeResult *changeResult, QList<FxViewItem *> *addedItems, QList<MovedItem> *movingIntoView) override;
+ void translateAndTransitionItemsAfter(int afterModelIndex, const ChangeResult &insertionResult, const ChangeResult &removalResult) override;
+ bool needsRefillForAddedOrRemovedIndex(int index) const override;
+
+ qreal headerSize() const override;
+ qreal footerSize() const override;
+ bool showHeaderForIndex(int index) const override;
+ bool showFooterForIndex(int index) const override;
+ void updateHeader() override;
+ void updateFooter() override;
+
+ void changedVisibleIndex(int newIndex) override;
+ void initializeCurrentItem() override;
+
+ void updateViewport() override;
+ void fixupPosition() override;
+ void fixup(AxisData &data, qreal minExtent, qreal maxExtent) override;
bool flick(QQuickItemViewPrivate::AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
- QQuickTimeLineCallback::Callback fixupCallback, qreal velocity) Q_DECL_OVERRIDE;
+ QQuickTimeLineCallback::Callback fixupCallback, qreal velocity) override;
QQuickGridView::Flow flow;
qreal cellWidth;
@@ -383,8 +383,7 @@ qreal QQuickGridViewPrivate::snapPosAt(qreal pos) const
FxViewItem *QQuickGridViewPrivate::snapItemAt(qreal pos) const
{
- for (int i = 0; i < visibleItems.count(); ++i) {
- FxViewItem *item = visibleItems.at(i);
+ for (FxViewItem *item : visibleItems) {
if (item->index == -1)
continue;
qreal itemTop = item->position();
@@ -397,16 +396,16 @@ FxViewItem *QQuickGridViewPrivate::snapItemAt(qreal pos) const
int QQuickGridViewPrivate::snapIndex() const
{
int index = currentIndex;
- for (int i = 0; i < visibleItems.count(); ++i) {
- FxGridItemSG *item = static_cast<FxGridItemSG*>(visibleItems.at(i));
+ for (FxViewItem *item : visibleItems) {
if (item->index == -1)
continue;
qreal itemTop = item->position();
FxGridItemSG *hItem = static_cast<FxGridItemSG*>(highlight);
if (itemTop >= hItem->rowPos()-rowSize()/2 && itemTop < hItem->rowPos()+rowSize()/2) {
- index = item->index;
- if (item->colPos() >= hItem->colPos()-colSize()/2 && item->colPos() < hItem->colPos()+colSize()/2)
- return item->index;
+ FxGridItemSG *gridItem = static_cast<FxGridItemSG*>(item);
+ index = gridItem->index;
+ if (gridItem->colPos() >= hItem->colPos()-colSize()/2 && gridItem->colPos() < hItem->colPos()+colSize()/2)
+ return gridItem->index;
}
}
return index;
@@ -496,8 +495,8 @@ bool QQuickGridViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal
// We've jumped more than a page. Estimate which items are now
// visible and fill from there.
int count = (fillFrom - (rowPos + rowSize())) / (rowSize()) * columns;
- for (int i = 0; i < visibleItems.count(); ++i)
- releaseItem(visibleItems.at(i));
+ for (FxViewItem *item : qAsConst(visibleItems))
+ releaseItem(item);
visibleItems.clear();
modelIndex += count;
if (modelIndex >= model->count())
@@ -2055,9 +2054,9 @@ void QQuickGridView::viewportMoved(Qt::Orientations orient)
// Set visibility of items to eliminate cost of items outside the visible area.
qreal from = d->isContentFlowReversed() ? -d->position()-d->displayMarginBeginning-d->size() : d->position()-d->displayMarginBeginning;
qreal to = d->isContentFlowReversed() ? -d->position()+d->displayMarginEnd : d->position()+d->size()+d->displayMarginEnd;
- for (int i = 0; i < d->visibleItems.count(); ++i) {
- FxGridItemSG *item = static_cast<FxGridItemSG*>(d->visibleItems.at(i));
- QQuickItemPrivate::get(item->item)->setCulled(item->rowPos() + d->rowSize() < from || item->rowPos() > to);
+ for (FxViewItem *item : qAsConst(d->visibleItems)) {
+ FxGridItemSG *gridItem = static_cast<FxGridItemSG*>(item);
+ QQuickItemPrivate::get(gridItem->item)->setCulled(gridItem->rowPos() + d->rowSize() < from || gridItem->rowPos() > to);
}
if (d->currentItem) {
FxGridItemSG *item = static_cast<FxGridItemSG*>(d->currentItem);
@@ -2357,8 +2356,7 @@ bool QQuickGridViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &ch
if (modelIndex <= visibleIndex) {
// Insert before visible items
visibleIndex += count;
- for (int i = 0; i < visibleItems.count(); ++i) {
- FxViewItem *item = visibleItems.at(i);
+ for (FxViewItem *item : qAsConst(visibleItems)) {
if (item->index != -1 && item->index >= modelIndex)
item->index += count;
}
@@ -2391,8 +2389,7 @@ bool QQuickGridViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &ch
}
// Update the indexes of the following visible items.
- for (int i = 0; i < visibleItems.count(); ++i) {
- FxViewItem *item = visibleItems.at(i);
+ for (FxViewItem *item : qAsConst(visibleItems)) {
if (item->index != -1 && item->index >= modelIndex) {
item->index += count;
if (change.isMove())
@@ -2535,8 +2532,10 @@ void QQuickGridViewPrivate::translateAndTransitionItemsAfter(int afterModelIndex
countItemsRemoved -= removalResult.countChangeAfterVisibleItems;
- for (int i=markerItemIndex+1; i<visibleItems.count() && visibleItems.at(i)->position() < viewEndPos; i++) {
+ for (int i=markerItemIndex+1; i<visibleItems.count(); i++) {
FxGridItemSG *gridItem = static_cast<FxGridItemSG *>(visibleItems.at(i));
+ if (gridItem->position() >= viewEndPos)
+ break;
if (!gridItem->transitionScheduledOrRunning()) {
qreal origRowPos = gridItem->colPos();
qreal origColPos = gridItem->rowPos();
diff --git a/src/quick/items/qquickgridview_p.h b/src/quick/items/qquickgridview_p.h
index aaf6e4a75b..5c6da2b433 100644
--- a/src/quick/items/qquickgridview_p.h
+++ b/src/quick/items/qquickgridview_p.h
@@ -84,8 +84,8 @@ public:
QQuickGridView(QQuickItem *parent=0);
~QQuickGridView();
- void setHighlightFollowsCurrentItem(bool) Q_DECL_OVERRIDE;
- void setHighlightMoveDuration(int) Q_DECL_OVERRIDE;
+ void setHighlightFollowsCurrentItem(bool) override;
+ void setHighlightMoveDuration(int) override;
Flow flow() const;
void setFlow(Flow);
@@ -117,10 +117,10 @@ Q_SIGNALS:
void snapModeChanged();
protected:
- void viewportMoved(Qt::Orientations) Q_DECL_OVERRIDE;
- void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
- void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
- void initItem(int index, QObject *item) Q_DECL_OVERRIDE;
+ void viewportMoved(Qt::Orientations) override;
+ void keyPressEvent(QKeyEvent *) override;
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
+ void initItem(int index, QObject *item) override;
};
class QQuickGridViewAttached : public QQuickItemViewAttached
diff --git a/src/quick/items/qquickimage.cpp b/src/quick/items/qquickimage.cpp
index e36c070248..f71a2fbdbd 100644
--- a/src/quick/items/qquickimage.cpp
+++ b/src/quick/items/qquickimage.cpp
@@ -69,7 +69,7 @@ public:
emit textureChanged();
}
- QSGTexture *texture() const {
+ QSGTexture *texture() const override {
if (m_texture) {
m_texture->setFiltering(m_smooth ? QSGTexture::Linear : QSGTexture::Nearest);
m_texture->setMipmapFiltering(m_mipmap ? QSGTexture::Linear : QSGTexture::None);
@@ -304,6 +304,15 @@ void QQuickImage::setFillMode(FillMode mode)
if (d->fillMode == mode)
return;
d->fillMode = mode;
+ if ((mode == PreserveAspectCrop) != d->providerOptions.preserveAspectRatioCrop()) {
+ d->providerOptions.setPreserveAspectRatioCrop(mode == PreserveAspectCrop);
+ if (isComponentComplete())
+ load();
+ } else if ((mode == PreserveAspectFit) != d->providerOptions.preserveAspectRatioFit()) {
+ d->providerOptions.setPreserveAspectRatioFit(mode == PreserveAspectFit);
+ if (isComponentComplete())
+ load();
+ }
update();
updatePaintedGeometry();
emit fillModeChanged();
@@ -423,7 +432,9 @@ qreal QQuickImage::paintedHeight() const
(The \l fillMode is independent of this.)
If both the sourceSize.width and sourceSize.height are set the image will be scaled
- down to fit within the specified size, maintaining the image's aspect ratio. The actual
+ down to fit within the specified size (unless PreserveAspectCrop or PreserveAspectFit
+ are used, then it will be scaled to match the optimal size for cropping/fitting),
+ maintaining the image's aspect ratio. The actual
size of the image after scaling is available via \l Item::implicitWidth and \l Item::implicitHeight.
If the source is an intrinsically scalable image (eg. SVG), this property
diff --git a/src/quick/items/qquickimagebase.cpp b/src/quick/items/qquickimagebase.cpp
index a2b99b6395..22d631e917 100644
--- a/src/quick/items/qquickimagebase.cpp
+++ b/src/quick/items/qquickimagebase.cpp
@@ -246,7 +246,7 @@ void QQuickImageBase::load()
resolve2xLocalFile(d->url, targetDevicePixelRatio, &loadUrl, &d->devicePixelRatio);
}
- d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options, d->autoTransform);
+ d->pix.load(qmlEngine(this), loadUrl, d->sourcesize * d->devicePixelRatio, options, d->providerOptions);
if (d->pix.isLoading()) {
if (d->progress != 0.0) {
@@ -281,7 +281,7 @@ void QQuickImageBase::requestFinished()
Q_D(QQuickImageBase);
if (d->pix.isError()) {
- qmlInfo(this) << d->pix.error();
+ qmlWarning(this) << d->pix.error();
d->pix.clear(this);
d->status = Error;
if (d->progress != 0.0) {
@@ -381,17 +381,18 @@ void QQuickImageBase::resolve2xLocalFile(const QUrl &url, qreal targetDevicePixe
bool QQuickImageBase::autoTransform() const
{
Q_D(const QQuickImageBase);
- if (d->autoTransform == UsePluginDefault)
- return d->pix.autoTransform() == ApplyTransform;
- return d->autoTransform == ApplyTransform;
+ if (d->providerOptions.autoTransform() == QQuickImageProviderOptions::UsePluginDefaultTransform)
+ return d->pix.autoTransform() == QQuickImageProviderOptions::ApplyTransform;
+ return d->providerOptions.autoTransform() == QQuickImageProviderOptions::ApplyTransform;
}
void QQuickImageBase::setAutoTransform(bool transform)
{
Q_D(QQuickImageBase);
- if (d->autoTransform != UsePluginDefault && transform == (d->autoTransform == ApplyTransform))
+ if (d->providerOptions.autoTransform() != QQuickImageProviderOptions::UsePluginDefaultTransform &&
+ transform == (d->providerOptions.autoTransform() == QQuickImageProviderOptions::ApplyTransform))
return;
- d->autoTransform = transform ? ApplyTransform : DoNotApplyTransform;
+ d->providerOptions.setAutoTransform(transform ? QQuickImageProviderOptions::ApplyTransform : QQuickImageProviderOptions::DoNotApplyTransform);
emitAutoTransformBaseChanged();
}
diff --git a/src/quick/items/qquickimagebase_p_p.h b/src/quick/items/qquickimagebase_p_p.h
index 1eb566a3c8..d9b609c7fe 100644
--- a/src/quick/items/qquickimagebase_p_p.h
+++ b/src/quick/items/qquickimagebase_p_p.h
@@ -68,7 +68,6 @@ public:
: status(QQuickImageBase::Null),
progress(0.0),
devicePixelRatio(1.0),
- autoTransform(UsePluginDefault),
async(false),
cache(true),
mirror(false),
@@ -83,7 +82,7 @@ public:
QSize sourcesize;
QSize oldSourceSize;
qreal devicePixelRatio;
- AutoTransform autoTransform;
+ QQuickImageProviderOptions providerOptions;
bool async : 1;
bool cache : 1;
bool mirror: 1;
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 021ca9b64b..1a244b0dd9 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -333,6 +333,12 @@ QVariant QQuickItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query) const
}
#endif // im
+void QQuickItemKeyFilter::shortcutOverride(QKeyEvent *event)
+{
+ if (m_next)
+ m_next->shortcutOverride(event);
+}
+
void QQuickItemKeyFilter::componentComplete()
{
if (m_next) m_next->componentComplete();
@@ -774,7 +780,7 @@ const SigMap sigMap[] = {
{ 0, 0 }
};
-const QByteArray QQuickKeysAttached::keyToSignal(int key)
+QByteArray QQuickKeysAttached::keyToSignal(int key)
{
QByteArray keySignal;
if (key >= Qt::Key_0 && key <= Qt::Key_9) {
@@ -789,9 +795,9 @@ const QByteArray QQuickKeysAttached::keyToSignal(int key)
return keySignal;
}
-bool QQuickKeysAttached::isConnected(const char *signalName)
+bool QQuickKeysAttached::isConnected(const char *signalName) const
{
- Q_D(QQuickKeysAttached);
+ Q_D(const QQuickKeysAttached);
int signal_index = d->signalIndex(signalName);
return d->isSignalConnected(signal_index);
}
@@ -935,6 +941,46 @@ bool QQuickKeysAttached::isConnected(const char *signalName)
*/
/*!
+ \qmlsignal QtQuick::Keys::shortcutOverride(KeyEvent event)
+ \since 5.9
+
+ This signal is emitted when a key has been pressed that could potentially
+ be used as a shortcut. The \a event parameter provides information about
+ the event.
+
+ Set \c event.accepted to \c true if you wish to prevent the pressed key
+ from being used as a shortcut by other types, such as \l Shortcut. For
+ example:
+
+ \code
+ Item {
+ id: escapeItem
+ focus: true
+
+ // Ensure that we get escape key press events first.
+ Keys.onShortcutOverride: event.accepted = (event.key === Qt.Key_Escape)
+
+ Keys.onEscapePressed: {
+ console.log("escapeItem is handling escape");
+ event.accepted = true;
+ }
+ }
+
+ Shortcut {
+ sequence: "Escape"
+ onActivated: console.log("Shortcut is handling escape")
+ }
+ \endcode
+
+ As with the other signals, \c shortcutOverride will only be emitted for an
+ item if that item has \l {Item::}{activeFocus}.
+
+ The corresponding handler is \c onShortcutOverride.
+
+ \sa Shortcut
+*/
+
+/*!
\qmlsignal QtQuick::Keys::digit0Pressed(KeyEvent event)
This signal is emitted when the digit '0' has been pressed. The \a event
@@ -1426,6 +1472,16 @@ QVariant QQuickKeysAttached::inputMethodQuery(Qt::InputMethodQuery query) const
}
#endif // im
+void QQuickKeysAttached::shortcutOverride(QKeyEvent *event)
+{
+ Q_D(QQuickKeysAttached);
+ QQuickKeyEvent &keyEvent = d->theKeyEvent;
+ keyEvent.reset(*event);
+ emit shortcutOverride(&keyEvent);
+
+ event->setAccepted(keyEvent.isAccepted());
+}
+
QQuickKeysAttached *QQuickKeysAttached::qmlAttachedProperties(QObject *obj)
{
return new QQuickKeysAttached(obj);
@@ -1510,7 +1566,7 @@ QQuickLayoutMirroringAttached::QQuickLayoutMirroringAttached(QObject *parent) :
if (itemPrivate)
itemPrivate->extra.value().layoutDirectionAttached = this;
else
- qmlInfo(parent) << tr("LayoutDirection attached property only works with Items and Windows");
+ qmlWarning(parent) << tr("LayoutDirection attached property only works with Items and Windows");
}
QQuickLayoutMirroringAttached * QQuickLayoutMirroringAttached::qmlAttachedProperties(QObject *object)
@@ -1658,7 +1714,7 @@ QQuickEnterKeyAttached::QQuickEnterKeyAttached(QObject *parent)
itemPrivate = QQuickItemPrivate::get(item);
itemPrivate->extra.value().enterKeyAttached = this;
} else
- qmlInfo(parent) << tr("EnterKey attached property only works with Items");
+ qmlWarning(parent) << tr("EnterKey attached property only works with Items");
}
QQuickEnterKeyAttached *QQuickEnterKeyAttached::qmlAttachedProperties(QObject *object)
@@ -4320,7 +4376,7 @@ void QQuickItem::mapFromItem(QQmlV4Function *args) const
}
if (!itemObj && !item->isNull()) {
- qmlInfo(this) << "mapFromItem() given argument \"" << item->toQStringNoThrow()
+ qmlWarning(this) << "mapFromItem() given argument \"" << item->toQStringNoThrow()
<< "\" which is neither null nor an Item";
v4->throwTypeError();
return;
@@ -4408,7 +4464,7 @@ void QQuickItem::mapToItem(QQmlV4Function *args) const
}
if (!itemObj && !item->isNull()) {
- qmlInfo(this) << "mapToItem() given argument \"" << item->toQStringNoThrow()
+ qmlWarning(this) << "mapToItem() given argument \"" << item->toQStringNoThrow()
<< "\" which is neither null nor an Item";
v4->throwTypeError();
return;
@@ -5021,6 +5077,13 @@ void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e)
}
#endif // im
+void QQuickItemPrivate::deliverShortcutOverrideEvent(QKeyEvent *event)
+{
+ if (extra.isAllocated() && extra->keyHandler) {
+ extra->keyHandler->shortcutOverride(event);
+ }
+}
+
/*!
Called when \a change occurs for this item.
@@ -7654,6 +7717,9 @@ bool QQuickItem::event(QEvent *ev)
case QEvent::KeyRelease:
d->deliverKeyEvent(static_cast<QKeyEvent*>(ev));
break;
+ case QEvent::ShortcutOverride:
+ d->deliverShortcutOverrideEvent(static_cast<QKeyEvent*>(ev));
+ break;
case QEvent::FocusIn:
focusInEvent(static_cast<QFocusEvent*>(ev));
break;
@@ -8325,7 +8391,7 @@ void QQuickItemWrapper::markObjects(QV4::Heap::Base *that, QV4::ExecutionEngine
{
QObjectWrapper::Data *This = static_cast<QObjectWrapper::Data *>(that);
if (QQuickItem *item = static_cast<QQuickItem*>(This->object())) {
- foreach (QQuickItem *child, QQuickItemPrivate::get(item)->childItems)
+ for (QQuickItem *child : qAsConst(QQuickItemPrivate::get(item)->childItems))
QV4::QObjectWrapper::markWrapper(child, e);
}
QV4::QObjectWrapper::markObjects(that, e);
diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h
index 45674a106d..c0c9bd46bd 100644
--- a/src/quick/items/qquickitem_p.h
+++ b/src/quick/items/qquickitem_p.h
@@ -559,6 +559,7 @@ public:
#if QT_CONFIG(im)
void deliverInputMethodEvent(QInputMethodEvent *);
#endif
+ void deliverShortcutOverrideEvent(QKeyEvent *);
bool isTransparentForPositioner() const;
void setTransparentForPositioner(bool trans);
@@ -622,6 +623,7 @@ public:
virtual void inputMethodEvent(QInputMethodEvent *event, bool post);
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
#endif
+ virtual void shortcutOverride(QKeyEvent *event);
virtual void componentComplete();
bool m_processPost;
@@ -813,6 +815,7 @@ Q_SIGNALS:
void priorityChanged();
void pressed(QQuickKeyEvent *event);
void released(QQuickKeyEvent *event);
+ void shortcutOverride(QQuickKeyEvent *event);
void digit0Pressed(QQuickKeyEvent *event);
void digit1Pressed(QQuickKeyEvent *event);
void digit2Pressed(QQuickKeyEvent *event);
@@ -861,9 +864,10 @@ private:
void inputMethodEvent(QInputMethodEvent *, bool post) Q_DECL_OVERRIDE;
QVariant inputMethodQuery(Qt::InputMethodQuery query) const Q_DECL_OVERRIDE;
#endif
- const QByteArray keyToSignal(int key);
+ void shortcutOverride(QKeyEvent *event) override;
+ static QByteArray keyToSignal(int key);
- bool isConnected(const char *signalName);
+ bool isConnected(const char *signalName) const;
};
Qt::MouseButtons QQuickItemPrivate::acceptedMouseButtons() const
diff --git a/src/quick/items/qquickitemanimation.cpp b/src/quick/items/qquickitemanimation.cpp
index fd4a7d733f..9873622f41 100644
--- a/src/quick/items/qquickitemanimation.cpp
+++ b/src/quick/items/qquickitemanimation.cpp
@@ -304,7 +304,7 @@ QAbstractAnimationJob* QQuickParentAnimation::transition(QQuickStateActions &act
bool ok;
const QTransform &transform = targetParent->itemTransform(d->via, &ok);
if (transform.type() >= QTransform::TxShear || !ok) {
- qmlInfo(this) << QQuickParentAnimation::tr("Unable to preserve appearance under complex transform");
+ qmlWarning(this) << QQuickParentAnimation::tr("Unable to preserve appearance under complex transform");
ok = false;
}
@@ -315,21 +315,21 @@ QAbstractAnimationJob* QQuickParentAnimation::transition(QQuickStateActions &act
if (transform.m11() == transform.m22())
scale = transform.m11();
else {
- qmlInfo(this) << QQuickParentAnimation::tr("Unable to preserve appearance under non-uniform scale");
+ qmlWarning(this) << QQuickParentAnimation::tr("Unable to preserve appearance under non-uniform scale");
ok = false;
}
} else if (ok && isRotate) {
if (transform.m11() == transform.m22())
scale = qSqrt(transform.m11()*transform.m11() + transform.m12()*transform.m12());
else {
- qmlInfo(this) << QQuickParentAnimation::tr("Unable to preserve appearance under non-uniform scale");
+ qmlWarning(this) << QQuickParentAnimation::tr("Unable to preserve appearance under non-uniform scale");
ok = false;
}
if (scale != 0)
rotation = qAtan2(transform.m12()/scale, transform.m11()/scale) * 180/M_PI;
else {
- qmlInfo(this) << QQuickParentAnimation::tr("Unable to preserve appearance under scale of 0");
+ qmlWarning(this) << QQuickParentAnimation::tr("Unable to preserve appearance under scale of 0");
ok = false;
}
}
@@ -474,7 +474,7 @@ int QQuickAnchorAnimation::duration() const
void QQuickAnchorAnimation::setDuration(int duration)
{
if (duration < 0) {
- qmlInfo(this) << tr("Cannot set a duration of < 0");
+ qmlWarning(this) << tr("Cannot set a duration of < 0");
return;
}
@@ -613,7 +613,7 @@ int QQuickPathAnimation::duration() const
void QQuickPathAnimation::setDuration(int duration)
{
if (duration < 0) {
- qmlInfo(this) << tr("Cannot set a duration of < 0");
+ qmlWarning(this) << tr("Cannot set a duration of < 0");
return;
}
@@ -869,7 +869,7 @@ QAbstractAnimationJob* QQuickPathAnimation::transition(QQuickStateActions &actio
data->reverse = direction == Backward ? true : false;
data->fromSourced = false;
data->fromDefined = (d->path && d->path->hasStartX() && d->path->hasStartY()) ? true : false;
- data->toDefined = d->path ? d->path->hasEnd() : false;
+ data->toDefined = d->path ? true : false;
int origModifiedSize = modified.count();
for (int i = 0; i < actions.count(); ++i) {
diff --git a/src/quick/items/qquickitemanimation_p_p.h b/src/quick/items/qquickitemanimation_p_p.h
index 92dd84e4a9..2d075dfab3 100644
--- a/src/quick/items/qquickitemanimation_p_p.h
+++ b/src/quick/items/qquickitemanimation_p_p.h
@@ -97,7 +97,7 @@ public:
entryInterval(0), exitInterval(0) {}
~QQuickPathAnimationUpdater() {}
- void setValue(qreal v);
+ void setValue(qreal v) override;
QQuickPath *path;
@@ -133,7 +133,7 @@ public:
void clearTemplate() { animationTemplate = 0; }
- QQuickPathAnimationUpdater *pathUpdater() { return static_cast<QQuickPathAnimationUpdater*>(getAnimValue()); }
+ QQuickPathAnimationUpdater *pathUpdater() const { return static_cast<QQuickPathAnimationUpdater*>(getAnimValue()); }
private:
QQuickPathAnimationPrivate *animationTemplate;
};
diff --git a/src/quick/items/qquickitemgrabresult.cpp b/src/quick/items/qquickitemgrabresult.cpp
index 1b0e1f07f6..12bcd43076 100644
--- a/src/quick/items/qquickitemgrabresult.cpp
+++ b/src/quick/items/qquickitemgrabresult.cpp
@@ -47,6 +47,7 @@
#endif
#include <QtQml/QQmlEngine>
+#include <QtQml/QQmlInfo>
#include <private/qquickpixmapcache_p.h>
#include <private/qquickitem_p.h>
@@ -74,7 +75,7 @@ public:
void ensureImageInCache() const {
if (url.isEmpty() && !image.isNull()) {
- url.setScheme(QStringLiteral("ItemGrabber"));
+ url.setScheme(QQuickPixmap::itemGrabberScheme);
url.setPath(QVariant::fromValue(item.data()).toString());
static uint counter = 0;
url.setFragment(QString::number(++counter));
@@ -184,13 +185,26 @@ QQuickItemGrabResult::QQuickItemGrabResult(QObject *parent)
/*!
* Saves the grab result as an image to \a fileName. Returns true
* if successful; otherwise returns false.
+ *
+ * \note In Qt versions prior to 5.9, this function is marked as non-\c{const}.
*/
-bool QQuickItemGrabResult::saveToFile(const QString &fileName)
+bool QQuickItemGrabResult::saveToFile(const QString &fileName) const
{
- Q_D(QQuickItemGrabResult);
+ Q_D(const QQuickItemGrabResult);
return d->image.save(fileName);
}
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+/*!
+ * \overload
+ * \internal
+ */
+bool QQuickItemGrabResult::saveToFile(const QString &fileName)
+{
+ return qAsConst(*this).saveToFile(fileName);
+}
+#endif // < Qt 6
+
QUrl QQuickItemGrabResult::url() const
{
Q_D(const QQuickItemGrabResult);
@@ -266,17 +280,17 @@ QQuickItemGrabResult *QQuickItemGrabResultPrivate::create(QQuickItem *item, cons
size = QSize(item->width(), item->height());
if (size.width() < 1 || size.height() < 1) {
- qWarning("Item::grabToImage: item has invalid dimensions");
+ qmlWarning(item) << "grabToImage: item has invalid dimensions";
return 0;
}
if (!item->window()) {
- qWarning("Item::grabToImage: item is not attached to a window");
+ qmlWarning(item) << "grabToImage: item is not attached to a window";
return 0;
}
if (!item->window()->isVisible()) {
- qWarning("Item::grabToImage: item's window is not visible");
+ qmlWarning(item) << "grabToImage: item's window is not visible";
return 0;
}
@@ -364,12 +378,12 @@ bool QQuickItem::grabToImage(const QJSValue &callback, const QSize &targetSize)
{
QQmlEngine *engine = qmlEngine(this);
if (!engine) {
- qWarning("Item::grabToImage: no QML Engine");
+ qmlWarning(this) << "grabToImage: item has no QML engine";
return false;
}
if (!callback.isCallable()) {
- qWarning("Item::grabToImage: 'callback' is not a function");
+ qmlWarning(this) << "grabToImage: 'callback' is not a function";
return false;
}
@@ -378,12 +392,12 @@ bool QQuickItem::grabToImage(const QJSValue &callback, const QSize &targetSize)
size = QSize(width(), height());
if (size.width() < 1 || size.height() < 1) {
- qWarning("Item::grabToImage: item has invalid dimensions");
+ qmlWarning(this) << "grabToImage: item has invalid dimensions";
return false;
}
if (!window()) {
- qWarning("Item::grabToImage: item is not attached to a window");
+ qmlWarning(this) << "grabToImage: item is not attached to a window";
return false;
}
diff --git a/src/quick/items/qquickitemgrabresult.h b/src/quick/items/qquickitemgrabresult.h
index 42d71862de..30f8f0c2ef 100644
--- a/src/quick/items/qquickitemgrabresult.h
+++ b/src/quick/items/qquickitemgrabresult.h
@@ -64,10 +64,13 @@ public:
QImage image() const;
QUrl url() const;
- Q_INVOKABLE bool saveToFile(const QString &fileName);
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ Q_INVOKABLE bool saveToFile(const QString &fileName); // ### Qt 6: remove
+#endif
+ Q_INVOKABLE bool saveToFile(const QString &fileName) const;
protected:
- bool event(QEvent *);
+ bool event(QEvent *) override;
Q_SIGNALS:
void ready();
diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp
index 0296ebe88c..a8824de9c8 100644
--- a/src/quick/items/qquickitemsmodule.cpp
+++ b/src/quick/items/qquickitemsmodule.cpp
@@ -373,6 +373,18 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
#if QT_CONFIG(quick_shadereffect)
qmlRegisterType<QQuickBorderImageMesh>("QtQuick", 2, 8, "BorderImageMesh");
#endif
+
+ qmlRegisterType<QQuickFlickable, 9>(uri, 2, 9, "Flickable");
+ qmlRegisterType<QQuickMouseArea, 9>(uri, 2, 9, "MouseArea");
+ qmlRegisterType<QQuickText, 9>(uri, 2, 9, "Text");
+ qmlRegisterType<QQuickTextInput, 9>(uri, 2, 9, "TextInput");
+ qmlRegisterType<QQuickTouchPoint>(uri, 2, 9, "TouchPoint");
+ qRegisterMetaType<QPointingDeviceUniqueId>("QPointingDeviceUniqueId");
+ qmlRegisterUncreatableType<QPointingDeviceUniqueId>(uri, 2, 9, "PointingDeviceUniqueId", QQuickTouchPoint::tr("PointingDeviceUniqueId is only available via read-only properties"));
+#if QT_CONFIG(quick_positioners)
+ qmlRegisterUncreatableType<QQuickBasePositioner, 9>(uri, 2, 9, "Positioner",
+ QStringLiteral("Positioner is an abstract type that is only available as an attached property."));
+#endif
}
static void initResources()
diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp
index 7f8b26f20b..a8bac633cc 100644
--- a/src/quick/items/qquickitemview.cpp
+++ b/src/quick/items/qquickitemview.cpp
@@ -380,8 +380,8 @@ void QQuickItemView::setDelegate(QQmlComponent *delegate)
int oldCount = dataModel->count();
dataModel->setDelegate(delegate);
if (isComponentComplete()) {
- for (int i = 0; i < d->visibleItems.count(); ++i)
- d->releaseItem(d->visibleItems.at(i));
+ for (FxViewItem *item : qAsConst(d->visibleItems))
+ d->releaseItem(item);
d->visibleItems.clear();
d->releaseItem(d->currentItem);
d->currentItem = 0;
@@ -487,7 +487,7 @@ void QQuickItemView::setCacheBuffer(int b)
{
Q_D(QQuickItemView);
if (b < 0) {
- qmlInfo(this) << "Cannot set a negative cache buffer";
+ qmlWarning(this) << "Cannot set a negative cache buffer";
return;
}
@@ -935,21 +935,23 @@ void QQuickItemViewPrivate::positionViewAtIndex(int index, int mode)
return;
applyPendingChanges();
- int idx = qMax(qMin(index, model->count()-1), 0);
+ const int modelCount = model->count();
+ int idx = qMax(qMin(index, modelCount - 1), 0);
- qreal pos = isContentFlowReversed() ? -position() - size() : position();
+ const auto viewSize = size();
+ qreal pos = isContentFlowReversed() ? -position() - viewSize : position();
FxViewItem *item = visibleItem(idx);
qreal maxExtent = calculatedMaxExtent();
if (!item) {
qreal itemPos = positionAt(idx);
changedVisibleIndex(idx);
// save the currently visible items in case any of them end up visible again
- QList<FxViewItem *> oldVisible = visibleItems;
+ const QList<FxViewItem *> oldVisible = visibleItems;
visibleItems.clear();
setPosition(qMin(itemPos, maxExtent));
// now release the reference to all the old visible items.
- for (int i = 0; i < oldVisible.count(); ++i)
- releaseItem(oldVisible.at(i));
+ for (FxViewItem *item : oldVisible)
+ releaseItem(item);
item = visibleItem(idx);
}
if (item) {
@@ -961,22 +963,22 @@ void QQuickItemViewPrivate::positionViewAtIndex(int index, int mode)
pos -= headerSize();
break;
case QQuickItemView::Center:
- pos = itemPos - (size() - item->size())/2;
+ pos = itemPos - (viewSize - item->size())/2;
break;
case QQuickItemView::End:
- pos = itemPos - size() + item->size();
- if (footer && (index >= model->count() || hasStickyFooter()))
+ pos = itemPos - viewSize + item->size();
+ if (footer && (index >= modelCount || hasStickyFooter()))
pos += footerSize();
break;
case QQuickItemView::Visible:
- if (itemPos > pos + size())
- pos = itemPos - size() + item->size();
+ if (itemPos > pos + viewSize)
+ pos = itemPos - viewSize + item->size();
else if (item->endPosition() <= pos)
pos = itemPos;
break;
case QQuickItemView::Contain:
- if (item->endPosition() >= pos + size())
- pos = itemPos - size() + item->size();
+ if (item->endPosition() >= pos + viewSize)
+ pos = itemPos - viewSize + item->size();
if (itemPos < pos)
pos = itemPos;
break;
@@ -1025,28 +1027,27 @@ void QQuickItemView::positionViewAtEnd()
d->positionViewAtIndex(d->model->count(), End);
}
-int QQuickItemView::indexAt(qreal x, qreal y) const
+static FxViewItem * fxViewItemAtPosition(const QList<FxViewItem *> &items, qreal x, qreal y)
{
- Q_D(const QQuickItemView);
- for (int i = 0; i < d->visibleItems.count(); ++i) {
- const FxViewItem *item = d->visibleItems.at(i);
+ for (FxViewItem *item : items) {
if (item->contains(x, y))
- return item->index;
+ return item;
}
+ return nullptr;
+}
- return -1;
+int QQuickItemView::indexAt(qreal x, qreal y) const
+{
+ Q_D(const QQuickItemView);
+ const FxViewItem *item = fxViewItemAtPosition(d->visibleItems, x, y);
+ return item ? item->index : -1;
}
QQuickItem *QQuickItemView::itemAt(qreal x, qreal y) const
{
Q_D(const QQuickItemView);
- for (int i = 0; i < d->visibleItems.count(); ++i) {
- const FxViewItem *item = d->visibleItems.at(i);
- if (item->contains(x, y))
- return item->item;
- }
-
- return 0;
+ const FxViewItem *item = fxViewItemAtPosition(d->visibleItems, x, y);
+ return item ? item->item : nullptr;
}
void QQuickItemView::forceLayout()
@@ -1198,10 +1199,10 @@ void QQuickItemViewPrivate::checkVisible() const
void QQuickItemViewPrivate::showVisibleItems() const
{
qDebug() << "Visible items:";
- for (int i = 0; i < visibleItems.count(); ++i) {
- qDebug() << "\t" << visibleItems.at(i)->index
- << visibleItems.at(i)->item->objectName()
- << visibleItems.at(i)->position();
+ for (FxViewItem *item : visibleItems) {
+ qDebug() << "\t" << item->index
+ << item->item->objectName()
+ << item->position();
}
}
@@ -1645,8 +1646,7 @@ FxViewItem *QQuickItemViewPrivate::visibleItem(int modelIndex) const {
// that don't look at the view position and size
FxViewItem *QQuickItemViewPrivate::firstVisibleItem() const {
const qreal pos = isContentFlowReversed() ? -position()-size() : position();
- for (int i = 0; i < visibleItems.count(); ++i) {
- FxViewItem *item = visibleItems.at(i);
+ for (FxViewItem *item : visibleItems) {
if (item->index != -1 && item->endPosition() > pos)
return item;
}
@@ -1743,14 +1743,14 @@ void QQuickItemViewPrivate::clear()
currentChanges.reset();
timeline.clear();
- for (int i = 0; i < visibleItems.count(); ++i)
- releaseItem(visibleItems.at(i));
+ for (FxViewItem *item : qAsConst(visibleItems))
+ releaseItem(item);
visibleItems.clear();
visibleIndex = 0;
- for (int i = 0; i < releasePendingTransition.count(); ++i) {
- releasePendingTransition.at(i)->releaseAfterTransition = false;
- releaseItem(releasePendingTransition.at(i));
+ for (FxViewItem *item : qAsConst(releasePendingTransition)) {
+ item->releaseAfterTransition = false;
+ releaseItem(item);
}
releasePendingTransition.clear();
@@ -1787,10 +1787,11 @@ void QQuickItemViewPrivate::animationFinished(QAbstractAnimationJob *)
void QQuickItemViewPrivate::refill()
{
qreal s = qMax(size(), qreal(0.));
+ const auto pos = position();
if (isContentFlowReversed())
- refill(-position()-displayMarginBeginning-s, -position()+displayMarginEnd);
+ refill(-pos - displayMarginBeginning-s, -pos + displayMarginEnd);
else
- refill(position()-displayMarginBeginning, position()+displayMarginEnd+s);
+ refill(pos - displayMarginBeginning, pos + displayMarginEnd+s);
}
void QQuickItemViewPrivate::refill(qreal from, qreal to)
@@ -1910,9 +1911,9 @@ void QQuickItemViewPrivate::layout()
forceLayout = false;
if (transitioner && transitioner->canTransition(QQuickItemViewTransitioner::PopulateTransition, true)) {
- for (int i=0; i<visibleItems.count(); i++) {
- if (!visibleItems.at(i)->transitionScheduledOrRunning())
- visibleItems.at(i)->transitionNextReposition(transitioner, QQuickItemViewTransitioner::PopulateTransition, true);
+ for (FxViewItem *item : qAsConst(visibleItems)) {
+ if (!item->transitionScheduledOrRunning())
+ item->transitionNextReposition(transitioner, QQuickItemViewTransitioner::PopulateTransition, true);
}
}
@@ -2008,18 +2009,18 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
ChangeResult removalResult(prevViewPos);
int removedCount = 0;
- for (int i=0; i<removals.count(); i++) {
- itemCount -= removals[i].count;
- if (applyRemovalChange(removals[i], &removalResult, &removedCount))
+ for (const QQmlChangeSet::Change &r : removals) {
+ itemCount -= r.count;
+ if (applyRemovalChange(r, &removalResult, &removedCount))
visibleAffected = true;
- if (!visibleAffected && needsRefillForAddedOrRemovedIndex(removals[i].index))
+ if (!visibleAffected && needsRefillForAddedOrRemovedIndex(r.index))
visibleAffected = true;
const int correctedFirstVisibleIndex = prevFirstVisibleIndex - removalResult.countChangeBeforeVisible;
- if (correctedFirstVisibleIndex >= 0 && removals[i].index < correctedFirstVisibleIndex) {
- if (removals[i].index + removals[i].count < correctedFirstVisibleIndex)
- removalResult.countChangeBeforeVisible += removals[i].count;
+ if (correctedFirstVisibleIndex >= 0 && r.index < correctedFirstVisibleIndex) {
+ if (r.index + r.count < correctedFirstVisibleIndex)
+ removalResult.countChangeBeforeVisible += r.count;
else
- removalResult.countChangeBeforeVisible += (correctedFirstVisibleIndex - removals[i].index);
+ removalResult.countChangeBeforeVisible += (correctedFirstVisibleIndex - r.index);
}
}
if (runDelayedRemoveTransition) {
@@ -2066,23 +2067,23 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
}
itemCount += insertions[i].count;
}
- for (int i=0; i<newItems.count(); i++) {
- if (newItems.at(i)->attached)
- newItems.at(i)->attached->emitAdd();
+ for (FxViewItem *item : qAsConst(newItems)) {
+ if (item->attached)
+ item->attached->emitAdd();
}
// for each item that was moved directly into the view as a result of a move(),
// find the index it was moved from in order to set its initial position, so that we
// can transition it from this "original" position to its new position in the view
if (transitioner && transitioner->canTransition(QQuickItemViewTransitioner::MoveTransition, true)) {
- for (int i=0; i<movingIntoView.count(); i++) {
- int fromIndex = findMoveKeyIndex(movingIntoView.at(i).moveKey, removals);
+ for (const MovedItem &m : qAsConst(movingIntoView)) {
+ int fromIndex = findMoveKeyIndex(m.moveKey, removals);
if (fromIndex >= 0) {
if (prevFirstVisibleIndex >= 0 && fromIndex < prevFirstVisibleIndex)
- repositionItemAt(movingIntoView.at(i).item, fromIndex, -totalInsertionResult->sizeChangesAfterVisiblePos);
+ repositionItemAt(m.item, fromIndex, -totalInsertionResult->sizeChangesAfterVisiblePos);
else
- repositionItemAt(movingIntoView.at(i).item, fromIndex, totalInsertionResult->sizeChangesAfterVisiblePos);
- movingIntoView.at(i).item->transitionNextReposition(transitioner, QQuickItemViewTransitioner::MoveTransition, true);
+ repositionItemAt(m.item, fromIndex, totalInsertionResult->sizeChangesAfterVisiblePos);
+ m.item->transitionNextReposition(transitioner, QQuickItemViewTransitioner::MoveTransition, true);
}
}
}
@@ -2343,7 +2344,7 @@ FxViewItem *QQuickItemViewPrivate::createItem(int modelIndex, bool asynchronous)
if (!delegateValidated) {
delegateValidated = true;
QObject* delegate = q->delegate();
- qmlInfo(delegate ? delegate : q) << QQuickItemView::tr("Delegate must be of Item type");
+ qmlWarning(delegate ? delegate : q) << QQuickItemView::tr("Delegate must be of Item type");
}
}
inRequest = false;
@@ -2428,14 +2429,14 @@ bool QQuickItemViewPrivate::releaseItem(FxViewItem *item)
return flags != QQmlInstanceModel::Referenced;
}
-QQuickItem *QQuickItemViewPrivate::createHighlightItem()
+QQuickItem *QQuickItemViewPrivate::createHighlightItem() const
{
return createComponentItem(highlightComponent, 0.0, true);
}
-QQuickItem *QQuickItemViewPrivate::createComponentItem(QQmlComponent *component, qreal zValue, bool createDefault)
+QQuickItem *QQuickItemViewPrivate::createComponentItem(QQmlComponent *component, qreal zValue, bool createDefault) const
{
- Q_Q(QQuickItemView);
+ Q_Q(const QQuickItemView);
QQuickItem *item = 0;
if (component) {
diff --git a/src/quick/items/qquickitemview_p.h b/src/quick/items/qquickitemview_p.h
index c289ace408..b38bc6174f 100644
--- a/src/quick/items/qquickitemview_p.h
+++ b/src/quick/items/qquickitemview_p.h
@@ -232,10 +232,10 @@ public:
Q_INVOKABLE void positionViewAtEnd();
Q_REVISION(1) Q_INVOKABLE void forceLayout();
- void setContentX(qreal pos) Q_DECL_OVERRIDE;
- void setContentY(qreal pos) Q_DECL_OVERRIDE;
- qreal originX() const Q_DECL_OVERRIDE;
- qreal originY() const Q_DECL_OVERRIDE;
+ void setContentX(qreal pos) override;
+ void setContentY(qreal pos) override;
+ qreal originX() const override;
+ qreal originY() const override;
Q_SIGNALS:
void modelChanged();
@@ -277,13 +277,13 @@ Q_SIGNALS:
void highlightMoveDurationChanged();
protected:
- void updatePolish() Q_DECL_OVERRIDE;
- void componentComplete() Q_DECL_OVERRIDE;
- void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
- qreal minYExtent() const Q_DECL_OVERRIDE;
- qreal maxYExtent() const Q_DECL_OVERRIDE;
- qreal minXExtent() const Q_DECL_OVERRIDE;
- qreal maxXExtent() const Q_DECL_OVERRIDE;
+ void updatePolish() override;
+ void componentComplete() override;
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
+ qreal minYExtent() const override;
+ qreal maxYExtent() const override;
+ qreal minXExtent() const override;
+ qreal maxXExtent() const override;
protected Q_SLOTS:
void destroyRemoved();
@@ -316,7 +316,7 @@ public:
: QObject(parent), m_isCurrent(false), m_delayRemove(false) {}
~QQuickItemViewAttached() {}
- QQuickItemView *view() { return m_view; }
+ QQuickItemView *view() const { return m_view; }
void setView(QQuickItemView *view) {
if (view != m_view) {
m_view = view;
diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h
index 62851c9a89..3087682ac7 100644
--- a/src/quick/items/qquickitemview_p_p.h
+++ b/src/quick/items/qquickitemview_p_p.h
@@ -201,16 +201,16 @@ public:
void regenerate(bool orientationChanged=false);
void layout();
- virtual void animationFinished(QAbstractAnimationJob *) Q_DECL_OVERRIDE;
+ virtual void animationFinished(QAbstractAnimationJob *) override;
void refill();
void refill(qreal from, qreal to);
- void mirrorChange() Q_DECL_OVERRIDE;
+ void mirrorChange() override;
FxViewItem *createItem(int modelIndex, bool asynchronous = false);
virtual bool releaseItem(FxViewItem *item);
- QQuickItem *createHighlightItem();
- QQuickItem *createComponentItem(QQmlComponent *component, qreal zValue, bool createDefault = false);
+ QQuickItem *createHighlightItem() const;
+ QQuickItem *createComponentItem(QQmlComponent *component, qreal zValue, bool createDefault = false) const;
void updateCurrent(int modelIndex);
void updateTrackedItem();
@@ -236,7 +236,7 @@ public:
void prepareVisibleItemTransitions();
void prepareRemoveTransitions(QHash<QQmlChangeSet::MoveKey, FxViewItem *> *removedItems);
bool prepareNonVisibleItemTransition(FxViewItem *item, const QRectF &viewBounds);
- void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) Q_DECL_OVERRIDE;
+ void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) override;
int findMoveKeyIndex(QQmlChangeSet::MoveKey key, const QVector<QQmlChangeSet::Change> &changes) const;
@@ -348,8 +348,8 @@ protected:
virtual bool showFooterForIndex(int index) const = 0;
virtual void updateHeader() = 0;
virtual void updateFooter() = 0;
- virtual bool hasStickyHeader() const { return false; };
- virtual bool hasStickyFooter() const { return false; };
+ virtual bool hasStickyHeader() const { return false; }
+ virtual bool hasStickyFooter() const { return false; }
virtual void createHighlight() = 0;
virtual void updateHighlight() = 0;
@@ -382,7 +382,7 @@ protected:
virtual void updateSectionCriteria() {}
virtual void updateSections() {}
- void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) Q_DECL_OVERRIDE;
+ void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) override;
};
diff --git a/src/quick/items/qquickitemviewtransition.cpp b/src/quick/items/qquickitemviewtransition.cpp
index 6d2421c3df..700c4cc620 100644
--- a/src/quick/items/qquickitemviewtransition.cpp
+++ b/src/quick/items/qquickitemviewtransition.cpp
@@ -64,7 +64,7 @@ public:
bool *m_wasDeleted;
protected:
- void finished() Q_DECL_OVERRIDE;
+ void finished() override;
};
@@ -246,7 +246,7 @@ void QQuickItemViewTransitioner::resetTargetLists()
moveTransitionTargets.clear();
}
-QQuickTransition *QQuickItemViewTransitioner::transitionObject(QQuickItemViewTransitioner::TransitionType type, bool asTarget)
+QQuickTransition *QQuickItemViewTransitioner::transitionObject(QQuickItemViewTransitioner::TransitionType type, bool asTarget) const
{
if (type == QQuickItemViewTransitioner::NoTransition)
return 0;
diff --git a/src/quick/items/qquickitemviewtransition_p.h b/src/quick/items/qquickitemviewtransition_p.h
index ff0e82ac7b..3d2f5361b1 100644
--- a/src/quick/items/qquickitemviewtransition_p.h
+++ b/src/quick/items/qquickitemviewtransition_p.h
@@ -97,7 +97,7 @@ public:
void addToTargetLists(QQuickItemViewTransitioner::TransitionType type, QQuickItemViewTransitionableItem *item, int index);
void resetTargetLists();
- QQuickTransition *transitionObject(QQuickItemViewTransitioner::TransitionType type, bool asTarget);
+ QQuickTransition *transitionObject(QQuickItemViewTransitioner::TransitionType type, bool asTarget) const;
const QList<int> &targetIndexes(QQuickItemViewTransitioner::TransitionType type) const;
const QList<QObject *> &targetItems(QQuickItemViewTransitioner::TransitionType type) const;
diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp
index f89a995e76..0351077f20 100644
--- a/src/quick/items/qquicklistview.cpp
+++ b/src/quick/items/qquicklistview.cpp
@@ -65,51 +65,51 @@ class QQuickListViewPrivate : public QQuickItemViewPrivate
public:
static QQuickListViewPrivate* get(QQuickListView *item) { return item->d_func(); }
- Qt::Orientation layoutOrientation() const Q_DECL_OVERRIDE;
- bool isContentFlowReversed() const Q_DECL_OVERRIDE;
+ Qt::Orientation layoutOrientation() const override;
+ bool isContentFlowReversed() const override;
bool isRightToLeft() const;
bool isBottomToTop() const;
- qreal positionAt(int index) const Q_DECL_OVERRIDE;
- qreal endPositionAt(int index) const Q_DECL_OVERRIDE;
- qreal originPosition() const Q_DECL_OVERRIDE;
- qreal lastPosition() const Q_DECL_OVERRIDE;
+ qreal positionAt(int index) const override;
+ qreal endPositionAt(int index) const override;
+ qreal originPosition() const override;
+ qreal lastPosition() const override;
FxViewItem *itemBefore(int modelIndex) const;
QString sectionAt(int modelIndex);
qreal snapPosAt(qreal pos);
FxViewItem *snapItemAt(qreal pos);
- void init() Q_DECL_OVERRIDE;
- void clear() Q_DECL_OVERRIDE;
+ void init() override;
+ void clear() override;
- bool addVisibleItems(qreal fillFrom, qreal fillTo, qreal bufferFrom, qreal bufferTo, bool doBuffer) Q_DECL_OVERRIDE;
- bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) Q_DECL_OVERRIDE;
- void visibleItemsChanged() Q_DECL_OVERRIDE;
+ bool addVisibleItems(qreal fillFrom, qreal fillTo, qreal bufferFrom, qreal bufferTo, bool doBuffer) override;
+ bool removeNonVisibleItems(qreal bufferFrom, qreal bufferTo) override;
+ void visibleItemsChanged() override;
void removeItem(FxViewItem *item);
- FxViewItem *newViewItem(int index, QQuickItem *item) Q_DECL_OVERRIDE;
- void initializeViewItem(FxViewItem *item) Q_DECL_OVERRIDE;
- bool releaseItem(FxViewItem *item) Q_DECL_OVERRIDE;
- void repositionItemAt(FxViewItem *item, int index, qreal sizeBuffer) Q_DECL_OVERRIDE;
- void repositionPackageItemAt(QQuickItem *item, int index) Q_DECL_OVERRIDE;
- void resetFirstItemPosition(qreal pos = 0.0) Q_DECL_OVERRIDE;
- void adjustFirstItem(qreal forwards, qreal backwards, int) Q_DECL_OVERRIDE;
- void updateSizeChangesBeforeVisiblePos(FxViewItem *item, ChangeResult *removeResult) Q_DECL_OVERRIDE;
+ FxViewItem *newViewItem(int index, QQuickItem *item) override;
+ void initializeViewItem(FxViewItem *item) override;
+ bool releaseItem(FxViewItem *item) override;
+ void repositionItemAt(FxViewItem *item, int index, qreal sizeBuffer) override;
+ void repositionPackageItemAt(QQuickItem *item, int index) override;
+ void resetFirstItemPosition(qreal pos = 0.0) override;
+ void adjustFirstItem(qreal forwards, qreal backwards, int) override;
+ void updateSizeChangesBeforeVisiblePos(FxViewItem *item, ChangeResult *removeResult) override;
- void createHighlight() Q_DECL_OVERRIDE;
- void updateHighlight() Q_DECL_OVERRIDE;
- void resetHighlightPosition() Q_DECL_OVERRIDE;
+ void createHighlight() override;
+ void updateHighlight() override;
+ void resetHighlightPosition() override;
- void setPosition(qreal pos) Q_DECL_OVERRIDE;
- void layoutVisibleItems(int fromModelIndex = 0) Q_DECL_OVERRIDE;
+ void setPosition(qreal pos) override;
+ void layoutVisibleItems(int fromModelIndex = 0) override;
- bool applyInsertionChange(const QQmlChangeSet::Change &insert, ChangeResult *changeResult, QList<FxViewItem *> *addedItems, QList<MovedItem> *movingIntoView) Q_DECL_OVERRIDE;
- void translateAndTransitionItemsAfter(int afterIndex, const ChangeResult &insertionResult, const ChangeResult &removalResult) Q_DECL_OVERRIDE;
+ bool applyInsertionChange(const QQmlChangeSet::Change &insert, ChangeResult *changeResult, QList<FxViewItem *> *addedItems, QList<MovedItem> *movingIntoView) override;
+ void translateAndTransitionItemsAfter(int afterIndex, const ChangeResult &insertionResult, const ChangeResult &removalResult) override;
- void updateSectionCriteria() Q_DECL_OVERRIDE;
- void updateSections() Q_DECL_OVERRIDE;
+ void updateSectionCriteria() override;
+ void updateSections() override;
QQuickItem *getSectionItem(const QString &section);
void releaseSectionItem(QQuickItem *item);
void releaseSectionItems();
@@ -117,25 +117,25 @@ public:
void updateCurrentSection();
void updateStickySections();
- qreal headerSize() const Q_DECL_OVERRIDE;
- qreal footerSize() const Q_DECL_OVERRIDE;
- bool showHeaderForIndex(int index) const Q_DECL_OVERRIDE;
- bool showFooterForIndex(int index) const Q_DECL_OVERRIDE;
- void updateHeader() Q_DECL_OVERRIDE;
- void updateFooter() Q_DECL_OVERRIDE;
- bool hasStickyHeader() const Q_DECL_OVERRIDE;
- bool hasStickyFooter() const Q_DECL_OVERRIDE;
+ qreal headerSize() const override;
+ qreal footerSize() const override;
+ bool showHeaderForIndex(int index) const override;
+ bool showFooterForIndex(int index) const override;
+ void updateHeader() override;
+ void updateFooter() override;
+ bool hasStickyHeader() const override;
+ bool hasStickyFooter() const override;
- void changedVisibleIndex(int newIndex) Q_DECL_OVERRIDE;
- void initializeCurrentItem() Q_DECL_OVERRIDE;
+ void changedVisibleIndex(int newIndex) override;
+ void initializeCurrentItem() override;
void updateAverage();
- void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
- void fixupPosition() Q_DECL_OVERRIDE;
- void fixup(AxisData &data, qreal minExtent, qreal maxExtent) Q_DECL_OVERRIDE;
+ void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &oldGeometry) override;
+ void fixupPosition() override;
+ void fixup(AxisData &data, qreal minExtent, qreal maxExtent) override;
bool flick(QQuickItemViewPrivate::AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
- QQuickTimeLineCallback::Callback fixupCallback, qreal velocity) Q_DECL_OVERRIDE;
+ QQuickTimeLineCallback::Callback fixupCallback, qreal velocity) override;
QQuickListView::Orientation orient;
qreal visiblePos;
@@ -263,7 +263,7 @@ public:
static_cast<QQuickListViewAttached*>(attached)->m_sectionItem = s;
}
- qreal position() const Q_DECL_OVERRIDE {
+ qreal position() const override {
if (section()) {
if (view->orientation() == QQuickListView::Vertical)
return (view->verticalLayoutDirection() == QQuickItemView::BottomToTop ? -section()->height()-section()->y() : section()->y());
@@ -279,7 +279,7 @@ public:
else
return (view->effectiveLayoutDirection() == Qt::RightToLeft ? -itemWidth()-itemX() : itemX());
}
- qreal size() const Q_DECL_OVERRIDE {
+ qreal size() const override {
if (section())
return (view->orientation() == QQuickListView::Vertical ? itemHeight()+section()->height() : itemWidth()+section()->width());
else
@@ -288,12 +288,12 @@ public:
qreal itemSize() const {
return (view->orientation() == QQuickListView::Vertical ? itemHeight() : itemWidth());
}
- qreal sectionSize() const Q_DECL_OVERRIDE {
+ qreal sectionSize() const override {
if (section())
return (view->orientation() == QQuickListView::Vertical ? section()->height() : section()->width());
return 0.0;
}
- qreal endPosition() const Q_DECL_OVERRIDE {
+ qreal endPosition() const override {
if (view->orientation() == QQuickListView::Vertical) {
return (view->verticalLayoutDirection() == QQuickItemView::BottomToTop
? -itemY()
@@ -327,7 +327,7 @@ public:
else
item->setWidth(size);
}
- bool contains(qreal x, qreal y) const Q_DECL_OVERRIDE {
+ bool contains(qreal x, qreal y) const override {
return (x >= itemX() && x < itemX() + itemWidth() &&
y >= itemY() && y < itemY() + itemHeight());
}
@@ -438,11 +438,12 @@ qreal QQuickListViewPrivate::lastPosition() const
int invisibleCount = INT_MIN;
int delayRemovedCount = 0;
for (int i = visibleItems.count()-1; i >= 0; --i) {
- if (visibleItems.at(i)->index != -1) {
+ FxViewItem *item = visibleItems.at(i);
+ if (item->index != -1) {
// Find the invisible count after the last visible item with known index
- invisibleCount = model->count() - (visibleItems.at(i)->index + 1 + delayRemovedCount);
+ invisibleCount = model->count() - (item->index + 1 + delayRemovedCount);
break;
- } else if (visibleItems.at(i)->attached->delayRemove()) {
+ } else if (item->attached->delayRemove()) {
++delayRemovedCount;
}
}
@@ -530,8 +531,7 @@ FxViewItem *QQuickListViewPrivate::snapItemAt(qreal pos)
{
FxViewItem *snapItem = 0;
qreal prevItemSize = 0;
- for (int i = 0; i < visibleItems.count(); ++i) {
- FxViewItem *item = visibleItems.at(i);
+ for (FxViewItem *item : qAsConst(visibleItems)) {
if (item->index == -1)
continue;
qreal itemTop = item->position();
@@ -660,8 +660,8 @@ bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal
int newModelIdx = qBound(0, modelIndex + count, model->count());
count = newModelIdx - modelIndex;
if (count) {
- for (int i = 0; i < visibleItems.count(); ++i)
- releaseItem(visibleItems.at(i));
+ for (FxViewItem *item : qAsConst(visibleItems))
+ releaseItem(item);
visibleItems.clear();
modelIndex = newModelIdx;
visibleIndex = modelIndex;
@@ -1008,8 +1008,8 @@ void QQuickListViewPrivate::releaseSectionItem(QQuickItem *item)
void QQuickListViewPrivate::releaseSectionItems()
{
- for (int i = 0; i < visibleItems.count(); ++i) {
- FxListItemSG *listItem = static_cast<FxListItemSG *>(visibleItems.at(i));
+ for (FxViewItem *item : qAsConst(visibleItems)) {
+ FxListItemSG *listItem = static_cast<FxListItemSG *>(item);
if (listItem->section()) {
qreal pos = listItem->position();
releaseSectionItem(listItem->section());
@@ -1168,16 +1168,15 @@ void QQuickListViewPrivate::updateSections()
QQuickListViewAttached *prevAtt = 0;
int prevIdx = -1;
int idx = -1;
- for (int i = 0; i < visibleItems.count(); ++i) {
- FxViewItem *item = visibleItems.at(i);
+ for (FxViewItem *item : qAsConst(visibleItems)) {
QQuickListViewAttached *attached = static_cast<QQuickListViewAttached*>(item->attached);
attached->setPrevSection(prevSection);
- if (visibleItems.at(i)->index != -1) {
- QString propValue = model->stringValue(visibleItems.at(i)->index, sectionCriteria->property());
+ if (item->index != -1) {
+ QString propValue = model->stringValue(item->index, sectionCriteria->property());
attached->setSection(sectionCriteria->sectionString(propValue));
- idx = visibleItems.at(i)->index;
+ idx = item->index;
}
- updateInlineSection(static_cast<FxListItemSG*>(visibleItems.at(i)));
+ updateInlineSection(static_cast<FxListItemSG*>(item));
if (prevAtt)
prevAtt->setNextSection(sectionAt(prevIdx+1));
prevSection = attached->section();
@@ -1210,9 +1209,12 @@ void QQuickListViewPrivate::updateCurrentSection()
qreal startPos = hasStickyHeader() ? header->endPosition() : viewPos;
int index = 0;
int modelIndex = visibleIndex;
- while (index < visibleItems.count() && visibleItems.at(index)->endPosition() <= startPos) {
- if (visibleItems.at(index)->index != -1)
- modelIndex = visibleItems.at(index)->index;
+ while (index < visibleItems.count()) {
+ FxViewItem *item = visibleItems.at(index);
+ if (item->endPosition() > startPos)
+ break;
+ if (item->index != -1)
+ modelIndex = item->index;
++index;
}
@@ -1236,10 +1238,13 @@ void QQuickListViewPrivate::updateCurrentSection()
qreal endPos = hasStickyFooter() ? footer->position() : viewPos + size();
if (nextSectionItem && !inlineSections)
endPos -= orient == QQuickListView::Vertical ? nextSectionItem->height() : nextSectionItem->width();
- while (index < visibleItems.count() && static_cast<FxListItemSG*>(visibleItems.at(index))->itemPosition() < endPos) {
- if (visibleItems.at(index)->index != -1)
- modelIndex = visibleItems.at(index)->index;
- lastSection = visibleItems.at(index)->attached->section();
+ while (index < visibleItems.count()) {
+ FxListItemSG *listItem = static_cast<FxListItemSG *>(visibleItems.at(index));
+ if (listItem->itemPosition() >= endPos)
+ break;
+ if (listItem->index != -1)
+ modelIndex = listItem->index;
+ lastSection = listItem->attached->section();
++index;
}
@@ -1288,8 +1293,8 @@ void QQuickListViewPrivate::updateAverage()
if (!visibleItems.count())
return;
qreal sum = 0.0;
- for (int i = 0; i < visibleItems.count(); ++i)
- sum += visibleItems.at(i)->size();
+ for (FxViewItem *item : qAsConst(visibleItems))
+ sum += item->size();
averageSize = qRound(sum / visibleItems.count());
}
@@ -1462,9 +1467,15 @@ void QQuickListViewPrivate::fixupPosition()
void QQuickListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent)
{
- if ((orient == QQuickListView::Horizontal && &data == &vData)
- || (orient == QQuickListView::Vertical && &data == &hData))
+ if (orient == QQuickListView::Horizontal && &data == &vData) {
+ if (flickableDirection != QQuickFlickable::HorizontalFlick)
+ QQuickItemViewPrivate::fixup(data, minExtent, maxExtent);
+ return;
+ } else if (orient == QQuickListView::Vertical && &data == &hData) {
+ if (flickableDirection != QQuickFlickable::VerticalFlick)
+ QQuickItemViewPrivate::fixup(data, minExtent, maxExtent);
return;
+ }
correctFlick = false;
fixupMode = moveReason == Mouse ? fixupMode : Immediate;
@@ -1813,6 +1824,19 @@ bool QQuickListViewPrivate::flick(AxisData &data, qreal minExtent, qreal maxExte
\image listview-layout-righttoleft.png
\endtable
+ \section1 Flickable Direction
+
+ By default, a vertical ListView sets \l {Flickable::}{flickableDirection} to \e Flickable.Vertical,
+ and a horizontal ListView sets it to \e Flickable.Horizontal. Furthermore, a vertical ListView only
+ calculates (estimates) the \l {Flickable::}{contentHeight}, and a horizontal ListView only calculates
+ the \l {Flickable::}{contentWidth}. The other dimension is set to \e -1.
+
+ Since Qt 5.9 (Qt Quick 2.9), it is possible to make a ListView that can be flicked to both directions.
+ In order to do this, the \l {Flickable::}{flickableDirection} can be set to \e Flickable.AutoFlickDirection
+ or \e Flickable.AutoFlickIfNeeded, and the desired \e contentWidth or \e contentHeight must be provided.
+
+ \snippet qml/listview/listview.qml flickBothDirections
+
\sa {QML Data Models}, GridView, PathView, {Qt Quick Examples - Views}
*/
QQuickListView::QQuickListView(QQuickItem *parent)
@@ -2099,6 +2123,8 @@ void QQuickListView::setSpacing(qreal spacing)
\li Vertical orientation:
\image listview-highlight.png
\endtable
+
+ \sa {Flickable Direction}
*/
QQuickListView::Orientation QQuickListView::orientation() const
{
@@ -2112,12 +2138,18 @@ void QQuickListView::setOrientation(QQuickListView::Orientation orientation)
if (d->orient != orientation) {
d->orient = orientation;
if (d->orient == Vertical) {
- setContentWidth(-1);
- setFlickableDirection(VerticalFlick);
+ if (d->flickableDirection == HorizontalFlick) {
+ setFlickableDirection(VerticalFlick);
+ if (isComponentComplete())
+ setContentWidth(-1);
+ }
setContentX(0);
} else {
- setContentHeight(-1);
- setFlickableDirection(HorizontalFlick);
+ if (d->flickableDirection == VerticalFlick) {
+ setFlickableDirection(HorizontalFlick);
+ if (isComponentComplete())
+ setContentHeight(-1);
+ }
setContentY(0);
}
d->regenerate(true);
@@ -2899,8 +2931,7 @@ void QQuickListView::viewportMoved(Qt::Orientations orient)
// Set visibility of items to eliminate cost of items outside the visible area.
qreal from = d->isContentFlowReversed() ? -d->position()-d->displayMarginBeginning-d->size() : d->position()-d->displayMarginBeginning;
qreal to = d->isContentFlowReversed() ? -d->position()+d->displayMarginEnd : d->position()+d->size()+d->displayMarginEnd;
- for (int i = 0; i < d->visibleItems.count(); ++i) {
- FxViewItem *item = static_cast<FxListItemSG*>(d->visibleItems.at(i));
+ for (FxViewItem *item : qAsConst(d->visibleItems)) {
if (item->item)
QQuickItemPrivate::get(item->item)->setCulled(item->endPosition() < from || item->position() > to);
}
@@ -3042,6 +3073,21 @@ void QQuickListView::initItem(int index, QObject *object)
}
}
+qreal QQuickListView::maxYExtent() const
+{
+ Q_D(const QQuickListView);
+ if (d->layoutOrientation() == Qt::Horizontal && d->flickableDirection != HorizontalFlick)
+ return QQuickFlickable::maxYExtent();
+ return QQuickItemView::maxYExtent();
+}
+
+qreal QQuickListView::maxXExtent() const
+{
+ Q_D(const QQuickListView);
+ if (d->layoutOrientation() == Qt::Vertical && d->flickableDirection != VerticalFlick)
+ return QQuickFlickable::maxXExtent();
+ return QQuickItemView::maxXExtent();
+}
/*!
\qmlmethod QtQuick::ListView::incrementCurrentIndex()
@@ -3120,8 +3166,7 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &ch
if (modelIndex < visibleIndex) {
// Insert before visible items
visibleIndex += count;
- for (int i = 0; i < visibleItems.count(); ++i) {
- FxViewItem *item = visibleItems.at(i);
+ for (FxViewItem *item : qAsConst(visibleItems)) {
if (item->index != -1 && item->index >= modelIndex)
item->index += count;
}
@@ -3138,8 +3183,7 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Change &ch
}
// Update the indexes of the following visible items.
- for (int i = 0; i < visibleItems.count(); ++i) {
- FxViewItem *item = visibleItems.at(i);
+ for (FxViewItem *item : qAsConst(visibleItems)) {
if (item->index != -1 && item->index >= modelIndex) {
item->index += count;
if (change.isMove())
@@ -3281,8 +3325,10 @@ void QQuickListViewPrivate::translateAndTransitionItemsAfter(int afterModelIndex
qreal sizeRemoved = -removalResult.sizeChangesAfterVisiblePos
- (removalResult.countChangeAfterVisibleItems * (averageSize + spacing));
- for (int i=markerItemIndex+1; i<visibleItems.count() && visibleItems.at(i)->position() < viewEndPos; i++) {
+ for (int i=markerItemIndex+1; i<visibleItems.count(); i++) {
FxListItemSG *listItem = static_cast<FxListItemSG *>(visibleItems.at(i));
+ if (listItem->position() >= viewEndPos)
+ break;
if (!listItem->transitionScheduledOrRunning()) {
qreal pos = listItem->position();
listItem->setPosition(pos - sizeRemoved);
diff --git a/src/quick/items/qquicklistview_p.h b/src/quick/items/qquicklistview_p.h
index 8d0ad7f618..f8db0f0f8f 100644
--- a/src/quick/items/qquicklistview_p.h
+++ b/src/quick/items/qquicklistview_p.h
@@ -88,7 +88,7 @@ public:
enum LabelPositioning { InlineLabels = 0x01, CurrentLabelAtStart = 0x02, NextLabelAtEnd = 0x04 };
Q_ENUM(LabelPositioning)
- int labelPositioning() { return m_labelPositioning; }
+ int labelPositioning() const { return m_labelPositioning; }
void setLabelPositioning(int pos);
Q_SIGNALS:
@@ -146,7 +146,7 @@ public:
QQuickViewSection *sectionCriteria();
QString currentSection() const;
- void setHighlightFollowsCurrentItem(bool) Q_DECL_OVERRIDE;
+ void setHighlightFollowsCurrentItem(bool) override;
qreal highlightMoveVelocity() const;
void setHighlightMoveVelocity(qreal);
@@ -157,7 +157,7 @@ public:
int highlightResizeDuration() const;
void setHighlightResizeDuration(int);
- void setHighlightMoveDuration(int) Q_DECL_OVERRIDE;
+ void setHighlightMoveDuration(int) override;
enum SnapMode { NoSnap, SnapToItem, SnapOneItem };
Q_ENUM(SnapMode)
@@ -192,10 +192,12 @@ Q_SIGNALS:
Q_REVISION(2) void footerPositioningChanged();
protected:
- void viewportMoved(Qt::Orientations orient) Q_DECL_OVERRIDE;
- void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
- void geometryChanged(const QRectF &newGeometry,const QRectF &oldGeometry) Q_DECL_OVERRIDE;
- void initItem(int index, QObject *item) Q_DECL_OVERRIDE;
+ void viewportMoved(Qt::Orientations orient) override;
+ void keyPressEvent(QKeyEvent *) override;
+ void geometryChanged(const QRectF &newGeometry,const QRectF &oldGeometry) override;
+ void initItem(int index, QObject *item) override;
+ qreal maxYExtent() const override;
+ qreal maxXExtent() const override;
};
class QQuickListViewAttached : public QQuickItemViewAttached
diff --git a/src/quick/items/qquickloader.cpp b/src/quick/items/qquickloader.cpp
index eeec562e3c..5d5934bbd2 100644
--- a/src/quick/items/qquickloader.cpp
+++ b/src/quick/items/qquickloader.cpp
@@ -971,7 +971,7 @@ QV4::ReturnedValue QQuickLoaderPrivate::extractInitialPropertyValues(QQmlV4Funct
QV4::ScopedValue v(scope, (*args)[1]);
if (!v->isObject() || v->as<QV4::ArrayObject>()) {
*error = true;
- qmlInfo(loader) << QQuickLoader::tr("setSource: value is not an object");
+ qmlWarning(loader) << QQuickLoader::tr("setSource: value is not an object");
} else {
*error = false;
valuemap = v;
diff --git a/src/quick/items/qquickloader_p_p.h b/src/quick/items/qquickloader_p_p.h
index a1e97b97d8..9b6267e011 100644
--- a/src/quick/items/qquickloader_p_p.h
+++ b/src/quick/items/qquickloader_p_p.h
@@ -94,7 +94,7 @@ public:
void incubatorStateChanged(QQmlIncubator::Status status);
void setInitialState(QObject *o);
void disposeInitialPropertyValues();
- QUrl resolveSourceUrl(QQmlV4Function *args);
+ static QUrl resolveSourceUrl(QQmlV4Function *args);
QV4::ReturnedValue extractInitialPropertyValues(QQmlV4Function *args, QObject *loader, bool *error);
qreal getImplicitWidth() const Q_DECL_OVERRIDE;
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp
index 4dcefc700d..c662efe40e 100644
--- a/src/quick/items/qquickmousearea.cpp
+++ b/src/quick/items/qquickmousearea.cpp
@@ -60,7 +60,8 @@ Q_DECLARE_LOGGING_CATEGORY(DBG_HOVER_TRACE)
QQuickMouseAreaPrivate::QQuickMouseAreaPrivate()
: enabled(true), scrollGestureEnabled(true), hovered(false), longPress(false),
moved(false), stealMouse(false), doubleClick(false), preventStealing(false),
- propagateComposedEvents(false), overThreshold(false), pressed(0)
+ propagateComposedEvents(false), overThreshold(false), pressed(0),
+ pressAndHoldInterval(-1)
#if QT_CONFIG(draganddrop)
, drag(0)
#endif
@@ -205,6 +206,9 @@ bool QQuickMouseAreaPrivate::propagateHelper(QQuickMouseEvent *ev, QQuickItem *i
the proxied item. When disabled, the mouse area becomes transparent to
mouse events.
+ MouseArea is an invisible Item, but it has a visible property.
+ When set to false, the mouse area becomes transparent to mouse events.
+
The \l pressed read-only property indicates whether or not the user is
holding down a mouse button over the mouse area. This property is often
used in bindings between properties in a user interface. The containsMouse
@@ -688,7 +692,7 @@ void QQuickMouseArea::mousePressEvent(QMouseEvent *event)
setKeepMouseGrab(d->stealMouse);
event->setAccepted(setPressed(event->button(), true, event->source()));
if (event->isAccepted())
- d->pressAndHoldTimer.start(QGuiApplication::styleHints()->mousePressAndHoldInterval(), this);
+ d->pressAndHoldTimer.start(pressAndHoldInterval(), this);
}
}
@@ -1306,6 +1310,48 @@ void QQuickMouseArea::setCursorShape(Qt::CursorShape shape)
#endif
+
+/*!
+ \qmlproperty int QtQuick::MouseArea::pressAndHoldInterval
+ \since 5.9
+
+ This property overrides the elapsed time in milliseconds before
+ \c pressAndHold is emitted.
+
+ If not explicitly set -- or after reset -- the value follows
+ \c QStyleHints::mousePressAndHoldInterval.
+
+ Typically it's sufficient to set this property globally using the
+ application style hint. This property should be used when varying intervals
+ are needed for certain MouseAreas.
+
+ \sa pressAndHold
+*/
+int QQuickMouseArea::pressAndHoldInterval() const
+{
+ Q_D(const QQuickMouseArea);
+ return d->pressAndHoldInterval > -1 ?
+ d->pressAndHoldInterval : QGuiApplication::styleHints()->mousePressAndHoldInterval();
+}
+
+void QQuickMouseArea::setPressAndHoldInterval(int interval)
+{
+ Q_D(QQuickMouseArea);
+ if (interval != d->pressAndHoldInterval) {
+ d->pressAndHoldInterval = interval;
+ emit pressAndHoldIntervalChanged();
+ }
+}
+
+void QQuickMouseArea::resetPressAndHoldInterval()
+{
+ Q_D(QQuickMouseArea);
+ if (d->pressAndHoldInterval > -1) {
+ d->pressAndHoldInterval = -1;
+ emit pressAndHoldIntervalChanged();
+ }
+}
+
/*!
\qmlpropertygroup QtQuick::MouseArea::drag
\qmlproperty Item QtQuick::MouseArea::drag.target
diff --git a/src/quick/items/qquickmousearea_p.h b/src/quick/items/qquickmousearea_p.h
index d90c8e1baa..ee166a2082 100644
--- a/src/quick/items/qquickmousearea_p.h
+++ b/src/quick/items/qquickmousearea_p.h
@@ -84,6 +84,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickMouseArea : public QQuickItem
Q_PROPERTY(Qt::CursorShape cursorShape READ cursorShape WRITE setCursorShape RESET unsetCursor NOTIFY cursorShapeChanged)
#endif
Q_PROPERTY(bool containsPress READ containsPress NOTIFY containsPressChanged REVISION 1)
+ Q_PROPERTY(int pressAndHoldInterval READ pressAndHoldInterval WRITE setPressAndHoldInterval NOTIFY pressAndHoldIntervalChanged RESET resetPressAndHoldInterval REVISION 9)
public:
QQuickMouseArea(QQuickItem *parent=0);
@@ -125,6 +126,10 @@ public:
void setCursorShape(Qt::CursorShape shape);
#endif
+ int pressAndHoldInterval() const;
+ void setPressAndHoldInterval(int interval);
+ void resetPressAndHoldInterval();
+
Q_SIGNALS:
void hoveredChanged();
void pressedChanged();
@@ -152,6 +157,7 @@ Q_SIGNALS:
void exited();
void canceled();
Q_REVISION(1) void containsPressChanged();
+ Q_REVISION(9) void pressAndHoldIntervalChanged();
protected:
void setHovered(bool);
diff --git a/src/quick/items/qquickmousearea_p_p.h b/src/quick/items/qquickmousearea_p_p.h
index 456b1866a3..2fa5f7cd44 100644
--- a/src/quick/items/qquickmousearea_p_p.h
+++ b/src/quick/items/qquickmousearea_p_p.h
@@ -95,6 +95,7 @@ public:
bool propagateComposedEvents : 1;
bool overThreshold : 1;
Qt::MouseButtons pressed;
+ int pressAndHoldInterval;
#if QT_CONFIG(draganddrop)
QQuickDrag *drag;
#endif
diff --git a/src/quick/items/qquickmultipointtoucharea.cpp b/src/quick/items/qquickmultipointtoucharea.cpp
index 706980cd13..62119effb2 100644
--- a/src/quick/items/qquickmultipointtoucharea.cpp
+++ b/src/quick/items/qquickmultipointtoucharea.cpp
@@ -60,6 +60,8 @@ DEFINE_BOOL_CONFIG_OPTION(qmlVisualTouchDebugging, QML_VISUAL_TOUCH_DEBUGGING)
The TouchPoint type contains information about a touch point, such as the current
position, pressure, and area.
+
+ \image touchpoint-metrics.png
*/
/*!
@@ -101,16 +103,29 @@ void QQuickTouchPoint::setY(qreal y)
}
/*!
+ \qmlproperty size QtQuick::TouchPoint::ellipseDiameters
+ \since 5.9
+
+ This property holds the major and minor axes of the ellipse representing
+ the covered area of the touch point.
+*/
+void QQuickTouchPoint::setEllipseDiameters(const QSizeF &d)
+{
+ if (_ellipseDiameters == d)
+ return;
+ _ellipseDiameters = d;
+ emit ellipseDiametersChanged();
+}
+
+/*!
\qmlproperty real QtQuick::TouchPoint::pressure
\qmlproperty vector2d QtQuick::TouchPoint::velocity
- \qmlproperty rectangle QtQuick::TouchPoint::area
These properties hold additional information about the current state of the touch point.
\list
\li \c pressure is a value in the range of 0.0 to 1.0.
\li \c velocity is a vector with magnitude reported in pixels per second.
- \li \c area is a rectangle covering the area of the touch point, centered on the current position of the touch point.
\endlist
Not all touch devices support velocity. If velocity is not supported, it will be reported
@@ -124,6 +139,26 @@ void QQuickTouchPoint::setPressure(qreal pressure)
emit pressureChanged();
}
+/*!
+ \qmlproperty real QtQuick::TouchPoint::rotation
+ \since 5.9
+
+ This property holds the angular orientation of this touch point. The return
+ value is in degrees, where zero (the default) indicates the finger or token
+ is pointing upwards, a negative angle means it's rotated to the left, and a
+ positive angle means it's rotated to the right. Most touchscreens do not
+ detect rotation, so zero is the most common value.
+
+ \sa QTouchEvent::TouchPoint::rotation()
+*/
+void QQuickTouchPoint::setRotation(qreal r)
+{
+ if (_rotation == r)
+ return;
+ _rotation = r;
+ emit rotationChanged();
+}
+
void QQuickTouchPoint::setVelocity(const QVector2D &velocity)
{
if (_velocity == velocity)
@@ -132,6 +167,18 @@ void QQuickTouchPoint::setVelocity(const QVector2D &velocity)
emit velocityChanged();
}
+/*!
+ \deprecated
+ \qmlproperty rectangle QtQuick::TouchPoint::area
+
+ A rectangle covering the area of the touch point, centered on the current
+ position of the touch point.
+
+ It is deprecated because a touch point is more correctly modeled as an ellipse,
+ whereas this rectangle represents the outer bounds of the ellipse after \l rotation.
+
+ \sa horizontalDiameter, verticalDiameter
+*/
void QQuickTouchPoint::setArea(const QRectF &area)
{
if (_area == area)
@@ -222,6 +269,25 @@ void QQuickTouchPoint::setSceneY(qreal sceneY)
}
/*!
+ \qmlproperty PointingDeviceUniqueId QtQuick::TouchPoint::uniqueId
+ \since 5.9
+
+ This property holds the unique ID of the touch point or token.
+
+ It is normally empty, because touchscreens cannot uniquely identify fingers.
+ But when it is set, it is expected to uniquely identify a specific token
+ (fiducial object).
+
+ Interpreting the contents of this ID requires knowledge of the hardware and
+ drivers in use (e.g. various TUIO-based touch surfaces).
+*/
+void QQuickTouchPoint::setUniqueId(const QPointingDeviceUniqueId &id)
+{
+ _uniqueId = id;
+ emit uniqueIdChanged();
+}
+
+/*!
\qmltype MultiPointTouchArea
\instantiates QQuickMultiPointTouchArea
\inqmlmodule QtQuick
@@ -691,9 +757,12 @@ void QQuickMultiPointTouchArea::updateTouchPoint(QQuickTouchPoint *dtp, const QT
{
//TODO: if !qmlDefined, could bypass setters.
// also, should only emit signals after all values have been set
+ dtp->setUniqueId(p->uniqueId());
dtp->setX(p->pos().x());
dtp->setY(p->pos().y());
+ dtp->setEllipseDiameters(p->ellipseDiameters());
dtp->setPressure(p->pressure());
+ dtp->setRotation(p->rotation());
dtp->setVelocity(p->velocity());
dtp->setArea(p->rect());
dtp->setStartX(p->startPos().x());
diff --git a/src/quick/items/qquickmultipointtoucharea_p.h b/src/quick/items/qquickmultipointtoucharea_p.h
index 541eb04764..25e1056712 100644
--- a/src/quick/items/qquickmultipointtoucharea_p.h
+++ b/src/quick/items/qquickmultipointtoucharea_p.h
@@ -67,10 +67,13 @@ class Q_AUTOTEST_EXPORT QQuickTouchPoint : public QObject
{
Q_OBJECT
Q_PROPERTY(int pointId READ pointId NOTIFY pointIdChanged)
+ Q_PROPERTY(QPointingDeviceUniqueId uniqueId READ uniqueId NOTIFY uniqueIdChanged REVISION 9)
Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
Q_PROPERTY(qreal x READ x NOTIFY xChanged)
Q_PROPERTY(qreal y READ y NOTIFY yChanged)
+ Q_PROPERTY(QSizeF ellipseDiameters READ ellipseDiameters NOTIFY ellipseDiametersChanged REVISION 9)
Q_PROPERTY(qreal pressure READ pressure NOTIFY pressureChanged)
+ Q_PROPERTY(qreal rotation READ rotation NOTIFY rotationChanged REVISION 9)
Q_PROPERTY(QVector2D velocity READ velocity NOTIFY velocityChanged)
Q_PROPERTY(QRectF area READ area NOTIFY areaChanged)
@@ -86,6 +89,7 @@ public:
: _id(0),
_x(0.0), _y(0.0),
_pressure(0.0),
+ _rotation(0),
_qmlDefined(qmlDefined),
_inUse(false),
_pressed(false),
@@ -97,15 +101,24 @@ public:
int pointId() const { return _id; }
void setPointId(int id);
+ QPointingDeviceUniqueId uniqueId() const { return _uniqueId; }
+ void setUniqueId(const QPointingDeviceUniqueId &id);
+
qreal x() const { return _x; }
void setX(qreal x);
qreal y() const { return _y; }
void setY(qreal y);
+ QSizeF ellipseDiameters() const { return _ellipseDiameters; }
+ void setEllipseDiameters(const QSizeF &d);
+
qreal pressure() const { return _pressure; }
void setPressure(qreal pressure);
+ qreal rotation() const { return _rotation; }
+ void setRotation(qreal r);
+
QVector2D velocity() const { return _velocity; }
void setVelocity(const QVector2D &velocity);
@@ -141,9 +154,12 @@ public:
Q_SIGNALS:
void pressedChanged();
void pointIdChanged();
+ Q_REVISION(9) void uniqueIdChanged();
void xChanged();
void yChanged();
+ Q_REVISION(9) void ellipseDiametersChanged();
void pressureChanged();
+ Q_REVISION(9) void rotationChanged();
void velocityChanged();
void areaChanged();
void startXChanged();
@@ -159,6 +175,8 @@ private:
qreal _x;
qreal _y;
qreal _pressure;
+ qreal _rotation;
+ QSizeF _ellipseDiameters;
QVector2D _velocity;
QRectF _area;
bool _qmlDefined;
@@ -170,6 +188,7 @@ private:
qreal _previousY;
qreal _sceneX;
qreal _sceneY;
+ QPointingDeviceUniqueId _uniqueId;
};
class QQuickGrabGestureEvent : public QObject
diff --git a/src/quick/items/qquickopenglshadereffect.cpp b/src/quick/items/qquickopenglshadereffect.cpp
index c7b851d33e..4f4c403483 100644
--- a/src/quick/items/qquickopenglshadereffect.cpp
+++ b/src/quick/items/qquickopenglshadereffect.cpp
@@ -288,14 +288,14 @@ void QQuickOpenGLShaderEffectCommon::updateParseLog(bool ignoreAttributes)
parseLog.clear();
if (!ignoreAttributes) {
if (!attributes.contains(qtPositionAttributeName())) {
- parseLog += QLatin1String("Warning: Missing reference to \'");
- parseLog += QLatin1String(qtPositionAttributeName());
- parseLog += QLatin1String("\'.\n");
+ parseLog += QLatin1String("Warning: Missing reference to \'")
+ + QLatin1String(qtPositionAttributeName())
+ + QLatin1String("\'.\n");
}
if (!attributes.contains(qtTexCoordAttributeName())) {
- parseLog += QLatin1String("Warning: Missing reference to \'");
- parseLog += QLatin1String(qtTexCoordAttributeName());
- parseLog += QLatin1String("\'.\n");
+ parseLog += QLatin1String("Warning: Missing reference to \'")
+ + QLatin1String(qtTexCoordAttributeName())
+ + QLatin1String("\'.\n");
}
}
bool respectsMatrix = false;
@@ -922,9 +922,7 @@ QSGNode *QQuickOpenGLShaderEffect::handleUpdatePaintNode(QSGNode *oldNode, QQuic
if (!mesh->validateAttributes(m_common.attributes, &posIndex)) {
QString log = mesh->log();
if (!log.isNull()) {
- m_log = parseLog();
- m_log += QLatin1String("*** Mesh ***\n");
- m_log += log;
+ m_log = parseLog() + QLatin1String("*** Mesh ***\n") + log;
m_status = QQuickShaderEffect::Error;
emit m_item->logChanged();
emit m_item->statusChanged();
diff --git a/src/quick/items/qquickopenglshadereffect_p.h b/src/quick/items/qquickopenglshadereffect_p.h
index 64e79a9343..bc2e2975ee 100644
--- a/src/quick/items/qquickopenglshadereffect_p.h
+++ b/src/quick/items/qquickopenglshadereffect_p.h
@@ -70,7 +70,6 @@ QT_REQUIRE_CONFIG(quick_shadereffect);
QT_BEGIN_NAMESPACE
class QSGContext;
-class QSignalMapper;
class QFileSelector;
class QQuickOpenGLCustomMaterialShader;
diff --git a/src/quick/items/qquickopenglshadereffectnode.cpp b/src/quick/items/qquickopenglshadereffectnode.cpp
index 02b76b2dbc..2d2cffbeed 100644
--- a/src/quick/items/qquickopenglshadereffectnode.cpp
+++ b/src/quick/items/qquickopenglshadereffectnode.cpp
@@ -260,14 +260,12 @@ void QQuickCustomMaterialShader::compile()
m_log.clear();
m_compiled = true;
- if (!program()->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShader())) {
- m_log += QLatin1String("*** Vertex shader ***\n");
- m_log += program()->log();
+ if (!program()->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexShader())) {
+ m_log += QLatin1String("*** Vertex shader ***\n") + program()->log();
m_compiled = false;
}
- if (!program()->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShader())) {
- m_log += QLatin1String("*** Fragment shader ***\n");
- m_log += program()->log();
+ if (!program()->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShader())) {
+ m_log += QLatin1String("*** Fragment shader ***\n") + program()->log();
m_compiled = false;
}
diff --git a/src/quick/items/qquickpainteditem.cpp b/src/quick/items/qquickpainteditem.cpp
index c5155c9c35..3911bb0f28 100644
--- a/src/quick/items/qquickpainteditem.cpp
+++ b/src/quick/items/qquickpainteditem.cpp
@@ -53,7 +53,7 @@ class QQuickPaintedItemTextureProvider : public QSGTextureProvider
{
public:
QSGPainterNode *node;
- QSGTexture *texture() const { return node ? node->texture() : 0; }
+ QSGTexture *texture() const override { return node ? node->texture() : 0; }
void fireTextureChanged() { emit textureChanged(); }
};
diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp
index e54ee66fe5..53e547fe98 100644
--- a/src/quick/items/qquickpathview.cpp
+++ b/src/quick/items/qquickpathview.cpp
@@ -63,13 +63,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcItemViewDelegateLifecycle)
const qreal MinimumFlickVelocity = 75.0;
-inline qreal qmlMod(qreal x, qreal y)
-{
- using std::fmod;
- return fmod(x, y);
-}
-
-static QQmlOpenMetaObjectType *qPathViewAttachedType = 0;
+static QQmlOpenMetaObjectType *qPathViewAttachedType = nullptr;
QQuickPathViewAttached::QQuickPathViewAttached(QObject *parent)
: QObject(parent), m_percent(-1), m_view(0), m_onPath(false), m_isCurrent(false)
@@ -96,7 +90,7 @@ void QQuickPathViewAttached::setValue(const QByteArray &name, const QVariant &va
}
QQuickPathViewPrivate::QQuickPathViewPrivate()
- : path(0), currentIndex(0), currentItemOffset(0.0), startPc(0)
+ : path(nullptr), currentIndex(0), currentItemOffset(0.0), startPc(0)
, offset(0.0), offsetAdj(0.0), mappedRange(1.0), mappedCache(0.0)
, stealMouse(false), ownModel(false), interactive(true), haveHighlightRange(true)
, autoHighlight(true), highlightUp(false), layoutScheduled(false)
@@ -106,7 +100,7 @@ QQuickPathViewPrivate::QQuickPathViewPrivate()
, moveOffset(this, &QQuickPathViewPrivate::setAdjustedOffset), flickDuration(0)
, pathItems(-1), requestedIndex(-1), cacheSize(0), requestedZ(0)
, moveReason(Other), movementDirection(QQuickPathView::Shortest), moveDirection(QQuickPathView::Shortest)
- , attType(0), highlightComponent(0), highlightItem(0)
+ , attType(nullptr), highlightComponent(nullptr), highlightItem(nullptr)
, moveHighlight(this, &QQuickPathViewPrivate::setHighlightPosition)
, highlightPosition(0)
, highlightRangeStart(0), highlightRangeEnd(0)
@@ -143,7 +137,7 @@ QQuickItem *QQuickPathViewPrivate::getItem(int modelIndex, qreal z, bool async)
if (!delegateValidated) {
delegateValidated = true;
QObject* delegate = q->delegate();
- qmlInfo(delegate ? delegate : q) << QQuickPathView::tr("Delegate must be of Item type");
+ qmlWarning(delegate ? delegate : q) << QQuickPathView::tr("Delegate must be of Item type");
}
}
} else {
@@ -163,7 +157,7 @@ void QQuickPathView::createdItem(int index, QObject *object)
if (d->requestedIndex != index) {
qPathViewAttachedType = d->attachedType();
QQuickPathViewAttached *att = static_cast<QQuickPathViewAttached *>(qmlAttachedPropertiesObject<QQuickPathView>(item));
- qPathViewAttachedType = 0;
+ qPathViewAttachedType = nullptr;
if (att) {
att->m_view = this;
att->setOnPath(false);
@@ -186,7 +180,7 @@ void QQuickPathView::initItem(int index, QObject *object)
item->setParentItem(this);
qPathViewAttachedType = d->attachedType();
QQuickPathViewAttached *att = static_cast<QQuickPathViewAttached *>(qmlAttachedPropertiesObject<QQuickPathView>(item));
- qPathViewAttachedType = 0;
+ qPathViewAttachedType = nullptr;
if (att) {
att->m_view = this;
qreal percent = d->positionOfIndex(index);
@@ -215,7 +209,7 @@ void QQuickPathViewPrivate::releaseItem(QQuickItem *item)
att->setOnPath(false);
} else if (flags & QQmlInstanceModel::Destroyed) {
// but we still reference it
- item->setParentItem(0);
+ item->setParentItem(nullptr);
}
}
@@ -244,7 +238,7 @@ void QQuickPathViewPrivate::clear()
{
if (currentItem) {
releaseItem(currentItem);
- currentItem = 0;
+ currentItem = nullptr;
}
for (QQuickItem *p : qAsConst(items))
releaseItem(p);
@@ -280,13 +274,13 @@ qreal QQuickPathViewPrivate::positionOfIndex(qreal index) const
|| snapMode != QQuickPathView::NoSnap))
start = highlightRangeStart;
qreal globalPos = index + offset;
- globalPos = qmlMod(globalPos, qreal(modelCount)) / modelCount;
+ globalPos = std::fmod(globalPos, qreal(modelCount)) / modelCount;
if (pathItems != -1 && pathItems < modelCount) {
globalPos += start / mappedRange;
- globalPos = qmlMod(globalPos, 1.0);
+ globalPos = std::fmod(globalPos, qreal(1.0));
pos = globalPos * mappedRange;
} else {
- pos = qmlMod(globalPos + start, 1.0);
+ pos = std::fmod(globalPos + start, qreal(1.0));
}
}
@@ -315,13 +309,13 @@ void QQuickPathViewPrivate::createHighlight()
bool changed = false;
if (highlightItem) {
- highlightItem->setParentItem(0);
+ highlightItem->setParentItem(nullptr);
highlightItem->deleteLater();
- highlightItem = 0;
+ highlightItem = nullptr;
changed = true;
}
- QQuickItem *item = 0;
+ QQuickItem *item = nullptr;
if (highlightComponent) {
QQmlContext *creationContext = highlightComponent->creationContext();
QQmlContext *highlightContext = new QQmlContext(
@@ -397,7 +391,7 @@ void QQuickPathViewPrivate::setHighlightPosition(qreal pos)
qreal range = qreal(modelCount);
// calc normalized position of highlight relative to offset
- qreal relativeHighlight = qmlMod(pos + offset, range) / range;
+ qreal relativeHighlight = std::fmod(pos + offset, range) / range;
if (!highlightUp && relativeHighlight > end / mappedRange) {
qreal diff = 1.0 - relativeHighlight;
@@ -636,7 +630,7 @@ void QQuickPathView::setModel(const QVariant &m)
d->modelVariant = model;
QObject *object = qvariant_cast<QObject*>(model);
- QQmlInstanceModel *vim = 0;
+ QQmlInstanceModel *vim = nullptr;
if (object && (vim = qobject_cast<QQmlInstanceModel *>(object))) {
if (d->ownModel) {
delete d->model;
@@ -710,16 +704,23 @@ void QQuickPathView::setPath(QQuickPath *path)
qmlobject_disconnect(d->path, QQuickPath, SIGNAL(changed()),
this, QQuickPathView, SLOT(pathUpdated()));
d->path = path;
- qmlobject_connect(d->path, QQuickPath, SIGNAL(changed()),
- this, QQuickPathView, SLOT(pathUpdated()));
- if (d->isValid() && isComponentComplete()) {
+
+ if (path) {
+ qmlobject_connect(d->path, QQuickPath, SIGNAL(changed()),
+ this, QQuickPathView, SLOT(pathUpdated()));
+ }
+
+ if (isComponentComplete()) {
d->clear();
- if (d->attType) {
- d->attType->release();
- d->attType = 0;
+ if (d->isValid()) {
+ if (d->attType) {
+ d->attType->release();
+ d->attType = nullptr;
+ }
+ d->regenerate();
}
- d->regenerate();
}
+
emit pathChanged();
}
@@ -755,7 +756,7 @@ void QQuickPathView::setCurrentIndex(int idx)
}
int oldCurrentIdx = d->currentIndex;
QQuickItem *oldCurrentItem = d->currentItem;
- d->currentItem = 0;
+ d->currentItem = nullptr;
d->moveReason = QQuickPathViewPrivate::SetIndex;
d->currentIndex = idx;
if (d->modelCount) {
@@ -836,7 +837,7 @@ void QQuickPathViewPrivate::setOffset(qreal o)
if (offset != o) {
if (isValid() && q->isComponentComplete()) {
qreal oldOffset = offset;
- offset = qmlMod(o, qreal(modelCount));
+ offset = std::fmod(o, qreal(modelCount));
if (offset < 0)
offset += qreal(modelCount);
qCDebug(lcItemViewDelegateLifecycle) << o << "was" << oldOffset << "now" << offset;
@@ -902,7 +903,7 @@ void QQuickPathView::setHighlight(QQmlComponent *highlight)
\sa highlight
*/
-QQuickItem *QQuickPathView::highlightItem()
+QQuickItem *QQuickPathView::highlightItem() const
{
Q_D(const QQuickPathView);
return d->highlightItem;
@@ -1237,7 +1238,7 @@ QQmlComponent *QQuickPathView::delegate() const
return dataModel->delegate();
}
- return 0;
+ return nullptr;
}
void QQuickPathView::setDelegate(QQmlComponent *delegate)
@@ -1468,7 +1469,7 @@ void QQuickPathView::positionViewAtIndex(int index, int mode)
// Small offset since the last point coincides with the first and
// this the only "end" position that gives the expected visual result.
qreal adj = sizeof(qreal) == sizeof(float) ? 0.00001f : 0.000000000001;
- endOffset = qmlMod(beginOffset + count, d->modelCount) - adj;
+ endOffset = std::fmod(beginOffset + count, qreal(d->modelCount)) - adj;
}
qreal offset = d->offset;
switch (mode) {
@@ -1489,8 +1490,8 @@ void QQuickPathView::positionViewAtIndex(int index, int mode)
case Contain:
if ((beginOffset < endOffset && (d->offset < beginOffset || d->offset > endOffset))
|| (d->offset < beginOffset && d->offset > endOffset)) {
- qreal diff1 = qmlMod(beginOffset - d->offset + d->modelCount, d->modelCount);
- qreal diff2 = qmlMod(d->offset - endOffset + d->modelCount, d->modelCount);
+ qreal diff1 = std::fmod(beginOffset - d->offset + d->modelCount, qreal(d->modelCount));
+ qreal diff2 = std::fmod(d->offset - endOffset + d->modelCount, qreal(d->modelCount));
if (diff1 < diff2)
offset = beginOffset;
else
@@ -1518,7 +1519,7 @@ int QQuickPathView::indexAt(qreal x, qreal y) const
{
Q_D(const QQuickPathView);
QQuickItem *item = itemAt(x, y);
- return item ? d->model->indexOf(item, 0) : -1;
+ return item ? d->model->indexOf(item, nullptr) : -1;
}
/*!
@@ -1533,7 +1534,7 @@ QQuickItem *QQuickPathView::itemAt(qreal x, qreal y) const
{
Q_D(const QQuickPathView);
if (!d->isValid())
- return 0;
+ return nullptr;
for (QQuickItem *item : d->items) {
QPointF p = item->mapFromItem(this, QPointF(x, y));
@@ -1541,7 +1542,7 @@ QQuickItem *QQuickPathView::itemAt(qreal x, qreal y) const
return item;
}
- return 0;
+ return nullptr;
}
QPointF QQuickPathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const
@@ -1606,7 +1607,7 @@ qreal QQuickPathViewPrivate::calcVelocity() const
return velocity;
}
-qint64 QQuickPathViewPrivate::computeCurrentTime(QInputEvent *event)
+qint64 QQuickPathViewPrivate::computeCurrentTime(QInputEvent *event) const
{
if (0 != event->timestamp())
return event->timestamp();
@@ -1810,7 +1811,7 @@ bool QQuickPathView::sendMouseEvent(QMouseEvent *event)
QPointF localPos = mapFromScene(event->windowPos());
QQuickWindow *c = window();
- QQuickItem *grabber = c ? c->mouseGrabberItem() : 0;
+ QQuickItem *grabber = c ? c->mouseGrabberItem() : nullptr;
if (grabber == this && d->stealMouse) {
// we are already the grabber and we do want the mouse event to ourselves.
return true;
@@ -1836,7 +1837,7 @@ bool QQuickPathView::sendMouseEvent(QMouseEvent *event)
default:
break;
}
- grabber = c ? c->mouseGrabberItem() : 0;
+ grabber = c ? c->mouseGrabberItem() : nullptr;
if ((grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this) || grabberDisabled) {
grabMouse();
}
@@ -1915,7 +1916,7 @@ void QQuickPathView::componentComplete()
if (d->model) {
d->modelCount = d->model->count();
if (d->modelCount && d->currentIndex != 0) // an initial value has been provided for currentIndex
- d->offset = qmlMod(d->modelCount - currentIndexRemainder(d->currentIndex, d->modelCount), d->modelCount);
+ d->offset = std::fmod(qreal(d->modelCount - currentIndexRemainder(d->currentIndex, d->modelCount)), qreal(d->modelCount));
}
d->createHighlight();
@@ -1951,7 +1952,7 @@ void QQuickPathView::refill()
QList<QQuickItem*>::iterator it = d->items.begin();
while (it != d->items.end()) {
QQuickItem *item = *it;
- int idx = d->model->indexOf(item, 0);
+ int idx = d->model->indexOf(item, nullptr);
qreal pos = d->positionOfIndex(idx);
if (lcItemViewDelegateLifecycle().isDebugEnabled()) {
QQuickText *text = qmlobject_cast<QQuickText*>(item);
@@ -1996,7 +1997,7 @@ void QQuickPathView::refill()
startPos = 2.0;
for (QQuickItem * item : qAsConst(d->items)) {
- int idx = d->model->indexOf(item, 0);
+ int idx = d->model->indexOf(item, nullptr);
qreal curPos = d->positionOfIndex(idx);
if (curPos > endPos) {
endPos = curPos;
@@ -2198,7 +2199,7 @@ void QQuickPathView::modelUpdated(const QQmlChangeSet &changeSet, bool reset)
if (QQuickPathViewAttached *att = d->attached(d->currentItem))
att->setIsCurrentItem(true);
d->releaseItem(d->currentItem);
- d->currentItem = 0;
+ d->currentItem = nullptr;
}
d->currentIndex = qMin(r.index, d->modelCount - r.count - 1);
currentChanged = true;
@@ -2231,7 +2232,7 @@ void QQuickPathView::modelUpdated(const QQmlChangeSet &changeSet, bool reset)
d->modelCount += i.count;
}
- d->offset = qmlMod(d->offset, d->modelCount);
+ d->offset = std::fmod(d->offset, qreal(d->modelCount));
if (d->offset < 0)
d->offset += d->modelCount;
if (d->currentIndex == -1)
@@ -2249,7 +2250,7 @@ void QQuickPathView::modelUpdated(const QQmlChangeSet &changeSet, bool reset)
d->tl.reset(d->moveOffset);
} else {
if (!d->flicking && !d->moving && d->haveHighlightRange && d->highlightRangeMode == QQuickPathView::StrictlyEnforceRange) {
- d->offset = qmlMod(d->modelCount - d->currentIndex, d->modelCount);
+ d->offset = std::fmod(qreal(d->modelCount - d->currentIndex), qreal(d->modelCount));
changedOffset = true;
}
d->updateMappedRange();
@@ -2295,10 +2296,10 @@ int QQuickPathViewPrivate::calcCurrentIndex()
{
int current = 0;
if (modelCount && model && items.count()) {
- offset = qmlMod(offset, modelCount);
+ offset = std::fmod(offset, qreal(modelCount));
if (offset < 0)
offset += modelCount;
- current = qRound(qAbs(qmlMod(modelCount - offset, modelCount)));
+ current = qRound(qAbs(std::fmod(modelCount - offset, qreal(modelCount))));
current = current % modelCount;
}
@@ -2312,7 +2313,7 @@ void QQuickPathViewPrivate::createCurrentItem()
bool inItems = false;
for (QQuickItem *item : qAsConst(items)) {
- if (model->indexOf(item, 0) == currentIndex) {
+ if (model->indexOf(item, nullptr) == currentIndex) {
inItems = true;
break;
}
@@ -2350,7 +2351,7 @@ void QQuickPathViewPrivate::updateCurrent()
}
int oldCurrentIndex = currentIndex;
currentIndex = idx;
- currentItem = 0;
+ currentItem = nullptr;
createCurrentItem();
if (oldCurrentIndex != currentIndex)
emit q->currentIndexChanged();
@@ -2383,7 +2384,7 @@ void QQuickPathViewPrivate::snapToIndex(int index, MovementReason reason)
if (!model || modelCount <= 0)
return;
- qreal targetOffset = qmlMod(modelCount - index, modelCount);
+ qreal targetOffset = std::fmod(qreal(modelCount - index), qreal(modelCount));
if (offset == targetOffset)
return;
diff --git a/src/quick/items/qquickpathview_p.h b/src/quick/items/qquickpathview_p.h
index a44d1be5c4..0e237b7b74 100644
--- a/src/quick/items/qquickpathview_p.h
+++ b/src/quick/items/qquickpathview_p.h
@@ -102,7 +102,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPathView : public QQuickItem
Q_PROPERTY(int cacheItemCount READ cacheItemCount WRITE setCacheItemCount NOTIFY cacheItemCountChanged)
public:
- QQuickPathView(QQuickItem *parent=0);
+ QQuickPathView(QQuickItem *parent = nullptr);
virtual ~QQuickPathView();
QVariant model() const;
@@ -121,7 +121,7 @@ public:
QQmlComponent *highlight() const;
void setHighlight(QQmlComponent *highlight);
- QQuickItem *highlightItem();
+ QQuickItem *highlightItem() const;
enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
Q_ENUM(HighlightRangeMode)
@@ -221,14 +221,14 @@ Q_SIGNALS:
void cacheItemCountChanged();
protected:
- void updatePolish() Q_DECL_OVERRIDE;
- void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
- void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
- void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void updatePolish() override;
+ void mousePressEvent(QMouseEvent *event) override;
+ void mouseMoveEvent(QMouseEvent *event) override;
+ void mouseReleaseEvent(QMouseEvent *) override;
bool sendMouseEvent(QMouseEvent *event);
- bool childMouseEventFilter(QQuickItem *, QEvent *) Q_DECL_OVERRIDE;
- void mouseUngrabEvent() Q_DECL_OVERRIDE;
- void componentComplete() Q_DECL_OVERRIDE;
+ bool childMouseEventFilter(QQuickItem *, QEvent *) override;
+ void mouseUngrabEvent() override;
+ void componentComplete() override;
private Q_SLOTS:
void refill();
@@ -259,7 +259,7 @@ public:
QQuickPathViewAttached(QObject *parent);
~QQuickPathViewAttached();
- QQuickPathView *view() { return m_view; }
+ QQuickPathView *view() const { return m_view; }
bool isCurrentItem() const { return m_isCurrent; }
void setIsCurrentItem(bool c) {
diff --git a/src/quick/items/qquickpathview_p_p.h b/src/quick/items/qquickpathview_p_p.h
index 64abe3d1dc..d58c986d1a 100644
--- a/src/quick/items/qquickpathview_p_p.h
+++ b/src/quick/items/qquickpathview_p_p.h
@@ -80,7 +80,7 @@ public:
void init();
- void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) Q_DECL_OVERRIDE {
+ void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) override {
if (change.sizeChange() && (!highlightItem || item != highlightItem)) {
if (QQuickPathViewAttached *att = attached(item))
att->m_percent = -1;
@@ -129,7 +129,7 @@ public:
QPointF pointNear(const QPointF &point, qreal *nearPercent=0) const;
void addVelocitySample(qreal v);
qreal calcVelocity() const;
- qint64 computeCurrentTime(QInputEvent *event);
+ qint64 computeCurrentTime(QInputEvent *event) const;
void setDragging(bool d);
QQuickPath *path;
diff --git a/src/quick/items/qquickpositioners.cpp b/src/quick/items/qquickpositioners.cpp
index e22427ca49..05d3ae0191 100644
--- a/src/quick/items/qquickpositioners.cpp
+++ b/src/quick/items/qquickpositioners.cpp
@@ -290,6 +290,11 @@ void QQuickBasePositioner::itemChange(ItemChange change, const ItemChangeData &v
QQuickItem::itemChange(change, value);
}
+void QQuickBasePositioner::forceLayout()
+{
+ updatePolish();
+}
+
void QQuickBasePositioner::prePositioning()
{
Q_D(QQuickBasePositioner);
@@ -401,6 +406,8 @@ void QQuickBasePositioner::prePositioning()
//Set implicit size to the size of its children
setImplicitSize(contentSize.width(), contentSize.height());
+
+ emit positioningComplete();
}
void QQuickBasePositioner::positionItem(qreal x, qreal y, PositionedItem *target)
@@ -910,6 +917,28 @@ void QQuickPositionerAttached::setIsLastItem(bool isLastItem)
\sa Grid::spacing
*/
+/*!
+ \qmlmethod QtQuick::Column::forceLayout()
+ \since 5.9
+
+ Column typically positions its children once per frame. This means that
+ inside script blocks it is possible for the underlying children to have changed,
+ but the Column to have not yet been updated accordingly.
+
+ This method forces the Column to immediately respond to any outstanding
+ changes in its children.
+
+ \b Note: methods in general should only be called after the Component has completed.
+*/
+/*!
+ \qmlsignal QtQuick::Column::positioningComplete()
+ \since 5.9
+
+ This signal is emitted when positioning has been completed.
+
+ The corresponding handler is \c onPositioningComplete.
+*/
+
QQuickColumn::QQuickColumn(QQuickItem *parent)
: QQuickBasePositioner(Vertical, parent)
{
@@ -957,7 +986,7 @@ void QQuickColumn::reportConflictingAnchors()
}
}
if (d->anchorConflict) {
- qmlInfo(this) << "Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column."
+ qmlWarning(this) << "Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column."
<< " Column will not function.";
}
}
@@ -1077,6 +1106,27 @@ void QQuickColumn::reportConflictingAnchors()
\sa Grid::spacing
*/
+/*!
+ \qmlmethod QtQuick::Row::forceLayout()
+ \since 5.9
+
+ Row typically positions its children once per frame. This means that
+ inside script blocks it is possible for the underlying children to have changed,
+ but the Row to have not yet been updated accordingly.
+
+ This method forces the Row to immediately respond to any outstanding
+ changes in its children.
+
+ \b Note: methods in general should only be called after the Component has completed.
+*/
+/*!
+ \qmlsignal QtQuick::Row::positioningComplete()
+ \since 5.9
+
+ This signal is emitted when positioning has been completed.
+
+ The corresponding handler is \c onPositioningComplete.
+*/
class QQuickRowPrivate : public QQuickBasePositionerPrivate
{
@@ -1224,7 +1274,7 @@ void QQuickRow::reportConflictingAnchors()
}
}
if (d->anchorConflict)
- qmlInfo(this) << "Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row."
+ qmlWarning(this) << "Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row."
<< " Row will not function.";
}
@@ -1355,6 +1405,27 @@ void QQuickRow::reportConflictingAnchors()
\sa rows, columns
*/
+/*!
+ \qmlmethod QtQuick::Grid::forceLayout()
+ \since 5.9
+
+ Grid typically positions its children once per frame. This means that
+ inside script blocks it is possible for the underlying children to have changed,
+ but the Grid to have not yet been updated accordingly.
+
+ This method forces the Grid to immediately respond to any outstanding
+ changes in its children.
+
+ \b Note: methods in general should only be called after the Component has completed.
+*/
+/*!
+ \qmlsignal QtQuick::Grid::positioningComplete()
+ \since 5.9
+
+ This signal is emitted when positioning has been completed.
+
+ The corresponding handler is \c onPositioningComplete.
+*/
class QQuickGridPrivate : public QQuickBasePositionerPrivate
{
@@ -1808,7 +1879,7 @@ void QQuickGrid::reportConflictingAnchors()
}
}
if (d->anchorConflict)
- qmlInfo(this) << "Cannot specify anchors for items inside Grid." << " Grid will not function.";
+ qmlWarning(this) << "Cannot specify anchors for items inside Grid." << " Grid will not function.";
}
/*!
@@ -1920,6 +1991,28 @@ void QQuickGrid::reportConflictingAnchors()
\sa Grid::spacing
*/
+/*!
+ \qmlmethod QtQuick::Flow::forceLayout()
+ \since 5.9
+
+ Flow typically positions its children once per frame. This means that
+ inside script blocks it is possible for the underlying children to have changed,
+ but the Flow to have not yet been updated accordingly.
+
+ This method forces the Flow to immediately respond to any outstanding
+ changes in its children.
+
+
+ \b Note: methods in general should only be called after the Component has completed.
+*/
+/*!
+ \qmlsignal QtQuick::Flow::positioningComplete()
+ \since 5.9
+
+ This signal is emitted when positioning has been completed.
+
+ The corresponding handler is \c onPositioningComplete.
+*/
class QQuickFlowPrivate : public QQuickBasePositionerPrivate
{
@@ -2121,7 +2214,7 @@ void QQuickFlow::reportConflictingAnchors()
}
}
if (d->anchorConflict)
- qmlInfo(this) << "Cannot specify anchors for items inside Flow." << " Flow will not function.";
+ qmlWarning(this) << "Cannot specify anchors for items inside Flow." << " Flow will not function.";
}
QT_END_NAMESPACE
diff --git a/src/quick/items/qquickpositioners_p.h b/src/quick/items/qquickpositioners_p.h
index c25ecd6dbc..ae6e795794 100644
--- a/src/quick/items/qquickpositioners_p.h
+++ b/src/quick/items/qquickpositioners_p.h
@@ -155,6 +155,8 @@ public:
void setBottomPadding(qreal padding);
void resetBottomPadding();
+ Q_REVISION(9) Q_INVOKABLE void forceLayout();
+
protected:
QQuickBasePositioner(QQuickBasePositionerPrivate &dd, PositionerType at, QQuickItem *parent);
void componentComplete() Q_DECL_OVERRIDE;
@@ -172,6 +174,7 @@ Q_SIGNALS:
Q_REVISION(6) void leftPaddingChanged();
Q_REVISION(6) void rightPaddingChanged();
Q_REVISION(6) void bottomPaddingChanged();
+ Q_REVISION(9) void positioningComplete();
protected Q_SLOTS:
void prePositioning();
diff --git a/src/quick/items/qquickrepeater.cpp b/src/quick/items/qquickrepeater.cpp
index 4f46f41b0d..a7254464ed 100644
--- a/src/quick/items/qquickrepeater.cpp
+++ b/src/quick/items/qquickrepeater.cpp
@@ -423,7 +423,7 @@ void QQuickRepeater::initItem(int index, QObject *object)
if (!d->delegateValidated) {
d->delegateValidated = true;
QObject* delegate = this->delegate();
- qmlInfo(delegate ? delegate : this) << QQuickRepeater::tr("Delegate must be of Item type");
+ qmlWarning(delegate ? delegate : this) << QQuickRepeater::tr("Delegate must be of Item type");
}
}
return;
diff --git a/src/quick/items/qquickscreen.cpp b/src/quick/items/qquickscreen.cpp
index 5d01a2af9d..20c6973ee1 100644
--- a/src/quick/items/qquickscreen.cpp
+++ b/src/quick/items/qquickscreen.cpp
@@ -207,100 +207,181 @@ QT_BEGIN_NAMESPACE
By default it is set to the value of the QScreen that the window uses.
*/
-QQuickScreenAttached::QQuickScreenAttached(QObject* attachee)
- : QObject(attachee)
- , m_screen(NULL)
- , m_window(NULL)
- , m_updateMask(0)
- , m_updateMaskSet(false)
+QQuickScreenInfo::QQuickScreenInfo(QObject *parent, QScreen *wrappedScreen)
+ : QObject(parent)
+ , m_screen(wrappedScreen)
{
- m_attachee = qobject_cast<QQuickItem*>(attachee);
-
- if (m_attachee) {
- QQuickItemPrivate::get(m_attachee)->extra.value().screenAttached = this;
-
- if (m_attachee->window()) //It might not be assigned to a window yet
- windowChanged(m_attachee->window());
- } else {
- QQuickWindow *window = qobject_cast<QQuickWindow*>(attachee);
- if (window)
- windowChanged(window);
- }
-
- if (!m_screen)
- screenChanged(QGuiApplication::primaryScreen());
}
-QString QQuickScreenAttached::name() const
+QString QQuickScreenInfo::name() const
{
if (!m_screen)
return QString();
return m_screen->name();
}
-int QQuickScreenAttached::width() const
+int QQuickScreenInfo::width() const
{
if (!m_screen)
return 0;
return m_screen->size().width();
}
-int QQuickScreenAttached::height() const
+int QQuickScreenInfo::height() const
{
if (!m_screen)
return 0;
return m_screen->size().height();
}
-int QQuickScreenAttached::desktopAvailableWidth() const
+int QQuickScreenInfo::desktopAvailableWidth() const
{
if (!m_screen)
return 0;
return m_screen->availableVirtualSize().width();
}
-int QQuickScreenAttached::desktopAvailableHeight() const
+int QQuickScreenInfo::desktopAvailableHeight() const
{
if (!m_screen)
return 0;
return m_screen->availableVirtualSize().height();
}
-qreal QQuickScreenAttached::logicalPixelDensity() const
+qreal QQuickScreenInfo::logicalPixelDensity() const
{
if (!m_screen)
return 0.0;
return m_screen->logicalDotsPerInch() / 25.4;
}
-qreal QQuickScreenAttached::pixelDensity() const
+qreal QQuickScreenInfo::pixelDensity() const
{
if (!m_screen)
return 0.0;
return m_screen->physicalDotsPerInch() / 25.4;
}
-qreal QQuickScreenAttached::devicePixelRatio() const
+qreal QQuickScreenInfo::devicePixelRatio() const
{
if (!m_screen)
return 1.0;
return m_screen->devicePixelRatio();
}
-Qt::ScreenOrientation QQuickScreenAttached::primaryOrientation() const
+Qt::ScreenOrientation QQuickScreenInfo::primaryOrientation() const
{
if (!m_screen)
return Qt::PrimaryOrientation;
return m_screen->primaryOrientation();
}
-Qt::ScreenOrientation QQuickScreenAttached::orientation() const
+Qt::ScreenOrientation QQuickScreenInfo::orientation() const
{
if (!m_screen)
return Qt::PrimaryOrientation;
return m_screen->orientation();
}
+int QQuickScreenInfo::virtualX() const
+{
+ if (!m_screen)
+ return 0;
+ return m_screen->geometry().topLeft().x();
+}
+
+int QQuickScreenInfo::virtualY() const
+{
+ if (!m_screen)
+ return 0;
+ return m_screen->geometry().topLeft().y();
+}
+
+void QQuickScreenInfo::setWrappedScreen(QScreen *screen)
+{
+ if (screen == m_screen)
+ return;
+
+ QScreen *oldScreen = m_screen;
+ m_screen = screen;
+
+ if (oldScreen)
+ oldScreen->disconnect(this);
+
+ if (!screen) //Don't bother emitting signals, because the new values are garbage anyways
+ return;
+
+ if (!oldScreen || screen->geometry() != oldScreen->geometry()) {
+ emit virtualXChanged();
+ emit virtualYChanged();
+ }
+ if (!oldScreen || screen->size() != oldScreen->size()) {
+ emit widthChanged();
+ emit heightChanged();
+ }
+ if (!oldScreen || screen->name() != oldScreen->name())
+ emit nameChanged();
+ if (!oldScreen || screen->orientation() != oldScreen->orientation())
+ emit orientationChanged();
+ if (!oldScreen || screen->primaryOrientation() != oldScreen->primaryOrientation())
+ emit primaryOrientationChanged();
+ if (!oldScreen || screen->availableVirtualGeometry() != oldScreen->availableVirtualGeometry())
+ emit desktopGeometryChanged();
+ if (!oldScreen || screen->logicalDotsPerInch() != oldScreen->logicalDotsPerInch())
+ emit logicalPixelDensityChanged();
+ if (!oldScreen || screen->physicalDotsPerInch() != oldScreen->physicalDotsPerInch())
+ emit pixelDensityChanged();
+ if (!oldScreen || screen->devicePixelRatio() != oldScreen->devicePixelRatio())
+ emit devicePixelRatioChanged();
+
+ connect(screen, SIGNAL(geometryChanged(QRect)),
+ this, SIGNAL(widthChanged()));
+ connect(screen, SIGNAL(geometryChanged(QRect)),
+ this, SIGNAL(heightChanged()));
+ connect(screen, SIGNAL(geometryChanged(QRect)),
+ this, SIGNAL(virtualXChanged()));
+ connect(screen, SIGNAL(geometryChanged(QRect)),
+ this, SIGNAL(virtualYChanged()));
+ connect(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)),
+ this, SIGNAL(orientationChanged()));
+ connect(screen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)),
+ this, SIGNAL(primaryOrientationChanged()));
+ connect(screen, SIGNAL(virtualGeometryChanged(QRect)),
+ this, SIGNAL(desktopGeometryChanged()));
+ connect(screen, SIGNAL(logicalDotsPerInchChanged(qreal)),
+ this, SIGNAL(logicalPixelDensityChanged()));
+ connect(screen, SIGNAL(physicalDotsPerInchChanged(qreal)),
+ this, SIGNAL(pixelDensityChanged()));
+}
+
+QScreen *QQuickScreenInfo::wrappedScreen() const
+{
+ return m_screen;
+}
+
+QQuickScreenAttached::QQuickScreenAttached(QObject* attachee)
+ : QQuickScreenInfo(attachee)
+ , m_window(NULL)
+ , m_updateMask(0)
+ , m_updateMaskSet(false)
+{
+ m_attachee = qobject_cast<QQuickItem*>(attachee);
+
+ if (m_attachee) {
+ QQuickItemPrivate::get(m_attachee)->extra.value().screenAttached = this;
+
+ if (m_attachee->window()) //It might not be assigned to a window yet
+ windowChanged(m_attachee->window());
+ } else {
+ QQuickWindow *window = qobject_cast<QQuickWindow*>(attachee);
+ if (window)
+ windowChanged(window);
+ }
+
+ if (!m_screen)
+ screenChanged(QGuiApplication::primaryScreen());
+}
+
Qt::ScreenOrientations QQuickScreenAttached::orientationUpdateMask() const
{
return m_updateMask;
@@ -341,55 +422,15 @@ void QQuickScreenAttached::screenChanged(QScreen *screen)
{
//qDebug() << "QQuickScreenAttached::screenChanged" << (screen ? screen->name() : QString::fromLatin1("null"));
if (screen != m_screen) {
- QScreen* oldScreen = m_screen;
- m_screen = screen;
-
- if (oldScreen)
- oldScreen->disconnect(this);
-
- if (!screen)
- return; //Don't bother emitting signals, because the new values are garbage anyways
-
+ setWrappedScreen(screen);
+ if (!m_screen)
+ return;
if (m_updateMaskSet) {
- screen->setOrientationUpdateMask(m_updateMask);
- } else if (m_updateMask != screen->orientationUpdateMask()) {
- m_updateMask = screen->orientationUpdateMask();
+ m_screen->setOrientationUpdateMask(m_updateMask);
+ } else if (m_updateMask != m_screen->orientationUpdateMask()) {
+ m_updateMask = m_screen->orientationUpdateMask();
emit orientationUpdateMaskChanged();
}
-
- if (!oldScreen || screen->size() != oldScreen->size()) {
- emit widthChanged();
- emit heightChanged();
- }
- if (!oldScreen || screen->name() != oldScreen->name())
- emit nameChanged();
- if (!oldScreen || screen->orientation() != oldScreen->orientation())
- emit orientationChanged();
- if (!oldScreen || screen->primaryOrientation() != oldScreen->primaryOrientation())
- emit primaryOrientationChanged();
- if (!oldScreen || screen->availableVirtualGeometry() != oldScreen->availableVirtualGeometry())
- emit desktopGeometryChanged();
- if (!oldScreen || screen->logicalDotsPerInch() != oldScreen->logicalDotsPerInch())
- emit logicalPixelDensityChanged();
- if (!oldScreen || screen->physicalDotsPerInch() != oldScreen->physicalDotsPerInch())
- emit pixelDensityChanged();
- if (!oldScreen || screen->devicePixelRatio() != oldScreen->devicePixelRatio())
- emit devicePixelRatioChanged();
-
- connect(screen, SIGNAL(geometryChanged(QRect)),
- this, SIGNAL(widthChanged()));
- connect(screen, SIGNAL(geometryChanged(QRect)),
- this, SIGNAL(heightChanged()));
- connect(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)),
- this, SIGNAL(orientationChanged()));
- connect(screen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)),
- this, SIGNAL(primaryOrientationChanged()));
- connect(screen, SIGNAL(virtualGeometryChanged(QRect)),
- this, SIGNAL(desktopGeometryChanged()));
- connect(screen, SIGNAL(logicalDotsPerInchChanged(qreal)),
- this, SIGNAL(logicalPixelDensityChanged()));
- connect(screen, SIGNAL(physicalDotsPerInchChanged(qreal)),
- this, SIGNAL(pixelDensityChanged()));
}
}
diff --git a/src/quick/items/qquickscreen_p.h b/src/quick/items/qquickscreen_p.h
index 06d9a06070..99e1466631 100644
--- a/src/quick/items/qquickscreen_p.h
+++ b/src/quick/items/qquickscreen_p.h
@@ -63,10 +63,10 @@ class QQuickItem;
class QQuickWindow;
class QScreen;
-class Q_AUTOTEST_EXPORT QQuickScreenAttached : public QObject
+
+class Q_AUTOTEST_EXPORT QQuickScreenInfo : public QObject
{
Q_OBJECT
-
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(int width READ width NOTIFY widthChanged)
Q_PROPERTY(int height READ height NOTIFY heightChanged)
@@ -79,11 +79,12 @@ class Q_AUTOTEST_EXPORT QQuickScreenAttached : public QObject
Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ primaryOrientation NOTIFY primaryOrientationChanged)
// TODO Qt 6 Remove this orientation -> incomplete device orientation -> better use OrientationSensor
Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged)
- Q_PROPERTY(Qt::ScreenOrientations orientationUpdateMask READ orientationUpdateMask
- WRITE setOrientationUpdateMask NOTIFY orientationUpdateMaskChanged)
+
+ Q_PROPERTY(int virtualX READ virtualX NOTIFY virtualXChanged REVISION 1)
+ Q_PROPERTY(int virtualY READ virtualY NOTIFY virtualYChanged REVISION 1)
public:
- QQuickScreenAttached(QObject* attachee);
+ QQuickScreenInfo(QObject *parent = nullptr, QScreen *wrappedScreen = nullptr);
QString name() const;
int width() const;
@@ -95,13 +96,11 @@ public:
qreal devicePixelRatio() const;
Qt::ScreenOrientation primaryOrientation() const;
Qt::ScreenOrientation orientation() const;
- Qt::ScreenOrientations orientationUpdateMask() const;
- void setOrientationUpdateMask(Qt::ScreenOrientations mask);
+ int virtualX() const;
+ int virtualY() const;
- //Treats int as Qt::ScreenOrientation, due to QTBUG-20639
- Q_INVOKABLE int angleBetween(int a, int b);
-
- void windowChanged(QQuickWindow*);
+ void setWrappedScreen(QScreen *screen);
+ QScreen *wrappedScreen() const;
Q_SIGNALS:
void nameChanged();
@@ -113,13 +112,37 @@ Q_SIGNALS:
void devicePixelRatioChanged();
void primaryOrientationChanged();
void orientationChanged();
+ Q_REVISION(1) void virtualXChanged();
+ Q_REVISION(1) void virtualYChanged();
+
+protected:
+ QPointer<QScreen> m_screen;
+};
+
+class Q_AUTOTEST_EXPORT QQuickScreenAttached : public QQuickScreenInfo
+{
+ Q_OBJECT
+ Q_PROPERTY(Qt::ScreenOrientations orientationUpdateMask READ orientationUpdateMask
+ WRITE setOrientationUpdateMask NOTIFY orientationUpdateMaskChanged)
+
+public:
+ QQuickScreenAttached(QObject* attachee);
+
+ Qt::ScreenOrientations orientationUpdateMask() const;
+ void setOrientationUpdateMask(Qt::ScreenOrientations mask);
+
+ //Treats int as Qt::ScreenOrientation, due to QTBUG-20639
+ Q_INVOKABLE int angleBetween(int a, int b);
+
+ void windowChanged(QQuickWindow*);
+
+Q_SIGNALS:
void orientationUpdateMaskChanged();
protected Q_SLOTS:
void screenChanged(QScreen*);
private:
- QPointer<QScreen> m_screen;
QQuickWindow* m_window;
QQuickItem* m_attachee;
Qt::ScreenOrientations m_updateMask;
@@ -136,5 +159,6 @@ public:
QT_END_NAMESPACE
QML_DECLARE_TYPEINFO(QQuickScreen, QML_HAS_ATTACHED_PROPERTIES)
+QML_DECLARE_TYPE(QQuickScreenInfo)
#endif
diff --git a/src/quick/items/qquickshadereffectmesh.cpp b/src/quick/items/qquickshadereffectmesh.cpp
index b572feb5ee..d23b576d42 100644
--- a/src/quick/items/qquickshadereffectmesh.cpp
+++ b/src/quick/items/qquickshadereffectmesh.cpp
@@ -95,9 +95,8 @@ bool QQuickGridMesh::validateAttributes(const QVector<QByteArray> &attributes, i
return false;
case 1:
if (positionIndex != 0) {
- m_log = QLatin1String("Error: Missing \'");
- m_log += QLatin1String(qtPositionAttributeName());
- m_log += QLatin1String("\' attribute.\n");
+ m_log = QLatin1String("Error: Missing \'") + QLatin1String(qtPositionAttributeName())
+ + QLatin1String("\' attribute.\n");
return false;
}
break;
@@ -105,14 +104,12 @@ bool QQuickGridMesh::validateAttributes(const QVector<QByteArray> &attributes, i
if (positionIndex == -1 || texCoordIndex == -1) {
m_log.clear();
if (positionIndex == -1) {
- m_log = QLatin1String("Error: Missing \'");
- m_log += QLatin1String(qtPositionAttributeName());
- m_log += QLatin1String("\' attribute.\n");
+ m_log = QLatin1String("Error: Missing \'") + QLatin1String(qtPositionAttributeName())
+ + QLatin1String("\' attribute.\n");
}
if (texCoordIndex == -1) {
- m_log += QLatin1String("Error: Missing \'");
- m_log += QLatin1String(qtTexCoordAttributeName());
- m_log += QLatin1String("\' attribute.\n");
+ m_log += QLatin1String("Error: Missing \'") + QLatin1String(qtTexCoordAttributeName())
+ + QLatin1String("\' attribute.\n");
}
return false;
}
@@ -367,7 +364,7 @@ QSGGeometry *QQuickBorderImageMesh::updateGeometry(QSGGeometry *geometry, int at
}
\endqml
*/
-QQuickScaleGrid *QQuickBorderImageMesh::border()
+QQuickScaleGrid *QQuickBorderImageMesh::border() const
{
return m_border;
}
diff --git a/src/quick/items/qquickshadereffectmesh_p.h b/src/quick/items/qquickshadereffectmesh_p.h
index cbf33b795f..aa3112b5a5 100644
--- a/src/quick/items/qquickshadereffectmesh_p.h
+++ b/src/quick/items/qquickshadereffectmesh_p.h
@@ -127,7 +127,7 @@ public:
QSGGeometry *updateGeometry(QSGGeometry *geometry, int attrCount, int posIndex,
const QRectF &srcRect, const QRectF &rect) override;
- QQuickScaleGrid *border();
+ QQuickScaleGrid *border() const;
enum TileMode { Stretch = Qt::StretchTile, Repeat = Qt::RepeatTile, Round = Qt::RoundTile };
Q_ENUM(TileMode)
diff --git a/src/quick/items/qquickshadereffectsource.cpp b/src/quick/items/qquickshadereffectsource.cpp
index a60a06f59a..1b37a746d3 100644
--- a/src/quick/items/qquickshadereffectsource.cpp
+++ b/src/quick/items/qquickshadereffectsource.cpp
@@ -64,7 +64,7 @@ public:
{
}
- QSGTexture *texture() const {
+ QSGTexture *texture() const override {
sourceTexture->setMipmapFiltering(mipmapFiltering);
sourceTexture->setFiltering(filtering);
sourceTexture->setHorizontalWrapMode(horizontalWrap);
diff --git a/src/quick/items/qquickspriteengine.cpp b/src/quick/items/qquickspriteengine.cpp
index b1905f2cc5..d26a1f8a64 100644
--- a/src/quick/items/qquickspriteengine.cpp
+++ b/src/quick/items/qquickspriteengine.cpp
@@ -323,13 +323,13 @@ void QQuickStochasticEngine::setGoal(int state, int sprite, bool jump)
return;
}
-QQuickPixmap::Status QQuickSpriteEngine::status()//Composed status of all Sprites
+QQuickPixmap::Status QQuickSpriteEngine::status() const //Composed status of all Sprites
{
if (!m_startedImageAssembly)
return QQuickPixmap::Null;
int null, loading, ready;
null = loading = ready = 0;
- for (QQuickSprite* s : qAsConst(m_sprites)) {
+ for (QQuickSprite* s : m_sprites) {
switch (s->m_pix.status()) {
// ### Maybe add an error message here, because this null shouldn't be reached but when it does, the image fails without an error message.
case QQuickPixmap::Null : null++; break;
@@ -378,7 +378,7 @@ QImage QQuickSpriteEngine::assembledImage(int maxSize)
if (!m_errorsPrinted && stat == QQuickPixmap::Error) {
for (QQuickSprite* s : qAsConst(m_sprites))
if (s->m_pix.isError())
- qmlInfo(s) << s->m_pix.error();
+ qmlWarning(s) << s->m_pix.error();
m_errorsPrinted = true;
}
@@ -399,7 +399,7 @@ QImage QQuickSpriteEngine::assembledImage(int maxSize)
{
const QSize frameSize(state->m_frameWidth, state->m_frameHeight);
if (!(img.size() - frameSize).isValid()) {
- qmlInfo(state).nospace() << "SpriteEngine: Invalid frame size " << frameSize << "."
+ qmlWarning(state).nospace() << "SpriteEngine: Invalid frame size " << frameSize << "."
" It's bigger than image size " << img.size() << ".";
return QImage();
}
@@ -419,10 +419,10 @@ QImage QQuickSpriteEngine::assembledImage(int maxSize)
int rowsNeeded = helper::divRoundUp(state->frames(), (maxSize / state->frameWidth()));
if (h + rowsNeeded * state->frameHeight() > maxSize){
if (rowsNeeded * state->frameHeight() > maxSize)
- qmlInfo(state) << "SpriteEngine: Animation too large to fit in one texture:" << state->source().toLocalFile();
+ qmlWarning(state) << "SpriteEngine: Animation too large to fit in one texture:" << state->source().toLocalFile();
else
- qmlInfo(state) << "SpriteEngine: Animations too large to fit in one texture, pushed over the edge by:" << state->source().toLocalFile();
- qmlInfo(state) << "SpriteEngine: Your texture max size today is " << maxSize;
+ qmlWarning(state) << "SpriteEngine: Animations too large to fit in one texture, pushed over the edge by:" << state->source().toLocalFile();
+ qmlWarning(state) << "SpriteEngine: Your texture max size today is " << maxSize;
return QImage();
}
state->m_generatedCount = rowsNeeded;
diff --git a/src/quick/items/qquickspriteengine_p.h b/src/quick/items/qquickspriteengine_p.h
index 3b7fcfb1f1..90ee68b2f6 100644
--- a/src/quick/items/qquickspriteengine_p.h
+++ b/src/quick/items/qquickspriteengine_p.h
@@ -293,11 +293,11 @@ public:
void advance(int index=0) Q_DECL_OVERRIDE;
//Similar API to QQuickPixmap for async loading convenience
- bool isNull() { return status() == QQuickPixmap::Null; }
- bool isReady() { return status() == QQuickPixmap::Ready; }
- bool isLoading() { return status() == QQuickPixmap::Loading; }
- bool isError() { return status() == QQuickPixmap::Error; }
- QQuickPixmap::Status status();//Composed status of all Sprites
+ bool isNull() const { return status() == QQuickPixmap::Null; }
+ bool isReady() const { return status() == QQuickPixmap::Ready; }
+ bool isLoading() const { return status() == QQuickPixmap::Loading; }
+ bool isError() const { return status() == QQuickPixmap::Error; }
+ QQuickPixmap::Status status() const; //Composed status of all Sprites
void startAssemblingImage();
QImage assembledImage(int maxSize = 2048);
diff --git a/src/quick/items/qquickspritesequence.cpp b/src/quick/items/qquickspritesequence.cpp
index 25a39f951a..858a3c0576 100644
--- a/src/quick/items/qquickspritesequence.cpp
+++ b/src/quick/items/qquickspritesequence.cpp
@@ -209,7 +209,7 @@ QSGSpriteNode *QQuickSpriteSequence::initNode()
Q_D(QQuickSpriteSequence);
if (!d->m_spriteEngine) {
- qmlInfo(this) << "No sprite engine...";
+ qmlWarning(this) << "No sprite engine...";
return nullptr;
} else if (d->m_spriteEngine->status() == QQuickPixmap::Null) {
d->m_spriteEngine->startAssemblingImage();
diff --git a/src/quick/items/qquickstateoperations.cpp b/src/quick/items/qquickstateoperations.cpp
index 7e485c675c..b40a9e2843 100644
--- a/src/quick/items/qquickstateoperations.cpp
+++ b/src/quick/items/qquickstateoperations.cpp
@@ -78,7 +78,7 @@ void QQuickParentChangePrivate::doChange(QQuickItem *targetParent, QQuickItem *s
bool ok;
const QTransform &transform = target->parentItem()->itemTransform(targetParent, &ok);
if (transform.type() >= QTransform::TxShear || !ok) {
- qmlInfo(q) << QQuickParentChange::tr("Unable to preserve appearance under complex transform");
+ qmlWarning(q) << QQuickParentChange::tr("Unable to preserve appearance under complex transform");
ok = false;
}
@@ -89,21 +89,21 @@ void QQuickParentChangePrivate::doChange(QQuickItem *targetParent, QQuickItem *s
if (transform.m11() == transform.m22())
scale = transform.m11();
else {
- qmlInfo(q) << QQuickParentChange::tr("Unable to preserve appearance under non-uniform scale");
+ qmlWarning(q) << QQuickParentChange::tr("Unable to preserve appearance under non-uniform scale");
ok = false;
}
} else if (ok && isRotate) {
if (transform.m11() == transform.m22())
scale = qSqrt(transform.m11()*transform.m11() + transform.m12()*transform.m12());
else {
- qmlInfo(q) << QQuickParentChange::tr("Unable to preserve appearance under non-uniform scale");
+ qmlWarning(q) << QQuickParentChange::tr("Unable to preserve appearance under non-uniform scale");
ok = false;
}
if (scale != 0)
rotation = qAtan2(transform.m12()/scale, transform.m11()/scale) * 180/M_PI;
else {
- qmlInfo(q) << QQuickParentChange::tr("Unable to preserve appearance under scale of 0");
+ qmlWarning(q) << QQuickParentChange::tr("Unable to preserve appearance under scale of 0");
ok = false;
}
}
@@ -899,9 +899,9 @@ QQuickAnchorChanges::ActionList QQuickAnchorChanges::actions()
return ActionList() << a;
}
-QQuickAnchorSet *QQuickAnchorChanges::anchors()
+QQuickAnchorSet *QQuickAnchorChanges::anchors() const
{
- Q_D(QQuickAnchorChanges);
+ Q_D(const QQuickAnchorChanges);
return d->anchorSet;
}
@@ -1134,9 +1134,9 @@ QQuickStateActionEvent::EventType QQuickAnchorChanges::type() const
return AnchorChanges;
}
-QList<QQuickStateAction> QQuickAnchorChanges::additionalActions()
+QList<QQuickStateAction> QQuickAnchorChanges::additionalActions() const
{
- Q_D(QQuickAnchorChanges);
+ Q_D(const QQuickAnchorChanges);
QList<QQuickStateAction> extra;
QQuickAnchors::Anchors combined = d->anchorSet->d_func()->usedAnchors | d->anchorSet->d_func()->resetAnchors;
diff --git a/src/quick/items/qquickstateoperations_p.h b/src/quick/items/qquickstateoperations_p.h
index 29dec218fa..48b4b23a76 100644
--- a/src/quick/items/qquickstateoperations_p.h
+++ b/src/quick/items/qquickstateoperations_p.h
@@ -192,7 +192,7 @@ public:
ActionList actions() Q_DECL_OVERRIDE;
- QQuickAnchorSet *anchors();
+ QQuickAnchorSet *anchors() const;
QQuickItem *object() const;
void setObject(QQuickItem *);
@@ -210,7 +210,7 @@ public:
void rewind() Q_DECL_OVERRIDE;
void saveCurrentValues() Q_DECL_OVERRIDE;
- QList<QQuickStateAction> additionalActions();
+ QList<QQuickStateAction> additionalActions() const;
void saveTargetValues() Q_DECL_OVERRIDE;
};
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp
index e37a7e6d5e..1720377046 100644
--- a/src/quick/items/qquicktext.cpp
+++ b/src/quick/items/qquicktext.cpp
@@ -74,7 +74,7 @@ Q_DECLARE_LOGGING_CATEGORY(DBG_HOVER_TRACE)
const QChar QQuickTextPrivate::elideChar = QChar(0x2026);
QQuickTextPrivate::QQuickTextPrivate()
- : elideLayout(0), textLine(0), lineWidth(0)
+ : fontInfo(font), elideLayout(0), textLine(0), lineWidth(0)
, color(0xFF000000), linkColor(0xFF0000FF), styleColor(0xFF000000)
, lineCount(1), multilengthEos(-1)
, elideMode(QQuickText::ElideNone), hAlign(QQuickText::AlignLeft), vAlign(QQuickText::AlignTop)
@@ -1018,6 +1018,17 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline)
implicitWidthValid = true;
implicitHeightValid = true;
+ QFontInfo scaledFontInfo(scaledFont);
+ if (fontInfo.weight() != scaledFontInfo.weight()
+ || fontInfo.pixelSize() != scaledFontInfo.pixelSize()
+ || fontInfo.italic() != scaledFontInfo.italic()
+ || !qFuzzyCompare(fontInfo.pointSizeF(), scaledFontInfo.pointSizeF())
+ || fontInfo.family() != scaledFontInfo.family()
+ || fontInfo.styleName() != scaledFontInfo.styleName()) {
+ fontInfo = scaledFontInfo;
+ emit q->fontInfoChanged();
+ }
+
if (eos != multilengthEos)
truncated = true;
@@ -1135,7 +1146,7 @@ void QQuickTextPrivate::setLineGeometry(QTextLine &line, qreal lineWidth, qreal
needToUpdateLayout = true;
}
} else if (image->pix->isError()) {
- qmlInfo(q) << image->pix->error();
+ qmlWarning(q) << image->pix->error();
}
}
@@ -2795,11 +2806,23 @@ void QQuickText::setRenderType(QQuickText::RenderType renderType)
/*!
\qmlmethod QtQuick::Text::doLayout()
+ \deprecated
- Triggers a re-layout of the displayed text.
+ Use \l forceLayout() instead.
*/
void QQuickText::doLayout()
{
+ forceLayout();
+}
+
+/*!
+ \qmlmethod QtQuick::Text::forceLayout()
+ \since 5.9
+
+ Triggers a re-layout of the displayed text.
+*/
+void QQuickText::forceLayout()
+{
Q_D(QQuickText);
d->updateSize();
}
@@ -2962,4 +2985,80 @@ void QQuickText::resetBottomPadding()
d->setBottomPadding(0, true);
}
+/*!
+ \qmlproperty string QtQuick::Text::fontInfo.family
+ \since 5.9
+
+ The family name of the font that has been resolved for the current font
+ and fontSizeMode.
+*/
+
+/*!
+ \qmlproperty string QtQuick::Text::fontInfo.styleName
+ \since 5.9
+
+ The style name of the font info that has been resolved for the current font
+ and fontSizeMode.
+*/
+
+/*!
+ \qmlproperty bool QtQuick::Text::fontInfo.bold
+ \since 5.9
+
+ The bold state of the font info that has been resolved for the current font
+ and fontSizeMode. This is true if the weight of the resolved font is bold or higher.
+*/
+
+/*!
+ \qmlproperty int QtQuick::Text::fontInfo.weight
+ \since 5.9
+
+ The weight of the font info that has been resolved for the current font
+ and fontSizeMode.
+*/
+
+/*!
+ \qmlproperty bool QtQuick::Text::fontInfo.italic
+ \since 5.9
+
+ The italic state of the font info that has been resolved for the current font
+ and fontSizeMode.
+*/
+
+/*!
+ \qmlproperty real QtQuick::Text::fontInfo.pointSize
+ \since 5.9
+
+ The pointSize of the font info that has been resolved for the current font
+ and fontSizeMode.
+*/
+
+/*!
+ \qmlproperty string QtQuick::Text::fontInfo.pixelSize
+ \since 5.9
+
+ The pixel size of the font info that has been resolved for the current font
+ and fontSizeMode.
+*/
+QJSValue QQuickText::fontInfo() const
+{
+ Q_D(const QQuickText);
+
+ QJSEngine *engine = qjsEngine(this);
+ if (!engine) {
+ qmlWarning(this) << "fontInfo: item has no JS engine";
+ return QJSValue();
+ }
+
+ QJSValue value = engine->newObject();
+ value.setProperty(QStringLiteral("family"), d->fontInfo.family());
+ value.setProperty(QStringLiteral("styleName"), d->fontInfo.styleName());
+ value.setProperty(QStringLiteral("bold"), d->fontInfo.bold());
+ value.setProperty(QStringLiteral("weight"), d->fontInfo.weight());
+ value.setProperty(QStringLiteral("italic"), d->fontInfo.italic());
+ value.setProperty(QStringLiteral("pointSize"), d->fontInfo.pointSizeF());
+ value.setProperty(QStringLiteral("pixelSize"), d->fontInfo.pixelSize());
+ return value;
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/items/qquicktext_p.h b/src/quick/items/qquicktext_p.h
index 40dbd51f39..b190738cfb 100644
--- a/src/quick/items/qquicktext_p.h
+++ b/src/quick/items/qquicktext_p.h
@@ -98,6 +98,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickText : public QQuickImplicitSizeItem
Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged REVISION 6)
Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION 6)
+ Q_PROPERTY(QJSValue fontInfo READ fontInfo NOTIFY fontInfoChanged REVISION 9)
+
public:
QQuickText(QQuickItem *parent=0);
~QQuickText();
@@ -218,7 +220,8 @@ public:
QRectF boundingRect() const Q_DECL_OVERRIDE;
QRectF clipRect() const Q_DECL_OVERRIDE;
- Q_INVOKABLE void doLayout();
+ Q_INVOKABLE void doLayout(); // ### Qt 6: remove
+ Q_REVISION(9) Q_INVOKABLE void forceLayout();
RenderType renderType() const;
void setRenderType(RenderType renderType);
@@ -247,6 +250,8 @@ public:
void setBottomPadding(qreal padding);
void resetBottomPadding();
+ QJSValue fontInfo() const;
+
Q_SIGNALS:
void textChanged(const QString &text);
void linkActivated(const QString &link);
@@ -279,6 +284,7 @@ Q_SIGNALS:
Q_REVISION(6) void leftPaddingChanged();
Q_REVISION(6) void rightPaddingChanged();
Q_REVISION(6) void bottomPaddingChanged();
+ Q_REVISION(9) void fontInfoChanged();
protected:
QQuickText(QQuickTextPrivate &dd, QQuickItem *parent = 0);
diff --git a/src/quick/items/qquicktext_p_p.h b/src/quick/items/qquicktext_p_p.h
index 0669bcf115..6456750359 100644
--- a/src/quick/items/qquicktext_p_p.h
+++ b/src/quick/items/qquicktext_p_p.h
@@ -122,6 +122,7 @@ public:
QString text;
QFont font;
QFont sourceFont;
+ QFontInfo fontInfo;
QTextLayout layout;
QTextLayout *elideLayout;
diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp
index 66936b0943..555fd233b3 100644
--- a/src/quick/items/qquicktextcontrol.cpp
+++ b/src/quick/items/qquicktextcontrol.cpp
@@ -1660,8 +1660,8 @@ void QQuickTextControl::insertFromMimeData(const QMimeData *source)
#if QT_CONFIG(texthtmlparser)
if (source->hasFormat(QLatin1String("application/x-qrichtext")) && d->acceptRichText) {
// x-qrichtext is always UTF-8 (taken from Qt3 since we don't use it anymore).
- QString richtext = QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext")));
- richtext.prepend(QLatin1String("<meta name=\"qrichtext\" content=\"1\" />"));
+ const QString richtext = QLatin1String("<meta name=\"qrichtext\" content=\"1\" />")
+ + QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext")));
fragment = QTextDocumentFragment::fromHtml(richtext, d->doc);
hasData = true;
} else if (source->hasHtml() && d->acceptRichText) {
diff --git a/src/quick/items/qquicktextcontrol_p.h b/src/quick/items/qquicktextcontrol_p.h
index 9bc5d057c7..70104a97e0 100644
--- a/src/quick/items/qquicktextcontrol_p.h
+++ b/src/quick/items/qquicktextcontrol_p.h
@@ -194,9 +194,11 @@ class QQuickTextEditMimeData : public QMimeData
public:
inline QQuickTextEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {}
- virtual QStringList formats() const;
+ QStringList formats() const override;
+
protected:
- virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const;
+ QVariant retrieveData(const QString &mimeType, QVariant::Type type) const override;
+
private:
void setup() const;
diff --git a/src/quick/items/qquicktextdocument.cpp b/src/quick/items/qquicktextdocument.cpp
index e7492b97ae..c272503480 100644
--- a/src/quick/items/qquicktextdocument.cpp
+++ b/src/quick/items/qquicktextdocument.cpp
@@ -179,7 +179,7 @@ void QQuickTextDocumentWithImageResources::drawObject(
{
}
-QImage QQuickTextDocumentWithImageResources::image(const QTextImageFormat &format)
+QImage QQuickTextDocumentWithImageResources::image(const QTextImageFormat &format) const
{
QVariant res = resource(QTextDocument::ImageResource, QUrl(format.name()));
return res.value<QImage>();
@@ -211,7 +211,7 @@ QQuickPixmap *QQuickTextDocumentWithImageResources::loadPixmap(
if (p->isError()) {
if (!errors.contains(url)) {
errors.insert(url);
- qmlInfo(parent()) << p->error();
+ qmlWarning(parent()) << p->error();
}
}
return p;
diff --git a/src/quick/items/qquicktextdocument_p.h b/src/quick/items/qquicktextdocument_p.h
index 3ffedb5b96..1218b12b89 100644
--- a/src/quick/items/qquicktextdocument_p.h
+++ b/src/quick/items/qquicktextdocument_p.h
@@ -75,10 +75,10 @@ public:
void setText(const QString &);
int resourcesLoading() const { return outstanding; }
- QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format);
- void drawObject(QPainter *p, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format);
+ QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) override;
+ void drawObject(QPainter *p, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) override;
- QImage image(const QTextImageFormat &format);
+ QImage image(const QTextImageFormat &format) const;
public Q_SLOTS:
void clearResources();
@@ -87,7 +87,7 @@ Q_SIGNALS:
void imagesLoaded();
protected:
- QVariant loadResource(int type, const QUrl &name);
+ QVariant loadResource(int type, const QUrl &name) override;
QQuickPixmap *loadPixmap(QQmlContext *context, const QUrl &name);
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp
index 94da44c00d..075fd48a46 100644
--- a/src/quick/items/qquicktextedit.cpp
+++ b/src/quick/items/qquicktextedit.cpp
@@ -1743,7 +1743,7 @@ void QQuickTextEdit::select(int start, int end)
bool QQuickTextEdit::isRightToLeft(int start, int end)
{
if (start > end) {
- qmlInfo(this) << "isRightToLeft(start, end) called with the end property being smaller than the start.";
+ qmlWarning(this) << "isRightToLeft(start, end) called with the end property being smaller than the start.";
return false;
} else {
return getText(start, end).isRightToLeft();
@@ -2569,7 +2569,7 @@ void QQuickTextEditPrivate::updateDefaultTextOption()
{
Q_Q(QQuickTextEdit);
QTextOption opt = document->defaultTextOption();
- int oldAlignment = opt.alignment();
+ const Qt::Alignment oldAlignment = opt.alignment();
Qt::LayoutDirection oldTextDirection = opt.textDirection();
QQuickTextEdit::HAlignment horizontalAlignment = q->effectiveHAlign();
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
index b3c7da1e3e..a023ad8a8c 100644
--- a/src/quick/items/qquicktextinput.cpp
+++ b/src/quick/items/qquicktextinput.cpp
@@ -1152,6 +1152,17 @@ bool QQuickTextInput::hasAcceptableInput() const
The corresponding handler is \c onEditingFinished.
*/
+/*!
+ \qmlsignal QtQuick::TextInput::textEdited()
+ \since 5.9
+
+ This signal is emitted whenever the text is edited. Unlike \c textChanged(),
+ this signal is not emitted when the text is changed programmatically, for example,
+ by changing the value of the \c text property or by calling \c clear().
+
+ The corresponding handler is \c onTextEdited.
+*/
+
#if QT_CONFIG(im)
Qt::InputMethodHints QQuickTextInputPrivate::effectiveInputMethodHints() const
{
@@ -1991,10 +2002,10 @@ void QQuickTextInput::selectAll()
bool QQuickTextInput::isRightToLeft(int start, int end)
{
if (start > end) {
- qmlInfo(this) << "isRightToLeft(start, end) called with the end property being smaller than the start.";
+ qmlWarning(this) << "isRightToLeft(start, end) called with the end property being smaller than the start.";
return false;
} else {
- return text().mid(start, end - start).isRightToLeft();
+ return text().midRef(start, end - start).isRightToLeft();
}
}
@@ -2846,7 +2857,7 @@ void QQuickTextInputPrivate::updateDisplayText(bool forceUpdate)
// drawing boxes when using fonts that don't have glyphs for such
// characters)
QChar* uc = str.data();
- for (int i = 0; i < (int)str.length(); ++i) {
+ for (int i = 0; i < str.length(); ++i) {
if ((uc[i].unicode() < 0x20 && uc[i] != QChar::Tabulation)
|| uc[i] == QChar::LineSeparator
|| uc[i] == QChar::ParagraphSeparator
@@ -3232,7 +3243,7 @@ void QQuickTextInputPrivate::setSelection(int start, int length)
commitPreedit();
#endif
- if (start < 0 || start > (int)m_text.length()){
+ if (start < 0 || start > m_text.length()) {
qWarning("QQuickTextInputPrivate::setSelection: Invalid start position");
return;
}
@@ -3241,7 +3252,7 @@ void QQuickTextInputPrivate::setSelection(int start, int length)
if (start == m_selstart && start + length == m_selend && m_cursor == m_selend)
return;
m_selstart = start;
- m_selend = qMin(start + length, (int)m_text.length());
+ m_selend = qMin(start + length, m_text.length());
m_cursor = m_selend;
} else if (length < 0){
if (start == m_selend && start + length == m_selstart && m_cursor == m_selstart)
@@ -3499,7 +3510,7 @@ void QQuickTextInputPrivate::selectWordAtPos(int cursor)
The \a update value is currently unused.
*/
-bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bool /*edited*/)
+bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bool edited)
{
Q_Q(QQuickTextInput);
@@ -3570,6 +3581,8 @@ bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bo
m_preeditDirty = false;
#endif
alignmentChanged = determineHorizontalAlignment();
+ if (edited)
+ emit q->textEdited();
emit q->textChanged();
}
@@ -3679,7 +3692,7 @@ void QQuickTextInputPrivate::internalInsert(const QString &s)
Q_ASSERT(!hasSelectedText()); // insert(), processInputMethodEvent() call removeSelectedText() first.
if (m_maskData) {
QString ms = maskString(m_cursor, s);
- for (int i = 0; i < (int) ms.length(); ++i) {
+ for (int i = 0; i < ms.length(); ++i) {
addCommand (Command(DeleteSelection, m_cursor + i, m_text.at(m_cursor + i), -1, -1));
addCommand(Command(Insert, m_cursor + i, ms.at(i), -1, -1));
}
@@ -3690,9 +3703,10 @@ void QQuickTextInputPrivate::internalInsert(const QString &s)
} else {
int remaining = m_maxLength - m_text.length();
if (remaining != 0) {
- m_text.insert(m_cursor, s.left(remaining));
- for (int i = 0; i < (int) s.leftRef(remaining).length(); ++i)
- addCommand(Command(Insert, m_cursor++, s.at(i), -1, -1));
+ const QStringRef remainingStr = s.leftRef(remaining);
+ m_text.insert(m_cursor, remainingStr);
+ for (auto e : remainingStr)
+ addCommand(Command(Insert, m_cursor++, e, -1, -1));
m_textDirty = true;
}
}
@@ -3711,7 +3725,7 @@ void QQuickTextInputPrivate::internalInsert(const QString &s)
*/
void QQuickTextInputPrivate::internalDelete(bool wasBackspace)
{
- if (m_cursor < (int) m_text.length()) {
+ if (m_cursor < m_text.length()) {
cancelPasswordEchoTimer();
Q_ASSERT(!hasSelectedText()); // del(), backspace() call removeSelectedText() first.
addCommand(Command((CommandType)((m_maskData ? 2 : 0) + (wasBackspace ? Remove : Delete)),
@@ -3737,7 +3751,7 @@ void QQuickTextInputPrivate::internalDelete(bool wasBackspace)
*/
void QQuickTextInputPrivate::removeSelectedText()
{
- if (m_selstart < m_selend && m_selend <= (int) m_text.length()) {
+ if (m_selstart < m_selend && m_selend <= m_text.length()) {
cancelPasswordEchoTimer();
int i ;
if (m_selstart <= m_cursor && m_cursor < m_selend) {
@@ -4023,44 +4037,44 @@ QString QQuickTextInputPrivate::maskString(uint pos, const QString &str, bool cl
if (strIndex < str.length()) {
if (m_maskData[i].separator) {
s += m_maskData[i].maskChar;
- if (str[(int)strIndex] == m_maskData[i].maskChar)
+ if (str[strIndex] == m_maskData[i].maskChar)
strIndex++;
++i;
} else {
- if (isValidInput(str[(int)strIndex], m_maskData[i].maskChar)) {
+ if (isValidInput(str[strIndex], m_maskData[i].maskChar)) {
switch (m_maskData[i].caseMode) {
case MaskInputData::Upper:
- s += str[(int)strIndex].toUpper();
+ s += str[strIndex].toUpper();
break;
case MaskInputData::Lower:
- s += str[(int)strIndex].toLower();
+ s += str[strIndex].toLower();
break;
default:
- s += str[(int)strIndex];
+ s += str[strIndex];
}
++i;
} else {
// search for separator first
- int n = findInMask(i, true, true, str[(int)strIndex]);
+ int n = findInMask(i, true, true, str[strIndex]);
if (n != -1) {
- if (str.length() != 1 || i == 0 || (i > 0 && (!m_maskData[i-1].separator || m_maskData[i-1].maskChar != str[(int)strIndex]))) {
+ if (str.length() != 1 || i == 0 || (i > 0 && (!m_maskData[i-1].separator || m_maskData[i-1].maskChar != str[strIndex]))) {
s += fill.midRef(i, n-i+1);
i = n + 1; // update i to find + 1
}
} else {
// search for valid m_blank if not
- n = findInMask(i, true, false, str[(int)strIndex]);
+ n = findInMask(i, true, false, str[strIndex]);
if (n != -1) {
s += fill.midRef(i, n-i);
switch (m_maskData[n].caseMode) {
case MaskInputData::Upper:
- s += str[(int)strIndex].toUpper();
+ s += str[strIndex].toUpper();
break;
case MaskInputData::Lower:
- s += str[(int)strIndex].toLower();
+ s += str[strIndex].toLower();
break;
default:
- s += str[(int)strIndex];
+ s += str[strIndex];
}
i = n + 1; // updates i to find + 1
}
@@ -4111,7 +4125,7 @@ QString QQuickTextInputPrivate::stripString(const QString &str) const
return str;
QString s;
- int end = qMin(m_maxLength, (int)str.length());
+ int end = qMin(m_maxLength, str.length());
for (int i = 0; i < end; ++i) {
if (m_maskData[i].separator)
s += m_maskData[i].maskChar;
@@ -4201,7 +4215,7 @@ void QQuickTextInputPrivate::internalRedo()
if (!isRedoAvailable())
return;
internalDeselect();
- while (m_undoState < (int)m_history.size()) {
+ while (m_undoState < m_history.size()) {
Command& cmd = m_history[m_undoState++];
switch (cmd.type) {
case Insert:
@@ -4228,7 +4242,7 @@ void QQuickTextInputPrivate::internalRedo()
m_cursor = cmd.pos;
break;
}
- if (m_undoState < (int)m_history.size()) {
+ if (m_undoState < m_history.size()) {
Command& next = m_history[m_undoState];
if (next.type != cmd.type
&& cmd.type < RemoveSelection
diff --git a/src/quick/items/qquicktextinput_p.h b/src/quick/items/qquicktextinput_p.h
index f4545e1574..c4da807471 100644
--- a/src/quick/items/qquicktextinput_p.h
+++ b/src/quick/items/qquicktextinput_p.h
@@ -319,6 +319,7 @@ Q_SIGNALS:
void accepted();
void acceptableInputChanged();
Q_REVISION(2) void editingFinished();
+ Q_REVISION(9) void textEdited();
void colorChanged();
void selectionColorChanged();
void selectedTextColorChanged();
diff --git a/src/quick/items/qquicktextutil.cpp b/src/quick/items/qquicktextutil.cpp
index 8bcdb0b5f6..b07289f4a3 100644
--- a/src/quick/items/qquicktextutil.cpp
+++ b/src/quick/items/qquicktextutil.cpp
@@ -61,7 +61,7 @@ QQuickItem *QQuickTextUtil::createCursor(
item->setPosition(rectangle.topLeft());
item->setHeight(rectangle.height());
} else {
- qmlInfo(parent) << tr("%1 does not support loading non-visual cursor delegates.")
+ qmlWarning(parent) << tr("%1 does not support loading non-visual cursor delegates.")
.arg(QString::fromUtf8(className));
}
component->completeCreate();
@@ -72,7 +72,7 @@ QQuickItem *QQuickTextUtil::createCursor(
parent, SLOT(createCursor()), Qt::UniqueConnection);
return item;
}
- qmlInfo(parent, component->errors()) << tr("Could not load cursor delegate");
+ qmlWarning(parent, component->errors()) << tr("Could not load cursor delegate");
return item;
}
diff --git a/src/quick/items/qquickview.cpp b/src/quick/items/qquickview.cpp
index 573440ff7f..d7171bf910 100644
--- a/src/quick/items/qquickview.cpp
+++ b/src/quick/items/qquickview.cpp
@@ -62,6 +62,8 @@ void QQuickViewPrivate::init(QQmlEngine* e)
if (engine.isNull())
engine = new QQmlEngine(q);
+ QQmlEngine::setContextForObject(contentItem, engine.data()->rootContext());
+
if (!engine.data()->incubationController())
engine.data()->setIncubationController(q->incubationController());
diff --git a/src/quick/items/qquickview.h b/src/quick/items/qquickview.h
index 1fcc34e3a1..6d3b30e4c4 100644
--- a/src/quick/items/qquickview.h
+++ b/src/quick/items/qquickview.h
@@ -97,14 +97,14 @@ private Q_SLOTS:
void continueExecute();
protected:
- void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
- void timerEvent(QTimerEvent*) Q_DECL_OVERRIDE;
-
- void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
- void keyReleaseEvent(QKeyEvent *) Q_DECL_OVERRIDE;
- void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
- void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
- void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *) override;
+ void timerEvent(QTimerEvent*) override;
+
+ void keyPressEvent(QKeyEvent *) override;
+ void keyReleaseEvent(QKeyEvent *) override;
+ void mousePressEvent(QMouseEvent *) override;
+ void mouseReleaseEvent(QMouseEvent *) override;
+ void mouseMoveEvent(QMouseEvent *) override;
private:
Q_DISABLE_COPY(QQuickView)
Q_DECLARE_PRIVATE(QQuickView)
diff --git a/src/quick/items/qquickview_p.h b/src/quick/items/qquickview_p.h
index a090bdc9f7..f92d4b95d6 100644
--- a/src/quick/items/qquickview_p.h
+++ b/src/quick/items/qquickview_p.h
@@ -88,7 +88,7 @@ public:
~QQuickViewPrivate();
void execute();
- void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) Q_DECL_OVERRIDE;
+ void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) override;
void initResize();
void updateSize();
void setRootObject(QObject *);
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index e9108b7bda..f90384b3b6 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -453,13 +453,20 @@ void QQuickWindowPrivate::renderSceneGraph(const QSize &size)
fboId = renderTargetId;
renderer->setDeviceRect(rect);
renderer->setViewportRect(rect);
+ if (QQuickRenderControl::renderWindowFor(q)) {
+ renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), size));
+ renderer->setDevicePixelRatio(devicePixelRatio);
+ } else {
+ renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), rect.size()));
+ renderer->setDevicePixelRatio(1);
+ }
} else {
QRect rect(QPoint(0, 0), devicePixelRatio * size);
renderer->setDeviceRect(rect);
renderer->setViewportRect(rect);
+ renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), size));
+ renderer->setDevicePixelRatio(devicePixelRatio);
}
- renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), size));
- renderer->setDevicePixelRatio(devicePixelRatio);
context->renderNextFrame(renderer, fboId);
}
@@ -1796,7 +1803,7 @@ bool QQuickWindowPrivate::deliverWheelEvent(QQuickItem *item, QWheelEvent *event
QPointF p = item->mapFromScene(event->posF());
if (item->contains(p)) {
- QWheelEvent wheel(p, p, event->pixelDelta(), event->angleDelta(), event->delta(),
+ QWheelEvent wheel(p, event->globalPosF(), event->pixelDelta(), event->angleDelta(), event->delta(),
event->orientation(), event->buttons(), event->modifiers(), event->phase(), event->source(), event->inverted());
wheel.setTimestamp(event->timestamp());
wheel.accept();
@@ -1895,8 +1902,6 @@ void QQuickWindowPrivate::deliverDelayedTouchEvent()
deliverPointerEvent(pointerEventInstance(e.data()));
}
-static bool qquickwindow_no_touch_compression = qEnvironmentVariableIsSet("QML_NO_TOUCH_COMPRESSION");
-
bool QQuickWindowPrivate::compressTouchEvent(QTouchEvent *event)
{
Q_Q(QQuickWindow);
@@ -1973,6 +1978,8 @@ void QQuickWindowPrivate::handleTouchEvent(QTouchEvent *event)
qCDebug(DBG_TOUCH) << event;
+ static bool qquickwindow_no_touch_compression = qEnvironmentVariableIsSet("QML_NO_TOUCH_COMPRESSION");
+
if (qquickwindow_no_touch_compression || pointerEventRecursionGuard) {
deliverPointerEvent(pointerEventInstance(event));
return;
@@ -2101,7 +2108,7 @@ void QQuickWindowPrivate::flushFrameSynchronousEvents()
There is a unique instance per QQuickPointerDevice, which is determined
from \a event's device.
*/
-QQuickPointerEvent *QQuickWindowPrivate::pointerEventInstance(QEvent *event)
+QQuickPointerEvent *QQuickWindowPrivate::pointerEventInstance(QEvent *event) const
{
QQuickPointerDevice *dev = nullptr;
switch (event->type()) {
@@ -4165,6 +4172,28 @@ void QQuickWindow::resetOpenGLState()
*/
/*!
+ \qmlproperty variant Window::screen
+
+ The screen with which the window is associated.
+
+ If specified before showing a window, will result in the window being shown
+ on that screen, unless an explicit window position has been set. The value
+ must be an element from the Qt.application.screens array.
+
+ \note To ensure that the window is associated with the desired screen when
+ the underlying native window is created, make sure this property is set as
+ early as possible and that the setting of its value is not deferred. This
+ can be particularly important on embedded platforms without a windowing system,
+ where only one window per screen is allowed at a time. Setting the screen after
+ a window has been created does not move the window if the new screen is part of
+ the same virtual desktop as the old screen.
+
+ \since 5.9
+
+ \sa QWindow::setScreen(), QWindow::screen(), QScreen, Qt.application
+ */
+
+/*!
\qmlproperty Item Window::activeFocusItem
\since 5.1
diff --git a/src/quick/items/qquickwindow.h b/src/quick/items/qquickwindow.h
index c1f690f325..27a73988ae 100644
--- a/src/quick/items/qquickwindow.h
+++ b/src/quick/items/qquickwindow.h
@@ -56,6 +56,7 @@ class QSGTexture;
class QInputMethodEvent;
class QQuickWindowPrivate;
class QQuickWindowAttached;
+class QOpenGLContext;
class QOpenGLFramebufferObject;
class QQmlIncubationController;
class QInputMethodEvent;
diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h
index 829fe53458..be915903c6 100644
--- a/src/quick/items/qquickwindow_p.h
+++ b/src/quick/items/qquickwindow_p.h
@@ -163,7 +163,7 @@ public:
void deliverDelayedTouchEvent();
// delivery of pointer events:
- QQuickPointerEvent *pointerEventInstance(QEvent *ev);
+ QQuickPointerEvent *pointerEventInstance(QEvent *ev) const;
void deliverPointerEvent(QQuickPointerEvent *);
void deliverTouchEvent(QQuickPointerTouchEvent *);
bool deliverTouchCancelEvent(QTouchEvent *);
@@ -200,7 +200,7 @@ public:
void setFocusInScope(QQuickItem *scope, QQuickItem *item, Qt::FocusReason reason, FocusOptions = 0);
void clearFocusInScope(QQuickItem *scope, QQuickItem *item, Qt::FocusReason reason, FocusOptions = 0);
static void notifyFocusChangesRecur(QQuickItem **item, int remaining);
- void clearFocusObject();
+ void clearFocusObject() override;
void updateFocusItemTransform();
diff --git a/src/quick/items/qquickwindowmodule.cpp b/src/quick/items/qquickwindowmodule.cpp
index deb44ce34d..6211b7802f 100644
--- a/src/quick/items/qquickwindowmodule.cpp
+++ b/src/quick/items/qquickwindowmodule.cpp
@@ -73,6 +73,7 @@ QQuickWindowQmlImpl::QQuickWindowQmlImpl(QWindow *parent)
{
connect(this, &QWindow::visibleChanged, this, &QQuickWindowQmlImpl::visibleChanged);
connect(this, &QWindow::visibilityChanged, this, &QQuickWindowQmlImpl::visibilityChanged);
+ connect(this, &QWindow::screenChanged, this, &QQuickWindowQmlImpl::screenChanged);
}
void QQuickWindowQmlImpl::setVisible(bool visible)
@@ -100,6 +101,9 @@ void QQuickWindowQmlImpl::classBegin()
{
Q_D(QQuickWindowQmlImpl);
QQmlEngine* e = qmlEngine(this);
+
+ QQmlEngine::setContextForObject(contentItem(), e->rootContext());
+
//Give QQuickView behavior when created from QML with QQmlApplicationEngine
if (QCoreApplication::instance()->property("__qml_using_qqmlapplicationengine") == QVariant(true)) {
if (e && !e->incubationController())
@@ -170,6 +174,17 @@ void QQuickWindowQmlImpl::setWindowVisibility()
}
}
+QObject *QQuickWindowQmlImpl::screen() const
+{
+ return new QQuickScreenInfo(const_cast<QQuickWindowQmlImpl *>(this), QWindow::screen());
+}
+
+void QQuickWindowQmlImpl::setScreen(QObject *screen)
+{
+ QQuickScreenInfo *screenWrapper = qobject_cast<QQuickScreenInfo *>(screen);
+ QWindow::setScreen(screenWrapper ? screenWrapper->wrappedScreen() : nullptr);
+}
+
void QQuickWindowModule::defineModule()
{
const char uri[] = "QtQuick.Window";
@@ -181,7 +196,10 @@ void QQuickWindowModule::defineModule()
qmlRegisterRevision<QQuickWindow,2>(uri, 2, 2);
qmlRegisterType<QQuickWindowQmlImpl>(uri, 2, 1, "Window");
qmlRegisterType<QQuickWindowQmlImpl,1>(uri, 2, 2, "Window");
+ qmlRegisterType<QQuickWindowQmlImpl,2>(uri, 2, 3, "Window");
qmlRegisterUncreatableType<QQuickScreen>(uri, 2, 0, "Screen", QStringLiteral("Screen can only be used via the attached property."));
+ qmlRegisterUncreatableType<QQuickScreen,1>(uri, 2, 3, "Screen", QStringLiteral("Screen can only be used via the attached property."));
+ qmlRegisterUncreatableType<QQuickScreenInfo,2>(uri, 2, 3, "ScreenInfo", QStringLiteral("ScreenInfo can only be used via the attached property."));
}
QT_END_NAMESPACE
diff --git a/src/quick/items/qquickwindowmodule_p.h b/src/quick/items/qquickwindowmodule_p.h
index 8a6bbac412..16130bc8a0 100644
--- a/src/quick/items/qquickwindowmodule_p.h
+++ b/src/quick/items/qquickwindowmodule_p.h
@@ -67,6 +67,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickWindowQmlImpl : public QQuickWindow, public Q
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged)
+ Q_PROPERTY(QObject *screen READ screen WRITE setScreen NOTIFY screenChanged REVISION 2)
public:
QQuickWindowQmlImpl(QWindow *parent = Q_NULLPTR);
@@ -74,11 +75,15 @@ public:
void setVisible(bool visible);
void setVisibility(Visibility visibility);
+ QObject *screen() const;
+ void setScreen(QObject *screen);
+
static QQuickWindowAttached *qmlAttachedProperties(QObject *object);
Q_SIGNALS:
void visibleChanged(bool arg);
void visibilityChanged(QWindow::Visibility visibility);
+ Q_REVISION(2) void screenChanged();
protected:
void classBegin() Q_DECL_OVERRIDE;
diff --git a/src/quick/qtquick2.cpp b/src/quick/qtquick2.cpp
index 226e7bf219..c6b89fabd3 100644
--- a/src/quick/qtquick2.cpp
+++ b/src/quick/qtquick2.cpp
@@ -72,19 +72,19 @@ class QQmlQtQuick2DebugStatesDelegate : public QQmlDebugStatesDelegate
{
public:
QQmlQtQuick2DebugStatesDelegate();
- virtual ~QQmlQtQuick2DebugStatesDelegate();
- virtual void buildStatesList(bool cleanList, const QList<QPointer<QObject> > &instances);
- virtual void updateBinding(QQmlContext *context,
- const QQmlProperty &property,
- const QVariant &expression, bool isLiteralValue,
- const QString &fileName, int line, int column,
- bool *isBaseState);
- virtual bool setBindingForInvalidProperty(QObject *object,
- const QString &propertyName,
- const QVariant &expression,
- bool isLiteralValue);
- virtual void resetBindingForInvalidProperty(QObject *object,
- const QString &propertyName);
+ ~QQmlQtQuick2DebugStatesDelegate();
+ void buildStatesList(bool cleanList, const QList<QPointer<QObject> > &instances) override;
+ void updateBinding(QQmlContext *context,
+ const QQmlProperty &property,
+ const QVariant &expression, bool isLiteralValue,
+ const QString &fileName, int line, int column,
+ bool *isBaseState) override;
+ bool setBindingForInvalidProperty(QObject *object,
+ const QString &propertyName,
+ const QVariant &expression,
+ bool isLiteralValue) override;
+ void resetBindingForInvalidProperty(QObject *object,
+ const QString &propertyName) override;
private:
void buildStatesList(QObject *obj);
diff --git a/src/quick/quick.pro b/src/quick/quick.pro
index 8f4f9a8290..eae9b09b2f 100644
--- a/src/quick/quick.pro
+++ b/src/quick/quick.pro
@@ -9,6 +9,8 @@ win32-msvc*:DEFINES *= _CRT_SECURE_NO_WARNINGS
solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2
win32:!winrt: LIBS += -luser32
+DEFINES += QT_NO_FOREACH
+
exists("qqml_enable_gcov") {
QMAKE_CXXFLAGS = -fprofile-arcs -ftest-coverage -fno-elide-constructors
LIBS_PRIVATE += -lgcov
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwareadaptation.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwareadaptation.cpp
index 8ad9b50b09..92c02b4966 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwareadaptation.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwareadaptation.cpp
@@ -78,7 +78,7 @@ QSGRenderLoop *QSGSoftwareAdaptation::createWindowManager()
static bool envChecked = false;
if (!envChecked) {
envChecked = true;
- threaded = qgetenv("QSG_RENDER_LOOP") == QByteArrayLiteral("threaded");
+ threaded = qgetenv("QSG_RENDER_LOOP") == "threaded";
}
if (threaded)
diff --git a/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp b/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp
index df5ec9b745..8abbefdd48 100644
--- a/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp
+++ b/src/quick/scenegraph/adaptations/software/qsgsoftwarethreadedrenderloop.cpp
@@ -618,6 +618,11 @@ void QSGSoftwareThreadedRenderLoop::windowDestroyed(QQuickWindow *window)
break;
}
}
+
+ // Now that we altered the window list, we may need to stop the animation
+ // timer even if we didn't via handleObscurity. This covers the case where
+ // we destroy a visible & exposed QQuickWindow.
+ startOrStopAnimationTimer();
}
void QSGSoftwareThreadedRenderLoop::exposureChanged(QQuickWindow *window)
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
index eb5bfca1ee..2c0f8667e8 100644
--- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
+++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
@@ -440,9 +440,7 @@ struct Batch
mutable uint uploadedThisFrame : 1; // solely for debugging purposes
Buffer vbo;
-#ifdef QSG_SEPARATE_INDEX_BUFFER
Buffer ibo;
-#endif
QDataBuffer<DrawSet> drawSets;
};
@@ -561,7 +559,7 @@ public:
void updateRootTransforms(Node *n);
void updateRootTransforms(Node *n, Node *root, const QMatrix4x4 &combined);
- void updateStates(QSGNode *n);
+ void updateStates(QSGNode *n) override;
void visitNode(Node *n);
void registerWithParentRoot(QSGNode *subRoot, QSGNode *parentRoot);
@@ -744,9 +742,7 @@ private:
ClipType m_currentClipType;
QDataBuffer<char> m_vertexUploadPool;
-#ifdef QSG_SEPARATE_INDEX_BUFFER
QDataBuffer<char> m_indexUploadPool;
-#endif
// For minimal OpenGL core profile support
QOpenGLVertexArrayObject *m_vao;
@@ -766,10 +762,7 @@ Batch *Renderer::newBatch()
m_batchPool.resize(size - 1);
} else {
b = new Batch();
- memset(&b->vbo, 0, sizeof(Buffer));
-#ifdef QSG_SEPARATE_INDEX_BUFFER
- memset(&b->ibo, 0, sizeof(Buffer));
-#endif
+ memset(&b->vbo, 0, sizeof(Buffer) * 2); // Clear VBO & IBO
}
b->init();
return b;
diff --git a/src/quick/scenegraph/coreapi/qsgmaterial.cpp b/src/quick/scenegraph/coreapi/qsgmaterial.cpp
index d2d27cd9aa..8d666d3d0b 100644
--- a/src/quick/scenegraph/coreapi/qsgmaterial.cpp
+++ b/src/quick/scenegraph/coreapi/qsgmaterial.cpp
@@ -364,8 +364,8 @@ void QSGMaterialShader::compile()
{
Q_ASSERT_X(!m_program.isLinked(), "QSGSMaterialShader::compile()", "Compile called multiple times!");
- program()->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShader());
- program()->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShader());
+ program()->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexShader());
+ program()->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShader());
char const *const *attr = attributeNames();
#ifndef QT_NO_DEBUG
diff --git a/src/quick/scenegraph/coreapi/qsgnode.h b/src/quick/scenegraph/coreapi/qsgnode.h
index f7ea6dbe23..1467f2233d 100644
--- a/src/quick/scenegraph/coreapi/qsgnode.h
+++ b/src/quick/scenegraph/coreapi/qsgnode.h
@@ -325,7 +325,7 @@ public:
void setCombinedOpacity(qreal opacity);
qreal combinedOpacity() const { return m_combined_opacity; }
- bool isSubtreeBlocked() const;
+ bool isSubtreeBlocked() const override;
private:
qreal m_opacity;
diff --git a/src/quick/scenegraph/coreapi/qsgrenderer_p.h b/src/quick/scenegraph/coreapi/qsgrenderer_p.h
index 26e29d414d..4589685765 100644
--- a/src/quick/scenegraph/coreapi/qsgrenderer_p.h
+++ b/src/quick/scenegraph/coreapi/qsgrenderer_p.h
@@ -138,7 +138,7 @@ class QSGBindableFboId : public QSGBindable
{
public:
QSGBindableFboId(GLuint);
- virtual void bind() const;
+ void bind() const override;
private:
GLuint m_id;
};
@@ -160,8 +160,8 @@ public:
static void dump(QSGNode *n);
QSGNodeDumper() : m_indent(0) {}
- void visitNode(QSGNode *n);
- void visitChildren(QSGNode *n);
+ void visitNode(QSGNode *n) override;
+ void visitChildren(QSGNode *n) override;
private:
int m_indent;
diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp
index d309044e8f..0f49e615e4 100644
--- a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp
+++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp
@@ -77,6 +77,7 @@ QT_BEGIN_NAMESPACE
\value Software The Qt Quick 2D Renderer is in use
\value OpenGL OpenGL ES 2.0 or higher
\value Direct3D12 Direct3D 12
+ \value OpenVG OpenVG via EGL
*/
/*!
@@ -126,7 +127,7 @@ QSGRendererInterface::~QSGRendererInterface()
*/
/*!
- Queries a graphics \a resource. Returns null when the resource in question is
+ Queries a graphics \a resource in \a window. Returns null when the resource in question is
not supported or not available.
When successful, the returned pointer is either a direct pointer to an
diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.h b/src/quick/scenegraph/coreapi/qsgrendererinterface.h
index cf8fcf9015..722488201b 100644
--- a/src/quick/scenegraph/coreapi/qsgrendererinterface.h
+++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.h
@@ -53,7 +53,8 @@ public:
Unknown,
Software,
OpenGL,
- Direct3D12
+ Direct3D12,
+ OpenVG
};
enum Resource {
diff --git a/src/quick/scenegraph/coreapi/qsgshaderrewriter.cpp b/src/quick/scenegraph/coreapi/qsgshaderrewriter.cpp
index 3a35632d5c..48ab1aa52f 100644
--- a/src/quick/scenegraph/coreapi/qsgshaderrewriter.cpp
+++ b/src/quick/scenegraph/coreapi/qsgshaderrewriter.cpp
@@ -193,13 +193,13 @@ QByteArray qsgShaderRewriter_insertZAttributes(const char *input, QSurfaceFormat
switch (profile) {
case QSurfaceFormat::NoProfile:
case QSurfaceFormat::CompatibilityProfile:
- result += QByteArrayLiteral("attribute highp float _qt_order;\n");
- result += QByteArrayLiteral("uniform highp float _qt_zRange;\n");
+ result += "attribute highp float _qt_order;\n"
+ "uniform highp float _qt_zRange;\n";
break;
case QSurfaceFormat::CoreProfile:
- result += QByteArrayLiteral("in float _qt_order;\n");
- result += QByteArrayLiteral("uniform float _qt_zRange;\n");
+ result += "in float _qt_order;\n"
+ "uniform float _qt_zRange;\n";
break;
}
@@ -214,9 +214,9 @@ QByteArray qsgShaderRewriter_insertZAttributes(const char *input, QSurfaceFormat
case Tokenizer::Token_CloseBrace:
braceDepth--;
if (braceDepth == 0) {
- result += QByteArray::fromRawData(voidPos, tok.pos - 1 - voidPos);
- result += QByteArrayLiteral(" gl_Position.z = (gl_Position.z * _qt_zRange + _qt_order) * gl_Position.w;\n");
- result += QByteArray(tok.pos - 1);
+ result += QByteArray::fromRawData(voidPos, tok.pos - 1 - voidPos)
+ + " gl_Position.z = (gl_Position.z * _qt_zRange + _qt_order) * gl_Position.w;\n"
+ + QByteArray(tok.pos - 1);
return result;
}
break;
diff --git a/src/quick/scenegraph/qsgadaptationlayer_p.h b/src/quick/scenegraph/qsgadaptationlayer_p.h
index 5880c67af0..03a1f7f281 100644
--- a/src/quick/scenegraph/qsgadaptationlayer_p.h
+++ b/src/quick/scenegraph/qsgadaptationlayer_p.h
@@ -87,6 +87,8 @@ class QSGRenderNode;
class Q_QUICK_PRIVATE_EXPORT QSGNodeVisitorEx
{
public:
+ virtual ~QSGNodeVisitorEx() {}
+
// visit(...) returns true if the children are supposed to be
// visisted and false if they're supposed to be skipped by the visitor.
@@ -141,7 +143,7 @@ public:
virtual void update() = 0;
- virtual void accept(QSGNodeVisitorEx *visitor) { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); }
+ void accept(QSGNodeVisitorEx *visitor) override { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); }
};
@@ -165,7 +167,7 @@ public:
virtual void update() = 0;
- virtual void accept(QSGNodeVisitorEx *visitor) { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); }
+ void accept(QSGNodeVisitorEx *visitor) override { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); }
};
class Q_QUICK_PRIVATE_EXPORT QSGPainterNode : public QSGVisitableNode
@@ -188,7 +190,7 @@ public:
virtual void update() = 0;
virtual QSGTexture *texture() const = 0;
- virtual void accept(QSGNodeVisitorEx *visitor) { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); }
+ void accept(QSGNodeVisitorEx *visitor) override { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); }
};
class Q_QUICK_EXPORT QSGLayer : public QSGDynamicTexture
@@ -231,7 +233,7 @@ public:
virtual void update() = 0;
- virtual void accept(QSGNodeVisitorEx *visitor) { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); }
+ void accept(QSGNodeVisitorEx *visitor) override { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); }
};
#endif
@@ -389,7 +391,7 @@ public:
void setOwnerElement(QQuickItem *ownerElement) { m_ownerElement = ownerElement; }
QQuickItem *ownerElement() const { return m_ownerElement; }
- virtual void accept(QSGNodeVisitorEx *visitor) { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); }
+ void accept(QSGNodeVisitorEx *visitor) override { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); }
protected:
QRectF m_bounding_rect;
QQuickItem *m_ownerElement;
diff --git a/src/quick/scenegraph/qsgbasicglyphnode_p.h b/src/quick/scenegraph/qsgbasicglyphnode_p.h
index 1d09367ea5..0a43d17d2b 100644
--- a/src/quick/scenegraph/qsgbasicglyphnode_p.h
+++ b/src/quick/scenegraph/qsgbasicglyphnode_p.h
@@ -63,16 +63,16 @@ public:
QSGBasicGlyphNode();
virtual ~QSGBasicGlyphNode();
- virtual QPointF baseLine() const { return m_baseLine; }
- virtual void setGlyphs(const QPointF &position, const QGlyphRun &glyphs);
- virtual void setColor(const QColor &color);
+ QPointF baseLine() const override { return m_baseLine; }
+ void setGlyphs(const QPointF &position, const QGlyphRun &glyphs) override;
+ void setColor(const QColor &color) override;
- virtual void setPreferredAntialiasingMode(AntialiasingMode) { }
- virtual void setStyle(QQuickText::TextStyle);
- virtual void setStyleColor(const QColor &);
+ void setPreferredAntialiasingMode(AntialiasingMode) override { }
+ void setStyle(QQuickText::TextStyle) override;
+ void setStyleColor(const QColor &) override;
virtual void setMaterialColor(const QColor &color) = 0;
- virtual void update() = 0;
+ void update() override = 0;
protected:
QGlyphRun m_glyphs;
diff --git a/src/quick/scenegraph/qsgcontext_p.h b/src/quick/scenegraph/qsgcontext_p.h
index 6b9db105e7..2f5d5790ee 100644
--- a/src/quick/scenegraph/qsgcontext_p.h
+++ b/src/quick/scenegraph/qsgcontext_p.h
@@ -88,6 +88,7 @@ class QSGRectangleNode;
class QSGImageNode;
class QSGNinePatchNode;
class QSGSpriteNode;
+class QSGRenderContext;
Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_RENDERLOOP)
Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_COMPILATION)
@@ -98,6 +99,54 @@ Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_TIME_RENDERER)
Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_INFO)
Q_DECLARE_LOGGING_CATEGORY(QSG_LOG_RENDERLOOP)
+class Q_QUICK_PRIVATE_EXPORT QSGContext : public QObject
+{
+ Q_OBJECT
+
+public:
+ enum AntialiasingMethod {
+ UndecidedAntialiasing,
+ VertexAntialiasing,
+ MsaaAntialiasing
+ };
+
+ explicit QSGContext(QObject *parent = 0);
+ virtual ~QSGContext();
+
+ virtual void renderContextInitialized(QSGRenderContext *renderContext);
+ virtual void renderContextInvalidated(QSGRenderContext *renderContext);
+ virtual QSGRenderContext *createRenderContext() = 0;
+
+ QSGInternalRectangleNode *createInternalRectangleNode(const QRectF &rect, const QColor &c);
+ virtual QSGInternalRectangleNode *createInternalRectangleNode() = 0;
+ virtual QSGInternalImageNode *createInternalImageNode() = 0;
+ virtual QSGPainterNode *createPainterNode(QQuickPaintedItem *item) = 0;
+ virtual QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode) = 0;
+ virtual QSGLayer *createLayer(QSGRenderContext *renderContext) = 0;
+ virtual QSGGuiThreadShaderEffectManager *createGuiThreadShaderEffectManager();
+ virtual QSGShaderEffectNode *createShaderEffectNode(QSGRenderContext *renderContext,
+ QSGGuiThreadShaderEffectManager *mgr);
+#if QT_CONFIG(quick_sprite)
+ virtual QSGSpriteNode *createSpriteNode() = 0;
+#endif
+ virtual QAnimationDriver *createAnimationDriver(QObject *parent);
+
+ virtual QSize minimumFBOSize() const;
+ virtual QSurfaceFormat defaultSurfaceFormat() const = 0;
+
+ virtual QSGRendererInterface *rendererInterface(QSGRenderContext *renderContext);
+
+ virtual QSGRectangleNode *createRectangleNode() = 0;
+ virtual QSGImageNode *createImageNode() = 0;
+ virtual QSGNinePatchNode *createNinePatchNode() = 0;
+
+ static QSGContext *createDefaultContext();
+ static QQuickTextureFactory *createTextureFactoryFromImage(const QImage &image);
+ static QSGRenderLoop *createWindowManager();
+
+ static void setBackend(const QString &backend);
+};
+
class Q_QUICK_PRIVATE_EXPORT QSGRenderContext : public QObject
{
Q_OBJECT
@@ -150,55 +199,6 @@ protected:
QSet<QFontEngine *> m_fontEnginesToClean;
};
-
-class Q_QUICK_PRIVATE_EXPORT QSGContext : public QObject
-{
- Q_OBJECT
-
-public:
- enum AntialiasingMethod {
- UndecidedAntialiasing,
- VertexAntialiasing,
- MsaaAntialiasing
- };
-
- explicit QSGContext(QObject *parent = 0);
- virtual ~QSGContext();
-
- virtual void renderContextInitialized(QSGRenderContext *renderContext);
- virtual void renderContextInvalidated(QSGRenderContext *renderContext);
- virtual QSGRenderContext *createRenderContext() = 0;
-
- QSGInternalRectangleNode *createInternalRectangleNode(const QRectF &rect, const QColor &c);
- virtual QSGInternalRectangleNode *createInternalRectangleNode() = 0;
- virtual QSGInternalImageNode *createInternalImageNode() = 0;
- virtual QSGPainterNode *createPainterNode(QQuickPaintedItem *item) = 0;
- virtual QSGGlyphNode *createGlyphNode(QSGRenderContext *rc, bool preferNativeGlyphNode) = 0;
- virtual QSGLayer *createLayer(QSGRenderContext *renderContext) = 0;
- virtual QSGGuiThreadShaderEffectManager *createGuiThreadShaderEffectManager();
- virtual QSGShaderEffectNode *createShaderEffectNode(QSGRenderContext *renderContext,
- QSGGuiThreadShaderEffectManager *mgr);
-#if QT_CONFIG(quick_sprite)
- virtual QSGSpriteNode *createSpriteNode() = 0;
-#endif
- virtual QAnimationDriver *createAnimationDriver(QObject *parent);
-
- virtual QSize minimumFBOSize() const;
- virtual QSurfaceFormat defaultSurfaceFormat() const = 0;
-
- virtual QSGRendererInterface *rendererInterface(QSGRenderContext *renderContext);
-
- virtual QSGRectangleNode *createRectangleNode() = 0;
- virtual QSGImageNode *createImageNode() = 0;
- virtual QSGNinePatchNode *createNinePatchNode() = 0;
-
- static QSGContext *createDefaultContext();
- static QQuickTextureFactory *createTextureFactoryFromImage(const QImage &image);
- static QSGRenderLoop *createWindowManager();
-
- static void setBackend(const QString &backend);
-};
-
QT_END_NAMESPACE
#endif // QSGCONTEXT_H
diff --git a/src/quick/scenegraph/qsgcontextplugin_p.h b/src/quick/scenegraph/qsgcontextplugin_p.h
index 08c3d21408..5914b42809 100644
--- a/src/quick/scenegraph/qsgcontextplugin_p.h
+++ b/src/quick/scenegraph/qsgcontextplugin_p.h
@@ -90,10 +90,10 @@ public:
explicit QSGContextPlugin(QObject *parent = 0);
virtual ~QSGContextPlugin();
- virtual QStringList keys() const = 0;
+ virtual QStringList keys() const override = 0;
- virtual QQuickTextureFactory *createTextureFactoryFromImage(const QImage &) { return 0; }
- virtual QSGRenderLoop *createWindowManager() { return 0; }
+ QQuickTextureFactory *createTextureFactoryFromImage(const QImage &) override { return 0; }
+ QSGRenderLoop *createWindowManager() override { return 0; }
};
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h
index eeea104e91..57dc4a5d07 100644
--- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h
+++ b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h
@@ -72,10 +72,10 @@ public:
QSGDefaultDistanceFieldGlyphCache(QSGDistanceFieldGlyphCacheManager *man, QOpenGLContext *c, const QRawFont &font);
virtual ~QSGDefaultDistanceFieldGlyphCache();
- void requestGlyphs(const QSet<glyph_t> &glyphs);
- void storeGlyphs(const QList<QDistanceField> &glyphs);
- void referenceGlyphs(const QSet<glyph_t> &glyphs);
- void releaseGlyphs(const QSet<glyph_t> &glyphs);
+ void requestGlyphs(const QSet<glyph_t> &glyphs) override;
+ void storeGlyphs(const QList<QDistanceField> &glyphs) override;
+ void referenceGlyphs(const QSet<glyph_t> &glyphs) override;
+ void releaseGlyphs(const QSet<glyph_t> &glyphs) override;
bool useTextureResizeWorkaround() const;
bool useTextureUploadWorkaround() const;
@@ -116,24 +116,16 @@ private:
{
m_blitProgram = new QOpenGLShaderProgram;
{
- QString source;
- source.append(QLatin1String(qopenglslMainWithTexCoordsVertexShader));
- source.append(QLatin1String(qopenglslUntransformedPositionVertexShader));
+ const QString source = QLatin1String(qopenglslMainWithTexCoordsVertexShader)
+ + QLatin1String(qopenglslUntransformedPositionVertexShader);
- QOpenGLShader *vertexShader = new QOpenGLShader(QOpenGLShader::Vertex, m_blitProgram);
- vertexShader->compileSourceCode(source);
-
- m_blitProgram->addShader(vertexShader);
+ m_blitProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, source);
}
{
- QString source;
- source.append(QLatin1String(qopenglslMainFragmentShader));
- source.append(QLatin1String(qopenglslImageSrcFragmentShader));
-
- QOpenGLShader *fragmentShader = new QOpenGLShader(QOpenGLShader::Fragment, m_blitProgram);
- fragmentShader->compileSourceCode(source);
+ const QString source = QLatin1String(qopenglslMainFragmentShader)
+ + QLatin1String(qopenglslImageSrcFragmentShader);
- m_blitProgram->addShader(fragmentShader);
+ m_blitProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, source);
}
m_blitProgram->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
m_blitProgram->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR);
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h b/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h
index caa7dfad07..b0a2788dd8 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h
+++ b/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h
@@ -71,9 +71,9 @@ public:
QSGTextMaskMaterial(const QRawFont &font, QFontEngine::GlyphFormat glyphFormat = QFontEngine::Format_None);
virtual ~QSGTextMaskMaterial();
- virtual QSGMaterialType *type() const;
- virtual QSGMaterialShader *createShader() const;
- virtual int compare(const QSGMaterial *other) const;
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
+ int compare(const QSGMaterial *other) const override;
void setColor(const QColor &c) { m_color = QVector4D(c.redF(), c.greenF(), c.blueF(), c.alphaF()); }
void setColor(const QVector4D &color) { m_color = color; }
@@ -115,10 +115,10 @@ public:
void setStyleColor(const QVector4D &color) { m_styleColor = color; }
const QVector4D &styleColor() const { return m_styleColor; }
- virtual QSGMaterialType *type() const;
- virtual QSGMaterialShader *createShader() const;
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
- int compare(const QSGMaterial *other) const;
+ int compare(const QSGMaterial *other) const override;
private:
QVector2D m_styleShift;
@@ -131,8 +131,8 @@ public:
QSGOutlinedTextMaterial(const QRawFont &font);
~QSGOutlinedTextMaterial() { }
- QSGMaterialType *type() const;
- QSGMaterialShader *createShader() const;
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
};
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgdefaultrendercontext.cpp b/src/quick/scenegraph/qsgdefaultrendercontext.cpp
index 1a17453baf..2c5b4ff5c8 100644
--- a/src/quick/scenegraph/qsgdefaultrendercontext.cpp
+++ b/src/quick/scenegraph/qsgdefaultrendercontext.cpp
@@ -262,8 +262,8 @@ void QSGDefaultRenderContext::compileShader(QSGMaterialShader *shader, QSGMateri
"QSGRenderContext::compile()",
"materials with custom compile step cannot have custom vertex/fragment code");
QOpenGLShaderProgram *p = shader->program();
- p->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexCode ? vertexCode : shader->vertexShader());
- p->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentCode ? fragmentCode : shader->fragmentShader());
+ p->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexCode ? vertexCode : shader->vertexShader());
+ p->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragmentCode ? fragmentCode : shader->fragmentShader());
p->link();
if (!p->isLinked())
qWarning() << "shader compilation failed:" << endl << p->log();
diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.h b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.h
index 22c68558ef..c0c6bda718 100644
--- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.h
+++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.h
@@ -67,19 +67,19 @@ public:
QSGDistanceFieldGlyphNode(QSGRenderContext *context);
~QSGDistanceFieldGlyphNode();
- virtual QPointF baseLine() const { return m_baseLine; }
- virtual void setGlyphs(const QPointF &position, const QGlyphRun &glyphs);
- virtual void setColor(const QColor &color);
+ QPointF baseLine() const override { return m_baseLine; }
+ void setGlyphs(const QPointF &position, const QGlyphRun &glyphs) override;
+ void setColor(const QColor &color) override;
- virtual void setPreferredAntialiasingMode(AntialiasingMode mode);
+ void setPreferredAntialiasingMode(AntialiasingMode mode) override;
- virtual void setStyle(QQuickText::TextStyle style);
- virtual void setStyleColor(const QColor &color);
+ void setStyle(QQuickText::TextStyle style) override;
+ void setStyleColor(const QColor &color) override;
- virtual void update();
- void preprocess();
+ void update() override;
+ void preprocess() override;
- void invalidateGlyphs(const QVector<quint32> &glyphs);
+ void invalidateGlyphs(const QVector<quint32> &glyphs) override;
void updateGeometry();
diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h b/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h
index 38dcf3d307..c13a0898eb 100644
--- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h
+++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h
@@ -63,9 +63,9 @@ public:
QSGDistanceFieldTextMaterial();
~QSGDistanceFieldTextMaterial();
- virtual QSGMaterialType *type() const;
- virtual QSGMaterialShader *createShader() const;
- virtual int compare(const QSGMaterial *other) const;
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
+ int compare(const QSGMaterial *other) const override;
virtual void setColor(const QColor &color);
const QVector4D &color() const { return m_color; }
@@ -97,9 +97,9 @@ public:
QSGDistanceFieldStyledTextMaterial();
~QSGDistanceFieldStyledTextMaterial();
- virtual QSGMaterialType *type() const = 0;
- virtual QSGMaterialShader *createShader() const = 0;
- virtual int compare(const QSGMaterial *other) const;
+ QSGMaterialType *type() const override = 0;
+ QSGMaterialShader *createShader() const override = 0;
+ int compare(const QSGMaterial *other) const override;
void setStyleColor(const QColor &color);
const QVector4D &styleColor() const { return m_styleColor; }
@@ -114,8 +114,8 @@ public:
QSGDistanceFieldOutlineTextMaterial();
~QSGDistanceFieldOutlineTextMaterial();
- virtual QSGMaterialType *type() const;
- virtual QSGMaterialShader *createShader() const;
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
};
class Q_QUICK_PRIVATE_EXPORT QSGDistanceFieldShiftedStyleTextMaterial : public QSGDistanceFieldStyledTextMaterial
@@ -124,9 +124,9 @@ public:
QSGDistanceFieldShiftedStyleTextMaterial();
~QSGDistanceFieldShiftedStyleTextMaterial();
- virtual QSGMaterialType *type() const;
- virtual QSGMaterialShader *createShader() const;
- virtual int compare(const QSGMaterial *other) const;
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
+ int compare(const QSGMaterial *other) const override;
void setShift(const QPointF &shift) { m_shift = shift; }
const QPointF &shift() const { return m_shift; }
@@ -138,17 +138,17 @@ protected:
class Q_QUICK_PRIVATE_EXPORT QSGHiQSubPixelDistanceFieldTextMaterial : public QSGDistanceFieldTextMaterial
{
public:
- virtual QSGMaterialType *type() const;
- virtual QSGMaterialShader *createShader() const;
- void setColor(const QColor &color) { m_color = QVector4D(color.redF(), color.greenF(), color.blueF(), color.alphaF()); }
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
+ void setColor(const QColor &color) override { m_color = QVector4D(color.redF(), color.greenF(), color.blueF(), color.alphaF()); }
};
class Q_QUICK_PRIVATE_EXPORT QSGLoQSubPixelDistanceFieldTextMaterial : public QSGDistanceFieldTextMaterial
{
public:
- virtual QSGMaterialType *type() const;
- virtual QSGMaterialShader *createShader() const;
- void setColor(const QColor &color) { m_color = QVector4D(color.redF(), color.greenF(), color.blueF(), color.alphaF()); }
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
+ void setColor(const QColor &color) override { m_color = QVector4D(color.redF(), color.greenF(), color.blueF(), color.alphaF()); }
};
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgrenderloop.cpp b/src/quick/scenegraph/qsgrenderloop.cpp
index ec874f6ff0..48288bfc62 100644
--- a/src/quick/scenegraph/qsgrenderloop.cpp
+++ b/src/quick/scenegraph/qsgrenderloop.cpp
@@ -211,11 +211,11 @@ QSGRenderLoop *QSGRenderLoop::instance()
if (Q_UNLIKELY(qEnvironmentVariableIsSet("QSG_RENDER_LOOP"))) {
const QByteArray loopName = qgetenv("QSG_RENDER_LOOP");
- if (loopName == QByteArrayLiteral("windows"))
+ if (loopName == "windows")
loopType = WindowsRenderLoop;
- else if (loopName == QByteArrayLiteral("basic"))
+ else if (loopName == "basic")
loopType = BasicRenderLoop;
- else if (loopName == QByteArrayLiteral("threaded"))
+ else if (loopName == "threaded")
loopType = ThreadedRenderLoop;
}
diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp
index 4543782d5b..5fa74027c1 100644
--- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp
+++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp
@@ -280,7 +280,7 @@ public:
, stopEventProcessing(false)
{
sgrc = static_cast<QSGDefaultRenderContext *>(renderContext);
-#if defined(Q_OS_QNX) && !defined(Q_OS_BLACKBERRY) && defined(Q_PROCESSOR_X86)
+#if defined(Q_OS_QNX) && defined(Q_PROCESSOR_X86)
// The SDP 6.6.0 x86 MESA driver requires a larger stack than the default.
setStackSize(1024 * 1024);
#endif
@@ -826,13 +826,14 @@ void QSGThreadedRenderLoop::startOrStopAnimationTimer()
}
if (m_animation_timer != 0 && (exposedWindows == 1 || !m_animation_driver->isRunning())) {
+ qCDebug(QSG_LOG_RENDERLOOP) << "*** Stopping animation timer";
killTimer(m_animation_timer);
m_animation_timer = 0;
// If animations are running, make sure we keep on animating
if (m_animation_driver->isRunning())
maybePostPolishRequest(const_cast<Window *>(theOne));
-
} else if (m_animation_timer == 0 && exposedWindows != 1 && m_animation_driver->isRunning()) {
+ qCDebug(QSG_LOG_RENDERLOOP) << "*** Starting animation timer";
m_animation_timer = startTimer(qsgrl_animation_interval());
}
}
@@ -888,6 +889,11 @@ void QSGThreadedRenderLoop::windowDestroyed(QQuickWindow *window)
}
}
+ // Now that we altered the window list, we may need to stop the animation
+ // timer even if we didn't via handleObscurity. This covers the case where
+ // we destroy a visible & exposed QQuickWindow.
+ startOrStopAnimationTimer();
+
qCDebug(QSG_LOG_RENDERLOOP) << "done windowDestroyed()" << window;
}
diff --git a/src/quick/scenegraph/qsgthreadedrenderloop_p.h b/src/quick/scenegraph/qsgthreadedrenderloop_p.h
index 0ab83b444a..32bfcb7148 100644
--- a/src/quick/scenegraph/qsgthreadedrenderloop_p.h
+++ b/src/quick/scenegraph/qsgthreadedrenderloop_p.h
@@ -68,29 +68,29 @@ public:
QSGThreadedRenderLoop();
~QSGThreadedRenderLoop();
- void show(QQuickWindow *) {}
- void hide(QQuickWindow *);
+ void show(QQuickWindow *) override {}
+ void hide(QQuickWindow *) override;
- void windowDestroyed(QQuickWindow *window);
- void exposureChanged(QQuickWindow *window);
+ void windowDestroyed(QQuickWindow *window) override;
+ void exposureChanged(QQuickWindow *window) override;
- QImage grab(QQuickWindow *);
+ QImage grab(QQuickWindow *) override;
- void update(QQuickWindow *window);
- void maybeUpdate(QQuickWindow *window);
- void handleUpdateRequest(QQuickWindow *window);
+ void update(QQuickWindow *window) override;
+ void maybeUpdate(QQuickWindow *window) override;
+ void handleUpdateRequest(QQuickWindow *window) override;
- QSGContext *sceneGraphContext() const;
- QSGRenderContext *createRenderContext(QSGContext *) const;
+ QSGContext *sceneGraphContext() const override;
+ QSGRenderContext *createRenderContext(QSGContext *) const override;
- QAnimationDriver *animationDriver() const;
+ QAnimationDriver *animationDriver() const override;
- void releaseResources(QQuickWindow *window);
+ void releaseResources(QQuickWindow *window) override;
- bool event(QEvent *);
- void postJob(QQuickWindow *window, QRunnable *job);
+ bool event(QEvent *) override;
+ void postJob(QQuickWindow *window, QRunnable *job) override;
- bool interleaveIncubation() const;
+ bool interleaveIncubation() const override;
public Q_SLOTS:
void animationStarted();
diff --git a/src/quick/scenegraph/qsgwindowsrenderloop.cpp b/src/quick/scenegraph/qsgwindowsrenderloop.cpp
index 13388c0841..e944ddbc4f 100644
--- a/src/quick/scenegraph/qsgwindowsrenderloop.cpp
+++ b/src/quick/scenegraph/qsgwindowsrenderloop.cpp
@@ -84,18 +84,17 @@ QSGWindowsRenderLoop::QSGWindowsRenderLoop()
{
m_rc = static_cast<QSGDefaultRenderContext *>(m_sg->createRenderContext());
- m_animationDriver = m_sg->createAnimationDriver(m_sg);
- m_animationDriver->install();
-
- connect(m_animationDriver, SIGNAL(started()), this, SLOT(started()));
- connect(m_animationDriver, SIGNAL(stopped()), this, SLOT(stopped()));
-
m_vsyncDelta = 1000 / QGuiApplication::primaryScreen()->refreshRate();
if (m_vsyncDelta <= 0)
m_vsyncDelta = 16;
RLDEBUG("Windows Render Loop created");
+ m_animationDriver = m_sg->createAnimationDriver(m_sg);
+ connect(m_animationDriver, SIGNAL(started()), this, SLOT(started()));
+ connect(m_animationDriver, SIGNAL(stopped()), this, SLOT(stopped()));
+ m_animationDriver->install();
+
qsg_render_timer.start();
}
diff --git a/src/quick/scenegraph/qsgwindowsrenderloop_p.h b/src/quick/scenegraph/qsgwindowsrenderloop_p.h
index 9e5d7f04d3..1940a66af2 100644
--- a/src/quick/scenegraph/qsgwindowsrenderloop_p.h
+++ b/src/quick/scenegraph/qsgwindowsrenderloop_p.h
@@ -70,31 +70,31 @@ public:
explicit QSGWindowsRenderLoop();
~QSGWindowsRenderLoop();
- void show(QQuickWindow *window);
- void hide(QQuickWindow *window);
+ void show(QQuickWindow *window) override;
+ void hide(QQuickWindow *window) override;
- void windowDestroyed(QQuickWindow *window);
+ void windowDestroyed(QQuickWindow *window) override;
- void exposureChanged(QQuickWindow *window);
- QImage grab(QQuickWindow *window);
+ void exposureChanged(QQuickWindow *window) override;
+ QImage grab(QQuickWindow *window) override;
- void update(QQuickWindow *window);
- void maybeUpdate(QQuickWindow *window);
+ void update(QQuickWindow *window) override;
+ void maybeUpdate(QQuickWindow *window) override;
- QAnimationDriver *animationDriver() const { return m_animationDriver; }
+ QAnimationDriver *animationDriver() const override { return m_animationDriver; }
- QSGContext *sceneGraphContext() const { return m_sg; }
- QSGRenderContext *createRenderContext(QSGContext *) const;
+ QSGContext *sceneGraphContext() const override { return m_sg; }
+ QSGRenderContext *createRenderContext(QSGContext *) const override;
- void releaseResources(QQuickWindow *) { }
+ void releaseResources(QQuickWindow *) override { }
void render();
void renderWindow(QQuickWindow *window);
- bool event(QEvent *event);
+ bool event(QEvent *event) override;
bool anyoneShowing() const;
- bool interleaveIncubation() const;
+ bool interleaveIncubation() const override;
public Q_SLOTS:
void started();
diff --git a/src/quick/scenegraph/scenegraph.pri b/src/quick/scenegraph/scenegraph.pri
index edf4aa08c5..38c3b8dd85 100644
--- a/src/quick/scenegraph/scenegraph.pri
+++ b/src/quick/scenegraph/scenegraph.pri
@@ -1,4 +1,4 @@
-# DEFINES += QSG_SEPARATE_INDEX_BUFFER
+DEFINES += QSG_SEPARATE_INDEX_BUFFER
# DEFINES += QSG_DISTANCEFIELD_CACHE_DEBUG
# Core API
diff --git a/src/quick/scenegraph/util/qsgatlastexture_p.h b/src/quick/scenegraph/util/qsgatlastexture_p.h
index cd24645fcf..3dee539547 100644
--- a/src/quick/scenegraph/util/qsgatlastexture_p.h
+++ b/src/quick/scenegraph/util/qsgatlastexture_p.h
@@ -131,26 +131,26 @@ public:
Texture(Atlas *atlas, const QRect &textureRect, const QImage &image);
~Texture();
- int textureId() const { return m_atlas->textureId(); }
- QSize textureSize() const { return atlasSubRectWithoutPadding().size(); }
+ int textureId() const override { return m_atlas->textureId(); }
+ QSize textureSize() const override { return atlasSubRectWithoutPadding().size(); }
void setHasAlphaChannel(bool alpha) { m_has_alpha = alpha; }
- bool hasAlphaChannel() const { return m_has_alpha; }
- bool hasMipmaps() const { return false; }
- bool isAtlasTexture() const { return true; }
+ bool hasAlphaChannel() const override { return m_has_alpha; }
+ bool hasMipmaps() const override { return false; }
+ bool isAtlasTexture() const override { return true; }
- QRectF normalizedTextureSubRect() const { return m_texture_coords_rect; }
+ QRectF normalizedTextureSubRect() const override { return m_texture_coords_rect; }
QRect atlasSubRect() const { return m_allocated_rect; }
QRect atlasSubRectWithoutPadding() const { return m_allocated_rect.adjusted(1, 1, -1, -1); }
bool isTexture() const { return true; }
- QSGTexture *removedFromAtlas() const;
+ QSGTexture *removedFromAtlas() const override;
void releaseImage() { m_image = QImage(); }
const QImage &image() const { return m_image; }
- void bind();
+ void bind() override;
private:
QRect m_allocated_rect;
diff --git a/src/quick/scenegraph/util/qsgdefaultimagenode.cpp b/src/quick/scenegraph/util/qsgdefaultimagenode.cpp
index 63773887a0..7186ee4265 100644
--- a/src/quick/scenegraph/util/qsgdefaultimagenode.cpp
+++ b/src/quick/scenegraph/util/qsgdefaultimagenode.cpp
@@ -94,6 +94,21 @@ QSGTexture::Filtering QSGDefaultImageNode::mipmapFiltering() const
return m_material.mipmapFiltering();
}
+void QSGDefaultImageNode::setAnisotropyLevel(QSGTexture::AnisotropyLevel level)
+{
+ if (m_material.anisotropyLevel() == level)
+ return;
+
+ m_material.setAnisotropyLevel(level);
+ m_opaque_material.setAnisotropyLevel(level);
+ markDirty(DirtyMaterial);
+}
+
+QSGTexture::AnisotropyLevel QSGDefaultImageNode::anisotropyLevel() const
+{
+ return m_material.anisotropyLevel();
+}
+
void QSGDefaultImageNode::setRect(const QRectF &r)
{
if (m_rect == r)
diff --git a/src/quick/scenegraph/util/qsgdefaultimagenode_p.h b/src/quick/scenegraph/util/qsgdefaultimagenode_p.h
index bb9ebec885..cb23e759d3 100644
--- a/src/quick/scenegraph/util/qsgdefaultimagenode_p.h
+++ b/src/quick/scenegraph/util/qsgdefaultimagenode_p.h
@@ -85,6 +85,10 @@ public:
void setOwnsTexture(bool owns) override;
bool ownsTexture() const override;
+ // QSGImageNode now being a public class does not allow any additional virtual methods. Placing these here, non-virtual.
+ void setAnisotropyLevel(QSGTexture::AnisotropyLevel level);
+ QSGTexture::AnisotropyLevel anisotropyLevel() const;
+
private:
QSGGeometry m_geometry;
QSGOpaqueTextureMaterial m_opaque_material;
diff --git a/src/quick/scenegraph/util/qsgdefaultpainternode_p.h b/src/quick/scenegraph/util/qsgdefaultpainternode_p.h
index 7488f7878d..084fc1e004 100644
--- a/src/quick/scenegraph/util/qsgdefaultpainternode_p.h
+++ b/src/quick/scenegraph/util/qsgdefaultpainternode_p.h
@@ -72,7 +72,7 @@ public:
void setDirtyRect(const QRect &rect) { m_dirty_rect = rect; }
- void bind();
+ void bind() override;
private:
QRect m_dirty_rect;
@@ -84,43 +84,43 @@ public:
QSGDefaultPainterNode(QQuickPaintedItem *item);
virtual ~QSGDefaultPainterNode();
- void setPreferredRenderTarget(QQuickPaintedItem::RenderTarget target);
+ void setPreferredRenderTarget(QQuickPaintedItem::RenderTarget target) override;
- void setSize(const QSize &size);
+ void setSize(const QSize &size) override;
QSize size() const { return m_size; }
- void setDirty(const QRect &dirtyRect = QRect());
+ void setDirty(const QRect &dirtyRect = QRect()) override;
- void setOpaquePainting(bool opaque);
+ void setOpaquePainting(bool opaque) override;
bool opaquePainting() const { return m_opaquePainting; }
- void setLinearFiltering(bool linearFiltering);
+ void setLinearFiltering(bool linearFiltering) override;
bool linearFiltering() const { return m_linear_filtering; }
- void setMipmapping(bool mipmapping);
+ void setMipmapping(bool mipmapping) override;
bool mipmapping() const { return m_mipmapping; }
- void setSmoothPainting(bool s);
+ void setSmoothPainting(bool s) override;
bool smoothPainting() const { return m_smoothPainting; }
- void setFillColor(const QColor &c);
+ void setFillColor(const QColor &c) override;
QColor fillColor() const { return m_fillColor; }
- void setContentsScale(qreal s);
+ void setContentsScale(qreal s) override;
qreal contentsScale() const { return m_contentsScale; }
- void setFastFBOResizing(bool fastResizing);
+ void setFastFBOResizing(bool fastResizing) override;
bool fastFBOResizing() const { return m_fastFBOResizing; }
- void setTextureSize(const QSize &textureSize);
+ void setTextureSize(const QSize &textureSize) override;
QSize textureSize() const { return m_textureSize; }
- QImage toImage() const;
- void update();
+ QImage toImage() const override;
+ void update() override;
void paint();
- QSGTexture *texture() const { return m_texture; }
+ QSGTexture *texture() const override { return m_texture; }
private:
void updateTexture();
diff --git a/src/quick/scenegraph/util/qsgdepthstencilbuffer_p.h b/src/quick/scenegraph/util/qsgdepthstencilbuffer_p.h
index c2d0590532..f7c6923021 100644
--- a/src/quick/scenegraph/util/qsgdepthstencilbuffer_p.h
+++ b/src/quick/scenegraph/util/qsgdepthstencilbuffer_p.h
@@ -119,7 +119,7 @@ public:
virtual ~QSGDefaultDepthStencilBuffer();
protected:
- virtual void free();
+ void free() override;
};
diff --git a/src/quick/scenegraph/util/qsgflatcolormaterial.h b/src/quick/scenegraph/util/qsgflatcolormaterial.h
index 7f292a2a9b..4829ac3279 100644
--- a/src/quick/scenegraph/util/qsgflatcolormaterial.h
+++ b/src/quick/scenegraph/util/qsgflatcolormaterial.h
@@ -49,13 +49,13 @@ class Q_QUICK_EXPORT QSGFlatColorMaterial : public QSGMaterial
{
public:
QSGFlatColorMaterial();
- virtual QSGMaterialType *type() const;
- virtual QSGMaterialShader *createShader() const;
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
void setColor(const QColor &color);
const QColor &color() const { return m_color; }
- int compare(const QSGMaterial *other) const;
+ int compare(const QSGMaterial *other) const override;
private:
QColor m_color;
diff --git a/src/quick/scenegraph/util/qsgimagenode.h b/src/quick/scenegraph/util/qsgimagenode.h
index d25e732e4b..0e053c307f 100644
--- a/src/quick/scenegraph/util/qsgimagenode.h
+++ b/src/quick/scenegraph/util/qsgimagenode.h
@@ -67,6 +67,8 @@ public:
virtual void setMipmapFiltering(QSGTexture::Filtering filtering) = 0;
virtual QSGTexture::Filtering mipmapFiltering() const = 0;
+ // ### Qt6: Add anisotropy support here, and possibly a virtual hook or another mean to extend this class.
+
enum TextureCoordinatesTransformFlag {
NoTransform = 0x00,
MirrorHorizontally = 0x01,
diff --git a/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp b/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp
index caa296451e..d8f92919cb 100644
--- a/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp
+++ b/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp
@@ -217,11 +217,11 @@ void QSGShaderSourceBuilder::initializeProgramFromFiles(QOpenGLShaderProgram *pr
QSGShaderSourceBuilder builder;
builder.appendSourceFile(vertexShader);
- program->addShaderFromSourceCode(QOpenGLShader::Vertex, builder.source());
+ program->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, builder.source());
builder.clear();
builder.appendSourceFile(fragmentShader);
- program->addShaderFromSourceCode(QOpenGLShader::Fragment, builder.source());
+ program->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, builder.source());
}
QByteArray QSGShaderSourceBuilder::source() const
@@ -310,13 +310,10 @@ void QSGShaderSourceBuilder::addDefinition(const QByteArray &definition)
const char *insertionPos = extensionPos ? extensionPos : (versionPos ? versionPos : input);
// Construct a new shader string, inserting the definition
- QByteArray newSource;
- newSource.reserve(m_source.size() + definition.size() + 9);
- newSource += QByteArray::fromRawData(input, insertionPos - input);
- newSource += QByteArrayLiteral("#define ") + definition + QByteArrayLiteral("\n");
- newSource += QByteArray::fromRawData(insertionPos, m_source.size() - (insertionPos - input));
-
- m_source = newSource;
+ QByteArray newSource = QByteArray::fromRawData(input, insertionPos - input)
+ + "#define " + definition + '\n'
+ + QByteArray::fromRawData(insertionPos, m_source.size() - (insertionPos - input));
+ m_source = std::move(newSource);
}
void QSGShaderSourceBuilder::removeVersion()
diff --git a/src/quick/scenegraph/util/qsgsimplematerial.h b/src/quick/scenegraph/util/qsgsimplematerial.h
index 8f42599832..0e7219d7bd 100644
--- a/src/quick/scenegraph/util/qsgsimplematerial.h
+++ b/src/quick/scenegraph/util/qsgsimplematerial.h
@@ -48,7 +48,7 @@ template <typename State>
class QSGSimpleMaterialShader : public QSGMaterialShader
{
public:
- void initialize() {
+ void initialize() override {
QSGMaterialShader::initialize();
#if QT_CONFIG(opengl)
m_id_matrix = program()->uniformLocation(uniformMatrixName());
@@ -74,7 +74,7 @@ public:
const char *uniformMatrixName() const { return "qt_Matrix"; }
const char *uniformOpacityName() const { return "qt_Opacity"; }
- void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
+ void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
virtual void updateState(const State *newState, const State *oldState) = 0;
@@ -82,7 +82,7 @@ public:
virtual QList<QByteArray> attributes() const = 0;
- char const *const *attributeNames() const
+ char const *const *attributeNames() const override
{
if (m_attribute_pointers.size())
return m_attribute_pointers.constData();
@@ -149,8 +149,8 @@ public:
{
}
- QSGMaterialShader *createShader() const { return m_func(); }
- QSGMaterialType *type() const { return &m_type; }
+ QSGMaterialShader *createShader() const override { return m_func(); }
+ QSGMaterialType *type() const override { return &m_type; }
State *state() { return &m_state; }
const State *state() const { return &m_state; }
diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/util/qsgtexture.cpp
index 47248f2f37..bc59c49162 100644
--- a/src/quick/scenegraph/util/qsgtexture.cpp
+++ b/src/quick/scenegraph/util/qsgtexture.cpp
@@ -83,6 +83,9 @@ static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK"
#define GL_BGRA 0x80E1
#endif
+#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
+#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
+#endif
QT_BEGIN_NAMESPACE
@@ -97,10 +100,12 @@ inline static bool isPowerOfTwo(int x)
QSGTexturePrivate::QSGTexturePrivate()
: wrapChanged(false)
, filteringChanged(false)
+ , anisotropyChanged(false)
, horizontalWrap(QSGTexture::ClampToEdge)
, verticalWrap(QSGTexture::ClampToEdge)
, mipmapMode(QSGTexture::None)
, filterMode(QSGTexture::Nearest)
+ , anisotropyLevel(QSGTexture::AnisotropyNone)
{
}
@@ -274,6 +279,23 @@ static void qt_debug_remove_texture(QSGTexture* texture)
*/
/*!
+ \enum QSGTexture::AnisotropyLevel
+
+ Specifies the anisotropic filtering level to be used when
+ the texture is not screen aligned.
+
+ \value AnisotropyNone No anisotropic filtering.
+
+ \value Anisotropy2x 2x anisotropic filtering.
+
+ \value Anisotropy4x 4x anisotropic filtering.
+
+ \value Anisotropy8x 8x anisotropic filtering.
+
+ \value Anisotropy16x 16x anisotropic filtering.
+*/
+
+/*!
\fn QSGTexture::QSGTexture(QSGTexturePrivate &dd)
\internal
*/
@@ -472,6 +494,31 @@ QSGTexture::Filtering QSGTexture::filtering() const
return (QSGTexture::Filtering) d_func()->filterMode;
}
+/*!
+ Sets the level of anisotropic filtering to be used for the upcoming bind() call to \a level.
+ The default value is QSGTexture::AnisotropyNone, which means no anisotropic filtering is enabled.
+
+ \since 5.9
+ */
+void QSGTexture::setAnisotropyLevel(AnisotropyLevel level)
+{
+ Q_D(QSGTexture);
+ if (d->anisotropyLevel != (uint) level) {
+ d->anisotropyLevel = level;
+ d->anisotropyChanged = true;
+ }
+}
+
+/*!
+ Returns the anisotropy level in use for filtering this texture.
+
+ \since 5.9
+ */
+QSGTexture::AnisotropyLevel QSGTexture::anisotropyLevel() const
+{
+ return (QSGTexture::AnisotropyLevel) d_func()->anisotropyLevel;
+}
+
/*!
@@ -548,6 +595,12 @@ void QSGTexture::updateBindOptions(bool force)
d->filteringChanged = false;
}
+ if (force || d->anisotropyChanged) {
+ d->anisotropyChanged = false;
+ if (QOpenGLContext::currentContext()->hasExtension(QByteArrayLiteral("GL_EXT_texture_filter_anisotropic")))
+ funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, float(1 << (d->anisotropyLevel)));
+ }
+
if (force || d->wrapChanged) {
#ifndef QT_NO_DEBUG
if (d->horizontalWrap == Repeat || d->verticalWrap == Repeat) {
diff --git a/src/quick/scenegraph/util/qsgtexture.h b/src/quick/scenegraph/util/qsgtexture.h
index f0509b58ae..035acc02b1 100644
--- a/src/quick/scenegraph/util/qsgtexture.h
+++ b/src/quick/scenegraph/util/qsgtexture.h
@@ -67,6 +67,14 @@ public:
Linear
};
+ enum AnisotropyLevel {
+ AnisotropyNone,
+ Anisotropy2x,
+ Anisotropy4x,
+ Anisotropy8x,
+ Anisotropy16x
+ };
+
virtual int textureId() const = 0;
virtual QSize textureSize() const = 0;
virtual bool hasAlphaChannel() const = 0;
@@ -87,6 +95,9 @@ public:
void setFiltering(Filtering filter);
QSGTexture::Filtering filtering() const;
+ void setAnisotropyLevel(AnisotropyLevel level);
+ QSGTexture::AnisotropyLevel anisotropyLevel() const;
+
void setHorizontalWrapMode(WrapMode hwrap);
QSGTexture::WrapMode horizontalWrapMode() const;
diff --git a/src/quick/scenegraph/util/qsgtexture_p.h b/src/quick/scenegraph/util/qsgtexture_p.h
index 13c862eb88..36f9b802ba 100644
--- a/src/quick/scenegraph/util/qsgtexture_p.h
+++ b/src/quick/scenegraph/util/qsgtexture_p.h
@@ -69,11 +69,13 @@ public:
uint wrapChanged : 1;
uint filteringChanged : 1;
+ uint anisotropyChanged : 1;
uint horizontalWrap : 1;
uint verticalWrap : 1;
uint mipmapMode : 2;
uint filterMode : 2;
+ uint anisotropyLevel: 3;
};
class Q_QUICK_PRIVATE_EXPORT QSGPlainTexture : public QSGTexture
@@ -87,19 +89,19 @@ public:
bool ownsTexture() const { return m_owns_texture; }
void setTextureId(int id);
- int textureId() const;
+ int textureId() const override;
void setTextureSize(const QSize &size) { m_texture_size = size; }
- QSize textureSize() const { return m_texture_size; }
+ QSize textureSize() const override { return m_texture_size; }
void setHasAlphaChannel(bool alpha) { m_has_alpha = alpha; }
- bool hasAlphaChannel() const { return m_has_alpha; }
+ bool hasAlphaChannel() const override { return m_has_alpha; }
- bool hasMipmaps() const { return mipmapFiltering() != QSGTexture::None; }
+ bool hasMipmaps() const override { return mipmapFiltering() != QSGTexture::None; }
void setImage(const QImage &image);
const QImage &image() { return m_image; }
- virtual void bind();
+ void bind() override;
static QSGPlainTexture *fromImage(const QImage &image) {
QSGPlainTexture *t = new QSGPlainTexture();
diff --git a/src/quick/scenegraph/util/qsgtexturematerial.cpp b/src/quick/scenegraph/util/qsgtexturematerial.cpp
index 9326ea640d..c536445e82 100644
--- a/src/quick/scenegraph/util/qsgtexturematerial.cpp
+++ b/src/quick/scenegraph/util/qsgtexturematerial.cpp
@@ -110,6 +110,7 @@ void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMa
Q_UNUSED(state)
#endif
t->setMipmapFiltering(tx->mipmapFiltering());
+ t->setAnisotropyLevel(tx->anisotropyLevel());
if (oldTx == 0 || oldTx->texture()->textureId() != t->textureId())
t->bind();
@@ -173,6 +174,7 @@ QSGOpaqueTextureMaterial::QSGOpaqueTextureMaterial()
, m_mipmap_filtering(QSGTexture::None)
, m_horizontal_wrap(QSGTexture::ClampToEdge)
, m_vertical_wrap(QSGTexture::ClampToEdge)
+ , m_anisotropy_level(QSGTexture::AnisotropyNone)
{
}
diff --git a/src/quick/scenegraph/util/qsgtexturematerial.h b/src/quick/scenegraph/util/qsgtexturematerial.h
index 02b59108b3..87d8e5fd49 100644
--- a/src/quick/scenegraph/util/qsgtexturematerial.h
+++ b/src/quick/scenegraph/util/qsgtexturematerial.h
@@ -50,9 +50,9 @@ class Q_QUICK_EXPORT QSGOpaqueTextureMaterial : public QSGMaterial
public:
QSGOpaqueTextureMaterial();
- virtual QSGMaterialType *type() const;
- virtual QSGMaterialShader *createShader() const;
- virtual int compare(const QSGMaterial *other) const;
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
+ int compare(const QSGMaterial *other) const override;
void setTexture(QSGTexture *texture);
QSGTexture *texture() const { return m_texture; }
@@ -69,6 +69,9 @@ public:
void setVerticalWrapMode(QSGTexture::WrapMode mode) { m_vertical_wrap = mode; }
QSGTexture::WrapMode verticalWrapMode() const { return QSGTexture::WrapMode(m_vertical_wrap); }
+ void setAnisotropyLevel(QSGTexture::AnisotropyLevel level) { m_anisotropy_level = level; }
+ QSGTexture::AnisotropyLevel anisotropyLevel() const { return QSGTexture::AnisotropyLevel(m_anisotropy_level); }
+
protected:
QSGTexture *m_texture;
@@ -76,16 +79,16 @@ protected:
uint m_mipmap_filtering: 2;
uint m_horizontal_wrap : 1;
uint m_vertical_wrap: 1;
-
- uint m_reserved : 26;
+ uint m_anisotropy_level : 3;
+ uint m_reserved : 23;
};
class Q_QUICK_EXPORT QSGTextureMaterial : public QSGOpaqueTextureMaterial
{
public:
- virtual QSGMaterialType *type() const;
- virtual QSGMaterialShader *createShader() const;
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
};
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgtexturematerial_p.h b/src/quick/scenegraph/util/qsgtexturematerial_p.h
index 75e5877a72..093d820801 100644
--- a/src/quick/scenegraph/util/qsgtexturematerial_p.h
+++ b/src/quick/scenegraph/util/qsgtexturematerial_p.h
@@ -61,13 +61,13 @@ class Q_QUICK_PRIVATE_EXPORT QSGOpaqueTextureMaterialShader : public QSGMaterial
public:
QSGOpaqueTextureMaterialShader();
- virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect);
- virtual char const *const *attributeNames() const;
+ void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;
+ char const *const *attributeNames() const override;
static QSGMaterialType type;
protected:
- virtual void initialize();
+ void initialize() override;
int m_matrix_id;
};
@@ -77,8 +77,8 @@ class QSGTextureMaterialShader : public QSGOpaqueTextureMaterialShader
public:
QSGTextureMaterialShader();
- virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect);
- virtual void initialize();
+ void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;
+ void initialize() override;
static QSGMaterialType type;
diff --git a/src/quick/scenegraph/util/qsgvertexcolormaterial.h b/src/quick/scenegraph/util/qsgvertexcolormaterial.h
index 68f32d8af0..65cb642d92 100644
--- a/src/quick/scenegraph/util/qsgvertexcolormaterial.h
+++ b/src/quick/scenegraph/util/qsgvertexcolormaterial.h
@@ -49,11 +49,11 @@ class Q_QUICK_EXPORT QSGVertexColorMaterial : public QSGMaterial
public:
QSGVertexColorMaterial();
- int compare(const QSGMaterial *other) const;
+ int compare(const QSGMaterial *other) const override;
protected:
- virtual QSGMaterialType *type() const;
- virtual QSGMaterialShader *createShader() const;
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
};
QT_END_NAMESPACE
diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp
index 206b92eb81..1a2441171d 100644
--- a/src/quick/util/qquickanimation.cpp
+++ b/src/quick/util/qquickanimation.cpp
@@ -192,14 +192,14 @@ QQmlProperty QQuickAbstractAnimationPrivate::createProperty(QObject *obj, const
if (errorMessage)
*errorMessage = message;
else
- qmlInfo(infoObj) << message;
+ qmlWarning(infoObj) << message;
return QQmlProperty();
} else if (!prop.isWritable()) {
const QString message = QQuickAbstractAnimation::tr("Cannot animate read-only property \"%1\"").arg(str);
if (errorMessage)
*errorMessage = message;
else
- qmlInfo(infoObj) << message;
+ qmlWarning(infoObj) << message;
return QQmlProperty();
}
return prop;
@@ -256,7 +256,7 @@ void QQuickAbstractAnimation::setRunning(bool r)
return;
if (d->group || d->disableUserControl) {
- qmlInfo(this) << "setRunning() cannot be used on non-root animation nodes.";
+ qmlWarning(this) << "setRunning() cannot be used on non-root animation nodes.";
return;
}
@@ -322,12 +322,12 @@ void QQuickAbstractAnimation::setPaused(bool p)
return;
if (!d->running) {
- qmlInfo(this) << "setPaused() cannot be used when animation isn't running.";
+ qmlWarning(this) << "setPaused() cannot be used when animation isn't running.";
return;
}
if (d->group || d->disableUserControl) {
- qmlInfo(this) << "setPaused() cannot be used on non-root animation nodes.";
+ qmlWarning(this) << "setPaused() cannot be used on non-root animation nodes.";
return;
}
@@ -709,7 +709,7 @@ int QQuickPauseAnimation::duration() const
void QQuickPauseAnimation::setDuration(int duration)
{
if (duration < 0) {
- qmlInfo(this) << tr("Cannot set a duration of < 0");
+ qmlWarning(this) << tr("Cannot set a duration of < 0");
return;
}
@@ -1004,7 +1004,7 @@ void QQuickScriptActionPrivate::execute()
QQmlExpression expr(scriptStr);
expr.evaluate();
if (expr.hasError())
- qmlInfo(q) << expr.error();
+ qmlWarning(q) << expr.error();
}
}
@@ -1198,14 +1198,14 @@ QAbstractAnimationJob* QQuickPropertyAction::transition(QQuickStateActions &acti
struct QQuickSetPropertyAnimationAction : public QAbstractAnimationAction
{
QQuickStateActions actions;
- virtual void doAction()
+ void doAction() override
{
for (int ii = 0; ii < actions.count(); ++ii) {
const QQuickStateAction &action = actions.at(ii);
QQmlPropertyPrivate::write(action.property, action.toValue, QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
}
}
- virtual void debugAction(QDebug d, int indentLevel) const {
+ void debugAction(QDebug d, int indentLevel) const override {
QByteArray ind(indentLevel, ' ');
for (int ii = 0; ii < actions.count(); ++ii) {
const QQuickStateAction &action = actions.at(ii);
@@ -2077,7 +2077,7 @@ int QQuickPropertyAnimation::duration() const
void QQuickPropertyAnimation::setDuration(int duration)
{
if (duration < 0) {
- qmlInfo(this) << tr("Cannot set a duration of < 0");
+ qmlWarning(this) << tr("Cannot set a duration of < 0");
return;
}
@@ -2644,7 +2644,7 @@ QQuickStateActions QQuickPropertyAnimation::createTransitionActions(QQuickStateA
if (!successfullyCreatedDefaultProperty) {
for (const QString &errorMessage : qAsConst(errorMessages))
- qmlInfo(this) << errorMessage;
+ qmlWarning(this) << errorMessage;
}
}
diff --git a/src/quick/util/qquickanimation_p.h b/src/quick/util/qquickanimation_p.h
index 145f2656d2..e27871dcaa 100644
--- a/src/quick/util/qquickanimation_p.h
+++ b/src/quick/util/qquickanimation_p.h
@@ -114,8 +114,8 @@ public:
void setDisableUserControl();
void setEnableUserControl();
bool userControlDisabled() const;
- void classBegin();
- void componentComplete();
+ void classBegin() override;
+ void componentComplete() override;
virtual ThreadingModel threadingModel() const;
@@ -150,7 +150,7 @@ public:
private Q_SLOTS:
void componentFinalized();
private:
- virtual void setTarget(const QQmlProperty &);
+ void setTarget(const QQmlProperty &) override;
void notifyRunningChanged(bool running);
friend class QQuickBehavior;
friend class QQuickBehaviorPrivate;
@@ -179,7 +179,7 @@ protected:
QAbstractAnimationJob* transition(QQuickStateActions &actions,
QQmlProperties &modified,
TransitionDirection direction,
- QObject *defaultTarget = 0);
+ QObject *defaultTarget = 0) override;
};
class QQuickScriptActionPrivate;
@@ -202,10 +202,10 @@ public:
void setStateChangeScriptName(const QString &);
protected:
- virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
+ QAbstractAnimationJob* transition(QQuickStateActions &actions,
QQmlProperties &modified,
TransitionDirection direction,
- QObject *defaultTarget = 0);
+ QObject *defaultTarget = 0) override;
};
class QQuickPropertyActionPrivate;
@@ -247,10 +247,10 @@ Q_SIGNALS:
void propertyChanged();
protected:
- virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
+ QAbstractAnimationJob* transition(QQuickStateActions &actions,
QQmlProperties &modified,
TransitionDirection direction,
- QObject *defaultTarget = 0);
+ QObject *defaultTarget = 0) override;
};
class QQuickPropertyAnimationPrivate;
@@ -303,10 +303,10 @@ protected:
QObject *defaultTarget = 0);
QQuickPropertyAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent);
- virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
+ QAbstractAnimationJob* transition(QQuickStateActions &actions,
QQmlProperties &modified,
TransitionDirection direction,
- QObject *defaultTarget = 0);
+ QObject *defaultTarget = 0) override;
Q_SIGNALS:
void durationChanged(int);
void fromChanged(const QVariant &);
@@ -438,11 +438,11 @@ public:
virtual ~QQuickSequentialAnimation();
protected:
- virtual ThreadingModel threadingModel() const;
- virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
+ ThreadingModel threadingModel() const override;
+ QAbstractAnimationJob* transition(QQuickStateActions &actions,
QQmlProperties &modified,
TransitionDirection direction,
- QObject *defaultTarget = 0);
+ QObject *defaultTarget = 0) override;
};
class Q_QUICK_PRIVATE_EXPORT QQuickParallelAnimation : public QQuickAnimationGroup
@@ -455,11 +455,11 @@ public:
virtual ~QQuickParallelAnimation();
protected:
- virtual ThreadingModel threadingModel() const;
- virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
+ ThreadingModel threadingModel() const override;
+ QAbstractAnimationJob* transition(QQuickStateActions &actions,
QQmlProperties &modified,
TransitionDirection direction,
- QObject *defaultTarget = 0);
+ QObject *defaultTarget = 0) override;
};
diff --git a/src/quick/util/qquickanimation_p_p.h b/src/quick/util/qquickanimation_p_p.h
index ea7bf62171..a7abc5a004 100644
--- a/src/quick/util/qquickanimation_p_p.h
+++ b/src/quick/util/qquickanimation_p_p.h
@@ -88,8 +88,8 @@ class QAnimationActionProxy : public QAbstractAnimationAction
{
public:
QAnimationActionProxy(T *instance) : m_instance(instance) {}
- virtual void doAction() { (m_instance->*method)(); }
- virtual void debugAction(QDebug d, int indentLevel) const { (m_instance->*debugMethod)(d, indentLevel); }
+ void doAction() override { (m_instance->*method)(); }
+ void debugAction(QDebug d, int indentLevel) const override { (m_instance->*debugMethod)(d, indentLevel); }
private:
T *m_instance;
};
@@ -104,13 +104,13 @@ public:
QActionAnimation(QAbstractAnimationAction *action);
~QActionAnimation();
- virtual int duration() const;
+ int duration() const override;
void setAnimAction(QAbstractAnimationAction *action);
protected:
- virtual void updateCurrentTime(int);
- virtual void updateState(State newState, State oldState);
- void debugAnimation(QDebug d) const;
+ void updateCurrentTime(int) override;
+ void updateState(State newState, State oldState) override;
+ void debugAnimation(QDebug d) const override;
private:
QAbstractAnimationAction *animAction;
@@ -137,16 +137,16 @@ public:
void setFromSourcedValue(bool *value) { fromSourced = value; }
- int duration() const { return m_duration; }
+ int duration() const override { return m_duration; }
void setDuration(int msecs) { m_duration = msecs; }
QEasingCurve easingCurve() const { return easing; }
void setEasingCurve(const QEasingCurve &curve) { easing = curve; }
protected:
- void updateCurrentTime(int currentTime);
- void topLevelAnimationLoopChanged();
- void debugAnimation(QDebug d) const;
+ void updateCurrentTime(int currentTime) override;
+ void topLevelAnimationLoopChanged() override;
+ void debugAnimation(QDebug d) const override;
private:
QQuickBulkValueUpdater *animValue;
@@ -162,9 +162,9 @@ class QTickAnimationProxy : public QAbstractAnimationJob
Q_DISABLE_COPY(QTickAnimationProxy)
public:
QTickAnimationProxy(T *instance) : QAbstractAnimationJob(), m_instance(instance) {}
- virtual int duration() const { return -1; }
+ int duration() const override { return -1; }
protected:
- virtual void updateCurrentTime(int msec) { (m_instance->*method)(msec); }
+ void updateCurrentTime(int msec) override { (m_instance->*method)(msec); }
private:
T *m_instance;
@@ -192,7 +192,7 @@ public:
int loopCount;
void commence();
- virtual void animationFinished(QAbstractAnimationJob *);
+ void animationFinished(QAbstractAnimationJob *) override;
QQmlProperty defaultProperty;
@@ -309,9 +309,9 @@ public:
QQuickAnimationPropertyUpdater() : interpolatorType(0), interpolator(0), prevInterpolatorType(0), reverse(false), fromSourced(false), fromDefined(false), wasDeleted(0) {}
~QQuickAnimationPropertyUpdater();
- void setValue(qreal v);
+ void setValue(qreal v) override;
- void debugUpdater(QDebug d, int indentLevel) const;
+ void debugUpdater(QDebug d, int indentLevel) const override;
QQuickStateActions actions;
int interpolatorType; //for Number/ColorAnimation
diff --git a/src/quick/util/qquickanimationcontroller.cpp b/src/quick/util/qquickanimationcontroller.cpp
index 8b6968ad98..fa1ade50d1 100644
--- a/src/quick/util/qquickanimationcontroller.cpp
+++ b/src/quick/util/qquickanimationcontroller.cpp
@@ -50,8 +50,8 @@ class QQuickAnimationControllerPrivate : public QObjectPrivate, QAnimationJobCha
public:
QQuickAnimationControllerPrivate()
: progress(0.0), animation(0), animationInstance(0), finalized(false) {}
- virtual void animationFinished(QAbstractAnimationJob *job);
- virtual void animationCurrentTimeChanged(QAbstractAnimationJob *job, int currentTime);
+ void animationFinished(QAbstractAnimationJob *job) override;
+ void animationCurrentTimeChanged(QAbstractAnimationJob *job, int currentTime) override;
qreal progress;
@@ -169,7 +169,7 @@ void QQuickAnimationController::setAnimation(QQuickAbstractAnimation *animation)
if (animation != d->animation) {
if (animation) {
if (animation->userControlDisabled()) {
- qmlInfo(this) << "QQuickAnimationController::setAnimation: the animation is controlled by others, can't be used in AnimationController.";
+ qmlWarning(this) << "QQuickAnimationController::setAnimation: the animation is controlled by others, can't be used in AnimationController.";
return;
}
animation->setDisableUserControl();
diff --git a/src/quick/util/qquickanimationcontroller_p.h b/src/quick/util/qquickanimationcontroller_p.h
index e37bb90a0a..43555ac1c1 100644
--- a/src/quick/util/qquickanimationcontroller_p.h
+++ b/src/quick/util/qquickanimationcontroller_p.h
@@ -78,8 +78,8 @@ public:
QQuickAbstractAnimation *animation() const;
void setAnimation(QQuickAbstractAnimation *animation);
- void classBegin();
- void componentComplete() {}
+ void classBegin() override;
+ void componentComplete() override {}
Q_SIGNALS:
void progressChanged();
void animationChanged();
diff --git a/src/quick/util/qquickanimator_p.h b/src/quick/util/qquickanimator_p.h
index 0fc900c5ac..92c66299dc 100644
--- a/src/quick/util/qquickanimator_p.h
+++ b/src/quick/util/qquickanimator_p.h
@@ -86,13 +86,13 @@ public:
void setFrom(qreal from);
protected:
- ThreadingModel threadingModel() const { return RenderThread; }
+ ThreadingModel threadingModel() const override { return RenderThread; }
virtual QQuickAnimatorJob *createJob() const = 0;
virtual QString propertyName() const = 0;
QAbstractAnimationJob *transition(QQuickStateActions &actions,
QQmlProperties &modified,
TransitionDirection,
- QObject *);
+ QObject *) override;
QQuickAnimator(QQuickAnimatorPrivate &dd, QObject *parent = 0);
QQuickAnimator(QObject *parent = 0);
@@ -112,8 +112,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickScaleAnimator : public QQuickAnimator
public:
QQuickScaleAnimator(QObject *parent = 0);
protected:
- QQuickAnimatorJob *createJob() const;
- QString propertyName() const { return QStringLiteral("scale"); }
+ QQuickAnimatorJob *createJob() const override;
+ QString propertyName() const override { return QStringLiteral("scale"); }
};
class Q_QUICK_PRIVATE_EXPORT QQuickXAnimator : public QQuickAnimator
@@ -122,8 +122,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickXAnimator : public QQuickAnimator
public:
QQuickXAnimator(QObject *parent = 0);
protected:
- QQuickAnimatorJob *createJob() const;
- QString propertyName() const{ return QStringLiteral("x"); }
+ QQuickAnimatorJob *createJob() const override;
+ QString propertyName() const override { return QStringLiteral("x"); }
};
class Q_QUICK_PRIVATE_EXPORT QQuickYAnimator : public QQuickAnimator
@@ -132,8 +132,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickYAnimator : public QQuickAnimator
public:
QQuickYAnimator(QObject *parent = 0);
protected:
- QQuickAnimatorJob *createJob() const;
- QString propertyName() const { return QStringLiteral("y"); }
+ QQuickAnimatorJob *createJob() const override;
+ QString propertyName() const override { return QStringLiteral("y"); }
};
class Q_QUICK_PRIVATE_EXPORT QQuickOpacityAnimator : public QQuickAnimator
@@ -142,8 +142,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickOpacityAnimator : public QQuickAnimator
public:
QQuickOpacityAnimator(QObject *parent = 0);
protected:
- QQuickAnimatorJob *createJob() const;
- QString propertyName() const { return QStringLiteral("opacity"); }
+ QQuickAnimatorJob *createJob() const override;
+ QString propertyName() const override { return QStringLiteral("opacity"); }
};
class QQuickRotationAnimatorPrivate;
@@ -166,8 +166,8 @@ Q_SIGNALS:
void directionChanged(RotationDirection dir);
protected:
- QQuickAnimatorJob *createJob() const;
- QString propertyName() const { return QStringLiteral("rotation"); }
+ QQuickAnimatorJob *createJob() const override;
+ QString propertyName() const override { return QStringLiteral("rotation"); }
};
#if QT_CONFIG(quick_shadereffect) && QT_CONFIG(opengl)
@@ -188,8 +188,8 @@ Q_SIGNALS:
void uniformChanged(const QString &);
protected:
- QQuickAnimatorJob *createJob() const;
- QString propertyName() const;
+ QQuickAnimatorJob *createJob() const override;
+ QString propertyName() const override;
};
#endif
diff --git a/src/quick/util/qquickanimatorcontroller.cpp b/src/quick/util/qquickanimatorcontroller.cpp
index 6d8167413e..2f96c511c0 100644
--- a/src/quick/util/qquickanimatorcontroller.cpp
+++ b/src/quick/util/qquickanimatorcontroller.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Gunnar Sletta <gunnar@sletta.org>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -50,228 +51,116 @@
QT_BEGIN_NAMESPACE
-QQuickAnimatorController::QQuickAnimatorController(QQuickWindow *window)
- : m_window(window)
- , m_nodesAreInvalid(false)
-{
- m_guiEntity = new QQuickAnimatorControllerGuiThreadEntity();
- m_guiEntity->controller = this;
- connect(window, SIGNAL(frameSwapped()), m_guiEntity, SLOT(frameSwapped()));
-}
-
-void QQuickAnimatorControllerGuiThreadEntity::frameSwapped()
+QQuickAnimatorController::~QQuickAnimatorController()
{
- if (!controller.isNull())
- controller->stopProxyJobs();
}
-QQuickAnimatorController::~QQuickAnimatorController()
+QQuickAnimatorController::QQuickAnimatorController(QQuickWindow *window)
+ : m_window(window)
{
- // The proxy job might already have been deleted, in which case we
- // need to avoid calling functions on them. Then delete the job.
- for (QAbstractAnimationJob *job : qAsConst(m_deleting)) {
- m_starting.take(job);
- m_stopping.take(job);
- m_animatorRoots.take(job);
- delete job;
- }
-
- for (QQuickAnimatorProxyJob *proxy : qAsConst(m_animatorRoots))
- proxy->controllerWasDeleted();
- for (auto it = m_animatorRoots.keyBegin(), end = m_animatorRoots.keyEnd(); it != end; ++it)
- delete *it;
-
- // Delete those who have been started, stopped and are now still
- // pending for restart.
- for (auto it = m_starting.keyBegin(), end = m_starting.keyEnd(); it != end; ++it) {
- QAbstractAnimationJob *job = *it;
- if (!m_animatorRoots.contains(job))
- delete job;
- }
-
- delete m_guiEntity;
}
-static void qquickanimator_invalidate_node(QAbstractAnimationJob *job)
+static void qquickanimator_invalidate_jobs(QAbstractAnimationJob *job)
{
if (job->isRenderThreadJob()) {
- static_cast<QQuickAnimatorJob *>(job)->nodeWasDestroyed();
+ static_cast<QQuickAnimatorJob *>(job)->invalidate();
} else if (job->isGroup()) {
QAnimationGroupJob *g = static_cast<QAnimationGroupJob *>(job);
for (QAbstractAnimationJob *a = g->firstChild(); a; a = a->nextSibling())
- qquickanimator_invalidate_node(a);
+ qquickanimator_invalidate_jobs(a);
}
}
void QQuickAnimatorController::windowNodesDestroyed()
{
- m_nodesAreInvalid = true;
- for (QHash<QAbstractAnimationJob *, QQuickAnimatorProxyJob *>::const_iterator it = m_animatorRoots.constBegin();
- it != m_animatorRoots.constEnd(); ++it) {
- qquickanimator_invalidate_node(it.key());
+ for (const QSharedPointer<QAbstractAnimationJob> &toStop : qAsConst(m_rootsPendingStop)) {
+ qquickanimator_invalidate_jobs(toStop.data());
+ toStop->stop();
}
-}
+ m_rootsPendingStop.clear();
-void QQuickAnimatorController::itemDestroyed(QObject *o)
-{
- m_deletedSinceLastFrame << (QQuickItem *) o;
+ // Clear animation roots and iterate over a temporary to avoid that job->stop()
+ // modifies the m_animationRoots and messes with our iteration
+ const auto roots = m_animationRoots;
+ m_animationRoots.clear();
+ for (const QSharedPointer<QAbstractAnimationJob> &job : roots) {
+ qquickanimator_invalidate_jobs(job.data());
+
+ // Stop it and add it to the list of pending start so it might get
+ // started later on.
+ job->stop();
+ m_rootsPendingStart.insert(job);
+ }
}
void QQuickAnimatorController::advance()
{
bool running = false;
- for (QHash<QAbstractAnimationJob *, QQuickAnimatorProxyJob *>::const_iterator it = m_animatorRoots.constBegin();
- !running && it != m_animatorRoots.constEnd(); ++it) {
- if (it.key()->isRunning())
+ for (const QSharedPointer<QAbstractAnimationJob> &job : qAsConst(m_animationRoots)) {
+ if (job->isRunning()) {
running = true;
+ break;
+ }
}
- // It was tempting to only run over the active animations, but we need to push
- // the values for the transforms that finished in the last frame and those will
- // have been removed already...
- lock();
- for (QHash<QQuickItem *, QQuickTransformAnimatorJob::Helper *>::const_iterator it = m_transforms.constBegin();
- it != m_transforms.constEnd(); ++it) {
- QQuickTransformAnimatorJob::Helper *xform = *it;
- // Set to zero when the item was deleted in beforeNodeSync().
- if (!xform->item)
- continue;
- (*it)->apply();
- }
- unlock();
+ for (QQuickAnimatorJob *job : qAsConst(m_runningAnimators))
+ job->commit();
if (running)
m_window->update();
}
-static void qquick_initialize_helper(QAbstractAnimationJob *job, QQuickAnimatorController *c, bool attachListener)
+static void qquickanimator_sync_before_start(QAbstractAnimationJob *job)
{
if (job->isRenderThreadJob()) {
- QQuickAnimatorJob *j = static_cast<QQuickAnimatorJob *>(job);
- // Note: since a QQuickAnimatorJob::m_target is a QPointer,
- // if m_target is destroyed between the time it was set
- // as the target of the animator job and before this step,
- // (e.g a Loader being set inactive just after starting the animator)
- // we are sure it will be NULL and won't be dangling around
- if (!j->target()) {
- return;
- } else if (c->m_deletedSinceLastFrame.contains(j->target())) {
- j->targetWasDeleted();
- } else {
- if (attachListener)
- j->addAnimationChangeListener(c, QAbstractAnimationJob::StateChange);
- j->initialize(c);
- }
+ static_cast<QQuickAnimatorJob *>(job)->preSync();
} else if (job->isGroup()) {
QAnimationGroupJob *g = static_cast<QAnimationGroupJob *>(job);
for (QAbstractAnimationJob *a = g->firstChild(); a; a = a->nextSibling())
- qquick_initialize_helper(a, c, attachListener);
+ qquickanimator_sync_before_start(a);
}
}
void QQuickAnimatorController::beforeNodeSync()
{
- for (QAbstractAnimationJob *job : qAsConst(m_deleting)) {
- m_starting.take(job);
- m_stopping.take(job);
- m_animatorRoots.take(job);
- job->stop();
- delete job;
- }
- m_deleting.clear();
+ for (const QSharedPointer<QAbstractAnimationJob> &toStop : qAsConst(m_rootsPendingStop))
+ toStop->stop();
+ m_rootsPendingStop.clear();
- if (m_starting.size())
- m_window->update();
- for (QQuickAnimatorProxyJob *proxy : qAsConst(m_starting)) {
- QAbstractAnimationJob *job = proxy->job();
- job->addAnimationChangeListener(this, QAbstractAnimationJob::Completion);
- qquick_initialize_helper(job, this, true);
- m_animatorRoots[job] = proxy;
- job->start();
- proxy->startedByController();
- }
- m_starting.clear();
- for (QQuickAnimatorProxyJob *proxy : qAsConst(m_stopping)) {
- QAbstractAnimationJob *job = proxy->job();
- job->stop();
- }
- m_stopping.clear();
-
- // First sync after a window was hidden or otherwise invalidated.
- // call initialize again to pick up new nodes..
- if (m_nodesAreInvalid) {
- for (QHash<QAbstractAnimationJob *, QQuickAnimatorProxyJob *>::const_iterator it = m_animatorRoots.constBegin();
- it != m_animatorRoots.constEnd(); ++it) {
- qquick_initialize_helper(it.key(), this, false);
- }
- m_nodesAreInvalid = false;
- }
+ for (QQuickAnimatorJob *job : qAsConst(m_runningAnimators))
+ job->preSync();
- for (QQuickAnimatorJob *job : qAsConst(m_activeLeafAnimations)) {
- if (!job->target())
- continue;
- else if (m_deletedSinceLastFrame.contains(job->target()))
- job->targetWasDeleted();
- else if (job->isTransform()) {
- QQuickTransformAnimatorJob *xform = static_cast<QQuickTransformAnimatorJob *>(job);
- xform->transformHelper()->sync();
- }
- }
- for (QQuickItem *wiped : qAsConst(m_deletedSinceLastFrame)) {
- QQuickTransformAnimatorJob::Helper *helper = m_transforms.take(wiped);
- // Helper will now already have been reset in all animators referencing it.
- delete helper;
- }
+ // Start pending jobs
+ for (const QSharedPointer<QAbstractAnimationJob> &job : qAsConst(m_rootsPendingStart)) {
+ Q_ASSERT(!job->isRunning());
- m_deletedSinceLastFrame.clear();
-}
+ // We want to make sure that presync is called before
+ // updateAnimationTime is called the very first time, so before
+ // starting a tree of jobs, we go through it and call preSync on all
+ // its animators.
+ qquickanimator_sync_before_start(job.data());
-void QQuickAnimatorController::afterNodeSync()
-{
- for (QQuickAnimatorJob *job : qAsConst(m_activeLeafAnimations)) {
- if (job->target())
- job->afterNodeSync();
+ // The start the job..
+ job->start();
+ m_animationRoots.insert(job.data(), job);
}
-}
+ m_rootsPendingStart.clear();
-void QQuickAnimatorController::proxyWasDestroyed(QQuickAnimatorProxyJob *proxy)
-{
- lock();
- m_proxiesToStop.remove(proxy);
- unlock();
+ // Issue an update directly on the window to force another render pass.
+ if (m_animationRoots.size())
+ m_window->update();
}
-void QQuickAnimatorController::stopProxyJobs()
+void QQuickAnimatorController::afterNodeSync()
{
- // Need to make a copy under lock and then stop while unlocked.
- // Stopping triggers writeBack which in turn may lock, so it needs
- // to be outside the lock. It is also safe because deletion of
- // proxies happens on the GUI thread, where this code is also executing.
- lock();
- const QSet<QQuickAnimatorProxyJob *> jobs = m_proxiesToStop;
- m_proxiesToStop.clear();
- unlock();
- for (QQuickAnimatorProxyJob *p : jobs)
- p->stop();
+ for (QQuickAnimatorJob *job : qAsConst(m_runningAnimators))
+ job->postSync();
}
void QQuickAnimatorController::animationFinished(QAbstractAnimationJob *job)
{
- /* We are currently on the render thread and m_deleting is primarily
- * being written on the GUI Thread and read during sync. However, we don't
- * need to lock here as this is a direct result of animationDriver->advance()
- * which is already locked. For non-threaded render loops no locking is
- * needed in any case.
- */
- if (!m_deleting.contains(job)) {
- QQuickAnimatorProxyJob *proxy = m_animatorRoots.value(job);
- if (proxy) {
- m_window->update();
- m_proxiesToStop << proxy;
- }
- // else already gone...
- }
+ m_animationRoots.remove(job);
}
void QQuickAnimatorController::animationStateChanged(QAbstractAnimationJob *job,
@@ -281,43 +170,52 @@ void QQuickAnimatorController::animationStateChanged(QAbstractAnimationJob *job,
Q_ASSERT(job->isRenderThreadJob());
QQuickAnimatorJob *animator = static_cast<QQuickAnimatorJob *>(job);
if (newState == QAbstractAnimationJob::Running) {
- m_activeLeafAnimations << animator;
- animator->setHasBeenRunning(true);
+ m_runningAnimators.insert(animator);
} else if (oldState == QAbstractAnimationJob::Running) {
- m_activeLeafAnimations.remove(animator);
+ animator->commit();
+ m_runningAnimators.remove(animator);
}
}
-
void QQuickAnimatorController::requestSync()
{
// Force a "sync" pass as the newly started animation needs to sync properties from GUI.
m_window->maybeUpdate();
}
-// These functions are called on the GUI thread.
-void QQuickAnimatorController::startJob(QQuickAnimatorProxyJob *proxy, QAbstractAnimationJob *job)
+// All this is being executed on the GUI thread while the animator controller
+// is locked.
+void QQuickAnimatorController::start_helper(QAbstractAnimationJob *job)
{
- proxy->markJobManagedByController();
- m_starting[job] = proxy;
- m_stopping.remove(job);
- requestSync();
+ if (job->isRenderThreadJob()) {
+ QQuickAnimatorJob *j = static_cast<QQuickAnimatorJob *>(job);
+ j->addAnimationChangeListener(this, QAbstractAnimationJob::StateChange);
+ j->initialize(this);
+ } else if (job->isGroup()) {
+ QAnimationGroupJob *g = static_cast<QAnimationGroupJob *>(job);
+ for (QAbstractAnimationJob *a = g->firstChild(); a; a = a->nextSibling())
+ start_helper(a);
+ }
}
-void QQuickAnimatorController::stopJob(QQuickAnimatorProxyJob *proxy, QAbstractAnimationJob *job)
+// Called by the proxy when it is time to kick off an animation job
+void QQuickAnimatorController::start(const QSharedPointer<QAbstractAnimationJob> &job)
{
- m_stopping[job] = proxy;
- m_starting.remove(job);
+ m_rootsPendingStart.insert(job);
+ m_rootsPendingStop.remove(job);
+ job->addAnimationChangeListener(this, QAbstractAnimationJob::Completion);
+ start_helper(job.data());
requestSync();
}
-void QQuickAnimatorController::deleteJob(QAbstractAnimationJob *job)
+
+// Called by the proxy when it is time to stop an animation job.
+void QQuickAnimatorController::cancel(const QSharedPointer<QAbstractAnimationJob> &job)
{
- lock();
- m_deleting << job;
- requestSync();
- unlock();
+ m_rootsPendingStart.remove(job);
+ m_rootsPendingStop.insert(job);
}
+
QT_END_NAMESPACE
diff --git a/src/quick/util/qquickanimatorcontroller_p.h b/src/quick/util/qquickanimatorcontroller_p.h
index 0a9902cc30..428a6700d4 100644
--- a/src/quick/util/qquickanimatorcontroller_p.h
+++ b/src/quick/util/qquickanimatorcontroller_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Gunnar Sletta <gunnar@sletta.org>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -60,8 +61,6 @@
QT_BEGIN_NAMESPACE
-class QQuickAnimatorControllerGuiThreadEntity;
-
class QQuickAnimatorController : public QObject, public QAnimationJobChangeListener
{
Q_OBJECT
@@ -74,54 +73,37 @@ public:
void beforeNodeSync();
void afterNodeSync();
- void animationFinished(QAbstractAnimationJob *job);
- void animationStateChanged(QAbstractAnimationJob *job, QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState);
+ void animationFinished(QAbstractAnimationJob *job) override;
+ void animationStateChanged(QAbstractAnimationJob *job, QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) override;
void requestSync();
// These are called from the GUI thread (the proxy)
- void startJob(QQuickAnimatorProxyJob *proxy, QAbstractAnimationJob *job);
- void stopJob(QQuickAnimatorProxyJob *proxy, QAbstractAnimationJob *job);
- void deleteJob(QAbstractAnimationJob *job);
+ void start(const QSharedPointer<QAbstractAnimationJob> &job);
+ void cancel(const QSharedPointer<QAbstractAnimationJob> &job);
+ bool isPendingStart(const QSharedPointer<QAbstractAnimationJob> &job) const { return m_rootsPendingStart.contains(job); }
void lock() { m_mutex.lock(); }
void unlock() { m_mutex.unlock(); }
-
void proxyWasDestroyed(QQuickAnimatorProxyJob *proxy);
void stopProxyJobs();
void windowNodesDestroyed();
-public Q_SLOTS:
- void itemDestroyed(QObject *);
+ QQuickWindow *window() const { return m_window; }
-public:
- // These are manipulated from the GUI thread and should only
- // be updated during the sync() phase.
- QHash<QAbstractAnimationJob *, QQuickAnimatorProxyJob *> m_starting;
- QHash<QAbstractAnimationJob *, QQuickAnimatorProxyJob *> m_stopping;
- QSet<QAbstractAnimationJob *> m_deleting;
-
- QHash<QAbstractAnimationJob *, QQuickAnimatorProxyJob *> m_animatorRoots;
- QSet<QQuickAnimatorJob *> m_activeLeafAnimations;
- QHash<QQuickItem *, QQuickTransformAnimatorJob::Helper *> m_transforms;
- QSet<QQuickItem *> m_deletedSinceLastFrame;
- QQuickWindow *m_window;
- QQuickAnimatorControllerGuiThreadEntity *m_guiEntity;
- QSet<QQuickAnimatorProxyJob *> m_proxiesToStop;
- QMutex m_mutex;
+private:
+ void start_helper(QAbstractAnimationJob *job);
+ void cancel_helper(QAbstractAnimationJob *job);
- bool m_nodesAreInvalid;
-};
-
-class QQuickAnimatorControllerGuiThreadEntity : public QObject
-{
- Q_OBJECT
public:
- QPointer<QQuickAnimatorController> controller;
+ QSet<QQuickAnimatorJob * > m_runningAnimators;
+ QHash<QAbstractAnimationJob *, QSharedPointer<QAbstractAnimationJob> > m_animationRoots;
+ QSet<QSharedPointer<QAbstractAnimationJob> > m_rootsPendingStop;
+ QSet<QSharedPointer<QAbstractAnimationJob> > m_rootsPendingStart;
-public Q_SLOTS:
- void frameSwapped();
+ QQuickWindow *m_window;
+ QMutex m_mutex;
};
diff --git a/src/quick/util/qquickanimatorjob.cpp b/src/quick/util/qquickanimatorjob.cpp
index 33569c4784..4aacb09c97 100644
--- a/src/quick/util/qquickanimatorjob.cpp
+++ b/src/quick/util/qquickanimatorjob.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Gunnar Sletta <gunnar@sletta.org>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -55,12 +56,42 @@
QT_BEGIN_NAMESPACE
+struct QQuickTransformAnimatorHelperStore
+{
+ QHash<QQuickItem *, QQuickTransformAnimatorJob::Helper *> store;
+ QMutex mutex;
+
+ QQuickTransformAnimatorJob::Helper *acquire(QQuickItem *item) {
+ mutex.lock();
+ QQuickTransformAnimatorJob::Helper *helper = store.value(item);
+ if (!helper) {
+ helper = new QQuickTransformAnimatorJob::Helper();
+ helper->item = item;
+ store[item] = helper;
+ } else {
+ ++helper->ref;
+ }
+ mutex.unlock();
+ return helper;
+ }
+
+ void release(QQuickTransformAnimatorJob::Helper *helper) {
+ mutex.lock();
+ if (--helper->ref == 0) {
+ store.remove(helper->item);
+ delete helper;
+ }
+ mutex.unlock();
+ }
+};
+Q_GLOBAL_STATIC(QQuickTransformAnimatorHelperStore, qquick_transform_animatorjob_helper_store);
+
QQuickAnimatorProxyJob::QQuickAnimatorProxyJob(QAbstractAnimationJob *job, QObject *item)
- : m_controller(0)
- , m_job(job)
+ : m_controller(nullptr)
, m_internalState(State_Stopped)
- , m_jobManagedByController(false)
{
+ m_job.reset(job);
+
m_isRenderThreadProxy = true;
m_animation = qobject_cast<QQuickAbstractAnimation *>(item);
@@ -88,57 +119,58 @@ QQuickAnimatorProxyJob::QQuickAnimatorProxyJob(QAbstractAnimationJob *job, QObje
QQuickItem *item = qobject_cast<QQuickItem *>(ctx);
if (item->window())
setWindow(item->window());
-
- qmlobject_connect(item, QQuickItem, SIGNAL(windowChanged(QQuickWindow*)), this, QQuickAnimatorProxyJob, SLOT(windowChanged(QQuickWindow*)));
+ connect(item, &QQuickItem::windowChanged, this, &QQuickAnimatorProxyJob::windowChanged);
}
}
QQuickAnimatorProxyJob::~QQuickAnimatorProxyJob()
{
- deleteJob();
- if (m_controller)
- m_controller->proxyWasDestroyed(this);
-}
-
-void QQuickAnimatorProxyJob::deleteJob()
-{
- if (m_job) {
- // If we have a controller, we might have posted the job to be started
- // so delete it through the controller to clean up properly.
- if (m_controller)
- m_controller->deleteJob(m_job);
-
- // We explicitly delete the job if the animator controller has never touched
- // it. If it has, it will have ownership as well.
- else if (!m_jobManagedByController)
- delete m_job;
- m_job = 0;
- }
+ if (m_job && m_controller)
+ m_controller->cancel(m_job);
+ m_job.reset();
}
QObject *QQuickAnimatorProxyJob::findAnimationContext(QQuickAbstractAnimation *a)
{
QObject *p = a->parent();
- while (p != 0 && qobject_cast<QQuickWindow *>(p) == 0 && qobject_cast<QQuickItem *>(p) == 0)
+ while (p != nullptr && qobject_cast<QQuickWindow *>(p) == nullptr && qobject_cast<QQuickItem *>(p) == nullptr)
p = p->parent();
return p;
}
void QQuickAnimatorProxyJob::updateCurrentTime(int)
{
+ // We do a simple check here to see if the animator has run and stopped on
+ // the render thread. isPendingStart() will perform a check against jobs
+ // that have been scheduled for start, but that will not yet have entered
+ // the actual running state.
+ // Secondly, we make an unprotected read of the job's state to figure out
+ // if it is running, but this is ok, since we're only reading the state
+ // and if the render thread should happen to be writing it concurrently,
+ // we might get the wrong value for this update, but then we'll simply
+ // pick it up on the next iterationm when the job is stopped and render
+ // thread is no longer using it.
+ if (m_internalState == State_Running
+ && !m_controller->isPendingStart(m_job)
+ && !m_job->isRunning()) {
+ stop();
+ }
}
void QQuickAnimatorProxyJob::updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State)
{
if (m_state == Running) {
m_internalState = State_Starting;
- if (m_controller)
- m_controller->startJob(this, m_job);
+ if (m_controller) {
+ m_internalState = State_Running;
+ m_controller->start(m_job);
+ }
+
} else if (newState == Stopped) {
syncBackCurrentValues();
m_internalState = State_Stopped;
if (m_controller) {
- m_controller->stopJob(this, m_job);
+ m_controller->cancel(m_job);
}
}
}
@@ -155,69 +187,54 @@ void QQuickAnimatorProxyJob::windowChanged(QQuickWindow *window)
setWindow(window);
}
-void QQuickAnimatorProxyJob::controllerWasDeleted()
-{
- m_controller = 0;
- m_job = 0;
-}
-
void QQuickAnimatorProxyJob::setWindow(QQuickWindow *window)
{
if (!window) {
- stop();
- deleteJob();
-
- // Upon leaving a window, we reset the controller. This means that
- // animators will only enter the Starting phase and won't be making
- // calls to QQuickAnimatorController::startjob().
- if (m_controller)
- m_controller->proxyWasDestroyed(this);
- m_controller = 0;
+ if (m_job && m_controller)
+ m_controller->cancel(m_job);
+ m_controller = nullptr;
} else if (!m_controller && m_job) {
m_controller = QQuickWindowPrivate::get(window)->animationController;
if (window->isSceneGraphInitialized())
readyToAnimate();
else
- connect(window, SIGNAL(sceneGraphInitialized()), this, SLOT(sceneGraphInitialized()));
+ connect(window, &QQuickWindow::sceneGraphInitialized, this, &QQuickAnimatorProxyJob::sceneGraphInitialized);
}
}
void QQuickAnimatorProxyJob::sceneGraphInitialized()
{
+ disconnect(m_controller->window(), &QQuickWindow::sceneGraphInitialized, this, &QQuickAnimatorProxyJob::sceneGraphInitialized);
readyToAnimate();
- disconnect(this, SLOT(sceneGraphInitialized()));
}
void QQuickAnimatorProxyJob::readyToAnimate()
{
- if (m_internalState == State_Starting)
- m_controller->startJob(this, m_job);
-}
-
-void QQuickAnimatorProxyJob::startedByController()
-{
- m_internalState = State_Running;
+ Q_ASSERT(m_controller);
+ if (m_internalState == State_Starting) {
+ m_internalState = State_Running;
+ m_controller->start(m_job);
+ }
}
static void qquick_syncback_helper(QAbstractAnimationJob *job)
{
if (job->isRenderThreadJob()) {
- QQuickAnimatorJob *a = static_cast<QQuickAnimatorJob *>(job);
- // Sync back only those jobs that actually have been running
- if (a->controller() && a->hasBeenRunning())
- a->writeBack();
+ static_cast<QQuickAnimatorJob *>(job)->writeBack();
+
} else if (job->isGroup()) {
QAnimationGroupJob *g = static_cast<QAnimationGroupJob *>(job);
for (QAbstractAnimationJob *a = g->firstChild(); a; a = a->nextSibling())
qquick_syncback_helper(a);
}
+
}
void QQuickAnimatorProxyJob::syncBackCurrentValues()
{
if (m_job)
- qquick_syncback_helper(m_job);
+ qquick_syncback_helper(m_job.data());
}
QQuickAnimatorJob::QQuickAnimatorJob()
@@ -229,7 +246,6 @@ QQuickAnimatorJob::QQuickAnimatorJob()
, m_duration(0)
, m_isTransform(false)
, m_isUniform(false)
- , m_hasBeenRunning(false)
{
m_isRenderThreadJob = true;
}
@@ -245,13 +261,16 @@ qreal QQuickAnimatorJob::progress(int time) const
{
return m_easing.valueForProgress((m_duration == 0) ? qreal(1) : qreal(time) / qreal(m_duration));
}
+
qreal QQuickAnimatorJob::value() const
{
- qreal v;
- m_controller->lock();
- v = m_value;
- m_controller->unlock();
- return v;
+ qreal value = m_to;
+ if (m_controller) {
+ m_controller->lock();
+ value = m_value;
+ m_controller->unlock();
+ }
+ return value;
}
void QQuickAnimatorJob::setTarget(QQuickItem *target)
@@ -264,62 +283,81 @@ void QQuickAnimatorJob::initialize(QQuickAnimatorController *controller)
m_controller = controller;
}
-void QQuickAnimatorJob::targetWasDeleted()
-{
- m_target = 0;
- m_controller = 0;
-}
-
QQuickTransformAnimatorJob::QQuickTransformAnimatorJob()
- : m_helper(0)
+ : m_helper(nullptr)
{
m_isTransform = true;
}
QQuickTransformAnimatorJob::~QQuickTransformAnimatorJob()
{
- if (m_helper && --m_helper->ref == 0) {
- // The only condition for not having a controller is when target was
- // destroyed, in which case we have neither m_helper nor m_contorller.
- Q_ASSERT(m_controller);
- Q_ASSERT(m_helper->item);
- m_controller->m_transforms.remove(m_helper->item);
- delete m_helper;
- }
+ if (m_helper)
+ qquick_transform_animatorjob_helper_store()->release(m_helper);
}
-void QQuickTransformAnimatorJob::initialize(QQuickAnimatorController *controller)
+void QQuickTransformAnimatorJob::setTarget(QQuickItem *item)
{
- QQuickAnimatorJob::initialize(controller);
+ // In the extremely unlikely event that the target of an animator has been
+ // changed into a new item that sits in the exact same pointer address, we
+ // want to force syncing it again.
+ if (m_helper && m_target)
+ m_helper->wasSynced = false;
+ QQuickAnimatorJob::setTarget(item);
+}
- if (m_controller) {
- bool newHelper = m_helper == 0;
- m_helper = m_controller->m_transforms.value(m_target);
- if (!m_helper) {
- m_helper = new Helper();
- m_helper->item = m_target;
- m_controller->m_transforms.insert(m_target, m_helper);
- QObject::connect(m_target, SIGNAL(destroyed(QObject*)), m_controller, SLOT(itemDestroyed(QObject*)), Qt::DirectConnection);
- } else {
- if (newHelper) // only add reference the first time around..
- ++m_helper->ref;
- // Make sure leftovers from previous runs are being used...
- m_helper->wasSynced = false;
- }
- m_helper->sync();
+void QQuickTransformAnimatorJob::preSync()
+{
+ // If the target has changed or become null, release and reset the helper
+ if (m_helper && (m_helper->item != m_target || !m_target)) {
+ qquick_transform_animatorjob_helper_store()->release(m_helper);
+ m_helper = nullptr;
}
+
+ if (!m_target)
+ return;
+
+ if (!m_helper) {
+ m_helper = qquick_transform_animatorjob_helper_store()->acquire(m_target);
+
+ // This is a bit superfluous, but it ends up being simpler than the
+ // alternative. When an item happens to land on the same address as a
+ // previous item, that helper might not have been fully cleaned up by
+ // the time it gets taken back into use. As an alternative to storing
+ // connections to each and every item's QObject::destroyed() and
+ // having to clean those up afterwards, we simply sync all helpers on
+ // the first run. The sync is only done once for the run of an
+ // animation and it is a fairly light function (compared to storing
+ // potentially thousands of connections and managing their lifetime.
+ m_helper->wasSynced = false;
+ }
+
+ m_helper->sync();
}
-void QQuickTransformAnimatorJob::nodeWasDestroyed()
+void QQuickTransformAnimatorJob::postSync()
{
- if (m_helper)
- m_helper->node = 0;
+ Q_ASSERT((m_helper != nullptr) == (m_target != nullptr)); // If there is a target, there should also be a helper, ref: preSync
+ Q_ASSERT(!m_helper || m_helper->item == m_target); // If there is a helper, it should point to our target
+
+ if (!m_target || !m_helper) {
+ invalidate();
+ return;
+ }
+
+ QQuickItemPrivate *d = QQuickItemPrivate::get(m_target);
+ if (d->extra.isAllocated()
+ && d->extra->layer
+ && d->extra->layer->enabled()) {
+ d = QQuickItemPrivate::get(d->extra->layer->m_effectSource);
+ }
+
+ m_helper->node = d->itemNode();
}
-void QQuickTransformAnimatorJob::targetWasDeleted()
+void QQuickTransformAnimatorJob::invalidate()
{
- m_helper = 0;
- QQuickAnimatorJob::targetWasDeleted();
+ if (m_helper)
+ m_helper->node = nullptr;
}
void QQuickTransformAnimatorJob::Helper::sync()
@@ -367,7 +405,7 @@ void QQuickTransformAnimatorJob::Helper::sync()
}
}
-void QQuickTransformAnimatorJob::Helper::apply()
+void QQuickTransformAnimatorJob::Helper::commit()
{
if (!wasChanged || !node)
return;
@@ -383,7 +421,11 @@ void QQuickTransformAnimatorJob::Helper::apply()
wasChanged = false;
}
-
+void QQuickTransformAnimatorJob::commit()
+{
+ if (m_helper)
+ m_helper->commit();
+}
void QQuickXAnimatorJob::writeBack()
{
@@ -393,7 +435,10 @@ void QQuickXAnimatorJob::writeBack()
void QQuickXAnimatorJob::updateCurrentTime(int time)
{
- if (!m_controller)
+#if QT_CONFIG(opengl)
+ Q_ASSERT(!m_controller || !m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread());
+#endif
+ if (!m_helper)
return;
m_value = m_from + (m_to - m_from) * progress(time);
@@ -409,7 +454,10 @@ void QQuickYAnimatorJob::writeBack()
void QQuickYAnimatorJob::updateCurrentTime(int time)
{
- if (!m_controller)
+#if QT_CONFIG(opengl)
+ Q_ASSERT(!m_controller || !m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread());
+#endif
+ if (!m_helper)
return;
m_value = m_from + (m_to - m_from) * progress(time);
@@ -417,14 +465,87 @@ void QQuickYAnimatorJob::updateCurrentTime(int time)
m_helper->wasChanged = true;
}
+void QQuickScaleAnimatorJob::writeBack()
+{
+ if (m_target)
+ m_target->setScale(value());
+}
+
+void QQuickScaleAnimatorJob::updateCurrentTime(int time)
+{
+#if QT_CONFIG(opengl)
+ Q_ASSERT(!m_controller || !m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread());
+#endif
+ if (!m_helper)
+ return;
+
+ m_value = m_from + (m_to - m_from) * progress(time);
+ m_helper->scale = m_value;
+ m_helper->wasChanged = true;
+}
+
+
+QQuickRotationAnimatorJob::QQuickRotationAnimatorJob()
+ : m_direction(QQuickRotationAnimator::Numerical)
+{
+}
+
+extern QVariant _q_interpolateShortestRotation(qreal &f, qreal &t, qreal progress);
+extern QVariant _q_interpolateClockwiseRotation(qreal &f, qreal &t, qreal progress);
+extern QVariant _q_interpolateCounterclockwiseRotation(qreal &f, qreal &t, qreal progress);
+
+void QQuickRotationAnimatorJob::updateCurrentTime(int time)
+{
+#if QT_CONFIG(opengl)
+ Q_ASSERT(!m_controller || !m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread());
+#endif
+ if (!m_helper)
+ return;
+
+ float t = progress(time);
+
+ switch (m_direction) {
+ case QQuickRotationAnimator::Clockwise:
+ m_value = _q_interpolateClockwiseRotation(m_from, m_to, t).toFloat();
+ // The logic in _q_interpolateClockwise comes out a bit wrong
+ // for the case of X->0 where 0<X<360. It ends on 360 which it
+ // shouldn't.
+ if (t == 1)
+ m_value = m_to;
+ break;
+ case QQuickRotationAnimator::Counterclockwise:
+ m_value = _q_interpolateCounterclockwiseRotation(m_from, m_to, t).toFloat();
+ break;
+ case QQuickRotationAnimator::Shortest:
+ m_value = _q_interpolateShortestRotation(m_from, m_to, t).toFloat();
+ break;
+ case QQuickRotationAnimator::Numerical:
+ m_value = m_from + (m_to - m_from) * t;
+ break;
+ }
+ m_helper->rotation = m_value;
+ m_helper->wasChanged = true;
+}
+
+void QQuickRotationAnimatorJob::writeBack()
+{
+ if (m_target)
+ m_target->setRotation(value());
+}
+
+
QQuickOpacityAnimatorJob::QQuickOpacityAnimatorJob()
- : m_opacityNode(0)
+ : m_opacityNode(nullptr)
{
}
-void QQuickOpacityAnimatorJob::initialize(QQuickAnimatorController *controller)
+void QQuickOpacityAnimatorJob::postSync()
{
- QQuickAnimatorJob::initialize(controller);
+ if (!m_target) {
+ invalidate();
+ return;
+ }
+
QQuickItemPrivate *d = QQuickItemPrivate::get(m_target);
#if QT_CONFIG(quick_shadereffect)
if (d->extra.isAllocated()
@@ -435,6 +556,7 @@ void QQuickOpacityAnimatorJob::initialize(QQuickAnimatorController *controller)
#endif
m_opacityNode = d->opacityNode();
+
if (!m_opacityNode) {
m_opacityNode = new QSGOpacityNode();
@@ -465,11 +587,12 @@ void QQuickOpacityAnimatorJob::initialize(QQuickAnimatorController *controller)
d->extra.value().opacityNode = m_opacityNode;
}
+ Q_ASSERT(m_opacityNode);
}
-void QQuickOpacityAnimatorJob::nodeWasDestroyed()
+void QQuickOpacityAnimatorJob::invalidate()
{
- m_opacityNode = 0;
+ m_opacityNode = nullptr;
}
void QQuickOpacityAnimatorJob::writeBack()
@@ -480,77 +603,21 @@ void QQuickOpacityAnimatorJob::writeBack()
void QQuickOpacityAnimatorJob::updateCurrentTime(int time)
{
- if (!m_controller || !m_opacityNode)
- return;
-
- m_value = m_from + (m_to - m_from) * progress(time);
- m_opacityNode->setOpacity(m_value);
-}
-
-void QQuickScaleAnimatorJob::writeBack()
-{
- if (m_target)
- m_target->setScale(value());
-}
+#if QT_CONFIG(opengl)
+ Q_ASSERT(!m_controller || !m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread());
+#endif
-void QQuickScaleAnimatorJob::updateCurrentTime(int time)
-{
- if (!m_controller)
+ if (!m_opacityNode)
return;
m_value = m_from + (m_to - m_from) * progress(time);
- m_helper->scale = m_value;
- m_helper->wasChanged = true;
-}
-
-QQuickRotationAnimatorJob::QQuickRotationAnimatorJob()
- : m_direction(QQuickRotationAnimator::Numerical)
-{
-}
-
-extern QVariant _q_interpolateShortestRotation(qreal &f, qreal &t, qreal progress);
-extern QVariant _q_interpolateClockwiseRotation(qreal &f, qreal &t, qreal progress);
-extern QVariant _q_interpolateCounterclockwiseRotation(qreal &f, qreal &t, qreal progress);
-
-void QQuickRotationAnimatorJob::updateCurrentTime(int time)
-{
- if (!m_controller)
- return;
-
- float t = progress(time);
-
- switch (m_direction) {
- case QQuickRotationAnimator::Clockwise:
- m_value = _q_interpolateClockwiseRotation(m_from, m_to, t).toFloat();
- // The logic in _q_interpolateClockwise comes out a bit wrong
- // for the case of X->0 where 0<X<360. It ends on 360 which it
- // shouldn't.
- if (t == 1)
- m_value = m_to;
- break;
- case QQuickRotationAnimator::Counterclockwise:
- m_value = _q_interpolateCounterclockwiseRotation(m_from, m_to, t).toFloat();
- break;
- case QQuickRotationAnimator::Shortest:
- m_value = _q_interpolateShortestRotation(m_from, m_to, t).toFloat();
- break;
- case QQuickRotationAnimator::Numerical:
- m_value = m_from + (m_to - m_from) * t;
- break;
- }
- m_helper->rotation = m_value;
- m_helper->wasChanged = true;
+ m_opacityNode->setOpacity(m_value);
}
-void QQuickRotationAnimatorJob::writeBack()
-{
- if (m_target)
- m_target->setRotation(value());
-}
#if QT_CONFIG(quick_shadereffect) && QT_CONFIG(opengl)
QQuickUniformAnimatorJob::QQuickUniformAnimatorJob()
- : m_node(0)
+ : m_node(nullptr)
, m_uniformIndex(-1)
, m_uniformType(-1)
{
@@ -564,15 +631,20 @@ void QQuickUniformAnimatorJob::setTarget(QQuickItem *target)
m_target = target;
}
-void QQuickUniformAnimatorJob::nodeWasDestroyed()
+void QQuickUniformAnimatorJob::invalidate()
{
- m_node = 0;
+ m_node = nullptr;
m_uniformIndex = -1;
m_uniformType = -1;
}
-void QQuickUniformAnimatorJob::afterNodeSync()
+void QQuickUniformAnimatorJob::postSync()
{
+ if (!m_target) {
+ invalidate();
+ return;
+ }
+
m_node = static_cast<QQuickOpenGLShaderEffectNode *>(QQuickItemPrivate::get(m_target)->paintNode);
if (m_node && m_uniformIndex == -1 && m_uniformType == -1) {
diff --git a/src/quick/util/qquickanimatorjob_p.h b/src/quick/util/qquickanimatorjob_p.h
index e891ebab72..a3ced4c21b 100644
--- a/src/quick/util/qquickanimatorjob_p.h
+++ b/src/quick/util/qquickanimatorjob_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Gunnar Sletta <gunnar@sletta.org>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -80,25 +81,20 @@ public:
QQuickAnimatorProxyJob(QAbstractAnimationJob *job, QObject *item);
~QQuickAnimatorProxyJob();
- int duration() const Q_DECL_OVERRIDE { return m_duration; }
+ int duration() const override { return m_duration; }
- QAbstractAnimationJob *job() const { return m_job; }
-
- void startedByController();
- void controllerWasDeleted();
- void markJobManagedByController() { m_jobManagedByController = true; }
+ const QSharedPointer<QAbstractAnimationJob> &job() const { return m_job; }
protected:
- void updateCurrentTime(int) Q_DECL_OVERRIDE;
- void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) Q_DECL_OVERRIDE;
- void debugAnimation(QDebug d) const Q_DECL_OVERRIDE;
+ void updateCurrentTime(int) override;
+ void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) override;
+ void debugAnimation(QDebug d) const override;
public Q_SLOTS:
void windowChanged(QQuickWindow *window);
void sceneGraphInitialized();
private:
- void deleteJob();
void syncBackCurrentValues();
void readyToAnimate();
void setWindow(QQuickWindow *window);
@@ -106,7 +102,7 @@ private:
QPointer<QQuickAnimatorController> m_controller;
QQuickAbstractAnimation *m_animation;
- QAbstractAnimationJob *m_job;
+ QSharedPointer<QAbstractAnimationJob> m_job;
int m_duration;
enum InternalState {
@@ -117,7 +113,6 @@ private:
};
InternalState m_internalState;
- bool m_jobManagedByController;
};
class Q_QUICK_PRIVATE_EXPORT QQuickAnimatorJob : public QAbstractAnimationJob
@@ -126,37 +121,53 @@ public:
virtual void setTarget(QQuickItem *target);
QQuickItem *target() const { return m_target; }
- void setFrom(qreal scale) { m_from = scale; }
+ void setFrom(qreal from) { m_from = from; }
qreal from() const { return m_from; }
void setTo(qreal to) { m_to = to; }
qreal to() const { return m_to; }
void setDuration(int duration) { m_duration = duration; }
- int duration() const Q_DECL_OVERRIDE { return m_duration; }
+ int duration() const override { return m_duration; }
QEasingCurve easingCurve() const { return m_easing; }
void setEasingCurve(const QEasingCurve &curve) { m_easing = curve; }
- virtual void targetWasDeleted();
+ // Initialize is called on the GUI thread just before it is started
+ // and taken over on the render thread.
virtual void initialize(QQuickAnimatorController *controller);
+
+ // Called on the render thread during SG shutdown.
+ virtual void invalidate() = 0;
+
+ // Called on the GUI thread after a complete render thread animation job
+ // has been completed to write back a given animator's result to the
+ // source item.
virtual void writeBack() = 0;
- virtual void nodeWasDestroyed() = 0;
- virtual void afterNodeSync() { }
+
+ // Called before the SG sync on the render thread. The GUI thread is
+ // locked during this call.
+ virtual void preSync() { }
+
+ // Called after the SG sync on the render thread. The GUI thread is
+ // locked during this call.
+ virtual void postSync() { }
+
+ // Called after animations have ticked on the render thread. No locks are
+ // held at this time, so synchronization needs to be taken into account
+ // if applicable.
+ virtual void commit() { }
bool isTransform() const { return m_isTransform; }
bool isUniform() const { return m_isUniform; }
- bool hasBeenRunning() const { return m_hasBeenRunning; }
- void setHasBeenRunning(bool has) { m_hasBeenRunning = has; }
-
qreal value() const;
QQuickAnimatorController *controller() const { return m_controller; }
protected:
QQuickAnimatorJob();
- void debugAnimation(QDebug d) const Q_DECL_OVERRIDE;
+ void debugAnimation(QDebug d) const override;
qreal progress(int time) const;
@@ -173,7 +184,6 @@ protected:
uint m_isTransform : 1;
uint m_isUniform : 1;
- uint m_hasBeenRunning : 1;
};
class QQuickTransformAnimatorJob : public QQuickAnimatorJob
@@ -197,7 +207,7 @@ public:
}
void sync();
- void apply();
+ void commit();
int ref;
QQuickItem *item;
@@ -217,13 +227,16 @@ public:
};
~QQuickTransformAnimatorJob();
- Helper *transformHelper() const { return m_helper; }
+
+ void commit() override;
+ void preSync() override;
+
+ void setTarget(QQuickItem *item) override;
protected:
QQuickTransformAnimatorJob();
- void initialize(QQuickAnimatorController *controller) Q_DECL_OVERRIDE;
- void nodeWasDestroyed() Q_DECL_OVERRIDE;
- void targetWasDeleted() Q_DECL_OVERRIDE;
+ void postSync() override;
+ void invalidate() override;
Helper *m_helper;
};
@@ -231,22 +244,22 @@ protected:
class Q_QUICK_PRIVATE_EXPORT QQuickScaleAnimatorJob : public QQuickTransformAnimatorJob
{
public:
- void updateCurrentTime(int time) Q_DECL_OVERRIDE;
- void writeBack() Q_DECL_OVERRIDE;
+ void updateCurrentTime(int time) override;
+ void writeBack() override;
};
class Q_QUICK_PRIVATE_EXPORT QQuickXAnimatorJob : public QQuickTransformAnimatorJob
{
public:
- void updateCurrentTime(int time) Q_DECL_OVERRIDE;
- void writeBack() Q_DECL_OVERRIDE;
+ void updateCurrentTime(int time) override;
+ void writeBack() override;
};
class Q_QUICK_PRIVATE_EXPORT QQuickYAnimatorJob : public QQuickTransformAnimatorJob
{
public:
- void updateCurrentTime(int time) Q_DECL_OVERRIDE;
- void writeBack() Q_DECL_OVERRIDE;
+ void updateCurrentTime(int time) override;
+ void writeBack() override;
};
class Q_QUICK_PRIVATE_EXPORT QQuickRotationAnimatorJob : public QQuickTransformAnimatorJob
@@ -254,8 +267,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickRotationAnimatorJob : public QQuickTransformA
public:
QQuickRotationAnimatorJob();
- void updateCurrentTime(int time) Q_DECL_OVERRIDE;
- void writeBack() Q_DECL_OVERRIDE;
+ void updateCurrentTime(int time) override;
+ void writeBack() override;
void setDirection(QQuickRotationAnimator::RotationDirection direction) { m_direction = direction; }
QQuickRotationAnimator::RotationDirection direction() const { return m_direction; }
@@ -269,10 +282,10 @@ class Q_QUICK_PRIVATE_EXPORT QQuickOpacityAnimatorJob : public QQuickAnimatorJob
public:
QQuickOpacityAnimatorJob();
- void initialize(QQuickAnimatorController *controller) Q_DECL_OVERRIDE;
- void updateCurrentTime(int time) Q_DECL_OVERRIDE;
- void writeBack() Q_DECL_OVERRIDE;
- void nodeWasDestroyed() Q_DECL_OVERRIDE;
+ void invalidate() override;
+ void updateCurrentTime(int time) override;
+ void writeBack() override;
+ void postSync() override;
private:
QSGOpacityNode *m_opacityNode;
@@ -283,16 +296,17 @@ class Q_QUICK_PRIVATE_EXPORT QQuickUniformAnimatorJob : public QQuickAnimatorJob
public:
QQuickUniformAnimatorJob();
- void setTarget(QQuickItem *target) Q_DECL_OVERRIDE;
+ void setTarget(QQuickItem *target) override;
void setUniform(const QByteArray &uniform) { m_uniform = uniform; }
QByteArray uniform() const { return m_uniform; }
- void afterNodeSync() Q_DECL_OVERRIDE;
+ void postSync() override;
+
+ void updateCurrentTime(int time) override;
+ void writeBack() override;
- void updateCurrentTime(int time) Q_DECL_OVERRIDE;
- void writeBack() Q_DECL_OVERRIDE;
- void nodeWasDestroyed() Q_DECL_OVERRIDE;
+ void invalidate() override;
private:
QByteArray m_uniform;
diff --git a/src/quick/util/qquickapplication.cpp b/src/quick/util/qquickapplication.cpp
index 5c26b23ff7..5c89275c5a 100644
--- a/src/quick/util/qquickapplication.cpp
+++ b/src/quick/util/qquickapplication.cpp
@@ -38,7 +38,7 @@
****************************************************************************/
#include "qquickapplication_p.h"
-
+#include <private/qquickscreen_p.h>
#include <private/qobject_p.h>
#include <private/qguiapplication_p.h>
#include <qpa/qplatformintegration.h>
@@ -63,6 +63,12 @@ QQuickApplication::QQuickApplication(QObject *parent)
this, SIGNAL(stateChanged(Qt::ApplicationState)));
connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
this, SIGNAL(activeChanged()));
+ connect(qApp, SIGNAL(applicationDisplayNameChanged()),
+ this, SIGNAL(displayNameChanged()));
+
+ connect(qApp, &QGuiApplication::screenAdded, this, &QQuickApplication::updateScreens);
+ connect(qApp, &QGuiApplication::screenRemoved, this, &QQuickApplication::updateScreens);
+ updateScreens();
}
}
@@ -95,4 +101,42 @@ QFont QQuickApplication::font() const
return QGuiApplication::font();
}
+QString QQuickApplication::displayName() const
+{
+ return QGuiApplication::applicationDisplayName();
+}
+
+void QQuickApplication::setDisplayName(const QString &displayName)
+{
+ return QGuiApplication::setApplicationDisplayName(displayName);
+}
+
+int screens_count(QQmlListProperty<QQuickScreenInfo> *prop)
+{
+ return static_cast<QVector<QQuickScreenInfo *> *>(prop->data)->count();
+}
+
+QQuickScreenInfo *screens_at(QQmlListProperty<QQuickScreenInfo> *prop, int idx)
+{
+ return static_cast<QVector<QQuickScreenInfo *> *>(prop->data)->at(idx);
+}
+
+QQmlListProperty<QQuickScreenInfo> QQuickApplication::screens()
+{
+ return QQmlListProperty<QQuickScreenInfo>(this,
+ const_cast<QVector<QQuickScreenInfo *> *>(&m_screens), &screens_count, &screens_at);
+}
+
+void QQuickApplication::updateScreens()
+{
+ const QList<QScreen *> screenList = QGuiApplication::screens();
+ m_screens.resize(screenList.count());
+ for (int i = 0; i < screenList.count(); ++i) {
+ if (!m_screens[i])
+ m_screens[i] = new QQuickScreenInfo(this);
+ m_screens[i]->setWrappedScreen(screenList[i]);
+ }
+ emit screensChanged();
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/util/qquickapplication_p.h b/src/quick/util/qquickapplication_p.h
index 091cb094ed..8ee203f0da 100644
--- a/src/quick/util/qquickapplication_p.h
+++ b/src/quick/util/qquickapplication_p.h
@@ -56,10 +56,10 @@
#include <qqml.h>
#include <QtQml/private/qqmlglobal_p.h>
#include <private/qtquickglobal_p.h>
+#include "../items/qquickscreen_p.h"
QT_BEGIN_NAMESPACE
-
class Q_AUTOTEST_EXPORT QQuickApplication : public QQmlApplication
{
Q_OBJECT
@@ -68,6 +68,8 @@ class Q_AUTOTEST_EXPORT QQuickApplication : public QQmlApplication
Q_PROPERTY(bool supportsMultipleWindows READ supportsMultipleWindows CONSTANT)
Q_PROPERTY(Qt::ApplicationState state READ state NOTIFY stateChanged)
Q_PROPERTY(QFont font READ font CONSTANT)
+ Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged)
+ Q_PROPERTY(QQmlListProperty<QQuickScreenInfo> screens READ screens NOTIFY screensChanged)
public:
explicit QQuickApplication(QObject *parent = 0);
@@ -77,14 +79,23 @@ public:
bool supportsMultipleWindows() const;
Qt::ApplicationState state() const;
QFont font() const;
+ QQmlListProperty<QQuickScreenInfo> screens();
+ QString displayName() const;
+ void setDisplayName(const QString &displayName);
Q_SIGNALS:
void activeChanged();
+ void displayNameChanged();
void layoutDirectionChanged();
void stateChanged(Qt::ApplicationState state);
+ void screensChanged();
+
+private Q_SLOTS:
+ void updateScreens();
private:
Q_DISABLE_COPY(QQuickApplication)
+ QVector<QQuickScreenInfo *> m_screens;
};
QT_END_NAMESPACE
diff --git a/src/quick/util/qquickbehavior.cpp b/src/quick/util/qquickbehavior.cpp
index 1d3ee2c4be..1b2d9afb7c 100644
--- a/src/quick/util/qquickbehavior.cpp
+++ b/src/quick/util/qquickbehavior.cpp
@@ -60,7 +60,7 @@ public:
QQuickBehaviorPrivate() : animation(0), animationInstance(0), enabled(true), finalized(false)
, blockRunningChanged(false) {}
- virtual void animationStateChanged(QAbstractAnimationJob *, QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState);
+ void animationStateChanged(QAbstractAnimationJob *, QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) override;
QQmlProperty property;
QVariant targetValue;
@@ -129,7 +129,7 @@ void QQuickBehavior::setAnimation(QQuickAbstractAnimation *animation)
{
Q_D(QQuickBehavior);
if (d->animation) {
- qmlInfo(this) << tr("Cannot change the animation assigned to a Behavior.");
+ qmlWarning(this) << tr("Cannot change the animation assigned to a Behavior.");
return;
}
diff --git a/src/quick/util/qquickbehavior_p.h b/src/quick/util/qquickbehavior_p.h
index c3438d8c6d..b3fd2af400 100644
--- a/src/quick/util/qquickbehavior_p.h
+++ b/src/quick/util/qquickbehavior_p.h
@@ -75,8 +75,8 @@ public:
QQuickBehavior(QObject *parent=0);
~QQuickBehavior();
- virtual void setTarget(const QQmlProperty &);
- virtual void write(const QVariant &value);
+ void setTarget(const QQmlProperty &) override;
+ void write(const QVariant &value) override;
QQuickAbstractAnimation *animation();
void setAnimation(QQuickAbstractAnimation *);
diff --git a/src/quick/util/qquickfontloader.cpp b/src/quick/util/qquickfontloader.cpp
index d13291c30a..3761a37a6d 100644
--- a/src/quick/util/qquickfontloader.cpp
+++ b/src/quick/util/qquickfontloader.cpp
@@ -307,7 +307,7 @@ void QQuickFontLoader::updateFontInfo(const QString& name, QQuickFontLoader::Sta
}
if (status != d->status) {
if (status == Error)
- qmlInfo(this) << "Cannot load font: \"" << d->url.toString() << '"';
+ qmlWarning(this) << "Cannot load font: \"" << d->url.toString() << '"';
d->status = status;
emit statusChanged();
}
diff --git a/src/quick/util/qquickimageprovider.cpp b/src/quick/util/qquickimageprovider.cpp
index d2a8a5097c..a026abe762 100644
--- a/src/quick/util/qquickimageprovider.cpp
+++ b/src/quick/util/qquickimageprovider.cpp
@@ -44,13 +44,6 @@
QT_BEGIN_NAMESPACE
-class QQuickImageProviderPrivate
-{
-public:
- QQuickImageProvider::ImageType type;
- QQuickImageProvider::Flags flags;
-};
-
/*!
\class QQuickTextureFactory
\since 5.0
@@ -351,6 +344,7 @@ QQuickImageProvider::QQuickImageProvider(ImageType type, Flags flags)
{
d->type = type;
d->flags = flags;
+ d->isProviderWithOptions = false;
}
/*!
@@ -506,26 +500,165 @@ QQuickAsyncImageProvider::~QQuickAsyncImageProvider()
implementation of this method is reentrant.
*/
+
+class QQuickImageProviderOptionsPrivate : public QSharedData
+{
+public:
+ QQuickImageProviderOptionsPrivate()
+ : autoTransform(QQuickImageProviderOptions::UsePluginDefaultTransform)
+ , preserveAspectRatioCrop(false)
+ , preserveAspectRatioFit(false)
+ {
+ }
+
+ QQuickImageProviderOptions::AutoTransform autoTransform;
+ bool preserveAspectRatioCrop;
+ bool preserveAspectRatioFit;
+};
+
/*!
- \fn QImage QQuickImageProvider::requestImage(const QString &id, QSize *size, const QSize& requestedSize, bool requestedAutoTransform);
+ \class QQuickImageProviderOptions
+ \brief The QQuickImageProviderOptions class provides options for QQuickImageProviderWithOptions image requests.
+ \inmodule QtQuick
+ \internal
- \internal
- For future reference.
+ \sa QQuickImageProviderWithOptions
*/
/*!
- \fn QPixmap QQuickImageProvider::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, bool requestedAutoTransform);
+ \enum QQuickImageProviderOptions::AutoTransform
- \internal
- For future reference.
+ Whether the image provider should apply transformation metadata on read().
+
+ \value UsePluginDefaultTransform Image provider should do its default behavior on whether applying transformation metadata on read or not
+ \value ApplyTransform Image provider should apply transformation metadata on read
+ \value DoNotApplyTransform Image provider should not apply transformation metadata on read
*/
+QQuickImageProviderOptions::QQuickImageProviderOptions()
+ : d(new QQuickImageProviderOptionsPrivate())
+{
+}
+
+QQuickImageProviderOptions::~QQuickImageProviderOptions()
+{
+}
+
+QQuickImageProviderOptions::QQuickImageProviderOptions(const QQuickImageProviderOptions &other)
+ : d(other.d)
+{
+}
+
+QQuickImageProviderOptions& QQuickImageProviderOptions::operator=(const QQuickImageProviderOptions &other)
+{
+ d = other.d;
+ return *this;
+}
+
+bool QQuickImageProviderOptions::operator==(const QQuickImageProviderOptions &other) const
+{
+ return d->autoTransform == other.d->autoTransform &&
+ d->preserveAspectRatioCrop == other.d->preserveAspectRatioCrop &&
+ d->preserveAspectRatioFit == other.d->preserveAspectRatioFit;
+}
+
/*!
- \fn QQuickTextureFactory *QQuickImageProvider::requestTexture(const QString &id, QSize *size, const QSize &requestedSize, bool requestedAutoTransform);
+ Returns whether the image provider should apply transformation metadata on read().
+*/
+QQuickImageProviderOptions::AutoTransform QQuickImageProviderOptions::autoTransform() const
+{
+ return d->autoTransform;
+}
+
+void QQuickImageProviderOptions::setAutoTransform(QQuickImageProviderOptions::AutoTransform autoTransform)
+{
+ d->autoTransform = autoTransform;
+}
- \internal
- For future reference.
+/*!
+ Returns whether the image request is for a PreserveAspectCrop Image.
+ This allows the provider to better optimize the size of the returned image.
*/
+bool QQuickImageProviderOptions::preserveAspectRatioCrop() const
+{
+ return d->preserveAspectRatioCrop;
+}
+
+void QQuickImageProviderOptions::setPreserveAspectRatioCrop(bool preserveAspectRatioCrop)
+{
+ d->preserveAspectRatioCrop = preserveAspectRatioCrop;
+}
+
+/*!
+ Returns whether the image request is for a PreserveAspectFit Image.
+ This allows the provider to better optimize the size of the returned image.
+*/
+bool QQuickImageProviderOptions::preserveAspectRatioFit() const
+{
+ return d->preserveAspectRatioFit;
+}
+
+void QQuickImageProviderOptions::setPreserveAspectRatioFit(bool preserveAspectRatioFit)
+{
+ d->preserveAspectRatioFit = preserveAspectRatioFit;
+}
+
+
+QQuickImageProviderWithOptions::QQuickImageProviderWithOptions(ImageType type, Flags flags)
+ : QQuickAsyncImageProvider()
+{
+ QQuickImageProvider::d->type = type;
+ QQuickImageProvider::d->flags = flags;
+ QQuickImageProvider::d->isProviderWithOptions = true;
+}
+
+QImage QQuickImageProviderWithOptions::requestImage(const QString &id, QSize *size, const QSize& requestedSize)
+{
+ return requestImage(id, size, requestedSize, QQuickImageProviderOptions());
+}
+
+QPixmap QQuickImageProviderWithOptions::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize)
+{
+ return requestPixmap(id, size, requestedSize, QQuickImageProviderOptions());
+}
+
+QQuickTextureFactory *QQuickImageProviderWithOptions::requestTexture(const QString &id, QSize *size, const QSize &requestedSize)
+{
+ return requestTexture(id, size, requestedSize, QQuickImageProviderOptions());
+}
+
+QImage QQuickImageProviderWithOptions::requestImage(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options)
+{
+ Q_UNUSED(options);
+ return QQuickAsyncImageProvider::requestImage(id, size, requestedSize);
+}
+
+QPixmap QQuickImageProviderWithOptions::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options)
+{
+ Q_UNUSED(options);
+ return QQuickAsyncImageProvider::requestPixmap(id, size, requestedSize);
+}
+
+QQuickTextureFactory *QQuickImageProviderWithOptions::requestTexture(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options)
+{
+ Q_UNUSED(options);
+ return QQuickAsyncImageProvider::requestTexture(id, size, requestedSize);
+}
+
+QQuickImageResponse *QQuickImageProviderWithOptions::requestImageResponse(const QString &id, const QSize &requestedSize)
+{
+ Q_UNUSED(id);
+ Q_UNUSED(requestedSize);
+ if (imageType() == ImageResponse)
+ qWarning("ImageProvider is of ImageResponse type but has not implemented requestImageResponse()");
+ return nullptr;
+}
+
+QQuickImageResponse *QQuickImageProviderWithOptions::requestImageResponse(const QString &id, const QSize &requestedSize, const QQuickImageProviderOptions &options)
+{
+ Q_UNUSED(options);
+ return requestImageResponse(id, requestedSize);
+}
QT_END_NAMESPACE
diff --git a/src/quick/util/qquickimageprovider.h b/src/quick/util/qquickimageprovider.h
index d4719a7f5b..c77ff95f32 100644
--- a/src/quick/util/qquickimageprovider.h
+++ b/src/quick/util/qquickimageprovider.h
@@ -50,6 +50,7 @@ QT_BEGIN_NAMESPACE
class QQuickImageProviderPrivate;
class QQuickAsyncImageProviderPrivate;
+class QQuickImageProviderOptionsPrivate;
class QSGTexture;
class QQuickWindow;
@@ -86,17 +87,19 @@ Q_SIGNALS:
class Q_QUICK_EXPORT QQuickImageProvider : public QQmlImageProviderBase
{
+ friend class QQuickImageProviderWithOptions; // ### Qt 6 Remove
+ friend class QQuickPixmapReader; // ### Qt 6 Remove
public:
QQuickImageProvider(ImageType type, Flags flags = Flags());
virtual ~QQuickImageProvider();
- ImageType imageType() const;
- Flags flags() const;
+ ImageType imageType() const override;
+ Flags flags() const override;
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
- virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize, bool requestedAutoTransform);
- virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, bool requestedAutoTransform);
- virtual QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize, bool requestedAutoTransform);
+ virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
+ virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
+ virtual QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options);
#else
virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize);
virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize);
@@ -113,7 +116,11 @@ public:
QQuickAsyncImageProvider();
virtual ~QQuickAsyncImageProvider();
+#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
+ virtual QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize, const QQuickImageProviderOptions &options) = 0;
+#else
virtual QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) = 0;
+#endif
private:
QQuickAsyncImageProviderPrivate *d;
diff --git a/src/quick/util/qquickpath.cpp b/src/quick/util/qquickpath.cpp
index 25a4433a9b..e31aed7b6d 100644
--- a/src/quick/util/qquickpath.cpp
+++ b/src/quick/util/qquickpath.cpp
@@ -149,20 +149,6 @@ bool QQuickPath::isClosed() const
return d->closed;
}
-bool QQuickPath::hasEnd() const
-{
- Q_D(const QQuickPath);
- for (int i = d->_pathElements.count() - 1; i > -1; --i) {
- if (QQuickCurve *curve = qobject_cast<QQuickCurve *>(d->_pathElements.at(i))) {
- if ((!curve->hasX() && !curve->hasRelativeX()) || (!curve->hasY() && !curve->hasRelativeY()))
- return false;
- else
- return true;
- }
- }
- return hasStartX() && hasStartY();
-}
-
/*!
\qmlproperty list<PathElement> QtQuick::Path::pathElements
This property holds the objects composing the path.
diff --git a/src/quick/util/qquickpath_p.h b/src/quick/util/qquickpath_p.h
index 457f69d20f..c0a96cad4f 100644
--- a/src/quick/util/qquickpath_p.h
+++ b/src/quick/util/qquickpath_p.h
@@ -156,7 +156,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPathLine : public QQuickCurve
public:
QQuickPathLine(QObject *parent=0) : QQuickCurve(parent) {}
- void addToPath(QPainterPath &path, const QQuickPathData &);
+ void addToPath(QPainterPath &path, const QQuickPathData &) override;
};
class Q_QUICK_PRIVATE_EXPORT QQuickPathQuad : public QQuickCurve
@@ -184,7 +184,7 @@ public:
void setRelativeControlY(qreal y);
bool hasRelativeControlY();
- void addToPath(QPainterPath &path, const QQuickPathData &);
+ void addToPath(QPainterPath &path, const QQuickPathData &) override;
Q_SIGNALS:
void controlXChanged();
@@ -242,7 +242,7 @@ public:
void setRelativeControl2Y(qreal y);
bool hasRelativeControl2Y();
- void addToPath(QPainterPath &path, const QQuickPathData &);
+ void addToPath(QPainterPath &path, const QQuickPathData &) override;
Q_SIGNALS:
void control1XChanged();
@@ -271,7 +271,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickPathCatmullRomCurve : public QQuickCurve
public:
QQuickPathCatmullRomCurve(QObject *parent=0) : QQuickCurve(parent) {}
- void addToPath(QPainterPath &path, const QQuickPathData &);
+ void addToPath(QPainterPath &path, const QQuickPathData &) override;
};
class Q_QUICK_PRIVATE_EXPORT QQuickPathArc : public QQuickCurve
@@ -301,7 +301,7 @@ public:
ArcDirection direction() const;
void setDirection(ArcDirection direction);
- void addToPath(QPainterPath &path, const QQuickPathData &);
+ void addToPath(QPainterPath &path, const QQuickPathData &) override;
Q_SIGNALS:
void radiusXChanged();
@@ -326,7 +326,7 @@ public:
QString path() const;
void setPath(const QString &path);
- void addToPath(QPainterPath &path, const QQuickPathData &);
+ void addToPath(QPainterPath &path, const QQuickPathData &) override;
Q_SIGNALS:
void pathChanged();
@@ -390,7 +390,6 @@ public:
bool hasStartY() const;
bool isClosed() const;
- bool hasEnd() const;
QPainterPath path() const;
QStringList attributes() const;
@@ -405,8 +404,8 @@ Q_SIGNALS:
void startYChanged();
protected:
- virtual void componentComplete();
- virtual void classBegin();
+ void componentComplete() override;
+ void classBegin() override;
void disconnectPathElements();
void connectPathElements();
void gatherAttributes();
diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp
index 96b88636fe..be27cba989 100644
--- a/src/quick/util/qquickpixmapcache.cpp
+++ b/src/quick/util/qquickpixmapcache.cpp
@@ -84,6 +84,7 @@
QT_BEGIN_NAMESPACE
+const QLatin1String QQuickPixmap::itemGrabberScheme = QLatin1String("itemgrabber");
#ifndef QT_NO_DEBUG
static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK");
@@ -140,18 +141,16 @@ public:
QUrl url;
bool loading;
- AutoTransform autoTransform;
int redirectCount;
class Event : public QEvent {
public:
- Event(ReadError, const QString &, const QSize &, AutoTransform, QQuickTextureFactory *factory);
+ Event(ReadError, const QString &, const QSize &, QQuickTextureFactory *factory);
~Event();
ReadError error;
QString errorString;
QSize implicitSize;
- AutoTransform autoTransform;
QQuickTextureFactory *textureFactory;
};
void postReply(ReadError, const QString &, const QSize &, QQuickTextureFactory *factory);
@@ -177,7 +176,7 @@ class QQuickPixmapReaderThreadObject : public QObject {
public:
QQuickPixmapReaderThreadObject(QQuickPixmapReader *);
void processJobs();
- virtual bool event(QEvent *e);
+ bool event(QEvent *e) override;
private slots:
void networkRequestDone();
void asyncResponseFinished();
@@ -205,7 +204,7 @@ protected:
private:
friend class QQuickPixmapReaderThreadObject;
void processJobs();
- void processJob(QQuickPixmapReply *, const QUrl &, const QString &, AutoTransform, QQuickImageProvider::ImageType, QQuickImageProvider *);
+ void processJob(QQuickPixmapReply *, const QUrl &, const QString &, const QQuickImageProviderOptions &, QQuickImageProvider::ImageType, QQuickImageProvider *);
#if QT_CONFIG(qml_network)
void networkRequestDone(QNetworkReply *);
#endif
@@ -239,20 +238,20 @@ public:
class QQuickPixmapData
{
public:
- QQuickPixmapData(QQuickPixmap *pixmap, const QUrl &u, const QSize &s, AutoTransform transform, const QString &e)
+ QQuickPixmapData(QQuickPixmap *pixmap, const QUrl &u, const QSize &s, const QQuickImageProviderOptions &po, const QString &e)
: refCount(1), inCache(false), pixmapStatus(QQuickPixmap::Error),
url(u), errorString(e), requestSize(s),
- requestedTransform(transform), appliedTransform(UsePluginDefault),
+ providerOptions(po), appliedTransform(QQuickImageProviderOptions::UsePluginDefaultTransform),
textureFactory(0), reply(0), prevUnreferenced(0),
prevUnreferencedPtr(0), nextUnreferenced(0)
{
declarativePixmaps.insert(pixmap);
}
- QQuickPixmapData(QQuickPixmap *pixmap, const QUrl &u, const QSize &r, AutoTransform rTransform, AutoTransform aTransform)
+ QQuickPixmapData(QQuickPixmap *pixmap, const QUrl &u, const QSize &r, const QQuickImageProviderOptions &po, QQuickImageProviderOptions::AutoTransform aTransform)
: refCount(1), inCache(false), pixmapStatus(QQuickPixmap::Loading),
url(u), requestSize(r),
- requestedTransform(rTransform), appliedTransform(aTransform),
+ providerOptions(po), appliedTransform(aTransform),
textureFactory(0), reply(0), prevUnreferenced(0), prevUnreferencedPtr(0),
nextUnreferenced(0)
{
@@ -260,10 +259,10 @@ public:
}
QQuickPixmapData(QQuickPixmap *pixmap, const QUrl &u, QQuickTextureFactory *texture,
- const QSize &s, const QSize &r, AutoTransform rTransform, AutoTransform aTransform)
+ const QSize &s, const QSize &r, const QQuickImageProviderOptions &po, QQuickImageProviderOptions::AutoTransform aTransform)
: refCount(1), inCache(false), pixmapStatus(QQuickPixmap::Ready),
url(u), implicitSize(s), requestSize(r),
- requestedTransform(rTransform), appliedTransform(aTransform),
+ providerOptions(po), appliedTransform(aTransform),
textureFactory(texture), reply(0), prevUnreferenced(0),
prevUnreferencedPtr(0), nextUnreferenced(0)
{
@@ -272,7 +271,7 @@ public:
QQuickPixmapData(QQuickPixmap *pixmap, QQuickTextureFactory *texture)
: refCount(1), inCache(false), pixmapStatus(QQuickPixmap::Ready),
- requestedTransform(UsePluginDefault), appliedTransform(UsePluginDefault),
+ appliedTransform(QQuickImageProviderOptions::UsePluginDefaultTransform),
textureFactory(texture), reply(0), prevUnreferenced(0),
prevUnreferencedPtr(0), nextUnreferenced(0)
{
@@ -306,8 +305,8 @@ public:
QString errorString;
QSize implicitSize;
QSize requestSize;
- AutoTransform requestedTransform;
- AutoTransform appliedTransform;
+ QQuickImageProviderOptions providerOptions;
+ QQuickImageProviderOptions::AutoTransform appliedTransform;
QQuickTextureFactory *textureFactory;
@@ -336,11 +335,11 @@ void QQuickPixmapReply::postReply(ReadError error, const QString &errorString,
const QSize &implicitSize, QQuickTextureFactory *factory)
{
loading = false;
- QCoreApplication::postEvent(this, new Event(error, errorString, implicitSize, autoTransform, factory));
+ QCoreApplication::postEvent(this, new Event(error, errorString, implicitSize, factory));
}
-QQuickPixmapReply::Event::Event(ReadError e, const QString &s, const QSize &iSize, AutoTransform iTransformed, QQuickTextureFactory *factory)
- : QEvent(QEvent::User), error(e), errorString(s), implicitSize(iSize), autoTransform(iTransformed), textureFactory(factory)
+QQuickPixmapReply::Event::Event(ReadError e, const QString &s, const QSize &iSize, QQuickTextureFactory *factory)
+ : QEvent(QEvent::User), error(e), errorString(s), implicitSize(iSize), textureFactory(factory)
{
}
@@ -384,25 +383,32 @@ static void maybeRemoveAlpha(QImage *image)
}
static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *errorString, QSize *impsize,
- const QSize &requestSize, AutoTransform &autoTransform)
+ const QSize &requestSize, const QQuickImageProviderOptions &providerOptions,
+ QQuickImageProviderOptions::AutoTransform *appliedTransform = nullptr)
{
+ const bool preserveAspectCropOrFit = providerOptions.preserveAspectRatioCrop() || providerOptions.preserveAspectRatioFit();
+
QImageReader imgio(dev);
- if (autoTransform != UsePluginDefault)
- imgio.setAutoTransform(autoTransform == ApplyTransform);
- else
- autoTransform = imgio.autoTransform() ? ApplyTransform : DoNotApplyTransform;
+ if (providerOptions.autoTransform() != QQuickImageProviderOptions::UsePluginDefaultTransform)
+ imgio.setAutoTransform(providerOptions.autoTransform() == QQuickImageProviderOptions::ApplyTransform);
+ else if (appliedTransform)
+ *appliedTransform = imgio.autoTransform() ? QQuickImageProviderOptions::ApplyTransform : QQuickImageProviderOptions::DoNotApplyTransform;
const bool force_scale = imgio.format() == "svg" || imgio.format() == "svgz";
if (requestSize.width() > 0 || requestSize.height() > 0) {
QSize s = imgio.size();
qreal ratio = 0.0;
- if (requestSize.width() && (force_scale || requestSize.width() < s.width())) {
+ if (requestSize.width() && (preserveAspectCropOrFit || force_scale || requestSize.width() < s.width())) {
ratio = qreal(requestSize.width())/s.width();
}
- if (requestSize.height() && (force_scale || requestSize.height() < s.height())) {
+ if (requestSize.height() && (preserveAspectCropOrFit || force_scale || requestSize.height() < s.height())) {
qreal hr = qreal(requestSize.height())/s.height();
- if (ratio == 0.0 || hr < ratio)
+ if (ratio == 0.0)
+ ratio = hr;
+ else if (!preserveAspectCropOrFit && (hr < ratio))
+ ratio = hr;
+ else if (preserveAspectCropOrFit && (hr > ratio))
ratio = hr;
}
if (ratio > 0.0) {
@@ -512,7 +518,7 @@ void QQuickPixmapReader::networkRequestDone(QNetworkReply *reply)
QByteArray all = reply->readAll();
QBuffer buff(&all);
buff.open(QIODevice::ReadOnly);
- if (!readImage(reply->url(), &buff, &image, &errorString, &readSize, job->requestSize, job->autoTransform))
+ if (!readImage(reply->url(), &buff, &image, &errorString, &readSize, job->requestSize, job->data->providerOptions))
error = QQuickPixmapReply::Decoding;
}
// send completion event to the QQuickPixmapReply
@@ -657,9 +663,8 @@ void QQuickPixmapReader::processJobs()
PIXMAP_PROFILE(pixmapStateChanged<QQuickProfiler::PixmapLoadingStarted>(url));
- AutoTransform autoTransform = job->autoTransform;
locker.unlock();
- processJob(job, url, localFile, autoTransform, imageType, provider);
+ processJob(job, url, localFile, job->data->providerOptions, imageType, provider);
locker.relock();
}
}
@@ -671,27 +676,41 @@ void QQuickPixmapReader::processJobs()
}
void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &url, const QString &localFile,
- AutoTransform autoTransform, QQuickImageProvider::ImageType imageType, QQuickImageProvider *provider)
+ const QQuickImageProviderOptions &providerOptions,
+ QQuickImageProvider::ImageType imageType, QQuickImageProvider *provider)
{
// fetch
if (url.scheme() == QLatin1String("image")) {
// Use QQuickImageProvider
QSize readSize;
+ if (imageType == QQuickImageProvider::Invalid) {
+ QString errorStr = QQuickPixmap::tr("Invalid image provider: %1").arg(url.toString());
+ mutex.lock();
+ if (!cancelled.contains(runningJob))
+ runningJob->postReply(QQuickPixmapReply::Loading, errorStr, readSize, 0);
+ mutex.unlock();
+ return;
+ }
+
+ QQuickImageProviderWithOptions *providerV2 = provider->d->isProviderWithOptions ? static_cast<QQuickImageProviderWithOptions *>(provider)
+ : nullptr;
+
switch (imageType) {
case QQuickImageProvider::Invalid:
{
- QString errorStr = QQuickPixmap::tr("Invalid image provider: %1").arg(url.toString());
- mutex.lock();
- if (!cancelled.contains(runningJob))
- runningJob->postReply(QQuickPixmapReply::Loading, errorStr, readSize, 0);
- mutex.unlock();
+ // Already handled
break;
}
case QQuickImageProvider::Image:
{
- QImage image = provider->requestImage(imageId(url), &readSize, runningJob->requestSize);
+ QImage image;
+ if (providerV2) {
+ image = providerV2->requestImage(imageId(url), &readSize, runningJob->requestSize, providerOptions);
+ } else {
+ image = provider->requestImage(imageId(url), &readSize, runningJob->requestSize);
+ }
QQuickPixmapReply::ReadError errorCode = QQuickPixmapReply::NoError;
QString errorStr;
if (image.isNull()) {
@@ -707,7 +726,12 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
case QQuickImageProvider::Pixmap:
{
- const QPixmap pixmap = provider->requestPixmap(imageId(url), &readSize, runningJob->requestSize);
+ QPixmap pixmap;
+ if (providerV2) {
+ pixmap = providerV2->requestPixmap(imageId(url), &readSize, runningJob->requestSize, providerOptions);
+ } else {
+ pixmap = provider->requestPixmap(imageId(url), &readSize, runningJob->requestSize);
+ }
QQuickPixmapReply::ReadError errorCode = QQuickPixmapReply::NoError;
QString errorStr;
if (pixmap.isNull()) {
@@ -723,7 +747,12 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
case QQuickImageProvider::Texture:
{
- QQuickTextureFactory *t = provider->requestTexture(imageId(url), &readSize, runningJob->requestSize);
+ QQuickTextureFactory *t;
+ if (providerV2) {
+ t = providerV2->requestTexture(imageId(url), &readSize, runningJob->requestSize, providerOptions);
+ } else {
+ t = provider->requestTexture(imageId(url), &readSize, runningJob->requestSize);
+ }
QQuickPixmapReply::ReadError errorCode = QQuickPixmapReply::NoError;
QString errorStr;
if (!t) {
@@ -741,8 +770,13 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
case QQuickImageProvider::ImageResponse:
{
- QQuickAsyncImageProvider *asyncProvider = static_cast<QQuickAsyncImageProvider*>(provider);
- QQuickImageResponse *response = asyncProvider->requestImageResponse(imageId(url), runningJob->requestSize);
+ QQuickImageResponse *response;
+ if (providerV2) {
+ response = providerV2->requestImageResponse(imageId(url), runningJob->requestSize, providerOptions);
+ } else {
+ QQuickAsyncImageProvider *asyncProvider = static_cast<QQuickAsyncImageProvider*>(provider);
+ response = asyncProvider->requestImageResponse(imageId(url), runningJob->requestSize);
+ }
QObject::connect(response, SIGNAL(finished()), threadObject, SLOT(asyncResponseFinished()));
@@ -760,7 +794,7 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
QFile f(localFile);
QSize readSize;
if (f.open(QIODevice::ReadOnly)) {
- if (!readImage(url, &f, &image, &errorStr, &readSize, runningJob->requestSize, autoTransform))
+ if (!readImage(url, &f, &image, &errorStr, &readSize, runningJob->requestSize, providerOptions))
errorCode = QQuickPixmapReply::Loading;
} else {
errorStr = QQuickPixmap::tr("Cannot open: %1").arg(url.toString());
@@ -865,17 +899,17 @@ class QQuickPixmapKey
public:
const QUrl *url;
const QSize *size;
- AutoTransform autoTransform;
+ QQuickImageProviderOptions options;
};
inline bool operator==(const QQuickPixmapKey &lhs, const QQuickPixmapKey &rhs)
{
- return *lhs.size == *rhs.size && *lhs.url == *rhs.url && lhs.autoTransform == rhs.autoTransform;
+ return *lhs.size == *rhs.size && *lhs.url == *rhs.url && lhs.options == rhs.options;
}
inline uint qHash(const QQuickPixmapKey &key)
{
- return qHash(*key.url) ^ (key.size->width()*7) ^ (key.size->height()*17) ^ (key.autoTransform * 0x5c5c5c5c);
+ return qHash(*key.url) ^ (key.size->width()*7) ^ (key.size->height()*17) ^ (key.options.autoTransform() * 0x5c5c5c5c);
}
class QQuickPixmapStore : public QObject
@@ -891,7 +925,7 @@ public:
void purgeCache();
protected:
- virtual void timerEvent(QTimerEvent *);
+ void timerEvent(QTimerEvent *) override;
public:
QHash<QQuickPixmapKey, QQuickPixmapData *> m_cache;
@@ -1041,7 +1075,7 @@ void QQuickPixmap::purgeCache()
}
QQuickPixmapReply::QQuickPixmapReply(QQuickPixmapData *d)
-: data(d), engineForReader(0), requestSize(d->requestSize), url(d->url), loading(false), autoTransform(d->appliedTransform), redirectCount(0)
+: data(d), engineForReader(0), requestSize(d->requestSize), url(d->url), loading(false), redirectCount(0)
{
if (finishedIndex == -1) {
finishedIndex = QMetaMethod::fromSignal(&QQuickPixmapReply::finished).methodIndex();
@@ -1066,7 +1100,6 @@ bool QQuickPixmapReply::event(QEvent *event)
data->textureFactory = de->textureFactory;
de->textureFactory = 0;
data->implicitSize = de->implicitSize;
- data->appliedTransform = de->autoTransform;
PIXMAP_PROFILE(pixmapLoadingFinished(data->url,
data->textureFactory != 0 && data->textureFactory->textureSize().isValid() ?
data->textureFactory->textureSize() :
@@ -1137,7 +1170,7 @@ void QQuickPixmapData::release()
void QQuickPixmapData::addToCache()
{
if (!inCache) {
- QQuickPixmapKey key = { &url, &requestSize, requestedTransform };
+ QQuickPixmapKey key = { &url, &requestSize, providerOptions };
pixmapStore()->m_cache.insert(key, this);
inCache = true;
PIXMAP_PROFILE(pixmapCountChanged<QQuickProfiler::PixmapCacheCountChanged>(
@@ -1148,7 +1181,7 @@ void QQuickPixmapData::addToCache()
void QQuickPixmapData::removeFromCache()
{
if (inCache) {
- QQuickPixmapKey key = { &url, &requestSize, requestedTransform };
+ QQuickPixmapKey key = { &url, &requestSize, providerOptions };
pixmapStore()->m_cache.remove(key);
inCache = false;
PIXMAP_PROFILE(pixmapCountChanged<QQuickProfiler::PixmapCacheCountChanged>(
@@ -1156,7 +1189,7 @@ void QQuickPixmapData::removeFromCache()
}
}
-static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, QQmlEngine *engine, const QUrl &url, const QSize &requestSize, AutoTransform autoTransform, bool *ok)
+static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, QQmlEngine *engine, const QUrl &url, const QSize &requestSize, const QQuickImageProviderOptions &providerOptions, bool *ok)
{
if (url.scheme() == QLatin1String("image")) {
QSize readSize;
@@ -1168,14 +1201,14 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
switch (imageType) {
case QQuickImageProvider::Invalid:
- return new QQuickPixmapData(declarativePixmap, url, requestSize, autoTransform,
+ return new QQuickPixmapData(declarativePixmap, url, requestSize, providerOptions,
QQuickPixmap::tr("Invalid image provider: %1").arg(url.toString()));
case QQuickImageProvider::Texture:
{
QQuickTextureFactory *texture = provider->requestTexture(imageId(url), &readSize, requestSize);
if (texture) {
*ok = true;
- return new QQuickPixmapData(declarativePixmap, url, texture, readSize, requestSize, autoTransform, UsePluginDefault);
+ return new QQuickPixmapData(declarativePixmap, url, texture, readSize, requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform);
}
break;
}
@@ -1185,7 +1218,7 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
QImage image = provider->requestImage(imageId(url), &readSize, requestSize);
if (!image.isNull()) {
*ok = true;
- return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(image), readSize, requestSize, autoTransform, UsePluginDefault);
+ return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(image), readSize, requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform);
}
break;
}
@@ -1194,7 +1227,7 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
QPixmap pixmap = provider->requestPixmap(imageId(url), &readSize, requestSize);
if (!pixmap.isNull()) {
*ok = true;
- return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(pixmap.toImage()), readSize, requestSize, autoTransform, UsePluginDefault);
+ return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(pixmap.toImage()), readSize, requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform);
}
break;
}
@@ -1206,7 +1239,7 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
}
// provider has bad image type, or provider returned null image
- return new QQuickPixmapData(declarativePixmap, url, requestSize, autoTransform,
+ return new QQuickPixmapData(declarativePixmap, url, requestSize, providerOptions,
QQuickPixmap::tr("Failed to get image from provider: %1").arg(url.toString()));
}
@@ -1220,15 +1253,15 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
if (f.open(QIODevice::ReadOnly)) {
QImage image;
- AutoTransform appliedTransform = autoTransform;
- if (readImage(url, &f, &image, &errorString, &readSize, requestSize, appliedTransform)) {
+ QQuickImageProviderOptions::AutoTransform appliedTransform = providerOptions.autoTransform();
+ if (readImage(url, &f, &image, &errorString, &readSize, requestSize, providerOptions, &appliedTransform)) {
*ok = true;
- return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(image), readSize, requestSize, autoTransform, appliedTransform);
+ return new QQuickPixmapData(declarativePixmap, url, QQuickTextureFactory::textureFactoryForImage(image), readSize, requestSize, providerOptions, appliedTransform);
}
} else {
errorString = QQuickPixmap::tr("Cannot open: %1").arg(url.toString());
}
- return new QQuickPixmapData(declarativePixmap, url, requestSize, autoTransform, errorString);
+ return new QQuickPixmapData(declarativePixmap, url, requestSize, providerOptions, errorString);
}
@@ -1257,7 +1290,7 @@ QQuickPixmap::QQuickPixmap(QQmlEngine *engine, const QUrl &url, const QSize &siz
QQuickPixmap::QQuickPixmap(const QUrl &url, const QImage &image)
{
- d = new QQuickPixmapData(this, url, new QQuickDefaultTextureFactory(image), image.size(), QSize(), UsePluginDefault, UsePluginDefault);
+ d = new QQuickPixmapData(this, url, new QQuickDefaultTextureFactory(image), image.size(), QSize(), QQuickImageProviderOptions(), QQuickImageProviderOptions::UsePluginDefaultTransform);
d->addToCache();
}
@@ -1330,12 +1363,12 @@ const QSize &QQuickPixmap::requestSize() const
return nullPixmap()->size;
}
-AutoTransform QQuickPixmap::autoTransform() const
+QQuickImageProviderOptions::AutoTransform QQuickPixmap::autoTransform() const
{
if (d)
return d->appliedTransform;
else
- return UsePluginDefault;
+ return QQuickImageProviderOptions::UsePluginDefaultTransform;
}
QQuickTextureFactory *QQuickPixmap::textureFactory() const
@@ -1413,10 +1446,10 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &size)
void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &requestSize, QQuickPixmap::Options options)
{
- load(engine, url, requestSize, options, UsePluginDefault);
+ load(engine, url, requestSize, options, QQuickImageProviderOptions());
}
-void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &requestSize, QQuickPixmap::Options options, AutoTransform requestAutoTransform)
+void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &requestSize, QQuickPixmap::Options options, const QQuickImageProviderOptions &providerOptions)
{
if (d) {
d->declarativePixmaps.remove(this);
@@ -1424,14 +1457,21 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
d = 0;
}
- QQuickPixmapKey key = { &url, &requestSize, requestAutoTransform };
+ QQuickPixmapKey key = { &url, &requestSize, providerOptions };
QQuickPixmapStore *store = pixmapStore();
QHash<QQuickPixmapKey, QQuickPixmapData *>::Iterator iter = store->m_cache.end();
// If Cache is disabled, the pixmap will always be loaded, even if there is an existing
- // cached version.
- if (options & QQuickPixmap::Cache)
+ // cached version. Unless it's an itemgrabber url, since the cache is used to pass
+ // the result between QQuickItemGrabResult and QQuickImage.
+ if (url.scheme() == itemGrabberScheme) {
+ QSize dummy;
+ if (requestSize != dummy)
+ qWarning() << "Ignoring sourceSize request for image url that came from grabToImage. Use the targetSize parameter of the grabToImage() function instead.";
+ const QQuickPixmapKey grabberKey = { &url, &dummy, QQuickImageProviderOptions() };
+ iter = store->m_cache.find(grabberKey);
+ } else if (options & QQuickPixmap::Cache)
iter = store->m_cache.find(key);
if (iter == store->m_cache.end()) {
@@ -1450,7 +1490,7 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
if (!(options & QQuickPixmap::Asynchronous)) {
bool ok = false;
PIXMAP_PROFILE(pixmapStateChanged<QQuickProfiler::PixmapLoadingStarted>(url));
- d = createPixmapDataSync(this, engine, url, requestSize, requestAutoTransform, &ok);
+ d = createPixmapDataSync(this, engine, url, requestSize, providerOptions, &ok);
if (ok) {
PIXMAP_PROFILE(pixmapLoadingFinished(url, QSize(width(), height())));
if (options & QQuickPixmap::Cache)
@@ -1466,7 +1506,8 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
if (!engine)
return;
- d = new QQuickPixmapData(this, url, requestSize, requestAutoTransform, requestAutoTransform);
+
+ d = new QQuickPixmapData(this, url, requestSize, providerOptions, QQuickImageProviderOptions::UsePluginDefaultTransform);
if (options & QQuickPixmap::Cache)
d->addToCache();
@@ -1500,9 +1541,9 @@ void QQuickPixmap::clear(QObject *obj)
}
}
-bool QQuickPixmap::isCached(const QUrl &url, const QSize &requestSize)
+bool QQuickPixmap::isCached(const QUrl &url, const QSize &requestSize, const QQuickImageProviderOptions &options)
{
- QQuickPixmapKey key = { &url, &requestSize, UsePluginDefault };
+ QQuickPixmapKey key = { &url, &requestSize, options };
QQuickPixmapStore *store = pixmapStore();
return store->m_cache.contains(key);
diff --git a/src/quick/util/qquickpixmapcache_p.h b/src/quick/util/qquickpixmapcache_p.h
index f53e847e00..93d5a1cf56 100644
--- a/src/quick/util/qquickpixmapcache_p.h
+++ b/src/quick/util/qquickpixmapcache_p.h
@@ -65,28 +65,62 @@ QT_BEGIN_NAMESPACE
class QQmlEngine;
class QQuickPixmapData;
class QQuickTextureFactory;
-
-enum AutoTransform {
- UsePluginDefault = -1,
- ApplyTransform = 0,
- DoNotApplyTransform = 1
-};
+class QQuickImageProviderOptionsPrivate;
class QQuickDefaultTextureFactory : public QQuickTextureFactory
{
Q_OBJECT
public:
QQuickDefaultTextureFactory(const QImage &i);
- QSGTexture *createTexture(QQuickWindow *window) const;
- QSize textureSize() const { return size; }
- int textureByteCount() const { return size.width() * size.height() * 4; }
- QImage image() const { return im; }
+ QSGTexture *createTexture(QQuickWindow *window) const override;
+ QSize textureSize() const override { return size; }
+ int textureByteCount() const override { return size.width() * size.height() * 4; }
+ QImage image() const override { return im; }
private:
QImage im;
QSize size;
};
+class QQuickImageProviderPrivate
+{
+public:
+ QQuickImageProvider::ImageType type;
+ QQuickImageProvider::Flags flags;
+ bool isProviderWithOptions;
+};
+
+// ### Qt 6: Make public moving to qquickimageprovider.h
+class Q_QUICK_PRIVATE_EXPORT QQuickImageProviderOptions
+{
+public:
+ enum AutoTransform {
+ UsePluginDefaultTransform = -1,
+ ApplyTransform = 0,
+ DoNotApplyTransform = 1
+ };
+
+ QQuickImageProviderOptions();
+ ~QQuickImageProviderOptions();
+
+ QQuickImageProviderOptions(const QQuickImageProviderOptions&);
+ QQuickImageProviderOptions& operator=(const QQuickImageProviderOptions&);
+
+ bool operator==(const QQuickImageProviderOptions&) const;
+
+ AutoTransform autoTransform() const;
+ void setAutoTransform(AutoTransform autoTransform);
+
+ bool preserveAspectRatioCrop() const;
+ void setPreserveAspectRatioCrop(bool preserveAspectRatioCrop);
+
+ bool preserveAspectRatioFit() const;
+ void setPreserveAspectRatioFit(bool preserveAspectRatioFit);
+
+private:
+ QSharedDataPointer<QQuickImageProviderOptionsPrivate> d;
+};
+
class Q_QUICK_PRIVATE_EXPORT QQuickPixmap
{
Q_DECLARE_TR_FUNCTIONS(QQuickPixmap)
@@ -115,7 +149,7 @@ public:
const QUrl &url() const;
const QSize &implicitSize() const;
const QSize &requestSize() const;
- AutoTransform autoTransform() const;
+ QQuickImageProviderOptions::AutoTransform autoTransform() const;
QImage image() const;
void setImage(const QImage &);
void setPixmap(const QQuickPixmap &other);
@@ -130,7 +164,7 @@ public:
void load(QQmlEngine *, const QUrl &, QQuickPixmap::Options options);
void load(QQmlEngine *, const QUrl &, const QSize &);
void load(QQmlEngine *, const QUrl &, const QSize &, QQuickPixmap::Options options);
- void load(QQmlEngine *, const QUrl &, const QSize &, QQuickPixmap::Options options, AutoTransform autoTransform);
+ void load(QQmlEngine *, const QUrl &, const QSize &, QQuickPixmap::Options options, const QQuickImageProviderOptions &providerOptions);
void clear();
void clear(QObject *);
@@ -141,7 +175,9 @@ public:
bool connectDownloadProgress(QObject *, int);
static void purgeCache();
- static bool isCached(const QUrl &url, const QSize &requestSize);
+ static bool isCached(const QUrl &url, const QSize &requestSize, const QQuickImageProviderOptions &options);
+
+ static const QLatin1String itemGrabberScheme;
private:
Q_DISABLE_COPY(QQuickPixmap)
@@ -152,6 +188,24 @@ private:
Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPixmap::Options)
+// This class will disappear with Qt6 and will just be the regular QQuickImageProvider
+// ### Qt 6: Remove this class and fold it with QQuickImageProvider
+class Q_QUICK_PRIVATE_EXPORT QQuickImageProviderWithOptions : public QQuickAsyncImageProvider
+{
+public:
+ QQuickImageProviderWithOptions(ImageType type, Flags flags = Flags());
+
+ QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize) override;
+ QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize) override;
+ QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize) override;
+ QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
+
+ virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
+ virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize, const QQuickImageProviderOptions &options);
+ virtual QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options);
+ virtual QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize, const QQuickImageProviderOptions &options);
+};
+
QT_END_NAMESPACE
#endif // QQUICKPIXMAPCACHE_H
diff --git a/src/quick/util/qquickpropertychanges.cpp b/src/quick/util/qquickpropertychanges.cpp
index 3d51269bc9..20aa52e472 100644
--- a/src/quick/util/qquickpropertychanges.cpp
+++ b/src/quick/util/qquickpropertychanges.cpp
@@ -142,29 +142,29 @@ public:
QQuickReplaceSignalHandler() {}
~QQuickReplaceSignalHandler() {}
- virtual EventType type() const { return SignalHandler; }
+ EventType type() const override { return SignalHandler; }
QQmlProperty property;
QQmlBoundSignalExpressionPointer expression;
QQmlBoundSignalExpressionPointer reverseExpression;
QQmlBoundSignalExpressionPointer rewindExpression;
- virtual void execute() {
+ void execute() override {
QQmlPropertyPrivate::setSignalExpression(property, expression);
}
- virtual bool isReversable() { return true; }
- virtual void reverse() {
+ bool isReversable() override { return true; }
+ void reverse() override {
QQmlPropertyPrivate::setSignalExpression(property, reverseExpression);
}
- virtual void saveOriginals() {
+ void saveOriginals() override {
saveCurrentValues();
reverseExpression = rewindExpression;
}
- virtual bool needsCopy() { return true; }
- virtual void copyOriginals(QQuickStateActionEvent *other)
+ bool needsCopy() override { return true; }
+ void copyOriginals(QQuickStateActionEvent *other) override
{
QQuickReplaceSignalHandler *rsh = static_cast<QQuickReplaceSignalHandler*>(other);
saveCurrentValues();
@@ -173,14 +173,14 @@ public:
reverseExpression = rsh->reverseExpression;
}
- virtual void rewind() {
+ void rewind() override {
QQmlPropertyPrivate::setSignalExpression(property, rewindExpression);
}
- virtual void saveCurrentValues() {
+ void saveCurrentValues() override {
rewindExpression = QQmlPropertyPrivate::signalExpression(property);
}
- virtual bool override(QQuickStateActionEvent*other) {
+ bool override(QQuickStateActionEvent *other) override {
if (other == this)
return true;
if (other->type() != type())
@@ -397,10 +397,10 @@ QQuickPropertyChangesPrivate::property(const QString &property)
Q_Q(QQuickPropertyChanges);
QQmlProperty prop(object, property, qmlContext(q));
if (!prop.isValid()) {
- qmlInfo(q) << QQuickPropertyChanges::tr("Cannot assign to non-existent property \"%1\"").arg(property);
+ qmlWarning(q) << QQuickPropertyChanges::tr("Cannot assign to non-existent property \"%1\"").arg(property);
return QQmlProperty();
} else if (!(prop.type() & QQmlProperty::SignalProperty) && !prop.isWritable()) {
- qmlInfo(q) << QQuickPropertyChanges::tr("Cannot assign to read-only property \"%1\"").arg(property);
+ qmlWarning(q) << QQuickPropertyChanges::tr("Cannot assign to read-only property \"%1\"").arg(property);
return QQmlProperty();
}
return prop;
diff --git a/src/quick/util/qquickpropertychanges_p.h b/src/quick/util/qquickpropertychanges_p.h
index 0537750338..35b37e84cb 100644
--- a/src/quick/util/qquickpropertychanges_p.h
+++ b/src/quick/util/qquickpropertychanges_p.h
@@ -78,7 +78,7 @@ public:
bool isExplicit() const;
void setIsExplicit(bool);
- virtual ActionList actions();
+ ActionList actions() override;
bool containsProperty(const QString &name) const;
bool containsValue(const QString &name) const;
@@ -103,8 +103,8 @@ public:
void verifyList(const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding);
- virtual void verifyBindings(const QV4::CompiledData::Unit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &props);
- virtual void applyBindings(QObject *obj, QV4::CompiledData::CompilationUnit *compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings);
+ void verifyBindings(const QV4::CompiledData::Unit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &props) override;
+ void applyBindings(QObject *obj, QV4::CompiledData::CompilationUnit *compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) override;
};
diff --git a/src/quick/util/qquickshortcut.cpp b/src/quick/util/qquickshortcut.cpp
index 3e04161639..72d9c889e3 100644
--- a/src/quick/util/qquickshortcut.cpp
+++ b/src/quick/util/qquickshortcut.cpp
@@ -70,7 +70,10 @@
}
\endqml
- \sa Keys
+ It is also possible to set multiple shortcut \l sequences, so that the shortcut
+ can be \l activated via several different sequences of key presses.
+
+ \sa Keys, {Keys::}{shortcutOverride()}
*/
/*! \qmlsignal QtQuick::Shortcut::activated()
@@ -121,14 +124,23 @@ Q_QUICK_PRIVATE_EXPORT void qt_quick_set_shortcut_context_matcher(ContextMatcher
QT_BEGIN_NAMESPACE
-QQuickShortcut::QQuickShortcut(QObject *parent) : QObject(parent), m_id(0),
+static QKeySequence valueToKeySequence(const QVariant &value)
+{
+ if (value.type() == QVariant::Int)
+ return QKeySequence(static_cast<QKeySequence::StandardKey>(value.toInt()));
+ return QKeySequence::fromString(value.toString());
+}
+
+QQuickShortcut::QQuickShortcut(QObject *parent) : QObject(parent),
m_enabled(true), m_completed(false), m_autorepeat(true), m_context(Qt::WindowShortcut)
{
}
QQuickShortcut::~QQuickShortcut()
{
- ungrabShortcut();
+ ungrabShortcut(m_shortcut);
+ for (Shortcut &shortcut : m_shortcuts)
+ ungrabShortcut(shortcut);
}
/*!
@@ -147,31 +159,79 @@ QQuickShortcut::~QQuickShortcut()
onActivated: edit.wrapMode = TextEdit.Wrap
}
\endqml
+
+ \sa sequences
*/
QVariant QQuickShortcut::sequence() const
{
- return m_sequence;
+ return m_shortcut.userValue;
}
-void QQuickShortcut::setSequence(const QVariant &sequence)
+void QQuickShortcut::setSequence(const QVariant &value)
{
- if (sequence == m_sequence)
+ if (value == m_shortcut.userValue)
return;
- QKeySequence shortcut;
- if (sequence.type() == QVariant::Int)
- shortcut = QKeySequence(static_cast<QKeySequence::StandardKey>(sequence.toInt()));
- else
- shortcut = QKeySequence::fromString(sequence.toString());
+ QKeySequence keySequence = valueToKeySequence(value);
- grabShortcut(shortcut, m_context);
-
- m_sequence = sequence;
- m_shortcut = shortcut;
+ ungrabShortcut(m_shortcut);
+ m_shortcut.userValue = value;
+ m_shortcut.keySequence = keySequence;
+ grabShortcut(m_shortcut, m_context);
emit sequenceChanged();
}
/*!
+ \qmlproperty list<keysequence> QtQuick::Shortcut::sequences
+ \since 5.9
+
+ This property holds multiple key sequences for the shortcut. The key sequences
+ can be set to one of the \l{QKeySequence::StandardKey}{standard keyboard shortcuts},
+ or they can be described with strings containing sequences of up to four key
+ presses that are needed to \l{Shortcut::activated}{activate} the shortcut.
+
+ \qml
+ Shortcut {
+ sequences: [StandardKey.Cut, "Ctrl+X", "Shift+Del"]
+ onActivated: edit.cut()
+ }
+ \endqml
+*/
+QVariantList QQuickShortcut::sequences() const
+{
+ QVariantList values;
+ for (const Shortcut &shortcut : m_shortcuts)
+ values += shortcut.userValue;
+ return values;
+}
+
+void QQuickShortcut::setSequences(const QVariantList &values)
+{
+ QVector<Shortcut> remainder = m_shortcuts.mid(values.count());
+ m_shortcuts.resize(values.count());
+
+ bool changed = !remainder.isEmpty();
+ for (int i = 0; i < values.count(); ++i) {
+ QVariant value = values.at(i);
+ Shortcut& shortcut = m_shortcuts[i];
+ if (value == shortcut.userValue)
+ continue;
+
+ QKeySequence keySequence = valueToKeySequence(value);
+
+ ungrabShortcut(shortcut);
+ shortcut.userValue = value;
+ shortcut.keySequence = keySequence;
+ grabShortcut(shortcut, m_context);
+
+ changed = true;
+ }
+
+ if (changed)
+ emit sequencesChanged();
+}
+
+/*!
\qmlproperty string QtQuick::Shortcut::nativeText
\since 5.6
@@ -184,7 +244,7 @@ void QQuickShortcut::setSequence(const QVariant &sequence)
*/
QString QQuickShortcut::nativeText() const
{
- return m_shortcut.toString(QKeySequence::NativeText);
+ return m_shortcut.keySequence.toString(QKeySequence::NativeText);
}
/*!
@@ -199,7 +259,7 @@ QString QQuickShortcut::nativeText() const
*/
QString QQuickShortcut::portableText() const
{
- return m_shortcut.toString(QKeySequence::PortableText);
+ return m_shortcut.keySequence.toString(QKeySequence::PortableText);
}
/*!
@@ -219,8 +279,9 @@ void QQuickShortcut::setEnabled(bool enabled)
if (enabled == m_enabled)
return;
- if (m_id)
- QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(enabled, m_id, this);
+ setEnabled(m_shortcut, enabled);
+ for (Shortcut &shortcut : m_shortcuts)
+ setEnabled(shortcut, enabled);
m_enabled = enabled;
emit enabledChanged();
@@ -243,8 +304,9 @@ void QQuickShortcut::setAutoRepeat(bool repeat)
if (repeat == m_autorepeat)
return;
- if (m_id)
- QGuiApplicationPrivate::instance()->shortcutMap.setShortcutAutoRepeat(repeat, m_id, this);
+ setAutoRepeat(m_shortcut, repeat);
+ for (Shortcut &shortcut : m_shortcuts)
+ setAutoRepeat(shortcut, repeat);
m_autorepeat = repeat;
emit autoRepeatChanged();
@@ -279,9 +341,9 @@ void QQuickShortcut::setContext(Qt::ShortcutContext context)
if (context == m_context)
return;
- grabShortcut(m_shortcut, context);
-
+ ungrabShortcut(m_shortcut);
m_context = context;
+ grabShortcut(m_shortcut, context);
emit contextChanged();
}
@@ -293,13 +355,19 @@ void QQuickShortcut::componentComplete()
{
m_completed = true;
grabShortcut(m_shortcut, m_context);
+ for (Shortcut &shortcut : m_shortcuts)
+ grabShortcut(shortcut, m_context);
}
bool QQuickShortcut::event(QEvent *event)
{
if (m_enabled && event->type() == QEvent::Shortcut) {
QShortcutEvent *se = static_cast<QShortcutEvent *>(event);
- if (se->shortcutId() == m_id && se->key() == m_shortcut){
+ bool match = m_shortcut.matches(se);
+ int i = 0;
+ while (!match && i < m_shortcuts.count())
+ match |= m_shortcuts.at(i++).matches(se);
+ if (match) {
if (se->isAmbiguous())
emit activatedAmbiguously();
else
@@ -310,25 +378,40 @@ bool QQuickShortcut::event(QEvent *event)
return false;
}
-void QQuickShortcut::grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context)
+bool QQuickShortcut::Shortcut::matches(QShortcutEvent *event) const
{
- ungrabShortcut();
+ return event->shortcutId() == id && event->key() == keySequence;
+}
+
+void QQuickShortcut::setEnabled(QQuickShortcut::Shortcut &shortcut, bool enabled)
+{
+ if (shortcut.id)
+ QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(enabled, shortcut.id, this);
+}
- if (m_completed && !sequence.isEmpty()) {
+void QQuickShortcut::setAutoRepeat(QQuickShortcut::Shortcut &shortcut, bool repeat)
+{
+ if (shortcut.id)
+ QGuiApplicationPrivate::instance()->shortcutMap.setShortcutAutoRepeat(repeat, shortcut.id, this);
+}
+
+void QQuickShortcut::grabShortcut(Shortcut &shortcut, Qt::ShortcutContext context)
+{
+ if (m_completed && !shortcut.keySequence.isEmpty()) {
QGuiApplicationPrivate *pApp = QGuiApplicationPrivate::instance();
- m_id = pApp->shortcutMap.addShortcut(this, sequence, context, *ctxMatcher());
+ shortcut.id = pApp->shortcutMap.addShortcut(this, shortcut.keySequence, context, *ctxMatcher());
if (!m_enabled)
- pApp->shortcutMap.setShortcutEnabled(false, m_id, this);
+ pApp->shortcutMap.setShortcutEnabled(false, shortcut.id, this);
if (!m_autorepeat)
- pApp->shortcutMap.setShortcutAutoRepeat(false, m_id, this);
+ pApp->shortcutMap.setShortcutAutoRepeat(false, shortcut.id, this);
}
}
-void QQuickShortcut::ungrabShortcut()
+void QQuickShortcut::ungrabShortcut(Shortcut &shortcut)
{
- if (m_id) {
- QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(m_id, this);
- m_id = 0;
+ if (shortcut.id) {
+ QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(shortcut.id, this);
+ shortcut.id = 0;
}
}
diff --git a/src/quick/util/qquickshortcut_p.h b/src/quick/util/qquickshortcut_p.h
index b3f33a33c1..93430ad893 100644
--- a/src/quick/util/qquickshortcut_p.h
+++ b/src/quick/util/qquickshortcut_p.h
@@ -52,17 +52,21 @@
//
#include <QtCore/qobject.h>
+#include <QtCore/qvector.h>
#include <QtCore/qvariant.h>
#include <QtGui/qkeysequence.h>
#include <QtQml/qqmlparserstatus.h>
QT_BEGIN_NAMESPACE
+class QShortcutEvent;
+
class QQuickShortcut : public QObject, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(QVariant sequence READ sequence WRITE setSequence NOTIFY sequenceChanged FINAL)
+ Q_PROPERTY(QVariantList sequences READ sequences WRITE setSequences NOTIFY sequencesChanged FINAL REVISION 9)
Q_PROPERTY(QString nativeText READ nativeText NOTIFY sequenceChanged FINAL REVISION 1)
Q_PROPERTY(QString portableText READ portableText NOTIFY sequenceChanged FINAL REVISION 1)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL)
@@ -76,6 +80,9 @@ public:
QVariant sequence() const;
void setSequence(const QVariant &sequence);
+ QVariantList sequences() const;
+ void setSequences(const QVariantList &sequences);
+
QString nativeText() const;
QString portableText() const;
@@ -90,6 +97,7 @@ public:
Q_SIGNALS:
void sequenceChanged();
+ Q_REVISION(9) void sequencesChanged();
void enabledChanged();
void autoRepeatChanged();
void contextChanged();
@@ -102,17 +110,26 @@ protected:
void componentComplete() Q_DECL_OVERRIDE;
bool event(QEvent *event) Q_DECL_OVERRIDE;
- void grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context);
- void ungrabShortcut();
+ struct Shortcut {
+ bool matches(QShortcutEvent *event) const;
+ int id;
+ QVariant userValue;
+ QKeySequence keySequence;
+ };
+
+ void setEnabled(Shortcut &shortcut, bool enabled);
+ void setAutoRepeat(Shortcut &shortcut, bool repeat);
+
+ void grabShortcut(Shortcut &shortcut, Qt::ShortcutContext context);
+ void ungrabShortcut(Shortcut &shortcut);
private:
- int m_id;
bool m_enabled;
bool m_completed;
bool m_autorepeat;
- QKeySequence m_shortcut;
Qt::ShortcutContext m_context;
- QVariant m_sequence;
+ Shortcut m_shortcut;
+ QVector<Shortcut> m_shortcuts;
};
QT_END_NAMESPACE
diff --git a/src/quick/util/qquicksmoothedanimation_p.h b/src/quick/util/qquicksmoothedanimation_p.h
index d640985b39..2f0e3bc0d8 100644
--- a/src/quick/util/qquicksmoothedanimation_p.h
+++ b/src/quick/util/qquicksmoothedanimation_p.h
@@ -79,8 +79,8 @@ public:
ReversingMode reversingMode() const;
void setReversingMode(ReversingMode);
- virtual int duration() const;
- virtual void setDuration(int);
+ int duration() const override;
+ void setDuration(int) override;
qreal velocity() const;
void setVelocity(qreal);
@@ -88,10 +88,10 @@ public:
int maximumEasingTime() const;
void setMaximumEasingTime(int);
- virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
+ QAbstractAnimationJob* transition(QQuickStateActions &actions,
QQmlProperties &modified,
TransitionDirection direction,
- QObject *defaultTarget = 0);
+ QObject *defaultTarget = 0) override;
Q_SIGNALS:
void velocityChanged();
void reversingModeChanged();
diff --git a/src/quick/util/qquicksmoothedanimation_p_p.h b/src/quick/util/qquicksmoothedanimation_p_p.h
index 4a61599592..a415fdb55f 100644
--- a/src/quick/util/qquicksmoothedanimation_p_p.h
+++ b/src/quick/util/qquicksmoothedanimation_p_p.h
@@ -93,7 +93,7 @@ public:
QQmlProperty target;
- int duration() const;
+ int duration() const override;
void restart();
void init();
@@ -101,9 +101,9 @@ public:
void clearTemplate() { animationTemplate = 0; }
protected:
- virtual void updateCurrentTime(int);
- virtual void updateState(QAbstractAnimationJob::State, QAbstractAnimationJob::State);
- void debugAnimation(QDebug d) const;
+ void updateCurrentTime(int) override;
+ void updateState(QAbstractAnimationJob::State, QAbstractAnimationJob::State) override;
+ void debugAnimation(QDebug d) const override;
private:
qreal easeFollow(qreal);
diff --git a/src/quick/util/qquickspringanimation.cpp b/src/quick/util/qquickspringanimation.cpp
index 294122150a..a9940959a0 100644
--- a/src/quick/util/qquickspringanimation.cpp
+++ b/src/quick/util/qquickspringanimation.cpp
@@ -61,7 +61,7 @@ public:
QSpringAnimation(QQuickSpringAnimationPrivate * = 0);
~QSpringAnimation();
- int duration() const;
+ int duration() const override;
void restart();
void init();
@@ -97,9 +97,9 @@ public:
void clearTemplate() { animationTemplate = 0; }
protected:
- virtual void updateCurrentTime(int time);
- virtual void updateState(QAbstractAnimationJob::State, QAbstractAnimationJob::State);
- void debugAnimation(QDebug d) const;
+ void updateCurrentTime(int time) override;
+ void updateState(QAbstractAnimationJob::State, QAbstractAnimationJob::State) override;
+ void debugAnimation(QDebug d) const override;
private:
QQuickSpringAnimationPrivate *animationTemplate;
diff --git a/src/quick/util/qquickspringanimation_p.h b/src/quick/util/qquickspringanimation_p.h
index 141a2469d7..ffb2c41e6b 100644
--- a/src/quick/util/qquickspringanimation_p.h
+++ b/src/quick/util/qquickspringanimation_p.h
@@ -94,10 +94,10 @@ public:
qreal modulus() const;
void setModulus(qreal modulus);
- virtual QAbstractAnimationJob* transition(QQuickStateActions &actions,
+ QAbstractAnimationJob* transition(QQuickStateActions &actions,
QQmlProperties &modified,
TransitionDirection direction,
- QObject *defaultTarget = 0);
+ QObject *defaultTarget = 0) override;
Q_SIGNALS:
void modulusChanged();
diff --git a/src/quick/util/qquickstate_p_p.h b/src/quick/util/qquickstate_p_p.h
index af97390efb..eba1dabecf 100644
--- a/src/quick/util/qquickstate_p_p.h
+++ b/src/quick/util/qquickstate_p_p.h
@@ -217,7 +217,7 @@ public:
setObject(static_cast<QQuickStateOperation *>(obj));
}
QList<OperationGuard> *list;
- void objectDestroyed(QQuickStateOperation *) {
+ void objectDestroyed(QQuickStateOperation *) override {
// we assume priv will always be destroyed after objectDestroyed calls
list->removeOne(*this);
}
diff --git a/src/quick/util/qquickstatechangescript.cpp b/src/quick/util/qquickstatechangescript.cpp
index 86b70fe879..a70fa1a676 100644
--- a/src/quick/util/qquickstatechangescript.cpp
+++ b/src/quick/util/qquickstatechangescript.cpp
@@ -131,7 +131,7 @@ void QQuickStateChangeScript::execute()
QQmlExpression expr(d->script);
expr.evaluate();
if (expr.hasError())
- qmlInfo(this, expr.error());
+ qmlWarning(this, expr.error());
}
}
diff --git a/src/quick/util/qquickstatechangescript_p.h b/src/quick/util/qquickstatechangescript_p.h
index 0c17b7c68c..a1315ae2ef 100644
--- a/src/quick/util/qquickstatechangescript_p.h
+++ b/src/quick/util/qquickstatechangescript_p.h
@@ -69,9 +69,9 @@ public:
QQuickStateChangeScript(QObject *parent=0);
~QQuickStateChangeScript();
- virtual ActionList actions();
+ ActionList actions() override;
- virtual EventType type() const;
+ EventType type() const override;
QQmlScriptString script() const;
void setScript(const QQmlScriptString &);
@@ -79,7 +79,7 @@ public:
QString name() const;
void setName(const QString &);
- virtual void execute();
+ void execute() override;
};
diff --git a/src/quick/util/qquickstategroup.cpp b/src/quick/util/qquickstategroup.cpp
index 200f243a1b..f2cd4638fc 100644
--- a/src/quick/util/qquickstategroup.cpp
+++ b/src/quick/util/qquickstategroup.cpp
@@ -438,7 +438,7 @@ void QQuickStateGroupPrivate::setCurrentStateInternal(const QString &state,
}
if (applyingState) {
- qmlInfo(q) << "Can't apply a state change as part of a state definition.";
+ qmlWarning(q) << "Can't apply a state change as part of a state definition.";
return;
}
diff --git a/src/quick/util/qquickstategroup_p.h b/src/quick/util/qquickstategroup_p.h
index 78508ac166..eebe3a9e56 100644
--- a/src/quick/util/qquickstategroup_p.h
+++ b/src/quick/util/qquickstategroup_p.h
@@ -81,8 +81,8 @@ public:
QQuickState *findState(const QString &name) const;
void removeState(QQuickState *state);
- virtual void classBegin();
- virtual void componentComplete();
+ void classBegin() override;
+ void componentComplete() override;
Q_SIGNALS:
void stateChanged(const QString &);
diff --git a/src/quick/util/qquickstyledtext.cpp b/src/quick/util/qquickstyledtext.cpp
index 4139c87eda..ae8719341d 100644
--- a/src/quick/util/qquickstyledtext.cpp
+++ b/src/quick/util/qquickstyledtext.cpp
@@ -721,8 +721,7 @@ void QQuickStyledTextPrivate::parseImageAttributes(const QChar *&ch, const QStri
QString padding(qFloor(imgWidth / spaceWidth), QChar::Nbsp);
if (!trailingSpace)
textOut += QLatin1Char(' ');
- textOut += padding;
- textOut += QLatin1Char(' ');
+ textOut += padding + QLatin1Char(' ');
}
QPair<QStringRef,QStringRef> QQuickStyledTextPrivate::parseAttribute(const QChar *&ch, const QString &textIn)
diff --git a/src/quick/util/qquicktimeline_p_p.h b/src/quick/util/qquicktimeline_p_p.h
index 552f194b79..ae1087487b 100644
--- a/src/quick/util/qquicktimeline_p_p.h
+++ b/src/quick/util/qquicktimeline_p_p.h
@@ -100,14 +100,14 @@ public:
int time() const;
- virtual int duration() const;
+ int duration() const override;
Q_SIGNALS:
void updated();
void completed();
protected:
- virtual void updateCurrentTime(int);
- void debugAnimation(QDebug d) const;
+ void updateCurrentTime(int) override;
+ void debugAnimation(QDebug d) const override;
private:
void remove(QQuickTimeLineObject *);
@@ -181,7 +181,7 @@ public:
Q_ASSERT(_class);
}
- virtual void setValue(qreal v)
+ void setValue(qreal v) override
{
QQuickTimeLineValue::setValue(v);
if (_setFunctionReal) (_class->*_setFunctionReal)(v);
diff --git a/src/quick/util/qquicktransition.cpp b/src/quick/util/qquicktransition.cpp
index c8b5482c87..1d258d84bf 100644
--- a/src/quick/util/qquicktransition.cpp
+++ b/src/quick/util/qquicktransition.cpp
@@ -106,7 +106,7 @@ public:
QQuickTransitionManager *manager;
protected:
- virtual void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState);
+ void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) override;
};
class QQuickTransitionPrivate : public QObjectPrivate, QAnimationJobChangeListener
@@ -134,7 +134,7 @@ public:
bool reversible;
bool enabled;
protected:
- virtual void animationStateChanged(QAbstractAnimationJob *, QAbstractAnimationJob::State, QAbstractAnimationJob::State);
+ void animationStateChanged(QAbstractAnimationJob *, QAbstractAnimationJob::State, QAbstractAnimationJob::State) override;
static void append_animation(QQmlListProperty<QQuickAbstractAnimation> *list, QQuickAbstractAnimation *a);
static int animation_count(QQmlListProperty<QQuickAbstractAnimation> *list);
diff --git a/src/quick/util/qquickutilmodule.cpp b/src/quick/util/qquickutilmodule.cpp
index 5728ad608e..b2e5b84cf4 100644
--- a/src/quick/util/qquickutilmodule.cpp
+++ b/src/quick/util/qquickutilmodule.cpp
@@ -129,5 +129,7 @@ void QQuickUtilModule::defineModule()
#if QT_CONFIG(shortcut)
qmlRegisterType<QQuickShortcut>("QtQuick", 2, 5, "Shortcut");
qmlRegisterType<QQuickShortcut,1>("QtQuick", 2, 6, "Shortcut");
+
+ qmlRegisterType<QQuickShortcut,9>("QtQuick", 2, 9, "Shortcut");
#endif
}
diff --git a/src/quick/util/qquickvaluetypes.cpp b/src/quick/util/qquickvaluetypes.cpp
index e673df0451..4afcb07a5c 100644
--- a/src/quick/util/qquickvaluetypes.cpp
+++ b/src/quick/util/qquickvaluetypes.cpp
@@ -56,8 +56,7 @@ namespace QQuickValueTypes {
QString QQuickColorValueType::toString() const
{
- // to maintain behaviour with QtQuick 1.0, we just output normal toString() value.
- return QVariant(v).toString();
+ return v.name(v.alpha() != 255 ? QColor::HexArgb : QColor::HexRgb);
}
qreal QQuickColorValueType::r() const
diff --git a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/data/test.qml b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/data/test.qml
index a36d0cae91..0fa9f1ffd8 100644
--- a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/data/test.qml
+++ b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/data/test.qml
@@ -36,6 +36,7 @@ Item {
var b = {a: "hello", d: 1 }
var c
var d = 12
+ console.log("Component.onCompleted");
}
function foo() {
var a = [1, 2]
diff --git a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp
index 8d1a165243..3aa3a5c87e 100644
--- a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp
+++ b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp
@@ -142,24 +142,36 @@ void tst_QQmlDebuggingEnabler::cleanup()
void tst_QQmlDebuggingEnabler::data()
{
+ QTest::addColumn<QString>("connector");
QTest::addColumn<bool>("blockMode");
QTest::addColumn<QStringList>("services");
- QTest::newRow("noblock,all") << false << QStringList();
- QTest::newRow("block,all") << true << QStringList();
- QTest::newRow("noblock,debugger") << false << QQmlDebuggingEnabler::debuggerServices();
- QTest::newRow("block,debugger") << true << QQmlDebuggingEnabler::debuggerServices();
- QTest::newRow("noblock,inspector") << false << QQmlDebuggingEnabler::inspectorServices();
- QTest::newRow("block,inspector") << true << QQmlDebuggingEnabler::inspectorServices();
- QTest::newRow("noblock,profiler") << false << QQmlDebuggingEnabler::profilerServices();
- QTest::newRow("block,profiler") << true << QQmlDebuggingEnabler::profilerServices();
- QTest::newRow("noblock,debugger+inspector")
- << false << QQmlDebuggingEnabler::debuggerServices() +
- QQmlDebuggingEnabler::inspectorServices();
- QTest::newRow("block,debugger+inspector")
- << true << QQmlDebuggingEnabler::debuggerServices() +
- QQmlDebuggingEnabler::inspectorServices();
-
+ QStringList connectors({
+ QLatin1String("QQmlDebugServer"),
+ QLatin1String("QQmlNativeDebugConnector")
+ });
+
+ QList<bool> blockModes({ true, false });
+
+ QList<QStringList> serviceLists({
+ QStringList(),
+ QQmlDebuggingEnabler::nativeDebuggerServices(),
+ QQmlDebuggingEnabler::debuggerServices(),
+ QQmlDebuggingEnabler::inspectorServices(),
+ QQmlDebuggingEnabler::profilerServices(),
+ QQmlDebuggingEnabler::debuggerServices() + QQmlDebuggingEnabler::inspectorServices()
+ });
+
+ foreach (const QString &connector, connectors) {
+ foreach (bool blockMode, blockModes) {
+ foreach (const QStringList &serviceList, serviceLists) {
+ QString name = connector + QLatin1Char(',')
+ + QLatin1String(blockMode ? "block" : "noblock") + QLatin1Char(',')
+ + serviceList.join(QLatin1Char('-'));
+ QTest::newRow(name.toUtf8().constData()) << connector << blockMode << serviceList;
+ }
+ }
+ }
}
void tst_QQmlDebuggingEnabler::qmlscene_data()
@@ -169,27 +181,36 @@ void tst_QQmlDebuggingEnabler::qmlscene_data()
void tst_QQmlDebuggingEnabler::qmlscene()
{
+ QFETCH(QString, connector);
QFETCH(bool, blockMode);
QFETCH(QStringList, services);
- connection = new QQmlDebugConnection();
- QList<QQmlDebugClient *> clients = QQmlDebugTest::createOtherClients(connection);
process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene",
this);
process->setMaximumBindErrors(1);
process->start(QStringList()
- << QString::fromLatin1("-qmljsdebugger=port:5555,5565%1%2%3")
+ << QString::fromLatin1("-qmljsdebugger=connector:%1%2%3%4")
+ .arg(connector + (connector == QLatin1String("QQmlDebugServer") ?
+ QLatin1String(",port:5555,5565") : QString()))
.arg(blockMode ? QLatin1String(",block") : QString())
.arg(services.isEmpty() ? QString() : QString::fromLatin1(",services:"))
.arg(services.isEmpty() ? QString() : services.join(","))
<< testFile(QLatin1String("test.qml")));
- QVERIFY(process->waitForSessionStart());
- connection->connectToHost("127.0.0.1", process->debugPort());
- QVERIFY(connection->waitForConnected());
- foreach (QQmlDebugClient *client, clients)
- QCOMPARE(client->state(), (services.isEmpty() || services.contains(client->name())) ?
- QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable);
+ if (connector == QLatin1String("QQmlDebugServer")) {
+ QVERIFY(process->waitForSessionStart());
+ connection = new QQmlDebugConnection();
+ QList<QQmlDebugClient *> clients = QQmlDebugTest::createOtherClients(connection);
+ connection->connectToHost("127.0.0.1", process->debugPort());
+ QVERIFY(connection->waitForConnected());
+ foreach (QQmlDebugClient *client, clients)
+ QCOMPARE(client->state(), (services.isEmpty() || services.contains(client->name())) ?
+ QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable);
+ }
+
+ QCOMPARE(process->state(), QLatin1String("running"));
+ if (!blockMode)
+ QTRY_VERIFY(process->output().contains(QLatin1String("qml: Component.onCompleted")));
}
void tst_QQmlDebuggingEnabler::custom_data()
@@ -199,13 +220,12 @@ void tst_QQmlDebuggingEnabler::custom_data()
void tst_QQmlDebuggingEnabler::custom()
{
+ QFETCH(QString, connector);
QFETCH(bool, blockMode);
QFETCH(QStringList, services);
const int portFrom = 5555;
const int portTo = 5565;
- connection = new QQmlDebugConnection();
- QList<QQmlDebugClient *> clients = QQmlDebugTest::createOtherClients(connection);
process = new QQmlDebugProcess(QCoreApplication::applicationDirPath() +
QLatin1String("/qqmldebuggingenablerserver"), this);
process->setMaximumBindErrors(portTo - portFrom);
@@ -214,18 +234,28 @@ void tst_QQmlDebuggingEnabler::custom()
if (blockMode)
args << QLatin1String("-block");
- args << QString::number(portFrom) << QString::number(portTo);
+ args << QLatin1String("-connector") << connector
+ << QString::number(portFrom) << QString::number(portTo);
+
if (!services.isEmpty())
args << QLatin1String("-services") << services;
process->start(args);
- QVERIFY(process->waitForSessionStart());
- connection->connectToHost("127.0.0.1", process->debugPort());
- QVERIFY(connection->waitForConnected());
- foreach (QQmlDebugClient *client, clients)
- QCOMPARE(client->state(), (services.isEmpty() || services.contains(client->name())) ?
- QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable);
+ if (connector == QLatin1String("QQmlDebugServer")) {
+ QVERIFY(process->waitForSessionStart());
+ connection = new QQmlDebugConnection();
+ QList<QQmlDebugClient *> clients = QQmlDebugTest::createOtherClients(connection);
+ connection->connectToHost("127.0.0.1", process->debugPort());
+ QVERIFY(connection->waitForConnected());
+ foreach (QQmlDebugClient *client, clients)
+ QCOMPARE(client->state(), (services.isEmpty() || services.contains(client->name())) ?
+ QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable);
+ }
+
+ QCOMPARE(process->state(), QLatin1String("running"));
+ if (!blockMode)
+ QTRY_VERIFY(process->output().contains(QLatin1String("QQmlEngine created")));
}
QTEST_MAIN(tst_QQmlDebuggingEnabler)
diff --git a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenablerserver/qqmldebuggingenablerserver.cpp b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenablerserver/qqmldebuggingenablerserver.cpp
index cfbb31f9e1..a064bbbacc 100644
--- a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenablerserver/qqmldebuggingenablerserver.cpp
+++ b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenablerserver/qqmldebuggingenablerserver.cpp
@@ -28,6 +28,7 @@
#include <QtCore/qcoreapplication.h>
#include <QtCore/qlibraryinfo.h>
+#include <QtCore/qdebug.h>
#include <QtQml/qqmldebug.h>
#include <QtQml/qqmlengine.h>
@@ -40,12 +41,18 @@ int main(int argc, char *argv[])
QCoreApplication app(argc, argv);
QStringList arguments = app.arguments();
arguments.removeFirst();
+ QString connector = QLatin1String("QQmlDebugServer");
if (arguments.size() && arguments.first() == QLatin1String("-block")) {
block = QQmlDebuggingEnabler::WaitForClient;
arguments.removeFirst();
}
+ if (arguments.size() >= 2 && arguments.first() == QLatin1String("-connector")) {
+ arguments.removeFirst();
+ connector = arguments.takeFirst();
+ }
+
if (arguments.size() >= 2) {
portFrom = arguments.takeFirst().toInt();
portTo = arguments.takeFirst().toInt();
@@ -54,12 +61,20 @@ int main(int argc, char *argv[])
if (arguments.size() && arguments.takeFirst() == QLatin1String("-services"))
QQmlDebuggingEnabler::setServices(arguments);
- if (!portFrom || !portTo)
- qFatal("Port range has to be specified.");
+ if (connector == QLatin1String("QQmlDebugServer")) {
+ if (!portFrom || !portTo)
+ qFatal("Port range has to be specified.");
+
+ while (portFrom <= portTo)
+ QQmlDebuggingEnabler::startTcpDebugServer(portFrom++, block);
+ } else if (connector == QLatin1String("QQmlNativeDebugConnector")) {
+ QVariantHash configuration;
+ configuration[QLatin1String("block")] = (block == QQmlDebuggingEnabler::WaitForClient);
+ QQmlDebuggingEnabler::startDebugConnector(connector, configuration);
+ }
- while (portFrom <= portTo)
- QQmlDebuggingEnabler::startTcpDebugServer(portFrom++, block);
QQmlEngine engine;
+ qDebug() << "QQmlEngine created\n";
Q_UNUSED(engine);
return app.exec();
}
diff --git a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro
index 79e772c1ee..cbaf3b5309 100644
--- a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro
+++ b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/qqmldebugjs.pro
@@ -9,6 +9,7 @@ SOURCES += tst_qqmldebugjs.cpp
INCLUDEPATH += ../../shared
include(../../../../shared/util.pri)
include(../../shared/debugutil.pri)
+include(../../shared/qqmlenginedebugclient.pri)
TESTDATA = data/*
diff --git a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp
index d1150be831..31b8d63ec2 100644
--- a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp
+++ b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp
@@ -27,6 +27,7 @@
****************************************************************************/
#include "debugutil_p.h"
+#include "../../shared/qqmlenginedebugclient.h"
#include "../../../../shared/util.h"
#include <private/qqmldebugclient_p.h>
@@ -52,6 +53,7 @@ const char *STEPACTION = "stepaction";
const char *STEPCOUNT = "stepcount";
const char *EXPRESSION = "expression";
const char *FRAME = "frame";
+const char *CONTEXT = "context";
const char *GLOBAL = "global";
const char *DISABLEBREAK = "disable_break";
const char *HANDLES = "handles";
@@ -215,6 +217,8 @@ private slots:
void evaluateInLocalScope_data() { targetData(); }
void evaluateInLocalScope();
+ void evaluateInContext();
+
void getScripts_data() { targetData(); }
void getScripts();
@@ -257,7 +261,7 @@ public:
void interrupt();
void continueDebugging(StepAction stepAction);
- void evaluate(QString expr, int frame = -1);
+ void evaluate(QString expr, int frame = -1, int context = -1);
void lookup(QList<int> handles, bool includeSource = false);
void backtrace(int fromFrame = -1, int toFrame = -1, bool bottom = false);
void frame(int number = -1);
@@ -280,6 +284,7 @@ signals:
void connected();
void interruptRequested();
void result();
+ void failure();
void stopped();
private:
@@ -340,13 +345,14 @@ void QJSDebugClient::continueDebugging(StepAction action)
sendMessage(packMessage(V8REQUEST, json.toString().toUtf8()));
}
-void QJSDebugClient::evaluate(QString expr, int frame)
+void QJSDebugClient::evaluate(QString expr, int frame, int context)
{
// { "seq" : <number>,
// "type" : "request",
// "command" : "evaluate",
// "arguments" : { "expression" : <expression to evaluate>,
- // "frame" : <number>
+ // "frame" : <number>,
+ // "context" : <object ID>
// }
// }
VARIANTMAPINIT;
@@ -358,6 +364,9 @@ void QJSDebugClient::evaluate(QString expr, int frame)
if (frame != -1)
args.setProperty(QLatin1String(FRAME),QJSValue(frame));
+ if (context != -1)
+ args.setProperty(QLatin1String(CONTEXT), QJSValue(context));
+
if (!args.isUndefined()) {
jsonVal.setProperty(QLatin1String(ARGUMENTS),args);
}
@@ -684,6 +693,7 @@ void QJSDebugClient::messageReceived(const QByteArray &data)
if (type == "response") {
if (!value.value("success").toBool()) {
+ emit failure();
qDebug() << "Received success == false response from application";
return;
}
@@ -1394,6 +1404,58 @@ void tst_QQmlDebugJS::evaluateInLocalScope()
QCOMPARE(body.value("value").toInt(),10);
}
+void tst_QQmlDebugJS::evaluateInContext()
+{
+ connection = new QQmlDebugConnection();
+ process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath)
+ + "/qmlscene", this);
+ client = new QJSDebugClient(connection);
+ QScopedPointer<QQmlEngineDebugClient> engineClient(new QQmlEngineDebugClient(connection));
+ process->start(QStringList() << QLatin1String(BLOCKMODE) << testFile(ONCOMPLETED_QMLFILE));
+
+ QVERIFY(process->waitForSessionStart());
+
+ connection->connectToHost("127.0.0.1", process->debugPort());
+ QVERIFY(connection->waitForConnected());
+
+ QTRY_COMPARE(client->state(), QQmlEngineDebugClient::Enabled);
+ QTRY_COMPARE(engineClient->state(), QQmlEngineDebugClient::Enabled);
+ client->connect();
+
+ // "a" not accessible without extra context
+ client->evaluate(QLatin1String("a + 10"), -1, -1);
+ QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(failure())));
+
+ bool success = false;
+ engineClient->queryAvailableEngines(&success);
+ QVERIFY(success);
+ QVERIFY(QQmlDebugTest::waitForSignal(engineClient.data(), SIGNAL(result())));
+
+ QVERIFY(engineClient->engines().count());
+ engineClient->queryRootContexts(engineClient->engines()[0].debugId, &success);
+ QVERIFY(success);
+ QVERIFY(QQmlDebugTest::waitForSignal(engineClient.data(), SIGNAL(result())));
+
+ auto contexts = engineClient->rootContext().contexts;
+ QCOMPARE(contexts.count(), 1);
+ auto objects = contexts[0].objects;
+ QCOMPARE(objects.count(), 1);
+ engineClient->queryObjectRecursive(objects[0], &success);
+ QVERIFY(success);
+ QVERIFY(QQmlDebugTest::waitForSignal(engineClient.data(), SIGNAL(result())));
+ auto object = engineClient->object();
+
+ // "a" accessible in context of surrounding object
+ client->evaluate(QLatin1String("a + 10"), -1, object.debugId);
+ QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result())));
+
+ QString jsonString = client->response;
+ QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap();
+
+ QVariantMap body = value.value("body").toMap();
+ QTRY_COMPARE(body.value("value").toInt(), 20);
+}
+
void tst_QQmlDebugJS::getScripts()
{
//void scripts(int types = -1, QList<int> ids = QList<int>(), bool includeSource = false, QVariant filter = QVariant());
diff --git a/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp
index a503da4e4b..8d21a8a45a 100644
--- a/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp
+++ b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp
@@ -51,12 +51,6 @@ private:
QQmlDebugConnection *m_conn;
QQmlDebugTestService *m_service;
- bool connect();
-
-signals:
- void waiting();
- void parallel();
-
private slots:
void initTestCase();
@@ -75,12 +69,13 @@ void tst_QQmlDebugLocal::initTestCase()
const QString waitingMsg = QString("QML Debugger: Connecting to socket %1...").arg(fileName);
QTest::ignoreMessage(QtDebugMsg, waitingMsg.toLatin1().constData());
+ QQmlDebuggingEnabler::connectToLocalDebugger(fileName);
+
+ QTest::qWait(1000);
m_conn = new QQmlDebugConnection(this);
m_conn->startLocalServer(fileName);
- QQmlDebuggingEnabler::connectToLocalDebugger(fileName);
-
new QQmlEngine(this);
QQmlDebugTestClient client("tst_QQmlDebugLocal::handshake()", m_conn);
diff --git a/tests/auto/qml/debugger/qqmlinspector/data/qtquick2.qml b/tests/auto/qml/debugger/qqmlinspector/data/qtquick2.qml
index f44c653840..f43cff15e4 100644
--- a/tests/auto/qml/debugger/qqmlinspector/data/qtquick2.qml
+++ b/tests/auto/qml/debugger/qqmlinspector/data/qtquick2.qml
@@ -29,16 +29,15 @@ Rectangle {
}
var milliDelta = millis - prevHit;
- if (milliDelta < 0)
+ if (milliDelta <= 0)
milliDelta += 1000;
- console.log(milliDelta, "milliseconds ");
prevHit = millis;
var delta = parent.rotation - prevRotation;
if (delta < 0)
delta += 360
prevRotation = parent.rotation
- console.log(delta, "degrees ");
+ console.log(milliDelta, delta, "ms/degrees ");
}
}
}
diff --git a/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp b/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp
index f55fef232e..9461922eff 100644
--- a/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp
+++ b/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp
@@ -102,29 +102,46 @@ void tst_QQmlInspector::startQmlProcess(const QString &qmlFile, bool restrictSer
void tst_QQmlInspector::checkAnimationSpeed(int targetMillisPerDegree)
{
- QString degreesString = QStringLiteral("degrees");
- QString millisecondsString = QStringLiteral("milliseconds");
- for (int i = 0; i < 2; ++i) { // skip one period; the change might have happened inside it
- int position = m_process->output().length();
- while (!m_process->output().mid(position).contains(degreesString) ||
- !m_process->output().mid(position).contains(millisecondsString)) {
+ const QString markerString = QStringLiteral("ms/degrees");
+
+ // Funny things can happen with time and VMs. Also the change might take a while to propagate.
+ // Thus, we wait until we either have 3 passes or 3 failures in a row, or 10 loops have passed.
+
+ int numFailures = 0;
+ int numPasses = 0;
+
+ for (int i = 0; i < 10; ++i) {
+ QString output = m_process->output();
+ int position = output.length();
+ do {
QVERIFY(QQmlDebugTest::waitForSignal(m_process.data(),
SIGNAL(readyReadStandardOutput())));
+ output = m_process->output();
+ } while (!output.mid(position).contains(markerString));
+
+
+ QStringList words = output.split(QLatin1Char(' '));
+ const int marker = words.lastIndexOf(markerString);
+ QVERIFY(marker > 1);
+ const double degrees = words[marker - 1].toDouble();
+ const int milliseconds = words[marker - 2].toInt();
+ const double millisecondsPerDegree = milliseconds / degrees;
+
+ if (millisecondsPerDegree > targetMillisPerDegree - 3
+ || millisecondsPerDegree < targetMillisPerDegree + 3) {
+ if (++numPasses == 3)
+ return; // pass
+ numFailures = 0;
+ } else {
+ QVERIFY2(++numFailures < 3,
+ QString("3 consecutive failures when checking for %1 milliseconds per degree")
+ .arg(targetMillisPerDegree).toLocal8Bit().constData());
+ numPasses = 0;
}
}
- QStringList words = m_process->output().split(QLatin1Char(' '));
- int degreesMarker = words.lastIndexOf(degreesString);
- QVERIFY(degreesMarker > 1);
- double degrees = words[degreesMarker - 1].toDouble();
- int millisecondsMarker = words.lastIndexOf(millisecondsString);
- QVERIFY(millisecondsMarker > 1);
- int milliseconds = words[millisecondsMarker - 1].toInt();
-
- double millisecondsPerDegree = milliseconds / degrees;
- QVERIFY(millisecondsPerDegree > targetMillisPerDegree - 3);
- QVERIFY(millisecondsPerDegree < targetMillisPerDegree + 3);
-
+ QFAIL(QString("Animation speed won't settle to %1 milliseconds per degree")
+ .arg(targetMillisPerDegree).toLocal8Bit().constData());
}
void tst_QQmlInspector::cleanup()
diff --git a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp
index a23b7e37eb..6793596174 100644
--- a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp
+++ b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp
@@ -41,6 +41,7 @@
#include <private/qv4isel_moth_p.h>
#include <private/qv4string_p.h>
#include <private/qqmlbuiltinfunctions_p.h>
+#include <private/qqmldebugservice_p.h>
using namespace QV4;
using namespace QV4::Debugging;
@@ -203,8 +204,8 @@ public slots:
while (!m_expressionRequests.isEmpty()) {
Q_ASSERT(debugger->state() == QV4Debugger::Paused);
ExpressionRequest request = m_expressionRequests.takeFirst();
- ExpressionEvalJob job(debugger->engine(), request.frameNr, request.expression,
- &collector);
+ ExpressionEvalJob job(debugger->engine(), request.frameNr, request.context,
+ request.expression, &collector);
debugger->runInEngine(&job);
m_expressionResults << job.returnValue();
m_expressionRefs << job.refs();
@@ -276,6 +277,7 @@ public:
struct ExpressionRequest {
QString expression;
int frameNr;
+ int context;
};
QVector<ExpressionRequest> m_expressionRequests;
QList<QJsonObject> m_expressionResults;
@@ -726,24 +728,34 @@ void tst_qv4debugger::evaluateExpression()
TestAgent::ExpressionRequest request;
request.expression = "x";
request.frameNr = 0;
+ request.context = -1; // no extra context
m_debuggerAgent->m_expressionRequests << request;
request.expression = "x";
request.frameNr = 1;
m_debuggerAgent->m_expressionRequests << request;
+ request.context = 5355; // invalid context object
+ m_debuggerAgent->m_expressionRequests << request;
+
+ QObject object; // some object without QML context
+ request.context = QQmlDebugService::idForObject(&object);
+ m_debuggerAgent->m_expressionRequests << request;
+
debugger()->addBreakPoint("evaluateExpression", 3);
evaluateJavaScript(script, "evaluateExpression");
- QCOMPARE(m_debuggerAgent->m_expressionRefs.count(), 2);
+ QCOMPARE(m_debuggerAgent->m_expressionRefs.count(), 4);
QCOMPARE(m_debuggerAgent->m_expressionRefs[0].size(), 1);
QJsonObject result0 = m_debuggerAgent->m_expressionRefs[0].first().toObject();
QCOMPARE(result0.value("type").toString(), QStringLiteral("number"));
QCOMPARE(result0.value("value").toInt(), 10);
- QCOMPARE(m_debuggerAgent->m_expressionRefs[1].size(), 1);
- QJsonObject result1 = m_debuggerAgent->m_expressionRefs[1].first().toObject();
- QCOMPARE(result1.value("type").toString(), QStringLiteral("number"));
- QCOMPARE(result1.value("value").toInt(), 20);
+ for (int i = 1; i < 4; ++i) {
+ QCOMPARE(m_debuggerAgent->m_expressionRefs[i].size(), 1);
+ QJsonObject result1 = m_debuggerAgent->m_expressionRefs[1].first().toObject();
+ QCOMPARE(result1.value("type").toString(), QStringLiteral("number"));
+ QCOMPARE(result1.value("value").toInt(), 20);
+ }
}
QTEST_MAIN(tst_qv4debugger)
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index 52df4c0642..82bc3d0c59 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -1040,6 +1040,8 @@ void tst_QJSEngine::builtinFunctionNames_data()
QTest::newRow("Array.prototype.toString") << QString("Array.prototype.toString") << QString("toString");
QTest::newRow("Array.prototype.toLocaleString") << QString("Array.prototype.toLocaleString") << QString("toLocaleString");
QTest::newRow("Array.prototype.concat") << QString("Array.prototype.concat") << QString("concat");
+ QTest::newRow("Array.prototype.find") << QString("Array.prototype.find") << QString("find");
+ QTest::newRow("Array.prototype.findIndex") << QString("Array.prototype.findIndex") << QString("findIndex");
QTest::newRow("Array.prototype.join") << QString("Array.prototype.join") << QString("join");
QTest::newRow("Array.prototype.pop") << QString("Array.prototype.pop") << QString("pop");
QTest::newRow("Array.prototype.push") << QString("Array.prototype.push") << QString("push");
@@ -2149,12 +2151,27 @@ void tst_QJSEngine::jsNumberClass()
QJSValue ret = eng.evaluate("new Number(123).toExponential()");
QVERIFY(ret.isString());
QCOMPARE(ret.toString(), QString::fromLatin1("1.23e+2"));
+ ret = eng.evaluate("new Number(123).toExponential(1)");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString::fromLatin1("1.2e+2"));
+ ret = eng.evaluate("new Number(123).toExponential(2)");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString::fromLatin1("1.23e+2"));
+ ret = eng.evaluate("new Number(123).toExponential(3)");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString::fromLatin1("1.230e+2"));
}
QVERIFY(proto.property("toFixed").isCallable());
{
QJSValue ret = eng.evaluate("new Number(123).toFixed()");
QVERIFY(ret.isString());
QCOMPARE(ret.toString(), QString::fromLatin1("123"));
+ ret = eng.evaluate("new Number(123).toFixed(1)");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString::fromLatin1("123.0"));
+ ret = eng.evaluate("new Number(123).toFixed(2)");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString::fromLatin1("123.00"));
}
QVERIFY(proto.property("toPrecision").isCallable());
{
diff --git a/tests/auto/qml/qqmlapplicationengine/data/LocalComponent.qml b/tests/auto/qml/qqmlapplicationengine/data/LocalComponent.qml
new file mode 100644
index 0000000000..ece4f45b4a
--- /dev/null
+++ b/tests/auto/qml/qqmlapplicationengine/data/LocalComponent.qml
@@ -0,0 +1,6 @@
+import QtQml 2.0
+
+// used in nonResolvedLocal
+QtObject {
+
+}
diff --git a/tests/auto/qml/qqmlapplicationengine/data/nonResolvedLocal.qml b/tests/auto/qml/qqmlapplicationengine/data/nonResolvedLocal.qml
new file mode 100644
index 0000000000..45a235346d
--- /dev/null
+++ b/tests/auto/qml/qqmlapplicationengine/data/nonResolvedLocal.qml
@@ -0,0 +1,9 @@
+import QtQml 2.0
+
+QtObject {
+ property bool success: true
+
+ property QtObject local: LocalComponent {
+ }
+}
+
diff --git a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp
index 98b92e5fab..74add85cb0 100644
--- a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp
+++ b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp
@@ -42,6 +42,7 @@ public:
private slots:
void initTestCase();
void basicLoading();
+ void testNonResolvedPath();
void application();
void applicationProperties();
private:
@@ -83,6 +84,29 @@ void tst_qqmlapplicationengine::basicLoading()
delete test;
}
+// make sure we resolve a relative URL to an absolute one, otherwise things
+// will break.
+void tst_qqmlapplicationengine::testNonResolvedPath()
+{
+ {
+ // NOTE NOTE NOTE! Missing testFileUrl is *WANTED* here! We want a
+ // non-resolved URL.
+ QQmlApplicationEngine test("data/nonResolvedLocal.qml");
+ QCOMPARE(test.rootObjects().size(), 1);
+ QVERIFY(test.rootObjects()[0]);
+ QVERIFY(test.rootObjects()[0]->property("success").toBool());
+ }
+ {
+ QQmlApplicationEngine test;
+ // NOTE NOTE NOTE! Missing testFileUrl is *WANTED* here! We want a
+ // non-resolved URL.
+ test.load("data/nonResolvedLocal.qml");
+ QCOMPARE(test.rootObjects().size(), 1);
+ QVERIFY(test.rootObjects()[0]);
+ QVERIFY(test.rootObjects()[0]->property("success").toBool());
+ }
+}
+
void tst_qqmlapplicationengine::application()
{
/* This test batches together some tests about running an external application
diff --git a/tests/auto/qml/qqmldirparser/data/classname/qmldir b/tests/auto/qml/qqmldirparser/data/classname/qmldir
new file mode 100644
index 0000000000..8167e813df
--- /dev/null
+++ b/tests/auto/qml/qqmldirparser/data/classname/qmldir
@@ -0,0 +1,5 @@
+module QtQuick
+plugin qtquick2plugin
+classname QtQuick2Plugin
+typeinfo plugins.qmltypes
+designersupported
diff --git a/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp b/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp
index 7d154d0ea6..3643ca65c6 100644
--- a/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp
+++ b/tests/auto/qml/qqmldirparser/tst_qqmldirparser.cpp
@@ -325,6 +325,15 @@ void tst_qqmldirparser::parse_data()
<< QStringList()
<< (QStringList() << "bar||1|0|true")
<< false;
+
+ QTest::newRow("classname")
+ << "classname/qmldir"
+ << QStringList()
+ << (QStringList() << "qtquick2plugin|")
+ << QStringList()
+ << QStringList()
+ << QStringList()
+ << true;
}
void tst_qqmldirparser::parse()
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp
index d9ddcd71a7..63c2918325 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.cpp
+++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp
@@ -515,6 +515,8 @@ void registerTypes()
qmlRegisterType<QObjectContainer>("Qt.test", 1, 0, "QObjectContainer");
qmlRegisterType<QObjectContainerWithGCOnAppend>("Qt.test", 1, 0, "QObjectContainerWithGCOnAppend");
qmlRegisterType<FloatingQObject>("Qt.test", 1, 0, "FloatingQObject");
+
+ qmlRegisterType<ClashingNames>("Qt.test", 1, 0, "ClashingNames");
}
#include "testtypes.moc"
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h
index 1f7f3344ef..eedeb66647 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.h
+++ b/tests/auto/qml/qqmlecmascript/testtypes.h
@@ -1714,6 +1714,14 @@ public:
virtual void componentComplete();
};
+class ClashingNames : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool clashes READ clashes CONSTANT)
+public:
+ Q_INVOKABLE bool clashes() const { return true; }
+};
+
void registerTypes();
#endif // TESTTYPES_H
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 20f7940e9d..b5df8307c0 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -46,6 +46,7 @@
#include <private/qv4runtime_p.h>
#include <private/qv4object_p.h>
#include <private/qqmlcomponentattached_p.h>
+#include <private/qv4objectiterator_p.h>
#ifdef Q_CC_MSVC
#define NO_INLINE __declspec(noinline)
@@ -260,6 +261,7 @@ private slots:
void nonNotifyable();
void deleteWhileBindingRunning();
void callQtInvokables();
+ void resolveClashingProperties();
void invokableObjectArg();
void invokableObjectRet();
void invokableEnumRet();
@@ -331,6 +333,9 @@ private slots:
void qtbug_54589();
void qtbug_54687();
void stringify_qtbug_50592();
+ void instanceof_data();
+ void instanceof();
+ void freeze_empty_object();
private:
// static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
@@ -2984,6 +2989,48 @@ void tst_qqmlecmascript::callQtInvokables()
QVERIFY(callback.isCallable());
}
+void tst_qqmlecmascript::resolveClashingProperties()
+{
+ ClashingNames *o = new ClashingNames();
+ QQmlEngine qmlengine;
+ QQmlEnginePrivate *ep = QQmlEnginePrivate::get(&qmlengine);
+
+ QV4::ExecutionEngine *engine = QV8Engine::getV4(ep->v8engine());
+ QV4::Scope scope(engine);
+
+ QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(engine, o));
+ QV4::ObjectIterator it(scope, object->as<QV4::Object>(), QV4::ObjectIterator::EnumerableOnly);
+ QV4::ScopedValue name(scope);
+ QV4::ScopedValue value(scope);
+
+ bool seenProperty = false;
+ bool seenMethod = false;
+ while (true) {
+ QV4::Value v;
+ name = it.nextPropertyNameAsString(&v);
+ if (name->isNull())
+ break;
+ QString key = name->toQStringNoThrow();
+ if (key == QLatin1String("clashes")) {
+ value = v;
+ QV4::ScopedValue typeString(scope, QV4::Runtime::method_typeofValue(engine, value));
+ QString type = typeString->toQStringNoThrow();
+ if (type == QLatin1String("boolean")) {
+ QVERIFY(!seenProperty);
+ seenProperty = true;
+ } else if (type == QLatin1String("function")) {
+ QVERIFY(!seenMethod);
+ seenMethod = true;
+ } else {
+ QFAIL(qPrintable(QString::fromLatin1("found 'clashes' property of type %1")
+ .arg(type)));
+ }
+ }
+ }
+ QVERIFY(seenProperty);
+ QVERIFY(seenMethod);
+}
+
// QTBUG-13047 (check that you can pass registered object types as args)
void tst_qqmlecmascript::invokableObjectArg()
{
@@ -8119,6 +8166,81 @@ void tst_qqmlecmascript::stringify_qtbug_50592()
QCOMPARE(obj->property("source").toString(), QString::fromLatin1("http://example.org/some_nonexistant_image.png"));
}
+void tst_qqmlecmascript::instanceof_data()
+{
+ QTest::addColumn<QString>("setupCode");
+ QTest::addColumn<QVariant>("expectedValue");
+
+ // so the way this works is that the name of the test tag defines the test
+ // to run. the code in setupCode defines code run before the actual test
+ // (e.g. to create vars).
+ //
+ // the expectedValue is either a boolean true or false for whether the two
+ // operands are indeed an instanceof each other, or a string for the
+ // expected error message.
+ QTest::newRow("String instanceof String")
+ << ""
+ << QVariant(false);
+ QTest::newRow("s instanceof String")
+ << "var s = \"hello\""
+ << QVariant(false);
+ QTest::newRow("objectString instanceof String")
+ << "var objectString = new String(\"hello\")"
+ << QVariant(true);
+ QTest::newRow("o instanceof Object")
+ << "var o = new Object()"
+ << QVariant(true);
+ QTest::newRow("o instanceof String")
+ << "var o = new Object()"
+ << QVariant(false);
+ QTest::newRow("true instanceof true")
+ << ""
+ << QVariant("TypeError: Type error");
+ QTest::newRow("1 instanceof Math")
+ << ""
+ << QVariant("TypeError: Type error");
+ QTest::newRow("date instanceof Date")
+ << "var date = new Date"
+ << QVariant(true);
+ QTest::newRow("date instanceof Object")
+ << "var date = new Date"
+ << QVariant(true);
+ QTest::newRow("date instanceof String")
+ << "var date = new Date"
+ << QVariant(false);
+}
+
+void tst_qqmlecmascript::instanceof()
+{
+ QFETCH(QString, setupCode);
+ QFETCH(QVariant, expectedValue);
+
+ QJSEngine engine;
+ QJSValue ret = engine.evaluate(setupCode + ";\n" + QTest::currentDataTag());
+
+ if (expectedValue.type() == QMetaType::Bool) {
+ bool returnValue = ret.toBool();
+ QVERIFY2(!ret.isError(), qPrintable(ret.toString()));
+ QCOMPARE(returnValue, expectedValue.toBool());
+ } else {
+ QVERIFY2(ret.isError(), qPrintable(ret.toString()));
+ QCOMPARE(ret.toString(), expectedValue.toString());
+ }
+}
+
+void tst_qqmlecmascript::freeze_empty_object()
+{
+ // this shouldn't crash
+ QJSEngine engine;
+ QJSValue v = engine.evaluate(QString::fromLatin1(
+ "var obj = {};\n"
+ "Object.freeze(obj);\n"
+ ));
+ QVERIFY(!v.isError());
+ QCOMPARE(v.toBool(), true);
+}
+
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"
diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
index 9c155eda5b..e170920486 100644
--- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
+++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
@@ -56,6 +56,7 @@ private slots:
void baseUrl();
void contextForObject();
void offlineStoragePath();
+ void offlineDatabaseStoragePath();
void clearComponentCache();
void trimComponentCache();
void trimComponentCache_data();
@@ -252,6 +253,34 @@ void tst_qqmlengine::offlineStoragePath()
QCOMPARE(engine.offlineStoragePath(), QDir::homePath());
}
+void tst_qqmlengine::offlineDatabaseStoragePath()
+{
+ // Without these set, QDesktopServices::storageLocation returns
+ // strings with extra "//" at the end. We set them to ignore this problem.
+ qApp->setApplicationName("tst_qqmlengine");
+ qApp->setOrganizationName("QtProject");
+ qApp->setOrganizationDomain("www.qt-project.org");
+
+ QQmlEngine engine;
+ QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
+ const QString databaseName = QLatin1String("foo");
+ QString databaseLocation = engine.offlineStorageDatabaseFilePath(databaseName);
+ QCOMPARE(dataLocation.isEmpty(), databaseLocation.isEmpty());
+
+ QDir dir(dataLocation);
+ dir.mkpath("QML");
+ dir.cd("QML");
+ dir.mkpath("OfflineStorage");
+ dir.cd("OfflineStorage");
+ dir.mkpath("Databases");
+ dir.cd("Databases");
+ QCOMPARE(QFileInfo(databaseLocation).dir().path(), dir.path());
+
+ QCryptographicHash md5(QCryptographicHash::Md5);
+ md5.addData(databaseName.toUtf8());
+ QCOMPARE(databaseLocation, QDir::toNativeSeparators(dir.filePath(QLatin1String(md5.result().toHex()))));
+}
+
void tst_qqmlengine::clearComponentCache()
{
QQmlEngine engine;
diff --git a/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp b/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp
index acda06c8d8..3f6c200027 100644
--- a/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp
+++ b/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp
@@ -49,6 +49,7 @@ private slots:
void nonQmlContextedObject();
void types();
void chaining();
+ void messageTypes();
private:
QQmlEngine engine;
@@ -62,14 +63,14 @@ void tst_qqmlinfo::qmlObject()
QVERIFY(object != 0);
QString message = component.url().toString() + ":3:1: QML QtObject: Test Message";
- QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
+ QTest::ignoreMessage(QtInfoMsg, qPrintable(message));
qmlInfo(object) << "Test Message";
QObject *nested = qvariant_cast<QObject *>(object->property("nested"));
QVERIFY(nested != 0);
message = component.url().toString() + ":6:13: QML QtObject: Second Test Message";
- QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
+ QTest::ignoreMessage(QtInfoMsg, qPrintable(message));
qmlInfo(nested) << "Second Test Message";
}
@@ -86,11 +87,11 @@ void tst_qqmlinfo::nestedQmlObject()
QVERIFY(nested2 != 0);
QString message = component.url().toString() + ":5:13: QML NestedObject: Outer Object";
- QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
+ QTest::ignoreMessage(QtInfoMsg, qPrintable(message));
qmlInfo(nested) << "Outer Object";
message = testFileUrl("NestedObject.qml").toString() + ":6:14: QML QtObject: Inner Object";
- QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
+ QTest::ignoreMessage(QtInfoMsg, qPrintable(message));
qmlInfo(nested2) << "Inner Object";
}
@@ -107,28 +108,28 @@ void tst_qqmlinfo::nestedComponent()
QVERIFY(nested2 != 0);
QString message = component.url().toString() + ":10:9: QML NestedObject: Complex Object";
- QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
+ QTest::ignoreMessage(QtInfoMsg, qPrintable(message));
qmlInfo(nested) << "Complex Object";
message = component.url().toString() + ":16:9: QML Image: Simple Object";
- QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
+ QTest::ignoreMessage(QtInfoMsg, qPrintable(message));
qmlInfo(nested2) << "Simple Object";
}
void tst_qqmlinfo::nonQmlObject()
{
QObject object;
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: QML QtObject: Test Message");
qmlInfo(&object) << "Test Message";
QTimer nonQmlObject;
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QTimer: Test Message");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: QML QTimer: Test Message");
qmlInfo(&nonQmlObject) << "Test Message";
}
void tst_qqmlinfo::nullObject()
{
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Null Object Test Message");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: Null Object Test Message");
qmlInfo(0) << "Null Object Test Message";
}
@@ -137,50 +138,50 @@ void tst_qqmlinfo::nonQmlContextedObject()
QObject object;
QQmlContext context(&engine);
QQmlEngine::setContextForObject(&object, &context);
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML QtObject: Test Message");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: QML QtObject: Test Message");
qmlInfo(&object) << "Test Message";
}
void tst_qqmlinfo::types()
{
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: false");
qmlInfo(0) << false;
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.1");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: 1.1");
qmlInfo(0) << 1.1;
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 1.2");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: 1.2");
qmlInfo(0) << 1.2f;
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 15");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: 15");
qmlInfo(0) << 15;
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: 'b'");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: 'b'");
qmlInfo(0) << QChar('b');
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: \"Qt\"");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: \"Qt\"");
qmlInfo(0) << QByteArray("Qt");
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: true");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: true");
qmlInfo(0) << bool(true);
//### do we actually want QUrl to show up in the output?
//### why the extra space at the end?
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QUrl(\"http://www.qt-project.org\") ");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: QUrl(\"http://www.qt-project.org\") ");
qmlInfo(0) << QUrl("http://www.qt-project.org");
//### should this be quoted?
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: hello");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: hello");
qmlInfo(0) << QLatin1String("hello");
//### should this be quoted?
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: World");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: World");
QString str("Hello World");
QStringRef ref(&str, 6, 5);
qmlInfo(0) << ref;
//### should this be quoted?
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Quick");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: Quick");
qmlInfo(0) << QString ("Quick");
}
@@ -188,7 +189,7 @@ void tst_qqmlinfo::chaining()
{
QString str("Hello World");
QStringRef ref(&str, 6, 5);
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: false 1.1 1.2 15 hello 'b' World \"Qt\" true Quick QUrl(\"http://www.qt-project.org\") ");
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: false 1.1 1.2 15 hello 'b' World \"Qt\" true Quick QUrl(\"http://www.qt-project.org\") ");
qmlInfo(0) << false << ' '
<< 1.1 << ' '
<< 1.2f << ' '
@@ -202,6 +203,19 @@ void tst_qqmlinfo::chaining()
<< QUrl("http://www.qt-project.org");
}
+// Ensure that messages of different types are sent with the correct QtMsgType.
+void tst_qqmlinfo::messageTypes()
+{
+ QTest::ignoreMessage(QtDebugMsg, "<Unknown File>: debug");
+ qmlDebug(0) << QLatin1String("debug");
+
+ QTest::ignoreMessage(QtInfoMsg, "<Unknown File>: info");
+ qmlInfo(0) << QLatin1String("info");
+
+ QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: warning");
+ qmlWarning(0) << QLatin1String("warning");
+}
+
QTEST_MAIN(tst_qqmlinfo)
#include "tst_qqmlinfo.moc"
diff --git a/tests/auto/qml/qqmllanguage/data/compositeTypeByName_anon_qmldir.qml b/tests/auto/qml/qqmllanguage/data/compositeTypeByName_anon_qmldir.qml
new file mode 100644
index 0000000000..5ffdc26096
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/compositeTypeByName_anon_qmldir.qml
@@ -0,0 +1,9 @@
+import QtQuick 2.6
+import "simpleimportByName"
+
+Item {
+ Component.onCompleted: {
+ console.warn(SimpleType)
+ }
+}
+
diff --git a/tests/auto/qml/qqmllanguage/data/compositeTypeByName_named_qmldir.qml b/tests/auto/qml/qqmllanguage/data/compositeTypeByName_named_qmldir.qml
new file mode 100644
index 0000000000..c446eae84c
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/compositeTypeByName_named_qmldir.qml
@@ -0,0 +1,9 @@
+import QtQuick 2.6
+import "simpleimportByName" as ImportName
+
+Item {
+ Component.onCompleted: {
+ console.warn(ImportName.SimpleType)
+ }
+}
+
diff --git a/tests/auto/qml/qqmllanguage/data/quickTypeByName_anon.qml b/tests/auto/qml/qqmllanguage/data/quickTypeByName_anon.qml
new file mode 100644
index 0000000000..abe750db33
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/quickTypeByName_anon.qml
@@ -0,0 +1,8 @@
+import QtQuick 2.6
+
+Item {
+ Component.onCompleted: {
+ console.warn(Item)
+ }
+}
+
diff --git a/tests/auto/qml/qqmllanguage/data/quickTypeByName_named.qml b/tests/auto/qml/qqmllanguage/data/quickTypeByName_named.qml
new file mode 100644
index 0000000000..397d4f42f0
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/quickTypeByName_named.qml
@@ -0,0 +1,8 @@
+import QtQuick 2.6 as Quick
+
+Quick.Item {
+ Quick.Component.onCompleted: {
+ console.warn(Quick.Item)
+ }
+}
+
diff --git a/tests/auto/qml/qqmllanguage/data/simpleimportByName/SimpleType.qml b/tests/auto/qml/qqmllanguage/data/simpleimportByName/SimpleType.qml
new file mode 100644
index 0000000000..4772dde8f0
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/simpleimportByName/SimpleType.qml
@@ -0,0 +1,4 @@
+import QtQuick 2.6
+
+MouseArea {
+}
diff --git a/tests/auto/qml/qqmllanguage/data/simpleimportByName/qmldir b/tests/auto/qml/qqmllanguage/data/simpleimportByName/qmldir
new file mode 100644
index 0000000000..80df37d0e6
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/simpleimportByName/qmldir
@@ -0,0 +1 @@
+SimpleType 1.0 SimpleType.qml
diff --git a/tests/auto/qml/qqmllanguage/testtypes.cpp b/tests/auto/qml/qqmllanguage/testtypes.cpp
index bc8c192a61..bdcdaa8137 100644
--- a/tests/auto/qml/qqmllanguage/testtypes.cpp
+++ b/tests/auto/qml/qqmllanguage/testtypes.cpp
@@ -87,6 +87,10 @@ void registerTypes()
qmlRegisterUncreatableType<MyUncreateableBaseClass,1>("Test", 1, 1, "MyUncreateableBaseClass", "Cannot create MyUncreateableBaseClass");
qmlRegisterType<MyCreateableDerivedClass,1>("Test", 1, 1, "MyCreateableDerivedClass");
+ qmlRegisterExtendedUncreatableType<MyExtendedUncreateableBaseClass, MyExtendedUncreateableBaseClassExtension>("Test", 1, 0, "MyExtendedUncreateableBaseClass", "Cannot create MyExtendedUncreateableBaseClass");
+ qmlRegisterExtendedUncreatableType<MyExtendedUncreateableBaseClass, MyExtendedUncreateableBaseClassExtension, 1>("Test", 1, 1, "MyExtendedUncreateableBaseClass", "Cannot create MyExtendedUncreateableBaseClass");
+ qmlRegisterType<MyExtendedCreateableDerivedClass>("Test", 1, 0, "MyExtendedCreateableDerivedClass");
+
qmlRegisterCustomType<CustomBinding>("Test", 1, 0, "CustomBinding", new CustomBindingParser);
qmlRegisterCustomType<SimpleObjectWithCustomParser>("Test", 1, 0, "SimpleObjectWithCustomParser", new SimpleObjectCustomParser);
diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h
index 6c62bcf7b9..7d7a8ac6d3 100644
--- a/tests/auto/qml/qqmllanguage/testtypes.h
+++ b/tests/auto/qml/qqmllanguage/testtypes.h
@@ -1021,6 +1021,60 @@ public:
}
};
+class MyExtendedUncreateableBaseClass : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool prop1 READ prop1 WRITE setprop1)
+ Q_PROPERTY(bool prop2 READ prop2 WRITE setprop2 REVISION 1)
+ Q_PROPERTY(bool prop3 READ prop3 WRITE setprop3 REVISION 1)
+public:
+ explicit MyExtendedUncreateableBaseClass(QObject *parent = 0)
+ : QObject(parent), _prop1(false), _prop2(false), _prop3(false)
+ {
+ }
+
+ bool _prop1;
+ bool prop1() const { return _prop1; }
+ void setprop1(bool p) { _prop1 = p; }
+ bool _prop2;
+ bool prop2() const { return _prop2; }
+ void setprop2(bool p) { _prop2 = p; }
+ bool _prop3;
+ bool prop3() const { return _prop3; }
+ void setprop3(bool p) { _prop3 = p; }
+};
+
+class MyExtendedUncreateableBaseClassExtension : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool prop4 READ prop4 WRITE setprop4)
+public:
+ explicit MyExtendedUncreateableBaseClassExtension(QObject *parent = 0)
+ : QObject(parent), _prop4(false)
+ {
+ }
+
+ bool _prop4;
+ bool prop4() const { return _prop4; }
+ void setprop4(bool p) { _prop4 = p; }
+};
+
+class MyExtendedCreateableDerivedClass : public MyExtendedUncreateableBaseClass
+{
+ Q_OBJECT
+ Q_PROPERTY(bool prop5 READ prop5 WRITE setprop5)
+
+public:
+ MyExtendedCreateableDerivedClass(QObject *parent = 0)
+ : MyExtendedUncreateableBaseClass(parent), _prop5(false)
+ {
+ }
+
+ bool _prop5;
+ bool prop5() const { return _prop5; }
+ void setprop5(bool p) { _prop5 = p; }
+};
+
class MyVersion2Class : public QObject
{
Q_OBJECT
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index f586f7d429..750c32cc3c 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -189,6 +189,9 @@ private slots:
void subclassedUncreateableRevision_data();
void subclassedUncreateableRevision();
+ void subclassedExtendedUncreateableRevision_data();
+ void subclassedExtendedUncreateableRevision();
+
void uncreatableTypesAsProperties();
void propertyInit();
@@ -257,6 +260,9 @@ private slots:
void defaultListProperty();
void namespacedPropertyTypes();
+ void qmlTypeCanBeResolvedByName_data();
+ void qmlTypeCanBeResolvedByName();
+
private:
QQmlEngine engine;
QStringList defaultImportPathList;
@@ -3225,6 +3231,62 @@ void tst_qqmllanguage::subclassedUncreateableRevision()
delete obj;
}
+void tst_qqmllanguage::subclassedExtendedUncreateableRevision_data()
+{
+ QTest::addColumn<QString>("version");
+ QTest::addColumn<QString>("prop");
+ QTest::addColumn<bool>("shouldWork");
+
+ QTest::newRow("prop1 exists in 1.0") << "1.0" << "prop1" << true;
+ QTest::newRow("prop2 does not exist in 1.0") << "1.0" << "prop2" << false;
+ QTest::newRow("prop3 does not exist in 1.0") << "1.0" << "prop3" << false;
+ QTest::newRow("prop4 exists in 1.0") << "1.0" << "prop4" << true;
+ QTest::newRow("prop5 exists in 1.0") << "1.0" << "prop5" << true;
+
+ QTest::newRow("prop1 exists in 1.1") << "1.1" << "prop1" << true;
+ QTest::newRow("prop2 exists in 1.1") << "1.1" << "prop2" << true;
+ QTest::newRow("prop3 exists in 1.1") << "1.1" << "prop3" << true;
+ QTest::newRow("prop4 exists in 1.1") << "1.1" << "prop4" << true;
+ QTest::newRow("prop5 exists in 1.1") << "1.1" << "prop5" << true;
+}
+
+void tst_qqmllanguage::subclassedExtendedUncreateableRevision()
+{
+ QFETCH(QString, version);
+ QFETCH(QString, prop);
+ QFETCH(bool, shouldWork);
+
+ {
+ QQmlEngine engine;
+ QString qml = QString("import QtQuick 2.0\nimport Test %1\nMyExtendedUncreateableBaseClass {}").arg(version);
+ QQmlComponent c(&engine);
+ QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready");
+ c.setData(qml.toUtf8(), QUrl::fromLocalFile(QDir::currentPath()));
+ QObject *obj = c.create();
+ QCOMPARE(obj, static_cast<QObject*>(0));
+ QCOMPARE(c.errors().count(), 1);
+ QCOMPARE(c.errors().first().description(), QString("Cannot create MyExtendedUncreateableBaseClass"));
+ }
+
+ QQmlEngine engine;
+ QString qml = QString("import QtQuick 2.0\nimport Test %1\nMyExtendedCreateableDerivedClass {\n%3: true\n}").arg(version).arg(prop);
+ QQmlComponent c(&engine);
+ if (!shouldWork)
+ QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready");
+ c.setData(qml.toUtf8(), QUrl::fromLocalFile(QDir::currentPath()));
+ QObject *obj = c.create();
+ if (!shouldWork) {
+ QCOMPARE(obj, static_cast<QObject*>(0));
+ return;
+ }
+
+ QVERIFY(obj);
+ MyExtendedUncreateableBaseClass *base = qobject_cast<MyExtendedUncreateableBaseClass*>(obj);
+ QVERIFY(base);
+ QCOMPARE(base->property(prop.toLatin1()).toBool(), true);
+ delete obj;
+}
+
void tst_qqmllanguage::uncreatableTypesAsProperties()
{
QQmlEngine engine;
@@ -4250,6 +4312,32 @@ void tst_qqmllanguage::namespacedPropertyTypes()
QVERIFY(!o.isNull());
}
+void tst_qqmllanguage::qmlTypeCanBeResolvedByName_data()
+{
+ QTest::addColumn<QUrl>("componentUrl");
+
+ // Built-in C++ types
+ QTest::newRow("C++ - Anonymous") << testFileUrl("quickTypeByName_anon.qml");
+ QTest::newRow("C++ - Named") << testFileUrl("quickTypeByName_named.qml");
+
+ // Composite types with a qmldir
+ QTest::newRow("QML - Anonymous - qmldir") << testFileUrl("compositeTypeByName_anon_qmldir.qml");
+ QTest::newRow("QML - Named - qmldir") << testFileUrl("compositeTypeByName_named_qmldir.qml");
+}
+
+void tst_qqmllanguage::qmlTypeCanBeResolvedByName()
+{
+ QFETCH(QUrl, componentUrl);
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine, componentUrl);
+ VERIFY_ERRORS(0);
+ QTest::ignoreMessage(QtMsgType::QtWarningMsg, "[object Object]"); // a bit crude, but it will do
+
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY(!o.isNull());
+}
+
QTEST_MAIN(tst_qqmllanguage)
#include "tst_qqmllanguage.moc"
diff --git a/tests/auto/qml/qqmllistreference/data/propertyList.qml b/tests/auto/qml/qqmllistreference/data/propertyList.qml
new file mode 100644
index 0000000000..c791c6dcf0
--- /dev/null
+++ b/tests/auto/qml/qqmllistreference/data/propertyList.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.7
+
+Item {
+ id:root
+
+ Component.onCompleted : {
+ var st1 = Qt.createQmlObject( "import QtQuick 2.7; State{ name: 'MyState1' }", root, "dynamicState1" );
+ var st2 = Qt.createQmlObject( "import QtQuick 2.7; State{ name: 'MyState2' }", root, "dynamicState2" );
+ root.states.push( st1, st2 );
+ root.state = "MyState2";
+ }
+}
diff --git a/tests/auto/qml/qqmllistreference/qqmllistreference.pro b/tests/auto/qml/qqmllistreference/qqmllistreference.pro
index dceb7d1133..110d0d9c81 100644
--- a/tests/auto/qml/qqmllistreference/qqmllistreference.pro
+++ b/tests/auto/qml/qqmllistreference/qqmllistreference.pro
@@ -8,4 +8,4 @@ include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private qml-private testlib
+QT += core-private gui-private quick-private qml-private testlib
diff --git a/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp b/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp
index 4d33359eaa..5c16a48378 100644
--- a/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp
+++ b/tests/auto/qml/qqmllistreference/tst_qqmllistreference.cpp
@@ -36,6 +36,7 @@
#include <QtQml/qqmlprivate.h>
#include <QtQml/qqmlproperty.h>
#include <QDebug>
+#include <private/qquickstate_p.h>
#include "../../shared/util.h"
class tst_qqmllistreference : public QQmlDataTest
@@ -65,6 +66,7 @@ private slots:
void qmlmetaproperty();
void engineTypes();
void variantToList();
+ void listProperty();
};
class TestType : public QObject
@@ -618,6 +620,28 @@ void tst_qqmllistreference::variantToList()
delete o;
}
+void tst_qqmllistreference::listProperty()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("propertyList.qml"));
+
+ QScopedPointer<QObject> object( component.create() );
+ QVERIFY(object != 0);
+
+ QCOMPARE( object->property("state").toString(), QStringLiteral("MyState2") );
+ QQmlListReference list( object.data(), "states");
+ QCOMPARE( list.count(), 2 );
+
+ QQuickState* state1 = dynamic_cast<QQuickState*>( list.at( 0 ) );
+ QVERIFY(state1 != 0);
+ QCOMPARE( state1->name(), QStringLiteral("MyState1") );
+ QQuickState* state2 = dynamic_cast<QQuickState*>( list.at( 1 ) );
+ QVERIFY(state2 != 0);
+
+ QCOMPARE( state2->name(), QStringLiteral("MyState2") );
+}
+
+
QTEST_MAIN(tst_qqmllistreference)
#include "tst_qqmllistreference.moc"
diff --git a/tests/auto/qml/qqmllocale/data/date.qml b/tests/auto/qml/qqmllocale/data/date.qml
index 3f58497d22..d8cd043cdf 100644
--- a/tests/auto/qml/qqmllocale/data/date.qml
+++ b/tests/auto/qml/qqmllocale/data/date.qml
@@ -7,6 +7,7 @@ QtObject {
locale = Qt.locale(l)
}
+ // Month number 9 is October: JS Date()'s month range is 0 to 11.
function toLocaleString(fmt) {
var d = new Date(2011, 9, 7, 18, 53, 48, 345);
if (fmt < 0)
diff --git a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
index 4d2cae1523..d0ce83b997 100644
--- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
+++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
@@ -640,9 +640,7 @@ void tst_qqmllocale::dateToLocaleString()
QObject *obj = c.create();
QVERIFY(obj);
- QDateTime dt;
- dt.setDate(QDate(2011, 10, 7)); // weirdly, JS Date month range is 0-11
- dt.setTime(QTime(18, 53, 48, 345));
+ const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345));
QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection,
Q_ARG(QVariant, QVariant(locale)));
@@ -701,9 +699,7 @@ void tst_qqmllocale::dateToLocaleStringFormatted()
QObject *obj = c.create();
QVERIFY(obj);
- QDateTime dt;
- dt.setDate(QDate(2011, 10, 7)); // weirdly, JS Date month range is 0-11
- dt.setTime(QTime(18, 53, 48, 345));
+ const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345));
QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection,
Q_ARG(QVariant, QVariant(locale)));
@@ -732,9 +728,7 @@ void tst_qqmllocale::dateToLocaleDateString()
QObject *obj = c.create();
QVERIFY(obj);
- QDateTime dt;
- dt.setDate(QDate(2011, 10, 7)); // weirdly, JS Date month range is 0-11
- dt.setTime(QTime(18, 53, 48, 345));
+ const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345));
QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection,
Q_ARG(QVariant, QVariant(locale)));
@@ -793,9 +787,7 @@ void tst_qqmllocale::dateToLocaleDateStringFormatted()
QObject *obj = c.create();
QVERIFY(obj);
- QDateTime dt;
- dt.setDate(QDate(2011, 10, 7)); // weirdly, JS Date month range is 0-11
- dt.setTime(QTime(18, 53, 48, 345));
+ const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345));
QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection,
Q_ARG(QVariant, QVariant(locale)));
@@ -824,9 +816,7 @@ void tst_qqmllocale::dateToLocaleTimeString()
QObject *obj = c.create();
QVERIFY(obj);
- QDateTime dt;
- dt.setDate(QDate(2011, 10, 7)); // weirdly, JS Date month range is 0-11
- dt.setTime(QTime(18, 53, 48, 345));
+ const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345));
QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection,
Q_ARG(QVariant, QVariant(locale)));
@@ -885,9 +875,7 @@ void tst_qqmllocale::dateToLocaleTimeStringFormatted()
QObject *obj = c.create();
QVERIFY(obj);
- QDateTime dt;
- dt.setDate(QDate(2011, 10, 7)); // weirdly, JS Date month range is 0-11
- dt.setTime(QTime(18, 53, 48, 345));
+ const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345));
QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection,
Q_ARG(QVariant, QVariant(locale)));
@@ -927,21 +915,20 @@ void tst_qqmllocale::dateFromLocaleString()
QObject *obj = c.create();
QVERIFY(obj);
- QDateTime dt;
- dt.setDate(QDate(2011, 10, 7));
- dt.setTime(QTime(18, 53, 48, 345));
+ const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345));
QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection,
Q_ARG(QVariant, QVariant(locale)));
QLocale l(locale);
+ const QString localeText(l.toString(dt, format));
QVariant val;
QMetaObject::invokeMethod(obj, "fromLocaleString", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, val),
- Q_ARG(QVariant, QVariant(l.toString(dt, format))),
+ Q_ARG(QVariant, QVariant(localeText)),
Q_ARG(QVariant, QVariant(format)));
- QDateTime pd = l.toDateTime(l.toString(dt, format), format);
+ QDateTime pd = l.toDateTime(localeText, format);
QCOMPARE(val.toDateTime(), pd);
}
@@ -971,21 +958,20 @@ void tst_qqmllocale::dateFromLocaleDateString()
QObject *obj = c.create();
QVERIFY(obj);
- QDateTime dt;
- dt.setDate(QDate(2011, 10, 7));
- dt.setTime(QTime(18, 53, 48, 345));
+ const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345));
QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection,
Q_ARG(QVariant, QVariant(locale)));
QLocale l(locale);
+ const QString localeText(l.toString(dt, format));
QVariant val;
QMetaObject::invokeMethod(obj, "fromLocaleDateString", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, val),
- Q_ARG(QVariant, QVariant(l.toString(dt, format))),
+ Q_ARG(QVariant, QVariant(localeText)),
Q_ARG(QVariant, QVariant(format)));
- QDate pd = l.toDate(l.toString(dt, format), format);
+ QDate pd = l.toDate(localeText, format);
QCOMPARE(val.toDate(), pd);
}
@@ -1015,21 +1001,20 @@ void tst_qqmllocale::dateFromLocaleTimeString()
QObject *obj = c.create();
QVERIFY(obj);
- QDateTime dt;
- dt.setDate(QDate(2011, 10, 7));
- dt.setTime(QTime(18, 53, 48, 345));
+ const QDateTime dt(QDate(2011, 10, 7), QTime(18, 53, 48, 345));
QMetaObject::invokeMethod(obj, "setLocale", Qt::DirectConnection,
Q_ARG(QVariant, QVariant(locale)));
QLocale l(locale);
+ const QString localeText(l.toString(dt, format));
QVariant val;
QMetaObject::invokeMethod(obj, "fromLocaleTimeString", Qt::DirectConnection,
Q_RETURN_ARG(QVariant, val),
- Q_ARG(QVariant, QVariant(l.toString(dt, format))),
+ Q_ARG(QVariant, QVariant(localeText)),
Q_ARG(QVariant, QVariant(format)));
- QTime pd = l.toTime(l.toString(dt, format), format);
+ QTime pd = l.toTime(localeText, format);
QCOMPARE(val.toTime(), pd);
}
@@ -1267,7 +1252,10 @@ QString DateFormatter::getLocalizedForm(const QString &isoTimestamp)
// which will require linking to a different library to access that API.
static void setTimeZone(const QByteArray &tz)
{
- qputenv("TZ", tz);
+ if (tz.isEmpty())
+ qunsetenv("TZ");
+ else
+ qputenv("TZ", tz);
::tzset();
// following left for future reference, see comment above
@@ -1291,7 +1279,7 @@ void tst_qqmllocale::timeZoneUpdated()
QQmlComponent c(&e, testFileUrl("timeZoneUpdated.qml"));
QScopedPointer<QObject> obj(c.create());
QVERIFY(obj);
- QCOMPARE(obj->property("success").toBool(), true);
+ QVERIFY(obj->property("success").toBool());
// Change to Indian time
setTimeZone(QByteArray("IST-05:30"));
@@ -1302,7 +1290,7 @@ void tst_qqmllocale::timeZoneUpdated()
setTimeZone(original);
QMetaObject::invokeMethod(obj.data(), "resetTimeZone");
- QCOMPARE(obj->property("success").toBool(), true);
+ QVERIFY(obj->property("success").toBool());
}
#endif
diff --git a/tests/auto/qml/qqmlmoduleplugin/data/works22.qml b/tests/auto/qml/qqmlmoduleplugin/data/works22.qml
new file mode 100644
index 0000000000..571a7e754d
--- /dev/null
+++ b/tests/auto/qml/qqmlmoduleplugin/data/works22.qml
@@ -0,0 +1,3 @@
+import org.qtproject.AutoTestQmlPluginType 2.2
+
+MyPluginType { valueOnlyIn2: 123 }
diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.2.2.pro b/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.2.2.pro
new file mode 100644
index 0000000000..eec5f23a7b
--- /dev/null
+++ b/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.2.2.pro
@@ -0,0 +1,12 @@
+TEMPLATE = lib
+CONFIG += plugin
+SOURCES = plugin.cpp
+QT = core qml
+DESTDIR = ../imports/org/qtproject/AutoTestQmlPluginType.2.2
+
+QT += core-private gui-private qml-private
+
+IMPORT_FILES = \
+ qmldir
+
+include (../../../shared/imports.pri)
diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.cpp b/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.cpp
new file mode 100644
index 0000000000..ecec870374
--- /dev/null
+++ b/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/plugin.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QStringList>
+#include <QtQml/qqmlextensionplugin.h>
+#include <QtQml/qqml.h>
+#include <QDebug>
+
+class MyPluginType : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int value READ value WRITE setValue)
+ Q_PROPERTY(int valueOnlyIn2 READ value WRITE setValue)
+
+public:
+ MyPluginType(QObject *parent=0) : QObject(parent)
+ {
+ qWarning("import2.2 worked");
+ }
+
+ int value() const { return v; }
+ void setValue(int i) { v = i; }
+
+private:
+ int v;
+};
+
+
+class MyPlugin : public QQmlExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
+
+public:
+ MyPlugin()
+ {
+ qWarning("plugin2.2 created");
+ }
+
+ void registerTypes(const char *uri)
+ {
+ Q_ASSERT(QLatin1String(uri) == "org.qtproject.AutoTestQmlPluginType");
+ qmlRegisterType<MyPluginType>(uri, 2, 0, "MyPluginType");
+ qmlRegisterModule(uri, 2, 2);
+ }
+};
+
+#include "plugin.moc"
diff --git a/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/qmldir b/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/qmldir
new file mode 100644
index 0000000000..0a8b5d46eb
--- /dev/null
+++ b/tests/auto/qml/qqmlmoduleplugin/plugin.2.2/qmldir
@@ -0,0 +1 @@
+plugin plugin
diff --git a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro
index 889968f6cc..0f548aa6f8 100644
--- a/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro
+++ b/tests/auto/qml/qqmlmoduleplugin/qqmlmoduleplugin.pro
@@ -20,7 +20,8 @@ SUBDIRS =\
protectedModule\
plugin/childplugin\
plugin.2/childplugin\
- plugin.2.1/childplugin
+ plugin.2.1/childplugin\
+ plugin.2.2
tst_qqmlmoduleplugin_pro.depends += plugin
SUBDIRS += tst_qqmlmoduleplugin.pro
diff --git a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp
index 265492b435..8600e1e8ab 100644
--- a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp
+++ b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp
@@ -52,8 +52,7 @@ public:
private slots:
virtual void initTestCase();
void importsPlugin();
- void importsPlugin2();
- void importsPlugin21();
+ void importsPlugin_data();
void importsMixedQmlCppPlugin();
void incorrectPluginCase();
void importPluginWithQmlFile();
@@ -70,6 +69,7 @@ private slots:
void importStrictModule();
void importStrictModule_data();
void importProtectedModule();
+ void importVersionedModule();
void importsChildPlugin();
void importsChildPlugin2();
void importsChildPlugin21();
@@ -130,29 +130,15 @@ void tst_qqmlmoduleplugin::initTestCase()
void tst_qqmlmoduleplugin::importsPlugin()
{
- QQmlEngine engine;
- engine.addImportPath(m_importsDirectory);
- QTest::ignoreMessage(QtWarningMsg, "plugin created");
- QTest::ignoreMessage(QtWarningMsg, "import worked");
- QTest::ignoreMessage(QtWarningMsg, "Module 'org.qtproject.AutoTestQmlPluginType' does not contain a module identifier directive - it cannot be protected from external registrations.");
- QQmlComponent component(&engine, testFileUrl(QStringLiteral("works.qml")));
- foreach (QQmlError err, component.errors())
- qWarning() << err;
- VERIFY_ERRORS(0);
- QObject *object = component.create();
- QVERIFY(object != 0);
- QCOMPARE(object->property("value").toInt(),123);
- delete object;
-}
+ QFETCH(QString, suffix);
+ QFETCH(QString, qmlFile);
-void tst_qqmlmoduleplugin::importsPlugin2()
-{
QQmlEngine engine;
engine.addImportPath(m_importsDirectory);
- QTest::ignoreMessage(QtWarningMsg, "plugin2 created");
- QTest::ignoreMessage(QtWarningMsg, "import2 worked");
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(QString("plugin%1 created").arg(suffix)));
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(QString("import%1 worked").arg(suffix)));
QTest::ignoreMessage(QtWarningMsg, "Module 'org.qtproject.AutoTestQmlPluginType' does not contain a module identifier directive - it cannot be protected from external registrations.");
- QQmlComponent component(&engine, testFileUrl(QStringLiteral("works2.qml")));
+ QQmlComponent component(&engine, testFileUrl(qmlFile));
foreach (QQmlError err, component.errors())
qWarning() << err;
VERIFY_ERRORS(0);
@@ -162,21 +148,15 @@ void tst_qqmlmoduleplugin::importsPlugin2()
delete object;
}
-void tst_qqmlmoduleplugin::importsPlugin21()
+void tst_qqmlmoduleplugin::importsPlugin_data()
{
- QQmlEngine engine;
- engine.addImportPath(m_importsDirectory);
- QTest::ignoreMessage(QtWarningMsg, "plugin2.1 created");
- QTest::ignoreMessage(QtWarningMsg, "import2.1 worked");
- QTest::ignoreMessage(QtWarningMsg, "Module 'org.qtproject.AutoTestQmlPluginType' does not contain a module identifier directive - it cannot be protected from external registrations.");
- QQmlComponent component(&engine, testFileUrl(QStringLiteral("works21.qml")));
- foreach (QQmlError err, component.errors())
- qWarning() << err;
- VERIFY_ERRORS(0);
- QObject *object = component.create();
- QVERIFY(object != 0);
- QCOMPARE(object->property("value").toInt(),123);
- delete object;
+ QTest::addColumn<QString>("suffix");
+ QTest::addColumn<QString>("qmlFile");
+
+ QTest::newRow("1.0") << "" << "works.qml";
+ QTest::newRow("2.0") << "2" << "works2.qml";
+ QTest::newRow("2.1") << "2.1" << "works21.qml";
+ QTest::newRow("2.2") << "2.2" << "works22.qml";
}
void tst_qqmlmoduleplugin::incorrectPluginCase()
@@ -578,6 +558,32 @@ void tst_qqmlmoduleplugin::importProtectedModule()
QVERIFY(object != 0);
}
+void tst_qqmlmoduleplugin::importVersionedModule()
+{
+ qmlRegisterType<QObject>("org.qtproject.VersionedModule", 1, 0, "TestType");
+ qmlRegisterModule("org.qtproject.VersionedModule", 1, 1);
+
+ QQmlEngine engine;
+ engine.addImportPath(m_importsDirectory);
+
+ QUrl url(testFileUrl("empty.qml"));
+
+ QQmlComponent component(&engine);
+ component.setData("import org.qtproject.VersionedModule 1.0\n TestType {}\n", url);
+ QScopedPointer<QObject> object10(component.create());
+ QVERIFY(!object10.isNull());
+
+ component.setData("import org.qtproject.VersionedModule 1.1\n TestType {}\n", url);
+ QScopedPointer<QObject> object11(component.create());
+ QVERIFY(!object11.isNull());
+
+ component.setData("import org.qtproject.VersionedModule 1.2\n TestType {}\n", url);
+ QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready");
+ QScopedPointer<QObject> object12(component.create());
+ QVERIFY(object12.isNull());
+ QCOMPARE(component.errorString(), QString("%1:1 module \"org.qtproject.VersionedModule\" version 1.2 is not installed\n").arg(url.toString()));
+}
+
void tst_qqmlmoduleplugin::importsChildPlugin()
{
QQmlEngine engine;
diff --git a/tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp b/tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp
index e16bfb08a2..3b982d1ab7 100644
--- a/tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp
+++ b/tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp
@@ -31,12 +31,6 @@
#include <QtQuick/private/qquicktext_p.h>
#include <private/qqmlengine_p.h>
#include <QtCore/qcryptographichash.h>
-/*
-#include <QtWebKit/qwebpage.h>
-#include <QtWebKit/qwebframe.h>
-#include <QtWebKit/qwebdatabase.h>
-#include <QtWebKit/qwebsecurityorigin.h>
-*/
#include <QtSql/qsqldatabase.h>
#include <QtCore/qdir.h>
#include <QtCore/qfile.h>
@@ -150,42 +144,6 @@ void tst_qqmlsqldatabase::testQml_data()
// test - in which case increment total_databases_created_by_tests above.
}
-/*
-class QWebPageWithJavaScriptConsoleMessages : public QWebPage {
-public:
- void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID)
- {
- qWarning() << sourceID << ":" << lineNumber << ":" << message;
- }
-};
-
-void tst_qqmlsqldatabase::validateAgainstWebkit()
-{
- // Validates tests against WebKit (HTML5) support.
- //
- QFETCH(QString, jsfile);
- QFETCH(QString, result);
- QFETCH(int, databases);
-
- QFile f(jsfile);
- QVERIFY(f.open(QIODevice::ReadOnly));
- QString js=f.readAll();
-
- QWebPageWithJavaScriptConsoleMessages webpage;
- webpage.settings()->setOfflineStoragePath(dbDir());
- webpage.settings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
-
- QEXPECT_FAIL("","WebKit doesn't support openDatabaseSync yet", Continue);
- QCOMPARE(webpage.mainFrame()->evaluateJavaScript(js).toString(),result);
-
- QTest::qWait(100); // WebKit crashes if you quit it too fast
-
- QWebSecurityOrigin origin = webpage.mainFrame()->securityOrigin();
- QList<QWebDatabase> dbs = origin.databases();
- QCOMPARE(dbs.count(), databases);
-}
-*/
-
void tst_qqmlsqldatabase::testQml()
{
if (engine->offlineStoragePath().isEmpty())
diff --git a/tests/auto/qmltest-blacklist/animators/tst_stopped.qml b/tests/auto/qmltest-blacklist/animators/tst_stopped.qml
new file mode 100644
index 0000000000..a70da63e13
--- /dev/null
+++ b/tests/auto/qmltest-blacklist/animators/tst_stopped.qml
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtTest 1.1
+
+Item {
+ id: root;
+ width: 200
+ height: 200
+
+ TestCase {
+ id: testcase
+ name: "animators-stopped"
+ when: false
+ function test_endresult() {
+ verify(true);
+ }
+ }
+
+ ShaderEffect {
+ id: shaderEffect
+ property real t;
+ width: 10
+ height: 10
+
+ fragmentShader: "
+ highp uniform float t;
+ void main() {
+ gl_FragColor = vec4(t, t, t, 1.0);
+ }
+ "
+ UniformAnimator { id: uniformAnimator; target: shaderEffect; uniform: "t"; loops: Animation.Infinite; running: true; }
+ }
+
+ Box {
+ id: box
+
+ ScaleAnimator { id: scaleAnimator; target: box; loops: Animation.Infinite; running: true; }
+ XAnimator { id: xAnimator; target: box; loops: Animation.Infinite; running: true; }
+ YAnimator { id: yAnimator; target: box; loops: Animation.Infinite; running: true; }
+ RotationAnimator { id: rotationAnimator; target: box; loops: Animation.Infinite; running: true; }
+ OpacityAnimator { id: opacityAnimator; target: box; loops: Animation.Infinite; running: true; }
+
+ Timer {
+ id: timer;
+ interval: 500
+ running: true
+ repeat: false
+ onTriggered: {
+ xAnimator.stop();
+ yAnimator.stop();
+ scaleAnimator.stop()
+ rotationAnimator.stop();
+ rotationAnimator.stop();
+ uniformAnimator.stop();
+ testcase.when = true;
+ }
+ }
+ }
+}
diff --git a/tests/auto/qmltest/events/tst_drag.qml b/tests/auto/qmltest/events/tst_drag.qml
index ffdc94167c..ae77247a41 100644
--- a/tests/auto/qmltest/events/tst_drag.qml
+++ b/tests/auto/qmltest/events/tst_drag.qml
@@ -117,9 +117,9 @@ Rectangle{
name:"mouserelease"
when:windowShown
function test_mouseDrag() {
- mouseDrag(container, 10, 10, 20, 30);
- compare(container.x, 20 - util.dragThreshold - 1);
- compare(container.y, 30 - util.dragThreshold - 1);
+ mouseDrag(container, 10, 10, util.dragThreshold * 2, util.dragThreshold * 3);
+ compare(container.x, util.dragThreshold - 1);
+ compare(container.y, util.dragThreshold * 2 - 1);
}
function test_doSomethingWhileDragging() {
diff --git a/tests/auto/qmltest/events/tst_events.qml b/tests/auto/qmltest/events/tst_events.qml
index e655c26c7d..d9868a316c 100644
--- a/tests/auto/qmltest/events/tst_events.qml
+++ b/tests/auto/qmltest/events/tst_events.qml
@@ -27,6 +27,7 @@
****************************************************************************/
import QtQuick 2.0
+import QtQuick.Window 2.0
import QtTest 1.1
Rectangle {
@@ -56,6 +57,16 @@ Rectangle {
signalName: "doubleClickSignalHelper"
}
+ Window {
+ id: sub
+ visible: true
+ property bool clicked: false
+ MouseArea {
+ anchors.fill: parent
+ onClicked: sub.clicked = true
+ }
+ }
+
MouseArea {
anchors.fill: parent
onClicked: {
@@ -89,6 +100,11 @@ Rectangle {
tryCompare(top, "mouseHasBeenClicked", true, 10000)
}
+ function test_mouse_click_subwindow() {
+ mouseClick(sub)
+ tryCompare(sub, "clicked", true, 10000)
+ }
+
function test_mouse_doubleclick() {
doubleClickSpy.clear()
mouseDoubleClickSequence(top, 25, 30)
diff --git a/tests/auto/qmltest/events/tst_touch.qml b/tests/auto/qmltest/events/tst_touch.qml
new file mode 100644
index 0000000000..5b209a6d0b
--- /dev/null
+++ b/tests/auto/qmltest/events/tst_touch.qml
@@ -0,0 +1,182 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Jeremy Katz
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Window 2.0
+import QtTest 1.0
+
+MultiPointTouchArea {
+ id: touchArea
+ width: 100
+ height: 100
+
+ SignalSpy {
+ id: touchUpdatedSpy
+ target: touchArea
+ signalName: "touchUpdated"
+ }
+
+ SignalSpy {
+ id: interiorSpy
+ target: interior
+ signalName: "touchUpdated"
+ }
+
+ MultiPointTouchArea {
+ id: interior
+ width: parent.width / 2
+ height: parent.height
+ anchors.right: parent.right
+ }
+
+ Window {
+ width: 100; height: 100
+
+ SignalSpy {
+ id: subWindowSpy
+ target: subWindowTouchArea
+ signalName: "touchUpdated"
+ }
+
+ MultiPointTouchArea {
+ id: subWindowTouchArea
+ anchors.fill: parent
+ }
+ }
+
+ TestCase {
+ when: windowShown
+ name: "touch"
+
+ function comparePoint(point, id, x, y) {
+ var retval = true;
+ var pointId = point.pointId & 0xFFFFFF; //strip device identifier
+ if (pointId !== id) {
+ warn("Unexpected pointId: " + pointId + ". Expected " + id);
+ retval = false;
+ }
+ if (point.x !== x) {
+ warn("Unexpected x: " + point.x + ". Expected " + x);
+ retval = false;
+ }
+ if (point.y !== y) {
+ warn("Unexpected y: " + point.y + ". Expected " + y);
+ retval = false;
+ }
+ return retval;
+ }
+
+ function cleanup() {
+ touchUpdatedSpy.clear();
+ interiorSpy.clear();
+ subWindowSpy.clear();
+ }
+
+ function test_secondWindow() {
+ var first = 1;
+ var sequence = touchEvent(subWindowTouchArea);
+ sequence.press(first, 0, 0, 0);
+ sequence.commit();
+ sequence.release(first, subWindowTouchArea, 0, 0)
+ sequence.commit();
+ compare(subWindowSpy.count, 2);
+ var touchPoint = subWindowSpy.signalArguments[0][0][0];
+ verify(comparePoint(touchPoint, first, 0, 0));
+ }
+
+ function initTestCase() {
+ waitForRendering(touchArea) // when: windowShown may be insufficient
+ }
+
+ function test_childMapping() {
+ var sequence = touchEvent(touchArea);
+
+ var first = 1;
+ // Test mapping touches to a child item
+ sequence.press(first, interior, 0, 0);
+ sequence.commit();
+
+ // Map touches to the parent at the same point
+ sequence.move(first, touchArea, interior.x, interior.y);
+ sequence.commit();
+
+ sequence.release(first, touchArea, interior.x, interior.y);
+ sequence.commit();
+
+ compare(interiorSpy.count, 3);
+ verify(comparePoint(interiorSpy.signalArguments[0][0][0], first, 0, 0));
+ verify(comparePoint(interiorSpy.signalArguments[1][0][0], first, 0, 0));
+ }
+
+ function test_fullSequence() {
+ var sequence = touchEvent(touchArea);
+ verify(sequence);
+
+ var first = 1;
+ var second = 2;
+
+ sequence.press(first, null, 0, 0);
+ sequence.commit();
+ compare(touchUpdatedSpy.count, 1);
+ var touchPoints = touchUpdatedSpy.signalArguments[0][0];
+ compare(touchPoints.length, 1);
+ verify(comparePoint(touchPoints[0], first, 0, 0));
+
+ sequence.stationary(first);
+ sequence.press(second, null, 1, 0);
+ sequence.commit();
+ compare(touchUpdatedSpy.count, 2);
+ touchPoints = touchUpdatedSpy.signalArguments[1][0];
+ compare(touchPoints.length, 2);
+ verify(comparePoint(touchPoints[0], first, 0, 0));
+ verify(comparePoint(touchPoints[1], second, 1, 0));
+
+ sequence.release(first);
+ sequence.move(second, null, 1, 1);
+ sequence.commit();
+ compare(touchUpdatedSpy.count, 3);
+ touchPoints = touchUpdatedSpy.signalArguments[2][0];
+ compare(touchPoints.length, 1);
+ verify(comparePoint(touchPoints[0], second, 1, 1));
+
+ sequence.release(second, null, 0, 1);
+ sequence.commit();
+ compare(touchUpdatedSpy.count, 4);
+ touchPoints = touchUpdatedSpy.signalArguments[3][0];
+ compare(touchPoints.length, 0);
+ }
+
+ function test_simpleChain() {
+ var first = 1;
+ touchEvent(touchArea).press(first).commit().release(first).commit();
+ compare(touchUpdatedSpy.count, 2);
+ var touchPoint = touchUpdatedSpy.signalArguments[0][0][0];
+ verify(comparePoint(touchPoint, first, touchArea.width / 2, touchArea.height / 2));
+ }
+ }
+}
diff --git a/tests/auto/qmltest/itemgrabber/tst_itemgrabber.qml b/tests/auto/qmltest/itemgrabber/tst_itemgrabber.qml
index 022e98a202..a80814d6de 100644
--- a/tests/auto/qmltest/itemgrabber/tst_itemgrabber.qml
+++ b/tests/auto/qmltest/itemgrabber/tst_itemgrabber.qml
@@ -37,8 +37,9 @@ Item {
TestCase {
id: testCase
name: "item-grabber"
- when: imageOnDisk.ready && imageOnDiskSmall.ready && imageInCache.ready && imageInCacheSmall.ready
- function test_endresult() {
+ when: imageOnDisk.ready && imageOnDiskSmall.ready
+
+ function test_endresult_disk() {
var image = grabImage(root);
// imageOnDisk at (0, 0) - (100x100)
@@ -52,6 +53,40 @@ Item {
compare(imageOnDiskSmall.height, 50);
verify(image.pixel(100, 0) === Qt.rgba(1, 0, 0, 1));
verify(image.pixel(149, 49) === Qt.rgba(0, 0, 1, 1));
+ }
+
+ function test_endresult_cache_data() {
+ return [
+ { cache: true, sourceSize: Qt.size(-1, -1), fillMode: Image.Stretch },
+ { cache: true, sourceSize: Qt.size(-1, -1), fillMode: Image.PreserveAspectFit },
+ { cache: true, sourceSize: Qt.size(-1, -1), fillMode: Image.PreserveAspectCrop },
+ { cache: true, sourceSize: Qt.size(10, 10), fillMode: Image.Stretch },
+ { cache: true, sourceSize: Qt.size(10, 10), fillMode: Image.PreserveAspectFit },
+ { cache: true, sourceSize: Qt.size(10, 10), fillMode: Image.PreserveAspectCrop },
+ { cache: false, sourceSize: Qt.size(-1, -1), fillMode: Image.Stretch },
+ { cache: false, sourceSize: Qt.size(-1, -1), fillMode: Image.PreserveAspectFit },
+ { cache: false, sourceSize: Qt.size(-1, -1), fillMode: Image.PreserveAspectCrop },
+ { cache: false, sourceSize: Qt.size(10, 10), fillMode: Image.Stretch },
+ { cache: false, sourceSize: Qt.size(10, 10), fillMode: Image.PreserveAspectFit },
+ { cache: false, sourceSize: Qt.size(10, 10), fillMode: Image.PreserveAspectCrop },
+ ];
+ }
+
+ function test_endresult_cache(data) {
+ imageInCache.cache = data.cache;
+ imageInCache.sourceSize = data.sourceSize;
+ imageInCache.fillMode = data.fillMode;
+ imageInCacheSmall.cache = data.cache;
+ imageInCacheSmall.sourceSize = data.sourceSize;
+ imageInCacheSmall.fillMode = data.fillMode;
+
+ box.grabToImage(imageInCache.handleGrab);
+ box.grabToImage(imageInCacheSmall.handleGrab, Qt.size(50, 50));
+
+ tryCompare(imageInCache, "ready", true);
+ tryCompare(imageInCacheSmall, "ready", true);
+
+ var image = grabImage(root);
// imageInCache at (0, 100) - 100x100
compare(imageInCache.width, 100);
@@ -72,8 +107,6 @@ Item {
onWindowShownChanged: {
box.grabToImage(imageOnDisk.handleGrab);
box.grabToImage(imageOnDiskSmall.handleGrab, Qt.size(50, 50));
- box.grabToImage(imageInCache.handleGrab);
- box.grabToImage(imageInCacheSmall.handleGrab, Qt.size(50, 50));
}
}
diff --git a/examples/quick/demos/samegame/content/BBSettings.qml b/tests/auto/qmltest/layout/Container.qml
index cd6be7dcf5..db3d68c485 100644
--- a/examples/quick/demos/samegame/content/BBSettings.qml
+++ b/tests/auto/qmltest/layout/Container.qml
@@ -1,9 +1,9 @@
/****************************************************************************
**
-** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
-** This file is part of the examples of the Qt Toolkit.
+** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
@@ -38,24 +38,18 @@
**
****************************************************************************/
-import QtQml 2.0
+import QtQuick 2.5
+import QtQuick.Layouts 1.2
-QtObject {
- // This height/width is here for desktop testing, otherwise
- // we could just use Screen.width/Screen.height.
- property int screenHeight: 1280
- property int screenWidth: 768
+Item {
+ objectName: "qtbug51927-window"
+ visible: true
- property int menuDelay: 500
+ default property alias _contents: customContent.data
- property int headerHeight: 70
- property int footerHeight: 100
-
- property int fontPixelSize: 55
-
- property int blockSize: 64
-
- property int toolButtonHeight: 64
-
- property int menuButtonSpacing: 15
+ ColumnLayout {
+ id: customContent
+ objectName: "qtbug51927-columnLayout"
+ anchors.fill: parent
+ }
}
diff --git a/tests/auto/qmltest/layout/ContainerUser.qml b/tests/auto/qmltest/layout/ContainerUser.qml
new file mode 100644
index 0000000000..ff7ce6221b
--- /dev/null
+++ b/tests/auto/qmltest/layout/ContainerUser.qml
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import QtQuick.Window 2.2
+
+Container {
+ visible: true
+
+ Text {
+ objectName: "qtbug51927-text"
+ text: qsTr("Hello World")
+ anchors.centerIn: parent
+ renderType: Text.QtRendering
+ }
+}
diff --git a/tests/auto/qmltest/layout/tst_layout.qml b/tests/auto/qmltest/layout/tst_layout.qml
new file mode 100644
index 0000000000..ee44a01080
--- /dev/null
+++ b/tests/auto/qmltest/layout/tst_layout.qml
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtTest 1.0
+
+TestCase {
+ id: testCase
+ name: "Tests_Layout"
+ when:windowShown
+ width:400
+ height:400
+
+ function test_invalidParent() {
+ ignoreWarning('<Unknown File>:1:49: QML QtObject: Layout must be attached to Item elements')
+ var object = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Layouts 1.0; QtObject { Layout.fillWidth: true }', testCase, '');
+ object.destroy()
+ }
+
+ function test_defaultPropertyAliasCrash() {
+ var containerUserComponent = Qt.createComponent("ContainerUser.qml");
+ compare(containerUserComponent.status, Component.Ready);
+
+ var containerUser = containerUserComponent.createObject(testCase);
+ verify(containerUser);
+
+ // Shouldn't crash.
+ containerUser.destroy();
+ }
+}
+
diff --git a/tests/auto/qmltest/positioners/tst_positioners.qml b/tests/auto/qmltest/positioners/tst_positioners.qml
new file mode 100644
index 0000000000..03a0e13225
--- /dev/null
+++ b/tests/auto/qmltest/positioners/tst_positioners.qml
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.9
+import QtTest 1.1
+
+Item {
+ Column {
+ id: column
+ Repeater {
+ id: repeater
+ model: 2
+ Rectangle {
+ width: 100
+ height: 30
+ border.width: 1
+ }
+ }
+ }
+
+ SignalSpy {
+ id: spy
+ target: column
+ signalName: "positioningComplete"
+ }
+
+ TestCase {
+ function test_forceLayout() {
+ compare(column.height, 60)
+ repeater.model = 4
+ column.forceLayout()
+ compare(column.height, 120)
+
+ // initial positioning and our forced layout
+ compare(spy.count, 2)
+ }
+ }
+}
diff --git a/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml b/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml
new file mode 100644
index 0000000000..5f1e802df2
--- /dev/null
+++ b/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml
@@ -0,0 +1,179 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.8
+import QtQuick.Window 2.2
+import QtTest 1.2
+
+TestCase {
+ id: testCase
+ name: "tst_createTemporaryObject"
+ width: 100
+ height: 100
+ when: windowShown
+
+ property var createdObjectNames: []
+ property var createdParentlessObjects: []
+
+ function verifyNoChildren() {
+ for (var i = 0; i < createdObjectNames.length; ++i) {
+ verify(!findChild(testCase, createdObjectNames[i]));
+ }
+
+ compare(createdParentlessObjects.length, 0,
+ "The following parentless temporary objects were not destroyed: " + createdParentlessObjects)
+ }
+
+ function init() {
+ // The items are destroyed after cleanup(), so we check here after every test,
+ // and once for the last test in cleanupTestCase().
+ verifyNoChildren();
+ }
+
+ function cleanupTestCase() {
+ verifyNoChildren();
+ }
+
+ function test_fromQml_data() {
+ return [
+ { tag: "QtObject", qml: "import QtQml 2.0; QtObject {}" },
+ { tag: "Item", qml: "import QtQuick 2.0; Item {}" },
+ ];
+ }
+
+ function test_fromQml(data) {
+ var object = createTemporaryQmlObject(data.qml, testCase);
+ verify(object);
+
+ object.objectName = data.tag + "FromQml";
+ compare(findChild(testCase, object.objectName), object);
+
+ createdObjectNames.push(object.objectName);
+
+ // Create an object and destroy it early. It should be
+ // removed from TestCase's list of temporary objects
+ // as soon as it's destroyed.
+ var manuallyDestroyedObject = createTemporaryQmlObject(data.qml, testCase);
+ verify(manuallyDestroyedObject);
+
+ var manuallyDestroyedObjectName = data.tag + "FromQmlShortLived";
+ manuallyDestroyedObject.objectName = manuallyDestroyedObjectName;
+ compare(findChild(testCase, manuallyDestroyedObjectName), manuallyDestroyedObject);
+
+ manuallyDestroyedObject.destroy();
+ wait(0);
+
+ verify(!findChild(testCase, manuallyDestroyedObjectName));
+ }
+
+ Component {
+ id: objectComponent
+
+ QtObject {}
+ }
+
+ Component {
+ id: itemComponent
+
+ Item {}
+ }
+
+ Component {
+ id: windowComponent
+
+ Window {}
+ }
+
+ function test_fromComponent_data() {
+ return [
+ { tag: "QtObject", component: objectComponent },
+ { tag: "Item", component: itemComponent },
+ { tag: "Window", component: windowComponent },
+ ];
+ }
+
+ function test_fromComponent(data) {
+ var object = createTemporaryObject(data.component, testCase);
+ verify(object);
+
+ object.objectName = data.tag + "FromComponent";
+ compare(findChild(testCase, object.objectName), object);
+
+ if (object.hasOwnProperty("contentItem"))
+ object.contentItem.objectName = "WindowContentItemFromComponent";
+
+ createdObjectNames.push(object.objectName);
+
+ // Create an object and destroy it early. It should be
+ // removed from TestCase's list of temporary objects
+ // as soon as it's destroyed.
+ var manuallyDestroyedObject = createTemporaryObject(data.component, testCase);
+ verify(manuallyDestroyedObject);
+
+ var manuallyDestroyedObjectName = data.tag + "FromComponentShortLived";
+ manuallyDestroyedObject.objectName = manuallyDestroyedObjectName;
+ compare(findChild(testCase, manuallyDestroyedObjectName), manuallyDestroyedObject);
+
+ manuallyDestroyedObject.destroy();
+ wait(0);
+
+ verify(!findChild(testCase, manuallyDestroyedObjectName));
+ }
+
+ function test_fromComponentParent_data() {
+ return [
+ { tag: "omit", expectedParent: null },
+ { tag: "undefined", parent: undefined, expectedParent: null },
+ { tag: "null", parent: null, expectedParent: null },
+ { tag: "1", parent: 1, expectedParent: null },
+ { tag: "testCase", parent: testCase, expectedParent: testCase }
+ ];
+ }
+
+ // Tests that an invalid or missing parent argument results in a parentless object.
+ // This is the same behavior as displayed by component.createObject().
+ function test_fromComponentParent(data) {
+ var object = data.hasOwnProperty("parent")
+ ? createTemporaryObject(itemComponent, data.parent)
+ : createTemporaryObject(itemComponent);
+ verify(object);
+ compare(object.parent, data.expectedParent);
+
+ object.objectName = data.tag + "FromComponentOmitParent";
+ if (object.parent) {
+ compare(findChild(testCase, object.objectName), object);
+ createdObjectNames.push(object.objectName);
+ } else {
+ object.Component.destruction.connect(function() {
+ var indexOfObject = createdParentlessObjects.indexOf(object);
+ createdParentlessObjects.splice(indexOfObject, 1);
+ });
+ createdParentlessObjects.push(object);
+ }
+ }
+}
diff --git a/tests/auto/quick/drawingmodes/data/DrawingModes.qml b/tests/auto/quick/drawingmodes/data/DrawingModes.qml
new file mode 100644
index 0000000000..4211f247f8
--- /dev/null
+++ b/tests/auto/quick/drawingmodes/data/DrawingModes.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+import Test 1.0
+
+Rectangle {
+ id: root
+
+ width: 200
+ height: 200
+ color: "black"
+
+ DrawingModeItem {
+ anchors.fill: parent
+ }
+}
diff --git a/tests/auto/quick/drawingmodes/drawingmodes.pro b/tests/auto/quick/drawingmodes/drawingmodes.pro
new file mode 100644
index 0000000000..ff5383b501
--- /dev/null
+++ b/tests/auto/quick/drawingmodes/drawingmodes.pro
@@ -0,0 +1,17 @@
+CONFIG += testcase
+TARGET = tst_drawingmodes
+SOURCES += tst_drawingmodes.cpp
+
+macos:CONFIG -= app_bundle
+
+TESTDATA = data/*
+
+include(../../shared/util.pri)
+
+CONFIG += parallel_test
+QT += gui qml quick testlib
+
+OTHER_FILES += \
+ data/DrawingModes.qml
+
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/quick/drawingmodes/tst_drawingmodes.cpp b/tests/auto/quick/drawingmodes/tst_drawingmodes.cpp
new file mode 100644
index 0000000000..d4065e3d38
--- /dev/null
+++ b/tests/auto/quick/drawingmodes/tst_drawingmodes.cpp
@@ -0,0 +1,340 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+
+#include <QtQuick/qquickitem.h>
+#include <QtQuick/qquickview.h>
+#include <QtQuick/qsgnode.h>
+#include <QtQuick/qsggeometry.h>
+#include <QtQuick/qsgflatcolormaterial.h>
+#include <QtGui/qscreen.h>
+#include <QtGui/qopenglcontext.h>
+
+#include "../../shared/util.h"
+
+class tst_drawingmodes : public QQmlDataTest
+{
+ Q_OBJECT
+public:
+ tst_drawingmodes();
+
+ bool hasPixelAround(const QImage &fb, int centerX, int centerY);
+ QImage runTest(const QString &fileName)
+ {
+ QQuickView view(&outerWindow);
+ view.setResizeMode(QQuickView::SizeViewToRootObject);
+ view.setSource(testFileUrl(fileName));
+ view.setVisible(true);
+ QTest::qWaitForWindowExposed(&view);
+ return view.grabWindow();
+ }
+
+ //It is important for platforms that only are able to show fullscreen windows
+ //to have a container for the window that is painted on.
+ QQuickWindow outerWindow;
+ const QRgb black;
+ const QRgb red;
+
+private slots:
+ void points();
+ void lines();
+ void lineStrip();
+ void lineLoop();
+ void triangles();
+ void triangleStrip();
+ void triangleFan();
+};
+
+class DrawingModeItem : public QQuickItem
+{
+ Q_OBJECT
+public:
+ static GLenum drawingMode;
+
+ DrawingModeItem() : first(QSGGeometry::defaultAttributes_Point2D(), 5),
+ second(QSGGeometry::defaultAttributes_Point2D(), 5)
+ {
+ setFlag(ItemHasContents, true);
+ material.setColor(Qt::red);
+ }
+
+protected:
+ QSGGeometry first;
+ QSGGeometry second;
+ QSGFlatColorMaterial material;
+
+ virtual QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *)
+ {
+ if (!node) {
+ QRect bounds(0, 0, 200, 200);
+ first.setDrawingMode(drawingMode);
+ second.setDrawingMode(drawingMode);
+
+ QSGGeometry::Point2D *v = first.vertexDataAsPoint2D();
+ v[0].set(bounds.width() * 2 / 8, bounds.height() / 2);
+ v[1].set(bounds.width() / 8, bounds.height() / 4);
+ v[2].set(bounds.width() * 3 / 8, bounds.height() / 4);
+ v[3].set(bounds.width() * 3 / 8, bounds.height() * 3 / 4);
+ v[4].set(bounds.width() / 8, bounds.height() * 3 / 4);
+
+ v = second.vertexDataAsPoint2D();
+ v[0].set(bounds.width() * 6 / 8, bounds.height() / 2);
+ v[1].set(bounds.width() * 5 / 8, bounds.height() / 4);
+ v[2].set(bounds.width() * 7 / 8, bounds.height() / 4);
+ v[3].set(bounds.width() * 7 / 8, bounds.height() * 3 / 4);
+ v[4].set(bounds.width() * 5 / 8, bounds.height() * 3 / 4);
+
+ node = new QSGNode;
+ QSGGeometryNode *child = new QSGGeometryNode;
+ child->setGeometry(&first);
+ child->setMaterial(&material);
+ node->appendChildNode(child);
+ child = new QSGGeometryNode;
+ child->setGeometry(&second);
+ child->setMaterial(&material);
+ node->appendChildNode(child);
+ }
+ return node;
+ }
+};
+
+GLenum DrawingModeItem::drawingMode;
+
+bool tst_drawingmodes::hasPixelAround(const QImage &fb, int centerX, int centerY) {
+ for (int x = centerX - 2; x <= centerX + 2; ++x) {
+ for (int y = centerY - 2; y <= centerY + 2; ++y) {
+ if (fb.pixel(x, y) == red)
+ return true;
+ }
+ }
+ return false;
+}
+
+tst_drawingmodes::tst_drawingmodes() : black(qRgb(0, 0, 0)), red(qRgb(0xff, 0, 0))
+{
+ qmlRegisterType<DrawingModeItem>("Test", 1, 0, "DrawingModeItem");
+ outerWindow.showNormal();
+ outerWindow.setGeometry(0,0,400,400);
+}
+
+void tst_drawingmodes::points()
+{
+ DrawingModeItem::drawingMode = GL_POINTS;
+ if (QGuiApplication::primaryScreen()->depth() < 24)
+ QSKIP("This test does not work at display depths < 24");
+
+#ifdef Q_OS_WIN
+ if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES)
+ QSKIP("ANGLE cannot draw GL_POINTS.");
+#endif
+
+ QImage fb = runTest("DrawingModes.qml");
+
+ QVERIFY(hasPixelAround(fb, 50, 100));
+ QVERIFY(hasPixelAround(fb, 25, 50));
+ QVERIFY(hasPixelAround(fb, 75, 50));
+ QVERIFY(hasPixelAround(fb, 75, 150));
+ QVERIFY(hasPixelAround(fb, 25, 150));
+
+ QVERIFY(hasPixelAround(fb, 150, 100));
+ QVERIFY(hasPixelAround(fb, 125, 50));
+ QVERIFY(hasPixelAround(fb, 175, 50));
+ QVERIFY(hasPixelAround(fb, 175, 150));
+ QVERIFY(hasPixelAround(fb, 125, 150));
+
+ QVERIFY(!hasPixelAround(fb, 135, 70));
+ QVERIFY(!hasPixelAround(fb, 175, 100));
+ QVERIFY(!hasPixelAround(fb, 110, 140));
+ QVERIFY(!hasPixelAround(fb, 50, 50));
+ QVERIFY(!hasPixelAround(fb, 50, 150));
+ QVERIFY(!hasPixelAround(fb, 25, 100));
+ QVERIFY(!hasPixelAround(fb, 75, 100));
+ QVERIFY(!hasPixelAround(fb, 125, 100));
+ QVERIFY(!hasPixelAround(fb, 150, 50));
+ QVERIFY(!hasPixelAround(fb, 150, 150));
+ QVERIFY(!hasPixelAround(fb, 135, 130));
+ QVERIFY(!hasPixelAround(fb, 35, 130));
+}
+
+void tst_drawingmodes::lines()
+{
+ DrawingModeItem::drawingMode = GL_LINES;
+ if (QGuiApplication::primaryScreen()->depth() < 24)
+ QSKIP("This test does not work at display depths < 24");
+ QImage fb = runTest("DrawingModes.qml");
+
+ QCOMPARE(fb.width(), 200);
+ QCOMPARE(fb.height(), 200);
+
+ QVERIFY(hasPixelAround(fb, 135, 70));
+ QVERIFY(hasPixelAround(fb, 175, 100));
+ QVERIFY(!hasPixelAround(fb, 110, 140));
+ QVERIFY(!hasPixelAround(fb, 50, 50));
+ QVERIFY(!hasPixelAround(fb, 50, 150));
+
+ QVERIFY(hasPixelAround(fb, 35, 70));
+ QVERIFY(hasPixelAround(fb, 75, 100));
+ QVERIFY(!hasPixelAround(fb, 25, 100));
+ QVERIFY(!hasPixelAround(fb, 125, 100));
+ QVERIFY(!hasPixelAround(fb, 150, 50));
+ QVERIFY(!hasPixelAround(fb, 150, 150));
+ QVERIFY(!hasPixelAround(fb, 135, 130));
+ QVERIFY(!hasPixelAround(fb, 35, 130));
+}
+
+void tst_drawingmodes::lineStrip()
+{
+ DrawingModeItem::drawingMode = GL_LINE_STRIP;
+ if (QGuiApplication::primaryScreen()->depth() < 24)
+ QSKIP("This test does not work at display depths < 24");
+ QImage fb = runTest("DrawingModes.qml");
+
+ QCOMPARE(fb.width(), 200);
+ QCOMPARE(fb.height(), 200);
+
+ QVERIFY(hasPixelAround(fb, 135, 70));
+ QVERIFY(hasPixelAround(fb, 150, 50));
+ QVERIFY(hasPixelAround(fb, 175, 100));
+ QVERIFY(hasPixelAround(fb, 150, 150));
+
+ QVERIFY(hasPixelAround(fb, 35, 70));
+ QVERIFY(hasPixelAround(fb, 50, 50));
+ QVERIFY(hasPixelAround(fb, 75, 100));
+ QVERIFY(hasPixelAround(fb, 50, 150));
+
+ QVERIFY(!hasPixelAround(fb, 110, 140)); // bad line not there => line strip unbatched
+
+ QVERIFY(!hasPixelAround(fb, 25, 100));
+ QVERIFY(!hasPixelAround(fb, 125, 100));
+ QVERIFY(!hasPixelAround(fb, 135, 130));
+ QVERIFY(!hasPixelAround(fb, 35, 130));
+}
+
+void tst_drawingmodes::lineLoop()
+{
+ DrawingModeItem::drawingMode = GL_LINE_LOOP;
+ if (QGuiApplication::primaryScreen()->depth() < 24)
+ QSKIP("This test does not work at display depths < 24");
+ QImage fb = runTest("DrawingModes.qml");
+
+ QCOMPARE(fb.width(), 200);
+ QCOMPARE(fb.height(), 200);
+
+ QVERIFY(hasPixelAround(fb, 135, 70));
+ QVERIFY(hasPixelAround(fb, 135, 130));
+ QVERIFY(hasPixelAround(fb, 150, 50));
+ QVERIFY(hasPixelAround(fb, 175, 100));
+ QVERIFY(hasPixelAround(fb, 150, 150));
+
+ QVERIFY(hasPixelAround(fb, 35, 70));
+ QVERIFY(hasPixelAround(fb, 35, 130));
+ QVERIFY(hasPixelAround(fb, 50, 50));
+ QVERIFY(hasPixelAround(fb, 75, 100));
+ QVERIFY(hasPixelAround(fb, 50, 150));
+
+ QVERIFY(!hasPixelAround(fb, 110, 140)); // bad line not there => line loop unbatched
+
+ QVERIFY(!hasPixelAround(fb, 25, 100));
+ QVERIFY(!hasPixelAround(fb, 125, 100));
+}
+
+void tst_drawingmodes::triangles()
+{
+ DrawingModeItem::drawingMode = GL_TRIANGLES;
+ if (QGuiApplication::primaryScreen()->depth() < 24)
+ QSKIP("This test does not work at display depths < 24");
+ QImage fb = runTest("DrawingModes.qml");
+
+ QCOMPARE(fb.width(), 200);
+ QCOMPARE(fb.height(), 200);
+
+ QVERIFY(hasPixelAround(fb, 150, 75));
+ QVERIFY(!hasPixelAround(fb, 162, 100));
+ QVERIFY(!hasPixelAround(fb, 150, 125));
+ QVERIFY(!hasPixelAround(fb, 137, 100));
+
+ QVERIFY(!hasPixelAround(fb, 100, 125));
+
+ QVERIFY(hasPixelAround(fb, 50, 75));
+ QVERIFY(!hasPixelAround(fb, 62, 100));
+ QVERIFY(!hasPixelAround(fb, 50, 125));
+ QVERIFY(!hasPixelAround(fb, 37, 100));
+}
+
+
+void tst_drawingmodes::triangleStrip()
+{
+ DrawingModeItem::drawingMode = GL_TRIANGLE_STRIP;
+ if (QGuiApplication::primaryScreen()->depth() < 24)
+ QSKIP("This test does not work at display depths < 24");
+ QImage fb = runTest("DrawingModes.qml");
+
+ QCOMPARE(fb.width(), 200);
+ QCOMPARE(fb.height(), 200);
+
+ QVERIFY(hasPixelAround(fb, 150, 75));
+ QVERIFY(hasPixelAround(fb, 162, 100));
+ QVERIFY(hasPixelAround(fb, 150, 125));
+ QVERIFY(!hasPixelAround(fb, 137, 100));
+
+ QVERIFY(!hasPixelAround(fb, 100, 125)); // batching avoids extra triangle by duplicating vertices.
+
+ QVERIFY(hasPixelAround(fb, 50, 75));
+ QVERIFY(hasPixelAround(fb, 62, 100));
+ QVERIFY(hasPixelAround(fb, 50, 125));
+ QVERIFY(!hasPixelAround(fb, 37, 100));
+}
+
+void tst_drawingmodes::triangleFan()
+{
+ DrawingModeItem::drawingMode = GL_TRIANGLE_FAN;
+ if (QGuiApplication::primaryScreen()->depth() < 24)
+ QSKIP("This test does not work at display depths < 24");
+ QImage fb = runTest("DrawingModes.qml");
+
+ QCOMPARE(fb.width(), 200);
+ QCOMPARE(fb.height(), 200);
+
+ QVERIFY(hasPixelAround(fb, 150, 75));
+ QVERIFY(hasPixelAround(fb, 162, 100));
+ QVERIFY(hasPixelAround(fb, 150, 125));
+ QVERIFY(!hasPixelAround(fb, 137, 100));
+
+ QVERIFY(!hasPixelAround(fb, 100, 125)); // no extra triangle; triangle fan is not batched
+
+ QVERIFY(hasPixelAround(fb, 50, 75));
+ QVERIFY(hasPixelAround(fb, 62, 100));
+ QVERIFY(hasPixelAround(fb, 50, 125));
+ QVERIFY(!hasPixelAround(fb, 37, 100));
+}
+
+
+QTEST_MAIN(tst_drawingmodes)
+
+#include "tst_drawingmodes.moc"
diff --git a/tests/auto/quick/examples/tst_examples.cpp b/tests/auto/quick/examples/tst_examples.cpp
index 1ca809c05f..d5c9aaeb90 100644
--- a/tests/auto/quick/examples/tst_examples.cpp
+++ b/tests/auto/quick/examples/tst_examples.cpp
@@ -88,12 +88,6 @@ tst_examples::tst_examples()
excludedDirs << "snippets/qml/qtbinding";
excludedDirs << "snippets/qml/imports";
-#ifdef QT_NO_WEBKIT
- excludedDirs << "qtquick/modelviews/webview";
- excludedDirs << "demos/webbrowser";
- excludedDirs << "doc/src/snippets/qml/webview";
-#endif
-
#ifdef QT_NO_XMLPATTERNS
excludedDirs << "demos/twitter";
excludedDirs << "demos/flickr";
diff --git a/tests/auto/quick/qquickanimations/data/pathLineUnspecifiedXYBug.qml b/tests/auto/quick/qquickanimations/data/pathLineUnspecifiedXYBug.qml
new file mode 100644
index 0000000000..426360bbcc
--- /dev/null
+++ b/tests/auto/quick/qquickanimations/data/pathLineUnspecifiedXYBug.qml
@@ -0,0 +1,28 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 400
+ height: 400
+
+ Rectangle {
+ id: redRect
+ color: "red"
+ width: 100; height: 100
+ x: 50; y: 50
+ }
+
+ PathAnimation {
+ target: redRect
+ duration: 1000
+ path: Path {
+ startX: 100; startY: 100
+
+ PathLine {
+ x: 200
+ y: 200
+ }
+
+ PathLine {}
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickanimations/data/pathSvgAnimation.qml b/tests/auto/quick/qquickanimations/data/pathSvgAnimation.qml
new file mode 100644
index 0000000000..e409bb031f
--- /dev/null
+++ b/tests/auto/quick/qquickanimations/data/pathSvgAnimation.qml
@@ -0,0 +1,25 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 400
+ height: 400
+
+ Rectangle {
+ id: redRect
+ color: "red"
+ width: 100; height: 100
+ x: 50; y: 50
+ }
+
+ PathAnimation {
+ target: redRect
+ duration: 1000;
+ path: Path {
+ startX: 100; startY: 100
+
+ PathSvg {
+ path: "M 200 200"
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp
index 6e265503a1..fbd6c9c97e 100644
--- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp
+++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp
@@ -101,6 +101,8 @@ private slots:
void scriptActionCrash();
void animatorInvalidTargetCrash();
void defaultPropertyWarning();
+ void pathSvgAnimation();
+ void pathLineUnspecifiedXYBug();
};
#define QTIMED_COMPARE(lhs, rhs) do { \
@@ -1523,6 +1525,48 @@ void tst_qquickanimations::defaultPropertyWarning()
QVERIFY(warnings.isEmpty());
}
+// QTBUG-57666
+void tst_qquickanimations::pathSvgAnimation()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("pathSvgAnimation.qml"));
+ QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(component.create()));
+ QVERIFY(rect);
+
+ QQuickRectangle *redRect = rect->findChild<QQuickRectangle*>();
+ QVERIFY(redRect);
+ QQuickPathAnimation *pathAnim = rect->findChild<QQuickPathAnimation*>();
+ QVERIFY(pathAnim);
+
+ QCOMPARE(redRect->x(), qreal(50));
+ QCOMPARE(redRect->y(), qreal(50));
+
+ pathAnim->start();
+ QTRY_COMPARE(redRect->x(), qreal(200));
+ QCOMPARE(redRect->y(), qreal(200));
+}
+
+// QTBUG-57666
+void tst_qquickanimations::pathLineUnspecifiedXYBug()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("pathLineUnspecifiedXYBug.qml"));
+ QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(component.create()));
+ QVERIFY(rect);
+
+ QQuickRectangle *redRect = rect->findChild<QQuickRectangle*>();
+ QVERIFY(redRect);
+ QQuickPathAnimation *pathAnim = rect->findChild<QQuickPathAnimation*>();
+ QVERIFY(pathAnim);
+
+ QCOMPARE(redRect->x(), qreal(50));
+ QCOMPARE(redRect->y(), qreal(50));
+
+ pathAnim->start();
+ QTRY_COMPARE(redRect->x(), qreal(0));
+ QCOMPARE(redRect->y(), qreal(0));
+}
+
QTEST_MAIN(tst_qquickanimations)
#include "tst_qquickanimations.moc"
diff --git a/tests/auto/quick/qquickapplication/data/tst_displayname.qml b/tests/auto/quick/qquickapplication/data/tst_displayname.qml
new file mode 100644
index 0000000000..f43beaf6de
--- /dev/null
+++ b/tests/auto/quick/qquickapplication/data/tst_displayname.qml
@@ -0,0 +1,7 @@
+import QtQuick 2.0;
+
+Item {
+ id: root;
+ property string displayName: Qt.application.displayName;
+ function updateDisplayName(name) { Qt.application.displayName = name; }
+}
diff --git a/tests/auto/quick/qquickapplication/qquickapplication.pro b/tests/auto/quick/qquickapplication/qquickapplication.pro
index 59445a6c16..c47f5472b7 100644
--- a/tests/auto/quick/qquickapplication/qquickapplication.pro
+++ b/tests/auto/quick/qquickapplication/qquickapplication.pro
@@ -3,5 +3,11 @@ TARGET = tst_qquickapplication
macx:CONFIG -= app_bundle
SOURCES += tst_qquickapplication.cpp
+OTHER_FILES += data/tst_displayname.qml
+
+include (../../shared/util.pri)
+
+TESTDATA = data/*
+
QT += core-private gui-private qml quick qml-private quick-private testlib
diff --git a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp
index 114f906736..d780b91260 100644
--- a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp
+++ b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp
@@ -36,8 +36,9 @@
#include <qpa/qwindowsysteminterface.h>
#include <qpa/qplatformintegration.h>
#include <private/qguiapplication_p.h>
+#include "../../shared/util.h"
-class tst_qquickapplication : public QObject
+class tst_qquickapplication : public QQmlDataTest
{
Q_OBJECT
public:
@@ -51,6 +52,7 @@ private slots:
void inputMethod();
void styleHints();
void cleanup();
+ void displayName();
private:
QQmlEngine engine;
@@ -239,6 +241,29 @@ void tst_qquickapplication::styleHints()
QCOMPARE(qvariant_cast<QObject*>(item->property("styleHints")), qApp->styleHints());
}
+void tst_qquickapplication::displayName()
+{
+ QString name[3] = { QStringLiteral("APP NAME 0"),
+ QStringLiteral("APP NAME 1"),
+ QStringLiteral("APP NAME 2")
+ };
+
+ QQmlComponent component(&engine, testFileUrl("tst_displayname.qml"));
+ QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
+ QVERIFY(item);
+ QQuickView view;
+ item->setParentItem(view.rootObject());
+
+ QCoreApplication::setApplicationName(name[0]);
+ QCOMPARE(qvariant_cast<QString>(item->property("displayName")), name[0]);
+
+ QGuiApplication::setApplicationName(name[1]);
+ QCOMPARE(qvariant_cast<QString>(item->property("displayName")), name[1]);
+
+ QMetaObject::invokeMethod(item, "updateDisplayName", Q_ARG(QVariant, QVariant(name[2])));
+ QCOMPARE(QGuiApplication::applicationDisplayName(), name[2]);
+}
+
QTEST_MAIN(tst_qquickapplication)
#include "tst_qquickapplication.moc"
diff --git a/tests/auto/quick/qquickflickable/data/overshoot.qml b/tests/auto/quick/qquickflickable/data/overshoot.qml
new file mode 100644
index 0000000000..4235156479
--- /dev/null
+++ b/tests/auto/quick/qquickflickable/data/overshoot.qml
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.9
+
+Flickable {
+ width: 200; height: 200
+ contentWidth: rect.width; contentHeight: rect.height
+
+ property real minContentY: 0
+ property real maxContentY: 0
+ onContentYChanged: {
+ minContentY = Math.min(contentY, minContentY)
+ maxContentY = Math.max(contentY, maxContentY)
+ }
+
+ property real minContentX: 0
+ property real maxContentX: 0
+ onContentXChanged: {
+ minContentX = Math.min(contentX, minContentX)
+ maxContentX = Math.max(contentX, maxContentX)
+ }
+
+ property real minVerticalOvershoot: 0
+ property real maxVerticalOvershoot: 0
+ onVerticalOvershootChanged: {
+ minVerticalOvershoot = Math.min(verticalOvershoot, minVerticalOvershoot)
+ maxVerticalOvershoot = Math.max(verticalOvershoot, maxVerticalOvershoot)
+ }
+
+ property real minHorizontalOvershoot: 0
+ property real maxHorizontalOvershoot: 0
+ onHorizontalOvershootChanged: {
+ minHorizontalOvershoot = Math.min(horizontalOvershoot, minHorizontalOvershoot)
+ maxHorizontalOvershoot = Math.max(horizontalOvershoot, maxHorizontalOvershoot)
+ }
+
+ function reset() {
+ minContentY = contentY
+ maxContentY = contentY
+ minContentX = contentX
+ maxContentX = contentX
+ minVerticalOvershoot = 0
+ maxVerticalOvershoot = 0
+ minHorizontalOvershoot = 0
+ maxHorizontalOvershoot = 0
+ }
+
+ Rectangle {
+ id: rect
+ color: "red"
+ width: 400; height: 400
+ }
+}
diff --git a/tests/auto/quick/qquickflickable/data/overshoot_reentrant.qml b/tests/auto/quick/qquickflickable/data/overshoot_reentrant.qml
new file mode 100644
index 0000000000..bc7abba25a
--- /dev/null
+++ b/tests/auto/quick/qquickflickable/data/overshoot_reentrant.qml
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.9
+
+Flickable {
+ width: 200; height: 200
+ contentWidth: rect.width; contentHeight: rect.height
+
+ property real contentPosAdjustment: 0.0
+
+ onContentXChanged: {
+ var adjustment = contentPosAdjustment
+ contentPosAdjustment = 0.0
+ contentX += adjustment
+ }
+
+ onContentYChanged: {
+ var adjustment = contentPosAdjustment
+ contentPosAdjustment = 0.0
+ contentY += adjustment
+ }
+
+ Rectangle {
+ id: rect
+ border.color: "red"
+ border.width: 5
+ width: 400; height: 400
+ }
+}
diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
index 2555322e3e..9ead271bfe 100644
--- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
+++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp
@@ -96,6 +96,9 @@ private slots:
void ratios_smallContent();
void contentXYNotTruncatedToInt();
void keepGrab();
+ void overshoot();
+ void overshoot_data();
+ void overshoot_reentrant();
private:
void flickWithTouch(QQuickWindow *window, QTouchDevice *touchDevice, const QPoint &from, const QPoint &to);
@@ -2057,6 +2060,199 @@ void tst_qquickflickable::keepGrab()
QVERIFY(flickable->contentY() != 0.0);
}
+Q_DECLARE_METATYPE(QQuickFlickable::BoundsBehavior)
+
+void tst_qquickflickable::overshoot()
+{
+ QFETCH(QQuickFlickable::BoundsBehavior, boundsBehavior);
+
+ QScopedPointer<QQuickView> window(new QQuickView);
+ window->setSource(testFileUrl("overshoot.qml"));
+ window->show();
+
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject());
+ QVERIFY(flickable);
+
+ QCOMPARE(flickable->width(), 200.0);
+ QCOMPARE(flickable->height(), 200.0);
+ QCOMPARE(flickable->contentWidth(), 400.0);
+ QCOMPARE(flickable->contentHeight(), 400.0);
+
+ flickable->setBoundsBehavior(boundsBehavior);
+
+ // drag past the beginning
+ QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(10, 10));
+ QTest::mouseMove(window.data(), QPoint(20, 20));
+ QTest::mouseMove(window.data(), QPoint(30, 30));
+ QTest::mouseMove(window.data(), QPoint(40, 40));
+ QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(50, 50));
+
+ if (boundsBehavior & QQuickFlickable::DragOverBounds) {
+ QVERIFY(flickable->property("minVerticalOvershoot").toReal() < 0.0);
+ QVERIFY(flickable->property("minHorizontalOvershoot").toReal() < 0.0);
+ QCOMPARE(flickable->property("minContentY").toReal(),
+ flickable->property("minVerticalOvershoot").toReal());
+ QCOMPARE(flickable->property("minContentX").toReal(),
+ flickable->property("minHorizontalOvershoot").toReal());
+ } else {
+ QCOMPARE(flickable->property("minContentY").toReal(), 0.0);
+ QCOMPARE(flickable->property("minContentX").toReal(), 0.0);
+ QCOMPARE(flickable->property("minVerticalOvershoot").toReal(), 0.0);
+ QCOMPARE(flickable->property("minHorizontalOvershoot").toReal(), 0.0);
+ }
+ QCOMPARE(flickable->property("maxContentY").toReal(), 0.0);
+ QCOMPARE(flickable->property("maxContentX").toReal(), 0.0);
+ QCOMPARE(flickable->property("maxVerticalOvershoot").toReal(), 0.0);
+ QCOMPARE(flickable->property("maxHorizontalOvershoot").toReal(), 0.0);
+
+ flickable->setContentX(20.0);
+ flickable->setContentY(20.0);
+ QMetaObject::invokeMethod(flickable, "reset");
+
+ // flick past the beginning
+ flick(window.data(), QPoint(10, 10), QPoint(50, 50), 100);
+ QTRY_VERIFY(!flickable->property("flicking").toBool());
+
+ if (boundsBehavior & QQuickFlickable::OvershootBounds) {
+ QVERIFY(flickable->property("minVerticalOvershoot").toReal() < 0.0);
+ QVERIFY(flickable->property("minHorizontalOvershoot").toReal() < 0.0);
+ QCOMPARE(flickable->property("minContentY").toReal(),
+ flickable->property("minVerticalOvershoot").toReal());
+ QCOMPARE(flickable->property("minContentX").toReal(),
+ flickable->property("minHorizontalOvershoot").toReal());
+ } else {
+ QCOMPARE(flickable->property("minContentY").toReal(), 0.0);
+ QCOMPARE(flickable->property("minContentX").toReal(), 0.0);
+ QCOMPARE(flickable->property("minVerticalOvershoot").toReal(), 0.0);
+ QCOMPARE(flickable->property("minHorizontalOvershoot").toReal(), 0.0);
+ }
+ QCOMPARE(flickable->property("maxContentY").toReal(), 20.0);
+ QCOMPARE(flickable->property("maxContentX").toReal(), 20.0);
+ QCOMPARE(flickable->property("maxVerticalOvershoot").toReal(), 0.0);
+ QCOMPARE(flickable->property("maxHorizontalOvershoot").toReal(), 0.0);
+
+ flickable->setContentX(200.0);
+ flickable->setContentY(200.0);
+ QMetaObject::invokeMethod(flickable, "reset");
+
+ // drag past the end
+ QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(50, 50));
+ QTest::mouseMove(window.data(), QPoint(40, 40));
+ QTest::mouseMove(window.data(), QPoint(30, 30));
+ QTest::mouseMove(window.data(), QPoint(20, 20));
+ QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(10, 10));
+
+ if (boundsBehavior & QQuickFlickable::DragOverBounds) {
+ QVERIFY(flickable->property("maxVerticalOvershoot").toReal() > 0.0);
+ QVERIFY(flickable->property("maxHorizontalOvershoot").toReal() > 0.0);
+ QCOMPARE(flickable->property("maxContentY").toReal() - 200.0,
+ flickable->property("maxVerticalOvershoot").toReal());
+ QCOMPARE(flickable->property("maxContentX").toReal() - 200.0,
+ flickable->property("maxHorizontalOvershoot").toReal());
+ } else {
+ QCOMPARE(flickable->property("maxContentY").toReal(), 200.0);
+ QCOMPARE(flickable->property("maxContentX").toReal(), 200.0);
+ QCOMPARE(flickable->property("maxVerticalOvershoot").toReal(), 0.0);
+ QCOMPARE(flickable->property("maxHorizontalOvershoot").toReal(), 0.0);
+ }
+ QCOMPARE(flickable->property("minContentY").toReal(), 200.0);
+ QCOMPARE(flickable->property("minContentX").toReal(), 200.0);
+ QCOMPARE(flickable->property("minVerticalOvershoot").toReal(), 0.0);
+ QCOMPARE(flickable->property("minHorizontalOvershoot").toReal(), 0.0);
+
+ flickable->setContentX(180.0);
+ flickable->setContentY(180.0);
+ QMetaObject::invokeMethod(flickable, "reset");
+
+ // flick past the end
+ flick(window.data(), QPoint(50, 50), QPoint(10, 10), 100);
+ QTRY_VERIFY(!flickable->property("flicking").toBool());
+
+ if (boundsBehavior & QQuickFlickable::OvershootBounds) {
+ QVERIFY(flickable->property("maxVerticalOvershoot").toReal() > 0.0);
+ QVERIFY(flickable->property("maxHorizontalOvershoot").toReal() > 0.0);
+ QCOMPARE(flickable->property("maxContentY").toReal() - 200.0,
+ flickable->property("maxVerticalOvershoot").toReal());
+ QCOMPARE(flickable->property("maxContentX").toReal() - 200.0,
+ flickable->property("maxHorizontalOvershoot").toReal());
+ } else {
+ QCOMPARE(flickable->property("maxContentY").toReal(), 200.0);
+ QCOMPARE(flickable->property("maxContentX").toReal(), 200.0);
+ QCOMPARE(flickable->property("maxVerticalOvershoot").toReal(), 0.0);
+ QCOMPARE(flickable->property("maxHorizontalOvershoot").toReal(), 0.0);
+ }
+ QCOMPARE(flickable->property("minContentY").toReal(), 180.0);
+ QCOMPARE(flickable->property("minContentX").toReal(), 180.0);
+ QCOMPARE(flickable->property("minVerticalOvershoot").toReal(), 0.0);
+ QCOMPARE(flickable->property("minHorizontalOvershoot").toReal(), 0.0);
+}
+
+void tst_qquickflickable::overshoot_data()
+{
+ QTest::addColumn<QQuickFlickable::BoundsBehavior>("boundsBehavior");
+
+ QTest::newRow("StopAtBounds")
+ << QQuickFlickable::BoundsBehavior(QQuickFlickable::StopAtBounds);
+ QTest::newRow("DragOverBounds")
+ << QQuickFlickable::BoundsBehavior(QQuickFlickable::DragOverBounds);
+ QTest::newRow("OvershootBounds")
+ << QQuickFlickable::BoundsBehavior(QQuickFlickable::OvershootBounds);
+ QTest::newRow("DragAndOvershootBounds")
+ << QQuickFlickable::BoundsBehavior(QQuickFlickable::DragAndOvershootBounds);
+}
+
+void tst_qquickflickable::overshoot_reentrant()
+{
+ QScopedPointer<QQuickView> window(new QQuickView);
+ window->setSource(testFileUrl("overshoot_reentrant.qml"));
+ window->show();
+
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject());
+ QVERIFY(flickable);
+
+ // horizontal
+ flickable->setContentX(-10.0);
+ QCOMPARE(flickable->contentX(), -10.0);
+ QCOMPARE(flickable->horizontalOvershoot(), -10.0);
+
+ flickable->setProperty("contentPosAdjustment", -5.0);
+ flickable->setContentX(-20.0);
+ QCOMPARE(flickable->contentX(), -25.0);
+ QCOMPARE(flickable->horizontalOvershoot(), -25.0);
+
+ flickable->setContentX(210);
+ QCOMPARE(flickable->contentX(), 210.0);
+ QCOMPARE(flickable->horizontalOvershoot(), 10.0);
+
+ flickable->setProperty("contentPosAdjustment", 5.0);
+ flickable->setContentX(220.0);
+ QCOMPARE(flickable->contentX(), 225.0);
+ QCOMPARE(flickable->horizontalOvershoot(), 25.0);
+
+ // vertical
+ flickable->setContentY(-10.0);
+ QCOMPARE(flickable->contentY(), -10.0);
+ QCOMPARE(flickable->verticalOvershoot(), -10.0);
+
+ flickable->setProperty("contentPosAdjustment", -5.0);
+ flickable->setContentY(-20.0);
+ QCOMPARE(flickable->contentY(), -25.0);
+ QCOMPARE(flickable->verticalOvershoot(), -25.0);
+
+ flickable->setContentY(210);
+ QCOMPARE(flickable->contentY(), 210.0);
+ QCOMPARE(flickable->verticalOvershoot(), 10.0);
+
+ flickable->setProperty("contentPosAdjustment", 5.0);
+ flickable->setContentY(220.0);
+ QCOMPARE(flickable->contentY(), 225.0);
+ QCOMPARE(flickable->verticalOvershoot(), 25.0);
+}
+
QTEST_MAIN(tst_qquickflickable)
#include "tst_qquickflickable.moc"
diff --git a/tests/auto/quick/qquickgraphicsinfo/tst_qquickgraphicsinfo.cpp b/tests/auto/quick/qquickgraphicsinfo/tst_qquickgraphicsinfo.cpp
index 650892d650..4da6da6043 100644
--- a/tests/auto/quick/qquickgraphicsinfo/tst_qquickgraphicsinfo.cpp
+++ b/tests/auto/quick/qquickgraphicsinfo/tst_qquickgraphicsinfo.cpp
@@ -51,7 +51,7 @@ private slots:
void tst_QQuickGraphicsInfo::testProperties()
{
QQuickView view;
- view.setSource(QUrl::fromLocalFile("data/basic.qml"));
+ view.setSource(QUrl("data/basic.qml"));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp
index d345163db5..4699f947a1 100644
--- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp
+++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp
@@ -145,9 +145,9 @@ void tst_qquickimage::imageSource_data()
QTest::newRow("remote") << "/colors.png" << 120.0 << 120.0 << true << false << true << "";
QTest::newRow("remote redirected") << "/oldcolors.png" << 120.0 << 120.0 << true << false << false << "";
if (QImageReader::supportedImageFormats().contains("svg"))
- QTest::newRow("remote svg") << "/heart.svg" << 550.0 << 500.0 << true << false << false << "";
+ QTest::newRow("remote svg") << "/heart.svg" << 595.0 << 841.0 << true << false << false << "";
if (QImageReader::supportedImageFormats().contains("svgz"))
- QTest::newRow("remote svgz") << "/heart.svgz" << 550.0 << 500.0 << true << false << false << "";
+ QTest::newRow("remote svgz") << "/heart.svgz" << 595.0 << 841.0 << true << false << false << "";
QTest::newRow("remote not found") << "/no-such-file.png" << 0.0 << 0.0 << true
<< false << true << "<Unknown File>:2:1: QML Image: Error transferring {{ServerBaseUrl}}/no-such-file.png - server replied: Not found";
@@ -309,10 +309,6 @@ void tst_qquickimage::mirror()
qreal devicePixelRatio = 1.0;
foreach (QQuickImage::FillMode fillMode, fillModes) {
-#if defined(Q_OS_BLACKBERRY)
- QWindow dummy; // On BlackBerry first window is always full screen,
- dummy.showFullScreen(); // so make test window a second window.
-#endif
QScopedPointer<QQuickView> window(new QQuickView);
window->setSource(testFileUrl("mirror.qml"));
@@ -402,12 +398,12 @@ void tst_qquickimage::svg()
component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
QQuickImage *obj = qobject_cast<QQuickImage*>(component.create());
QVERIFY(obj != 0);
- QCOMPARE(obj->width(), 300.0);
- QCOMPARE(obj->height(), 273.0);
+ QCOMPARE(obj->width(), 212.0);
+ QCOMPARE(obj->height(), 300.0);
obj->setSourceSize(QSize(200,200));
- QCOMPARE(obj->width(), 200.0);
- QCOMPARE(obj->height(), 182.0);
+ QCOMPARE(obj->width(), 141.0);
+ QCOMPARE(obj->height(), 200.0);
delete obj;
}
diff --git a/tests/auto/quick/qquickitem/data/shortcutOverride.qml b/tests/auto/quick/qquickitem/data/shortcutOverride.qml
new file mode 100644
index 0000000000..fab9175c17
--- /dev/null
+++ b/tests/auto/quick/qquickitem/data/shortcutOverride.qml
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.8
+import QtQuick.Window 2.1
+
+Item {
+ property int escapeHandlerActivationCount: 0
+ property int shortcutActivationCount: 0
+ property alias escapeItem: escapeItem
+
+ Item {
+ id: escapeItem
+ objectName: "escapeItem"
+ focus: true
+
+ // By accepting shortcut override events when the key is Qt.Key_Escape,
+ // we can ensure that our Keys.onEscapePressed handler (below) will be called.
+ Keys.onShortcutOverride: event.accepted = (event.key === Qt.Key_Escape)
+
+ Keys.onEscapePressed: {
+ // Pretend that we just did some really important stuff that was triggered
+ // by the escape key (like might occur in a popup that has a keyboard shortcut editor, for example).
+ // Now that we're done, we no longer need focus, so we won't accept future shorcut override events.
+ focus = false;
+ event.accepted = true;
+ ++escapeHandlerActivationCount;
+ }
+ }
+
+ Shortcut {
+ sequence: "Escape"
+ onActivated: ++shortcutActivationCount
+ }
+}
diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp
index d0139b6cdf..10a3a0bfa8 100644
--- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp
@@ -48,7 +48,8 @@ public:
TestItem(QQuickItem *parent = 0)
: QQuickItem(parent), focused(false), pressCount(0), releaseCount(0)
, wheelCount(0), acceptIncomingTouchEvents(true)
- , touchEventReached(false), timestamp(0) {}
+ , touchEventReached(false), timestamp(0)
+ , lastWheelEventPos(0, 0), lastWheelEventGlobalPos(0, 0) {}
bool focused;
int pressCount;
@@ -57,6 +58,8 @@ public:
bool acceptIncomingTouchEvents;
bool touchEventReached;
ulong timestamp;
+ QPoint lastWheelEventPos;
+ QPoint lastWheelEventGlobalPos;
protected:
virtual void focusInEvent(QFocusEvent *) { Q_ASSERT(!focused); focused = true; }
virtual void focusOutEvent(QFocusEvent *) { Q_ASSERT(focused); focused = false; }
@@ -66,7 +69,13 @@ protected:
touchEventReached = true;
event->setAccepted(acceptIncomingTouchEvents);
}
- virtual void wheelEvent(QWheelEvent *event) { event->accept(); ++wheelCount; timestamp = event->timestamp(); }
+ virtual void wheelEvent(QWheelEvent *event) {
+ event->accept();
+ ++wheelCount;
+ timestamp = event->timestamp();
+ lastWheelEventPos = event->pos();
+ lastWheelEventGlobalPos = event->globalPos();
+ }
};
class TestWindow: public QQuickWindow
@@ -172,6 +181,8 @@ private slots:
void ignoreButtonPressNotInAcceptedMouseButtons();
+ void shortcutOverride();
+
private:
enum PaintOrderOp {
@@ -1420,19 +1431,24 @@ void tst_qquickitem::wheelEvent()
const bool shouldReceiveWheelEvents = visible && enabled;
+ const int width = 200;
+ const int height = 200;
+
QQuickWindow window;
- window.resize(200, 200);
+ window.resize(width, height);
window.show();
QTest::qWaitForWindowExposed(&window);
TestItem *item = new TestItem;
- item->setSize(QSizeF(200, 100));
+ item->setSize(QSizeF(width, height));
item->setParentItem(window.contentItem());
item->setEnabled(enabled);
item->setVisible(visible);
- QWheelEvent event(QPoint(100, 50), -120, Qt::NoButton, Qt::NoModifier, Qt::Vertical);
+ QPoint localPoint(width / 2, height / 2);
+ QPoint globalPoint = window.mapToGlobal(localPoint);
+ QWheelEvent event(localPoint, globalPoint, -120, Qt::NoButton, Qt::NoModifier, Qt::Vertical);
event.setTimestamp(123456UL);
event.setAccepted(false);
QGuiApplication::sendEvent(&window, &event);
@@ -1441,6 +1457,8 @@ void tst_qquickitem::wheelEvent()
QVERIFY(event.isAccepted());
QCOMPARE(item->wheelCount, 1);
QCOMPARE(item->timestamp, 123456UL);
+ QCOMPARE(item->lastWheelEventPos, localPoint);
+ QCOMPARE(item->lastWheelEventGlobalPos, globalPoint);
} else {
QVERIFY(!event.isAccepted());
QCOMPARE(item->wheelCount, 0);
@@ -2036,6 +2054,39 @@ void tst_qquickitem::ignoreButtonPressNotInAcceptedMouseButtons()
QCOMPARE(item.releaseCount, 1);
}
+void tst_qquickitem::shortcutOverride()
+{
+ QQuickView view;
+ view.setSource(testFileUrl("shortcutOverride.qml"));
+ ensureFocus(&view);
+
+ QCOMPARE(view.rootObject()->property("escapeHandlerActivationCount").toInt(), 0);
+ QCOMPARE(view.rootObject()->property("shortcutActivationCount").toInt(), 0);
+
+ QQuickItem *escapeItem = view.rootObject()->property("escapeItem").value<QQuickItem*>();
+ QVERIFY(escapeItem);
+ QVERIFY(escapeItem->hasActiveFocus());
+
+ // escapeItem's onEscapePressed handler should accept the first escape press event.
+ QTest::keyPress(&view, Qt::Key_Escape);
+ QCOMPARE(view.rootObject()->property("escapeHandlerActivationCount").toInt(), 1);
+ QCOMPARE(view.rootObject()->property("shortcutActivationCount").toInt(), 0);
+ // Now it shouldn't have focus, so it can't handle the next escape press event.
+ QVERIFY(!escapeItem->hasActiveFocus());
+
+ QTest::keyRelease(&view, Qt::Key_Escape);
+ QCOMPARE(view.rootObject()->property("escapeHandlerActivationCount").toInt(), 1);
+ QCOMPARE(view.rootObject()->property("shortcutActivationCount").toInt(), 0);
+
+ QTest::keyPress(&view, Qt::Key_Escape);
+ QCOMPARE(view.rootObject()->property("escapeHandlerActivationCount").toInt(), 1);
+ QCOMPARE(view.rootObject()->property("shortcutActivationCount").toInt(), 1);
+
+ QTest::keyRelease(&view, Qt::Key_Escape);
+ QCOMPARE(view.rootObject()->property("escapeHandlerActivationCount").toInt(), 1);
+ QCOMPARE(view.rootObject()->property("shortcutActivationCount").toInt(), 1);
+}
+
QTEST_MAIN(tst_qquickitem)
#include "tst_qquickitem.moc"
diff --git a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
index 44310008d6..5419778cfc 100644
--- a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
+++ b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp
@@ -44,10 +44,6 @@ public:
QImage runTest(const QString &fileName)
{
-#if defined(Q_OS_BLACKBERRY)
- QWindow dummy; // On BlackBerry first window is always full screen,
- dummy.showFullScreen(); // so make test window a second window.
-#endif
QQuickView view;
view.setSource(testFileUrl(fileName));
diff --git a/tests/auto/quick/qquicklayouts/data/rowlayout/Container2.qml b/tests/auto/quick/qquicklayouts/data/rowlayout/Container2.qml
new file mode 100644
index 0000000000..248652e82b
--- /dev/null
+++ b/tests/auto/quick/qquicklayouts/data/rowlayout/Container2.qml
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.9
+import QtQuick.Layouts 1.3
+
+Item {
+ objectName: "qtbug51927-container"
+ visible: true
+
+ default property alias _contents: customContent.data
+
+ ColumnLayout {
+ id: customContent
+ objectName: "qtbug51927-columnLayout"
+ anchors.fill: parent
+ }
+}
diff --git a/tests/auto/quick/qquicklayouts/data/rowlayout/ContainerUser2.qml b/tests/auto/quick/qquicklayouts/data/rowlayout/ContainerUser2.qml
new file mode 100644
index 0000000000..9def782d4a
--- /dev/null
+++ b/tests/auto/quick/qquicklayouts/data/rowlayout/ContainerUser2.qml
@@ -0,0 +1,46 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+
+Container2 {
+ visible: true
+ Item {}
+}
diff --git a/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml b/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml
index 97860458fe..4346c5283e 100644
--- a/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml
+++ b/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml
@@ -959,5 +959,15 @@ Item {
// Shouldn't crash.
containerUser.destroy();
}
+
+ function test_defaultPropertyAliasCrashAgain() {
+ var containerUserComponent = Qt.createComponent("rowlayout/ContainerUser2.qml");
+ compare(containerUserComponent.status, Component.Ready);
+
+ var containerUser = createTemporaryObject(containerUserComponent, testCase);
+ verify(containerUser);
+
+ // Shouldn't crash upon destroying containerUser.
+ }
}
}
diff --git a/tests/auto/quick/qquicklistview/data/flickBothDirections.qml b/tests/auto/quick/qquicklistview/data/flickBothDirections.qml
new file mode 100644
index 0000000000..5d80ce4110
--- /dev/null
+++ b/tests/auto/quick/qquicklistview/data/flickBothDirections.qml
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import QtQuick 2.9
+
+Rectangle {
+ width: 200
+ height: 200
+ ListView {
+ id: list
+ objectName: "list"
+ width: 100
+ height: 100
+ model: 20
+ anchors.centerIn: parent
+ orientation: initialOrientation
+ contentWidth: initialContentWidth
+ contentHeight: initialContentHeight
+ flickableDirection: initialFlickableDirection
+ delegate: Rectangle {
+ width: list.orientation == ListView.Vertical ? 120 : 10
+ height: list.orientation == ListView.Vertical ? 20 : 110
+ color: Qt.rgba(0, 0, index / 19, 1)
+ opacity: 0.8
+ }
+ Rectangle {
+ z: -1
+ width: 100
+ height: 100
+ border.width: 1
+ border.color: "red"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index 4816d9c341..ff06c1e1a4 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -53,6 +53,7 @@ Q_DECLARE_METATYPE(Qt::LayoutDirection)
Q_DECLARE_METATYPE(QQuickItemView::VerticalLayoutDirection)
Q_DECLARE_METATYPE(QQuickItemView::PositionMode)
Q_DECLARE_METATYPE(QQuickListView::Orientation)
+Q_DECLARE_METATYPE(QQuickFlickable::FlickableDirection)
Q_DECLARE_METATYPE(Qt::Key)
using namespace QQuickViewTestUtil;
@@ -205,6 +206,8 @@ private slots:
void multipleDisplaced();
void flickBeyondBounds();
+ void flickBothDirections();
+ void flickBothDirections_data();
void destroyItemOnCreation();
void parentBinding();
@@ -7123,6 +7126,82 @@ void tst_QQuickListView::flickBeyondBounds()
}
}
+void tst_QQuickListView::flickBothDirections()
+{
+ QFETCH(bool, initValues);
+ QFETCH(QQuickListView::Orientation, orientation);
+ QFETCH(QQuickFlickable::FlickableDirection, flickableDirection);
+ QFETCH(qreal, contentWidth);
+ QFETCH(qreal, contentHeight);
+ QFETCH(QPointF, targetPos);
+
+ QQuickView *window = getView();
+ QQuickViewTestUtil::moveMouseAway(window);
+
+ QQmlContext *ctxt = window->rootContext();
+ ctxt->setContextProperty("initialOrientation", initValues ? orientation : QQuickListView::Vertical);
+ ctxt->setContextProperty("initialFlickableDirection", initValues ? flickableDirection : QQuickFlickable::VerticalFlick);
+ ctxt->setContextProperty("initialContentWidth", initValues ? contentWidth : -1);
+ ctxt->setContextProperty("initialContentHeight", initValues ? contentHeight : -1);
+
+ window->setSource(testFileUrl("flickBothDirections.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickListView *listview = findItem<QQuickListView>(window->rootObject(), "list");
+ QVERIFY(listview);
+
+ if (!initValues) {
+ listview->setOrientation(orientation);
+ listview->setFlickableDirection(flickableDirection);
+ if (contentWidth > 0)
+ listview->setContentWidth(contentWidth);
+ if (contentHeight > 0)
+ listview->setContentHeight(contentHeight);
+ }
+
+ flick(window, QPoint(100, 100), QPoint(25, 25), 50);
+ QVERIFY(listview->isMoving());
+ QTRY_VERIFY(!listview->isMoving());
+ QCOMPARE(listview->contentX(), targetPos.x());
+ QCOMPARE(listview->contentY(), targetPos.y());
+}
+
+void tst_QQuickListView::flickBothDirections_data()
+{
+ QTest::addColumn<bool>("initValues");
+ QTest::addColumn<QQuickListView::Orientation>("orientation");
+ QTest::addColumn<QQuickFlickable::FlickableDirection>("flickableDirection");
+ QTest::addColumn<qreal>("contentWidth");
+ QTest::addColumn<qreal>("contentHeight");
+ QTest::addColumn<QPointF>("targetPos");
+
+ // model: 20
+ // listview: 100x100
+ // vertical delegate: 120x20 -> contentHeight: 20x20=400
+ // horizontal delegate: 10x110 -> contentWidth: 20x10=200
+
+ QTest::newRow("init:vertical,-1") << true << QQuickListView::Vertical << QQuickFlickable::VerticalFlick << -1. << -1. << QPointF(0, 300);
+ QTest::newRow("init:vertical,120") << true << QQuickListView::Vertical << QQuickFlickable::VerticalFlick<< 120. << -1. << QPointF(0, 300);
+ QTest::newRow("init:vertical,auto,-1") << true << QQuickListView::Vertical << QQuickFlickable::AutoFlickDirection << -1. << -1. << QPointF(0, 300);
+ QTest::newRow("init:vertical,auto,120") << true << QQuickListView::Vertical << QQuickFlickable::AutoFlickDirection << 120. << -1. << QPointF(20, 300);
+
+ QTest::newRow("completed:vertical,-1") << false << QQuickListView::Vertical << QQuickFlickable::VerticalFlick << -1. << -1. << QPointF(0, 300);
+ QTest::newRow("completed:vertical,120") << false << QQuickListView::Vertical << QQuickFlickable::VerticalFlick << 120. << -1. << QPointF(0, 300);
+ QTest::newRow("completed:vertical,auto,-1") << false << QQuickListView::Vertical << QQuickListView::AutoFlickDirection << -1. << -1. << QPointF(0, 300);
+ QTest::newRow("completed:vertical,auto,120") << false << QQuickListView::Vertical << QQuickListView::AutoFlickDirection << 120. << -1. << QPointF(20, 300);
+
+ QTest::newRow("init:horizontal,-1") << true << QQuickListView::Horizontal << QQuickFlickable::HorizontalFlick << -1. << -1. << QPointF(100, 0);
+ QTest::newRow("init:horizontal,110") << true << QQuickListView::Horizontal << QQuickFlickable::HorizontalFlick <<-1. << 110. << QPointF(100, 0);
+ QTest::newRow("init:horizontal,auto,-1") << true << QQuickListView::Horizontal << QQuickListView::AutoFlickDirection << -1. << -1. << QPointF(100, 0);
+ QTest::newRow("init:horizontal,auto,110") << true << QQuickListView::Horizontal << QQuickListView::AutoFlickDirection << -1. << 110. << QPointF(100, 10);
+
+ QTest::newRow("completed:horizontal,-1") << false << QQuickListView::Horizontal << QQuickFlickable::HorizontalFlick << -1. << -1. << QPointF(100, 0);
+ QTest::newRow("completed:horizontal,110") << false << QQuickListView::Horizontal << QQuickFlickable::HorizontalFlick << -1. << 110. << QPointF(100, 0);
+ QTest::newRow("completed:horizontal,auto,-1") << false << QQuickListView::Horizontal << QQuickListView::AutoFlickDirection << -1. << -1. << QPointF(100, 0);
+ QTest::newRow("completed:horizontal,auto,110") << false << QQuickListView::Horizontal << QQuickListView::AutoFlickDirection << -1. << 110. << QPointF(100, 10);
+}
+
void tst_QQuickListView::destroyItemOnCreation()
{
QaimModel model;
diff --git a/tests/auto/quick/qquickmousearea/data/pressAndHold.qml b/tests/auto/quick/qquickmousearea/data/pressAndHold.qml
new file mode 100644
index 0000000000..bde195965e
--- /dev/null
+++ b/tests/auto/quick/qquickmousearea/data/pressAndHold.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.9
+
+Item {
+ width: 100
+ height: 100
+
+ MouseArea {
+ id: mouseArea
+ objectName: "mouseArea"
+ anchors.fill: parent
+ }
+}
diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
index c2a2118598..01bce46ccb 100644
--- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
+++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
@@ -128,6 +128,8 @@ private slots:
void containsPress();
void ignoreBySource();
void notPressedAfterStolenGrab();
+ void pressAndHold_data();
+ void pressAndHold();
private:
int startDragDistance() const {
@@ -2128,6 +2130,49 @@ void tst_QQuickMouseArea::notPressedAfterStolenGrab()
QVERIFY(!ma->pressed());
}
+void tst_QQuickMouseArea::pressAndHold_data()
+{
+ QTest::addColumn<int>("pressAndHoldInterval");
+ QTest::addColumn<int>("waitTime");
+
+ QTest::newRow("default") << -1 << QGuiApplication::styleHints()->mousePressAndHoldInterval();
+ QTest::newRow("short") << 500 << 500;
+ QTest::newRow("long") << 1000 << 1000;
+}
+
+void tst_QQuickMouseArea::pressAndHold()
+{
+ QFETCH(int, pressAndHoldInterval);
+ QFETCH(int, waitTime);
+
+ QQuickView window;
+ QByteArray errorMessage;
+ QVERIFY2(initView(window, testFileUrl("pressAndHold.qml"), true, &errorMessage), errorMessage.constData());
+ window.show();
+ window.requestActivate();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QQuickItem *root = window.rootObject();
+ QVERIFY(root != 0);
+
+ QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mouseArea");
+ QVERIFY(mouseArea != 0);
+
+ QSignalSpy pressAndHoldSpy(mouseArea, &QQuickMouseArea::pressAndHold);
+
+ if (pressAndHoldInterval > -1)
+ mouseArea->setPressAndHoldInterval(pressAndHoldInterval);
+ else
+ mouseArea->resetPressAndHoldInterval();
+
+ QElapsedTimer t;
+ t.start();
+ QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(50, 50));
+ QVERIFY(pressAndHoldSpy.wait());
+ // should be off by no more than 20% of waitTime
+ QVERIFY(qAbs(t.elapsed() - waitTime) < (waitTime * 0.2));
+ QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(50, 50));
+}
+
QTEST_MAIN(tst_QQuickMouseArea)
#include "tst_qquickmousearea.moc"
diff --git a/tests/auto/quick/qquickpathview/data/removePath.qml b/tests/auto/quick/qquickpathview/data/removePath.qml
new file mode 100644
index 0000000000..85029f3eaf
--- /dev/null
+++ b/tests/auto/quick/qquickpathview/data/removePath.qml
@@ -0,0 +1,26 @@
+import QtQuick 2.0
+
+PathView {
+ width: 240
+ height: 200
+
+ path: myPath
+
+ delegate: Text { text: value }
+ model: 10
+
+ Path {
+ id: myPath
+ startX: 120; startY: 100
+ PathQuad { x: 120; y: 25; controlX: 260; controlY: 75 }
+ PathQuad { x: 120; y: 100; controlX: -20; controlY: 75 }
+ }
+
+ function removePath() {
+ path = null
+ }
+
+ function setPath() {
+ path = myPath
+ }
+}
diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp
index ba3d182efc..b01d0c3cec 100644
--- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp
+++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp
@@ -141,6 +141,7 @@ private slots:
void addCustomAttribute();
void movementDirection_data();
void movementDirection();
+ void removePath();
};
class TestObject : public QObject
@@ -2504,6 +2505,19 @@ void tst_QQuickPathView::movementDirection()
verify_offsets(pathview, toidx, fromoffset, tooffset);
}
+void tst_QQuickPathView::removePath()
+{
+ QScopedPointer<QQuickView> window(createView());
+ window->setSource(testFileUrl("removePath.qml"));
+ window->show();
+
+ QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
+ QVERIFY(pathview != 0);
+
+ QVERIFY(QMetaObject::invokeMethod(pathview, "removePath"));
+ QVERIFY(QMetaObject::invokeMethod(pathview, "setPath"));
+}
+
QTEST_MAIN(tst_QQuickPathView)
#include "tst_qquickpathview.moc"
diff --git a/tests/auto/quick/qquickscreen/data/screen.qml b/tests/auto/quick/qquickscreen/data/screen.qml
index c246b3cd83..cf60d0ae40 100644
--- a/tests/auto/quick/qquickscreen/data/screen.qml
+++ b/tests/auto/quick/qquickscreen/data/screen.qml
@@ -1,5 +1,5 @@
import QtQuick 2.0
-import QtQuick.Window 2.0 as Window
+import QtQuick.Window 2.3 as Window
Item {
width: 100
@@ -10,6 +10,18 @@ Item {
property int priOrientation: Window.Screen.primaryOrientation
property int updateMask: Window.Screen.orientationUpdateMask
property real devicePixelRatio: Window.Screen.devicePixelRatio
+ property int vx: Window.Screen.virtualX
+ property int vy: Window.Screen.virtualY
Window.Screen.orientationUpdateMask: Qt.LandscapeOrientation | Qt.InvertedLandscapeOrientation
+
+ property int screenCount: Qt.application.screens.length
+
+ property variant allScreens
+ Component.onCompleted: {
+ allScreens = [];
+ var s = Qt.application.screens;
+ for (var i = 0; i < s.length; ++i)
+ allScreens.push(s[i]);
+ }
}
diff --git a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp
index 92afdf6864..26b687a4a6 100644
--- a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp
+++ b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp
@@ -33,13 +33,15 @@
#include <QtQuick/QQuickView>
#include <QtGui/QScreen>
#include "../../shared/util.h"
-
+#include <QtQuick/private/qquickscreen_p.h>
+#include <QDebug>
class tst_qquickscreen : public QQmlDataTest
{
Q_OBJECT
private slots:
void basicProperties();
void screenOnStartup();
+ void fullScreenList();
};
void tst_qquickscreen::basicProperties()
@@ -62,6 +64,10 @@ void tst_qquickscreen::basicProperties()
QCOMPARE(int(screen->orientationUpdateMask()), root->property("updateMask").toInt());
QCOMPARE(screen->devicePixelRatio(), root->property("devicePixelRatio").toReal());
QVERIFY(screen->devicePixelRatio() >= 1.0);
+ QCOMPARE(screen->geometry().x(), root->property("vx").toInt());
+ QCOMPARE(screen->geometry().y(), root->property("vy").toInt());
+
+ QVERIFY(root->property("screenCount").toInt() == QGuiApplication::screens().count());
}
void tst_qquickscreen::screenOnStartup()
@@ -83,6 +89,38 @@ void tst_qquickscreen::screenOnStartup()
QCOMPARE(int(screen->orientationUpdateMask()), root->property("updateMask").toInt());
QCOMPARE(screen->devicePixelRatio(), root->property("devicePixelRatio").toReal());
QVERIFY(screen->devicePixelRatio() >= 1.0);
+ QCOMPARE(screen->geometry().x(), root->property("vx").toInt());
+ QCOMPARE(screen->geometry().y(), root->property("vy").toInt());
+}
+
+void tst_qquickscreen::fullScreenList()
+{
+ QQuickView view;
+ view.setSource(testFileUrl("screen.qml"));
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
+ QQuickItem* root = view.rootObject();
+ QVERIFY(root);
+
+ QJSValue screensArray = root->property("allScreens").value<QJSValue>();
+ QVERIFY(screensArray.isArray());
+ int length = screensArray.property("length").toInt();
+ const QList<QScreen *> screenList = QGuiApplication::screens();
+ QVERIFY(length == screenList.count());
+
+ for (int i = 0; i < length; ++i) {
+ QQuickScreenInfo *info = qobject_cast<QQuickScreenInfo *>(screensArray.property(i).toQObject());
+ QVERIFY(info != nullptr);
+ QCOMPARE(screenList[i]->name(), info->name());
+ QCOMPARE(screenList[i]->size().width(), info->width());
+ QCOMPARE(screenList[i]->size().height(), info->height());
+ QCOMPARE(screenList[i]->availableVirtualGeometry().width(), info->desktopAvailableWidth());
+ QCOMPARE(screenList[i]->availableVirtualGeometry().height(), info->desktopAvailableHeight());
+ QCOMPARE(screenList[i]->devicePixelRatio(), info->devicePixelRatio());
+ QCOMPARE(screenList[i]->geometry().x(), info->virtualX());
+ QCOMPARE(screenList[i]->geometry().y(), info->virtualY());
+ }
}
QTEST_MAIN(tst_qquickscreen)
diff --git a/tests/auto/quick/qquickshortcut/data/multiple.qml b/tests/auto/quick/qquickshortcut/data/multiple.qml
new file mode 100644
index 0000000000..2b58327cf0
--- /dev/null
+++ b/tests/auto/quick/qquickshortcut/data/multiple.qml
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.9
+import QtQuick.Window 2.2
+
+Window {
+ id: window
+
+ width: 300
+ height: 300
+
+ property bool activated: false
+ property alias shortcut: shortcut
+
+ Shortcut {
+ id: shortcut
+ onActivated: window.activated = true
+ }
+}
diff --git a/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp b/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp
index 2df94bb84a..75ccf26af9 100644
--- a/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp
+++ b/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp
@@ -45,6 +45,8 @@ private slots:
void context();
void matcher_data();
void matcher();
+ void multiple_data();
+ void multiple();
};
Q_DECLARE_METATYPE(Qt::Key)
@@ -408,6 +410,49 @@ void tst_QQuickShortcut::matcher()
qt_quick_set_shortcut_context_matcher(defaultMatcher);
}
+void tst_QQuickShortcut::multiple_data()
+{
+ QTest::addColumn<QStringList>("sequences");
+ QTest::addColumn<Qt::Key>("key");
+ QTest::addColumn<Qt::KeyboardModifiers>("modifiers");
+ QTest::addColumn<bool>("enabled");
+ QTest::addColumn<bool>("activated");
+
+ // first
+ QTest::newRow("Ctrl+X,(Shift+Del)") << (QStringList() << "Ctrl+X" << "Shift+Del") << Qt::Key_X << Qt::KeyboardModifiers(Qt::ControlModifier) << true << true;
+ // second
+ QTest::newRow("(Ctrl+X),Shift+Del") << (QStringList() << "Ctrl+X" << "Shift+Del") << Qt::Key_Delete << Qt::KeyboardModifiers(Qt::ShiftModifier) << true << true;
+ // disabled
+ QTest::newRow("(Ctrl+X,Shift+Del)") << (QStringList() << "Ctrl+X" << "Shift+Del") << Qt::Key_X << Qt::KeyboardModifiers(Qt::ControlModifier) << false << false;
+}
+
+void tst_QQuickShortcut::multiple()
+{
+ QFETCH(QStringList, sequences);
+ QFETCH(Qt::Key, key);
+ QFETCH(Qt::KeyboardModifiers, modifiers);
+ QFETCH(bool, enabled);
+ QFETCH(bool, activated);
+
+ QQmlApplicationEngine engine;
+
+ engine.load(testFileUrl("multiple.qml"));
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(engine.rootObjects().value(0));
+ QVERIFY(window);
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ QObject *shortcut = window->property("shortcut").value<QObject *>();
+ QVERIFY(shortcut);
+
+ shortcut->setProperty("enabled", enabled);
+ shortcut->setProperty("sequences", sequences);
+
+ QTest::keyPress(window, key, modifiers);
+
+ QCOMPARE(window->property("activated").toBool(), activated);
+}
+
QTEST_MAIN(tst_QQuickShortcut)
#include "tst_qquickshortcut.moc"
diff --git a/tests/auto/quick/qquicktext/data/fontInfo.qml b/tests/auto/quick/qquicktext/data/fontInfo.qml
new file mode 100644
index 0000000000..25f924029f
--- /dev/null
+++ b/tests/auto/quick/qquicktext/data/fontInfo.qml
@@ -0,0 +1,24 @@
+import QtQuick 2.9
+
+Item {
+ Text {
+ id: main
+ objectName: "main"
+ width: 500
+ height: 500
+ text: "Meaningless text"
+ font.pixelSize: 1000
+ fontSizeMode: Text.Fit
+ }
+
+ Text {
+ objectName: "copy"
+ text: main.text
+ width: main.width
+ height: main.height
+
+ font.family: main.fontInfo.family
+ font.pixelSize: main.fontInfo.pixelSize
+ }
+}
+
diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
index 2032f72e26..f741062d42 100644
--- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp
+++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
@@ -154,6 +154,8 @@ private slots:
void hAlignWidthDependsOnImplicitWidth_data();
void hAlignWidthDependsOnImplicitWidth();
+ void fontInfo();
+
private:
QStringList standard;
QStringList richText;
@@ -762,11 +764,6 @@ void tst_qquicktext::horizontalAlignment()
void tst_qquicktext::horizontalAlignment_RightToLeft()
{
-#if defined(Q_OS_BLACKBERRY)
- QQuickWindow dummy; // On BlackBerry first window is always full screen,
- dummy.showFullScreen(); // so make test window a second window.
-#endif
-
QScopedPointer<QQuickView> window(createView(testFile("horizontalAlignment_RightToLeft.qml")));
QQuickText *text = window->rootObject()->findChild<QQuickText*>("text");
QVERIFY(text != 0);
@@ -4258,6 +4255,23 @@ void tst_qquicktext::hAlignWidthDependsOnImplicitWidth()
QCOMPARE(numberOfNonWhitePixels(0, rectX - 1, image), 0);
}
+void tst_qquicktext::fontInfo()
+{
+ QQmlComponent component(&engine, testFile("fontInfo.qml"));
+
+ QScopedPointer<QObject> object(component.create());
+ QObject *root = object.data();
+
+ QQuickText *main = root->findChild<QQuickText *>("main");
+ QVERIFY(main);
+ QCOMPARE(main->font().pixelSize(), 1000);
+
+ QQuickText *copy = root->findChild<QQuickText *>("copy");
+ QVERIFY(copy);
+ QCOMPARE(copy->font().family(), QFontInfo(QFont()).family());
+ QVERIFY(copy->font().pixelSize() < 1000);
+}
+
QTEST_MAIN(tst_qquicktext)
#include "tst_qquicktext.moc"
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index 765523316f..ac57a05176 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -929,7 +929,6 @@ void tst_qquicktextedit::hAlignVisual()
const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image);
const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image);
const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image);
- image.save("test3.png");
QVERIFY2(left < mid, msgNotLessThan(left, mid).constData());
QVERIFY2(mid < right, msgNotLessThan(mid, right).constData());
}
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
index 1451f8e2fc..67921e1fd0 100644
--- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
+++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
@@ -135,6 +135,7 @@ private slots:
void signal_accepted();
void signal_editingfinished();
+ void signal_textEdited();
void passwordCharacter();
void cursorDelegate_data();
@@ -2441,6 +2442,57 @@ void tst_qquicktextinput::signal_editingfinished()
QTRY_COMPARE(editingFinished2Spy.count(), 1);
}
+void tst_qquicktextinput::signal_textEdited()
+{
+ QQuickWindow window;
+ window.show();
+ window.requestActivate();
+ QTest::qWaitForWindowActive(&window);
+
+ QQuickTextInput *input = new QQuickTextInput(window.contentItem());
+ QVERIFY(input);
+
+ QSignalSpy textChangedSpy(input, SIGNAL(textChanged()));
+ QVERIFY(textChangedSpy.isValid());
+
+ QSignalSpy textEditedSpy(input, SIGNAL(textEdited()));
+ QVERIFY(textEditedSpy.isValid());
+
+ input->forceActiveFocus();
+ QTRY_VERIFY(input->hasActiveFocus());
+
+ int textChanges = 0;
+ int textEdits = 0;
+
+ QTest::keyClick(&window, Qt::Key_A);
+ QCOMPARE(textChangedSpy.count(), ++textChanges);
+ QCOMPARE(textEditedSpy.count(), ++textEdits);
+
+ QTest::keyClick(&window, Qt::Key_B);
+ QCOMPARE(textChangedSpy.count(), ++textChanges);
+ QCOMPARE(textEditedSpy.count(), ++textEdits);
+
+ QTest::keyClick(&window, Qt::Key_C);
+ QCOMPARE(textChangedSpy.count(), ++textChanges);
+ QCOMPARE(textEditedSpy.count(), ++textEdits);
+
+ QTest::keyClick(&window, Qt::Key_Space);
+ QCOMPARE(textChangedSpy.count(), ++textChanges);
+ QCOMPARE(textEditedSpy.count(), ++textEdits);
+
+ QTest::keyClick(&window, Qt::Key_Backspace);
+ QCOMPARE(textChangedSpy.count(), ++textChanges);
+ QCOMPARE(textEditedSpy.count(), ++textEdits);
+
+ input->clear();
+ QCOMPARE(textChangedSpy.count(), ++textChanges);
+ QCOMPARE(textEditedSpy.count(), textEdits);
+
+ input->setText("TextInput");
+ QCOMPARE(textChangedSpy.count(), ++textChanges);
+ QCOMPARE(textEditedSpy.count(), textEdits);
+}
+
/*
TextInput element should only handle left/right keys until the cursor reaches
the extent of the text, then they should ignore the keys.
diff --git a/tests/auto/quick/qquickwindow/data/grabContentItemToImage.qml b/tests/auto/quick/qquickwindow/data/grabContentItemToImage.qml
new file mode 100644
index 0000000000..9086e0cc84
--- /dev/null
+++ b/tests/auto/quick/qquickwindow/data/grabContentItemToImage.qml
@@ -0,0 +1,15 @@
+import QtQuick 2.0
+import QtQuick.Window 2.2 as Window
+
+Window.Window {
+ visible: true
+ width: 100
+ height: 100
+ property int success: 0
+
+ function grabContentItemToImage() {
+ contentItem.grabToImage(function (image) {
+ success = 1
+ })
+ }
+}
diff --git a/tests/auto/quick/qquickwindow/data/windowWithScreen.qml b/tests/auto/quick/qquickwindow/data/windowWithScreen.qml
new file mode 100644
index 0000000000..2a5a7b7b76
--- /dev/null
+++ b/tests/auto/quick/qquickwindow/data/windowWithScreen.qml
@@ -0,0 +1,10 @@
+import QtQuick 2.0
+import QtQuick.Window 2.3 as Window
+
+Window.Window {
+ color: "#00FF00"
+ screen: Qt.application.screens[0]
+ Item {
+ objectName: "item"
+ }
+}
diff --git a/tests/auto/quick/qquickwindow/qquickwindow.pro b/tests/auto/quick/qquickwindow/qquickwindow.pro
index 05093ba8e0..b0a5f97a32 100644
--- a/tests/auto/quick/qquickwindow/qquickwindow.pro
+++ b/tests/auto/quick/qquickwindow/qquickwindow.pro
@@ -16,4 +16,5 @@ OTHER_FILES += \
data/AnimationsWhileHidden.qml \
data/Headless.qml \
data/showHideAnimate.qml \
- data/windoworder.qml
+ data/windoworder.qml \
+ data/grabContentItemToImage.qml
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
index 8d021d92da..dd00154935 100644
--- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
+++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
@@ -311,6 +311,7 @@ private slots:
void clearWindow();
void qmlCreation();
+ void qmlCreationWithScreen();
void clearColor();
void defaultState();
@@ -369,6 +370,8 @@ private slots:
void pointerEventTypeAndPointCount();
+ void grabContentItemToImage();
+
private:
QTouchDevice *touchDevice;
QTouchDevice *touchDeviceWithVelocity;
@@ -1122,6 +1125,24 @@ void tst_qquickwindow::qmlCreation()
QCOMPARE(item->window(), window);
}
+void tst_qquickwindow::qmlCreationWithScreen()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.loadUrl(testFileUrl("windowWithScreen.qml"));
+ QObject *created = component.create();
+ QScopedPointer<QObject> cleanup(created);
+ QVERIFY(created);
+
+ QQuickWindow *window = qobject_cast<QQuickWindow*>(created);
+ QVERIFY(window);
+ QCOMPARE(window->color(), QColor(Qt::green));
+
+ QQuickItem *item = window->findChild<QQuickItem*>("item");
+ QVERIFY(item);
+ QCOMPARE(item->window(), window);
+}
+
void tst_qquickwindow::clearColor()
{
//::grab examines rendering to make sure it works visually
@@ -2535,6 +2556,23 @@ void tst_qquickwindow::pointerEventTypeAndPointCount()
QVERIFY(!pte.touchPointById(0));
}
+void tst_qquickwindow::grabContentItemToImage()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.loadUrl(testFileUrl("grabContentItemToImage.qml"));
+
+ QObject *created = component.create();
+ QScopedPointer<QObject> cleanup(created);
+ QVERIFY(created);
+
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(created);
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QMetaObject::invokeMethod(window, "grabContentItemToImage");
+ QTRY_COMPARE(created->property("success").toInt(), 1);
+}
+
QTEST_MAIN(tst_qquickwindow)
#include "tst_qquickwindow.moc"
diff --git a/tests/auto/quick/qquickxmllistmodel/qquickxmllistmodel.pro b/tests/auto/quick/qquickxmllistmodel/qquickxmllistmodel.pro
index 642345a4bb..902325802c 100644
--- a/tests/auto/quick/qquickxmllistmodel/qquickxmllistmodel.pro
+++ b/tests/auto/quick/qquickxmllistmodel/qquickxmllistmodel.pro
@@ -2,7 +2,9 @@ CONFIG += testcase
TARGET = tst_qquickxmllistmodel
macx:CONFIG -= app_bundle
-SOURCES += tst_qquickxmllistmodel.cpp
+SOURCES += tst_qquickxmllistmodel.cpp \
+ ../../../../src/imports/xmllistmodel/qqmlxmllistmodel.cpp
+HEADERS += ../../../../src/imports/xmllistmodel/qqmlxmllistmodel_p.h
include (../../shared/util.pri)
diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro
index c7ba4de86c..6e9998c061 100644
--- a/tests/auto/quick/quick.pro
+++ b/tests/auto/quick/quick.pro
@@ -6,6 +6,7 @@ PUBLICTESTS += \
qtConfig(opengl(es1|es2)?) {
PUBLICTESTS += \
+ drawingmodes \
rendernode
qtHaveModule(widgets): PUBLICTESTS += nodes
diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp
index 309c01dcdc..4f4fac8fa5 100644
--- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp
+++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp
@@ -71,7 +71,7 @@ Q_SIGNALS:
public:
EventItem(QQuickItem *parent = 0)
- : QQuickItem(parent), acceptMouse(false), acceptTouch(false), filterTouch(false)
+ : QQuickItem(parent), acceptMouse(false), acceptTouch(false), filterTouch(false), point0(-1)
{
setAcceptedMouseButtons(Qt::LeftButton);
}
@@ -79,6 +79,9 @@ public:
void touchEvent(QTouchEvent *event)
{
eventList.append(Event(event->type(), event->touchPoints()));
+ QList<QTouchEvent::TouchPoint> tps = event->touchPoints();
+ Q_ASSERT(!tps.isEmpty());
+ point0 = tps.first().id();
event->setAccepted(acceptTouch);
emit onTouchEvent(this);
}
@@ -125,12 +128,16 @@ public:
event->type() == QEvent::TouchEnd) {
QTouchEvent *touch = static_cast<QTouchEvent*>(event);
eventList.append(Event(event->type(), touch->touchPoints()));
+ QList<QTouchEvent::TouchPoint> tps = touch->touchPoints();
+ Q_ASSERT(!tps.isEmpty());
+ point0 = tps.first().id();
if (filterTouch)
event->accept();
return true;
}
return false;
}
+ int point0;
};
class tst_TouchMouse : public QQmlDataTest
@@ -187,8 +194,6 @@ private:
QQuickView *tst_TouchMouse::createView()
{
QQuickView *window = new QQuickView(0);
- window->setGeometry(0,0,240,320);
-
return window;
}
@@ -203,13 +208,11 @@ void tst_TouchMouse::initTestCase()
void tst_TouchMouse::simpleTouchEvent()
{
- QQuickView *window = createView();
-
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("singleitem.qml"));
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QVERIFY(window->rootObject() != 0);
EventItem *eventItem1 = window->rootObject()->findChild<EventItem*>("eventItem1");
@@ -218,33 +221,33 @@ void tst_TouchMouse::simpleTouchEvent()
// Do not accept touch or mouse
QPoint p1;
p1 = QPoint(20, 20);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
// Get a touch and then mouse event offered
QCOMPARE(eventItem1->eventList.size(), 2);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
p1 += QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
// Not accepted, no updates
QCOMPARE(eventItem1->eventList.size(), 2);
- QTest::touchEvent(window, device).release(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 2);
eventItem1->eventList.clear();
// Accept touch
eventItem1->acceptTouch = true;
p1 = QPoint(20, 20);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 1);
p1 += QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 2);
- QTest::touchEvent(window, device).release(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 3);
eventItem1->eventList.clear();
@@ -256,8 +259,8 @@ void tst_TouchMouse::simpleTouchEvent()
eventItem1->acceptMouse = true;
eventItem1->setAcceptedMouseButtons(Qt::LeftButton);
p1 = QPoint(20, 20);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 2);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress);
@@ -273,13 +276,13 @@ void tst_TouchMouse::simpleTouchEvent()
QCOMPARE(eventItem1->eventList.at(1).mousePosGlobal, globalPos);
p1 += QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 4);
QCOMPARE(eventItem1->eventList.at(2).type, QEvent::TouchUpdate);
QCOMPARE(eventItem1->eventList.at(3).type, QEvent::MouseMove);
- QTest::touchEvent(window, device).release(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 7);
QCOMPARE(eventItem1->eventList.at(4).type, QEvent::TouchEnd);
QCOMPARE(eventItem1->eventList.at(5).type, QEvent::MouseButtonRelease);
@@ -294,17 +297,17 @@ void tst_TouchMouse::simpleTouchEvent()
eventItem1->acceptMouse = false;
eventItem1->setAcceptedMouseButtons(Qt::LeftButton);
p1 = QPoint(20, 20);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 2);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress);
p1 += QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 2);
- QTest::touchEvent(window, device).release(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 2);
eventItem1->eventList.clear();
@@ -315,32 +318,30 @@ void tst_TouchMouse::simpleTouchEvent()
eventItem1->acceptTouch = true;
eventItem1->setAcceptedMouseButtons(Qt::LeftButton);
p1 = QPoint(20, 20);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 1);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
p1 += QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 2);
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::TouchUpdate);
- QTest::touchEvent(window, device).release(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 3);
QCOMPARE(eventItem1->eventList.at(2).type, QEvent::TouchEnd);
eventItem1->eventList.clear();
-
- delete window;
}
void tst_TouchMouse::testEventFilter()
{
// // install event filter on item and see that it can grab events
-// QQuickView *window = createView();
-
+// QScopedPointer<QQuickView> window(createView());
// window->setSource(testFileUrl("singleitem.qml"));
// window->show();
-// window->requestActivate();
+// QQuickViewTestUtil::centerOnScreen(window.data());
+// QVERIFY(QTest::qWaitForWindowActive(window.data()));
// QVERIFY(window->rootObject() != 0);
// EventItem *eventItem1 = window->rootObject()->findChild<EventItem*>("eventItem1");
@@ -352,16 +353,15 @@ void tst_TouchMouse::testEventFilter()
// eventItem1->installEventFilter(filter);
// QPoint p1 = QPoint(20, 20);
-// QTest::touchEvent(window, device).press(0, p1, window);
+// QTest::touchEvent(window.data(), device).press(0, p1, window.data());
// // QEXPECT_FAIL("", "We do not implement event filters correctly", Abort);
// QCOMPARE(eventItem1->eventList.size(), 0);
// QCOMPARE(filter->eventList.size(), 1);
-// QTest::touchEvent(window, device).release(0, p1, window);
+// QTest::touchEvent(window.data(), device).release(0, p1, window.data());
// QCOMPARE(eventItem1->eventList.size(), 0);
// QCOMPARE(filter->eventList.size(), 2);
// delete filter;
-// delete window;
}
void tst_TouchMouse::mouse()
@@ -370,34 +370,29 @@ void tst_TouchMouse::mouse()
// - eventItem2
QTest::qWait(qApp->styleHints()->mouseDoubleClickInterval() + 10);
- QQuickView *window = createView();
-
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("twoitems.qml"));
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QVERIFY(window->rootObject() != 0);
EventItem *eventItem1 = window->rootObject()->findChild<EventItem*>("eventItem1");
QVERIFY(eventItem1);
EventItem *eventItem2 = window->rootObject()->findChild<EventItem*>("eventItem2");
QVERIFY(eventItem2);
- QVERIFY(QTest::qWaitForWindowExposed(window));
// bottom item likes mouse, top likes touch
eventItem1->setAcceptedMouseButtons(Qt::LeftButton);
eventItem1->acceptMouse = true;
// item 2 doesn't accept anything, thus it sees a touch pass by
QPoint p1 = QPoint(30, 30);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 2);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress);
-
- delete window;
}
void tst_TouchMouse::touchOverMouse()
@@ -405,13 +400,11 @@ void tst_TouchMouse::touchOverMouse()
// eventItem1
// - eventItem2
- QQuickView *window = createView();
-
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("twoitems.qml"));
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QVERIFY(window->rootObject() != 0);
EventItem *eventItem1 = window->rootObject()->findChild<EventItem*>("eventItem1");
@@ -423,27 +416,23 @@ void tst_TouchMouse::touchOverMouse()
eventItem1->setAcceptedMouseButtons(Qt::LeftButton);
eventItem2->acceptTouch = true;
- QVERIFY(QTest::qWaitForWindowExposed(window));
-
QCOMPARE(eventItem1->eventList.size(), 0);
QPoint p1 = QPoint(20, 20);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 0);
QCOMPARE(eventItem2->eventList.size(), 1);
QCOMPARE(eventItem2->eventList.at(0).type, QEvent::TouchBegin);
p1 += QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem2->eventList.size(), 2);
QCOMPARE(eventItem2->eventList.at(1).type, QEvent::TouchUpdate);
- QTest::touchEvent(window, device).release(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem2->eventList.size(), 3);
QCOMPARE(eventItem2->eventList.at(2).type, QEvent::TouchEnd);
eventItem2->eventList.clear();
-
- delete window;
}
void tst_TouchMouse::mouseOverTouch()
@@ -451,13 +440,11 @@ void tst_TouchMouse::mouseOverTouch()
// eventItem1
// - eventItem2
- QQuickView *window = createView();
-
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("twoitems.qml"));
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QVERIFY(window->rootObject() != 0);
EventItem *eventItem1 = window->rootObject()->findChild<EventItem*>("eventItem1");
@@ -470,12 +457,10 @@ void tst_TouchMouse::mouseOverTouch()
eventItem2->setAcceptedMouseButtons(Qt::LeftButton);
eventItem2->acceptMouse = true;
- QVERIFY(QTest::qWaitForWindowExposed(window));
-
QPoint p1 = QPoint(20, 20);
QTest::qWait(qApp->styleHints()->mouseDoubleClickInterval() + 10);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 0);
QCOMPARE(eventItem2->eventList.size(), 2);
QCOMPARE(eventItem2->eventList.at(0).type, QEvent::TouchBegin);
@@ -483,13 +468,11 @@ void tst_TouchMouse::mouseOverTouch()
// p1 += QPoint(10, 0);
-// QTest::touchEvent(window, device).move(0, p1, window);
+// QTest::touchEvent(window.data(), device).move(0, p1, window.data());
// QCOMPARE(eventItem2->eventList.size(), 1);
-// QTest::touchEvent(window, device).release(0, p1, window);
+// QTest::touchEvent(window.data(), device).release(0, p1, window.data());
// QCOMPARE(eventItem2->eventList.size(), 1);
// eventItem2->eventList.clear();
-
- delete window;
}
void tst_TouchMouse::buttonOnFlickable()
@@ -498,13 +481,11 @@ void tst_TouchMouse::buttonOnFlickable()
// - eventItem1 y: 100, height 100
// - eventItem2 y: 300, height 100
- QQuickView *window = createView();
-
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("buttononflickable.qml"));
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QVERIFY(window->rootObject() != 0);
QQuickFlickable *flickable = window->rootObject()->findChild<QQuickFlickable*>("flickable");
@@ -529,13 +510,13 @@ void tst_TouchMouse::buttonOnFlickable()
// mouse button
QCOMPARE(eventItem1->eventList.size(), 0);
QPoint p1 = QPoint(20, 130);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QTRY_COMPARE(eventItem1->eventList.size(), 2);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress);
- QTest::touchEvent(window, device).release(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 5);
QCOMPARE(eventItem1->eventList.at(2).type, QEvent::TouchEnd);
QCOMPARE(eventItem1->eventList.at(3).type, QEvent::MouseButtonRelease);
@@ -544,12 +525,12 @@ void tst_TouchMouse::buttonOnFlickable()
// touch button
p1 = QPoint(10, 310);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem2->eventList.size(), 1);
QCOMPARE(eventItem2->eventList.at(0).type, QEvent::TouchBegin);
- QTest::touchEvent(window, device).release(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem2->eventList.size(), 2);
QCOMPARE(eventItem2->eventList.at(1).type, QEvent::TouchEnd);
QCOMPARE(eventItem1->eventList.size(), 0);
@@ -560,11 +541,11 @@ void tst_TouchMouse::buttonOnFlickable()
// click above button, no events please
p1 = QPoint(10, 90);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 0);
- QTest::touchEvent(window, device).release(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 0);
eventItem1->eventList.clear();
@@ -574,14 +555,14 @@ void tst_TouchMouse::buttonOnFlickable()
// check that flickable moves - mouse button
QCOMPARE(eventItem1->eventList.size(), 0);
p1 = QPoint(10, 110);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 2);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress);
- QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window);
- QCOMPARE(windowPriv->touchMouseId, 0);
+ QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window.data());
+ QVERIFY(windowPriv->touchMouseId != -1);
auto pointerEvent = QQuickPointerDevice::touchDevices().at(0)->pointerEvent();
QCOMPARE(pointerEvent->point(0)->grabber(), eventItem1);
QCOMPARE(window->mouseGrabberItem(), eventItem1);
@@ -589,13 +570,13 @@ void tst_TouchMouse::buttonOnFlickable()
p1 += QPoint(0, -10);
QPoint p2 = p1 + QPoint(0, -10);
QPoint p3 = p2 + QPoint(0, -10);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).move(0, p1, window);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).move(0, p2, window);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).move(0, p3, window);
- QQuickTouchUtils::flush(window);
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).move(0, p2, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).move(0, p3, window.data());
+ QQuickTouchUtils::flush(window.data());
// we cannot really know when the events get grabbed away
QVERIFY(eventItem1->eventList.size() >= 4);
@@ -603,13 +584,12 @@ void tst_TouchMouse::buttonOnFlickable()
QCOMPARE(eventItem1->eventList.at(3).type, QEvent::MouseMove);
QCOMPARE(window->mouseGrabberItem(), flickable);
- QCOMPARE(windowPriv->touchMouseId, 0);
+ QVERIFY(windowPriv->touchMouseId != -1);
QCOMPARE(pointerEvent->point(0)->grabber(), flickable);
QVERIFY(flickable->isMovingVertically());
- QTest::touchEvent(window, device).release(0, p3, window);
- QQuickTouchUtils::flush(window);
- delete window;
+ QTest::touchEvent(window.data(), device).release(0, p3, window.data());
+ QQuickTouchUtils::flush(window.data());
}
void tst_TouchMouse::buttonOnDelayedPressFlickable_data()
@@ -635,13 +615,11 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable()
qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, true);
filteredEventList.clear();
- QQuickView *window = createView();
-
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("buttononflickable.qml"));
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QVERIFY(window->rootObject() != 0);
QQuickFlickable *flickable = window->rootObject()->findChild<QQuickFlickable*>("flickable");
@@ -666,13 +644,13 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable()
// wait to avoid getting a double click event
QTest::qWait(qApp->styleHints()->mouseDoubleClickInterval() + 10);
- QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window);
+ QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window.data());
QCOMPARE(windowPriv->touchMouseId, -1); // no grabber
// touch press
QPoint p1 = QPoint(10, 110);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
if (scrollBeforeDelayIsOver) {
// no events, the flickable got scrolled, the button sees nothing
@@ -687,13 +665,13 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable()
p1 += QPoint(0, -10);
QPoint p2 = p1 + QPoint(0, -10);
QPoint p3 = p2 + QPoint(0, -10);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).move(0, p1, window);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).move(0, p2, window);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).move(0, p3, window);
- QQuickTouchUtils::flush(window);
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).move(0, p2, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).move(0, p3, window.data());
+ QQuickTouchUtils::flush(window.data());
QTRY_VERIFY(flickable->isMovingVertically());
if (scrollBeforeDelayIsOver) {
@@ -710,12 +688,12 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable()
// flickable should have the mouse grab, and have moved the itemForTouchPointId
// for the touchMouseId to the new grabber.
QCOMPARE(window->mouseGrabberItem(), flickable);
- QCOMPARE(windowPriv->touchMouseId, 0);
+ QVERIFY(windowPriv->touchMouseId != -1);
auto pointerEvent = QQuickPointerDevice::touchDevices().at(0)->pointerEvent();
QCOMPARE(pointerEvent->point(0)->grabber(), flickable);
- QTest::touchEvent(window, device).release(0, p3, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).release(0, p3, window.data());
+ QQuickTouchUtils::flush(window.data());
// We should not have received any synthesised mouse events from Qt gui,
// just the delayed press.
@@ -723,8 +701,6 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable()
QCOMPARE(filteredEventList.count(), 0);
else
QCOMPARE(filteredEventList.count(), 1);
-
- delete window;
}
void tst_TouchMouse::buttonOnTouch()
@@ -737,12 +713,11 @@ void tst_TouchMouse::buttonOnTouch()
// - eventItem1 y: 100, height 100
// - eventItem2 y: 300, height 100
- QQuickView *window = createView();
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("buttonontouch.qml"));
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QVERIFY(window->rootObject() != 0);
QQuickPinchArea *pinchArea = window->rootObject()->findChild<QQuickPinchArea*>("pincharea");
@@ -772,10 +747,10 @@ void tst_TouchMouse::buttonOnTouch()
// Normal touch click
QPoint p1 = QPoint(10, 110);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).release(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(eventItem1->eventList.size(), 5);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress);
@@ -785,7 +760,7 @@ void tst_TouchMouse::buttonOnTouch()
eventItem1->eventList.clear();
// Normal mouse click
- QTest::mouseClick(window, Qt::LeftButton, 0, p1);
+ QTest::mouseClick(window.data(), Qt::LeftButton, 0, p1);
QCOMPARE(eventItem1->eventList.size(), 3);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::MouseButtonPress);
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonRelease);
@@ -797,35 +772,35 @@ void tst_TouchMouse::buttonOnTouch()
QPoint p2 = QPoint(60, 10);
// Start the events after each other
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).stationary(0).press(1, p2, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).stationary(0).press(1, p2, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(button1->scale(), 1.0);
// This event seems to be discarded, let's ignore it for now until someone digs into pincharea
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p1, window).move(1, p2, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data()).move(1, p2, window.data());
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p1, window).move(1, p2, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data()).move(1, p2, window.data());
+ QQuickTouchUtils::flush(window.data());
// QCOMPARE(button1->scale(), 1.5);
qDebug() << "Button scale: " << button1->scale();
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p1, window).move(1, p2, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data()).move(1, p2, window.data());
+ QQuickTouchUtils::flush(window.data());
// QCOMPARE(button1->scale(), 2.0);
qDebug() << "Button scale: " << button1->scale();
- QTest::touchEvent(window, device).release(0, p1, window).release(1, p2, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data()).release(1, p2, window.data());
+ QQuickTouchUtils::flush(window.data());
// QVERIFY(eventItem1->eventList.isEmpty());
// QCOMPARE(button1->scale(), 2.0);
qDebug() << "Button scale: " << button1->scale();
@@ -838,8 +813,8 @@ void tst_TouchMouse::buttonOnTouch()
button1->setScale(1.0);
p1 = QPoint(40, 110);
p2 = QPoint(60, 110);
- QTest::touchEvent(window, device).press(0, p1, window).press(1, p2, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data()).press(1, p2, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(button1->scale(), 1.0);
QCOMPARE(eventItem1->eventList.count(), 2);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
@@ -848,40 +823,37 @@ void tst_TouchMouse::buttonOnTouch()
// This event seems to be discarded, let's ignore it for now until someone digs into pincharea
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p1, window).move(1, p2, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data()).move(1, p2, window.data());
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p1, window).move(1, p2, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data()).move(1, p2, window.data());
+ QQuickTouchUtils::flush(window.data());
//QCOMPARE(button1->scale(), 1.5);
qDebug() << button1->scale();
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p1, window).move(1, p2, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p1, window.data()).move(1, p2, window.data());
+ QQuickTouchUtils::flush(window.data());
qDebug() << button1->scale();
//QCOMPARE(button1->scale(), 2.0);
- QTest::touchEvent(window, device).release(0, p1, window).release(1, p2, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data()).release(1, p2, window.data());
+ QQuickTouchUtils::flush(window.data());
// QCOMPARE(eventItem1->eventList.size(), 99);
qDebug() << button1->scale();
//QCOMPARE(button1->scale(), 2.0);
-
- delete window;
}
void tst_TouchMouse::pinchOnFlickable()
{
- QQuickView *window = createView();
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("pinchonflickable.qml"));
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QVERIFY(window->rootObject() != 0);
QQuickPinchArea *pinchArea = window->rootObject()->findChild<QQuickPinchArea*>("pincharea");
@@ -894,23 +866,23 @@ void tst_TouchMouse::pinchOnFlickable()
// flickable - single touch point
QCOMPARE(flickable->contentX(), 0.0);
QPoint p = QPoint(100, 100);
- QTest::touchEvent(window, device).press(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(rect->position(), QPointF(200.0, 200.0));
p -= QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
p -= QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
p -= QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
p -= QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p, window);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).release(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).release(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
QGuiApplication::processEvents();
QTest::qWait(10);
@@ -922,48 +894,47 @@ void tst_TouchMouse::pinchOnFlickable()
QPoint p1 = QPoint(40, 20);
QPoint p2 = QPoint(60, 20);
- QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, device);
- QQuickTouchUtils::flush(window);
- pinchSequence.press(0, p1, window).commit();
- QQuickTouchUtils::flush(window);
+ QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window.data(), device);
+ QQuickTouchUtils::flush(window.data());
+ pinchSequence.press(0, p1, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
// In order for the stationary point to remember its previous position,
// we have to reuse the same pinchSequence object. Otherwise if we let it
// be destroyed and then start a new sequence, point 0 will default to being
// stationary at 0, 0, and PinchArea will filter out that touchpoint because
// it is outside its bounds.
- pinchSequence.stationary(0).press(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.stationary(0).press(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(10,10);
p2 += QPoint(10,10);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(rect->scale(), 1.0);
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
QVERIFY(!flickable->isDragging());
- QQuickTouchUtils::flush(window);
- pinchSequence.release(0, p1, window).release(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ QQuickTouchUtils::flush(window.data());
+ pinchSequence.release(0, p1, window.data()).release(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
QVERIFY(rect->scale() > 1.0);
}
void tst_TouchMouse::flickableOnPinch()
{
- QQuickView *window = createView();
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("flickableonpinch.qml"));
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QVERIFY(window->rootObject() != 0);
QQuickPinchArea *pinchArea = window->rootObject()->findChild<QQuickPinchArea*>("pincharea");
@@ -976,23 +947,23 @@ void tst_TouchMouse::flickableOnPinch()
// flickable - single touch point
QCOMPARE(flickable->contentX(), 0.0);
QPoint p = QPoint(100, 100);
- QTest::touchEvent(window, device).press(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(rect->position(), QPointF(200.0, 200.0));
p -= QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
p -= QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
QTest::qWait(1000);
p -= QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p, window);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).release(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).release(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
QTest::qWait(1000);
@@ -1004,45 +975,47 @@ void tst_TouchMouse::flickableOnPinch()
// pinch
QPoint p1 = QPoint(40, 20);
QPoint p2 = QPoint(60, 20);
- QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, device);
- pinchSequence.press(0, p1, window).commit();
- QQuickTouchUtils::flush(window);
+ QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window.data(), device);
+ pinchSequence.press(0, p1, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
// In order for the stationary point to remember its previous position,
// we have to reuse the same pinchSequence object. Otherwise if we let it
// be destroyed and then start a new sequence, point 0 will default to being
// stationary at 0, 0, and PinchArea will filter out that touchpoint because
// it is outside its bounds.
- pinchSequence.stationary(0).press(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.stationary(0).press(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(10,10);
p2 += QPoint(10,10);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(rect->scale(), 1.0);
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
- pinchSequence.release(0, p1, window).release(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
+ pinchSequence.release(0, p1, window.data()).release(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
QVERIFY(rect->scale() > 1.0);
}
void tst_TouchMouse::mouseOnFlickableOnPinch()
{
- QQuickView *window = createView();
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("mouseonflickableonpinch.qml"));
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QVERIFY(window->rootObject() != 0);
+
QRect windowRect = QRect(window->position(), window->size());
QCursor::setPos(windowRect.center());
@@ -1056,20 +1029,20 @@ void tst_TouchMouse::mouseOnFlickableOnPinch()
// flickable - single touch point
QCOMPARE(flickable->contentX(), 0.0);
QPoint p = QPoint(100, 100);
- QTest::touchEvent(window, device).press(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(rect->position(), QPointF(200.0, 200.0));
p -= QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
p -= QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
p -= QPoint(10, 0);
- QTest::touchEvent(window, device).move(0, p, window);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).release(0, p, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).move(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).release(0, p, window.data());
+ QQuickTouchUtils::flush(window.data());
//QVERIFY(flickable->isMovingHorizontally());
@@ -1080,81 +1053,81 @@ void tst_TouchMouse::mouseOnFlickableOnPinch()
// pinch
QPoint p1 = QPoint(40, 20);
QPoint p2 = QPoint(60, 20);
- QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, device);
- pinchSequence.press(0, p1, window).commit();
- QQuickTouchUtils::flush(window);
+ QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window.data(), device);
+ pinchSequence.press(0, p1, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
// In order for the stationary point to remember its previous position,
// we have to reuse the same pinchSequence object. Otherwise if we let it
// be destroyed and then start a new sequence, point 0 will default to being
// stationary at 0, 0, and PinchArea will filter out that touchpoint because
// it is outside its bounds.
- pinchSequence.stationary(0).press(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.stationary(0).press(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(10,10);
p2 += QPoint(10,10);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(rect->scale(), 1.0);
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(10, 0);
p2 += QPoint(10, 0);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
- pinchSequence.release(0, p1, window).release(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
+ pinchSequence.release(0, p1, window.data()).release(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
QVERIFY(rect->scale() > 1.0);
// PinchArea should steal the event after flicking started
rect->setScale(1.0);
flickable->setContentX(0.0);
p = QPoint(100, 100);
- pinchSequence.press(0, p, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.press(0, p, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(rect->position(), QPointF(200.0, 200.0));
p -= QPoint(10, 0);
- pinchSequence.move(0, p, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
p -= QPoint(10, 0);
- pinchSequence.move(0, p, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
QGuiApplication::processEvents();
p -= QPoint(10, 0);
- pinchSequence.move(0, p, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(window->mouseGrabberItem(), flickable);
// Add a second finger, this should lead to stealing
p1 = QPoint(40, 100);
p2 = QPoint(60, 100);
- pinchSequence.stationary(0).press(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.stationary(0).press(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(rect->scale(), 1.0);
p1 -= QPoint(5, 0);
p2 += QPoint(5, 0);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(5, 0);
p2 += QPoint(5, 0);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
p1 -= QPoint(5, 0);
p2 += QPoint(5, 0);
- pinchSequence.move(0, p1, window).move(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
- pinchSequence.release(0, p1, window).release(1, p2, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.move(0, p1, window.data()).move(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
+ pinchSequence.release(0, p1, window.data()).release(1, p2, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
QVERIFY(rect->scale() > 1.0);
- pinchSequence.release(0, p, window).commit();
- QQuickTouchUtils::flush(window);
+ pinchSequence.release(0, p, window.data()).commit();
+ QQuickTouchUtils::flush(window.data());
}
/*
@@ -1169,13 +1142,11 @@ void tst_TouchMouse::mouseOnFlickableOnPinch()
*/
void tst_TouchMouse::tapOnDismissiveTopMouseAreaClicksBottomOne()
{
- QQuickView *window = createView();
-
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("twoMouseAreas.qml"));
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QVERIFY(window->rootObject() != 0);
QQuickMouseArea *bottomMouseArea =
@@ -1187,23 +1158,21 @@ void tst_TouchMouse::tapOnDismissiveTopMouseAreaClicksBottomOne()
// tap the front mouse area (see qml file)
QPoint p1(20, 20);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).release(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(bottomClickedSpy.count(), 1);
QCOMPARE(bottomDoubleClickedSpy.count(), 0);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
- QTest::touchEvent(window, device).release(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(bottomClickedSpy.count(), 1);
QCOMPARE(bottomDoubleClickedSpy.count(), 1);
-
- delete window;
}
/*
@@ -1213,13 +1182,11 @@ void tst_TouchMouse::tapOnDismissiveTopMouseAreaClicksBottomOne()
*/
void tst_TouchMouse::touchGrabCausesMouseUngrab()
{
- QQuickView *window = createView();
-
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("twosiblingitems.qml"));
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QVERIFY(window->rootObject() != 0);
EventItem *leftItem = window->rootObject()->findChild<EventItem*>("leftItem");
@@ -1235,8 +1202,8 @@ void tst_TouchMouse::touchGrabCausesMouseUngrab()
leftItem->setAcceptedMouseButtons(Qt::LeftButton);
QPoint p1;
p1 = QPoint(leftItem->width() / 2, leftItem->height() / 2);
- QTest::touchEvent(window, device).press(0, p1, window);
- QQuickTouchUtils::flush(window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
+ QQuickTouchUtils::flush(window.data());
QCOMPARE(leftItem->eventList.size(), 2);
QCOMPARE(leftItem->eventList.at(0).type, QEvent::TouchBegin);
QCOMPARE(leftItem->eventList.at(1).type, QEvent::MouseButtonPress);
@@ -1246,7 +1213,7 @@ void tst_TouchMouse::touchGrabCausesMouseUngrab()
rightItem->acceptTouch = true;
{
QVector<int> ids;
- ids.append(0);
+ ids.append(leftItem->point0);
rightItem->grabTouchPoints(ids);
}
@@ -1255,16 +1222,17 @@ void tst_TouchMouse::touchGrabCausesMouseUngrab()
QCOMPARE(leftItem->eventList.size(), 1);
QCOMPARE(leftItem->eventList.at(0).type, QEvent::UngrabMouse);
QCOMPARE(window->mouseGrabberItem(), (QQuickItem*)0);
-
- delete window;
}
void tst_TouchMouse::touchPointDeliveryOrder()
{
// Touch points should be first delivered to the item under the primary finger
QScopedPointer<QQuickView> window(createView());
-
window->setSource(testFileUrl("touchpointdeliveryorder.qml"));
+ window->show();
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
+
/*
The items are positioned from left to right:
| background |
@@ -1278,8 +1246,6 @@ void tst_TouchMouse::touchPointDeliveryOrder()
QPoint pLeftMiddle = QPoint(200, 100);
QPoint pRightMiddle = QPoint(350, 100);
- window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window.data()));
QVector<QQuickItem*> events;
EventItem *background = window->rootObject()->findChild<EventItem*>("background");
@@ -1364,16 +1330,12 @@ void tst_TouchMouse::hoverEnabled()
// device->setType(QTouchDevice::TouchScreen);
// QWindowSystemInterface::registerTouchDevice(device);
- // Ensure the cursor is away from the window
- QCursor::setPos(0, 0);
-
- QQuickView *window = createView();
+ QScopedPointer<QQuickView> window(createView());
window->setSource(testFileUrl("hoverMouseAreas.qml"));
- window->setPosition(10, 10);
-
+ QQuickViewTestUtil::centerOnScreen(window.data());
+ QQuickViewTestUtil::moveMouseAway(window.data());
window->show();
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowExposed(window));
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
QQuickItem *root = window->rootObject();
QVERIFY(root != 0);
@@ -1396,14 +1358,14 @@ void tst_TouchMouse::hoverEnabled()
QPoint p2(150, 250);
// ------------------------- Mouse move to mouseArea1
- QTest::mouseMove(window, p1);
+ QTest::mouseMove(window.data(), p1);
QVERIFY(enterSpy1.count() == 1);
QVERIFY(mouseArea1->hovered());
QVERIFY(!mouseArea2->hovered());
// ------------------------- Touch click on mouseArea1
- QTest::touchEvent(window, device).press(0, p1, window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
QCOMPARE(enterSpy1.count(), 1);
QCOMPARE(enterSpy2.count(), 0);
@@ -1411,7 +1373,7 @@ void tst_TouchMouse::hoverEnabled()
QVERIFY(mouseArea1->hovered());
QVERIFY(!mouseArea2->hovered());
- QTest::touchEvent(window, device).release(0, p1, window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
QVERIFY(clickSpy1.count() == 1);
QVERIFY(mouseArea1->hovered());
QVERIFY(!mouseArea2->hovered());
@@ -1420,7 +1382,7 @@ void tst_TouchMouse::hoverEnabled()
if (QGuiApplication::platformName().compare(QLatin1String("xcb"), Qt::CaseInsensitive) == 0)
QSKIP("hover can be momentarily inconsistent on X11, depending on timing of flushFrameSynchronousEvents with touch and mouse movements (QTBUG-55350)");
- QTest::touchEvent(window, device).press(0, p2, window);
+ QTest::touchEvent(window.data(), device).press(0, p2, window.data());
QVERIFY(mouseArea1->hovered());
QVERIFY(mouseArea2->hovered());
@@ -1428,7 +1390,7 @@ void tst_TouchMouse::hoverEnabled()
QCOMPARE(enterSpy1.count(), 1);
QCOMPARE(enterSpy2.count(), 1);
- QTest::touchEvent(window, device).release(0, p2, window);
+ QTest::touchEvent(window.data(), device).release(0, p2, window.data());
QVERIFY(clickSpy2.count() == 1);
QVERIFY(mouseArea1->hovered());
@@ -1437,7 +1399,7 @@ void tst_TouchMouse::hoverEnabled()
QCOMPARE(exitSpy2.count(), 1);
// ------------------------- Another touch click on mouseArea1
- QTest::touchEvent(window, device).press(0, p1, window);
+ QTest::touchEvent(window.data(), device).press(0, p1, window.data());
QCOMPARE(enterSpy1.count(), 1);
QCOMPARE(enterSpy2.count(), 1);
@@ -1445,7 +1407,7 @@ void tst_TouchMouse::hoverEnabled()
QVERIFY(mouseArea1->hovered());
QVERIFY(!mouseArea2->hovered());
- QTest::touchEvent(window, device).release(0, p1, window);
+ QTest::touchEvent(window.data(), device).release(0, p1, window.data());
QCOMPARE(clickSpy1.count(), 2);
QVERIFY(mouseArea1->hovered());
QVERIFY(!mouseArea1->pressed());
diff --git a/tests/benchmarks/qml/compilation/tst_compilation.cpp b/tests/benchmarks/qml/compilation/tst_compilation.cpp
index 61339c6f60..b28d69332c 100644
--- a/tests/benchmarks/qml/compilation/tst_compilation.cpp
+++ b/tests/benchmarks/qml/compilation/tst_compilation.cpp
@@ -51,6 +51,9 @@ private slots:
void jsparser_data();
void jsparser();
+ void bigimport_data();
+ void bigimport();
+
private:
QQmlEngine engine;
};
@@ -115,6 +118,74 @@ void tst_compilation::jsparser()
}
}
+void tst_compilation::bigimport_data()
+{
+ QTest::addColumn<int>("filesToCreate");
+ QTest::addColumn<bool>("writeQmldir");
+
+ QTest::newRow("10, qmldir")
+ << 10 << true;
+ QTest::newRow("100, qmldir")
+ << 100 << true;
+ QTest::newRow("1000, qmldir")
+ << 1000 << true;
+
+ QTest::newRow("10, noqmldir")
+ << 10 << false;
+ QTest::newRow("100, noqmldir")
+ << 100 << false;
+ QTest::newRow("1000, noqmldir")
+ << 1000 << false;
+}
+
+void tst_compilation::bigimport()
+{
+ QFETCH(int, filesToCreate);
+ QFETCH(bool, writeQmldir);
+ QTemporaryDir d;
+ //d.setAutoRemove(false); // for debugging
+
+ QString p;
+ {
+ for (int i = 0; i < filesToCreate; ++i) {
+ QFile f(d.path() + QDir::separator() + QString::fromLatin1("Type%1.qml").arg(i));
+ QVERIFY(f.open(QIODevice::WriteOnly));
+ f.write("import QtQuick 2.0\n");
+ f.write("import \".\"\n");
+ f.write("Item {}\n");
+ }
+
+ QFile qmldir(d.path() + QDir::separator() + "qmldir");
+ if (writeQmldir)
+ QVERIFY(qmldir.open(QIODevice::WriteOnly));
+ QFile main(d.path() + QDir::separator() + "main.qml");
+ QVERIFY(main.open(QIODevice::WriteOnly));
+ p = QFileInfo(main).absoluteFilePath();
+ //qDebug() << p; // for debugging
+
+ main.write("import QtQuick 2.0\n");
+ main.write("import \".\"\n");
+ main.write("\n");
+ main.write("Item {\n");
+
+ for (int i = 0; i < filesToCreate; ++i) {
+ main.write(qPrintable(QString::fromLatin1("Type%1 {}\n").arg(i)));
+ if (writeQmldir)
+ qmldir.write(qPrintable(QString::fromLatin1("Type%1 1.0 Type%1.qml\n").arg(i)));
+ }
+
+ main.write("}");
+ }
+
+ QBENCHMARK {
+ QQmlEngine e;
+ QQmlComponent c(&e, p);
+ QCOMPARE(c.status(), QQmlComponent::Ready);
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(o->children().count() == filesToCreate);
+ }
+}
+
QTEST_MAIN(tst_compilation)
#include "tst_compilation.moc"
diff --git a/tests/manual/text/SignalIndicator.qml b/tests/manual/text/SignalIndicator.qml
new file mode 100644
index 0000000000..3eaadde6d7
--- /dev/null
+++ b/tests/manual/text/SignalIndicator.qml
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the manual tests of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.9
+
+Rectangle {
+ implicitWidth: text.implicitWidth * 1.2
+ implicitHeight: text.implicitHeight * 1.1
+ color: "lightgrey"
+ property color blipColor: "green"
+ property int blipDuration: 30 // ms
+ property alias label: text.text
+
+ function blip() {
+ blipAnim.start()
+ }
+
+ SequentialAnimation on color {
+ id: blipAnim
+ PropertyAction { value: blipColor }
+ PauseAnimation { duration: blipDuration }
+ PropertyAction { value: "lightgrey" }
+ }
+
+ Text {
+ id: text
+ anchors.centerIn: parent
+ }
+}
diff --git a/tests/manual/text/main.cpp b/tests/manual/text/main.cpp
new file mode 100644
index 0000000000..a4e1060cf5
--- /dev/null
+++ b/tests/manual/text/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the manual tests of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QGuiApplication>
+#include <QQmlApplicationEngine>
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ QQmlApplicationEngine engine;
+ engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
+
+ return app.exec();
+}
diff --git a/tests/manual/text/main.qml b/tests/manual/text/main.qml
new file mode 100644
index 0000000000..d7e214ee38
--- /dev/null
+++ b/tests/manual/text/main.qml
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the manual tests of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.9
+import QtQuick.Window 2.2
+import "qrc:/quick/shared/" as Examples
+
+Window {
+ width: 800
+ height: 600
+ visible: true
+ Examples.LauncherList {
+ id: ll
+ anchors.fill: parent
+ Component.onCompleted: {
+ addExample("TextInput", "TextInput properties and signals", Qt.resolvedUrl("textInputPropertiesAndSignals.qml"))
+ }
+ }
+}
diff --git a/tests/manual/text/qml.qrc b/tests/manual/text/qml.qrc
new file mode 100644
index 0000000000..555e37bd69
--- /dev/null
+++ b/tests/manual/text/qml.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>textInputPropertiesAndSignals.qml</file>
+ <file>SignalIndicator.qml</file>
+ </qresource>
+</RCC>
diff --git a/tests/manual/text/text.pro b/tests/manual/text/text.pro
new file mode 100644
index 0000000000..3705d41df0
--- /dev/null
+++ b/tests/manual/text/text.pro
@@ -0,0 +1,7 @@
+TEMPLATE = app
+
+QT += qml quick
+
+SOURCES += main.cpp
+
+RESOURCES += qml.qrc ../../../examples/quick/shared/quick_shared.qrc
diff --git a/tests/manual/text/textInputPropertiesAndSignals.qml b/tests/manual/text/textInputPropertiesAndSignals.qml
new file mode 100644
index 0000000000..a3fd602c16
--- /dev/null
+++ b/tests/manual/text/textInputPropertiesAndSignals.qml
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the manual tests of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.9
+import QtQuick.Layouts 1.1
+import "qrc:/quick/shared/" as Shared
+
+Item {
+ width: 600; height: 600
+ GridLayout {
+ columns: 3; rowSpacing: 6; columnSpacing: 6
+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: 12 }
+
+ // ----------------------------------------------------
+ Text {
+ text: "try typing and input methods in the TextInput below:"
+ Layout.columnSpan: 3
+ }
+
+ // ----------------------------------------------------
+ Text {
+ text: "TextInput"
+ }
+
+ Rectangle {
+ Layout.fillWidth: true
+ implicitHeight: textInput.implicitHeight + 8
+ radius: 4; antialiasing: true
+ border.color: "black"; color: "transparent"
+
+ TextInput {
+ id: textInput
+ anchors.fill: parent; anchors.margins: 4
+
+ onTextEdited: textEditedInd.blip()
+ onTextChanged: textChangedInd.blip()
+ onPreeditTextChanged: preeditInd.blip()
+ onDisplayTextChanged: displayTextInd.blip()
+ }
+
+ }
+
+ SignalIndicator {
+ id: textEditedInd
+ label: "textEdited"
+ }
+
+ // ----------------------------------------------------
+ Text { text: "text" }
+
+ Text { text: textInput.text; Layout.fillWidth: true }
+
+ SignalIndicator {
+ id: textChangedInd
+ label: "textChanged"
+ }
+
+ // ----------------------------------------------------
+ Text { text: "preeditText" }
+
+ Text { text: textInput.preeditText; Layout.fillWidth: true }
+
+ SignalIndicator {
+ id: preeditInd
+ label: "preeditTextChanged"
+ }
+
+ // ----------------------------------------------------
+ Text { text: "displayText" }
+
+ Text { text: textInput.displayText; Layout.fillWidth: true }
+
+ SignalIndicator {
+ id: displayTextInd
+ label: "displayTextChanged"
+ }
+
+ // ----------------------------------------------------
+ Shared.TextField {
+ id: copyFrom
+ Layout.column: 1
+ Layout.row: 5
+ Layout.fillWidth: true
+ text: "copy this"
+ }
+
+ Shared.Button {
+ Layout.column: 2
+ Layout.row: 5
+ text: "setText"
+ onClicked: {
+ Qt.inputMethod.reset()
+ textInput.text = copyFrom.text
+ }
+ }
+ }
+}
diff --git a/tests/manual/touch/mpta-crosshairs.qml b/tests/manual/touch/mpta-crosshairs.qml
index 8b71e4fdc3..d1dbd0f188 100644
--- a/tests/manual/touch/mpta-crosshairs.qml
+++ b/tests/manual/touch/mpta-crosshairs.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2017 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the manual tests of the Qt Toolkit.
@@ -38,11 +38,13 @@
**
****************************************************************************/
-import QtQuick 2.4
+import QtQuick 2.9
import QtQuick.Window 2.2
Rectangle {
id: root
+ width: 480
+ height: 480
color: "black"
MultiPointTouchArea {
@@ -51,11 +53,11 @@ Rectangle {
touchPoints: [
TouchPoint { property color color: "red" },
TouchPoint { property color color: "orange" },
- TouchPoint { property color color: "yellow" },
+ TouchPoint { property color color: "lightsteelblue" },
TouchPoint { property color color: "green" },
TouchPoint { property color color: "blue" },
TouchPoint { property color color: "violet" },
- TouchPoint { property color color: "cyan" },
+ TouchPoint { property color color: "steelblue" },
TouchPoint { property color color: "magenta" },
TouchPoint { property color color: "goldenrod" },
TouchPoint { property color color: "darkgray" }
@@ -65,40 +67,81 @@ Rectangle {
model: 10
Item {
- anchors.fill: parent
+ id: crosshairs
property TouchPoint touchPoint
+ x: touchPoint.x - width / 2
+ y: touchPoint.y - height / 2
+ width: 300; height: 300
visible: touchPoint.pressed
+ rotation: touchPoint.rotation
Rectangle {
color: touchPoint.color
- anchors.top: parent.top
- anchors.bottom: parent.bottom
- width: 2
- x: touchPoint.x - 1
+ anchors.centerIn: parent
+ width: 2; height: parent.height
+ antialiasing: true
}
Rectangle {
color: touchPoint.color
- anchors.left: parent.left
- anchors.right: parent.right
- height: 2
- y: touchPoint.y - 1
+ anchors.centerIn: parent
+ width: parent.width; height: 2
+ antialiasing: true
}
Rectangle {
color: touchPoint.color
- width: 50 * touchPoint.pressure
- height: width
+ implicitWidth: label.implicitWidth + 8
+ implicitHeight: label.implicitHeight + 16
radius: width / 2
- x: touchPoint.x - width / 2
- y: touchPoint.y - width / 2
+ anchors.centerIn: parent
+ antialiasing: true
+ Rectangle {
+ color: "black"
+ opacity: 0.35
+ width: (parent.width - 8) * touchPoint.pressure
+ height: width
+ radius: width / 2
+ anchors.centerIn: parent
+ antialiasing: true
+ }
+ Rectangle {
+ color: "transparent"
+ border.color: "white"
+ border.width: 2
+ opacity: 0.75
+ visible: width > 0
+ width: touchPoint.ellipseDiameters.width
+ height: touchPoint.ellipseDiameters.height
+ radius: Math.min(width, height) / 2
+ anchors.centerIn: parent
+ antialiasing: true
+ }
+ Text {
+ id: label
+ anchors.centerIn: parent
+ color: "white"
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ property string uid: touchPoint.uniqueId === undefined || touchPoint.uniqueId.numericId === -1 ?
+ "" : "\nUID " + touchPoint.uniqueId.numericId
+ text: "x " + touchPoint.x.toFixed(1) +
+ "\ny " + touchPoint.y.toFixed(1) + uid +
+ "\nID " + touchPoint.pointId.toString(16) +
+ "\n∡" + touchPoint.rotation.toFixed(1) + "°"
+ }
}
Rectangle {
id: velocityVector
visible: width > 0
width: touchPoint.velocity.length()
- height: 1
- x: touchPoint.x
- y: touchPoint.y
- rotation: width > 0 ? Math.acos(touchPoint.velocity.x / width) : 0
+ height: 4
+ Behavior on width { SmoothedAnimation { duration: 200 } }
+ radius: height / 2
+ antialiasing: true
+ color: "gray"
+ x: crosshairs.width / 2
+ y: crosshairs.height / 2
+ rotation: width > 0 ? Math.atan2(touchPoint.velocity.y, touchPoint.velocity.x) * 180 / Math.PI - crosshairs.rotation : 0
+ Behavior on rotation { SmoothedAnimation { duration: 20 } }
transformOrigin: Item.BottomLeft
}
diff --git a/tests/manual/v4/fun.4.js b/tests/manual/v4/fun.4.js
index b130acccd3..277761ad09 100644
--- a/tests/manual/v4/fun.4.js
+++ b/tests/manual/v4/fun.4.js
@@ -15,4 +15,5 @@ print([10, 20, 30].filter(function (v,k,o) { return v >= 20 }));
print([10,20,30].reduce(function(a,v,k,o) { return a + v }));
print([10,20,30].reduceRight(function(a,v,k,o) { return a + v }));
-
+print([10, 20, 30].find(function (v,k,o) { return v >= 20 }));
+print([10, 20, 30].findIndex(function (v,k,o) { return v >= 20 }));
diff --git a/tests/manual/v4/tests.pro b/tests/manual/v4/tests.pro
index a86a6bf6af..ce4a34f7a0 100644
--- a/tests/manual/v4/tests.pro
+++ b/tests/manual/v4/tests.pro
@@ -1,7 +1,7 @@
TEMPLATE = aux
TESTSCRIPT=$$PWD/test262.py
-V4CMD = qmljs
+isEmpty(V4CMD): V4CMD = qmljs
checktarget.target = check
checktarget.commands = python $$TESTSCRIPT --command=$$V4CMD --parallel --with-test-expectations --update-expectations
diff --git a/tests/testapplications/textlayout/styledtext-layout.qml b/tests/testapplications/textlayout/styledtext-layout.qml
index 4ad0c7e279..80f62a6b8f 100644
--- a/tests/testapplications/textlayout/styledtext-layout.qml
+++ b/tests/testapplications/textlayout/styledtext-layout.qml
@@ -88,7 +88,7 @@ Rectangle {
drag.target: rect
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: mouse.button == Qt.RightButton ? myText.font.pixelSize -= 1 : myText.font.pixelSize += 1
- onPositionChanged: myText.doLayout()
+ onPositionChanged: myText.forceLayout()
}
}
}
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp
index 31fd9b383f..e8a506264c 100644
--- a/tools/qml/main.cpp
+++ b/tools/qml/main.cpp
@@ -46,7 +46,6 @@
#include <QDir>
#include <QFile>
#include <QFileInfo>
-#include <QRegularExpression>
#include <QStringList>
#include <QScopedPointer>
#include <QDebug>
@@ -464,7 +463,7 @@ int main(int argc, char *argv[])
QString dummyDir;
//Handle main arguments
- QStringList argList = app->arguments();
+ const QStringList argList = app->arguments();
for (int i = 1; i < argList.count(); i++) {
const QString &arg = argList[i];
if (arg == QLatin1String("-quiet"))
@@ -568,29 +567,14 @@ int main(int argc, char *argv[])
loadDummyDataFiles(e, dummyDir);
for (const QString &path : qAsConst(files)) {
- //QUrl::fromUserInput doesn't treat no scheme as relative file paths
-#if QT_CONFIG(regularexpression)
- QRegularExpression urlRe("[[:word:]]+://.*");
- if (urlRe.match(path).hasMatch()) { //Treat as a URL
- QUrl url = QUrl::fromUserInput(path);
- if (verboseMode)
- printf("qml: loading %s\n",
- qPrintable(url.isLocalFile()
- ? QDir::toNativeSeparators(url.toLocalFile())
- : url.toString()));
+ QUrl url = QUrl::fromUserInput(path, QDir::currentPath());
+ if (verboseMode)
+ printf("qml: loading %s\n", qPrintable(url.toString()));
+ QByteArray strippedFile;
+ if (getFileSansBangLine(path, strippedFile))
+ e.loadData(strippedFile, e.baseUrl().resolved(url)); //QQmlComponent won't resolve it for us, it doesn't know it's a valid file if we loadData
+ else //Errors or no bang line
e.load(url);
- } else
-#endif
- { //Local file path
- if (verboseMode)
- printf("qml: loading %s\n", qPrintable(QDir::toNativeSeparators(path)));
-
- QByteArray strippedFile;
- if (getFileSansBangLine(path, strippedFile))
- e.loadData(strippedFile, e.baseUrl().resolved(QUrl::fromLocalFile(path))); //QQmlComponent won't resolve it for us, it doesn't know it's a valid file if we loadData
- else //Errors or no bang line
- e.load(path);
- }
}
if (lw->earlyExit)
diff --git a/tools/qmlcachegen/qmlcache.prf b/tools/qmlcachegen/qmlcache.prf
new file mode 100644
index 0000000000..fed9f0d2f3
--- /dev/null
+++ b/tools/qmlcachegen/qmlcache.prf
@@ -0,0 +1,12 @@
+qtPrepareTool(QML_CACHEGEN, qmlcachegen)
+
+!isEmpty(QT_TARGET_ARCH):QML_CACHEGEN_ARCH=$$QT_TARGET_ARCH
+else:QML_CACHEGEN_ARCH=$$QT_ARCH
+
+qmlcachegen.input = QML_FILES
+qmlcachegen.output = ${QMAKE_FILE_IN}c
+qmlcachegen.commands = $$QML_CACHEGEN --target-architecture=$$QML_CACHEGEN_ARCH ${QMAKE_FILE_IN}
+qmlcachegen.name = Generate QML Cache ${QMAKE_FILE_IN}
+qmlcachegen.variable_out = AUX_QML_FILES
+
+QMAKE_EXTRA_COMPILERS += qmlcachegen
diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp
new file mode 100644
index 0000000000..977c5b6ff1
--- /dev/null
+++ b/tools/qmlcachegen/qmlcachegen.cpp
@@ -0,0 +1,312 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QCoreApplication>
+#include <QStringList>
+#include <QCommandLineParser>
+#include <QFile>
+#include <QFileInfo>
+#include <QDateTime>
+
+#include <private/qqmlirbuilder_p.h>
+#include <private/qv4isel_moth_p.h>
+#include <private/qqmljsparser_p.h>
+
+QT_BEGIN_NAMESPACE
+extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed;
+
+namespace QV4 { namespace JIT {
+Q_QML_EXPORT QV4::EvalISelFactory *createISelForArchitecture(const QString &architecture);
+} }
+
+QT_END_NAMESPACE
+
+struct Error
+{
+ QString message;
+ void print();
+ Error augment(const QString &contextErrorMessage) const;
+};
+
+void Error::print()
+{
+ fprintf(stderr, "%s\n", qPrintable(message));
+}
+
+Error Error::augment(const QString &contextErrorMessage) const
+{
+ Error augmented;
+ augmented.message = contextErrorMessage + message;
+ return augmented;
+}
+
+QString diagnosticErrorMessage(const QString &fileName, const QQmlJS::DiagnosticMessage &m)
+{
+ QString message;
+ message = fileName + QLatin1Char(':') + QString::number(m.loc.startLine) + QLatin1Char(':');
+ if (m.loc.startColumn > 0)
+ message += QString::number(m.loc.startColumn) + QLatin1Char(':');
+
+ if (m.isError())
+ message += QLatin1String(" error: ");
+ else
+ message += QLatin1String(" warning: ");
+ message += m.message;
+ return message;
+}
+
+static bool compileQmlFile(const QString &inputFileName, QV4::EvalISelFactory *iselFactory, Error *error)
+{
+ QmlIR::Document irDocument(/*debugMode*/false);
+
+ QString sourceCode;
+ {
+ QFile f(inputFileName);
+ if (!f.open(QIODevice::ReadOnly)) {
+ error->message = QLatin1String("Error opening ") + inputFileName + QLatin1Char(':') + f.errorString();
+ return false;
+ }
+ sourceCode = QString::fromUtf8(f.readAll());
+ if (f.error() != QFileDevice::NoError) {
+ error->message = QLatin1String("Error reading from ") + inputFileName + QLatin1Char(':') + f.errorString();
+ return false;
+ }
+ irDocument.jsModule.sourceTimeStamp = QFileInfo(f).lastModified().toMSecsSinceEpoch();
+ }
+
+ {
+ QSet<QString> illegalNames; // ####
+ QmlIR::IRBuilder irBuilder(illegalNames);
+ if (!irBuilder.generateFromQml(sourceCode, inputFileName, &irDocument)) {
+ for (const QQmlJS::DiagnosticMessage &parseError: qAsConst(irBuilder.errors)) {
+ if (!error->message.isEmpty())
+ error->message += QLatin1Char('\n');
+ error->message += diagnosticErrorMessage(inputFileName, parseError);
+ }
+ return false;
+ }
+ }
+
+ {
+ QmlIR::JSCodeGen v4CodeGen(inputFileName, irDocument.code, &irDocument.jsModule, &irDocument.jsParserEngine, irDocument.program, /*import cache*/0, &irDocument.jsGenerator.stringTable);
+ for (QmlIR::Object *object: qAsConst(irDocument.objects)) {
+ if (object->functionsAndExpressions->count == 0)
+ continue;
+ QList<QmlIR::CompiledFunctionOrExpression> functionsToCompile;
+ for (QmlIR::CompiledFunctionOrExpression *foe = object->functionsAndExpressions->first; foe; foe = foe->next) {
+ foe->disableAcceleratedLookups = true;
+ functionsToCompile << *foe;
+ }
+ const QVector<int> runtimeFunctionIndices = v4CodeGen.generateJSCodeForFunctionsAndBindings(functionsToCompile);
+ QList<QQmlJS::DiagnosticMessage> jsErrors = v4CodeGen.errors();
+ if (!jsErrors.isEmpty()) {
+ for (const QQmlJS::DiagnosticMessage &e: qAsConst(jsErrors)) {
+ if (!error->message.isEmpty())
+ error->message += QLatin1Char('\n');
+ error->message += diagnosticErrorMessage(inputFileName, e);
+ }
+ return false;
+ }
+
+ QQmlJS::MemoryPool *pool = irDocument.jsParserEngine.pool();
+ object->runtimeFunctionIndices.allocate(pool, runtimeFunctionIndices);
+ }
+
+ QmlIR::QmlUnitGenerator generator;
+
+ // ### translation binding simplification
+
+ QV4::ExecutableAllocator allocator;
+ QScopedPointer<QV4::EvalInstructionSelection> isel(iselFactory->create(/*engine*/nullptr, &allocator, &irDocument.jsModule, &irDocument.jsGenerator));
+ // Disable lookups in non-standalone (aka QML) mode
+ isel->setUseFastLookups(false);
+ irDocument.javaScriptCompilationUnit = isel->compile(/*generate unit*/false);
+ // ###
+ QV4::CompiledData::ResolvedTypeReferenceMap dummyDependencies;
+ QV4::CompiledData::Unit *unit = generator.generate(irDocument, /*engine*/nullptr, dummyDependencies);
+ unit->flags |= QV4::CompiledData::Unit::StaticData;
+ unit->flags |= QV4::CompiledData::Unit::PendingTypeCompilation;
+ irDocument.javaScriptCompilationUnit->data = unit;
+
+ if (!irDocument.javaScriptCompilationUnit->saveToDisk(inputFileName, &error->message))
+ return false;
+
+ free(unit);
+ }
+ return true;
+}
+
+static bool compileJSFile(const QString &inputFileName, QV4::EvalISelFactory *iselFactory, Error *error)
+{
+ QmlIR::Document irDocument(/*debugMode*/false);
+
+ QString sourceCode;
+ {
+ QFile f(inputFileName);
+ if (!f.open(QIODevice::ReadOnly)) {
+ error->message = QLatin1String("Error opening ") + inputFileName + QLatin1Char(':') + f.errorString();
+ return false;
+ }
+ sourceCode = QString::fromUtf8(f.readAll());
+ if (f.error() != QFileDevice::NoError) {
+ error->message = QLatin1String("Error reading from ") + inputFileName + QLatin1Char(':') + f.errorString();
+ return false;
+ }
+ irDocument.jsModule.sourceTimeStamp = QFileInfo(f).lastModified().toMSecsSinceEpoch();
+ }
+
+ QQmlJS::Engine *engine = &irDocument.jsParserEngine;
+ QmlIR::ScriptDirectivesCollector directivesCollector(engine, &irDocument.jsGenerator);
+ QQmlJS::Directives *oldDirs = engine->directives();
+ engine->setDirectives(&directivesCollector);
+
+ QQmlJS::AST::Program *program = nullptr;
+
+ {
+ QQmlJS::Lexer lexer(engine);
+ lexer.setCode(sourceCode, /*line*/1, /*parseAsBinding*/false);
+ QQmlJS::Parser parser(engine);
+
+ bool parsed = parser.parseProgram();
+
+ for (const QQmlJS::DiagnosticMessage &parseError: parser.diagnosticMessages()) {
+ if (!error->message.isEmpty())
+ error->message += QLatin1Char('\n');
+ error->message += diagnosticErrorMessage(inputFileName, parseError);
+ }
+
+ if (!parsed) {
+ engine->setDirectives(oldDirs);
+ return false;
+ }
+
+ program = QQmlJS::AST::cast<QQmlJS::AST::Program*>(parser.rootNode());
+ if (!program) {
+ lexer.setCode(QStringLiteral("undefined;"), 1, false);
+ parsed = parser.parseProgram();
+ Q_ASSERT(parsed);
+ program = QQmlJS::AST::cast<QQmlJS::AST::Program*>(parser.rootNode());
+ Q_ASSERT(program);
+ }
+ }
+
+ {
+ QmlIR::JSCodeGen v4CodeGen(inputFileName, irDocument.code, &irDocument.jsModule, &irDocument.jsParserEngine, irDocument.program, /*import cache*/0, &irDocument.jsGenerator.stringTable);
+ v4CodeGen.generateFromProgram(inputFileName, sourceCode, program, &irDocument.jsModule, QQmlJS::Codegen::GlobalCode);
+ QList<QQmlJS::DiagnosticMessage> jsErrors = v4CodeGen.errors();
+ if (!jsErrors.isEmpty()) {
+ for (const QQmlJS::DiagnosticMessage &e: qAsConst(jsErrors)) {
+ if (!error->message.isEmpty())
+ error->message += QLatin1Char('\n');
+ error->message += diagnosticErrorMessage(inputFileName, e);
+ }
+ engine->setDirectives(oldDirs);
+ return false;
+ }
+
+ QmlIR::QmlUnitGenerator generator;
+
+ // ### translation binding simplification
+
+ QScopedPointer<QV4::EvalInstructionSelection> isel(iselFactory->create(/*engine*/nullptr, /*executable allocator*/nullptr, &irDocument.jsModule, &irDocument.jsGenerator));
+ // Disable lookups in non-standalone (aka QML) mode
+ isel->setUseFastLookups(false);
+ irDocument.javaScriptCompilationUnit = isel->compile(/*generate unit*/false);
+ // ###
+ QV4::CompiledData::ResolvedTypeReferenceMap dummyDependencies;
+ QV4::CompiledData::Unit *unit = generator.generate(irDocument, /*engine*/nullptr, dummyDependencies);
+ unit->flags |= QV4::CompiledData::Unit::StaticData;
+ irDocument.javaScriptCompilationUnit->data = unit;
+
+ if (!irDocument.javaScriptCompilationUnit->saveToDisk(inputFileName, &error->message)) {
+ engine->setDirectives(oldDirs);
+ return false;
+ }
+
+ free(unit);
+ }
+ engine->setDirectives(oldDirs);
+ return true;
+}
+
+int main(int argc, char **argv)
+{
+ // Produce reliably the same output for the same input by disabling QHash's random seeding.
+ qt_qhash_seed.testAndSetRelaxed(-1, 0);
+
+ QCoreApplication app(argc, argv);
+ QCoreApplication::setApplicationName(QStringLiteral("qmlcachegen"));
+ QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR));
+
+ QCommandLineParser parser;
+ parser.addHelpOption();
+ parser.addVersionOption();
+
+ QCommandLineOption targetArchitectureOption(QStringLiteral("target-architecture"), QCoreApplication::translate("main", "Target architecture"), QCoreApplication::translate("main", "architecture"));
+ parser.addOption(targetArchitectureOption);
+
+ parser.addPositionalArgument(QStringLiteral("[qml file]"),
+ QStringLiteral("QML source file to generate cache for."));
+
+ parser.process(app);
+
+ const QStringList sources = parser.positionalArguments();
+ if (sources.isEmpty()){
+ parser.showHelp();
+ } else if (sources.count() > 1) {
+ fprintf(stderr, "%s\n", qPrintable(QStringLiteral("Too many input files specified: '") + sources.join(QStringLiteral("' '")) + QLatin1Char('\'')));
+ return EXIT_FAILURE;
+ }
+ const QString inputFile = sources.first();
+
+ QScopedPointer<QV4::EvalISelFactory> isel;
+ const QString targetArchitecture = parser.value(targetArchitectureOption);
+
+ isel.reset(QV4::JIT::createISelForArchitecture(targetArchitecture));
+
+ if (!isel)
+ isel.reset(new QV4::Moth::ISelFactory);
+
+ Error error;
+
+ if (inputFile.endsWith(QLatin1String(".qml"))) {
+ if (!compileQmlFile(inputFile, isel.data(), &error)) {
+ error.augment(QLatin1String("Error compiling qml file: ")).print();
+ return EXIT_FAILURE;
+ }
+ } else if (inputFile.endsWith(QLatin1String(".js"))) {
+ if (!compileJSFile(inputFile, isel.data(), &error)) {
+ error.augment(QLatin1String("Error compiling qml file: ")).print();
+ return EXIT_FAILURE;
+ }
+ } else {
+ fprintf(stderr, "Ignoring %s input file as it is not QML source code - maybe remove from QML_FILES?\n", qPrintable(inputFile)); }
+
+
+ return EXIT_SUCCESS;
+}
diff --git a/tools/qmlcachegen/qmlcachegen.pro b/tools/qmlcachegen/qmlcachegen.pro
new file mode 100644
index 0000000000..81783d0396
--- /dev/null
+++ b/tools/qmlcachegen/qmlcachegen.pro
@@ -0,0 +1,24 @@
+option(host_build)
+
+QT = qmldevtools-private
+DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
+
+SOURCES = qmlcachegen.cpp
+TARGET = qmlcachegen
+
+BUILD_INTEGRATION = qmlcache.prf
+!force_independent {
+ qmake_integration.input = BUILD_INTEGRATION
+ qmake_integration.output = $$[QT_HOST_DATA]/mkspecs/features/${QMAKE_FILE_BASE}.prf
+ qmake_integration.commands = $$QMAKE_COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
+ qmake_integration.name = COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
+ qmake_integration.CONFIG = no_clean no_link
+ !contains(TEMPLATE, vc.*): qmake_integration.variable_out = GENERATED_FILES
+ QMAKE_EXTRA_COMPILERS += qmake_integration
+}
+
+qmake_integration_installs.files = $$BUILD_INTEGRATION
+qmake_integration_installs.path = $$[QT_HOST_DATA]/mkspecs/features
+INSTALLS += qmake_integration_installs
+
+load(qt_tool)
diff --git a/tools/qmleasing/mainwindow.cpp b/tools/qmleasing/mainwindow.cpp
index 5a5f651396..d36ab5fd75 100644
--- a/tools/qmleasing/mainwindow.cpp
+++ b/tools/qmleasing/mainwindow.cpp
@@ -73,7 +73,8 @@ MainWindow::MainWindow(QWidget *parent) :
quickView.rootContext()->setContextProperty(QLatin1String("spinBox"), ui_properties.spinBox);
- foreach (const QString &name, splineEditor->presetNames())
+ const auto presetNames = splineEditor->presetNames();
+ for (const QString &name : presetNames)
ui_properties.comboBox->addItem(name);
connect(ui_properties.comboBox, SIGNAL(currentIndexChanged(QString)), splineEditor, SLOT(setPreset(QString)));
diff --git a/tools/qmleasing/mainwindow.h b/tools/qmleasing/mainwindow.h
index 9af5c8050c..7ca4dbfd5c 100644
--- a/tools/qmleasing/mainwindow.h
+++ b/tools/qmleasing/mainwindow.h
@@ -51,9 +51,9 @@ public slots:
void importData(int result);
protected:
- virtual void moveEvent(QMoveEvent *event);
- virtual void resizeEvent(QResizeEvent *event);
- virtual void closeEvent(QCloseEvent *event);
+ void moveEvent(QMoveEvent *event) override;
+ void resizeEvent(QResizeEvent *event) override;
+ void closeEvent(QCloseEvent *event) override;
void initQml();
private:
diff --git a/tools/qmleasing/splineeditor.cpp b/tools/qmleasing/splineeditor.cpp
index 01a279afbf..cd0c0b3ae0 100644
--- a/tools/qmleasing/splineeditor.cpp
+++ b/tools/qmleasing/splineeditor.cpp
@@ -620,7 +620,7 @@ void SplineEditor::mouseMoveEvent(QMouseEvent *e)
if (indexIsRealPoint(m_activeControlPoint)) {
//move also the tangents
QPointF targetPoint = p;
- QPointF distance = targetPoint - m_controlPoints[m_activeControlPoint];
+ QPointF distance = targetPoint - m_controlPoints.at(m_activeControlPoint);
m_controlPoints[m_activeControlPoint] = targetPoint;
m_controlPoints[m_activeControlPoint - 1] += distance;
m_controlPoints[m_activeControlPoint + 1] += distance;
@@ -629,7 +629,7 @@ void SplineEditor::mouseMoveEvent(QMouseEvent *e)
m_controlPoints[m_activeControlPoint] = p;
} else {
QPointF targetPoint = p;
- QPointF distance = targetPoint - m_controlPoints[m_activeControlPoint];
+ QPointF distance = targetPoint - m_controlPoints.at(m_activeControlPoint);
m_controlPoints[m_activeControlPoint] = p;
if ((m_activeControlPoint > 1) && (m_activeControlPoint % 3) == 0) { //right control point
diff --git a/tools/qmleasing/splineeditor.h b/tools/qmleasing/splineeditor.h
index 414b787bc3..8dd47c3a89 100644
--- a/tools/qmleasing/splineeditor.h
+++ b/tools/qmleasing/splineeditor.h
@@ -75,12 +75,12 @@ public slots:
void setEasingCurve(const QString &code);
protected:
- void paintEvent(QPaintEvent *);
- void mousePressEvent(QMouseEvent *);
- void mouseMoveEvent(QMouseEvent *);
- void mouseReleaseEvent(QMouseEvent *);
+ void paintEvent(QPaintEvent *) override;
+ void mousePressEvent(QMouseEvent *) override;
+ void mouseMoveEvent(QMouseEvent *) override;
+ void mouseReleaseEvent(QMouseEvent *) override;
#if QT_CONFIG(contextmenu)
- void contextMenuEvent(QContextMenuEvent *);
+ void contextMenuEvent(QContextMenuEvent *) override;
#endif // contextmenu
void invalidate();
diff --git a/tools/qmlimportscanner/main.cpp b/tools/qmlimportscanner/main.cpp
index b2ff751231..bac7694e17 100644
--- a/tools/qmlimportscanner/main.cpp
+++ b/tools/qmlimportscanner/main.cpp
@@ -146,7 +146,7 @@ QVariantMap pluginsForModulePath(const QString &modulePath) {
classnames += QString::fromUtf8(line.split(' ').at(1));
classnames += QLatin1Char(' ');
} else if (line.startsWith("depends")) {
- QList<QByteArray> dep = line.split(' ');
+ const QList<QByteArray> dep = line.split(' ');
if (dep.length() != 3)
std::cerr << "depends: expected 2 arguments: module identifier and version" << std::endl;
else
@@ -222,8 +222,8 @@ QVariantList findPathsForModuleImports(const QVariantList &imports)
QVariantList importsCopy(imports);
for (int i = 0; i < importsCopy.length(); ++i) {
- QVariantMap import = qvariant_cast<QVariantMap>(importsCopy[i]);
- if (import[typeLiteral()] == QLatin1String("module")) {
+ QVariantMap import = qvariant_cast<QVariantMap>(importsCopy.at(i));
+ if (import.value(typeLiteral()) == QLatin1String("module")) {
const QPair<QString, QString> paths =
resolveImportPath(import.value(nameLiteral()).toString(), import.value(versionLiteral()).toString());
if (!paths.first.isEmpty()) {
@@ -264,7 +264,8 @@ static QVariantList findQmlImportsInQmlCode(const QString &filePath, const QStri
if (!parser.parse() || !parser.diagnosticMessages().isEmpty()) {
// Extract errors from the parser
- foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) {
+ const auto diagnosticMessages = parser.diagnosticMessages();
+ for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) {
std::cerr << QDir::toNativeSeparators(filePath).toStdString() << ':'
<< m.loc.startLine << ':' << m.message.toStdString() << std::endl;
}
@@ -342,7 +343,8 @@ QVariantList findQmlImportsInJavascriptFile(const QString &filePath)
QQmlJS::Parser parser(&ee);
parser.parseProgram();
- foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages())
+ const auto diagnosticMessages = parser.diagnosticMessages();
+ for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages)
if (m.isError())
return QVariantList();
@@ -537,7 +539,7 @@ int main(int argc, char *argv[])
if (arg.startsWith(QLatin1Char('-')) && arg != QLatin1String("-"))
break;
++i;
- if (!QFile::exists(arg)) {
+ if (arg != QLatin1String("-") && !QFile::exists(arg)) {
std::cerr << qPrintable(appName) << ": No such file or directory: \""
<< qPrintable(arg) << "\"\n";
return 1;
diff --git a/tools/qmljs/qmljs.cpp b/tools/qmljs/qmljs.cpp
index dd1898a88a..4d0f9d278f 100644
--- a/tools/qmljs/qmljs.cpp
+++ b/tools/qmljs/qmljs.cpp
@@ -103,29 +103,29 @@ int main(int argc, char *argv[])
bool cache = false;
if (!args.isEmpty()) {
- if (args.first() == QLatin1String("--jit")) {
+ if (args.constFirst() == QLatin1String("--jit")) {
mode = use_masm;
args.removeFirst();
}
#if QT_CONFIG(qml_interpreter)
- if (args.first() == QLatin1String("--interpret")) {
+ if (args.constFirst() == QLatin1String("--interpret")) {
mode = use_moth;
args.removeFirst();
}
#endif
- if (args.first() == QLatin1String("--qml")) {
+ if (args.constFirst() == QLatin1String("--qml")) {
runAsQml = true;
args.removeFirst();
}
- if (args.first() == QLatin1String("--cache")) {
+ if (args.constFirst() == QLatin1String("--cache")) {
cache = true;
args.removeFirst();
}
- if (args.first() == QLatin1String("--help")) {
+ if (args.constFirst() == QLatin1String("--help")) {
std::cerr << "Usage: qmljs [|--jit|--interpret|--qml] file..." << std::endl;
return EXIT_SUCCESS;
}
@@ -141,7 +141,7 @@ int main(int argc, char *argv[])
#endif
#ifdef V4_ENABLE_JIT
} else {
- iSelFactory = new QV4::JIT::ISelFactory;
+ iSelFactory = new QV4::JIT::ISelFactory<>;
#endif // V4_ENABLE_JIT
}
diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp
index 45914353a8..791fb71685 100644
--- a/tools/qmllint/main.cpp
+++ b/tools/qmllint/main.cpp
@@ -61,7 +61,8 @@ static bool lint_file(const QString &filename, bool silent)
bool success = isJavaScript ? parser.parseProgram() : parser.parse();
if (!success && !silent) {
- foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) {
+ const auto diagnosticMessages = parser.diagnosticMessages();
+ for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) {
qWarning("%s:%d : %s", qPrintable(filename), m.loc.startLine, qPrintable(m.message));
}
}
@@ -85,7 +86,8 @@ int main(int argv, char *argc[])
parser.process(app);
- if (parser.positionalArguments().isEmpty()) {
+ const auto positionalArguments = parser.positionalArguments();
+ if (positionalArguments.isEmpty()) {
parser.showHelp(-1);
}
@@ -95,12 +97,12 @@ int main(int argv, char *argc[])
#endif
bool success = true;
#if QT_CONFIG(commandlineparser)
- foreach (const QString &filename, parser.positionalArguments()) {
+ for (const QString &filename : positionalArguments)
#else
- foreach (const QString &filename, app.arguments()) {
+ const auto arguments = app.arguments();
+ for (const QString &filename : arguments)
#endif
success &= lint_file(filename, silent);
- }
return success ? 0 : -1;
}
diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp
index e4482ba2a6..dd7ae36c5d 100644
--- a/tools/qmlplugindump/main.cpp
+++ b/tools/qmlplugindump/main.cpp
@@ -212,7 +212,8 @@ QByteArray convertToId(const QMetaObject *mo)
// Collect all metaobjects for types registered with qmlRegisterType() without parameters
void collectReachableMetaObjectsWithoutQmlName(QQmlEnginePrivate *engine, QSet<const QMetaObject *>& metas ) {
- foreach (const QQmlType *ty, QQmlMetaType::qmlAllTypes()) {
+ const auto qmlAllTypes = QQmlMetaType::qmlAllTypes();
+ for (const QQmlType *ty : qmlAllTypes) {
if ( ! metas.contains(ty->metaObject()) ) {
if (!ty->isComposite()) {
collectReachableMetaObjects(engine, ty, &metas);
@@ -232,7 +233,8 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine,
metas.insert(FriendlyQObject::qtMeta());
QHash<QByteArray, QSet<QByteArray> > extensions;
- foreach (const QQmlType *ty, QQmlMetaType::qmlTypes()) {
+ const auto qmlTypes = QQmlMetaType::qmlTypes();
+ for (const QQmlType *ty : qmlTypes) {
if (!ty->isCreatable())
noncreatables.insert(ty->metaObject());
if (ty->isSingleton())
@@ -282,7 +284,7 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine,
if (creatable) {
// find even more QMetaObjects by instantiating QML types and running
// over the instances
- foreach (QQmlType *ty, QQmlMetaType::qmlTypes()) {
+ for (QQmlType *ty : qmlTypes) {
if (skip.contains(ty))
continue;
if (ty->isExtendedType())
@@ -773,7 +775,8 @@ static bool readDependenciesData(QString dependenciesFile, const QByteArray &fil
const QStringList requiredKeys = QStringList() << QStringLiteral("name")
<< QStringLiteral("type")
<< QStringLiteral("version");
- foreach (const QJsonValue &dep, doc.array()) {
+ const auto deps = doc.array();
+ for (const QJsonValue &dep : deps) {
if (dep.isObject()) {
QJsonObject obj = dep.toObject();
for (const QString &requiredKey : requiredKeys)
@@ -840,7 +843,9 @@ static bool getDependencies(const QQmlEngine &engine, const QString &pluginImpor
QStringList commandArgs = QStringList()
<< QLatin1String("-qmlFiles")
<< QLatin1String("-");
- foreach (const QString &path, engine.importPathList())
+ QStringList importPathList = engine.importPathList();
+ importPathList.removeOne(QStringLiteral("qrc:/qt-project.org/imports"));
+ for (const QString &path : importPathList)
commandArgs << QLatin1String("-importPath") << path;
QProcess importScanner;
@@ -866,6 +871,8 @@ static bool getDependencies(const QQmlEngine &engine, const QString &pluginImpor
if (!readDependenciesData(QLatin1String("<outputOfQmlimportscanner>"), depencenciesData,
dependencies, QStringList(pluginImportUri), forceQtQuickDependency)) {
std::cerr << "failed to process output of qmlimportscanner" << std::endl;
+ if (importScanner.exitCode() != 0)
+ std::cerr << importScanner.readAllStandardError().toStdString();
return false;
}
@@ -884,20 +891,20 @@ bool compactDependencies(QStringList *dependencies)
if (dependencies->isEmpty())
return false;
dependencies->sort();
- QStringList oldDep = dependencies->first().split(QLatin1Char(' '));
+ QStringList oldDep = dependencies->constFirst().split(QLatin1Char(' '));
Q_ASSERT(oldDep.size() == 2);
int oldPos = 0;
for (int idep = 1; idep < dependencies->size(); ++idep) {
QString depStr = dependencies->at(idep);
const QStringList newDep = depStr.split(QLatin1Char(' '));
Q_ASSERT(newDep.size() == 2);
- if (newDep.first() != oldDep.first()) {
+ if (newDep.constFirst() != oldDep.constFirst()) {
if (++oldPos != idep)
dependencies->replace(oldPos, depStr);
oldDep = newDep;
} else {
- QStringList v1 = oldDep.last().split(QLatin1Char('.'));
- QStringList v2 = newDep.last().split(QLatin1Char('.'));
+ const QStringList v1 = oldDep.constLast().split(QLatin1Char('.'));
+ const QStringList v2 = newDep.constLast().split(QLatin1Char('.'));
Q_ASSERT(v1.size() == 2);
Q_ASSERT(v2.size() == 2);
bool ok;
@@ -906,9 +913,9 @@ bool compactDependencies(QStringList *dependencies)
int major2 = v2.first().toInt(&ok);
Q_ASSERT(ok);
if (major1 != major2) {
- std::cerr << "Found a dependency on " << qPrintable(oldDep.first())
- << " with two major versions:" << qPrintable(oldDep.last())
- << " and " << qPrintable(newDep.last())
+ std::cerr << "Found a dependency on " << qPrintable(oldDep.constFirst())
+ << " with two major versions:" << qPrintable(oldDep.constLast())
+ << " and " << qPrintable(newDep.constLast())
<< " which is unsupported, discarding smaller version" << std::endl;
if (major1 < major2)
dependencies->replace(oldPos, depStr);
@@ -1091,18 +1098,18 @@ int main(int argc, char *argv[])
std::cerr << "Incorrect number of positional arguments" << std::endl;
return EXIT_INVALIDARGUMENTS;
}
- pluginImportUri = positionalArgs[1];
+ pluginImportUri = positionalArgs.at(1);
pluginImportVersion = positionalArgs[2];
if (positionalArgs.size() >= 4)
- pluginImportPath = positionalArgs[3];
+ pluginImportPath = positionalArgs.at(3);
} else if (action == Path) {
if (positionalArgs.size() != 2 && positionalArgs.size() != 3) {
std::cerr << "Incorrect number of positional arguments" << std::endl;
return EXIT_INVALIDARGUMENTS;
}
- pluginImportPath = QDir::fromNativeSeparators(positionalArgs[1]);
+ pluginImportPath = QDir::fromNativeSeparators(positionalArgs.at(1));
if (positionalArgs.size() == 3)
- pluginImportVersion = positionalArgs[2];
+ pluginImportVersion = positionalArgs.at(2);
} else if (action == Builtins) {
if (positionalArgs.size() != 1) {
std::cerr << "Incorrect number of positional arguments" << std::endl;
@@ -1124,7 +1131,7 @@ int main(int argc, char *argv[])
QStringList mergeDependencies;
QString mergeComponents;
if (!mergeFile.isEmpty()) {
- QStringList merge = readQmlTypes(mergeFile);
+ const QStringList merge = readQmlTypes(mergeFile);
if (!merge.isEmpty()) {
QRegularExpression re("(\\w+\\.*\\w*\\s*\\d+\\.\\d+)");
QRegularExpressionMatchIterator i = re.globalMatch(merge[1]);
@@ -1166,8 +1173,9 @@ int main(int argc, char *argv[])
QQmlComponent c(&engine);
c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/loaddependencies.qml"));
c.create();
- if (!c.errors().isEmpty()) {
- foreach (const QQmlError &error, c.errors())
+ const auto errors = c.errors();
+ if (!errors.isEmpty()) {
+ for (const QQmlError &error : errors)
std::cerr << qPrintable( error.toString() ) << std::endl;
return EXIT_IMPORTERROR;
}
@@ -1196,7 +1204,7 @@ int main(int argc, char *argv[])
}
} else if (pluginImportUri == QLatin1String("QtQml")) {
bool ok = false;
- const uint major = pluginImportVersion.split('.')[0].toUInt(&ok, 10);
+ const uint major = pluginImportVersion.splitRef('.').at(0).toUInt(&ok, 10);
if (!ok) {
std::cerr << "Malformed version string \""<< qPrintable(pluginImportVersion) << "\"."
<< std::endl;
@@ -1252,8 +1260,9 @@ int main(int argc, char *argv[])
c.setData(code, QUrl::fromLocalFile(pluginImportPath + "/typelist.qml"));
c.create();
- if (!c.errors().isEmpty()) {
- foreach (const QQmlError &error, c.errors())
+ const auto errors = c.errors();
+ if (!errors.isEmpty()) {
+ for (const QQmlError &error : errors)
std::cerr << qPrintable( error.toString() ) << std::endl;
return EXIT_IMPORTERROR;
}
diff --git a/tools/qmlprofiler/qmlprofilerclient.h b/tools/qmlprofiler/qmlprofilerclient.h
index 1da04db42a..a04a412bb0 100644
--- a/tools/qmlprofiler/qmlprofilerclient.h
+++ b/tools/qmlprofiler/qmlprofilerclient.h
@@ -50,24 +50,24 @@ signals:
void error(const QString &error);
private:
- virtual void stateChanged(State state);
+ void stateChanged(State state) override;
- void traceStarted(qint64 time, int engineId);
- void traceFinished(qint64 time, int engineId);
- void rangeStart(QQmlProfilerDefinitions::RangeType type, qint64 startTime);
- void rangeData(QQmlProfilerDefinitions::RangeType type, qint64 time, const QString &data);
+ void traceStarted(qint64 time, int engineId) override;
+ void traceFinished(qint64 time, int engineId) override;
+ void rangeStart(QQmlProfilerDefinitions::RangeType type, qint64 startTime) override;
+ void rangeData(QQmlProfilerDefinitions::RangeType type, qint64 time, const QString &data) override;
void rangeLocation(QQmlProfilerDefinitions::RangeType type, qint64 time,
- const QQmlEventLocation &location);
- void rangeEnd(QQmlProfilerDefinitions::RangeType type, qint64 endTime);
- void animationFrame(qint64 time, int frameRate, int animationCount, int threadId);
+ const QQmlEventLocation &location) override;
+ void rangeEnd(QQmlProfilerDefinitions::RangeType type, qint64 endTime) override;
+ void animationFrame(qint64 time, int frameRate, int animationCount, int threadId) override;
void sceneGraphEvent(QQmlProfilerDefinitions::SceneGraphFrameType type, qint64 time,
qint64 numericData1, qint64 numericData2, qint64 numericData3,
- qint64 numericData4, qint64 numericData5);
+ qint64 numericData4, qint64 numericData5) override;
void pixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventType type, qint64 time,
- const QString &url, int numericData1, int numericData2);
- void memoryAllocation(QQmlProfilerDefinitions::MemoryType type, qint64 time, qint64 amount);
- void inputEvent(QQmlProfilerDefinitions::InputEventType type, qint64 time, int a, int b);
- void complete();
+ const QString &url, int numericData1, int numericData2) override;
+ void memoryAllocation(QQmlProfilerDefinitions::MemoryType type, qint64 time, qint64 amount) override;
+ void inputEvent(QQmlProfilerDefinitions::InputEventType type, qint64 time, int a, int b) override;
+ void complete() override;
};
#endif // QMLPROFILERCLIENT_H
diff --git a/tools/qmlprofiler/qmlprofilerdata.cpp b/tools/qmlprofiler/qmlprofilerdata.cpp
index 048c92bb93..668cb3ce2d 100644
--- a/tools/qmlprofiler/qmlprofilerdata.cpp
+++ b/tools/qmlprofiler/qmlprofilerdata.cpp
@@ -403,23 +403,23 @@ void QmlProfilerData::computeQmlTime()
int level = minimumLevel;
for (int i = 0; i < d->startInstanceList.count(); i++) {
- qint64 st = d->startInstanceList[i].startTime;
+ qint64 st = d->startInstanceList.at(i).startTime;
- if (d->startInstanceList[i].data->rangeType == QQmlProfilerDefinitions::Painting) {
+ if (d->startInstanceList.at(i).data->rangeType == QQmlProfilerDefinitions::Painting) {
continue;
}
// general level
- if (endtimesPerLevel[level] > st) {
+ if (endtimesPerLevel.value(level) > st) {
level++;
} else {
while (level > minimumLevel && endtimesPerLevel[level-1] <= st)
level--;
}
- endtimesPerLevel[level] = st + d->startInstanceList[i].duration;
+ endtimesPerLevel[level] = st + d->startInstanceList.at(i).duration;
if (level == minimumLevel) {
- d->qmlMeasuredTime += d->startInstanceList[i].duration;
+ d->qmlMeasuredTime += d->startInstanceList.at(i).duration;
}
}
}
diff --git a/tools/qmltime/qmltime.cpp b/tools/qmltime/qmltime.cpp
index 4c282dd8f4..b337ccac5c 100644
--- a/tools/qmltime/qmltime.cpp
+++ b/tools/qmltime/qmltime.cpp
@@ -222,7 +222,7 @@ int main(int argc, char ** argv)
QByteArray its(argv[ii]);
bool ok = false;
iterations = its.toUInt(&ok);
- if (!ok)
+ if (!ok || iterations == 0)
usage(argv[0]);
} else {
usage(argv[0]);
diff --git a/tools/tools.pro b/tools/tools.pro
index d16888e539..bf39a649df 100644
--- a/tools/tools.pro
+++ b/tools/tools.pro
@@ -2,7 +2,8 @@ TEMPLATE = subdirs
QT_FOR_CONFIG += qml-private
SUBDIRS += \
qmlmin \
- qmlimportscanner
+ qmlimportscanner \
+ qmlcachegen
!android|android_app {
SUBDIRS += \
@@ -31,7 +32,7 @@ SUBDIRS += \
qml.depends = qmlimportscanner
qmleasing.depends = qmlimportscanner
-# qmlmin, qmlimportscanner & qmlbundle are build tools.
+# qmlmin, qmlimportscanner & qmlcachegen are build tools.
# qmlscene is needed by the autotests.
# qmltestrunner may be useful for manual testing.
# qmlplugindump cannot be a build tool, because it loads target plugins.