ecmascript: Add code to destroy registered properties when unloading plugins

Fixes #2437