Closed
Bug 365869
Opened 18 years ago
Closed 18 years ago
Add a strict warning for when an object literal has two properties with the same name
Categories
(Core :: JavaScript Engine, enhancement)
Tracking
()
VERIFIED
FIXED
People
(Reporter: jruderman, Assigned: mrbkap)
References
Details
Attachments
(2 files, 2 obsolete files)
3.84 KB,
patch
|
brendan
:
review+
|
Details | Diff | Splinter Review |
1.10 KB,
patch
|
crowderbt
:
review+
|
Details | Diff | Splinter Review |
> uneval({a:4, a:5})
({a:5})
This should give a strict warning, because it usually indicates a bug in the code.
(While investigating bug 341872, Gavin noticed that HelperApps.prototype in helperApps.js has two "RemoveObserver" functions. If that triggered a strict warning, it might have prevented a typo from becoming a bug in Firefox.)
Assignee | ||
Comment 1•18 years ago
|
||
This is one approach to the bug. Note that in the newly created 'else' case, report will always be JSREPORT_ERROR, I'm not sure what the proper control flow there should be, though.
Comment 2•18 years ago
|
||
Comment on attachment 250430 [details] [diff] [review]
One approach (diff -w)
At least call it JSPROP_INITIALIZER or something like that (JSPROP_LITERAL?). Otherwise this seems ok. I didn't understand what you meant about "newly created 'else' clause", though.
/be
Assignee | ||
Comment 3•18 years ago
|
||
From the patch:
report = ((oldAttrs | attrs) & JSPROP_READONLY)
? JSREPORT_ERROR
: JSREPORT_WARNING | JSREPORT_STRICT;
if (report != JSREPORT_ERROR) {
[comment elided]
if (!(attrs & (JSPROP_GETTER | JSPROP_SETTER)))
return JS_TRUE;
if ((~(oldAttrs ^ attrs) & (JSPROP_GETTER | JSPROP_SETTER)) == 0)
return JS_TRUE;
if (!(oldAttrs & JSPROP_PERMANENT))
return JS_TRUE;
report = JSREPORT_ERROR;
}
This is the code that's there now; in the patch it's in an else clause. Note that report == JSREPORT_ERROR no matter what if we end up actually reporting the error. I'm not sure if this is desired, but, as written, it's slightly misleading.
I'll rename the pseudo-attribute JSPROP_INITIALIZER.
Comment 4•18 years ago
|
||
I'm confused -- why is report always JSREPORT_ERROR in the code you put in the new outer else clause? It could be JSREPORT_WARNING | JSREPORT_STRICT if neither of oldAttrs and attrs contains JSPROP_READONLY.
/be
Assignee | ||
Comment 5•18 years ago
|
||
Because the if statement right after the assignment is basically:
if (report != JSREPORT_ERROR)
report = JSREPORT_ERROR;
Comment 6•18 years ago
|
||
You are ignoring early returns....
/be
Assignee | ||
Comment 7•18 years ago
|
||
Right - if any of those conditions are met, we won't report an error. Otherwise, we'll set report = JSREPORT_ERROR, so what's the point of the JSREPORT_WARNING | JSREPORT_STRICT?
Comment 8•18 years ago
|
||
(In reply to comment #7)
> Right - if any of those conditions are met, we won't report an error.
> Otherwise, we'll set report = JSREPORT_ERROR, so what's the point of the
> JSREPORT_WARNING | JSREPORT_STRICT?
Not sure -- seemed like there was a need for it at one point. You could eliminate the ?: that synthesizes it, yeah. Hmm.
A little cvs annotate/log/diff work shows this code went in for bug 40760, and it was just obfuscated from the start. Please fix!
/be
Assignee | ||
Comment 9•18 years ago
|
||
I simply removed report = JSREPORT_ERROR... I'm not sure if that preserves the original intent, though.
Attachment #250430 -
Attachment is obsolete: true
Attachment #250851 -
Flags: review?(brendan)
Attachment #250430 -
Flags: review?(brendan)
Comment 10•18 years ago
|
||
Comment on attachment 250851 [details] [diff] [review]
Updated patch (diff -w)
How about just eliminating report and inlining the inverse of its initializer's ? condition -- !((oldAttrs | attrs) & JSPROP_READONLY) -- in the if condition?
/be
Assignee | ||
Comment 11•18 years ago
|
||
Attachment #250851 -
Attachment is obsolete: true
Attachment #253064 -
Flags: review?(brendan)
Attachment #250851 -
Flags: review?(brendan)
Comment 12•18 years ago
|
||
Comment on attachment 253064 [details] [diff] [review]
With that (-w)
Sorry, forgot about this. I think it's right from the -w; I'll read the plain diff on checkin.
/be
Attachment #253064 -
Flags: review?(brendan) → review+
Assignee | ||
Comment 13•18 years ago
|
||
I just checked the latest patch in, but have a followup patch that I'll attach in a second.
Assignee | ||
Comment 14•18 years ago
|
||
Before this patch you'd get:
js> ({__proto__:null})
typein:1: strict warning: redeclaration of property __proto__
which isn't really useful, IMO.
Attachment #255861 -
Flags: review?(brendan)
Comment 15•18 years ago
|
||
mrbkap: re comment 14, this is actually a not-very-nice regression for Foo.prototype.toString() definitions; we hit the same warning.
Is this testable via xpcshell? I hear javascript.options.werror = true means strict warnings become catchable errors.
Assignee | ||
Comment 16•18 years ago
|
||
Comment on attachment 255861 [details] [diff] [review]
Allow for overriding properties
Brendan: ping?
Comment 17•18 years ago
|
||
Comment on attachment 255861 [details] [diff] [review]
Allow for overriding properties
mrbkap asked me to snatch this review.
Attachment #255861 -
Flags: review?(brendan) → review+
Assignee | ||
Comment 18•18 years ago
|
||
Fixed for real now.
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Comment 19•18 years ago
|
||
/cvsroot/mozilla/js/tests/js1_5/extensions/regress-365869.js,v <-- regress-365869.js
initial revision: 1.1
Flags: in-testsuite+
You need to log in
before you can comment on or make changes to this bug.
Description
•