Bug #3811 - Extracted the script task handlers into methods
auto merge of #3915 : shinglyu/servo/bug3811, r=jdm

This is a fix for bug #3811 , thank you.