Skip to content

Commit 0b4a813

Browse files
committed
Fix accessors test to work with Holder unwrapping
To ensure that the Holder of an accessor is indeed an instance of the corret type, we can't attach the holders to the prototype but have to attach them to the object itself.
1 parent f7c8d4d commit 0b4a813

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

test/cpp/accessors.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ NAN_MODULE_INIT(SetterGetter::Init) {
4848
tpl->SetClassName(Nan::New<v8::String>("SetterGetter").ToLocalChecked());
4949
tpl->InstanceTemplate()->SetInternalFieldCount(1);
5050
SetPrototypeMethod(tpl, "log", SetterGetter::Log);
51-
v8::Local<v8::ObjectTemplate> proto = tpl->PrototypeTemplate();
51+
v8::Local<v8::ObjectTemplate> itpl = tpl->InstanceTemplate();
5252
SetAccessor(
53-
proto
53+
itpl
5454
, Nan::New("prop1").ToLocalChecked()
5555
, SetterGetter::GetProp1);
5656
SetAccessor(
57-
proto
57+
itpl
5858
, Nan::New<v8::String>("prop2").ToLocalChecked()
5959
, SetterGetter::GetProp2
6060
, SetterGetter::SetProp2

test/js/accessors-test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const test = require('tap').test
1111
, bindings = require('bindings')({ module_root: testRoot, bindings: 'accessors' });
1212

1313
test('accessors', function (t) {
14-
t.plan(4)
14+
t.plan(7)
1515
var settergetter = bindings.create()
1616
t.equal(settergetter.prop1, 'this is property 1')
1717
t.ok(settergetter.prop2 === '')
@@ -24,4 +24,9 @@ test('accessors', function (t) {
2424
'Prop2:SETTER(setting a value)\n' +
2525
'Prop2:GETTER(setting a value)\n'
2626
)
27+
var derived = Object.create(settergetter)
28+
t.equal(derived.prop1, 'this is property 1')
29+
derived.prop2 = 'setting a new value'
30+
t.equal(derived.prop2, 'setting a new value')
31+
t.equal(settergetter.prop2, 'setting a new value')
2732
})

0 commit comments

Comments
 (0)