Maybe add a script->IsFunction() assert here, Cast() is unchecked in release builds.

(Note to self: switch over to ASSERT and CHECK macros.)