Wed, 05 Sep 2018 01:21:35 -0700
Added tag jdk8u192-b09 for changeset 456c0d45c43b
hannesw@582 | 1 | /* |
hannesw@582 | 2 | * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
hannesw@582 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
attila@962 | 4 | * |
hannesw@582 | 5 | * This code is free software; you can redistribute it and/or modify it |
hannesw@582 | 6 | * under the terms of the GNU General Public License version 2 only, as |
hannesw@582 | 7 | * published by the Free Software Foundation. |
attila@962 | 8 | * |
hannesw@582 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
hannesw@582 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
hannesw@582 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
hannesw@582 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
hannesw@582 | 13 | * accompanied this code). |
attila@962 | 14 | * |
hannesw@582 | 15 | * You should have received a copy of the GNU General Public License version |
hannesw@582 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
hannesw@582 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
attila@962 | 18 | * |
hannesw@582 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
hannesw@582 | 20 | * or visit www.oracle.com if you need additional information or have any |
hannesw@582 | 21 | * questions. |
hannesw@582 | 22 | */ |
hannesw@582 | 23 | |
hannesw@582 | 24 | /** |
hannesw@582 | 25 | * JDK-8025515: Performance issues with Source.getLine() |
hannesw@582 | 26 | * |
hannesw@582 | 27 | * @test |
hannesw@582 | 28 | * @run |
hannesw@582 | 29 | */ |
hannesw@582 | 30 | |
hannesw@582 | 31 | // Make sure synthetic names of anonymous functions have correct line numbers |
hannesw@582 | 32 | |
sundar@750 | 33 | function getFirstScriptFrame(stack) { |
sundar@750 | 34 | for (frameNum in stack) { |
sundar@750 | 35 | var frame = stack[frameNum]; |
sundar@750 | 36 | if (frame.className.startsWith("jdk.nashorn.internal.scripts.Script$")) { |
sundar@750 | 37 | return frame; |
sundar@750 | 38 | } |
sundar@750 | 39 | } |
sundar@750 | 40 | } |
sundar@750 | 41 | |
hannesw@582 | 42 | function testMethodName(f, expected) { |
hannesw@582 | 43 | try { |
hannesw@582 | 44 | f(); |
hannesw@582 | 45 | fail("expected error"); |
hannesw@582 | 46 | } catch (e) { |
sundar@750 | 47 | var stack = e.nashornException.getStackTrace(); |
sundar@750 | 48 | var name = getFirstScriptFrame(stack).methodName; |
sundar@750 | 49 | if (name !== expected) { |
attila@963 | 50 | fail("got " + name + ", expected " + expected); |
hannesw@582 | 51 | } |
hannesw@582 | 52 | } |
hannesw@582 | 53 | } |
hannesw@582 | 54 | |
hannesw@582 | 55 | testMethodName(function() { |
hannesw@582 | 56 | return a.b.c; |
sundar@750 | 57 | }, "L:55"); |
hannesw@582 | 58 | |
sundar@750 | 59 | testMethodName(function() { throw new Error() }, "L:59"); |
hannesw@582 | 60 | |
hannesw@582 | 61 | var f = (function() { |
hannesw@582 | 62 | return function() { a.b.c; }; |
hannesw@582 | 63 | })(); |
hannesw@1829 | 64 | testMethodName(f, "f#L:62"); |
hannesw@582 | 65 | |
hannesw@582 | 66 | testMethodName((function() { |
hannesw@582 | 67 | return function() { return a.b.c; }; |
hannesw@1829 | 68 | })(), "L:66#L:67"); |