test/script/basic/getclassname.js

Fri, 05 Jun 2015 12:38:53 +0200

author
mhaupt
date
Fri, 05 Jun 2015 12:38:53 +0200
changeset 1398
2f1b9f4daec1
parent 962
ac62e33a99b0
child 1205
4112748288bb
permissions
-rw-r--r--

8080087: Nashorn $ENV.PWD is originally undefined
Summary: On Windows, the PWD environment variable does not exist and cannot be imported in scripting mode, so it is set explicitly.
Reviewed-by: lagergren, sundar

     1 /*
     2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /**
    25  * Test to check [[Class]] internal property for various standard objects.
    26  *
    27  * @test
    28  * @run
    29  */
    31 function checkClass(obj, expected) {
    32     var str = Object.prototype.toString.call(obj);
    33     if (str != expected) {
    34         fail("expected " + expected + ", got " + str);
    35     }
    36 }
    38 // objects
    39 checkClass([2, 23], "[object Array]");
    40 checkClass(new Boolean(true), "[object Boolean]");
    41 checkClass(new Date(0), "[object Date]");
    42 checkClass(new Error(), "[object Error]");
    43 checkClass(new EvalError(), "[object Error]");
    44 if (typeof JSAdapter != 'undefined') {
    45     checkClass(new JSAdapter({}), "[object JSAdapter]");
    46 }
    47 if (typeof JavaImporter != 'undefined') {
    48     checkClass(new JavaImporter(java.io), "[object JavaImporter]");
    49 }
    50 checkClass(function() {}, "[object Function]");
    51 checkClass(new Number(42), "[object Number]");
    52 checkClass(new Object(), "[object Object]");
    53 checkClass(new RangeError(), "[object Error]");
    54 checkClass(new ReferenceError(), "[object Error]");
    55 checkClass(/nashorn/, "[object RegExp]");
    56 checkClass(new String('hello'), "[object String]");
    57 checkClass(new SyntaxError(), "[object Error]");
    58 checkClass(new TypeError(), "[object Error]");
    59 checkClass(new URIError(), "[object Error]");
    61 // constructors and prototypes
    62 checkClass(Array, "[object Function]");
    63 checkClass(Array.prototype, "[object Array]");
    64 checkClass(Boolean, "[object Function]");
    65 checkClass(Boolean.prototype, "[object Boolean]");
    66 checkClass(Date, "[object Function]");
    67 checkClass(Date.prototype, "[object Date]");
    68 checkClass(Error, "[object Function]");
    69 checkClass(Error.prototype, "[object Error]");
    70 checkClass(EvalError, "[object Function]");
    71 checkClass(EvalError.prototype, "[object Error]");
    72 checkClass(Function, "[object Function]");
    73 checkClass(Function.prototype, "[object Function]");
    74 if (typeof JSAdapter != 'undefined') {
    75     checkClass(JSAdapter, "[object Function]");
    76     checkClass(JSAdapter.prototype, "[object JSAdapter]");
    77 }
    78 if (typeof JavaImporter != 'undefined') {
    79     checkClass(JavaImporter, "[object Function]");
    80     checkClass(JavaImporter.prototype, "[object JavaImporter]");
    81 }
    82 checkClass(Number, "[object Function]");
    83 checkClass(Number.prototype, "[object Number]");
    84 checkClass(Object, "[object Function]");
    85 checkClass(Object.prototype, "[object Object]");
    86 checkClass(RangeError, "[object Function]");
    87 checkClass(RangeError.prototype, "[object Error]");
    88 checkClass(ReferenceError, "[object Function]");
    89 checkClass(ReferenceError.prototype, "[object Error]");
    90 checkClass(RegExp, "[object Function]");
    91 checkClass(RegExp.prototype, "[object RegExp]");
    92 checkClass(String, "[object Function]");
    93 checkClass(String.prototype, "[object String]");
    94 checkClass(SyntaxError, "[object Function]");
    95 checkClass(SyntaxError.prototype, "[object Error]");
    96 checkClass(TypeError, "[object Function]");
    97 checkClass(TypeError.prototype, "[object Error]");
    98 checkClass(URIError, "[object Function]");
    99 checkClass(URIError.prototype, "[object Error]");
   101 // misc. objects
   102 checkClass(this, "[object global]");
   103 checkClass(this.prototype, "[object Undefined]");
   105 if (typeof Packages != 'undefined') {
   106     checkClass(Packages, "[object JavaPackage]");
   107     checkClass(java, "[object JavaPackage]");
   108     checkClass(javax, "[object JavaPackage]");
   109 }
   111 if (typeof Java != 'undefined') {
   112     checkClass(Java, "[object Java]");
   113     checkClass(Java.prototype, "[object Undefined]");
   114 }
   116 if (typeof Debug != 'undefined') {
   117     checkClass(Debug, "[object Debug]");
   118 }
   120 checkClass((function() { return arguments; })(), "[object Arguments]");
   121 // strict arguments implementation is different.
   122 checkClass((function() { 'use strict'; return arguments; })(), "[object Arguments]");
   123 checkClass(JSON, "[object JSON]");
   124 checkClass(JSON.prototype, "[object Undefined]");
   125 checkClass(Math, "[object Math]");
   126 checkClass(Math.prototype, "[object Undefined]");

mercurial