|
81 | 81 | end |
82 | 82 | end |
83 | 83 |
|
| 84 | + describe '#SetAccessorProperty' do |
| 85 | + it 'can set getters' do |
| 86 | + o = V8::C::Object.New(@isolate) |
| 87 | + key = V8::C::String.NewFromUtf8(@isolate, 'foo') |
| 88 | + |
| 89 | + get_value = V8::C::String.NewFromUtf8(@isolate, 'bar') |
| 90 | + getter = V8::C::Function.New(@isolate, proc { |info| info.GetReturnValue.Set(get_value) }) |
| 91 | + |
| 92 | + o.SetAccessorProperty(@ctx, key, getter) |
| 93 | + expect(o.Get(@ctx, key)).to strict_eq get_value |
| 94 | + end |
| 95 | + |
| 96 | + it 'can set setters' do |
| 97 | + o = V8::C::Object.New(@isolate) |
| 98 | + key = V8::C::String.NewFromUtf8(@isolate, 'foo') |
| 99 | + |
| 100 | + set_value = nil |
| 101 | + |
| 102 | + getter = V8::C::Function.New(@isolate, proc { }) |
| 103 | + setter = V8::C::Function.New(@isolate, proc { |info| set_value = info[0] }) |
| 104 | + |
| 105 | + o.SetAccessorProperty(@ctx, key, getter, setter) |
| 106 | + expect(o.Set(@ctx, key, key)).to be_successful |
| 107 | + expect(set_value).to strict_eq key |
| 108 | + end |
| 109 | + end |
| 110 | + |
84 | 111 | describe '#CreateDataProperty' do |
85 | 112 | it 'can set the property' do |
86 | 113 | o = V8::C::Object.New(@isolate) |
|
151 | 178 | expect(enumerable.FromJust.Value).to be false |
152 | 179 | end |
153 | 180 |
|
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 |
| 181 | + it 'can read the descriptor of an accessor property' do |
| 182 | + o = V8::C::Object.New(@isolate) |
| 183 | + key = V8::C::String.NewFromUtf8(@isolate, 'foo') |
| 184 | + data = V8::C::String.NewFromUtf8(@isolate, 'data') |
| 185 | + |
| 186 | + getter = V8::C::Function.New @isolate, proc { }, V8::C::Object::New(@isolate) |
| 187 | + setter = V8::C::Function.New @isolate, proc { }, V8::C::Object::New(@isolate) |
| 188 | + |
| 189 | + o.SetAccessorProperty(@ctx, key, getter, setter) |
| 190 | + |
| 191 | + maybe = o.GetOwnPropertyDescriptor(@ctx, key) |
| 192 | + expect(maybe).to be_successful |
| 193 | + |
| 194 | + descriptor = maybe.FromJust |
| 195 | + value = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'value')) |
| 196 | + writable = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'writable')) |
| 197 | + get = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'get')) |
| 198 | + set = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'set')) |
| 199 | + configurable = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'configurable')) |
| 200 | + enumerable = descriptor.Get(@ctx, V8::C::String.NewFromUtf8(@isolate, 'enumerable')) |
| 201 | + |
| 202 | + expect(value).to be_successful |
| 203 | + expect(value.FromJust).to be_a V8::C::Undefined |
| 204 | + expect(writable).to be_successful |
| 205 | + |
| 206 | + expect(get).to strict_eq getter |
| 207 | + expect(set).to strict_eq setter |
| 208 | + |
| 209 | + expect(configurable).to be_successful |
| 210 | + expect(configurable.FromJust.Value).to be true |
| 211 | + |
| 212 | + expect(enumerable).to be_successful |
| 213 | + expect(enumerable.FromJust.Value).to be true |
| 214 | + end |
192 | 215 | end |
193 | 216 |
|
194 | 217 | # TODO: Enable this when the methods are implemented in the extension |
|
0 commit comments