|
| 1 | +require 'c_spec_helper' |
| 2 | + |
| 3 | +describe V8::C::Template do |
| 4 | + requires_v8_context |
| 5 | + |
| 6 | + let(:key) { V8::C::String::NewFromUtf8(@isolate, "key") } |
| 7 | + let(:value) { V8::C::Integer::New(@isolate, 23) } |
| 8 | + let(:template) { V8::C::ObjectTemplate::New(@isolate) } |
| 9 | + |
| 10 | + describe "Set()" do |
| 11 | + |
| 12 | + describe "without property attributes" do |
| 13 | + before do |
| 14 | + template.Set(key, value) |
| 15 | + end |
| 16 | + it "places those values on all new instances" do |
| 17 | + object = template.NewInstance(@ctx).FromJust() |
| 18 | + expect(object.Get(@ctx, key).FromJust().Value).to be 23 |
| 19 | + end |
| 20 | + end |
| 21 | + |
| 22 | + describe "with property attributes" do |
| 23 | + before do |
| 24 | + template.Set(key, value, V8::C::PropertyAttribute::ReadOnly) |
| 25 | + @object = template.NewInstance(@ctx).FromJust() |
| 26 | + @object.Set(@ctx, key, V8::C::Integer::New(@isolate, 25)) |
| 27 | + end |
| 28 | + it "applies those property attributes" do |
| 29 | + expect(@object.Get(@ctx, key).FromJust().Value).to be 23 |
| 30 | + end |
| 31 | + end |
| 32 | + end |
| 33 | + |
| 34 | + describe "SetAccessorProperty()" do |
| 35 | + describe "with the bare minimum" do |
| 36 | + before do |
| 37 | + template.SetAccessorProperty(key) |
| 38 | + @object = template.NewInstance(@ctx).FromJust() |
| 39 | + @object.Set(@ctx, key, value) |
| 40 | + end |
| 41 | + it "cannot be shared across contexts" do |
| 42 | + ctx2 = V8::C::Context::New(@isolate) |
| 43 | + expect(@object.Get(@ctx, key).FromJust().Value).to be 23 |
| 44 | + expect(@object.Get(ctx2, key).FromJust()).to be_nil |
| 45 | + end |
| 46 | + end |
| 47 | + end |
| 48 | +end |
0 commit comments