| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 "use strict"; | 28 "use strict"; |
| 29 | 29 |
| 30 // This file relies on the fact that the following declarations have been made | 30 // This file relies on the fact that the following declarations have been made |
| 31 // in runtime.js: | 31 // in runtime.js: |
| 32 // var $Function = global.Function; | 32 // var $Function = global.Function; |
| 33 | 33 |
| 34 // ---------------------------------------------------------------------------- | 34 // ---------------------------------------------------------------------------- |
| 35 | 35 |
| 36 | 36 |
| 37 // TODO(wingo): Give link to specification. For now, the following diagram is | 37 // Generator functions and objects are specified by ES6, sections 15.19.3 and |
| 38 // the spec: | 38 // 15.19.4. |
| 39 // http://wiki.ecmascript.org/lib/exe/fetch.php?cache=cache&media=harmony:es6_ge
nerator_object_model_3-29-13.png | |
| 40 | 39 |
| 41 function GeneratorObjectNext() { | 40 function GeneratorObjectNext(value) { |
| 42 if (!IS_GENERATOR(this)) { | 41 if (!IS_GENERATOR(this)) { |
| 43 throw MakeTypeError('incompatible_method_receiver', | 42 throw MakeTypeError('incompatible_method_receiver', |
| 44 ['[Generator].prototype.next', this]); | 43 ['[Generator].prototype.next', this]); |
| 45 } | 44 } |
| 46 | 45 |
| 47 return %_GeneratorSend(this, void 0); | 46 return %_GeneratorNext(this, value); |
| 48 } | |
| 49 | |
| 50 function GeneratorObjectSend(value) { | |
| 51 if (!IS_GENERATOR(this)) { | |
| 52 throw MakeTypeError('incompatible_method_receiver', | |
| 53 ['[Generator].prototype.send', this]); | |
| 54 } | |
| 55 | |
| 56 return %_GeneratorSend(this, value); | |
| 57 } | 47 } |
| 58 | 48 |
| 59 function GeneratorObjectThrow(exn) { | 49 function GeneratorObjectThrow(exn) { |
| 60 if (!IS_GENERATOR(this)) { | 50 if (!IS_GENERATOR(this)) { |
| 61 throw MakeTypeError('incompatible_method_receiver', | 51 throw MakeTypeError('incompatible_method_receiver', |
| 62 ['[Generator].prototype.throw', this]); | 52 ['[Generator].prototype.throw', this]); |
| 63 } | 53 } |
| 64 | 54 |
| 65 return %_GeneratorThrow(this, exn); | 55 return %_GeneratorThrow(this, exn); |
| 66 } | 56 } |
| 67 | 57 |
| 68 function SetUpGenerators() { | 58 function SetUpGenerators() { |
| 69 %CheckIsBootstrapping(); | 59 %CheckIsBootstrapping(); |
| 70 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; | 60 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; |
| 71 InstallFunctions(GeneratorObjectPrototype, | 61 InstallFunctions(GeneratorObjectPrototype, |
| 72 DONT_ENUM | DONT_DELETE | READ_ONLY, | 62 DONT_ENUM | DONT_DELETE | READ_ONLY, |
| 73 ["next", GeneratorObjectNext, | 63 ["next", GeneratorObjectNext, |
| 74 "send", GeneratorObjectSend, | |
| 75 "throw", GeneratorObjectThrow]); | 64 "throw", GeneratorObjectThrow]); |
| 76 %SetProperty(GeneratorObjectPrototype, "constructor", | 65 %SetProperty(GeneratorObjectPrototype, "constructor", |
| 77 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY); | 66 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 78 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype); | 67 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype); |
| 79 %SetProperty(GeneratorFunctionPrototype, "constructor", | 68 %SetProperty(GeneratorFunctionPrototype, "constructor", |
| 80 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); | 69 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 81 %SetPrototype(GeneratorFunction, $Function); | 70 %SetPrototype(GeneratorFunction, $Function); |
| 82 } | 71 } |
| 83 | 72 |
| 84 SetUpGenerators(); | 73 SetUpGenerators(); |
| OLD | NEW |