Chromium Code Reviews

Unified Diff: src/generator.js

Issue 14857009: GeneratorFunction() makes generator instances (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: React to feedback Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « no previous file | src/v8natives.js » ('j') | src/v8natives.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/generator.js
diff --git a/src/generator.js b/src/generator.js
index 5e61091565567bf9d516a45d0efd72add6aa33af..d2e53ee7cafb070317de32af9837c8c8fcdaa580 100644
--- a/src/generator.js
+++ b/src/generator.js
@@ -65,6 +65,24 @@ function GeneratorObjectThrow(exn) {
return %_GeneratorThrow(this, exn);
}
+function GeneratorFunctionPrototypeConstructor(x) {
+ if (%_IsConstructCall()) {
+ throw MakeTypeError('not_constructor', ['GeneratorFunctionPrototype']);
+ }
+}
+
+function GeneratorFunctionConstructor(arg1) { // length == 1
+ var n = %_ArgumentsLength();
+ if (n > 0) {
+ var formals = new InternalArray(n - 1);
+ for (var i = 0; i < n - 1; i++) formals[i] = %_Arguments(i);
+ return NewFunction(formals, ToString(%_Arguments(n - 1)), true);
+ } else {
+ return NewFunction(new InternalArray(0), '', true);
+ }
+}
+
+
function SetUpGenerators() {
%CheckIsBootstrapping();
var GeneratorObjectPrototype = GeneratorFunctionPrototype.prototype;
@@ -76,9 +94,11 @@ function SetUpGenerators() {
%SetProperty(GeneratorObjectPrototype, "constructor",
GeneratorFunctionPrototype, DONT_ENUM | DONT_DELETE | READ_ONLY);
%SetPrototype(GeneratorFunctionPrototype, $Function.prototype);
+ %SetCode(GeneratorFunctionPrototype, GeneratorFunctionPrototypeConstructor);
%SetProperty(GeneratorFunctionPrototype, "constructor",
GeneratorFunction, DONT_ENUM | DONT_DELETE | READ_ONLY);
%SetPrototype(GeneratorFunction, $Function);
+ %SetCode(GeneratorFunction, GeneratorFunctionConstructor);
}
SetUpGenerators();
« no previous file with comments | « no previous file | src/v8natives.js » ('j') | src/v8natives.js » ('J')

Powered by Google App Engine