therubyracer-freebsd 0.10.1 → 0.11.1p2
Sign up to get free protection for your applications and to get access to all the features.
- metadata +37 -109
- data/.gitignore +0 -13
- data/.rspec +0 -1
- data/.travis.yml +0 -8
- data/.yardopts +0 -1
- data/Changelog.md +0 -231
- data/Gemfile +0 -3
- data/README.md +0 -167
- data/Rakefile +0 -26
- data/bin/therubyracer +0 -11
- data/ext/v8/extconf.rb +0 -26
- data/ext/v8/rr.cpp +0 -189
- data/ext/v8/rr.h +0 -41
- data/ext/v8/v8.cpp +0 -48
- data/ext/v8/v8_array.cpp +0 -48
- data/ext/v8/v8_array.h +0 -8
- data/ext/v8/v8_callbacks.cpp +0 -81
- data/ext/v8/v8_callbacks.h +0 -8
- data/ext/v8/v8_context.cpp +0 -92
- data/ext/v8/v8_context.h +0 -6
- data/ext/v8/v8_date.cpp +0 -40
- data/ext/v8/v8_date.h +0 -6
- data/ext/v8/v8_debug.cpp +0 -17
- data/ext/v8/v8_debug.h +0 -6
- data/ext/v8/v8_exception.cpp +0 -133
- data/ext/v8/v8_exception.h +0 -11
- data/ext/v8/v8_external.cpp +0 -70
- data/ext/v8/v8_external.h +0 -8
- data/ext/v8/v8_function.cpp +0 -69
- data/ext/v8/v8_function.h +0 -11
- data/ext/v8/v8_handle.cpp +0 -186
- data/ext/v8/v8_handle.h +0 -48
- data/ext/v8/v8_locker.cpp +0 -139
- data/ext/v8/v8_locker.h +0 -6
- data/ext/v8/v8_message.cpp +0 -67
- data/ext/v8/v8_message.h +0 -10
- data/ext/v8/v8_object.cpp +0 -122
- data/ext/v8/v8_object.h +0 -10
- data/ext/v8/v8_script.cpp +0 -36
- data/ext/v8/v8_script.h +0 -8
- data/ext/v8/v8_string.cpp +0 -52
- data/ext/v8/v8_string.h +0 -9
- data/ext/v8/v8_template.cpp +0 -344
- data/ext/v8/v8_template.h +0 -8
- data/ext/v8/v8_try_catch.cpp +0 -70
- data/ext/v8/v8_try_catch.h +0 -5
- data/ext/v8/v8_v8.cpp +0 -34
- data/ext/v8/v8_v8.h +0 -6
- data/ext/v8/v8_value.cpp +0 -175
- data/ext/v8/v8_value.h +0 -10
- data/ext/v8/v8_weakref.cpp +0 -61
- data/ext/v8/v8_weakref.h +0 -29
- data/lib/v8/access.rb +0 -92
- data/lib/v8/array.rb +0 -17
- data/lib/v8/c/locker.rb +0 -18
- data/lib/v8/cli.rb +0 -133
- data/lib/v8/context.rb +0 -111
- data/lib/v8/error.rb +0 -130
- data/lib/v8/function.rb +0 -44
- data/lib/v8/object.rb +0 -69
- data/lib/v8/portal/caller.rb +0 -37
- data/lib/v8/portal/constructor.rb +0 -98
- data/lib/v8/portal/function.rb +0 -63
- data/lib/v8/portal/interceptors.rb +0 -152
- data/lib/v8/portal/proxies.rb +0 -151
- data/lib/v8/portal/templates.rb +0 -73
- data/lib/v8/portal.rb +0 -86
- data/lib/v8/stack.rb +0 -66
- data/lib/v8/tap.rb +0 -9
- data/lib/v8/version.rb +0 -3
- data/lib/v8.rb +0 -23
- data/spec/ext/array_spec.rb +0 -15
- data/spec/ext/cxt_spec.rb +0 -57
- data/spec/ext/ext_spec_helper.rb +0 -27
- data/spec/ext/func_spec.rb +0 -64
- data/spec/ext/object_spec.rb +0 -10
- data/spec/ext/string_spec.rb +0 -11
- data/spec/ext/try_catch_spec.rb +0 -60
- data/spec/redjs_spec.rb +0 -9
- data/spec/spec_helper.rb +0 -9
- data/spec/v8/error_spec.rb +0 -131
- data/spec/v8/portal/proxies_spec.rb +0 -106
- data/specmem/handle_memspec.rb +0 -41
- data/specmem/object_memspec.rb +0 -14
- data/specmem/proxies_memspec.rb +0 -49
- data/specmem/spec_helper.rb +0 -24
- data/specthread/spec_helper.rb +0 -2
- data/specthread/threading_spec.rb +0 -13
- data/thefrontside.png +0 -0
- data/therubyracer.gemspec +0 -27
data/lib/v8/context.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'stringio'
|
2
|
-
|
3
|
-
module V8
|
4
|
-
class Context
|
5
|
-
attr_reader :native, :scope, :access
|
6
|
-
|
7
|
-
def initialize(opts = {})
|
8
|
-
@access = Access.new
|
9
|
-
@to = Portal.new(self, @access)
|
10
|
-
@to.lock do
|
11
|
-
with = opts[:with]
|
12
|
-
constructor = nil
|
13
|
-
template = if with
|
14
|
-
constructor = @to.templates.to_constructor(with.class)
|
15
|
-
constructor.disable()
|
16
|
-
constructor.template.InstanceTemplate()
|
17
|
-
else
|
18
|
-
C::ObjectTemplate::New()
|
19
|
-
end
|
20
|
-
@native = opts[:with] ? C::Context::New(template) : C::Context::New()
|
21
|
-
@native.enter do
|
22
|
-
@global = @native.Global()
|
23
|
-
@to.proxies.register_javascript_proxy @global, :for => with if with
|
24
|
-
constructor.enable() if constructor
|
25
|
-
@scope = @to.rb(@global)
|
26
|
-
@global.SetHiddenValue(C::String::NewSymbol("TheRubyRacer::RubyContext"), C::External::New(self))
|
27
|
-
end
|
28
|
-
yield(self) if block_given?
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def eval(javascript, filename = "<eval>", line = 1)
|
33
|
-
if IO === javascript || StringIO === javascript
|
34
|
-
javascript = javascript.read()
|
35
|
-
end
|
36
|
-
err = nil
|
37
|
-
value = nil
|
38
|
-
@to.lock do
|
39
|
-
C::TryCatch.try do |try|
|
40
|
-
@native.enter do
|
41
|
-
script = C::Script::Compile(@to.v8(javascript.to_s), @to.v8(filename.to_s))
|
42
|
-
if try.HasCaught()
|
43
|
-
err = JSError.new(try, @to)
|
44
|
-
else
|
45
|
-
result = script.Run()
|
46
|
-
if try.HasCaught()
|
47
|
-
err = JSError.new(try, @to)
|
48
|
-
else
|
49
|
-
value = @to.rb(result)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
raise err if err
|
56
|
-
return value
|
57
|
-
end
|
58
|
-
|
59
|
-
def load(filename)
|
60
|
-
File.open(filename) do |file|
|
61
|
-
self.eval file, filename, 1
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def [](key)
|
66
|
-
@to.open do
|
67
|
-
@to.rb @global.Get(@to.v8(key))
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def []=(key, value)
|
72
|
-
@to.open do
|
73
|
-
@global.Set(@to.v8(key), @to.v8(value))
|
74
|
-
end
|
75
|
-
return value
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.stack(limit = 99)
|
79
|
-
if native = C::Context::GetEntered()
|
80
|
-
global = native.Global()
|
81
|
-
cxt = global.GetHiddenValue(C::String::NewSymbol("TheRubyRacer::RubyContext")).Value()
|
82
|
-
cxt.instance_eval {@to.rb(C::StackTrace::CurrentStackTrace(limit))}
|
83
|
-
else
|
84
|
-
[]
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.passes_this_argument?
|
89
|
-
true
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
module C
|
94
|
-
class Context
|
95
|
-
def enter
|
96
|
-
if block_given?
|
97
|
-
if IsEntered()
|
98
|
-
yield(self)
|
99
|
-
else
|
100
|
-
Enter()
|
101
|
-
begin
|
102
|
-
yield(self)
|
103
|
-
ensure
|
104
|
-
Exit()
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
data/lib/v8/error.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
|
2
|
-
module V8
|
3
|
-
class JSError < StandardError
|
4
|
-
attr_reader :value, :boundaries
|
5
|
-
|
6
|
-
def initialize(try, to)
|
7
|
-
@to = to
|
8
|
-
super(initialize_unsafe(try))
|
9
|
-
rescue Exception => e
|
10
|
-
@boundaries = [Boundary.new(:rbframes => e.backtrace)]
|
11
|
-
@value = e
|
12
|
-
super(<<-EOMSG)
|
13
|
-
You have uncovered what is probably a BUG in therubyracer exception code. An error report would be very helpful.
|
14
|
-
JSError#initialize failed!: #{e.message}"
|
15
|
-
EOMSG
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize_unsafe(try)
|
19
|
-
message = nil
|
20
|
-
ex = @to.rb(try.Exception())
|
21
|
-
@boundaries = [Boundary.new(:rbframes => caller(3), :jsframes => parse_js_frames(try))]
|
22
|
-
if V8::Object === ex
|
23
|
-
if msg = ex['message']
|
24
|
-
message = msg
|
25
|
-
else
|
26
|
-
message = ex.to_s
|
27
|
-
end
|
28
|
-
if cause = ex.instance_variable_get(:@native).GetHiddenValue("TheRubyRacer::Cause")
|
29
|
-
if !cause.IsEmpty()
|
30
|
-
prev = cause.Value()
|
31
|
-
if prev.kind_of?(JSError)
|
32
|
-
@boundaries.concat prev.boundaries
|
33
|
-
@value = prev.value
|
34
|
-
else
|
35
|
-
@value = prev
|
36
|
-
@boundaries.concat [Boundary.new(:rbframes => prev.backtrace)]
|
37
|
-
end
|
38
|
-
else
|
39
|
-
@value = ex
|
40
|
-
end
|
41
|
-
end
|
42
|
-
else
|
43
|
-
@value = ex
|
44
|
-
message = ex.to_s
|
45
|
-
end
|
46
|
-
return message
|
47
|
-
end
|
48
|
-
|
49
|
-
def in_ruby?
|
50
|
-
@value.kind_of?(Exception)
|
51
|
-
end
|
52
|
-
|
53
|
-
def in_javascript?
|
54
|
-
!in_ruby?
|
55
|
-
end
|
56
|
-
|
57
|
-
def backtrace(*modifiers)
|
58
|
-
trace_framework = modifiers.include?(:framework)
|
59
|
-
trace_ruby = modifiers.length == 0 || modifiers.include?(:ruby)
|
60
|
-
trace_javascript = modifiers.length == 0 || modifiers.include?(:javascript)
|
61
|
-
mixed = []
|
62
|
-
rbcontext = []
|
63
|
-
jscontext = []
|
64
|
-
@boundaries.each do |b|
|
65
|
-
rbframes = b.rbframes.dup
|
66
|
-
rbcontext.reverse_each do |frame|
|
67
|
-
if frame == rbframes.last
|
68
|
-
rbframes.pop
|
69
|
-
else
|
70
|
-
break
|
71
|
-
end
|
72
|
-
end if trace_ruby
|
73
|
-
jsframes = b.jsframes.dup
|
74
|
-
jscontext.reverse_each do |frame|
|
75
|
-
if frame == jsframes.last
|
76
|
-
jsframes.pop
|
77
|
-
else
|
78
|
-
break
|
79
|
-
end
|
80
|
-
end if trace_javascript
|
81
|
-
rbcontext = b.rbframes
|
82
|
-
jscontext = b.jsframes
|
83
|
-
rbframes.reject! {|f| f =~ /lib\/v8\/.*\.rb/} unless trace_framework
|
84
|
-
mixed.unshift(*rbframes) if trace_ruby
|
85
|
-
mixed.unshift(*jsframes) if trace_javascript
|
86
|
-
end
|
87
|
-
return mixed
|
88
|
-
end
|
89
|
-
|
90
|
-
def parse_js_frames(try)
|
91
|
-
#I can't figure out why V8 is not capturing the stacktrace here
|
92
|
-
#in terms of StackTrace and StackFrame objects, so we have to
|
93
|
-
#parse the string.
|
94
|
-
raw = @to.rb(try.StackTrace())
|
95
|
-
if raw && !raw.empty? && !syntax_error?(try)
|
96
|
-
raw.split("\n")[1..-1].tap do |frames|
|
97
|
-
frames.each {|frame| frame.strip!; frame.chomp!(",")}
|
98
|
-
end.reject(&:empty?)
|
99
|
-
else
|
100
|
-
msg = try.Message()
|
101
|
-
["at #{@to.rb(msg.GetScriptResourceName())}:#{msg.GetLineNumber()}:#{msg.GetStartColumn() + 1}"]
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
#Syntax errors are weird in that they have a non-empty stack trace
|
106
|
-
#but it does not contain any source location information, so
|
107
|
-
#in these instances, we have to pull it out of the Message object
|
108
|
-
#in the TryCatch. Is there a better way to detect a syntax error
|
109
|
-
def syntax_error?(try)
|
110
|
-
ex = @to.rb(try.Exception())
|
111
|
-
if ex && ex.kind_of?(V8::Object)
|
112
|
-
type = ex["constructor"]
|
113
|
-
type && type.kind_of?(V8::Function) && type.name == "SyntaxError"
|
114
|
-
else
|
115
|
-
false
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
class Boundary
|
120
|
-
attr_reader :rbframes, :jsframes
|
121
|
-
|
122
|
-
def initialize(frames = {})
|
123
|
-
@rbframes = frames[:rbframes] || []
|
124
|
-
@jsframes = frames[:jsframes] || []
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
#deprecated -- use JSError
|
129
|
-
JavasriptError = JSError
|
130
|
-
end
|
data/lib/v8/function.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
module V8
|
2
|
-
class Function < V8::Object
|
3
|
-
|
4
|
-
def methodcall(thisObject, *args)
|
5
|
-
err = nil
|
6
|
-
return_value = nil
|
7
|
-
@portal.open do |to|
|
8
|
-
C::TryCatch.try do |try|
|
9
|
-
this = to.v8(thisObject)
|
10
|
-
return_value = to.rb(@native.Call(this, to.v8(args)))
|
11
|
-
err = JSError.new(try, to) if try.HasCaught()
|
12
|
-
end
|
13
|
-
end
|
14
|
-
raise err if err
|
15
|
-
return return_value
|
16
|
-
end
|
17
|
-
|
18
|
-
def call(*args)
|
19
|
-
@portal.open do
|
20
|
-
self.methodcall(@portal.context.native.Global(), *args)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def new(*args)
|
25
|
-
@portal.open do |to|
|
26
|
-
to.rb(@native.NewInstance(to.v8(args)))
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def name
|
31
|
-
@portal.open do |to|
|
32
|
-
to.rb(@native.GetName())
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def name=(name)
|
37
|
-
name.tap do
|
38
|
-
@portal.open do |to|
|
39
|
-
@native.SetName(to.v8(name))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/lib/v8/object.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
|
2
|
-
module V8
|
3
|
-
class Object
|
4
|
-
include Enumerable
|
5
|
-
|
6
|
-
def initialize(native, portal)
|
7
|
-
@native, @portal = native, portal
|
8
|
-
end
|
9
|
-
|
10
|
-
def [](key)
|
11
|
-
@portal.open do |to|
|
12
|
-
to.rb(@native.Get(to.v8(key)))
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def []=(key, value)
|
17
|
-
value.tap do
|
18
|
-
@portal.open do |to|
|
19
|
-
@native.Set(to.v8(key), to.v8(value))
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_s
|
25
|
-
@portal.open do |to|
|
26
|
-
to.rb(@native.ToString())
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def each
|
31
|
-
@portal.open do |to|
|
32
|
-
for prop in to.rb(@native.GetPropertyNames())
|
33
|
-
yield prop, self[prop]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def respond_to?(method)
|
39
|
-
super or self[method] != nil
|
40
|
-
end
|
41
|
-
|
42
|
-
def method_missing(name, *args, &block)
|
43
|
-
if name.to_s =~ /(.*)=$/
|
44
|
-
if args.length > 1
|
45
|
-
self[$1] = args
|
46
|
-
return args
|
47
|
-
else
|
48
|
-
self[$1] = args.first
|
49
|
-
return args
|
50
|
-
end
|
51
|
-
end
|
52
|
-
return super(name, *args, &block) unless self.respond_to?(name)
|
53
|
-
property = self[name]
|
54
|
-
if property.kind_of?(V8::Function)
|
55
|
-
property.methodcall(self, *args)
|
56
|
-
elsif args.empty?
|
57
|
-
property
|
58
|
-
else
|
59
|
-
raise ArgumentError, "wrong number of arguments (#{args.length} for 0)" unless args.empty?
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class Object
|
66
|
-
def eval_js(javascript)
|
67
|
-
V8::Context.new(:with => self).eval(javascript)
|
68
|
-
end
|
69
|
-
end
|
data/lib/v8/portal/caller.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
|
2
|
-
module V8
|
3
|
-
class Portal
|
4
|
-
class Caller
|
5
|
-
|
6
|
-
def initialize(portal)
|
7
|
-
@portal = portal
|
8
|
-
end
|
9
|
-
|
10
|
-
def raw
|
11
|
-
yield
|
12
|
-
rescue Exception => e
|
13
|
-
case e
|
14
|
-
when SystemExit, NoMemoryError
|
15
|
-
raise e
|
16
|
-
else
|
17
|
-
error = V8::C::Exception::Error(V8::C::String::New(e.message))
|
18
|
-
#TODO: This is almost certainly a crash here.
|
19
|
-
#we need to hold onto `error` while it bubbles up the javascript stack.
|
20
|
-
error.SetHiddenValue("TheRubyRacer::Cause", C::External::New(e))
|
21
|
-
V8::C::ThrowException(error)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def protect(*args, &block)
|
26
|
-
@portal.v8 raw(*args, &block)
|
27
|
-
end
|
28
|
-
|
29
|
-
def invoke(code, *args, &block)
|
30
|
-
protect do
|
31
|
-
args = args.slice(0, code.arity) if code.arity >= 0
|
32
|
-
code.call(*args, &block)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
|
2
|
-
module V8
|
3
|
-
class Portal
|
4
|
-
class ConstructorAdapter
|
5
|
-
attr_reader :template, :exposed
|
6
|
-
alias_method :exposed?, :exposed
|
7
|
-
|
8
|
-
def initialize(templates, class_id)
|
9
|
-
@exposed = false
|
10
|
-
@class_id = class_id
|
11
|
-
@templates = templates
|
12
|
-
@invoke = method(:invoke)
|
13
|
-
@template = C::FunctionTemplate::New(@invoke)
|
14
|
-
portal.interceptors.setup(@template.InstanceTemplate())
|
15
|
-
cls = self.ruby_class
|
16
|
-
superclass = cls.superclass
|
17
|
-
if cls != ::Object && superclass != ::Object && superclass != ::Class
|
18
|
-
@template.Inherit(templates.to_constructor(superclass).template)
|
19
|
-
end
|
20
|
-
if cls.name && cls.name =~ /(::)?(\w+?)$/
|
21
|
-
template.SetClassName(C::String::NewSymbol("rb::" + $2))
|
22
|
-
else
|
23
|
-
template.SetClassName("Ruby")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def function
|
28
|
-
@template.GetFunction()
|
29
|
-
end
|
30
|
-
|
31
|
-
def allocate(object)
|
32
|
-
arguments = C::Array::New(1)
|
33
|
-
arguments.Set(0, C::External::New(object))
|
34
|
-
function.NewInstance(arguments)
|
35
|
-
end
|
36
|
-
|
37
|
-
def disable
|
38
|
-
@disabled = true
|
39
|
-
end
|
40
|
-
|
41
|
-
def enable
|
42
|
-
@disabled = nil
|
43
|
-
end
|
44
|
-
|
45
|
-
def invoke(arguments)
|
46
|
-
return if @disabled
|
47
|
-
if !@exposed
|
48
|
-
unless arguments.Length() == 1 && arguments[0].kind_of?(C::External)
|
49
|
-
C::ThrowException(C::Exception::Error(C::String::New("cannot call native constructor from javascript")))
|
50
|
-
else
|
51
|
-
object = arguments[0].Value()
|
52
|
-
proxies.register_javascript_proxy arguments.This(), :for => object
|
53
|
-
end
|
54
|
-
else
|
55
|
-
instance = nil
|
56
|
-
if arguments.Length() > 0 && arguments[0].kind_of?(C::External)
|
57
|
-
instance = arguments[0].Value()
|
58
|
-
else
|
59
|
-
rbargs = []
|
60
|
-
for i in 0..arguments.Length() - 1
|
61
|
-
rbargs << @templates.portal.rb(arguments[i])
|
62
|
-
end
|
63
|
-
instance = portal.caller.raw do
|
64
|
-
self.ruby_class.new(*rbargs)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
proxies.register_javascript_proxy arguments.This(), :for => instance
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def exposed=(exposed)
|
72
|
-
if exposed && !@augmented
|
73
|
-
#create a prototype so that this constructor also acts like a ruby object
|
74
|
-
prototype_template = C::ObjectTemplate::New()
|
75
|
-
portal.interceptors.setup(prototype_template)
|
76
|
-
prototype = prototype_template.NewInstance()
|
77
|
-
#set *that* object's prototype to an empty function so that it will look and behave like a function.
|
78
|
-
prototype.SetPrototype(C::FunctionTemplate::New().GetFunction())
|
79
|
-
template.GetFunction().SetPrototype(prototype)
|
80
|
-
@augmented = true
|
81
|
-
end
|
82
|
-
@exposed = exposed
|
83
|
-
end
|
84
|
-
|
85
|
-
def ruby_class
|
86
|
-
ObjectSpace._id2ref(@class_id)
|
87
|
-
end
|
88
|
-
|
89
|
-
def proxies
|
90
|
-
@templates.proxies
|
91
|
-
end
|
92
|
-
|
93
|
-
def portal
|
94
|
-
@templates.portal
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
data/lib/v8/portal/function.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
module V8
|
2
|
-
class Portal
|
3
|
-
class FunctionAdapter
|
4
|
-
|
5
|
-
attr_reader :template
|
6
|
-
|
7
|
-
def initialize(portal, code)
|
8
|
-
@portal = 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
|
14
|
-
@code = code
|
15
|
-
@template = V8::C::FunctionTemplate::New(@caller, @code)
|
16
|
-
end
|
17
|
-
|
18
|
-
def function
|
19
|
-
@template.GetFunction()
|
20
|
-
end
|
21
|
-
|
22
|
-
class Call
|
23
|
-
def initialize(portal)
|
24
|
-
@portal = portal
|
25
|
-
end
|
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
|
38
|
-
def call(arguments)
|
39
|
-
proc = arguments.Data()
|
40
|
-
rbargs = []
|
41
|
-
for i in 0..arguments.Length() - 1
|
42
|
-
rbargs << @portal.rb(arguments[i])
|
43
|
-
end
|
44
|
-
@portal.caller.invoke(proc, *rbargs)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class BindAndCall < Call
|
49
|
-
def call(arguments)
|
50
|
-
method = arguments.Data()
|
51
|
-
rbargs = []
|
52
|
-
for i in 0..arguments.Length() - 1
|
53
|
-
rbargs << @portal.rb(arguments[i])
|
54
|
-
end
|
55
|
-
this = @portal.rb(arguments.This())
|
56
|
-
@portal.caller.protect do
|
57
|
-
method.bind(this).call(*rbargs)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
module V8
|
2
|
-
class Portal
|
3
|
-
class Interceptors
|
4
|
-
def initialize(portal)
|
5
|
-
@getter = NamedPropertyGetter.new(portal)
|
6
|
-
@setter = NamedPropertySetter.new(portal)
|
7
|
-
@query = nil
|
8
|
-
@deleter = nil
|
9
|
-
@enumerator = NamedPropertyEnumerator.new(portal)
|
10
|
-
@igetter = IndexedPropertyGetter.new(portal)
|
11
|
-
@isetter = IndexedPropertySetter.new(portal)
|
12
|
-
@iquery = nil
|
13
|
-
@ideleter = nil
|
14
|
-
@ienumerator = IndexedPropertyEnumerator.new(portal)
|
15
|
-
end
|
16
|
-
|
17
|
-
def setup(template)
|
18
|
-
template.SetNamedPropertyHandler(@getter,@setter,@query,@deleter,@enumerator, nil)
|
19
|
-
template.SetIndexedPropertyHandler(@igetter,@isetter,@iquery,@ideleter,@ienumerator, nil)
|
20
|
-
end
|
21
|
-
|
22
|
-
class PropertyAttributes
|
23
|
-
attr_reader :flags
|
24
|
-
def initialize
|
25
|
-
@flags = 0
|
26
|
-
end
|
27
|
-
|
28
|
-
def read_only
|
29
|
-
tap do
|
30
|
-
@flags |= V8::C::ReadOnly
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def dont_enum
|
35
|
-
tap do
|
36
|
-
@flags |= V8::C::DontEnum
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def dont_delete
|
41
|
-
tap do
|
42
|
-
@flags |= V8::C::DontDelete
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class Interceptor
|
48
|
-
|
49
|
-
def initialize(portal)
|
50
|
-
@to, @access = portal, portal.access
|
51
|
-
end
|
52
|
-
|
53
|
-
def intercept(info, retval = nil, &code)
|
54
|
-
obj = @to.rb(info.This())
|
55
|
-
intercepts = true
|
56
|
-
result = @to.caller.protect do
|
57
|
-
dontintercept = proc do
|
58
|
-
intercepts = false
|
59
|
-
end
|
60
|
-
code.call(obj, dontintercept)
|
61
|
-
end
|
62
|
-
intercepts ? (retval || result) : C::Empty
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
class NamedPropertyGetter < Interceptor
|
67
|
-
def call(property, info)
|
68
|
-
intercept(info) do |obj, dontintercept|
|
69
|
-
@access.get(obj, @to.rb(property), &dontintercept)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
class NamedPropertySetter < Interceptor
|
75
|
-
def call(property, value, info)
|
76
|
-
intercept(info, value) do |obj, dontintercept|
|
77
|
-
@access.set(obj, @to.rb(property), @to.rb(value), &dontintercept)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class NamedPropertyQuery
|
83
|
-
def call(property, info)
|
84
|
-
attributes = PropertyAttributes.new
|
85
|
-
result = intercept(info) do |obj, dontintercept|
|
86
|
-
@access.query(obj, @to.rb(property), attributes, &dontintercept)
|
87
|
-
end
|
88
|
-
return result == C::Empty ? result : C::Integer::New(attributes.flags)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class NamedPropertyEnumerator < Interceptor
|
93
|
-
def call(info)
|
94
|
-
intercept(info) do |obj, dontintercept|
|
95
|
-
@access.names(obj, &dontintercept).to_a
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
class NamedPropertyDeleter < Interceptor
|
101
|
-
def call(property, info)
|
102
|
-
intercept(info) do |obj, dontintercept|
|
103
|
-
@access.delete(obj, property, &dontintercept)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class IndexedPropertyGetter < Interceptor
|
109
|
-
def call(index, info)
|
110
|
-
intercept(info) do |obj, dontintercept|
|
111
|
-
@access.iget(obj, index, &dontintercept)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
class IndexedPropertySetter < Interceptor
|
117
|
-
def call(index, value, info)
|
118
|
-
intercept(info, value) do |obj, dontintercept|
|
119
|
-
@access.iset(obj, index, @to.rb(value), &dontintercept)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
class IndexedPropertyQuery < Interceptor
|
125
|
-
def call(property, info)
|
126
|
-
attributes = PropertyAttributes.new
|
127
|
-
result = intercept(info) do |obj, dontintercept|
|
128
|
-
@access.indices(obj, &dontintercept)
|
129
|
-
end
|
130
|
-
result == C::Empty ? C::Empty : C::Integer::New(attributes.flags)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
class IndexedPropertyDeleter < Interceptor
|
135
|
-
def call(index, info)
|
136
|
-
intercept(info) do |obj, dontintercept|
|
137
|
-
@access.idelete(obj, index, &dontintercept)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
class IndexedPropertyEnumerator < Interceptor
|
143
|
-
def call(info)
|
144
|
-
intercept(info) do |obj, dontintercept|
|
145
|
-
@access.indices(obj, &dontintercept)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|