src/bootstrap-fork.js
function safeToArray(args) {
		const seen = [];
		const argsArray = [];

		let res;

		// Massage some arguments with special treatment
		if (args.length) {
			for (let i = 0; i < args.length; i++) {

				// Any argument of type 'undefined' needs to be specially treated because
				// JSON.stringify will simply ignore those. We replace them with the string
				// 'undefined' which is not 100% right, but good enough to be logged to console
				if (typeof args[i] === 'undefined') {
					args[i] = 'undefined';
				}

				// Any argument that is an Error will be changed to be just the error stack/message
				// itself because currently cannot serialize the error over entirely.
				else if (args[i] instanceof Error) {
					const errorObj = args[i];
					if (errorObj.stack) {
						args[i] = errorObj.stack;
					} else {
						args[i] = errorObj.toString();
					}
				}

				argsArray.push(args[i]);
			}
		}

		// Add the stack trace as payload if we are told so. We remove the message and the 2 top frames
		// to start the stacktrace where the console message was being written
		if (process.env.VSCODE_LOG_STACK === 'true') {
			const stack = new Error().stack;
			argsArray.push({ __$stack: stack.split('\n').slice(3).join('\n') });
		}

		try {
			res = JSON.stringify(argsArray, function (key, value) {

				// Objects get special treatment to prevent circles
				if (isObject(value) || Array.isArray(value)) {
					if (seen.indexOf(value) !== -1) {
						return '[Circular]';
					}

					seen.push(value);
				}

				return value;
			});
		} catch (error) {
			return 'Output omitted for an object that cannot be inspected (' + error.toString() + ')';
		}

		if (res && res.length > MAX_LENGTH) {
			return 'Output omitted for a large object that exceeds the limits';
		}

		return res;
	}
function safeToArray(args) {
		const seen = [];
		const argsArray = [];

		let res;

		// Massage some arguments with special treatment
		if (args.length) {
			for (let i = 0; i < args.length; i++) {

				// Any argument of type 'undefined' needs to be specially treated because
				// JSON.stringify will simply ignore those. We replace them with the string
				// 'undefined' which is not 100% right, but good enough to be logged to console
				if (typeof args[i] === 'undefined') {
					args[i] = 'undefined';
				}

				// Any argument that is an Error will be changed to be just the error stack/message
				// itself because currently cannot serialize the error over entirely.
				else if (args[i] instanceof Error) {
					const errorObj = args[i];
					if (errorObj.stack) {
						args[i] = errorObj.stack;
					} else {
						args[i] = errorObj.toString();
					}
				}

				argsArray.push(args[i]);
			}
		}

		// Add the stack trace as payload if we are told so. We remove the message and the 2 top frames
		// to start the stacktrace where the console message was being written
		if (process.env.VSCODE_LOG_STACK === 'true') {
			const stack = new Error().stack;
			argsArray.push({ __$stack: stack.split('\n').slice(3).join('\n') });
		}

		try {
			res = JSON.stringify(argsArray, function (key, value) {

				// Objects get special treatment to prevent circles
				if (isObject(value) || Array.isArray(value)) {
					if (seen.indexOf(value) !== -1) {
						return '[Circular]';
					}

					seen.push(value);
				}

				return value;
			});
		} catch (error) {
			return 'Output omitted for an object that cannot be inspected (' + error.toString() + ')';
		}

		if (res && res.length > MAX_LENGTH) {
			return 'Output omitted for a large object that exceeds the limits';
		}

		return res;
	}
function safeToArray ( args ) { const seen = [ ] ; const argsArray = [ ] ; let res ; // Massage some arguments with special treatment if ( args . length ) { for ( let i = 0 ; i < args . length ; i ++ ) { // Any argument of type 'undefined' needs to be specially treated because // JSON.stringify will simply ignore those. We replace them with the string // 'undefined' which is not 100% right, but good enough to be logged to console if ( typeof args [ i ] === 'undefined' ) { args [ i ] = 'undefined' ; } // Any argument that is an Error will be changed to be just the error stack/message // itself because currently cannot serialize the error over entirely. else if ( args [ i ] instanceof Error ) { const errorObj = args [ i ] ; if ( errorObj . stack ) { args [ i ] = errorObj . stack ; } else { args [ i ] = errorObj . toString ( ) ; } } argsArray . push ( args [ i ] ) ; } } // Add the stack trace as payload if we are told so. We remove the message and the 2 top frames // to start the stacktrace where the console message was being written if ( process . env . VSCODE_LOG_STACK === 'true' ) { const stack = new Error ( ) . stack ; argsArray . push ( { __$stack : stack . split ( '\n' ) . slice ( 3 ) . join ( '\n' ) } ) ; } try { res = JSON . stringify ( argsArray , function ( key , value ) { // Objects get special treatment to prevent circles if ( isObject ( value ) || Array . isArray ( value ) ) { if ( seen . indexOf ( value ) !== - 1 ) { return '[Circular]' ; } seen . push ( value ) ; } return value ; } ) ; } catch ( error ) { return 'Output omitted for an object that cannot be inspected (' + error . toString ( ) + ')' ; } if ( res && res . length > MAX_LENGTH ) { return 'Output omitted for a large object that exceeds the limits' ; } return res ; }
Prevent circular stringify and convert arguments to real array
Prevent circular stringify and convert arguments to real array