js/src/tests/js1_5/extensions/regress-435345-01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/extensions/regress-435345-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +// |reftest| fails
     1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +//-----------------------------------------------------------------------------
    1.11 +var BUGNUMBER = 435345;
    1.12 +var summary = 'Watch the length property of arrays';
    1.13 +var actual = '';
    1.14 +var expect = '';
    1.15 +
    1.16 +// see http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Object:watch
    1.17 +
    1.18 +//-----------------------------------------------------------------------------
    1.19 +test();
    1.20 +//-----------------------------------------------------------------------------
    1.21 +
    1.22 +function test()
    1.23 +{
    1.24 +  enterFunc ('test');
    1.25 +  printBugNumber(BUGNUMBER);
    1.26 +  printStatus (summary);
    1.27 +  
    1.28 +  var arr;
    1.29 + 
    1.30 +  try
    1.31 +  {
    1.32 +    expect = 'watcher: propname=length, oldval=0, newval=1; ';
    1.33 +    actual = '';
    1.34 +    arr = [];
    1.35 +    arr.watch('length', watcher);
    1.36 +    arr[0] = '0';
    1.37 +  }
    1.38 +  catch(ex)
    1.39 +  {
    1.40 +    actual = ex + '';
    1.41 +  }
    1.42 +  reportCompare(expect, actual, summary + ': 1');
    1.43 +
    1.44 +  try
    1.45 +  {
    1.46 +    expect = 'watcher: propname=length, oldval=1, newval=2; ' + 
    1.47 +      'watcher: propname=length, oldval=2, newval=2; ';
    1.48 +    actual = '';
    1.49 +    arr.push(5);
    1.50 +  }
    1.51 +  catch(ex)
    1.52 +  {
    1.53 +    actual = ex + '';
    1.54 +  }
    1.55 +  reportCompare(expect, actual, summary + ': 2');
    1.56 +
    1.57 +  try
    1.58 +  {
    1.59 +    expect = 'watcher: propname=length, oldval=2, newval=1; ';
    1.60 +    actual = '';
    1.61 +    arr.pop();
    1.62 +  }
    1.63 +  catch(ex)
    1.64 +  {
    1.65 +    actual = ex + '';
    1.66 +  }
    1.67 +  reportCompare(expect, actual, summary + ': 3');
    1.68 +
    1.69 +  try
    1.70 +  {
    1.71 +    expect = 'watcher: propname=length, oldval=1, newval=2; ';
    1.72 +    actual = '';
    1.73 +    arr.length++;
    1.74 +  }
    1.75 +  catch(ex)
    1.76 +  {
    1.77 +    actual = ex + '';
    1.78 +  }
    1.79 +  reportCompare(expect, actual, summary + ': 4');
    1.80 +
    1.81 +  try
    1.82 +  {
    1.83 +    expect = 'watcher: propname=length, oldval=2, newval=5; ';
    1.84 +    actual = '';
    1.85 +    arr.length = 5;
    1.86 +  }
    1.87 +  catch(ex)
    1.88 +  {
    1.89 +    actual = ex + '';
    1.90 +  }
    1.91 +  reportCompare(expect, actual, summary + ': 5');
    1.92 +
    1.93 +  exitFunc ('test');
    1.94 +}
    1.95 +
    1.96 +function watcher(propname, oldval, newval)
    1.97 +{
    1.98 +  actual += 'watcher: propname=' + propname + ', oldval=' + oldval + 
    1.99 +    ', newval=' + newval + '; ';
   1.100 +
   1.101 +  return newval;
   1.102 +}
   1.103 +

mercurial