Skip to content

Commit e2395b0

Browse files
committed
lib: use Object static properties from primordials
PR-URL: #35380 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Ricky Zhou <0x19951125@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
1 parent eee1d29 commit e2395b0

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

lib/internal/abort_controller.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
// in https://github.com/mysticatea/abort-controller (MIT license)
55

66
const {
7-
Object,
7+
ObjectAssign,
8+
ObjectDefineProperties,
89
ObjectSetPrototypeOf,
910
ObjectDefineProperty,
1011
Symbol,
@@ -35,7 +36,7 @@ function customInspect(self, obj, depth, options) {
3536
if (depth < 0)
3637
return self;
3738

38-
const opts = Object.assign({}, options, {
39+
const opts = ObjectAssign({}, options, {
3940
depth: options.depth === null ? null : options.depth - 1
4041
});
4142

@@ -69,7 +70,7 @@ class AbortSignal extends EventTarget {
6970
}
7071
}
7172

72-
Object.defineProperties(AbortSignal.prototype, {
73+
ObjectDefineProperties(AbortSignal.prototype, {
7374
aborted: { enumerable: true }
7475
});
7576

@@ -131,7 +132,7 @@ class AbortController {
131132
}
132133
}
133134

134-
Object.defineProperties(AbortController.prototype, {
135+
ObjectDefineProperties(AbortController.prototype, {
135136
signal: { enumerable: true },
136137
abort: { enumerable: true }
137138
});

lib/internal/event_target.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const {
55
Boolean,
66
Error,
77
NumberIsInteger,
8-
Object,
8+
ObjectAssign,
9+
ObjectDefineProperties,
910
ObjectDefineProperty,
1011
ObjectGetOwnPropertyDescriptor,
1112
ReflectApply,
@@ -108,7 +109,7 @@ class Event {
108109
if (depth < 0)
109110
return name;
110111

111-
const opts = Object.assign({}, options, {
112+
const opts = ObjectAssign({}, options, {
112113
depth: NumberIsInteger(options.depth) ? options.depth - 1 : options.depth
113114
});
114115

@@ -170,7 +171,7 @@ class Event {
170171
static BUBBLING_PHASE = 3;
171172
}
172173

173-
Object.defineProperty(Event.prototype, SymbolToStringTag, {
174+
ObjectDefineProperty(Event.prototype, SymbolToStringTag, {
174175
writable: false,
175176
enumerable: false,
176177
configurable: true,
@@ -417,20 +418,20 @@ class EventTarget {
417418
if (depth < 0)
418419
return name;
419420

420-
const opts = Object.assign({}, options, {
421+
const opts = ObjectAssign({}, options, {
421422
depth: NumberIsInteger(options.depth) ? options.depth - 1 : options.depth
422423
});
423424

424425
return `${name} ${inspect({}, opts)}`;
425426
}
426427
}
427428

428-
Object.defineProperties(EventTarget.prototype, {
429+
ObjectDefineProperties(EventTarget.prototype, {
429430
addEventListener: { enumerable: true },
430431
removeEventListener: { enumerable: true },
431432
dispatchEvent: { enumerable: true }
432433
});
433-
Object.defineProperty(EventTarget.prototype, SymbolToStringTag, {
434+
ObjectDefineProperty(EventTarget.prototype, SymbolToStringTag, {
434435
writable: false,
435436
enumerable: false,
436437
configurable: true,
@@ -511,7 +512,7 @@ class NodeEventTarget extends EventTarget {
511512
}
512513
}
513514

514-
Object.defineProperties(NodeEventTarget.prototype, {
515+
ObjectDefineProperties(NodeEventTarget.prototype, {
515516
setMaxListeners: { enumerable: true },
516517
getMaxListeners: { enumerable: true },
517518
eventNames: { enumerable: true },

lib/internal/modules/cjs/loader.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const {
3333
ObjectGetOwnPropertyDescriptor,
3434
ObjectGetPrototypeOf,
3535
ObjectKeys,
36+
ObjectPrototype,
3637
ObjectPrototypeHasOwnProperty,
3738
ObjectSetPrototypeOf,
3839
ReflectSet,
@@ -678,14 +679,10 @@ const CircularRequirePrototypeWarningProxy = new Proxy({}, {
678679
}
679680
});
680681

681-
// Object.prototype and ObjectPrototype refer to our 'primordials' versions
682-
// and are not identical to the versions on the global object.
683-
const PublicObjectPrototype = global.Object.prototype;
684-
685682
function getExportsForCircularRequire(module) {
686683
if (module.exports &&
687684
!isProxy(module.exports) &&
688-
ObjectGetPrototypeOf(module.exports) === PublicObjectPrototype &&
685+
ObjectGetPrototypeOf(module.exports) === ObjectPrototype &&
689686
// Exclude transpiled ES6 modules / TypeScript code because those may
690687
// employ unusual patterns for accessing 'module.exports'. That should
691688
// be okay because ES6 modules have a different approach to circular
@@ -791,7 +788,7 @@ Module._load = function(request, parent, isMain) {
791788
!isProxy(module.exports) &&
792789
ObjectGetPrototypeOf(module.exports) ===
793790
CircularRequirePrototypeWarningProxy) {
794-
ObjectSetPrototypeOf(module.exports, PublicObjectPrototype);
791+
ObjectSetPrototypeOf(module.exports, ObjectPrototype);
795792
}
796793
}
797794

lib/timers.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
'use strict';
2323

2424
const {
25-
ObjectCreate,
2625
MathTrunc,
27-
Object,
28-
SymbolToPrimitive,
26+
ObjectCreate,
27+
ObjectDefineProperty,
28+
SymbolToPrimitive
2929
} = primordials;
3030

3131
const {
@@ -161,7 +161,7 @@ function setTimeout(callback, after, arg1, arg2, arg3) {
161161
return timeout;
162162
}
163163

164-
Object.defineProperty(setTimeout, customPromisify, {
164+
ObjectDefineProperty(setTimeout, customPromisify, {
165165
enumerable: true,
166166
get() {
167167
if (!timersPromises)
@@ -262,7 +262,7 @@ function setImmediate(callback, arg1, arg2, arg3) {
262262
return new Immediate(callback, args);
263263
}
264264

265-
Object.defineProperty(setImmediate, customPromisify, {
265+
ObjectDefineProperty(setImmediate, customPromisify, {
266266
enumerable: true,
267267
get() {
268268
if (!timersPromises)

0 commit comments

Comments
 (0)