Skip to content
Snippets Groups Projects
Commit 6ae5234a authored by Jason Mulligan's avatar Jason Mulligan
Browse files

Synchronizing the validation of `addEventListener()`

parent 14a9a911
Branches
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ var fs = require("fs"); ...@@ -4,6 +4,7 @@ var fs = require("fs");
var path = require("path"); var path = require("path");
var vm = require("vm"); var vm = require("vm");
var noop = require(path.join(__dirname, "noop.js")); var noop = require(path.join(__dirname, "noop.js"));
var events = /^(error|message)$/;
function trim(arg) { function trim(arg) {
return arg.replace(/^(\s+|\t+|\n+)|(\s+|\t+|\n+)$/g, ""); return arg.replace(/^(\s+|\t+|\n+)|(\s+|\t+|\n+)$/g, "");
...@@ -34,7 +35,9 @@ process.once("message", function (obj) { ...@@ -34,7 +35,9 @@ process.once("message", function (obj) {
onmessage: void 0, onmessage: void 0,
onerror: void 0, onerror: void 0,
addEventListener: function addEventListener(event, fn) { addEventListener: function addEventListener(event, fn) {
global["on" + event] = global.self["on" + event] = fn; if (events.test(event)) {
global["on" + event] = global.self["on" + event] = fn;
}
} }
}; };
......
{ {
"name": "tiny-worker", "name": "tiny-worker",
"version": "1.1.3", "version": "1.1.4",
"description": "Tiny WebWorker for Server", "description": "Tiny WebWorker for Server",
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {
......
...@@ -2,6 +2,7 @@ const fs = require("fs"); ...@@ -2,6 +2,7 @@ const fs = require("fs");
const path = require("path"); const path = require("path");
const vm = require("vm"); const vm = require("vm");
const noop = require(path.join(__dirname, "noop.js")); const noop = require(path.join(__dirname, "noop.js"));
const events = /^(error|message)$/;
function trim (arg) { function trim (arg) {
return arg.replace(/^(\s+|\t+|\n+)|(\s+|\t+|\n+)$/g, ""); return arg.replace(/^(\s+|\t+|\n+)|(\s+|\t+|\n+)$/g, "");
...@@ -32,7 +33,9 @@ process.once("message", obj => { ...@@ -32,7 +33,9 @@ process.once("message", obj => {
onmessage: void 0, onmessage: void 0,
onerror: void 0, onerror: void 0,
addEventListener: (event, fn) => { addEventListener: (event, fn) => {
global["on" + event] = global.self["on" + event] = fn; if (events.test(event)) {
global["on" + event] = global.self["on" + event] = fn;
}
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment