author | sundar |
Wed, 21 Aug 2013 17:28:53 +0530 | |
changeset 19619 | 4085b74056ee |
parent 18839 | adc14dc1ca96 |
child 24778 | 2ff5d7041566 |
permissions | -rw-r--r-- |
18839
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
1 |
/* |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
4 |
* |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
8 |
* |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
13 |
* accompanied this code). |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
14 |
* |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
18 |
* |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
21 |
* questions. |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
22 |
*/ |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
23 |
|
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
24 |
/** |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
25 |
* JDK-8019783: typeof does not work properly for java methods and foreign objects |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
26 |
* |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
27 |
* @test |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
28 |
* @run |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
29 |
*/ |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
30 |
|
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
31 |
function printTypeof(str) { |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
32 |
print("typeof(" + str + ") = " + eval('typeof ' + str)); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
33 |
} |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
34 |
|
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
35 |
// Java methods |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
36 |
printTypeof("java.lang.System.exit"); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
37 |
printTypeof("java.lang.System['exit']"); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
38 |
// full signature |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
39 |
printTypeof("java.lang.System['exit(int)']"); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
40 |
// overloaded method |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
41 |
printTypeof("java.security.AccessController.doPrivileged"); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
42 |
printTypeof("java.security.AccessController['doPrivileged']"); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
43 |
|
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
44 |
// foreign objects |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
45 |
var global = loadWithNewGlobal({ name: "t", script: "this" }); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
46 |
print("typeof(global.Object) = " + (typeof global.Object)); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
47 |
print("typeof(new global.Object()) = " + (typeof (new global.Object()))); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
48 |
|
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
49 |
// foreign engine objects |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
50 |
var m = new javax.script.ScriptEngineManager(); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
51 |
var engine = m.getEngineByName("nashorn"); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
52 |
var engineGlobal = engine.eval("this"); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
53 |
|
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
54 |
print("typeof(engineGlobal.Object) = " + (typeof engineGlobal.Object)); |
adc14dc1ca96
8019783: typeof does not work properly for java methods and foreign objects
sundar
parents:
diff
changeset
|
55 |
print("typeof(new engineGlobal.Object()) = " + (typeof (new engineGlobal.Object()))); |