test/script/basic/getclassname.js

Thu, 12 Oct 2017 19:52:15 +0800

author
aoqi
date
Thu, 12 Oct 2017 19:52:15 +0800
changeset 1205
4112748288bb
parent 962
ac62e33a99b0
parent 952
6d5471a497fb
permissions
-rw-r--r--

merge

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

mercurial