Share code between HTMLScriptElement:Text and Node:GetTextContent

Added a function in Node called collect_text_contents which is called
from both places.

Fixes #3157