hannesw@1829: /* hannesw@1829: * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. hannesw@1829: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. hannesw@1829: * hannesw@1829: * This code is free software; you can redistribute it and/or modify it hannesw@1829: * under the terms of the GNU General Public License version 2 only, as hannesw@1829: * published by the Free Software Foundation. hannesw@1829: * hannesw@1829: * This code is distributed in the hope that it will be useful, but WITHOUT hannesw@1829: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or hannesw@1829: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License hannesw@1829: * version 2 for more details (a copy is included in the LICENSE file that hannesw@1829: * accompanied this code). hannesw@1829: * hannesw@1829: * You should have received a copy of the GNU General Public License version hannesw@1829: * 2 along with this work; if not, write to the Free Software Foundation, hannesw@1829: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. hannesw@1829: * hannesw@1829: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA hannesw@1829: * or visit www.oracle.com if you need additional information or have any hannesw@1829: * questions. hannesw@1829: */ hannesw@1829: hannesw@1829: /** hannesw@1829: * JDK-8156896: Script stack trace should display function names hannesw@1829: * hannesw@1829: * @test hannesw@1829: * @run hannesw@1829: */ hannesw@1829: hannesw@1829: function checkNamedFunction(stack) { hannesw@1829: Assert.assertTrue(stack.indexOf("Error\n\tat bar (") === 0); hannesw@1829: } hannesw@1829: hannesw@1829: function checkAnonymousFunction(stack) { hannesw@1829: Assert.assertTrue(stack.indexOf("Error\n\tat (") === 0); hannesw@1829: } hannesw@1829: hannesw@1829: // Named functions hannesw@1829: function bar() { try { throw new Error(); } catch(e) { return e.stack; } } hannesw@1829: checkNamedFunction(bar()); hannesw@1829: hannesw@1829: bar = function() { try { throw new Error(); } catch(e) { return e.stack; } }; hannesw@1829: checkNamedFunction(bar()); hannesw@1829: hannesw@1829: f = (function() {return function bar() { try { throw new Error(); } catch(e) { return e.stack; } } })(); hannesw@1829: checkNamedFunction(f()); hannesw@1829: hannesw@1829: f = new Function("return function bar() { try { throw new Error(); } catch(e) { return e.stack; } }")(); hannesw@1829: checkNamedFunction(f()); hannesw@1829: hannesw@1829: // Anonymous functions hannesw@1829: checkAnonymousFunction((function() { try { throw new Error(); } catch(e) { return e.stack; } })()); hannesw@1829: hannesw@1829: f = (function() {return function() { try { throw new Error(); } catch(e) { return e.stack; } } })(); hannesw@1829: checkAnonymousFunction(f()); hannesw@1829: hannesw@1829: f = new Function("return function() { try { throw new Error(); } catch(e) { return e.stack; } }")(); hannesw@1829: checkAnonymousFunction(f());