forked from nilproject/NiL.JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuzz.js
300 lines (226 loc) · 7.62 KB
/
fuzz.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
try {
eval('(function(){})(,1);');
console.log("empty func argument fail #1");
}
catch (e) {
if (!(e instanceof SyntaxError))
console.log("empty func argument fail #1.1");
}
try {
eval('(function(){})(1,,1);');
console.log("empty func argument fail #2");
}
catch (e) {
if (!(e instanceof SyntaxError))
console.log("empty func argument fail #2.1");
}
try {
eval('(function(){})(1,);');
console.log("empty func argument fail #3");
}
catch (e) {
if (!(e instanceof SyntaxError))
console.log("empty func argument fail #3.1");
}
var f = eval("function functionInsideEval(){}");
for ([, ]; false;);
(function () {
var s0 = Symbol();
var s1 = Symbol();
var o = {};
o[s0] = 1;
if (o[s0] !== 1)
console.log("Can not get value by Symbol");
if (o[s0] === o[s1])
console.log("Incorrect keying with symbols");
})();
function func(x) {
return x + 1;
}
(function (x, y) { if (x == y) console.log("a(1) == a(2)"); })(func(1), func(2));
function x2(x) {
return 2 * x;
}
(function (a, b) { with ({}) if (a == b) console.log("Weak parameters") })(x2(2), x2(3));
if (Math.max(...[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) != 9)
console.log("Spread in proxied method works incorrectly");
function func1(a, b, ...rest) {
if (JSON.stringify(rest) !== JSON.stringify([2, 3, 4]))
console.log("Invalid rest parameters container");
if (JSON.stringify(arguments) !== JSON.stringify({ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4 }))
console.log("Invalid arguments object inside function with rest parameters");
return arguments.length;
}
var test = {};
test[Symbol.iterator] = function* () {
for (var i = 0; i < 5; i++)
yield i;
}
if (func1(...test) !== 5)
console.log("Function with rest parameters returns invalid value");
(function (...args) {
if (JSON.stringify(args) !== JSON.stringify([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, "word"]))
console.log("Spread operator in array definition work incorrectly");
})(...[1, 2, 3, 4, ...[5, 6, 7, 8], 9, 0], "word");
function funcWhichReturnThis() {
return this;
}
var b0 = funcWhichReturnThis.bind(undefined);
if (b0() !== function () { return this; } ())
console.log("Invalid this linking for binded function #1");
var b1 = funcWhichReturnThis.bind(null);
if (b1() !== function () { return this; } ())
console.log("Invalid this linking for binded function #2");
function bindedConstruct() {
function f() { return this; };
return new (f.bind({ fake: 'value' }))();
}
if (bindedConstruct().fake !== undefined)
console.log("Invalid [[Construct]] of binded function");
var i = 1;
(function (p) { (function (x, y) { if (x != 1) console.log("Incorrect parameters processing #1"); })(p, i = 2) })(i);
i = 1;
(function (p) { (function (x, y) { i = 2; if (x != 1) console.log("Incorrect parameters processing #2"); })(p) })(i);
i = 1;
(function (p) { (function (x, y) { i = 2; if (x != 1) console.log("Incorrect parameters processing #3"); })(p, p) })(i);
(function (p) { (function (x, y) { if (x != true) console.log("Incorrect parameters processing #4"); })(p, i = 2) })(true);
(function (p) { (function (x, y) { p = 2; if (x != true) console.log("Incorrect parameters processing #5"); })(p) })(true);
(function (x) { var a = [x]; a[0] = 2; if (x != 1) console.log("Incorrect clone flag in fast function"); })(1);
(function (x) { var a = [x]; a[0] = 2; if (x != 1) console.log("Incorrect clone flag in regular function"); })(1, 2);
if ((new class extends null { get test() { return "hello" } }).test != "hello")
console.log("Something wrong with classes");
(function () {
var e = eval;
e("var mustBeDeclaredInGlobalContext = " + eval("'2'"));
(1, eval)("var mustBeDeclaredInGlobalContext_second = 2");
})();
if (typeof mustBeDeclaredInGlobalContext === "undefined")
console.log("Incorrect processing of eval function");
if (typeof mustBeDeclaredInGlobalContext_second === "undefined")
console.log("Incorrect processing of eval function");
var functionInExpression = function () {
function test() {
return 1;
}
return test();
}
functionInExpression();
function runEvalTest(x) {
x();
}
eval('\
function testEval() {\
}\
\
runEvalTest(testEval);');
function twoParametersWithSameName(x, x) {
return x;
}
if (!(twoParametersWithSameName(1, 2) === 2)) {
$ERROR("#1: twoParametersWithSameName(1, 2) === 2");
}
class A {
constructor() {
this.text = new.target.name;
}
}
class B extends A { constructor() { super(); } }
var a = new A().text;
var b = new B().text;
if (a != "A")
console.log("new.target works incorrectly");
if (b != "B")
console.log("new.target works incorrectly");
a = console ? 1 : 2, { test: 1 };
(function () {
// parse only
var r;
if (r) for (t = 0; u > t; t++) n[t][e][1] /= r; else for (t = 0; u > t; t++) n[t][e][1] = o;
(this||/[/]/);
});
var undefined;
try {
undefined.test = 1;
console.log("'undefined.test = 1' did not thrown exception")
}
catch (e) {
}
try {
delete undefined.test;
console.log("'delete undefined.test' did not thrown exception")
}
catch (e) {
}
JSON.stringify(new Date());
if (JSON.stringify([,1])!=='[null,1]')
console.log(`JSON.stringify works incorrectly (${JSON.stringify([,1])})`);
if (JSON.stringify([,,1])!=='[null,null,1]')
console.log(`JSON.stringify works incorrectly (${JSON.stringify([,,1])})`);
({get [1](){return 1;},[2]:2})
console.assert(((x) => { var r = "" + x; return r })("123"), "123");
if (Object.name !== "Object")
throw "Invalid name of Object(...)";
if (Object.toString() !== "function Object() { [native code] }")
throw "Incorrect toString of Object(...)";
Object.toString = () =>'hello';
if (Object.toString() === "function Object() { [native code] }")
throw "toString of Object(...) does not change";
if ([1, , 2, 3][['length']] != 4)
throw "Invalid array.length optimization";
if (isNaN.__proto__ != Function.__proto__)
throw "Incorrect prototype of ExternalFunction";
[...new Date()];
console.asserta(() => Error.constructor == Function.constructor);
console.asserta(() => Error.constructor().__proto__ == Function.prototype);
console.asserta(() => Object.call(Error).__proto__ == Object.prototype);
if ((function(a = 5) { return a })() != 5)
throw new 'Something wrong with default parameter value';
if ("1234".substring(0, null) !== "")
throw "null should be used as 0";
if ("1234".substring(0, undefined) !== "1234")
throw "undefined should be used as string.length";
[][""];
var _should_be_changed_ = 'initial';
Math.abs(0, _should_be_changed_ = '1');
Math.random(_should_be_changed_ += '2');
if (_should_be_changed_ !== '12')
throw "Incorrect arguments processing in MethodProxy";
console.asserta(() => (new class {}).toString(), {}.toString());
console.asserta(() => 0b11, 3);
console.asserta(() => 0o11, 9);
console.asserta(() => 0x11, 17);
for (let i = 0; i < 1; i++) {
let i = NaN;
isNaN(i);
(function () {
isNaN(i);
})();
}
(function(){
var A = new Array(8).fill(0);
A[5] = A[5] + 4;
if (A[0] !== 0)
throw "Array.prototype fill is broken";
})();
(function () {
eval("function ok(){} ok()");
eval("()=>(ok())")();
try {
eval("function(){}")();
console.log("Error in function hoisting");
} catch (e) {
// OK
}
})();
console.asserta(() => 1..__proto__, Number.prototype);
(function () {
function f({ a } = { a: 1 }, c = f({ a: 1 }, 2)) {
if (!c)
return 1;
}
f();
})();
console.asserta(() => JSON.stringify({ 1: 1, 2: { 1: 1 } }, [1]), "{\"1\":1}")
var o = {};
JSON.stringify([o, o]);
JSON.stringify([o, [o]]);