1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/spec/c/object_spec.rb
2012-06-05 08:00:04 -05:00

40 lines
No EOL
1.3 KiB
Ruby

require 'spec_helper'
describe V8::C::Object do
it "can store and retrieve a value" do
o = V8::C::Object::New()
key = V8::C::String::New("foo")
value = V8::C::String::New("bar")
o.Set(key, value)
o.Get(key).Utf8Value().should eql "bar"
end
it "can retrieve all property names" do
o = V8::C::Object::New()
o.Set(V8::C::String::New("foo"), V8::C::String::New("bar"))
o.Set(V8::C::String::New("baz"), V8::C::String::New("bang"))
names = o.GetPropertyNames()
names.Length().should eql 2
names.Get(0).Utf8Value().should eql "foo"
names.Get(1).Utf8Value().should eql "baz"
end
it "can set an accessor from ruby" do
o = V8::C::Object::New()
property = V8::C::String::New("statement")
callback_data = V8::C::String::New("I am Legend")
left = V8::C::String::New("Yo! ")
getter = proc do |name, info|
info.This().StrictEquals(o).should be_true
info.Holder().StrictEquals(o).should be_true
V8::C::String::Concat(left, info.Data())
end
setter = proc do |name, value, info|
left = value
end
o.SetAccessor(property, getter, setter, callback_data)
o.Get(property).Utf8Value().should eql "Yo! I am Legend"
o.Set(property, V8::C::String::New("Bro! "))
o.Get(property).Utf8Value().should eql "Bro! I am Legend"
end
end