Skip to content

Commit 3844af2

Browse files
BenzeneAlcoholUlisesGascon
authored andcommitted
lib: make 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: #50417 PR-URL: #50425 Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Matthew Aitken <[email protected]>
1 parent 9950203 commit 3844af2

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

‎lib/internal/event_target.js‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const{
44
ArrayFrom,
5+
ArrayPrototypeReduce,
56
Boolean,
67
Error,
78
FunctionPrototypeCall,
@@ -318,11 +319,6 @@ class Event{
318319
thrownewERR_INVALID_THIS('Event');
319320
this.#propagationStopped =true;
320321
}
321-
322-
staticNONE=0;
323-
staticCAPTURING_PHASE=1;
324-
staticAT_TARGET=2;
325-
staticBUBBLING_PHASE=3;
326322
}
327323

328324
ObjectDefineProperties(
@@ -358,6 +354,22 @@ ObjectDefineProperties(
358354
isTrusted: isTrustedDescriptor,
359355
});
360356

357+
conststaticProps=['NONE','CAPTURING_PHASE','AT_TARGET','BUBBLING_PHASE'];
358+
359+
ObjectDefineProperties(
360+
Event,
361+
ArrayPrototypeReduce(staticProps,(result,staticProp,index=0)=>{
362+
result[staticProp]={
363+
__proto__: null,
364+
writable: false,
365+
configurable: false,
366+
enumerable: true,
367+
value: index,
368+
};
369+
returnresult;
370+
},{}),
371+
);
372+
361373
functionisCustomEvent(value){
362374
returnisEvent(value)&&(value?.[kDetail]!==undefined);
363375
}

‎test/parallel/test-event-target.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
require('../common');
4+
constassert=require('assert');
5+
6+
consteventPhases={
7+
'NONE': 0,
8+
'CAPTURING_PHASE': 1,
9+
'AT_TARGET': 2,
10+
'BUBBLING_PHASE': 3
11+
};
12+
13+
for(const[prop,value]ofObject.entries(eventPhases)){
14+
// Check if the value of the property matches the expected value
15+
assert.strictEqual(Event[prop],value,`Expected Event.${prop} to be ${value}, but got ${Event[prop]}`);
16+
17+
constdesc=Object.getOwnPropertyDescriptor(Event,prop);
18+
assert.strictEqual(desc.writable,false,`${prop} should not be writable`);
19+
assert.strictEqual(desc.configurable,false,`${prop} should not be configurable`);
20+
assert.strictEqual(desc.enumerable,true,`${prop} should be enumerable`);
21+
}

0 commit comments

Comments
(0)