Skip to content

Commit

Permalink
lib: event static properties non writable and configurable
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 and writable.
However, they were, and this commit fixes that.

Fixes: #50417
  • Loading branch information
BenzeneAlcohol committed Oct 30, 2023
1 parent c4685ee commit e90fbb1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 37 deletions.
57 changes: 31 additions & 26 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,32 +349,37 @@ 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,
}
});
ObjectDefineProperties(
Event, {
NONE: {
__proto__: null,
writable: false,
configurable: false,
enumerable: true,
value: 0,
},
CAPTURING_PHASE: {
__proto__: null,
writable: false,
configurable: false,
enumerable: true,
value: 1,
},
AT_TARGET: {
__proto__: null,
writable: false,
configurable: false,
enumerable: true,
value: 2,
},
BUBBLING_PHASE: {
__proto__: null,
writable: false,
configurable: false,
enumerable: true,
value: 3,
},
});

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

require('../common');
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);
}
11 changes: 0 additions & 11 deletions test/parallel/test-event.js

This file was deleted.

0 comments on commit e90fbb1

Please sign in to comment.