Skip to content

Commit

Permalink
Add to OptimizeArgumentsArrayTest
Browse files Browse the repository at this point in the history
Documents some crashes on ES6 code and adds a few more cases.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=230648052
  • Loading branch information
lauraharker authored and tjgq committed Jan 25, 2019
1 parent c8f5a9d commit 31b1de3
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions test/com/google/javascript/jscomp/OptimizeArgumentsArrayTest.java
Expand Up @@ -16,6 +16,7 @@

package com.google.javascript.jscomp;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -184,6 +185,11 @@ public void testDecimalArgumentIndex() {
testSame("function f() { arguments[0.5]; }");
}

@Test
public void testNegativeArgumentIndex() {
testSame("function badFunction() { arguments[-1]; }");
}

@Test
public void testArrowFunctions() {

Expand Down Expand Up @@ -284,7 +290,13 @@ public void testNestedFunctions() {

@Test
public void testNoOptimizationWhenArgumentIsUsedAsFunctionCall() {
testSame("function f() {arguments[0]()}");
testSame("function f() {arguments[0]()}"); // replacing the call would change `this`
}

@Test
public void testNoOptimizationWhenArgumentsReassigned() {
// replacing the post-assignment `arguments[0]` with a named parameter would be incorrect
testSame("function f() { arguments[0]; arguments = [3, 4, 5]; arguments[0]; }");
}

@Test
Expand All @@ -293,7 +305,27 @@ public void testUnusualArgumentsUsage() {
}

@Test
public void testNegativeIndexNoCrash() {
testSame("function badFunction() { arguments[-1]; }");
@Ignore
public void testUseArgumentsToAccessParamWithDefault() {
// TODO(b/123256727): fix this case. right now the pass crashes
test("function f(x = 0) { arguments[0]; }", "function f(x = 0) { x; }");
}

@Test
@Ignore
public void testUseArgumentsWithRestParam() {
// TODO(b/123256727): fix this case. right now the pass crashes
test("function f(x, ...rest) { arguments[1]; }", "function f(...rest) { rest[0]; }");

test("function f(x, ...rest) { arguments[2]; }", "function f(...rest) { rest[1]; }");
}

@Test
@Ignore
public void testUseArgumentsWithDestructuringParam() {
// TODO(b/123256727): fix this case. right now the pass crashes
test("function f([x, y]) { arguments[1]; }", "function f([x, y], p0) { p0; }");

testSame("function f([x, y]) { arguments[0]; }");
}
}

0 comments on commit 31b1de3

Please sign in to comment.