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 18 matching lines...) Expand all Loading... |
29 function GeneratorObjectNext(value) { | 29 function GeneratorObjectNext(value) { |
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 return %_GeneratorNext(this, value); |
40 return %_GeneratorNext(this, value); | |
41 } catch (e) { | |
42 %GeneratorClose(this); | |
43 throw e; | |
44 } | |
45 } else if (continuation == 0) { | 40 } else if (continuation == 0) { |
46 // Generator is already closed. | 41 // Generator is already closed. |
47 return { value: void 0, done: true }; | 42 return { value: void 0, done: true }; |
48 } else { | 43 } else { |
49 // Generator is running. | 44 // Generator is running. |
50 throw MakeTypeError(kGeneratorRunning); | 45 throw MakeTypeError(kGeneratorRunning); |
51 } | 46 } |
52 } | 47 } |
53 | 48 |
54 | 49 |
55 function GeneratorObjectThrow(exn) { | 50 function GeneratorObjectThrow(exn) { |
56 if (!IS_GENERATOR(this)) { | 51 if (!IS_GENERATOR(this)) { |
57 throw MakeTypeError(kIncompatibleMethodReceiver, | 52 throw MakeTypeError(kIncompatibleMethodReceiver, |
58 '[Generator].prototype.throw', this); | 53 '[Generator].prototype.throw', this); |
59 } | 54 } |
60 | 55 |
61 var continuation = %GeneratorGetContinuation(this); | 56 var continuation = %GeneratorGetContinuation(this); |
62 if (continuation > 0) { | 57 if (continuation > 0) { |
63 // Generator is suspended. | 58 // Generator is suspended. |
64 try { | 59 return %_GeneratorThrow(this, exn); |
65 return %_GeneratorThrow(this, exn); | |
66 } catch (e) { | |
67 %GeneratorClose(this); | |
68 throw e; | |
69 } | |
70 } else if (continuation == 0) { | 60 } else if (continuation == 0) { |
71 // Generator is already closed. | 61 // Generator is already closed. |
72 throw exn; | 62 throw exn; |
73 } else { | 63 } else { |
74 // Generator is running. | 64 // Generator is running. |
75 throw MakeTypeError(kGeneratorRunning); | 65 throw MakeTypeError(kGeneratorRunning); |
76 } | 66 } |
77 } | 67 } |
78 | 68 |
79 // ---------------------------------------------------------------------------- | 69 // ---------------------------------------------------------------------------- |
(...skipping 15 matching lines...) Expand all Loading... |
95 %AddNamedProperty(GeneratorObjectPrototype, | 85 %AddNamedProperty(GeneratorObjectPrototype, |
96 toStringTagSymbol, "Generator", DONT_ENUM | READ_ONLY); | 86 toStringTagSymbol, "Generator", DONT_ENUM | READ_ONLY); |
97 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); | 87 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); |
98 %AddNamedProperty(GeneratorFunctionPrototype, | 88 %AddNamedProperty(GeneratorFunctionPrototype, |
99 toStringTagSymbol, "GeneratorFunction", DONT_ENUM | READ_ONLY); | 89 toStringTagSymbol, "GeneratorFunction", DONT_ENUM | READ_ONLY); |
100 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", | 90 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", |
101 GeneratorFunction, DONT_ENUM | READ_ONLY); | 91 GeneratorFunction, DONT_ENUM | READ_ONLY); |
102 %InternalSetPrototype(GeneratorFunction, GlobalFunction); | 92 %InternalSetPrototype(GeneratorFunction, GlobalFunction); |
103 | 93 |
104 }) | 94 }) |
OLD | NEW |