From 53502c7e929d017df25b131234456ca2ebf96ff8 Mon Sep 17 00:00:00 2001 From: BenzeneAlcohol Date: Fri, 27 Oct 2023 16:43:16 +0530 Subject: [PATCH] lib: event static properties non writable and configurable 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: https://github.com/nodejs/node/issues/50417 --- lib/internal/event_target.js | 37 ++++++++++++++++++++++++++---- test/parallel/test-event-target.js | 13 +++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 test/parallel/test-event-target.js diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 0236f3a53c5276..660c2456cc02bc 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -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( @@ -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); } diff --git a/test/parallel/test-event-target.js b/test/parallel/test-event-target.js new file mode 100644 index 00000000000000..4490faeecfba6a --- /dev/null +++ b/test/parallel/test-event-target.js @@ -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); +}