Commit Graph

493 Commits

Author SHA1 Message Date
Liang Qi 3e3c6717ba Merge remote-tracking branch 'origin/5.9' into 5.10
Change-Id: I3b250545e334f50dcef1a75acdef51820d34079a
2018-02-07 11:03:01 +01:00
Erik Verbruggen 8501993e52 QML: Collapse all NaNs into one single (encoded) NaN
The idea of NaN boxing is to use one single NaN as a "true" NaN, and all
others as a boxed value. So when encoding some NaN, be sure to use that
one "true" NaN. Otherwise, it will be interpreted as an encoded value.

Task-number: QTBUG-65998
Change-Id: Ia6e4641be180f3d626c40a57b473f181358e04db
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-02-05 09:15:25 +00:00
Ulf Hermann 65606ea155 Remove double indirection between QJSEngine and QV4::ExecutionEngine
As QJSEngine's handle() method is internal, we can redefine it to return
a pointer to an ExecutionEngine. That makes many things easier.

Change-Id: Ie3df99e0bad5f00ad4fe73182896cd135fa82994
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-02-02 09:37:40 +00:00
Liang Qi 38fa20ea75 Merge remote-tracking branch 'origin/5.9' into 5.10
Change-Id: Idde38761897f078cd9957f01d34a9751217e4c53
2018-01-31 10:05:15 +01:00
Simon Hausmann 406ef45aaa Fix exposure of -1 as enum value in QML exposed C++ singletons
When a C++ singleton has an enum with the value -1, we would expose that
value correctly when taking the accelerated property access code path in
the optimizer, but when going through the slower QQmlTypeWrapper we
would return undefined. This turned out to be a silly logic error that
assumed that -1 is not a valid value for an enum and instead indicates
an enum value not present.

[ChangeLog][Qml] Fix -1 as enum value in QML exposed C++ singletons
showing up as undefined.

Task-number: QTBUG-66067
Change-Id: Ib66dad7a4b59822b2c40ad6bd9af4b72469582e9
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Michael Brasser <michael.brasser@live.com>
2018-01-31 08:07:41 +00:00
Lars Knoll 4588e73020 Arguments passed to functions should shadow the function name
Task-number: QTBUG-65140
Change-Id: I6c6b24f081b31ef0f16fec9b2024485acec11c2d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-01-12 07:04:44 +00:00
Ulf Hermann c0250b67e4 Avoid warning about comparing QVariant::Bool to QMetatype::Bool
Change-Id: Icc2ca6c5cdb259e415abd7a6b43a0e8b0b142af5
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-01-08 12:32:26 +00:00
Friedemann Kleint e8b8de4460 Raise minimum supported MSVC version to 2015
Remove code for older versions and streamline #ifdefs.

Remove the helpers macros Q_STATIC_ASSERT_FOR_SANE_COMPILERS
and V4_ASSERT_IS_TRIVIAL.

Task-number: QTBUG-40658
Task-number: QTBUG-51673
Change-Id: Ifa4fab653b10ce7858739adef08364cddc6507cf
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-01-06 17:14:09 +00:00
Erik Verbruggen 904179cb68 Fix iterator assignment for for-in loops
When iterating over an object using an for-in loop, the value for the
next iteration should be assigned in the body of the loop. This means
that after the loop, the value of the last iteration is still assigned
to that variable, not null (which marks the end of the iterable values).

Task-number: QTBUG-65104
Change-Id: Icbddbc67723719005120587bcdc63dcdfa52b67f
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-12-13 08:58:52 +00:00
Simon Hausmann d373d5e7d7 Merge remote-tracking branch 'origin/wip/new-backend' into dev
Conflicts:
	src/qml/compiler/qv4isel_moth.cpp
	src/qml/compiler/qv4jsir_p.h
	src/qml/jsruntime/qv4engine_p.h
	src/qml/jsruntime/qv4vme_moth.cpp
	tests/auto/qml/qml.pro

Change-Id: Ia7b6ec24c7fcbcbb1786d9e798d2df294020ae37
2017-11-21 12:29:40 +01:00
Kevin Funk 9880acb424 Replace remaining Q_NULLPTR with nullptr
Change-Id: I28a32af7f1c306a3002d47025a842475f848c1a4
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-11-17 10:05:23 +00:00
Edward Welbourne 948e24cb6d V4 Date.ParseString(): fix UTC-ness of date-only formats
ECMA-262 stipulates that date-only formats should be treated as UTC,
while date-times are handled as standard time, if no time zone is
explicitly given.  Tidied up the parser a bit in the process and
documented what the spec says.  Fixed some broken test-cases.

Handling of date-times without zone as local time is a correction
since edition 5.1 of ECMA-262 (which said to handle it as UTC):
http://www.ecma-international.org/ecma-262/7.0/index.html#sec-corrections-and-clarifications-in-ecmascript-2015-with-possible-compatibility-impact
We were previously handling both dates and date-times as local time,
violating the old spec for both and the revised spec for dates.

Task-number: QTBUG-56787
Change-Id: I557789d855b910ca6a859fca396af1a0205c9417
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-11-14 17:18:21 +00:00
Lars Knoll e72306a6f2 Further cleanup JSCallData
Avoid allocations on the JS stack if possible

Change-Id: I344cd6dceb6264314f9d22c94db22b22d1d24d14
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-11-07 09:00:48 +00:00
Lars Knoll bc5ff76e5a Simplify JSCallData construction
Change-Id: Ic53532edae9a209aa7125af6f00a9d993d74f1a3
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-11-07 09:00:44 +00:00
Lars Knoll a59d9a7eac Get rid of JSCallData::call()
Change-Id: I6b99e9a7102b3dcb6a7699f54b6456eba6248699
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-11-07 09:00:37 +00:00
Lars Knoll c6c79644dc Rename JSCall to JSCallData
As, this is going to change in a simple stack based structure
to keep pointers to the data to pass to calls.

Change-Id: Ia9aa3f81ee3eeba36affd16aac7b2fe97d59aea9
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-11-07 09:00:26 +00:00
Lars Knoll bc2427ce32 Never truncate the JS stack
Truncating it can lead to all sorts of crazy side effects, especially
as we'd be extending it again when leaving the function. When that happens
already freed JS objects could suddenly become visible to the GC again.

Fix this by copying the CallData to set up a new stack frame. This is not yet
ideal, as we're copying too much data, but that can be fixed separately.

Change-Id: I02a39ce479475bae326f9eddfe6654fbcf8e6d35
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-10-23 06:27:33 +00:00
Lars Knoll aceb0d0cd2 Merge remote-tracking branch 'origin/dev' into HEAD
Conflicts:
	src/qml/compiler/qv4codegen.cpp
	src/qml/compiler/qv4compileddata.cpp
	src/qml/compiler/qv4compileddata_p.h
	src/qml/compiler/qv4isel_moth_p.h
	src/qml/compiler/qv4ssa.cpp
	src/qml/jit/qv4assembler_p.h
	src/qml/jit/qv4isel_masm_p.h
	src/qml/jit/qv4regalloc.cpp
	src/qml/jsruntime/qv4engine.cpp
	src/qml/jsruntime/qv4qmlcontext_p.h
	src/qml/jsruntime/qv4regexp.cpp
	src/qml/jsruntime/qv4regexp_p.h
	src/qml/jsruntime/qv4regexpobject.cpp
	src/qml/jsruntime/qv4runtime.cpp
	src/qml/jsruntime/qv4vme_moth.cpp
	src/qml/qml/v8/qqmlbuiltinfunctions.cpp
	tests/auto/qml/qml.pro
	tests/auto/qml/qmlplugindump/tst_qmlplugindump.cpp
	tools/qmlcachegen/qmlcachegen.cpp

Change-Id: I1577e195c736f3414089036b957a01cb91a3ca23
2017-10-22 12:26:28 +02:00
Erik Verbruggen 7372758263 Fix delayed loading of arguments in binary expressions
Consider the following functions:
    function f(x) {
        return x + (++x)
    }

    function g(x) {
        return x + x
    }

In f() it is not correct to delay the load of x on the left-hand side of
the + operator, while in g() it is. The reason is that calculating the
right-hand side of the + operator in f() will change the value of x.

So, if an argument is written to in an expression in a statement, it
cannot be delay-loaded. The same is true for member/field accesses,
because the accessors can be overwritten and do anything.

Change-Id: I5bed4b0d03919edc1c94a82127e2dd705fc1d9b1
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-09-20 12:46:19 +00:00
Lars Knoll 55a671ea73 Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts:
	src/qml/compiler/qv4compileddata.cpp
	src/qml/compiler/qv4compileddata_p.h
	src/qml/jsruntime/qv4engine.cpp
	src/qml/jsruntime/qv4qmlcontext.cpp
	src/qml/jsruntime/qv4qmlcontext_p.h
	src/qml/jsruntime/qv4regexpobject.cpp
	src/qml/jsruntime/qv4regexpobject_p.h
	src/qml/types/qqmllistmodel.cpp
	src/quick/items/qquickanimatedimage_p.h
	src/quick/scenegraph/qsgrenderloop.cpp
	tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp

Change-Id: If20ef62b2c98bdf656cb2f5d27b1897b754d3dc0
2017-09-20 14:27:41 +02:00
Simon Hausmann 131243b3c8 Stabilize the threadSignal() test
We've seen the case in the CI where we delete the worker thread object
before it has had a chance (resulting in a crash). This patch attempts
to stabilize this by waiting for the thread to terminate properly.

In addition QSignalSpy's connection to the done(QString) signal is
forced to be direct, which means the spy's internal list is accessed
from the gui thread (via QCOMPARE) at the same time as the thread may be
emitting the signal and calling the signalspy's slot (metacall), which
helgrind complains about (rightly so).

I don't see any purpose in connecting to the signal, so let's remove
that code. The test continues to cover the threading code in
QQmlData::signalEmitted, once as the thread is triggered via C++ and
once via QML (doIt invocation).

Change-Id: I5e8a4ae65e2d0890a26491d25c73de1ba33a6668
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2017-09-06 09:31:27 +00:00
Lars Knoll 74c8fe8675 Always set the correct FunctionObject when calling JS functions
Renamed ScopedCallData to JSCall, enforced passing a JS
FunctionObject to it, and added call() and callAsConstructor()
methods to it.

Change-Id: I30db65c9765c2896b5909fe2105c0934c6dad861
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-09-02 07:12:17 +00:00
Lars Knoll aa8f956e8d Move ScopedCallData and ScopedStackFrame into a separate file
Change-Id: I9ae42aa7a811aa93fe0950725e9d253a0c5e8dba
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-09-01 12:31:19 +00:00
Lars Knoll 6df6f642ea Move CallContext construction into a interpreter instruction
This will allow us to further cut down on function call
overhead. To make this work, introduce a proper distinction
between EvalCode and GlobalCode and use the correct
compilation mode in all places.

Change-Id: I070621142159b7416026347c9239200c5ed7a56b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-09-01 12:30:49 +00:00
Lars Knoll c0f961cd6b Change function signatures for call/construct back
Change those back again to return a value. This will be required
to avoid creation of Scope objects between JS function calls.

Change-Id: I05cb5cf8fd0c13dcefa60d213ccd5983fab57ea3
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2017-08-04 07:08:19 +00:00
Liang Qi 55490690f8 Merge remote-tracking branch 'origin/5.9' into dev
Change-Id: I61ab3d0bd8cc02f640c60c037226eace09ec09ba
2017-06-07 12:06:15 +02:00
Robin Burchell 6a02fb09af QQmlIRBuilder: Only query type name cache for type names
The behavior here was always incorrect: type names must start with
an uppercase letter, so querying the type name cache with a lowercase
string is wrong.

However, this was turned into a larger problem by making more extensive use of
QQmlTypeNameCache in e74a1d0b34, as it
contained a lot of new types (including composite types, which
previously were only in the cache if they were singletons).

Task-number: QTBUG-60547
Change-Id: I40be2d535e99d3e1af250d995d7149ecbe2965d7
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-05-19 08:42:53 +00:00
Robin Burchell d27047bd90 QmlContextWrapper -> QQmlContextWrapper
That poor Q looked so lonely.

Change-Id: I29a0aa0574fefa5be8ffaa9857e03500c914c830
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-05-04 09:31:42 +00:00
Lars Knoll c3e1e6390e Merge remote-tracking branch 'origin/5.9' into dev
Change-Id: I71275a2076c3d32ee2896571be882067320a2e9e
2017-05-02 08:40:48 +02:00
Simon Hausmann c9728926a8 Merge remote-tracking branch 'origin/5.8' into 5.9
Conflicts:
	src/qtqmlglobal.h
	src/qtqmlglobal_p.h
	src/jsruntime/qv4global_p.h
	src/qml/compiler/compiler.pri
	src/qml/compiler/qv4ssa.cpp
	src/qmldevtools/qtqmldevtoolsglobal_p.h
	tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

Change-Id: I55c5d015b2cb1053b83b9c61caaf004fb49ee486
2017-04-27 15:16:00 +02:00
Erik Verbruggen 8d0d1b11e3 V4: Fix issues with very small loops
Loops consisting of just a single basic block (e.g. a do-while loop with
no nested loops or if statements) have a back-edge to themselves. There
were 2 problems:
- loop detection would create LoopInfo for any loop header referred to
  by blocks inside the loop (and a 1 block loop doesn't have body
  blocks), nor would it mark the loop header as such
- when splitting critical edges, the newly inserted block would not be
  marked as part of the loop

This is a problem specifically for 1 block loops: the block ends with
a CJUMP, so the back-edge is a critical edge. So the new block inserted
by edge splitting wouldn't be marked as belonging to the loop.

The end result was that the life-time intervals for temporaries that
are defined before the loop, but that are used inside the loop, and not
after the loop, would have their life-time ended before the loop ends
(instead of spanning the whole loop, *including* the back-edge). This
in turns could lead to the stack/register allocator re-using the storage
for that temporary, resulting in strange things happening.

Task-number: QTBUG-59012
Change-Id: Ic946c73913711272efea2151cb85350412ca2fde
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-04-18 07:53:48 +00:00
Robin Burchell 34ff6c40c1 qml: Override the new Object::instanceOf hook to allow QML type checking
[ChangeLog][QtQml] The instanceof keyword in JavaScript has been
extended to work on QML types and instances. This means that you are now
able to use it to verify that a var is indeed the type you expect (e.g.
someVar instanceof Rectangle).

Note that one of the added tests revealed a slight shortcoming in the
QML type system (QTBUG-58477). For now, we should keep consistency and
work to address the problem universally in the future.

Change-Id: I7d9bf9b64cfd037908de1ae51b01065eacb95abe
Task-number: QTBUG-24799
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-03-15 22:11:31 +00:00
Liang Qi afec9016d0 Merge remote-tracking branch 'origin/5.9' into dev
Change-Id: I92b13a9c1727644d63e125c1e6f1fdac72720ad7
2017-02-28 13:04:17 +01:00
Ulf Hermann 74dc6ef8d5 Directly load already known metaproperties in QV4QObjectWrapper
A method and a property can have the same name in a QObject. This is
not directly expressible in a JS object, but when iterating the
properties of a wrapped QObject we should not look them up by name as
we might find the wrong one this way. However, as we already know what
we are looking for, there is no need for any further searching anyway.

Task-number: QTBUG-58887
Change-Id: I68574008c7a078baab9b343d550cc27956b0d5a9
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-02-15 13:51:26 +00:00
Lars Knoll 802bebd566 Merge remote-tracking branch 'origin/5.9' into dev
Change-Id: I372850330c1d92edc5b07596759f0db3a59082a8
2017-02-14 08:21:39 +01:00
Robin Burchell bdb20c74eb As crazy as it is, redefinition of global properties should work
Furthermore, some of the ES6 tests do check for this behavior (this
fixes at least 9 of the tests in /test/built-ins/Object/, maybe more
elsewhere).

createMutableBinding used hasProperty(String*) to determine whether or
not it needs to actually define a property, which checks the prototype
chain.

This would be fine, but when writing values to properties, we used find() on
the InternalClass (which is equivilent to Object::hasOwnProperty), which
would fail as the property doesn't "really" exist on the object, it's somewhere
in the prototype chain. Thus, we'd incorrectly throw an exception in strict mode.

I see no regressions in ES5 from this change.

Change-Id: I3b097306f220a891955ec11eea860264746bc0ee
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-02-09 14:53:18 +00:00
Robin Burchell bc5cdd23f1 parser: Add "let" keyword (& T_LET)
We also tie this up to the existing skeletal "const" support so that they
are also checked for duplicate declarations.

While we do that, change from using a boolean to an enum so we make the scope of
a declaration a little more easily comprehensible.

Change-Id: I6a6e08aed4e16a53690d6f6bafb55632807b6024
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-02-03 15:10:25 +00:00
Robin Burchell 5f807a6276 Codegen: Disallow duplicate declarations of const properties
Spec 13.3.1.1 (Static Semantics: Early Errors) says:

    It is a Syntax Error if the BoundNames of BindingList contains any
    duplicate entries.

Only let/const are supposed to be treated in this way, so we ensure that
one of them has been marked read-only (since we don't support "let"
yet).

There's still no runtime check on assigning to a constant-declared variable.

[ChangeLog][QtQml] "const" variable declarations now throw a SyntaxError if
multiple attempts to declare the same variable name are found. Note that
"const" is still not fully spec-compliant (i.e. reassignment at runtime is
not disallowed).

Task-number: QTBUG-58493
Change-Id: I31fd5f2bf3e79d48734e8ecb714c4e7f47e31d2a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-02-03 15:10:18 +00:00
Robin Burchell b7090f1334 Fix a crash in setInternalClass
Revealed by the ES6 testsuite, ./test/built-ins/Object/freeze/15.2.3.9-2-1.js
and probably others. We cannot unconditionally dereference memberData,
it may not always exist.

ES6 tests test/built-ins/Object/freeze before:
    === Summary ===
     - Ran 92 tests
     - Passed 66 tests (71.7%)
     - Failed 26 tests (28.3%)

after:
    === Summary ===
     - Ran 92 tests
     - Passed 90 tests (97.8%)
     - Failed 2 tests (2.2%)

Change-Id: I22a6c9ca081394ba15edfde09f73769eb3ce47b3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-02-03 12:48:40 +00:00
Robin Burchell b63393c7aa Codegen: Disallow const declaration without an initializer expression
This seems to match up with the spec behavior. 13.3.1.1 (Static Semantics:
Early Errors) says:

    It is a Syntax Error if Initializer is not present and IsConstantDeclaration
    of the LexicalDeclaration containing this production is true.

In addition, we also allow "const" to be used in JS mode too. We don't
yet fully support the semantics, but as it's there, why not let it work.

[ChangeLog][QtQml] "const" variable declarations are now available in JS
as well as QML mode.

[ChangeLog][QtQml] "const" variable declarations now require an
initializer, bringing them closer to the required spec behavior.

Task-number: QTBUG-58493
Change-Id: Ife5d5979b3e7a5d7340bf04f43605f847ee25ee2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-02-02 15:49:13 +00:00
Liang Qi 0076c44d39 Merge remote-tracking branch 'origin/5.8' into dev
Conflicts:
	src/quick/util/qquickutilmodule.cpp
	tools/qmllint/main.cpp

Change-Id: Ic2283f88c293ca7fc776de3e83eb4c7812309d8a
2017-01-26 00:34:21 +01:00
Robin Burchell b3629b4c27 tst_qqmlecmascript: Add some simple coverage for instanceof
Since I'm working on this, it is nice to have some simple verification
that things are working. I don't expect this to provide full coverage,
but it should at least make sure that the basics are ok, and nicely
provides a place to put further tests if it ever somehow breaks.

Change-Id: If91154dee836cc514515bde122e48b271de22676
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-01-20 13:28:54 +00:00
Simon Hausmann 89c6bee139 Fix support for QJSValue as C++ signal parameter type, part 2
After commit 0e3380f9c6 we wouldn't crash
anymore, if QJSValue::UndefinedValue was provided as value for a
QJSValue C++ signal parameter. However that was not a complete fix for
the regression of commit aa869cbb06, as
other primitive values stored in QJSValue as QVariant were not
converted, so for example QJSValue(42). So let's fix this once and for
all by using QJSValuePrivate::valueForData, that handles all types of
QJSValuePrivate encodings.

Task-number: QTBUG-58133
Change-Id: Ib7c0461b18df6260ccd4bce729ae2348281eb7f3
Reviewed-by: Arnaud Vrac <avrac@freebox.fr>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-01-18 05:51:05 +00:00
Simon Hausmann 0e3380f9c6 Fix crash when C++ QJSValue parameterized signal interacts with JS
When converting the parameters of a C++ signal to JS values to provide
to a signal handler written in JS, the conversion of a QJSValue to a
QV4::Value* may yield a null pointer in case of a default constructed
QJSValue for example. This is a regression from commit
aa869cbb06 and we must check for this.

Task-number: QTBUG-58133
Change-Id: I528b606b2851dfb3072e54902bd8843d31571a55
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-01-13 12:41:33 +00:00
Lars Knoll f2a9579375 Inline the qmlScope and urlScope methods
They are only a couple of lines and used only in one place.

Change-Id: Iee9139e78d5d7fd385cae39d6dd5fad7e5d461b5
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-12-04 08:31:56 +00:00
Lars Knoll 8a6383775a Start cleaning up the QmlContextWrapper
The class should get merged with the QV4::QmlContext class.
Simplify the cleanup by moving both classes into a common
file.

Change-Id: I0074da79701d5f41eb51681b70fcde85bfd45fc1
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-12-04 08:31:49 +00:00
Liang Qi 102fa9b6db Merge remote-tracking branch 'origin/5.7' into 5.8
Conflicts:
	examples/quick/quickwidgets/quickwidget/main.cpp
	src/qml/jsruntime/qv4jsonobject.cpp
	src/qml/jsruntime/qv4qobjectwrapper.cpp
	src/qml/jsruntime/qv4qobjectwrapper_p.h
	src/qml/qml/qqmlengine.cpp
	src/qml/qml/qqmlpropertycache.cpp
	src/qml/qml/qqmlpropertycache_p.h
	src/quick/items/qquickanimatedsprite.cpp
	src/quick/items/qquickitem.cpp
	src/quick/items/qquickitem.h
	src/quick/items/qquickitem_p.h
	src/quick/items/qquickview_p.h
	src/quick/scenegraph/qsgcontext.cpp
	src/quick/scenegraph/qsgdefaultrendercontext.cpp

Change-Id: I172c6fbff97208f21ed4c8b6db3d1747a889f22b
2016-10-10 16:01:48 +02:00
Erik Verbruggen 57c9d6969a QML: Also check for correct destroy() chaining
Check that the destroy() method of Heap::Base was called when a Managed
object needs destruction. This checks if a call to the parent's
destroy() method was accidentally omitted.

Change-Id: Id025ecd6d4744bf3eab23503fbe317ed2a461138
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-10-06 14:46:21 +00:00
Erik Verbruggen 3b14e2ffdd QML: Make Heap::Object and all subclasses trivial
GCC6 might dead-store-eliminate out our secret write to Base::mmdata,
because it expects all memory content to be "undefined" before
constructor calls. Clang might take the same approach if the constructor
of Heap::Object is removed.

By making these structs trivial, it also makes them memcpy-able.

Change-Id: I055b2ad28311b997fbe059849ebda4d5894eaa9b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-10-06 11:44:08 +00:00
Erik Verbruggen 64afa01c32 QML: Introduce destroy() on Base subclasses
This removes the destructors of subclasses of Base, making them nearly
trivial.

Change-Id: Ia6f7d467e87899b5ad37b8709a8f633a51689d59
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-10-05 13:15:18 +00:00
Liang Qi 0d2fad48fc Merge remote-tracking branch 'origin/5.6' into 5.7
Change-Id: I48764527fa1ab6d8d59c24552394459b1cdc58ee
2016-10-04 12:27:15 +02:00
Robin Burchell 0d8a283177 qv4jsonobject: Make use of QVariant::toString in stringification
This covers a whole host of missing cases, notably QUrl stored in a QV4::Value.

Task-number: QTBUG-50592
Change-Id: I8afd772046c7bfbbcf916a7e90a57be5257b9df8
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-09-30 09:24:05 +00:00
Simon Hausmann 12d8004874 Fix binding dependencies when used in together with functions
When a function called from a binding would access a scope or context
property, we would end up registering those dependencies as permanent
dependencies in the expression and set m_permanentDependenciesRegistered
to true. Then after the binding evaluation itself, we would not end up
registering the real binding's permanent dependencies.

Change-Id: I3b6c1c181aa064d535362c736b5b2bbc4f576ba9
Done-with: Erik
Task-number: QTBUG-54394
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2016-08-30 13:48:19 +00:00
Liang Qi 7e609f6d10 Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
	src/qml/compiler/qqmltypecompiler.cpp
	src/qml/compiler/qv4isel_moth.cpp
	src/qml/compiler/qv4ssa_p.h
	src/qml/qml/qqmlobjectcreator.cpp

Change-Id: I8bb7fe773d657f908f20ee5e72c2b9bd643f6260
2016-08-17 10:57:38 +02:00
Liang Qi d54d28981c Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
	src/qml/compiler/qv4isel_moth.cpp
	src/qml/compiler/qv4ssa_p.h
	tests/benchmarks/qml/qqmlimage/qqmlimage.pro
	tests/benchmarks/qml/qqmlimage/tst_qqmlimage.cpp

Change-Id: Iad11ce7fdf0c6d200fdebc16a94081bd8069a87a
2016-08-13 00:41:58 +02:00
Liang Qi 5517c63c2e Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
	src/qml/qml/qqmlcomponent.cpp
	tests/auto/quick/scenegraph/tst_scenegraph.cpp

Change-Id: Ibc811b95a57f175ca53337db7bbd1f575a745937
2016-08-09 10:28:48 +02:00
Christian Kandeler 3e5152be41 QJSValue: Adapt to introduction of QMetaType::Nullptr
[ChangeLog][QtQml][Important Behavior Changes] A JS null value converted
to a QVariant now has type QMetaType::Nullptr rather than
QMetaType::VoidStar.

Change-Id: I91a64e444ada0f1884fe807f9973348ba1a878ff
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-08-08 12:45:38 +00:00
Simon Hausmann 68bfc9332c Fix crash with Component.onDestruction
A call to a handler of Component.onDestruction may end up causing WeakValues
such as QQmlData::jsWrapper to be set again, even though they've been set to
undefined in an earlier iteration of the loop that walks through the weak
references. That in turn may result in invalid object references to objects
that are scheduled for destruction by the collector.

So after calling all destroy handlers for QObjects, reset all of the weak
values again.

Task-number: QTBUG-54939
Change-Id: I00ebabb76274e296fb1bd90d8d3e21dbbb920b57
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-08-05 18:55:39 +00:00
Liang Qi 45f79dc7e5 Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
	src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp
	src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.h

Change-Id: I1e6a9424e7f87d9e4ac1ea387ec70e151106f1c7
2016-08-05 09:02:17 +02:00
Ulf Hermann 97b2fc9d64 Relax negativeYear EcmaScript test
EcmaScript doesn't in fact require the date to be represented in
english. Thus, only test for the year number to be contained in the
date string.

Change-Id: I5b89c14a833b317f259f4cd2855b3f24310a7d72
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-08-03 21:17:48 +00:00
Edward Welbourne 74f0d15e08 Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
	src/quick/items/qquickshadereffect.cpp
5.7 had a bug-fix in code dev has replaced wholesale.

	src/quick/items/qquickwindow.cpp
	src/quick/items/qquickwindow_p.h
One side changed a method's signature; the other side renamed a method
declared adjacent to it and changed some code using it, moving some
from the public class to its private partner.

	tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp
One side added a blank line before a comment the other re-wrote.
Kept the re-write, killed the stray blank.

	.qmake.conf
Ignore 5.7's change to MODULE_VERSION.

	src/qml/compiler/qqmltypecompiler.cpp
	src/qml/compiler/qqmlpropertyvalidator.cpp
5.7 changed code in the former that dev moved to the latter.
Reflect 5.7's changes there, adapted to dev's form.

	src/qml/qml/qqmlobjectcreator.cpp
One side added new QVariant types; the other changed how it handled
each type of QVariant (without git seeing any conflict); adapted the
new stanzas to work the same as the transformed ones.

	tests/manual/v4/test262
dev had a broken sha1 for it; so used 5.7's 9741ac4655808ac46c127e3d1d8ba3d27ada618e

Change-Id: I1fbe2255b97d6ef405cdd1d0cea7fab8dc351d6f
2016-08-02 18:34:30 +02:00
Liang Qi 6839f03051 Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
	tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
	tests/auto/quick/qquickitem/tst_qquickitem.cpp

Change-Id: If261f8eea84dfa5944bb55de999d1f70aba528fd
2016-08-01 13:14:04 +02:00
Erik Verbruggen 06ed1ad17a JS: Check for errors before using sub-expression results
Specifically: don't de-reference a result and assume that it's not-null.

Task-number: QTBUG-54687
Change-Id: If07d3250a95a7815ab7a3262b88e0227965ef8e7
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-07-20 10:36:58 +00:00
Edward Welbourne f23ad9d576 Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
	examples/quick/demos/photoviewer/deployment.pri
One side made it redundant; the other removed part of it; remove it all !

	src/quick/scenegraph/util/qsgatlastexture.cpp
One side changed a preprocessor condition, the other a code condition,
on adjacent lines; keep both changes.

	tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp
One side changed a condition, the other the content of its block; keep both.

Change-Id: Idb8937f92a7edb28212449dfe0c5cfdb8e6de986
2016-07-15 21:08:50 +02:00
Lars Knoll 91ed06b767 Fix logic bug when deleting properties of JS objects
The code used the size of the internal class in an inconsistent
way. It should simply compute and work with the old internal
class size, as that reflects the old object layout.

[ChangeLog][QtQml] Fix assertion when deleting properties of JS objects

Task-number: QTBUG-54589
Change-Id: Ie3db70437e780215d08a1a96491db75f8b859754
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-07-14 11:29:34 +00:00
Simon Hausmann 8d139e5e42 Minor optimization
I've seen people write

    property SomeItem myProperty: null

This is an unnecessary initialization that ends up creating a binding
expression. Generally there's handling missing for null and undefined, but in
this very case we should just optimize away the initializer expression,
because QObject style properties are initialized to null by default, as opposed
to undefined.

Change-Id: I7af4cd45461304753c93cef3926f6e92d3b6c95d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-27 07:39:47 +00:00
Erik Verbruggen 702c4247d7 V4: Pass scope around as parameters inside the runtime.
The implementation of many (or all) runtime functions consist of first
creating a QV4::Scope, which saves and restores the JS stack pointer.
It also prevents tail-calls because of that restoring behavior. In many
cases it suffices to do that at the entry-point of the runtime.

The return value of a JS function call is now also stored in the scope.
Previously, all return values were stored in a ScopedValue, got loaded
on return, and immediately stored in another ScopedValue in the caller.
This resulted in a lot of stores, where now there is only one store
needed, and no extra ScopedValue for every function.

Change-Id: I13d80fc0ce72c5702ef1536d41d12f710c5914fa
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-06-22 11:07:05 +00:00
Liang Qi ae745746a6 Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
	src/qml/jsapi/qjsengine.cpp
	src/qml/qml/qqmlengine_p.h
	src/quick/items/qquickanchors.cpp
	src/quick/items/qquickanimatedimage_p_p.h
	src/quick/items/qquickitem_p.h
	tests/auto/qml/qqmlecmascript/testtypes.h
	tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
	tests/benchmarks/qml/creation/tst_creation.cpp

Change-Id: I65861e32f16e8a04c7090a90231627e1ebf6ba6f
2016-05-13 08:28:27 +02:00
Liang Qi 9b6d55ddf3 Merge remote-tracking branch 'origin/5.6' into 5.7
Change-Id: I3c6a93917cb46868cdb9dd50566b90c70f67102e
2016-05-06 09:17:24 +02:00
Kevin Ottens 373c621bf4 Add QVector support to JS sequences
Change-Id: I731355aa1754721236f3711a65af4f96781cebc0
Task-number: QTBUG-51467
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-05-03 08:00:30 +00:00
Simon Hausmann 1650377af7 Fix crash when trying to call a property of the scope or context object
For calls on properties of the scope or context object the thisObject parameter
in the callData is a reference to the QmlContext, not a real object - therefore
the toString conversion fails.

Task-number: QTBUG-52340
Change-Id: I08d01cc5c05920c2fac46ddd40fa41e630bcade3
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-01 09:08:52 +00:00
Liang Qi da374438be Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
	src/quick/items/qquickimagebase.cpp
	src/imports/layouts/plugin.cpp

Change-Id: I5f48474df4034a1347ec74795c85d369a55b6b21
2016-04-27 08:47:35 +02:00
Michael Bruning 0b7c11e7c2 Also match QJSValue conversion types in MatchScore.
This had the effect that overloaded methods were always mapped to the
wrong slot.

[ChangeLog][QtQml][Important Behavior Changes] When matching the method signature
of a invokable method to the slot in the metaobject, the matching function now
assigns the best match to a QJSValue if the parameter actually is a QJSValue. This
corrects the previous behavior, where QJSValue and int were given the same match score
even though QJSValue would have been the best match.

Task-number: QTBUG-51746
Change-Id: I906e7b006ee5af92ea760ed1625e5047aef123bf
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-04-20 13:38:31 +00:00
Simon Hausmann 8ca22ca7eb Fix invocations of methods taking a QByteArray
Since commit 3b7e2a69f7 when calling a slot that
takes a QByteArray with a parameter that is not a QByteArray, we would end up
passing an empty QByteArray. This is a regression as previously we supported
the conversion code path, i.e. when passing a QString it would be converted to
utf-8, through QVariant's conversion code path. This code path needs to be
re-activated by removing this "shortcut". The shortcut is not necessary as the
execution engine's toVariant() function also knows how to apply the conversion.

Change-Id: I0600d195c94fa4e1e0b7ab807f045f0da42f595b
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
2016-04-12 11:52:49 +00:00
Lars Knoll 3057b8c7e6 Convert the remaining runtime methods to new calling convention
Change-Id: I88ad3ca430508617d527715aa85ae8474ab7c621
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-04-11 12:27:39 +00:00
Liang Qi 1e421097f0 Merge remote-tracking branch 'origin/5.6' into dev
Change-Id: Iec1b2de53c275996364c4bab0123ccb3e6e9895e
2016-01-29 13:01:22 +01:00
Lars Knoll e9a6c1d4e3 Don't check for revisions when assigning to grouped properties
This leads to wrong behavior in some cases, where we reject
valid revisions, and there is probably no case, where this could
lead to a conflict for the user of the API.

Change-Id: I1614332cf4c07c6a227551612331dd69b2ae71f3
Task-number: QTBUG-40043
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-01-27 12:15:53 +00:00
Jani Heikkinen 38ec3bd755 Updated license headers
From Qt 5.7 -> tools & applications are lisenced under GPL v3 with some
exceptions, see
http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/

Updated license headers to use new GPL-EXCEPT header instead of LGPL21 one
(in those files which will be under GPL 3 with exceptions)

Change-Id: I04760a0801837cfc516d1c7c02d4f503f6bb70b6
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-01-20 11:46:25 +00:00
Liang Qi 7063fefe4b Merge remote-tracking branch 'origin/5.6' into dev
Change-Id: I11ea57222ba5aa683b7bfd7735fbc1d2cf86e875
2015-10-14 15:48:12 +02:00
Ulf Hermann 35da68a15c Provide a threaded TestHTTPServer
This allows us to do blocking operations that interact with the test
server in the main thread. The threaded server is used in tests that
don't explicitly require asynchronous operation.

Change-Id: Ibcb28e79a1114cb9cfb812e86aae0a1af71c569e
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-10-14 08:03:38 +00:00
Friedemann Kleint 0f5a721761 Tests: Fix single-character string literals.
Use character literals where applicable.

Change-Id: Ib0e618752fbc762a73a0a91c43efab61ef2c9687
Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-10-13 14:24:16 +00:00
Liang Qi f9ef039ad9 Merge remote-tracking branch 'origin/5.6' into dev
Conflicts:
	src/qml/debugger/qqmldebug.cpp

Change-Id: I93de5a81b18cdece475870cf7cfba1b9baef2304
2015-09-25 20:56:51 +02:00
Lars Knoll f01bfcf8ed Cleanups to property allocation in the VMEMO
There's no need for a separate propertiesAllocated bool,
we can keep that state in the WeakValue itself.

Change-Id: Ife0f517bee9bc5830680eec68983767379a3c2cf
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-25 18:53:17 +00:00
Ron Hashimoto c47dacde0b V4: Fix SparseArray::deleteNode
SparseArray::deleteNode should modify size_left only if
the deleted node had a right child

Change-Id: I0f3504a5c6568dbd9e392bf83eaf3f9780eb2b84
Task-number: QTBUG-46022
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-25 08:39:46 +00:00
Friedemann Kleint 06f11da5e1 Tests: Remove QT_DISABLE_DEPRECATED_BEFORE=0 for simple cases.
Fix usage of API that is marked deprecated.

Change-Id: Ia887437f99b9ce207891ca19bc49294acb7d629d
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
2015-09-02 04:19:22 +00:00
Lars Knoll 88cc9b2334 Cleanup qmlcontextwrapper usage in XHR
Get rid of the static getContext overload and
simplify the signature of the dispatchCallback
method in XHR.

Get rid of the m_me object, and instead store a
pointer to the thisObject and the context data
directly.

Turn all internal errors into assertions.

Change-Id: I5427b2009c64f54b67cce1c130eace47201624bd
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-08-20 20:01:29 +00:00
Lars Knoll 7fccfc4663 Fix test case
After the latest changes to the VMEMO, JS declared properties
will not be available after the engine is deleted.

Change-Id: Ifc6034bd0dff18d26863ca9bcf7a19e1c7d68ff6
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-08-18 20:27:17 +00:00
Lars Knoll 6cd0001054 Get rid of special handling of var properties
These can be handled in a simple way now by using a special
propertyType value indicating that we have a var property.

Also remove the additional write calls in the different
readProperty implementations. If the stored data doesn't
match, we can simply return the default value directly.

Change-Id: I3823a971df24bd78f0acdc4c0042776277b3c55f
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-08-18 20:27:11 +00:00
Friedemann Kleint 0ea3c24cfe tests/qml: Replace Q[TRY]_VERIFY(a == b) by Q[TRY]_COMPARE(a, b).
- Replace Q[TRY]_VERIFY(pointer == 0) by Q[TRY]_VERIFY(!pointer).
- Replace Q[TRY]_VERIFY(smartPointer == 0)  by
          Q[TRY]_VERIFY(smartPointer.isNull()).
- Replace Q[TRY]_VERIFY(a == b) by  Q[TRY]_COMPARE(a, b) and
  add casts where necessary. The values will then be logged
  should a test fail.

Change-Id: I8cc97fd9b48fc789a849e9527c292c4e05accd97
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
2015-07-29 09:44:39 +00:00
Friedemann Kleint 0959281be2 Tests: Replace Q[TRY]_VERIFY(v == true|false) by QVERIFY(v)|QVERIFY(!v).
Preparing the replacement of Q[TRY]_VERIFY(a == b) by
Q[TRY]_COMPARE(a, b) for non-boolean types.

Change-Id: I8a4e44a2b4e20a9c8b811799e3932c8ce1a2cbbb
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
2015-07-27 12:32:49 +00:00
Simon Hausmann e2447f9f5f Merge remote-tracking branch 'origin/5.4' into 5.5
Conflicts:
	.qmake.conf
	tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp

Change-Id: I715b8a78b74cbe0dcaf599367fd6e08af4858e11
2015-04-27 14:40:00 +02:00
Simon Hausmann 79d56651ed Prospective fix for flakey "network" related QML tests
Replace hard-coded server ports with dynamically allocated ports.

Change-Id: Iab8f9a88343a9f2c49af3cd700c954c13c3bf121
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
2015-04-25 12:02:55 +00:00
Lars Knoll d1c5f134bd Don't evaluate the expression in switch() multiple times
The old code would evaluate the expression in the switch
statement once for every case label. This is not only slower
than it should be, but can also lead to unexpected results in
case the expression doesn't always evaluate to the same value
or has side effects.

Task-number: QTBUG-41630
Change-Id: Id93baca7e3aa09ce884967ef6524d4c4f055bcd6
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-03-11 08:23:10 +00:00
Jani Heikkinen c5796292ad Update copyright headers
Qt copyrights are now in The Qt Company, so we could update the source
code headers accordingly. In the same go we should also fix the links to
point to qt.io.

Change-Id: I61120571787870c0ed17066afb31779b1e6e30e9
Reviewed-by: Iikka Eklund <iikka.eklund@theqtcompany.com>
2015-02-12 10:28:11 +00:00
Lars Knoll 3dbf4e9a69 Cleanups
Remove duplicated methods. Remove some mostly unused methods,
and simplify some others.

Change-Id: I605b249e54417bb32c3dfc8e22f2c8b6b684a1e1
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-23 12:30:35 +01:00
Lars Knoll 13cf87fa93 Remove all remaining usages of ValueRef
Change-Id: Icd76d3d03fac2e57530e55f8ec15b97109dcdcbc
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-23 08:07:35 +01:00
Lars Knoll 002a5d4303 Get rid of most uses of ValueRef
Instead pass a const Value & into the functions

With our new inheritance structure, we can get rid of ValueRef
and instead simply pass a pointer to a Value again. Pointers to
Values are safe to use again now, as they are now guaranteed to
be in a place where the GC knows about them.

Change-Id: I44c606fde764db3993b8128fd6fb781d3a298e53
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-23 08:07:32 +01:00
Simon Hausmann 291aea1463 Merge remote-tracking branch 'origin/5.4' into dev
Conflicts:
	.qmake.conf
	src/qml/jsruntime/qv4context_p.h
	src/qml/jsruntime/qv4debugging.cpp
	src/qml/jsruntime/qv4engine.cpp
	src/qml/jsruntime/qv4functionobject_p.h
	src/qml/jsruntime/qv4qobjectwrapper.cpp
	src/quick/scenegraph/shaders/visualization.frag
	tests/auto/qml/qjsengine/tst_qjsengine.cpp

Change-Id: I492e8546c278f80a300a2129e9a29d861e144a30
2015-01-16 12:46:52 +01:00
Lars Knoll 39f1e0d66d Make sure we always have an engine when assigning to a Persistent
This prepares things for a rewrite of the internals of Persistent.

Change-Id: Ib93ec5911984d1bfce87ffdc3f86bc75f6ecafe9
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-13 22:42:04 +01:00
Lars Knoll ca977a0c8f Cleanup variant conversion code
Make public methods proper members of the ExecutionEngine, and
move private methods into the .cpp file only.

Change-Id: I3ca49e39bb1c4e559a2c63346e6ae6cfa446147d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-09 10:27:57 +01:00
Lars Knoll 7041eb353a Move the variant conversion methods from qv8engine to qv4::ExecutionEngine
Change-Id: Ibd529ae5cc3ba06f46152e9daa9119a4e7a2561c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-09 10:27:55 +01:00
Simon Hausmann 9d7b27f5bf Clean up JS .import/.pragma directive scanning
There's a scanner in QQmlJS::Lexer::scanDirectives that can parse those, so
let's get rid of extra parser that operates on a string. Instead this way we
can do the scanning all in one shot, avoid detaching a copy of the source code
string and (most importantly) bring the parser closer to the copy in Qt
Creator, which uses the directives approach to extract imports and pragma.

Change-Id: Iff6eb8d91a45d8a70f383f953115692be48259de
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@theqtcompany.com>
2015-01-08 22:08:19 +01:00
Lars Knoll bede2a3ac7 Remove qv8engine usage in the contextwrapper
Change-Id: Iaf807add5d971e96cac57e38e13385e901f9c930
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-08 12:34:36 +01:00
Lars Knoll 3e054a80dd Get rid of QV8Engine::toString
Change-Id: Ib51fa09ae251c1b7b8878ecdf920016f8fcc0067
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-08 12:34:32 +01:00
Albert Astals Cid 5cfe7d2074 Parse dates as Qt::RFC2822Date too
[ChangeLog][QtQml] Fix JavaScript Date parsing to correctly accept RC2822 dates.

Task-number: QTBUG-38011
Change-Id: Ic7d3f5b8c624d6780d4c3595fd2efe22c427ffd3
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2015-01-08 10:03:02 +01:00
Oleg Shparber 2fadffdc46 Use QV4::ScopedFunctionObject typedef instead of actual type
Change-Id: I6b4effaa5bef992b4ae9402eea7fe655bc7b18f0
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-02 21:29:41 +01:00
Lars Knoll 2056538fea Remove v8engine dependency in toVariant conversions
Change-Id: I0f2f77c9cc268a0c5ca3ffe0cd66fc98bb1964b3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-02 21:10:43 +01:00
Lars Knoll 05bf96997c Return Heap::ExecutionContext for globalContext()
Change-Id: Ide7c81735be4662ff45bf268cfe750ff1f784453
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-19 18:52:07 +01:00
Mitch Curtis 450883d16b Read and write QObject pointer properties in QML without registration.
Previously, accessing QObject pointer properties from QML would require
these types to be registered with qRegisterMetaType(), but this
shouldn't be necessary if we're able to read/write the property, because
the moc generates code that calls qRegisterMetaType in the static meta-call
implementation. So when resolving a property in the property cache and we
can't resolve, fall back to placing the static meta-call to register the
type, similar to what QMetaType::userType() does.

Change-Id: Ic8b00ed93a1e5e42cf7aaaf1c355e89557485c59
Reviewed-by: Christopher Adams <chris.adams@jollamobile.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
2014-12-13 01:36:30 +01:00
Ulf Hermann 68c2c56a1a Revert "Properly handle negative years when printing JS Dates to strings."
This reverts commit f06daaf3d8.

The only things actually specified by the ECMAScript standard on dates
are:

1. Reparsing a date output from any of the to*String() functions has to
result in the same date representation.

2. The ISO 8601 standard has to be followed for the ISO format.

Currently we clearly don't follow rule 1. Date.parse(d.toString()) will
not yield the same as d.valueOf() for negative dates.

The ISO 8601 standard clearly has a year 0 while common human language
has not. All non ISO date representations are considered
"implementation-dependent" in the ECMAScript standard. We can thus
define the relation between our representations and the ISO standard any
way we like. If we try to match up the dates so that the negative years
look equal in each representation we cannot properly interact with QDate
for dates in the year 0 as that doesn't exist in QDate. We can, however,
choose not to make the dates look equal. That means a date with a
negative year will be "one off" when represented in ISO 8601. "333 BC"
in human language is "-332" in ISO 8601. Our internal representation is
aligned to ISO 8601 and the to*String() methods may output something
else. That means we can easily set the year in ISO 8601 sense from the
Date constructor as well as from setYear() and setFullYear().

This, of course, is somewhat unintuitive and also differs from most
other JavaScript implementations (which don't have to interoperate with
QDate). However, it is still correct.

Change-Id: I5fc26b709a486cb520a075918b184a80bec56c9b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-12 12:56:57 +01:00
Lars Knoll ddfe9defa8 Encapsulate accesses to the root context
Change-Id: I668cef1363a5c1a5c5b9a7e138f3bd0338712eea
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-11 08:40:41 +01:00
Lars Knoll b943d80dd9 Remove the executioncontext in a few more places where it's not needed
Change-Id: I4c92c7bc9d94d8265e306f45d863fdc080a5e2a6
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-21 16:36:24 +01:00
Thiago Macieira 205336ebc8 Change test data from 6.7 to 6.5
6.5 is an exact binary number (4 + 2 + 0.5), so all conversions to
string will result in "6.5", regardless of how many digits of precision
are used.

This is done in advance of changing QVariant to add more digits of
precision, which would cause toString() of 6.7 to result in
"6.7000000000000002".

Change-Id: I19ea4c5bb02b99f0655c0b9bc9dc09f06ec654e5
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-18 09:34:01 +01:00
Lars Knoll 3dc7b5ddf6 Cleanup exception catching code
Change-Id: I85afd5758f72e19c280dc196601ee145f0c25f01
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-15 13:16:28 +01:00
Lars Knoll 6f6b350976 Cleanup header file dependencies
Change-Id: Ibb4658576a98b53de2eac2474ce4d5b9eb83b6ae
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-04 20:17:23 +01:00
Ulf Hermann f06daaf3d8 Properly handle negative years when printing JS Dates to strings.
JavaScript knows a year 0. That is correctly translated into QDateTime
terms when creating a Date object, but it's not correctly translated
back when converting the JavaScript date to a string.

Task-number: QTBUG-29491
Change-Id: I46b200a144434187656d08e87f422f97523acd0e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-10-24 17:03:51 +02:00
Simon Hausmann 3dbe05f6bf Fix mapping of JS objects/arrays to C++
[ChangeLog][QtQml][Important Behavior Changes] When a JavaScript object/array
is passed to C++ through a QVariant, the engine no longer immediately converts
the object recursively into a QVariantMap or QVariantList but instead stores
a QJSValue in the QVariant. This prevents a loss of data when the JS object
contains non-primitive types such as function objects for example. Code that
expects the variant type to be exactly QVariant::Map or QVariant::List may
need to be adapted. Registered conversion functions however ensure that code
that merely calls toMap() or toList() continues to work.

Task-number: QTBUG-40431
Change-Id: I1dbc1d5f8e78ad28bb62db3681b9a0b34557e7f5
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-09-17 08:13:11 +02:00
Lars Knoll 046cce32d9 Fix setUTCXxx methods in Date
The methods where converting doing a localtime->UTC
conversion even though the input was already in UTC.

Task-number: QTBUG-38448
Change-Id: I4409275fade0dd2a677af2293edc87445f853879
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-09-11 09:57:00 +02:00
Lars Knoll 91d6a63ab3 Fix roundtrip conversion between JS var and QVariant
Always convert null to a QVariant(VoidStar) as documented in
QJSValue. Make sure the reverse conversion will lead back to
a null JS value.

Adjusted two test cases that expected an invalid QVariant when
setting the property to null, and added test cases for the
correct conversion.

Task-number: QTBUG-40880
Change-Id: I6eb01f0067f2c89779c53fd2cd0a1193047ed2cc
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-09-11 09:56:48 +02:00
Simon Hausmann 38fe461e2c Merge remote-tracking branch 'origin/5.3' into 5.4
Conflicts:
	.qmake.conf
	src/qml/jsruntime/qv4arraydata.cpp
	src/quick/scenegraph/util/qsgatlastexture.cpp

Change-Id: Ic4c96066d5c37dcf0d5446baed590ea005d445ce
2014-09-08 13:10:21 +02:00
Erik Verbruggen f7c3035fa1 QML: parse .js files as JavaScript, not QML.
When importing a JS library into a QML file with the "import" keyword,
that JS file was parsed in QML mode, disallowing QML keywords like "as".

Task-number: QTBUG-40143
Change-Id: Ie98adceb27544732c2e96657d41170db36bff288
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-09-05 09:43:16 +02:00
Jani Heikkinen e7ceacda70 Update license headers and add new licenses
- Renamed LICENSE.LGPL to LICENSE.LGPLv21
- Added LICENSE.LGPLv3 & LICENSE.GPLv2
- Removed LICENSE.GPL

Change-Id: I84a565e2e0caa3b76bf291a7d188a57a4b00e1b0
Reviewed-by: Jani Heikkinen <jani.heikkinen@digia.com>
2014-08-25 11:28:46 +02:00
Simon Hausmann 61f72d32b4 Merge remote-tracking branch 'origin/5.3' into 5.4
Conflicts:
	src/qml/jsruntime/qv4include.cpp
	src/quick/items/qquickrendercontrol.cpp
	src/quick/items/qquickrendercontrol_p.h
	src/quickwidgets/qquickwidget.cpp

Change-Id: Ib2dc0051a38cd283a37a7665eb4a76f6f7ec8b15
2014-08-12 10:04:33 +02:00
Erik Verbruggen ead3da17e7 V4: change string flattening to be iterative and use a worklist.
And not recursive, because that might blow out of stack space.

Task-number: QTBUG-39520
Change-Id: Id961d4af03a543d3efa173f976626cf2dae4f483
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-08-08 10:45:28 +02:00
Simon Hausmann 2121de6d87 Fix Qt.include with cached compilation units and resources
Similar to the worker scripts we also need to do a lookup for cached
scripts here. Added also a test to ensure that Qt.include works correctly
from Qt resources.

Change-Id: Idb67af3da4b0cc91edbd3d2746d074fd68ed8bf0
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-08-06 09:56:49 +02:00
Frederik Gladhorn 8b88e37bf7 Merge remote-tracking branch 'origin/5.3' into dev
Change-Id: Id95f7b01de36bccecbb7b73acc041654a1fe2ebe
2014-07-29 12:49:37 +02:00
Simon Hausmann 14bc8dc3f3 Fix interaction of garbage collector with JS objects during QML type instantiation
It may happen that during the lengthy process of instantiating a tree of
objects for QML, the garbage collector runs.

For objects created by QML we support different ownership models, for example
in QtQuick visual parents keep their visual children alive, despite perhaps a
lack of QObject parentship. That ownership becomes active once the QML
autoparent function has assigned the correct visual parent, which happens after
object instantiation (after QQmlObjectCreator).

Similarly when a composite type is created, its QObject parent is only set
after all properties have been set. The root QObject is kept alive through a
special boolean, but if the sub-objects aren't children yet, their JS wrapper
might get deleted. For composite types with var properties, that also means
their var properties get deleted, such as the model property of TableView.qml
in the bug report.

In the future we want to support creating QWidget hierarchies with QML, which
also for layouts may rely on a delayed parent assignment for layouts.

To accommodate all this, this patch introduces an array on the JS stack that
keeps track of all JS wrappers for all QObjects created. This array is alive
during object tree creation. Afterwards, the different ownership models take
over, for example the auto parent function assigning a visual parent.

This patch also fixes an off-by-one in the total object count calculation
for composite types, where when instantiating a composite type as a sub-object
we counted the sub composite's object count but forgot the object itself.

Task-number: QTBUG-38835
Task-number: QTBUG-39966
Change-Id: I6104b2434510642081e0c54793ed296adeca7481
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-07-26 04:37:48 +02:00
Paul Lemire fcb40ff6d7 qmlRegisterCustomExtendedType, qmlRegisterExtendedUncreatableType
There are cases in Qt3D where we'd like to be able to register uncreatable
extended types. The main use case is having an abstract class that has an
extension class so as to have a clean separation between the C++
and QML API. Implementations of the abstract can then be easily registered
to QML and rely on the extension class for QML specific properties.

The other feature we'll need in the near future is the ability to create
extended QML types that use a custom parser.

Two new type registration method were added to qqml.h to fulfill those
needs. Unit tests for those are present in qqmlecmascript and qqmllanguage.

Change-Id: I15b2cd791ffd36b537305af1873491c079d4094e
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-25 16:29:36 +02:00
Lars Knoll 2e529aa4c0 Remove unused method
Change-Id: I3830de8c4f01cc7340ab37673024ceea93585a9e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:15 +02:00
Oleg Shparber 435fb27335 Allow integer values to be assigned QList<qreal> properties
Before this patch it was not possible to assign an integer value to
QList<qreal> property, while it worked for non-list properties.

Change-Id: Iab00288f7d78f4f76056ab4291700d7f51626de4
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-06-25 17:31:47 +02:00
Frederik Gladhorn 66646dd8c3 Merge remote-tracking branch 'origin/stable' into dev
Conflicts:
	.qmake.conf
	src/plugins/accessible/quick/quick.pro
	src/quick/items/qquickpincharea.cpp
	src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
	src/quick/scenegraph/qsgthreadedrenderloop.cpp

Manually adjusted for TestHTTPServer constructor change:
    tests/auto/quick/qquickimage/tst_qquickimage.cpp

Change-Id: I5e58a7c08ea92d6fc5e3bce98571c54f7b2ce08f
2014-05-10 11:53:47 +02:00
Albert Astals Cid fc45fd6983 Don't crash on Runtime::getQmlImportedScripts
Task-number: QTBUG-37303

Change-Id: I083ca0cc3223fe0dbf1c768ad43a0d4927579867
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-24 11:40:10 +01:00
Robin Burchell aa578c4e29 TestHTTPServer: Make listening an explicit operation that reports failure.
Use this to print the error message when listening fails, and switch to always
stack allocating TestHTTPServer instances for easier cleanup.

Change-Id: I63b2bd38963b66611dc08a5c322615d91a91e675
Reviewed-by: John Brooks <john.brooks@dereferenced.net>
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Reviewed-by: Lorn Potter <lorn.potter@jollamobile.com>
2014-03-21 00:09:29 +01:00
Simon Hausmann ecd4a9ba23 Namespace cleanup
Move the QML IR types into the QmlIR namespace and clean them up.

Change-Id: I2125449e5a519034e23670651efa620f405730b4
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-03-17 20:41:34 +01:00
Simon Hausmann acf1298e21 Fix crash with lazy binding initialization and compile time calculated dependencies
During lazy binding initialization we may execute bindings where we calculated
dependencies to the context object at compile time. In order to register those
dependencies, the contet object needs to be set in the QQmlContextData.

This patch makes sure to set it before setting up the bindings.

Change-Id: Iacd360140cd9c389487bda82f6a7e6cc3a44c154
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-03-17 15:45:45 +01:00
Simon Hausmann f844c588fc Don't crash when a signal/slot connection outlives the engine
In the test case in the bug, the signal was emitted from the QApplication
destructor (somewhere from the qpa plugin when the platform windows were
destroyed)

Task-number: QTBUG-37351
Change-Id: Ieec59e12be10bab1428743b80eecdf22ef9d8bf6
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-03-12 15:10:04 +01:00
Lars Knoll 8ed6c62dc7 Cleanup our runtime methods
Move all our runtime methods into the QV4::Runtime
struct and give them nicer names without underscores.
Sort them logically and remove a few unused methods.

Change-Id: Ib69b71764ff194d0ba211aac581f9a99734d8180
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-11 08:37:01 +01:00
Simon Hausmann dc9bf8ecdc Fix crash when accessing var properties in objects with invalid context
We've had two indepedent reports of people running into the issue of
their QML code accidentally trying to access var properties in item view
delegates that were on the path of destruction, i.e. their QQmlContext was
already marked as invalid. Any such access would cause a failing assertion
in debug builds or a crash in release builds.

This patch removes the dependency to QQmlContextData for accessing the
var properties and adds a test-case that covers this use-case.

This is a regression from Qt 5.1.x.

Task-number: QTBUG-37227
Change-Id: Icf55d5fa8c15e45974e78086e9e11b2401ea9bad
Reviewed-by: Albert Astals Cid <albert.astals@canonical.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-03-04 15:22:58 +01:00
Sergio Ahumada d286f5bf75 Prefer to use normalised signal/slot signatures
Change-Id: I9856c110399c4b6b1ea6aba2d92392cecff04656
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-03 10:08:49 +01:00
Simon Hausmann 7c9497a6d4 Merge remote-tracking branch 'origin/stable' into dev
Conflicts:
	src/qml/compiler/qv4ssa.cpp
	src/qml/jsruntime/qv4arrayobject.cpp
	src/qml/jsruntime/qv4context.cpp

Change-Id: Ied5b23bec4dc14abe51127c507aed668f855c1e1
2014-02-11 12:00:31 +01:00
Simon Hausmann 5dc7649f5a [Regression] Fix lazy binding evaluation
Commit 04774bb14c long time ago introduced the
concept of fixed order binding initialization with lazy evaluation, where a bit
is reserved for each binding that indicates whether it's been initialized the
first time or not. When reading a property on a QObject, we'd check if the
corresponding binding for the property has been initialized or not and flush
(i.e. execute) the binding if necessary.

As part of the V4/V8 clean-up, commit 1eb4120094
removed the StoreV8Binding instruction, which made the call for setting the
this-binding-is-not-evaluated-yet bit. Nowadays we only use StoreBinding, for
which this optimization was never implemented (and not needed really). Now that
we have a unified JS code path, we need to set the pending binding bit and also
make sure that we call flushPendingBinding for any JS side property access
(accelerated or not).

Also flushPendingBindingImpl had two bugs:

   * In an attempt of trying to find the binding to flush, it could happen that
     we'd try to flush a previously destroyed binding (m_mePtr is null), so
     the b variable would remain the first binding in the object and we'd flush
     the wrong one (instead of none). Added a missing check to verify that the
     property index matches.
   * Also resetting the mePtr must be done through clear(), to ensure that the
     pointer in bindValues in the VME is also cleared, to avoid re-enabling the
     same binding again in complete();

Task-number: QTBUG-36441

Change-Id: Icdb0c8fb036051fd5d6c4d33b10cd0c0ed9a9d5c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-02-06 13:53:31 +01:00
Simon Hausmann 37019a96db [new compiler] Fix propagation of imported scripts for anonymous components
We must take the imported scripts from the creation context. Fixes various
errors in Qt Quick Controls.

Change-Id: I336d8ffa0537cefd4eeac15f98bbf1b0a5c784af
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-02-05 19:48:26 +01:00
Gabriel de Dietrich ae19cdacbe alloca() is declared in stdlib.h on BSD systems
... except on Darwin.

Bonus change: Updated auto-tests trying to include 'alloca.h'.

This is a follow up on 24c43a5748.

Change-Id: I299de00bf0dca7842470b158282daea221a10f2d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-02 14:29:07 +01:00
Friedemann Kleint c6d90f47b9 Fix MSVC-warnings about double to float truncation in QML-tests.
Change-Id: Ie58585ca3555f0f7808b59221a00763cc702863a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-24 17:28:34 +01:00
Oswald Buddenhagen e2ea0a83cc fix whitespace
remove trailing spaces and expand tabs

Change-Id: Ieacb9d096b612c45d1a64700044c114d1f7522bc
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-22 21:01:53 +01:00
Lars Knoll 459c9a2a88 Rework array handling for JS objects
Split up ArrayData into two classes, one for regular
arrays, one for sparse arrays and cleanly separate
the two cases. Only create array data on demand.

Change-Id: I9ca8d0b53592174f213ba0f20caf93e77dba690a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-09 07:47:06 +01:00
Frederik Gladhorn 24e2b39e7a Merge remote-tracking branch 'origin/stable' into dev
Change-Id: If9a205bea219b9aca95d78b1e556ca9bbff58dd0
2014-01-06 16:12:41 +01:00
Simon Hausmann eb3087e4b0 Fix lookups of enums in singletons
This is a regression against 5.2.0 (which didn't have this bug), due to
optimizations introduced in the stable branch after the release. The code path
for optimizing access to the members of C++ based singletons through the
regular meta-object properties would end up excluding access to enums when the
lookup happens at run-time. The run-time getter for the singleton itself would
return a wrapped QObject instead of a QQmlTypeWrapper, and only the latter
includes enums.

As QML based singletons (composite singletons) cannot declare enums, we can
continue to do fast lookups on these, but otherwise have to fall back to the
slower code path.

Task-number: QTBUG-35721

Change-Id: Icc66bdaf3572622cdb718f82b706e3204afa0167
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-01-02 23:36:58 +01:00
Simon Hausmann 70004585f8 Change C++ parameter type used for var parameters in QML declared signals
"signal someSignal(var foo)" mapped to foo being of type QVariant.
Unfortunately that is a "lossy" type and it cannot represent all JavaScript
values, including for example function closures (as reported in the JIRA bug).
Instead we should use QJSValue. It is an important behavioural change because
it affects the presumably rare case of somebody declaring a signal in QML with
such a parameter and connect to it from C++ (or trying to emit it) - in that
situation the code needs to be changed.

Task-number: QTBUG-35171
Change-Id: I4fb4a18b407e4ea6c28a3a297fc6f76edb76d734
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-12-24 10:32:35 +01:00
Simon Hausmann 7a344ef2b7 Fix dependency calculation for context and scope properties
We were incorrectly calculating writing to a context or scope property as a
dependency for an expression. We don't know whether a property is being written
only or also being read from at lookup time, but we can make that decision in
the isel then when generating the move instructions.

So initially context and scope properties end up in a candidate set first
and get promoted to real dependencies when they're being used in reading
moves.

Task-number: QTBUG-35210
Change-Id: Ia67057abafc2d611e1e6605327b4965ebe91cbed
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-12-05 22:05:21 +01:00
Lars Knoll 9306c05dd1 Encapsulate the current context and fix it's usage
Encapsulate accesses to the current context, and rework
the way we push and pop this context from the context
stack.

Largely a cleanup, but simplifies the code in the long term

Change-Id: I409e378490d0ab027be6a4c01a4031b2ea35c51d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-12-04 09:45:50 +01:00
Simon Hausmann 55b5e30901 Fix JavaScript signal connect on alias without other handlers
The changed handlers for aliases are connected lazily in the engine.
QQmlPropertyPrivate::flushSignal is responsible for that and called in other
places, for example when installing a onSomeAliasPropertyChanged handler.
However we were missing a call to flushSignal when doing
onSomeAliasPropertyChanged.connect(...), i.e. using the JavaScript connect API.

Task-number: QTBUG-30493
Change-Id: Ia3f008626fd7af3f2cfbdd30d13fb83158bed4d5
Reviewed-by: Albert Astals Cid <albert.astals@canonical.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-29 08:19:11 +01:00
Liang Qi 6d4d98bc59 V4: fix Array.indexOf() for QStringList
Autotest is included.

Task-number: QTBUG-33542
Change-Id: I46c3a81006019c6613a3d35aa018217f85a15d0b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Liang Qi <liang.qi@digia.com>
2013-11-20 10:06:12 +01:00
Erik Verbruggen 48c45418cc V4: remove failing assert and fix code.
Assert failed for cases where the node’s ancestor with lowest
semi-dominator number was not the same as the parent. The test case
exemplifies this.

Task-number: QTBUG-34792
Change-Id: Ie6847b22a27211801bff7479bfcbfaf329c6005a
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
2013-11-19 13:00:37 +01:00
Simon Hausmann cac9989643 Fix failing assertion when trying to assign to an id referenced QML object
References to id addressed QML objects are member expressions, which are unlike
other member expressions by not being lvalues. Handle this correctly.

Task-Number: QTBUG-34890

Change-Id: Ied6230edbc561128ad36bf0d1a1918185204deec
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-19 07:57:45 +01:00
Albert Astals Cid 96ee686016 Make comparison of singletons and qobjects work
Otherwise you can end up with some weird situation in which you have
two objects, you print them and then you print the comparison and get
a Foo(0x858480) b Foo(0x858480) a == b false

Task-number: QTBUG-34651

Change-Id: Id2444d919f039be085eb5ed9112345db691540a5
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-18 15:53:57 +01:00
Lars Knoll 95d35ab188 Fix interaction between head room and appending in arrays
We reserve space on both ends of the JS array for appending
and prepending. Make sure they interact well with each other
and don't cause any memory corruption.

Task-number: QTBUG-34853
Change-Id: I184280178690e3cb12ab9b199a8436b32383af38
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-18 15:53:57 +01:00
Lars Knoll 3d145175fd Don't assert in QQuickItem::update
The method can actually be called from QML, so we can not
have an assert in that method. Instead simply return if the
item has no contents

Task-number: QTBUG-34060
Change-Id: Ib28ffa5c6c63fbec956abe25020010ed73a9cfa9
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
2013-11-18 14:43:13 +01:00
Lars Knoll 965878e88a Limit the amount of memory we allocate on the stack
Setup limits for both the C and the JS stack, and check
them before entering functions. If we run out of space,
throw a RangeError exception.

Be careful and recheck the stack bounds when things go
outside. This catches the case where the engine got
moved to another thread changing the stack boundaries.

Windows currently uses an unsafe fallback implementation,
this needs to be fixed later on.

Task-number: QTBUG-34568

Change-Id: I22fbcbec57b28f9cc8a49e12f1cc6e53e4f07888
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
2013-11-18 11:05:25 +01:00
Lars Knoll 0dc17ae4d8 Fix === operator for value types
Fix === comparison for urls and other QML value types.

Task-number: QTBUG-33546

Change-Id: I4a7066e6bbc7de7c599fe2c7b2fdfb75e0ff5196
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-15 13:07:52 +01:00
Lars Knoll d8fe3dfde9 Don't crash when trying to assign to null.prop
Fixes a regression introduced during the exception handling
refactoring.

Task-number: QTBUG-34544

Change-Id: Ib751274d759030db3e5d3b1380b30dc07ec85f83
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-15 13:07:11 +01:00
Albert Astals Cid 1df8a42e5b Allow passing qmlRegisterSingletonType QObjects to C++ as QObject*
At the moment you can pass them as their FinalType* or
as one of their ParentType* but not as QObject* which
does not make much sense to me

Task-number: QTBUG-34617
Task-number: QTBUG-30730

Change-Id: Id5cfb7bbb123456ef43f44f33b450f8966a7641a
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-14 08:03:55 +01:00
Erik Verbruggen 2e8dfb5d5c V4 IR: scan arguments when entering function scope in QML.
When doing IR generation for a function declaration in a QML object,
call through the helper methods to check for forbidden names, and most
importantly, also checks if the function has parameters. If the latter
is the case, they need to be added as a member for the current scope
in order to get IR generation correct.

Task-number: QTBUG-34493

Change-Id: I0ade15ee19e1b1ac8ee2f2d3fa186d1551800199
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-12 14:40:22 +01:00
Erik Verbruggen ff306b7829 V4: fix loop block marking for initializer blocks.
Any new blocks generated as part of the initializer were incorrectly
marked as belonging to a loop. For example, if a LocalForStatement
would contain a ternary expression, the generated then and else blocks
would be marked. This would confuse the block scheduling, because all
blocks are postponed unil the condition block (“group start”) is
scheduled.

Task-number: QTBUG-33754

Change-Id: I45919ebeac356f015bb91fe0210472b3df0b56d8
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-12 14:40:22 +01:00
Simon Hausmann 3a61da32e4 Ensure the this object is set correctly to the scope object in binding expressions
This is a regression from 5.1

Change-Id: I61ad372a02d937c195dad74bd9fcb8fd4410d97a
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-05 23:47:27 +01:00
Simon Hausmann 4ffa7d3f65 Fix rounding behavior of Qml when assigning doubles to integer properties
The engine used to round, but that is inconsistent with ECMAScript's way of
converting doubles to integers by truncation.

With this patch we can also enable the propagation of integer type information
into the IR, but we have to be careful not to utilize it when writing
properties.

Change-Id: I04af4879ba5131349eca2eeff2b27f4598f5267b
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-05 21:13:00 +01:00
Simon Hausmann bbc36ebbc3 Speed up lookups of imported scripts
The QQmlContextData stores the JS objects of imported scripts in a
QList<PersistentValue>. Instead of indexing into that list, this patch changes
ctxt->importedScripts to be a JavaScript array, that in the IR we can index via
subscript.

Change-Id: Ie2c35fb5294a20a0b7084bb51d19671a27195fec
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-31 21:49:21 +01:00
Simon Hausmann 34c85bb56c Initial support for resolving meta-property access for the scope and context objects at QML compile time
This avoids having to do a string lookup for ids and in the import cache at
run-time, before we can do a string hash lookup in the property cache. Instead
we resolve final properties in the context and scope object at compile time and
look them up at run-time using their index instead. The dependencies to these
properties are also tracked separately and recorded in the compiled data.

This is merely the initial patch. There's a lot left to do, such as having
specialized getter and setters for specific property types. Setters are missing
altogether right now and will fall back to name lookup.

Change-Id: If3cb4e7c9454ef4850a615f0935b311c9395b165
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-31 10:50:38 +01:00
Lars Knoll e0284ab41f Properly propagate parse errors
Replace all try/catch statements used when parsing
with checks for engine->hasException.

Change-Id: I4493cb600d5a3eb095c2003bb88bd031403e47c9
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 10:38:55 +01:00
J-P Nurmi 4f1ed0948b Avoid crash when a QML signal is connected to a non-void slot
Don't pass a QVariant pointer for the return value when we're
not interested in it and the return type might not even be a
QVariant (that would be only true for QML methods).

Task-number: QTBUG-32801
Change-Id: I8f14e40d8f94caef7e3d086b776735f0484dbf0e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-22 13:51:33 +02:00
Lars Knoll ad7f91c59a Turn on exact garbage collection by default
Keep conservative GC as a fallback for testing
Enable all tests again that were skipped due to
GC issues.

Change-Id: I8e0fa728207bdd39a96d0acf95e27841157d8402
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-16 06:36:47 +02:00
Simon Hausmann 7d9780b630 Cleanup exception handling
The code in the Exception class operates entirely on the engine's data,
so move it into ExecutionEngine instead. This eliminates the need for
a QV4::Exception class and catches and old code that tries to still do
catch (Exception &) instead of catch (...)

Change-Id: Ie608bec6af652038aca6c9423c225a4d7eb13b39
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-03 09:24:41 +02:00
Simon Hausmann c860d1399b Change exception handling API
This patch changes the exception handling API in the engine slightly, encapsulating
any use of direct throw statements and catch blocks with concrete types. In the future
we need to be able to change the way these are implemented, in order to ensure that
the correct stack unwinding code is triggered for throw and re-throw.

This patch separates the C++ exception object thrown from the V4 exception
(that includes value, throwing context pointer) and stores the latter inside
the engine.

In order for that to compile, ExecutionEngine::StackTrace and StackFrame had to
move into the QV4 namespace directly.

In addition the syntax for catching exceptions changes from

try {
    ...
} catch (QV4::Exception &ex) {
    ex.accept(context);
    QV4::ScopedValue exceptionValue(scope, ex.value());
}

to

try {
    ...
} catch (...) {
    QV4::ScopedValue exception(scope, context->catchException());
}

Context::catchException() checks if there's a "current" exception in the engine,
and if not assumes that we caught an unrelated exception and consequently re-throws.

partiallyUnwind() is also gone and replaced with rethrowException(), in order to
encapsulate the re-throw.

Lastly, in the future nesting try/catch blocks isn't going to be possible due to
limitations in the common C++ ABI with regards to foreign exceptions.

Change-Id: Ic81c75b057a2147e3176d8e0b4d326c14278b47d
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-02 16:07:33 +02:00
Lars Knoll c1d66eec1d Cleanup API of Safe<T>
Don't have an implicit cast operator to Returned<T>
anymore, and return a T* from the operator->()

Change-Id: If4165071b986bfc84a157560d94d39c2dcfbc9e1
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-02 16:07:33 +02:00
Simon Hausmann c48d727e25 Compile imported scripts in the loader thread
This has the benefit of blocking the GUI thread less and speeding up type
creation in the GUI thread (for types that import js libraries).

This patch also brings one behavioral change: Due to the parsing at type
instantiation type, things like syntax errors for script imports would only
generate a run-time warning and the code in the QML file would just see
"undefined". Errors in the script now generate real errors at component
compilation time, meaning the errors come out earlier and as real errors.

This patch implements the separation for the VME only (to keep the size
of this patch small).

Change-Id: I82f7f3a2d3d4524ea12a7ab62abd8640aba6a47f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-30 18:21:26 +02:00
Lars Knoll e57c2c8a0a remove more uses of QV4::Value
Change-Id: I11b0b2b7626297e2c98dc77784574da4b59ba8cf
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-30 08:05:48 +02:00
Lars Knoll cf2a253f2f Move Value::fromBool, ... to a new Primitive class
This will simplify finding the remaining direct usages of
QV4::Value that need fixing.

Change-Id: I223099727436d5748027c84c53d9dfc4028e38ed
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-28 13:33:24 +02:00
Lars Knoll 6d425ebab3 Skip two tests that don't work reliably with a conservative GC
Change-Id: I5619d533b6e48c88fda063bc7cdcc62d6838bcdf
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-26 09:05:45 +02:00
Lars Knoll 74807c0725 Move more API over to use ValueRef
Change-Id: I372f1f3e3e78d45912a913f437e622e0acfc9646
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-26 09:05:32 +02:00
Lars Knoll 12fd2ccd3f Fix Persistent/WeakValue API
Don't use unprotected Values in the API anymore.

Change-Id: I8851628227fca374de24701bc8ee0908b5ae3923
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-26 09:05:16 +02:00
Erik Verbruggen 7d37b2c3fb Split off crashing test from qqmlecmascript.
Task-number: QTBUG-33658

Change-Id: I5a9f24d49ab894e3cde745cc0c1d44ef0880510f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-25 16:16:15 +02:00
Lars Knoll 21198a6761 Don't use Value::emptyValue() anymore.
emptyValue is special and reserved for usage inside the
engine to mark missing values. The main to use cases
are when converting property descriptors, and to mark
holes in array data.

Change-Id: I0ed357e65102b1041bf9a878e6e9a4ae0657523b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-22 01:06:20 +02:00
Lars Knoll bc8b25dd91 Correctly convert an invalid QDateTime to JS
Task-number: QTBUG-33539

Change-Id: I645db2e12e3b46731c0bef04e2d48abb71650974
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-18 18:48:24 +02:00
Lars Knoll 4241a55836 Fix handling of empty Values
Make things consistent between 32 and 64 bit again
Adjust test results after the changes

Almost all uses of Value::empty() will get removed
in the future, but for now this gets all our tests
to pass again.

Change-Id: I44784a43432e78febbdfe78115c9be2a3e3ece76
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-18 13:14:52 +02:00
Lars Knoll a2d115fbaf Convert most remaining return values from Value to ReturnedValue
Change-Id: If8b0c3b91be50678693868c10fefc3678008834d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-18 13:13:55 +02:00
Lars Knoll d6837e9ca3 Rename QV4::ValueScope to QV4::Scope
The class is going to be used all over the place, so let's
give it a short name :)

Change-Id: If61543cb2c885e7fbb95c8fc4d0e870097c352ed
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-18 13:13:23 +02:00
Lars Knoll 002e6105f6 Require a ValueScope for ScopedCallData as well
This brings things more in line with ScopedValue, and
also simplifies cleanup of Scoped values.

Change-Id: If5f1466b4e13c629d56c1e7c638937f61ba48f77
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-18 13:13:21 +02:00
Lars Knoll 1a2a83f80b Use a ReturnedValue for Managed::call()
Change-Id: Ief2d75e9789dd367c603d90dc0fe5316a0d055e3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-18 13:13:18 +02:00
Lars Knoll a723c7ae75 Use a ReturnedValue when converting to String or Object
Also rename Value::toQString() to Value::toQStringNoThrow(),
and add a throwing toQString() method for JS use.

Change-Id: I821b33fc61abb7d08839df965fd337685f61a545
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-12 21:52:00 +02:00
Erik Verbruggen 6aabeb55e6 Fix return type checks in test.
Same problem as 3dbc7a72c7 fixed in
another test. Same solution.

Change-Id: Ib476239e567c43e4657487c34cfc7157a1f5d33f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-11 17:12:19 +02:00
Lars Knoll 6e8e5d16e1 Move CallData onto the JS stack
Change-Id: I22e853acfd2da337344b581bb0412c5f9930c510
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-11 13:01:50 +02:00
Lars Knoll 6f472680eb change calling convention for JS function calls
This allows faster pass through of the data if we have
nested calls.

Also make sure we always reserve at least
QV4::Global::ReservedArgumentCount Values on the
stack to avoid stack corruption.

Change-Id: I42976460f1ef11a333d4adda70fba8daac66acf3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-02 17:27:36 +02:00
Simon Hausmann fc9199e4db Improve reliability of propertyVarOwnership test
In the last expect-to-collect-a-QObject test, avoid calling gc() from within
JavaScript and call it from C++ instead with zap stacking. That reduces the
probability of finding an old reference on the stack that would keep the
object alive.

Change-Id: Ia9c66dd188f31264a70ad4dbd20356d16aa7a057
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-08-27 13:55:22 +02:00
Alan Alpert fac5337abf Don't crash with deferred properties
There are cases where a qmlExecuteDeferred(o) can be postponed until the
context of o is being destroyed, at which point it's too late to create
an object in that context.

Task-number: QTBUG-33112
Change-Id: I7f981b5e34e3cb8a52c00de4742a7242d7e4df54
Reviewed-by: Christopher Adams <chris.adams@jollamobile.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-08-22 21:12:58 +02:00
Simon Hausmann 3b8457712e Fix tst_qqmlecmascript::scope() and behavioural compatibility with v8 based qml
In the V8 based QML the global object would come _before_ the "QML global object",
which is the QML context (wrapper). We had a bunch of tests that verify the exact
scope chain and with this "compatibility" fix we can re-enable them.

Also fix missing prototype setup for the console object.

Change-Id: Ib3886f2d86472eb752a6ad1a2d8d89709548c5b4
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-08-08 15:35:26 +02:00
Simon Hausmann 0c179baade Fix hasOwnProperty on various types wrapped in QML
* Change semantics of Object::query to not walk the prototype chain but let the
  caller do that where needed (__hasProperty__)
* Re-implement query in various places
* Implement method_hasOwnProperty to fall back to query() if getOwnProperty failed
* Fix missing prototype initialization in some qml wrappers, as well as missing base
  class calls to ::get()

Change-Id: Ic2a702fd5ff3be2ff3c8317a8a24f99940a9594f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-08-08 15:35:18 +02:00
Simon Hausmann f3cbd0b8aa Fix some GC related tests to work with MSVC
Using alloca instead of memset we can convince even MSVC to allocate memory on the
stack, to overwrite any previous dead V4 pointers.

Change-Id: Ic01bebfc6368e9c3ce1f6155a0f0ea206b90764c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-08-06 12:04:59 +02:00
Simon Hausmann 78fc74eac4 Disable some GC sensitive tests with MSVC
We can't get these tests to work reliably with MSVC because it depends on
how MSVC optimizes away memory stores that are "dead" stores for the compiler
but not for our conservative collector.

Change-Id: Ia5ca197573a09358c220d926deccaaf0bacc3a0b
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-08-05 21:20:11 +02:00
Simon Hausmann 6d3fb85f96 Improve reliability of GC related tests
Fixes propertyVarCircular2 in clang release builds for example.

Some of the QML/GC related tests had functions like

   function deassign()
   {
       someVariableThatWasholdingSomethingThatShouldBeCollectedNow = null;
       gc();
   }

which work fine with an exact GC like in v8, but with our conservative
collector they are not that reliable and much more vulnerable to a reference
to the object still being around somewhere. So to improve the reliability
of the test, this patch moves the gc() calls out of the JavaScript function
and back to the C++ caller side (these functions are invoked via QMetaObject::invokeMethod),
where the existing gc() helper function will call the collector and also
process posted deferred deletion events for QObjects.

Change-Id: I8c1f715d56d66bc567ea8bd1575f171460b15ac8
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
2013-07-29 13:28:48 +02:00
Simon Hausmann 60bb004ea2 Silence qqmlecmascript::propertyVarInheritance failures with clang release builds
There's no equivalent to #pragma GCC optimize ("O0") yet, so we cannot run
these test (sort of) reliably with clang.

Change-Id: Ie41d3ba7911cefacca00165941761b20579107a2
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
2013-07-26 17:31:39 +02:00