therubyracer 0.8.0 → 0.8.1.pre1

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/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ .bundle
2
+ Gemfile.lock
3
+ v8.bundle
4
+ v8.so
5
+ *.o
6
+ *.gem
7
+ *.log
8
+ *~
9
+ docs/cpp/html/*
10
+
11
+ ext/v8/upstream/build
12
+
13
+ pkg/
14
+ tmp/
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "spec/redjs"]
2
+ path = spec/redjs
3
+ url = git://github.com/cowboyd/redjs.git
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Changelog.md ADDED
@@ -0,0 +1,165 @@
1
+ # Changelog
2
+
3
+ ## EDGE
4
+
5
+ * decruft all the crap that had accumulated in the gem
6
+ * Javascript Objects are now always mapped to the same V8::Object when read from the context
7
+
8
+ ## 0.8.0 - 2010/12/02
9
+
10
+ * every V8 Context gets its own unique access strategy
11
+ * ruby methods and procs embedded in javascript always return the same function per context.
12
+ * ruby classes and subclasses are now all connected via the javascript prototype chain
13
+ * better error reporting on syntax errors
14
+ * upgrade to rspec 2
15
+ * several bug fixes and stability fixes
16
+
17
+ ## 0.7.5 - 1010/08/03
18
+
19
+ * upgrade to V8 2.3.3
20
+ * property interceptors from ruby via [] and []=
21
+ * indexed property access via [] and []=
22
+ * property
23
+ * several bugfixes
24
+ * stability: eliminate many segfaults
25
+ * don't enumerate property setters such as foo= from javascript
26
+
27
+ ## 0.7.4 - 2010/06/15
28
+
29
+ * bug fix for rvm ruby installs incorrectly detected as 32bit
30
+
31
+ ## 0.7.3 - 2010/06/15
32
+
33
+ * don't catch SystemExit and NoMemoryError
34
+ * fix bug bundling gem
35
+
36
+ ## 0.7.2 - 2010/06/14
37
+
38
+ * embed ruby classes as constructors
39
+ * support for rubinius
40
+ * uniform backtrace() function on JSError mixes the ruby
41
+ * String::NewSymbol() is now scriptable
42
+ * InstanceTemplate(), PrototypeTemplate(), Inherit() methods on v8::FunctionTemplate now scriptable.
43
+ * reuse the standard ruby object access template
44
+ * fix a bunch of compile warnings
45
+ * Store any ruby object in V8 with V8::C::External
46
+
47
+ ## 0.7.1 - 2010/06/03
48
+
49
+ * Function#call() now uses the global scope for 'this' by default
50
+ * Function#methodcall() added to allow passing in 'this' object
51
+ * Function#new() method to invoke javascript constructor from ruby
52
+ * access javascript properties and call javascript methods from ruby
53
+ * bundled Jasmine DOM-Less browser testing framework.
54
+
55
+ * added Object::GetHiddenValue() to v8 metal
56
+ * added Handle::IsEmpty() to v8 metal
57
+ * fixed bug where iterating over arrays sometimes failed
58
+ * numerous bug /segfault fixes.
59
+
60
+ ## 0.7.0 - 2010/05/31
61
+
62
+ * upgraded to V8 2.1.10
63
+ * added low level scripting interface for V8 objects
64
+ * ruby object property/method access is now implemented in ruby
65
+ * auto-convert javascript arrays to rb arrays and vice-versa
66
+ * auto-convert ruby hashes into javascript objects
67
+ * auto-convert javascript Date into ruby Time object and vice versa.
68
+ * better exception handling when passing through multiple language boundaries
69
+ * objects maintain referential integrity when passing objects from ruby to javascript and vice-versa
70
+ * added debug compile option for getting C/C++ backtraces whenever segfaults occur.
71
+ * official support for REE 1.8.7
72
+ * fixed numerous segfaults
73
+ * implemented V8::Value#to_s
74
+ * the global scope is available to every V8::Context as the 'scope' attribute
75
+ * properly convert ruby boolean values into V8 booleans.
76
+
77
+ ## 0.6.3 - 2010/05/07
78
+
79
+ * FIX: linkage error on OSX /usr/bin/ruby
80
+
81
+ ## 0.6.2 - 2010/05/06
82
+
83
+ * FIX: linkage error on OSX 10.5
84
+
85
+ ## 0.6.1 - 2010/05/03
86
+
87
+ * call JavaScript functions from Ruby
88
+
89
+ ## 0.6.0 - 2010/03/31
90
+
91
+ * ruby 1.9 compatible
92
+ * full featured command line bin/v8 and bin/therubyracer
93
+ * self validating install (v8 --selftest)
94
+ * Only dependency to build gem from source is rubygems.
95
+
96
+ ## 0.5.5 - 2010/03/15
97
+
98
+ * fix string encoding issue that was breaking RHEL 5.x
99
+ * fix pthread linking issue on RHEL 5.2
100
+
101
+ ## 0.5.4 - 2010/03/09
102
+
103
+ * add ext directory to gem require paths which was causing problems for non-binary gems
104
+
105
+ ## 0.5.3 - 2010/03/01
106
+
107
+ * added full back trace to javascript code
108
+
109
+ ## 0.5.2 - 2010/02/26
110
+
111
+ * added javascript shell (bin/therubyracer)
112
+ * added to_s method for embedded ruby objects
113
+ * added line number and file name to error message.
114
+
115
+ ## 0.5.1 - 2010/02/17
116
+
117
+ * fix bug in 1.8.6 by creating Object#tap if it does not exist
118
+
119
+ ## 0.5.0 - 2010/02/17
120
+
121
+ * support for Linux 64 bit
122
+
123
+ ## 0.4.9 - 2010/02/16
124
+
125
+ * support for Linux 32 bit
126
+
127
+ ## 0.4.8 - 2010/02/08
128
+
129
+ * expose line number and source name on JavascriptErrors.
130
+
131
+ ## 0.4.5 - 2010/01/18
132
+
133
+ * case munging so that ruby methods(perl_case) are accessed through javascript in camelCase.
134
+ * access 0-arity ruby methods as javascript properties
135
+ * invoke ruby setters from javascript as properties
136
+ * contexts detect whether they are open or not and open when needed
137
+
138
+ ## 0.4.4 - 2010/01/14
139
+
140
+ * Ruby objects embedded into javascript are passed back to ruby as themselves and not a wrapped V8 object wrapping a ruby object.
141
+ * Use any ruby object as the scope of eval().
142
+ * quick and dirty V8.eval() method added
143
+ * native objects have a reference to the context that created them.
144
+ * context now has equality check.
145
+ * expose InContext() and GetCurrent() methods.
146
+ * fix a couple of segmentation faults
147
+
148
+ ## 0.4.3 - 2010/10/11
149
+
150
+ * access properties on Ruby objects with their camel case equivalents
151
+ * reflect JavaScript objects into Ruby and access their properties
152
+ * load JavaScript source from an IO object or by filename
153
+
154
+ ## 0.4.2 - 2010/10/10
155
+
156
+ * embed Ruby Objects into Javascript and call their methods
157
+
158
+ ## 0.4.1 - 2010/01/09
159
+
160
+ * embed bare Proc and Method objects into JavaScript and call them
161
+ * catch JavaScript exceptions from Ruby
162
+
163
+ ## 0.4.0 - 2009/12/21
164
+
165
+ * evaluate JavaScript code from inside Ruby.
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ source :rubygems;gemspec
data/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # therubyracer
2
+
3
+ * http://github.com/cowboyd/therubyracer
4
+ * http://groups.google.com/group/therubyracer
5
+ * irc://irc.freenode.net/therubyracer
6
+
7
+ ## DESCRIPTION:
8
+
9
+ Embed the V8 Javascript interpreter into Ruby.
10
+
11
+
12
+ ## FEATURES/PROBLEMS:
13
+
14
+ * Evaluate Javascript from with in Ruby
15
+ * Embed your Ruby objects into the Javascript world
16
+ * Manipulate JavaScript objects and call JavaScript functions from Ruby
17
+ * API compatible with the The Ruby Rhino (for JRuby: http://github.com/cowboyd/therubyrhino)
18
+
19
+ ## SYNOPSIS:
20
+
21
+ gem install therubyracer (stable)
22
+ gem install therubyracer --pre (bleeding edge)
23
+
24
+ then in your ruby code
25
+
26
+ require 'v8'
27
+
28
+ evaluate some simple javascript
29
+
30
+ cxt = V8::Context.new
31
+ cxt.eval('7 * 6') #=> 42
32
+
33
+ embed values into the scope of your context
34
+
35
+ cxt['foo'] = "bar"
36
+ cxt.eval('foo') # => "bar"
37
+
38
+ embed ruby code into your scope and call it from javascript
39
+
40
+ cxt["say"] = lambda {|word, times| word * times}
41
+ cxt.eval("say('Hello', 3)") #=> HelloHelloHello
42
+
43
+ embed a ruby object into your scope and access its properties/methods from javascript
44
+
45
+ class MyMath
46
+ def plus(lhs, rhs)
47
+ lhs + rhs
48
+ end
49
+ end
50
+
51
+ cxt['math'] = MyMath.new
52
+ cxt.eval("math.plus(20,22)") #=> 42
53
+
54
+ make a ruby object *be* your global javascript scope.
55
+
56
+ math = MyMath.new
57
+ V8::Context.new(:with => math) do |cxt|
58
+ cxt.eval("plus(20,22)") #=> 42
59
+ end
60
+
61
+ you can do the same thing with Object#eval_js
62
+
63
+ math.eval_js("plus(20,22)")
64
+
65
+ ## Different ways of loading javascript source
66
+
67
+ In addition to just evaluating strings, you can also use streams such as files.
68
+
69
+ evaluate bytes read from any File/IO object:
70
+
71
+ File.open("mysource.js") do |file|
72
+ cxt.eval(file, "mysource.js")
73
+ end
74
+
75
+ or load it by filename
76
+
77
+ cxt.load("mysource.js")
78
+
79
+
80
+ ## Safe by default, dangerous by demand
81
+
82
+ The Ruby Racer is designed to let you evaluate javascript as safely as possible unless you tell it to do something more
83
+ dangerous. The default context is a hermetically sealed javascript environment with only the standard javascript objects
84
+ and functions. Nothing from the ruby world is accessible at all.
85
+
86
+ For ruby objects that you explicitly embed into javascript, by default only the _public_ methods _below_ `Object` are
87
+ exposed by default. E.g.
88
+
89
+ class A
90
+ def a
91
+ "a"
92
+ end
93
+
94
+ def to_s
95
+ super
96
+ end
97
+ end
98
+
99
+ class B < A
100
+ def b
101
+ "b"
102
+ end
103
+ end
104
+
105
+
106
+ V8::Context.new do |cxt|
107
+ cxt['a'] = A.new
108
+ cxt['b'] = B.new
109
+ cxt.eval("a.a") # => 'a'
110
+ cxt.eval("b.b") # => 'b'
111
+ cxt.eval("b.a") # => 'a'
112
+ cxt.eval("b.to_s") # => #<B:0x101776be8> (because A explicitly defined it)
113
+ cxt.eval("b.object_id") #=> undefined, object_id is on Object
114
+ end
115
+
116
+ If needed, you can override the [Ruby Access](https://github.com/cowboyd/therubyracer/blob/master/lib/v8/access.rb)
117
+ to allow whatever behavior you'd like
118
+
119
+ ## REQUIREMENTS:
120
+
121
+ * python >= 2.5 (required to compile v8)
122
+ * C++ compiler
123
+
124
+
125
+ ## DEVELOP
126
+ * git clone git://github.com/cowboyd/therubyracer.git
127
+ * cd therubyracer
128
+ * git submodule update --init
129
+ * rake compile
130
+
131
+ ## LICENSE:
132
+
133
+ (The MIT License)
134
+
135
+ Copyright (c) 2009,2010,2011 Charles Lowell
136
+
137
+ Permission is hereby granted, free of charge, to any person obtaining
138
+ a copy of this software and associated documentation files (the
139
+ 'Software'), to deal in the Software without restriction, including
140
+ without limitation the rights to use, copy, modify, merge, publish,
141
+ distribute, sublicense, and/or sell copies of the Software, and to
142
+ permit persons to whom the Software is furnished to do so, subject to
143
+ the following conditions:
144
+
145
+ The above copyright notice and this permission notice shall be
146
+ included in all copies or substantial portions of the Software.
147
+
148
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
149
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
150
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
151
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
152
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
153
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
154
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,42 +1,14 @@
1
- require 'rubygems'
2
-
3
- UPSTREAM = "ext/v8/upstream"
4
-
5
- manifest = Rake::FileList.new("**/*")
6
- manifest.exclude "lib/v8/*.bundle", "lib/v8/*.so", "ext/**/test/*", "ext/**/test/*", "ext/**/samples/*", "ext/**/benchmarks/*", "#{UPSTREAM}/build", "tmp", "tmp/**/*", "**/*.gem"
7
- Gem::Specification.new do |gemspec|
8
- $gemspec = gemspec
9
- gemspec.name = gemspec.rubyforge_project = "therubyracer"
10
- gemspec.version = "0.8.0"
11
- gemspec.summary = "Embed the V8 Javascript interpreter into Ruby"
12
- gemspec.description = "Call javascript code and manipulate javascript objects from ruby. Call ruby code and manipulate ruby objects from javascript."
13
- gemspec.email = "cowboyd@thefrontside.net"
14
- gemspec.homepage = "http://github.com/cowboyd/therubyracer"
15
- gemspec.authors = ["Charles Lowell", "Bill Robertson"]
16
- gemspec.extra_rdoc_files = ["README.rdoc"]
17
- gemspec.executables = ["therubyracer", "v8"]
18
- gemspec.extensions = ["ext/v8/extconf.rb"]
19
- gemspec.require_paths = ["lib", "ext", "contrib"]
20
- gemspec.files = manifest.to_a
21
- end
1
+ require 'bundler'
2
+ require 'bundler/setup'
3
+ require "rake/extensiontask"
4
+ require "rspec/core/rake_task"
5
+ Bundler::GemHelper.install_tasks
22
6
 
23
7
  task :default => :spec
24
8
 
25
- desc "Build gem"
26
- task :gem => :gemspec do
27
- Gem::Builder.new($gemspec).build
28
- end
29
-
30
- desc "build the gemspec"
31
- task :gemspec => :clean do
32
- File.open("#{$gemspec.name}.gemspec", "w") do |f|
33
- f.write($gemspec.to_ruby)
34
- end
35
- end
36
-
37
9
  desc "remove all generated artifacts except built v8 objects"
38
10
  task :clean do
39
- sh "rm -rf *.gem"
11
+ sh "rm -rf pkg"
40
12
  sh "rm -rf ext/v8/Makefile"
41
13
  sh "rm -rf ext/v8/*.bundle ext/v8/*.so"
42
14
  sh "rm -rf lib/v8/*.bundle lib/v8/*.so"
@@ -44,16 +16,19 @@ end
44
16
 
45
17
  desc "remove all built v8 objects"
46
18
  task "v8:clean" => "clean" do
47
- sh "cd #{UPSTREAM} && make clean"
19
+ sh "cd ext/v8/upstream && make clean"
48
20
  end
49
21
 
50
22
  desc "build v8 with debugging symbols (much slower)"
51
23
  task "v8:debug" do
52
- sh "cd #{UPSTREAM} && make debug"
24
+ sh "cd ext/v8/upstream && make debug"
53
25
  end
54
26
 
55
- for file in Dir['tasks/*.rake']
56
- load file
27
+ Rake::ExtensionTask.new("v8", eval(File.read("therubyracer.gemspec"))) do |ext|
28
+ ext.lib_dir = "lib/v8"
29
+ ext.source_pattern = "*.{cpp,h}"
57
30
  end
58
31
 
32
+ RSpec::Core::RakeTask.new(:spec)
33
+
59
34
 
@@ -0,0 +1,26 @@
1
+ *.a
2
+ *.exe
3
+ *.lib
4
+ *.log
5
+ *.map
6
+ *.mk
7
+ *.ncb
8
+ *.pyc
9
+ *.scons*
10
+ *.suo
11
+ *.user
12
+ *.xcodeproj
13
+ *.idb
14
+ *.pdb
15
+ #*#
16
+ *~
17
+ .cpplint-cache
18
+ d8
19
+ d8_g
20
+ shell
21
+ shell_g
22
+ /obj/
23
+ /tools/visual_studio/Debug
24
+ /tools/visual_studio/Release
25
+ /xcodebuild/
26
+ TAGS
data/lib/v8/context.rb CHANGED
@@ -8,8 +8,9 @@ module V8
8
8
  @to = Portal.new(self, @access)
9
9
  @native = opts[:with] ? C::Context::New(@to.rubytemplate) : C::Context::New()
10
10
  @native.enter do
11
- @scope = @to.rb(@native.Global())
12
- @native.Global().SetHiddenValue(C::String::New("TheRubyRacer::RubyObject"), C::External::New(opts[:with])) if opts[:with]
11
+ @global = @native.Global()
12
+ @scope = @to.rb(@global)
13
+ @global.SetHiddenValue(C::String::New("TheRubyRacer::RubyObject"), C::External::New(opts[:with])) if opts[:with]
13
14
  end
14
15
  yield(self) if block_given?
15
16
  end
data/lib/v8/error.rb CHANGED
@@ -107,9 +107,9 @@ module V8
107
107
  #in the TryCatch. Is there a better way to detect a syntax error
108
108
  def syntax_error?(try)
109
109
  ex = try.Exception()
110
- if ex && ex.kind_of?(V8::C::Object)
111
- type = ex.Get("constructor")
112
- type && type.kind_of?(V8::C::Function) && type.GetName().AsciiValue == "SyntaxError"
110
+ if ex && ex.kind_of?(V8::Object)
111
+ type = ex["constructor"]
112
+ type && type.kind_of?(V8::Function) && type.name == "SyntaxError"
113
113
  else
114
114
  false
115
115
  end
data/lib/v8/portal.rb CHANGED
@@ -186,7 +186,9 @@ module V8
186
186
  if external && !external.IsEmpty()
187
187
  external.Value()
188
188
  else
189
- yield.new(value, self)
189
+ yield.new(value, self).tap do |object|
190
+ value.SetHiddenValue(C::String::NewSymbol("TheRubyRacer::RubyObject"), C::External::New(object))
191
+ end
190
192
  end
191
193
  end
192
194
 
data/lib/v8/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module V8
2
+ VERSION = "0.8.1.pre1"
3
+ end
data/lib/v8.rb CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module V8
5
- VERSION = '0.8.0'
5
+ require 'v8/version'
6
6
  require 'v8/v8' #native glue
7
7
  require 'v8/portal'
8
8
  require 'v8/portal/functions'
@@ -84,6 +84,13 @@ describe "Ruby Javascript API" do
84
84
  end
85
85
  end
86
86
 
87
+ it "always returns the same ruby object for a single javascript object" do
88
+ obj = @cxt.eval('obj = {}')
89
+ obj.should be @cxt['obj']
90
+ @cxt.eval('obj').should be @cxt['obj']
91
+ @cxt['obj'].should be @cxt['obj']
92
+ end
93
+
87
94
  it "converts arrays to javascript" do
88
95
  @cxt['a'] = [1,2,4]
89
96
  @cxt.eval('var sum = 0;for (var i = 0; i < a.length; i++) {sum += a[i]}; sum').should == 7
@@ -230,7 +237,7 @@ describe "Ruby Javascript API" do
230
237
 
231
238
  it "reports ruby methods that do not exist as undefined" do
232
239
  Context.new(:with => Object.new) do |cxt|
233
- cxt.eval('this.foobar').should be_nil
240
+ cxt.eval('this.foobar').should be_nil
234
241
  end
235
242
  end
236
243