lib: replace MessageEvent with undici's

undici's MessageEvent is better tested and has a complete WebIDL
implementation for validation. Not only this, but it's also used in
Node's  current WebSocket implementation. There are a large number of
webidl-related issues in the current MessageEvent, such as not
implementing `MessageEvent.prototype.initMessageEvent`, not validating
arguments passed to its constructor
(https://github.com/nodejs/node/pull/51771), not validating the values
passed to the constructor (such as not validating that `ports` is a
sequence, not converting origin to a USVString, etc.), and other issues.

fixup

PR-URL: https://github.com/nodejs/node/pull/52370
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
This commit is contained in:
Khafra authored and GitHub committed 2024-04-29 11:05:57 +00:00
1 parent 7c3dce0e4f
commit 3136fb0c28
5 files changed
+20 -120

No files matched your search

@@ -1,13 +1,8 @@
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const {
MessageEvent,
} = require('internal/worker/io');
[
'data',
'origin',
@@ -15,7 +10,5 @@ const {
'source',
'ports',
].forEach((i) => {
assert.throws(() => Reflect.get(MessageEvent.prototype, i, {}), {
code: 'ERR_INVALID_THIS',
});
assert.throws(() => Reflect.get(MessageEvent.prototype, i, {}), TypeError);
});
+9 -9
View File
@@ -61,31 +61,31 @@ const dummyPort = new MessageChannel().port1;
assert.throws(() => {
new MessageEvent('message', { source: 1 });
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "init\.source" property must be an instance of MessagePort/,
name: 'TypeError',
message: /Expected 1 to be an instance of MessagePort/,
});
assert.throws(() => {
new MessageEvent('message', { source: {} });
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "init\.source" property must be an instance of MessagePort/,
name: 'TypeError',
message: /Expected {} to be an instance of MessagePort/,
});
assert.throws(() => {
new MessageEvent('message', { ports: 0 });
}, {
message: /ports is not iterable/,
message: /Sequence: Value of type Number is not an Object/,
});
assert.throws(() => {
new MessageEvent('message', { ports: [ null ] });
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "init\.ports\[0\]" property must be an instance of MessagePort/,
name: 'TypeError',
message: /Expected null to be an instance of MessagePort/,
});
assert.throws(() => {
new MessageEvent('message', { ports: [ {} ] });
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "init\.ports\[0\]" property must be an instance of MessagePort/,
name: 'TypeError',
message: /Expected {} to be an instance of MessagePort/,
});
}