Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make EventSource properties enumerable #2987

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/web/eventsource/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
])


Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
module.exports = {
EventSource,
defaultReconnectionTime
Expand Down
15 changes: 15 additions & 0 deletions test/eventsource/eventsource-properties.js
Original file line number Diff line number Diff line change
@@ -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))
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved

for (const [key, value] of props) {
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
if (key !== 'constructor') {
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
assert(value.enumerable, `${key} is not enumerable`)
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
}
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
}
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
})
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved