JDK-8019783.js revision 401:9d3a9fdab668
139287Ssos/*
239643Syokota * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
339287Ssos * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
439287Ssos *
539287Ssos * This code is free software; you can redistribute it and/or modify it
639287Ssos * under the terms of the GNU General Public License version 2 only, as
739287Ssos * published by the Free Software Foundation.
839287Ssos *
939643Syokota * This code is distributed in the hope that it will be useful, but WITHOUT
1039643Syokota * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1139287Ssos * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1239287Ssos * version 2 for more details (a copy is included in the LICENSE file that
1339287Ssos * accompanied this code).
1439287Ssos *
1539643Syokota * You should have received a copy of the GNU General Public License version
1639643Syokota * 2 along with this work; if not, write to the Free Software Foundation,
1739643Syokota * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1839643Syokota *
1939643Syokota * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2039643Syokota * or visit www.oracle.com if you need additional information or have any
2139643Syokota * questions.
2239643Syokota */
2339643Syokota
2439643Syokota/**
2539287Ssos * JDK-8019783: typeof does not work properly for java methods and foreign objects
2639287Ssos *
27115703Sobrien * @test
28115703Sobrien * @run
29115703Sobrien */
3042504Syokota
3166710Sjhbfunction printTypeof(str) {
3239287Ssos    print("typeof(" + str + ") =  " + eval('typeof ' + str));
3356836Speter}
3439287Ssos
3539287Ssos// Java methods
36198251SjkimprintTypeof("java.lang.System.exit");
3739287SsosprintTypeof("java.lang.System['exit']");
3839287Ssos// full signature
3942179SyokotaprintTypeof("java.lang.System['exit(int)']");
4039287Ssos// overloaded method
4148104SyokotaprintTypeof("java.security.AccessController.doPrivileged");
4248104SyokotaprintTypeof("java.security.AccessController['doPrivileged']");
4339287Ssos
4448104Syokota// foreign objects
4548104Syokotavar global = loadWithNewGlobal({ name: "t", script: "this" });
46130312Sjhbprint("typeof(global.Object) = " + (typeof global.Object));
4739287Ssosprint("typeof(new global.Object()) = " + (typeof (new global.Object())));
4839287Ssos
49197383Sdelphij// foreign engine objects
50197025Sdelphijvar m = new javax.script.ScriptEngineManager();
5139287Ssosvar engine = m.getEngineByName("nashorn");
5242504Syokotavar engineGlobal = engine.eval("this");
5342504Syokota
5439287Ssosprint("typeof(engineGlobal.Object) = " + (typeof engineGlobal.Object));
55198251Sjkimprint("typeof(new engineGlobal.Object()) = " + (typeof (new engineGlobal.Object())));
56198251Sjkim