OLD | NEW |
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 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1759 function NewFunction(arg1) { // length == 1 | 1759 function NewFunction(arg1) { // length == 1 |
1760 var n = %_ArgumentsLength(); | 1760 var n = %_ArgumentsLength(); |
1761 var p = ''; | 1761 var p = ''; |
1762 if (n > 1) { | 1762 if (n > 1) { |
1763 p = new InternalArray(n - 1); | 1763 p = new InternalArray(n - 1); |
1764 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); | 1764 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); |
1765 p = Join(p, n - 1, ',', NonStringToString); | 1765 p = Join(p, n - 1, ',', NonStringToString); |
1766 // If the formal parameters string include ) - an illegal | 1766 // If the formal parameters string include ) - an illegal |
1767 // character - it may make the combined function expression | 1767 // character - it may make the combined function expression |
1768 // compile. We avoid this problem by checking for this early on. | 1768 // compile. We avoid this problem by checking for this early on. |
1769 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); | 1769 if (p.indexOf(')') != -1) throw MakeSyntaxError('paren_in_arg_string',[]); |
1770 // If the formal parameters include an unbalanced block comment, the | 1770 // If the formal parameters include an unbalanced block comment, the |
1771 // function must be rejected. Since JavaScript does not allow nested | 1771 // function must be rejected. Since JavaScript does not allow nested |
1772 // comments we can include a trailing block comment to catch this. | 1772 // comments we can include a trailing block comment to catch this. |
1773 p += '\n/' + '**/'; | 1773 p += '\n/' + '**/'; |
1774 } | 1774 } |
1775 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; | 1775 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; |
1776 var source = '(function(' + p + ') {\n' + body + '\n})'; | 1776 var source = '(function(' + p + ') {\n' + body + '\n})'; |
1777 | 1777 |
1778 // The call to SetNewFunctionAttributes will ensure the prototype | 1778 // The call to SetNewFunctionAttributes will ensure the prototype |
1779 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). | 1779 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). |
(...skipping 13 matching lines...) Expand all Loading... |
1793 %SetCode($Function, NewFunction); | 1793 %SetCode($Function, NewFunction); |
1794 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); | 1794 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); |
1795 | 1795 |
1796 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1796 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1797 "bind", FunctionBind, | 1797 "bind", FunctionBind, |
1798 "toString", FunctionToString | 1798 "toString", FunctionToString |
1799 )); | 1799 )); |
1800 } | 1800 } |
1801 | 1801 |
1802 SetUpFunction(); | 1802 SetUpFunction(); |
OLD | NEW |