resourceloader: Condition-wrap the HTML tag instead of JS response
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 8 Sep 2014 16:31:54 +0000 (18:31 +0200)
committerKrinkle <krinklemail@gmail.com>
Tue, 9 Sep 2014 15:54:16 +0000 (15:54 +0000)
commit9d390a09cdfb47cca33a0d6f4346053952e68894
tree076e1b75ede9afc9a02b566e6bf28d7be3bbd717
parent5963e7b97303a4332b3f884d3a8eb76294058272
resourceloader: Condition-wrap the HTML tag instead of JS response

Follows-up 9272bc6c4703c503da221e063f6078.

One can't wrap arbitrary JavaScript in an if-statement and have
its inner-body mean exactly the same.

Certain statements are only allowed in the top of a scope (such
as hoisted function declarations). These are not allowed inside
a block. They're fine in both global scope and local function
scope, but not inside an if-block of any scope.

The ECMAScript spec only describes what is an allowed token.
Any unexpected token should result in a SyntaxError.

Chrome's implementation (V8) allows function declarations in
blocks and hoists them to *outside* the condition. Firefox's
SpiderMonkey silently ignores the statement. Neither throw a
SyntaxError.

Rgular ResourceLoader responses only contain mw.loader.implement()
and mw.loader.state() call which could be wrapped without issues.
However such responses don't need wrapping as they're only made
by mediawiki.js (in which case mw is obviously loaded). The
wrapping is for legacy scripts that execute in the global scope.

For those, let's wrap the script tag itself (instead of the
response). That seems like the most water-tight and semantically
correct solution.

Had to bring in $isRaw from ResourceLoader.php, else the startup
module would have been wrapped as well (added regression test).

Bug: 69924
Change-Id: Iedda0464f734ba5f7a884726487f6c7e07d444f1
includes/OutputPage.php
includes/resourceloader/ResourceLoader.php
tests/phpunit/ResourceLoaderTestCase.php
tests/phpunit/includes/OutputPageTest.php