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

TypeError: undefined is not an Object after JDK-8240299

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • None
    • None
    • core-libs
    • None

    Description

      The following program is accepted by the version of nashorn that shipped in JDK 14, but rejected by the latest version of org.openjdk.nashorn.

      My colleague Nicholas Burbaum found that the commit that changed this behaviour is https://github.com/openjdk/nashorn/commit/9b87e5dadcabdf4965a278a4f090c0fffbbd60b7, and minimized the repro. He also mentioned that the fix might be to check against check against "obj" instead of "self".

      ```
      import org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory;

      class NashornTest {

        public static void main(String[] args) throws Exception {
          String js = "var objectSetPrototypeOf = Object.setPrototypeOf; objectSetPrototypeOf({}, {});";
          new NashornScriptEngineFactory().getScriptEngine().eval(js);
        }
      }
      ```

      java -cp nashorn-core-15.3.jar:asm-9.2.jar:asm-util-9.2.jar:. NashornTest
      Exception in thread "main" javax.script.ScriptException: TypeError: undefined is not an Object in <eval> at line number 1
      at org.openjdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:463)
      at org.openjdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:447)
      at org.openjdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)
      at org.openjdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:395)
      at org.openjdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:151)
      at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
      at NashornTest.main(NashornTest.java:7)
      Caused by: <eval>:1 TypeError: undefined is not an Object
      at org.openjdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
      at org.openjdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:212)
      at org.openjdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:184)
      at org.openjdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:171)
      at org.openjdk.nashorn.internal.objects.Global.checkObjectCoercible(Global.java:2391)
      at org.openjdk.nashorn.internal.objects.NativeObject.setPrototypeOf(NativeObject.java:201)
      at org.openjdk.nashorn.internal.scripts.Script$\^eval\_/0x0000000800c8e840.:program(<eval>:1)
      at org.openjdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:646)
      at org.openjdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
      at org.openjdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:520)
      at org.openjdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:442)
      ... 5 more

      Attachments

        Activity

          People

            attila Attila Szegedi
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: