This repository has been archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 889158 - Fix arrow function lexical arguments binding, allow rest…
… + arguments. r=jorendorff
- Loading branch information
Showing
19 changed files
with
136 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
js/src/jit-test/tests/arguments/rest-disallow-arguments.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// 'arguments' is allowed with rest parameters. | ||
|
||
// FIXME: We should create an unmapped arguments object in this case, | ||
// see bug 1175394. This test is not correct until then. | ||
|
||
var args; | ||
|
||
function restWithArgs(a, b, ...rest) { | ||
return arguments; | ||
} | ||
|
||
args = restWithArgs(1, 3, 6, 9); | ||
assertEq(args.length, 4); | ||
assertEq(JSON.stringify(args), '{"0":1,"1":3,"2":[6,9],"3":9}', | ||
"Did you just fix bug 1175394?"); | ||
|
||
args = restWithArgs(); | ||
assertEq(args.length, 0); | ||
|
||
args = restWithArgs(4, 5); | ||
assertEq(args.length, 2); | ||
assertEq(JSON.stringify(args), '{"0":4,"1":5}'); | ||
|
||
function restWithArgsEval(a, b, ...rest) { | ||
return eval("arguments"); | ||
} | ||
|
||
args = restWithArgsEval(1, 3, 6, 9); | ||
assertEq(args.length, 4); | ||
assertEq(JSON.stringify(args), '{"0":1,"1":3,"2":[6,9],"3":9}', | ||
"Did you just fix bug 1175394?"); | ||
|
||
function g(...rest) { | ||
h(); | ||
} | ||
function h() { | ||
g.arguments; | ||
} | ||
g(); | ||
|
||
// eval() is evil, but you can still use it with rest parameters! | ||
function still_use_eval(...rest) { | ||
eval("x = 4"); | ||
} | ||
still_use_eval(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
// arrow functions have an 'arguments' binding, like any other function | ||
// no 'arguments' binding in arrow functions | ||
|
||
var arguments = []; | ||
var f = () => arguments; | ||
var args = f(); | ||
assertEq(args.length, 0); | ||
assertEq(Object.getPrototypeOf(args), Object.prototype); | ||
|
||
args = f(true, false); | ||
assertEq(args.length, 2); | ||
assertEq(args[0], true); | ||
assertEq(args[1], false); | ||
|
||
assertEq(f(), arguments); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
// 'arguments' in arrow functions nested in other functions | ||
// 'arguments' is lexically scoped in arrow functions | ||
|
||
var g; | ||
var args, g; | ||
function f() { | ||
g = () => arguments; | ||
args = arguments; | ||
} | ||
f(); | ||
var args = g(); | ||
assertEq(args.length, 0); | ||
|
||
args = g(1, 2, 3); | ||
assertEq(args.length, 3); | ||
assertEq(args[0], 1); | ||
assertEq(args[2], 3); | ||
assertEq(g(), args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
// the 'arguments' binding in an arrow function is visible in direct eval code | ||
// 'arguments' in eval | ||
|
||
function f() { | ||
return s => eval(s); | ||
var g = s => eval(s); | ||
assertEq(g("arguments"), arguments); | ||
} | ||
|
||
var g = f(); | ||
var args = g("arguments"); | ||
assertEq(typeof args, "object"); | ||
assertEq(args !== g("arguments"), true); | ||
assertEq(args.length, 1); | ||
assertEq(args[0], "arguments"); | ||
f(); | ||
f(0, 1, 2); | ||
|
||
function h() { | ||
return s => eval(s); | ||
} | ||
var result = h(1, 2, 3, 4)("arguments"); | ||
assertEq(result.length, 4); | ||
assertEq(result[3], 4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
// 'arguments' is banned in a function with a rest param, | ||
// even nested in an arrow-function parameter default value | ||
|
||
load(libdir + "asserts.js"); | ||
|
||
var mistakes = [ | ||
"(...rest) => arguments", | ||
"(...rest) => (x=arguments) => 0", | ||
"function f(...rest) { return (x=arguments) => 0; }", | ||
"function f(...rest) { return (x=(y=arguments) => 1) => 0; }", | ||
]; | ||
// 'arguments' is allowed in a non-arrow-function with a rest param. | ||
assertEq((function(...rest) { return (x => arguments)(1, 2)})().length, 0); | ||
|
||
function restAndArgs(...rest) { | ||
return () => eval("arguments"); | ||
} | ||
|
||
var args = restAndArgs(1, 2, 3)(); | ||
assertEq(args.length, 3); | ||
assertDeepEq(args[0], [1, 2, 3], "This is bogus, see bug 1175394"); | ||
assertEq(args[1], 2); | ||
assertEq(args[2], 3); | ||
|
||
for (var s of mistakes) | ||
assertThrowsInstanceOf(function () { eval(s); }, SyntaxError); | ||
(function() { | ||
return ((...rest) => { | ||
assertDeepEq(rest, [1, 2, 3]); | ||
assertEq(arguments.length, 2); | ||
assertEq(eval("arguments").length, 2); | ||
})(1, 2, 3); | ||
})(4, 5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,28 @@ | ||
// deoptimize `arguments` in the arrow's closest enclosing non-arrow-function | ||
|
||
// non-arrow-function -> arrow function | ||
a = 0; | ||
(function() { | ||
a = (b => eval("arguments"))(); | ||
a = (() => eval("arguments"))(); | ||
})(1, 2, 3, 4); | ||
assertEq(a.length, 0); | ||
assertEq(a.length, 4); | ||
|
||
// non-arrow-function -> arrow function -> arrow function | ||
a = 0; | ||
(function() { | ||
(() => { | ||
a = (() => eval("arguments"))(); | ||
})(); | ||
})(1, 2, 3, 4); | ||
assertEq(a.length, 4); | ||
|
||
// non-arrow-function -> arrow function -> non-arrow-function -> arrow function | ||
a = 0; | ||
(function() { | ||
(() => { | ||
(function () { | ||
a = (() => eval("arguments"))(); | ||
})(1, 2, 3, 4); | ||
})(); | ||
})(); | ||
assertEq(a.length, 4); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.