From 10f36d7392f9070f4af75ae757b61b56d4da3294 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Sun, 3 May 2015 19:21:35 -0700 Subject: [PATCH 1/3] Bind the step function to the active domain (if present) --- runtime.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/runtime.js b/runtime.js index 186a09f12..017f8e51f 100644 --- a/runtime.js +++ b/runtime.js @@ -105,10 +105,8 @@ runtime.async = function(innerFn, outerFn, self, tryLocsList) { return new Promise(function(resolve, reject) { var generator = wrap(innerFn, outerFn, self, tryLocsList); - var callNext = step.bind(generator, "next"); - var callThrow = step.bind(generator, "throw"); - function step(method, arg) { + var step = function(method, arg) { var record = tryCatch(generator[method], generator, arg); if (record.type === "throw") { reject(record.arg); @@ -121,8 +119,15 @@ } else { Promise.resolve(info.value).then(callNext, callThrow); } + }; + + if (process.domain) { + step = process.domain.bind(step); } + var callNext = step.bind(generator, "next"); + var callThrow = step.bind(generator, "throw"); + callNext(); }); }; From a7219b72bb83ec445660edbcf37bf71667a6032c Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Sun, 3 May 2015 19:26:48 -0700 Subject: [PATCH 2/3] Ensure that process is defined before use --- runtime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime.js b/runtime.js index 017f8e51f..a833670dd 100644 --- a/runtime.js +++ b/runtime.js @@ -121,7 +121,7 @@ } }; - if (process.domain) { + if (process && process.domain) { step = process.domain.bind(step); } From d3861889240cccb9b394ed460af58dc53328d1fc Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Sun, 3 May 2015 20:32:44 -0700 Subject: [PATCH 3/3] Check for process being undefined using typeof --- runtime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime.js b/runtime.js index a833670dd..0650c4de1 100644 --- a/runtime.js +++ b/runtime.js @@ -121,7 +121,7 @@ } }; - if (process && process.domain) { + if (typeof process !== "undefined" && process.domain) { step = process.domain.bind(step); }