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 "use strict"; | 5 "use strict"; |
6 | 6 |
7 // This file relies on the fact that the following declarations have been made | 7 // This file relies on the fact that the following declarations have been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $Function = global.Function; | 9 // var $Function = global.Function; |
10 | 10 |
11 // ---------------------------------------------------------------------------- | 11 // ---------------------------------------------------------------------------- |
12 | 12 |
13 | 13 |
14 // Generator functions and objects are specified by ES6, sections 15.19.3 and | 14 // Generator functions and objects are specified by ES6, sections 15.19.3 and |
15 // 15.19.4. | 15 // 15.19.4. |
16 | 16 |
17 function GeneratorObjectNext(value) { | 17 function GeneratorObjectNext(value) { |
18 if (!IS_GENERATOR(this)) { | 18 if (!IS_GENERATOR(this)) { |
19 throw MakeTypeError('incompatible_method_receiver', | 19 throw MakeTypeError('incompatible_method_receiver', |
20 ['[Generator].prototype.next', this]); | 20 ['[Generator].prototype.next', this]); |
21 } | 21 } |
22 | 22 |
23 if (DEBUG_IS_ACTIVE) %DebugPrepareStepInIfStepping(this); | 23 if (DEBUG_IS_ACTIVE) %DebugPrepareStepInIfStepping(this); |
24 return %_GeneratorNext(this, value); | 24 try { |
25 return %_GeneratorNext(this, value); | |
26 } catch (e) { | |
27 %GeneratorClose(this); | |
28 throw e; | |
29 } | |
25 } | 30 } |
26 | 31 |
27 function GeneratorObjectThrow(exn) { | 32 function GeneratorObjectThrow(exn) { |
28 if (!IS_GENERATOR(this)) { | 33 if (!IS_GENERATOR(this)) { |
29 throw MakeTypeError('incompatible_method_receiver', | 34 throw MakeTypeError('incompatible_method_receiver', |
30 ['[Generator].prototype.throw', this]); | 35 ['[Generator].prototype.throw', this]); |
31 } | 36 } |
32 | 37 |
33 return %_GeneratorThrow(this, exn); | 38 try { |
39 return %_GeneratorThrow(this, exn); | |
40 } catch (e) { | |
rossberg
2014/11/12 11:56:27
Wait, won't this catch the very throw above?
wingo
2014/11/12 12:03:02
It could, if the generator itself doesn't catch it
| |
41 %GeneratorClose(this); | |
42 throw e; | |
43 } | |
34 } | 44 } |
35 | 45 |
36 function GeneratorObjectIterator() { | 46 function GeneratorObjectIterator() { |
37 return this; | 47 return this; |
38 } | 48 } |
39 | 49 |
40 function GeneratorFunctionPrototypeConstructor(x) { | 50 function GeneratorFunctionPrototypeConstructor(x) { |
41 if (%_IsConstructCall()) { | 51 if (%_IsConstructCall()) { |
42 throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']); | 52 throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']); |
43 } | 53 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 symbolToStringTag, "Generator", DONT_ENUM | READ_ONLY); | 88 symbolToStringTag, "Generator", DONT_ENUM | READ_ONLY); |
79 %InternalSetPrototype(GeneratorFunctionPrototype, $Function.prototype); | 89 %InternalSetPrototype(GeneratorFunctionPrototype, $Function.prototype); |
80 %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor); | 90 %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor); |
81 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", | 91 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", |
82 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); | 92 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); |
83 %InternalSetPrototype(GeneratorFunction, $Function); | 93 %InternalSetPrototype(GeneratorFunction, $Function); |
84 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); | 94 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); |
85 } | 95 } |
86 | 96 |
87 SetUpGenerators(); | 97 SetUpGenerators(); |
OLD | NEW |