1 of 11

Stage 3 Update: Accessible Object.prototype.hasOwnProperty

Jamie Kyle (Rome) & Tierney Cyren (Microsoft)

2 of 11

Super fast explainer

  • Object.prototype.hasOwnProperty() is not always reliably accessible due to things like Object.create(null)
  • Code like Object.prototype.hasOwnProperty.call(obj, prop) is common, but also requires understanding a lot of concepts all at once for new users
  • There are lots of libraries like “has” and “lodash.has” that make hasOwnProperty() easier to use (with billions of npm downloads!)
  • Object.hasOwn(obj, key) mirrors hasOwnProperty.call(obj, key) to make it more accessible
  • Besides a flip in the ordering of their ToObject and ToPropertyKey steps (fixing a legacy issue), they are identical and can share implementations.

3 of 11

Status: Ecma262 Spec

  • Prepared & Editor-Approved ecma262 PR: tc39/ecma262#2415

4 of 11

Status: Test262 Tests

  • Merged: tc39/test262#2995

5 of 11

Status: Implementations

🚀 V8: Implemented, only available with --harmony-object-has-own

🚀 SpiderMonkey: Implemented, only available in nightly builds

🛠️ JavaScriptCore: In Progress? rdar://problem/78782545 ??

Others:

🚀 Serenity LibJS: SerenityOS/serenity@3ee092

🚀 engine262: engine262/engine262#163

👍

6 of 11

Status: Community Polyfills

7 of 11

Status: Community Codemod

8 of 11

Status: Community Feedback

Feedback tracking issue: tc39/proposal-accessible-object-hasownproperty#18

  • We’ve mostly heard excitement for this feature on social media
  • We’ve heard from a couple users that they’ve started using polyfills in their codebases successfully
  • Thousands of core-js/es-shims users have merged PRs including the Object.hasOwn() polyfill https://github.com/search?q=Object.hasOwn+is%3Apr+is%3Amerged&type=Issues

👍

9 of 11

Status: Stage 4 Requirements Overview

Tracking issue: tc39/proposal-accessible-object-hasownproperty#6

✅ Ecma262 PR is editor-approved and ready to be merged

✅ Test262 tests merged

👍 Implemented (feature flagged) in two browsers

👍 Getting more community feedback with polyfills (how much do we need?)

Plan to seek Stage 4 pending feedback from browsers

10 of 11

Thanks

Champion: Tierney Cyren

Spec Text Reviewers: Jordan Harband, Kevin Gibbons, Nicolo Ribaudo

Implementers/Reviewers:

  • V8: Victor Gomes, Shu-yu Guo, Jakob Gruber
  • SpiderMonkey: Yulia Startsev, Matthew Gaudet
  • engine262: Gus Caplan
  • Polyfills: Jordan Harband, Denis Pushkarev, Nicolo Ribaudo

Test262 Reviewers: Mike Pennisi, Rick Waldron, Nicolo Ribaudo

Proposal Feedback: Mathias Bynens, Denis Pushkarev, Jordan Harband, Justin Ridgewell, Jason Yu, HE Shi-Jun, Kevin Gibbons, and others!

11 of 11

Questions?