1
0
Fork 0

Nasal/globals.nas: setlistener(): call die() if callback is not a function.

This avoids getting confusing errors later on, e.g. see bug 2641.
This commit is contained in:
Julian Smith 2021-08-26 22:06:54 +01:00
parent 89da92dd05
commit b6da3872f1

View file

@ -124,6 +124,12 @@ var interpolate = func(node, val...) {
# written to" (2).
#
var setlistener = func(node, fn, init = 0, runtime = 1) {
if (typeof(fn) != "func") {
# This avoids unhelpful failures later on when we try to call <fn> - we
# get an error without a useful backtrace, because property callbacks
# use a new Nasal context.
die(sprintf("setlistener() called with non-function; typeof(fn)=%s", typeof(fn)));
}
if (isa(node, props.Node)) node = node._g;
elsif (!isscalar(node) and !isghost(node))
die("bad argument to setlistener()");