Skip to content

Commit

Permalink
== to ===, != to !== (web-platform-tests#45514)
Browse files Browse the repository at this point in the history
These are preferred as they're more strict [0][1].

The exception is comparisons with null -- we sometimes want
== and != since they also match undefined.

[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_inequality

Change-Id: I7a391faab107f02c2486cdd59ebb415c7613526d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5420989
Reviewed-by: mmenke <mmenke@chromium.org>
Commit-Queue: Caleb Raitto <caraitto@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1282132}

Co-authored-by: Caleb Raitto <caraitto@chromium.org>
  • Loading branch information
chromium-wpt-export-bot and caraitto authored Apr 3, 2024
1 parent fa48865 commit 4eb1146
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions fledge/tentative/auction-config.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,9 @@ subsetTest(promise_test, async test => {
let bid = browserSignals.forDebuggingOnlyInCooldownOrLockout ? 1 : 2;
return {bid: bid, render: '${renderURL}'};`,
reportWin: `
if (browserSignals.bid == 1)
if (browserSignals.bid === 1)
sendReportTo('${bidderReportURL1}');
if (browserSignals.bid == 2)
if (browserSignals.bid === 2)
sendReportTo('${bidderReportURL2}');`

})
Expand All @@ -443,9 +443,9 @@ subsetTest(promise_test, async test => {
browserSignals.forDebuggingOnlyInCooldownOrLockout ? 1 : 2;
return {desirability: desirability};`,
reportResult: `
if (browserSignals.desirability == 1)
if (browserSignals.desirability === 1)
sendReportTo('${sellerReportURL1}');
if (browserSignals.desirability == 2)
if (browserSignals.desirability === 2)
sendReportTo('${sellerReportURL2}');`
})
};
Expand Down
4 changes: 2 additions & 2 deletions fledge/tentative/component-ads.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function runComponentAdLoadingTest(test, uuid, numComponentAdsInInterestGr
`// "status" is passed to the beacon URL, to be verified by waitForObservedRequests().
let status = "ok";
const componentAds = window.fence.getNestedConfigs()
if (componentAds.length != 40)
if (componentAds.length !== 40)
status = "unexpected getNestedConfigs() length";
for (let i of ${JSON.stringify(componentAdsToLoad)}) {
let fencedFrame = document.createElement("fencedframe");
Expand Down Expand Up @@ -144,7 +144,7 @@ subsetTest(promise_test, async test => {
const nestedConfigsLength = window.fence.getNestedConfigs().length
// "getNestedConfigs()" should return a list of 40 configs, to avoid leaking
// whether there were any component URLs to the page.
if (nestedConfigsLength != 40)
if (nestedConfigsLength !== 40)
status = "unexpected getNestedConfigs() length: " + nestedConfigsLength;
window.fence.reportEvent({eventType: "beacon",
eventData: status,
Expand Down
4 changes: 2 additions & 2 deletions fledge/tentative/component-auction.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ subsetTest(promise_test, async test => {
auctionConfig.componentAuctions[0].decisionLogicURL =
createDecisionScriptURL(
uuid,
{ scoreAd: `if (browserSignals.renderURL != '${renderURL1}')
{ scoreAd: `if (browserSignals.renderURL !== '${renderURL1}')
throw 'Wrong ad';`,
reportResult: `sendReportTo('${seller1ReportURL}');`}
);
Expand All @@ -696,7 +696,7 @@ subsetTest(promise_test, async test => {
decisionLogicURL: createDecisionScriptURL(
uuid,
{ origin: OTHER_ORIGIN1,
scoreAd: `if (browserSignals.renderURL != '${renderURL2}')
scoreAd: `if (browserSignals.renderURL !== '${renderURL2}')
throw 'Wrong ad';`,
reportResult: `sendReportTo('${seller2ReportURL}');`}
)
Expand Down
2 changes: 1 addition & 1 deletion fledge/tentative/cross-origin.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ subsetTest(promise_test, async test => {
throw "Wrong origin: " + interestGroup.owner;
if (!interestGroup.biddingLogicURL.startsWith("${bidderOrigin}"))
throw "Wrong origin: " + interestGroup.biddingLogicURL;
if (interestGroup.ads[0].renderURL != "${renderURL}")
if (interestGroup.ads[0].renderURL !== "${renderURL}")
throw "Wrong renderURL: " + interestGroup.ads[0].renderURL;
if (browserSignals.seller !== "${sellerOrigin}")
throw "Wrong origin: " + browserSignals.seller;`,
Expand Down
2 changes: 1 addition & 1 deletion fledge/tentative/currency.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ subsetTest(promise_test, async test => {
topLevelSellerScriptParamsOverride: {
scoreAd: `
// scoreAd sees what's actually passed in.
if (bid != 9)
if (bid !== 9)
throw 'Wrong bid';
if (browserSignals.bidCurrency !== '???')
throw 'Wrong currency';`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ subsetTest(promise_test, async test => {
if (!deepEquals(Object.keys(instance.exports), ["increment"]))
throw "Unexpected exports: " + JSON.stringify(instance.exports);
if (instance.exports.increment(1) != 2)
if (instance.exports.increment(1) !== 2)
throw "Unexpected increment result: " + instance.exports.increment(1);` })
}
});
Expand Down
30 changes: 15 additions & 15 deletions fledge/tentative/resources/fledge-util.sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async function waitForObservedRequestsIgnoreDebugOnlyReports(
function createBiddingScriptURL(params = {}) {
let origin = params.origin ? params.origin : new URL(BASE_URL).origin;
let url = new URL(`${origin}${RESOURCE_PATH}bidding-logic.sub.py`);
// These checks use "==" to ignore null and not provided arguments, while
// These checks use "!=" to ignore null and not provided arguments, while
// treating '' as a valid argument.
if (params.generateBid != null)
url.searchParams.append('generateBid', params.generateBid);
Expand Down Expand Up @@ -213,7 +213,7 @@ function createDecisionScriptURL(uuid, params = {}) {
let origin = params.origin ? params.origin : new URL(BASE_URL).origin;
let url = new URL(`${origin}${RESOURCE_PATH}decision-logic.sub.py`);
url.searchParams.append('uuid', uuid);
// These checks use "==" to ignore null and not provided arguments, while
// These checks use "!=" to ignore null and not provided arguments, while
// treating '' as a valid argument.
if (params.scoreAd != null)
url.searchParams.append('scoreAd', params.scoreAd);
Expand All @@ -230,8 +230,8 @@ function createDecisionScriptURL(uuid, params = {}) {
// be last. "signalsParams" also has no effect, but is used by
// trusted-scoring-signals.py to affect the response.
function createRenderURL(uuid, script, signalsParams, origin) {
// These checks use "==" to ignore null and not provided arguments, while
// treating '' as a valid argument.
// These checks use "==" and "!=" to ignore null and not provided
// arguments, while treating '' as a valid argument.
if (origin == null)
origin = new URL(BASE_URL).origin;
let url = new URL(`${origin}${RESOURCE_PATH}fenced-frame.sub.py`);
Expand Down Expand Up @@ -298,7 +298,7 @@ async function joinNegativeInterestGroup(
name: name,
additionalBidKey: additionalBidKey
};
if (owner != window.location.origin) {
if (owner !== window.location.origin) {
let iframe = await createIframe(test, owner, 'join-ad-interest-group');
await runInFrame(
test, iframe,
Expand Down Expand Up @@ -557,7 +557,7 @@ async function runInFrame(test, child_window, script, param) {

let promise = new Promise(function(resolve, reject) {
function WaitForMessage(event) {
if (event.data.messageUuid != messageUuid)
if (event.data.messageUuid !== messageUuid)
return;
receivedResponse = event.data;
if (event.data.result === 'success') {
Expand Down Expand Up @@ -589,7 +589,7 @@ async function createFrame(test, origin, is_iframe = true, permissions = null) {
`${origin}${RESOURCE_PATH}subordinate-frame.sub.html?uuid=${frameUuid}`;
let promise = new Promise(function(resolve, reject) {
function WaitForMessage(event) {
if (event.data.messageUuid != frameUuid)
if (event.data.messageUuid !== frameUuid)
return;
if (event.data.result === 'load complete') {
resolve();
Expand Down Expand Up @@ -703,35 +703,35 @@ function directFromSellerSignalsValidatorCode(uuid, expectedSellerSignals,
return {
// Seller worklets
scoreAd:
`if (directFromSellerSignals === null ||
`if (directFromSellerSignals == null ||
directFromSellerSignals.sellerSignals !== ${expectedSellerSignals} ||
directFromSellerSignals.auctionSignals !== ${expectedAuctionSignals} ||
Object.keys(directFromSellerSignals).length != 2) {
Object.keys(directFromSellerSignals).length !== 2) {
throw 'Failed to get expected directFromSellerSignals in scoreAd(): ' +
JSON.stringify(directFromSellerSignals);
}`,
reportResultSuccessCondition:
`directFromSellerSignals !== null &&
`directFromSellerSignals != null &&
directFromSellerSignals.sellerSignals === ${expectedSellerSignals} &&
directFromSellerSignals.auctionSignals === ${expectedAuctionSignals} &&
Object.keys(directFromSellerSignals).length == 2`,
Object.keys(directFromSellerSignals).length === 2`,
reportResult:
`sendReportTo("${createSellerReportURL(uuid)}");`,

// Bidder worklets
generateBid:
`if (directFromSellerSignals === null ||
`if (directFromSellerSignals == null ||
directFromSellerSignals.perBuyerSignals !== ${expectedPerBuyerSignals} ||
directFromSellerSignals.auctionSignals !== ${expectedAuctionSignals} ||
Object.keys(directFromSellerSignals).length != 2) {
Object.keys(directFromSellerSignals).length !== 2) {
throw 'Failed to get expected directFromSellerSignals in generateBid(): ' +
JSON.stringify(directFromSellerSignals);
}`,
reportWinSuccessCondition:
`directFromSellerSignals !== null &&
`directFromSellerSignals != null &&
directFromSellerSignals.perBuyerSignals === ${expectedPerBuyerSignals} &&
directFromSellerSignals.auctionSignals === ${expectedAuctionSignals} &&
Object.keys(directFromSellerSignals).length == 2`,
Object.keys(directFromSellerSignals).length === 2`,
reportWin:
`sendReportTo("${createBidderReportURL(uuid)}");`,
};
Expand Down
4 changes: 2 additions & 2 deletions fledge/tentative/resources/worklet-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ function deepEquals(a, b) {
return a === b;

let aKeys = Object.keys(a);
if (aKeys.length != Object.keys(b).length)
if (aKeys.length !== Object.keys(b).length)
return false;
for (let key of aKeys) {
if (a.hasOwnProperty(key) != b.hasOwnProperty(key) ||
if (a.hasOwnProperty(key) !== b.hasOwnProperty(key) ||
!deepEquals(a[key], b[key])) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion fledge/tentative/tie.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ promise_test(async test => {
auctionConfigOverrides.decisionLogicURL =
createDecisionScriptURL(
uuid,
{scoreAd: `if (browserSignals.renderURL == "${winningAdURL}")
{scoreAd: `if (browserSignals.renderURL === "${winningAdURL}")
return 0;`});

// Add an abort controller, so can cancel extra auctions.
Expand Down

0 comments on commit 4eb1146

Please sign in to comment.