1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor; 17print(Object.isExtensible(AsyncGeneratorFunction)); 18 19function fun1(){ 20 var returnGets_1 = 0; 21 var asyncIterable_1 = { 22 [Symbol.asyncIterator]: function() { 23 return this; 24 }, 25 next: function() { 26 return {value: 1, done: false}; 27 }, 28 get return() { 29 returnGets_1 += 1; 30 return null; 31 }, 32 }; 33 34 async function* asyncGenerator() { 35 yield* asyncIterable_1; 36 } 37 38 var asyncIterator_1 = asyncGenerator(); 39 asyncIterator_1.next().then(function() { 40 return asyncIterator_1.return(2).then(function(result) { 41 print(result.value); 42 print(result.done); 43 print(returnGets_1); 44 }); 45 }); 46} 47fun1(); 48 49function fun2(){ 50 var asyncIterable_2 = { 51 [Symbol.asyncIterator]: function() { 52 return this; 53 }, 54 next: function() { 55 return {value: 1, done: false}; 56 }, 57 }; 58 59 async function* asyncGenerator() { 60 yield* asyncIterable_2; 61 } 62 63 var asyncIterator_2 = asyncGenerator(); 64 asyncIterator_2.next().then(function() { 65 var promise = Promise.resolve(2).then(() => 3); 66 return asyncIterator_2.return(promise).then(function(result) { 67 print(result.value); 68 print(result.done); 69 }); 70 }); 71} 72fun2(); 73 74function fun3(){ 75 var token_1 = {}; 76 77 var asyncIter_3 = { 78 [Symbol.asyncIterator]() { 79 return this; 80 }, 81 next() { 82 return { 83 done: false, 84 value: undefined, 85 }; 86 }, 87 return() { 88 return { 89 done: false, 90 get value() { 91 throw token_1; 92 } 93 }; 94 } 95 }; 96 97 async function* f_3() { 98 var thrown_3; 99 try { 100 yield* asyncIter_3; 101 } catch (e) { 102 thrown_3 = e; 103 } 104 return thrown_3; 105 } 106 107 var iter_3 = f_3(); 108 109 iter_3.next().then(() => { 110 iter_3.return().then(({value}) => { 111 print(value); 112 }); 113 }); 114} 115fun3();