resourceloader: Consistently set state=ready after script execution (not before)
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 28 Aug 2015 22:56:24 +0000 (00:56 +0200)
committerOri.livneh <ori@wikimedia.org>
Tue, 1 Sep 2015 16:23:18 +0000 (16:23 +0000)
commit0f69149f798345dbe69be8540ba2c80aa7b2a8b6
tree6e2931bd61bff3ce38bedd746ce134684d8b880e
parentd92472373234d3de235c6fed001f902b5b7717b3
resourceloader: Consistently set state=ready after script execution (not before)

For the case of 'module.script' being an array, mw.loader already sets state=ready
after execution. For the cases of it being a function or string, we were setting
state=ready before execution.

This looks like it may have intended to prevent double execution where e.g.
some other module may need this module and see it has state 'loading' and start
executing it. However ResourceLoader doesn't expose execute(). The only code
calling execute() is code that also sets 'state=loading', or handlePending.

In fact, this early setting of "ready" could actually cause double execution.
Not of the current module, but of dependent modules. If a module's script loads
other modules that are cache hits, that could may trigger handlePending() which
will assume the current module to be ready, when it isn't.

Now that these code paths match, re-use the markModuleReady callback instead of
repeating this code.

Update tests:
* Make assertion captions less verbose.
* Change load instruction from "test.implement" to "test.implement.import".
  Module "test.implement" doesn't exist. This worked by accident because
  implement() can sometimes run a module immediately if it doesn't exist.
* Update test to reflect internal detail that state=loading during script
  execution.
* Assert afterwards that script ran and state=ready.

Change-Id: I6b0542edb113d58b8f24cc8587e98ee88b514c55
resources/src/mediawiki/mediawiki.js
tests/qunit/suites/resources/mediawiki/mediawiki.test.js