Home | History | Annotate | Download | only in Object
      1 /*
      2 * The contents of this file are subject to the Netscape Public
      3 * License Version 1.1 (the "License"); you may not use this file
      4 * except in compliance with the License. You may obtain a copy of
      5 * the License at http://www.mozilla.org/NPL/
      6 *
      7 * Software distributed under the License is distributed on an "AS IS"
      8 * basis, WITHOUT WARRANTY OF ANY KIND, either expressed
      9 * or implied. See the License for the specific language governing
     10 * rights and limitations under the License.
     11 *
     12 * The Original Code is mozilla.org code.
     13 *
     14 * The Initial Developer of the Original Code is Netscape
     15 * Communications Corporation.  Portions created by Netscape are
     16 * Copyright (C) 1998 Netscape Communications Corporation. All
     17 * Rights Reserved.
     18 *
     19 * Contributor(s): pschwartau (at) netscape.com
     20 * Date: 14 Mar 2001
     21 *
     22 * SUMMARY: Testing the internal [[Class]] property of user-defined types.
     23 * See ECMA-262 Edition 3 13-Oct-1999, Section 8.6.2 re [[Class]] property.
     24 *
     25 * Same as class-001.js - but testing user-defined types here, not native types.
     26 * Therefore we expect the [[Class]] property to equal 'Object' in each case -
     27 *
     28 * The getJSClass() function we use is in a utility file, e.g. "shell.js"
     29 */
     30 //-------------------------------------------------------------------------------------------------
     31 var i = 0;
     32 var UBound = 0;
     33 var bug = '(none)';
     34 var summary = 'Testing the internal [[Class]] property of user-defined types';
     35 var statprefix = 'Current user-defined type is: ';
     36 var status = ''; var statusList = [ ];
     37 var actual = ''; var actualvalue = [ ];
     38 var expect= ''; var expectedvalue = [ ];
     39 
     40 
     41 Calf.prototype= new Cow();
     42 
     43 /*
     44  * We set the expect variable each time only for readability.
     45  * We expect 'Object' every time; see discussion above -
     46  */
     47 status = 'new Cow()';
     48 actual = getJSClass(new Cow());
     49 expect = 'Object';
     50 addThis();
     51 
     52 status = 'new Calf()';
     53 actual = getJSClass(new Calf());
     54 expect = 'Object';
     55 addThis();
     56 
     57 
     58 //---------------------------------------------------------------------------------
     59 test();
     60 //---------------------------------------------------------------------------------
     61 
     62 
     63 function addThis()
     64 {
     65   statusList[UBound] = status;
     66   actualvalue[UBound] = actual;
     67   expectedvalue[UBound] = expect;
     68   UBound++;
     69 }
     70 
     71 
     72 function test()
     73 {
     74   enterFunc ('test');
     75   printBugNumber (bug);
     76   printStatus (summary);
     77 
     78   for (i = 0; i < UBound; i++)
     79   {
     80     reportCompare(expectedvalue[i], actualvalue[i], getStatus(i));
     81   }
     82 
     83   exitFunc ('test');
     84 }
     85 
     86 
     87 function getStatus(i)
     88 {
     89   return statprefix + statusList[i];
     90 }
     91 
     92 
     93 function Cow(name)
     94 {
     95   this.name=name;
     96 }
     97 
     98 
     99 function Calf(name)
    100 {
    101   this.name=name;
    102 }
    103