| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
var gTestfile = 'regress-384412.js'; |
| 7 |
|
| 8 |
var BUGNUMBER = 384412; |
| 9 |
var summary = 'Exercise frame handling code'; |
| 10 |
var actual = ''; |
| 11 |
var expect = ''; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
test(); |
| 16 |
|
| 17 |
|
| 18 |
function test() |
| 19 |
{ |
| 20 |
enterFunc ('test'); |
| 21 |
printBugNumber(BUGNUMBER); |
| 22 |
printStatus (summary); |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
f = (function(n) { for (var i = 0; i != n; i++) yield i }); |
| 30 |
g = f(3); |
| 31 |
expect(0, g.next()); |
| 32 |
expect(1, g.next()); |
| 33 |
expect(2, g.next()); |
| 34 |
s = "no exception"; |
| 35 |
try { g.next(); } catch (e) { s = e + ""; } |
| 36 |
expect("[object StopIteration]", s); |
| 37 |
|
| 38 |
|
| 39 |
f = (function(n) { |
| 40 |
try { |
| 41 |
for (var i = 0; i != n; i++) |
| 42 |
yield i; |
| 43 |
} finally { |
| 44 |
yield "finally"; |
| 45 |
} |
| 46 |
}); |
| 47 |
|
| 48 |
g = f(3); |
| 49 |
expect(0, g.next()); |
| 50 |
expect(1, g.next()); |
| 51 |
expect(2, g.next()); |
| 52 |
expect("finally", g.next()); |
| 53 |
|
| 54 |
|
| 55 |
g = f(3); |
| 56 |
expect(0, g.next()); |
| 57 |
s = "no exception"; |
| 58 |
try { g.close(); } catch (e) { s = e + ""; }; |
| 59 |
expect("TypeError: yield from closing generator " + f.toSource(), s); |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
t = <xml><eins><name>ich</name></eins><eins><name>joki</name></eins></xml>; |
| 66 |
|
| 67 |
|
| 68 |
expect(<eins><name>joki</name></eins>, t.eins.(name == "joki")); |
| 69 |
expect(t.eins, t.eins.(t.eins.(true))); |
| 70 |
expect(t.(false), t.eins.(false).(true)); |
| 71 |
|
| 72 |
|
| 73 |
f = (function() { t.eins.(yield true); }); |
| 74 |
g = f(); |
| 75 |
s = "no exception"; |
| 76 |
try { g.next(); } catch (e) { s = e + ""; } |
| 77 |
expect("no exception", s); |
| 78 |
|
| 79 |
|
| 80 |
f = (function() { t.eins.(true); }); |
| 81 |
expect(undefined, f()); |
| 82 |
|
| 83 |
|
| 84 |
f = (function() { |
| 85 |
try { |
| 86 |
return "hallo"; |
| 87 |
} finally { |
| 88 |
t.eins.(true); |
| 89 |
} |
| 90 |
}); |
| 91 |
expect("hallo", f()); |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
f = (function() { return arguments[(arguments.length - 1) / 2]; }); |
| 98 |
expect(2, f(1, 2, 3)); |
| 99 |
expect(2, f.call(null, 1, 2, 3)); |
| 100 |
expect(2, f.apply(null, [1, 2, 3])); |
| 101 |
expect("a1c", "abc".replace("b", f)); |
| 102 |
s = "no exception"; |
| 103 |
try { |
| 104 |
"abc".replace("b", (function() { throw "hello" })); |
| 105 |
} catch (e) { |
| 106 |
s = e + ""; |
| 107 |
} |
| 108 |
expect("hello", s); |
| 109 |
expect(6, [1, 2, 3].reduce(function(a, b) { return a + b; })); |
| 110 |
s = "no exception"; |
| 111 |
try { |
| 112 |
[1, 2, 3].reduce(function(a, b) { if (b == 2) throw "hello"; }); |
| 113 |
} catch (e) { |
| 114 |
s = e + ""; |
| 115 |
} |
| 116 |
expect("hello", s); |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
o = {}; |
| 122 |
s = "no exception"; |
| 123 |
try { |
| 124 |
o.hello(); |
| 125 |
} catch (e) { |
| 126 |
s = e + ""; |
| 127 |
} |
| 128 |
expect("TypeError: o.hello is not a function", s); |
| 129 |
o.__noSuchMethod__ = (function() { return "world"; }); |
| 130 |
expect("world", o.hello()); |
| 131 |
o.__noSuchMethod__ = 1; |
| 132 |
s = "no exception"; |
| 133 |
try { |
| 134 |
o.hello(); |
| 135 |
} catch (e) { |
| 136 |
s = e + ""; |
| 137 |
} |
| 138 |
expect("TypeError: o.hello is not a function", s); |
| 139 |
o.__noSuchMethod__ = {}; |
| 140 |
s = "no exception"; |
| 141 |
try { |
| 142 |
o.hello(); |
| 143 |
} catch (e) { |
| 144 |
s = e + ""; |
| 145 |
} |
| 146 |
expect("TypeError: o.hello() is not a function", s); |
| 147 |
s = "no exception"; |
| 148 |
try { |
| 149 |
eval("o.hello()"); |
| 150 |
} catch (e) { |
| 151 |
s = e + ""; |
| 152 |
} |
| 153 |
expect("TypeError: o.hello() is not a function", s); |
| 154 |
s = "no exception"; |
| 155 |
try { [2, 3, 0].sort({}); } catch (e) { s = e + ""; } |
| 156 |
expect("TypeError: [2, 3, 0].sort({}) is not a function", s); |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
String.prototype.__iterator__ = (function () { |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
for (let i = 0; i != 0 + this.length; i++) |
| 168 |
yield this[i]; |
| 169 |
}); |
| 170 |
expect(["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"] + "", |
| 171 |
([a + b for (a in 'abc') for (b in '123')]) + ""); |
| 172 |
expect("", ([x for (x in <x/>)]) + ""); |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
if (typeof version == 'function') |
| 178 |
{ |
| 179 |
var v = version(150); |
| 180 |
f = new Function("return version(arguments[0])"); |
| 181 |
version(v); |
| 182 |
expect(150, f()); |
| 183 |
expect(150, eval("f()")); |
| 184 |
expect(0, eval("f(0); f()")); |
| 185 |
version(v); |
| 186 |
} |
| 187 |
print("End of Tests"); |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
function expect(a, b) { |
| 193 |
print('expect: ' + a + ', actual: ' + b); |
| 194 |
reportCompare(a, b, summary); |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
exitFunc ('test'); |
| 199 |
} |