OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 // Function | 517 // Function |
518 | 518 |
519 $Function.prototype.constructor = $Function; | 519 $Function.prototype.constructor = $Function; |
520 | 520 |
521 function FunctionSourceString(func) { | 521 function FunctionSourceString(func) { |
522 if (!IS_FUNCTION(func)) { | 522 if (!IS_FUNCTION(func)) { |
523 throw new $TypeError('Function.prototype.toString is not generic'); | 523 throw new $TypeError('Function.prototype.toString is not generic'); |
524 } | 524 } |
525 | 525 |
526 var source = %FunctionGetSourceCode(func); | 526 var source = %FunctionGetSourceCode(func); |
527 if (!IS_STRING(source)) { | 527 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { |
528 var name = %FunctionGetName(func); | 528 var name = %FunctionGetName(func); |
529 if (name) { | 529 if (name) { |
530 // Mimic what KJS does. | 530 // Mimic what KJS does. |
531 return 'function ' + name + '() { [native code] }'; | 531 return 'function ' + name + '() { [native code] }'; |
532 } else { | 532 } else { |
533 return 'function () { [native code] }'; | 533 return 'function () { [native code] }'; |
534 } | 534 } |
535 } | 535 } |
536 | 536 |
537 // Censor occurrences of internal calls. We do that for all | |
538 // functions and don't cache under the assumption that people rarly | |
539 // convert functions to strings. Note that we (apparently) can't | |
540 // use regular expression literals in natives files. | |
541 var regexp = ORIGINAL_REGEXP("%(\\w+\\()", "gm"); | |
542 if (source.match(regexp)) source = source.replace(regexp, "$1"); | |
543 var name = %FunctionGetName(func); | 537 var name = %FunctionGetName(func); |
544 return 'function ' + name + source; | 538 return 'function ' + name + source; |
545 } | 539 } |
546 | 540 |
547 | 541 |
548 function FunctionToString() { | 542 function FunctionToString() { |
549 return FunctionSourceString(this); | 543 return FunctionSourceString(this); |
550 } | 544 } |
551 | 545 |
552 | 546 |
(...skipping 26 matching lines...) Expand all Loading... |
579 | 573 |
580 // ---------------------------------------------------------------------------- | 574 // ---------------------------------------------------------------------------- |
581 | 575 |
582 function SetupFunction() { | 576 function SetupFunction() { |
583 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 577 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
584 "toString", FunctionToString | 578 "toString", FunctionToString |
585 )); | 579 )); |
586 } | 580 } |
587 | 581 |
588 SetupFunction(); | 582 SetupFunction(); |
OLD | NEW |