sundar@1508: /* sundar@1515: * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. sundar@1508: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sundar@1508: * sundar@1508: * This code is free software; you can redistribute it and/or modify it sundar@1508: * under the terms of the GNU General Public License version 2 only, as sundar@1508: * published by the Free Software Foundation. sundar@1508: * sundar@1508: * This code is distributed in the hope that it will be useful, but WITHOUT sundar@1508: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sundar@1508: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sundar@1508: * version 2 for more details (a copy is included in the LICENSE file that sundar@1508: * accompanied this code). sundar@1508: * sundar@1508: * You should have received a copy of the GNU General Public License version sundar@1508: * 2 along with this work; if not, write to the Free Software Foundation, sundar@1508: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sundar@1508: * sundar@1508: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sundar@1508: * or visit www.oracle.com if you need additional information or have any sundar@1508: * questions. sundar@1508: */ sundar@1508: sundar@1508: /** sundar@1508: * JDK-8130853: Non-extensible global is not handled property sundar@1508: * sundar@1508: * @test sundar@1508: * @run sundar@1508: */ sundar@1508: sundar@1508: // don't allow extensions to global sundar@1508: Object.preventExtensions(this); sundar@1508: try { sundar@1508: eval("var x = 34;"); sundar@1508: throw new Error("should have thrown TypeError"); sundar@1508: } catch (e) { sundar@1508: if (! (e instanceof TypeError)) { sundar@1508: throw e; sundar@1508: } sundar@1508: } sundar@1508: sundar@1508: try { sundar@1508: eval("function func() {}"); sundar@1508: throw new Error("should have thrown TypeError"); sundar@1508: } catch (e) { sundar@1508: if (! (e instanceof TypeError)) { sundar@1508: throw e; sundar@1508: } sundar@1508: } sundar@1508: sundar@1508: function checkLoad(code) { sundar@1508: try { sundar@1508: load({ name: "test", script: code }); sundar@1508: throw new Error("should have thrown TypeError for load: " + code); sundar@1508: } catch (e) { sundar@1508: if (! (e instanceof TypeError)) { sundar@1508: throw e; sundar@1508: } sundar@1508: } sundar@1508: } sundar@1508: sundar@1508: checkLoad("var y = 55"); sundar@1508: checkLoad("function f() {}"); sundar@1508: sundar@1508: // check script engine eval sundar@1508: var ScriptEngineManager = Java.type("javax.script.ScriptEngineManager"); sundar@1508: var e = new ScriptEngineManager().getEngineByName("nashorn"); sundar@1508: var global = e.eval("this"); sundar@1508: e.eval("Object.preventExtensions(this);"); sundar@1508: try { sundar@1508: e.eval("var myVar = 33;"); sundar@1508: throw new Error("should have thrown TypeError"); sundar@1508: } catch (e) { sundar@1508: if (! (e.cause.ecmaError instanceof global.TypeError)) { sundar@1508: throw e; sundar@1508: } sundar@1508: } sundar@1508: sundar@1508: // Object.bindProperties on arbitrary non-extensible object sundar@1508: var obj = {}; sundar@1508: Object.preventExtensions(obj); sundar@1508: try { sundar@1508: Object.bindProperties(obj, { foo: 434 }); sundar@1508: throw new Error("should have thrown TypeError"); sundar@1508: } catch (e) { sundar@1508: if (! (e instanceof TypeError)) { sundar@1508: throw e; sundar@1508: } sundar@1508: }