Skip to content

Commit

Permalink
Fix a number of imprecisions in GenerateBidOutput handling: (WICG#664)
Browse files Browse the repository at this point in the history
* 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 <morlovich@chromium.org>
  • Loading branch information
morlovich and Maks Orlovich authored Jul 12, 2023
1 parent 77601ee commit 66cc6c2
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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=] &le; 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|.
Expand Down Expand Up @@ -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;
};

Expand All @@ -2314,24 +2311,20 @@ Each {{InterestGroupBiddingScriptRunnerGlobalScope}} has a

</dl>

<div algorithm>
The <dfn method for="InterestGroupBiddingScriptRunnerGlobalScope">setBid()</dfn> method steps are:

1. Set [=this=]'s [=relevant global object=]'s [=InterestGroupBiddingScriptRunnerGlobalScope/bid=]
to null.
1. Return true.
</div>

<div algorithm>

To <dfn>convert GenerateBidOutput to generated bid</dfn> 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}}"] &le; 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
Expand Down Expand Up @@ -2383,8 +2376,8 @@ To <dfn>convert GenerateBidOutput to generated bid</dfn> 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| &ge; 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|.

</div>
Expand Down Expand Up @@ -2412,7 +2405,6 @@ To <dfn>convert GenerateBidOutput to generated bid</dfn> given a {{GenerateBidOu
To <dfn>convert an ad render</dfn> 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.
Expand Down Expand Up @@ -2462,10 +2454,9 @@ To <dfn>convert GenerateBidOutput to generated bid</dfn> 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.
</div>

<div algorithm>
Expand Down

0 comments on commit 66cc6c2

Please sign in to comment.