Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6346732

can't assign undefined or null value to JavaScript global variables

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 6
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b63
    • CPU:
      generic
    • OS:
      generic

      Description

      JavaScript has two special values 'null' and 'undefined' respectively. It should be possible to assign these values for global (or local) variables. This can be seen by following jrunscript sessions:

      ./jrunscript
      js> var v = null
      js> v
      script error: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "v" is not defined. (<STDIN>#1) in <STDIN> at line number 1
      js>quit()

      ./jrunscript
      js> var u = undefined
      js> u
      script error: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "u" is not defined. (<STDIN>#1) in <STDIN> at line number 1
      js>quit()
      In fact, these are allowed for local variables as shown by following jrunscript sessions:

      ./jrunscript
      js> function f() { var v = null; print(v); }
      js> f()
      null
      js>quit()

      ./jrunscript
      js> function g() { var u = undefined; print(u); }
      js> g()
      undefined
      js>quit()

      These are problems with API implementation rather than jrunscript tool. This can be verified by a simple program as below:

      import javax.script.*;

      public class t {
              public static void main(String[] args) throws Exception {
                      ScriptEngineManager m = new ScriptEngineManager();
                      ScriptEngine e = m.getEngineByName("js");
                      e.eval("x = null; print(x)");
              }
      }


      or

      import javax.script.*;

      public class t {
              public static void main(String[] args) throws Exception {
                      ScriptEngineManager m = new ScriptEngineManager();
                      ScriptEngine e = m.getEngineByName("js");
                      e.eval("x = undefined; print(x);");
              }
      }


      Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "x" is not defined. (<Unknown source>#1) in <Unknown source> at line number 1

      is thrown with these programs.

        Attachments

          Activity

            People

            • Assignee:
              sundar Sundararajan Athijegannathan
              Reporter:
              sundar Sundararajan Athijegannathan
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: