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

Side by Side Diff: src/generator.js

Issue 15218004: GeneratorFunction() makes generator instances (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 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 | « no previous file | src/v8natives.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 // 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
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 source = NewFunctionString(arguments, 'function*');
76 var global_receiver = %GlobalReceiver(global);
77 // Compile the string in the constructor and not a helper so that errors
78 // appear to come from here.
79 var f = %_CallFunction(global_receiver, %CompileString(source, true));
80 %FunctionMarkNameShouldPrintAsAnonymous(f);
81 return f;
82 }
83
84
68 function SetUpGenerators() { 85 function SetUpGenerators() {
69 %CheckIsBootstrapping(); 86 %CheckIsBootstrapping();
70 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype; 87 var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
71 InstallFunctions(GeneratorObjectPrototype, 88 InstallFunctions(GeneratorObjectPrototype,
72 DONT_ENUM | DONT_DELETE | READ_ONLY, 89 DONT_ENUM | DONT_DELETE | READ_ONLY,
73 ["next", GeneratorObjectNext, 90 ["next", GeneratorObjectNext,
74 "send", GeneratorObjectSend, 91 "send", GeneratorObjectSend,
75 "throw", GeneratorObjectThrow]); 92 "throw", GeneratorObjectThrow]);
76 %SetProperty(GeneratorObjectPrototype, "constructor", 93 %SetProperty(GeneratorObjectPrototype, "constructor",
77 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY); 94 GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY);
78 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype); 95 %SetPrototype(GeneratorFunctionPrototype, $Function.prototype);
96 %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor);
79 %SetProperty(GeneratorFunctionPrototype, "constructor", 97 %SetProperty(GeneratorFunctionPrototype, "constructor",
80 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY); 98 GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY);
81 %SetPrototype(GeneratorFunction, $Function); 99 %SetPrototype(GeneratorFunction, $Function);
100 %SetCode(GeneratorFunction, GeneratorFunctionConstructor);
82 } 101 }
83 102
84 SetUpGenerators(); 103 SetUpGenerators();
OLDNEW
« no previous file with comments | « no previous file | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698