https://bugzilla.wikimedia.org/show_bug.cgi?id=69924

--- Comment #11 from Krinkle <krinklem...@gmail.com> ---
This is not a new problem. Users using older browsers have always had fatal
errors because jquery/mediawiki are not loaded in blacklisted browsers not
supporting our required version for the javascript engine. They used to fail on
a ReferenceError for $ or mw undefined. This error happens because, unlike
modern modules that are only loaded in a supported environment, site/user
modules are executed in the global scope for legacy reasons and unconditionally
referenced in the HTML.


As we do, we move with the times and naturally raise our requirements as new
technologies come available, become dependant on it, and eventually no longer
support older engines for javascript features (basic functionality will remain
supported in these browsers however!).

Up until recently this applied to MSIE 5, Firefox 2 (and below). This was
raised to MSIE 6, Firefox 2 and Opera 11 (and below).

This has exposed the ReferenceError wider. Thus, we've wrapped the site/user
module in the same "if(window.mw)" conditional as we've wrapped other scripts
for years now (mw.config.set, mw.user.options etc.). This means users in older
browsers no longer get errors (especially for site scripts. For user scripts
it's a minor issue because they are their own scripts, if they frequently use
older browsers, they probably don't need that user script as it wouldn't be
executed anyway).

---

We can't wrap the code in a closure because they need to be executed in the
global scope. If we can wrap them in a closure, they wouldn't have to be loaded
via hardcoded script tags, wrapped in mw.loader.implement closures and we
wouldn't have this problem in the first place.

Many of these scripts do indeed have global var statements or function
declarations (including relying on function hoisting).

To my knowledge, conditional function declarations (or variable declarations
for that matter) are a bit silly because it's unconditionally hoisted.

e.g.

> bar;
>> ReferenceError: bar is undefined

> if (true) {
>   var bar = 5;
> }
> bar;
>> (nothing)

Because 'var bar;' was hoisted.

The same applies to function declarations (executed in V8 under Chrome)

> function bar() { return 1; }
> bar();
>> 1

> if (true) {
>   function bar() { return 1; }
> } else {
>   function bar() { return 2; }
> }
> bar();
>> 2

This is bad practice, but I figured it'd be harmless for an implementation
detail like if-window-mw (considering there'd never be any statements before or
after the if-statement).

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are on the CC list for the bug.
_______________________________________________
Wikibugs-l mailing list
Wikibugs-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to