test/script/basic/getclassname.js

changeset 0
b1a7da25b547
child 952
6d5471a497fb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/script/basic/getclassname.js	Wed Apr 27 01:36:41 2016 +0800
     1.3 @@ -0,0 +1,126 @@
     1.4 +/*
     1.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + * 
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + * 
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + * 
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + * 
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/**
    1.28 + * Test to check [[Class]] internal property for various standard objects.
    1.29 + *
    1.30 + * @test
    1.31 + * @run
    1.32 + */
    1.33 +
    1.34 +function checkClass(obj, expected) {
    1.35 +    var str = Object.prototype.toString.call(obj);
    1.36 +    if (str != expected) {
    1.37 +        fail("expected " + expected + ", got " + str);
    1.38 +    }
    1.39 +}
    1.40 +
    1.41 +// objects
    1.42 +checkClass([2, 23], "[object Array]");
    1.43 +checkClass(new Boolean(true), "[object Boolean]");
    1.44 +checkClass(new Date(0), "[object Date]");
    1.45 +checkClass(new Error(), "[object Error]");
    1.46 +checkClass(new EvalError(), "[object Error]");
    1.47 +if (typeof JSAdapter != 'undefined') {
    1.48 +    checkClass(new JSAdapter({}), "[object JSAdapter]");
    1.49 +}
    1.50 +if (typeof JavaImporter != 'undefined') {
    1.51 +    checkClass(new JavaImporter(java.io), "[object JavaImporter]");
    1.52 +}
    1.53 +checkClass(function() {}, "[object Function]");
    1.54 +checkClass(new Number(42), "[object Number]");
    1.55 +checkClass(new Object(), "[object Object]");
    1.56 +checkClass(new RangeError(), "[object Error]");
    1.57 +checkClass(new ReferenceError(), "[object Error]");
    1.58 +checkClass(/nashorn/, "[object RegExp]");
    1.59 +checkClass(new String('hello'), "[object String]");
    1.60 +checkClass(new SyntaxError(), "[object Error]");
    1.61 +checkClass(new TypeError(), "[object Error]");
    1.62 +checkClass(new URIError(), "[object Error]");
    1.63 +
    1.64 +// constructors and prototypes
    1.65 +checkClass(Array, "[object Function]");
    1.66 +checkClass(Array.prototype, "[object Array]");
    1.67 +checkClass(Boolean, "[object Function]");
    1.68 +checkClass(Boolean.prototype, "[object Boolean]");
    1.69 +checkClass(Date, "[object Function]");
    1.70 +checkClass(Date.prototype, "[object Date]");
    1.71 +checkClass(Error, "[object Function]");
    1.72 +checkClass(Error.prototype, "[object Error]");
    1.73 +checkClass(EvalError, "[object Function]");
    1.74 +checkClass(EvalError.prototype, "[object Error]");
    1.75 +checkClass(Function, "[object Function]");
    1.76 +checkClass(Function.prototype, "[object Function]");
    1.77 +if (typeof JSAdapter != 'undefined') {
    1.78 +    checkClass(JSAdapter, "[object Function]");
    1.79 +    checkClass(JSAdapter.prototype, "[object JSAdapter]");
    1.80 +}
    1.81 +if (typeof JavaImporter != 'undefined') {
    1.82 +    checkClass(JavaImporter, "[object Function]");
    1.83 +    checkClass(JavaImporter.prototype, "[object JavaImporter]");
    1.84 +}
    1.85 +checkClass(Number, "[object Function]");
    1.86 +checkClass(Number.prototype, "[object Number]");
    1.87 +checkClass(Object, "[object Function]");
    1.88 +checkClass(Object.prototype, "[object Object]");
    1.89 +checkClass(RangeError, "[object Function]");
    1.90 +checkClass(RangeError.prototype, "[object Error]");
    1.91 +checkClass(ReferenceError, "[object Function]");
    1.92 +checkClass(ReferenceError.prototype, "[object Error]");
    1.93 +checkClass(RegExp, "[object Function]");
    1.94 +checkClass(RegExp.prototype, "[object RegExp]");
    1.95 +checkClass(String, "[object Function]");
    1.96 +checkClass(String.prototype, "[object String]");
    1.97 +checkClass(SyntaxError, "[object Function]");
    1.98 +checkClass(SyntaxError.prototype, "[object Error]");
    1.99 +checkClass(TypeError, "[object Function]");
   1.100 +checkClass(TypeError.prototype, "[object Error]");
   1.101 +checkClass(URIError, "[object Function]");
   1.102 +checkClass(URIError.prototype, "[object Error]");
   1.103 +
   1.104 +// misc. objects
   1.105 +checkClass(this, "[object global]");
   1.106 +checkClass(this.prototype, "[object Undefined]");
   1.107 +
   1.108 +if (typeof Packages != 'undefined') {
   1.109 +    checkClass(Packages, "[object JavaPackage]");
   1.110 +    checkClass(java, "[object JavaPackage]");
   1.111 +    checkClass(javax, "[object JavaPackage]");
   1.112 +}
   1.113 +
   1.114 +if (typeof Java != 'undefined') {
   1.115 +    checkClass(Java, "[object Java]");
   1.116 +    checkClass(Java.prototype, "[object Undefined]");
   1.117 +}
   1.118 +
   1.119 +if (typeof Debug != 'undefined') {
   1.120 +    checkClass(Debug, "[object Debug]");
   1.121 +}
   1.122 +
   1.123 +checkClass((function() { return arguments; })(), "[object Arguments]");
   1.124 +// strict arguments implementation is different.
   1.125 +checkClass((function() { 'use strict'; return arguments; })(), "[object Arguments]");
   1.126 +checkClass(JSON, "[object JSON]");
   1.127 +checkClass(JSON.prototype, "[object Undefined]");
   1.128 +checkClass(Math, "[object Math]");
   1.129 +checkClass(Math.prototype, "[object Undefined]");

mercurial