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 func = %_CallFunction(global_proxy, %CompileString(source, true)); | 87 var f = %_CallFunction(global_proxy, %CompileString(source, true)); |
88 // Set name-should-print-as-anonymous flag on the ShareFunctionInfo and | 88 %FunctionMarkNameShouldPrintAsAnonymous(f); |
89 // ensure that |func| uses correct initial map from |new.target| if | 89 return f; |
90 // it's available. | |
91 return %CompleteFunctionConstruction(func, GeneratorFunction, new.target); | |
92 } | 90 } |
93 | 91 |
94 // ---------------------------------------------------------------------------- | 92 // ---------------------------------------------------------------------------- |
95 | 93 |
96 // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by | 94 // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by |
97 // neither Crankshaft nor TurboFan, disable optimization of wrappers here. | 95 // neither Crankshaft nor TurboFan, disable optimization of wrappers here. |
98 %NeverOptimizeFunction(GeneratorObjectNext); | 96 %NeverOptimizeFunction(GeneratorObjectNext); |
99 %NeverOptimizeFunction(GeneratorObjectThrow); | 97 %NeverOptimizeFunction(GeneratorObjectThrow); |
100 | 98 |
101 // Set up non-enumerable functions on the generator prototype object. | 99 // Set up non-enumerable functions on the generator prototype object. |
102 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; | 100 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; |
103 utils.InstallFunctions(GeneratorObjectPrototype, | 101 utils.InstallFunctions(GeneratorObjectPrototype, |
104 DONT_ENUM, | 102 DONT_ENUM, |
105 ["next", GeneratorObjectNext, | 103 ["next", GeneratorObjectNext, |
106 "throw", GeneratorObjectThrow]); | 104 "throw", GeneratorObjectThrow]); |
107 | 105 |
108 %AddNamedProperty(GeneratorObjectPrototype, "constructor", | 106 %AddNamedProperty(GeneratorObjectPrototype, "constructor", |
109 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY); | 107 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY); |
110 %AddNamedProperty(GeneratorObjectPrototype, | 108 %AddNamedProperty(GeneratorObjectPrototype, |
111 toStringTagSymbol, "Generator", DONT_ENUM | READ_ONLY); | 109 toStringTagSymbol, "Generator", DONT_ENUM | READ_ONLY); |
112 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); | 110 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); |
113 %AddNamedProperty(GeneratorFunctionPrototype, | 111 %AddNamedProperty(GeneratorFunctionPrototype, |
114 toStringTagSymbol, "GeneratorFunction", DONT_ENUM | READ_ONLY); | 112 toStringTagSymbol, "GeneratorFunction", DONT_ENUM | READ_ONLY); |
115 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", | 113 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", |
116 GeneratorFunction, DONT_ENUM | READ_ONLY); | 114 GeneratorFunction, DONT_ENUM | READ_ONLY); |
117 %InternalSetPrototype(GeneratorFunction, GlobalFunction); | 115 %InternalSetPrototype(GeneratorFunction, GlobalFunction); |
118 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); | 116 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); |
119 | 117 |
120 }) | 118 }) |
OLD | NEW |