From 5528ba5caced8b1a185186a6e195ddcabd018034 Mon Sep 17 00:00:00 2001 From: "norris%netscape.com" Date: Wed, 4 Aug 1999 23:14:57 +0000 Subject: [PATCH] Fix problem found by Andrew Wason : Subject: null arguments Date: Wed, 04 Aug 1999 13:22:35 -0400 From: Andrew Wason To: norris@netscape.com CC: Howard Lin When I try to pass a null argument to an interface implemented in JS, I get: js: Cannot convert null to an object. js: uncaught JavaScript exception: org.mozilla.javascript.EvaluatorException: Cannot convert null to an object. var b = new Packages.javax.swing.border.Border() { getBorderInsets : function(c) { return new Insets(0,0,0,0); } }; b.getBorderInsets(null); Here is the stack trace where the exception is happening: java.lang.reflect.InvocationTargetException: org.mozilla.javascript.EvaluatorException: Cannot convert null to an object. at org.mozilla.javascript.tools.ToolErrorReporter.runtimeError(ToolErrorReporte r.java:106) at org.mozilla.javascript.Context.reportRuntimeError(Context.java:484) at org.mozilla.javascript.Context.reportRuntimeError(Context.java:500) at org.mozilla.javascript.ScriptRuntime.toObject(ScriptRuntime.java:529) at org.mozilla.javascript.Context.toObject(Context.java:1107) at adapter0.getBorderInsets() at java.lang.reflect.Method.invoke(Native Method) at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java, Compiled Code) at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1256) at org.mozilla.javascript.Interpreter.interpret(Interpreter.java, Compiled Code) at org.mozilla.javascript.InterpretedScript.call(InterpretedScript.java:49) at org.mozilla.javascript.InterpretedScript.exec(InterpretedScript.java:37) at org.mozilla.javascript.Context.evaluateReader(Context.java:691) at org.mozilla.javascript.tools.shell.Main.processSource(Main.java, Compiled Code) at org.mozilla.javascript.tools.shell.Main.main(Main.java:146) Context.toObject does not allow wrapping nulls. JavaAdapter.generateOverride should generate bytecode to check if an argument is null and if it is not call Context.toObject. I'll take a look at fixing this after the other JavaAdapter patches get checked in so we don't get out of sync. Andrew -- Andrew Wason SoftCom, Inc. aw@softcom.com --- js/rhino/org/mozilla/javascript/Context.java | 2 ++ js/rhino/src/org/mozilla/javascript/Context.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/js/rhino/org/mozilla/javascript/Context.java b/js/rhino/org/mozilla/javascript/Context.java index 820f1aaeda97..6dcbf24fcc7f 100644 --- a/js/rhino/org/mozilla/javascript/Context.java +++ b/js/rhino/org/mozilla/javascript/Context.java @@ -1110,6 +1110,8 @@ public final class Context { public static Scriptable toObject(Object value, Scriptable scope, Class staticType) { + if (value == null && staticType != null) + return null; return ScriptRuntime.toObject(scope, value, staticType); } diff --git a/js/rhino/src/org/mozilla/javascript/Context.java b/js/rhino/src/org/mozilla/javascript/Context.java index 820f1aaeda97..6dcbf24fcc7f 100644 --- a/js/rhino/src/org/mozilla/javascript/Context.java +++ b/js/rhino/src/org/mozilla/javascript/Context.java @@ -1110,6 +1110,8 @@ public final class Context { public static Scriptable toObject(Object value, Scriptable scope, Class staticType) { + if (value == null && staticType != null) + return null; return ScriptRuntime.toObject(scope, value, staticType); }