Skip to content

[test][js-api] WebAssembly.Exception.length should be 2#2123

Merged
eqrion merged 1 commit intoWebAssembly:mainfrom
Liedtke:change_wasm_exception_constructor_length
Mar 25, 2026
Merged

[test][js-api] WebAssembly.Exception.length should be 2#2123
eqrion merged 1 commit intoWebAssembly:mainfrom
Liedtke:change_wasm_exception_constructor_length

Conversation

@Liedtke
Copy link
Contributor

@Liedtke Liedtke commented Mar 25, 2026

Based on: https://webassembly.github.io/spec/js-api/#exceptions

[LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)]
interface Exception {
  constructor(Tag exceptionTag, sequence<any> payload, optional ExceptionOptions options = {});
  any getArg(Tag exceptionTag, [EnforceRange] unsigned long index);
  boolean is(Tag exceptionTag);
  readonly attribute (DOMString or undefined) stack;
};

At least our WPT tests are unhappy about V8 returning 1 here instead of 2 and according to MDN it seems like this number should include all parameters before the first one with a default value?
(I'm not very familiar with JS semantics and WebIDL definitions.)

@Ms2ger: Could you please take a look?

See https://webassembly.github.io/spec/js-api/#exceptions
> constructor(Tag exceptionTag, sequence<any> payload,
>             optional ExceptionOptions options = {});
@eqrion
Copy link
Collaborator

eqrion commented Mar 25, 2026

It looks like we need to 'Set length to the length of the shortest argument list of the entries in S.' where S is the effective overload set [1] [2]. This gets passed to create builtin function which calls SetFunctionLength.

I don't see in the WebIDL spec where we determine the 'length of an argument list' for a constructor, and if an optional argument counts or not. It seems reasonable to exclude it, but just want to confirm first.

[1] https://webidl.spec.whatwg.org/#interface-object
[2] https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-createbuiltinfunction

@eqrion
Copy link
Collaborator

eqrion commented Mar 25, 2026

I don't see in the WebIDL spec where we determine the 'length of an argument list' for a constructor, and if an optional argument counts or not. It seems reasonable to exclude it, but just want to confirm first.

This is done by computing the effective overload set [1] operation. A constructor with an optional parameter appears as two overloads, one with the parameter and one without. The length is then the minimum which doesn't contain the optional parameter.

This LGTM then.

[1] https://webidl.spec.whatwg.org/#compute-the-effective-overload-set

@eqrion eqrion merged commit dd0d7a9 into WebAssembly:main Mar 25, 2026
1 check passed
@Liedtke Liedtke deleted the change_wasm_exception_constructor_length branch March 26, 2026 16:17
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.

2 participants