test/script/basic/JDK-8058422.js

Tue, 21 Mar 2017 13:41:57 -0700

author
asaha
date
Tue, 21 Mar 2017 13:41:57 -0700
changeset 2160
1df40fe54cd6
parent 1013
3ce674906b2a
permissions
-rw-r--r--

Merge

sundar@1013 1 /*
sundar@1013 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
sundar@1013 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sundar@1013 4 *
sundar@1013 5 * This code is free software; you can redistribute it and/or modify it
sundar@1013 6 * under the terms of the GNU General Public License version 2 only, as
sundar@1013 7 * published by the Free Software Foundation.
sundar@1013 8 *
sundar@1013 9 * This code is distributed in the hope that it will be useful, but WITHOUT
sundar@1013 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sundar@1013 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sundar@1013 12 * version 2 for more details (a copy is included in the LICENSE file that
sundar@1013 13 * accompanied this code).
sundar@1013 14 *
sundar@1013 15 * You should have received a copy of the GNU General Public License version
sundar@1013 16 * 2 along with this work; if not, write to the Free Software Foundation,
sundar@1013 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sundar@1013 18 *
sundar@1013 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sundar@1013 20 * or visit www.oracle.com if you need additional information or have any
sundar@1013 21 * questions.
sundar@1013 22 */
sundar@1013 23
sundar@1013 24 /**
sundar@1013 25 * JDK-8058422: Users should be able to overwrite "context" and "engine" variables
sundar@1013 26 *
sundar@1013 27 * @test
sundar@1013 28 * @run
sundar@1013 29 */
sundar@1013 30
sundar@1013 31 var m = new javax.script.ScriptEngineManager();
sundar@1013 32 var e = m.getEngineByName("nashorn");
sundar@1013 33 e.put("foo", "hello");
sundar@1013 34 var obj = e.eval("context.getAttribute('foo')");
sundar@1013 35 if (obj != "hello") {
sundar@1013 36 fail("Expected 'obj' to be 'hello'");
sundar@1013 37 }
sundar@1013 38
sundar@1013 39 e.put("context", "bar");
sundar@1013 40 if (e.eval("context") != "bar") {
sundar@1013 41 fail("Expected 'context' to be 'bar'");
sundar@1013 42 }
sundar@1013 43
sundar@1013 44 if (e.eval("foo") != "hello") {
sundar@1013 45 fail("Expected 'foo' to be 'hello'");
sundar@1013 46 }
sundar@1013 47
sundar@1013 48 if (e.eval("engine") != e) {
sundar@1013 49 fail("'engine' is not evaluaed to current engine");
sundar@1013 50 }
sundar@1013 51
sundar@1013 52 e.put("engine", "foobar");
sundar@1013 53 if (e.eval("engine") != "foobar") {
sundar@1013 54 fail("'engine' is not evalued to 'foobar'");
sundar@1013 55 }

mercurial