therubyracer-st 0.11.0beta5-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/.gitignore +23 -0
  2. data/.travis.yml +10 -0
  3. data/Changelog.md +242 -0
  4. data/Gemfile +15 -0
  5. data/README.md +185 -0
  6. data/Rakefile +58 -0
  7. data/benchmarks.rb +217 -0
  8. data/ext/v8/accessor.cc +181 -0
  9. data/ext/v8/array.cc +26 -0
  10. data/ext/v8/backref.cc +54 -0
  11. data/ext/v8/build.rb +53 -0
  12. data/ext/v8/constants.cc +34 -0
  13. data/ext/v8/constraints.cc +52 -0
  14. data/ext/v8/context.cc +130 -0
  15. data/ext/v8/date.cc +18 -0
  16. data/ext/v8/exception.cc +38 -0
  17. data/ext/v8/extconf.rb +23 -0
  18. data/ext/v8/external.cc +43 -0
  19. data/ext/v8/function.cc +58 -0
  20. data/ext/v8/gc.cc +43 -0
  21. data/ext/v8/handles.cc +34 -0
  22. data/ext/v8/heap.cc +31 -0
  23. data/ext/v8/init.cc +39 -0
  24. data/ext/v8/invocation.cc +86 -0
  25. data/ext/v8/locker.cc +77 -0
  26. data/ext/v8/message.cc +51 -0
  27. data/ext/v8/object.cc +334 -0
  28. data/ext/v8/primitive.cc +8 -0
  29. data/ext/v8/rr.cc +83 -0
  30. data/ext/v8/rr.h +883 -0
  31. data/ext/v8/script.cc +80 -0
  32. data/ext/v8/signature.cc +18 -0
  33. data/ext/v8/stack.cc +75 -0
  34. data/ext/v8/string.cc +47 -0
  35. data/ext/v8/template.cc +175 -0
  36. data/ext/v8/trycatch.cc +86 -0
  37. data/ext/v8/v8.cc +87 -0
  38. data/ext/v8/value.cc +239 -0
  39. data/lib/v8.rb +36 -0
  40. data/lib/v8/access.rb +5 -0
  41. data/lib/v8/access/indices.rb +40 -0
  42. data/lib/v8/access/invocation.rb +47 -0
  43. data/lib/v8/access/names.rb +65 -0
  44. data/lib/v8/array.rb +26 -0
  45. data/lib/v8/context.rb +243 -0
  46. data/lib/v8/conversion.rb +35 -0
  47. data/lib/v8/conversion/array.rb +11 -0
  48. data/lib/v8/conversion/class.rb +120 -0
  49. data/lib/v8/conversion/code.rb +38 -0
  50. data/lib/v8/conversion/fundamental.rb +11 -0
  51. data/lib/v8/conversion/hash.rb +11 -0
  52. data/lib/v8/conversion/indentity.rb +31 -0
  53. data/lib/v8/conversion/method.rb +26 -0
  54. data/lib/v8/conversion/object.rb +28 -0
  55. data/lib/v8/conversion/primitive.rb +7 -0
  56. data/lib/v8/conversion/proc.rb +5 -0
  57. data/lib/v8/conversion/reference.rb +16 -0
  58. data/lib/v8/conversion/string.rb +12 -0
  59. data/lib/v8/conversion/symbol.rb +7 -0
  60. data/lib/v8/conversion/time.rb +13 -0
  61. data/lib/v8/error.rb +25 -0
  62. data/lib/v8/error/protect.rb +20 -0
  63. data/lib/v8/error/try.rb +15 -0
  64. data/lib/v8/function.rb +28 -0
  65. data/lib/v8/helper.rb +30 -0
  66. data/lib/v8/object.rb +79 -0
  67. data/lib/v8/util/weakcell.rb +29 -0
  68. data/lib/v8/version.rb +3 -0
  69. data/spec/c/array_spec.rb +17 -0
  70. data/spec/c/constants_spec.rb +20 -0
  71. data/spec/c/exception_spec.rb +26 -0
  72. data/spec/c/external_spec.rb +9 -0
  73. data/spec/c/function_spec.rb +46 -0
  74. data/spec/c/handles_spec.rb +35 -0
  75. data/spec/c/locker_spec.rb +38 -0
  76. data/spec/c/object_spec.rb +46 -0
  77. data/spec/c/script_spec.rb +28 -0
  78. data/spec/c/string_spec.rb +16 -0
  79. data/spec/c/template_spec.rb +30 -0
  80. data/spec/c/trycatch_spec.rb +51 -0
  81. data/spec/mem/blunt_spec.rb +42 -0
  82. data/spec/redjs_spec.rb +10 -0
  83. data/spec/spec_helper.rb +45 -0
  84. data/spec/threading_spec.rb +52 -0
  85. data/spec/v8/context_spec.rb +19 -0
  86. data/spec/v8/conversion_spec.rb +9 -0
  87. data/spec/v8/error_spec.rb +21 -0
  88. data/spec/v8/function_spec.rb +9 -0
  89. data/spec/v8/object_spec.rb +15 -0
  90. data/thefrontside.png +0 -0
  91. data/therubyracer.gemspec +20 -0
  92. data/vendor/v8.dll +0 -0
  93. metadata +161 -0
@@ -0,0 +1,3 @@
1
+ module V8
2
+ VERSION = "0.11.0beta5"
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe V8::C::Array do
4
+ it "can store and retrieve a value" do
5
+ o = V8::C::Object::New()
6
+ a = V8::C::Array::New()
7
+ a.Length().should eql 0
8
+ a.Set(0, o)
9
+ a.Length().should eql 1
10
+ a.Get(0).Equals(o).should be_true
11
+ end
12
+
13
+ it "can be initialized with a length" do
14
+ a = V8::C::Array::New(5)
15
+ a.Length().should eql 5
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe V8::C do
4
+ it "has constant methods for Undefined, Null, True and False" do
5
+ [:Undefined, :Null, :True, :False].each do |name|
6
+ constant = V8::C.send(name)
7
+ constant.should_not be_nil
8
+ V8::C.send(name).should be constant
9
+ end
10
+ end
11
+
12
+ it "has a value for the Empty handle" do
13
+ V8::C::Value::Empty.should_not be_nil
14
+ V8::C::Value::Empty.should be V8::C::Value::Empty
15
+ end
16
+
17
+ it "can access the V8 version" do
18
+ V8::C::V8::GetVersion().should match /^3\.11/
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe V8::C::Exception do
4
+ it "can be thrown from Ruby" do
5
+ t = V8::C::FunctionTemplate::New(method(:explode))
6
+ @cxt.Global().Set("explode", t.GetFunction())
7
+ script = V8::C::Script::New(<<-JS, '<eval>')
8
+ (function() {
9
+ try {
10
+ explode()
11
+ } catch (e) {
12
+ return e.message
13
+ }
14
+ })()
15
+ JS
16
+ result = script.Run()
17
+ result.should_not be_nil
18
+ result.should be_kind_of(V8::C::String)
19
+ result.Utf8Value().should eql 'did not pay syntax'
20
+ end
21
+
22
+ def explode(arguments)
23
+ error = V8::C::Exception::SyntaxError('did not pay syntax')
24
+ V8::C::ThrowException(error)
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe V8::C::External do
4
+ it "can store and retrieve a value" do
5
+ o = Object.new
6
+ external = V8::C::External::New(o)
7
+ external.Value().should be(o)
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe V8::C::Function do
4
+ it "can be called" do
5
+ fn = run '(function() {return "foo"})'
6
+ fn.Call(@cxt.Global(), []).Utf8Value().should eql "foo"
7
+ end
8
+
9
+ it "can be called with arguments and context" do
10
+ fn = run '(function(one, two, three) {this.one = one; this.two = two; this.three = three})'
11
+ one = V8::C::Object::New()
12
+ two = V8::C::Object::New()
13
+ fn.Call(@cxt.Global(), [one, two, 3])
14
+ @cxt.Global().Get("one").should eql one
15
+ @cxt.Global().Get("two").should eql two
16
+ @cxt.Global().Get("three").should eql 3
17
+ end
18
+
19
+ it "can be called as a constructor" do
20
+ fn = run '(function() {this.foo = "foo"})'
21
+ fn.NewInstance().Get(V8::C::String::New('foo')).Utf8Value().should eql "foo"
22
+ end
23
+
24
+ it "can be called as a constructor with arguments" do
25
+ fn = run '(function(foo) {this.foo = foo})'
26
+ object = fn.NewInstance([V8::C::String::New("bar")])
27
+ object.Get(V8::C::String::New('foo')).Utf8Value().should eql "bar"
28
+ end
29
+
30
+ it "doesn't kill the world if invoking it throws a javascript exception" do
31
+ V8::C::TryCatch() do
32
+ fn = run '(function() { throw new Error("boom!")})'
33
+ fn.Call(@cxt.Global(), [])
34
+ fn.NewInstance([])
35
+ end
36
+ end
37
+
38
+
39
+ def run(source)
40
+ source = V8::C::String::New(source.to_s)
41
+ filename = V8::C::String::New("<eval>")
42
+ script = V8::C::Script::New(source, filename)
43
+ result = script.Run()
44
+ result.kind_of?(V8::C::String) ? result.Utf8Value() : result
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe "setting up handles scopes" do
4
+ include ExplicitScoper
5
+
6
+ before do
7
+ def self.instance_eval(*args, &block)
8
+ V8::C::Locker() do
9
+ cxt = V8::C::Context::New()
10
+ begin
11
+ cxt.Enter()
12
+ super(*args, &block)
13
+ ensure
14
+ cxt.Exit()
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ it "can allocate handle scopes" do
21
+ V8::C::HandleScope() do
22
+ V8::C::Object::New()
23
+ end.class.should eql V8::C::Object
24
+ end
25
+
26
+ it "isn't the end of the world if a ruby exception is raised inside a HandleScope" do
27
+ begin
28
+ V8::C::HandleScope() do
29
+ raise "boom!"
30
+ end
31
+ rescue StandardError => e
32
+ e.message.should eql "boom!"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe V8::C::Locker do
4
+ include ExplicitScoper
5
+
6
+ it "can lock and unlock the VM" do
7
+ V8::C::Locker::IsLocked().should be_false
8
+ V8::C::Locker() do
9
+ V8::C::Locker::IsLocked().should be_true
10
+ V8::C::Unlocker() do
11
+ V8::C::Locker::IsLocked().should be_false
12
+ end
13
+ end
14
+ V8::C::Locker::IsLocked().should be_false
15
+ end
16
+
17
+ it "properly unlocks if an exception is thrown inside a lock block" do
18
+ begin
19
+ V8::C::Locker() do
20
+ raise "boom!"
21
+ end
22
+ rescue
23
+ V8::C::Locker::IsLocked().should be_false
24
+ end
25
+ end
26
+
27
+ it "properly re-locks if an exception is thrown inside an un-lock block" do
28
+ V8::C::Locker() do
29
+ begin
30
+ V8::C::Unlocker() do
31
+ raise "boom!"
32
+ end
33
+ rescue
34
+ V8::C::Locker::IsLocked().should be_true
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe V8::C::Object do
4
+
5
+ it "can store and retrieve a value" do
6
+ o = V8::C::Object::New()
7
+ key = V8::C::String::New("foo")
8
+ value = V8::C::String::New("bar")
9
+ o.Set(key, value)
10
+ o.Get(key).Utf8Value().should eql "bar"
11
+ end
12
+
13
+ it "can retrieve all property names" do
14
+ o = V8::C::Object::New()
15
+ o.Set(V8::C::String::New("foo"), V8::C::String::New("bar"))
16
+ o.Set(V8::C::String::New("baz"), V8::C::String::New("bang"))
17
+ names = o.GetPropertyNames()
18
+ names.Length().should eql 2
19
+ names.Get(0).Utf8Value().should eql "foo"
20
+ names.Get(1).Utf8Value().should eql "baz"
21
+ end
22
+ it "can set an accessor from ruby" do
23
+ o = V8::C::Object::New()
24
+ property = V8::C::String::New("statement")
25
+ callback_data = V8::C::String::New("I am Legend")
26
+ left = V8::C::String::New("Yo! ")
27
+ getter = proc do |name, info|
28
+ info.This().StrictEquals(o).should be_true
29
+ info.Holder().StrictEquals(o).should be_true
30
+ V8::C::String::Concat(left, info.Data())
31
+ end
32
+ setter = proc do |name, value, info|
33
+ left = value
34
+ end
35
+ o.SetAccessor(property, getter, setter, callback_data)
36
+ o.Get(property).Utf8Value().should eql "Yo! I am Legend"
37
+ o.Set(property, V8::C::String::New("Bro! "))
38
+ o.Get(property).Utf8Value().should eql "Bro! I am Legend"
39
+ end
40
+ it "always returns the same ruby object for the same V8 object" do
41
+ one = V8::C::Object::New()
42
+ two = V8::C::Object::New()
43
+ one.Set("two", two)
44
+ one.Get("two").should be two
45
+ end
46
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe V8::C::Script do
5
+ it "can run a script and return a polymorphic result" do
6
+ source = V8::C::String::New("(new Array())")
7
+ filename = V8::C::String::New("<eval>")
8
+ script = V8::C::Script::New(source, filename)
9
+ result = script.Run()
10
+ result.should be_kind_of V8::C::Array
11
+ end
12
+
13
+ it "can accept precompiled script data" do
14
+ source = "7 * 6"
15
+ name = V8::C::String::New("<spec>")
16
+ origin = V8::C::ScriptOrigin.new(name)
17
+ data = V8::C::ScriptData::PreCompile(source, source.length)
18
+ data.HasError().should be_false
19
+ script = V8::C::Script::New(V8::C::String::New(source), origin, data)
20
+ script.Run().should eql 42
21
+ end
22
+
23
+ it "can detect errors in the script data" do
24
+ source = "^ = ;"
25
+ data = V8::C::ScriptData::PreCompile(source, source.length)
26
+ data.HasError().should be_true
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe V8::C::String do
4
+ it "can hold Unicode values outside the Basic Multilingual Plane" do
5
+ string = V8::C::String::New("\u{100000}")
6
+ string.Utf8Value().should eql "\u{100000}"
7
+ end
8
+
9
+ it "can naturally translate ruby strings into v8 strings" do
10
+ V8::C::String::Concat(V8::C::String::New("Hello "), "World").Utf8Value().should eql "Hello World"
11
+ end
12
+
13
+ it "can naturally translate ruby objects into v8 strings" do
14
+ V8::C::String::Concat(V8::C::String::New("forty two is "), 42).Utf8Value().should eql "forty two is 42"
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe V8::C::Template do
4
+
5
+ describe V8::C::FunctionTemplate do
6
+ it "can be created with no arguments" do
7
+ t = V8::C::FunctionTemplate::New()
8
+ t.GetFunction().Call(@cxt.Global(),[]).StrictEquals(@cxt.Global()).should be_true
9
+ end
10
+
11
+ it "can be created with a callback" do
12
+ receiver = V8::C::Object::New()
13
+ f = nil
14
+ callback = lambda do |arguments|
15
+ arguments.Length().should be(2)
16
+ arguments[0].Utf8Value().should eql 'one'
17
+ arguments[1].Utf8Value().should eql 'two'
18
+ arguments.Callee().StrictEquals(f).should be_true
19
+ arguments.This().StrictEquals(receiver).should be_true
20
+ arguments.Holder().StrictEquals(receiver).should be_true
21
+ arguments.IsConstructCall().should be_false
22
+ arguments.Data().Value().should be(42)
23
+ V8::C::String::New("result")
24
+ end
25
+ t = V8::C::FunctionTemplate::New(callback, V8::C::External::New(42))
26
+ f = t.GetFunction()
27
+ f.Call(receiver, [V8::C::String::New('one'), V8::C::String::New('two')]).Utf8Value().should eql "result"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe V8::C::External do
4
+
5
+ it "can catch javascript exceptions" do
6
+ V8::C::V8::SetCaptureStackTraceForUncaughtExceptions(true, 99, V8::C::StackTrace::kDetailed)
7
+ V8::C::TryCatch() do |trycatch|
8
+ source = V8::C::String::New(<<-JS)
9
+ function one() {
10
+ two()
11
+ }
12
+ function two() {
13
+ three()
14
+ }
15
+ function three() {
16
+ boom()
17
+ }
18
+ function boom() {
19
+ throw new Error('boom!')
20
+ }
21
+ eval('one()')
22
+ JS
23
+ filename = V8::C::String::New("<eval>")
24
+ script = V8::C::Script::New(source, filename)
25
+ result = script.Run()
26
+ trycatch.HasCaught().should be_true
27
+ trycatch.CanContinue().should be_true
28
+ exception = trycatch.Exception()
29
+ exception.should_not be_nil
30
+ exception.IsNativeError().should be_true
31
+ trycatch.StackTrace().Utf8Value().should match /boom.*three.*two.*one/m
32
+ message = trycatch.Message();
33
+ message.should_not be_nil
34
+ message.Get().Utf8Value().should eql "Uncaught Error: boom!"
35
+ message.GetSourceLine().Utf8Value().should eql " throw new Error('boom!')"
36
+ message.GetScriptResourceName().Utf8Value().should eql "<eval>"
37
+ message.GetLineNumber().should eql 11
38
+ stack = message.GetStackTrace()
39
+ stack.should_not be_nil
40
+ stack.GetFrameCount().should eql 6
41
+ frame = stack.GetFrame(0)
42
+ frame.GetLineNumber().should eql 11
43
+ frame.GetColumn().should eql 15
44
+ frame.GetScriptName().Utf8Value().should eql "<eval>"
45
+ frame.GetScriptNameOrSourceURL().Utf8Value().should eql "<eval>"
46
+ frame.IsEval().should be_false
47
+ stack.GetFrame(4).IsEval().should be_true
48
+ frame.IsConstructor().should be_false
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe "A Very blunt test to make sure that we aren't doing stupid leaks", :memory => true do
4
+ before do
5
+ if Object.const_defined?(:RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
6
+ pending 'need to figure out how to do memory sanity checks on rbx'
7
+ end
8
+ #allocate a single context to make sure that v8 loads its snapshot and
9
+ #we pay the overhead.
10
+ V8::Context.new
11
+ @start_memory = process_memory
12
+ GC.stress = true
13
+ end
14
+
15
+ after do
16
+ GC.stress = false
17
+ end
18
+ it "won't increase process memory by more than 50% no matter how many contexts we create" do
19
+ 500.times do
20
+ V8::Context.new
21
+ run_v8_gc
22
+ end
23
+ process_memory.should <= @start_memory * 1.5
24
+ end
25
+
26
+ it "can eval simple value passing statements repeatedly without significantly increasing memory" do
27
+ V8::C::Locker() do
28
+ cxt = V8::Context.new
29
+ 500.times do
30
+ cxt.eval('7 * 6')
31
+ run_v8_gc
32
+ end
33
+ end
34
+ process_memory.should <= @start_memory * 1.1
35
+ end
36
+
37
+ def process_memory
38
+ /\w*[ ]*#{Process.pid}[ ]*([.,\d]*)[ ]*([.,\d]*)[ ]*([\d]*)[ ]*([\d]*)/.match(`ps aux`)[4].to_i
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'redjs/load_specs'
3
+ module RedJS
4
+ Context = V8::Context
5
+ Error = V8::Error
6
+ end
7
+ describe V8::Context do
8
+ pending "not ready for prime-time"
9
+ #it_behaves_like 'RedJS::Context'
10
+ end
@@ -0,0 +1,45 @@
1
+ require 'v8'
2
+
3
+ def run_v8_gc
4
+ V8::C::V8::LowMemoryNotification()
5
+ while !V8::C::V8::IdleNotification() do
6
+ end
7
+ end
8
+
9
+ def rputs(msg)
10
+ puts "<pre>#{ERB::Util.h(msg)}</pre>"
11
+ $stdout.flush
12
+ end
13
+
14
+ module ExplicitScoper;end
15
+ module Autoscope
16
+ def instance_eval(*args, &block)
17
+ return super unless low_level_c_spec? && !explicitly_defines_scope?
18
+ V8::C::Locker() do
19
+ V8::C::HandleScope() do
20
+ @cxt = V8::C::Context::New()
21
+ begin
22
+ @cxt.Enter()
23
+ super(*args, &block)
24
+ ensure
25
+ @cxt.Exit()
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def low_level_c_spec?
32
+ return false unless described_class
33
+ described_class.name =~ /^V8::C::/
34
+ end
35
+
36
+ def explicitly_defines_scope?
37
+ is_a?(ExplicitScoper)
38
+ end
39
+ end
40
+
41
+ RSpec.configure do |c|
42
+ c.before(:each) do
43
+ extend Autoscope
44
+ end
45
+ end