js/src/jit-test/tests/arguments/defaults-scoping.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 var x = 'global';
     2 function f(a=x) {  // local variable x
     3     var x = 'local';
     4     return a;
     5 }
     6 assertEq(f(), undefined);
     8 function g(f=function () { return ++x; }) {  // closes on local variable x
     9     var x = 0;
    10     return f;
    11 }
    12 var gf = g();
    13 assertEq(gf(), 1);
    14 assertEq(gf(), 2);
    15 gf = g();
    16 assertEq(gf(), 1);
    18 function h(f=function (s) { return eval(s); }) {  // closes on local scope
    19     var x = 'hlocal';
    20     return f;
    21 }
    22 var hf = h();
    23 assertEq(hf('x'), 'hlocal');
    24 assertEq(hf('f'), hf);
    25 assertEq(hf('var x = 3; x'), 3);
    27 function j(expr, v=eval(expr)) {
    28     return v;
    29 }
    30 assertEq(j("expr"), "expr");
    31 assertEq(j("v"), undefined);
    32 assertEq(j("Array"), Array);
    33 assertEq(j("arguments").length, 1);

mercurial