From e2395b0f3b1a4cf2fee43d5937d16dcff1c9c2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 27 Sep 2020 17:39:01 +0200 Subject: [PATCH] lib: use Object static properties from primordials MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/35380 Reviewed-By: Matteo Collina Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca Reviewed-By: Gerhard Stöbich Reviewed-By: Ricky Zhou <0x19951125@gmail.com> Reviewed-By: Daijiro Wachi --- lib/internal/abort_controller.js | 9 +++++---- lib/internal/event_target.js | 15 ++++++++------- lib/internal/modules/cjs/loader.js | 9 +++------ lib/timers.js | 10 +++++----- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/internal/abort_controller.js b/lib/internal/abort_controller.js index 95584feeeecb84..0db98f903a1556 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, ObjectSetPrototypeOf, ObjectDefineProperty, Symbol, @@ -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 }); @@ -69,7 +70,7 @@ class AbortSignal extends EventTarget { } } -Object.defineProperties(AbortSignal.prototype, { +ObjectDefineProperties(AbortSignal.prototype, { aborted: { enumerable: true } }); @@ -131,7 +132,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 31e23feeb55f67..e63b5f2af1f902 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -5,7 +5,8 @@ const { Boolean, Error, NumberIsInteger, - Object, + ObjectAssign, + ObjectDefineProperties, ObjectDefineProperty, ObjectGetOwnPropertyDescriptor, ReflectApply, @@ -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 }); @@ -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, @@ -417,7 +418,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 }); @@ -425,12 +426,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, @@ -511,7 +512,7 @@ class NodeEventTarget extends EventTarget { } } -Object.defineProperties(NodeEventTarget.prototype, { +ObjectDefineProperties(NodeEventTarget.prototype, { setMaxListeners: { enumerable: true }, getMaxListeners: { enumerable: true }, eventNames: { enumerable: true }, diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index ebe0c741c9e177..dd1fe209b28652 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, @@ -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 @@ -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); } } diff --git a/lib/timers.js b/lib/timers.js index 6732ae06bc0b2e..fdeb92b1c1b5d3 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -22,10 +22,10 @@ 'use strict'; const { - ObjectCreate, MathTrunc, - Object, - SymbolToPrimitive, + ObjectCreate, + ObjectDefineProperty, + SymbolToPrimitive } = primordials; const { @@ -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)