Class: RubyRunJs::OPCODES::FOR_IN

Inherits:
OP_CODE
  • Object
show all
Defined in:
lib/ruby_run_js/opcodes.rb

Instance Method Summary collapse

Methods inherited from OP_CODE

#to_s

Methods included from RubyRunJs::Operation

#abstract_equality_op, #abstract_inequality_op, #abstract_relational_comparison, #add_op, #binary_operation, #bit_and_op, #bit_bshift_op, #bit_invert_uop, #bit_lshift_op, #bit_or_op, #bit_rshift_op, #bit_xor_op, #div_op, #float, #greater_eq_op, #greater_op, #in_op, #instanceof_op, #less_eq_op, #less_op, #logical_negation_uop, #minus_uop, #mod_op, #mul_op, #plus_uop, #strict_equality_op, #strict_inequality_op, #sub_op, #typeof_uop, #unary_operation, #void_op

Methods included from Helper

#check_object, #get_member, #get_member_dot, #is_accessor_descriptor, #is_callable, #is_data_descriptor, #is_generic_descriptor, #is_primitive, #make_error, #strict_equality

Methods included from ConversionHelper

#convert_to_js_type, #to_boolean, #to_int32, #to_integer, #to_number, #to_object, #to_primitive, #to_string, #to_uint16, #to_uint32

Constructor Details

#initialize(name, label_start, label_continue, label_break) ⇒ FOR_IN

Returns a new instance of FOR_IN.



867
868
869
870
871
872
# File 'lib/ruby_run_js/opcodes.rb', line 867

def initialize(name, label_start, label_continue, label_break)
  @name = name
  @label_start = label_start
  @label_continue = label_continue
  @label_break = label_break
end

Instance Method Details

#eval(ctx) ⇒ Object



874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
# File 'lib/ruby_run_js/opcodes.rb', line 874

def eval(ctx)
  iterable = ctx.stack.pop()
  if iterable == null || iterable == undefined
    ctx.stack.pop()
    ctx.stack.append(undefined)
    return @label_break
  end

  obj = to_object(iterable, ctx.builtin)

  obj.own.keys.sort.each do |k|
    unless obj.own[k]['enumerable']
      next
    end

    ctx.set_binding(@name, k)

    status = ctx.builtin.executor.run_under_control(\
      ctx, @label_start, @label_break)

    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)
      if label == @label_continue
        next
      end
      return label
    elsif type == 3
      raise return_value
    else
      raise "Unexpected Type: #{type}"
    end
  end

  return @label_break
end