Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: force using primordials for JSON, Math and Reflect #27027

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/_http_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Math } = primordials;

const { getOptionValue } = require('internal/options');

const { methods, HTTPParser } =
Expand Down
2 changes: 2 additions & 0 deletions lib/async_hooks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Reflect } = primordials;

const {
ERR_ASYNC_CALLBACK,
ERR_INVALID_ASYNC_ID
Expand Down
2 changes: 2 additions & 0 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Math } = primordials;

const {
byteLengthUtf8,
copy: _copy,
Expand Down
2 changes: 2 additions & 0 deletions lib/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Math, Reflect } = primordials;

var spliceOne;

const {
Expand Down
2 changes: 2 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

'use strict';

const { Math, Reflect } = primordials;

const { fs: constants } = internalBinding('constants');
const {
S_IFIFO,
Expand Down
2 changes: 2 additions & 0 deletions lib/inspector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { JSON } = primordials;

const {
ERR_INSPECTOR_ALREADY_CONNECTED,
ERR_INSPECTOR_CLOSED,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/assert/assertion_error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Math } = primordials;

const { inspect } = require('internal/util/inspect');
const { codes: {
ERR_INVALID_ARG_TYPE
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/async_hooks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Reflect } = primordials;

const {
ERR_ASYNC_TYPE,
ERR_INVALID_ASYNC_ID
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/primordials.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/buffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Math } = primordials;

const {
ERR_BUFFER_OUT_OF_BOUNDS,
ERR_INVALID_ARG_TYPE,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { JSON } = primordials;

const {
errnoException,
codes: {
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/cli_table.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/console/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// Therefore, the console.Console.prototype is not
// in the global console prototype chain anymore.

const { Reflect } = primordials;

const {
Console,
kBindStreamsLazy,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/crypto/random.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/freeze_intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Math } = primordials;

const {
F_OK,
O_SYMLINK,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/fs/read_file_context.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Math } = primordials;

const { Buffer } = require('buffer');

const { FSReqCallback, close, read } = internalBinding('fs');
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Math } = primordials;

const {
FSReqCallback,
writeBuffers
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Reflect } = primordials;

const { Buffer, kMaxLength } = require('buffer');
const {
codes: {
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Reflect } = primordials;

const assert = require('internal/assert');
const Stream = require('stream');
const Readable = Stream.Readable;
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

const { Math, Reflect } = primordials;

const {
assertCrypto,
customInspectSymbol: kInspect,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/http2/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Math } = primordials;

const binding = internalBinding('http2');
const {
codes: {
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/print_help.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

/* eslint-disable no-restricted-globals */

const { types } = internalBinding('options');
const hasCrypto = Boolean(process.versions.openssl);

Expand Down
2 changes: 2 additions & 0 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/process/execution.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { JSON } = primordials;

const path = require('path');

const {
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/process/policy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { JSON, Reflect } = primordials;

const {
ERR_MANIFEST_TDZ,
} = require('internal/errors').codes;
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/process/task_queues.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/streams/state.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Math } = primordials;

const { ERR_INVALID_OPT_VALUE } = require('internal/errors').codes;

function highWaterMarkFrom(options, isDuplex, duplexKey) {
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Reflect } = primordials;

const { inspect } = require('internal/util/inspect');
const {
encodeStr,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Reflect } = primordials;

const {
ERR_INVALID_ARG_TYPE,
ERR_NO_CRYPTO,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { JSON, Math } = primordials;

const {
getOwnNonIndexProperties,
getPromiseDetails,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/v8_prof_processor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { JSON } = primordials;

const vm = require('vm');

const scriptFiles = [
Expand Down
2 changes: 2 additions & 0 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

'use strict';

const { Math } = primordials;

const {
ERR_INVALID_CURSOR_POS,
ERR_INVALID_OPT_VALUE
Expand Down
2 changes: 2 additions & 0 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

'use strict';

const { Math } = primordials;

const {
builtinLibs,
makeRequireFunction,
Expand Down
2 changes: 2 additions & 0 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Math } = primordials;

const {
immediateInfo,
toggleImmediateRef
Expand Down
2 changes: 2 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Reflect } = primordials;

const {
codes: {
ERR_FALSY_VALUE_REJECTION,
Expand Down
2 changes: 2 additions & 0 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

'use strict';

const { Math } = primordials;

const {
codes: {
ERR_BROTLI_INVALID_PARAM,
Expand Down