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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 throw MakeTypeError(kGeneratorRunning); | 77 throw MakeTypeError(kGeneratorRunning); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 | 81 |
82 function GeneratorFunctionConstructor(arg1) { // length == 1 | 82 function GeneratorFunctionConstructor(arg1) { // length == 1 |
83 var source = NewFunctionString(arguments, 'function*'); | 83 var source = NewFunctionString(arguments, 'function*'); |
84 var global_proxy = %GlobalProxy(GeneratorFunctionConstructor); | 84 var global_proxy = %GlobalProxy(GeneratorFunctionConstructor); |
85 // Compile the string in the constructor and not a helper so that errors | 85 // Compile the string in the constructor and not a helper so that errors |
86 // appear to come from here. | 86 // appear to come from here. |
87 var f = %_CallFunction(global_proxy, %CompileString(source, true)); | 87 var func = %_CallFunction(global_proxy, %CompileString(source, true)); |
88 %FunctionMarkNameShouldPrintAsAnonymous(f); | 88 // Set name-should-print-as-anonymous flag on the ShareFunctionInfo and |
89 return f; | 89 // ensure that |func| uses correct initial map from |new.target| if |
| 90 // it's available. |
| 91 return %CompleteFunctionConstruction(func, GeneratorFunction, new.target); |
90 } | 92 } |
91 | 93 |
92 // ---------------------------------------------------------------------------- | 94 // ---------------------------------------------------------------------------- |
93 | 95 |
94 // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by | 96 // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by |
95 // neither Crankshaft nor TurboFan, disable optimization of wrappers here. | 97 // neither Crankshaft nor TurboFan, disable optimization of wrappers here. |
96 %NeverOptimizeFunction(GeneratorObjectNext); | 98 %NeverOptimizeFunction(GeneratorObjectNext); |
97 %NeverOptimizeFunction(GeneratorObjectThrow); | 99 %NeverOptimizeFunction(GeneratorObjectThrow); |
98 | 100 |
99 // Set up non-enumerable functions on the generator prototype object. | 101 // Set up non-enumerable functions on the generator prototype object. |
100 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; | 102 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; |
101 utils.InstallFunctions(GeneratorObjectPrototype, | 103 utils.InstallFunctions(GeneratorObjectPrototype, |
102 DONT_ENUM, | 104 DONT_ENUM, |
103 ["next", GeneratorObjectNext, | 105 ["next", GeneratorObjectNext, |
104 "throw", GeneratorObjectThrow]); | 106 "throw", GeneratorObjectThrow]); |
105 | 107 |
106 %AddNamedProperty(GeneratorObjectPrototype, "constructor", | 108 %AddNamedProperty(GeneratorObjectPrototype, "constructor", |
107 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY); | 109 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY); |
108 %AddNamedProperty(GeneratorObjectPrototype, | 110 %AddNamedProperty(GeneratorObjectPrototype, |
109 toStringTagSymbol, "Generator", DONT_ENUM | READ_ONLY); | 111 toStringTagSymbol, "Generator", DONT_ENUM | READ_ONLY); |
110 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); | 112 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); |
111 %AddNamedProperty(GeneratorFunctionPrototype, | 113 %AddNamedProperty(GeneratorFunctionPrototype, |
112 toStringTagSymbol, "GeneratorFunction", DONT_ENUM | READ_ONLY); | 114 toStringTagSymbol, "GeneratorFunction", DONT_ENUM | READ_ONLY); |
113 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", | 115 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", |
114 GeneratorFunction, DONT_ENUM | READ_ONLY); | 116 GeneratorFunction, DONT_ENUM | READ_ONLY); |
115 %InternalSetPrototype(GeneratorFunction, GlobalFunction); | 117 %InternalSetPrototype(GeneratorFunction, GlobalFunction); |
116 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); | 118 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); |
117 | 119 |
118 }) | 120 }) |
OLD | NEW |