There's also the getDistanceFromGround function...
Yes, that tells you how far you're away from a baseplate / root brick. It'd be the basis of this test.
For example:

If you want to delete the brick marked on the right, you will have to check whether it leaves the two connected ones unsupported. Our current distance is 3.
The lower one is easy, it's distance is smaller than the current. It's safe.
The top one however... you have to follow through the tree until you discover a brick with a distance that is smaller than the current one. So that's all the way across to the other side, then back. You also have to make sure you're not getting stuck in loops, and do this for every connected brick. It'll be an enormous task to handle in torkscript.
::willCauseChainKill() does pretty much exactly this in c++.