Skip to content

RTCError constructor fails the copy constructor pattern #3064

@jan-ivar

Description

@jan-ivar

WebRTC generally follows the Event copy-constructor pattern for all its events, as well as its light data-holder interfaces like

However, the latter misses the mark as it doesn't allow initializing members to null, causing side-effects (coersion to 0). Codepen:

const e1 = new RTCError({errorDetail: "data-channel-failure"}, "foo");
const e2 = new RTCError(e1, e1.message);

[
  "name",
  "message",
  "sdpLineNumber",
  "sctpCauseCode",
  "receivedAlert",
  "sentAlert"
].forEach(name => test(t => assert_equals(e2[name], e1[name], name)));
PASS undefined
PASS undefined
FAIL undefined: sdpLineNumber - Expected null, got 0 failed
FAIL undefined: sctpCauseCode - Expected null, got 0 failed
FAIL undefined: receivedAlert - Expected null, got 0 failed
FAIL undefined: sentAlert - Expected null, got 0 failed
2/6 tests passed
PASS finished

This seems easily fixed by changing RTCErrorInit to accept null as member inputs.

Metadata

Metadata

Assignees

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