Skip to content

Unexpected error "Cannot read private member #availableParallelism from an object whose class did not declare it" #63513

@ericcornelissen

Description

@ericcornelissen

Version

v26.0.0

Platform

Linux eric-cornelissen-Latitude-7640 6.17.0-29-generic #29~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon May 11 10:30:58 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

node:internal/navigator

What steps will reproduce the bug?

For the error mentioned in the title:

node -e 'globalThis.Navigator.prototype.hardwareConcurrency'

This applies to other getters of this object too, namely:

node -e 'globalThis.Navigator.prototype.locks'
node -e 'globalThis.Navigator.prototype.languages'
node -e 'globalThis.Navigator.prototype.userAgent'
node -e 'globalThis.Navigator.prototype.platform'

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

Not an internal error about the implementation of the Navigator.

Based on the behavior of browsers1, a TypeError is still expected, but instead something like:

Uncaught TypeError: 'get hardwareConcurrency' called on an object that does not implement interface Navigator.

What do you see instead?

For hardwareConcurrency:

node:internal/navigator:100
    this.#availableParallelism ??= getAvailableParallelism();
        ^

TypeError: Cannot read private member #availableParallelism from an object whose class did not declare it
    at get hardwareConcurrency (node:internal/navigator:100:9)
    at Reflect.get (<anonymous>)
    at [eval]:1:9
    at runScriptInThisContext (node:internal/vm:219:10)
    at node:internal/process/execution:483:12
    at [eval]-wrapper:6:24
    at runScriptInContext (node:internal/process/execution:481:60)
    at evalFunction (node:internal/process/execution:315:30)
    at evalTypeScript (node:internal/process/execution:327:3)
    at node:internal/main/eval_string:71:3

For the other properties a similar error about using a private member.

Additional information

  1. I tested the hardwareConcurrency property on older versions too and found the report applies to v24.15.0 and v22.0.0 too, in v20.20.2 the Navigate global did not yet exist.

  2. Interestingly the following property does not result in an error

    node -e 'console.log(globalThis.Navigator.prototype.language)'
    

    This might be a bug as well given that in browsers the only properties that can be accessed on this object are functions (whereas this is also a getter), which you can verify using:

    for (const key of Object.keys(Navigator.prototype)) { try { Navigator.prototype[key]; console.log("no error for", key, typeof Navigator.prototype[key]) } catch { } }

Footnotes

  1. I only tried Firefox.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions