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 "use strict"; | 5 "use strict"; |
6 | 6 |
7 // This file relies on the fact that the following declarations have been made | 7 // This file relies on the fact that the following declarations have been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $Function = global.Function; | 9 // var $Function = global.Function; |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 if (%_IsConstructCall()) { | 36 if (%_IsConstructCall()) { |
37 throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']); | 37 throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']); |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 function GeneratorFunctionConstructor(arg1) { // length == 1 | 41 function GeneratorFunctionConstructor(arg1) { // length == 1 |
42 var source = NewFunctionString(arguments, 'function*'); | 42 var source = NewFunctionString(arguments, 'function*'); |
43 var global_receiver = %GlobalReceiver(global); | 43 var global_receiver = %GlobalReceiver(global); |
44 // Compile the string in the constructor and not a helper so that errors | 44 // Compile the string in the constructor and not a helper so that errors |
45 // appear to come from here. | 45 // appear to come from here. |
46 var f = %_CallFunction(global_receiver, %CompileString(source, true)); | 46 var f = %CompileString(source, true); |
| 47 if (!IS_FUNCTION(f)) return f; |
| 48 f = %_CallFunction(global_receiver, f); |
47 %FunctionMarkNameShouldPrintAsAnonymous(f); | 49 %FunctionMarkNameShouldPrintAsAnonymous(f); |
48 return f; | 50 return f; |
49 } | 51 } |
50 | 52 |
51 | 53 |
52 function SetUpGenerators() { | 54 function SetUpGenerators() { |
53 %CheckIsBootstrapping(); | 55 %CheckIsBootstrapping(); |
54 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; | 56 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; |
55 InstallFunctions(GeneratorObjectPrototype, | 57 InstallFunctions(GeneratorObjectPrototype, |
56 DONT_ENUM | DONT_DELETE | READ_ONLY, | 58 DONT_ENUM | DONT_DELETE | READ_ONLY, |
57 ["next", GeneratorObjectNext, | 59 ["next", GeneratorObjectNext, |
58 "throw", GeneratorObjectThrow]); | 60 "throw", GeneratorObjectThrow]); |
59 %SetProperty(GeneratorObjectPrototype, "constructor", | 61 %SetProperty(GeneratorObjectPrototype, "constructor", |
60 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY); | 62 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY); |
61 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype); | 63 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype); |
62 %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor); | 64 %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor); |
63 %SetProperty(GeneratorFunctionPrototype, "constructor", | 65 %SetProperty(GeneratorFunctionPrototype, "constructor", |
64 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); | 66 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); |
65 %SetPrototype(GeneratorFunction, $Function); | 67 %SetPrototype(GeneratorFunction, $Function); |
66 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); | 68 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); |
67 } | 69 } |
68 | 70 |
69 SetUpGenerators(); | 71 SetUpGenerators(); |
OLD | NEW |