From f400939206c5bf1fb369f360913b7db94e00f2d7 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 28 Jun 2017 12:06:47 -0400 Subject: [PATCH] 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 Reviewed-By: Evan Lucas Reviewed-By: Anna Henningsen Reviewed-By: Michael Dawson --- test/addons-napi/test_object/test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/addons-napi/test_object/test.js b/test/addons-napi/test_object/test.js index 4b64fa4b381af5..c9c549c827409f 100644 --- a/test/addons-napi/test_object/test.js +++ b/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 = {