-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathWith.js
178 lines (152 loc) · 3.52 KB
/
With.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
function A(k)
{
this.k = k;
}
var x = new A(1);
var y = new A(undefined);
var i = 1;
var j = 2;
with (x)
{
i = 2;
with (A.prototype)
{
i = 3;
x.i = 77;
i = 4;
}
with (y)
{
i = 4.0;
j = "y.j";
y.j = undefined;
k = null;
}
A.prototype.i = undefined;
with (A.prototype)
{
i = 99;
}
WScript.Echo(i);
WScript.Echo(j);
WScript.Echo(k);
with (y)
{
WScript.Echo(i);
if (j === undefined)
WScript.Echo("undefined");
WScript.Echo(k);
}
j = 0;
k = "x.k";
var foo = function f() {
var i = 'local.i';
WScript.Echo(i);
WScript.Echo(foo.length);
};
x.foo = 'x.foo';
}
WScript.Echo(i);
WScript.Echo(A.prototype.i);
WScript.Echo(x.i);
WScript.Echo(y.i);
WScript.Echo(j);
if (A.prototype.j === undefined)
WScript.Echo("undefined");
if (x.j === undefined)
WScript.Echo("undefined");
if (y.j === undefined)
WScript.Echo("undefined");
WScript.Echo(x.k);
WScript.Echo(y.k);
WScript.Echo(x.foo);
foo();
try
{
f(); // doesn't escape the blocks cope
} catch (e) {
WScript.Echo(e);
}
function foo2() {
var a1 = new Object();
a1.foo = 16;
a1.bar = "abcd";
with ( a1 ) {
a1 = new Object();
a1.foo = 16;
a1.bar = "dcba";
WScript.Echo(bar);
}
}
foo2();
var evalinwith = 'global evalinwith';
(function (){
var O = {evalinwith:'no'};
with(O)
{
eval('var evalinwith = "O.evalinwith"');
eval('WScript.Echo(evalinwith + "")');
}
evalinwith = 'local evalinwith';
eval('WScript.Echo(evalinwith + "")');
})();
eval('WScript.Echo(evalinwith + "")');
function verify(act, msg) { WScript.Echo(msg + ': ' + act); }
var level1Func = function level1FuncIdent() {
var level1 = "level1";
with({level1: ""}) {
try {
throw "throw";
} catch(level1) {}
}
verify(level1, "Value of level1 after assignment at level 1");
}
level1Func();
(function () {
function a()
{
WScript.Echo("a is called");
}
(function(){
try {
throw a;
}
catch(x) {
with({}){
x();
}
}
})();
})();
// Guarantee that function-body-in-array script length heuristic is not broken
// by compat mode named-function-expression-in-with.
with ({}) {
var arrwithfunc = [(function handlerFactory() { return; })];
}
(function() {
function outer() {
function inner(){ WScript.Echo('in inner') }
with({})
{
{
(function(){ inner(); })();
}
}
}
outer();
})();
(function() {
{
function inner() { WScript.Echo('in inner'); }
function outer() {
with({}) {
inner();
}
}
}
outer();
})();