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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 function g1(x, args) {
michael@0 2 args[0] = 88;
michael@0 3 }
michael@0 4
michael@0 5 // We assume we can optimize arguments access in |f|.
michael@0 6 //
michael@0 7 // Then the apply-call invalidates the arguments optimization,
michael@0 8 // and creates a real arguments object.
michael@0 9 //
michael@0 10 // Test that x and y fetch the values from the args object when
michael@0 11 // that happens.
michael@0 12 function f1(x, y, o) {
michael@0 13 var res = 0;
michael@0 14 for (var i=0; i<50; i++) {
michael@0 15 res += x + y;
michael@0 16 if (i > 10)
michael@0 17 o.apply(null, arguments);
michael@0 18 }
michael@0 19 return res;
michael@0 20 }
michael@0 21
michael@0 22 var o1 = {apply: g1};
michael@0 23 assertEq(f1(3, 5, o1), 3630);
michael@0 24 assertEq(f1(3, 5, o1), 3630);
michael@0 25
michael@0 26 // In strict mode, the arguments object does not alias formals.
michael@0 27 function g2(x, args) {
michael@0 28 args[0] = 88;
michael@0 29 }
michael@0 30
michael@0 31 function f2(x, y, o) {
michael@0 32 "use strict";
michael@0 33 var res = 0;
michael@0 34 for (var i=0; i<50; i++) {
michael@0 35 res += x + y;
michael@0 36 if (i > 10)
michael@0 37 o.apply(null, arguments);
michael@0 38 }
michael@0 39 return res;
michael@0 40 }
michael@0 41
michael@0 42 var o2 = {apply: g2};
michael@0 43 assertEq(f2(3, 5, o2), 400);
michael@0 44 assertEq(f2(3, 5, o2), 400);

mercurial