hannesw@582: /* hannesw@582: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. hannesw@582: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. attila@962: * hannesw@582: * This code is free software; you can redistribute it and/or modify it hannesw@582: * under the terms of the GNU General Public License version 2 only, as hannesw@582: * published by the Free Software Foundation. attila@962: * hannesw@582: * This code is distributed in the hope that it will be useful, but WITHOUT hannesw@582: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or hannesw@582: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License hannesw@582: * version 2 for more details (a copy is included in the LICENSE file that hannesw@582: * accompanied this code). attila@962: * hannesw@582: * You should have received a copy of the GNU General Public License version hannesw@582: * 2 along with this work; if not, write to the Free Software Foundation, hannesw@582: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. attila@962: * hannesw@582: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA hannesw@582: * or visit www.oracle.com if you need additional information or have any hannesw@582: * questions. hannesw@582: */ hannesw@582: hannesw@582: /** hannesw@582: * JDK-8025515: Performance issues with Source.getLine() hannesw@582: * hannesw@582: * @test hannesw@582: * @run hannesw@582: */ hannesw@582: hannesw@582: // Make sure synthetic names of anonymous functions have correct line numbers hannesw@582: sundar@750: function getFirstScriptFrame(stack) { sundar@750: for (frameNum in stack) { sundar@750: var frame = stack[frameNum]; sundar@750: if (frame.className.startsWith("jdk.nashorn.internal.scripts.Script$")) { sundar@750: return frame; sundar@750: } sundar@750: } sundar@750: } sundar@750: hannesw@582: function testMethodName(f, expected) { hannesw@582: try { hannesw@582: f(); hannesw@582: fail("expected error"); hannesw@582: } catch (e) { sundar@750: var stack = e.nashornException.getStackTrace(); sundar@750: var name = getFirstScriptFrame(stack).methodName; sundar@750: if (name !== expected) { attila@963: fail("got " + name + ", expected " + expected); hannesw@582: } hannesw@582: } hannesw@582: } hannesw@582: hannesw@582: testMethodName(function() { hannesw@582: return a.b.c; sundar@750: }, "L:55"); hannesw@582: sundar@750: testMethodName(function() { throw new Error() }, "L:59"); hannesw@582: hannesw@582: var f = (function() { hannesw@582: return function() { a.b.c; }; hannesw@582: })(); hannesw@1829: testMethodName(f, "f#L:62"); hannesw@582: hannesw@582: testMethodName((function() { hannesw@582: return function() { return a.b.c; }; hannesw@1829: })(), "L:66#L:67");