Browse Source

test: verify napi_get_property() walks prototype

Refs: https://github.com/nodejs/node/issues/13925
PR-URL: https://github.com/nodejs/node/pull/13961
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
v6
cjihrig 8 years ago
parent
commit
0f1888f313
  1. 19
      test/addons-napi/test_object/test.js

19
test/addons-napi/test_object/test.js

@ -31,6 +31,25 @@ assert(test_object.Has(newObject, 'test_number'));
assert.strictEqual(newObject.test_number, 987654321);
assert.strictEqual(newObject.test_string, 'test string');
{
// Verify that napi_get_property() walks the prototype chain.
function MyObject() {
this.foo = 42;
this.bar = 43;
}
MyObject.prototype.bar = 44;
MyObject.prototype.baz = 45;
const obj = new MyObject();
assert.strictEqual(test_object.Get(obj, 'foo'), 42);
assert.strictEqual(test_object.Get(obj, 'bar'), 43);
assert.strictEqual(test_object.Get(obj, 'baz'), 45);
assert.strictEqual(test_object.Get(obj, 'toString'),
Object.prototype.toString);
}
{
// test_object.Inflate increases all properties by 1
const cube = {

Loading…
Cancel
Save