js/src/tests/js1_5/Scope/regress-191276.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:bbe2874f4b95
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /*
7 *
8 * Date: 30 January 2003
9 * SUMMARY: Testing |this[name]| via Function.prototype.call(), apply()
10 *
11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=191276
12 *
13 * Igor: "This script fails when run in Rhino compiled mode, but passes in
14 * interpreted mode. Note that presence of the never-called |unused_function|
15 * with |f('a')| line is essential; the script works OK without it."
16 *
17 */
18 //-----------------------------------------------------------------------------
19 var UBound = 0;
20 var BUGNUMBER = 191276;
21 var summary = 'Testing |this[name]| via Function.prototype.call(), apply()';
22 var status = '';
23 var statusitems = [];
24 var actual = '';
25 var actualvalues = [];
26 var expect= '';
27 var expectedvalues = [];
28
29
30 function F(name)
31 {
32 return this[name];
33 }
34
35 function unused_function()
36 {
37 F('a');
38 }
39
40 status = inSection(1);
41 actual = F.call({a: 'aaa'}, 'a');
42 expect = 'aaa';
43 addThis();
44
45 status = inSection(2);
46 actual = F.apply({a: 'aaa'}, ['a']);
47 expect = 'aaa';
48 addThis();
49
50 /*
51 * Try the same things with an object variable instead of a literal
52 */
53 var obj = {a: 'aaa'};
54
55 status = inSection(3);
56 actual = F.call(obj, 'a');
57 expect = 'aaa';
58 addThis();
59
60 status = inSection(4);
61 actual = F.apply(obj, ['a']);
62 expect = 'aaa';
63 addThis();
64
65
66
67 //-----------------------------------------------------------------------------
68 test();
69 //-----------------------------------------------------------------------------
70
71
72
73 function addThis()
74 {
75 statusitems[UBound] = status;
76 actualvalues[UBound] = actual;
77 expectedvalues[UBound] = expect;
78 UBound++;
79 }
80
81
82 function test()
83 {
84 enterFunc('test');
85 printBugNumber(BUGNUMBER);
86 printStatus(summary);
87
88 for (var i=0; i<UBound; i++)
89 {
90 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
91 }
92
93 exitFunc ('test');
94 }

mercurial