Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2002 from estebanlm/22682-when-callback-fails-a-d…
…efault-value-should-be-returned-to-prevent-crashes 22682-when-callback-fails-a-default-value-should-be-returned-to-prevent-crashes
- Loading branch information
Showing
10 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Extension { #name : #BlockClosure } | ||
|
||
{ #category : #'*UnifiedFFI' } | ||
BlockClosure >> on: exception fork: handlerAction return: answerAction [ | ||
"This is the same as #on:fork: but instead just fork and letting the flow continues, in | ||
case of an error it also evaluates answerAction and returns its result." | ||
|
||
^ self on: exception do: [:ex | | ||
| onDoCtx handler bottom thisCtx | | ||
|
||
onDoCtx := thisContext. | ||
thisCtx := onDoCtx home. | ||
|
||
"find the context on stack for which this method's is sender" | ||
|
||
[ onDoCtx sender == thisCtx] whileFalse: [ | ||
onDoCtx := onDoCtx sender. | ||
onDoCtx ifNil: [ | ||
"Can't find our home context. seems like we're already forked | ||
and handling another exception in new thread. In this case, just pass it through handler." | ||
^ handlerAction cull: ex ] ]. | ||
|
||
bottom := [ Processor terminateActive ] asContext. | ||
onDoCtx privSender: bottom. | ||
|
||
handler := [ handlerAction cull: ex ] asContext. | ||
handler privSender: thisContext sender. | ||
|
||
(Process forContext: handler priority: Processor activePriority) resume. | ||
|
||
"cut the stack of current process" | ||
thisContext privSender: thisCtx. | ||
answerAction cull: exception ] | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters