Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
G. Gibson
@mistergibson
Sorry for all the pestering - I'm just still giddy with the prospect of coding in Ruby .... IN a webpage! Awesome.
Mitch VanDuyn
@catmando
Is there any known issue (or changes in behavior) in Opal 0.11 around the second parameter of const_get and const_defined?
specifically we have code with const_get(xxx, false) (meaning do not search down tree) and it broke in Opal 0.11
Elia Schito
@elia
@catmando the const lookup was rewritten, as far as you know the new behavior differs from MRI?
Mitch VanDuyn
@catmando
we don't know in detail.... just got a report from @sfcgeorge that code which was working with const_get(xxx, false) or perhaps const_defined? stopped working in 11, until he changed false to true.
that is all I know ATM
Elia Schito
@elia
@catmando ok, that could be a collateral effect of the improved behavior, @sfcgeorge let me know what's that, if it's an actual issue I'd like to look into it
Mitch VanDuyn
@catmando
@elia is there any way to run try opal on older versions?
Simon George
@sfcgeorge

A version selector on Try Opal would be amazingly helpful.

In this case I just know that making the second parameter true made something work in 0.11 that had worked in 0.10. I don't know which one the bug is in though, just because it worked before doesn't mean it was working as intended.

Elia Schito
@elia
@catmando no, but you can run the CLI on any installed version with opal _0.10.5_ -e 'p RUBY_ENGINE_VERSION'
@sfcgeorge yeah, 0.11 catched a bunch of errors in one of my apps
Mitch VanDuyn
@catmando
@elia :-) I have never used the CLI
I will try it now :-)
is there an opal irb ?
Mitch VanDuyn
@catmando
@elia - just using some simple tests I can see no behavior change...
Elia Schito
@elia
@catmando there's opal-repl, it needs thrubyracer IIRC
G. Gibson
@mistergibson
@elia I'm having trouble adding methods to class String - is this unsupported?
Elia Schito
@elia
should work fine, unless you're trying to mutate the string, inheriting from String it's more of a hackery but still supported
G. Gibson
@mistergibson
no, it mainly is for some methods that do regex matching
Elia Schito
@elia
@mistergibson can you paste your attempt here?
G. Gibson
@mistergibson
yeah, I'll whip up a gist for you
Elia Schito
@elia
Looks good, what kind of error are you getting?
G. Gibson
@mistergibson
This: uncaught exception: TypeError: can't convert String into Kernel::String (String#to_str gives String
I was surprised
Elia Schito
@elia
Seems to be working here, p "AsdfAasdf".split_camelcase resulted in ["Asdf", "Aasdf"]
G. Gibson
@mistergibson
I wonder what the deal is?
it won't even accept my method defs
it must be in the way I'm building the bootstrap
Elia Schito
@elia
maybe it's some weird interaction due to all those requires, try removing most of them and see if it works, if it does then you can start looking for the one to blame
G. Gibson
@mistergibson
sure
G. Gibson
@mistergibson
Hrm ... loaded it right after 'opal/full' and got the same error - never makes it to the other requires.
Elia Schito
@elia
have you tried just with 'opal'?
G. Gibson
@mistergibson
That's my next stop :)
Same error
so .... require 'opal' ... then the .rb file on require_remote gives the error.
Elia Schito
@elia
gotta go to sleep :crescent_moon: , I'll read tomorrow :wave:
G. Gibson
@mistergibson
ok ... sleep tight :)
G. Gibson
@mistergibson
@elia -- when you get up: When I exclude 'opal-parser' I don't get the error.
Ghost
@ghost~59874280d73408ce4f704e9c

@elia i think there is a bug in js inlining, sometimes not generating a necessary return
example opal-active support String.camelize
non-working, generated by 0.11:

return (Opal.defn(self, '$camelize', TMP_String_camelize_2 = function $$camelize(first_letter) {
      var self = this;

      if (first_letter == null) {
        first_letter = "upper";
      }
      self.$underscore().replace(/(^|_)([^_]+)/g, function(match, pre, word, index) {
      var capitalize = first_letter === "upper" || index > 0;
      return capitalize ? word.substr(0,1).toUpperCase()+word.substr(1) : word;
    })

manual workaround:

    return (Opal.defn(self, '$camelize', TMP_String_camelize_2 = function $$camelize(first_letter) {
      var self = this;

      if (first_letter == null) {
        first_letter = "upper";
      }
      return self.$underscore().replace(/(^|_)([^_]+)/g, function(match, pre, word, index) {
      var capitalize = first_letter === "upper" || index > 0;
      return capitalize ? word.substr(0,1).toUpperCase()+word.substr(1) : word;
    })
note the added return in the middle
original code:
  def camelize(first_letter = :upper)
    `#{underscore}.replace(/(^|_)([^_]+)/g, function(match, pre, word, index) {
      var capitalize = #{first_letter} === #{:upper} || index > 0;
      return capitalize ? word.substr(0,1).toUpperCase()+word.substr(1) : word;
    })`
  end
workaround:
  def camelize(first_letter = :upper)
    `return #{underscore}.replace(/(^|_)([^_]+)/g, function(match, pre, word, index) {
      var capitalize = #{first_letter} === #{:upper} || index > 0;
      return capitalize ? word.substr(0,1).toUpperCase()+word.substr(1) : word;
    })`
  end
Ghost
@ghost~59874280d73408ce4f704e9c
now, where would i have to look for fixing this in the compiler?
Ghost
@ghost~59874280d73408ce4f704e9c
or how can i debug such things?
Simon George
@sfcgeorge
That native inlining issue @janbiedermann mentions is reported here opal/opal-activesupport#16 - Another workaround is rather than adding a return you can just call .to_s on the backtick string. I don't know why that would change what is happening. Does it force a native value to be cast into an Opal value or something?
Elia Schito
@elia

@janbiedermann try adding a semicolon before closing the backticks, that said to debug this kind of stuff I often do

opal -cEO -e "def foo; `return 123, function(){}` end"

and

opal --sexp  -e "def foo; `return 123, function(){}` end"
Ghost
@ghost~59874280d73408ce4f704e9c
@sfcgeorge when you add the the .to_s the compiler adds the returnabove, thats why it works with .to_s
Simon George
@sfcgeorge
@janbiedermann Interesting. That almost makes it seem like expected behaviour. If you show you intend to use the value then it returns it. Seems unhelpful though, especially if you don't know what the return type will be.