Skip to content

Commit

Permalink
fix: properly attribute stack with fileName, removes slow leak
Browse files Browse the repository at this point in the history
Co-authored-by: Brenden Palmer <brendenpalmer@gmail.com>
  • Loading branch information
gabrielcsapo and brendenpalmer committed Jun 9, 2022
1 parent ec6f0ec commit 13e6512
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 74 deletions.
22 changes: 14 additions & 8 deletions packages/fastboot/src/ember-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ class EmberApp {
this.config = allConfig;
}

this.scripts = buildScripts([
require.resolve('./scripts/install-source-map-support'),
...config.scripts,
]);
if (process.setSourceMapsEnabled) {
process.setSourceMapsEnabled(true);

this.scripts = buildScripts([...config.scripts]);
} else {
this.scripts = buildScripts([
require.resolve('./scripts/install-source-map-support'),
...config.scripts,
]);
}

// default to 1 if maxSandboxQueueSize is not defined so the sandbox is pre-warmed when process comes up
const maxSandboxQueueSize = options.maxSandboxQueueSize || 1;
Expand Down Expand Up @@ -161,7 +167,7 @@ class EmberApp {
debug('files evaluated');

// Retrieve the application factory from within the sandbox
let AppFactory = sandbox.run(function(ctx) {
let AppFactory = sandbox.run(function (ctx) {
return ctx.require('~fastboot/app-factory');
});

Expand Down Expand Up @@ -312,7 +318,7 @@ class EmberApp {
if (destroyAppInstanceInMs > 0) {
// start a timer to destroy the appInstance forcefully in the given ms.
// This is a failure mechanism so that node process doesn't get wedged if the `visit` never completes.
destroyAppInstanceTimer = setTimeout(function() {
destroyAppInstanceTimer = setTimeout(function () {
if (result._destroy()) {
result.error = new Error(
'App instance was forcefully destroyed in ' + destroyAppInstanceInMs + 'ms'
Expand Down Expand Up @@ -414,7 +420,7 @@ const JSON_ESCAPE = {
const JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/g;

function escapeJSONString(string) {
return string.replace(JSON_ESCAPE_REGEXP, function(match) {
return string.replace(JSON_ESCAPE_REGEXP, function (match) {
return JSON_ESCAPE[match];
});
}
Expand All @@ -428,7 +434,7 @@ function registerFastBootInfo(info, instance) {
}

function buildScripts(filePaths) {
return filePaths.filter(Boolean).map(filePath => {
return filePaths.filter(Boolean).map((filePath) => {
let source = fs.readFileSync(filePath, { encoding: 'utf8' });

return new vm.Script(source, { filename: filePath });
Expand Down
8 changes: 5 additions & 3 deletions packages/fastboot/src/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ module.exports = class Sandbox {
let URL = require('url');
let globals = this.globals;

const sourceMapConfig = process.setSourceMapsEnabled ? { sourceMapSupport } : {};

let sandbox = Object.assign(
{
sourceMapSupport,
sourceMapConfig,
console,
setTimeout,
clearTimeout,
Expand All @@ -41,10 +43,10 @@ module.exports = class Sandbox {
buildWrappedConsole() {
let wrappedConsole = Object.create(console);

wrappedConsole.error = function(...args) {
wrappedConsole.error = function (...args) {
console.error.apply(
console,
args.map(function(a) {
args.map(function (a) {
return typeof a === 'string' ? chalk.red(a) : a;
})
);
Expand Down
Loading

0 comments on commit 13e6512

Please # to comment.