Skip to content

Commit 0817840

Browse files
targosZYSzys
authored andcommitted
lib: force using primordials for JSON, Math and Reflect
Use the "no-restricted-globals" ESLint rule to lint for it. PR-URL: #27027 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 8a6dcd0 commit 0817840

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+83
-3
lines changed

lib/.eslintrc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
rules:
22
prefer-object-spread: error
33
no-buffer-constructor: error
4+
no-restricted-globals: ["error", "JSON", "Math", "Reflect"]
45
no-restricted-syntax:
56
# Config copied from .eslintrc.js
67
- error

lib/_http_common.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Math } = primordials;
25+
2426
const { getOptionValue } = require('internal/options');
2527

2628
const { methods, HTTPParser } =

lib/async_hooks.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Reflect } = primordials;
4+
35
const {
46
ERR_ASYNC_CALLBACK,
57
ERR_INVALID_ASYNC_ID

lib/buffer.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Math } = primordials;
25+
2426
const {
2527
byteLengthUtf8,
2628
copy: _copy,

lib/domain.js

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
// No new pull requests targeting this module will be accepted
2727
// unless they address existing, critical bugs.
2828

29+
const { Reflect } = primordials;
30+
2931
const util = require('util');
3032
const EventEmitter = require('events');
3133
const {

lib/events.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Math, Reflect } = primordials;
25+
2426
var spliceOne;
2527

2628
const {

lib/fs.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
'use strict';
2626

27+
const { Math, Reflect } = primordials;
28+
2729
const { fs: constants } = internalBinding('constants');
2830
const {
2931
S_IFIFO,

lib/inspector.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { JSON } = primordials;
4+
35
const {
46
ERR_INSPECTOR_ALREADY_CONNECTED,
57
ERR_INSPECTOR_CLOSED,

lib/internal/assert/assertion_error.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Math } = primordials;
4+
35
const { inspect } = require('internal/util/inspect');
46
const { codes: {
57
ERR_INVALID_ARG_TYPE

lib/internal/async_hooks.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Reflect } = primordials;
4+
35
const {
46
ERR_ASYNC_TYPE,
57
ERR_INVALID_ASYNC_ID

lib/internal/bootstrap/node.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
// This file is compiled as if it's wrapped in a function with arguments
3535
// passed by node::RunBootstrapping()
3636
/* global process, require, internalBinding, isMainThread, ownsProcessState */
37-
/* global primordials */
3837

39-
const { Object, Symbol } = primordials;
38+
const { JSON, Object, Symbol } = primordials;
4039
const config = internalBinding('config');
4140
const { deprecate } = require('internal/util');
4241

lib/internal/bootstrap/primordials.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
/* global primordials */
3+
/* eslint-disable no-restricted-globals */
44

55
// This file subclasses and stores the JS builtins that come from the VM
66
// so that Node.js's builtin modules do not need to later look these up from

lib/internal/buffer.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Math } = primordials;
4+
35
const {
46
ERR_BUFFER_OUT_OF_BOUNDS,
57
ERR_INVALID_ARG_TYPE,

lib/internal/child_process.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { JSON } = primordials;
4+
35
const {
46
errnoException,
57
codes: {

lib/internal/cli_table.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Math } = primordials;
4+
35
const { Buffer } = require('buffer');
46
const { removeColors } = require('internal/util');
57
const HasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);

lib/internal/console/constructor.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// The Console constructor is not actually used to construct the global
44
// console. It's exported for backwards compatibility.
55

6+
const { Reflect } = primordials;
7+
68
const { trace } = internalBinding('trace_events');
79
const {
810
isStackOverflowError,

lib/internal/console/global.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// Therefore, the console.Console.prototype is not
1313
// in the global console prototype chain anymore.
1414

15+
const { Reflect } = primordials;
16+
1517
const {
1618
Console,
1719
kBindStreamsLazy,

lib/internal/crypto/random.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Math } = primordials;
4+
35
const { AsyncWrap, Providers } = internalBinding('async_wrap');
46
const { Buffer, kMaxLength } = require('buffer');
57
const { randomBytes: _randomBytes } = internalBinding('crypto');

lib/internal/freeze_intrinsics.js

+2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
// https://github.com/tc39/proposal-frozen-realms/blob/91ac390e3451da92b5c27e354b39e52b7636a437/shim/src/deep-freeze.js
2121

2222
/* global WebAssembly, SharedArrayBuffer, console */
23+
/* eslint-disable no-restricted-globals */
2324
'use strict';
25+
2426
module.exports = function() {
2527

2628
const intrinsics = [

lib/internal/fs/promises.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Math } = primordials;
4+
35
const {
46
F_OK,
57
O_SYMLINK,

lib/internal/fs/read_file_context.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Math } = primordials;
4+
35
const { Buffer } = require('buffer');
46

57
const { FSReqCallback, close, read } = internalBinding('fs');

lib/internal/fs/streams.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Math } = primordials;
4+
35
const {
46
FSReqCallback,
57
writeBuffers

lib/internal/fs/utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Reflect } = primordials;
4+
35
const { Buffer, kMaxLength } = require('buffer');
46
const {
57
codes: {

lib/internal/http2/compat.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Reflect } = primordials;
4+
35
const assert = require('internal/assert');
46
const Stream = require('stream');
57
const Readable = Stream.Readable;

lib/internal/http2/core.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
/* eslint-disable no-use-before-define */
44

5+
const { Math, Reflect } = primordials;
6+
57
const {
68
assertCrypto,
79
customInspectSymbol: kInspect,

lib/internal/http2/util.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Math } = primordials;
4+
35
const binding = internalBinding('http2');
46
const {
57
codes: {

lib/internal/main/print_help.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
/* eslint-disable no-restricted-globals */
4+
35
const { types } = internalBinding('options');
46
const hasCrypto = Boolean(process.versions.openssl);
57

lib/internal/modules/cjs/loader.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { JSON, Reflect } = primordials;
25+
2426
const { NativeModule } = require('internal/bootstrap/loaders');
2527
const { pathToFileURL } = require('internal/url');
2628
const { deprecate } = require('internal/util');

lib/internal/process/execution.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { JSON } = primordials;
4+
35
const path = require('path');
46

57
const {

lib/internal/process/policy.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { JSON, Reflect } = primordials;
4+
35
const {
46
ERR_MANIFEST_TDZ,
57
} = require('internal/errors').codes;

lib/internal/process/task_queues.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Reflect } = primordials;
4+
35
const {
46
// For easy access to the nextTick state in the C++ land,
57
// and to avoid unnecessary calls into JS land.

lib/internal/profiler.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Implements coverage collection exposed by the `NODE_V8_COVERAGE`
44
// environment variable which can also be used in the user land.
55

6+
const { JSON } = primordials;
7+
68
let coverageDirectory;
79

810
function writeCoverage() {

lib/internal/streams/state.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Math } = primordials;
4+
35
const { ERR_INVALID_OPT_VALUE } = require('internal/errors').codes;
46

57
function highWaterMarkFrom(options, isDuplex, duplexKey) {

lib/internal/timers.js

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
// timers within (or creation of a new list). However, these operations combined
7373
// have shown to be trivial in comparison to other timers architectures.
7474

75+
const { Math, Reflect } = primordials;
76+
7577
const {
7678
scheduleTimer,
7779
toggleTimerRef,

lib/internal/url.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Reflect } = primordials;
4+
35
const { inspect } = require('internal/util/inspect');
46
const {
57
encodeStr,

lib/internal/util.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { Reflect } = primordials;
4+
35
const {
46
ERR_INVALID_ARG_TYPE,
57
ERR_NO_CRYPTO,

lib/internal/util/inspect.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { JSON, Math } = primordials;
4+
35
const {
46
getOwnNonIndexProperties,
57
getPromiseDetails,

lib/internal/v8_prof_processor.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { JSON } = primordials;
4+
35
const vm = require('vm');
46

57
const scriptFiles = [

lib/readline.js

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
'use strict';
2929

30+
const { Math } = primordials;
31+
3032
const {
3133
ERR_INVALID_CURSOR_POS,
3234
ERR_INVALID_OPT_VALUE

lib/repl.js

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
'use strict';
4444

45+
const { Math } = primordials;
46+
4547
const {
4648
builtinLibs,
4749
makeRequireFunction,

lib/timers.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Math } = primordials;
25+
2426
const {
2527
immediateInfo,
2628
toggleImmediateRef

lib/util.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Reflect } = primordials;
25+
2426
const {
2527
codes: {
2628
ERR_FALSY_VALUE_REJECTION,

lib/zlib.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
'use strict';
2323

24+
const { Math } = primordials;
25+
2426
const {
2527
codes: {
2628
ERR_BROTLI_INVALID_PARAM,

0 commit comments

Comments
 (0)