|
250 | 250 | end |
251 | 251 | end |
252 | 252 |
|
253 | | - # TODO: Enable this when the methods are implemented in the extension |
254 | | - # it 'can retrieve all property names' do |
255 | | - # o = V8::C::Object.New |
256 | | - # o.Set(V8::C::String.New('foo'), V8::C::String.New('bar')) |
257 | | - # o.Set(V8::C::String.New('baz'), V8::C::String.New('bang')) |
258 | | - # |
259 | | - # names = o.GetPropertyNames() |
260 | | - # names.Length().should eql 2 |
261 | | - # names.Get(0).Utf8Value().should eql 'foo' |
262 | | - # names.Get(1).Utf8Value().should eql 'baz' |
263 | | - # end |
264 | | - # |
265 | | - # it 'can set an accessor from ruby' do |
266 | | - # o = V8::C::Object.New |
267 | | - # property = V8::C::String.New('statement') |
268 | | - # callback_data = V8::C::String.New('I am Legend') |
269 | | - # left = V8::C::String.New('Yo! ') |
270 | | - # getter = proc do |name, info| |
271 | | - # info.This().StrictEquals(o).should be_true |
272 | | - # info.Holder().StrictEquals(o).should be_true |
273 | | - # V8::C::String::Concat(left, info.Data()) |
274 | | - # end |
275 | | - # setter = proc do |name, value, info| |
276 | | - # left = value |
277 | | - # end |
278 | | - # o.SetAccessor(property, getter, setter, callback_data) |
279 | | - # o.Get(property).Utf8Value().should eql 'Yo! I am Legend' |
280 | | - # o.Set(property, V8::C::String::New('Bro! ')) |
281 | | - # o.Get(property).Utf8Value().should eql 'Bro! I am Legend' |
282 | | - # end |
| 253 | + context 'with prototypes' do |
| 254 | + let(:o) { V8::C::Object.New(@isolate) } |
| 255 | + let(:prototype) { V8::C::Object.New(@isolate) } |
| 256 | + let(:prototype_key) { V8::C::String.NewFromUtf8(@isolate, 'foo') } |
| 257 | + let(:o_key) { V8::C::String.NewFromUtf8(@isolate, 'bar') } |
| 258 | + |
| 259 | + before do |
| 260 | + expect(prototype.Set(@ctx, prototype_key, prototype_key)).to be_successful |
| 261 | + expect(o.Set(@ctx, o_key, o_key)).to be_successful |
| 262 | + |
| 263 | + expect(o.SetPrototype(@ctx, prototype)).to be_successful |
| 264 | + end |
| 265 | + |
| 266 | + it 'can set the object prototype' do |
| 267 | + expect(o.Get(@ctx, prototype_key)).to strict_eq prototype_key |
| 268 | + end |
| 269 | + |
| 270 | + it 'can enumerate only own properties' do |
| 271 | + names = o.GetOwnPropertyNames(@ctx) |
| 272 | + |
| 273 | + expect(names).to be_successful |
| 274 | + expect(names.FromJust.Get(@ctx, 0)).to v8_eq o_key |
| 275 | + end |
| 276 | + |
| 277 | + it 'can enumerate all properties' do |
| 278 | + names = o.GetPropertyNames(@ctx) |
| 279 | + |
| 280 | + expect(names).to be_successful |
| 281 | + expect(names.FromJust.Get(@ctx, 0)).to v8_eq o_key |
| 282 | + expect(names.FromJust.Get(@ctx, 1)).to v8_eq prototype_key |
| 283 | + end |
| 284 | + end |
283 | 285 | end |
0 commit comments