Skip to content

Commit a880653

Browse files
targosaddaleax
authored andcommitted
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 a77f2ea commit a880653

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
Symbol,
910
} = primordials;
1011

@@ -24,7 +25,7 @@ function customInspect(self, obj, depth, options) {
2425
if (depth < 0)
2526
return self;
2627

27-
const opts = Object.assign({}, options, {
28+
const opts = ObjectAssign({}, options, {
2829
depth: options.depth === null ? null : options.depth - 1
2930
});
3031

@@ -41,7 +42,7 @@ class AbortSignal extends EventTarget {
4142
}
4243
}
4344

44-
Object.defineProperties(AbortSignal.prototype, {
45+
ObjectDefineProperties(AbortSignal.prototype, {
4546
aborted: { enumerable: true }
4647
});
4748

@@ -75,7 +76,7 @@ class AbortController {
7576
}
7677
}
7778

78-
Object.defineProperties(AbortController.prototype, {
79+
ObjectDefineProperties(AbortController.prototype, {
7980
signal: { enumerable: true },
8081
abort: { enumerable: true }
8182
});

lib/internal/event_target.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const {
66
Error,
77
Map,
88
NumberIsInteger,
9-
Object,
9+
ObjectAssign,
10+
ObjectDefineProperties,
1011
ObjectDefineProperty,
1112
Symbol,
1213
SymbolFor,
@@ -89,7 +90,7 @@ class Event {
8990
if (depth < 0)
9091
return name;
9192

92-
const opts = Object.assign({}, options, {
93+
const opts = ObjectAssign({}, options, {
9394
depth: NumberIsInteger(options.depth) ? options.depth - 1 : options.depth
9495
});
9596

@@ -151,7 +152,7 @@ class Event {
151152
static BUBBLING_PHASE = 3;
152153
}
153154

154-
Object.defineProperty(Event.prototype, SymbolToStringTag, {
155+
ObjectDefineProperty(Event.prototype, SymbolToStringTag, {
155156
writable: false,
156157
enumerable: false,
157158
configurable: true,
@@ -369,20 +370,20 @@ class EventTarget {
369370
if (depth < 0)
370371
return name;
371372

372-
const opts = Object.assign({}, options, {
373+
const opts = ObjectAssign({}, options, {
373374
depth: NumberIsInteger(options.depth) ? options.depth - 1 : options.depth
374375
});
375376

376377
return `${name} ${inspect({}, opts)}`;
377378
}
378379
}
379380

380-
Object.defineProperties(EventTarget.prototype, {
381+
ObjectDefineProperties(EventTarget.prototype, {
381382
addEventListener: { enumerable: true },
382383
removeEventListener: { enumerable: true },
383384
dispatchEvent: { enumerable: true }
384385
});
385-
Object.defineProperty(EventTarget.prototype, SymbolToStringTag, {
386+
ObjectDefineProperty(EventTarget.prototype, SymbolToStringTag, {
386387
writable: false,
387388
enumerable: false,
388389
configurable: true,
@@ -477,7 +478,7 @@ class NodeEventTarget extends EventTarget {
477478
}
478479
}
479480

480-
Object.defineProperties(NodeEventTarget.prototype, {
481+
ObjectDefineProperties(NodeEventTarget.prototype, {
481482
setMaxListeners: { enumerable: true },
482483
getMaxListeners: { enumerable: true },
483484
eventNames: { enumerable: true },
@@ -545,7 +546,7 @@ function emitUnhandledRejectionOrErr(that, err, event) {
545546
function defineEventHandler(emitter, name) {
546547
// 8.1.5.1 Event handlers - basically `on[eventName]` attributes
547548
let eventHandlerValue;
548-
Object.defineProperty(emitter, `on${name}`, {
549+
ObjectDefineProperty(emitter, `on${name}`, {
549550
get() {
550551
return eventHandlerValue;
551552
},

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,
@@ -707,14 +708,10 @@ const CircularRequirePrototypeWarningProxy = new Proxy({}, {
707708
}
708709
});
709710

710-
// Object.prototype and ObjectPrototype refer to our 'primordials' versions
711-
// and are not identical to the versions on the global object.
712-
const PublicObjectPrototype = global.Object.prototype;
713-
714711
function getExportsForCircularRequire(module) {
715712
if (module.exports &&
716713
!isProxy(module.exports) &&
717-
ObjectGetPrototypeOf(module.exports) === PublicObjectPrototype &&
714+
ObjectGetPrototypeOf(module.exports) === ObjectPrototype &&
718715
// Exclude transpiled ES6 modules / TypeScript code because those may
719716
// employ unusual patterns for accessing 'module.exports'. That should
720717
// be okay because ES6 modules have a different approach to circular
@@ -820,7 +817,7 @@ Module._load = function(request, parent, isMain) {
820817
!isProxy(module.exports) &&
821818
ObjectGetPrototypeOf(module.exports) ===
822819
CircularRequirePrototypeWarningProxy) {
823-
ObjectSetPrototypeOf(module.exports, PublicObjectPrototype);
820+
ObjectSetPrototypeOf(module.exports, ObjectPrototype);
824821
}
825822
}
826823

lib/timers.js

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

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

@@ -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)