forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop.js
More file actions
202 lines (171 loc) · 4.09 KB
/
loop.js
File metadata and controls
202 lines (171 loc) · 4.09 KB
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
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
function Ctor()
{
}
Ctor.prototype.blah = function()
{
for (var i = 0; i < 10; i++)
{
eval("this.blahnum= 1000; ");
}
}
var a = new Ctor();
a.blah();
WScript.Echo(a.blahnum);
var o = {
f: function(a,b,c) {
WScript.Echo(a,b,c);
},
g: function() {
for(var i = 0; i < 1; ++i)
this.f.apply(this, arguments);
}
};
o.g(1,2,3);
function f() {
for (var i = 0; i < 1; i++) {
var g_args = g.arguments;
WScript.Echo(g_args === f.caller.arguments);
WScript.Echo(g_args.callee === f.caller);
}
}
function g() {
for (var i = 0; i < 1; i++) {
f();
}
}
g('hi');
function test()
{
with({x:"x"})
{
while((function(){ return x; })())
{
WScript.Echo(x);
break;
}
}
}
test();
function retval()
{
for (var i = 0; i < 1; i++)
{
if (i > 1)
{
return i;
}
}
return 0;
}
retval();
function testForInWithPrototype()
{
function LoopResultsOfObject(o, methodName)
{
WScript.Echo(methodName);
var method = eval("Object." + methodName);
var r = method(o);
WScript.Echo("Length: " + r.length);
for (var i in r) {
WScript.Echo(i + " => " + r[i]);
}
}
var protoObject = {}
protoObject.prop1 = "p1";
function MyClass()
{
this.prop2 = "p2";
}
MyClass.prototype = protoObject;
var instance = new MyClass;
LoopResultsOfObject(instance, "getOwnPropertyNames");
LoopResultsOfObject(instance, "keys");
}
testForInWithPrototype();
// Test loop that shouldn't execute and has a side-effect in the loop body
for (var z = 0; z < 0; ++z) {
1 in 2;
}
try {
eval('for (var a, b in z) {}');
}
catch(e) {
WScript.Echo(e.message);
}
try {
Function("for (var a, b in z) {}")();
}
catch(e) {
WScript.Echo(e.message);
}
try {
eval('for (a, b in z) {}');
}
catch(e) {
WScript.Echo(e.message);
}
try {
Function("for (a, b in z) {}")();
}
catch(e) {
WScript.Echo(e.message);
}
// Test loop that has bailout in the loop header and must have vars initialized
// (or bailout may try to box garbage values).
function test_bail(){
var obj0 = {};
var obj1 = {};
var func0 = function(){
}
var func1 = function(p0,p1,p2){
var __loopvar2 = 0;
for(; __loopvar2 < 3 && p2 < (1); __loopvar2++, 14) {
var __loopvar3 = 0;
do {
__loopvar3++;
obj0.prop0 <<=(ary[(8)] - ((obj2.prop3 ^= (++ obj1.prop1)) ? 1701746938.1 : this.prop2));
var obj4 = 1;
} while((1) && __loopvar3 < 3)
}
var obj4 = func0(2147483647, (new RegExp("xyz")), 1.1, 1, (7 ? -970342005 : 1));
}
var func2 = function(){
if(ui8[1073741824]) {
-2;
var __loopvar3 = 0;
for(var strvar0 in obj0 ) {
if(__loopvar3++ > 3) break;
var fPolyProp = function (o) {
if (o!==undefined) {
WScript.Echo(o.prop0 + ' ' + o.prop1 + ' ' + o.prop2);
}
}
fPolyProp(litObj0); fPolyProp(litObj1); fPolyProp(litObj2);
obj2.prop5 = 2147483647;
}
}
for(var __loopvar2 = 0; __loopvar2 < 3; __loopvar2++) {
}
}
obj0.method0 = func2;
var ui8 = new Uint8Array(256);
var __loopvar1 = 0;
do {
__loopvar1++;
(function(p0, p1, p2, p3){
var obj5 = obj0;
obj4 = (new obj5.method0());
})();
} while((1) && __loopvar1 < 3)
if(func1(1, 1)) {
}
};
// generate profile
test_bail();
// run JITted code
test_bail();
WScript.Echo('done')