Skip to content

feat: add Object::GetPrototype and Object::SetPrototype#1715

Open
KevinEady wants to merge 1 commit intonodejs:mainfrom
KevinEady:add-get-set-prototype
Open

feat: add Object::GetPrototype and Object::SetPrototype#1715
KevinEady wants to merge 1 commit intonodejs:mainfrom
KevinEady:add-get-set-prototype

Conversation

@KevinEady
Copy link
Contributor

  • Add Object::GetPrototype and Object::SetPrototype
  • Update docs and tests

Fixes: #1691

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 63.51%. Comparing base (fe0c48e) to head (aa0f8c0).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
napi-inl.h 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1715   +/-   ##
=======================================
  Coverage   63.50%   63.51%           
=======================================
  Files           3        3           
  Lines        2047     2050    +3     
  Branches      728      729    +1     
=======================================
+ Hits         1300     1302    +2     
  Misses        162      162           
- Partials      585      586    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

### GetPrototype()

```cpp
Napi::Object Napi::Object::GetPrototype() const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prototype of the method is MaybeOrValue<Object> Object::GetPrototype() const.

Maybe it could be good to explain if the object has no prototype.

const prototype = {};
const obj = Object.create(prototype);
assert.strictEqual(binding.object.getPrototype(obj), prototype);
}
Copy link
Member

@NickNaso NickNaso Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be useful to test when the oblect has no prototype const obj = Object.create(null); ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Need Triage

Development

Successfully merging this pull request may close these issues.

Safer way to set object prototype

4 participants