mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-26 14:50:34 +00:00
8030182: scopeCall with -1 as line number
Reviewed-by: hannesw, jlaskey
This commit is contained in:
parent
53293af78c
commit
1bef37e215
@ -158,7 +158,7 @@ final class CodeGeneratorLexicalContext extends LexicalContext {
|
||||
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 @@ final class CodeGeneratorLexicalContext extends LexicalContext {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@ import jdk.nashorn.internal.runtime.Source;
|
||||
*/
|
||||
|
||||
public enum CompilerConstants {
|
||||
|
||||
/** the __FILE__ variable */
|
||||
__FILE__,
|
||||
|
||||
@ -75,7 +76,7 @@ public enum CompilerConstants {
|
||||
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 @@ public enum CompilerConstants {
|
||||
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;
|
||||
|
||||
@ -30,6 +30,7 @@ import java.util.Locale;
|
||||
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 @@ public final class ECMAErrors {
|
||||
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!
|
||||
|
||||
46
nashorn/test/script/basic/JDK-8030182.js
Normal file
46
nashorn/test/script/basic/JDK-8030182.js
Normal file
@ -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, '/'));
|
||||
}
|
||||
3
nashorn/test/script/basic/JDK-8030182.js.EXPECTED
Normal file
3
nashorn/test/script/basic/JDK-8030182.js.EXPECTED
Normal file
@ -0,0 +1,3 @@
|
||||
Error: Strange...
|
||||
at func (test/script/basic/JDK-8030182.js:32)
|
||||
at <program> (test/script/basic/JDK-8030182.js:43)
|
||||
46
nashorn/test/script/basic/JDK-8030182_2.js
Normal file
46
nashorn/test/script/basic/JDK-8030182_2.js
Normal file
@ -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, '/'));
|
||||
}
|
||||
|
||||
3
nashorn/test/script/basic/JDK-8030182_2.js.EXPECTED
Normal file
3
nashorn/test/script/basic/JDK-8030182_2.js.EXPECTED
Normal file
@ -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)
|
||||
Loading…
x
Reference in New Issue
Block a user