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
|
// |reftest| skip-if(!xulRuntime.shell)
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//-----------------------------------------------------------------------------
var BUGNUMBER = 384412;
var summary = 'Exercise frame handling code';
var actual = '';
var expect = '';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
/*
* Generators
*/
/* Generator yields properly */
f = (function(n) { for (var i = 0; i != n; i++) yield i });
g = f(3);
expect(0, g.next());
expect(1, g.next());
expect(2, g.next());
s = "no exception";
try { g.next(); } catch (e) { s = e + ""; }
expect("[object StopIteration]", s);
/* Generator yields properly in finally */
f = (function(n) {
try {
for (var i = 0; i != n; i++)
yield i;
} finally {
yield "finally";
}
});
g = f(3);
expect(0, g.next());
expect(1, g.next());
expect(2, g.next());
expect("finally", g.next());
/* Generator throws when closed with yield in finally */
g = f(3);
expect(0, g.next());
s = "no exception";
try { g.close(); } catch (e) { s = e + ""; };
expect("TypeError: yield from closing generator " + f.toSource(), s);
/*
* Calls that have been replaced with js_PushFrame() &c...
*/
f = (function() { return arguments[(arguments.length - 1) / 2]; });
expect(2, f(1, 2, 3));
expect(2, f.call(null, 1, 2, 3));
expect(2, f.apply(null, [1, 2, 3]));
expect("a1c", "abc".replace("b", f));
s = "no exception";
try {
"abc".replace("b", (function() { throw "hello" }));
} catch (e) {
s = e + "";
}
expect("hello", s);
expect(6, [1, 2, 3].reduce(function(a, b) { return a + b; }));
s = "no exception";
try {
[1, 2, 3].reduce(function(a, b) { if (b == 2) throw "hello"; });
} catch (e) {
s = e + "";
}
expect("hello", s);
print("End of Tests");
/*
* Utility functions
*/
function expect(a, b) {
print('expect: ' + a + ', actual: ' + b);
reportCompare(a, b, summary);
}
exitFunc ('test');
}
|