]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_5/Scope/scope-001.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / js1_5 / Scope / scope-001.js
1 /*
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is mozilla.org code.
13 *
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
17 * Rights Reserved.
18 *
19 * Contributor(s): pschwartau@netscape.com
20 *
21 *
22 * The idea behind bug 53268 is as follows. The item 'five' below is defined
23 * as const, hence is a read-only property of the global object. So if we set
24 * obj.__proto__ = this, 'five' should become a read-only propery of obj.
25 *
26 * If we then change obj.__proto__ to null, obj.five should initially be
27 * undefined. We should be able to define obj.five to whatever we want,
28 * and be able to access this value as obj.five.
29 *
30 * Bug 53268 was filed because obj.five could not be set or accessed after
31 * obj.__proto__ had been set to the global object and then to null.
32 */
33 //-----------------------------------------------------------------------------
34 var bug = '53268';
35 var status = 'Testing scope after changing obj.__proto__';
36 var expect= '';
37 var actual = '';
38 var obj = {};
39 const five = 5;
40
41
42 //-----------------------------------------------------------------------------
43 test();
44 //-----------------------------------------------------------------------------
45
46
47 function test()
48 {
49 enterFunc ("test");
50 printBugNumber (bug);
51 printStatus (status);
52
53
54 status= 'Step 1: setting obj.__proto__ = global object';
55 obj.__proto__ = this;
56
57 actual = obj.five;
58 expect=5;
59 reportCompare (expect, actual, status);
60
61 obj.five=1;
62 actual = obj.five;
63 expect=5;
64 reportCompare (expect, actual, status);
65
66
67
68 status= 'Step 2: setting obj.__proto__ = null';
69 obj.__proto__ = null;
70
71 actual = obj.five;
72 expect=undefined;
73 reportCompare (expect, actual, status);
74
75 obj.five=2;
76 actual = obj.five;
77 expect=2;
78 reportCompare (expect, actual, status);
79
80
81
82 status= 'Step 3: setting obj.__proto__ to global object again';
83 obj.__proto__ = this;
84
85 actual = obj.five;
86 expect=2; //<--- (FROM STEP 2 ABOVE)
87 reportCompare (expect, actual, status);
88
89 obj.five=3;
90 actual = obj.five;
91 expect=3;
92 reportCompare (expect, actual, status);
93
94
95
96 status= 'Step 4: setting obj.__proto__ to null again';
97 obj.__proto__ = null;
98
99 actual = obj.five;
100 expect=3; //<--- (FROM STEP 3 ABOVE)
101 reportCompare (expect, actual, status);
102
103 obj.five=4;
104 actual = obj.five;
105 expect=4;
106 reportCompare (expect, actual, status);
107
108
109 exitFunc ("test");
110 }