JDK-8015969.js revision 974:57500636de77
1326938Sdim/* 2326938Sdim * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3353358Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4353358Sdim * 5353358Sdim * This code is free software; you can redistribute it and/or modify it 6326938Sdim * under the terms of the GNU General Public License version 2 only, as 7326938Sdim * published by the Free Software Foundation. 8326938Sdim * 9326938Sdim * This code is distributed in the hope that it will be useful, but WITHOUT 10326938Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11326938Sdim * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12326938Sdim * version 2 for more details (a copy is included in the LICENSE file that 13326938Sdim * accompanied this code). 14326938Sdim * 15326938Sdim * You should have received a copy of the GNU General Public License version 16326938Sdim * 2 along with this work; if not, write to the Free Software Foundation, 17326938Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18326938Sdim * 19326938Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20326938Sdim * or visit www.oracle.com if you need additional information or have any 21326938Sdim * questions. 22326938Sdim */ 23326938Sdim 24326938Sdim/** 25326938Sdim * JDK-8015969: Needs to enforce and document that global "context" and "engine" can't be modified when running via jsr223 26326938Sdim * 27341825Sdim * @test 28326938Sdim * @option -scripting 29326938Sdim * @run 30326938Sdim */ 31326938Sdim 32326938Sdimvar m = new javax.script.ScriptEngineManager(); 33326938Sdimvar e = m.getEngineByName("nashorn"); 34326938Sdim 35326938Sdime.eval(<<EOF 36326938Sdim 37326938Sdim'use strict'; 38326938Sdim 39326938Sdimtry { 40326938Sdim context = 444; 41326938Sdim print("FAILED!! context write should have thrown error"); 42326938Sdim} catch (e) { 43326938Sdim if (! (e instanceof TypeError)) { 44326938Sdim print("TypeError expected but got " + e); 45326938Sdim } 46326938Sdim} 47326938Sdim 48326938Sdimtry { 49326938Sdim engine = "hello"; 50326938Sdim print("FAILED!! engine write should have thrown error"); 51326938Sdim} catch (e) { 52326938Sdim if (! (e instanceof TypeError)) { 53326938Sdim print("TypeError expected but got " + e); 54326938Sdim } 55326938Sdim} 56326938Sdim 57326938Sdimtry { 58326938Sdim delete context; 59326938Sdim print("FAILED!! context delete should have thrown error"); 60326938Sdim} catch (e) { 61326938Sdim if (! (e instanceof SyntaxError)) { 62326938Sdim print("SyntaxError expected but got " + e); 63326938Sdim } 64326938Sdim} 65326938Sdim 66326938Sdimtry { 67326938Sdim delete engine; 68326938Sdim print("FAILED!! engine delete should have thrown error"); 69326938Sdim} catch (e) { 70326938Sdim if (! (e instanceof SyntaxError)) { 71326938Sdim print("SyntaxError expected but got " + e); 72326938Sdim } 73326938Sdim} 74326938Sdim 75326938SdimEOF); 76326938Sdim