| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 function GeneratorObjectThrow(exn) { | 49 function GeneratorObjectThrow(exn) { |
| 50 if (!IS_GENERATOR(this)) { | 50 if (!IS_GENERATOR(this)) { |
| 51 throw MakeTypeError('incompatible_method_receiver', | 51 throw MakeTypeError('incompatible_method_receiver', |
| 52 ['[Generator].prototype.throw', this]); | 52 ['[Generator].prototype.throw', this]); |
| 53 } | 53 } |
| 54 | 54 |
| 55 return %_GeneratorThrow(this, exn); | 55 return %_GeneratorThrow(this, exn); |
| 56 } | 56 } |
| 57 | 57 |
| 58 function GeneratorFunctionPrototypeConstructor(x) { |
| 59 if (%_IsConstructCall()) { |
| 60 throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']); |
| 61 } |
| 62 } |
| 63 |
| 64 function GeneratorFunctionConstructor(arg1) { // length == 1 |
| 65 var source = NewFunctionString(arguments, 'function*'); |
| 66 var global_receiver = %GlobalReceiver(global); |
| 67 // Compile the string in the constructor and not a helper so that errors |
| 68 // appear to come from here. |
| 69 var f = %_CallFunction(global_receiver, %CompileString(source, true)); |
| 70 %FunctionMarkNameShouldPrintAsAnonymous(f); |
| 71 return f; |
| 72 } |
| 73 |
| 74 |
| 58 function SetUpGenerators() { | 75 function SetUpGenerators() { |
| 59 %CheckIsBootstrapping(); | 76 %CheckIsBootstrapping(); |
| 60 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; | 77 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; |
| 61 InstallFunctions(GeneratorObjectPrototype, | 78 InstallFunctions(GeneratorObjectPrototype, |
| 62 DONT_ENUM | DONT_DELETE | READ_ONLY, | 79 DONT_ENUM | DONT_DELETE | READ_ONLY, |
| 63 ["next", GeneratorObjectNext, | 80 ["next", GeneratorObjectNext, |
| 64 "throw", GeneratorObjectThrow]); | 81 "throw", GeneratorObjectThrow]); |
| 65 %SetProperty(GeneratorObjectPrototype, "constructor", | 82 %SetProperty(GeneratorObjectPrototype, "constructor", |
| 66 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY); | 83 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 67 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype); | 84 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype); |
| 85 %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor); |
| 68 %SetProperty(GeneratorFunctionPrototype, "constructor", | 86 %SetProperty(GeneratorFunctionPrototype, "constructor", |
| 69 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); | 87 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 70 %SetPrototype(GeneratorFunction, $Function); | 88 %SetPrototype(GeneratorFunction, $Function); |
| 89 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); |
| 71 } | 90 } |
| 72 | 91 |
| 73 SetUpGenerators(); | 92 SetUpGenerators(); |
| OLD | NEW |