jquery/jquery — pull request #1449 by markelog (2013-11-29 11:57:56+00:00)
Title: Switch to script injection instead of indirect eval call

Right now, 2.x uses two techincs for code execution in global scope: script injection if "use strict" statement is found and indirect eval call if not. 1.x only uses eval path.

With indirect eval call, we have only one problem - if evaluated code uses strict pragma, it will not be executed in global scope, which subverts function purpose. Although current code tries to circumvent it, but fails on edge cases.

With script injection we have four problems:
1) It requires browser environments, i.e. DOM
2) It might be executed asynchronously
3) Errors do not propagate, but instead would be thrown in different flow, meaning you can't catch them without `window.onerror`
4) Potential performance penalty

One common and obvious issue is difference of `globalEval` functionality between branches. Because now we have all those problems combine, so i propose to start using only one technic, this PR will try to do it with script injection.

Now about issues with this way:

It requires browser env, i.e. DOM

Well, jQuery is DOM-centric library, in other environments you should use other means

It might be executed asynchronously

It's no longer true, since Firefox 4.0, but just to be sure, i added a test for it.

Errors do not propagate

Yes, that would be a incompatible difference

Potential perfomance penalty

It's actually the opposite (it's not my test if anyone asks :-)

I think the important thing is that jQuery should use only one technic and it should be identical between branches, i, personally, could live with any of them.

/cc @dmethvin, @rwaldron, @jdalton, @jaubourg