Skip to content

Promise-returning operations should return Promise.reject on invalid argument #79

Closed
@danyao

Description

@danyao

If an interface defines a Promise-returning operation with required arguments, the generated wrapper throws TypeError if insufficient number of arguments are provided. I believe the expected behavior is to return a Promise.reject that throws.

E.g.

interface Foo {
  Promise<string> greet(string name);
};

Generates:

Foo.prototype.greet = function greet(name) {
  ...
  if (arguments.length < 1) {
    throw new TypeError(
      "Failed to execute 'greet' on 'Foo': " + "1 argument required, but only " + arguments.length + " present."
    );  // [*]
  }

  ...
}

[*] should be:

return Promise.reject(new TypeError("<error message>"));

I couldn't find exact wording in WebIDL spec about this. However, the return-rejected-promise behavior is what Web Platform Test's idlharness.js enforces.

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