Commit Graph

436 Commits

Author SHA1 Message Date
Robin Burchell a0fcf724ef Add the start of a Map from ES7
Like Set, for the time being, this is baseed on top of ArrayObject: two
of them, one for keys, one for values. Again, this goes against the
spirit of the spec (which requires nonlinear access), but having the API
present is at least a start, and the implementation is easily changed.

Change-Id: Idcf0ad8d92eb5daac734d52e8e2dd4c8e0dd5109
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-06-01 11:53:37 +00:00
Robin Burchell 19f657d995 Add the start of a Set from ES7
Based on top of an ArrayObject for now, which is admittedly a bit of a
cheat and not matching the "spirit" of the spec. OTOH, that makes it
easy to write, and is presumably quite lightweight, so perhaps this is acceptable
as a starting point.

Change-Id: Ibc98137965b3e75635b960a2f88c251d45e6e837
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-05-30 20:57:17 +00:00
Lars Knoll 3ccd529e35 Implement toPrimitive() the way the ES7 spec wants it
Add Dat.prototype[Symbol.toPrimitive] and make use of those
methods in the toPrimitive implementation.

Change-Id: I82a9a94dcae6822100de364373b3f4de1e3d749b
Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
2018-05-28 10:40:08 +00:00
Lars Knoll 6cbc287c06 Cleanup JS stack allocations
Avoid double writes to the stack, and use scope.alloc() for
most allocations on the stack.

Change-Id: I8b89273c1b6796d955fc8eeb72c67cff208ef786
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-26 06:49:04 +00:00
Lars Knoll de95f4da8b Fix the inheritance structure for typed arrays
Change-Id: I8a16c1f5e0252b4ea85ff8f623beb39df747e383
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-24 08:09:33 +00:00
Lars Knoll b254bbb82b Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: I0127f2c16de1d930bdd8cbccd42ec6785f31ab96
2018-05-24 09:15:57 +02:00
Lars Knoll 3de014db9e Fixup the throwTypeError internal function
Make the function conform to section 9.2.7.1 of the spec.

Change-Id: Ieb3295198f407d4404e06a54efb51a8b8496bbd7
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-23 13:19:28 +00:00
Simon Hausmann 60176efa78 Fix crash when incubating objects with non-existent initial properties
When incubation is triggered from C++ and reaches the state of setting
the initial properties (as supplied to incubateObject), we'd set
engine->currentStackFrame to a CppStackFrame that provides access to the
correct QML context. As we're not called from the interpreter, the
v4Function pointer would be a null pointer. If during the initial
property setting an exception is thrown (due to non-existent property
access) and a back-trace is created, we'd end up dereferencing
v4Function.

Change-Id: I7f6b0ba7893bfb4186f55d4c213b4bb602d29aa0
Task-number: QTBUG-68416
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-05-23 11:06:34 +00:00
Lars Knoll cc8cb4b442 Implement Symbol.species getter functions
Change-Id: I18b3e382e679f95d7cb53b4ed03be2513ea0204b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-15 18:21:10 +00:00
Lars Knoll c4ef0d6e4b Call iterator.return when required in destructuring assignments
Array destructuring assignments require a call to iterator.return if
the iterator hasn't been exhausted during destructuring.

Change-Id: I39fe4bc01bef6fb2ad3bda92caf6779fbbddc8e2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-14 19:32:42 +00:00
Lars Knoll 3d5ba9f86e Add instructions to simplify for-of loops
Added an IteratorNext instruction to fetch the next
iteration value (empty if the iterator is done).

This will also help to implement array destructuring without
requiring huge amounts of byte code.

Change-Id: If96c1e81471e5e2b0b7b2af122238d87741aa371
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-13 12:55:20 +00:00
Lars Knoll 4cf7e80c57 Ensure we have a lexical scope for global code
This requires a bit more work than simply pushing a
new BlockContext for the lexically declared variables,
as eval() and the Function constructor operate on the
global scope (including the lexically declared names).

To fix this introduce Push/PopScriptContext instructions,
that create a BlockContext for the lexically declared
vars and pushes that one as a global script context that
eval and friends use.

Change-Id: I0fd0b0f682f82e250545e874fe93978449fe5e46
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-11 07:17:05 +00:00
Lars Knoll 8e69a9868c Avoid accessing an object with this == nullptr
Get rid of a circular dependency when initializing
StringObject.prototype, by setting it's string value
later during the initialization process.

Change-Id: I5bdaff3936c1f8af12c4d53f95747b8aa43f4ef6
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-04 18:13:09 +00:00
Lars Knoll 4f086e3aac Rename ForeachIterator to ForInIterator
As it's being used for for(... in ...) loops. Also add a ES6
compatible iterator interface to it, so that we can unify
the handling of for-in and for-of.

Change-Id: I264f88ed049484945f5ea7e8bdf0227187456ba2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-04 18:12:50 +00:00
Lars Knoll 1f9fdd1af7 The length property of function objects is configurable
Change-Id: I657be2e2eb4dfd86850bb73e85d4ddd24f0b8986
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-03 20:05:18 +00:00
Lars Knoll 5747a75302 Add Generator support
Add support for ES6 generators. Those are currently
always executed in the interpreter (we never JIT them),
to simplify the initial implementation.

Most functionality, except for 'yield *' expressions
are supported. 'yield *' will have to wait until we
support for(... of ...)

Change-Id: I7c059d1e3b301cbcb79e3746b4bec346738fd426
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-03 20:05:14 +00:00
Lars Knoll 8761cbd4f7 Implement StringIterator
Add support for String.prototype[Symbol.iterator] and the
StringIterator object.

Change-Id: I72c4f988e4f363be1af51f9cc5f8e83af43cd151
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:20:29 +00:00
Lars Knoll 7d46d72510 Implement support for arguments[Symbol.iterator]
Change-Id: Ieb60e2d8f41c38146b588bc8cd225a2a567e0956
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:20:25 +00:00
Lars Knoll c7fe748850 Cleanup creation code for builtin functions
Centralize the code in FunctionObject::createBuiltinFunction and setup
function names and length properties there.

Change-Id: I21f1d42b475070ee091d96d97387149af1dc47f2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:20:21 +00:00
Robin Burchell a4207b2f95 Add Array Iterator objects from ES6 (22.1.5)
And implement / expose them via:
    22.1.3.4 - Array.prototype.entries()
    22.1.3.13 - Array.prototype.keys()
    22.1.3.29 - Array.prototype.values()
    22.1.3.31 - Array.prototype[Symbol.iterator]

Most tests for Array iterators now pass.

At the same time, expose them on TypedArray's prototype:
    - 22.2.3.15 %TypedArray%.prototype.keys
    - 22.2.3.29 %TypedArray%.prototype.values
    - 22.2.3.6 %TypedArray%.prototype.entries
    - 22.2.3.31 %TypedArray%.prototype[Symbol.iterator]

For TypedArray, test coverage improves a tiny bit (3 passing tests), but the
vast majority fail as it seems like the object structure for TypedArray is
currently incomplete as far as ES6 expects.

It seems that ES6 expects the object structure to be:
* %TypedArray% (inherits FunctionObject)
    (this is the TypedArray intrinsic object, and responsible for initializing
    the TypedArray instances)

* All the TypedArray ctors (e.g. UInt8Array)
    These inherit %TypedArray%, and make a super call to it to do their work

* %TypedArrayPrototype% (inherits Object)
    (this is the initial prototype for %TypedArray%)
    * All the ctors have their own separate instance of this
    * The instances also make use it

So, for instance, a lot of the tests attempt to access the prototype like:
    var proto = Object.getPrototypeOf(Int8Array)
    var keys = proto.prototype.keys

As ES6 expects Int8Array.prototype to be %TypedArray% (22.2.5), this expands to:
    Object.getPrototypeOf(%TypedArray%)
which it expects to be %TypedArrayPrototype%.

But since we have no intrinsic object, and the ctors inherit
FunctionObject, we instead return the wrong prototype into 'var proto'.

Change-Id: I5e1a95a0420ecb70a0e35a5df3f65557510c5925
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:20:13 +00:00
Lars Knoll 37b85ca10e Add SymbolObject, well known symbols and fix most remaining issues
Added SymbolObject, the equivalent to StringObject which was
still missing so far. Added the predefined standard symbols,
and fixed most test failures related to symbols.

Change-Id: I1e28b439e7c4f5141b4a09bd8fb666c60691f192
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:18:45 +00:00
Lars Knoll 360a48aa3f Implement Symbol.for and Symbol.keyFor
Change-Id: I5fde731b3a1a6d7c15154881ed82549b2800d104
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:18:41 +00:00
Lars Knoll bab5e5adf5 Partial Symbol support
Added basic infrastructure to create symbols and convert them
back to strings. In addition, storing and retrieving of symbol
based properties in Objects works.

Change-Id: I185f7aa46e7afa19db5a801102142892e03b7bf1
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:18:36 +00:00
Lars Knoll a6da23bb5f Garbage collect identifiers
Implemented by storing a backpointer to the Heap object
in the identifier.

Since identifiers now point back to their originating
String or Symbol, we can now easily mark all identifiers
that are still in use and collect those that aren't.

Since Identifiers are 64bit also add support for holding an
array index in there. With that an identifier can describe
any kind of property that can be accessed in an object. This
helps speed up and simplify some code paths.

To make this possible, we need to register all
IdentifierHash instances with the identifier table, so that
we can properly mark those identifiers.

Change-Id: Icadbaf5712ab9d252d4e71aa4a520e86b14cd2a0
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:18:32 +00:00
Lars Knoll 3c090c80c5 Remove String dependency from InternalClass
This is required, so we can also use Symbols in
the internal classes.

Change-Id: I630e7aa7b8b16d5a94041f8d18515fd582f94264
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:18:23 +00:00
Lars Knoll 922e6f42b4 Rework catch context handling
Remove the need for a specialized catch context, instead
use a regular block context, that also captures the
catched variable.

This also removes the need to do lookups by name inside
a catch expression.

Change-Id: I8b037add7f423922e2a76b4c0da646ca7e25813a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:17:51 +00:00
Lars Knoll 7e854bc568 Clean up handling of the 'caller' property
This brings it closer in line with the ES8 spec. Also
remove a couple of tests testing the 'caller' property
of non strict functions, as it's not mandated by the
spec and we never set it.

Change-Id: Icece8a03989c474df1eae0e4e77b356e49575b32
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-26 20:26:56 +00:00
Lars Knoll ce2f9621e0 Get rid of some outdated code
There's no point in trying to treat syntax errors specially here.

Change-Id: Idde8f9c9669f183e1b8f5b17bb7e4299fc5f1e5f
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-12 13:59:21 +00:00
Lars Knoll 6002b48c3c garbage collect InternalClass
Internal classes are now allocated and collected through
the GC. As they are important to the deletion of other
objects (because of the vtable pointer living inside the
internal class), they need to get destroyed after regular
objects have been sweeped. Achieve this by using a separate
block allocator for internal class objects.

Our lookups do often contain pointers to internal classes,
so those need to be marked as well, so we don't accidentally
collect them.

Change-Id: I4762b054361c70c31f79f920f669ea0e8551601f
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-12 13:59:08 +00:00
Lars Knoll 3932536b59 Better encapsulation for EngineBase::internalClass
Turn it into a method instead of accessing the array directly
to simplify refactoring.

Change-Id: I197b56c8f58cfdfd294f429e6b15268c755f9837
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-12 13:59:02 +00:00
Lars Knoll b6bb3fe423 Clean up Engine::newObject/newArrayObject
They don't need a prototype argument neither anymore.

Change-Id: I80fa99cb382e8dca4cfa51fdd87b4c9b0f59573a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-12 13:58:52 +00:00
Lars Knoll 278b144a35 Disambiguate different allocation functions in the memory manager
Some compilers (in this case MingW 5.3) don't manage to properly
disambiguate the template overloads, and try to instantiate the
wrong template function.

Solve this by renaming the one of the template functions.

Change-Id: I3574e617fe96c4bd52920a0127a1dfe39cc3d302
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-12 13:58:48 +00:00
Lars Knoll 6c2f6e029e Cleanup MM::allocObject()
The prototype argument has been unused for quite some time,
finally remove it.

Change-Id: Ifcebe413a1951ed972b370afc48640bd22969943
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-12 13:58:45 +00:00
Lars Knoll f3ae6799e1 Optimize MM::allocManaged()
We can manage without calls to changeVTable() here, as the
set of classes allocated with this is rather limited.

Change-Id: I804e4850b91c61ebbca8a04edbe51deac911928d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-12 13:58:41 +00:00
Lars Knoll c7bac1588e Remove the pool allocator from InternalClass
Makes it easier to transition it over to be controlled
by the GC.

Change-Id: I6bea738b3852abfc7870b71e639efc595eeb28fc
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-12 13:58:30 +00:00
Qt Forward Merge Bot 9477ba4e42 Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: I2e3ba907a6afcaa69354a894259c7b7accf3e3ac
2018-03-17 20:42:46 +01:00
Simon Hausmann ee89a8c052 Fix lookup of enums declared in QML singletons
Given the following expression

    var x = MySingleton.MyEnumValue

where MySingleton is a QML (composite) singleton and MyEnumValue comes
from a QML declared enum, we had code in place up to (and including)
5.10 to attempt to optimize that expression to a enum constant at
compile time. In 5.10 that optimization does not exist anymore. In <=
5.10 we would also skip the optimization under certain circumstances
(too many statementes, etc.). The fallback that is in place for handling
this at run-time tried to be smart by avoiding the
QQmlContextWrapper::get lookup and return straight a reference to the
singleton as QObject. That works for regular property lookups, but it
fails when trying to look up something like an enum, that isn't a
meta-object property.

Change-Id: I1819b9d8ae06a3f595e067bf5b018c4065be76bb
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-03-16 10:42:57 +00:00
Qt Forward Merge Bot bf0603fd03 Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: I308b964d86ca01916f6af7d6e3f71557e3624eca
2018-03-03 01:00:13 +01:00
Ville Voutilainen d0c1b1e8f9 Silence a GCC 8 warning in qv4engine
qtdeclarative/src/qml/jsruntime/qv4engine.cpp:913:78: error: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct QV4::Property’ with no trivial copy-assignment [-Werror=class-memaccess]
             memcpy(argumentsAccessors, oldAccessors, oldSize*sizeof(Property));

Change-Id: I6e3d6a1a26fda33aa47c315a183edba9dcd0c0b9
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-02-28 16:10:55 +00:00
Liang Qi bb7a5d0cb6 Merge remote-tracking branch 'origin/5.11' into dev
Conflicts:
	src/qml/jsruntime/qv4engine.cpp
	src/qml/jsruntime/qv4internalclass.cpp
	src/qml/parser/qqmljslexer.cpp
	src/qml/qml/v8/qv8engine.cpp
	src/qml/util/qqmladaptormodel_p.h
	src/quick/items/qquickanimatedsprite.cpp
	tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp

Change-Id: I16702b7a0da29c2a332afee47728d6a6ebf4fb3f
2018-02-27 08:43:10 +01:00
Shawn Rutledge 499ec43937 use nullptr consistently (clang-tidy)
From now on we prefer nullptr instead of 0 to clarify cases where
we are assigning or testing a pointer rather than a numeric zero.

Also, replaced cases where 0 was passed as Qt::KeyboardModifiers
with Qt::NoModifier (clang-tidy replaced them with nullptr, which
waas wrong, so it was just as well to make the tests more readable
rather than to revert those lines).

Change-Id: I4735d35e4d9f42db5216862ce091429eadc6e65d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-02-26 07:13:18 +00:00
Qt Forward Merge Bot d21fd06627 Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: I8cca650fbb1904ecba59da909a08dba3cc574add
2018-02-22 09:19:15 +01:00
Oliver Wolff ab03ee7b7e WinRT: Do not call canAllocateExecutableMemory from static initializer
When the code generation capability is not set, the first call of
canAllocateExecutableMemory will cause a warning about suboptimal
performance. The qWarning code checks, which thread caused the message
and QThread::current sets QCoreApplicationPrivate;s theMainThread when
it is called for the first time on Windows.

If we call that function inside a static initializer, it will be called
before QCoreApplication is created and thus set the main thread to the
one that called the function. This will cause a warning about QApplication
not being created inside the main() thread, but more importantly,
delivering of events will not work in WinRT applications afterwards.

Task-number: QTBUG-66418
Change-Id: I3b6bf804983644b5ae5fe2288a587dc95fab2c8b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2018-02-22 06:30:29 +00:00
Ulf Hermann f254b0aa67 Add a feature for QML locale support
Change-Id: I1cfb2da317f52709011b67a68e87a73ed24ef6d6
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-02-15 08:04:43 +00:00
Qt Forward Merge Bot 268931e742 Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: Ib297817e2fd9b6790d9bc8ee522c32f5b3422574
2018-02-13 20:21:35 +01:00
Ulf Hermann b897a4b9e5 QML: Make mapping of sequence object in JS optional
qv4sequenceobject.o is the largest single object in QtQml.so. This is
probably due to template and macro explosion. Not everyone will want to
pay this price to have Qt containers natively available in JS.

Change-Id: I7dc64566a653c865d5c1b6e4f21a3a9089db100a
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-02-11 19:20:12 +00:00
Simon Hausmann 6a2ebc47cf Fix crashes on WinRT when allocation of executable memory is disabled
This regressed in commit b56f7d6f79. We
need to choose the YARR JIT (as well as the regular JIT) only if we can
allocate executable memory.

Change-Id: I150238fda7b3699cb1d7ffedeeed3c6f3f54132b
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-02-09 13:18:28 +00:00
Lars Knoll ea164ca4a8 Change creation of new internal classes
So far we often began with the empty class again when creating
new internal classes. This allowed for multiple paths through the
internal class hierarchy ending up at the same internal class object.

But to be able to efficiently garbage collect internal classes, we
need to have only one path to each instance of an internal class.

Change-Id: Ic6c1f2b3d021e92b44f76a04a8886820e63e8f26
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-02-09 07:55:36 +00:00
Ulf Hermann 8419ff45d4 Further simplify relation between different engines
The only engine we ever ask for QJSEngine is QV4::ExecutionEngine.

Change-Id: Ia1354e552bddac72177b7aa62de5a7a502089841
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2018-02-07 16:32:48 +00:00
Shawn Rutledge 81b393227d Merge "Merge remote-tracking branch 'origin/5.10' into dev" into refs/staging/dev 2018-02-06 19:40:36 +00:00