| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 if (!IS_GENERATOR(this)) { | 30 if (!IS_GENERATOR(this)) { |
| 31 throw MakeTypeError(kIncompatibleMethodReceiver, | 31 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 32 '[Generator].prototype.next', this); | 32 '[Generator].prototype.next', this); |
| 33 } | 33 } |
| 34 | 34 |
| 35 var continuation = %GeneratorGetContinuation(this); | 35 var continuation = %GeneratorGetContinuation(this); |
| 36 if (continuation > 0) { | 36 if (continuation > 0) { |
| 37 // Generator is suspended. | 37 // Generator is suspended. |
| 38 DEBUG_PREPARE_STEP_IN_IF_STEPPING(this); | 38 DEBUG_PREPARE_STEP_IN_IF_STEPPING(this); |
| 39 try { | 39 try { |
| 40 return %_GeneratorNext(this, value); | 40 let result = %_GeneratorNext(this, value); |
| 41 if (result.done) %GeneratorClose(this); |
| 42 return result; |
| 41 } catch (e) { | 43 } catch (e) { |
| 42 %GeneratorClose(this); | 44 %GeneratorClose(this); |
| 43 throw e; | 45 throw e; |
| 44 } | 46 } |
| 45 } else if (continuation == 0) { | 47 } else if (continuation == 0) { |
| 46 // Generator is already closed. | 48 // Generator is already closed. |
| 47 return { value: void 0, done: true }; | 49 return %_CreateIterResultObject(UNDEFINED, true); |
| 48 } else { | 50 } else { |
| 49 // Generator is running. | 51 // Generator is running. |
| 50 throw MakeTypeError(kGeneratorRunning); | 52 throw MakeTypeError(kGeneratorRunning); |
| 53 } |
| 54 } |
| 55 |
| 56 |
| 57 function GeneratorObjectReturn(value) { |
| 58 if (!IS_GENERATOR(this)) { |
| 59 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 60 '[Generator].prototype.return', this); |
| 61 } |
| 62 |
| 63 var continuation = %GeneratorGetContinuation(this); |
| 64 if (continuation > 0) { |
| 65 // Generator is suspended. |
| 66 DEBUG_PREPARE_STEP_IN_IF_STEPPING(this); |
| 67 try { |
| 68 let result = %_GeneratorReturn(this, value); |
| 69 if (result.done) %GeneratorClose(this); |
| 70 return result; |
| 71 } catch (e) { |
| 72 %GeneratorClose(this); |
| 73 throw e; |
| 74 } |
| 75 } else if (continuation == 0) { |
| 76 // Generator is already closed. |
| 77 return %_CreateIterResultObject(value, true); |
| 78 } else { |
| 79 // Generator is running. |
| 80 throw MakeTypeError(kGeneratorRunning); |
| 51 } | 81 } |
| 52 } | 82 } |
| 53 | 83 |
| 54 | 84 |
| 55 function GeneratorObjectThrow(exn) { | 85 function GeneratorObjectThrow(exn) { |
| 56 if (!IS_GENERATOR(this)) { | 86 if (!IS_GENERATOR(this)) { |
| 57 throw MakeTypeError(kIncompatibleMethodReceiver, | 87 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 58 '[Generator].prototype.throw', this); | 88 '[Generator].prototype.throw', this); |
| 59 } | 89 } |
| 60 | 90 |
| 61 var continuation = %GeneratorGetContinuation(this); | 91 var continuation = %GeneratorGetContinuation(this); |
| 62 if (continuation > 0) { | 92 if (continuation > 0) { |
| 63 // Generator is suspended. | 93 // Generator is suspended. |
| 64 try { | 94 try { |
| 65 return %_GeneratorThrow(this, exn); | 95 let result = %_GeneratorThrow(this, exn); |
| 96 if (result.done) %GeneratorClose(this); |
| 97 return result; |
| 66 } catch (e) { | 98 } catch (e) { |
| 67 %GeneratorClose(this); | 99 %GeneratorClose(this); |
| 68 throw e; | 100 throw e; |
| 69 } | 101 } |
| 70 } else if (continuation == 0) { | 102 } else if (continuation == 0) { |
| 71 // Generator is already closed. | 103 // Generator is already closed. |
| 72 throw exn; | 104 throw exn; |
| 73 } else { | 105 } else { |
| 74 // Generator is running. | 106 // Generator is running. |
| 75 throw MakeTypeError(kGeneratorRunning); | 107 throw MakeTypeError(kGeneratorRunning); |
| 76 } | 108 } |
| 77 } | 109 } |
| 78 | 110 |
| 79 // ---------------------------------------------------------------------------- | 111 // ---------------------------------------------------------------------------- |
| 80 | 112 |
| 81 // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by | 113 // None of the three resume operations (Runtime_GeneratorNext, |
| 82 // neither Crankshaft nor TurboFan, disable optimization of wrappers here. | 114 // Runtime_GeneratorReturn, Runtime_GeneratorThrow) is supported by |
| 115 // Crankshaft or TurboFan. Disable optimization of wrappers here. |
| 83 %NeverOptimizeFunction(GeneratorObjectNext); | 116 %NeverOptimizeFunction(GeneratorObjectNext); |
| 117 %NeverOptimizeFunction(GeneratorObjectReturn); |
| 84 %NeverOptimizeFunction(GeneratorObjectThrow); | 118 %NeverOptimizeFunction(GeneratorObjectThrow); |
| 85 | 119 |
| 86 // Set up non-enumerable functions on the generator prototype object. | 120 // Set up non-enumerable functions on the generator prototype object. |
| 87 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; | 121 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; |
| 88 utils.InstallFunctions(GeneratorObjectPrototype, | 122 utils.InstallFunctions(GeneratorObjectPrototype, |
| 89 DONT_ENUM, | 123 DONT_ENUM, |
| 90 ["next", GeneratorObjectNext, | 124 ["next", GeneratorObjectNext, |
| 125 "return", GeneratorObjectReturn, |
| 91 "throw", GeneratorObjectThrow]); | 126 "throw", GeneratorObjectThrow]); |
| 92 | 127 |
| 93 %AddNamedProperty(GeneratorObjectPrototype, "constructor", | 128 %AddNamedProperty(GeneratorObjectPrototype, "constructor", |
| 94 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY); | 129 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY); |
| 95 %AddNamedProperty(GeneratorObjectPrototype, | 130 %AddNamedProperty(GeneratorObjectPrototype, |
| 96 toStringTagSymbol, "Generator", DONT_ENUM | READ_ONLY); | 131 toStringTagSymbol, "Generator", DONT_ENUM | READ_ONLY); |
| 97 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); | 132 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); |
| 98 %AddNamedProperty(GeneratorFunctionPrototype, | 133 %AddNamedProperty(GeneratorFunctionPrototype, |
| 99 toStringTagSymbol, "GeneratorFunction", DONT_ENUM | READ_ONLY); | 134 toStringTagSymbol, "GeneratorFunction", DONT_ENUM | READ_ONLY); |
| 100 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", | 135 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", |
| 101 GeneratorFunction, DONT_ENUM | READ_ONLY); | 136 GeneratorFunction, DONT_ENUM | READ_ONLY); |
| 102 %InternalSetPrototype(GeneratorFunction, GlobalFunction); | 137 %InternalSetPrototype(GeneratorFunction, GlobalFunction); |
| 103 | 138 |
| 104 }) | 139 }) |
| OLD | NEW |