Enhanced Applet On Quit Handler: Why is it repeating?

Experiencing this issue with my stay open enhanced applet created with SD 8. The continue quit statement in the on quit handler seems to call the quit handler. It doesn’t do so recursively; it only calls the quit handler the first time it is executed. The second time it executes it doesn’t call the quit handler again, but it doesn’t seem to actually quit either. The applet if launched from Finder/the Doc (outside SD 8) will remain open after quitting.

Try this as a demo stay open enhanced applet in SD 8.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on run
	say "running"
	quit
end run

on quit
	say "quitting"
	if (name of current application as text) is "Script Editor" or (name of current application as text) is "Script Debugger" then
		say "user cancelled error"
		error number -128
	else
		say "continue quit"
		continue quit
	end if
end quit

I get the same behavior on my system. Sort of.

On first run (and now and then on later runs), it said “Running, quitting, continue quit”, then it quit.

But then I got an “Apple Problem Report” dialog saying “QuitHandlers quit unexpectedly”

On most subsequent runs it said those things twice and then quit without the error dialog. But the error dialog pops up every now and then after saying it once without repeating.

Running from an Apple applet it ran fine every time.
I can provide the Apple crash details if that would help.

→ Script Debugger 7.0.13 (7A125)
→ Mac OS 10.11.6 (15G22010)

I’m using Script Debugger 8, not 7, so that might explain the slightly different results.

I seem to have found a work around. In the on run handler, if I call “continue quit”, rather than “quit”, the quit handler is called and executes just once, even when running in the enhanced applet shell.

What happens if you do that in the standard applet? (On mine it just says “running” then quits).

It’s good to have a workaround, but it’s also good to let Mark and Shane know that the behavior of enhanced and standard is different (in case they didn’t know already). The crash I’m getting may actually be helpful in tracking down the issue.