js/src/jit-test/tests/arguments/access-formals.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/arguments/access-formals.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +function g1(x, args) {
     1.5 +    args[0] = 88;
     1.6 +}
     1.7 +
     1.8 +// We assume we can optimize arguments access in |f|.
     1.9 +//
    1.10 +// Then the apply-call invalidates the arguments optimization,
    1.11 +// and creates a real arguments object.
    1.12 +//
    1.13 +// Test that x and y fetch the values from the args object when
    1.14 +// that happens.
    1.15 +function f1(x, y, o) {
    1.16 +    var res = 0;
    1.17 +    for (var i=0; i<50; i++) {
    1.18 +	res += x + y;
    1.19 +	if (i > 10)
    1.20 +	    o.apply(null, arguments);
    1.21 +    }
    1.22 +    return res;
    1.23 +}
    1.24 +
    1.25 +var o1 = {apply: g1};
    1.26 +assertEq(f1(3, 5, o1), 3630);
    1.27 +assertEq(f1(3, 5, o1), 3630);
    1.28 +
    1.29 +// In strict mode, the arguments object does not alias formals.
    1.30 +function g2(x, args) {
    1.31 +    args[0] = 88;
    1.32 +}
    1.33 +
    1.34 +function f2(x, y, o) {
    1.35 +    "use strict";
    1.36 +    var res = 0;
    1.37 +    for (var i=0; i<50; i++) {
    1.38 +	res += x + y;
    1.39 +	if (i > 10)
    1.40 +	    o.apply(null, arguments);
    1.41 +    }
    1.42 +    return res;
    1.43 +}
    1.44 +
    1.45 +var o2 = {apply: g2};
    1.46 +assertEq(f2(3, 5, o2), 400);
    1.47 +assertEq(f2(3, 5, o2), 400);

mercurial