js/src/tests/ecma_6/Generators/iteration.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // This file was written by Andy Wingo <wingo@igalia.com> and originally
michael@0 2 // contributed to V8 as generators-objects.js, available here:
michael@0 3 //
michael@0 4 // http://code.google.com/p/v8/source/browse/branches/bleeding_edge/test/mjsunit/harmony/generators-objects.js
michael@0 5
michael@0 6 // Test aspects of the generator runtime.
michael@0 7
michael@0 8
michael@0 9 var GeneratorFunction = (function*(){yield 1;}).constructor;
michael@0 10
michael@0 11
michael@0 12 function TestGeneratorResultPrototype() {
michael@0 13 function* g() { yield 1; }
michael@0 14 var iter = g();
michael@0 15 assertIteratorNext(iter, 1);
michael@0 16 assertIteratorDone(iter, undefined);
michael@0 17 assertIteratorDone(iter, undefined);
michael@0 18 }
michael@0 19 TestGeneratorResultPrototype();
michael@0 20
michael@0 21 function TestGenerator(g, expected_values_for_next,
michael@0 22 send_val, expected_values_for_send) {
michael@0 23 function testNext(thunk) {
michael@0 24 var iter = thunk();
michael@0 25 for (var i = 0; i < expected_values_for_next.length; i++) {
michael@0 26 assertIteratorResult(iter.next(), expected_values_for_next[i],
michael@0 27 i == expected_values_for_next.length - 1);
michael@0 28 }
michael@0 29 assertIteratorDone(iter, undefined);
michael@0 30 }
michael@0 31 function testSend(thunk) {
michael@0 32 var iter = thunk();
michael@0 33 for (var i = 0; i < expected_values_for_send.length; i++) {
michael@0 34 assertIteratorResult(i ? iter.next(send_val) : iter.next(),
michael@0 35 expected_values_for_send[i],
michael@0 36 i == expected_values_for_send.length - 1);
michael@0 37 }
michael@0 38 assertIteratorDone(iter, undefined);
michael@0 39 }
michael@0 40 function testThrow(thunk) {
michael@0 41 for (var i = 0; i < expected_values_for_next.length; i++) {
michael@0 42 var iter = thunk();
michael@0 43 for (var j = 0; j < i; j++) {
michael@0 44 assertIteratorResult(iter.next(),
michael@0 45 expected_values_for_next[j],
michael@0 46 j == expected_values_for_next.length - 1);
michael@0 47 }
michael@0 48 var Sentinel = function () {}
michael@0 49 assertThrowsInstanceOf(function () { iter.throw(new Sentinel); }, Sentinel);
michael@0 50 assertIteratorDone(iter, undefined);
michael@0 51 }
michael@0 52 }
michael@0 53
michael@0 54 testNext(g);
michael@0 55 testSend(g);
michael@0 56 testThrow(g);
michael@0 57
michael@0 58 testNext(function*() { return yield* g(); });
michael@0 59 testSend(function*() { return yield* g(); });
michael@0 60 testThrow(function*() { return yield* g(); });
michael@0 61
michael@0 62 if (g instanceof GeneratorFunction) {
michael@0 63 testNext(function() { return new g(); });
michael@0 64 testSend(function() { return new g(); });
michael@0 65 testThrow(function() { return new g(); });
michael@0 66 }
michael@0 67 }
michael@0 68
michael@0 69 TestGenerator(function* g1() { },
michael@0 70 [undefined],
michael@0 71 "foo",
michael@0 72 [undefined]);
michael@0 73
michael@0 74 TestGenerator(function* g2() { yield 1; },
michael@0 75 [1, undefined],
michael@0 76 "foo",
michael@0 77 [1, undefined]);
michael@0 78
michael@0 79 TestGenerator(function* g3() { yield 1; yield 2; },
michael@0 80 [1, 2, undefined],
michael@0 81 "foo",
michael@0 82 [1, 2, undefined]);
michael@0 83
michael@0 84 TestGenerator(function* g4() { yield 1; yield 2; return 3; },
michael@0 85 [1, 2, 3],
michael@0 86 "foo",
michael@0 87 [1, 2, 3]);
michael@0 88
michael@0 89 TestGenerator(function* g5() { return 1; },
michael@0 90 [1],
michael@0 91 "foo",
michael@0 92 [1]);
michael@0 93
michael@0 94 TestGenerator(function* g6() { var x = yield 1; return x; },
michael@0 95 [1, undefined],
michael@0 96 "foo",
michael@0 97 [1, "foo"]);
michael@0 98
michael@0 99 TestGenerator(function* g7() { var x = yield 1; yield 2; return x; },
michael@0 100 [1, 2, undefined],
michael@0 101 "foo",
michael@0 102 [1, 2, "foo"]);
michael@0 103
michael@0 104 TestGenerator(function* g8() { for (var x = 0; x < 4; x++) { yield x; } },
michael@0 105 [0, 1, 2, 3, undefined],
michael@0 106 "foo",
michael@0 107 [0, 1, 2, 3, undefined]);
michael@0 108
michael@0 109 // Generator with arguments.
michael@0 110 TestGenerator(
michael@0 111 function g9() {
michael@0 112 return (function*(a, b, c, d) {
michael@0 113 yield a; yield b; yield c; yield d;
michael@0 114 })("fee", "fi", "fo", "fum");
michael@0 115 },
michael@0 116 ["fee", "fi", "fo", "fum", undefined],
michael@0 117 "foo",
michael@0 118 ["fee", "fi", "fo", "fum", undefined]);
michael@0 119
michael@0 120 // Too few arguments.
michael@0 121 TestGenerator(
michael@0 122 function g10() {
michael@0 123 return (function*(a, b, c, d) {
michael@0 124 yield a; yield b; yield c; yield d;
michael@0 125 })("fee", "fi");
michael@0 126 },
michael@0 127 ["fee", "fi", undefined, undefined, undefined],
michael@0 128 "foo",
michael@0 129 ["fee", "fi", undefined, undefined, undefined]);
michael@0 130
michael@0 131 // Too many arguments.
michael@0 132 TestGenerator(
michael@0 133 function g11() {
michael@0 134 return (function*(a, b, c, d) {
michael@0 135 yield a; yield b; yield c; yield d;
michael@0 136 })("fee", "fi", "fo", "fum", "I smell the blood of an Englishman");
michael@0 137 },
michael@0 138 ["fee", "fi", "fo", "fum", undefined],
michael@0 139 "foo",
michael@0 140 ["fee", "fi", "fo", "fum", undefined]);
michael@0 141
michael@0 142 // The arguments object.
michael@0 143 TestGenerator(
michael@0 144 function g12() {
michael@0 145 return (function*(a, b, c, d) {
michael@0 146 for (var i = 0; i < arguments.length; i++) {
michael@0 147 yield arguments[i];
michael@0 148 }
michael@0 149 })("fee", "fi", "fo", "fum", "I smell the blood of an Englishman");
michael@0 150 },
michael@0 151 ["fee", "fi", "fo", "fum", "I smell the blood of an Englishman",
michael@0 152 undefined],
michael@0 153 "foo",
michael@0 154 ["fee", "fi", "fo", "fum", "I smell the blood of an Englishman",
michael@0 155 undefined]);
michael@0 156
michael@0 157 // Access to captured free variables.
michael@0 158 TestGenerator(
michael@0 159 function g13() {
michael@0 160 return (function(a, b, c, d) {
michael@0 161 return (function*() {
michael@0 162 yield a; yield b; yield c; yield d;
michael@0 163 })();
michael@0 164 })("fee", "fi", "fo", "fum");
michael@0 165 },
michael@0 166 ["fee", "fi", "fo", "fum", undefined],
michael@0 167 "foo",
michael@0 168 ["fee", "fi", "fo", "fum", undefined]);
michael@0 169
michael@0 170 // Abusing the arguments object.
michael@0 171 TestGenerator(
michael@0 172 function g14() {
michael@0 173 return (function*(a, b, c, d) {
michael@0 174 arguments[0] = "Be he live";
michael@0 175 arguments[1] = "or be he dead";
michael@0 176 arguments[2] = "I'll grind his bones";
michael@0 177 arguments[3] = "to make my bread";
michael@0 178 yield a; yield b; yield c; yield d;
michael@0 179 })("fee", "fi", "fo", "fum");
michael@0 180 },
michael@0 181 ["Be he live", "or be he dead", "I'll grind his bones", "to make my bread",
michael@0 182 undefined],
michael@0 183 "foo",
michael@0 184 ["Be he live", "or be he dead", "I'll grind his bones", "to make my bread",
michael@0 185 undefined]);
michael@0 186
michael@0 187 // Abusing the arguments object: strict mode.
michael@0 188 TestGenerator(
michael@0 189 function g15() {
michael@0 190 return (function*(a, b, c, d) {
michael@0 191 "use strict";
michael@0 192 arguments[0] = "Be he live";
michael@0 193 arguments[1] = "or be he dead";
michael@0 194 arguments[2] = "I'll grind his bones";
michael@0 195 arguments[3] = "to make my bread";
michael@0 196 yield a; yield b; yield c; yield d;
michael@0 197 })("fee", "fi", "fo", "fum");
michael@0 198 },
michael@0 199 ["fee", "fi", "fo", "fum", undefined],
michael@0 200 "foo",
michael@0 201 ["fee", "fi", "fo", "fum", undefined]);
michael@0 202
michael@0 203 // GC.
michael@0 204 if (typeof gc == 'function') {
michael@0 205 TestGenerator(function* g16() { yield "baz"; gc(); yield "qux"; },
michael@0 206 ["baz", "qux", undefined],
michael@0 207 "foo",
michael@0 208 ["baz", "qux", undefined]);
michael@0 209 }
michael@0 210
michael@0 211 // Receivers.
michael@0 212 TestGenerator(
michael@0 213 function g17() {
michael@0 214 function* g() { yield this.x; yield this.y; }
michael@0 215 var o = { start: g, x: 1, y: 2 };
michael@0 216 return o.start();
michael@0 217 },
michael@0 218 [1, 2, undefined],
michael@0 219 "foo",
michael@0 220 [1, 2, undefined]);
michael@0 221
michael@0 222 // FIXME: Capture the generator object as "this" in new g(). Bug 907742.
michael@0 223 // TestGenerator(
michael@0 224 // function g18() {
michael@0 225 // function* g() { yield this.x; yield this.y; }
michael@0 226 // var iter = new g;
michael@0 227 // iter.x = 1;
michael@0 228 // iter.y = 2;
michael@0 229 // return iter;
michael@0 230 // },
michael@0 231 // [1, 2, undefined],
michael@0 232 // "foo",
michael@0 233 // [1, 2, undefined]);
michael@0 234
michael@0 235 TestGenerator(
michael@0 236 function* g19() {
michael@0 237 var x = 1;
michael@0 238 yield x;
michael@0 239 with({x:2}) { yield x; }
michael@0 240 yield x;
michael@0 241 },
michael@0 242 [1, 2, 1, undefined],
michael@0 243 "foo",
michael@0 244 [1, 2, 1, undefined]);
michael@0 245
michael@0 246 TestGenerator(
michael@0 247 function* g20() { yield (1 + (yield 2) + 3); },
michael@0 248 [2, NaN, undefined],
michael@0 249 "foo",
michael@0 250 [2, "1foo3", undefined]);
michael@0 251
michael@0 252 TestGenerator(
michael@0 253 function* g21() { return (1 + (yield 2) + 3); },
michael@0 254 [2, NaN],
michael@0 255 "foo",
michael@0 256 [2, "1foo3"]);
michael@0 257
michael@0 258 TestGenerator(
michael@0 259 function* g22() { yield (1 + (yield 2) + 3); yield (4 + (yield 5) + 6); },
michael@0 260 [2, NaN, 5, NaN, undefined],
michael@0 261 "foo",
michael@0 262 [2, "1foo3", 5, "4foo6", undefined]);
michael@0 263
michael@0 264 TestGenerator(
michael@0 265 function* g23() {
michael@0 266 return (yield (1 + (yield 2) + 3)) + (yield (4 + (yield 5) + 6));
michael@0 267 },
michael@0 268 [2, NaN, 5, NaN, NaN],
michael@0 269 "foo",
michael@0 270 [2, "1foo3", 5, "4foo6", "foofoo"]);
michael@0 271
michael@0 272 // Rewind a try context with and without operands on the stack.
michael@0 273 TestGenerator(
michael@0 274 function* g24() {
michael@0 275 try {
michael@0 276 return (yield (1 + (yield 2) + 3)) + (yield (4 + (yield 5) + 6));
michael@0 277 } catch (e) {
michael@0 278 throw e;
michael@0 279 }
michael@0 280 },
michael@0 281 [2, NaN, 5, NaN, NaN],
michael@0 282 "foo",
michael@0 283 [2, "1foo3", 5, "4foo6", "foofoo"]);
michael@0 284
michael@0 285 // Yielding in a catch context, with and without operands on the stack.
michael@0 286 TestGenerator(
michael@0 287 function* g25() {
michael@0 288 try {
michael@0 289 throw (yield (1 + (yield 2) + 3))
michael@0 290 } catch (e) {
michael@0 291 if (typeof e == 'object') throw e;
michael@0 292 return e + (yield (4 + (yield 5) + 6));
michael@0 293 }
michael@0 294 },
michael@0 295 [2, NaN, 5, NaN, NaN],
michael@0 296 "foo",
michael@0 297 [2, "1foo3", 5, "4foo6", "foofoo"]);
michael@0 298
michael@0 299 // Generator function instances.
michael@0 300 TestGenerator(GeneratorFunction(),
michael@0 301 [undefined],
michael@0 302 "foo",
michael@0 303 [undefined]);
michael@0 304
michael@0 305 TestGenerator(new GeneratorFunction(),
michael@0 306 [undefined],
michael@0 307 "foo",
michael@0 308 [undefined]);
michael@0 309
michael@0 310 TestGenerator(GeneratorFunction('yield 1;'),
michael@0 311 [1, undefined],
michael@0 312 "foo",
michael@0 313 [1, undefined]);
michael@0 314
michael@0 315 TestGenerator(
michael@0 316 function() { return GeneratorFunction('x', 'y', 'yield x + y;')(1, 2) },
michael@0 317 [3, undefined],
michael@0 318 "foo",
michael@0 319 [3, undefined]);
michael@0 320
michael@0 321 // Access to this with formal arguments.
michael@0 322 TestGenerator(
michael@0 323 function () {
michael@0 324 return ({ x: 42, g: function* (a) { yield this.x } }).g(0);
michael@0 325 },
michael@0 326 [42, undefined],
michael@0 327 "foo",
michael@0 328 [42, undefined]);
michael@0 329
michael@0 330 function TestTryCatch(instantiate) {
michael@0 331 function* g() { yield 1; try { yield 2; } catch (e) { yield e; } yield 3; }
michael@0 332 function Sentinel() {}
michael@0 333
michael@0 334 function Test1(iter) {
michael@0 335 assertIteratorNext(iter, 1);
michael@0 336 assertIteratorNext(iter, 2);
michael@0 337 assertIteratorNext(iter, 3);
michael@0 338 assertIteratorDone(iter, undefined);
michael@0 339 assertIteratorDone(iter, undefined);
michael@0 340 }
michael@0 341 Test1(instantiate(g));
michael@0 342
michael@0 343 function Test2(iter) {
michael@0 344 assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
michael@0 345 assertIteratorDone(iter, undefined);
michael@0 346 }
michael@0 347 Test2(instantiate(g));
michael@0 348
michael@0 349 function Test3(iter) {
michael@0 350 assertIteratorNext(iter, 1);
michael@0 351 assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
michael@0 352 assertIteratorDone(iter, undefined);
michael@0 353 }
michael@0 354 Test3(instantiate(g));
michael@0 355
michael@0 356 function Test4(iter) {
michael@0 357 assertIteratorNext(iter, 1);
michael@0 358 assertIteratorNext(iter, 2);
michael@0 359 var exn = new Sentinel;
michael@0 360 assertIteratorResult(iter.throw(exn), exn, false);
michael@0 361 assertIteratorNext(iter, 3);
michael@0 362 assertIteratorDone(iter, undefined);
michael@0 363 assertIteratorDone(iter, undefined);
michael@0 364 }
michael@0 365 Test4(instantiate(g));
michael@0 366
michael@0 367 function Test5(iter) {
michael@0 368 assertIteratorNext(iter, 1);
michael@0 369 assertIteratorNext(iter, 2);
michael@0 370 var exn = new Sentinel;
michael@0 371 assertIteratorResult(iter.throw(exn), exn, false);
michael@0 372 assertIteratorNext(iter, 3);
michael@0 373 assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
michael@0 374 assertIteratorDone(iter, undefined);
michael@0 375
michael@0 376 }
michael@0 377 Test5(instantiate(g));
michael@0 378
michael@0 379 function Test6(iter) {
michael@0 380 assertIteratorNext(iter, 1);
michael@0 381 assertIteratorNext(iter, 2);
michael@0 382 var exn = new Sentinel;
michael@0 383 assertIteratorResult(iter.throw(exn), exn, false);
michael@0 384 assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
michael@0 385 assertIteratorDone(iter, undefined);
michael@0 386 }
michael@0 387 Test6(instantiate(g));
michael@0 388 }
michael@0 389 TestTryCatch(function (g) { return g(); });
michael@0 390 TestTryCatch(function* (g) { return yield* g(); });
michael@0 391
michael@0 392 function TestTryFinally(instantiate) {
michael@0 393 function* g() { yield 1; try { yield 2; } finally { yield 3; } yield 4; }
michael@0 394 function Sentinel() {}
michael@0 395 function Sentinel2() {}
michael@0 396
michael@0 397 function Test1(iter) {
michael@0 398 assertIteratorNext(iter, 1);
michael@0 399 assertIteratorNext(iter, 2);
michael@0 400 assertIteratorNext(iter, 3);
michael@0 401 assertIteratorNext(iter, 4);
michael@0 402 assertIteratorDone(iter, undefined);
michael@0 403 assertIteratorDone(iter, undefined);
michael@0 404 }
michael@0 405 Test1(instantiate(g));
michael@0 406
michael@0 407 function Test2(iter) {
michael@0 408 assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
michael@0 409 assertIteratorDone(iter, undefined);
michael@0 410 }
michael@0 411 Test2(instantiate(g));
michael@0 412
michael@0 413 function Test3(iter) {
michael@0 414 assertIteratorNext(iter, 1);
michael@0 415 assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
michael@0 416 assertIteratorDone(iter, undefined);
michael@0 417 }
michael@0 418 Test3(instantiate(g));
michael@0 419
michael@0 420 function Test4(iter) {
michael@0 421 assertIteratorNext(iter, 1);
michael@0 422 assertIteratorNext(iter, 2);
michael@0 423 assertIteratorResult(iter.throw(new Sentinel), 3, false);
michael@0 424 assertThrowsInstanceOf(function() { iter.next(); }, Sentinel);
michael@0 425 assertIteratorDone(iter, undefined);
michael@0 426
michael@0 427 }
michael@0 428 Test4(instantiate(g));
michael@0 429
michael@0 430 function Test5(iter) {
michael@0 431 assertIteratorNext(iter, 1);
michael@0 432 assertIteratorNext(iter, 2);
michael@0 433 assertIteratorResult(iter.throw(new Sentinel), 3, false);
michael@0 434 assertThrowsInstanceOf(function() { iter.throw(new Sentinel2); }, Sentinel2);
michael@0 435 assertIteratorDone(iter, undefined);
michael@0 436 }
michael@0 437 Test5(instantiate(g));
michael@0 438
michael@0 439 function Test6(iter) {
michael@0 440 assertIteratorNext(iter, 1);
michael@0 441 assertIteratorNext(iter, 2);
michael@0 442 assertIteratorNext(iter, 3);
michael@0 443 assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
michael@0 444 assertIteratorDone(iter, undefined);
michael@0 445 }
michael@0 446 Test6(instantiate(g));
michael@0 447
michael@0 448 function Test7(iter) {
michael@0 449 assertIteratorNext(iter, 1);
michael@0 450 assertIteratorNext(iter, 2);
michael@0 451 assertIteratorNext(iter, 3);
michael@0 452 assertIteratorNext(iter, 4);
michael@0 453 assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
michael@0 454 assertIteratorDone(iter, undefined);
michael@0 455 }
michael@0 456 Test7(instantiate(g));
michael@0 457 }
michael@0 458 TestTryFinally(function (g) { return g(); });
michael@0 459 TestTryFinally(function* (g) { return yield* g(); });
michael@0 460
michael@0 461 function TestNestedTry(instantiate) {
michael@0 462 function* g() {
michael@0 463 try {
michael@0 464 yield 1;
michael@0 465 try { yield 2; } catch (e) { yield e; }
michael@0 466 yield 3;
michael@0 467 } finally {
michael@0 468 yield 4;
michael@0 469 }
michael@0 470 yield 5;
michael@0 471 }
michael@0 472 function Sentinel() {}
michael@0 473 function Sentinel2() {}
michael@0 474
michael@0 475 function Test1(iter) {
michael@0 476 assertIteratorNext(iter, 1);
michael@0 477 assertIteratorNext(iter, 2);
michael@0 478 assertIteratorNext(iter, 3);
michael@0 479 assertIteratorNext(iter, 4);
michael@0 480 assertIteratorNext(iter, 5);
michael@0 481 assertIteratorDone(iter, undefined);
michael@0 482 assertIteratorDone(iter, undefined);
michael@0 483 }
michael@0 484 Test1(instantiate(g));
michael@0 485
michael@0 486 function Test2(iter) {
michael@0 487 assertThrowsInstanceOf(function() { iter.throw(new Sentinel); }, Sentinel);
michael@0 488 assertIteratorDone(iter, undefined);
michael@0 489 }
michael@0 490 Test2(instantiate(g));
michael@0 491
michael@0 492 function Test3(iter) {
michael@0 493 assertIteratorNext(iter, 1);
michael@0 494 assertIteratorResult(iter.throw(new Sentinel), 4, false);
michael@0 495 assertThrowsInstanceOf(function() { iter.next(); }, Sentinel);
michael@0 496 assertIteratorDone(iter, undefined);
michael@0 497 }
michael@0 498 Test3(instantiate(g));
michael@0 499
michael@0 500 function Test4(iter) {
michael@0 501 assertIteratorNext(iter, 1);
michael@0 502 assertIteratorResult(iter.throw(new Sentinel), 4, false);
michael@0 503 assertThrowsInstanceOf(function() { iter.throw(new Sentinel2); }, Sentinel2);
michael@0 504 assertIteratorDone(iter, undefined);
michael@0 505 }
michael@0 506 Test4(instantiate(g));
michael@0 507
michael@0 508 function Test5(iter) {
michael@0 509 assertIteratorNext(iter, 1);
michael@0 510 assertIteratorNext(iter, 2);
michael@0 511 var exn = new Sentinel;
michael@0 512 assertIteratorResult(iter.throw(exn), exn, false);
michael@0 513 assertIteratorNext(iter, 3);
michael@0 514 assertIteratorNext(iter, 4);
michael@0 515 assertIteratorNext(iter, 5);
michael@0 516 assertIteratorDone(iter, undefined);
michael@0 517 assertIteratorDone(iter, undefined);
michael@0 518
michael@0 519 }
michael@0 520 Test5(instantiate(g));
michael@0 521
michael@0 522 function Test6(iter) {
michael@0 523 assertIteratorNext(iter, 1);
michael@0 524 assertIteratorNext(iter, 2);
michael@0 525 var exn = new Sentinel;
michael@0 526 assertIteratorResult(iter.throw(exn), exn, false);
michael@0 527 assertIteratorResult(iter.throw(new Sentinel2), 4, false);
michael@0 528 assertThrowsInstanceOf(function() { iter.next(); }, Sentinel2);
michael@0 529 assertIteratorDone(iter, undefined);
michael@0 530 }
michael@0 531 Test6(instantiate(g));
michael@0 532
michael@0 533 function Test7(iter) {
michael@0 534 assertIteratorNext(iter, 1);
michael@0 535 assertIteratorNext(iter, 2);
michael@0 536 var exn = new Sentinel;
michael@0 537 assertIteratorResult(iter.throw(exn), exn, false);
michael@0 538 assertIteratorNext(iter, 3);
michael@0 539 assertIteratorResult(iter.throw(new Sentinel2), 4, false);
michael@0 540 assertThrowsInstanceOf(function() { iter.next(); }, Sentinel2);
michael@0 541 assertIteratorDone(iter, undefined);
michael@0 542
michael@0 543 }
michael@0 544 Test7(instantiate(g));
michael@0 545
michael@0 546 // That's probably enough.
michael@0 547 }
michael@0 548 TestNestedTry(function (g) { return g(); });
michael@0 549 TestNestedTry(function* (g) { return yield* g(); });
michael@0 550
michael@0 551 function TestRecursion() {
michael@0 552 function TestNextRecursion() {
michael@0 553 function* g() { yield iter.next(); }
michael@0 554 var iter = g();
michael@0 555 return iter.next();
michael@0 556 }
michael@0 557 function TestSendRecursion() {
michael@0 558 function* g() { yield iter.next(42); }
michael@0 559 var iter = g();
michael@0 560 return iter.next();
michael@0 561 }
michael@0 562 function TestThrowRecursion() {
michael@0 563 function* g() { yield iter.throw(1); }
michael@0 564 var iter = g();
michael@0 565 return iter.next();
michael@0 566 }
michael@0 567 assertThrowsInstanceOf(TestNextRecursion, TypeError);
michael@0 568 assertThrowsInstanceOf(TestSendRecursion, TypeError);
michael@0 569 assertThrowsInstanceOf(TestThrowRecursion, TypeError);
michael@0 570 }
michael@0 571 TestRecursion();
michael@0 572
michael@0 573 if (typeof reportCompare == "function")
michael@0 574 reportCompare(true, true);

mercurial