Skip to content

Commit cd1ea26

Browse files
committed
lib: use __proto__: null when calling ObjectDefineProperty
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #64239 Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
1 parent 34d09a7 commit cd1ea26

5 files changed

Lines changed: 28 additions & 17 deletions

File tree

‎lib/internal/debugger/inspect_repl.js‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ const {
1919
JSONStringify,
2020
MathMax,
2121
ObjectAssign,
22+
ObjectDefineProperties,
2223
ObjectDefineProperty,
24+
ObjectGetOwnPropertyDescriptors,
2325
ObjectKeys,
26+
ObjectSetPrototypeOf,
2427
ObjectValues,
2528
Promise,
2629
PromisePrototypeThen,
2730
PromiseResolve,
2831
PromiseWithResolvers,
2932
ReflectGetOwnPropertyDescriptor,
30-
ReflectOwnKeys,
3133
RegExpPrototypeExec,
3234
SafeMap,
3335
SafePromiseAllReturnArrayLike,
@@ -347,18 +349,20 @@ class ScopeSnapshot {
347349
}
348350

349351
functioncopyOwnProperties(target,source){
350-
ArrayPrototypeForEach(
351-
ReflectOwnKeys(source),
352-
(prop)=>{
353-
constdesc=ReflectGetOwnPropertyDescriptor(source,prop);
354-
ObjectDefineProperty(target,prop,desc);
355-
});
352+
constdescriptors=ObjectGetOwnPropertyDescriptors(source);
353+
354+
constdescValues=ObjectValues(descriptors);
355+
for(leti=0;i<descValues.length;++i){
356+
ObjectSetPrototypeOf(descValues[i],null);
357+
}
358+
359+
ObjectDefineProperties(target,descriptors);
356360
}
357361

358362
functionaliasProperties(target,mapping){
359363
ArrayPrototypeForEach(ObjectKeys(mapping),(key)=>{
360364
constdesc=ReflectGetOwnPropertyDescriptor(target,key);
361-
ObjectDefineProperty(target,mapping[key],desc);
365+
ObjectDefineProperty(target,mapping[key],{__proto__: null, ...desc});
362366
});
363367
}
364368

‎lib/internal/http2/core.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,6 +3246,7 @@ function handleHeaderContinue(headers) {
32463246
}
32473247

32483248
constsetTimeoutValue={
3249+
__proto__: null,
32493250
configurable: true,
32503251
enumerable: true,
32513252
writable: true,

‎lib/internal/per_context/domexception.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ for (const { 0: name, 1: codeName, 2: value } of [
196196
// There are some more error names, but since they don't have codes assigned,
197197
// we don't need to care about them.
198198
]){
199-
constdesc={enumerable: true, value };
199+
constdesc={__proto__: null,enumerable: true, value };
200200
ObjectDefineProperty(DOMException,codeName,desc);
201201
ObjectDefineProperty(DOMExceptionPrototype,codeName,desc);
202202
nameToCodeMap.set(name,value);

‎lib/internal/test_runner/mock/mock.js‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ const {
77
FunctionPrototypeBind,
88
FunctionPrototypeCall,
99
ObjectAssign,
10+
ObjectDefineProperties,
1011
ObjectDefineProperty,
1112
ObjectGetOwnPropertyDescriptor,
13+
ObjectGetOwnPropertyDescriptors,
1214
ObjectGetPrototypeOf,
1315
ObjectKeys,
16+
ObjectSetPrototypeOf,
17+
ObjectValues,
1418
Proxy,
1519
ReflectApply,
1620
ReflectConstruct,
@@ -146,7 +150,7 @@ class MockFunctionContext {
146150

147151
if(typeofmethodName==='string'){
148152
// This is an object method spy.
149-
ObjectDefineProperty(object,methodName,descriptor);
153+
ObjectDefineProperty(object,methodName,{__proto__: null, ...descriptor});
150154
}else{
151155
// This is a bare function spy. There isn't much to do here but make
152156
// the mock call the original function.
@@ -880,13 +884,14 @@ function normalizeModuleMockOptions(options) {
880884

881885

882886
functioncopyOwnProperties(from,to){
883-
constkeys=ObjectKeys(from);
887+
constdescriptors=ObjectGetOwnPropertyDescriptors(from);
884888

885-
for(leti=0;i<keys.length;++i){
886-
constkey=keys[i];
887-
constdescriptor=ObjectGetOwnPropertyDescriptor(from,key);
888-
ObjectDefineProperty(to,key,descriptor);
889+
constdescValues=ObjectValues(descriptors);
890+
for(leti=0;i<descValues.length;++i){
891+
ObjectSetPrototypeOf(descValues[i],null);
889892
}
893+
894+
ObjectDefineProperties(to,descriptors);
890895
}
891896

892897
functionsetupSharedModuleState(){

‎lib/internal/test_runner/mock/mock_timers.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
ObjectDefineProperty,
1414
ObjectGetOwnPropertyDescriptor,
1515
ObjectGetOwnPropertyDescriptors,
16+
ObjectSetPrototypeOf,
1617
PromiseWithResolvers,
1718
Symbol,
1819
SymbolDispose,
@@ -325,7 +326,7 @@ class MockTimers {
325326
}
326327

327328
#restoreOriginalAbortSignalTimeout(){
328-
ObjectDefineProperty(AbortSignal,'timeout',this.#realAbortSignalTimeout);
329+
ObjectDefineProperty(AbortSignal,'timeout',ObjectSetPrototypeOf(this.#realAbortSignalTimeout,null));
329330
}
330331

331332
#createTimer(isInterval,callback,delay, ...args){
@@ -633,7 +634,7 @@ class MockTimers {
633634
);
634635
},
635636
'Date': ()=>{
636-
this.#nativeDateDescriptor =ObjectGetOwnPropertyDescriptor(globalThis,'Date');
637+
this.#nativeDateDescriptor =ObjectSetPrototypeOf(ObjectGetOwnPropertyDescriptor(globalThis,'Date'),null);
637638
globalThis.Date=this.#createDate();
638639
},
639640
'AbortSignal.timeout': ()=>{

0 commit comments

Comments
 (0)