class RubyRunJs::OPCODES::WITH

———— WITH + ITERATORS ———-

Public Class Methods

new(label_start, label_end) click to toggle source
# File lib/ruby_run_js/opcodes.rb, line 829
def initialize(label_start, label_end)
  @label_start = label_start
  @label_end = label_end
end

Public Instance Methods

eval(ctx) click to toggle source
# File lib/ruby_run_js/opcodes.rb, line 834
def eval(ctx)
  obj = to_object(ctx.stack.pop(), ctx.builtin)

  scope = ObjectScope.new(obj, ctx, ctx.builtin)

  scope.this_binding = ctx.this_binding
  status = ctx.builtin.executor.run_under_control( \
      scope, @label_start, @label_end)

  ctx.stack.pop()

  type, return_value, label = status
  if type == 0  # normal
    ctx.stack.append(return_value)
    return nil
  elsif type == 1  # return
    ctx.stack.append(return_value)
    return :Return  # send return signal
  elsif type == 2  # jump outside
    ctx.stack.append(return_value)
    return label
  elsif type == 3
      # throw is made with empty stack as usual
    raise return_value
  else
    raise "Unexpected Type: #{type}"
  end
end