1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

support indexed getters on object.

This commit is contained in:
Charles Lowell 2012-06-12 04:18:17 -05:00
parent 2c7586536e
commit fb4ac37c69

View file

@ -1,5 +1,7 @@
class V8::Conversion
module Object
include V8::Util::Weakcell
def to_v8
object = to_v8_template.NewInstance()
V8::Context.link self, object
@ -7,8 +9,12 @@ class V8::Conversion
end
def to_v8_template
V8::C::ObjectTemplate::New().tap do |template|
template.SetNamedPropertyHandler(Get, Set, nil, nil, nil, V8::C::External::New(self))
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
@ -45,6 +51,34 @@ class V8::Conversion
warn "uncaught exception: #{e.class}: #{e.message} while accessing object property: #{e.backtrace.join('\n')}"
end
end
class IGet
def self.call(index, info)
context = V8::Context.current
access = context.access
object = info.Data().Value()
dontintercept = proc do
return V8::C::Value::Empty
end
context.to_v8 access.iget(object, index, &dontintercept)
rescue Exception => e
warn "uncaught exception: #{e.class}: #{e.message} while accessing object property: #{e.backtrace.join('\n')}"
end
end
class ISet
def self.call(index, value, info)
context = V8::Context.current
access = context.access
object = info.Data().Value()
dontintercept = proc do
return V8::C::Value::Empty
end
access.iset(object, index, context.to_ruby(value), &dontintercept)
rescue Exception => e
warn "uncaught exception: #{e.class}: #{e.message} while accessing object property: #{e.backtrace.join('\n')}"
end
end
end
module NativeObject