Skip to content

Object.getOwnPropertyDescriptor throws TypeError on process _handle #17636

Description

@erulabs
  • Version: v8.9.2, v8.9.3 and v9.3.0 (at least, suspect its all versions >=8.9.2)
  • Platform: All (tested OSX, Linux)
  • Subsystem: N/A

Hello!

Related to #16949 and #16860 - it appears that since Node 8 there have been some issues with Object.getOwnPropertyDescriptor.

The simplest test case is

Object.getOwnPropertyDescriptor(process.stdin._handle.__proto__, "bytesRead"))

Expected output: undefined (pre 8.9 behavior)
Pre 8.9.2, this crashes node with a Segmentation Fault (see linked issues)
On and after 8.9.2, this returns TypeError:

> Object.getOwnPropertyDescriptor(process.stdin._handle.__proto__, "bytesRead")
TypeError: Method bytesRead called on incompatible receiver #<TTY>
    at Function.getOwnPropertyDescriptor (<anonymous>)
    at repl:1:8
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:442:10)
    at emitOne (events.js:121:20)
    at REPLServer.emit (events.js:211:7)
    at REPLServer.Interface._onLine (readline.js:282:10)

This means that calling Object.getOwnPropertyDescripton on a process handle fails.

At least according to https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor - I don't see any specification for throwing a TypeError here (particularly since the Prototype is of course an Object, it even seems to violate the ES5 spec)

Can we return to returning undefined here?

After thinking about it, I believe returning a proper descriptor with a value of 0 would actually be preferable to undefined, since bytesRead is a getter which returns a Number. This is the case with, for example length:

> Object.getOwnPropertyDescriptor([].__proto__, 'length')
{ value: 0,
  writable: true,
  enumerable: false,
  configurable: false }

Thank you for your time!

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues asking questions about Node.js.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions