exit.js revision 877:cf4d2252d444
1243789Sdim/*
2243789Sdim * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3243789Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4243789Sdim *
5243789Sdim * This code is free software; you can redistribute it and/or modify it
6243789Sdim * under the terms of the GNU General Public License version 2 only, as
7243789Sdim * published by the Free Software Foundation.
8243789Sdim *
9243789Sdim * This code is distributed in the hope that it will be useful, but WITHOUT
10243789Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11243789Sdim * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12243789Sdim * version 2 for more details (a copy is included in the LICENSE file that
13243789Sdim * accompanied this code).
14243789Sdim *
15243789Sdim * You should have received a copy of the GNU General Public License version
16243789Sdim * 2 along with this work; if not, write to the Free Software Foundation,
17243789Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18243789Sdim *
19243789Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20243789Sdim * or visit www.oracle.com if you need additional information or have any
21249423Sdim * questions.
22249423Sdim */
23249423Sdim
24249423Sdim/**
25249423Sdim * Try to call System.exit, quit and exit.
26249423Sdim *
27249423Sdim * @test
28249423Sdim * @security
29249423Sdim */
30249423Sdim
31243789Sdimfunction check(e) {
32243789Sdim    if (e instanceof java.lang.SecurityException) {
33243789Sdim        print(e);
34243789Sdim    } else {
35243789Sdim        fail("expected SecurityException, got " + e);
36243789Sdim    }
37243789Sdim}
38243789Sdim
39243789Sdimtry {
40243789Sdim    java.lang.System.exit(0);
41243789Sdim    // will not reach here regardless of outcome..
42243789Sdim} catch (e) {
43249423Sdim    check(e);
44249423Sdim}
45243789Sdim
46243789Sdimtry {
47243789Sdim    quit();
48243789Sdim    // will not reach here regardless of outcome..
49243789Sdim} catch (e) {
50243789Sdim    check(e);
51243789Sdim}
52243789Sdim
53243789Sdimtry {
54243789Sdim    exit(0);
55243789Sdim    // will not reach here regardless of outcome..
56243789Sdim} catch (e) {
57243789Sdim    check(e);
58243789Sdim}
59243789Sdim
60243789Sdimprint("Success, didn't exit!");
61243789Sdim