-
Notifications
You must be signed in to change notification settings - Fork 45.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hasOwnProperty checks where appropriate #1189
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,7 +128,7 @@ var topEventMapping = { | |
var topListenersIDKey = "_reactListenersID" + String(Math.random()).slice(2); | ||
|
||
function getListeningForDocument(mountAt) { | ||
if (mountAt[topListenersIDKey] == null) { | ||
if (!mountAt.hasOwnProperty(topListenersIDKey)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From @salier - "This is breaking in IE8, where We can probably just revert this part. |
||
mountAt[topListenersIDKey] = reactTopListenersCounter++; | ||
alreadyListeningTo[mountAt[topListenersIDKey]] = {}; | ||
} | ||
|
@@ -253,7 +253,10 @@ var ReactEventEmitter = merge(ReactEventEmitterMixin, { | |
var topLevelTypes = EventConstants.topLevelTypes; | ||
for (var i = 0, l = dependencies.length; i < l; i++) { | ||
var dependency = dependencies[i]; | ||
if (!isListening[dependency]) { | ||
if (!( | ||
isListening.hasOwnProperty(dependency) && | ||
isListening[dependency] | ||
)) { | ||
var topLevelType = topLevelTypes[dependency]; | ||
|
||
if (topLevelType === topLevelTypes.topWheel) { | ||
|
@@ -292,7 +295,7 @@ var ReactEventEmitter = merge(ReactEventEmitterMixin, { | |
// to make sure blur and focus event listeners are only attached once | ||
isListening[topLevelTypes.topBlur] = true; | ||
isListening[topLevelTypes.topFocus] = true; | ||
} else if (topEventMapping[dependency]) { | ||
} else if (topEventMapping.hasOwnProperty(dependency)) { | ||
trapBubbledEvent(topLevelType, topEventMapping[dependency], mountAt); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,19 +149,18 @@ function extractEvents( | |
topLevelTargetID, | ||
nativeEvent) { | ||
var currentEvent = topLevelTypesToAnalyticsEvent[topLevelType]; | ||
if (!currentEvent || !topLevelTarget || !topLevelTarget.attributes) { | ||
if (!currentEvent || !topLevelTarget) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm looking at another comment where this broken something... investigating |
||
return null; | ||
} | ||
|
||
var analyticsIDAttribute = topLevelTarget.attributes[ANALYTICS_ID]; | ||
var analyticsEventsAttribute = topLevelTarget.attributes[ANALYTICS_EVENTS]; | ||
if(!analyticsIDAttribute || !analyticsEventsAttribute) { | ||
var analyticsID = topLevelTarget.getAttribute(ANALYTICS_ID); | ||
var analyticsEventsStr = topLevelTarget.getAttribute(ANALYTICS_EVENTS); | ||
if (!analyticsID || !analyticsEventsStr) { | ||
return null; | ||
} | ||
|
||
var analyticsEventsArr = analyticsEventsAttribute.value.split(","); | ||
var analyticsID = analyticsIDAttribute.value; | ||
if (!analyticsData[analyticsID]) { | ||
var analyticsEventsArr = analyticsEventsStr.split(","); | ||
if (!analyticsData.hasOwnProperty(analyticsID)) { | ||
initAnalyticsDataForID(analyticsID, analyticsEventsArr); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should some of these hasOwnProperty checks inside for-in loops be early continue instead of wrapping in a conditional? Now it is quite easy to still run some code after the conditional but still inside the for in loop, perhaps unintentionally? But I don't know those few places in this diff so well.