From 66cc6c278ed3ee179a79f7a068b11a8d793bda7f Mon Sep 17 00:00:00 2001 From: Maks Orlovich Date: Wed, 12 Jul 2023 11:03:21 -0400 Subject: [PATCH] Fix a number of imprecisions in GenerateBidOutput handling: (#664) * Fix a number of imprecisions in generateBidOutput handling: 1. The return value of generateBid() always wins over setBid if the function completed normally; even if it's invalid. 2. setBid doesn't return true/false, it throws on invalid input. 3. 'render' is not strictly required: if the bid value is <= 0 the object is a valid representation of not bidding regardless of other fields; this is relevant because doing setBid() with it does not throw. 4. modelingSignals is actually an unrestricted double: the explainer has NaN/inf/-inf as ignored, and conveniently none of these are in the [0, 4095) range anyway. I've also scooted over the zero-argument setBid() next to its full-functioned sibling, rather than separated by a giant algorithm. * Add missing floor() and make 'bid' optional to make setBid(null) work. * Hopefully make the tougher verifier happy. * Making verifier I don't know how to run locally happy, take two * Fix buglets with AdRender, too. * Fancy <= and explicit typecast * Don't need floor again * Fix typos Qingxin pointed out. --------- Co-authored-by: Maks Orlovich --- spec.bs | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/spec.bs b/spec.bs index 8d29de814..db7ee718e 100644 --- a/spec.bs +++ b/spec.bs @@ -2147,11 +2147,9 @@ of the following global objects: 1. Let |generatedBidIDL| be the result of [=converted to an IDL value|converting=] |result|'s \[[Value]] to a {{GenerateBidOutput}}. 1. If no exception was [=exception/thrown=] in the previous step: - 1. Let |groupHasAdComponents| be true. - 1. If |ig|'s [=interest group/ad components=] is null, set |groupHasAdComponents| be false. - 1. Let |possibleGeneratedBid| be the result of [=converting GenerateBidOutput to generated bid=] - with |generatedBidIDL|, |ig|, |expectedCurrency|, |isComponentAuction|, and |groupHasAdComponents|. - 1. If |possibleGeneratedBid| is not failure, set |generatedBid| to it. + 1. Set |generatedBid| to the result of [=converting GenerateBidOutput to generated bid=] with |generatedBidIDL|, |ig|, |expectedCurrency|, |isComponentAuction|, and |global|'s [=InterestGroupBiddingScriptRunnerGlobalScope/group has ad components=]. + 1. Otherwise, set |generatedBid| to failure. + 1. If |generatedBid| is a [=generated bid=] and |generatedBid|'s [=generated bid/bid=]'s [=bid with currency/value=] ≤ 0, set |generatedBid| to failure. 1. If |generatedBid| is null, set it to failure. 1. If |generatedBid| is not failure: 1. Set |generatedBid|'s [=generated bid/bid duration=] to |duration|. @@ -2270,26 +2268,25 @@ interface InterestGroupScriptRunnerGlobalScope { InterestGroupBiddingScriptRunnerGlobalScope)] interface InterestGroupBiddingScriptRunnerGlobalScope : InterestGroupScriptRunnerGlobalScope { - boolean setBid(); - boolean setBid(GenerateBidOutput generateBidOutput); + boolean setBid(optional GenerateBidOutput generateBidOutput = {}); undefined setPriority(double priority); undefined setPrioritySignalsOverride(DOMString key, double priority); }; dictionary AdRender { required DOMString url; - required DOMString width; - required DOMString height; + DOMString width; + DOMString height; }; dictionary GenerateBidOutput { - required double bid; + double bid = -1; DOMString bidCurrency; - required (DOMString or AdRender) render; + (DOMString or AdRender) render; any ad; sequence<(DOMString or AdRender)> adComponents; double adCost; - double modelingSignals; + unrestricted double modelingSignals; boolean allowComponentAuction = false; }; @@ -2314,24 +2311,20 @@ Each {{InterestGroupBiddingScriptRunnerGlobalScope}} has a -
- The setBid() method steps are: - - 1. Set [=this=]'s [=relevant global object=]'s [=InterestGroupBiddingScriptRunnerGlobalScope/bid=] - to null. - 1. Return true. -
To convert GenerateBidOutput to generated bid given a {{GenerateBidOutput}} |generateBidOutput|, an [=interest group=] |ig|, a [=currency tag=] |expectedCurrency|, a [=boolean=] |isComponentAuction| and a [=boolean=] |groupHasAdComponents|: - 1. If |generateBidOutput|["{{GenerateBidOutput/bid}}"] is less than or equal to 0, return failure. + 1. Let |bid| be a new [=generated bid=]. + 1. If |generateBidOutput|["{{GenerateBidOutput/bid}}"] ≤ 0: + 1. Set |bid|'s [=generated bid/bid=] to a [=bid with currency=] with [=bid with currency/value=] |generateBidOutput|["{{GenerateBidOutput/bid}}"] and [=bid with currency/currency=] null. + 1. Return |bid|. + 1. If |generateBidOutput|["{{GenerateBidOutput/render}}"] does not [=map/exist=], return failure. 1. If |isComponentAuction| is true, and |generateBidOutput|["{{GenerateBidOutput/allowComponentAuction}}"] is false: 1. Return failure. - 1. Let |bid| be a new [=generated bid=]. 1. Let |bidCurrency| be null. 1. If |generateBidOutput|["{{GenerateBidOutput/bidCurrency}}"] is specified: 1. If the result of [=checking whether a string is a valid currency tag=] on @@ -2383,8 +2376,8 @@ To convert GenerateBidOutput to generated bid given a {{GenerateBidOu |generateBidOutput|["{{GenerateBidOutput/adCost}}"]. 1. If |generateBidOutput|["{{GenerateBidOutput/modelingSignals}}"] [=map/exists=]: 1. Let |modelingSignals| be |generateBidOutput|["{{GenerateBidOutput/modelingSignals}}"]. - 1. If |modelingSignals| is greater than or equal to 0 and less than 4096: - 1. Set |bid|'s [=generated bid/modeling signals=] to |modelingSignals|. + 1. If |modelingSignals| ≥ 0 and |modelingSignals| < 4096: + 1. Set |bid|'s [=generated bid/modeling signals=] to the result of [=converted to an IDL value|converting=] the ECMAScript value represented by |modelingSignals| to an {{unsigned short}}. 1. Return |bid|.
@@ -2412,7 +2405,6 @@ To convert GenerateBidOutput to generated bid given a {{GenerateBidOu To convert an ad render given an {{AdRender}} |adRender|, an [=interest group=] |ig|, and a [=boolean=] |isComponent|: - 1. If |adRender|["{{AdRender/url}}"] does not [=map/exist=], return false. 1. Let |adUrl| be the result of running the [=URL parser=] on |adRender|["{{AdRender/url}}"]. 1. If |adUrl| is failure, return failure. 1. If [=validating an ad url=] given |adUrl|, |ig|, and |isComponent| returns false, return failure. @@ -2462,10 +2454,9 @@ To convert GenerateBidOutput to generated bid given a {{GenerateBidOu [=InterestGroupBiddingScriptRunnerGlobalScope/is component auction=], and [=this=]'s [=relevant global object=]'s [=InterestGroupBiddingScriptRunnerGlobalScope/group has ad components=]. - 1. If |bidToSet| is failure, return false. + 1. If |bidToSet| is failure, [=exception/throw=] a {{TypeError}}. 1. Set [=this=]'s [=relevant global object=]'s [=InterestGroupBiddingScriptRunnerGlobalScope/bid=] to |bidToSet|. - 1. Return true.