|
114 | 114 | end |
115 | 115 | end |
116 | 116 |
|
| 117 | + describe '#GetOwnPropertyDescriptor' do |
| 118 | + it 'can read the descriptor of a data property' do |
| 119 | + o = V8::C::Object.New(@isolate) |
| 120 | + key = V8::C::String.NewFromUtf8(@isolate, 'foo') |
| 121 | + data = V8::C::String.NewFromUtf8(@isolate, 'data') |
| 122 | + |
| 123 | + expect(o.DefineOwnProperty(@ctx, key, data, V8::C::PropertyAttribute::DontEnum)).to be_successful |
| 124 | + |
| 125 | + maybe = o.GetOwnPropertyDescriptor(@ctx, key) |
| 126 | + expect(maybe).to be_successful |
| 127 | + |
| 128 | + descriptor = maybe.FromJust |
| 129 | + value = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'value')) |
| 130 | + writable = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'writable')) |
| 131 | + get = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'get')) |
| 132 | + set = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'set')) |
| 133 | + configurable = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'configurable')) |
| 134 | + enumerable = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'enumerable')) |
| 135 | + |
| 136 | + expect(value).to strict_eq data |
| 137 | + |
| 138 | + expect(writable).to be_successful |
| 139 | + expect(writable.FromJust.Value).to be true |
| 140 | + |
| 141 | + expect(get).to be_successful |
| 142 | + expect(get.FromJust).to be_a V8::C::Undefined |
| 143 | + |
| 144 | + expect(set).to be_successful |
| 145 | + expect(set.FromJust).to be_a V8::C::Undefined |
| 146 | + |
| 147 | + expect(configurable).to be_successful |
| 148 | + expect(configurable.FromJust.Value).to be true |
| 149 | + |
| 150 | + expect(enumerable).to be_successful |
| 151 | + expect(enumerable.FromJust.Value).to be false |
| 152 | + end |
| 153 | + |
| 154 | + # it 'can read the descriptor of an accessor property' do |
| 155 | + # o = V8::C::Object.New(@isolate) |
| 156 | + # key = V8::C::String.NewFromUtf8(@isolate, 'foo') |
| 157 | + # data = V8::C::String.NewFromUtf8(@isolate, 'data') |
| 158 | + # |
| 159 | + # getter = V8::C::Function.New @isolate, proc { }, V8::C::Object::New(@isolate) |
| 160 | + # setter = V8::C::Function.New @isolate, proc { }, V8::C::Object::New(@isolate) |
| 161 | + # |
| 162 | + # expect(o.SetAccessorProperty(@ctx, key, getter, setter)).to be_successful |
| 163 | + # |
| 164 | + # maybe = o.GetOwnPropertyDescriptor(@ctx, key) |
| 165 | + # expect(maybe).to be_successful |
| 166 | + # |
| 167 | + # descriptor = maybe.FromJust |
| 168 | + # value = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'value')) |
| 169 | + # writable = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'writable')) |
| 170 | + # get = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'get')) |
| 171 | + # set = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'set')) |
| 172 | + # configurable = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'configurable')) |
| 173 | + # enumerable = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'enumerable')) |
| 174 | + # |
| 175 | + # expect(value).to be_successful |
| 176 | + # |
| 177 | + # expect(writable).to be_successful |
| 178 | + # expect(writable.FromJust.Value).to be true |
| 179 | + # |
| 180 | + # expect(get).to be_successful |
| 181 | + # expect(get.FromJust).to be_a V8::C::Undefined |
| 182 | + # |
| 183 | + # expect(set).to be_successful |
| 184 | + # expect(set.FromJust).to be_a V8::C::Undefined |
| 185 | + # |
| 186 | + # expect(configurable).to be_successful |
| 187 | + # expect(configurable.FromJust.Value).to be true |
| 188 | + # |
| 189 | + # expect(enumerable).to be_successful |
| 190 | + # expect(enumerable.FromJust.Value).to be true |
| 191 | + # end |
| 192 | + end |
| 193 | + |
117 | 194 | # TODO: Enable this when the methods are implemented in the extension |
118 | 195 | # it 'can retrieve all property names' do |
119 | 196 | # o = V8::C::Object.New |
|
0 commit comments