Skip to content

Commit

Permalink
Remove process.mainModule mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
appurva21 committed Apr 22, 2024
1 parent fa66d23 commit 532be0f
Showing 1 changed file with 0 additions and 31 deletions.
31 changes: 0 additions & 31 deletions lib/postman-sandbox.js
Expand Up @@ -9,15 +9,11 @@ const _ = require('lodash'),
EXECUTION_TIMEOUT_ERROR_MESSAGE = 'sandbox not responding',
BRIDGE_DISCONNECTING_ERROR_MESSAGE = 'sandbox: execution interrupted, bridge disconnecting.';

let MAIN_MODULE = null,
ACTIVE_INSTANCES = 0;

class PostmanSandbox extends UniversalVM {
constructor () {
super();

this._executing = {};
this._initialized = false;
}

initialize (initOptions, connectOptions, callback) {
Expand All @@ -27,17 +23,6 @@ class PostmanSandbox extends UniversalVM {

this.debug = Boolean(connectOptions.debug);

// Modify mainModule to prevent access to the Module object
if (!MAIN_MODULE && typeof process === 'object' && process.mainModule) {
MAIN_MODULE = process.mainModule;
process.mainModule = {
..._.pick(process.mainModule, ['id', 'path', 'paths', 'filename', 'loaded']),
exports: {},
children: [],
parent: null
};
}

// set the dispatch timeout of UVM based on what is set in options unless original options sends the same
_.isFinite(connectOptions.timeout) &&
(connectOptions.dispatchTimeout = this.executionTimeout = connectOptions.timeout);
Expand All @@ -46,9 +31,6 @@ class PostmanSandbox extends UniversalVM {
if (err) { return callback(err); }

this.once('initialize', (err) => {
this._initialized = !err;
ACTIVE_INSTANCES++;

this.on(CONSOLE_EVENT_NAME, (cursor, level, args) => {
if (connectOptions.serializeLogs) {
return this.emit('console', cursor, level, args);
Expand Down Expand Up @@ -150,10 +132,6 @@ class PostmanSandbox extends UniversalVM {
}

dispose () {
if (!this._initialized) {
return;
}

_.forEach(this._executing, (irq, id) => {
irq && clearTimeout(irq);

Expand All @@ -167,15 +145,6 @@ class PostmanSandbox extends UniversalVM {

this.removeAllListeners(CONSOLE_EVENT_NAME);
this.disconnect();

this._initialized = false;
ACTIVE_INSTANCES--;

// reset the mainModule to its original value
if (ACTIVE_INSTANCES === 0 && MAIN_MODULE) {
process.mainModule = MAIN_MODULE;
MAIN_MODULE = null;
}
}
}

Expand Down

0 comments on commit 532be0f

Please sign in to comment.