mediawiki.requestIdleCallback: Implement timeRemaining()
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 12 Mar 2016 02:19:35 +0000 (02:19 +0000)
committerOri.livneh <ori@wikimedia.org>
Wed, 23 Mar 2016 22:29:44 +0000 (22:29 +0000)
commit55fc2a9bd247ec82f9aa5e99af95855d28eea326
treec07b03ea1b13ecb2f1fe0db26a7a9c448c464c87
parent337bf08c7d4dd378353e0c63a509ae5bac47ade6
mediawiki.requestIdleCallback: Implement timeRemaining()

This matches the native API. This allows callers to better batch and spread out
expensive operations based on actual execution speed.

Right now CentralNotice is manually creating arbitrarily sized batches in
kvStoreMaintenance. Instead this can use a while loop with timeRemaining()
to run as quickly as possible whilst still being able to stop and yield when
it runs for too long. This way will naturally take more iterations on slow
devices and less iterations on faster ones - to be least disruptive.

While timeRemaining() is already available in the native interface,
it was previously unsafe to call because the fallback didn't implement it.

* Remove redundant QUnit.test() expect numbers.

* Add a test for the native one if available. This will catch silly mistakes
  like assigning the native one to mw.requestIdleCallback directly that result
  in 'Uncaught TypeError: Illegal invocation' due to missing call context.

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