module: do not share the internal require function with public loaders · nodejs/node@235bb73 (original) (raw)

`@@ -33,13 +33,12 @@

`

33

33

``

34

34

`// This file is compiled as if it's wrapped in a function with arguments

`

35

35

`// passed by node::RunBootstrapping()

`

36

``

`-

/* global process, loaderExports, isMainThread, ownsProcessState */

`

``

36

`+

/* global process, require, internalBinding, isMainThread, ownsProcessState */

`

37

37

`/* global primordials */

`

38

38

``

39

``

`-

const { internalBinding, NativeModule } = loaderExports;

`

40

39

`const { Object, Symbol } = primordials;

`

41

40

`const config = internalBinding('config');

`

42

``

`-

const { deprecate } = NativeModule.require('internal/util');

`

``

41

`+

const { deprecate } = require('internal/util');

`

43

42

``

44

43

`setupProcessObject();

`

45

44

``

`@@ -50,17 +49,17 @@ process.domain = null;

`

50

49

`process._exiting = false;

`

51

50

``

52

51

`// Bootstrappers for all threads, including worker threads and main thread

`

53

``

`-

const perThreadSetup = NativeModule.require('internal/process/per_thread');

`

``

52

`+

const perThreadSetup = require('internal/process/per_thread');

`

54

53

`// Bootstrappers for the main thread only

`

55

54

`let mainThreadSetup;

`

56

55

`// Bootstrappers for the worker threads only

`

57

56

`let workerThreadSetup;

`

58

57

`if (ownsProcessState) {

`

59

``

`-

mainThreadSetup = NativeModule.require(

`

``

58

`+

mainThreadSetup = require(

`

60

59

`'internal/process/main_thread_only'

`

61

60

`);

`

62

61

`} else {

`

63

``

`-

workerThreadSetup = NativeModule.require(

`

``

62

`+

workerThreadSetup = require(

`

64

63

`'internal/process/worker_thread_only'

`

65

64

`);

`

66

65

`}

`

`@@ -116,14 +115,14 @@ if (isMainThread) {

`

116

115

``

117

116

`const {

`

118

117

` emitWarning

`

119

``

`-

} = NativeModule.require('internal/process/warning');

`

``

118

`+

} = require('internal/process/warning');

`

120

119

``

121

120

`process.emitWarning = emitWarning;

`

122

121

``

123

122

`const {

`

124

123

` nextTick,

`

125

124

` runNextTicks

`

126

``

`-

} = NativeModule.require('internal/process/next_tick').setup();

`

``

125

`+

} = require('internal/process/next_tick').setup();

`

127

126

``

128

127

`process.nextTick = nextTick;

`

129

128

`// Used to emulate a tick manually in the JS land.

`

`@@ -161,7 +160,7 @@ if (credentials.implementsPosixCredentials) {

`

161

160

``

162

161

`if (isMainThread) {

`

163

162

`const { getStdout, getStdin, getStderr } =

`

164

``

`-

NativeModule.require('internal/process/stdio').getMainThreadStdio();

`

``

163

`+

require('internal/process/stdio').getMainThreadStdio();

`

165

164

`setupProcessStdio(getStdout, getStdin, getStderr);

`

166

165

`} else {

`

167

166

`const { getStdout, getStdin, getStderr } =

`

`@@ -173,7 +172,7 @@ if (isMainThread) {

`

173

172

`// process. They use the same functions as the JS embedder API. These callbacks

`

174

173

`// are setup immediately to prevent async_wrap.setupHooks() from being hijacked

`

175

174

`// and the cost of doing so is negligible.

`

176

``

`-

const { nativeHooks } = NativeModule.require('internal/async_hooks');

`

``

175

`+

const { nativeHooks } = require('internal/async_hooks');

`

177

176

`internalBinding('async_wrap').setupHooks(nativeHooks);

`

178

177

``

179

178

`// XXX(joyeecheung): this has to be done after the initial load of

`

`@@ -183,7 +182,7 @@ if (config.hasInspector) {

`

183

182

`const {

`

184

183

` enable,

`

185

184

` disable

`

186

``

`-

} = NativeModule.require('internal/inspector_async_hook');

`

``

185

`+

} = require('internal/inspector_async_hook');

`

187

186

`internalBinding('inspector').registerAsyncHook(enable, disable);

`

188

187

`}

`

189

188

``

`@@ -193,22 +192,22 @@ if (!config.noBrowserGlobals) {

`

193

192

`// https://console.spec.whatwg.org/#console-namespace

`

194

193

`exposeNamespace(global, 'console', createGlobalConsole(global.console));

`

195

194

``

196

``

`-

const { URL, URLSearchParams } = NativeModule.require('internal/url');

`

``

195

`+

const { URL, URLSearchParams } = require('internal/url');

`

197

196

`// https://url.spec.whatwg.org/#url

`

198

197

`exposeInterface(global, 'URL', URL);

`

199

198

`// https://url.spec.whatwg.org/#urlsearchparams

`

200

199

`exposeInterface(global, 'URLSearchParams', URLSearchParams);

`

201

200

``

202

201

`const {

`

203

202

` TextEncoder, TextDecoder

`

204

``

`-

} = NativeModule.require('internal/encoding');

`

``

203

`+

} = require('internal/encoding');

`

205

204

`// https://encoding.spec.whatwg.org/#textencoder

`

206

205

`exposeInterface(global, 'TextEncoder', TextEncoder);

`

207

206

`// https://encoding.spec.whatwg.org/#textdecoder

`

208

207

`exposeInterface(global, 'TextDecoder', TextDecoder);

`

209

208

``

210

209

`// https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope

`

211

``

`-

const timers = NativeModule.require('timers');

`

``

210

`+

const timers = require('timers');

`

212

211

`defineOperation(global, 'clearInterval', timers.clearInterval);

`

213

212

`defineOperation(global, 'clearTimeout', timers.clearTimeout);

`

214

213

`defineOperation(global, 'setInterval', timers.setInterval);

`

`@@ -302,7 +301,7 @@ Object.defineProperty(process, 'features', {

`

302

301

` fatalException,

`

303

302

` setUncaughtExceptionCaptureCallback,

`

304

303

` hasUncaughtExceptionCaptureCallback

`

305

``

`-

} = NativeModule.require('internal/process/execution');

`

``

304

`+

} = require('internal/process/execution');

`

306

305

``

307

306

`process._fatalException = fatalException;

`

308

307

`process.setUncaughtExceptionCaptureCallback =

`

`@@ -312,7 +311,7 @@ Object.defineProperty(process, 'features', {

`

312

311

`}

`

313

312

``

314

313

`function setupProcessObject() {

`

315

``

`-

const EventEmitter = NativeModule.require('events');

`

``

314

`+

const EventEmitter = require('events');

`

316

315

`const origProcProto = Object.getPrototypeOf(process);

`

317

316

`Object.setPrototypeOf(origProcProto, EventEmitter.prototype);

`

318

317

`EventEmitter.call(process);

`

`@@ -391,7 +390,7 @@ function setupGlobalProxy() {

`

391

390

`}

`

392

391

``

393

392

`function setupBuffer() {

`

394

``

`-

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

`

``

393

`+

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

`

395

394

`const bufferBinding = internalBinding('buffer');

`

396

395

``

397

396

`// Only after this point can C++ use Buffer::New()

`

`@@ -404,9 +403,9 @@ function setupBuffer() {

`

404

403

``

405

404

`function createGlobalConsole(consoleFromVM) {

`

406

405

`const consoleFromNode =

`

407

``

`-

NativeModule.require('internal/console/global');

`

``

406

`+

require('internal/console/global');

`

408

407

`if (config.hasInspector) {

`

409

``

`-

const inspector = NativeModule.require('internal/util/inspector');

`

``

408

`+

const inspector = require('internal/util/inspector');

`

410

409

`` // This will be exposed by require('inspector').console later.

``

411

410

`inspector.consoleFromVM = consoleFromVM;

`

412

411

`// TODO(joyeecheung): postpone this until the first time inspector

`

`@@ -424,8 +423,7 @@ function setupQueueMicrotask() {

`

424

423

`get() {

`

425

424

`process.emitWarning('queueMicrotask() is experimental.',

`

426

425

`'ExperimentalWarning');

`

427

``

`-

const { queueMicrotask } =

`

428

``

`-

NativeModule.require('internal/queue_microtask');

`

``

426

`+

const { queueMicrotask } = require('internal/queue_microtask');

`

429

427

``

430

428

`Object.defineProperty(global, 'queueMicrotask', {

`

431

429

`value: queueMicrotask,

`