[Truffle] Be explicit about what the guards are applying to.
[Truffle] Removed unnecessary casts.
[Truffle] Use a NameError rather than NoMethodError for bad references on main object.

Fixes #2289 for Truffle: Incorrect exception type for bad reference.