Fix issue where Function#argumentNames returned incorrect results in IE when comments were intermixed with argument names. [#397 state:resolved]

This commit is contained in:
Andrew Dupont 2008-10-26 15:33:10 -05:00 committed by Tobie Langel
parent c039f68fb7
commit 54bf343560
3 changed files with 14 additions and 1 deletions

View File

@ -1,3 +1,5 @@
* Fix issue where Function#argumentNames returned incorrect results in IE when comments were intermixed with argument names. (Christophe Porteneuve, T.J. Crowder)
* Selector.patterns should be represented as an ordered structure. (ADO, kangax)
* Performance improvements in Function methods (Samuel Lebeau, kangax, jddalton, Tobie Langel).

View File

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

View File

@ -13,6 +13,16 @@ new Test.Unit.Runner({
this.assertEnumEqual(["one"], named2.argumentNames());
function named3(one, two, three) {};
this.assertEnumEqual(["one", "two", "three"], named3.argumentNames());
function named4(/*foo*/ foo, /* bar */ bar, /*****/ baz) {}
this.assertEnumEqual($w("foo bar baz"), named4.argumentNames());
function named5(
/*foo*/ foo,
/**/bar,
/* baz */ /* baz */ baz,
// Skip a line just to screw with the regex...
/* thud */ thud) {}
this.assertEnumEqual($w("foo bar baz thud"), named5.argumentNames());
},
testFunctionBind: function() {