-
Notifications
You must be signed in to change notification settings - Fork 1
/
goto.html
71 lines (62 loc) · 1.07 KB
/
goto.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width"/>
<title>GOTO tests (not for the evil)</title>
<script src="tests.common.js"></script>
</head>
<body>
<script>
Tests.test(function (t)
{
t.log('This test had been written to check if its possibile to emulate some kind of “goto” in JS. It would be useful in the yarv2js project.')
t.test('an old dirty loop', function (t)
{
var i = 0
A: for (;;) // continue needs “for (;;)”
{
if (i == 5)
break A // goto B
i++
continue A // goto A
t.fail('continue does not work')
break A // goto B (never reached)
}
// here is B:
t.eq(i, 5, 'loop index is ok')
})
t.test('external jump', function (t)
{
var i = 0
A:
{
for (var i = 0; i < 10; i++)
if (i == 5)
break A
}
t.eq(i, 5, 'loop index is ok')
})
t.test('nested jumps', function (t)
{
var i = 0
A:
{
B:
{
C:
{
break B
i++
}
i++
}
i++
break A
i++
}
t.eq(i, 1, 'index is ok')
})
})
</script>
</body>
</html>