These are chat archives for opal/opal

1st
Jun 2016
Mitch VanDuyn
@catmando
Jun 01 2016 18:58
@adamcreekroad you said you had a problem with opal 9.0 and reactrb ?
Adam
@adamcreekroad
Jun 01 2016 19:02

@catmando Yeah, the problem seems to be in stdlib/native.rb in the initialize method of Hash.

in 0.9 is does
if (defaults !== undefined && defaults.constructor === Object) {
which raises the error
TypeError: Cannot read property 'constructor' of null

in 0.8 it checks

    if (defaults != null) {
            if (defaults.constructor === Object) {

so switching it to
if (defaults != null && defaults.constructor === Object) {

makes everything (to my knowledge) work fine again.

Mitch VanDuyn
@catmando
Jun 01 2016 19:03
can you paste the bigger context?
Adam
@adamcreekroad
Jun 01 2016 19:05

Opal 0.9 (broken)

    def initialize(defaults = undefined, &block)
      %x{
        if (defaults !== undefined && defaults.constructor === Object) {
          var smap = self.$$smap,
              keys = self.$$keys,
              key, value;
          for (key in defaults) {
            value = defaults[key];
            if (value && value.constructor === Object) {
              smap[key] = #{Hash.new(`value`)};
            } else if (value && value.$$is_array) {
              value = value.map(function(item) {
                if (item && item.constructor === Object) {
                  return #{Hash.new(`item`)};
                }
                return item;
              });
              smap[key] = value
            } else {
              smap[key] = #{Native(`value`)};
            }
            keys.push(key);
          }
          return self;
        }
        return #{_initialize(defaults, &block)};
      }
    end

Opal 0.9 (what is working for me

def initialize(defaults = undefined, &block)
      %x{
        if (defaults != null && defaults.constructor === Object) {
          var smap = self.$$smap,
              keys = self.$$keys,
              key, value;
          for (key in defaults) {
            value = defaults[key];
            if (value && value.constructor === Object) {
              smap[key] = #{Hash.new(`value`)};
            } else if (value && value.$$is_array) {
              value = value.map(function(item) {
                if (item && item.constructor === Object) {
                  return #{Hash.new(`item`)};
                }
                return item;
              });
              smap[key] = value
            } else {
              smap[key] = #{Native(`value`)};
            }
            keys.push(key);
          }
          return self;
        }
        return #{_initialize(defaults, &block)};
      }
    end
Mitch VanDuyn
@catmando
Jun 01 2016 19:08
so where is this called from in reactrb?
Adam
@adamcreekroad
Jun 01 2016 19:13
module React
  class StateWrapper < BasicObject
    def initialize(native, from)
      @state_hash = Hash.new(`#{native}.state`)
      @from = from
    end
...
  end
end
at Hash.new
Mitch VanDuyn
@catmando
Jun 01 2016 19:14
Does anybody know why the above changed (Hash.new(...)) in Opal 0.9???
looks like what you want is:
defaults !== undefined && defaults != null && defaults.constructor === Object
Can you do a PR for that for opal?
meanwhile I will put a monkey patch in the reactrb branch that works with 0.9
deal?
Adam
@adamcreekroad
Jun 01 2016 19:47
yeah I can do that
Mitch VanDuyn
@catmando
Jun 01 2016 20:10
@vais - we just hit a problem with opal 0.9 (see above discussion)... We are counting on
Hash.new(`null`)
but since your recent commit only checks defaults for undefined are you okay with updating to check null and undefined ?