From 0646eda4fc0affb98e13c30acb522e63b7fd6dde Mon Sep 17 00:00:00 2001 From: Michaƫl Zasso Date: Fri, 22 Nov 2019 18:04:46 +0100 Subject: lib: flatten access to primordials Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: Colin Ihrig Reviewed-By: Trivikram Kamat --- lib/domain.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'lib/domain.js') diff --git a/lib/domain.js b/lib/domain.js index c3e38ba832..7c35a7c81a 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -26,7 +26,10 @@ // No new pull requests targeting this module will be accepted // unless they address existing, critical bugs. -const { Object, Reflect } = primordials; +const { + ObjectDefineProperty, + ReflectApply, +} = primordials; const EventEmitter = require('events'); const { @@ -43,7 +46,7 @@ const { WeakReference } = internalBinding('util'); // Overwrite process.domain with a getter/setter that will allow for more // effective optimizations const _domain = [null]; -Object.defineProperty(process, 'domain', { +ObjectDefineProperty(process, 'domain', { enumerable: true, get: function() { return _domain[0]; @@ -59,7 +62,7 @@ const asyncHook = createHook({ if (process.domain !== null && process.domain !== undefined) { // If this operation is created while in a domain, let's mark it pairing.set(asyncId, process.domain[kWeak]); - Object.defineProperty(resource, 'domain', { + ObjectDefineProperty(resource, 'domain', { configurable: true, enumerable: false, value: process.domain, @@ -127,7 +130,7 @@ function topLevelDomainCallback(cb, ...args) { if (domain) domain.enter(); - const ret = Reflect.apply(cb, this, args); + const ret = ReflectApply(cb, this, args); if (domain) domain.exit(); @@ -207,7 +210,7 @@ Domain.prototype._errorHandler = function(er) { let caught = false; if ((typeof er === 'object' && er !== null) || typeof er === 'function') { - Object.defineProperty(er, 'domain', { + ObjectDefineProperty(er, 'domain', { configurable: true, enumerable: false, value: this, @@ -332,7 +335,7 @@ Domain.prototype.add = function(ee) { } } - Object.defineProperty(ee, 'domain', { + ObjectDefineProperty(ee, 'domain', { configurable: true, enumerable: false, value: this, @@ -376,7 +379,7 @@ function intercepted(_this, self, cb, fnargs) { const er = fnargs[0]; er.domainBound = cb; er.domainThrown = false; - Object.defineProperty(er, 'domain', { + ObjectDefineProperty(er, 'domain', { configurable: true, enumerable: false, value: self, @@ -435,7 +438,7 @@ Domain.prototype.bind = function(cb) { return bound(this, self, cb, arguments); } - Object.defineProperty(runBound, 'domain', { + ObjectDefineProperty(runBound, 'domain', { configurable: true, enumerable: false, value: this, @@ -450,7 +453,7 @@ EventEmitter.usingDomains = true; const eventInit = EventEmitter.init; EventEmitter.init = function() { - Object.defineProperty(this, 'domain', { + ObjectDefineProperty(this, 'domain', { configurable: true, enumerable: false, value: null, @@ -475,7 +478,7 @@ EventEmitter.prototype.emit = function(...args) { // handler, there's no active domain or this is process if (shouldEmitError || domain === null || domain === undefined || this === process) { - return Reflect.apply(eventEmit, this, args); + return ReflectApply(eventEmit, this, args); } if (type === 'error') { @@ -484,7 +487,7 @@ EventEmitter.prototype.emit = function(...args) { if (typeof er === 'object') { er.domainEmitter = this; - Object.defineProperty(er, 'domain', { + ObjectDefineProperty(er, 'domain', { configurable: true, enumerable: false, value: domain, @@ -537,7 +540,7 @@ EventEmitter.prototype.emit = function(...args) { } domain.enter(); - const ret = Reflect.apply(eventEmit, this, args); + const ret = ReflectApply(eventEmit, this, args); domain.exit(); return ret; -- cgit v1.2.3