forked from mozilla/rhino
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull Request mozilla#1435: Fixes for Symbol.iterator handling in Nati…
…veArray
- Loading branch information
Showing
6 changed files
with
190 additions
and
34 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
66 changes: 66 additions & 0 deletions
66
testsrc/org/mozilla/javascript/tests/es6/ArgumentsTest.java
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,66 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.javascript.tests.es6; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.ScriptableObject; | ||
import org.mozilla.javascript.tests.Utils; | ||
|
||
/** Tests for Arguments support. */ | ||
public class ArgumentsTest { | ||
|
||
@Test | ||
public void argumentsSymbolIterator() { | ||
String code = | ||
"function foo() {" | ||
+ " return arguments[Symbol.iterator] === Array.prototype.values;" | ||
+ "}" | ||
+ "foo()"; | ||
|
||
test(true, code); | ||
} | ||
|
||
@Test | ||
public void argumentsSymbolIterator2() { | ||
String code = | ||
"function foo() {" | ||
+ " return arguments[Symbol.iterator] === [][Symbol.iterator];" | ||
+ "}" | ||
+ "foo()"; | ||
|
||
test(true, code); | ||
} | ||
|
||
@Test | ||
public void argumentsForOf() { | ||
String code = | ||
"function foo() {" | ||
+ " var res = '';" | ||
+ " for (arg of arguments) {" | ||
+ " res += arg;" | ||
+ " }" | ||
+ " return res;" | ||
+ "}" | ||
+ "foo(1, 2, 3, 5)"; | ||
|
||
test("1235", code); | ||
} | ||
|
||
private static void test(Object expected, String js) { | ||
Utils.runWithAllOptimizationLevels( | ||
cx -> { | ||
cx.setLanguageVersion(Context.VERSION_ES6); | ||
ScriptableObject scope = cx.initStandardObjects(); | ||
|
||
Object result = cx.evaluateString(scope, js, "test", 1, null); | ||
assertEquals(expected, result); | ||
|
||
return null; | ||
}); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
testsrc/org/mozilla/javascript/tests/es6/NativeArray3Test.java
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,74 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.javascript.tests.es6; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.ScriptableObject; | ||
import org.mozilla.javascript.tests.Utils; | ||
|
||
/** Tests for NativeArray support. */ | ||
public class NativeArray3Test { | ||
|
||
@Test | ||
public void iteratorPrototype() { | ||
String code = "Array.prototype.values === [][Symbol.iterator]"; | ||
|
||
test(true, code); | ||
} | ||
|
||
@Test | ||
public void iteratorInstances() { | ||
String code = "[1, 2][Symbol.iterator] === [][Symbol.iterator]"; | ||
|
||
test(true, code); | ||
} | ||
|
||
@Test | ||
public void iteratorPrototypeName() { | ||
String code = "Array.prototype.values.name;"; | ||
|
||
test("values", code); | ||
} | ||
|
||
@Test | ||
public void iteratorInstanceName() { | ||
String code = "[][Symbol.iterator].name;"; | ||
|
||
test("values", code); | ||
} | ||
|
||
@Test | ||
public void redefineIterator() { | ||
String code = | ||
"var res = '';\n" | ||
+ "var arr = ['hello', 'world'];\n" | ||
+ "res += arr[Symbol.iterator].toString().includes('return i;');\n" | ||
+ "res += ' - ';\n" | ||
+ "arr[Symbol.iterator] = function () { return i; };\n" | ||
+ "res += arr[Symbol.iterator].toString().includes('return i;');\n" | ||
+ "res += ' - ';\n" | ||
+ "delete arr[Symbol.iterator];\n" | ||
+ "res += arr[Symbol.iterator].toString().includes('return i;');\n" | ||
+ "res;"; | ||
|
||
test("false - true - false", code); | ||
} | ||
|
||
private static void test(Object expected, String js) { | ||
Utils.runWithAllOptimizationLevels( | ||
cx -> { | ||
cx.setLanguageVersion(Context.VERSION_ES6); | ||
ScriptableObject scope = cx.initStandardObjects(); | ||
|
||
Object result = cx.evaluateString(scope, js, "test", 1, null); | ||
assertEquals(expected, result); | ||
|
||
return null; | ||
}); | ||
} | ||
} |
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