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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 | 58 |
59 function GeneratorObjectThrow(exn) { | 59 function GeneratorObjectThrow(exn) { |
60 if (!IS_GENERATOR(this)) { | 60 if (!IS_GENERATOR(this)) { |
61 throw MakeTypeError('incompatible_method_receiver', | 61 throw MakeTypeError('incompatible_method_receiver', |
62 ['[Generator].prototype.throw', this]); | 62 ['[Generator].prototype.throw', this]); |
63 } | 63 } |
64 | 64 |
65 return %_GeneratorThrow(this, exn); | 65 return %_GeneratorThrow(this, exn); |
66 } | 66 } |
67 | 67 |
68 function GeneratorFunctionPrototypeConstructor(x) { | |
69 if (%_IsConstructCall()) { | |
70 throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']); | |
71 } | |
72 } | |
73 | |
74 function GeneratorFunctionConstructor(arg1) { // length == 1 | |
75 var n = %_ArgumentsLength(); | |
76 if (n) { | |
rossberg
2013/05/13 11:33:46
Nit: n > 0
wingo
2013/05/14 10:11:50
Done.
| |
77 var formals = new InternalArray(n - 1); | |
78 for (var i = 0; i < n - 1; i++) formals[i] = %_Arguments(i); | |
79 return NewFunctionHelper(formals, ToString(%_Arguments(n - 1)), true); | |
80 } else { | |
81 return NewFunctionHelper(new InternalArray(0), '', true); | |
82 } | |
83 } | |
84 | |
85 | |
68 function SetUpGenerators() { | 86 function SetUpGenerators() { |
69 %CheckIsBootstrapping(); | 87 %CheckIsBootstrapping(); |
70 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; | 88 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; |
71 InstallFunctions(GeneratorObjectPrototype, | 89 InstallFunctions(GeneratorObjectPrototype, |
72 DONT_ENUM | DONT_DELETE | READ_ONLY, | 90 DONT_ENUM | DONT_DELETE | READ_ONLY, |
73 ["next", GeneratorObjectNext, | 91 ["next", GeneratorObjectNext, |
74 "send", GeneratorObjectSend, | 92 "send", GeneratorObjectSend, |
75 "throw", GeneratorObjectThrow]); | 93 "throw", GeneratorObjectThrow]); |
76 %SetProperty(GeneratorObjectPrototype, "constructor", | 94 %SetProperty(GeneratorObjectPrototype, "constructor", |
77 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY); | 95 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY); |
78 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype); | 96 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype); |
97 %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor); | |
79 %SetProperty(GeneratorFunctionPrototype, "constructor", | 98 %SetProperty(GeneratorFunctionPrototype, "constructor", |
80 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); | 99 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); |
81 %SetPrototype(GeneratorFunction, $Function); | 100 %SetPrototype(GeneratorFunction, $Function); |
101 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); | |
82 } | 102 } |
83 | 103 |
84 SetUpGenerators(); | 104 SetUpGenerators(); |
OLD | NEW |