Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/generator.js

Issue 328093002: Add @@iterator for generator objects (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/flag-definitions.h ('k') | test/mjsunit/harmony/generators-runtime.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
25 25
26 function GeneratorObjectThrow(exn) { 26 function GeneratorObjectThrow(exn) {
27 if (!IS_GENERATOR(this)) { 27 if (!IS_GENERATOR(this)) {
28 throw MakeTypeError('incompatible_method_receiver', 28 throw MakeTypeError('incompatible_method_receiver',
29 ['[Generator].prototype.throw', this]); 29 ['[Generator].prototype.throw', this]);
30 } 30 }
31 31
32 return %_GeneratorThrow(this, exn); 32 return %_GeneratorThrow(this, exn);
33 } 33 }
34 34
35 function GeneratorObjectIterator() {
36 return this;
37 }
38
35 function GeneratorFunctionPrototypeConstructor(x) { 39 function GeneratorFunctionPrototypeConstructor(x) {
36 if (%_IsConstructCall()) { 40 if (%_IsConstructCall()) {
37 throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']); 41 throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']);
38 } 42 }
39 } 43 }
40 44
41 function GeneratorFunctionConstructor(arg1) { // length == 1 45 function GeneratorFunctionConstructor(arg1) { // length == 1
42 var source = NewFunctionString(arguments, 'function*'); 46 var source = NewFunctionString(arguments, 'function*');
43 var global_receiver = %GlobalReceiver(global); 47 var global_receiver = %GlobalReceiver(global);
44 // Compile the string in the constructor and not a helper so that errors 48 // Compile the string in the constructor and not a helper so that errors
45 // appear to come from here. 49 // appear to come from here.
46 var f = %_CallFunction(global_receiver, %CompileString(source, true)); 50 var f = %_CallFunction(global_receiver, %CompileString(source, true));
47 %FunctionMarkNameShouldPrintAsAnonymous(f); 51 %FunctionMarkNameShouldPrintAsAnonymous(f);
48 return f; 52 return f;
49 } 53 }
50 54
51 55
52 function SetUpGenerators() { 56 function SetUpGenerators() {
53 %CheckIsBootstrapping(); 57 %CheckIsBootstrapping();
54 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; 58 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
55 InstallFunctions(GeneratorObjectPrototype, 59 InstallFunctions(GeneratorObjectPrototype,
56 DONT_ENUM | DONT_DELETE | READ_ONLY, 60 DONT_ENUM | DONT_DELETE | READ_ONLY,
57 ["next", GeneratorObjectNext, 61 ["next", GeneratorObjectNext,
58 "throw", GeneratorObjectThrow]); 62 "throw", GeneratorObjectThrow]);
63 %SetProperty(GeneratorObjectPrototype, symbolIterator, GeneratorObjectIterator ,
64 DONT_ENUM | DONT_DELETE | READ_ONLY);
59 %SetProperty(GeneratorObjectPrototype, "constructor", 65 %SetProperty(GeneratorObjectPrototype, "constructor",
60 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY); 66 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY);
61 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype); 67 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype);
62 %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor); 68 %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor);
63 %SetProperty(GeneratorFunctionPrototype, "constructor", 69 %SetProperty(GeneratorFunctionPrototype, "constructor",
64 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); 70 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY);
65 %SetPrototype(GeneratorFunction, $Function); 71 %SetPrototype(GeneratorFunction, $Function);
66 %SetCode(GeneratorFunction, GeneratorFunctionConstructor); 72 %SetCode(GeneratorFunction, GeneratorFunctionConstructor);
67 } 73 }
68 74
69 SetUpGenerators(); 75 SetUpGenerators();
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | test/mjsunit/harmony/generators-runtime.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698