nopp icon indicating copy to clipboard operation
nopp copied to clipboard

[BUG]: harmless updates to objects are also blocked

Open misterfish opened this issue 1 year ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Description of the bug

This is useful but it seems to be quite impractical to use unfortunately. Even harmless updates are blocked, causing a runtime error. Such updates could happen at any time in your program, especially in libraries you don't control. Are there any known workarounds for this?

Steps To Reproduce

import 'nopp'
const o = {}
o.toString = function () { return '10' } // runtime error

toString is defined on Object.prototype and the freezing process prevents us even from shadowing toString on our own object. (The same is true for valueOf).

You can get around this like this:

...
// o.toString = function () { return '10' } // runtime error
Object.defineProperty (o, 'toString', { value: function () { ... } })

or if you happen to have included toString when you made the object:

...
const o = { toString: ... }
o.toString = function () { ... } // ok

but all in all it's really hard to be sure there won't be runtime errors if you're using any libraries.

Additional Information

No response

misterfish avatar Jun 13 '23 20:06 misterfish