Skip to content

Commit

Permalink
remove polyfill.js and remove global polyfills (#1918)
Browse files Browse the repository at this point in the history
* remove polyfill.js and remove global polyfills

* make sure find, findIndex, and includes use core-js in tests

* switch from virtual function bind core-js to explicit usage.

* remove transform-function-bind babel plugin
  • Loading branch information
snapwich authored and jaiminpanchal27 committed Dec 6, 2017
1 parent 87bfe40 commit de5ed4d
Show file tree
Hide file tree
Showing 27 changed files with 112 additions and 90 deletions.
6 changes: 5 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"presets": ["es2015"],
"plugins": ["transform-object-assign", "transform-es3-property-literals", "transform-es3-member-expression-literals"]
"plugins": [
"transform-object-assign",
"transform-es3-property-literals",
"transform-es3-member-expression-literals"
]
}
3 changes: 2 additions & 1 deletion modules/adkernelAdnBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
import { BANNER, VIDEO } from 'src/mediaTypes';
import includes from 'core-js/library/fn/array/includes';

const DEFAULT_ADKERNEL_DSP_DOMAIN = 'tag.adkernel.com';
const VIDEO_TARGETING = ['mimes', 'protocols', 'api'];
Expand Down Expand Up @@ -28,7 +29,7 @@ function buildImp(bidRequest) {
};
if (bidRequest.params.video) {
Object.keys(bidRequest.params.video)
.filter(param => VIDEO_TARGETING.includes(param))
.filter(param => includes(VIDEO_TARGETING, param))
.forEach(param => imp.video[param] = bidRequest.params.video[param]);
}
} else {
Expand Down
6 changes: 4 additions & 2 deletions modules/adkernelBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as utils from 'src/utils';
import { BANNER, VIDEO } from 'src/mediaTypes';
import {registerBidder} from 'src/adapters/bidderFactory';
import find from 'core-js/library/fn/array/find';
import includes from 'core-js/library/fn/array/includes';

const VIDEO_TARGETING = ['mimes', 'minduration', 'maxduration', 'protocols',
'startdelay', 'linearity', 'boxingallowed', 'playbackmethod', 'delivery',
Expand Down Expand Up @@ -63,7 +65,7 @@ export const spec = {
.reduce((a, b) => a.concat(b), []);

return rtbBids.map(rtbBid => {
let imp = rtbImps.find(imp => imp.id === rtbBid.impid);
let imp = find(rtbImps, imp => imp.id === rtbBid.impid);
let prBid = {
requestId: rtbBid.impid,
cpm: rtbBid.price,
Expand Down Expand Up @@ -119,7 +121,7 @@ function buildImp(bid) {
imp.video = {w: size[0], h: size[1]};
if (bid.params.video) {
Object.keys(bid.params.video)
.filter(param => VIDEO_TARGETING.includes(param))
.filter(param => includes(VIDEO_TARGETING, param))
.forEach(param => imp.video[param] = bid.params.video[param]);
}
} else {
Expand Down
7 changes: 4 additions & 3 deletions modules/adomikAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import adapter from 'src/AnalyticsAdapter';
import CONSTANTS from 'src/constants.json';
import adaptermanager from 'src/adaptermanager';
// import utils from 'src/utils';
import find from 'core-js/library/fn/array/find';
import findIndex from 'core-js/library/fn/array/find-index';

// Events used in adomik analytics adapter
const auctionInit = CONSTANTS.EVENTS.AUCTION_INIT;
Expand Down Expand Up @@ -139,7 +140,7 @@ adomikAdapter.buildBidResponse = function (bid) {

adomikAdapter.sizeUtils = {
sizeAlreadyExists: (sizes, typedEventSize) => {
return sizes.find((size) => size.height === typedEventSize.height && size.width === typedEventSize.width);
return find(sizes, (size) => size.height === typedEventSize.height && size.width === typedEventSize.width);
},
formatSize: (typedEventSize) => {
return {
Expand All @@ -160,7 +161,7 @@ adomikAdapter.buildTypedEvents = function () {
const groupedTypedEvents = [];
adomikAdapter.bucketEvents.forEach(function(typedEvent, i) {
const [placementCode, type] = [typedEvent.event.placementCode, typedEvent.type];
let existTypedEvent = groupedTypedEvents.findIndex((groupedTypedEvent) => groupedTypedEvent.placementCode === placementCode);
let existTypedEvent = findIndex(groupedTypedEvents, (groupedTypedEvent) => groupedTypedEvent.placementCode === placementCode);

if (existTypedEvent === -1) {
groupedTypedEvents.push({
Expand Down
8 changes: 7 additions & 1 deletion modules/aolBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ let showCpmAdjustmentWarning = (function () {
};
})();

function isInteger(value) {
return typeof value === 'number' &&
isFinite(value) &&
Math.floor(value) === value;
}

function template(strings, ...keys) {
return function(...values) {
let dict = values[values.length - 1] || {};
let result = [strings[0]];
keys.forEach(function(key, i) {
let value = Number.isInteger(key) ? values[key] : dict[key];
let value = isInteger(key) ? values[key] : dict[key];
result.push(value, strings[i + 1]);
});
return result.join('');
Expand Down
16 changes: 9 additions & 7 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Renderer } from 'src/Renderer';
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { NATIVE, VIDEO } from 'src/mediaTypes';
import find from 'core-js/library/fn/array/find';
import includes from 'core-js/library/fn/array/includes';

const BIDDER_CODE = 'appnexus';
const URL = '//ib.adnxs.com/ut/v3/prebid';
Expand Down Expand Up @@ -49,16 +51,16 @@ export const spec = {
*/
buildRequests: function(bidRequests, bidderRequest) {
const tags = bidRequests.map(bidToTag);
const userObjBid = bidRequests.find(hasUserInfo);
const userObjBid = find(bidRequests, hasUserInfo);
let userObj;
if (userObjBid) {
userObj = {};
Object.keys(userObjBid.params.user)
.filter(param => USER_PARAMS.includes(param))
.filter(param => includes(USER_PARAMS, param))
.forEach(param => userObj[param] = userObjBid.params.user[param]);
}

const memberIdBid = bidRequests.find(hasMemberId);
const memberIdBid = find(bidRequests, hasMemberId);
const member = memberIdBid ? parseInt(memberIdBid.params.member, 10) : 0;

const payload = {
Expand Down Expand Up @@ -101,7 +103,7 @@ export const spec = {
serverResponse.tags.forEach(serverBid => {
const rtbBid = getRtbBid(serverBid);
if (rtbBid) {
if (rtbBid.cpm !== 0 && SUPPORTED_AD_TYPES.includes(rtbBid.ad_type)) {
if (rtbBid.cpm !== 0 && includes(SUPPORTED_AD_TYPES, rtbBid.ad_type)) {
const bid = newBid(serverBid, rtbBid);
bid.mediaType = parseMediaType(rtbBid);
bids.push(bid);
Expand Down Expand Up @@ -300,7 +302,7 @@ function bidToTag(bid) {
tag.video = {};
// place any valid video params on the tag
Object.keys(bid.params.video)
.filter(param => VIDEO_TARGETING.includes(param))
.filter(param => includes(VIDEO_TARGETING, param))
.forEach(param => tag.video[param] = bid.params.video[param]);
}

Expand Down Expand Up @@ -339,7 +341,7 @@ function hasMemberId(bid) {
}

function getRtbBid(tag) {
return tag && tag.ads && tag.ads.length && tag.ads.find(ad => ad.rtb);
return tag && tag.ads && tag.ads.length && find(tag.ads, ad => ad.rtb);
}

function buildNativeRequest(params) {
Expand Down Expand Up @@ -368,7 +370,7 @@ function buildNativeRequest(params) {
// subtract required keys from adunit keys
const adunitKeys = Object.keys(params[key]);
const requiredKeys = Object.keys(requiredParams);
const remaining = adunitKeys.filter(key => !requiredKeys.includes(key));
const remaining = adunitKeys.filter(key => !includes(requiredKeys, key));

// if none are left over, the minimum params needs to be sent
if (remaining.length === 0) {
Expand Down
6 changes: 4 additions & 2 deletions modules/audienceNetworkBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { registerBidder } from 'src/adapters/bidderFactory';
import { config } from 'src/config';
import { formatQS } from 'src/url';
import { getTopWindowUrl } from 'src/utils';
import findIndex from 'core-js/library/fn/array/find-index';
import includes from 'core-js/library/fn/array/includes';

const code = 'audienceNetwork';
const currency = 'USD';
Expand Down Expand Up @@ -47,7 +49,7 @@ const expandSize = size => size.split('x').map(Number);
* @param {String} size
* @returns {Boolean}
*/
const isValidSize = size => ['300x250', '320x50'].includes(size);
const isValidSize = size => includes(['300x250', '320x50'], size);

/**
* Is this a video format?
Expand Down Expand Up @@ -139,7 +141,7 @@ const buildRequests = bids => {
pageurl,
sdk
};
const video = adformats.findIndex(isVideo);
const video = findIndex(adformats, isVideo);
if (video !== -1) {
[search.playerwidth, search.playerheight] = sizes[video].split('x').map(Number)
}
Expand Down
5 changes: 3 additions & 2 deletions modules/bridgewellBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
import find from 'core-js/library/fn/array/find';

const BIDDER_CODE = 'bridgewell';
const REQUEST_ENDPOINT = '//rec.scupio.com/recweb/prebid.aspx';
Expand Down Expand Up @@ -58,8 +59,8 @@ export const spec = {
return;
}

let matchedResponse = serverResponse.body.find(function(res) {
return !!res && !res.consumed && req.sizes.find(function(size) {
let matchedResponse = find(serverResponse.body, function(res) {
return !!res && !res.consumed && find(req.sizes, function(size) {
return res.width === size[0] && res.height === size[1];
});
});
Expand Down
5 changes: 3 additions & 2 deletions modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import adaptermanager from 'src/adaptermanager';
import { config } from 'src/config';
import { VIDEO } from 'src/mediaTypes';
import { isValid } from 'src/adapters/bidderFactory';
import includes from 'core-js/library/fn/array/includes';

const getConfig = config.getConfig;

Expand Down Expand Up @@ -43,7 +44,7 @@ function setS2sConfig(options) {
let keys = Object.keys(options);

if (['accountId', 'bidders', 'endpoint'].filter(key => {
if (!keys.includes(key)) {
if (!includes(keys, key)) {
utils.logError(key + ' missing in server to server config');
return true;
}
Expand Down Expand Up @@ -319,7 +320,7 @@ export function PrebidServer() {
utils.logError(error);
}

if (!result || (result.status && result.status.includes('Error'))) {
if (!result || (result.status && includes(result.status, 'Error'))) {
utils.logError('error parsing response: ', result.status);
}

Expand Down
7 changes: 4 additions & 3 deletions modules/roxotAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import adapter from 'src/AnalyticsAdapter';
import CONSTANTS from 'src/constants.json';
import adaptermanager from 'src/adaptermanager';
import includes from 'core-js/library/fn/array/includes';

const utils = require('src/utils');

Expand Down Expand Up @@ -106,7 +107,7 @@ function checkAdUnitConfig() {
function buildBidWon(eventType, args) {
bidWon.options = initOptions;
if (checkAdUnitConfig()) {
if (initOptions.adUnits.includes(args.adUnitCode)) {
if (includes(initOptions.adUnits, args.adUnitCode)) {
bidWon.events = [{ args: args, eventType: eventType }];
}
} else {
Expand All @@ -121,7 +122,7 @@ function buildEventStack() {
function filterBidsByAdUnit(bids) {
var filteredBids = [];
bids.forEach(function (bid) {
if (initOptions.adUnits.includes(bid.placementCode)) {
if (includes(initOptions.adUnits, bid.placementCode)) {
filteredBids.push(bid);
}
});
Expand All @@ -131,7 +132,7 @@ function filterBidsByAdUnit(bids) {
function isValidEvent(eventType, adUnitCode) {
if (checkAdUnitConfig()) {
let validationEvents = [bidAdjustmentConst, bidResponseConst, bidWonConst];
if (!initOptions.adUnits.includes(adUnitCode) && validationEvents.includes(eventType)) {
if (!includes(initOptions.adUnits, adUnitCode) && includes(validationEvents, eventType)) {
return false;
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { processNativeAdUnitParams, nativeAdapters } from './native';
import { newBidder } from './adapters/bidderFactory';
import { ajaxBuilder } from 'src/ajax';
import { config, RANDOM } from 'src/config';
import includes from 'core-js/library/fn/array/includes';

var utils = require('./utils.js');
var CONSTANTS = require('./constants.json');
Expand Down Expand Up @@ -115,7 +116,7 @@ function getAdUnitCopyForPrebidServer(adUnits) {

// filter out client side bids
adUnit.bids = adUnit.bids.filter((bid) => {
return adaptersServerSide.includes(bid.bidder) && (!doingS2STesting() || bid.finalSource !== s2sTestingModule.CLIENT);
return includes(adaptersServerSide, bid.bidder) && (!doingS2STesting() || bid.finalSource !== s2sTestingModule.CLIENT);
}).map((bid) => {
bid.bid_id = utils.getUniqueIdentifierStr();
return bid;
Expand Down Expand Up @@ -167,7 +168,7 @@ exports.makeBidRequests = function(adUnits, auctionStart, auctionId, cbTimeout,

// don't call these client side (unless client request is needed for testing)
clientBidderCodes = bidderCodes.filter((elm) => {
return !adaptersServerSide.includes(elm) || clientTestAdapters.includes(elm);
return !includes(adaptersServerSide, elm) || includes(clientTestAdapters, elm);
});

let adUnitsS2SCopy = getAdUnitCopyForPrebidServer(adUnits);
Expand Down Expand Up @@ -240,7 +241,7 @@ exports.callBids = (adUnits, bidRequests, addBidResponse, doneCb) => {
return adapters.concat((adUnit.bids || []).reduce((adapters, bid) => { return adapters.concat(bid.bidder) }, []));
}, []);
utils.logMessage(`CALLING S2S HEADER BIDDERS ==== ${adaptersServerSide.filter(adapter => {
return allBidders.includes(adapter);
return includes(allBidders, adapter);
}).join(',')}`);

// fire BID_REQUESTED event for each s2s bidRequest
Expand Down Expand Up @@ -283,8 +284,8 @@ function doingS2STesting() {

function getSupportedMediaTypes(bidderCode) {
let result = [];
if (exports.videoAdapters.includes(bidderCode)) result.push('video');
if (nativeAdapters.includes(bidderCode)) result.push('native');
if (includes(exports.videoAdapters, bidderCode)) result.push('video');
if (includes(nativeAdapters, bidderCode)) result.push('native');
return result;
}

Expand All @@ -295,10 +296,10 @@ exports.registerBidAdapter = function (bidAdaptor, bidderCode, {supportedMediaTy
if (typeof bidAdaptor.callBids === 'function') {
_bidderRegistry[bidderCode] = bidAdaptor;

if (supportedMediaTypes.includes('video')) {
if (includes(supportedMediaTypes, 'video')) {
exports.videoAdapters.push(bidderCode);
}
if (supportedMediaTypes.includes('native')) {
if (includes(supportedMediaTypes, 'native')) {
nativeAdapters.push(bidderCode);
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { STATUS } from 'src/constants';
import { userSync } from 'src/userSync';
import { nativeBidIsValid } from 'src/native';
import { isValidVideoBid } from 'src/video';
import includes from 'core-js/library/fn/array/includes';

import { logWarn, logError, parseQueryStringParameters, delayExecution, parseSizesInput, getBidderRequest } from 'src/utils';

Expand Down Expand Up @@ -362,7 +363,7 @@ function validBidSize(adUnitCode, bid, bidRequests) {
export function isValid(adUnitCode, bid, bidRequests) {
function hasValidKeys() {
let bidKeys = Object.keys(bid);
return COMMON_BID_RESPONSE_KEYS.every(key => bidKeys.includes(key));
return COMMON_BID_RESPONSE_KEYS.every(key => includes(bidKeys, key));
}

function errorMessage(msg) {
Expand Down
8 changes: 5 additions & 3 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ import { config } from 'src/config';
import { userSync } from 'src/userSync';
import { createHook } from 'src/hook';
import { videoAdUnit } from 'src/video';
import find from 'core-js/library/fn/array/find';
import includes from 'core-js/library/fn/array/includes';

const { syncUsers } = userSync;
const utils = require('./utils');
Expand Down Expand Up @@ -147,7 +149,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels})
function done(bidRequestId) {
var innerBidRequestId = bidRequestId;
return delayExecution(function() {
let request = _bidderRequests.find((bidRequest) => {
let request = find(_bidderRequests, (bidRequest) => {
return innerBidRequestId === bidRequest.bidderRequestId;
});
request.doneCbCallCount += 1;
Expand Down Expand Up @@ -488,10 +490,10 @@ function getTimedOutBids(bidderRequests, bidsReceived) {
.filter(uniques);

const timedOutBidderCodes = bidRequestedCodes
.filter(bidder => !bidReceivedCodes.includes(bidder));
.filter(bidder => !includes(bidReceivedCodes, bidder));

const timedOutBids = bidderRequests
.map(bid => (bid.bids || []).filter(bid => timedOutBidderCodes.includes(bid.bidder)))
.map(bid => (bid.bids || []).filter(bid => includes(timedOutBidderCodes, bid.bidder)))
.reduce(flatten, [])
.map(bid => ({
bidId: bid.bidId,
Expand Down
Loading

0 comments on commit de5ed4d

Please sign in to comment.