| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package org.mozilla.javascript.tests; |
| 9 |
|
| 10 |
import static org.junit.Assert.*; |
| 11 |
|
| 12 |
import org.junit.After; |
| 13 |
import org.junit.Before; |
| 14 |
import org.junit.Test; |
| 15 |
import org.mozilla.javascript.Context; |
| 16 |
import org.mozilla.javascript.EvaluatorException; |
| 17 |
import org.mozilla.javascript.Script; |
| 18 |
import org.mozilla.javascript.ScriptableObject; |
| 19 |
|
| 20 |
|
| 21 |
l |
| 22 |
|
| 23 |
|
| 24 |
public class Bug714204Test { |
| 25 |
private Context cx; |
| 26 |
private ScriptableObject scope; |
| 27 |
|
| 28 |
@Before |
| 29 |
public void setUp() { |
| 30 |
cx = Context.enter(); |
| 31 |
scope = cx.initStandardObjects(); |
| 32 |
cx.setLanguageVersion(170); |
| 33 |
} |
| 34 |
|
| 35 |
@After |
| 36 |
public void tearDown() { |
| 37 |
Context.exit(); |
| 38 |
} |
| 39 |
|
| 40 |
@Test |
| 41 |
public void test_assign_this() { |
| 42 |
StringBuilder sb = new StringBuilder(); |
| 43 |
sb.append("function F() {\n"); |
| 44 |
sb.append(" [this.x] = arguments;\n"); |
| 45 |
sb.append("}\n"); |
| 46 |
sb.append("var f = new F('a');\n"); |
| 47 |
sb.append("(f.x == 'a')\n"); |
| 48 |
Script script = cx.compileString(sb.toString(), "<eval>", 1, null); |
| 49 |
Object result = script.exec(cx, scope); |
| 50 |
assertEquals(Boolean.TRUE, result); |
| 51 |
} |
| 52 |
|
| 53 |
@Test(expected = EvaluatorException.class) |
| 54 |
public void test_var_this() { |
| 55 |
StringBuilder sb = new StringBuilder(); |
| 56 |
sb.append("function F() {\n"); |
| 57 |
sb.append(" var [this.x] = arguments;\n"); |
| 58 |
sb.append("}\n"); |
| 59 |
cx.compileString(sb.toString(), "<eval>", 1, null); |
| 60 |
} |
| 61 |
|
| 62 |
@Test(expected = EvaluatorException.class) |
| 63 |
public void test_let_this() { |
| 64 |
StringBuilder sb = new StringBuilder(); |
| 65 |
sb.append("function F() {\n"); |
| 66 |
sb.append(" let [this.x] = arguments;\n"); |
| 67 |
sb.append("}\n"); |
| 68 |
cx.compileString(sb.toString(), "<eval>", 1, null); |
| 69 |
} |
| 70 |
|
| 71 |
@Test(expected = EvaluatorException.class) |
| 72 |
public void test_const_this() { |
| 73 |
StringBuilder sb = new StringBuilder(); |
| 74 |
sb.append("function F() {\n"); |
| 75 |
sb.append(" const [this.x] = arguments;\n"); |
| 76 |
sb.append("}\n"); |
| 77 |
cx.compileString(sb.toString(), "<eval>", 1, null); |
| 78 |
} |
| 79 |
|
| 80 |
@Test(expected = EvaluatorException.class) |
| 81 |
public void test_args_this() { |
| 82 |
StringBuilder sb = new StringBuilder(); |
| 83 |
sb.append("function F([this.x]) {\n"); |
| 84 |
sb.append("}\n"); |
| 85 |
cx.compileString(sb.toString(), "<eval>", 1, null); |
| 86 |
} |
| 87 |
} |