Avoid crash when closing RStudio on Mac
Avoid crash when closing RStudio on Mac

`pEvent` is captured by reference in lambda passed to runJavaScript, but it's a raw pointer so there's no lifetime guarantee that it will still be valid when the callback fires. On the Mac, when closing via Cmd+Q, it is indeed bogus by then and the accept() call crashes.

Fix for this was to do the non-async "have we quit?" checks first. This triggers the pEvent->accept() without needing the async call.

There's still a theoretical window of opportunity for a crash here, if window.desktopHooks has gone away without triggering the other "have we quit?" conditions and pEvent goes away before the first callback fires.

JanMarvin/rstudio,JanMarvin/rstudio,JanMarvin/rstudio,JanMarvin/rstudio,JanMarvin/rstudio,JanMarvin/rstudio,JanMarvin/rstudio,JanMarvin/rstudio,JanMarvin/rstudio