8184241: Fix nashorn/samples/filebrowser.js
Summary: Fixed global/delegate field issue in case of overridden method called from super constructor
Reviewed-by: hannesw, jlaskey
Contributed-by: srinivas.dama@oracle.com
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java Thu Aug 24 16:29:53 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java Thu Jul 20 19:56:34 2017 +0530
@@ -666,7 +666,6 @@
// Load the creatingGlobal object
loadField(mv, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
-
// stack: [creatingGlobal]
SET_GLOBAL.invoke(mv);
// stack: [runnable]
@@ -727,6 +726,11 @@
}
loadField(mv, DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+ //For the cases like scripted overridden methods invoked from super constructors get adapter global/delegate fields as null, since we
+ //cannot set these fields before invoking super constructor better solution is opt out of scripted overridden method if global/delegate fields
+ //are null and invoke super method instead
+ mv.ifnull(defaultBehavior);
+ loadField(mv, DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
mv.dup();
// stack: [delegate, delegate]
final String encodedName = NameCodec.encode(name);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/nosecurity/JDK-8184241.js Thu Jul 20 19:56:34 2017 +0530
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8184241: Fix nashorn/samples/filebrowser.js
+ *
+ * @test
+ * @run
+ * @option -scripting
+ */
+
+var type = Java.type("jdk.nashorn.test.models.JDK_8184241Test");
+var extendedtype = Java.extend(type);
+try {
+ var obj = new extendedtype({});
+ print("PASS");
+} catch(e) {
+ print("Caught" + e);
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/nosecurity/JDK-8184241.js.EXPECTED Thu Jul 20 19:56:34 2017 +0530
@@ -0,0 +1,1 @@
+PASS
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/src/jdk/nashorn/test/models/JDK_8184241Test.java Thu Jul 20 19:56:34 2017 +0530
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.nashorn.test.models;
+
+public class JDK_8184241Test {
+ public JDK_8184241Test() {
+ foo();
+ }
+ public void foo() {
+ }
+}