fixed possible null pointer crash in emit() callback

because JSON.stringify(undefined) => undefined, but
JSON.stringify(null) => "null"