Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,11 @@ const kEnumerableProperty = {
enumerable: true
}

const kNonEnumerableProperty = {
__proto__: null,
enumerable: false
}

const normalizedMethodRecordsBase = {
delete: 'DELETE',
DELETE: 'DELETE',
Expand Down Expand Up @@ -1003,6 +1008,7 @@ Object.setPrototypeOf(normalizedMethodRecords, null)

module.exports = {
kEnumerableProperty,
kNonEnumerableProperty,
isDisturbed,
isBlobLike,
parseOrigin,
Expand Down
4 changes: 3 additions & 1 deletion lib/web/websocket/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {
} = require('./util')
const { establishWebSocketConnection, closeWebSocketConnection, failWebsocketConnection } = require('./connection')
const { ByteParser } = require('./receiver')
const { kEnumerableProperty } = require('../../core/util')
const { kEnumerableProperty, kNonEnumerableProperty } = require('../../core/util')
const { getGlobalDispatcher } = require('../../global')
const { ErrorEvent, CloseEvent, createFastMessageEvent } = require('./events')
const { SendQueue } = require('./sender')
Expand Down Expand Up @@ -691,6 +691,8 @@ WebSocket.CLOSING = WebSocket.prototype.CLOSING = states.CLOSING
WebSocket.CLOSED = WebSocket.prototype.CLOSED = states.CLOSED

Object.defineProperties(WebSocket.prototype, {
[kRef]: kNonEnumerableProperty,
[kUnref]: kNonEnumerableProperty,
CONNECTING: staticPropertyDescriptors,
OPEN: staticPropertyDescriptors,
CLOSING: staticPropertyDescriptors,
Expand Down
15 changes: 15 additions & 0 deletions test/websocket/non-enum-ref.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

const { test } = require('node:test')
const { WebSocket } = require('../..')
const kRef = Symbol.for('nodejs.ref')
const kUnref = Symbol.for('nodejs.unref')

test('kRef/kUnref are non-enumerable on WebSocket.prototype', async (t) => {
const refDesc = Object.getOwnPropertyDescriptor(WebSocket.prototype, kRef)
console.log(refDesc)
t.assert.ok(!refDesc.enumerable)

const unrefDesc = Object.getOwnPropertyDescriptor(WebSocket.prototype, kUnref)
t.assert.ok(!unrefDesc.enumerable)
})
Loading