Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: use Object static properties from primordials #35380

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/internal/abort_controller.js
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
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
Expand Up @@ -39,6 +39,7 @@ const {
ObjectGetOwnPropertyDescriptor,
ObjectGetPrototypeOf,
ObjectKeys,
ObjectPrototype,
ObjectPrototypeHasOwnProperty,
ObjectSetPrototypeOf,
ReflectSet,
Expand Down Expand Up @@ -704,14 +705,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.
Comment on lines -707 to -708
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the case anymore. primordials.Object is the same as global.Object and primordials.ObjectPrototype is the same as global.Object.prototype

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 @@ -812,7 +809,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
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