class JS::Promise
def catch(&block)
def catch(&block) js_callback = %x{ function(error) { var ruby_result = #{block.call(wrap_result(`error`))}; if (ruby_result && typeof ruby_result.then === 'function') { return ruby_result; } else if (ruby_result && typeof ruby_result.to_n === 'function') { return ruby_result.to_n(); } else { return ruby_result; } } } self.native = `#{to_n}.catch(#{js_callback})` end
def then(&block)
def then(&block) js_callback = %x{ function(value) { var ruby_result = #{block.call(wrap_result(`value`))}; if (ruby_result && typeof ruby_result.then === 'function') { return ruby_result; } else if (ruby_result && typeof ruby_result.to_n === 'function') { return ruby_result.to_n(); } else { return ruby_result; } } } self.native = `#{to_n}.then(#{js_callback})` end