Skip to content

Commit

Permalink
lib: use Object static properties from primordials
Browse files Browse the repository at this point in the history
PR-URL: #35380
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Ricky Zhou <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
  • Loading branch information
targos committed May 16, 2021
1 parent eee1d29 commit e2395b0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
9 changes: 5 additions & 4 deletions lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// in https://github.com/mysticatea/abort-controller (MIT license)

const {
Object,
ObjectAssign,
ObjectDefineProperties,
ObjectSetPrototypeOf,
ObjectDefineProperty,
Symbol,
Expand Down Expand Up @@ -35,7 +36,7 @@ function customInspect(self, obj, depth, options) {
if (depth < 0)
return self;

const opts = Object.assign({}, options, {
const opts = ObjectAssign({}, options, {
depth: options.depth === null ? null : options.depth - 1
});

Expand Down Expand Up @@ -69,7 +70,7 @@ class AbortSignal extends EventTarget {
}
}

Object.defineProperties(AbortSignal.prototype, {
ObjectDefineProperties(AbortSignal.prototype, {
aborted: { enumerable: true }
});

Expand Down Expand Up @@ -131,7 +132,7 @@ class AbortController {
}
}

Object.defineProperties(AbortController.prototype, {
ObjectDefineProperties(AbortController.prototype, {
signal: { enumerable: true },
abort: { enumerable: true }
});
Expand Down
15 changes: 8 additions & 7 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const {
Boolean,
Error,
NumberIsInteger,
Object,
ObjectAssign,
ObjectDefineProperties,
ObjectDefineProperty,
ObjectGetOwnPropertyDescriptor,
ReflectApply,
Expand Down Expand Up @@ -108,7 +109,7 @@ class Event {
if (depth < 0)
return name;

const opts = Object.assign({}, options, {
const opts = ObjectAssign({}, options, {
depth: NumberIsInteger(options.depth) ? options.depth - 1 : options.depth
});

Expand Down Expand Up @@ -170,7 +171,7 @@ class Event {
static BUBBLING_PHASE = 3;
}

Object.defineProperty(Event.prototype, SymbolToStringTag, {
ObjectDefineProperty(Event.prototype, SymbolToStringTag, {
writable: false,
enumerable: false,
configurable: true,
Expand Down Expand Up @@ -417,20 +418,20 @@ class EventTarget {
if (depth < 0)
return name;

const opts = Object.assign({}, options, {
const opts = ObjectAssign({}, options, {
depth: NumberIsInteger(options.depth) ? options.depth - 1 : options.depth
});

return `${name} ${inspect({}, opts)}`;
}
}

Object.defineProperties(EventTarget.prototype, {
ObjectDefineProperties(EventTarget.prototype, {
addEventListener: { enumerable: true },
removeEventListener: { enumerable: true },
dispatchEvent: { enumerable: true }
});
Object.defineProperty(EventTarget.prototype, SymbolToStringTag, {
ObjectDefineProperty(EventTarget.prototype, SymbolToStringTag, {
writable: false,
enumerable: false,
configurable: true,
Expand Down Expand Up @@ -511,7 +512,7 @@ class NodeEventTarget extends EventTarget {
}
}

Object.defineProperties(NodeEventTarget.prototype, {
ObjectDefineProperties(NodeEventTarget.prototype, {
setMaxListeners: { enumerable: true },
getMaxListeners: { enumerable: true },
eventNames: { enumerable: true },
Expand Down
9 changes: 3 additions & 6 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
ObjectGetOwnPropertyDescriptor,
ObjectGetPrototypeOf,
ObjectKeys,
ObjectPrototype,
ObjectPrototypeHasOwnProperty,
ObjectSetPrototypeOf,
ReflectSet,
Expand Down Expand Up @@ -678,14 +679,10 @@ const CircularRequirePrototypeWarningProxy = new Proxy({}, {
}
});

// Object.prototype and ObjectPrototype refer to our 'primordials' versions
// and are not identical to the versions on the global object.
const PublicObjectPrototype = global.Object.prototype;

function getExportsForCircularRequire(module) {
if (module.exports &&
!isProxy(module.exports) &&
ObjectGetPrototypeOf(module.exports) === PublicObjectPrototype &&
ObjectGetPrototypeOf(module.exports) === ObjectPrototype &&
// Exclude transpiled ES6 modules / TypeScript code because those may
// employ unusual patterns for accessing 'module.exports'. That should
// be okay because ES6 modules have a different approach to circular
Expand Down Expand Up @@ -791,7 +788,7 @@ Module._load = function(request, parent, isMain) {
!isProxy(module.exports) &&
ObjectGetPrototypeOf(module.exports) ===
CircularRequirePrototypeWarningProxy) {
ObjectSetPrototypeOf(module.exports, PublicObjectPrototype);
ObjectSetPrototypeOf(module.exports, ObjectPrototype);
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
'use strict';

const {
ObjectCreate,
MathTrunc,
Object,
SymbolToPrimitive,
ObjectCreate,
ObjectDefineProperty,
SymbolToPrimitive
} = primordials;

const {
Expand Down Expand Up @@ -161,7 +161,7 @@ function setTimeout(callback, after, arg1, arg2, arg3) {
return timeout;
}

Object.defineProperty(setTimeout, customPromisify, {
ObjectDefineProperty(setTimeout, customPromisify, {
enumerable: true,
get() {
if (!timersPromises)
Expand Down Expand Up @@ -262,7 +262,7 @@ function setImmediate(callback, arg1, arg2, arg3) {
return new Immediate(callback, args);
}

Object.defineProperty(setImmediate, customPromisify, {
ObjectDefineProperty(setImmediate, customPromisify, {
enumerable: true,
get() {
if (!timersPromises)
Expand Down

0 comments on commit e2395b0

Please sign in to comment.