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 |
| 11 // ------------------------------------------------------------------- |
| 12 // Imports |
| 13 |
11 var GlobalFunction = global.Function; | 14 var GlobalFunction = global.Function; |
12 | 15 |
| 16 var NewFunctionString; |
| 17 |
| 18 utils.Import(function(from) { |
| 19 NewFunctionString = from.NewFunctionString; |
| 20 }); |
| 21 |
13 // ---------------------------------------------------------------------------- | 22 // ---------------------------------------------------------------------------- |
14 | 23 |
15 // Generator functions and objects are specified by ES6, sections 15.19.3 and | 24 // Generator functions and objects are specified by ES6, sections 15.19.3 and |
16 // 15.19.4. | 25 // 15.19.4. |
17 | 26 |
18 function GeneratorObjectNext(value) { | 27 function GeneratorObjectNext(value) { |
19 if (!IS_GENERATOR(this)) { | 28 if (!IS_GENERATOR(this)) { |
20 throw MakeTypeError(kIncompatibleMethodReceiver, | 29 throw MakeTypeError(kIncompatibleMethodReceiver, |
21 '[Generator].prototype.next', this); | 30 '[Generator].prototype.next', this); |
22 } | 31 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // Generator is already closed. | 69 // Generator is already closed. |
61 throw exn; | 70 throw exn; |
62 } else { | 71 } else { |
63 // Generator is running. | 72 // Generator is running. |
64 throw MakeTypeError(kGeneratorRunning); | 73 throw MakeTypeError(kGeneratorRunning); |
65 } | 74 } |
66 } | 75 } |
67 | 76 |
68 | 77 |
69 function GeneratorFunctionConstructor(arg1) { // length == 1 | 78 function GeneratorFunctionConstructor(arg1) { // length == 1 |
70 var source = $newFunctionString(arguments, 'function*'); | 79 var source = NewFunctionString(arguments, 'function*'); |
71 var global_proxy = %GlobalProxy(GeneratorFunctionConstructor); | 80 var global_proxy = %GlobalProxy(GeneratorFunctionConstructor); |
72 // Compile the string in the constructor and not a helper so that errors | 81 // Compile the string in the constructor and not a helper so that errors |
73 // appear to come from here. | 82 // appear to come from here. |
74 var f = %_CallFunction(global_proxy, %CompileString(source, true)); | 83 var f = %_CallFunction(global_proxy, %CompileString(source, true)); |
75 %FunctionMarkNameShouldPrintAsAnonymous(f); | 84 %FunctionMarkNameShouldPrintAsAnonymous(f); |
76 return f; | 85 return f; |
77 } | 86 } |
78 | 87 |
79 // ---------------------------------------------------------------------------- | 88 // ---------------------------------------------------------------------------- |
80 | 89 |
81 // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by | 90 // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by |
82 // neither Crankshaft nor TurboFan, disable optimization of wrappers here. | 91 // neither Crankshaft nor TurboFan, disable optimization of wrappers here. |
83 %NeverOptimizeFunction(GeneratorObjectNext); | 92 %NeverOptimizeFunction(GeneratorObjectNext); |
84 %NeverOptimizeFunction(GeneratorObjectThrow); | 93 %NeverOptimizeFunction(GeneratorObjectThrow); |
85 | 94 |
86 // Set up non-enumerable functions on the generator prototype object. | 95 // Set up non-enumerable functions on the generator prototype object. |
87 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; | 96 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; |
88 $installFunctions(GeneratorObjectPrototype, | 97 utils.InstallFunctions(GeneratorObjectPrototype, |
89 DONT_ENUM, | 98 DONT_ENUM, |
90 ["next", GeneratorObjectNext, | 99 ["next", GeneratorObjectNext, |
91 "throw", GeneratorObjectThrow]); | 100 "throw", GeneratorObjectThrow]); |
92 | 101 |
93 %AddNamedProperty(GeneratorObjectPrototype, "constructor", | 102 %AddNamedProperty(GeneratorObjectPrototype, "constructor", |
94 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY); | 103 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY); |
95 %AddNamedProperty(GeneratorObjectPrototype, | 104 %AddNamedProperty(GeneratorObjectPrototype, |
96 symbolToStringTag, "Generator", DONT_ENUM | READ_ONLY); | 105 symbolToStringTag, "Generator", DONT_ENUM | READ_ONLY); |
97 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); | 106 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); |
98 %AddNamedProperty(GeneratorFunctionPrototype, | 107 %AddNamedProperty(GeneratorFunctionPrototype, |
99 symbolToStringTag, "GeneratorFunction", DONT_ENUM | READ_ONLY); | 108 symbolToStringTag, "GeneratorFunction", DONT_ENUM | READ_ONLY); |
100 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", | 109 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", |
101 GeneratorFunction, DONT_ENUM | READ_ONLY); | 110 GeneratorFunction, DONT_ENUM | READ_ONLY); |
102 %InternalSetPrototype(GeneratorFunction, GlobalFunction); | 111 %InternalSetPrototype(GeneratorFunction, GlobalFunction); |
103 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); | 112 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); |
104 | 113 |
105 }) | 114 }) |
OLD | NEW |