test/script/basic/JDK-8156896.js

Fri, 13 May 2016 14:30:54 +0200

author
hannesw
date
Fri, 13 May 2016 14:30:54 +0200
changeset 1829
ee0bd940c2bd
permissions
-rw-r--r--

8156896: Script stack trace should display function names
Reviewed-by: attila, sundar

hannesw@1829 1 /*
hannesw@1829 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
hannesw@1829 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
hannesw@1829 4 *
hannesw@1829 5 * This code is free software; you can redistribute it and/or modify it
hannesw@1829 6 * under the terms of the GNU General Public License version 2 only, as
hannesw@1829 7 * published by the Free Software Foundation.
hannesw@1829 8 *
hannesw@1829 9 * This code is distributed in the hope that it will be useful, but WITHOUT
hannesw@1829 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
hannesw@1829 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
hannesw@1829 12 * version 2 for more details (a copy is included in the LICENSE file that
hannesw@1829 13 * accompanied this code).
hannesw@1829 14 *
hannesw@1829 15 * You should have received a copy of the GNU General Public License version
hannesw@1829 16 * 2 along with this work; if not, write to the Free Software Foundation,
hannesw@1829 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
hannesw@1829 18 *
hannesw@1829 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
hannesw@1829 20 * or visit www.oracle.com if you need additional information or have any
hannesw@1829 21 * questions.
hannesw@1829 22 */
hannesw@1829 23
hannesw@1829 24 /**
hannesw@1829 25 * JDK-8156896: Script stack trace should display function names
hannesw@1829 26 *
hannesw@1829 27 * @test
hannesw@1829 28 * @run
hannesw@1829 29 */
hannesw@1829 30
hannesw@1829 31 function checkNamedFunction(stack) {
hannesw@1829 32 Assert.assertTrue(stack.indexOf("Error\n\tat bar (") === 0);
hannesw@1829 33 }
hannesw@1829 34
hannesw@1829 35 function checkAnonymousFunction(stack) {
hannesw@1829 36 Assert.assertTrue(stack.indexOf("Error\n\tat <anonymous> (") === 0);
hannesw@1829 37 }
hannesw@1829 38
hannesw@1829 39 // Named functions
hannesw@1829 40 function bar() { try { throw new Error(); } catch(e) { return e.stack; } }
hannesw@1829 41 checkNamedFunction(bar());
hannesw@1829 42
hannesw@1829 43 bar = function() { try { throw new Error(); } catch(e) { return e.stack; } };
hannesw@1829 44 checkNamedFunction(bar());
hannesw@1829 45
hannesw@1829 46 f = (function() {return function bar() { try { throw new Error(); } catch(e) { return e.stack; } } })();
hannesw@1829 47 checkNamedFunction(f());
hannesw@1829 48
hannesw@1829 49 f = new Function("return function bar() { try { throw new Error(); } catch(e) { return e.stack; } }")();
hannesw@1829 50 checkNamedFunction(f());
hannesw@1829 51
hannesw@1829 52 // Anonymous functions
hannesw@1829 53 checkAnonymousFunction((function() { try { throw new Error(); } catch(e) { return e.stack; } })());
hannesw@1829 54
hannesw@1829 55 f = (function() {return function() { try { throw new Error(); } catch(e) { return e.stack; } } })();
hannesw@1829 56 checkAnonymousFunction(f());
hannesw@1829 57
hannesw@1829 58 f = new Function("return function() { try { throw new Error(); } catch(e) { return e.stack; } }")();
hannesw@1829 59 checkAnonymousFunction(f());

mercurial