js/src/tests/js1_5/Scope/scope-002.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/Scope/scope-002.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,108 @@
     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: 2001-07-02
    1.11 + *
    1.12 + * SUMMARY:  Testing visibility of outer function from inner function.
    1.13 + *
    1.14 + */
    1.15 +//-----------------------------------------------------------------------------
    1.16 +var UBound = 0;
    1.17 +var BUGNUMBER = '(none)';
    1.18 +var summary = 'Testing visibility of outer function from inner function';
    1.19 +var cnCousin = 'Fred';
    1.20 +var cnColor = 'red';
    1.21 +var cnMake = 'Toyota';
    1.22 +var status = '';
    1.23 +var statusitems = [];
    1.24 +var actual = '';
    1.25 +var actualvalues = [];
    1.26 +var expect= '';
    1.27 +var expectedvalues = [];
    1.28 +
    1.29 +
    1.30 +// TEST 1
    1.31 +function Outer()
    1.32 +{
    1.33 +
    1.34 +  function inner()
    1.35 +  {
    1.36 +    Outer.cousin = cnCousin;
    1.37 +    return Outer.cousin;
    1.38 +  }
    1.39 +
    1.40 +  status = 'Section 1 of test';
    1.41 +  actual = inner();
    1.42 +  expect = cnCousin;
    1.43 +  addThis();
    1.44 +}
    1.45 +
    1.46 +
    1.47 +Outer();
    1.48 +status = 'Section 2 of test';
    1.49 +actual = Outer.cousin;
    1.50 +expect = cnCousin;
    1.51 +addThis();
    1.52 +
    1.53 +
    1.54 +
    1.55 +// TEST 2
    1.56 +function Car(make)
    1.57 +{
    1.58 +  this.make = make;
    1.59 +  Car.prototype.paint = paint;
    1.60 +
    1.61 +  function paint()
    1.62 +  {
    1.63 +    Car.color = cnColor;
    1.64 +    Car.prototype.color = Car.color;
    1.65 +  }
    1.66 +}
    1.67 +
    1.68 +
    1.69 +var myCar = new Car(cnMake);
    1.70 +status = 'Section 3 of test';
    1.71 +actual = myCar.make;
    1.72 +expect = cnMake;
    1.73 +addThis();
    1.74 +
    1.75 +
    1.76 +myCar.paint();
    1.77 +status = 'Section 4 of test';
    1.78 +actual = myCar.color;
    1.79 +expect = cnColor;
    1.80 +addThis();
    1.81 +
    1.82 +
    1.83 +
    1.84 +//--------------------------------------------------
    1.85 +test();
    1.86 +//--------------------------------------------------
    1.87 +
    1.88 +
    1.89 +
    1.90 +function addThis()
    1.91 +{
    1.92 +  statusitems[UBound] = status;
    1.93 +  actualvalues[UBound] = actual;
    1.94 +  expectedvalues[UBound] = expect;
    1.95 +  UBound++;
    1.96 +}
    1.97 +
    1.98 +
    1.99 +function test()
   1.100 +{
   1.101 +  enterFunc ('test');
   1.102 +  printBugNumber(BUGNUMBER);
   1.103 +  printStatus (summary);
   1.104 +
   1.105 +  for (var i=0; i<UBound; i++)
   1.106 +  {
   1.107 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.108 +  }
   1.109 +
   1.110 +  exitFunc ('test');
   1.111 +}

mercurial