Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: use ObjectHasOwn instead of alternatives #54710

Closed
wants to merge 1 commit into from

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Sep 2, 2024

Let's use ObjectHasOwn instead of the alternative: ObjectPrototypeHasOwnProperty

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/loaders
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Sep 2, 2024
Copy link

codecov bot commented Sep 2, 2024

Codecov Report

Attention: Patch coverage is 90.47619% with 6 lines in your changes missing coverage. Please review.

Project coverage is 87.60%. Comparing base (71b36b3) to head (4d304bd).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/crypto/util.js 66.66% 1 Missing ⚠️
lib/internal/freeze_intrinsics.js 75.00% 1 Missing ⚠️
lib/internal/modules/cjs/loader.js 0.00% 1 Missing ⚠️
lib/internal/modules/esm/fetch_module.js 50.00% 1 Missing ⚠️
lib/internal/modules/esm/get_format.js 66.66% 1 Missing ⚠️
lib/internal/util.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #54710      +/-   ##
==========================================
- Coverage   87.61%   87.60%   -0.02%     
==========================================
  Files         650      650              
  Lines      182834   182834              
  Branches    35382    35389       +7     
==========================================
- Hits       160194   160175      -19     
- Misses      15925    15929       +4     
- Partials     6715     6730      +15     
Files with missing lines Coverage Δ
lib/child_process.js 97.74% <100.00%> (ø)
lib/cluster.js 96.55% <100.00%> (ø)
lib/internal/async_hooks.js 98.88% <100.00%> (ø)
lib/internal/bootstrap/realm.js 95.79% <100.00%> (-0.22%) ⬇️
lib/internal/cli_table.js 98.93% <100.00%> (ø)
lib/internal/console/constructor.js 99.85% <100.00%> (ø)
lib/internal/errors.js 94.91% <100.00%> (ø)
lib/internal/modules/esm/assert.js 100.00% <100.00%> (ø)
lib/internal/modules/esm/resolve.js 96.63% <100.00%> (ø)
lib/internal/modules/esm/translators.js 91.70% <100.00%> (ø)
... and 16 more

... and 35 files with indirect coverage changes

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@aduh95 aduh95 added the dont-land-on-v18.x PRs that should not land on the v18.x-staging branch and should not be released in v18.x. label Sep 2, 2024
@@ -330,7 +330,7 @@ declare namespace primordials {
export const ObjectEntries: typeof Object.entries
export const ObjectFromEntries: typeof Object.fromEntries
export const ObjectValues: typeof Object.values
export const ObjectPrototypeHasOwnProperty: UncurryThis<typeof Object.prototype.hasOwnProperty>
export const ObjectHasOwn: typeof Object.hasOwn
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about this change, both technically exist. In any case, ObjectHasOwn should ideally appear before ObjectValues, in the same order they are listed in the spec.

Copy link
Member

Choose a reason for hiding this comment

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

ObjectPrototypeHasOwnProperty will likely have an inherent slowdown due to the bind in UncurryThis, so preferring ObjectHasOwn makes sense to me

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm talking about this specific change, the one in typings/primordials.d.ts, not about the whole PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was my intention.

Copy link
Member Author

Choose a reason for hiding this comment

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

I replaced to discourage people from reusing it.

Copy link
Contributor

Choose a reason for hiding this comment

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

In any case, ObjectHasOwn should ideally appear before ObjectValues, in the same order they are listed in the spec.

Copy link
Member

@mertcanaltin mertcanaltin left a comment

Choose a reason for hiding this comment

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

lgtm

@joyeecheung
Copy link
Member

In V8 Object.hasOwn() is built on top of Object.prototype.hasOwnProperty with some null/undefined checks first, so if anything this is likely to be slower than faster:

Return(CallBuiltin(Builtin::kObjectPrototypeHasOwnProperty, context, target,

@ljharb
Copy link
Member

ljharb commented Sep 2, 2024

oof, that's very sad for v8.

@anonrig anonrig closed this Sep 2, 2024
@anonrig
Copy link
Member Author

anonrig commented Sep 2, 2024

I'm closing due to @joyeecheung's comment. Thank you all for reviewing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dont-land-on-v18.x PRs that should not land on the v18.x-staging branch and should not be released in v18.x. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants