Debian Codegraph @

rhino/testsrc/tests/js1_5/Scope/regress-191276.js

raw symbols SCIP
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 gTestfile = 'regress-191276.js';
20 var UBound = 0;
21 var BUGNUMBER = 191276;
22 var summary = 'Testing |this[name]| via Function.prototype.call(), apply()';
23 var status = '';
24 var statusitems = [];
25 var actual = '';
26 var actualvalues = [];
27 var expect= '';
28 var expectedvalues = [];
29
30
31 function F(name)
32 {
33 return this[name];
34 }
35
36 function unused_function()
37 {
38 F('a');
39 }
40
41 status = inSection(1);
42 actual = F.call({a: 'aaa'}, 'a');
43 expect = 'aaa';
44 addThis();
45
46 status = inSection(2);
47 actual = F.apply({a: 'aaa'}, ['a']);
48 expect = 'aaa';
49 addThis();
50
51 /*
52 * Try the same things with an object variable instead of a literal
53 */
54 var obj = {a: 'aaa'};
55
56 status = inSection(3);
57 actual = F.call(obj, 'a');
58 expect = 'aaa';
59 addThis();
60
61 status = inSection(4);
62 actual = F.apply(obj, ['a']);
63 expect = 'aaa';
64 addThis();
65
66
67
68 //-----------------------------------------------------------------------------
69 test();
70 //-----------------------------------------------------------------------------
71
72
73
74 function addThis()
75 {
76 statusitems[UBound] = status;
77 actualvalues[UBound] = actual;
78 expectedvalues[UBound] = expect;
79 UBound++;
80 }
81
82
83 function test()
84 {
85 enterFunc('test');
86 printBugNumber(BUGNUMBER);
87 printStatus(summary);
88
89 for (var i=0; i<UBound; i++)
90 {
91 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
92 }
93
94 exitFunc ('test');
95 }