From 54bf3435609f649a40084ccbaa0695012a0b38e1 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Sun, 26 Oct 2008 15:33:10 -0500 Subject: [PATCH] Fix issue where Function#argumentNames returned incorrect results in IE when comments were intermixed with argument names. [#397 state:resolved] --- CHANGELOG | 2 ++ src/lang/function.js | 3 ++- test/unit/base_test.js | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 53807a0..adb377e 100644 --- a/CHANGELOG +++ b/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). diff --git a/src/lang/function.js b/src/lang/function.js index df2f737..e73a01e 100644 --- a/src/lang/function.js +++ b/src/lang/function.js @@ -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; } diff --git a/test/unit/base_test.js b/test/unit/base_test.js index 25e163a..c995793 100644 --- a/test/unit/base_test.js +++ b/test/unit/base_test.js @@ -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() {