Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you create an environment? #16

Open
ghost opened this issue Nov 8, 2014 · 5 comments
Open

How do you create an environment? #16

ghost opened this issue Nov 8, 2014 · 5 comments

Comments

@ghost
Copy link

ghost commented Nov 8, 2014

The README says

env = CommonJS::Environment.new(:path => '/path/to/lib/dir')

But it doesn't explain what the path to lib directory is supposed to be a path to? What library? I've tried using the current directory but get an error.

1.9.3-p484 :024 >   env = CommonJS::Environment.new(:path => './')
TypeError: can't convert nil into String
    from /Users/mgwelch/.rvm/gems/ruby-1.9.3-p484/gems/commonjs-0.2.7/lib/commonjs/environment.rb:9:in `initialize'
    from /Users/mgwelch/.rvm/gems/ruby-1.9.3-p484/gems/commonjs-0.2.7/lib/commonjs/environment.rb:9:in `Pathname'
    from /Users/mgwelch/.rvm/gems/ruby-1.9.3-p484/gems/commonjs-0.2.7/lib/commonjs/environment.rb:9:in `block in initialize'
    from /Users/mgwelch/.rvm/gems/ruby-1.9.3-p484/gems/commonjs-0.2.7/lib/commonjs/environment.rb:9:in `map'
    from /Users/mgwelch/.rvm/gems/ruby-1.9.3-p484/gems/commonjs-0.2.7/lib/commonjs/environment.rb:9:in `initialize'
    from (irb):24:in `new'
    from (irb):24
    from /Users/mgwelch/.rvm/rubies/ruby-1.9.3-p484/bin/irb:12:in `<main>'
@RKushnir
Copy link

The readme is wrong.
The constructor actually takes 2 arguments - runtime and options(which are empty hash by default, but default doesn't work), see

def initialize(runtime, options = {})

@MhdSyrwan
Copy link

You can find an example of a successful environment object creation here
https://github.com/cowboyd/commonjs.rb/blob/master/spec/spec_helper.rb

Example:

js = CommonJS::Environment.new(V8::Context.new, path: './node_modules')

@rogsmith
Copy link

rogsmith commented Nov 6, 2015

Any ideas on how I can eval() js code now if I am using commonjs and therubyracer?

@bbozo
Copy link

bbozo commented Dec 15, 2015

What rogsmith said :)

@orta
Copy link

orta commented Aug 12, 2016

Looking at the source - this will just add them as modules into the existing runtime, you would re-use the V8::Context.new to eval things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants