| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,6 +42,7 @@ const { | |||
| 42 | 42 | kEnumerableProperty, | |
| 43 | 43 | } = require('internal/util'); | |
| 44 | 44 | const { inspect } = require('util'); | |
| 45 | + const webidl = require('internal/webidl'); | ||
| 45 | 46 | ||
| 46 | 47 | const kIsEventTarget = SymbolFor('nodejs.event_target'); | |
| 47 | 48 | const kIsNodeEventTarget = Symbol('kIsNodeEventTarget'); | |
@@ -598,7 +599,7 @@ class EventTarget { | |||
| 598 | 599 | process.emitWarning(w); | |
| 599 | 600 | return; | |
| 600 | 601 | } | |
| 601 | - type = String(type); | ||
| 602 | + type = webidl.converters.DOMString(type); | ||
| 602 | 603 | ||
| 603 | 604 | if (signal) { | |
| 604 | 605 | if (signal.aborted) { | |
@@ -664,7 +665,7 @@ class EventTarget { | |||
| 664 | 665 | if (!validateEventListener(listener)) | |
| 665 | 666 | return; | |
| 666 | 667 | ||
| 667 | - type = String(type); | ||
| 668 | + type = webidl.converters.DOMString(type); | ||
| 668 | 669 | const capture = options?.capture === true; | |
| 669 | 670 | ||
| 670 | 671 | const root = this[kEvents].get(type); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ const { | |||
| 10 | 10 | NumberIsNaN, | |
| 11 | 11 | NumberMAX_SAFE_INTEGER, | |
| 12 | 12 | NumberMIN_SAFE_INTEGER, | |
| 13 | + String, | ||
| 13 | 14 | } = primordials; | |
| 14 | 15 | ||
| 15 | 16 | const { | |
@@ -19,6 +20,8 @@ const { | |||
| 19 | 20 | } = require('internal/errors'); | |
| 20 | 21 | const { kEmptyObject } = require('internal/util'); | |
| 21 | 22 | ||
| 23 | + const converters = { __proto__: null }; | ||
| 24 | + | ||
| 22 | 25 | // https://webidl.spec.whatwg.org/#abstract-opdef-integerpart | |
| 23 | 26 | const integerPart = MathTrunc; | |
| 24 | 27 | ||
@@ -157,7 +160,21 @@ function convertToInt(name, value, bitLength, options = kEmptyObject) { | |||
| 157 | 160 | return x; | |
| 158 | 161 | } | |
| 159 | 162 | ||
| 163 | + /** | ||
| 164 | + * @see https://webidl.spec.whatwg.org/#es-DOMString | ||
| 165 | + * @param {any} V | ||
| 166 | + * @returns {string} | ||
| 167 | + */ | ||
| 168 | + converters.DOMString = function DOMString(V) { | ||
| 169 | + if (typeof V === 'symbol') { | ||
| 170 | + throw new ERR_INVALID_ARG_VALUE('value', V); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + return String(V); | ||
| 174 | + }; | ||
| 175 | + | ||
| 160 | 176 | module.exports = { | |
| 161 | 177 | convertToInt, | |
| 162 | 178 | evenRound, | |
| 179 | + converters, | ||
| 163 | 180 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,6 +60,7 @@ const expectedModules = new Set([ | |||
| 60 | 60 | 'Internal Binding blob', | |
| 61 | 61 | 'NativeModule internal/url', | |
| 62 | 62 | 'NativeModule util', | |
| 63 | + 'NativeModule internal/webidl', | ||
| 63 | 64 | 'Internal Binding performance', | |
| 64 | 65 | 'Internal Binding permission', | |
| 65 | 66 | 'NativeModule internal/perf/utils', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -714,3 +714,15 @@ let asyncTest = Promise.resolve(); | |||
| 714 | 714 | name: 'TypeError', | |
| 715 | 715 | }); | |
| 716 | 716 | } | |
| 717 | + | ||
| 718 | + { | ||
| 719 | + const et = new EventTarget(); | ||
| 720 | + | ||
| 721 | + throws(() => { | ||
| 722 | + et.addEventListener(Symbol('symbol'), () => {}); | ||
| 723 | + }, TypeError); | ||
| 724 | + | ||
| 725 | + throws(() => { | ||
| 726 | + et.removeEventListener(Symbol('symbol'), () => {}); | ||
| 727 | + }, TypeError); | ||
| 728 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments