| 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 1739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1750 // which are non-configurable. It therefore makes no sence to | 1750 // which are non-configurable. It therefore makes no sence to |
| 1751 // try to redefine these as defined by the spec. The spec says | 1751 // try to redefine these as defined by the spec. The spec says |
| 1752 // that bind should make these throw a TypeError if get or set | 1752 // that bind should make these throw a TypeError if get or set |
| 1753 // is called and make them non-enumerable and non-configurable. | 1753 // is called and make them non-enumerable and non-configurable. |
| 1754 // To be consistent with our normal functions we leave this as it is. | 1754 // To be consistent with our normal functions we leave this as it is. |
| 1755 // TODO(lrn): Do set these to be thrower. | 1755 // TODO(lrn): Do set these to be thrower. |
| 1756 return result; | 1756 return result; |
| 1757 } | 1757 } |
| 1758 | 1758 |
| 1759 | 1759 |
| 1760 function NewFunction(arg1) { // length == 1 | 1760 function NewFunctionString(arguments, function_token) { |
| 1761 var n = %_ArgumentsLength(); | 1761 var n = arguments.length; |
| 1762 var p = ''; | 1762 var p = ''; |
| 1763 if (n > 1) { | 1763 if (n > 1) { |
| 1764 p = new InternalArray(n - 1); | 1764 p = ToString(arguments[0]); |
| 1765 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); | 1765 for (var i = 1; i < n - 1; i++) { |
| 1766 p = Join(p, n - 1, ',', NonStringToString); | 1766 p += ',' + ToString(arguments[i]); |
| 1767 } |
| 1767 // If the formal parameters string include ) - an illegal | 1768 // If the formal parameters string include ) - an illegal |
| 1768 // character - it may make the combined function expression | 1769 // character - it may make the combined function expression |
| 1769 // compile. We avoid this problem by checking for this early on. | 1770 // compile. We avoid this problem by checking for this early on. |
| 1770 if (%_CallFunction(p, ')', StringIndexOf) != -1) { | 1771 if (%_CallFunction(p, ')', StringIndexOf) != -1) { |
| 1771 throw MakeSyntaxError('paren_in_arg_string',[]); | 1772 throw MakeSyntaxError('paren_in_arg_string', []); |
| 1772 } | 1773 } |
| 1773 // If the formal parameters include an unbalanced block comment, the | 1774 // If the formal parameters include an unbalanced block comment, the |
| 1774 // function must be rejected. Since JavaScript does not allow nested | 1775 // function must be rejected. Since JavaScript does not allow nested |
| 1775 // comments we can include a trailing block comment to catch this. | 1776 // comments we can include a trailing block comment to catch this. |
| 1776 p += '\n/' + '**/'; | 1777 p += '\n/' + '**/'; |
| 1777 } | 1778 } |
| 1778 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; | 1779 var body = (n > 0) ? ToString(arguments[n - 1]) : ''; |
| 1779 var source = '(function(' + p + ') {\n' + body + '\n})'; | 1780 return '(' + function_token + '(' + p + ') {\n' + body + '\n})'; |
| 1781 } |
| 1780 | 1782 |
| 1783 |
| 1784 function FunctionConstructor(arg1) { // length == 1 |
| 1785 var source = NewFunctionString(arguments, 'function'); |
| 1781 var global_receiver = %GlobalReceiver(global); | 1786 var global_receiver = %GlobalReceiver(global); |
| 1787 // Compile the string in the constructor and not a helper so that errors |
| 1788 // appear to come from here. |
| 1782 var f = %_CallFunction(global_receiver, %CompileString(source, true)); | 1789 var f = %_CallFunction(global_receiver, %CompileString(source, true)); |
| 1783 | |
| 1784 %FunctionMarkNameShouldPrintAsAnonymous(f); | 1790 %FunctionMarkNameShouldPrintAsAnonymous(f); |
| 1785 return f; | 1791 return f; |
| 1786 } | 1792 } |
| 1787 | 1793 |
| 1788 | 1794 |
| 1789 // ---------------------------------------------------------------------------- | 1795 // ---------------------------------------------------------------------------- |
| 1790 | 1796 |
| 1791 function SetUpFunction() { | 1797 function SetUpFunction() { |
| 1792 %CheckIsBootstrapping(); | 1798 %CheckIsBootstrapping(); |
| 1793 | 1799 |
| 1794 %SetCode($Function, NewFunction); | 1800 %SetCode($Function, FunctionConstructor); |
| 1795 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); | 1801 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); |
| 1796 | 1802 |
| 1797 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1803 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1798 "bind", FunctionBind, | 1804 "bind", FunctionBind, |
| 1799 "toString", FunctionToString | 1805 "toString", FunctionToString |
| 1800 )); | 1806 )); |
| 1801 } | 1807 } |
| 1802 | 1808 |
| 1803 SetUpFunction(); | 1809 SetUpFunction(); |
| OLD | NEW |