mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
lib: use webidl DOMString converter in EventTarget
PR-URL: https://github.com/nodejs/node/pull/47514 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
parent
9decb70d05
commit
41b8872cbd
@ -42,6 +42,7 @@ const {
|
||||
kEnumerableProperty,
|
||||
} = require('internal/util');
|
||||
const { inspect } = require('util');
|
||||
const webidl = require('internal/webidl');
|
||||
|
||||
const kIsEventTarget = SymbolFor('nodejs.event_target');
|
||||
const kIsNodeEventTarget = Symbol('kIsNodeEventTarget');
|
||||
@ -598,7 +599,7 @@ class EventTarget {
|
||||
process.emitWarning(w);
|
||||
return;
|
||||
}
|
||||
type = String(type);
|
||||
type = webidl.converters.DOMString(type);
|
||||
|
||||
if (signal) {
|
||||
if (signal.aborted) {
|
||||
@ -664,7 +665,7 @@ class EventTarget {
|
||||
if (!validateEventListener(listener))
|
||||
return;
|
||||
|
||||
type = String(type);
|
||||
type = webidl.converters.DOMString(type);
|
||||
const capture = options?.capture === true;
|
||||
|
||||
const root = this[kEvents].get(type);
|
||||
|
@ -10,6 +10,7 @@ const {
|
||||
NumberIsNaN,
|
||||
NumberMAX_SAFE_INTEGER,
|
||||
NumberMIN_SAFE_INTEGER,
|
||||
String,
|
||||
} = primordials;
|
||||
|
||||
const {
|
||||
@ -19,6 +20,8 @@ const {
|
||||
} = require('internal/errors');
|
||||
const { kEmptyObject } = require('internal/util');
|
||||
|
||||
const converters = { __proto__: null };
|
||||
|
||||
// https://webidl.spec.whatwg.org/#abstract-opdef-integerpart
|
||||
const integerPart = MathTrunc;
|
||||
|
||||
@ -157,7 +160,21 @@ function convertToInt(name, value, bitLength, options = kEmptyObject) {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://webidl.spec.whatwg.org/#es-DOMString
|
||||
* @param {any} V
|
||||
* @returns {string}
|
||||
*/
|
||||
converters.DOMString = function DOMString(V) {
|
||||
if (typeof V === 'symbol') {
|
||||
throw new ERR_INVALID_ARG_VALUE('value', V);
|
||||
}
|
||||
|
||||
return String(V);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
convertToInt,
|
||||
evenRound,
|
||||
converters,
|
||||
};
|
||||
|
@ -60,6 +60,7 @@ const expectedModules = new Set([
|
||||
'Internal Binding blob',
|
||||
'NativeModule internal/url',
|
||||
'NativeModule util',
|
||||
'NativeModule internal/webidl',
|
||||
'Internal Binding performance',
|
||||
'Internal Binding permission',
|
||||
'NativeModule internal/perf/utils',
|
||||
|
@ -714,3 +714,15 @@ let asyncTest = Promise.resolve();
|
||||
name: 'TypeError',
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const et = new EventTarget();
|
||||
|
||||
throws(() => {
|
||||
et.addEventListener(Symbol('symbol'), () => {});
|
||||
}, TypeError);
|
||||
|
||||
throws(() => {
|
||||
et.removeEventListener(Symbol('symbol'), () => {});
|
||||
}, TypeError);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user