moz-http2-child.js (982B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /* eslint-env node */ 6 7 function sendBackResponse(messageId, evalResult, e) { 8 const output = { result: evalResult, error: "", errorStack: "", messageId }; 9 if (e) { 10 output.error = e.toString(); 11 output.errorStack = e.stack; 12 } 13 process.send(output); 14 } 15 16 process.on("message", msg => { 17 const code = msg.code; 18 const messageId = msg.messageId; 19 let evalResult = null; 20 try { 21 // eslint-disable-next-line no-eval 22 evalResult = eval(code); 23 if (evalResult instanceof Promise) { 24 evalResult 25 .then(x => sendBackResponse(messageId, x)) 26 .catch(e => sendBackResponse(messageId, undefined, e)); 27 return; 28 } 29 } catch (e) { 30 sendBackResponse(messageId, undefined, e); 31 return; 32 } 33 sendBackResponse(messageId, evalResult); 34 });