From 206a4c824f42e763bcd07342bf06f424497c8024 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Wed, 7 May 2008 11:53:34 +0200 Subject: [PATCH] Allow Function#argumentNames to handle line breaks between arguments. --- CHANGELOG | 2 ++ src/base.js | 3 ++- test/unit/base_test.js | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6135ed7..d5b5bef 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/src/base.js b/src/base.js index eae7f18..072d204 100644 --- a/src/base.js +++ b/src/base.js @@ -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; }, diff --git a/test/unit/base_test.js b/test/unit/base_test.js index 73e268f..a3c631f 100644 --- a/test/unit/base_test.js +++ b/test/unit/base_test.js @@ -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() {};