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 constant
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 Nov 1, 2023
1 parent 6431c65 commit 53502c7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
37 changes: 32 additions & 5 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,6 @@ class Event {
throw new ERR_INVALID_THIS('Event');
this.#propagationStopped = true;
}

static NONE = 0;
static CAPTURING_PHASE = 1;
static AT_TARGET = 2;
static BUBBLING_PHASE = 3;
}

ObjectDefineProperties(
Expand Down Expand Up @@ -354,6 +349,38 @@ ObjectDefineProperties(
isTrusted: isTrustedDescriptor,
});

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);
}

0 comments on commit 53502c7

Please sign in to comment.