diff --git a/lib/internal/abort_controller.js b/lib/internal/abort_controller.js index 45ffb7aee8db6a..b3568ce2093889 100644 --- a/lib/internal/abort_controller.js +++ b/lib/internal/abort_controller.js @@ -4,7 +4,8 @@ // in https://github.com/mysticatea/abort-controller (MIT license) const { - Object, + ObjectAssign, + ObjectDefineProperties, Symbol, } = primordials; @@ -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 }); @@ -41,7 +42,7 @@ class AbortSignal extends EventTarget { } } -Object.defineProperties(AbortSignal.prototype, { +ObjectDefineProperties(AbortSignal.prototype, { aborted: { enumerable: true } }); @@ -75,7 +76,7 @@ class AbortController { } } -Object.defineProperties(AbortController.prototype, { +ObjectDefineProperties(AbortController.prototype, { signal: { enumerable: true }, abort: { enumerable: true } }); diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 8f0657c8d5b193..f9dda75f0465df 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -6,7 +6,8 @@ const { Error, Map, NumberIsInteger, - Object, + ObjectAssign, + ObjectDefineProperties, ObjectDefineProperty, Symbol, SymbolFor, @@ -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 }); @@ -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, @@ -369,7 +370,7 @@ 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 }); @@ -377,12 +378,12 @@ class EventTarget { } } -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, @@ -477,7 +478,7 @@ class NodeEventTarget extends EventTarget { } } -Object.defineProperties(NodeEventTarget.prototype, { +ObjectDefineProperties(NodeEventTarget.prototype, { setMaxListeners: { enumerable: true }, getMaxListeners: { enumerable: true }, eventNames: { enumerable: true }, @@ -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; }, diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index a745c66c6142a2..6f47bbc7144361 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -33,6 +33,7 @@ const { ObjectGetOwnPropertyDescriptor, ObjectGetPrototypeOf, ObjectKeys, + ObjectPrototype, ObjectPrototypeHasOwnProperty, ObjectSetPrototypeOf, ReflectSet, @@ -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 @@ -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); } } diff --git a/lib/timers.js b/lib/timers.js index f7106c90cbff10..6cb64b98b5cdc0 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -22,9 +22,9 @@ 'use strict'; const { - ObjectCreate, MathTrunc, - Object, + ObjectCreate, + ObjectDefineProperty, SymbolToPrimitive } = primordials; @@ -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) @@ -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)