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:
Michaël Zasso 2019-03-31 13:30:12 +02:00 committed by ZYSzys
parent 8a6dcd040f
commit 0817840f77
43 changed files with 83 additions and 3 deletions

View File

@ -1,6 +1,7 @@
rules:
prefer-object-spread: error
no-buffer-constructor: error
no-restricted-globals: ["error", "JSON", "Math", "Reflect"]
no-restricted-syntax:
# Config copied from .eslintrc.js
- error

View File

@ -21,6 +21,8 @@
'use strict';
const { Math } = primordials;
const { getOptionValue } = require('internal/options');
const { methods, HTTPParser } =

View File

@ -1,5 +1,7 @@
'use strict';
const { Reflect } = primordials;
const {
ERR_ASYNC_CALLBACK,
ERR_INVALID_ASYNC_ID

View File

@ -21,6 +21,8 @@
'use strict';
const { Math } = primordials;
const {
byteLengthUtf8,
copy: _copy,

View File

@ -26,6 +26,8 @@
// No new pull requests targeting this module will be accepted
// unless they address existing, critical bugs.
const { Reflect } = primordials;
const util = require('util');
const EventEmitter = require('events');
const {

View File

@ -21,6 +21,8 @@
'use strict';
const { Math, Reflect } = primordials;
var spliceOne;
const {

View File

@ -24,6 +24,8 @@
'use strict';
const { Math, Reflect } = primordials;
const { fs: constants } = internalBinding('constants');
const {
S_IFIFO,

View File

@ -1,5 +1,7 @@
'use strict';
const { JSON } = primordials;
const {
ERR_INSPECTOR_ALREADY_CONNECTED,
ERR_INSPECTOR_CLOSED,

View File

@ -1,5 +1,7 @@
'use strict';
const { Math } = primordials;
const { inspect } = require('internal/util/inspect');
const { codes: {
ERR_INVALID_ARG_TYPE

View File

@ -1,5 +1,7 @@
'use strict';
const { Reflect } = primordials;
const {
ERR_ASYNC_TYPE,
ERR_INVALID_ASYNC_ID

View File

@ -34,9 +34,8 @@
// This file is compiled as if it's wrapped in a function with arguments
// passed by node::RunBootstrapping()
/* global process, require, internalBinding, isMainThread, ownsProcessState */
/* global primordials */
const { Object, Symbol } = primordials;
const { JSON, Object, Symbol } = primordials;
const config = internalBinding('config');
const { deprecate } = require('internal/util');

View File

@ -1,6 +1,6 @@
'use strict';
/* global primordials */
/* eslint-disable no-restricted-globals */
// 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

View File

@ -1,5 +1,7 @@
'use strict';
const { Math } = primordials;
const {
ERR_BUFFER_OUT_OF_BOUNDS,
ERR_INVALID_ARG_TYPE,

View File

@ -1,5 +1,7 @@
'use strict';
const { JSON } = primordials;
const {
errnoException,
codes: {

View File

@ -1,5 +1,7 @@
'use strict';
const { Math } = primordials;
const { Buffer } = require('buffer');
const { removeColors } = require('internal/util');
const HasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);

View File

@ -3,6 +3,8 @@
// The Console constructor is not actually used to construct the global
// console. It's exported for backwards compatibility.
const { Reflect } = primordials;
const { trace } = internalBinding('trace_events');
const {
isStackOverflowError,

View File

@ -12,6 +12,8 @@
// Therefore, the console.Console.prototype is not
// in the global console prototype chain anymore.
const { Reflect } = primordials;
const {
Console,
kBindStreamsLazy,

View File

@ -1,5 +1,7 @@
'use strict';
const { Math } = primordials;
const { AsyncWrap, Providers } = internalBinding('async_wrap');
const { Buffer, kMaxLength } = require('buffer');
const { randomBytes: _randomBytes } = internalBinding('crypto');

View File

@ -20,7 +20,9 @@
// https://github.com/tc39/proposal-frozen-realms/blob/91ac390e3451da92b5c27e354b39e52b7636a437/shim/src/deep-freeze.js
/* global WebAssembly, SharedArrayBuffer, console */
/* eslint-disable no-restricted-globals */
'use strict';
module.exports = function() {
const intrinsics = [

View File

@ -1,5 +1,7 @@
'use strict';
const { Math } = primordials;
const {
F_OK,
O_SYMLINK,

View File

@ -1,5 +1,7 @@
'use strict';
const { Math } = primordials;
const { Buffer } = require('buffer');
const { FSReqCallback, close, read } = internalBinding('fs');

View File

@ -1,5 +1,7 @@
'use strict';
const { Math } = primordials;
const {
FSReqCallback,
writeBuffers

View File

@ -1,5 +1,7 @@
'use strict';
const { Reflect } = primordials;
const { Buffer, kMaxLength } = require('buffer');
const {
codes: {

View File

@ -1,5 +1,7 @@
'use strict';
const { Reflect } = primordials;
const assert = require('internal/assert');
const Stream = require('stream');
const Readable = Stream.Readable;

View File

@ -2,6 +2,8 @@
/* eslint-disable no-use-before-define */
const { Math, Reflect } = primordials;
const {
assertCrypto,
customInspectSymbol: kInspect,

View File

@ -1,5 +1,7 @@
'use strict';
const { Math } = primordials;
const binding = internalBinding('http2');
const {
codes: {

View File

@ -1,5 +1,7 @@
'use strict';
/* eslint-disable no-restricted-globals */
const { types } = internalBinding('options');
const hasCrypto = Boolean(process.versions.openssl);

View File

@ -21,6 +21,8 @@
'use strict';
const { JSON, Reflect } = primordials;
const { NativeModule } = require('internal/bootstrap/loaders');
const { pathToFileURL } = require('internal/url');
const { deprecate } = require('internal/util');

View File

@ -1,5 +1,7 @@
'use strict';
const { JSON } = primordials;
const path = require('path');
const {

View File

@ -1,5 +1,7 @@
'use strict';
const { JSON, Reflect } = primordials;
const {
ERR_MANIFEST_TDZ,
} = require('internal/errors').codes;

View File

@ -1,5 +1,7 @@
'use strict';
const { Reflect } = primordials;
const {
// For easy access to the nextTick state in the C++ land,
// and to avoid unnecessary calls into JS land.

View File

@ -3,6 +3,8 @@
// Implements coverage collection exposed by the `NODE_V8_COVERAGE`
// environment variable which can also be used in the user land.
const { JSON } = primordials;
let coverageDirectory;
function writeCoverage() {

View File

@ -1,5 +1,7 @@
'use strict';
const { Math } = primordials;
const { ERR_INVALID_OPT_VALUE } = require('internal/errors').codes;
function highWaterMarkFrom(options, isDuplex, duplexKey) {

View File

@ -72,6 +72,8 @@
// timers within (or creation of a new list). However, these operations combined
// have shown to be trivial in comparison to other timers architectures.
const { Math, Reflect } = primordials;
const {
scheduleTimer,
toggleTimerRef,

View File

@ -1,5 +1,7 @@
'use strict';
const { Reflect } = primordials;
const { inspect } = require('internal/util/inspect');
const {
encodeStr,

View File

@ -1,5 +1,7 @@
'use strict';
const { Reflect } = primordials;
const {
ERR_INVALID_ARG_TYPE,
ERR_NO_CRYPTO,

View File

@ -1,5 +1,7 @@
'use strict';
const { JSON, Math } = primordials;
const {
getOwnNonIndexProperties,
getPromiseDetails,

View File

@ -1,5 +1,7 @@
'use strict';
const { JSON } = primordials;
const vm = require('vm');
const scriptFiles = [

View File

@ -27,6 +27,8 @@
'use strict';
const { Math } = primordials;
const {
ERR_INVALID_CURSOR_POS,
ERR_INVALID_OPT_VALUE

View File

@ -42,6 +42,8 @@
'use strict';
const { Math } = primordials;
const {
builtinLibs,
makeRequireFunction,

View File

@ -21,6 +21,8 @@
'use strict';
const { Math } = primordials;
const {
immediateInfo,
toggleImmediateRef

View File

@ -21,6 +21,8 @@
'use strict';
const { Reflect } = primordials;
const {
codes: {
ERR_FALSY_VALUE_REJECTION,

View File

@ -21,6 +21,8 @@
'use strict';
const { Math } = primordials;
const {
codes: {
ERR_BROTLI_INVALID_PARAM,