mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
move object access to the class layer.
This commit is contained in:
parent
e7db9d8d38
commit
478d99b72f
5 changed files with 7 additions and 74 deletions
2
Gemfile
2
Gemfile
|
@ -4,4 +4,4 @@ source 'http://rubygems.org'
|
|||
gemspec
|
||||
|
||||
gem 'redjs', :git => 'https://github.com/cowboyd/redjs.git'
|
||||
gem 'libv8', "~> 3.10.8"
|
||||
gem 'libv8', "~> 3.11.8"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
LIBV8_COMPATIBILITY = '~> 3.10.8'
|
||||
LIBV8_COMPATIBILITY = '~> 3.11.8'
|
||||
|
||||
def have_rubygem_libv8?
|
||||
gem 'libv8', LIBV8_COMPATIBILITY
|
||||
|
|
|
@ -8,16 +8,11 @@ module V8
|
|||
@conversion = Conversion.new
|
||||
@access = Access.new
|
||||
if global = options[:with]
|
||||
V8::C::Locker() do
|
||||
V8::C::HandleScope() do
|
||||
tmp = V8::C::Context::New()
|
||||
tmp.Enter()
|
||||
global_template = global.to_v8_template
|
||||
tmp.Exit()
|
||||
@native = V8::C::Context::New(nil, global_template)
|
||||
enter { link global, @native.Global() }
|
||||
end
|
||||
Context.new.enter do
|
||||
global_template = global.class.to_v8_template.InstanceTemplate()
|
||||
@native = V8::C::Context::New(nil, global_template)
|
||||
end
|
||||
enter {link global, @native.Global()}
|
||||
else
|
||||
@native = V8::C::Context::New()
|
||||
end
|
||||
|
|
|
@ -34,6 +34,7 @@ class V8::Conversion
|
|||
arguments.construct @class
|
||||
end
|
||||
end
|
||||
return arguments.This()
|
||||
end
|
||||
|
||||
module Args
|
||||
|
|
|
@ -9,72 +9,9 @@ class V8::Conversion
|
|||
return object
|
||||
end
|
||||
|
||||
def to_v8_template
|
||||
weakcell(:v8_template) do
|
||||
V8::C::ObjectTemplate::New().tap do |template|
|
||||
data = V8::C::External::New(self)
|
||||
template.SetNamedPropertyHandler(Get, Set, nil, nil, nil, data)
|
||||
template.SetIndexedPropertyHandler(IGet, ISet, nil, nil, nil, data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_ruby
|
||||
self
|
||||
end
|
||||
|
||||
module Accessor
|
||||
include V8::Error::Protect
|
||||
def intercept(info, key, &block)
|
||||
context = V8::Context.current
|
||||
access = context.access
|
||||
object = info.Data().Value()
|
||||
handles_property = true
|
||||
dontintercept = proc do
|
||||
handles_property = false
|
||||
end
|
||||
protect do
|
||||
result = block.call(context, access, object, context.to_ruby(key), dontintercept)
|
||||
handles_property ? context.to_v8(result) : V8::C::Value::Empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Get
|
||||
extend Accessor
|
||||
def self.call(property, info)
|
||||
intercept(info, property) do |context, access, object, key, dontintercept|
|
||||
access.get(object, key, &dontintercept)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Set
|
||||
extend Accessor
|
||||
def self.call(property, value, info)
|
||||
intercept(info, property) do |context, access, object, key, dontintercept|
|
||||
access.set(object, key, context.to_ruby(value), &dontintercept)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class IGet
|
||||
extend Accessor
|
||||
def self.call(property, info)
|
||||
intercept(info, property) do |context, access, object, key, dontintercept|
|
||||
access.iget(object, key, &dontintercept)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ISet
|
||||
extend Accessor
|
||||
def self.call(property, value, info)
|
||||
intercept(info, property) do |context, access, object, key, dontintercept|
|
||||
access.iset(object, key, context.to_ruby(value), &dontintercept)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module NativeObject
|
||||
|
|
Loading…
Add table
Reference in a new issue