[ESNext] Implement nullish coalescing
Created attachment 374762 [details] Patch
Created attachment 374765 [details] Patch
Comment on attachment 374765 [details] Patch Feature flag, please! (Looks like at least a compile-time flag should be practical, and maybe even runtime if it wasn't too much of a perf hit).
(In reply to Maciej Stachowiak from comment #3) > Comment on attachment 374765 [details] > Patch > > Feature flag, please! (Looks like at least a compile-time flag should be > practical, and maybe even runtime if it wasn't too much of a perf hit). Will do!
Created attachment 374782 [details] Patch
Comment on attachment 374782 [details] Patch I believe it should suffice to simply refuse to lex the token -- let me know if we'd like to do this differently. (I'll probably also want to update this flag to be useNullishAwareOperators in the ?. patch but there's no need to jump the gun here.)
Created attachment 374795 [details] Patch
Comment on attachment 374795 [details] Patch LGTM overall. I think it would be good have tests covering short circuiting.
Created attachment 374817 [details] Patch
(In reply to Caio Lima from comment #8) > Comment on attachment 374795 [details] > Patch > > LGTM overall. I think it would be good have tests covering short circuiting. Good call! Added these as well as a makeMasquerader case to cover the document.all behavior.
Comment on attachment 374817 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=374817&action=review > Source/JavaScriptCore/parser/ASTBuilder.h:1397 > + return new (m_parserArena) CoalesceNode(location, lhs.first, rhs.first); What’s the pro and con for extending LogicalOpNode instead adding a new class? > Source/JavaScriptCore/parser/ResultType.h:184 > + if (op1.definitelyIsBoolean() || op1.definitelyIsNumber() || op1.definitelyIsString() || op1.definitelyIsBigInt()) Could this be "definitelyIsNotNull" instead? I think we could possibly correctly cover more cases and have more maintainable code that way.
Thanks for the review! (In reply to Darin Adler from comment #11) > > Source/JavaScriptCore/parser/ASTBuilder.h:1397 > > + return new (m_parserArena) CoalesceNode(location, lhs.first, rhs.first); > > What’s the pro and con for extending LogicalOpNode instead adding a new > class? Hmm, we could do that given how similar the emitBytecode implementation is, but the emitBytecodeInConditionContext would not apply (I guess we'd just early out to emitBytecode) and we'd still call a different ResultType function. I personally thought the separation might be clearer, but do you have a preference? > > Source/JavaScriptCore/parser/ResultType.h:184 > > + if (op1.definitelyIsBoolean() || op1.definitelyIsNumber() || op1.definitelyIsString() || op1.definitelyIsBigInt()) > > Could this be "definitelyIsNotNull" instead? I think we could possibly > correctly cover more cases and have more maintainable code that way. We could do definitelyIsNotNullOrUndefined by checking against TypeMaybeNull and TypeMaybeOther, sure.
Created attachment 374860 [details] Patch for landing
Created attachment 374863 [details] Patch for landing
Created attachment 374864 [details] Patch for landing
Comment on attachment 374864 [details] Patch for landing Clearing flags on attachment: 374864 Committed r247819: <https://trac.webkit.org/changeset/247819>
All reviewed patches have been landed. Closing bug.
<rdar://problem/53531846>