Patch from Anonymous
Thanks to Iliad for finding this! :^)
If we have a function as class extends value, we still cannot assume that it has a prototype property and that property has a function or null as its value - blindly calling to_object() on it may fail. Fixes #5075.