You can use TextEncoder
and friends inside a javascript module. But doing so might be an overkill, if all you want is a couple of missing globals (putting aside the fact that jsm
are cached and this might not work well with a restartless addon).
Conveniently Addon SDK's loader delivers what you need.
const { TextDecoder, TextEncoder } = Cu.import('resource://gre/modules/commonjs/toolkit/loader.js', {});