Skip to content

fix: handle missing Object.prototype methods in @stdlib/assert - #16808

Open
ItsAbir005 wants to merge 13 commits into
stdlib-js:developfrom
ItsAbir005:fix/missing-object-prototype-methods
Open

ItsAbir005 wants to merge 13 commits into
stdlib-js:developfrom
ItsAbir005:fix/missing-object-prototype-methods

Conversation

@ItsAbir005

@ItsAbir005 ItsAbir005 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #16798.

Description

What is the purpose of this pull request?

This pull request:

  • Adds a dependency-free fallback polyfill for Object.prototype.propertyIsEnumerable in @stdlib/assert/is-enumerable-property using Object.keys when the built-in is unavailable or not a function, while retaining the module-scope cache in lib/native.js.
  • Updates @stdlib/assert/is-plain-object to test proto === objectPrototype (same-realm check) first, requiring an own isPrototypeOf method only on the cross-realm fallback branch.
  • Adds test suites for both packages verifying correct behavior when propertyIsEnumerable and isPrototypeOf are deleted from Object.prototype (and safely restored using Object.defineProperty).
  • Fixes loading failures for @stdlib/math/strided/ops/* and dependent assertion utilities on minimal JavaScript engines that omit these prototype methods (such as MicroQuickJS).

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Reference Packages

Did the content of this pull request follow one or more existing packages? Answering is optional.

This pull request followed these packages:

  • process/getuid

What carried over from the reference(s)?

  • Package structure separating native.js, polyfill.js, and main.js, as well as standard symbol-support test skip guards (hasSymbolSupport).

What differed, or what did you have to work out yourself?

  • The specific Object.keys-based polyfill for propertyIsEnumerable, documenting symbol omission notes, and the same-realm prototype reordering in is-plain-object.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

  • Tests restore prototype methods using Object.defineProperty (with enumerable: false) and explicitly assert that for ( k in {} ) produces zero enumerable keys.
  • All unit tests and repository ESLint rules pass cleanly.

Note: In run_affected_tests, tests in internal @stdlib/_tools packages (such as _tools/benchmarks/bundle and _tools/links/validate) fail due to pre-existing shell quoting issues in those internal scripts on Linux. All unit tests and linters for @stdlib/assert/is-enumerable-property, @stdlib/assert/is-plain-object, and public downstream packages pass 100%.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

This PR was developed with assistance from Gemini for research, code implementation, and test generation, followed by manual verification, test runs, and lint validation in GitHub Codespaces.


@stdlib-js/reviewers

@ItsAbir005
ItsAbir005 requested a review from a team November 24, 2026 17:01
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Nov 24, 2026
@stdlib-bot

stdlib-bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
assert/is-enumerable-property $\\color{red}363/365$
$\\color{green}+0.01\\%$
$\\color{red}29/30$
$\\color{green}+0.00\\%$
$\\color{green}3/3$
$\\color{green}+0.00\\%$
$\\color{red}363/365$
$\\color{green}+0.01\\%$
assert/is-plain-object $\\color{green}156/156$
$\\color{green}+0.00\\%$
$\\color{green}18/18$
$\\color{green}+0.00\\%$
$\\color{green}2/2$
$\\color{green}+0.00\\%$
$\\color{green}156/156$
$\\color{green}+0.00\\%$

The above coverage report was generated for the changes in this PR.

@ItsAbir005 ItsAbir005 changed the title Fix/missing object prototype methods fix: handle missing Object.prototype methods in @stdlib/assert Nov 24, 2026
@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. review: 2 and removed Needs Review A pull request which needs code review. labels Nov 25, 2026
@ItsAbir005
ItsAbir005 requested a review from kgryte November 25, 2026 12:43
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Nov 25, 2026
@batpigandme

Copy link
Copy Markdown
Member

For the record, I bundled this PR's head (16904b94) and ran it on MicroQuickJS (which is technically an ES5 subset): with both package changes, the math/strided/ops/* path from the issue now loads, and its output matches Node.js byte for byte. I also checked the new polyfill on lv5, an ES5.1 engine, where it gives the same answers as the built-in, including for primitive receivers.

Why the polyfill throwing on primitives in MicroQuickJS isn't a problem

On MicroQuickJS, the polyfill throws when given a primitive receiver (e.g., isEnumerableProperty( 'beep', '0' )). That comes from MicroQuickJS implementing a subset of ES5 without value boxing, not from anything ES5, stdlib's baseline, requires. In ES5, Object( value ) boxes primitives (§15.2.1.1, §9.9), and a String object's indices are enumerable while its length is not (§15.5.5.1–§15.5.5.2), so Object.keys( Object( value ) ) gives the same answers as the built-in, as it does on lv5. It does so without code generation, which stdlib avoids because of content security policies.

And on engines that implement ES5 in full, Object.prototype.propertyIsEnumerable exists (§15.2.4.7), so has_builtin.js is true and the polyfill isn't used at all. So no change is needed for this.

@ItsAbir005

Copy link
Copy Markdown
Contributor Author

For the record, I bundled this PR's head (16904b94) and ran it on MicroQuickJS (which is technically an ES5 subset): with both package changes, the math/strided/ops/* path from the issue now loads, and its output matches Node.js byte for byte. I also checked the new polyfill on lv5, an ES5.1 engine, where it gives the same answers as the built-in, including for primitive receivers.

Why the polyfill throwing on primitives in MicroQuickJS isn't a problem
On MicroQuickJS, the polyfill throws when given a primitive receiver (e.g., isEnumerableProperty( 'beep', '0' )). That comes from MicroQuickJS implementing a subset of ES5 without value boxing, not from anything ES5, stdlib's baseline, requires. In ES5, Object( value ) boxes primitives (§15.2.1.1, §9.9), and a String object's indices are enumerable while its length is not (§15.5.5.1–§15.5.5.2), so Object.keys( Object( value ) ) gives the same answers as the built-in, as it does on lv5. It does so without code generation, which stdlib avoids because of content security policies.

And on engines that implement ES5 in full, Object.prototype.propertyIsEnumerable exists (§15.2.4.7), so has_builtin.js is true and the polyfill isn't used at all. So no change is needed for this.

Thanks @batpigandme for verifying on MicroQuickJS and lv5! @kgryte All requested changes have been addressed (using standard barrel file architecture and proxyquire). Could you take another look when you have a moment?

@batpigandme batpigandme left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the updates! The barrel file and the proxyquire tests now follow string/base/trim closely. The line comments bring polyfill.js in line with how sibling packages handle the same things:

  • Requiring @stdlib/object/ctor and caching Object.keys, as other packages that can't depend on @stdlib/utils/keys do, rather than disabling two lint rules for the whole file.
  • String( property ) rather than '' + property.

With them applied, polyfill.js lints cleanly with no disable comments, and test.polyfill.js still passes.

@batpigandme

Copy link
Copy Markdown
Member

Changes look god, @ItsAbir005. We'll wait on @kgryte to approve and merge when he gets a chance. 👍

@ItsAbir005

Copy link
Copy Markdown
Contributor Author

Changes look god, @ItsAbir005. We'll wait on @kgryte to approve and merge when he gets a chance. 👍

Thanks @batpigandme for review & suggestions. Can you review #16920 I recently open fix doc typos

This branch has not been deployed

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

Labels

Needs Changes Pull request which needs changes before being merged. Needs Review A pull request which needs code review. review: 2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: loading fails without propertyIsEnumerable or isPrototypeOf

4 participants