Allow Function#argumentNames to handle line breaks between arguments.

This commit is contained in:
Tobie Langel 2008-05-07 11:53:34 +02:00
parent 55af63fdd6
commit 206a4c824f
3 changed files with 6 additions and 2 deletions

View File

@ -1,3 +1,5 @@
* Allow Function#argumentNames to handle line breaks between arguments. (Geoff M. Granum, Tobie Langel) [#63 state:resolved]
* For consistency, add additional optional parameter "context" to Number.prototype.times. (Samuel Lebeau)
* Replace all instances of foo.__proto__ by foo['__proto__'] for Caja-compliance. (Tobie Langel)

View File

@ -159,7 +159,8 @@ Object.extend(Object, {
Object.extend(Function.prototype, {
argumentNames: function() {
var names = this.toString().match(/^[\s\(]*function[^(]*\(\s*(.*?)\s*\)/)[1].split(/\s*,\s*/);
var names = this.toString().match(/^[\s\(]*function[^(]*\(([^\)]*)\)/)[1]
.replace(/\s+/g, '').split(',');
return names.length == 1 && !names[0] ? [] : names;
},

View File

@ -3,7 +3,8 @@ new Test.Unit.Runner({
this.assertEnumEqual([], (function() {}).argumentNames());
this.assertEnumEqual(["one"], (function(one) {}).argumentNames());
this.assertEnumEqual(["one", "two", "three"], (function(one, two, three) {}).argumentNames());
this.assertEnumEqual(["one", "two", "three"], (function( one , two , three ) {}).argumentNames());
this.assertEnumEqual(["one", "two", "three"], (function( one , two
, three ) {}).argumentNames());
this.assertEqual("$super", (function($super) {}).argumentNames().first());
function named1() {};