{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/20267","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/20267/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/20267/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/20267/events","html_url":"https://github.com/nodejs/node/pull/20267","id":317427546,"number":20267,"title":"n-api: fix inheritance","user":{"login":"gabrielschulhof","id":976081,"avatar_url":"https://avatars2.githubusercontent.com/u/976081?v=4","gravatar_id":"","url":"https://api.github.com/users/gabrielschulhof","html_url":"https://github.com/gabrielschulhof","followers_url":"https://api.github.com/users/gabrielschulhof/followers","following_url":"https://api.github.com/users/gabrielschulhof/following{/other_user}","gists_url":"https://api.github.com/users/gabrielschulhof/gists{/gist_id}","starred_url":"https://api.github.com/users/gabrielschulhof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabrielschulhof/subscriptions","organizations_url":"https://api.github.com/users/gabrielschulhof/orgs","repos_url":"https://api.github.com/users/gabrielschulhof/repos","events_url":"https://api.github.com/users/gabrielschulhof/events{/privacy}","received_events_url":"https://api.github.com/users/gabrielschulhof/received_events","type":"User","site_admin":false},"labels":[{"id":155267502,"url":"https://api.github.com/repos/nodejs/node/labels/C++","name":"C++","color":"e11d21","default":false},{"id":311670452,"url":"https://api.github.com/repos/nodejs/node/labels/dont-land-on-v4.x","name":"dont-land-on-v4.x","color":"eb6420","default":false},{"id":364533783,"url":"https://api.github.com/repos/nodejs/node/labels/dont-land-on-v6.x","name":"dont-land-on-v6.x","color":"c2e0c6","default":false},{"id":574036893,"url":"https://api.github.com/repos/nodejs/node/labels/n-api","name":"n-api","color":"d93f0b","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2018-04-24T23:15:52Z","updated_at":"2018-05-07T22:32:34Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/20267","html_url":"https://github.com/nodejs/node/pull/20267","diff_url":"https://github.com/nodejs/node/pull/20267.diff","patch_url":"https://github.com/nodejs/node/pull/20267.patch"},"body":"In `napi_define_class()` we assign prototype properties to `InstanceTemplate`. This seems to cause an `Illegal invocation` exception when attempting to call a method on an object which is inherited from its parent class.\r\n\r\nOTOH if we retrieve the `\"prototype\"` property of the class and assign prototype properties to the resulting object, following the prototype chain and retrieving the method and invoking it from the parent class' prototype works.\r\n\r\nThis problem has been discussed in https://github.com/nodejs/node-addon-api/issues/246.\r\n\r\nShould there be a distinction between assigning properties to a `FunctionTemplate`'s `InstanceTemplate` and to the object residing at the resulting function's `\"prototype\"` property?\r\n\r\n@TimothyGu @hashseed what do you think?\r\n<!--\r\nThank you for your pull request. Please provide a description above and review\r\nthe requirements below.\r\n\r\nBug fixes and new features should include tests and possibly benchmarks.\r\n\r\nContributors guide: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md\r\n-->\r\n\r\n##### Checklist\r\n<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->\r\n\r\n- [x] `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes\r\n- [x] tests and/or benchmarks are included\r\n- [x] commit message follows [commit guidelines](https://github.com/nodejs/node/blob/master/doc/guides/contributing/pull-requests.md#commit-message-guidelines)\r\n"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/387227087","html_url":"https://github.com/nodejs/node/pull/20267#issuecomment-387227087","issue_url":"https://api.github.com/repos/nodejs/node/issues/20267","id":387227087,"user":{"login":"gabrielschulhof","id":976081,"avatar_url":"https://avatars2.githubusercontent.com/u/976081?v=4","gravatar_id":"","url":"https://api.github.com/users/gabrielschulhof","html_url":"https://github.com/gabrielschulhof","followers_url":"https://api.github.com/users/gabrielschulhof/followers","following_url":"https://api.github.com/users/gabrielschulhof/following{/other_user}","gists_url":"https://api.github.com/users/gabrielschulhof/gists{/gist_id}","starred_url":"https://api.github.com/users/gabrielschulhof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabrielschulhof/subscriptions","organizations_url":"https://api.github.com/users/gabrielschulhof/orgs","repos_url":"https://api.github.com/users/gabrielschulhof/repos","events_url":"https://api.github.com/users/gabrielschulhof/events{/privacy}","received_events_url":"https://api.github.com/users/gabrielschulhof/received_events","type":"User","site_admin":false},"created_at":"2018-05-07T22:32:34Z","updated_at":"2018-05-07T22:32:34Z","author_association":"CONTRIBUTOR","body":"@hashseed Node.js has always had this restriction. As a result, instances subclasses of classes created with `node::ObjectWrap`, `Nan::ObjectWrap`, and now `napi_define_class()` cannot call methods defined on the parent class unless the subclasses are defined with `extends` in JavaScript or `FunctionTemplate::Inherit` in C++.\r\n\r\nIf `GetCompatibleReceiver()` iterates the prototype chain, then it seems to miss the prototype assigned with `Object.setPrototypeOf()`."}}
{"actor":{"display_login":"gabrielschulhof"}}