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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/web/eventsource/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
const { MessageEvent } = require('../websocket/events')
const { isNetworkError } = require('../fetch/response')
const { delay } = require('./util')
const { kEnumerableProperty } = require('../../core/util')

let experimentalWarned = false

Expand Down Expand Up @@ -459,10 +460,21 @@
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,

Check failure on line 470 in lib/web/eventsource/eventsource.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected trailing comma
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
})

webidl.converters.EventSourceInitDict = webidl.dictionaryConverter([
{ key: 'withCredentials', converter: webidl.converters.boolean, defaultValue: false }
])


Check failure on line 477 in lib/web/eventsource/eventsource.js

View workflow job for this annotation

GitHub Actions / Lint

More than 1 blank line not allowed
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))

Check failure on line 8 in test/eventsource/eventsource-properties.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved

for (const [key, value] of props) {

Check failure on line 10 in test/eventsource/eventsource-properties.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
if (key !== 'constructor') {

Check failure on line 11 in test/eventsource/eventsource-properties.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 8
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
assert(value.enumerable, `${key} is not enumerable`)

Check failure on line 12 in test/eventsource/eventsource-properties.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 6 spaces but found 12
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
}

Check failure on line 13 in test/eventsource/eventsource-properties.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 8
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
}

Check failure on line 14 in test/eventsource/eventsource-properties.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
})

Check failure on line 15 in test/eventsource/eventsource-properties.js

View workflow job for this annotation

GitHub Actions / Lint

Newline required at end of file but not found
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
Loading