constructorname.js revision 2:da1e581c933b
1105068Sphk/*
2105068Sphk * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
3105068Sphk * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4105068Sphk *
5105068Sphk * This code is free software; you can redistribute it and/or modify it
6105068Sphk * under the terms of the GNU General Public License version 2 only, as
7105068Sphk * published by the Free Software Foundation.
8105068Sphk *
9105068Sphk * This code is distributed in the hope that it will be useful, but WITHOUT
10105068Sphk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11105068Sphk * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12105068Sphk * version 2 for more details (a copy is included in the LICENSE file that
13105068Sphk * accompanied this code).
14105068Sphk *
15105068Sphk * You should have received a copy of the GNU General Public License version
16105068Sphk * 2 along with this work; if not, write to the Free Software Foundation,
17105068Sphk * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18105068Sphk *
19105068Sphk * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20105068Sphk * or visit www.oracle.com if you need additional information or have any
21105068Sphk * questions.
22105068Sphk */
23105068Sphk
24105068Sphk/**
25105068Sphk * Check obj.constructor property for user-defined constructor as well
26105068Sphk * as built-in constructors.
27105068Sphk *
28105068Sphk * @test
29105068Sphk * @run
30105068Sphk */
31105068Sphk
32105068Sphkfunction MyConstructor() {}
33105068Sphkvar myObj = new MyConstructor();
34105068Sphkprint(myObj.constructor.name);
35105068Sphk
36105068SphkmyObj = {};
37105068Sphkprint(myObj.constructor.name);
38105068Sphk
39105068SphkmyObj = new Boolean(true);
40105068Sphkprint(myObj.constructor.name);
41105068Sphk
42105068SphkmyObj = new Number(3);
43105068Sphkprint(myObj.constructor.name);
44105068Sphk
45105068SphkmyObj = new String("hello");
46105068Sphkprint(myObj.constructor.name);
47105068Sphk
48105068SphkmyObj = new Array();
49113892Sphkprint(myObj.constructor.name);
50105068Sphk
51105068SphkmyObj = /javascript/;
52105068Sphkprint(myObj.constructor.name);
53112511Sphk