Class: RubyRunJs::OPCODES::STORE_MEMBER_DOT_OP

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(prop, op) ⇒ STORE_MEMBER_DOT_OP

Returns a new instance of STORE_MEMBER_DOT_OP.



587
588
589
590
# File 'lib/ruby_run_js/opcodes.rb', line 587

def initialize(prop, op)
  @prop = prop
  @op = op
end

Instance Method Details

#eval(ctx) ⇒ Object



592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
# File 'lib/ruby_run_js/opcodes.rb', line 592

def eval(ctx)
  value = ctx.stack.pop()
  left = ctx.stack.pop()

  if is_primitive(left)
    if left.js_type == :Null
        raise make_error('TypeError',
                        "Cannot set property '#{@prop}' of null")
    elsif left.js_type == :Undefined
        raise make_error('TypeError',
                        "Cannot set property '#{@prop}' of undefined")
    end
    ctx.stack.append(binary_operation(@op, get_member(left, @prop, ctx.builtin), value))
  else
    ctx.stack.append(binary_operation(@op, get_member(left, @prop, ctx.builtin), value))
    left.put(@prop, ctx.stack[-1])
  end
  nil
end