8030182: scopeCall with -1 as line number
authorsundar
Mon, 16 Dec 2013 23:25:50 +0530
changeset 22373 ca044992c73f
parent 22372 cedd324ae5b2
child 22374 5231ab59e740
8030182: scopeCall with -1 as line number Reviewed-by: hannesw, jlaskey
nashorn/src/jdk/nashorn/internal/codegen/CodeGeneratorLexicalContext.java
nashorn/src/jdk/nashorn/internal/codegen/CompilerConstants.java
nashorn/src/jdk/nashorn/internal/runtime/ECMAErrors.java
nashorn/test/script/basic/JDK-8030182.js
nashorn/test/script/basic/JDK-8030182.js.EXPECTED
nashorn/test/script/basic/JDK-8030182_2.js
nashorn/test/script/basic/JDK-8030182_2.js.EXPECTED
--- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGeneratorLexicalContext.java	Mon Dec 16 18:32:50 2013 +0530
+++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGeneratorLexicalContext.java	Mon Dec 16 23:25:50 2013 +0530
@@ -158,7 +158,7 @@
         if (scopeCalls.containsKey(scopeCall)) {
             return scopeCalls.get(scopeCall);
         }
-        scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName("scopeCall"));
+        scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName(":scopeCall"));
         scopeCalls.put(scopeCall, scopeCall);
         return scopeCall;
     }
@@ -177,7 +177,7 @@
         if (scopeCalls.containsKey(scopeCall)) {
             return scopeCalls.get(scopeCall);
         }
-        scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName("scopeCall"));
+        scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName(":scopeCall"));
         scopeCalls.put(scopeCall, scopeCall);
         return scopeCall;
     }
--- a/nashorn/src/jdk/nashorn/internal/codegen/CompilerConstants.java	Mon Dec 16 18:32:50 2013 +0530
+++ b/nashorn/src/jdk/nashorn/internal/codegen/CompilerConstants.java	Mon Dec 16 23:25:50 2013 +0530
@@ -41,6 +41,7 @@
  */
 
 public enum CompilerConstants {
+
     /** the __FILE__ variable */
     __FILE__,
 
@@ -75,7 +76,7 @@
     DEFAULT_SCRIPT_NAME("Script"),
 
     /** function prefix for anonymous functions */
-    FUNCTION_PREFIX("function$"),
+    FUNCTION_PREFIX(":function$"),
 
     /** method name for Java method that is script entry point */
     RUN_SCRIPT("runScript"),
@@ -149,26 +150,31 @@
     ALLOCATE("allocate"),
 
     /** prefix for split methods, @see Splitter */
-    SPLIT_PREFIX("$split"),
+    SPLIT_PREFIX(":split"),
 
     /** prefix for split array method and slot */
-    SPLIT_ARRAY_ARG("split_array", 3),
+    SPLIT_ARRAY_ARG(":split_array", 3),
 
     /** get string from constant pool */
-    GET_STRING("$getString"),
+    GET_STRING(":getString"),
 
     /** get map */
-    GET_MAP("$getMap"),
+    GET_MAP(":getMap"),
 
     /** get map */
-    SET_MAP("$setMap"),
+    SET_MAP(":setMap"),
 
     /** get array prefix */
-    GET_ARRAY_PREFIX("$get"),
+    GET_ARRAY_PREFIX(":get"),
 
     /** get array suffix */
     GET_ARRAY_SUFFIX("$array");
 
+    /**
+     * Prefix used for internal methods generated in script clases.
+     */
+    public static final String INTERNAL_METHOD_PREFIX = ":";
+
     private final String symbolName;
     private final Class<?> type;
     private final int slot;
--- a/nashorn/src/jdk/nashorn/internal/runtime/ECMAErrors.java	Mon Dec 16 18:32:50 2013 +0530
+++ b/nashorn/src/jdk/nashorn/internal/runtime/ECMAErrors.java	Mon Dec 16 23:25:50 2013 +0530
@@ -30,6 +30,7 @@
 import java.util.ResourceBundle;
 import jdk.nashorn.api.scripting.NashornException;
 import jdk.nashorn.internal.scripts.JS;
+import jdk.nashorn.internal.codegen.CompilerConstants;
 
 /**
  * Helper class to throw various standard "ECMA error" exceptions such as Error, ReferenceError, TypeError etc.
@@ -401,7 +402,7 @@
         final String className = frame.getClassName();
 
         // Look for script package in class name (into which compiler puts generated code)
-        if (className.startsWith(scriptPackage)) {
+        if (className.startsWith(scriptPackage) && !frame.getMethodName().startsWith(CompilerConstants.INTERNAL_METHOD_PREFIX)) {
             final String source = frame.getFileName();
             /*
              * Make sure that it is not some Java code that Nashorn has in that package!
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8030182.js	Mon Dec 16 23:25:50 2013 +0530
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2010, 2013, 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-8030182: scopeCall with -1 as line number
+ *
+ * @test
+ * @run
+ */
+
+function func() {
+    throw new Error("Strange...");
+}
+
+var f2 = func;
+var f3 = func;
+var f4 = func;
+var f5 = func;
+
+// check that "scopeCall" or some such internal method
+// does not appear in script stack trace.
+try {
+    func();
+} catch(err) {
+    print(err.stack.replace(/\\/g, '/'));
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8030182.js.EXPECTED	Mon Dec 16 23:25:50 2013 +0530
@@ -0,0 +1,3 @@
+Error: Strange...
+	at func (test/script/basic/JDK-8030182.js:32)
+	at <program> (test/script/basic/JDK-8030182.js:43)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8030182_2.js	Mon Dec 16 23:25:50 2013 +0530
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2010, 2013, 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-8030182: scopeCall with -1 as line number
+ *
+ * @test
+ * @run
+ */
+
+var str = ""; 
+
+// large code to force splitting
+for (i = 0; i < 1000; ++i) 
+    str +="o = new Object()\n";
+
+str +="g()"; 
+
+// check that "$split" or some such internal method
+// does not appear in script stack trace!!
+try {
+    eval(str);
+} catch (e) {
+    print(e.stack.replace(/\\/g, '/'));
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8030182_2.js.EXPECTED	Mon Dec 16 23:25:50 2013 +0530
@@ -0,0 +1,3 @@
+ReferenceError: "g" is not defined
+	at <program> (test/script/basic/JDK-8030182_2.js#42:4<eval>@0:-1)
+	at <program> (test/script/basic/JDK-8030182_2.js:42)