protect code that requires handle scope

We don't put a top handle scope in the message loop now.
These are the cases that code runs without any handle scope.