From 758b3ae0b0711dac8b9d4f709ab42e4dc3d69de2 Mon Sep 17 00:00:00 2001 From: Emiliano Date: Tue, 27 Mar 2018 18:30:30 +0200 Subject: [PATCH] fixes elm/core#952 Checking callback type on port subscribe Currently calling `elm.ports[portName].subscribe(undefined)` will cause an exception only when subscribers get called, this commit adds a type check before pushing the callback on subscription list --- src/Elm/Kernel/Platform.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Elm/Kernel/Platform.js b/src/Elm/Kernel/Platform.js index d3cf8db0..d897ac5f 100644 --- a/src/Elm/Kernel/Platform.js +++ b/src/Elm/Kernel/Platform.js @@ -389,6 +389,11 @@ function _Platform_setupOutgoingPort(name) function subscribe(callback) { + if (typeof callback !== 'function') + { + throw new Error('Trying to subscribe an invalid callback on port `' + name + '`'); + } + subs.push(callback); }