diff options
Diffstat (limited to 'lib/internal/bootstrap')
-rw-r--r-- | lib/internal/bootstrap/loaders.js | 22 | ||||
-rw-r--r-- | lib/internal/bootstrap/node.js | 45 | ||||
-rw-r--r-- | lib/internal/bootstrap/pre_execution.js | 17 |
3 files changed, 48 insertions, 36 deletions
diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 1915dc6674..cfefc56bd8 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -44,15 +44,17 @@ /* global process, getLinkedBinding, getInternalBinding, primordials */ const { - Reflect, - Object, - ObjectPrototype, - SafeSet + ReflectGet, + ObjectCreate, + ObjectDefineProperty, + ObjectKeys, + ObjectPrototypeHasOwnProperty, + SafeSet, } = primordials; // Set up process.moduleLoadList. const moduleLoadList = []; -Object.defineProperty(process, 'moduleLoadList', { +ObjectDefineProperty(process, 'moduleLoadList', { value: moduleLoadList, configurable: true, enumerable: true, @@ -98,7 +100,7 @@ const internalBindingWhitelist = new SafeSet([ // Set up process.binding() and process._linkedBinding(). { - const bindingObj = Object.create(null); + const bindingObj = ObjectCreate(null); process.binding = function binding(module) { module = String(module); @@ -123,7 +125,7 @@ const internalBindingWhitelist = new SafeSet([ // Set up internalBinding() in the closure. let internalBinding; { - const bindingObj = Object.create(null); + const bindingObj = ObjectCreate(null); // eslint-disable-next-line no-global-assign internalBinding = function internalBinding(module) { let mod = bindingObj[module]; @@ -222,7 +224,7 @@ NativeModule.prototype.compileForPublicLoader = function() { // When using --expose-internals, we do not want to reflect the named // exports from core modules as this can trigger unnecessary getters. const internal = this.id.startsWith('internal/'); - this.exportKeys = internal ? [] : Object.keys(this.exports); + this.exportKeys = internal ? [] : ObjectKeys(this.exports); } this.getESMFacade(); this.syncExports(); @@ -230,8 +232,8 @@ NativeModule.prototype.compileForPublicLoader = function() { }; const getOwn = (target, property, receiver) => { - return ObjectPrototype.hasOwnProperty(target, property) ? - Reflect.get(target, property, receiver) : + return ObjectPrototypeHasOwnProperty(target, property) ? + ReflectGet(target, property, receiver) : undefined; }; diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 18acd9d2b6..c586ddfd5e 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -35,7 +35,14 @@ setupPrepareStackTrace(); -const { JSON, Object, Symbol } = primordials; +const { + JSONParse, + ObjectDefineProperties, + ObjectDefineProperty, + ObjectGetPrototypeOf, + ObjectSetPrototypeOf, + SymbolToStringTag, +} = primordials; const config = internalBinding('config'); const { deprecate } = require('internal/util'); @@ -64,7 +71,7 @@ if (ownsProcessState) { } // process.config is serialized config.gypi -process.config = JSON.parse(internalBinding('native_module').config); +process.config = JSONParse(internalBinding('native_module').config); const rawMethods = internalBinding('process_methods'); // Set up methods and events on the process object for the main thread @@ -205,7 +212,7 @@ const { setTraceCategoryStateUpdateHandler } = internalBinding('trace_events'); setTraceCategoryStateUpdateHandler(perThreadSetup.toggleTraceCategoryState); // process.allowedNodeEnvironmentFlags -Object.defineProperty(process, 'allowedNodeEnvironmentFlags', { +ObjectDefineProperty(process, 'allowedNodeEnvironmentFlags', { get() { const flags = perThreadSetup.buildAllowedFlags(); process.allowedNodeEnvironmentFlags = flags; @@ -214,7 +221,7 @@ Object.defineProperty(process, 'allowedNodeEnvironmentFlags', { // If the user tries to set this to another value, override // this completely to that value. set(value) { - Object.defineProperty(this, 'allowedNodeEnvironmentFlags', { + ObjectDefineProperty(this, 'allowedNodeEnvironmentFlags', { value, configurable: true, enumerable: true, @@ -234,7 +241,7 @@ process.assert = deprecate( // TODO(joyeecheung): this property has not been well-maintained, should we // deprecate it in favor of a better API? const { isDebugBuild, hasOpenSSL, hasInspector } = config; -Object.defineProperty(process, 'features', { +ObjectDefineProperty(process, 'features', { enumerable: true, writable: false, configurable: false, @@ -318,17 +325,17 @@ function setupPrepareStackTrace() { function setupProcessObject() { const EventEmitter = require('events'); - const origProcProto = Object.getPrototypeOf(process); - Object.setPrototypeOf(origProcProto, EventEmitter.prototype); + const origProcProto = ObjectGetPrototypeOf(process); + ObjectSetPrototypeOf(origProcProto, EventEmitter.prototype); EventEmitter.call(process); - Object.defineProperty(process, Symbol.toStringTag, { + ObjectDefineProperty(process, SymbolToStringTag, { enumerable: false, writable: true, configurable: false, value: 'process' }); // Make process globally available to users by putting it on the global proxy - Object.defineProperty(global, 'process', { + ObjectDefineProperty(global, 'process', { value: process, enumerable: false, writable: true, @@ -337,19 +344,19 @@ function setupProcessObject() { } function setupProcessStdio(getStdout, getStdin, getStderr) { - Object.defineProperty(process, 'stdout', { + ObjectDefineProperty(process, 'stdout', { configurable: true, enumerable: true, get: getStdout }); - Object.defineProperty(process, 'stderr', { + ObjectDefineProperty(process, 'stderr', { configurable: true, enumerable: true, get: getStderr }); - Object.defineProperty(process, 'stdin', { + ObjectDefineProperty(process, 'stdin', { configurable: true, enumerable: true, get: getStdin @@ -362,7 +369,7 @@ function setupProcessStdio(getStdout, getStdin, getStderr) { } function setupGlobalProxy() { - Object.defineProperty(global, Symbol.toStringTag, { + ObjectDefineProperty(global, SymbolToStringTag, { value: 'global', writable: false, enumerable: false, @@ -377,7 +384,7 @@ function setupGlobalProxy() { function makeSetter(name) { return deprecate(function(value) { - Object.defineProperty(this, name, { + ObjectDefineProperty(this, name, { configurable: true, writable: true, enumerable: true, @@ -386,7 +393,7 @@ function setupGlobalProxy() { }, `'${name}' is deprecated, use 'global'`, 'DEP0016'); } - Object.defineProperties(global, { + ObjectDefineProperties(global, { GLOBAL: { configurable: true, get: makeGetter('GLOBAL'), @@ -409,7 +416,7 @@ function setupBuffer() { delete bufferBinding.setBufferPrototype; delete bufferBinding.zeroFill; - Object.defineProperty(global, 'Buffer', { + ObjectDefineProperty(global, 'Buffer', { value: Buffer, enumerable: false, writable: true, @@ -436,7 +443,7 @@ function createGlobalConsole(consoleFromVM) { // https://heycam.github.io/webidl/#es-namespaces function exposeNamespace(target, name, namespaceObject) { - Object.defineProperty(target, name, { + ObjectDefineProperty(target, name, { writable: true, enumerable: false, configurable: true, @@ -446,7 +453,7 @@ function exposeNamespace(target, name, namespaceObject) { // https://heycam.github.io/webidl/#es-interfaces function exposeInterface(target, name, interfaceObject) { - Object.defineProperty(target, name, { + ObjectDefineProperty(target, name, { writable: true, enumerable: false, configurable: true, @@ -456,7 +463,7 @@ function exposeInterface(target, name, interfaceObject) { // https://heycam.github.io/webidl/#define-the-operations function defineOperation(target, name, method) { - Object.defineProperty(target, name, { + ObjectDefineProperty(target, name, { writable: true, enumerable: true, configurable: true, diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index db50c3d0ee..b373801592 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -1,6 +1,9 @@ 'use strict'; -const { Object, SafeWeakMap } = primordials; +const { + ObjectDefineProperty, + SafeWeakMap, +} = primordials; const { getOptionValue } = require('internal/options'); const { Buffer } = require('buffer'); @@ -74,7 +77,7 @@ function patchProcessObject(expandArgv1) { patchProcessObjectNative(process); - Object.defineProperty(process, 'argv0', { + ObjectDefineProperty(process, 'argv0', { enumerable: true, configurable: false, value: process.argv[0] @@ -107,7 +110,7 @@ function patchProcessObject(expandArgv1) { function addReadOnlyProcessAlias(name, option, enumerable = true) { const value = getOptionValue(option); if (value) { - Object.defineProperty(process, name, { + ObjectDefineProperty(process, name, { writable: false, configurable: true, enumerable, @@ -153,7 +156,7 @@ function initializeReport() { } const { report } = require('internal/process/report'); const { emitExperimentalWarning } = require('internal/util'); - Object.defineProperty(process, 'report', { + ObjectDefineProperty(process, 'report', { enumerable: false, configurable: true, get() { @@ -273,7 +276,7 @@ function initializeDeprecations() { // process.features. const { noBrowserGlobals } = internalBinding('config'); if (noBrowserGlobals) { - Object.defineProperty(process, '_noBrowserGlobals', { + ObjectDefineProperty(process, '_noBrowserGlobals', { writable: false, enumerable: true, configurable: true, @@ -295,7 +298,7 @@ function initializeDeprecations() { // deprecation path for these in ES Modules. // See https://github.com/nodejs/node/pull/26334. let _process = process; - Object.defineProperty(global, 'process', { + ObjectDefineProperty(global, 'process', { get() { return _process; }, @@ -307,7 +310,7 @@ function initializeDeprecations() { }); let _Buffer = Buffer; - Object.defineProperty(global, 'Buffer', { + ObjectDefineProperty(global, 'Buffer', { get() { return _Buffer; }, |