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

set named Ruby properties from JS

This commit is contained in:
Charles Lowell 2012-06-11 16:21:06 -05:00
parent 4a8612f5c4
commit ad7e9dddb7

View file

@ -2,7 +2,7 @@ class V8::Conversion
module Object module Object
def to_v8 def to_v8
template = V8::C::ObjectTemplate::New() template = V8::C::ObjectTemplate::New()
template.SetNamedPropertyHandler(Get, nil, nil, nil, nil, V8::C::External::New(self)) template.SetNamedPropertyHandler(Get, Set, nil, nil, nil, V8::C::External::New(self))
instance = template.NewInstance() instance = template.NewInstance()
V8::Context.link self, instance V8::Context.link self, instance
return instance return instance
@ -19,13 +19,28 @@ class V8::Conversion
object = info.Data().Value() object = info.Data().Value()
name = property.Utf8Value() name = property.Utf8Value()
dontintercept = proc do dontintercept = proc do
return V8::C::Empty return V8::C::Value::Empty
end end
context.to_v8 access.get(object, name, &dontintercept) context.to_v8 access.get(object, name, &dontintercept)
rescue Exception => e rescue Exception => e
warn "uncaught exception: #{e.class}: #{e.message} while accessing object property: #{e.backtrace.join('\n')}" warn "uncaught exception: #{e.class}: #{e.message} while accessing object property: #{e.backtrace.join('\n')}"
end end
end end
class Set
def self.call(property, value, info)
context = V8::Context.current
access = context.access
object = info.Data().Value()
name = property.Utf8Value()
dontintercept = proc do
return V8::C::Value::Empty
end
access.set(object, name, 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 end
module NativeObject module NativeObject