ChakraCore
ChakraCore copied to clipboard
Optional chaining
This PR aims to add support for the stage-4 proposal optional-chaining. It's inspired by the work of @rhuanjl but uses a more hacky approach to parsing.
Goals
- Minimize amount of changes
- (Hopefully) Performance
ToDo
- [x] Add tests
- [x] Unused expression result
- [x] Return expression
- [x] Root optional-call (e.g.
eval?.('a')) - [x] Scoped method load (e.g. inside
eval) - [x]
delete
- [x] implement optional-deletion
- [x] optional call invoked on eval function should be indirect eval
- [x] Simple function calls
- [x] Preserve
this(a.b)().cshould be equivalent toa.b().c - [x] short circuit embedded expressions like
a?.[++x]++xshould not be evaluated ifaisnullorundefined - [x] Don't tokenize
a?.3:0(ternary) astkOptChain(?.) - [x] Tagged templates are not allowed in optional chain
- [x] fix
tmp-renaming forevalresulteval("foo?.()")oreval("foo?.property") - [ ] Works with optimizations
- [ ] What about the
applycall optimization? - [x] Loop inversion (AST cloning)
Only triggered for 2 nested
forloops with assignment https://github.com/chakra-core/ChakraCore/blob/e26c81f6eabf3b4c0f45c3963be807d3ea90c63e/test/loop/loopinversion.js#L60-L66
- [ ] What about the
Out of scope
- Remove
EmitInvoke(seems unused) - Better error message for a call on a non-function
Spec: Optional Chains Fixes #6349
I'm currently working on function calls. At the moment it would just be handled as if no optional-chaining would be used ⇾ crash in js land
Edit: Function call should work now but this is not always propagated correctly (yet)
Edit: Function calls should now work
The jitted code currently crashes at this assertion (causing the test-failures) https://github.com/chakra-core/ChakraCore/blob/1f6e17c4c55231846596223eab8ab36360349fa3/lib/Backend/GlobOpt.cpp#L11384