-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 additions
and
1 deletion.
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
68 changes: 68 additions & 0 deletions
68
testsrc/org/mozilla/javascript/tests/es6/NativeArray2Test.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,68 @@ | ||
package org.mozilla.javascript.tests.es6; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.ScriptableObject; | ||
|
||
/** | ||
* @see <a | ||
* href="https://github.com/mozilla/rhino/issues/673">https://github.com/mozilla/rhino/issues/673</a> | ||
*/ | ||
public class NativeArray2Test { | ||
|
||
private Context cx; | ||
private ScriptableObject scope; | ||
|
||
@Before | ||
public void setUp() { | ||
cx = Context.enter(); | ||
cx.setLanguageVersion(Context.VERSION_ES6); | ||
scope = cx.initStandardObjects(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
Context.exit(); | ||
} | ||
|
||
@Test | ||
public void concatLimitSpreadable() { | ||
String js = | ||
"var spreadable = {};\n" | ||
+ "spreadable.length = Number.MAX_SAFE_INTEGER;\n" | ||
+ "spreadable[Symbol.isConcatSpreadable] = true;\n" | ||
+ "try {\n" | ||
+ " [1].concat(spreadable);\n" | ||
+ "} catch(e) {" | ||
+ " '' + e;\n" | ||
+ "};"; | ||
|
||
String result = (String) cx.evaluateString(scope, js, "test", 1, null); | ||
assertTrue(result.endsWith("exceeds supported capacity limit.")); | ||
} | ||
|
||
@Test | ||
public void concatLimitSpreadable2() { | ||
String js = | ||
"var spreadable = {\n" | ||
+ " length: Number.MAX_SAFE_INTEGER,\n" | ||
+ " get 0() {\n" | ||
+ " throw new Error('get failed');\n" | ||
+ " },\n" | ||
+ "};\n" | ||
+ "spreadable[Symbol.isConcatSpreadable] = true;\n" | ||
+ "try {\n" | ||
+ " [].concat(spreadable);\n" | ||
+ "} catch(e) {" | ||
+ " '' + e;\n" | ||
+ "};"; | ||
|
||
String result = (String) cx.evaluateString(scope, js, "test", 1, null); | ||
assertEquals(result, "Error: get failed", result); | ||
} | ||
} |