Debian Codegraph @

rhino/testsrc/org/mozilla/javascript/tests/DeletePropertyTest.java

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
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 * Test for delete that should apply for properties defined in prototype chain.
17 * See https://bugzilla.mozilla.org/show_bug.cgi?id=510504
18 * @author Marc Guillemot
19 */
20 public class DeletePropertyTest extends TestCase {
21 /**
22 * delete should not delete anything in the prototype chain.
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 }