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 <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>
  • Loading branch information
targos authored and addaleax committed Sep 30, 2020
1 parent a77f2ea commit a880653
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,
Symbol,
} = primordials;

Expand All @@ -24,7 +25,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 All @@ -41,7 +42,7 @@ class AbortSignal extends EventTarget {
}
}

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

Expand Down Expand Up @@ -75,7 +76,7 @@ class AbortController {
}
}

Object.defineProperties(AbortController.prototype, {
ObjectDefineProperties(AbortController.prototype, {
signal: { enumerable: true },
abort: { enumerable: true }
});
Expand Down
17 changes: 9 additions & 8 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const {
Error,
Map,
NumberIsInteger,
Object,
ObjectAssign,
ObjectDefineProperties,
ObjectDefineProperty,
Symbol,
SymbolFor,
Expand Down Expand Up @@ -89,7 +90,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 @@ -151,7 +152,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 @@ -369,20 +370,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 @@ -477,7 +478,7 @@ class NodeEventTarget extends EventTarget {
}
}

Object.defineProperties(NodeEventTarget.prototype, {
ObjectDefineProperties(NodeEventTarget.prototype, {
setMaxListeners: { enumerable: true },
getMaxListeners: { enumerable: true },
eventNames: { enumerable: true },
Expand Down Expand Up @@ -545,7 +546,7 @@ function emitUnhandledRejectionOrErr(that, err, event) {
function defineEventHandler(emitter, name) {
// 8.1.5.1 Event handlers - basically `on[eventName]` attributes
let eventHandlerValue;
Object.defineProperty(emitter, `on${name}`, {
ObjectDefineProperty(emitter, `on${name}`, {
get() {
return eventHandlerValue;
},
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 @@ -707,14 +708,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 @@ -820,7 +817,7 @@ Module._load = function(request, parent, isMain) {
!isProxy(module.exports) &&
ObjectGetPrototypeOf(module.exports) ===
CircularRequirePrototypeWarningProxy) {
ObjectSetPrototypeOf(module.exports, PublicObjectPrototype);
ObjectSetPrototypeOf(module.exports, ObjectPrototype);
}
}

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

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

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 a880653

Please sign in to comment.