sundar@1013: /* sundar@1013: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. sundar@1013: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sundar@1013: * sundar@1013: * This code is free software; you can redistribute it and/or modify it sundar@1013: * under the terms of the GNU General Public License version 2 only, as sundar@1013: * published by the Free Software Foundation. sundar@1013: * sundar@1013: * This code is distributed in the hope that it will be useful, but WITHOUT sundar@1013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sundar@1013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sundar@1013: * version 2 for more details (a copy is included in the LICENSE file that sundar@1013: * accompanied this code). sundar@1013: * sundar@1013: * You should have received a copy of the GNU General Public License version sundar@1013: * 2 along with this work; if not, write to the Free Software Foundation, sundar@1013: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sundar@1013: * sundar@1013: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sundar@1013: * or visit www.oracle.com if you need additional information or have any sundar@1013: * questions. sundar@1013: */ sundar@1013: sundar@1013: /** sundar@1013: * JDK-8058422: Users should be able to overwrite "context" and "engine" variables sundar@1013: * sundar@1013: * @test sundar@1013: * @run sundar@1013: */ sundar@1013: sundar@1013: var m = new javax.script.ScriptEngineManager(); sundar@1013: var e = m.getEngineByName("nashorn"); sundar@1013: e.put("foo", "hello"); sundar@1013: var obj = e.eval("context.getAttribute('foo')"); sundar@1013: if (obj != "hello") { sundar@1013: fail("Expected 'obj' to be 'hello'"); sundar@1013: } sundar@1013: sundar@1013: e.put("context", "bar"); sundar@1013: if (e.eval("context") != "bar") { sundar@1013: fail("Expected 'context' to be 'bar'"); sundar@1013: } sundar@1013: sundar@1013: if (e.eval("foo") != "hello") { sundar@1013: fail("Expected 'foo' to be 'hello'"); sundar@1013: } sundar@1013: sundar@1013: if (e.eval("engine") != e) { sundar@1013: fail("'engine' is not evaluaed to current engine"); sundar@1013: } sundar@1013: sundar@1013: e.put("engine", "foobar"); sundar@1013: if (e.eval("engine") != "foobar") { sundar@1013: fail("'engine' is not evalued to 'foobar'"); sundar@1013: }