  We prove an abstract modularity result for classes of Heegner divisors in the
generalized Jacobian of a modular curve associated to a cuspidal modulus.
Extending the Gross-Kohnen-Zagier theorem, we prove that the generating series
of these classes is a weakly holomorphic modular form of weight 3/2. Moreover,
we show that any harmonic Maass forms of weight 0 defines a functional on the
generalized Jacobian. Combining these results, we obtain a unifying framework
and new proofs for the Gross-Kohnen-Zagier theorem and Zagier's modularity of
traces of singular moduli, together with new geometric interpretations of the
traces with non-positive index.
