author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 45033 | nashorn/test/script/basic/JDK-8150218.js@0a226c99bb5a |
permissions | -rw-r--r-- |
36686
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
1 |
/* |
45033
0a226c99bb5a
8179889: Fix typographic errors in copyright headers
ihse
parents:
36686
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
36686
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
45033
0a226c99bb5a
8179889: Fix typographic errors in copyright headers
ihse
parents:
36686
diff
changeset
|
4 |
* |
36686
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
45033
0a226c99bb5a
8179889: Fix typographic errors in copyright headers
ihse
parents:
36686
diff
changeset
|
8 |
* |
36686
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
13 |
* accompanied this code). |
45033
0a226c99bb5a
8179889: Fix typographic errors in copyright headers
ihse
parents:
36686
diff
changeset
|
14 |
* |
36686
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
45033
0a226c99bb5a
8179889: Fix typographic errors in copyright headers
ihse
parents:
36686
diff
changeset
|
18 |
* |
36686
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
21 |
* questions. |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
22 |
*/ |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
23 |
|
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
24 |
/** |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
25 |
* JDK-8150218: Autoconversion SAM adapters sometimes don't get privileges |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
26 |
* |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
27 |
* @test |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
28 |
* @run |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
29 |
*/ |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
30 |
|
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
31 |
function f() { |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
32 |
java.lang.System.getProperty("user.dir") |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
33 |
} |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
34 |
|
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
35 |
java.security.AccessController.doPrivileged(new java.security.PrivilegedAction(function () { |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
36 |
// Control: this used to work even before this improvement |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
37 |
new java.lang.Runnable(f).run() |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
38 |
|
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
39 |
// SAM type explicitly created through an array needs to get the right permissions too |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
40 |
Java.to([f], Java.type("java.lang.Runnable[]"))[0].run() |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
41 |
|
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
42 |
// Even when more deeply nested |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
43 |
Java.to([[[f]]], Java.type("java.lang.Runnable[][][]"))[0][0][0].run() |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
44 |
|
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
45 |
var rt = new (Java.type("jdk.dynalink.test.ArrayRunnableTest")) |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
46 |
var n = "runnables" |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
47 |
|
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
48 |
// Explicit array passed to vararg setter chosen at run time |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
49 |
rt[n] = [f] |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
50 |
rt.firstRunnable.run() |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
51 |
|
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
52 |
// Automatically packed one-element array passed to vararg setter chosen at run time |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
53 |
rt[n] = f |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
54 |
rt.firstRunnable.run() |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
55 |
|
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
56 |
// Explicit array passed to vararg method overload chosen at run time |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
57 |
rt.setRunnablesOverloaded([f]) |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
58 |
rt.firstRunnable.run() |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
59 |
|
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
60 |
// Automatically packed one-element array passed to vararg method overload chosen at run time |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
61 |
rt.setRunnablesOverloaded(f) |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
62 |
rt.firstRunnable.run() |
a351eacd4c42
8150218: Autoconversion SAM adapters sometimes don't get privileges
attila
parents:
diff
changeset
|
63 |
})) |