| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package org.mozilla.javascript.tests; |
| 6 |
|
| 7 |
import junit.framework.TestCase; |
| 8 |
|
| 9 |
|
| 10 |
import org.junit.Test; |
| 11 |
import org.mozilla.javascript.Context; |
| 12 |
import org.mozilla.javascript.ContextAction; |
| 13 |
import org.mozilla.javascript.ScriptableObject; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public class DeletePropertyTest extends TestCase { |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
@Test |
| 25 |
public void testDeletePropInPrototype() throws Exception { |
| 26 |
final String script = "Array.prototype.foo = function() {};\n" |
| 27 |
+ "Array.prototype[1] = function() {};\n" |
| 28 |
+ "var t = [];\n" |
| 29 |
+ "[].foo();\n" |
| 30 |
+ "for (var i in t) delete t[i];\n" |
| 31 |
+ "[].foo();\n" |
| 32 |
+ "[][1]();\n"; |
| 33 |
|
| 34 |
final ContextAction action = new ContextAction() |
| 35 |
{ |
| 36 |
public Object run(final Context _cx) |
| 37 |
{ |
| 38 |
final ScriptableObject scope = _cx.initStandardObjects(); |
| 39 |
final Object result = _cx.evaluateString(scope, script, "test script", 0, null); |
| 40 |
return null; |
| 41 |
} |
| 42 |
}; |
| 43 |
|
| 44 |
Utils.runWithAllOptimizationLevels(action); |
| 45 |
} |
| 46 |
} |