therubyracer 0.9.10 → 0.10.0beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of therubyracer might be problematic. Click here for more details.

data/README.md CHANGED
@@ -48,7 +48,7 @@ embed a ruby object into your scope and access its properties/methods from javas
48
48
  lhs + rhs
49
49
  end
50
50
  end
51
-
51
+
52
52
  cxt['math'] = MyMath.new
53
53
  cxt.eval("math.plus(20,22)") #=> 42
54
54
 
@@ -59,7 +59,7 @@ make a ruby object *be* your global javascript scope.
59
59
  cxt.eval("plus(20,22)") #=> 42
60
60
  end
61
61
 
62
- you can do the same thing with Object#eval_js
62
+ you can do the same thing with Object#eval_js
63
63
 
64
64
  math.eval_js("plus(20,22)")
65
65
 
@@ -96,14 +96,14 @@ exposed by default. E.g.
96
96
  super
97
97
  end
98
98
  end
99
-
99
+
100
100
  class B < A
101
101
  def b
102
102
  "b"
103
103
  end
104
104
  end
105
-
106
-
105
+
106
+
107
107
  V8::Context.new do |cxt|
108
108
  cxt['a'] = A.new
109
109
  cxt['b'] = B.new
@@ -138,9 +138,6 @@ To use the ruby racer in rails, or any application using Bundler to manage gems,
138
138
  bundle install
139
139
  rake compile
140
140
 
141
- ## Sponsored by
142
- <a href="http://thefrontside.net">![The Frontside](http://github.com/cowboyd/therubyracer/raw/master/thefrontside.png)</a>
143
-
144
141
  ## LICENSE:
145
142
 
146
143
  (The MIT License)
@@ -18,8 +18,8 @@ $CPPFLAGS += " -Wall" unless $CPPFLAGS.split.include? "-Wall"
18
18
  $CPPFLAGS += " -g" unless $CPPFLAGS.split.include? "-g"
19
19
  $CPPFLAGS += " -rdynamic" unless $CPPFLAGS.split.include? "-rdynamic"
20
20
 
21
- $LDFLAGS.insert 0, "#{Libv8.library_path}/libv8.#{$LIBEXT} "
22
- $LIBS << ' -lpthread'
21
+ $DEFLIBPATH.unshift(Libv8.library_path)
22
+ $LIBS << ' -lv8 -lpthread'
23
23
 
24
24
  CONFIG['LDSHARED'] = '$(CXX) -shared' unless RUBY_PLATFORM =~ /darwin/
25
25
 
@@ -1,5 +1,4 @@
1
1
 
2
- #include <vector>
3
2
  #include "v8_function.h"
4
3
  #include "v8_object.h"
5
4
  #include "v8_handle.h"
@@ -22,11 +21,11 @@ namespace {
22
21
  Local<Object> thisObj = rr_rb2v8(recv)->ToObject();
23
22
  Handle<Array> args = rr_v8_handle<Array>(arguments);
24
23
  int argc = args->Length();
25
- std::vector< Handle<Value> > argv (argc);
24
+ Handle<Value> argv[argc];
26
25
  for (int i = 0; i < argc; i++) {
27
26
  argv[i] = args->Get(i);
28
27
  }
29
- return rr_v82rb(function->Call(thisObj, argc, &argv[0]));
28
+ return rr_v82rb(function->Call(thisObj, argc, argv));
30
29
  }
31
30
 
32
31
  VALUE NewInstance(VALUE self, VALUE arguments) {
@@ -34,11 +33,11 @@ namespace {
34
33
  Handle<Function> function = unwrap(self);
35
34
  Handle<Array> args = rr_v8_handle<Array>(arguments);
36
35
  int argc = args->Length();
37
- std::vector< Handle<Value> > argv (argc);
36
+ Handle<Value> argv[argc];
38
37
  for (int i = 0; i < argc; i++) {
39
38
  argv[i] = args->Get(i);
40
39
  }
41
- return rr_v82rb(function->NewInstance(argc, &argv[0]));
40
+ return rr_v82rb(function->NewInstance(argc, argv));
42
41
  }
43
42
  VALUE GetName(VALUE self) {
44
43
  HandleScope scope;
@@ -3,7 +3,7 @@ require 'ostruct'
3
3
 
4
4
  module V8
5
5
  module CLI
6
- def self.run(exename = 'v8', args = [])
6
+ def self.run(exename = 'v8', args = [])
7
7
  options = OpenStruct.new
8
8
  options.libs = []
9
9
  options.libdirs = []
@@ -30,12 +30,12 @@ module V8
30
30
  puts "V8 Version #{Libv8::V8_VERSION}"
31
31
  exit
32
32
  elsif options.selftest
33
- self.test
33
+ self.test
34
34
  end
35
35
  Context.new(:with => Shell.new) do |cxt|
36
36
  for libfile in options.libs do
37
37
  load(cxt,libfile)
38
- end
38
+ end
39
39
  if options.interactive
40
40
  repl(cxt, exename)
41
41
  elsif options.execute
@@ -60,36 +60,35 @@ module V8
60
60
  puts e
61
61
  end
62
62
  end
63
-
63
+
64
64
  def self.test
65
65
  begin
66
+ require 'rubygems'
66
67
  require 'rspec'
67
- specs = File.expand_path('../../../spec', __FILE__)
68
- $:.unshift specs
69
68
  ARGV.clear
70
- ARGV << specs
69
+ ARGV << File.dirname(__FILE__) + '/../../spec/'
71
70
  ::RSpec::Core::Runner.autorun
72
71
  exit(0)
73
72
  rescue LoadError => e
74
73
  puts "selftest requires rspec to be installed (gem install rspec)"
75
74
  exit(1)
76
75
  end
77
-
76
+
78
77
  end
79
78
 
80
79
  def self.repl(cxt, exename)
81
80
  require 'readline'
82
81
  puts "help() for help. quit() to quit."
83
82
  puts "The Ruby Racer #{V8::VERSION}"
84
- puts "Vroom Vroom!"
83
+ puts "Vroom Vroom!"
85
84
  trap("SIGINT") do
86
85
  puts "^C"
87
- end
86
+ end
88
87
  loop do
89
88
  line = Readline.readline("#{exename}> ", true)
90
89
  begin
91
90
  result = cxt.eval(line, '<shell>')
92
- puts(result) unless result.nil?
91
+ puts(result) unless result.nil?
93
92
  rescue V8::JSError => e
94
93
  puts e.message
95
94
  puts e.backtrace(:javascript)
@@ -97,9 +96,9 @@ module V8
97
96
  puts e
98
97
  puts e.backtrace.join("\n")
99
98
  end
100
- end
101
- end
102
-
99
+ end
100
+ end
101
+
103
102
  class Shell
104
103
  def to_s
105
104
  "[object Shell]"
@@ -112,18 +111,18 @@ module V8
112
111
  def exit(status = 0)
113
112
  Kernel.exit(status)
114
113
  end
115
-
114
+
116
115
  alias_method :quit, :exit
117
-
116
+
118
117
  def help(*args)
119
118
  <<-HELP
120
119
  print(msg)
121
- print msg to STDOUT
122
-
120
+ print msg to STDOUT
121
+
123
122
  exit(status = 0)
124
123
  exit the shell
125
124
  also: quit()
126
-
125
+
127
126
  evalrb(source)
128
127
  evaluate some ruby source
129
128
  HELP
@@ -2,11 +2,11 @@
2
2
  module V8
3
3
  class Portal
4
4
  class Caller
5
-
5
+
6
6
  def initialize(portal)
7
7
  @portal = portal
8
8
  end
9
-
9
+
10
10
  def raw
11
11
  yield
12
12
  rescue Exception => e
@@ -28,6 +28,7 @@ module V8
28
28
 
29
29
  def invoke(code, *args, &block)
30
30
  protect do
31
+ args = args.slice(0, code.arity) if code.arity >= 0
31
32
  code.call(*args, &block)
32
33
  end
33
34
  end
@@ -6,7 +6,11 @@ module V8
6
6
 
7
7
  def initialize(portal, code)
8
8
  @portal = portal
9
- @caller = code.respond_to?(:call) ? Call.new(portal) : BindAndCall.new(portal)
9
+ @caller = case code
10
+ when Method then BoundCall.new(portal)
11
+ when UnboundMethod then BindAndCall.new(portal)
12
+ else Call.new(portal)
13
+ end
10
14
  @code = code
11
15
  @template = V8::C::FunctionTemplate::New(@caller, @code)
12
16
  end
@@ -14,12 +18,23 @@ module V8
14
18
  def function
15
19
  @template.GetFunction()
16
20
  end
17
-
21
+
18
22
  class Call
19
23
  def initialize(portal)
20
24
  @portal = portal
21
25
  end
22
26
 
27
+ def call(arguments)
28
+ proc = arguments.Data()
29
+ rbargs = [@portal.rb(arguments.This())]
30
+ for i in 0..arguments.Length() - 1
31
+ rbargs << @portal.rb(arguments[i])
32
+ end
33
+ @portal.caller.invoke(proc, *rbargs)
34
+ end
35
+ end
36
+
37
+ class BoundCall < Call
23
38
  def call(arguments)
24
39
  proc = arguments.Data()
25
40
  rbargs = []
@@ -29,7 +44,7 @@ module V8
29
44
  @portal.caller.invoke(proc, *rbargs)
30
45
  end
31
46
  end
32
-
47
+
33
48
  class BindAndCall < Call
34
49
  def call(arguments)
35
50
  method = arguments.Data()
@@ -1,3 +1,3 @@
1
1
  module V8
2
- VERSION = "0.9.10"
2
+ VERSION = "0.10.0beta1"
3
3
  end
@@ -5,25 +5,25 @@ include V8
5
5
  describe C::Function do
6
6
  it "is callable" do
7
7
  Context.new do |cxt|
8
- f = cxt.eval('(function() {return "Hello World"})', '<eval>');
9
- f.call().should == "Hello World"
8
+ f = cxt.eval('(function() {return "Hello World"})', '<eval>');
9
+ f.call().should == "Hello World"
10
10
  end
11
11
  end
12
-
12
+
13
13
  it "receives proper argument length from ruby" do
14
14
  Context.new do |cxt|
15
15
  f = cxt.eval('(function() {return arguments.length})', 'eval')
16
16
  f.call(1, 2, 3).should == 3
17
17
  end
18
18
  end
19
-
19
+
20
20
  it "maps all arguments from ruby" do
21
21
  Context.new do |cxt|
22
22
  f = cxt.eval('(function(one, two, three) {return one + two + three})', 'eval')
23
23
  f.call(1,2,3).should == 6
24
24
  end
25
25
  end
26
-
26
+
27
27
  it "properly maps ruby objects back and forth from arguments to return value" do
28
28
  Context.new do |cxt|
29
29
  Object.new.tap do |this|
@@ -31,22 +31,22 @@ describe C::Function do
31
31
  f.methodcall(this).should be(this)
32
32
  end
33
33
  end
34
- end
35
-
34
+ end
35
+
36
36
  it "can be called outside of a context" do
37
37
  Context.new do |cxt|
38
38
  @f = cxt.eval('(function() {return "Call Me"})', 'eval')
39
39
  end
40
40
  @f.call().should == "Call Me"
41
41
  end
42
-
42
+
43
43
  it "is reflected properly" do
44
44
  Context.new do |cxt|
45
- cxt['say'] = lambda {|word, times| word * times}
45
+ cxt['say'] = lambda {|this, word, times| word * times}
46
46
  cxt.eval('say("Hello", 3)').should == "HelloHelloHello"
47
47
  end
48
48
  end
49
-
49
+
50
50
  it "has a name" do
51
51
  Context.new do |cxt|
52
52
  f = cxt.eval('(function hi() {return "Hello World"})', '<eval>')
@@ -36,7 +36,7 @@ describe "Ruby Javascript API" do
36
36
  it "can pass boolean values back to ruby" do
37
37
  @cxt.eval("true").should be(true)
38
38
  @cxt.eval("false").should be(false)
39
- end
39
+ end
40
40
 
41
41
  it "treats nil and the empty string as the same thing when it comes to eval" do
42
42
  @cxt.eval(nil).should == @cxt.eval('')
@@ -135,10 +135,17 @@ describe "Ruby Javascript API" do
135
135
  end
136
136
 
137
137
  it "can embed a closure into a context and call it" do
138
- @cxt["say"] = lambda {|word, times| word * times}
138
+ @cxt["say"] = lambda {|this, word, times| word * times}
139
139
  @cxt.eval("say('Hello',2)").should == "HelloHello"
140
140
  end
141
141
 
142
+ it "truncates the arguments passed in to match the arity of the function" do
143
+ @cxt['testing'] = lambda {|this|}
144
+ expect{@cxt.eval('testing(1,2,3)')}.should_not raise_error
145
+ @cxt['testing'] = lambda {}
146
+ expect{@cxt.eval('testing(1,2,3)')}.should_not raise_error
147
+ end
148
+
142
149
  it "recognizes the same closure embedded into the same context as the same function object" do
143
150
  @cxt['say'] = @cxt['declare'] = lambda {|word, times| word * times}
144
151
  @cxt.eval('say == declare').should be(true)
@@ -525,7 +532,7 @@ describe "Ruby Javascript API" do
525
532
  end
526
533
  end
527
534
  @cxt.eval("o.whiz('bang')").should == "whizbang!"
528
- end
535
+ end
529
536
 
530
537
  it "treats ruby methods that have an arity of 0 as javascript properties by default" do
531
538
  class_eval do
@@ -541,10 +548,10 @@ describe "Ruby Javascript API" do
541
548
  def dollars
542
549
  @dollars
543
550
  end
544
-
551
+
545
552
  def dollars=(amount)
546
553
  @dollars = amount
547
- end
554
+ end
548
555
  end
549
556
  evaljs('o.dollars = 50')
550
557
  @instance.dollars.should == 50
@@ -558,7 +565,7 @@ describe "Ruby Javascript API" do
558
565
  class_eval do
559
566
  def bar
560
567
  "baz"
561
- end
568
+ end
562
569
  end
563
570
  evaljs('o.bar = "bing"; o.bar').should == "baz"
564
571
  end
@@ -655,7 +662,7 @@ describe "Ruby Javascript API" do
655
662
  cxt.eval("plus(1,2)", "test").should == 3
656
663
  cxt.eval("minus(10, 20)", "test").should == -10
657
664
  cxt.eval("this").should be(scope)
658
- end
665
+ end
659
666
  end
660
667
 
661
668
  it "can directly embed ruby values into javascript" do
@@ -744,7 +751,7 @@ describe "Ruby Javascript API" do
744
751
  end
745
752
 
746
753
  def timesfive(rhs)
747
- @lhs * rhs
754
+ @lhs * rhs
748
755
  end
749
756
 
750
757
  new.eval_js("timesfive(6)").should == 30
@@ -761,7 +768,7 @@ describe "Ruby Javascript API" do
761
768
  # end
762
769
  # end
763
770
  # }.should raise_error(RunawayScriptError)
764
- # end
771
+ # end
765
772
  end
766
773
 
767
774
  describe "Loading javascript source into the interpreter" do
@@ -841,7 +848,7 @@ EOJS
841
848
  end
842
849
  h.should == {"foo" => 'bar', "bang" => 'baz', 5 => 'flip'}
843
850
  end
844
- end
851
+ end
845
852
  end
846
853
 
847
854
  describe "Exception Handling" do
@@ -859,8 +866,8 @@ EOJS
859
866
 
860
867
  it "translates ruby exceptions into javascript exceptions if they are thrown from code called it javascript" do
861
868
  Context.new do |cxt|
862
- cxt['rputs'] = lambda {|msg| rputs msg}
863
- cxt['boom'] = lambda do
869
+ cxt['rputs'] = lambda {|this, msg| rputs msg}
870
+ cxt['boom'] = lambda do |this|
864
871
  raise "BOOM!"
865
872
  end
866
873
  cxt.eval('var msg;try {boom()} catch (e) {msg = e.message};msg').should == 'BOOM!'
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.add_dependency "libv8", "~> 3.3.10"
25
25
 
26
- s.add_development_dependency "rake"
26
+ s.add_development_dependency "rake", "0.8.7"
27
27
  s.add_development_dependency "rspec", "~> 2.0"
28
28
  s.add_development_dependency "rake-compiler"
29
29
  end
metadata CHANGED
@@ -1,96 +1,73 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: therubyracer
3
- version: !ruby/object:Gem::Version
4
- hash: 47
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 9
9
- - 10
10
- version: 0.9.10
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.0beta1
5
+ prerelease: 6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Charles Lowell
14
9
  - Bill Robertson
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2012-02-17 00:00:00 -06:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
23
- requirement: &id001 !ruby/object:Gem::Requirement
13
+ date: 2011-10-06 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: libv8
17
+ requirement: &2151896520 !ruby/object:Gem::Requirement
24
18
  none: false
25
- requirements:
19
+ requirements:
26
20
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 31
29
- segments:
30
- - 3
31
- - 3
32
- - 10
21
+ - !ruby/object:Gem::Version
33
22
  version: 3.3.10
34
23
  type: :runtime
35
24
  prerelease: false
36
- name: libv8
37
- version_requirements: *id001
38
- - !ruby/object:Gem::Dependency
39
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *2151896520
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: &2151895720 !ruby/object:Gem::Requirement
40
29
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
30
+ requirements:
31
+ - - =
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.7
48
34
  type: :development
49
35
  prerelease: false
50
- name: rake
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *2151895720
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &2151894900 !ruby/object:Gem::Requirement
54
40
  none: false
55
- requirements:
41
+ requirements:
56
42
  - - ~>
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 2
61
- - 0
62
- version: "2.0"
43
+ - !ruby/object:Gem::Version
44
+ version: '2.0'
63
45
  type: :development
64
46
  prerelease: false
65
- name: rspec
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *2151894900
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake-compiler
50
+ requirement: &2151894100 !ruby/object:Gem::Requirement
69
51
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
77
56
  type: :development
78
57
  prerelease: false
79
- name: rake-compiler
80
- version_requirements: *id004
81
- description: Call javascript code and manipulate javascript objects from ruby. Call ruby code and manipulate ruby objects from javascript.
58
+ version_requirements: *2151894100
59
+ description: Call javascript code and manipulate javascript objects from ruby. Call
60
+ ruby code and manipulate ruby objects from javascript.
82
61
  email: cowboyd@thefrontside.net
83
- executables:
62
+ executables:
84
63
  - therubyracer
85
- extensions:
64
+ extensions:
86
65
  - ext/v8/extconf.rb
87
66
  extra_rdoc_files: []
88
-
89
- files:
67
+ files:
90
68
  - .gitignore
91
69
  - .gitmodules
92
70
  - .rspec
93
- - .travis.yml
94
71
  - .yardopts
95
72
  - Changelog.md
96
73
  - Gemfile
@@ -175,46 +152,37 @@ files:
175
152
  - specmem/spec_helper.rb
176
153
  - specthread/spec_helper.rb
177
154
  - specthread/threading_spec.rb
178
- - thefrontside.png
179
155
  - therubyracer.gemspec
180
156
  - spec/redjs/.gitignore
181
157
  - spec/redjs/README.txt
182
158
  - spec/redjs/jsapi_spec.rb
183
159
  - spec/redjs/loadme.js
184
- has_rdoc: true
185
160
  homepage: http://github.com/cowboyd/therubyracer
186
161
  licenses: []
187
-
188
162
  post_install_message:
189
163
  rdoc_options: []
190
-
191
- require_paths:
164
+ require_paths:
192
165
  - lib
193
166
  - ext
194
- required_ruby_version: !ruby/object:Gem::Requirement
167
+ required_ruby_version: !ruby/object:Gem::Requirement
195
168
  none: false
196
- requirements:
197
- - - ">="
198
- - !ruby/object:Gem::Version
199
- hash: 3
200
- segments:
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ segments:
201
174
  - 0
202
- version: "0"
203
- required_rubygems_version: !ruby/object:Gem::Requirement
175
+ hash: -1706553205254102038
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
204
177
  none: false
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- hash: 3
209
- segments:
210
- - 0
211
- version: "0"
178
+ requirements:
179
+ - - ! '>'
180
+ - !ruby/object:Gem::Version
181
+ version: 1.3.1
212
182
  requirements: []
213
-
214
183
  rubyforge_project: therubyracer
215
- rubygems_version: 1.3.7
184
+ rubygems_version: 1.8.10
216
185
  signing_key:
217
186
  specification_version: 3
218
187
  summary: Embed the V8 Javascript interpreter into Ruby
219
188
  test_files: []
220
-
@@ -1,9 +0,0 @@
1
- rvm:
2
- - 1.9.2
3
- - 1.9.3
4
- - 1.8.7
5
- notifications:
6
- recipients:
7
- - cowboyd@thefrontside.net
8
- script: bundle exec rake compile spec
9
- before_install: git submodule update --init
Binary file