Last active
November 6, 2015 04:02
-
-
Save rogsmith/5f723ffd99e70f9c63df to your computer and use it in GitHub Desktop.
therubyracer + commonsjsrb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context = V8::Context.new timeout: timeout | |
js = CommonJS::Environment.new(context, path: "#{Rails.root}/lib/javascripts") | |
context["_"] = js.require('underscore.js') | |
context['data'] = "[1,2,3,4]" | |
source = "(function(){return _.map(JSON.parse(data), function(num){ return num * 5 });});" | |
res = context.eval(source) | |
# res is a #<V8::Function:0x007feaf195a720 | |
# if I then try | |
res.call() | |
#it gives me a #<V8::Array:0x007feaf1689f50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment