Tue, 01 Sep 2015 18:28:11 +0530
8068901: Surprising behavior with more than one functional interface on a class
8068903: Can't invoke vararg @FunctionalInterface methods
Reviewed-by: attila, hannesw
sundar@1412 | 1 | /* |
sundar@1482 | 2 | * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
sundar@1412 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
sundar@1482 | 4 | * |
sundar@1412 | 5 | * This code is free software; you can redistribute it and/or modify it |
sundar@1412 | 6 | * under the terms of the GNU General Public License version 2 only, as |
sundar@1412 | 7 | * published by the Free Software Foundation. |
sundar@1482 | 8 | * |
sundar@1412 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
sundar@1412 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
sundar@1412 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
sundar@1412 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
sundar@1412 | 13 | * accompanied this code). |
sundar@1482 | 14 | * |
sundar@1412 | 15 | * You should have received a copy of the GNU General Public License version |
sundar@1412 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
sundar@1412 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
sundar@1482 | 18 | * |
sundar@1412 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
sundar@1412 | 20 | * or visit www.oracle.com if you need additional information or have any |
sundar@1412 | 21 | * questions. |
sundar@1412 | 22 | */ |
sundar@1412 | 23 | |
sundar@1412 | 24 | /** |
sundar@1412 | 25 | * JDK-8098578: Global scope is not accessible with indirect load call |
sundar@1412 | 26 | * |
sundar@1412 | 27 | * @test |
sundar@1412 | 28 | * @run |
sundar@1412 | 29 | */ |
sundar@1412 | 30 | |
sundar@1412 | 31 | var obj = { foo: 343 }; |
sundar@1412 | 32 | var global = this; |
sundar@1412 | 33 | var x = 434; |
sundar@1412 | 34 | |
sundar@1412 | 35 | // indirect load call |
sundar@1412 | 36 | var res = load.call(obj, { |
sundar@1412 | 37 | name: "t.js", |
sundar@1412 | 38 | // global is accessible. All declarations go into |
sundar@1412 | 39 | // intermediate inaccessible scope. "this" is global |
sundar@1412 | 40 | // User's passed object's properties are accessible |
sundar@1412 | 41 | // as variables. |
sundar@1412 | 42 | script: "foo -= 300; var bar = x; Assert.assertTrue(bar == 434); function func() {}; this" |
sundar@1412 | 43 | }) |
sundar@1412 | 44 | |
sundar@1412 | 45 | // 'this' for the evaluated code is global |
sundar@1412 | 46 | Assert.assertTrue(res === global); |
sundar@1412 | 47 | |
sundar@1412 | 48 | // properties of passed object are accessible in evaluated code |
sundar@1412 | 49 | Assert.assertTrue(obj.foo == 43); |
sundar@1412 | 50 | |
sundar@1412 | 51 | // vars, functions definined in evaluated code don't go into passed object |
sundar@1412 | 52 | Assert.assertTrue(typeof obj.bar == "undefined"); |
sundar@1412 | 53 | Assert.assertTrue(typeof obj.func == "undefined"); |
sundar@1412 | 54 | |
sundar@1412 | 55 | // vars, functions definined in evaluated code don't go leak into global |
sundar@1412 | 56 | Assert.assertTrue(typeof bar == "undefined"); |
sundar@1412 | 57 | Assert.assertTrue(typeof func == "undefined"); |
sundar@1412 | 58 | Assert.assertTrue(typeof foo == "undefined"); |
sundar@1412 | 59 | |
sundar@1412 | 60 | var res = load.call(undefined, { |
sundar@1412 | 61 | name: "t1.js", |
sundar@1412 | 62 | // still global is accessible and 'this' is global |
sundar@1412 | 63 | script: "Assert.assertTrue(x == 434); this" |
sundar@1412 | 64 | }); |
sundar@1412 | 65 | |
sundar@1412 | 66 | // indirect load with 'undefined' this is same as as direct load |
sundar@1412 | 67 | // or load on global itself. |
sundar@1412 | 68 | Assert.assertTrue(res === global); |
sundar@1412 | 69 | |
sundar@1412 | 70 | // indirect load with 'undefined' this is same as as direct load |
sundar@1412 | 71 | // or load on global itself. |
sundar@1412 | 72 | var res = load.call(null, { |
sundar@1412 | 73 | name: "t2.js", |
sundar@1412 | 74 | // still global is accessible and 'this' is global |
sundar@1412 | 75 | script: "Assert.assertTrue(x == 434); this" |
sundar@1412 | 76 | }); |
sundar@1412 | 77 | Assert.assertTrue(res === global); |
sundar@1412 | 78 | |
sundar@1412 | 79 | // indirect load with mirror object |
sundar@1412 | 80 | var mirror = loadWithNewGlobal({ |
sundar@1412 | 81 | name: "t3.js", |
sundar@1412 | 82 | script: "({ foo: 'hello', x: Math.PI })" |
sundar@1412 | 83 | }); |
sundar@1412 | 84 | |
sundar@1412 | 85 | var res = load.call(mirror, { |
sundar@1412 | 86 | name: "t4.js", |
sundar@1412 | 87 | script: "Assert.assertTrue(foo == 'hello'); Assert.assertTrue(x == Math.PI); this" |
sundar@1412 | 88 | }); |
sundar@1412 | 89 | Assert.assertTrue(res === global); |
sundar@1412 | 90 | |
sundar@1412 | 91 | // indirect load on non-script object, non-mirror results in TypeError |
sundar@1412 | 92 | function tryLoad(obj) { |
sundar@1412 | 93 | try { |
sundar@1412 | 94 | load.call(obj, { |
sundar@1412 | 95 | name: "t5.js", script: "this" |
sundar@1412 | 96 | }); |
sundar@1412 | 97 | throw new Error("should thrown TypeError for: " + obj); |
sundar@1412 | 98 | } catch (e if TypeError) {} |
sundar@1412 | 99 | } |
sundar@1412 | 100 | |
sundar@1412 | 101 | tryLoad("hello"); |
sundar@1412 | 102 | tryLoad(Math.E); |
sundar@1412 | 103 | tryLoad(true); |
sundar@1412 | 104 | tryLoad(false); |
sundar@1412 | 105 | |
sundar@1412 | 106 | // indirect load of a large script |
sundar@1412 | 107 | load.call({}, __DIR__ + "JDK-8098807-payload.js"); |