lib: force using primordials for JSON, Math and Reflect
Use the "no-restricted-globals" ESLint rule to lint for it. PR-URL: https://github.com/nodejs/node/pull/27027 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
8a6dcd040f
commit
0817840f77
@ -1,6 +1,7 @@
|
|||||||
rules:
|
rules:
|
||||||
prefer-object-spread: error
|
prefer-object-spread: error
|
||||||
no-buffer-constructor: error
|
no-buffer-constructor: error
|
||||||
|
no-restricted-globals: ["error", "JSON", "Math", "Reflect"]
|
||||||
no-restricted-syntax:
|
no-restricted-syntax:
|
||||||
# Config copied from .eslintrc.js
|
# Config copied from .eslintrc.js
|
||||||
- error
|
- error
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const { getOptionValue } = require('internal/options');
|
const { getOptionValue } = require('internal/options');
|
||||||
|
|
||||||
const { methods, HTTPParser } =
|
const { methods, HTTPParser } =
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Reflect } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ERR_ASYNC_CALLBACK,
|
ERR_ASYNC_CALLBACK,
|
||||||
ERR_INVALID_ASYNC_ID
|
ERR_INVALID_ASYNC_ID
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
byteLengthUtf8,
|
byteLengthUtf8,
|
||||||
copy: _copy,
|
copy: _copy,
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
// No new pull requests targeting this module will be accepted
|
// No new pull requests targeting this module will be accepted
|
||||||
// unless they address existing, critical bugs.
|
// unless they address existing, critical bugs.
|
||||||
|
|
||||||
|
const { Reflect } = primordials;
|
||||||
|
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
const {
|
const {
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math, Reflect } = primordials;
|
||||||
|
|
||||||
var spliceOne;
|
var spliceOne;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math, Reflect } = primordials;
|
||||||
|
|
||||||
const { fs: constants } = internalBinding('constants');
|
const { fs: constants } = internalBinding('constants');
|
||||||
const {
|
const {
|
||||||
S_IFIFO,
|
S_IFIFO,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { JSON } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ERR_INSPECTOR_ALREADY_CONNECTED,
|
ERR_INSPECTOR_ALREADY_CONNECTED,
|
||||||
ERR_INSPECTOR_CLOSED,
|
ERR_INSPECTOR_CLOSED,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const { inspect } = require('internal/util/inspect');
|
const { inspect } = require('internal/util/inspect');
|
||||||
const { codes: {
|
const { codes: {
|
||||||
ERR_INVALID_ARG_TYPE
|
ERR_INVALID_ARG_TYPE
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Reflect } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ERR_ASYNC_TYPE,
|
ERR_ASYNC_TYPE,
|
||||||
ERR_INVALID_ASYNC_ID
|
ERR_INVALID_ASYNC_ID
|
||||||
|
@ -34,9 +34,8 @@
|
|||||||
// This file is compiled as if it's wrapped in a function with arguments
|
// This file is compiled as if it's wrapped in a function with arguments
|
||||||
// passed by node::RunBootstrapping()
|
// passed by node::RunBootstrapping()
|
||||||
/* global process, require, internalBinding, isMainThread, ownsProcessState */
|
/* global process, require, internalBinding, isMainThread, ownsProcessState */
|
||||||
/* global primordials */
|
|
||||||
|
|
||||||
const { Object, Symbol } = primordials;
|
const { JSON, Object, Symbol } = primordials;
|
||||||
const config = internalBinding('config');
|
const config = internalBinding('config');
|
||||||
const { deprecate } = require('internal/util');
|
const { deprecate } = require('internal/util');
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/* global primordials */
|
/* eslint-disable no-restricted-globals */
|
||||||
|
|
||||||
// This file subclasses and stores the JS builtins that come from the VM
|
// This file subclasses and stores the JS builtins that come from the VM
|
||||||
// so that Node.js's builtin modules do not need to later look these up from
|
// so that Node.js's builtin modules do not need to later look these up from
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ERR_BUFFER_OUT_OF_BOUNDS,
|
ERR_BUFFER_OUT_OF_BOUNDS,
|
||||||
ERR_INVALID_ARG_TYPE,
|
ERR_INVALID_ARG_TYPE,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { JSON } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
errnoException,
|
errnoException,
|
||||||
codes: {
|
codes: {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const { Buffer } = require('buffer');
|
const { Buffer } = require('buffer');
|
||||||
const { removeColors } = require('internal/util');
|
const { removeColors } = require('internal/util');
|
||||||
const HasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);
|
const HasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
// The Console constructor is not actually used to construct the global
|
// The Console constructor is not actually used to construct the global
|
||||||
// console. It's exported for backwards compatibility.
|
// console. It's exported for backwards compatibility.
|
||||||
|
|
||||||
|
const { Reflect } = primordials;
|
||||||
|
|
||||||
const { trace } = internalBinding('trace_events');
|
const { trace } = internalBinding('trace_events');
|
||||||
const {
|
const {
|
||||||
isStackOverflowError,
|
isStackOverflowError,
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
// Therefore, the console.Console.prototype is not
|
// Therefore, the console.Console.prototype is not
|
||||||
// in the global console prototype chain anymore.
|
// in the global console prototype chain anymore.
|
||||||
|
|
||||||
|
const { Reflect } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
Console,
|
Console,
|
||||||
kBindStreamsLazy,
|
kBindStreamsLazy,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const { AsyncWrap, Providers } = internalBinding('async_wrap');
|
const { AsyncWrap, Providers } = internalBinding('async_wrap');
|
||||||
const { Buffer, kMaxLength } = require('buffer');
|
const { Buffer, kMaxLength } = require('buffer');
|
||||||
const { randomBytes: _randomBytes } = internalBinding('crypto');
|
const { randomBytes: _randomBytes } = internalBinding('crypto');
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
// https://github.com/tc39/proposal-frozen-realms/blob/91ac390e3451da92b5c27e354b39e52b7636a437/shim/src/deep-freeze.js
|
// https://github.com/tc39/proposal-frozen-realms/blob/91ac390e3451da92b5c27e354b39e52b7636a437/shim/src/deep-freeze.js
|
||||||
|
|
||||||
/* global WebAssembly, SharedArrayBuffer, console */
|
/* global WebAssembly, SharedArrayBuffer, console */
|
||||||
|
/* eslint-disable no-restricted-globals */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = function() {
|
module.exports = function() {
|
||||||
|
|
||||||
const intrinsics = [
|
const intrinsics = [
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
F_OK,
|
F_OK,
|
||||||
O_SYMLINK,
|
O_SYMLINK,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const { Buffer } = require('buffer');
|
const { Buffer } = require('buffer');
|
||||||
|
|
||||||
const { FSReqCallback, close, read } = internalBinding('fs');
|
const { FSReqCallback, close, read } = internalBinding('fs');
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
FSReqCallback,
|
FSReqCallback,
|
||||||
writeBuffers
|
writeBuffers
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Reflect } = primordials;
|
||||||
|
|
||||||
const { Buffer, kMaxLength } = require('buffer');
|
const { Buffer, kMaxLength } = require('buffer');
|
||||||
const {
|
const {
|
||||||
codes: {
|
codes: {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Reflect } = primordials;
|
||||||
|
|
||||||
const assert = require('internal/assert');
|
const assert = require('internal/assert');
|
||||||
const Stream = require('stream');
|
const Stream = require('stream');
|
||||||
const Readable = Stream.Readable;
|
const Readable = Stream.Readable;
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
/* eslint-disable no-use-before-define */
|
/* eslint-disable no-use-before-define */
|
||||||
|
|
||||||
|
const { Math, Reflect } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
assertCrypto,
|
assertCrypto,
|
||||||
customInspectSymbol: kInspect,
|
customInspectSymbol: kInspect,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const binding = internalBinding('http2');
|
const binding = internalBinding('http2');
|
||||||
const {
|
const {
|
||||||
codes: {
|
codes: {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/* eslint-disable no-restricted-globals */
|
||||||
|
|
||||||
const { types } = internalBinding('options');
|
const { types } = internalBinding('options');
|
||||||
const hasCrypto = Boolean(process.versions.openssl);
|
const hasCrypto = Boolean(process.versions.openssl);
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { JSON, Reflect } = primordials;
|
||||||
|
|
||||||
const { NativeModule } = require('internal/bootstrap/loaders');
|
const { NativeModule } = require('internal/bootstrap/loaders');
|
||||||
const { pathToFileURL } = require('internal/url');
|
const { pathToFileURL } = require('internal/url');
|
||||||
const { deprecate } = require('internal/util');
|
const { deprecate } = require('internal/util');
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { JSON } = primordials;
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { JSON, Reflect } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ERR_MANIFEST_TDZ,
|
ERR_MANIFEST_TDZ,
|
||||||
} = require('internal/errors').codes;
|
} = require('internal/errors').codes;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Reflect } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
// For easy access to the nextTick state in the C++ land,
|
// For easy access to the nextTick state in the C++ land,
|
||||||
// and to avoid unnecessary calls into JS land.
|
// and to avoid unnecessary calls into JS land.
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
// Implements coverage collection exposed by the `NODE_V8_COVERAGE`
|
// Implements coverage collection exposed by the `NODE_V8_COVERAGE`
|
||||||
// environment variable which can also be used in the user land.
|
// environment variable which can also be used in the user land.
|
||||||
|
|
||||||
|
const { JSON } = primordials;
|
||||||
|
|
||||||
let coverageDirectory;
|
let coverageDirectory;
|
||||||
|
|
||||||
function writeCoverage() {
|
function writeCoverage() {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const { ERR_INVALID_OPT_VALUE } = require('internal/errors').codes;
|
const { ERR_INVALID_OPT_VALUE } = require('internal/errors').codes;
|
||||||
|
|
||||||
function highWaterMarkFrom(options, isDuplex, duplexKey) {
|
function highWaterMarkFrom(options, isDuplex, duplexKey) {
|
||||||
|
@ -72,6 +72,8 @@
|
|||||||
// timers within (or creation of a new list). However, these operations combined
|
// timers within (or creation of a new list). However, these operations combined
|
||||||
// have shown to be trivial in comparison to other timers architectures.
|
// have shown to be trivial in comparison to other timers architectures.
|
||||||
|
|
||||||
|
const { Math, Reflect } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
scheduleTimer,
|
scheduleTimer,
|
||||||
toggleTimerRef,
|
toggleTimerRef,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Reflect } = primordials;
|
||||||
|
|
||||||
const { inspect } = require('internal/util/inspect');
|
const { inspect } = require('internal/util/inspect');
|
||||||
const {
|
const {
|
||||||
encodeStr,
|
encodeStr,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Reflect } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ERR_INVALID_ARG_TYPE,
|
ERR_INVALID_ARG_TYPE,
|
||||||
ERR_NO_CRYPTO,
|
ERR_NO_CRYPTO,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { JSON, Math } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
getOwnNonIndexProperties,
|
getOwnNonIndexProperties,
|
||||||
getPromiseDetails,
|
getPromiseDetails,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { JSON } = primordials;
|
||||||
|
|
||||||
const vm = require('vm');
|
const vm = require('vm');
|
||||||
|
|
||||||
const scriptFiles = [
|
const scriptFiles = [
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ERR_INVALID_CURSOR_POS,
|
ERR_INVALID_CURSOR_POS,
|
||||||
ERR_INVALID_OPT_VALUE
|
ERR_INVALID_OPT_VALUE
|
||||||
|
@ -42,6 +42,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
builtinLibs,
|
builtinLibs,
|
||||||
makeRequireFunction,
|
makeRequireFunction,
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
immediateInfo,
|
immediateInfo,
|
||||||
toggleImmediateRef
|
toggleImmediateRef
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Reflect } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
codes: {
|
codes: {
|
||||||
ERR_FALSY_VALUE_REJECTION,
|
ERR_FALSY_VALUE_REJECTION,
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { Math } = primordials;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
codes: {
|
codes: {
|
||||||
ERR_BROTLI_INVALID_PARAM,
|
ERR_BROTLI_INVALID_PARAM,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user