js/src/tests/js1_8/genexps/regress-349326.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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 //-----------------------------------------------------------------------------
michael@0 7 var BUGNUMBER = 349326;
michael@0 8 var summary = 'closing generators';
michael@0 9 var actual = 'PASS';
michael@0 10 var expect = 'PASS';
michael@0 11
michael@0 12
michael@0 13 //-----------------------------------------------------------------------------
michael@0 14 test();
michael@0 15 //-----------------------------------------------------------------------------
michael@0 16
michael@0 17 function test()
michael@0 18 {
michael@0 19 enterFunc ('test');
michael@0 20 printBugNumber(BUGNUMBER);
michael@0 21 printStatus (summary);
michael@0 22
michael@0 23 let closed;
michael@0 24
michael@0 25 function gen()
michael@0 26 {
michael@0 27 try {
michael@0 28 yield 1;
michael@0 29 yield 2;
michael@0 30 } finally {
michael@0 31 closed = true;
michael@0 32 }
michael@0 33 }
michael@0 34
michael@0 35 // Test that return closes the generator
michael@0 36 function test_return()
michael@0 37 {
michael@0 38 for (let i in gen()) {
michael@0 39 if (i != 1)
michael@0 40 throw "unexpected generator value";
michael@0 41 return 10;
michael@0 42 }
michael@0 43 }
michael@0 44
michael@0 45 closed = false;
michael@0 46 test_return();
michael@0 47 if (closed !== true)
michael@0 48 throw "return does not close generator";
michael@0 49
michael@0 50 // test that break closes generator
michael@0 51
michael@0 52 closed = false;
michael@0 53 for (let i in gen()) {
michael@0 54 if (i != 1)
michael@0 55 throw "unexpected generator value";
michael@0 56 break;
michael@0 57 }
michael@0 58 if (closed !== true)
michael@0 59 throw "break does not close generator";
michael@0 60
michael@0 61 label: {
michael@0 62 for (;;) {
michael@0 63 closed = false;
michael@0 64 for (let i in gen()) {
michael@0 65 if (i != 1)
michael@0 66 throw "unexpected generator value";
michael@0 67 break label;
michael@0 68 }
michael@0 69 }
michael@0 70 }
michael@0 71
michael@0 72 if (closed !== true)
michael@0 73 throw "break does not close generator";
michael@0 74
michael@0 75 // test that an exception closes generator
michael@0 76
michael@0 77 function function_that_throws()
michael@0 78 {
michael@0 79 throw function_that_throws;
michael@0 80 }
michael@0 81
michael@0 82 try {
michael@0 83 closed = false;
michael@0 84 for (let i in gen()) {
michael@0 85 if (i != 1)
michael@0 86 throw "unexpected generator value";
michael@0 87 function_that_throws();
michael@0 88 }
michael@0 89 } catch (e) {
michael@0 90 if (e !== function_that_throws)
michael@0 91 throw e;
michael@0 92 }
michael@0 93
michael@0 94 if (closed !== true)
michael@0 95 throw "exception does not close generator";
michael@0 96
michael@0 97 // Check consistency of finally execution in presence of generators
michael@0 98
michael@0 99 let gen2_was_closed = false;
michael@0 100 let gen3_was_closed = false;
michael@0 101 let finally_was_executed = false;
michael@0 102
michael@0 103 function gen2() {
michael@0 104 try {
michael@0 105 yield 2;
michael@0 106 } finally {
michael@0 107 if (gen2_was_closed || !finally_was_executed || !gen3_was_closed)
michael@0 108 throw "bad oder of gen2 finally execution"
michael@0 109 gen2_was_closed = true;
michael@0 110 throw gen2;
michael@0 111 }
michael@0 112 }
michael@0 113
michael@0 114 function gen3() {
michael@0 115 try {
michael@0 116 yield 3;
michael@0 117 } finally {
michael@0 118 if (gen2_was_closed || finally_was_executed || gen3_was_closed)
michael@0 119 throw "bad oder of gen3 finally execution"
michael@0 120 gen3_was_closed = true;
michael@0 121 }
michael@0 122 }
michael@0 123
michael@0 124 label2: {
michael@0 125 try {
michael@0 126 for (let i in gen2()) {
michael@0 127 try {
michael@0 128 for (let j in gen3()) {
michael@0 129 break label2;
michael@0 130 }
michael@0 131 } finally {
michael@0 132 if (gen2_was_closed || finally_was_executed || !gen3_was_closed)
michael@0 133 throw "bad oder of try-finally execution";
michael@0 134 finally_was_executed = true;
michael@0 135 }
michael@0 136 }
michael@0 137 throw "gen2 finally should throw";
michael@0 138 } catch (e) {
michael@0 139 if (e != gen2) throw e;
michael@0 140 }
michael@0 141 }
michael@0 142
michael@0 143 print("OK");
michael@0 144
michael@0 145 reportCompare(expect, actual, summary);
michael@0 146
michael@0 147 exitFunc ('test');
michael@0 148 }

mercurial