How to use [EnforceRange] with union types and enums

# Adam Bergkvist (6 hours ago)

The WebIDL spec is a bit slim on how the [EnforceRange] extended attribute can be used.

Consider the below case. The LongRage dictionary enforces range on it's max and min members. I want to enforce range on the remaining 'long' in the Longish typedef. Is it valid to squeeze in the extended attribute in the typedef?

========== void acceptLongish(Longish num);

typedef (long or LongRange) Longish;

dictionary LongRange { [EnforceRange] long max; [EnforceRange] long min;

};

BR

Contact us to advertise here
# Anne van Kesteren (6 hours ago)

On Tue, Sep 13, 2016 at 1:26 PM, Adam Bergkvist

adam.bergkvist@ericsson.com wrote:

Consider the below case. The LongRage dictionary enforces range on it's max and min members. I want to enforce range on the remaining 'long' in the Longish typedef. Is it valid to squeeze in the extended attribute in the typedef?

It's an open issue: www.w3.org/Bugs/Public/show_bug.cgi?id=28834. I think I agree that extended attributes that effectively modify the type coercion should be usable in such a context.

# Boris Zbarsky (5 hours ago)

On 9/13/16 7:26 AM, Adam Bergkvist wrote:

Is it valid to squeeze in the extended attribute in the typedef?

As the spec stands, it's not, though note the bug Anne linked to in his response.

The fundamental question is whether the range-enforcement is a property of the type or of the argument. It's mostly been treated as the latter, but this does lead to a slightly weird distinction between union and dictionary arguments in terms of how range-enforcement happens.

Maybe the right answer is to really make range-enforcement a property of the type, nix the [EnforceRange] thing entirely and just have an "enforced long" type and similar for other numeric types....

# Anne van Kesteren (5 hours ago)

On Tue, Sep 13, 2016 at 3:12 PM, Boris Zbarsky bzbarsky@mit.edu wrote:

Maybe the right answer is to really make range-enforcement a property of the type, nix the [EnforceRange] thing entirely and just have an "enforced long" type and similar for other numeric types....

That's what we ended up doing when we hit exactly this problem with ByteString/USVString (formerly [EnforceUTF16] DOMString or some such)...

# Adam Bergkvist (4 hours ago)

On 2016-09-13 15:23, Anne van Kesteren wrote:

On Tue, Sep 13, 2016 at 3:12 PM, Boris Zbarsky bzbarsky@mit.edu wrote:

Maybe the right answer is to really make range-enforcement a property of the type, nix the [EnforceRange] thing entirely and just have an "enforced long" type and similar for other numeric types....

That's what we ended up doing when we hit exactly this problem with ByteString/USVString (formerly [EnforceUTF16] DOMString or some such)...

Thanks for quick feedback.

Having a strict type that enforces range seems like flexible solution.

Want more features?

Request early access to our private beta of readable email premium.