1
0
Fork 0
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:
Charles Lowell 2012-06-15 09:57:42 -05:00
parent e7db9d8d38
commit 478d99b72f
5 changed files with 7 additions and 74 deletions

View file

@ -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"

View file

@ -1,5 +1,5 @@
LIBV8_COMPATIBILITY = '~> 3.10.8'
LIBV8_COMPATIBILITY = '~> 3.11.8'
def have_rubygem_libv8?
gem 'libv8', LIBV8_COMPATIBILITY

View file

@ -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

View file

@ -34,6 +34,7 @@ class V8::Conversion
arguments.construct @class
end
end
return arguments.This()
end
module Args

View file

@ -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