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

Side by Side Diff: src/v8natives.js

Issue 14857009: 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 // which are non-configurable. It therefore makes no sence to 1749 // which are non-configurable. It therefore makes no sence to
1750 // try to redefine these as defined by the spec. The spec says 1750 // try to redefine these as defined by the spec. The spec says
1751 // that bind should make these throw a TypeError if get or set 1751 // that bind should make these throw a TypeError if get or set
1752 // is called and make them non-enumerable and non-configurable. 1752 // is called and make them non-enumerable and non-configurable.
1753 // To be consistent with our normal functions we leave this as it is. 1753 // To be consistent with our normal functions we leave this as it is.
1754 // TODO(lrn): Do set these to be thrower. 1754 // TODO(lrn): Do set these to be thrower.
1755 return result; 1755 return result;
1756 } 1756 }
1757 1757
1758 1758
1759 function NewFunction(arg1) { // length == 1 1759 // InternalArray -> string -> boolean -> Function
rossberg 2013/05/13 11:33:46 Nit: JS functions aren't curried. ;)
wingo 2013/05/14 10:11:50 My notational ignorance showing again :)
1760 var n = %_ArgumentsLength(); 1760 function NewFunctionHelper(formals, body, is_generator) {
1761 var p = ''; 1761 var formals_string = '';
1762 if (n > 1) { 1762 if (formals.length) {
rossberg 2013/05/13 11:33:46 Nit: ... > 0
wingo 2013/05/14 10:11:50 Done.
1763 p = new InternalArray(n - 1); 1763 formals_string = Join(formals, formals.length, ',', NonStringToString);
1764 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i);
1765 p = Join(p, n - 1, ',', NonStringToString);
1766 // If the formal parameters string include ) - an illegal 1764 // If the formal parameters string include ) - an illegal
1767 // character - it may make the combined function expression 1765 // character - it may make the combined function expression
1768 // compile. We avoid this problem by checking for this early on. 1766 // compile. We avoid this problem by checking for this early on.
1769 if (p.indexOf(')') != -1) throw MakeSyntaxError('paren_in_arg_string',[]); 1767 if (formals_string.indexOf(')') != -1)
1768 throw MakeSyntaxError('paren_in_arg_string',[]);
rossberg 2013/05/13 11:33:46 Nit: can you insert a space before []?
wingo 2013/05/14 10:11:50 Done.
1770 // If the formal parameters include an unbalanced block comment, the 1769 // If the formal parameters include an unbalanced block comment, the
1771 // function must be rejected. Since JavaScript does not allow nested 1770 // function must be rejected. Since JavaScript does not allow nested
1772 // comments we can include a trailing block comment to catch this. 1771 // comments we can include a trailing block comment to catch this.
1773 p += '\n/' + '**/'; 1772 formals_string += '\n/' + '**/';
1774 } 1773 }
1775 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; 1774 var head = is_generator ? '(function*(' : '(function(';
1776 var source = '(function(' + p + ') {\n' + body + '\n})'; 1775 var source = head + formals_string + ') {\n' + body + '\n})';
1777 1776
1778 var global_receiver = %GlobalReceiver(global); 1777 var global_receiver = %GlobalReceiver(global);
1779 var f = %_CallFunction(global_receiver, %CompileString(source, true)); 1778 var f = %_CallFunction(global_receiver, %CompileString(source, true));
1780 1779
1781 %FunctionMarkNameShouldPrintAsAnonymous(f); 1780 %FunctionMarkNameShouldPrintAsAnonymous(f);
1782 return f; 1781 return f;
1783 } 1782 }
1784 1783
1785 1784
1785 function NewFunction(arg1) { // length == 1
Michael Starzinger 2013/05/13 11:35:39 Since we are at it, can we rename this to Function
wingo 2013/05/14 10:11:50 Done. I renamed the nelper to NewFunction, as it
1786 var n = %_ArgumentsLength();
1787 if (n) {
rossberg 2013/05/13 11:33:46 Nit: n > 0 But I'd actually avoid the whole copyi
wingo 2013/05/14 10:11:50 Fixed the nit. We can't copy arguments as-is beca
rossberg 2013/05/14 14:05:46 Yes, but the code not only copies, but also takes
1788 var formals = new InternalArray(n - 1);
1789 for (var i = 0; i < n - 1; i++) formals[i] = %_Arguments(i);
1790 return NewFunctionHelper(formals, ToString(%_Arguments(n - 1)), false);
1791 } else {
1792 return NewFunctionHelper(new InternalArray(0), '', false);
1793 }
1794 }
1795
1796
1786 // ---------------------------------------------------------------------------- 1797 // ----------------------------------------------------------------------------
1787 1798
1788 function SetUpFunction() { 1799 function SetUpFunction() {
1789 %CheckIsBootstrapping(); 1800 %CheckIsBootstrapping();
1790 1801
1791 %SetCode($Function, NewFunction); 1802 %SetCode($Function, NewFunction);
1792 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); 1803 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM);
1793 1804
1794 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1805 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1795 "bind", FunctionBind, 1806 "bind", FunctionBind,
1796 "toString", FunctionToString 1807 "toString", FunctionToString
1797 )); 1808 ));
1798 } 1809 }
1799 1810
1800 SetUpFunction(); 1811 SetUpFunction();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698