summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-catch/mrblib/catch.rb
AgeCommit message (Collapse)Author
2021-02-12Add `UncaughtThrowError#{tag,value}` for Ruby compatibilityKOBAYASHI Shuji
2021-02-10Refactor `mruby-catch`; ref #5328Yukihiro "Matz" Matsumoto
- Move `#catch` definition to `mruby-catch.c` to avoid tweaking - Remove `#__preserve_catch_method` - Implement whole `#throw` method in C
2021-02-06Reimplement mruby-catch; ref #5321dearblue
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.
2021-02-06Make the argument of `Kernel#catch` optional as Ruby doesKOBAYASHI Shuji
Also implement the following changes. * Add tests * Use `Object#equal?` to compare tags for Ruby compatibility * Use `attr_reader`
2021-02-05Fix message of `ThrowCatchJump` in `mruby-catch` gemKOBAYASHI Shuji
### Example ```ruby begin throw 1 rescue Exception => e puts e.message end ``` #### Before this patch: ```console $ bin/mruby example.rb uncaught throw :1 ``` #### After this patch (same as Ruby): ```console $ bin/mruby example.rb uncaught throw 1 ```
2020-10-12Add a new gem: `mruby-catch`.Yukihiro "Matz" Matsumoto
Implements `catch`/`throw` non-local jump inherited from Lisp. `catch([tag]) {|tag| block } -> obj` Example: ``` catch(:foo) { 123 } # => 123 catch(:foo) { throw(:foo, 456) } # => 456 catch(:foo) { throw(:foo) } # => nil ```