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

megamorphic getter for scope objects does not call __noSuchProperty__ hook

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 8u20, 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b17
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        The following code works on jdk8 and jdk8u5 - but fails on jdk8u20 and jdk9. So, it is a regression due to recent jdk8u and jdk9 changes:

        ---- File: Main.java ----

        import javax.script.*;

        public class Main {
          public static void main(String[] args) throws Exception {
            ScriptEngineManager m = new ScriptEngineManager();
            ScriptEngine engine = m.getEngineByName("nashorn");
            for (int index = 0; index < 20; index++) {
                final Bindings bindings = new SimpleBindings();
                bindings.put("foo", index);
                String script = "print(foo)";
                engine.eval(script, bindings);
            }
          }
        }

        --- Main.java ends ----

        jdk9 failure stack trace looks as follows:

        0
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        Exception in thread "main" javax.script.ScriptException: ReferenceError: "foo" is not defined in <eval> at line number 1
        at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:586)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:570)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:525)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:521)
        at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:192)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
        at Main.main(Main.java:11)
        Caused by: <eval>:1 ReferenceError: "foo" is not defined
        at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:58)
        at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:320)
        at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:292)
        at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:279)
        at jdk.nashorn.internal.runtime.ScriptObject.megamorphicGet(ScriptObject.java:2000)
        at jdk.nashorn.internal.scripts.Script$1$\^eval\_.:program(<eval>:1)
        at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:565)
        at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:221)
        at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:374)
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:568)
        ... 5 more


        Another test that is independent of javax.script API is as follows:

        ----- File: x.js -------

        __noSuchProperty__ = function(name) {
            return 1;
        }

        function func(obj) {
            with(obj) {
                foo;
            }
        }

        for (var i = 0; i < 20; i++) {
            var obj = {};
            obj.foo = i;
            obj[i] = i;
            func(obj);
        }

        func({});

        ---- x.js ends ----------

        In jdk8 and jdk8u5, no error with that script. But with jdk9 and jdk8u20, we get:

        x.js:7 ReferenceError: "foo" is not defined

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved: