diff --git a/lib/worker.js b/lib/worker.js index 6d59a12901a4f3a9ff5df50a0f41fc288cd28d84..afb5dfec9049181612ce6477a0ac9878818ee373 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -3,7 +3,7 @@ var fs = require("fs"); var path = require("path"); var vm = require("vm"); -var noop = path.join(__dirname, "noop.js"); +var noop = require(path.join(__dirname, "noop.js")); function trim(arg) { return arg.replace(/^(\s+|\t+|\n+)|(\s+|\t+|\n+)$/g, ""); @@ -63,11 +63,11 @@ process.once("message", function (obj) { }); process.on("message", function (msg) { - global.self.onmessage(JSON.parse(msg)); + (global.self.onmessage || global.onmessage || noop)(JSON.parse(msg)); }); process.on("error", function (err) { - global.self.onerror(err); + (global.self.onerror || global.onerror || noop)(err); }); if (typeof exp === "function") { diff --git a/src/worker.js b/src/worker.js index 7e1a6cc7a4e8c6bc07cb5488cadbe5a938fb3bad..ee324f65f9ca4561e578a43dd3afb02f2bb69380 100644 --- a/src/worker.js +++ b/src/worker.js @@ -1,7 +1,7 @@ const fs = require("fs"); const path = require("path"); const vm = require("vm"); -const noop = path.join(__dirname, "noop.js"); +const noop = require(path.join(__dirname, "noop.js")); function trim (arg) { return arg.replace(/^(\s+|\t+|\n+)|(\s+|\t+|\n+)$/g, ""); @@ -56,11 +56,11 @@ process.once("message", function (obj) { }); process.on("message", function (msg) { - global.self.onmessage(JSON.parse(msg)); + (global.self.onmessage || global.onmessage || noop)(JSON.parse(msg)); }); process.on("error", function (err) { - global.self.onerror(err); + (global.self.onerror || global.onerror || noop)(err); }); if (typeof exp === "function") {