Skip to content

Commit

Permalink
lib: Event static properties non configurable and writable
Browse files Browse the repository at this point in the history
The idl definition for Event makes the properties constants, this means
that they shouldn't be configurable. However, they were, and this commit
fixes that.

Fixes: nodejs#50417
  • Loading branch information
BenzeneAlcohol committed Oct 27, 2023
1 parent 6431c65 commit e867c32
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,33 @@ ObjectDefineProperties(
isTrusted: isTrustedDescriptor,
});

Object.defineProperties(Event, {
NONE: {
writable: false,
configurable: false,
enumerable: true,
value: 0,
},
CAPTURING_PHASE: {
writable: false,
configurable: false,
enumerable: true,
value: 1,
},
AT_TARGET: {
writable: false,
configurable: false,
enumerable: true,
value: 2,
},
BUBBLING_PHASE: {
writable: false,
configurable: false,
enumerable: true,
value: 3,
}
});

function isCustomEvent(value) {
return isEvent(value) && (value?.[kDetail] !== undefined);
}
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';
const assert = require('assert');

const props = ['NONE', 'CAPTURING_PHASE', 'AT_TARGET', 'BUBBLING_PHASE']

for (const prop of props) {
const desc = Object.getOwnPropertyDescriptor(Event, prop)
assert.strictEqual(desc.writable, false)
assert.strictEqual(desc.configurable, false)
assert.strictEqual(desc.enumerable, true)
}

0 comments on commit e867c32

Please sign in to comment.