Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | var x = 'global'; |
michael@0 | 2 | function f(a=x) { // local variable x |
michael@0 | 3 | var x = 'local'; |
michael@0 | 4 | return a; |
michael@0 | 5 | } |
michael@0 | 6 | assertEq(f(), undefined); |
michael@0 | 7 | |
michael@0 | 8 | function g(f=function () { return ++x; }) { // closes on local variable x |
michael@0 | 9 | var x = 0; |
michael@0 | 10 | return f; |
michael@0 | 11 | } |
michael@0 | 12 | var gf = g(); |
michael@0 | 13 | assertEq(gf(), 1); |
michael@0 | 14 | assertEq(gf(), 2); |
michael@0 | 15 | gf = g(); |
michael@0 | 16 | assertEq(gf(), 1); |
michael@0 | 17 | |
michael@0 | 18 | function h(f=function (s) { return eval(s); }) { // closes on local scope |
michael@0 | 19 | var x = 'hlocal'; |
michael@0 | 20 | return f; |
michael@0 | 21 | } |
michael@0 | 22 | var hf = h(); |
michael@0 | 23 | assertEq(hf('x'), 'hlocal'); |
michael@0 | 24 | assertEq(hf('f'), hf); |
michael@0 | 25 | assertEq(hf('var x = 3; x'), 3); |
michael@0 | 26 | |
michael@0 | 27 | function j(expr, v=eval(expr)) { |
michael@0 | 28 | return v; |
michael@0 | 29 | } |
michael@0 | 30 | assertEq(j("expr"), "expr"); |
michael@0 | 31 | assertEq(j("v"), undefined); |
michael@0 | 32 | assertEq(j("Array"), Array); |
michael@0 | 33 | assertEq(j("arguments").length, 1); |