There are some ways to do this.
One easy way is to define a (new) white color.
Replace these 2 lines:
doc.selection.select(mySelection); doc.mySelection.fill ("White");
with this:
var white = new SolidColor(); white.rgb.red = white.rgb.green = white.rgb.blue = 255; doc.selection.select(mySelection); doc.selection.fill (white); doc.selection.deselect();
Have fun