class SyntaxTree::YARV::Throw
### Summary
‘throw` pops a value off the top of the stack and throws it. It is caught using the instruction sequence’s (or an ancestor’s) catch table. It pushes on the result of throwing the value.
### Usage
~~~ruby [1, 2, 3].map { break 2 } ~~~
Constants
- RUBY_TAG_BREAK
- RUBY_TAG_FATAL
- RUBY_TAG_NEXT
- RUBY_TAG_NONE
- RUBY_TAG_RAISE
- RUBY_TAG_REDO
- RUBY_TAG_RETRY
- RUBY_TAG_RETURN
- RUBY_TAG_THROW
- VM_THROW_NO_ESCAPE_FLAG
- VM_THROW_STATE_MASK
Attributes
Public Class Methods
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5713 def initialize(type) @type = type end
Public Instance Methods
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5729 def ==(other) other.is_a?(Throw) && other.type == type end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5745 def call(vm) state = type & VM_THROW_STATE_MASK value = vm.pop case state when RUBY_TAG_NONE case value when nil # do nothing when Exception raise value else raise NotImplementedError end when RUBY_TAG_RETURN raise VM::ReturnError.new(value, error_backtrace(vm)) when RUBY_TAG_BREAK raise VM::BreakError.new(value, error_backtrace(vm)) when RUBY_TAG_NEXT raise VM::NextError.new(value, error_backtrace(vm)) else raise NotImplementedError, "Unknown throw kind #{state}" end end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5725 def deconstruct_keys(_keys) { type: type } end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5717 def disasm(fmt) fmt.instruction("throw", [fmt.object(type)]) end
Source
# File lib/syntax_tree/yarv/instructions.rb, line 5721 def to_a(_iseq) [:throw, type] end