js/src/tests/ecma_3/Object/class-005.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/Object/class-005.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Date: 14 Mar 2001
    1.11 + *
    1.12 + * SUMMARY: Testing the internal [[Class]] property of user-defined types.
    1.13 + * See ECMA-262 Edition 3 13-Oct-1999, Section 8.6.2 re [[Class]] property.
    1.14 + *
    1.15 + * Same as class-001.js - but testing user-defined types here, not
    1.16 + * native types.  Therefore we expect the [[Class]] property to equal
    1.17 + * 'Object' in each case -
    1.18 + *
    1.19 + * The getJSClass() function we use is in a utility file, e.g. "shell.js"
    1.20 + */
    1.21 +//-----------------------------------------------------------------------------
    1.22 +var i = 0;
    1.23 +var UBound = 0;
    1.24 +var BUGNUMBER = '(none)';
    1.25 +var summary = 'Testing the internal [[Class]] property of user-defined types';
    1.26 +var statprefix = 'Current user-defined type is: ';
    1.27 +var status = ''; var statusList = [ ];
    1.28 +var actual = ''; var actualvalue = [ ];
    1.29 +var expect= ''; var expectedvalue = [ ];
    1.30 +
    1.31 +
    1.32 +Calf.prototype= new Cow();
    1.33 +
    1.34 +/*
    1.35 + * We set the expect variable each time only for readability.
    1.36 + * We expect 'Object' every time; see discussion above -
    1.37 + */
    1.38 +status = 'new Cow()';
    1.39 +actual = getJSClass(new Cow());
    1.40 +expect = 'Object';
    1.41 +addThis();
    1.42 +
    1.43 +status = 'new Calf()';
    1.44 +actual = getJSClass(new Calf());
    1.45 +expect = 'Object';
    1.46 +addThis();
    1.47 +
    1.48 +
    1.49 +//---------------------------------------------------------------------------------
    1.50 +test();
    1.51 +//---------------------------------------------------------------------------------
    1.52 +
    1.53 +
    1.54 +function addThis()
    1.55 +{
    1.56 +  statusList[UBound] = status;
    1.57 +  actualvalue[UBound] = actual;
    1.58 +  expectedvalue[UBound] = expect;
    1.59 +  UBound++;
    1.60 +}
    1.61 +
    1.62 +
    1.63 +function test()
    1.64 +{
    1.65 +  enterFunc ('test');
    1.66 +  printBugNumber(BUGNUMBER);
    1.67 +  printStatus (summary);
    1.68 +
    1.69 +  for (i = 0; i < UBound; i++)
    1.70 +  {
    1.71 +    reportCompare(expectedvalue[i], actualvalue[i], getStatus(i));
    1.72 +  }
    1.73 +
    1.74 +  exitFunc ('test');
    1.75 +}
    1.76 +
    1.77 +
    1.78 +function getStatus(i)
    1.79 +{
    1.80 +  return statprefix + statusList[i];
    1.81 +}
    1.82 +
    1.83 +
    1.84 +function Cow(name)
    1.85 +{
    1.86 +  this.name=name;
    1.87 +}
    1.88 +
    1.89 +
    1.90 +function Calf(name)
    1.91 +{
    1.92 +  this.name=name;
    1.93 +}

mercurial