JDK-8015969.js revision 980:0f91116bb4bd
1296177Sjhibbits/*
2296177Sjhibbits * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3296177Sjhibbits * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4296177Sjhibbits *
5296177Sjhibbits * This code is free software; you can redistribute it and/or modify it
6296177Sjhibbits * under the terms of the GNU General Public License version 2 only, as
7296177Sjhibbits * published by the Free Software Foundation.
8296177Sjhibbits *
9296177Sjhibbits * This code is distributed in the hope that it will be useful, but WITHOUT
10296177Sjhibbits * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11296177Sjhibbits * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12296177Sjhibbits * version 2 for more details (a copy is included in the LICENSE file that
13296177Sjhibbits * accompanied this code).
14296177Sjhibbits *
15296177Sjhibbits * You should have received a copy of the GNU General Public License version
16296177Sjhibbits * 2 along with this work; if not, write to the Free Software Foundation,
17296177Sjhibbits * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18296177Sjhibbits *
19296177Sjhibbits * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20296177Sjhibbits * or visit www.oracle.com if you need additional information or have any
21296177Sjhibbits * questions.
22296177Sjhibbits */
23296177Sjhibbits
24296177Sjhibbits/**
25296177Sjhibbits * JDK-8015969: Needs to enforce and document that global "context" and "engine" can't be modified when running via jsr223
26296177Sjhibbits *
27296177Sjhibbits * @test
28296177Sjhibbits * @option -scripting
29296177Sjhibbits * @run
30296177Sjhibbits */
31296177Sjhibbits
32296177Sjhibbitsvar m = new javax.script.ScriptEngineManager();
33296177Sjhibbitsvar e = m.getEngineByName("nashorn");
34296177Sjhibbits
35296177Sjhibbitse.put("fail", fail);
36296177Sjhibbitse.eval(<<EOF
37296177Sjhibbits
38296177Sjhibbits'use strict';
39296177Sjhibbits
40296177Sjhibbitstry {
41296177Sjhibbits    delete context;
42296177Sjhibbits    fail("FAILED!! context delete should have thrown error");
43296177Sjhibbits} catch (e) {
44296177Sjhibbits    if (! (e instanceof SyntaxError)) {
45296177Sjhibbits        fail("SyntaxError expected but got " + e);
46296177Sjhibbits    }
47296177Sjhibbits}
48296177Sjhibbits
49296177Sjhibbitstry {
50296177Sjhibbits    delete engine;
51296177Sjhibbits    fail("FAILED!! engine delete should have thrown error");
52296177Sjhibbits} catch (e) {
53296177Sjhibbits    if (! (e instanceof SyntaxError)) {
54296177Sjhibbits        fail("SyntaxError expected but got " + e);
55296177Sjhibbits    }
56296177Sjhibbits}
57296177Sjhibbits
58296177SjhibbitsEOF);
59296177Sjhibbits