| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package org.mozilla.javascript.tests; |
| 6 |
|
| 7 |
import java.lang.reflect.Method; |
| 8 |
|
| 9 |
import junit.framework.TestCase; |
| 10 |
|
| 11 |
import org.mozilla.javascript.Context; |
| 12 |
import org.mozilla.javascript.ContextFactory; |
| 13 |
import org.mozilla.javascript.Scriptable; |
| 14 |
import org.mozilla.javascript.ScriptableObject; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public class CustomSetterAcceptNullScriptableTest extends TestCase |
| 23 |
{ |
| 24 |
public static class Foo extends ScriptableObject { |
| 25 |
private static final long serialVersionUID = -8771045033217033529L; |
| 26 |
|
| 27 |
@Override |
| 28 |
public String getClassName() |
| 29 |
{ |
| 30 |
return "Foo"; |
| 31 |
} |
| 32 |
|
| 33 |
public void setMyProp(final Foo2 s) { } |
| 34 |
} |
| 35 |
|
| 36 |
public static class Foo2 extends ScriptableObject { |
| 37 |
private static final long serialVersionUID = -8880603824656138628L; |
| 38 |
|
| 39 |
@Override |
| 40 |
public String getClassName() |
| 41 |
{ |
| 42 |
return "Foo2"; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
public void testSetNullForScriptableSetter() throws Exception { |
| 47 |
|
| 48 |
final String scriptCode = "foo.myProp = new Foo2();\n" |
| 49 |
+ "foo.myProp = null;"; |
| 50 |
|
| 51 |
final ContextFactory factory = new ContextFactory(); |
| 52 |
final Context cx = factory.enterContext(); |
| 53 |
|
| 54 |
try { |
| 55 |
final ScriptableObject topScope = cx.initStandardObjects(); |
| 56 |
final Foo foo = new Foo(); |
| 57 |
|
| 58 |
|
| 59 |
final Method setMyPropMethod = Foo.class.getMethod("setMyProp", Foo2.class); |
| 60 |
foo.defineProperty("myProp", null, null, setMyPropMethod, ScriptableObject.EMPTY); |
| 61 |
|
| 62 |
topScope.put("foo", topScope, foo); |
| 63 |
|
| 64 |
ScriptableObject.defineClass(topScope, Foo2.class); |
| 65 |
|
| 66 |
cx.evaluateString(topScope, scriptCode, "myScript", 1, null); |
| 67 |
} |
| 68 |
finally { |
| 69 |
Context.exit(); |
| 70 |
} |
| 71 |
} |
| 72 |
} |