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

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:652352571e02
1 // |reftest| fails
2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = 435345;
9 var summary = 'Watch the length property of arrays';
10 var actual = '';
11 var expect = '';
12
13 // see http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Object:watch
14
15 //-----------------------------------------------------------------------------
16 test();
17 //-----------------------------------------------------------------------------
18
19 function test()
20 {
21 enterFunc ('test');
22 printBugNumber(BUGNUMBER);
23 printStatus (summary);
24
25 var arr;
26
27 try
28 {
29 expect = 'watcher: propname=length, oldval=0, newval=1; ';
30 actual = '';
31 arr = [];
32 arr.watch('length', watcher);
33 arr[0] = '0';
34 }
35 catch(ex)
36 {
37 actual = ex + '';
38 }
39 reportCompare(expect, actual, summary + ': 1');
40
41 try
42 {
43 expect = 'watcher: propname=length, oldval=1, newval=2; ' +
44 'watcher: propname=length, oldval=2, newval=2; ';
45 actual = '';
46 arr.push(5);
47 }
48 catch(ex)
49 {
50 actual = ex + '';
51 }
52 reportCompare(expect, actual, summary + ': 2');
53
54 try
55 {
56 expect = 'watcher: propname=length, oldval=2, newval=1; ';
57 actual = '';
58 arr.pop();
59 }
60 catch(ex)
61 {
62 actual = ex + '';
63 }
64 reportCompare(expect, actual, summary + ': 3');
65
66 try
67 {
68 expect = 'watcher: propname=length, oldval=1, newval=2; ';
69 actual = '';
70 arr.length++;
71 }
72 catch(ex)
73 {
74 actual = ex + '';
75 }
76 reportCompare(expect, actual, summary + ': 4');
77
78 try
79 {
80 expect = 'watcher: propname=length, oldval=2, newval=5; ';
81 actual = '';
82 arr.length = 5;
83 }
84 catch(ex)
85 {
86 actual = ex + '';
87 }
88 reportCompare(expect, actual, summary + ': 5');
89
90 exitFunc ('test');
91 }
92
93 function watcher(propname, oldval, newval)
94 {
95 actual += 'watcher: propname=' + propname + ', oldval=' + oldval +
96 ', newval=' + newval + '; ';
97
98 return newval;
99 }
100

mercurial