From 1d7773ad3b4cad33874633c91af5787d73136ac4 Mon Sep 17 00:00:00 2001 From: Kevin Townsend Date: Mon, 6 Nov 2023 17:38:59 -0500 Subject: [PATCH] Close some of the IE compatibility issues (#7) * es5 compatible * upticked --- index.js | 11 +++++++---- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index dacec6c..1ad9e3b 100644 --- a/index.js +++ b/index.js @@ -49,7 +49,7 @@ if (shouldPolyfillEventTarget) { ) { if (arguments.length < 2) { throw new TypeError( - `TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.` + "TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only " + arguments.length + " present." ); } const __listeners = this.__listeners; @@ -71,7 +71,7 @@ if (shouldPolyfillEventTarget) { ) { if (arguments.length < 2) { throw new TypeError( - `TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.` + "TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only " + arguments.length + " present." ); } const __listeners = this.__listeners; @@ -87,14 +87,17 @@ if (shouldPolyfillEventTarget) { EventTarget.prototype.dispatchEvent = function (event) { if (!(event instanceof Event)) { throw new TypeError( - `Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.` + "Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'." ); } const type = event.type; const __listeners = this.__listeners; const listenersForType = __listeners.get(type); if (listenersForType) { - for (const [listener, options] of listenersForType.entries()) { + for (var listnerEntry of listenersForType.entries()) { + const listener = listnerEntry[0]; + const options = listnerEntry[1]; + try { if (typeof listener === "function") { // Listener functions must be executed with the EventTarget as the `this` context. diff --git a/package-lock.json b/package-lock.json index a8185bc..43a31ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { "name": "event-target-polyfill", - "version": "0.0.0", + "version": "0.0.4", "lockfileVersion": 1 } diff --git a/package.json b/package.json index 5f00d59..55eda46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "event-target-polyfill", - "version": "0.0.3", + "version": "0.0.4", "description": "An EventTarget Polyfill", "main": "index.js", "exports": {