Skip to content
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

Optional chaining #2221

Closed

Conversation

mariusGundersen
Copy link
Contributor

This adds support for the three types of optional chaining:

a?.b // returns b unless a is nullish
a?.() // calls the function a unless a is nullish
a?.[0] // returns the first item in the array a unless a is nullish

@mariusGundersen
Copy link
Contributor Author

This is wished for here: #1302 (comment)

@mariusGundersen mariusGundersen marked this pull request as ready for review June 10, 2022 10:57
if (functionName)
jsiConsolePrintf("Stepping into %v\n", functionName);
else
jsiConsolePrintf("Stepping into function\n", functionName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed these spaces got replaced with tabs. Please can you try and tweak these (and change your editor so tabs don't get added?). It really screws up the layout if someone views the code and doesn't have 8 space tabs set

@@ -1123,6 +1150,10 @@ NO_INLINE JsVar *jspeFactorMember(JsVar *a, JsVar **parentResult) {
jsvUnLock(aVar);
}
jsvUnLock(index);

#ifndef ESPR_NO_OPTIONAL_CHAINING
JSP_RESTORE_EXECUTE();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this breaks stuff. undefined[1] should cause an exception (like 1143) but JSP_RESTORE_EXECUTE removes the error flag, so it just quietly completes. I can imagine there might be other code you could come up with (not just errors, but return/break/etc) too

@gfwilliams
Copy link
Member

Sorry it's taken so long to look into this! But I am a bit concerned about the use of JSP_SAVE_EXECUTE/RESTORE - they need to be used with real care so you don't accidentally remove execution state. I think it might be possible to make it work without them though, as all you care about is executing or not (rather than any of the other state)

@gfwilliams gfwilliams closed this Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants