aoqi@0: /* aoqi@0: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. attila@962: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. attila@962: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). attila@962: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. attila@962: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /** aoqi@0: * Test to check [[Class]] internal property for various standard objects. aoqi@0: * aoqi@0: * @test aoqi@0: * @run aoqi@0: */ aoqi@0: aoqi@0: function checkClass(obj, expected) { aoqi@0: var str = Object.prototype.toString.call(obj); aoqi@0: if (str != expected) { aoqi@0: fail("expected " + expected + ", got " + str); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // objects aoqi@0: checkClass([2, 23], "[object Array]"); aoqi@0: checkClass(new Boolean(true), "[object Boolean]"); aoqi@0: checkClass(new Date(0), "[object Date]"); aoqi@0: checkClass(new Error(), "[object Error]"); aoqi@0: checkClass(new EvalError(), "[object Error]"); aoqi@0: if (typeof JSAdapter != 'undefined') { aoqi@0: checkClass(new JSAdapter({}), "[object JSAdapter]"); aoqi@0: } aoqi@0: if (typeof JavaImporter != 'undefined') { aoqi@0: checkClass(new JavaImporter(java.io), "[object JavaImporter]"); aoqi@0: } aoqi@0: checkClass(function() {}, "[object Function]"); aoqi@0: checkClass(new Number(42), "[object Number]"); aoqi@0: checkClass(new Object(), "[object Object]"); aoqi@0: checkClass(new RangeError(), "[object Error]"); aoqi@0: checkClass(new ReferenceError(), "[object Error]"); aoqi@0: checkClass(/nashorn/, "[object RegExp]"); aoqi@0: checkClass(new String('hello'), "[object String]"); aoqi@0: checkClass(new SyntaxError(), "[object Error]"); aoqi@0: checkClass(new TypeError(), "[object Error]"); aoqi@0: checkClass(new URIError(), "[object Error]"); aoqi@0: aoqi@0: // constructors and prototypes aoqi@0: checkClass(Array, "[object Function]"); aoqi@0: checkClass(Array.prototype, "[object Array]"); aoqi@0: checkClass(Boolean, "[object Function]"); aoqi@0: checkClass(Boolean.prototype, "[object Boolean]"); aoqi@0: checkClass(Date, "[object Function]"); aoqi@0: checkClass(Date.prototype, "[object Date]"); aoqi@0: checkClass(Error, "[object Function]"); aoqi@0: checkClass(Error.prototype, "[object Error]"); aoqi@0: checkClass(EvalError, "[object Function]"); aoqi@0: checkClass(EvalError.prototype, "[object Error]"); aoqi@0: checkClass(Function, "[object Function]"); aoqi@0: checkClass(Function.prototype, "[object Function]"); aoqi@0: if (typeof JSAdapter != 'undefined') { aoqi@0: checkClass(JSAdapter, "[object Function]"); aoqi@0: checkClass(JSAdapter.prototype, "[object JSAdapter]"); aoqi@0: } aoqi@0: if (typeof JavaImporter != 'undefined') { aoqi@0: checkClass(JavaImporter, "[object Function]"); aoqi@0: checkClass(JavaImporter.prototype, "[object JavaImporter]"); aoqi@0: } aoqi@0: checkClass(Number, "[object Function]"); aoqi@0: checkClass(Number.prototype, "[object Number]"); aoqi@0: checkClass(Object, "[object Function]"); aoqi@0: checkClass(Object.prototype, "[object Object]"); aoqi@0: checkClass(RangeError, "[object Function]"); aoqi@0: checkClass(RangeError.prototype, "[object Error]"); aoqi@0: checkClass(ReferenceError, "[object Function]"); aoqi@0: checkClass(ReferenceError.prototype, "[object Error]"); aoqi@0: checkClass(RegExp, "[object Function]"); aoqi@0: checkClass(RegExp.prototype, "[object RegExp]"); aoqi@0: checkClass(String, "[object Function]"); aoqi@0: checkClass(String.prototype, "[object String]"); aoqi@0: checkClass(SyntaxError, "[object Function]"); aoqi@0: checkClass(SyntaxError.prototype, "[object Error]"); aoqi@0: checkClass(TypeError, "[object Function]"); aoqi@0: checkClass(TypeError.prototype, "[object Error]"); aoqi@0: checkClass(URIError, "[object Function]"); aoqi@0: checkClass(URIError.prototype, "[object Error]"); aoqi@0: aoqi@0: // misc. objects aoqi@0: checkClass(this, "[object global]"); aoqi@0: checkClass(this.prototype, "[object Undefined]"); aoqi@0: aoqi@0: if (typeof Packages != 'undefined') { aoqi@0: checkClass(Packages, "[object JavaPackage]"); aoqi@0: checkClass(java, "[object JavaPackage]"); aoqi@0: checkClass(javax, "[object JavaPackage]"); aoqi@0: } aoqi@0: aoqi@0: if (typeof Java != 'undefined') { aoqi@0: checkClass(Java, "[object Java]"); aoqi@0: checkClass(Java.prototype, "[object Undefined]"); aoqi@0: } aoqi@0: aoqi@0: if (typeof Debug != 'undefined') { aoqi@0: checkClass(Debug, "[object Debug]"); aoqi@0: } aoqi@0: aoqi@0: checkClass((function() { return arguments; })(), "[object Arguments]"); aoqi@0: // strict arguments implementation is different. aoqi@0: checkClass((function() { 'use strict'; return arguments; })(), "[object Arguments]"); aoqi@0: checkClass(JSON, "[object JSON]"); aoqi@0: checkClass(JSON.prototype, "[object Undefined]"); aoqi@0: checkClass(Math, "[object Math]"); aoqi@0: checkClass(Math.prototype, "[object Undefined]");