Skip to content

Commit

Permalink
Fix issue where Function#argumentNames returned incorrect results in …
Browse files Browse the repository at this point in the history
…IE when comments were intermixed with argument names. [#397 state:resolved]
  • Loading branch information
savetheclocktower authored and tobie committed Dec 11, 2008
1 parent c039f68 commit 54bf343
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -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).
Expand Down
3 changes: 2 additions & 1 deletion src/lang/function.js
Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions test/unit/base_test.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 54bf343

Please sign in to comment.