From b328eb80413fa337992936f3ca4df0c682304961 Mon Sep 17 00:00:00 2001 From: MattBidewell Date: Sat, 23 Mar 2024 14:37:38 +0000 Subject: [PATCH 1/4] make eventsource properties enumberable --- lib/web/eventsource/eventsource.js | 50 ++++++++++++++++++++++ test/eventsource/eventsource-properties.js | 15 +++++++ 2 files changed, 65 insertions(+) create mode 100644 test/eventsource/eventsource-properties.js diff --git a/lib/web/eventsource/eventsource.js b/lib/web/eventsource/eventsource.js index cf5093e1bdf..ef6014d717c 100644 --- a/lib/web/eventsource/eventsource.js +++ b/lib/web/eventsource/eventsource.js @@ -459,10 +459,60 @@ const constantsPropertyDescriptors = { Object.defineProperties(EventSource, constantsPropertyDescriptors) Object.defineProperties(EventSource.prototype, constantsPropertyDescriptors) +Object.defineProperty(EventSource.prototype, 'readyState', { + enumerable: true, + get: function() { + return this.readyState; + } +}); + +Object.defineProperty(EventSource.prototype, 'url', { + enumerable: true, + get: function() { + return this.url; + } +}); + +Object.defineProperty(EventSource.prototype, 'withCredentials', { + enumerable: true, + get: function() { + return this.url; + } +}); + +Object.defineProperty(EventSource.prototype, 'close', { + enumerable: true, + get: function() { + return this.url; + } +}); + +Object.defineProperty(EventSource.prototype, 'onopen', { + enumerable: true, + get: function() { + return this.url; + } +}); + +Object.defineProperty(EventSource.prototype, 'onmessage', { + enumerable: true, + get: function() { + return this.url; + } +}); + +Object.defineProperty(EventSource.prototype, 'onerror', { + enumerable: true, + get: function() { + return this.url; + } +}); + webidl.converters.EventSourceInitDict = webidl.dictionaryConverter([ { key: 'withCredentials', converter: webidl.converters.boolean, defaultValue: false } ]) + module.exports = { EventSource, defaultReconnectionTime diff --git a/test/eventsource/eventsource-properties.js b/test/eventsource/eventsource-properties.js new file mode 100644 index 00000000000..9fd9eab4d91 --- /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`) + } + } +}) \ No newline at end of file From d80f9757149fe3c8087fc0431c0df85aa7d3180d Mon Sep 17 00:00:00 2001 From: MattBidewell Date: Sat, 23 Mar 2024 16:54:08 +0000 Subject: [PATCH 2/4] Use kEnumerableProperty for eventsource immutable fields --- lib/web/eventsource/eventsource.js | 58 ++++++------------------------ 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/lib/web/eventsource/eventsource.js b/lib/web/eventsource/eventsource.js index ef6014d717c..e0fc7e45851 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,54 +460,15 @@ const constantsPropertyDescriptors = { Object.defineProperties(EventSource, constantsPropertyDescriptors) Object.defineProperties(EventSource.prototype, constantsPropertyDescriptors) -Object.defineProperty(EventSource.prototype, 'readyState', { - enumerable: true, - get: function() { - return this.readyState; - } -}); - -Object.defineProperty(EventSource.prototype, 'url', { - enumerable: true, - get: function() { - return this.url; - } -}); - -Object.defineProperty(EventSource.prototype, 'withCredentials', { - enumerable: true, - get: function() { - return this.url; - } -}); - -Object.defineProperty(EventSource.prototype, 'close', { - enumerable: true, - get: function() { - return this.url; - } -}); - -Object.defineProperty(EventSource.prototype, 'onopen', { - enumerable: true, - get: function() { - return this.url; - } -}); - -Object.defineProperty(EventSource.prototype, 'onmessage', { - enumerable: true, - get: function() { - return this.url; - } -}); - -Object.defineProperty(EventSource.prototype, 'onerror', { - enumerable: true, - get: function() { - return this.url; - } -}); +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 } From e6812529d1995fe526daa824c198c0f8350994c8 Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Sat, 23 Mar 2024 18:41:08 +0100 Subject: [PATCH 3/4] Apply suggestions from code review --- lib/web/eventsource/eventsource.js | 3 +-- test/eventsource/eventsource-properties.js | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/web/eventsource/eventsource.js b/lib/web/eventsource/eventsource.js index e0fc7e45851..708caef1258 100644 --- a/lib/web/eventsource/eventsource.js +++ b/lib/web/eventsource/eventsource.js @@ -467,14 +467,13 @@ Object.defineProperties(EventSource.prototype, { onopen: kEnumerableProperty, readyState: kEnumerableProperty, url: kEnumerableProperty, - withCredentials: kEnumerableProperty, + withCredentials: kEnumerableProperty }) webidl.converters.EventSourceInitDict = webidl.dictionaryConverter([ { key: 'withCredentials', converter: webidl.converters.boolean, defaultValue: false } ]) - module.exports = { EventSource, defaultReconnectionTime diff --git a/test/eventsource/eventsource-properties.js b/test/eventsource/eventsource-properties.js index 9fd9eab4d91..34ee5e84e1e 100644 --- a/test/eventsource/eventsource-properties.js +++ b/test/eventsource/eventsource-properties.js @@ -5,11 +5,11 @@ 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)) + const props = Object.entries(Object.getOwnPropertyDescriptors(EventSource.prototype)) - for (const [key, value] of props) { + for (const [key, value] of props) { if (key !== 'constructor') { - assert(value.enumerable, `${key} is not enumerable`) - } + assert(value.enumerable, `${key} is not enumerable`) } -}) \ No newline at end of file + } +}) From 901ca9039e512d3e52d751d1dbdb3d21fc8f0efa Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Sat, 23 Mar 2024 18:41:16 +0100 Subject: [PATCH 4/4] Apply suggestions from code review --- test/eventsource/eventsource-properties.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/eventsource/eventsource-properties.js b/test/eventsource/eventsource-properties.js index 34ee5e84e1e..58a02a91614 100644 --- a/test/eventsource/eventsource-properties.js +++ b/test/eventsource/eventsource-properties.js @@ -8,7 +8,7 @@ test('EventSource.prototype properties are configured correctly', () => { const props = Object.entries(Object.getOwnPropertyDescriptors(EventSource.prototype)) for (const [key, value] of props) { - if (key !== 'constructor') { + if (key !== 'constructor') { assert(value.enumerable, `${key} is not enumerable`) } }