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

Unified Diff: src/v8natives.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. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/generator.js ('k') | test/mjsunit/harmony/generators-iteration.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index fd8b7f20689e6a87d89cc9db30c358caa84b7413..85f6c4f28df2074ea9dbb958f15f4a6e4b313d58 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -1756,24 +1756,23 @@ function FunctionBind(this_arg) { // Length is 1.
}
-function NewFunction(arg1) { // length == 1
- var n = %_ArgumentsLength();
- var p = '';
- if (n > 1) {
- p = new InternalArray(n - 1);
- for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i);
- p = Join(p, n - 1, ',', NonStringToString);
+// InternalArray, string, boolean -> Function
+function NewFunction(formals, body, is_generator) {
+ var formals_string = '';
+ if (formals.length > 0) {
+ formals_string = Join(formals, formals.length, ',', NonStringToString);
// If the formal parameters string include ) - an illegal
// character - it may make the combined function expression
// compile. We avoid this problem by checking for this early on.
- if (p.indexOf(')') != -1) throw MakeSyntaxError('paren_in_arg_string',[]);
+ if (formals_string.indexOf(')') != -1)
+ throw MakeSyntaxError('paren_in_arg_string', []);
// If the formal parameters include an unbalanced block comment, the
// function must be rejected. Since JavaScript does not allow nested
// comments we can include a trailing block comment to catch this.
- p += '\n/' + '**/';
+ formals_string += '\n/' + '**/';
}
- var body = (n > 0) ? ToString(%_Arguments(n - 1)) : '';
- var source = '(function(' + p + ') {\n' + body + '\n})';
+ var head = is_generator ? '(function*(' : '(function(';
+ var source = head + formals_string + ') {\n' + body + '\n})';
var global_receiver = %GlobalReceiver(global);
var f = %_CallFunction(global_receiver, %CompileString(source, true));
@@ -1783,12 +1782,24 @@ function NewFunction(arg1) { // length == 1
}
+function FunctionConstructor(arg1) { // length == 1
+ var n = %_ArgumentsLength();
+ if (n > 0) {
Michael Starzinger 2013/05/14 13:51:31 We should try to have a fast-path for the case whe
+ 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)), false);
+ } else {
+ return NewFunction(new InternalArray(0), '', false);
+ }
+}
+
+
// ----------------------------------------------------------------------------
function SetUpFunction() {
%CheckIsBootstrapping();
- %SetCode($Function, NewFunction);
+ %SetCode($Function, FunctionConstructor);
%SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM);
InstallFunctions($Function.prototype, DONT_ENUM, $Array(
« no previous file with comments | « src/generator.js ('k') | test/mjsunit/harmony/generators-iteration.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698