Skip to content

repl: Enable tab completion for global properties when useGlobal is false - #7369

Closed
lance wants to merge 5 commits into
nodejs:masterfrom
lance:repl-useglobal-false-tab-completion
Closed

repl: Enable tab completion for global properties when useGlobal is false#7369
lance wants to merge 5 commits into
nodejs:masterfrom
lance:repl-useglobal-false-tab-completion

Conversation

@lance

Copy link
Copy Markdown
Member
Checklist
  • make -j4 test (UNIX) or vcbuild test nosign (Windows) passes
  • a test and/or benchmark is included
  • the commit message follows commit guidelines
Affected core subsystem(s)

repl

Description of change

When useGlobal is false, tab completion in the repl does not enumerate
global properties. Instead of just setting these properties blindly on
the global context, e.g.

context[prop] = global[prop]

Use Object.defineProperty and the property descriptor found on
global for the new property in context.

Also addresses a previously unnoticed issue where console is writable
when useGlobal is false.

Ref: #7353

@nodejs-github-botnodejs-github-bot added the repl Issues and PRs related to the REPL subsystem. label Jun 22, 2016
@Fishrock123

Copy link
Copy Markdown
Contributor

idea seems sound to me

Comment threadlib/repl.js Outdated

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.

What does global in the inner context refer to now? I think it should still be context, right?

(The second line here also seems to have been superfluous?)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Both lines should stay the same

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

@addaleax - yes, this was an oversight...

@princejwesley

Copy link
Copy Markdown
Contributor

@lance This solution has some side effects!

node 🙈git:(master)cat~/Desktop/test.jsletrepl=require('repl')repl.start({useGlobal: false})
node 🙈git:(master)./node!$./node~/Desktop/test.js>[]instanceofArrayfalse>/vm/instanceofRegExpfalse>

@lance

Copy link
Copy Markdown
MemberAuthor

@princejwesley hmm - this is strange. I will take a look at this.

@lance

Copy link
Copy Markdown
MemberAuthor

@princejwesley this issue should be addressed with my latest push.
@addaleax your comments are addressed as well.

Comment threadlib/repl.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lanceinstanceof test for this filtered list may fail!. e.g Int16Array. Can you confirm that? Adding those missing properties to GLOBAL_OBJECT_PROPERTIES will solve this issue.

@lancelanceJun 23, 2016

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I couldn't figure out the best way to test this programmatically, but the CLI behavior tests manually as expected.

~/s/node git:repl-useglobal-false-tab-completion ❯❯❯ ./node test-use-global-auto-complete.js
> const x = new Int16Array()
undefined
> x instanceof Int16Array
true
>

I think this is the case because there is no builtin shorthand for Int16Array and the like. For builtin objects that have a shorthand representation such as [] or /\w+/ that representation is an instanceofthe builtin language object no matter what. But there is no builtin shorthand for Int16Array.

@addaleax

Copy link
Copy Markdown
Member

nice work, LGTM with two questions

lance added 4 commits June 27, 2016 10:39
When `useGlobal` is false, tab completion in the repl does not enumerate
global properties. Instead of just setting these properties blindly on
the global context, e.g.
context[prop] = global[prop]
Use `Object.defineProperty` and the property descriptor found on
`global` for the new property in `context`.
Also addresses a previously unnoticed issue where `console` is writable
when `useGlobal` is false.
Ref: #7353
When `useGlobal` is false, all of the properties on `global` are copied
to the new context (excluding `console` and `global`). Since
`Object.getOwnPropertyNames()` returns all properties, not just
enumerable ones, builtin properties on `global` are returned. We need to
filter those out.
This existed in the original `repl.js` code, but it's not clear what the
purpose is. It appears to be redundant.
Comment threadlib/repl.js
const parentModule = module;
const replMap = new WeakMap();

const GLOBAL_OBJECT_PROPERTIES = ['NaN', 'Infinity', 'undefined',

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.

I really wish we had a better way of tracking these... ah well.

@jasnell

Copy link
Copy Markdown
Member

LGTM with a couple of nits

If the binary has been built with `./configure --without-intl` then the
`Intl` builtin type will not be available in a repl runtime. Check for
this in the test.
@lance

Copy link
Copy Markdown
MemberAuthor

CI: https://ci.nodejs.org/job/node-test-pull-request/3094/

@addaleax have I answered your questions well enough?
@jasnell nits addressed

@addaleax

Copy link
Copy Markdown
Member

CI is green & this still LGTM

@jasnell

Copy link
Copy Markdown
Member

LGTM

lance added a commit that referenced this pull request Jun 27, 2016
When `useGlobal` is false, tab completion in the repl does not enumerate
global properties. Instead of just setting these properties blindly on
the global context, e.g.
context[prop] = global[prop]
Use `Object.defineProperty` and the property descriptor found on
`global` for the new property in `context`.
Also addresses a previously unnoticed issue where `console` is writable
when `useGlobal` is false.
If the binary has been built with `./configure --without-intl` then the
`Intl` builtin type will not be available in a repl runtime. Check for
this in the test.
Fixes: #7353
PR-URL: #7369
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@lance

Copy link
Copy Markdown
MemberAuthor

Landed in: c0e48bf

@lancelance closed this Jun 27, 2016
Fishrock123 pushed a commit that referenced this pull request Jul 5, 2016
When `useGlobal` is false, tab completion in the repl does not enumerate
global properties. Instead of just setting these properties blindly on
the global context, e.g.
context[prop] = global[prop]
Use `Object.defineProperty` and the property descriptor found on
`global` for the new property in `context`.
Also addresses a previously unnoticed issue where `console` is writable
when `useGlobal` is false.
If the binary has been built with `./configure --without-intl` then the
`Intl` builtin type will not be available in a repl runtime. Check for
this in the test.
Fixes: #7353
PR-URL: #7369
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@Fishrock123Fishrock123 mentioned this pull request Jul 5, 2016
@MylesBorins

Copy link
Copy Markdown
Contributor

@lance@addaleax @nodejs/lts lts?

@addaleax

Copy link
Copy Markdown
Member

Yes, but I think I’d like to give it a bit more time in v6? @lance feel free to overrule me here. :)

@cjihrig

Copy link
Copy Markdown
Contributor

I agree, this should be in a couple v6 releases first.

@lance

Copy link
Copy Markdown
MemberAuthor

@addaleax@cjihrig wfm

MylesBorins pushed a commit that referenced this pull request Oct 10, 2016
When `useGlobal` is false, tab completion in the repl does not enumerate
global properties. Instead of just setting these properties blindly on
the global context, e.g.
context[prop] = global[prop]
Use `Object.defineProperty` and the property descriptor found on
`global` for the new property in `context`.
Also addresses a previously unnoticed issue where `console` is writable
when `useGlobal` is false.
If the binary has been built with `./configure --without-intl` then the
`Intl` builtin type will not be available in a repl runtime. Check for
this in the test.
Fixes: #7353
PR-URL: #7369
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MylesBorins pushed a commit that referenced this pull request Oct 10, 2016
When `useGlobal` is false, tab completion in the repl does not enumerate
global properties. Instead of just setting these properties blindly on
the global context, e.g.
context[prop] = global[prop]
Use `Object.defineProperty` and the property descriptor found on
`global` for the new property in `context`.
Also addresses a previously unnoticed issue where `console` is writable
when `useGlobal` is false.
If the binary has been built with `./configure --without-intl` then the
`Intl` builtin type will not be available in a repl runtime. Check for
this in the test.
Fixes: #7353
PR-URL: #7369
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
rvagg pushed a commit that referenced this pull request Oct 18, 2016
When `useGlobal` is false, tab completion in the repl does not enumerate
global properties. Instead of just setting these properties blindly on
the global context, e.g.
context[prop] = global[prop]
Use `Object.defineProperty` and the property descriptor found on
`global` for the new property in `context`.
Also addresses a previously unnoticed issue where `console` is writable
when `useGlobal` is false.
If the binary has been built with `./configure --without-intl` then the
`Intl` builtin type will not be available in a repl runtime. Check for
this in the test.
Fixes: #7353
PR-URL: #7369
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MylesBorins pushed a commit that referenced this pull request Oct 26, 2016
When `useGlobal` is false, tab completion in the repl does not enumerate
global properties. Instead of just setting these properties blindly on
the global context, e.g.
context[prop] = global[prop]
Use `Object.defineProperty` and the property descriptor found on
`global` for the new property in `context`.
Also addresses a previously unnoticed issue where `console` is writable
when `useGlobal` is false.
If the binary has been built with `./configure --without-intl` then the
`Intl` builtin type will not be available in a repl runtime. Check for
this in the test.
Fixes: #7353
PR-URL: #7369
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@MylesBorinsMylesBorins mentioned this pull request Oct 26, 2016
MylesBorins added a commit that referenced this pull request Oct 26, 2016
This LTS release comes with 219 commits. This includes 80 commits that
are docs related, 58 commits that are test related, 20 commits that
are build / tool related, and 9 commits that are updates to
dependencies.
Notable Changes
* build:
- It is now possible to build the documentation from the release
tarball (Anna Henningsen)
#8413
* buffer:
- Buffer will no longer incorrectly return a zero filled buffer when
an encoding is passed (Teddy Katz)
#9238
* deps:
- upgrade npm in LTS to 2.15.11 (Kat Marchán)
#8928
* repl:
- Enable tab completion for global properties (Lance Ball)
#7369
* url:
- `url.format()` will now encode all `#` in `search` (Ilkka Myller)
#8072
PR-URL: #9298
MylesBorins added a commit that referenced this pull request Oct 26, 2016
This LTS release comes with 219 commits. This includes 80 commits that
are docs related, 58 commits that are test related, 20 commits that
are build / tool related, and 9 commits that are updates to
dependencies.
Notable Changes
* build:
- It is now possible to build the documentation from the release
tarball (Anna Henningsen)
#8413
* buffer:
- Buffer.alloc() will no longer incorrectly return a zero filled
buffer when an encoding is passed (Teddy Katz)
#9238
* deps:
- upgrade npm in LTS to 2.15.11 (Kat Marchán)
#8928
* repl:
- Enable tab completion for global properties (Lance Ball)
#7369
* url:
- `url.format()` will now encode all `#` in `search` (Ilkka Myller)
#8072
PR-URL: #9298
MylesBorins added a commit that referenced this pull request Nov 7, 2016
This LTS release comes with 219 commits. This includes 80 commits that
are docs related, 58 commits that are test related, 20 commits that
are build / tool related, and 9 commits that are updates to
dependencies.
Notable Changes
* build:
- It is now possible to build the documentation from the release
tarball (Anna Henningsen)
#8413
* buffer:
- Buffer.alloc() will no longer incorrectly return a zero filled
buffer when an encoding is passed (Teddy Katz)
#9238
* deps:
- upgrade npm in LTS to 2.15.11 (Kat Marchán)
#8928
* repl:
- Enable tab completion for global properties (Lance Ball)
#7369
* url:
- `url.format()` will now encode all `#` in `search` (Ilkka Myller)
#8072
PR-URL: #9298
MylesBorins added a commit that referenced this pull request Nov 8, 2016
This LTS release comes with 219 commits. This includes 80 commits that
are docs related, 58 commits that are test related, 20 commits that
are build / tool related, and 9 commits that are updates to
dependencies.
Notable Changes
* build:
- It is now possible to build the documentation from the release
tarball (Anna Henningsen)
#8413
* buffer:
- Buffer.alloc() will no longer incorrectly return a zero filled
buffer when an encoding is passed (Teddy Katz)
#9238
* deps:
- upgrade npm in LTS to 2.15.11 (Kat Marchán)
#8928
* repl:
- Enable tab completion for global properties (Lance Ball)
#7369
* url:
- `url.format()` will now encode all `#` in `search` (Ilkka Myller)
#8072
PR-URL: #9298
imyller added a commit to imyller/meta-nodejs that referenced this pull request Nov 11, 2016
 This LTS release comes with 219 commits. This includes 80 commits that
are docs related, 58 commits that are test related, 20 commits that
are build / tool related, and 9 commits that are updates to
dependencies.
Notable Changes
* build:
- It is now possible to build the documentation from the release
tarball (Anna Henningsen)
nodejs/node#8413
* buffer:
- Buffer.alloc() will no longer incorrectly return a zero filled
buffer when an encoding is passed (Teddy Katz)
nodejs/node#9238
* deps:
- upgrade npm in LTS to 2.15.11 (Kat Marchan)
nodejs/node#8928
* repl:
- Enable tab completion for global properties (Lance Ball)
nodejs/node#7369
* url:
- `url.format()` will now encode all `#` in `search` (Ilkka Myller)
nodejs/node#8072
PR-URL: nodejs/node#9298
Signed-off-by: Ilkka Myller <ilkka.myller@nodefield.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

replIssues and PRs related to the REPL subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@lance@Fishrock123@princejwesley@addaleax@jasnell@MylesBorins@cjihrig@nodejs-github-bot