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