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...) 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. | 1668 // TODO(wingo): Print source using function* for generators. |
Michael Starzinger
2013/05/03 10:35:08
This TODO is done I think, let's remove it.
| |
1669 if (!IS_FUNCTION(func)) { | 1669 if (!IS_FUNCTION(func)) { |
1670 throw new $TypeError('Function.prototype.toString is not generic'); | 1670 throw new $TypeError('Function.prototype.toString is not generic'); |
1671 } | 1671 } |
1672 | 1672 |
1673 var source = %FunctionGetSourceCode(func); | 1673 var source = %FunctionGetSourceCode(func); |
1674 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { | 1674 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { |
1675 var name = %FunctionGetName(func); | 1675 var name = %FunctionGetName(func); |
1676 if (name) { | 1676 if (name) { |
1677 // Mimic what KJS does. | 1677 // Mimic what KJS does. |
1678 return 'function ' + name + '() { [native code] }'; | 1678 return 'function ' + name + '() { [native code] }'; |
1679 } else { | 1679 } else { |
1680 return 'function () { [native code] }'; | 1680 return 'function () { [native code] }'; |
1681 } | 1681 } |
1682 } | 1682 } |
1683 | 1683 |
1684 var name = %FunctionNameShouldPrintAsAnonymous(func) | 1684 var name = %FunctionNameShouldPrintAsAnonymous(func) |
1685 ? 'anonymous' | 1685 ? 'anonymous' |
1686 : %FunctionGetName(func); | 1686 : %FunctionGetName(func); |
1687 return 'function ' + name + source; | 1687 var head = %FunctionIsGenerator(func) ? 'function* ' : 'function '; |
1688 return head + name + source; | |
1688 } | 1689 } |
1689 | 1690 |
1690 | 1691 |
1691 function FunctionToString() { | 1692 function FunctionToString() { |
1692 return FunctionSourceString(this); | 1693 return FunctionSourceString(this); |
1693 } | 1694 } |
1694 | 1695 |
1695 | 1696 |
1696 // ES5 15.3.4.5 | 1697 // ES5 15.3.4.5 |
1697 function FunctionBind(this_arg) { // Length is 1. | 1698 function FunctionBind(this_arg) { // Length is 1. |
(...skipping 95 matching lines...) Loading... | |
1793 %SetCode($Function, NewFunction); | 1794 %SetCode($Function, NewFunction); |
1794 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); | 1795 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); |
1795 | 1796 |
1796 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1797 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1797 "bind", FunctionBind, | 1798 "bind", FunctionBind, |
1798 "toString", FunctionToString | 1799 "toString", FunctionToString |
1799 )); | 1800 )); |
1800 } | 1801 } |
1801 | 1802 |
1802 SetUpFunction(); | 1803 SetUpFunction(); |
OLD | NEW |