-
Notifications
You must be signed in to change notification settings - Fork 756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object.freeze(this) in a constructor restricts class extension #940
Comments
@cgewecke That's a great find, thanks for going into this! I have pushed #941, I think this should be a good way to handle it. People get still the increased security properties of freezing by default, but can also deactivate if necessary (I guess there also might be more customization cases where this is needed). If they do they have to explicitly make the decision and are also guided to re-enable by the comment from the option. When reading the code from Ganache you referenced I was a bit tempted to also remove the import { Transaction } from './src'
import { BN, toBuffer } from 'ethereumjs-util'
let tx = Transaction.fromTxData({})
tx.gasPrice = new BN(toBuffer('0x0005'))
console.log(tx.gasPrice) But this in fact does NOT throw but just keeps the value and outputs My suggestion now after these first experiences would be that we keep this Another thing I noticed: subclassing is not particularly user friendly with this new structure, since one has to pass all the tx main constructor parameter values to the Note: along with the PR mentioned I also fixed a significant bug with the options not being passed to the main constructor on the block static factory methods. |
(not sure would it makes sense to pass these data options here in as a dict to the main constructors of |
Wow - this I see this |
@jochem-brouwer thanks for giving this some thought! 🙂 Is this any-casting a provable working solution also in a JavaScript context? Or would JavaScript keep the read-only and forget about the any casting (just plainly guessing what could happen)? 🤔 |
@holgerd77 JavaScript doesn't have If you run your code as above in |
#923, #907
Object.freeze(this) is called at the end of the Transaction, Block, and BlockHeader constructors.
Surprisingly, if you extend any of these classes and add properties, the derived class's constructor throws.
Example
Throws
Am guessing the freeze locks the outputs of the new generators but I wonder if locating it in the constructor might be too restrictive for users who want to use these libs as a base for other work.
At ganache-core, for example, Transaction is extended here.
The text was updated successfully, but these errors were encountered: