js/src/tests/js1_5/Scope/scope-003.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-003.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     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-03
    1.11 + *
    1.12 + * SUMMARY:  Testing scope with nested functions
    1.13 + *
    1.14 + * From correspondence with Christopher Oliver <coliver@mminternet.com>:
    1.15 + *
    1.16 + * > Running this test with Rhino produces the following exception:
    1.17 + * >
    1.18 + * > uncaught JavaScript exception: undefined: Cannot find default value for
    1.19 + * > object. (line 3)
    1.20 + * >
    1.21 + * > This is due to a bug in org.mozilla.javascript.NativeCall which doesn't
    1.22 + * > implement toString or valueOf or override getDefaultValue.
    1.23 + * > However, even after I hacked in an implementation of getDefaultValue in
    1.24 + * > NativeCall, Rhino still produces a different result then SpiderMonkey:
    1.25 + * >
    1.26 + * > [object Call]
    1.27 + * > [object Object]
    1.28 + * > [object Call]
    1.29 + *
    1.30 + * Note the results should be:
    1.31 + *
    1.32 + *   [object global]
    1.33 + *   [object Object]
    1.34 + *   [object global]
    1.35 + *
    1.36 + * This is what we are checking for in this testcase -
    1.37 + */
    1.38 +//-----------------------------------------------------------------------------
    1.39 +var UBound = 0;
    1.40 +var BUGNUMBER = '(none)';
    1.41 +var summary = 'Testing scope with nested functions';
    1.42 +var statprefix = 'Section ';
    1.43 +var statsuffix = ' of test -';
    1.44 +var self = this; // capture a reference to the global object;
    1.45 +var cnGlobal = self.toString();
    1.46 +var cnObject = (new Object).toString();
    1.47 +var statusitems = [];
    1.48 +var actualvalues = [];
    1.49 +var expectedvalues = [];
    1.50 +
    1.51 +
    1.52 +function a()
    1.53 +{
    1.54 +  function b()
    1.55 +  {
    1.56 +    capture(this.toString());
    1.57 +  }
    1.58 +
    1.59 +  this.c = function()
    1.60 +    {
    1.61 +      capture(this.toString());
    1.62 +      b();
    1.63 +    }
    1.64 +
    1.65 +  b();
    1.66 +}
    1.67 +
    1.68 +
    1.69 +var obj = new a();  // captures actualvalues[0]
    1.70 +obj.c();            // captures actualvalues[1], actualvalues[2]
    1.71 +
    1.72 +
    1.73 +// The values we expect - see introduction above -
    1.74 +expectedvalues[0] = cnGlobal;
    1.75 +expectedvalues[1] = cnObject;
    1.76 +expectedvalues[2] = cnGlobal;
    1.77 +
    1.78 +
    1.79 +
    1.80 +//-----------------------------------------------------------------------------
    1.81 +test();
    1.82 +//-----------------------------------------------------------------------------
    1.83 +
    1.84 +
    1.85 +
    1.86 +function capture(val)
    1.87 +{
    1.88 +  actualvalues[UBound] = val;
    1.89 +  statusitems[UBound] = getStatus(UBound);
    1.90 +  UBound++;
    1.91 +}
    1.92 +
    1.93 +
    1.94 +function test()
    1.95 +{
    1.96 +  enterFunc ('test');
    1.97 +  printBugNumber(BUGNUMBER);
    1.98 +  printStatus (summary);
    1.99 +
   1.100 +  for (var i=0; i<UBound; i++)
   1.101 +  {
   1.102 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.103 +  }
   1.104 +
   1.105 +  exitFunc ('test');
   1.106 +}
   1.107 +
   1.108 +
   1.109 +function getStatus(i)
   1.110 +{
   1.111 +  return statprefix + i + statsuffix;
   1.112 +}

mercurial