Closed
Bug 912469
Opened 12 years ago
Closed 12 years ago
Always check hasOwnProperty when iterating over an object's key
Categories
(L20n :: JS Library, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: stas, Assigned: stas)
References
Details
Attachments
(1 file, 1 obsolete file)
7.95 KB,
patch
|
zbraniecki
:
review+
|
Details | Diff | Splinter Review |
Third-party code might have extended Object's prototype.
Assignee | ||
Comment 1•12 years ago
|
||
Comment 2•12 years ago
|
||
Comment on attachment 805021 [details] [diff] [review]
Patch
Review of attachment 805021 [details] [diff] [review]:
-----------------------------------------------------------------
::: bindings/l20n/html.js
@@ +206,3 @@
> return;
> }
> for (var key in entity.attributes) {
maybe just getOwnPropertyNames?
::: lib/l20n/context.js
@@ +254,4 @@
>
> function extend(dst, src) {
> for (var i in src) {
> + if (!src.hasOwnProperty(i)) {
maybe just use getOwnPropertyNames ?
Comment 3•12 years ago
|
||
(In reply to Zbigniew Braniecki [:gandalf] from comment #2)
> ::: bindings/l20n/html.js
> @@ +206,3 @@
> > return;
> > }
> > for (var key in entity.attributes) {
>
> maybe just getOwnPropertyNames?
getOwnPropertyNames will enumerate non-enumerable properties. Object.keys() would be appropriate here.
Assignee | ||
Updated•12 years ago
|
Attachment #805021 -
Attachment is obsolete: true
Attachment #805021 -
Flags: review?(gandalf)
Assignee | ||
Comment 4•12 years ago
|
||
I followed Masatoshi's advice and used Object.keys were possible.
I also moved the test into context/ctxdata.js because it wasn't really relevant
in retranslation.js. I still kept the relevant tests that I wrote in
retranslation.js
Attachment #806651 -
Flags: review?(gandalf)
Assignee | ||
Comment 5•12 years ago
|
||
Comment on attachment 806651 [details] [diff] [review]
Use Object.keys
>+ it('when absent, all testing entities don\'t work', function() {
>+ it('when absent, all testing entities don\'t work', function() {
>+ it('when absent, all testing entities don\'t work', function() {
Oops, too much copy&paste :) I'll fix this when I land.
Updated•12 years ago
|
Attachment #806651 -
Flags: review?(gandalf) → review+
Assignee | ||
Comment 6•12 years ago
|
||
https://github.com/l20n/l20n.js/commit/e88b21aa1bf5ae196f406beca6416f08616bc8a0
In one place (Context::getMany), I used hasOwnProperty instead of Object.keys to avoid creating functions inside of a loop.
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
•