Permalink
Browse files

Crop function body text + question for Simon

  • Loading branch information...
1 parent 544243e commit 82381d06091bd9529a5e961451994175d16a721d @janodvarko janodvarko committed Mar 20, 2013
Showing with 8 additions and 3 deletions.
  1. +8 −3 extension/content/firebug/chrome/reps.js
@@ -208,18 +208,25 @@ FirebugReps.Warning = domplate(Firebug.Rep,
FirebugReps.Func = domplate(Firebug.Rep,
{
+ className: "function",
+
tag:
OBJECTLINK("$object|summarizeFunction"),
summarizeFunction: function(fn)
{
var fnText = Str.safeToString(fn);
+
+ // xxxHonza: Simon this regexpr doesn't return 'myFunc' for:
+ // "function myFunc(event) { ... }". Any tips?
@simonlindholm

simonlindholm Mar 24, 2013

Member

Sorry for the late response, for some reason my RSS feed for commits stopped working...

It seems to work for me, or, well, it returns "myFunc(event)" which is what that regex does - if you wanted just "myFunc" then use /^function ([^(]+)\(/ (but we seem to want parameters here). Do you have a minimal JS-only test-case?

@janodvarko

janodvarko Mar 25, 2013

Owner

var myfunc = "function onExecuteTest2(event)"+
"{"+
" var bob = {name: "Bob", age: 42, married: false};"+
" var ed = {name: "Ed", age: 12};"+
"}";

/^function ([^(]+([^)]*)) {/.exec(myfunc);

or

var myfunc = "function onExecute(event){}";
/^function ([^(]+([^)]*)) {/.exec(myfunc);

both return null

Honza

@simonlindholm

simonlindholm Mar 25, 2013

Member

Ah, the regex includes '{'. Just remove that, I think (edit: and the space, clearly).

(Note: There are some cases we simply can't handle with regexps, like function f(a=({a:1})) 1 or ((a=((a)=>1))=>1); we'll need actual parsing libraries when it comes to that.)

@janodvarko

janodvarko Mar 25, 2013

Owner

thanks!

(we'll need actual parsing libraries when it comes to that.)

ok, we should remember this.

Honza

var namedFn = /^function ([^(]+\([^)]*\)) \{/.exec(fnText);
var anonFn = /^function \(/.test(fnText);
var displayName = fn.displayName;
- return namedFn ? namedFn[1] : (displayName ? displayName + "()" :
+ var result = namedFn ? namedFn[1] : (displayName ? displayName + "()" :
(anonFn ? "function()" : fnText));
+
+ return Str.cropString(result, 100);
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -240,8 +247,6 @@ FirebugReps.Func = domplate(Firebug.Rep,
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
- className: "function",
-
supportsObject: function(object, type)
{
return type == "function";

0 comments on commit 82381d0

Please sign in to comment.