diff --git a/lib/web/eventsource/eventsource.js b/lib/web/eventsource/eventsource.js index cf5093e1bdf..708caef1258 100644 --- a/lib/web/eventsource/eventsource.js +++ b/lib/web/eventsource/eventsource.js @@ -10,6 +10,7 @@ const { parseMIMEType } = require('../fetch/data-url') const { MessageEvent } = require('../websocket/events') const { isNetworkError } = require('../fetch/response') const { delay } = require('./util') +const { kEnumerableProperty } = require('../../core/util') let experimentalWarned = false @@ -459,6 +460,16 @@ const constantsPropertyDescriptors = { Object.defineProperties(EventSource, constantsPropertyDescriptors) Object.defineProperties(EventSource.prototype, constantsPropertyDescriptors) +Object.defineProperties(EventSource.prototype, { + close: kEnumerableProperty, + onerror: kEnumerableProperty, + onmessage: kEnumerableProperty, + onopen: kEnumerableProperty, + readyState: kEnumerableProperty, + url: kEnumerableProperty, + withCredentials: kEnumerableProperty +}) + webidl.converters.EventSourceInitDict = webidl.dictionaryConverter([ { key: 'withCredentials', converter: webidl.converters.boolean, defaultValue: false } ]) diff --git a/test/eventsource/eventsource-properties.js b/test/eventsource/eventsource-properties.js new file mode 100644 index 00000000000..58a02a91614 --- /dev/null +++ b/test/eventsource/eventsource-properties.js @@ -0,0 +1,15 @@ +'use strict' + +const { test } = require('node:test') +const assert = require('node:assert') +const { EventSource } = require('../..') // assuming the test is in test/eventsource/ + +test('EventSource.prototype properties are configured correctly', () => { + const props = Object.entries(Object.getOwnPropertyDescriptors(EventSource.prototype)) + + for (const [key, value] of props) { + if (key !== 'constructor') { + assert(value.enumerable, `${key} is not enumerable`) + } + } +})