tests/auto/qml/ecmascripttests/test262/test/language/expressions/yield/star-rhs-iter-thrw-res-value-final.js
raw symbols SCIP| 1 | // Copyright (C) 2016 the V8 project authors. All rights reserved. |
| 2 | // This code is governed by the BSD license found in the LICENSE file. |
| 3 | /*--- |
| 4 | esid: sec-generator-function-definitions-runtime-semantics-evaluation |
| 5 | description: Value received from invocation of generator's `throw` method |
| 6 | info: | |
| 7 | YieldExpression : yield * AssignmentExpression |
| 8 | |
| 9 | 1. Let exprRef be the result of evaluating AssignmentExpression. |
| 10 | 2. Let value be ? GetValue(exprRef). |
| 11 | 3. Let iterator be ? GetIterator(value). |
| 12 | 4. Let received be NormalCompletion(undefined). |
| 13 | 5. Repeat |
| 14 | a. If received.[[Type]] is normal, then |
| 15 | [...] |
| 16 | b. Else if received.[[Type]] is throw, then |
| 17 | i. Let throw be ? GetMethod(iterator, "throw"). |
| 18 | ii. If throw is not undefined, then |
| 19 | 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] |
| 20 | »). |
| 21 | 2. NOTE: Exceptions from the inner iterator throw method are |
| 22 | propagated. Normal completions from an inner throw method are |
| 23 | processed similarly to an inner next. |
| 24 | 3. If Type(innerResult) is not Object, throw a TypeError exception. |
| 25 | 4. Let done be ? IteratorComplete(innerResult). |
| 26 | 5. If done is true, then |
| 27 | [...] |
| 28 | 6. Let received be GeneratorYield(innerResult). |
| 29 | features: [generators, Symbol.iterator] |
| 30 | ---*/ |
| 31 | |
| 32 | var quickIter = {}; |
| 33 | var iter, exprValue, throwReceived; |
| 34 | quickIter[Symbol.iterator] = function() { |
| 35 | return { |
| 36 | next: function() { |
| 37 | return { done: false }; |
| 38 | }, |
| 39 | throw: function(x) { |
| 40 | throwReceived = x; |
| 41 | return { done: true, value: 3333 }; |
| 42 | } |
| 43 | }; |
| 44 | }; |
| 45 | function* g() { |
| 46 | exprValue = yield * quickIter; |
| 47 | } |
| 48 | |
| 49 | iter = g(); |
| 50 | |
| 51 | iter.next(); |
| 52 | iter.throw(2222); |
| 53 | assert.sameValue(throwReceived, 2222); |
| 54 | assert.sameValue(exprValue, 3333); |