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

repl completion for large buffers fails to display named properties #21446

Closed
killagu opened this issue Jun 21, 2018 · 5 comments
Closed

repl completion for large buffers fails to display named properties #21446

killagu opened this issue Jun 21, 2018 · 5 comments
Labels
confirmed-bug Issues with confirmed bugs. repl Issues and PRs related to the REPL subsystem.

Comments

@killagu
Copy link
Contributor

killagu commented Jun 21, 2018

  • Version: v10.5.0
  • Platform: macOS
  • Subsystem:REPL

When alloc a large buffer, and input a. then press tab. It's a warning.

> a = Buffer.alloc(1024*1024)
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... >
> a.
(node:7432) REPLWarning: The current array, Buffer or TypedArray has too many entries. Certain properties may be missing from completion output.

But it works well, when alloc a small buffer.

> a = Buffer.alloc(1024)
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... >
> a.
a.__defineGetter__      a.__defineSetter__      a.__lookupGetter__      a.__lookupSetter__      a.__proto__             a.constructor           a.hasOwnProperty        a.isPrototypeOf         a.propertyIsEnumerable
a.toLocaleString        a.toString              a.valueOf               

a.buffer                a.byteLength            a.byteOffset            a.copyWithin            a.entries               a.every                 a.fill                  a.filter                a.find
a.findIndex             a.forEach               a.includes              a.indexOf               a.join                  a.keys                  a.lastIndexOf           a.length                a.map
a.reduce                a.reduceRight           a.reverse               a.set                   a.slice                 a.some                  a.sort                  a.subarray              a.values

a.BYTES_PER_ELEMENT     

a.asciiSlice            a.asciiWrite            a.base64Slice           a.base64Write           a.compare               a.copy                  a.equals                a.hexSlice              a.hexWrite
a.inspect               a.latin1Slice           a.latin1Write           a.offset                a.parent                a.readDoubleBE          a.readDoubleLE          a.readFloatBE           a.readFloatLE
a.readInt16BE           a.readInt16LE           a.readInt32BE           a.readInt32LE           a.readInt8              a.readIntBE             a.readIntLE             a.readUInt16BE          a.readUInt16LE
a.readUInt32BE          a.readUInt32LE          a.readUInt8             a.readUIntBE            a.readUIntLE            a.swap16                a.swap32                a.swap64                a.toJSON
a.ucs2Slice             a.ucs2Write             a.utf8Slice             a.utf8Write             a.write                 a.writeDoubleBE         a.writeDoubleLE         a.writeFloatBE          a.writeFloatLE
a.writeInt16BE          a.writeInt16LE          a.writeInt32BE          a.writeInt32LE          a.writeInt8             a.writeIntBE            a.writeIntLE            a.writeUInt16BE         a.writeUInt16LE
a.writeUInt32BE         a.writeUInt32LE         a.writeUInt8            a.writeUIntBE           a.writeUIntLE           
@ghost
Copy link

ghost commented Jun 21, 2018

The relevant part is

node/lib/repl.js

Lines 910 to 918 in 4dbfb09

function mayBeLargeObject(obj) {
if (Array.isArray(obj)) {
return obj.length > ARRAY_LENGTH_THRESHOLD ? ['length'] : null;
} else if (isTypedArray(obj)) {
return obj.length > ARRAY_LENGTH_THRESHOLD ? [] : null;
}
return null;
}

In order to list accessible properties, the REPL script has to obtain all properties of the given object. Without the above check, Node.js may crash due to out of memory error.

I don't think this is fixable.

@Fishrock123 Fishrock123 added confirmed-bug Issues with confirmed bugs. repl Issues and PRs related to the REPL subsystem. labels Jun 21, 2018
@Fishrock123
Copy link
Contributor

I think it might be fixable. We should lookup named properties first, which should be possible.

@Fishrock123 Fishrock123 changed the title repl bug repl completion for large buffers fails to display named properties Jun 21, 2018
@thatshailesh
Copy link
Contributor

Interesred in picking this up.. need some guidance

@nodejs nodejs deleted a comment Jun 22, 2018
@ghost
Copy link

ghost commented Jun 22, 2018

Re: @͏Fishrock123

I would be very happy to see how it can be fixed. In order to obtain named properties of an object, the repl script should call Object.getOwnPropertyNames on the given object. However, consider this example:

> var a = Buffer.alloc(2 ** 30)
undefined
> a.someProperty = 'someValue'
'someValue'
> a.
(node:1932) REPLWarning: The current array, Buffer or TypedArray has too many entries. Certain properties may be missing from completion output.

In order to enumerate someProperty as a property of the object a, either Object.getOwnPropertyNames or Object.keys should be called. But, both of them result in out of memory error:

> Object.keys(a)
RangeError: Invalid array length
    at Function.keys (<anonymous>)
> Object.getOwnPropertyNames(a)
FATAL ERROR: invalid table size Allocation failed - JavaScript heap out of memory

@bnoordhuis
Copy link
Member

We should lookup named properties first, which should be possible.

Not without changes to V8 first. There is currently no way to retrieve a bounded number of own properties.

We might be able to make do with a for/in loop and check each key with Object#hasOwnProperty().

BridgeAR added a commit to BridgeAR/node that referenced this issue Aug 20, 2018
Due to a new API it's possible to skip the indices. That allows to
use auto completion with big (typed) arrays.

Fixes: nodejs#21446
targos pushed a commit that referenced this issue Aug 24, 2018
Due to a new API it's possible to skip the indices. That allows to
use auto completion with big (typed) arrays.

PR-URL: #22408
Fixes: #21446
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
targos pushed a commit that referenced this issue Sep 3, 2018
Due to a new API it's possible to skip the indices. That allows to
use auto completion with big (typed) arrays.

PR-URL: #22408
Fixes: #21446
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants