Debian Codegraph @

rhino/testsrc/tests/js1_5/Scope/regress-184107.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: 09 December 2002
9 * SUMMARY: with(...) { function f ...} should set f in the global scope
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=184107
11 *
12 * In fact, any variable defined in a with-block should be created
13 * in global scope, i.e. should be a property of the global object.
14 *
15 * The with-block syntax allows existing local variables to be SET,
16 * but does not allow new local variables to be CREATED.
17 *
18 * See http://bugzilla.mozilla.org/show_bug.cgi?id=159849#c11
19 */
20 //-----------------------------------------------------------------------------
21 var gTestfile = 'regress-184107.js';
22 var UBound = 0;
23 var BUGNUMBER = 184107;
24 var summary = 'with(...) { function f ...} should set f in the global scope';
25 var status = '';
26 var statusitems = [];
27 var actual = '';
28 var actualvalues = [];
29 var expect= '';
30 var expectedvalues = [];
31
32 var obj = {y:10};
33 with (obj)
34 {
35 // function statement
36 function f()
37 {
38 return y;
39 }
40
41 // function expression
42 g = function() {return y;}
43 }
44
45 status = inSection(1);
46 actual = obj.f;
47 expect = undefined;
48 addThis();
49
50 status = inSection(2);
51 actual = f();
52 expect = obj.y;
53 addThis();
54
55 status = inSection(3);
56 actual = obj.g;
57 expect = undefined;
58 addThis();
59
60 status = inSection(4);
61 actual = g();
62 expect = obj.y;
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 }