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 1609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 // ---------------------------------------------------------------------------- | 1620 // ---------------------------------------------------------------------------- |
1621 // Function | 1621 // Function |
1622 | 1622 |
1623 $Function.prototype.constructor = $Function; | 1623 $Function.prototype.constructor = $Function; |
1624 | 1624 |
1625 function FunctionSourceString(func) { | 1625 function FunctionSourceString(func) { |
1626 while (%IsJSFunctionProxy(func)) { | 1626 while (%IsJSFunctionProxy(func)) { |
1627 func = %GetCallTrap(func); | 1627 func = %GetCallTrap(func); |
1628 } | 1628 } |
1629 | 1629 |
| 1630 // TODO(wingo): Print source using function* for generators. |
1630 if (!IS_FUNCTION(func)) { | 1631 if (!IS_FUNCTION(func)) { |
1631 throw new $TypeError('Function.prototype.toString is not generic'); | 1632 throw new $TypeError('Function.prototype.toString is not generic'); |
1632 } | 1633 } |
1633 | 1634 |
1634 var source = %FunctionGetSourceCode(func); | 1635 var source = %FunctionGetSourceCode(func); |
1635 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { | 1636 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { |
1636 var name = %FunctionGetName(func); | 1637 var name = %FunctionGetName(func); |
1637 if (name) { | 1638 if (name) { |
1638 // Mimic what KJS does. | 1639 // Mimic what KJS does. |
1639 return 'function ' + name + '() { [native code] }'; | 1640 return 'function ' + name + '() { [native code] }'; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1751 | 1752 |
1752 function SetUpFunction() { | 1753 function SetUpFunction() { |
1753 %CheckIsBootstrapping(); | 1754 %CheckIsBootstrapping(); |
1754 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1755 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1755 "bind", FunctionBind, | 1756 "bind", FunctionBind, |
1756 "toString", FunctionToString | 1757 "toString", FunctionToString |
1757 )); | 1758 )); |
1758 } | 1759 } |
1759 | 1760 |
1760 SetUpFunction(); | 1761 SetUpFunction(); |
OLD | NEW |