These are chat archives for opal/opal

20th
Jul 2016
Doug Orleans
@dougo
Jul 20 2016 03:32
I finally dived in and made a fork of opal. When I run the specs I get one failure:
The rescue keyword parses 'a += b rescue c' as 'a += (b rescue c)' ERROR
Doug Orleans
@dougo
Jul 20 2016 04:05
bah, the optparse test uses String#<<.
Doug Orleans
@dougo
Jul 20 2016 06:12
hm, any chance of getting the conflicts in opal/opal#657 resolved? (better rand and srand)
Minitest --seed is kind of useless without it...
Everything is compiled in a single file but can we create a new @env in mspec-opal/runner https://github.com/opal/opal/blob/master/spec/mspec-opal/runner.rb#L87-L88 ?
Ilya Bylich
@iliabylich
Jul 20 2016 11:21
@Mogztter The idea is to replace explicit require-s in the generated tmp/mspec_nodejs.rb to just register running files using MSpec.register_files. Later we should call MSpec.files - https://github.com/ruby/mspec/blob/master/lib/mspec/runner/mspec.rb#L48-L61 - which iterates over registered files, loads them one by one, and executes in a separate @env. I'll send a PR soon
Probably we can even use the original MSpec's method that runs the whole test suite - MSpec.process - https://github.com/ruby/mspec/blob/master/lib/mspec/runner/mspec.rb#L42-L46
Mitch VanDuyn
@catmando
Jul 20 2016 19:11
hey all, trying to get execjs to evaluate opal code for middleman prerendering. Stole the code from react-rails. Problem is everytime I do a puts it blows up. its as if "puts" is some how emitting something into the execjs output buffer??? this is with opal 0.9.4... same version of execjs, and ruby-racer work fine for me in react-rails. Any ideas appreciated!
for example if I do this:
@context.eval("Opal.top.$puts('hi')")
exec-js sends this string to be the json parser!
"hi\n[\"ok\",{\"$$id\":4}]"
Mitch VanDuyn
@catmando
Jul 20 2016 19:31
for example:
Ilya Bylich
@iliabylich
Jul 20 2016 19:31
Nil has id=4 in opal
looks like it merges output and returning value
puts always returns nil
Mitch VanDuyn
@catmando
Jul 20 2016 19:33
@context.eval("(function() {console.log('hi'); return console.history})()") 
# returns [{"level"=>"log", "arguments"=>["hi"]}]
@context.eval("(function() {Opal.top.$puts('hi'); return console.history})()")
# throws an error because the above string is sent to be parsed
somehow I've managed to get Opal puts to squirt crap into V8s output buffer.
Ilya Bylich
@iliabylich
Jul 20 2016 19:35
console.log works in your example, could you try process.stdout.write(s)?
Mitch VanDuyn
@catmando
Jul 20 2016 19:36
sure... what is process?
Ilya Bylich
@iliabylich
Jul 20 2016 19:36
A property on the global object I guess
Call chain is the following: Kernel.puts -> $stdout.puts -> $stdout.write -> STDOUT.write_proc
Mitch VanDuyn
@catmando
Jul 20 2016 19:38
okay... yes that seems to be the problem. process.stdout is defined
not sure who or what is defining it!
Mitch VanDuyn
@catmando
Jul 20 2016 19:39
hah:
@context.eval("typeof(process) === 'object'")
=> true
you were right
Ilya Bylich
@iliabylich
Jul 20 2016 19:40
Looks like execjs works as some kind of output interceptor (which is actually very weird)
Ilya Bylich
@iliabylich
Jul 20 2016 19:47
I don't understand. console.log works, but process.stdout.write doesn't. But Nodejs documentation says that console.log internally invokes process.stdout.write - https://nodejs.org/api/console.html#console_new_console_stdout_stderr
Mitch VanDuyn
@catmando
Jul 20 2016 20:06
Its true, but react-rails (and my hack) overrides console.log to put the output into a "history" array.
So in fact console.log and process.stdout.write are again different..
but Opal doesn't know that... and is using process.stdout.write, which I believe is what execjs assumes will hold the output data
so the only thing I have to figure out how to do is redefine the way STDOUT.write_proc works. But I can't make it stick...
Forrest Chang
@fkchang
Jul 20 2016 20:55