Skip to content

Commit 34a537c

Browse files
aduh95richardlau
authored andcommitted
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 eacfbd0 commit 34a537c

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
function copyOwnProperties(target, source) {
350-
ArrayPrototypeForEach(
351-
ReflectOwnKeys(source),
352-
(prop) => {
353-
const desc = ReflectGetOwnPropertyDescriptor(source, prop);
354-
ObjectDefineProperty(target, prop, desc);
355-
});
352+
const descriptors = ObjectGetOwnPropertyDescriptors(source);
353+
354+
const descValues = ObjectValues(descriptors);
355+
for (let i = 0; i < descValues.length; ++i) {
356+
ObjectSetPrototypeOf(descValues[i], null);
357+
}
358+
359+
ObjectDefineProperties(target, descriptors);
356360
}
357361

358362
function aliasProperties(target, mapping) {
359363
ArrayPrototypeForEach(ObjectKeys(mapping), (key) => {
360364
const desc = 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
const setTimeoutValue = {
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
@@ -199,7 +199,7 @@ for (const { 0: name, 1: codeName, 2: value } of [
199199
// There are some more error names, but since they don't have codes assigned,
200200
// we don't need to care about them.
201201
]) {
202-
const desc = { enumerable: true, value };
202+
const desc = { __proto__: null, enumerable: true, value };
203203
ObjectDefineProperty(DOMException, codeName, desc);
204204
ObjectDefineProperty(DOMExceptionPrototype, codeName, desc);
205205
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 (typeof methodName === '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
function copyOwnProperties(from, to) {
883-
const keys = ObjectKeys(from);
887+
const descriptors = ObjectGetOwnPropertyDescriptors(from);
884888

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

892897
function setupSharedModuleState() {

lib/internal/test_runner/mock/mock_timers.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
ObjectDefineProperty,
1313
ObjectGetOwnPropertyDescriptor,
1414
ObjectGetOwnPropertyDescriptors,
15+
ObjectSetPrototypeOf,
1516
PromiseWithResolvers,
1617
ReflectApply,
1718
Symbol,
@@ -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)