michael@0: function g1(x, args) { michael@0: args[0] = 88; michael@0: } michael@0: michael@0: // We assume we can optimize arguments access in |f|. michael@0: // michael@0: // Then the apply-call invalidates the arguments optimization, michael@0: // and creates a real arguments object. michael@0: // michael@0: // Test that x and y fetch the values from the args object when michael@0: // that happens. michael@0: function f1(x, y, o) { michael@0: var res = 0; michael@0: for (var i=0; i<50; i++) { michael@0: res += x + y; michael@0: if (i > 10) michael@0: o.apply(null, arguments); michael@0: } michael@0: return res; michael@0: } michael@0: michael@0: var o1 = {apply: g1}; michael@0: assertEq(f1(3, 5, o1), 3630); michael@0: assertEq(f1(3, 5, o1), 3630); michael@0: michael@0: // In strict mode, the arguments object does not alias formals. michael@0: function g2(x, args) { michael@0: args[0] = 88; michael@0: } michael@0: michael@0: function f2(x, y, o) { michael@0: "use strict"; michael@0: var res = 0; michael@0: for (var i=0; i<50; i++) { michael@0: res += x + y; michael@0: if (i > 10) michael@0: o.apply(null, arguments); michael@0: } michael@0: return res; michael@0: } michael@0: michael@0: var o2 = {apply: g2}; michael@0: assertEq(f2(3, 5, o2), 400); michael@0: assertEq(f2(3, 5, o2), 400);