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, shared, exports) { | 5 (function(global, shared, exports) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } else if (continuation == 0) { | 59 } else if (continuation == 0) { |
60 // Generator is already closed. | 60 // Generator is already closed. |
61 throw exn; | 61 throw exn; |
62 } else { | 62 } else { |
63 // Generator is running. | 63 // Generator is running. |
64 throw MakeTypeError(kGeneratorRunning); | 64 throw MakeTypeError(kGeneratorRunning); |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 | 68 |
69 function GeneratorObjectIterator() { | |
70 return this; | |
71 } | |
72 | |
73 | |
74 function GeneratorFunctionConstructor(arg1) { // length == 1 | 69 function GeneratorFunctionConstructor(arg1) { // length == 1 |
75 var source = $newFunctionString(arguments, 'function*'); | 70 var source = $newFunctionString(arguments, 'function*'); |
76 var global_proxy = %GlobalProxy(GeneratorFunctionConstructor); | 71 var global_proxy = %GlobalProxy(GeneratorFunctionConstructor); |
77 // Compile the string in the constructor and not a helper so that errors | 72 // Compile the string in the constructor and not a helper so that errors |
78 // appear to come from here. | 73 // appear to come from here. |
79 var f = %_CallFunction(global_proxy, %CompileString(source, true)); | 74 var f = %_CallFunction(global_proxy, %CompileString(source, true)); |
80 %FunctionMarkNameShouldPrintAsAnonymous(f); | 75 %FunctionMarkNameShouldPrintAsAnonymous(f); |
81 return f; | 76 return f; |
82 } | 77 } |
83 | 78 |
84 // ---------------------------------------------------------------------------- | 79 // ---------------------------------------------------------------------------- |
85 | 80 |
86 // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by | 81 // Both Runtime_GeneratorNext and Runtime_GeneratorThrow are supported by |
87 // neither Crankshaft nor TurboFan, disable optimization of wrappers here. | 82 // neither Crankshaft nor TurboFan, disable optimization of wrappers here. |
88 %NeverOptimizeFunction(GeneratorObjectNext); | 83 %NeverOptimizeFunction(GeneratorObjectNext); |
89 %NeverOptimizeFunction(GeneratorObjectThrow); | 84 %NeverOptimizeFunction(GeneratorObjectThrow); |
90 | 85 |
91 // Set up non-enumerable functions on the generator prototype object. | 86 // Set up non-enumerable functions on the generator prototype object. |
92 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; | 87 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; |
93 $installFunctions(GeneratorObjectPrototype, | 88 $installFunctions(GeneratorObjectPrototype, |
94 DONT_ENUM, | 89 DONT_ENUM, |
95 ["next", GeneratorObjectNext, | 90 ["next", GeneratorObjectNext, |
96 "throw", GeneratorObjectThrow]); | 91 "throw", GeneratorObjectThrow]); |
97 | 92 |
98 $setFunctionName(GeneratorObjectIterator, symbolIterator); | |
99 %AddNamedProperty(GeneratorObjectPrototype, symbolIterator, | |
100 GeneratorObjectIterator, DONT_ENUM | DONT_DELETE | READ_ONLY); | |
101 %AddNamedProperty(GeneratorObjectPrototype, "constructor", | 93 %AddNamedProperty(GeneratorObjectPrototype, "constructor", |
102 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY); | 94 GeneratorFunctionPrototype, DONT_ENUM | READ_ONLY); |
103 %AddNamedProperty(GeneratorObjectPrototype, | 95 %AddNamedProperty(GeneratorObjectPrototype, |
104 symbolToStringTag, "Generator", DONT_ENUM | READ_ONLY); | 96 symbolToStringTag, "Generator", DONT_ENUM | READ_ONLY); |
105 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); | 97 %InternalSetPrototype(GeneratorFunctionPrototype, GlobalFunction.prototype); |
106 %AddNamedProperty(GeneratorFunctionPrototype, | 98 %AddNamedProperty(GeneratorFunctionPrototype, |
107 symbolToStringTag, "GeneratorFunction", DONT_ENUM | READ_ONLY); | 99 symbolToStringTag, "GeneratorFunction", DONT_ENUM | READ_ONLY); |
108 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", | 100 %AddNamedProperty(GeneratorFunctionPrototype, "constructor", |
109 GeneratorFunction, DONT_ENUM | READ_ONLY); | 101 GeneratorFunction, DONT_ENUM | READ_ONLY); |
110 %InternalSetPrototype(GeneratorFunction, GlobalFunction); | 102 %InternalSetPrototype(GeneratorFunction, GlobalFunction); |
111 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); | 103 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); |
112 | 104 |
113 }) | 105 }) |
OLD | NEW |