mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
bootstrap: consolidate global properties definition
`globalThis.process` and `globalThis.Buffer` has been re-defined with a getter/setter pair. `atob` and `bota` are defined as enumerable properties according to WebIDL definition. PR-URL: https://github.com/nodejs/node/pull/43357 Refs: https://github.com/nodejs/node/pull/26882 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
committed by
legendecas
parent
3d0a0b6825
commit
511e289ea8
@@ -65,6 +65,13 @@ defineOperation(globalThis, 'clearTimeout', timers.clearTimeout);
|
||||
defineOperation(globalThis, 'setInterval', timers.setInterval);
|
||||
defineOperation(globalThis, 'setTimeout', timers.setTimeout);
|
||||
|
||||
const buffer = require('buffer');
|
||||
defineOperation(globalThis, 'atob', buffer.atob);
|
||||
defineOperation(globalThis, 'btoa', buffer.btoa);
|
||||
|
||||
// https://www.w3.org/TR/FileAPI/#dfn-Blob
|
||||
exposeInterface(globalThis, 'Blob', buffer.Blob);
|
||||
|
||||
// https://www.w3.org/TR/hr-time-2/#the-performance-attribute
|
||||
defineReplacableAttribute(globalThis, 'performance',
|
||||
require('perf_hooks').performance);
|
||||
|
||||
@@ -45,7 +45,6 @@ const {
|
||||
FunctionPrototypeCall,
|
||||
JSONParse,
|
||||
ObjectDefineProperty,
|
||||
ObjectDefineProperties,
|
||||
ObjectGetPrototypeOf,
|
||||
ObjectPreventExtensions,
|
||||
ObjectSetPrototypeOf,
|
||||
@@ -377,13 +376,21 @@ function setupProcessObject() {
|
||||
configurable: false,
|
||||
value: 'process'
|
||||
});
|
||||
// Make process globally available to users by putting it on the global proxy
|
||||
|
||||
// Create global.process as getters so that we have a
|
||||
// deprecation path for these in ES Modules.
|
||||
// See https://github.com/nodejs/node/pull/26334.
|
||||
let _process = process;
|
||||
ObjectDefineProperty(globalThis, 'process', {
|
||||
__proto__: null,
|
||||
value: process,
|
||||
get() {
|
||||
return _process;
|
||||
},
|
||||
set(value) {
|
||||
_process = value;
|
||||
},
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -399,10 +406,7 @@ function setupGlobalProxy() {
|
||||
|
||||
function setupBuffer() {
|
||||
const {
|
||||
Blob,
|
||||
Buffer,
|
||||
atob,
|
||||
btoa,
|
||||
} = require('buffer');
|
||||
const bufferBinding = internalBinding('buffer');
|
||||
|
||||
@@ -411,34 +415,19 @@ function setupBuffer() {
|
||||
delete bufferBinding.setBufferPrototype;
|
||||
delete bufferBinding.zeroFill;
|
||||
|
||||
ObjectDefineProperties(globalThis, {
|
||||
'Blob': {
|
||||
__proto__: null,
|
||||
value: Blob,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
// Create global.Buffer as getters so that we have a
|
||||
// deprecation path for these in ES Modules.
|
||||
// See https://github.com/nodejs/node/pull/26334.
|
||||
let _Buffer = Buffer;
|
||||
ObjectDefineProperty(globalThis, 'Buffer', {
|
||||
__proto__: null,
|
||||
get() {
|
||||
return _Buffer;
|
||||
},
|
||||
'Buffer': {
|
||||
__proto__: null,
|
||||
value: Buffer,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
},
|
||||
'atob': {
|
||||
__proto__: null,
|
||||
value: atob,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
},
|
||||
'btoa': {
|
||||
__proto__: null,
|
||||
value: btoa,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
set(value) {
|
||||
_Buffer = value;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ const {
|
||||
exposeInterface,
|
||||
} = require('internal/util');
|
||||
|
||||
const { Buffer } = require('buffer');
|
||||
const {
|
||||
ERR_MANIFEST_ASSERT_INTEGRITY,
|
||||
} = require('internal/errors').codes;
|
||||
@@ -408,35 +407,6 @@ function initializeDeprecations() {
|
||||
'process._tickCallback() is deprecated',
|
||||
'DEP0134');
|
||||
}
|
||||
|
||||
// Create global.process and global.Buffer as getters so that we have a
|
||||
// deprecation path for these in ES Modules.
|
||||
// See https://github.com/nodejs/node/pull/26334.
|
||||
let _process = process;
|
||||
ObjectDefineProperty(globalThis, 'process', {
|
||||
__proto__: null,
|
||||
get() {
|
||||
return _process;
|
||||
},
|
||||
set(value) {
|
||||
_process = value;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
let _Buffer = Buffer;
|
||||
ObjectDefineProperty(globalThis, 'Buffer', {
|
||||
__proto__: null,
|
||||
get() {
|
||||
return _Buffer;
|
||||
},
|
||||
set(value) {
|
||||
_Buffer = value;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
|
||||
function setupChildProcessIpcChannel() {
|
||||
|
||||
@@ -49,6 +49,8 @@ builtinModules.forEach((moduleName) => {
|
||||
'clearImmediate',
|
||||
'clearInterval',
|
||||
'clearTimeout',
|
||||
'atob',
|
||||
'btoa',
|
||||
'performance',
|
||||
'setImmediate',
|
||||
'setInterval',
|
||||
|
||||
Reference in New Issue
Block a user