提交 c5a32e42 编写于 作者: S sundar

8012164: Error.stack needs trimming

Reviewed-by: lagergren, jlaskey
上级 e416912d
......@@ -32,6 +32,7 @@ import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
import jdk.nashorn.internal.codegen.CompilerConstants;
import jdk.nashorn.internal.objects.annotations.Attribute;
import jdk.nashorn.internal.objects.annotations.Constructor;
import jdk.nashorn.internal.objects.annotations.Function;
......@@ -248,7 +249,13 @@ public final class NativeError extends ScriptObject {
final List<StackTraceElement> filtered = new ArrayList<>();
for (final StackTraceElement st : frames) {
if (ECMAErrors.isScriptFrame(st)) {
filtered.add(st);
final String className = "<" + st.getFileName() + ">";
String methodName = st.getMethodName();
if (methodName.equals(CompilerConstants.RUN_SCRIPT.symbolName())) {
methodName = "<program>";
}
filtered.add(new StackTraceElement(className, methodName,
st.getFileName(), st.getLineNumber()));
}
}
res = filtered.toArray();
......
/*
* 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-8012164: Error.stack needs trimming
*
* @test
* @run
*/
function func() {
error();
}
function error() {
try {
throw new Error('foo');
} catch (e) {
for (i in e.stack) {
print(e.stack[i]);
}
}
}
func();
<test/script/basic/JDK-8012164.js>.error(test/script/basic/JDK-8012164.js:38)
<test/script/basic/JDK-8012164.js>.func(test/script/basic/JDK-8012164.js:33)
<test/script/basic/JDK-8012164.js>.<program>(test/script/basic/JDK-8012164.js:46)
runScript 33
runScript 32
<program> 33
<program> 32
done
func3 : 40
func2 : 36
func1 : 32
runScript : 44
<program> : 44
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册