Skip to content

Spec should be clearer than a Promise<T> argument also accepts T objects #1494

@tabatkins

Description

@tabatkins

What is the issue with the Web IDL Standard?

As far as I can tell, when an argument is of type Promise<T>, no verification is done on the value itself. Instead, when such an argument passes from JS into IDL, the algorithm just wraps the value in a new promise capability (which absorbs a passed promise, but also absorbs arbitrary thenables, and in fact any value at all). (This is presumably why it's not allowed to put Promise<> in a union, because it already absorbs all possible input types and thus isn't distinguishable from anything.)

This implies a few things that I think are useful for spec authors to know, neither of which are spelled out in the spec:

  1. Authors can automatically pass T values to any Promise<T> argument.
  2. Authors can also pass non-T values to any Promise<T> argument, so the function's algorithm needs to manually verify that it's the right type when responding to the promise.

I'm happy to PR some Note text, if y'all agree this is worth fixing.

(Context: a Googler spec author was asking how they should write their IDL to accept both a T and Promise<T> for an argument.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions