KEMBAR78
ixBidAdapter: avoid looping over all properties of the array by robin-crazygames · Pull Request #13703 · prebid/Prebid.js · GitHub
Skip to content

Conversation

@robin-crazygames
Copy link
Contributor

Type of change

  • Bugfix

  • Feature

  • New bidder adapter

  • Updated bidder adapter

  • Code style update (formatting, local variables)

  • Refactoring (no functional changes, no api changes)

  • Build related changes

  • CI related changes

  • Does this change affect user-facing APIs or examples documented on http://prebid.org?

  • Other

Description of change

Switched from a for...in loop to an indexed for loop in the ixBidAdapter to loop over the values in an array.

We got warnings like

IX Bid Adapter: ad unit mediaTypes average is not supported

The root cause is another JS library which is messing around with the Array prototype, and adds additional functions on it. The for...in loop picks those up, and starts logging warnings.

As there is no real reason to use a for...in loop to iterate over an array, I switched it to a regular indexed for loop which avoids the problem.

Other information

Switch to an indexed for loop instead of a for...in loop to loop over
the values contained in the array.
Otherwise other properties of the array might be picked up, for example
when somebody has adjusted the array prototype to for example add an
average function on it.
@patmmccann
Copy link
Collaborator

The root cause is another JS library which is messing around with the Array prototype, and adds additional functions on it.

Which one?

@robin-crazygames
Copy link
Contributor Author

Nothing prebid related.
We have a games website on which we show ads, and one of the games is messing with the Array prototype.

@patmmccann
Copy link
Collaborator

one of the games is messing with the Array prototype.

it is very surprising ix is the only problem you are experiencing

@lcorrigall
Copy link

lcorrigall commented Jul 31, 2025

We log a warning when we don't find a matching creative type, but there are likely many other places that iterate over arrays this way that don't log when there's a problem across the bidders.

@robin-crazygames
Copy link
Contributor Author

robin-crazygames commented Jul 31, 2025

it is very surprising ix is the only problem you are experiencing

Well, it isn't really a problem as all that happens is that a warning gets logged.

But each time I see that warning, I have to remember what is causing it and that it isn't a real issue.

there are likely many other places that iterate over arrays this way

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#arrays suggests that is not the way to iterate over an array, and an indexed for loop or the for...of is preferred. Mainly to avoid this exact problem.

Copy link
Collaborator

@lksharma lksharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@patmmccann patmmccann merged commit 254b5e3 into prebid:master Aug 1, 2025
18 checks passed
@robin-crazygames robin-crazygames deleted the ix_bid_adapter_for_loop branch August 4, 2025 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants