Closed
Bug 788586
Opened 12 years ago
Closed 12 years ago
Inferred names for anonymous JavaScript functions could be more accurate
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla18
People
(Reporter: jimb, Assigned: jimb)
Details
Attachments
(3 files)
2.51 KB,
patch
|
u443197
:
review+
|
Details | Diff | Splinter Review |
2.56 KB,
patch
|
u443197
:
review+
|
Details | Diff | Splinter Review |
3.13 KB,
patch
|
u443197
:
review+
|
Details | Diff | Splinter Review |
SpiderMonkey now infers names for anonymous functions, but in some cases those names are not as good as they could be. - Although JJB's paper suggests it, naming Constructor.prototype.method "Constructor.method" is just not right - especially since people do make 'class methods' by putting functions directly on the constructor. "prototype" should not be dropped. - We don't quite get names right for numeric indices in object initializers: a = { 1: function () {} }; - We generate bogus names when string literal property names in object initializers contain spaces or other things: a = { "embedded spaces": function(){}, "dots.look.like.property.references": function(){}, "\"\'quotes\'\"": function(){}, "!@#$%": function(){} };
Assignee | ||
Comment 1•12 years ago
|
||
Assignee: general → jimb
Status: NEW → ASSIGNED
Assignee | ||
Comment 2•12 years ago
|
||
Assignee | ||
Comment 3•12 years ago
|
||
Assignee | ||
Updated•12 years ago
|
Attachment #658537 -
Flags: review?(alex)
Assignee | ||
Updated•12 years ago
|
Attachment #658538 -
Flags: review?(alex)
Assignee | ||
Updated•12 years ago
|
Attachment #658541 -
Flags: review?(alex)
Attachment #658537 -
Flags: review?(alex) → review+
Comment on attachment 658538 [details] [diff] [review] When inferring display names, handle numeric literals better. Review of attachment 658538 [details] [diff] [review]: ----------------------------------------------------------------- ::: js/src/frontend/NameFunctions.cpp @@ +39,5 @@ > + return buf->appendInflated(number, digits); > + } > + > + /* Append a reference to a property named by a numeric literal to buf. */ > + bool appendNumericPropertyReference(double n) { I'd also be ok with this not being a function because it's only called in one place. It took me a second to figure out what's going on based on the name.
Attachment #658538 -
Flags: review?(alex) → review+
Comment on attachment 658541 [details] [diff] [review] When inferring display names, handle property names that are not valid identifier names. Review of attachment 658541 [details] [diff] [review]: ----------------------------------------------------------------- ::: js/src/frontend/NameFunctions.cpp @@ +47,5 @@ > + return buf->append(".") && buf->append(name); > + > + /* Quote the string as needed. */ > + RootedValue string(cx, StringValue(name)); > + JSString *source = js_ValueToSource(cx, string); Could you just call js_QuoteString directly? ::: js/src/jit-test/tests/basic/functionnames.js @@ +145,5 @@ > + > +a.b = {}; > +a.b.c = {}; > +a.b["c"]["d e"] = { f: { 1: { "g": { "h i": function() {} } } } }; > +assertName(a.b.c["d e"].f[1].g["h i"], 'a.b.c["d e"].f[1].g["h i"]'); I like this! Definitely a good idea for these weird identifiers
Attachment #658541 -
Flags: review?(alex) → review+
(In reply to Alex Crichton [:acrichto] from comment #4) > I'd also be ok with this not being a function because it's only called in > one place. It took me a second to figure out what's going on based on the > name. Disregard this, with the appendPropertyReference function in the next patch, I'm perfectly OK with this.
Assignee | ||
Comment 7•12 years ago
|
||
(In reply to Alex Crichton [:acrichto] from comment #5) > > + /* Quote the string as needed. */ > > + RootedValue string(cx, StringValue(name)); > > + JSString *source = js_ValueToSource(cx, string); > > Could you just call js_QuoteString directly? I was going to do that, but then I thought it would be too simple and direct. (fixed, thanks!)
Assignee | ||
Comment 8•12 years ago
|
||
(In reply to Alex Crichton [:acrichto] from comment #6) > Disregard this, with the appendPropertyReference function in the next patch, > I'm perfectly OK with this. I admit to a bit of retroactive consistency in my patch queue...
Assignee | ||
Comment 9•12 years ago
|
||
Try: https://tbpl.mozilla.org/?tree=Try&rev=6516f988fdee
Assignee | ||
Comment 10•12 years ago
|
||
Looks okay. https://hg.mozilla.org/integration/mozilla-inbound/rev/49ca4e7be55f https://hg.mozilla.org/integration/mozilla-inbound/rev/789680f57083 https://hg.mozilla.org/integration/mozilla-inbound/rev/b064789c1758
Assignee | ||
Updated•12 years ago
|
Flags: in-testsuite+
Target Milestone: --- → mozilla18
Assignee | ||
Comment 11•12 years ago
|
||
For what it's worth, CoffeeScript abbreviates Foo.prototype.bar to Foo::bar.
Comment 12•12 years ago
|
||
I'd just stick with Foo.prototype.bar.
Comment 13•12 years ago
|
||
FYI, b064789c1758 accidentally referred to bug 778586 instead of this one.
Comment 14•12 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/49ca4e7be55f https://hg.mozilla.org/mozilla-central/rev/789680f57083 https://hg.mozilla.org/mozilla-central/rev/b064789c1758
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•