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)

x86_64
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: stas, Assigned: stas)

References

Details

Attachments

(1 file, 1 obsolete file)

Third-party code might have extended Object's prototype.
Attached patch Patch (obsolete) — Splinter Review
Assignee: nobody → stas
Status: NEW → ASSIGNED
Attachment #805021 - Flags: review?(gandalf)
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 ?
Blocks: 917195
(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.
Attachment #805021 - Attachment is obsolete: true
Attachment #805021 - Flags: review?(gandalf)
Attached patch Use Object.keysSplinter Review
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)
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.
Attachment #806651 - Flags: review?(gandalf) → review+
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.

Attachment

General

Created:
Updated:
Size: