test/script/basic/JDK-8130853.js

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

author
asaha
date
Tue, 21 Mar 2017 13:41:57 -0700
changeset 2160
1df40fe54cd6
parent 1515
4db30ae9ff23
permissions
-rw-r--r--

Merge

sundar@1508 1 /*
sundar@1515 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
sundar@1508 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sundar@1508 4 *
sundar@1508 5 * This code is free software; you can redistribute it and/or modify it
sundar@1508 6 * under the terms of the GNU General Public License version 2 only, as
sundar@1508 7 * published by the Free Software Foundation.
sundar@1508 8 *
sundar@1508 9 * This code is distributed in the hope that it will be useful, but WITHOUT
sundar@1508 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sundar@1508 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sundar@1508 12 * version 2 for more details (a copy is included in the LICENSE file that
sundar@1508 13 * accompanied this code).
sundar@1508 14 *
sundar@1508 15 * You should have received a copy of the GNU General Public License version
sundar@1508 16 * 2 along with this work; if not, write to the Free Software Foundation,
sundar@1508 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sundar@1508 18 *
sundar@1508 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sundar@1508 20 * or visit www.oracle.com if you need additional information or have any
sundar@1508 21 * questions.
sundar@1508 22 */
sundar@1508 23
sundar@1508 24 /**
sundar@1508 25 * JDK-8130853: Non-extensible global is not handled property
sundar@1508 26 *
sundar@1508 27 * @test
sundar@1508 28 * @run
sundar@1508 29 */
sundar@1508 30
sundar@1508 31 // don't allow extensions to global
sundar@1508 32 Object.preventExtensions(this);
sundar@1508 33 try {
sundar@1508 34 eval("var x = 34;");
sundar@1508 35 throw new Error("should have thrown TypeError");
sundar@1508 36 } catch (e) {
sundar@1508 37 if (! (e instanceof TypeError)) {
sundar@1508 38 throw e;
sundar@1508 39 }
sundar@1508 40 }
sundar@1508 41
sundar@1508 42 try {
sundar@1508 43 eval("function func() {}");
sundar@1508 44 throw new Error("should have thrown TypeError");
sundar@1508 45 } catch (e) {
sundar@1508 46 if (! (e instanceof TypeError)) {
sundar@1508 47 throw e;
sundar@1508 48 }
sundar@1508 49 }
sundar@1508 50
sundar@1508 51 function checkLoad(code) {
sundar@1508 52 try {
sundar@1508 53 load({ name: "test", script: code });
sundar@1508 54 throw new Error("should have thrown TypeError for load: " + code);
sundar@1508 55 } catch (e) {
sundar@1508 56 if (! (e instanceof TypeError)) {
sundar@1508 57 throw e;
sundar@1508 58 }
sundar@1508 59 }
sundar@1508 60 }
sundar@1508 61
sundar@1508 62 checkLoad("var y = 55");
sundar@1508 63 checkLoad("function f() {}");
sundar@1508 64
sundar@1508 65 // check script engine eval
sundar@1508 66 var ScriptEngineManager = Java.type("javax.script.ScriptEngineManager");
sundar@1508 67 var e = new ScriptEngineManager().getEngineByName("nashorn");
sundar@1508 68 var global = e.eval("this");
sundar@1508 69 e.eval("Object.preventExtensions(this);");
sundar@1508 70 try {
sundar@1508 71 e.eval("var myVar = 33;");
sundar@1508 72 throw new Error("should have thrown TypeError");
sundar@1508 73 } catch (e) {
sundar@1508 74 if (! (e.cause.ecmaError instanceof global.TypeError)) {
sundar@1508 75 throw e;
sundar@1508 76 }
sundar@1508 77 }
sundar@1508 78
sundar@1508 79 // Object.bindProperties on arbitrary non-extensible object
sundar@1508 80 var obj = {};
sundar@1508 81 Object.preventExtensions(obj);
sundar@1508 82 try {
sundar@1508 83 Object.bindProperties(obj, { foo: 434 });
sundar@1508 84 throw new Error("should have thrown TypeError");
sundar@1508 85 } catch (e) {
sundar@1508 86 if (! (e instanceof TypeError)) {
sundar@1508 87 throw e;
sundar@1508 88 }
sundar@1508 89 }

mercurial