therubyracer-st 0.11.0beta5-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/.travis.yml +10 -0
- data/Changelog.md +242 -0
- data/Gemfile +15 -0
- data/README.md +185 -0
- data/Rakefile +58 -0
- data/benchmarks.rb +217 -0
- data/ext/v8/accessor.cc +181 -0
- data/ext/v8/array.cc +26 -0
- data/ext/v8/backref.cc +54 -0
- data/ext/v8/build.rb +53 -0
- data/ext/v8/constants.cc +34 -0
- data/ext/v8/constraints.cc +52 -0
- data/ext/v8/context.cc +130 -0
- data/ext/v8/date.cc +18 -0
- data/ext/v8/exception.cc +38 -0
- data/ext/v8/extconf.rb +23 -0
- data/ext/v8/external.cc +43 -0
- data/ext/v8/function.cc +58 -0
- data/ext/v8/gc.cc +43 -0
- data/ext/v8/handles.cc +34 -0
- data/ext/v8/heap.cc +31 -0
- data/ext/v8/init.cc +39 -0
- data/ext/v8/invocation.cc +86 -0
- data/ext/v8/locker.cc +77 -0
- data/ext/v8/message.cc +51 -0
- data/ext/v8/object.cc +334 -0
- data/ext/v8/primitive.cc +8 -0
- data/ext/v8/rr.cc +83 -0
- data/ext/v8/rr.h +883 -0
- data/ext/v8/script.cc +80 -0
- data/ext/v8/signature.cc +18 -0
- data/ext/v8/stack.cc +75 -0
- data/ext/v8/string.cc +47 -0
- data/ext/v8/template.cc +175 -0
- data/ext/v8/trycatch.cc +86 -0
- data/ext/v8/v8.cc +87 -0
- data/ext/v8/value.cc +239 -0
- data/lib/v8.rb +36 -0
- data/lib/v8/access.rb +5 -0
- data/lib/v8/access/indices.rb +40 -0
- data/lib/v8/access/invocation.rb +47 -0
- data/lib/v8/access/names.rb +65 -0
- data/lib/v8/array.rb +26 -0
- data/lib/v8/context.rb +243 -0
- data/lib/v8/conversion.rb +35 -0
- data/lib/v8/conversion/array.rb +11 -0
- data/lib/v8/conversion/class.rb +120 -0
- data/lib/v8/conversion/code.rb +38 -0
- data/lib/v8/conversion/fundamental.rb +11 -0
- data/lib/v8/conversion/hash.rb +11 -0
- data/lib/v8/conversion/indentity.rb +31 -0
- data/lib/v8/conversion/method.rb +26 -0
- data/lib/v8/conversion/object.rb +28 -0
- data/lib/v8/conversion/primitive.rb +7 -0
- data/lib/v8/conversion/proc.rb +5 -0
- data/lib/v8/conversion/reference.rb +16 -0
- data/lib/v8/conversion/string.rb +12 -0
- data/lib/v8/conversion/symbol.rb +7 -0
- data/lib/v8/conversion/time.rb +13 -0
- data/lib/v8/error.rb +25 -0
- data/lib/v8/error/protect.rb +20 -0
- data/lib/v8/error/try.rb +15 -0
- data/lib/v8/function.rb +28 -0
- data/lib/v8/helper.rb +30 -0
- data/lib/v8/object.rb +79 -0
- data/lib/v8/util/weakcell.rb +29 -0
- data/lib/v8/version.rb +3 -0
- data/spec/c/array_spec.rb +17 -0
- data/spec/c/constants_spec.rb +20 -0
- data/spec/c/exception_spec.rb +26 -0
- data/spec/c/external_spec.rb +9 -0
- data/spec/c/function_spec.rb +46 -0
- data/spec/c/handles_spec.rb +35 -0
- data/spec/c/locker_spec.rb +38 -0
- data/spec/c/object_spec.rb +46 -0
- data/spec/c/script_spec.rb +28 -0
- data/spec/c/string_spec.rb +16 -0
- data/spec/c/template_spec.rb +30 -0
- data/spec/c/trycatch_spec.rb +51 -0
- data/spec/mem/blunt_spec.rb +42 -0
- data/spec/redjs_spec.rb +10 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/threading_spec.rb +52 -0
- data/spec/v8/context_spec.rb +19 -0
- data/spec/v8/conversion_spec.rb +9 -0
- data/spec/v8/error_spec.rb +21 -0
- data/spec/v8/function_spec.rb +9 -0
- data/spec/v8/object_spec.rb +15 -0
- data/thefrontside.png +0 -0
- data/therubyracer.gemspec +20 -0
- data/vendor/v8.dll +0 -0
- metadata +161 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
class V8::Conversion
|
2
|
+
module Code
|
3
|
+
include V8::Util::Weakcell
|
4
|
+
|
5
|
+
def to_v8
|
6
|
+
fn = to_template.GetFunction()
|
7
|
+
V8::Context.link self, fn
|
8
|
+
return fn
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_template
|
12
|
+
weakcell(:template) {V8::C::FunctionTemplate::New(InvocationHandler.new(self))}
|
13
|
+
end
|
14
|
+
|
15
|
+
class InvocationHandler
|
16
|
+
include V8::Error::Protect
|
17
|
+
|
18
|
+
def initialize(code)
|
19
|
+
@code = code
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(arguments)
|
23
|
+
protect do
|
24
|
+
context = V8::Context.current
|
25
|
+
access = context.access
|
26
|
+
args = ::Array.new(arguments.Length())
|
27
|
+
0.upto(args.length - 1) do |i|
|
28
|
+
if i < args.length
|
29
|
+
args[i] = context.to_ruby arguments[i]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
this = context.to_ruby arguments.This()
|
33
|
+
context.to_v8 access.methodcall(@code, this, args)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'ref'
|
2
|
+
|
3
|
+
class V8::Conversion
|
4
|
+
module Identity
|
5
|
+
def to_ruby(v8_object)
|
6
|
+
if v8_object.class <= V8::C::Object
|
7
|
+
v8_idmap[v8_object.GetIdentityHash()] || super(v8_object)
|
8
|
+
else
|
9
|
+
super(v8_object)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_v8(ruby_object)
|
14
|
+
return super(ruby_object) if ruby_object.is_a?(String) || ruby_object.is_a?(Primitive)
|
15
|
+
rb_idmap[ruby_object.object_id] || super(ruby_object)
|
16
|
+
end
|
17
|
+
|
18
|
+
def equate(ruby_object, v8_object)
|
19
|
+
v8_idmap[v8_object.GetIdentityHash()] = ruby_object
|
20
|
+
rb_idmap[ruby_object.object_id] = v8_object
|
21
|
+
end
|
22
|
+
|
23
|
+
def v8_idmap
|
24
|
+
@v8_idmap ||= Ref::WeakValueMap.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def rb_idmap
|
28
|
+
@ruby_idmap ||= Ref::WeakValueMap.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class V8::Conversion
|
2
|
+
module Method
|
3
|
+
include V8::Conversion::Code
|
4
|
+
|
5
|
+
def to_v8
|
6
|
+
template = @@method_cache[self] ||= to_template
|
7
|
+
template.GetFunction()
|
8
|
+
end
|
9
|
+
|
10
|
+
class MethodCache
|
11
|
+
def initialize
|
12
|
+
@map = Ref::WeakValueMap.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](method)
|
16
|
+
@map[method.to_s]
|
17
|
+
end
|
18
|
+
|
19
|
+
def []=(method, template)
|
20
|
+
@map[method.to_s] = template
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
@@method_cache = MethodCache.new
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class V8::Conversion
|
2
|
+
module Object
|
3
|
+
def to_v8
|
4
|
+
Reference.construct! self
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_ruby
|
8
|
+
self
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module NativeObject
|
13
|
+
def to_ruby
|
14
|
+
wrap = if IsArray()
|
15
|
+
::V8::Array
|
16
|
+
elsif IsFunction()
|
17
|
+
::V8::Function
|
18
|
+
else
|
19
|
+
::V8::Object
|
20
|
+
end
|
21
|
+
wrap.new(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_v8
|
25
|
+
self
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class V8::Conversion
|
2
|
+
module Reference
|
3
|
+
|
4
|
+
def self.construct!(object)
|
5
|
+
context = V8::Context.current
|
6
|
+
constructor = context.to_v8(object.class)
|
7
|
+
reference = constructor.NewInstance([V8::C::External::New(object)])
|
8
|
+
return reference
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_v8
|
12
|
+
Reference.construct! self
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/v8/error.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module V8
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :value
|
4
|
+
def initialize(message, value)
|
5
|
+
super(message)
|
6
|
+
@value = value
|
7
|
+
end
|
8
|
+
end
|
9
|
+
const_set :JSError, Error
|
10
|
+
|
11
|
+
def self.Error(exception)
|
12
|
+
value = exception.to_ruby
|
13
|
+
if !exception.kind_of?(V8::C::Value)
|
14
|
+
raise V8::Error.new(exception.to_s, value)
|
15
|
+
elsif exception.IsNativeError()
|
16
|
+
if football = exception.GetHiddenValue("rr::Football")
|
17
|
+
raise football.Value()
|
18
|
+
else
|
19
|
+
raise V8::Error.new(exception.Get("message").to_ruby, value)
|
20
|
+
end
|
21
|
+
else
|
22
|
+
raise V8::Error.new(exception.ToString().to_ruby, value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class V8::Error
|
2
|
+
module Protect
|
3
|
+
def protect
|
4
|
+
yield
|
5
|
+
rescue Football => e
|
6
|
+
e.kickoff!
|
7
|
+
rescue Exception => e
|
8
|
+
e.extend Football
|
9
|
+
e.kickoff!
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Football
|
14
|
+
def kickoff!
|
15
|
+
error = V8::C::Exception::Error(message)
|
16
|
+
error.SetHiddenValue("rr::Football", V8::C::External::New(self))
|
17
|
+
V8::C::ThrowException(error)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/v8/error/try.rb
ADDED
data/lib/v8/function.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class V8::Function < V8::Object
|
2
|
+
include V8::Error::Try
|
3
|
+
|
4
|
+
def initialize(native = nil)
|
5
|
+
super do
|
6
|
+
native || V8::C::FunctionTemplate::New().GetFunction()
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def methodcall(this, *args)
|
11
|
+
@context.enter do
|
12
|
+
this ||= @context.native.Global()
|
13
|
+
@context.to_ruby try {native.Call(@context.to_v8(this), args.map {|a| @context.to_v8 a})}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(*args)
|
18
|
+
@context.enter do
|
19
|
+
methodcall @context.native.Global(), *args
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def new(*args)
|
24
|
+
@context.enter do
|
25
|
+
@context.to_ruby try {native.NewInstance(args.map {|a| @context.to_v8 a})}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/v8/helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module V8
|
2
|
+
module_function
|
3
|
+
|
4
|
+
def find_file(name, where)
|
5
|
+
where.split(File::PATH_SEPARATOR).each do |path|
|
6
|
+
file = File.join(path, name)
|
7
|
+
return file if File.exist? file
|
8
|
+
end
|
9
|
+
false
|
10
|
+
end
|
11
|
+
|
12
|
+
def v8_path
|
13
|
+
begin
|
14
|
+
require 'libv8'
|
15
|
+
return Libv8.libv8_source_path
|
16
|
+
rescue LoadError
|
17
|
+
end
|
18
|
+
|
19
|
+
v8_path = find_file("libv8.a", ENV['PATH'])
|
20
|
+
File.dirname v8_path if v8_path
|
21
|
+
end
|
22
|
+
|
23
|
+
def darwin?
|
24
|
+
RUBY_PLATFORM =~ /darwin/
|
25
|
+
end
|
26
|
+
|
27
|
+
def mingw?
|
28
|
+
RUBY_PLATFORM =~ /mingw/
|
29
|
+
end
|
30
|
+
end
|
data/lib/v8/object.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
class V8::Object
|
2
|
+
include Enumerable
|
3
|
+
attr_reader :native
|
4
|
+
alias_method :to_v8, :native
|
5
|
+
|
6
|
+
def initialize(native = nil)
|
7
|
+
@context = V8::Context.current or fail "tried to initialize a #{self.class} without being in an entered V8::Context"
|
8
|
+
@native = block_given? ? yield : native || V8::C::Object::New()
|
9
|
+
@context.link self, @native
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](key)
|
13
|
+
@context.enter do
|
14
|
+
@context.to_ruby @native.Get(@context.to_v8(key))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def []=(key, value)
|
19
|
+
@context.enter do
|
20
|
+
@native.Set(@context.to_v8(key), @context.to_v8(value))
|
21
|
+
end
|
22
|
+
return value
|
23
|
+
end
|
24
|
+
|
25
|
+
def keys
|
26
|
+
@context.enter do
|
27
|
+
names = @native.GetPropertyNames()
|
28
|
+
0.upto( names.Length() - 1).to_enum.map {|i| @context.to_ruby names.Get(i)}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def values
|
33
|
+
@context.enter do
|
34
|
+
names = @native.GetPropertyNames()
|
35
|
+
0.upto( names.Length() - 1).to_enum.map {|i| @context.to_ruby @native.Get(names.Get(i))}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def each
|
40
|
+
@context.enter do
|
41
|
+
names = @native.GetPropertyNames()
|
42
|
+
0.upto(names.Length() - 1) do |i|
|
43
|
+
name = names.Get(i)
|
44
|
+
yield @context.to_ruby(name), @context.to_ruby(@native.Get(name))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_s
|
50
|
+
@context.enter do
|
51
|
+
@context.to_ruby @native.ToString()
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def respond_to?(method)
|
56
|
+
super or self[method] != nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def method_missing(name, *args, &block)
|
60
|
+
if name.to_s =~ /(.*)=$/
|
61
|
+
if args.length > 1
|
62
|
+
self[$1] = args
|
63
|
+
return args
|
64
|
+
else
|
65
|
+
self[$1] = args.first
|
66
|
+
return args
|
67
|
+
end
|
68
|
+
end
|
69
|
+
return super(name, *args, &block) unless self.respond_to?(name)
|
70
|
+
property = self[name]
|
71
|
+
if property.kind_of?(V8::Function)
|
72
|
+
property.methodcall(self, *args)
|
73
|
+
elsif args.empty?
|
74
|
+
property
|
75
|
+
else
|
76
|
+
raise ArgumentError, "wrong number of arguments (#{args.length} for 0)" unless args.empty?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module V8
|
2
|
+
module Util
|
3
|
+
module Weakcell
|
4
|
+
def weakcell(name, &block)
|
5
|
+
unless storage = instance_variable_get("@#{name}")
|
6
|
+
storage = instance_variable_set("@#{name}", Storage.new)
|
7
|
+
end
|
8
|
+
storage.access(&block)
|
9
|
+
end
|
10
|
+
class Storage
|
11
|
+
def access(&block)
|
12
|
+
if @ref
|
13
|
+
@ref.object || populate(block)
|
14
|
+
else
|
15
|
+
populate(block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def populate(block)
|
22
|
+
occupant = block.call()
|
23
|
+
@ref = Ref::WeakReference.new(occupant)
|
24
|
+
return occupant
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|