Feature Request: `with` statement for SES (Secure EcmaScript) support
Problem
Continuing our convo
- https://github.com/facebook/hermes/issues/957
We have no plans to support non-strict local
evalorwith- unfortunately they are incompatible with our code generation strategy and bytecode instructions. It is theoretically possible to implement them on top of JS objects with the existing bytecode, but the effort would be significant and the performance truly appalling...
...FWIW, I think we might be able to add support for
with. It feels wrong to completely ignore a language feature that has been with us for many years. It also feels good to pass most of test262. Plus, the implementation is interesting and will not slow everything down. But I can't promise it is high priority.
in order to introduce SES to our RN ecosystem (starting with metamask-mobile)
we can get by without local eval, but with statements are required
Solution
with statements support 🙏
Alternatives considered
- facebook/hermes community contribution:
withstatements - more detailed in https://github.com/facebook/hermes/issues/957
- https://github.com/endojs/endo/issues/1561
Additional Context
https://github.com/facebook/hermes/blob/main/doc/Features.md#excluded-from-support
Excluded From Support
Symbol.unscopables(Hermes does not supportwith)withstatements
hermesengine.dev/playground
# with ([1, 2, 3]) {
# console.log(toString()); // 1,2,3
# }
/tmp/hermes-input.js:1:1: error: invalid statement encountered.
with ([1, 2, 3]) {
^~~~~~~~~~~~~~~~~~
Emitted 1 errors. exiting.
@tmikov noting this won't slow everything down, but not promised as high priority do you have an update on the timeframe? and would you be happy to accept a community contribution?
keen to know more on the interesting implementation and any pointers (like given for eval in the past) to give it a try
@leotm unfortunately the answer is tricky. Ordinarily we are very happy to accept community contributions (although historically we have gotten very few, and the bar for changing the compiler is quite high).
The problem is that the current version of Hermes is frozen, except for bug fixes, while the next version, which is developed in a branch, has diverged significantly, particularly in the area of variable resolution and code generation, which is precisely where with would be handled. Worse, the next version is changing very rapidly at the moment, so it is not a very suitable target.
Even if we were to implement "with" in the frozen version, it wouldn't be portable to the next version.
Let me think about the best way to do this.
thanks again for the detailed update and porting previous issue here (i didn't spot 🙈)
happy to assist when thoughts have marinated, like with test cases covering the SES with requirement (in addition to test262)