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 1647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 | 1658 |
1659 | 1659 |
1660 // ---------------------------------------------------------------------------- | 1660 // ---------------------------------------------------------------------------- |
1661 // Function | 1661 // Function |
1662 | 1662 |
1663 function FunctionSourceString(func) { | 1663 function FunctionSourceString(func) { |
1664 while (%IsJSFunctionProxy(func)) { | 1664 while (%IsJSFunctionProxy(func)) { |
1665 func = %GetCallTrap(func); | 1665 func = %GetCallTrap(func); |
1666 } | 1666 } |
1667 | 1667 |
1668 // TODO(wingo): Print source using function* for generators. | |
1669 if (!IS_FUNCTION(func)) { | 1668 if (!IS_FUNCTION(func)) { |
1670 throw new $TypeError('Function.prototype.toString is not generic'); | 1669 throw new $TypeError('Function.prototype.toString is not generic'); |
1671 } | 1670 } |
1672 | 1671 |
1673 var source = %FunctionGetSourceCode(func); | 1672 var source = %FunctionGetSourceCode(func); |
1674 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { | 1673 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { |
1675 var name = %FunctionGetName(func); | 1674 var name = %FunctionGetName(func); |
1676 if (name) { | 1675 if (name) { |
1677 // Mimic what KJS does. | 1676 // Mimic what KJS does. |
1678 return 'function ' + name + '() { [native code] }'; | 1677 return 'function ' + name + '() { [native code] }'; |
1679 } else { | 1678 } else { |
1680 return 'function () { [native code] }'; | 1679 return 'function () { [native code] }'; |
1681 } | 1680 } |
1682 } | 1681 } |
1683 | 1682 |
1684 var name = %FunctionNameShouldPrintAsAnonymous(func) | 1683 var name = %FunctionNameShouldPrintAsAnonymous(func) |
1685 ? 'anonymous' | 1684 ? 'anonymous' |
1686 : %FunctionGetName(func); | 1685 : %FunctionGetName(func); |
1687 return 'function ' + name + source; | 1686 var head = %FunctionIsGenerator(func) ? 'function* ' : 'function '; |
| 1687 return head + name + source; |
1688 } | 1688 } |
1689 | 1689 |
1690 | 1690 |
1691 function FunctionToString() { | 1691 function FunctionToString() { |
1692 return FunctionSourceString(this); | 1692 return FunctionSourceString(this); |
1693 } | 1693 } |
1694 | 1694 |
1695 | 1695 |
1696 // ES5 15.3.4.5 | 1696 // ES5 15.3.4.5 |
1697 function FunctionBind(this_arg) { // Length is 1. | 1697 function FunctionBind(this_arg) { // Length is 1. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |