test/script/basic/JDK-8025515.js

Print this page
rev 739 : 8030809: Anonymous functions should not be shown with internal names in script stack trace
Reviewed-by: lagergren, hannesw, jlaskey

*** 28,58 **** * @run */ // Make sure synthetic names of anonymous functions have correct line numbers function testMethodName(f, expected) { try { f(); fail("expected error"); } catch (e) { ! var stack = e.getStackTrace(); ! if (stack[0].methodName !== expected) { fail("got " + stack[0].methodName + ", expected " + expected); } } } testMethodName(function() { return a.b.c; ! }, "_L45"); ! testMethodName(function() { throw new Error() }, "_L49"); var f = (function() { return function() { a.b.c; }; })(); ! testMethodName(f, "_L51$_L52"); testMethodName((function() { return function() { return a.b.c; }; ! })(), "_L56$_L57"); --- 28,68 ---- * @run */ // 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.nashornException.getStackTrace(); ! var name = getFirstScriptFrame(stack).methodName; ! if (name !== expected) { fail("got " + stack[0].methodName + ", expected " + expected); } } } testMethodName(function() { return a.b.c; ! }, "L:55"); ! testMethodName(function() { throw new Error() }, "L:59"); var f = (function() { return function() { a.b.c; }; })(); ! testMethodName(f, "L:61$L:62"); testMethodName((function() { return function() { return a.b.c; }; ! })(), "L:66$L:67");