From 7dda50a7c9fabf977287c855fd09046da2b886d8 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Sun, 14 Oct 2007 10:54:06 +0000 Subject: [PATCH] Make Function#argumentNames work with named functions. Closes #9826 --- CHANGELOG | 2 ++ src/base.js | 2 +- test/unit/base.html | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 3318851..f7b8493 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make Function#argumentNames work with named functions. Closes #9826. [Samuel Lebeau] + * Add Object.isHash. [Tobie Langel] * Performance improvements to String#times. [Martin Ström] diff --git a/src/base.js b/src/base.js index 1ea0ba7..f73c9f9 100644 --- a/src/base.js +++ b/src/base.js @@ -154,7 +154,7 @@ Object.extend(Object, { Object.extend(Function.prototype, { argumentNames: function() { - var names = this.toString().match(/^[\s\(]*function\s*\((.*?)\)/)[1].split(",").invoke("strip"); + var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip"); return names.length == 1 && !names[0] ? [] : names; }, diff --git a/test/unit/base.html b/test/unit/base.html index 2941793..12a8d80 100644 --- a/test/unit/base.html +++ b/test/unit/base.html @@ -140,6 +140,13 @@ assertEnumEqual(["one"], (function(one) {}).argumentNames()); assertEnumEqual(["one", "two", "three"], (function(one, two, three) {}).argumentNames()); assertEqual("$super", (function($super) {}).argumentNames().first()); + + function named1() {}; + assertEnumEqual([], named1.argumentNames()); + function named2(one) {}; + assertEnumEqual(["one"], named2.argumentNames()); + function named3(one, two, three) {}; + assertEnumEqual(["one", "two", "three"], named3.argumentNames()); }}, testFunctionBind: function() { with(this) {