Mon, 16 Dec 2013 23:25:50 +0530
8030182: scopeCall with -1 as line number
Reviewed-by: hannesw, jlaskey
1.1 --- a/src/jdk/nashorn/internal/codegen/CodeGeneratorLexicalContext.java Mon Dec 02 18:19:26 2013 +0530 1.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGeneratorLexicalContext.java Mon Dec 16 23:25:50 2013 +0530 1.3 @@ -158,7 +158,7 @@ 1.4 if (scopeCalls.containsKey(scopeCall)) { 1.5 return scopeCalls.get(scopeCall); 1.6 } 1.7 - scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName("scopeCall")); 1.8 + scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName(":scopeCall")); 1.9 scopeCalls.put(scopeCall, scopeCall); 1.10 return scopeCall; 1.11 } 1.12 @@ -177,7 +177,7 @@ 1.13 if (scopeCalls.containsKey(scopeCall)) { 1.14 return scopeCalls.get(scopeCall); 1.15 } 1.16 - scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName("scopeCall")); 1.17 + scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName(":scopeCall")); 1.18 scopeCalls.put(scopeCall, scopeCall); 1.19 return scopeCall; 1.20 }
2.1 --- a/src/jdk/nashorn/internal/codegen/CompilerConstants.java Mon Dec 02 18:19:26 2013 +0530 2.2 +++ b/src/jdk/nashorn/internal/codegen/CompilerConstants.java Mon Dec 16 23:25:50 2013 +0530 2.3 @@ -41,6 +41,7 @@ 2.4 */ 2.5 2.6 public enum CompilerConstants { 2.7 + 2.8 /** the __FILE__ variable */ 2.9 __FILE__, 2.10 2.11 @@ -75,7 +76,7 @@ 2.12 DEFAULT_SCRIPT_NAME("Script"), 2.13 2.14 /** function prefix for anonymous functions */ 2.15 - FUNCTION_PREFIX("function$"), 2.16 + FUNCTION_PREFIX(":function$"), 2.17 2.18 /** method name for Java method that is script entry point */ 2.19 RUN_SCRIPT("runScript"), 2.20 @@ -149,26 +150,31 @@ 2.21 ALLOCATE("allocate"), 2.22 2.23 /** prefix for split methods, @see Splitter */ 2.24 - SPLIT_PREFIX("$split"), 2.25 + SPLIT_PREFIX(":split"), 2.26 2.27 /** prefix for split array method and slot */ 2.28 - SPLIT_ARRAY_ARG("split_array", 3), 2.29 + SPLIT_ARRAY_ARG(":split_array", 3), 2.30 2.31 /** get string from constant pool */ 2.32 - GET_STRING("$getString"), 2.33 + GET_STRING(":getString"), 2.34 2.35 /** get map */ 2.36 - GET_MAP("$getMap"), 2.37 + GET_MAP(":getMap"), 2.38 2.39 /** get map */ 2.40 - SET_MAP("$setMap"), 2.41 + SET_MAP(":setMap"), 2.42 2.43 /** get array prefix */ 2.44 - GET_ARRAY_PREFIX("$get"), 2.45 + GET_ARRAY_PREFIX(":get"), 2.46 2.47 /** get array suffix */ 2.48 GET_ARRAY_SUFFIX("$array"); 2.49 2.50 + /** 2.51 + * Prefix used for internal methods generated in script clases. 2.52 + */ 2.53 + public static final String INTERNAL_METHOD_PREFIX = ":"; 2.54 + 2.55 private final String symbolName; 2.56 private final Class<?> type; 2.57 private final int slot;
3.1 --- a/src/jdk/nashorn/internal/runtime/ECMAErrors.java Mon Dec 02 18:19:26 2013 +0530 3.2 +++ b/src/jdk/nashorn/internal/runtime/ECMAErrors.java Mon Dec 16 23:25:50 2013 +0530 3.3 @@ -30,6 +30,7 @@ 3.4 import java.util.ResourceBundle; 3.5 import jdk.nashorn.api.scripting.NashornException; 3.6 import jdk.nashorn.internal.scripts.JS; 3.7 +import jdk.nashorn.internal.codegen.CompilerConstants; 3.8 3.9 /** 3.10 * Helper class to throw various standard "ECMA error" exceptions such as Error, ReferenceError, TypeError etc. 3.11 @@ -401,7 +402,7 @@ 3.12 final String className = frame.getClassName(); 3.13 3.14 // Look for script package in class name (into which compiler puts generated code) 3.15 - if (className.startsWith(scriptPackage)) { 3.16 + if (className.startsWith(scriptPackage) && !frame.getMethodName().startsWith(CompilerConstants.INTERNAL_METHOD_PREFIX)) { 3.17 final String source = frame.getFileName(); 3.18 /* 3.19 * Make sure that it is not some Java code that Nashorn has in that package!
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/script/basic/JDK-8030182.js Mon Dec 16 23:25:50 2013 +0530 4.3 @@ -0,0 +1,46 @@ 4.4 +/* 4.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/** 4.28 + * JDK-8030182: scopeCall with -1 as line number 4.29 + * 4.30 + * @test 4.31 + * @run 4.32 + */ 4.33 + 4.34 +function func() { 4.35 + throw new Error("Strange..."); 4.36 +} 4.37 + 4.38 +var f2 = func; 4.39 +var f3 = func; 4.40 +var f4 = func; 4.41 +var f5 = func; 4.42 + 4.43 +// check that "scopeCall" or some such internal method 4.44 +// does not appear in script stack trace. 4.45 +try { 4.46 + func(); 4.47 +} catch(err) { 4.48 + print(err.stack.replace(/\\/g, '/')); 4.49 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/script/basic/JDK-8030182.js.EXPECTED Mon Dec 16 23:25:50 2013 +0530 5.3 @@ -0,0 +1,3 @@ 5.4 +Error: Strange... 5.5 + at func (test/script/basic/JDK-8030182.js:32) 5.6 + at <program> (test/script/basic/JDK-8030182.js:43)
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/script/basic/JDK-8030182_2.js Mon Dec 16 23:25:50 2013 +0530 6.3 @@ -0,0 +1,46 @@ 6.4 +/* 6.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + */ 6.26 + 6.27 +/** 6.28 + * JDK-8030182: scopeCall with -1 as line number 6.29 + * 6.30 + * @test 6.31 + * @run 6.32 + */ 6.33 + 6.34 +var str = ""; 6.35 + 6.36 +// large code to force splitting 6.37 +for (i = 0; i < 1000; ++i) 6.38 + str +="o = new Object()\n"; 6.39 + 6.40 +str +="g()"; 6.41 + 6.42 +// check that "$split" or some such internal method 6.43 +// does not appear in script stack trace!! 6.44 +try { 6.45 + eval(str); 6.46 +} catch (e) { 6.47 + print(e.stack.replace(/\\/g, '/')); 6.48 +} 6.49 +
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/script/basic/JDK-8030182_2.js.EXPECTED Mon Dec 16 23:25:50 2013 +0530 7.3 @@ -0,0 +1,3 @@ 7.4 +ReferenceError: "g" is not defined 7.5 + at <program> (test/script/basic/JDK-8030182_2.js#42:4<eval>@0:-1) 7.6 + at <program> (test/script/basic/JDK-8030182_2.js:42)