• dearblue's avatar
    Reimplement mruby-catch; ref #5321 · 232e07ad
    dearblue authored
    When there is a corresponding tag, the `RBreak` object is used to make a global jump.
    
    Like CRuby, it can't be caught by `rescue`.
    It is also the same as CRuby that it can be canceled in the middle by `ensure`.
    
     ### How to find the corresponding tag with `throw`
    
    The called `catch` method remains in the call stack, and the tag also remains in the stack at that time.
    So it is possible to find the called location by searching the two.
    
    Note that no method can be given to the `proc` object specified in `RBreak`.
    Therefore, inside the `catch` method, the argument block is called in a seemingly meaningless closure.
    
    Also, as a countermeasure against `alias` etc., the `proc` object, which is the body of the `catch` method, is saved when mrbgem is initialized.
    232e07ad
catch.rb 541 Bytes