Skip to content

Conversation

KhafraDev
Copy link
Member

This relates to...

Rationale

Changes

Features

Bug Fixes

Breaking Changes and Deprecations

Status

@Renegade334
Copy link
Contributor

+1. Would it be worth renaming opts parameters to flags as well, to avoid any ambiguity?

Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec doesnt speak of Flags but extended attributes.

I think this is the wrong approach.

E.g. Clamp
https://webidl.spec.whatwg.org/#Clamp

The example would be basically:

const Clamp =  Symbol('webidl.extended-attribute.Clamp')

webidl.converters.octet = function (V) {
  // Clamped integer between 0 - 255
  if (V[Clamp] === true) {
    if (V > 255) {
      return 255
    }
    if (V < 0) {
      return 0
    }
    return V
  }
  
  // ToUint8 is basically modulo 256
  return V & 255
}
const value = new Number(257)
console.log(webidl.converters.octet(value)) // should be '1'

but:

const value = new Number(257)
value[Clamp] = true
console.log(webidl.converters.octet(octet)) // should be '255'

So I think it is expected by webidl, that we set as it clearly states attributes to the values and not pass flags to webidl functions.

@Uzlopak
Copy link
Contributor

Uzlopak commented Sep 2, 2025

@KhafraDev
Copy link
Member Author

An extended attribute is an annotation that can appear on definitions, types as annotated types, interface members, interface mixin members, callback interface members, namespace members, dictionary members, and operation arguments, and is used to control how language bindings will handle those constructs. Extended attributes are specified with an ExtendedAttributeList, which is a square bracket enclosed, comma separated list of ExtendedAttributes.

Your approach wouldn't work, in a number of ways that would take too long to explain (and I don't have any motivation to explain). This PR is a simple refactor of moving options as an object to options as a bitwise flag.

}

webidl.util.HasFlag = function (flags, attributes) {
return typeof flags === 'number' && (flags & attributes) === attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need to check if flags is a number? cant we expect that we are smart enough to pass numbers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flags are optional

Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we cant do it closer to the spec.

@Uzlopak Uzlopak merged commit c2da306 into nodejs:main Sep 4, 2025
29 of 32 checks passed
@KhafraDev KhafraDev deleted the webidl-attribute-flags branch September 4, 2025 21:43
@github-actions github-actions bot mentioned this pull request Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants