-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathcallmissingtgt.js
218 lines (179 loc) · 5.62 KB
/
callmissingtgt.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
var echo = WScript.Echo;
var globalObject = this;
var o = {};
function foo() {
echo(" ", "Evaluate arg list");
}
function test(title, f) {
echo(title);
try {
f();
} catch (e) {
echo(" ", e.name);
}
echo();
}
test("Global member missing", function () {
bar(foo());
});
test("Global member undefined", function () {
bar = undefined;
bar(foo());
});
test("Global member null", function () {
bar = null;
bar(foo());
});
test("Global member is not callable", function () {
bar = 23;
bar(foo());
});
if (Object.defineProperties) {
test("Global member getter returns undefined", function () {
Object.defineProperty(this, "bar", {
get: function () { },
configurable: true
});
bar(foo());
});
test("Global member getter returns null", function () {
Object.defineProperty(this, "bar", {
get: function () { return null; },
configurable: true
});
bar(foo());
});
}
echo();
test("Global member missing via property reference via dot syntax", function () {
globalObject.baz(foo());
});
test("Global member undefined via property reference via dot syntax", function () {
globalObject.baz = undefined;
globalObject.baz(foo());
});
test("Global member null via property reference via dot syntax", function () {
globalObject.baz = null;
globalObject.baz(foo());
});
test("Global member is not callable via property reference via dot syntax", function () {
globalObject.baz = 23;
globalObject.baz(foo());
});
if (Object.defineProperties) {
test("Global member getter returns undefined via property reference via dot syntax", function () {
Object.defineProperty(this, "baz", {
get: function () { },
configurable: true
});
globalObject.baz(foo());
});
test("Global member getter returns null via property reference via dot syntax", function () {
Object.defineProperty(this, "baz", {
get: function () { return null; },
configurable: true
});
globalObject.baz(foo());
});
}
echo();
function elementname() { return "buz"; }
test("Global member missing via property reference via element access syntax", function () {
globalObject[elementname()](foo());
});
test("Global member undefined via property reference via element access syntax", function () {
globalObject[elementname()] = undefined;
globalObject[elementname()](foo());
});
test("Global member null via property reference via element access syntax", function () {
globalObject[elementname()] = null;
globalObject[elementname()](foo());
});
test("Global member is not callable via property reference via element access syntax", function () {
globalObject[elementname()] = 23;
globalObject[elementname()](foo());
});
if (Object.defineProperties) {
test("Global member getter returns undefined via property reference via element access syntax", function () {
Object.defineProperty(this, elementname(), {
get: function () { },
configurable: true
});
globalObject[elementname()](foo());
});
test("Global member getter returns null via property reference via element access syntax", function () {
Object.defineProperty(this, elementname(), {
get: function () { return null; },
configurable: true
});
globalObject[elementname()](foo());
});
}
echo();
test("Object member missing", function () {
o.bar(foo());
});
test("Object member undefined", function () {
o.bar = undefined;
o.bar(foo());
});
test("Object member null", function () {
o.bar = null;
o.bar(foo());
});
test("Object member is not callable", function () {
o.bar = 23;
o.bar(foo());
});
if (Object.defineProperties) {
test("Object member getter returns undefined", function () {
Object.defineProperty(o, "bar", {
get: function () { },
configurable: true
});
o.bar(foo());
});
test("Object member getter returns null", function () {
Object.defineProperty(o, "bar", {
get: function () { return null; },
configurable: true
});
o.bar(foo());
});
}
echo();
test("Object element missing", function () {
o[3](foo());
});
test("Object element undefined", function () {
o[3] = undefined;
o[3](foo());
});
test("Object element null", function () {
o[3] = null;
o[3](foo());
});
test("Object element is not callable", function () {
o[3] = 23;
o[3](foo());
});
if (Object.defineProperties) {
test("Object element getter returns undefined", function () {
Object.defineProperty(o, 3, {
get: function () { },
configurable: true
});
o[3](foo());
});
test("Object element getter returns null", function () {
Object.defineProperty(o, 3, {
get: function () { return null; },
configurable: true
});
o[3](foo());
});
}