aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorsundar <none@none>2013-12-19 21:53:27 +0530
committersundar <none@none>2013-12-19 21:53:27 +0530
commitf4d9ee99925c6eae5f2423d9ea654f72efa9b310 (patch)
tree1b97b6f17ddeaab6e6c79e4cff798219d53f3e73 /test
parent0d50a039141fbe71f1c6d4be53ab807f16382c2c (diff)
downloadnashorn-f4d9ee99925c6eae5f2423d9ea654f72efa9b310.tar.gz
8030809: Anonymous functions should not be shown with internal names in script stack trace
Reviewed-by: lagergren, hannesw, jlaskey
Diffstat (limited to 'test')
-rw-r--r--test/script/basic/JDK-8025515.js22
-rw-r--r--test/script/basic/JDK-8030809.js41
-rw-r--r--test/script/basic/JDK-8030809.js.EXPECTED4
3 files changed, 61 insertions, 6 deletions
diff --git a/test/script/basic/JDK-8025515.js b/test/script/basic/JDK-8025515.js
index f3d7cee4..29574d2a 100644
--- a/test/script/basic/JDK-8025515.js
+++ b/test/script/basic/JDK-8025515.js
@@ -30,13 +30,23 @@
// Make sure synthetic names of anonymous functions have correct line numbers
+function getFirstScriptFrame(stack) {
+ for (frameNum in stack) {
+ var frame = stack[frameNum];
+ if (frame.className.startsWith("jdk.nashorn.internal.scripts.Script$")) {
+ return frame;
+ }
+ }
+}
+
function testMethodName(f, expected) {
try {
f();
fail("expected error");
} catch (e) {
- var stack = e.getStackTrace();
- if (stack[0].methodName !== expected) {
+ var stack = e.nashornException.getStackTrace();
+ var name = getFirstScriptFrame(stack).methodName;
+ if (name !== expected) {
fail("got " + stack[0].methodName + ", expected " + expected);
}
}
@@ -44,15 +54,15 @@ function testMethodName(f, expected) {
testMethodName(function() {
return a.b.c;
-}, "_L45");
+}, "L:55");
-testMethodName(function() { throw new Error() }, "_L49");
+testMethodName(function() { throw new Error() }, "L:59");
var f = (function() {
return function() { a.b.c; };
})();
-testMethodName(f, "_L51$_L52");
+testMethodName(f, "L:61$L:62");
testMethodName((function() {
return function() { return a.b.c; };
-})(), "_L56$_L57");
+})(), "L:66$L:67");
diff --git a/test/script/basic/JDK-8030809.js b/test/script/basic/JDK-8030809.js
new file mode 100644
index 00000000..01c7687c
--- /dev/null
+++ b/test/script/basic/JDK-8030809.js
@@ -0,0 +1,41 @@
+/*
+ * 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-8030809: Anonymous functions should not be shown with internal names in script stack trace
+ *
+ * @test
+ * @run
+ */
+
+function func() {
+ (function() {
+ throw new Error();
+ })();
+}
+
+try {
+ func();
+} catch (e) {
+ print(e.stack.replace(/\\/g, '/'));
+}
diff --git a/test/script/basic/JDK-8030809.js.EXPECTED b/test/script/basic/JDK-8030809.js.EXPECTED
new file mode 100644
index 00000000..6d2ee69b
--- /dev/null
+++ b/test/script/basic/JDK-8030809.js.EXPECTED
@@ -0,0 +1,4 @@
+Error
+ at <anonymous> (test/script/basic/JDK-8030809.js:33)
+ at func (test/script/basic/JDK-8030809.js:32)
+ at <program> (test/script/basic/JDK-8030809.js:38)