Ensure use of .hasOwnProperty() check when using for/in loops

This is a fix for #1269