0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 23:43:09 +01:00
Commit Graph

444 Commits

Author SHA1 Message Date
Sam Ruby
a2ec80851c repl: support mult-line string-keyed objects
isRecoverableError is completely reimplemented using acorn and an
acorn plugin that examines the state of the parser at the time of the
error to determine if the code could be completed on a subsequent line.

PR-URL: https://github.com/nodejs/node/pull/21805
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-08-03 20:20:00 -07:00
Sam Ruby
4d42083d1a
repl: make own properties shadow prototype properties
Previously, the code displayed properties backwards (e.g., showing
prototype properties before own properties).  It also did uniqueness
checks during this processing, so these checks were done backwards.

After this change, the properties continue to be displayed backwards,
but the uniqueness checks are done in the proper order.

See also: https://github.com/nodejs/node/issues/21586 which was
discovered during the testing of this fix.

Fixes: https://github.com/nodejs/node/issues/15199
PR-URL: https://github.com/nodejs/node/pull/21588
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-07-13 18:57:16 +02:00
Weijia Wang
4f15122847 repl: fix tab completion for object properties with special char
The old RegExp will pass property names like `"hello world!"`
when filtering the results of tab complete. This change is to
fix it.

Fixes: https://github.com/nodejs/node/issues/21201

PR-URL: https://github.com/nodejs/node/pull/21556
Fixes: https://github.com/nodejs/node/issues/21201
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
2018-07-02 23:04:04 +08:00
cjihrig
4dbfb096f0
Revert "repl: add friendly tips about how to exit repl"
This reverts commit 9aa4ec43fc.

This commit in question introduced a regression in repl.eval(),
as the context argument is no longer passed to runInContext().

PR-URL: https://github.com/nodejs/node/pull/20972
Fixes: https://github.com/nodejs/node/issues/20965
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
2018-05-28 13:53:26 -04:00
Ruben Bridgewater
f954aba39e
repl: make console, module and require non-enumerable
This aligns these globals with the regular context.

PR-URL: https://github.com/nodejs/node/pull/20717
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-05-19 17:55:55 +02:00
monkingxue
9aa4ec43fc
repl: add friendly tips about how to exit repl
Imitate python repl, when the user enters 'exit' or 'quit',
no longer prompt 'Reference Error', but
prompts 'To exit, press ^D or type .exit'.
If the user defines variables named 'exit' or 'quit' ,
only the value of the variables are output

PR-URL: https://github.com/nodejs/node/pull/20617
Fixes: https://github.com/nodejs/node/issues/19021
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-05-18 15:47:17 +02:00
Anna Henningsen
849aaaeeb0
Revert "util: change util.inspect depth default"
This reverts commit b994b8eff6.

This caused regressions in ecosystem code. While the change originally
was semver-major and could be postponed until after Node.js 10,
I think reverting it is a good choice at this point.

Also, I personally do not think defaulting to a shallow inspect
is a bad thing at all – quite the opposite: It makes `util.inspect()`
give an overview of an object, rather than providing a full
display of its contents. Changing the `depth` default to infinity
fundamentally changed the role that `util.inspect()` plays,
and makes output much more verbose and thus at times unusable
for `console.log()`-style debugging.

PR-URL: https://github.com/nodejs/node/pull/20017
Fixes: https://github.com/nodejs/node/issues/19405
Refs: https://github.com/nodejs/node/pull/17907
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-05-11 17:46:56 +02:00
cjihrig
17a4421b69
repl: add spaces to load/save messages
PR-URL: https://github.com/nodejs/node/pull/20536
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-05-05 13:39:11 +02:00
Timothy Gu
be92eab92a
repl: hide top-level await feature behind a flag
PR-URL: https://github.com/nodejs/node/pull/19604
Refs: https://github.com/nodejs/node/pull/17807
Refs: https://github.com/nodejs/node/pull/15566#issuecomment-353428430
Reviewed-By: Gus Caplan <me@gus.host>
2018-04-18 07:50:17 -07:00
Joyee Cheung
c2b01881dc
lib: restructure cjs and esm loaders
Create `lib/internal/modules` and restructure the module loaders
to make the purpose of those files clearer.

Also make it clear in the code that the object exported by
`lib/internal/modules/cjs/loader.js` is `CJSModule` instead of the
ambiguous `Module`.

Before:

```
lib
├── ...
├── internal
│       ├── loaders
│       │     ├── CreateDynamicModule.js
│       │     ├── DefaultResolve.js
│       │     ├── Loader.js
│       │     ├── ModuleJob.js
│       │     ├── ModuleMap.js
│       │     └── Translators.js
│       └── module.js
└── module.js
```

After:

```
lib
├── ...
├── internal
│       ├── ...
│       └── modules
│              ├── cjs
│              │     ├── helpers.js
│              │     └── loader.js
│              └── esm
│                    ├── CreateDynamicModule.js
│                    ├── DefaultResolve.js
│                    ├── Loader.js
│                    ├── ModuleJob.js
│                    ├── ModuleMap.js
│                    └── Translators.js
└── module.js # deleted in this commit to work with git file mode
```

PR-URL: https://github.com/nodejs/node/pull/19177
Refs: https://github.com/nodejs/node/pull/19112
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2018-03-15 20:50:35 +08:00
Prince J Wesley
ebfa8b1464
repl: better handling of recoverable errors
Below syntax errors are handled without force .break/clear
  - Unexpected Token (prefix errors)
  - missing ) after argument list

In the multiline expression, recoverable errors are truly
recoverable, otherwise syntax error will be thrown.

PR-URL: https://github.com/nodejs/node/pull/18915
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-03-11 03:28:18 +01:00
Ruben Bridgewater
4893f70d12
repl: remove magic mode
The magic mode is long deprecated and works the same as the sloppy
mode. Since the sloppy mode is the default, removing the magic mode
should be safe.

PR-URL: https://github.com/nodejs/node/pull/19187
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
2018-03-11 02:43:27 +01:00
Michaël Zasso
1e8d110e64 lib: port errors to new system
This is a first batch of updates that touches non-underscored modules in
lib.

PR-URL: https://github.com/nodejs/node/pull/19034
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-03-05 19:51:30 +01:00
Anna Henningsen
a8b5192fef
repl: make last error available as _error
This is pretty useful when trying to inspect the last
error caught by a REPL, and is made to be analogous to `_`,
which contains the last successful completion value.

PR-URL: https://github.com/nodejs/node/pull/18919
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
2018-03-04 22:01:57 +00:00
killagu
26231548ad
repl: fix tab-complete warning
When create a nest repl, will register `Runtime.executionContextCreated`
listener to the inspector session.This patch will fix listener
repeatedly register.

PR-URL: https://github.com/nodejs/node/pull/18881
Fixes: https://github.com/nodejs/node/issues/18284
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-02-22 15:07:05 +00:00
Ruben Bridgewater
96c57fbfaa
lib: switch to Number.isNaN
Number.isNaN is now as fast as `val !== val`. Switch to the more
readable version. Also switch all `isNaN` to `Number.isNaN`.

PR-URL: https://github.com/nodejs/node/pull/18744
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-02-16 18:09:56 +01:00
Ruben Bridgewater
1fc373bdf6
Revert "repl: refactor tests to not rely on timing"
This reverts commit de848ac1e0.

The commit broke multiline repl.

PR-URL: https://github.com/nodejs/node/pull/18715
Refs: https://github.com/nodejs/node/pull/17828
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-02-12 15:42:06 +01:00
Bradley Farias
de848ac1e0
repl: refactor tests to not rely on timing
Tests relying on synchronous timing have been migrated to use events.

PR-URL: https://github.com/nodejs/node/pull/17828
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2018-02-10 14:19:54 +01:00
Ruben Bridgewater
b994b8eff6
util: change util.inspect depth default
The current default is not ideal in most use cases. Therefore it is
changed to showing unlimited depth in case util.inspect is called
directly. The default is kept as before for console.log and similar.

Using console.dir will now show a depth of up to five and
console.assert / console.trace will show a unlimited depth.

PR-URL: https://github.com/nodejs/node/pull/17907
Refs: https://github.com/nodejs/node/issues/12693
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2018-01-16 15:34:03 +01:00
Ruben Bridgewater
11dda69a33
repl: refactor code for readability
PR-URL: https://github.com/nodejs/node/pull/17919
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Lance Ball <lball@redhat.com>
2018-01-04 21:21:22 +01:00
Ruben Bridgewater
80988f9322
repl: upper case comments first char
PR-URL: https://github.com/nodejs/node/pull/17919
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Lance Ball <lball@redhat.com>
2018-01-04 21:21:21 +01:00
kysnm
ab5a2aba38 repl: migrate errors to internal/errors
PR-URL: https://github.com/nodejs/node/pull/17716
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2017-12-22 13:27:25 -05:00
Michaël Zasso
416c0ec952 repl: show lexically scoped vars in tab completion
Use the V8 inspector protocol, if available, to query the list of
lexically scoped variables (defined with `let`, `const` or `class`).

PR-URL: https://github.com/nodejs/node/pull/16591
Fixes: https://github.com/nodejs/node/issues/983
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2017-12-21 14:47:29 +01:00
Ben Noordhuis
727339e9c2
repl: fix util.inspect() coloring regression
The `Object.assign()` calls introduced in commit 90a4390 ("repl: show
proxies as Proxy objects") mutated their first argument, causing the
`{ colors: true }` option from the REPL to leak over into the global
`util.inspect.defaultOptions` object.

Refs: https://github.com/nodejs/node/pull/16485#issuecomment-350428638

PR-URL: https://github.com/nodejs/node/pull/17565
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-12-12 12:49:32 -02:00
Timothy Gu
eeab7bc068
repl: support top-level await
Much of the AST visitor code was ported from Chrome DevTools code
written by Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>.

PR-URL: https://github.com/nodejs/node/pull/15566
Fixes: https://github.com/nodejs/node/issues/13209
Refs: e8111c396f
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-11-16 15:42:46 -08:00
Timothy Gu
ab64b6d799
repl: add async and await as keywords
PR-URL: https://github.com/nodejs/node/pull/15566
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-11-16 15:42:05 -08:00
Timothy Gu
cff6e69057
repl: add an internal "paused" mode
PR-URL: https://github.com/nodejs/node/pull/15566
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-11-16 15:42:03 -08:00
Weijia Wang
e22b8d0c46 lib: improve the usage of TypeError[INVALID_ARG_TYPE]
The initials of expected in TypeError[ERR_INVALID_ARG_TYPE]
are inconsistent. This change is to unify them.

PR-URL: https://github.com/nodejs/node/pull/16401
Fixes: https://github.com/nodejs/node/issues/16383
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2017-11-12 11:04:06 -08:00
Ben Noordhuis
90a43906ab repl: show proxies as Proxy objects
Before this commit they transparently invoked their magic methods but
that sometimes throws confusing exceptions with misbehaving proxies.

This change is not wholly uncontroversial but we can always change the
default if necessary.  Let's see how it goes.

Fixes: https://github.com/nodejs/node/issues/16483
PR-URL: https://github.com/nodejs/node/pull/16485
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-11-07 19:51:51 +01:00
James M Snell
3d20190a3a src: remove throws in set/getHiddenValue
These are internal only utility functions, CHECK instead of throw

PR-URL: https://github.com/nodejs/node/pull/16544
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2017-11-02 07:24:49 -07:00
James M Snell
67c8511ea1 src: use internal/errors for startSigintWatchdog
Move the throw out of c++ and into js using internal/errors

PR-URL: https://github.com/nodejs/node/pull/16546
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-11-01 21:42:15 -07:00
cPhost
bb59d2bd19
repl: avoid crashing from null and undefined errors
When `throw undefined` or `throw null` is executed, the REPL crashes.
This change does a check for `null|undefined` before accessing an
error's properties to prevent crashing.

Fixes: https://github.com/nodejs/node/issues/16545
Fixes: https://github.com/nodejs/node/issues/16607

PR-URL: https://github.com/nodejs/node/pull/16574
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Lance Ball <lball@redhat.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2017-10-31 14:37:37 -04:00
Lance Ball
7a29f44071
repl: deprecate REPLServer.prototype.memory
This method is only useful for the internal mechanics of the REPLServer
and does not need to be exposed in user space. It was previously not
documented, so I believe a Runtime deprecation makes sense.

PR-URL: https://github.com/nodejs/node/pull/16242
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Jeremiah Senkpiel <fishrock123@rocketmail.com>
2017-10-19 14:58:26 -04:00
Weijia Wang
212de3c5ec
lib: use destructuring for some constants
This change is to unify the declaration for constants into using
destructuring on the top-level-module scope, reducing some redundant
code.

PR-URL: https://github.com/nodejs/node/pull/16063
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2017-10-16 23:34:32 +02:00
Jon Moss
0229e6746c repl: remove unused err argument
Not used by any callers in `lib/repl.js`, and is not public API.

PR-URL: https://github.com/nodejs/node/pull/16152
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-10-12 21:23:28 +08:00
Lance Ball
c5f54b1fad
repl: remove internal frames from runtime errors
When a user executes code in the REPLServer which generates an
exception, there is no need to display the REPLServer internal
stack frames.

PR-URL: https://github.com/nodejs/node/pull/15351
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>

Refs: https://github.com/nodejs/node/pull/9601
2017-10-11 14:51:41 -04:00
Timothy Gu
7907534a8d
lib: faster type checks for some types
PR-URL: https://github.com/nodejs/node/pull/15663
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-10-01 23:58:59 -03:00
Ruben Bridgewater
da40050b59
repl: fix deprecation code
This slipped through while landing.

PR-URL: https://github.com/nodejs/node/pull/15668
Refs: https://github.com/nodejs/node/pull/15136
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
2017-10-01 20:39:02 -03:00
Lance Ball
e416b3ee36
repl: deprecate turnOffEditorMode
This deprecates the current REPLServer.prototype.turnOffEditorMode
and adds a private function for turnOffEditorMode which handles the
necessary internal changes required instead of having them scattered
about.

PR-URL: https://github.com/nodejs/node/pull/15136
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-09-28 01:54:03 -03:00
Lance Ball
4bd44c11a5
repl: force editorMode in .load
The `.load` command would fail with any file that contains
multiline `.` operator expressions. This was particularly
noticeable when chaining promises or multi-line arrow
expressions.

This change Forces the REPL to be in `editorMode` while loading
a file from disk using the `.load` command.

Fixes: https://github.com/nodejs/node/issues/14022

PR-URL: https://github.com/nodejs/node/pull/14861
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-09-01 10:33:15 -04:00
Lance Ball
ed1ba4580b
repl: remove REPLServer.createContext side effects
The internal method `REPLServer.createContext()` had
unexpected side effects. When called, the value for the
`underscoreAssigned` and `lines` properties were reset.

This change ensures that those properties are not modified
when a context is created.

Fixes: https://github.com/nodejs/node/issues/14226
Refs: https://github.com/nodejs/node/issues/7619

PR-URL: https://github.com/nodejs/node/pull/14331
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2017-08-30 16:22:16 -04:00
Teddy Katz
b646a3df29
repl: include folder extensions in autocomplete
When autocompleting `require` calls, the repl strips .js file extensions
from results. However, stripping an extension from a directory results
in an error. Update the autocompletion logic to avoid stripping
extensions from directories.

PR-URL: https://github.com/nodejs/node/pull/14727
Fixes: https://github.com/nodejs/node/issues/14726
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
2017-08-13 01:03:30 -07:00
Lance Ball
766506a2e9
repl: deprecate REPLServer.parseREPLKeyword
This method does not need to be visible to user code. It has been
undocumented since it was introduced which was perhaps v0.8.9.

The motivation for this change is that the method is simply an
implementation detail of the REPLServer behavior, and does
not need to be exposed to user code.

This change adds documentation of the method with a deprecation
warning, and a test that the method is actually documented.

PR-RUL: https://github.com/nodejs/node/pull/14223
Refs: https://github.com/nodejs/node/issues/7619
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-08-02 14:39:06 -04:00
Lance Ball
2ca9f94e33
repl: make REPLServer.bufferedCommand private
The `REPLServer.bufferedCommand` property was undocumented, except
for its usage appearing, unexplained, in an example for
`REPLServer.defineCommand`. This commit deprecates that property,
privatizes it, and adds a `REPLServer.clearBufferedCommand()`
function that will clear the buffer.

PR-URL: https://github.com/nodejs/node/pull/13687
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <mhdawson@ibm.com>
Reviewed-By: Ruben Bridgewater <ruben.bridgewater@fintura.de>

Refs: https://github.com/nodejs/node/issues/12686
2017-08-01 22:45:28 +02:00
Shivanth MP
46d3ff2af9
repl: do not consider ... as a REPL command
This fix makes ... in REPL to be considered as a javascript construct
rather than a REPL keyword.

Fixes: https://github.com/nodejs/node/issues/14426
PR-URL: https://github.com/nodejs/node/pull/14467
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2017-07-29 10:35:01 +02:00
Rich Trott
8cccdd96f5 lib: adjust indentation for impending lint change
ESLint 4.x provides stricter indentation linting than previous versions.
In preparation for enabling the stricter indentation linting, adjust the
indentation of four lines in lib/net.js and lib/repl.js.

PR-URL: https://github.com/nodejs/node/pull/14403
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
2017-07-24 13:55:44 -07:00
Alexey Orlenko
45b730ec42
repl: improve require() autocompletion
Currently REPL supports autocompletion for core modules and those found
in node_modules.  This commit adds tab completion for modules relative
to the current directory.

PR-URL: https://github.com/nodejs/node/pull/14409
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-24 17:10:43 +03:00
Sebastiaan Deckers
bb29405904
lib,src: fix consistent spacing inside braces
PR-URL: https://github.com/nodejs/node/pull/14162
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-07-21 15:13:47 -04:00
Vse Mozhet Byt
4f87522244 doc, lib, test: do not re-require needlessly
PR-URL: https://github.com/nodejs/node/pull/14244
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
2017-07-21 20:40:52 +03:00
Benjamin Gruenbaum
030a0285d8 repl: don't terminate on null thrown
Previous behavior was to assume an error is a proper error in the
repl module. A check was added to not terminate the process on thrown
repl errors that are `null` or `undefined`.

PR-URL: https://github.com/nodejs/node/pull/14306
Fixes: https://github.com/nodejs/node/issues/12373
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com
2017-07-19 12:20:09 +03:00
XadillaX
7d7ccf0631
repl: fix crash with large buffer tab completion
If the buffer or array is too large to completion, make a dummy smallest
substitute object for it and emit a warning.

PR-URL: https://github.com/nodejs/node/pull/13817
Fixes: https://github.com/nodejs/node/issues/3136
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
2017-07-07 13:03:44 +08:00
Vse Mozhet Byt
5100cc6851 tools: use no-use-before-define ESLint rule
Also fix repl and url libs for the rule.

PR-URL: https://github.com/nodejs/node/pull/14032
Refs: http://eslint.org/docs/rules/no-use-before-define
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
2017-07-04 20:23:53 +03:00
Ruben Bridgewater
c474f88987
lib: fix typos
PR-URL: https://github.com/nodejs/node/pull/13741
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2017-06-19 18:18:56 +02:00
Vse Mozhet Byt
878990498a readline,repl,url,util: remove needless capturing
Use non-capturing grouping or remove capturing completely when:

* capturing is useless per se, e.g. in test() check;
* captured groups are not used afterwards at all;
* some of the later captured groups are not used afterwards.

PR-URL: https://github.com/nodejs/node/pull/13718
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-06-19 18:07:52 +03:00
Dan Homola
aff8d358fa errors, repl: migrate to use internal/errors.js
* Use existing errors where suitable
* Assign code to a REPL specific error
* Include documentation for the new error code

PR-URL: https://github.com/nodejs/node/pull/11347
Ref: https://github.com/nodejs/node/issues/11273
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-06-14 23:05:25 +02:00
Vse Mozhet Byt
390fa0380e cluster, dns, repl, tls, util: fix RegExp nits
* Take RegExp creation out of cycles.
* Use test(), not match() in boolean context.
* Remove redundant RegExp parts.

PR-URL: https://github.com/nodejs/node/pull/13536
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-06-10 13:37:04 +03:00
Nikolai Vavilov
3d9e7bb1d4 repl: remove unused function convertToContext
PR-URL: https://github.com/nodejs/node/pull/13434
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-06-05 13:30:05 +03:00
Marcel Laverdet
3c5bfba28b
vm: fix displayErrors in runIn.. functions
This option has been broken for almost a year when used with any of the
vm.runIn.. family of functions, except for syntax errors.

PR-URL: https://github.com/nodejs/node/pull/13074
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-05-23 20:59:24 +02:00
Brian White
b45abfda5f
repl: fix permanent deoptimizations
PR-URL: https://github.com/nodejs/node/pull/12456
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-04-30 03:18:01 -04:00
James M Snell
ae9e640f30 repl: avoid using forEach
PR-URL: https://github.com/nodejs/node/pull/11582
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-03-17 11:09:40 -07:00
Jan Krems
c7b60165a6 repl: Empty command should be sent to eval function
This fixes a regression introduced in https://github.com/nodejs/node/pull/6171

PR-URL: https://github.com/nodejs/node/pull/11871
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-03-17 08:58:22 -07:00
Blake Embrey
39d9afe279 repl: refactor LineParser implementation
Move the core logic from `LineParser` should fail handling into the
recoverable error check for the REPL default eval.

PR-URL: https://github.com/nodejs/node/pull/6171
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2017-03-14 15:04:50 -07:00
Brian White
c67207731f
lib: simplify Module._resolveLookupPaths
This commit consists of two changes:

* Avoids returning request/id *just* for the debug() output
* Returns `null` instead of an empty array for the list of paths

PR-URL: https://github.com/nodejs/node/pull/10789
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2017-03-10 23:48:59 -05:00
Brian White
28dc848e70
lib: improve method of function calling
Using a more "direct" method of function calling yields better
performance.

PR-URL: https://github.com/nodejs/node/pull/10789
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2017-03-10 23:48:46 -05:00
James M Snell
98e54b0bd4 meta: restore original copyright header
A prior io.js era commit inappropriately removed the
original copyright statements from the source. This
restores those in any files still remaining from that
edit.

Ref: https://github.com/nodejs/TSC/issues/174
Ref: https://github.com/nodejs/node/pull/10599
PR-URL: https://github.com/nodejs/node/pull/10155

Note: This PR was required, reviewed-by and approved
by the Node.js Foundation Legal Committee and the TSC.
There is no `Approved-By:` meta data.
2017-03-10 11:23:48 -08:00
Timothy Gu
3f27f02da0 repl: docs-only deprecation of magic mode
The workaround used in repl to support `let` and `const` in non-strict
mode (known as "magic" mode) has been unnecessary since V8 v4.9 /
Node.js v6.0.0. This commit doc-deprecate magic mode (which is now
entirely equivalent to sloppy mode) in both `repl` module and in
`internal/repl`, which is responsible for starting the REPL in `node`
interactive mode.

PR-URL: https://github.com/nodejs/node/pull/11599
Refs: https://v8project.blogspot.com/2016/01/v8-release-49.html
Refs: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V6.md#6.0.0
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
2017-03-06 19:23:34 -08:00
Timothy Gu
b77c89022b repl: remove magic mode semantics
The workaround used in repl to support `let` and `const` in non-strict
mode (known as "magic" mode) has been unnecessary since V8 v4.9 /
Node.js v6.0.0. This commit functionally removes this workaround.

PR-URL: https://github.com/nodejs/node/pull/11599
Refs: https://v8project.blogspot.com/2016/01/v8-release-49.html
Refs: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V6.md#6.0.0
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
2017-03-06 19:22:23 -08:00
Michaël Zasso
193468667b tools: enable one-var-declaration-per-line ESLint rule
This rule enforces new lines around variable declarations. It is
configured to spot only variables that are initialized.

PR-URL: https://github.com/nodejs/node/pull/11462
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-02-21 12:53:19 +01:00
Ben Noordhuis
fd8587eb38 lib: replace \u2019 with regular ascii quote
The previous commit stores baked-in files with non-ASCII characters
as UTF-16.  Replace the \u2019 with a regular quote character so that
the files they're in can be stored as one-byte strings.  The UTF-16
functionality is still tested by the Unicode diagram in lib/timers.js.

PR-URL: https://github.com/nodejs/node/pull/11129
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-02-13 19:16:47 +01:00
James M Snell
5de3cf099c lib: add static identifier codes for all deprecations
Assigns a static identifier code to all runtime and documentation
only deprecations. The identifier code is included in the emitted
DeprecationWarning.

Also adds a deprecations.md to the API docs to provide a central
location where deprecation codes can be referenced and explained.

PR-URL: https://github.com/nodejs/node/pull/10116
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2017-01-30 11:11:57 -08:00
Michaël Zasso
007386ee81 repl: remove workaround for function redefinition
The issue is fixed upstream in V8. Thus we do not need this workaround
in REPL.

Fixes: https://github.com/nodejs/node/issues/548
PR-URL: https://github.com/nodejs/node/pull/9618
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-01-26 22:46:18 +01:00
Rich Trott
338d09d25b test,repl: add coverage for repl .clear+useGlobal
Add a test to cover situation where REPL is initialized with `useGlobal`
set to `true` and `.clear` is called. This adds coverage for code in
repl.js that is not currently covered.

Includes minor refactor of rocket functions in repl.js for concision.

PR-URL: https://github.com/nodejs/node/pull/10777
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-01-15 18:33:50 -08:00
Rich Trott
a68987c154 benchmark,lib,test: adjust for linting
Formatting changes for upcoming linter update.

PR-URL: https://github.com/nodejs/node/pull/10561
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
2017-01-06 14:36:01 -08:00
Evan Lucas
e248f7f9e7 repl: allow autocompletion for scoped packages
Previously, autocompletion of scoped packages was not supported by the
repl due to not including the `@` character in the regular expression.

PR-URL: https://github.com/nodejs/node/pull/10296
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-12-22 22:03:39 -08:00
Michaël Zasso
966e5cfb81 tools: enforce linebreak after ternary operators
This is to be consistent with the other operators and helps
understanding the context when the code is grepped.

PR-URL: https://github.com/nodejs/node/pull/10213
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-12-22 20:27:59 -08:00
Teddy Katz
9d493d0064
repl: avoid parsing division operator as regex
This improves the heuristic used in multiline-prompt mode to determine
whether a given slash character is at the beginning of a regular
expression.

PR-URL: https://github.com/nodejs/node/pull/10103
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: James M Snell <jasnell@keybase.io>
Fixes: https://github.com/nodejs/node/issues/9300
2016-12-06 02:26:24 -05:00
Prince J Wesley
9366b8d90a
repl: preprocess only for defaultEval
Code preprocessing is applicable only for default
eval function. Therefore, Moved `preprocess` function
invocation inside `defaultEval` function.

Fixes: https://github.com/nodejs/node/issues/9743
PR-URL: https://github.com/nodejs/node/pull/9752
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-12-05 19:30:56 +05:30
Teddy Katz
24a98dd810
repl: fix generator function preprocessing
Function declarations in the REPL are preprocessed into variable
declarations before being evaluated. However, the preprocessing logic
did not account for the star in a generator function declaration, which
caused the preprocessor to output invalid syntax in some circumstances.

PR-URL: https://github.com/nodejs/node/pull/9852
Fixes: https://github.com/nodejs/node/issues/9850
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2016-12-02 03:15:39 -05:00
Anna Henningsen
2e2887579f
Revert "repl: disable Ctrl+C support on win32 for now"
This reverts commit f59b8888f1
now that the libuv update containing the proper fix has
landed in 63243bcb33.

Ref: https://github.com/libuv/libuv/pull/1054
Ref: https://github.com/nodejs/node/issues/7837
PR-URL: https://github.com/nodejs/node/pull/8645
Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-11-16 19:37:05 +01:00
Rich Trott
5cbb7a887a repl: refactor lib/repl.js
* remove unnecessary backslash (`\`) escaping in regular expressions
* favor `===` over `==`
* multiline arrays indentation consistent with other indentation

PR-URL: https://github.com/nodejs/node/pull/9374
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-11-03 13:20:15 -07:00
Pedro Victor
e658f5b066
repl: name anonymous functions
the changes are related to https://github.com/nodejs/node/issues/8913
regarding the naming of just the inline anonymous
functions that are not assigned to a variable

PR-URL: https://github.com/nodejs/node/pull/9356
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-11-01 23:43:02 +01:00
Anna Henningsen
3dfc12793f
repl: don’t write to input stream in editor mode
Instead of writing to the REPL’s input stream for the alignment
spaces in `.editor` mode, let `readline` handle the spaces
properly (echoing them using `_ttyWrite` and adding them to the
current line buffer).

Fixes: https://github.com/nodejs/node/issues/9189
PR-URL: https://github.com/nodejs/node/pull/9207
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-10-26 21:41:52 +02:00
Anna Henningsen
8b6fd4386a
repl: make key of repl.write() optional always
In `.editor` mode, `repl.write()` would have crashed when the
`key` argument was not present, because the overwritten
`_ttyWrite` of REPLs doesn’t check for the absence of a second
argument like `readline.write()` does.

Since the docs indicate that the argument is optional, add
a check paralleling the one in `readline.write()`.

PR-URL: https://github.com/nodejs/node/pull/9207
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-10-26 21:41:52 +02:00
Rich Trott
68ba9aa0fb test,lib,benchmark: match function names
In most cases, named functions match the variable or property to which
they are being assigned. That also seems to be the practice in a series
of PRs currently being evaluated that name currently-anonymous
functions.

This change applies that rule to instances in the code base that don't
comply with that practice.

This will be enforceable with a lint rule once we upgrade to ESLint
3.8.0.

PR-URL: https://github.com/nodejs/node/pull/9113
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2016-10-19 22:20:27 -07:00
Myles Borins
2e568d95bd lib: remove let from for loops
This is a known de-opt. It may not be 100% necessary in all cases but it
seems like a decent enough idea to avoid it.

PR-URL: https://github.com/nodejs/node/pull/8873
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2016-10-04 12:17:32 -04:00
Rich Trott
4316f4df31 test,lib: align arguments in multiline calls
An upcoming custom lint rule will provide slightly more strict
enforcement of argument alignment for multiline function calls. Adjust
existing code to conform.

PR-URL: https://github.com/nodejs/node/pull/8642
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2016-09-20 10:22:23 -07:00
Roman Reiss
39fbb5adf5
repl: improve .help message
- Added dots to printed commands.
- Use spaces instead of tabs so there's no misalignment on terminals
  with a tab size other than 4.
- Improved the help text for .editor and .help.
- Automatically indent command help based on the longest command.

PR-URL: https://github.com/nodejs/node/pull/8519
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
2016-09-16 16:53:03 +02:00
Prince J Wesley
5bef38b627
repl: Auto alignment for .editor mode
When in `.editor` mode, current line whitespace prefixes
are preserved in the subsequent line. User can hit backspace
to clean the whitespace

```js
node 🙈 ₹ node
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
function test() {
  console.log('tested!'); //On enter, cursor will be after 2 spaces
  _
```

PR-URL: https://github.com/nodejs/node/pull/8241
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-27 16:53:59 +05:30
Prince J Wesley
f6a74345d1
repl: Failed to save editor mode text in .save
Fixes: https://github.com/nodejs/node/issues/8142
PR-URL: https://github.com/nodejs/node/pull/8145
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-08-21 02:15:28 +05:30
Evan Lucas
76007079ec Revert "repl,util: insert carriage returns in output"
This reverts commit fce4b981ea.

This was a breaking change and should have been marked semver-major.
The change that was made altered the output of util.format() and
util.inspect(). With how much those are used in the wild, this type of
change deserves more justification.

Fixes: https://github.com/nodejs/node/issues/8138
PR-URL: https://github.com/nodejs/node/pull/8143
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-19 11:48:52 -05:00
JungMinu
fce4b981ea repl,util: insert carriage returns in output
`\n` is not enough for Linux with some custom stream
add carriage returns to ensure that the output is displayed correctly
using `\r\n` should not be a problem, even on non-Windows platforms.

Fixes: https://github.com/nodejs/node/issues/7954
PR-URL: https://github.com/nodejs/node/pull/8028
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-08-13 23:03:30 +09:00
Anna Henningsen
f59b8888f1 repl: disable Ctrl+C support on win32 for now
Disable Windows support for interrupting REPL commands using
Ctrl+C by default, because the switches from console raw mode
and back have been interfering with printing the results of
evaluated expressions.

This is a temporary measure, since the underlying problem is
very likely not related to this specific feature.

Ref: https://github.com/nodejs/node/issues/7837

PR-URL: https://github.com/nodejs/node/pull/7977
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: João Reis <reis@janeasystems.com>
2016-08-08 09:43:32 -07:00
Prince J Wesley
b779eb423d
repl: Add editor mode support
```js
> node
> .editor
// Entering editor mode (^D to finish, ^C to cancel)
function test() {
  console.log('tested!');
}

test();

// ^D
tested!
undefined
>
```

PR-URL: https://github.com/nodejs/node/pull/7275
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-08-06 19:41:35 +05:30
Prince J Wesley
488d28d391 repl: deprecate unused function convertToContext
PR-URL: https://github.com/nodejs/node/pull/7829
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-04 12:59:50 -07:00
Prince J Wesley
68ac0d0d7d
repl: Use displayErrors for SyntaxError
```js
node 🙈 ₹ git:(upstream  display-error-repl) ./node
> var 4;
var 4;
    ^
SyntaxError: Unexpected number

>
```

PR-URL: https://github.com/nodejs/node/pull/7589
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
2016-07-27 21:26:06 +05:30
Evan Lucas
392c70a827 repl: prevent undefined ref in completion
Fixes: https://github.com/nodejs/node/issues/7716
PR-URL: https://github.com/nodejs/node/pull/7718
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-07-26 09:14:43 -05:00
Prince J Wesley
bb9eabec40 repl: Mitigate vm #548 function redefinition issue
```js
node 🙈 ₹ git:(upstream  repl-tmp-548) ./node
> function name() { return "node"; };
undefined
> name()
'node'
> function name() { return "nodejs"; };
undefined
> name()
'nodejs'
>
```

Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Lance Ball <lball@redhat.com>
2016-07-15 13:44:34 -04:00
Diosney Sarmiento
9fbe456db1 repl: add support for custom completions
Allow user code to override the default `complete()` function from
`readline.Interface`. See:
https://nodejs.org/api/readline.html#readline_use_of_the_completer_function

Ref: https://github.com/nodejs/node-v0.x-archive/pull/8484

PR-URL: https://github.com/nodejs/node/pull/7527
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Lance Ball <lball@redhat.com>
2016-07-08 16:47:05 -04:00
Ali Ijaz Sheikh
a33909e107
repl: fix repl after V8 upgrade
V8 improved the error message for illegal token in
https://github.com/v8/v8/commit/879b617b. This breaks the recoverable
error handling in repl.

Ref: https://github.com/nodejs/node/pull/6482

PR-URL: https://github.com/nodejs/node/pull/7016
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
2016-06-29 10:43:07 +02:00
Lance Ball
c0e48bf27d repl: Enable tab completion for global properties
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: https://github.com/nodejs/node/issues/7353
PR-URL: https://github.com/nodejs/node/pull/7369
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-06-27 16:55:53 -04:00
Prince J Wesley
9d56c4079a repl: fix tab completion for defined commands
PR-URL: https://github.com/nodejs/node/pull/7364
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-06-27 14:26:03 +02:00
Evan Lucas
3f5623dd46 readline: allow passing prompt to constructor
Previously, one would have to call setPrompt after calling
rl.createInterface. Now, the prompt string can be set by passing the
prompt property.

PR-URL: https://github.com/nodejs/node/pull/7125
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-06-25 12:10:28 -05:00
Anna Henningsen
6a93ab11a9
repl: break on sigint/ctrl+c
Adds the ability to stop execution of the current REPL command
when receiving SIGINT. This applies only to the default eval
function.

Fixes: https://github.com/nodejs/node/issues/6612
PR-URL: https://github.com/nodejs/node/pull/6635
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-06-18 20:44:25 +02:00
Rich Trott
de0aa23ad7 repl: refine handling of illegal tokens
Illegal tokens are only recoverable in string literals, RegExp literals,
and block comments. If not in one of these constructs, immediately
return an error rather than giving the user false hope by giving them a
chance to try to recover.

PR-URL: https://github.com/nodejs/node/pull/7104
Fixes: https://github.com/nodejs/node/issues/3611
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-06-04 14:25:25 -07:00
Blake Embrey
9552e3b4af repl: exports Recoverable
Allow REPL consumers to callback with a `Recoverable` error instance
and trigger multi-line REPL prompts.

Fixes: https://github.com/nodejs/node/issues/2939
PR-URL: https://github.com/nodejs/node/pull/3488
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-05-12 10:03:06 -04:00
Rich Trott
a56da51a38 benchmark,test,lib: remove extra spaces
In preparation for stricter linting, remove extra spaces.

PR-URL: https://github.com/nodejs/node/pull/6645
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-05-11 23:18:16 -07:00
Anna Henningsen
3ee68f794f repl: don’t complete expressions when eval fails
Instead of changing the way “simple” expressions are detected,
switch to ignoring errors when completing. This approach is more
generic than the previous one from 0b66b8f2d, but also changes
the way errors are thrown when completing.

This reverts the code changes from commit 0b66b8f2d2.
The test case is left intact.

Fixes: https://github.com/nodejs/node/issues/6325
PR-URL: https://github.com/nodejs/node/pull/6328
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-04-25 09:40:55 -07:00
Rich Trott
31600735f4 lib,test,tools: alignment on variable assignments
Correct alignment on variable assignments that span multiple lines in
preparation for lint rule to enforce such alignment.

PR-URL: https://github.com/nodejs/node/pull/6242
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-04-18 17:19:11 -07:00
Anna Henningsen
39d905e293 node: make builtin libs available for --eval
Make the builtin libraries available for the `--eval` and
`--print` CLI options, using the same mechanism that the
REPL uses.

This renders workarounds like `node -e 'require("fs").doStuff()'`
unnecessary.

As part of this, the list of builtin modules and the code for
adding the corresponding properties to the target context is moved
to `internal/module.js`, and the previously missing `repl` entry
is added.

PR-URL: https://github.com/nodejs/node/pull/6207
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-04-18 15:31:32 -07:00
Rich Trott
1df84f4f75 debugger: run last command on presssing enter
PR-URL: https://github.com/nodejs/node/pull/6090
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Fixes: https://github.com/nodejs/node/issues/2895
2016-04-14 10:53:07 -07:00
Anna Henningsen
0b66b8f2d2 repl: don’t complete non-simple expressions
Change the regular expression that recognizes “simple” JS expressions
to requiring that the full line needs to match it.

Previously, in terms like `a().b.`, `b.` would be a partial match.
This meant that completion would evaluate `b` and either fail with
a `ReferenceError` or, if `b` was some global, return the properties
of the global `b` object.

PR-URL: https://github.com/nodejs/node/pull/6192
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-04-14 08:23:23 -04:00
Rich Trott
c5afd98b48 repl: refactor repl.js
There is some unnecessary logic in repl.js. Remove it.

PR-URL: https://github.com/nodejs/node/pull/6071
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-04-08 13:58:48 -07:00
Jackson Tian
91466b855f lib: refactor code with startsWith/endsWith
reduce using RegExp for string test. This pull reuqest replaces
various usages of regular expressions in favor of the ES2015
startsWith and endsWith methods.

PR-URL: https://github.com/nodejs/node/pull/5753
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-03-23 15:58:52 +02:00
Jackson Tian
d2b93e55cc lib: reduce usage of self = this
Remove unnecessary `self = this`.

PR-URL: https://github.com/nodejs/node/pull/5231
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-21 15:48:51 -07:00
Prince J Wesley
a38d6ad4be repl: support standalone blocks
Enable support for standalone block statements.

```js
node 🙈 ₹ git:(upstream  bare-block) ./node
> { var x = 3; console.log(x); }
3
undefined
> {}
{}
> { x:1, y:"why not", z: function() {} }
{ x: 1, y: 'why not', z: [Function] }
>
```
For the ambiguous inputs like `{ x }`, the existing REPL
behaviour (ES6 literal shorthand) is preserved (prefers
expression over statement).

Fixes: https://github.com/nodejs/node/issues/5576
PR-URL: https://github.com/nodejs/node/pull/5581
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-03-18 17:13:09 -07:00
Lance Ball
ad8257fa5b repl: Assignment of _ allowed with warning
This commit addresses https://github.com/nodejs/node/issues/5431 by
changing the way that the repl handles assignment to the global _
variable.

Prior to this commit, node sets the result of the last expression
evaluated in the repl to `_`. This causes problems for users of
underscore, lodash and other packages where it is common to assign
`_` to the package, e.g. `_ = require('lodash');`.

Changes in this commit now result in the following behavior.

- If unassigned on the repl, `_` continues to refer to the last
  evaluated expression.
- If assigned, the default behavior of assigning `_` to the last
  evaluated expression is disabled, and `_` now references whatever
  value was explicitly set. A warning is issued on the repl -
  'expression assignment to _ now disabled'.
- If `_` is assigned multiple times, the warning is only displayed once.
- When `.clear` is executed in the repl, `_` continues to refer to its
  most recent value, whatever that is (this is per existing behavior).
  If `_` had been explicitly set prior to `.clear` it will not change
  again with the evaluation of the next expression.

PR-URL: https://github.com/nodejs/node/pull/5535
Fixes: https://github.com/nodejs/node/issues/5431
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-18 21:03:40 +01:00
Prince J Wesley
40d57b714e repl: fix stack trace column number in strict mode
On strict mode, "'use strict'; void 0; " is added as prefix
in order to prevent "use strict" as the result value
for let/const statements. It causes wrong column number in
stack trace.

PR-URL: https://github.com/nodejs/node/pull/5416
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-02-29 10:46:31 +01:00
cjihrig
ee7754be47 repl: accept no arguments to start()
Currently, there is a check to ensure that the user either
provides an object or a string to repl.start(). The string case
is used to set a REPL prompt. However, a default of '> ' already
exists, so forcing the user to specify a prompt is a bit
redundant. This commit removes this restriction.

Fixes: https://github.com/nodejs/node/issues/5385
PR-URL: https://github.com/nodejs/node/pull/5388
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Julian Duque <julianduquej@gmail.com>
2016-02-25 08:48:43 -05:00
Zirak
a06066ca31 repl: allow multiline function call
Currently, the repl allows multiline function declarations, strings, and
all sorts of niceties by catching the SyntaxErrors they issue and
ignoring them. However, the SyntaxError raised by multiline function
calls was not caught. This commit adds to the whitelist.

PR-URL: https://github.com/nodejs/node/pull/3823
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-02-16 14:03:54 +05:30
Prince J Wesley
211018fe72 repl: handle quotes within regexp literal
PR-URL: https://github.com/nodejs/node/pull/5117
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
2016-02-09 13:21:09 +01:00
Rich Trott
ba81d152ec repl: remove variable redeclaration
`match` and `filter` are declared twice with `var` in `repl.js`.
Declare the variables only once.

PR-URL: https://github.com/nodejs/node/pull/4977
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-02-01 08:41:46 -08:00
Evan Lucas
50125e27b7 repl: use String#repeat instead of Array#join
String#repeat is quite a bit faster than new Array().join().

PR-URL: https://github.com/nodejs/node/pull/3900
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-12-21 10:54:01 -06:00
Prince J Wesley
aad6b9f0eb repl: display error message when loading directory
When loading directory instead of file, no error message
is displayed. It's good to display error message for
this scenario.

PR-URL: https://github.com/nodejs/node/pull/4170
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
2015-12-11 10:21:14 +09:00
Ben Noordhuis
213ede6cee repl: fix require('3rdparty') regression
Fix module loading of third-party modules in the REPL by inheriting
module.paths from the REPL's parent module.

Commit ee72ee7 ("module,repl: remove repl require() hack") introduced
a regression where require() of modules in node_modules directories
no longer worked in the REPL (and fortunately only in the REPL.)
It turns out we didn't have test coverage for that but we do now.

Fixes: https://github.com/nodejs/node/issues/4208
PR-URL: https://github.com/nodejs/node/pull/4215
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-12-09 23:30:02 +01:00
Zirak
451254ed25 repl: allow leading period in multiline input
When writing multiline input, one can't chain function calls as if the
lines begin with a period, since those are treated as REPL commands.

Before:

    > ([0, 1, 2]
    ... .map(x => x + 1))
    Invalid REPL keyword

After:

    > ([0, 1, 2]
    ... .map(x => x + 1))
    [ 1, 2, 3 ]

PR-URL: https://github.com/nodejs/node/pull/3835
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-12-01 19:40:43 -05:00
Ben Noordhuis
04b1a2f756 util: move .decorateErrorStack to internal/util
Move the method that was added in commit 8ca412b from earlier this month
from lib/util.js to lib/internal/util.js.

Avoids exposing a method that we may not wish to expose just yet, seeing
how it relies on implementation details.

PR-URL: https://github.com/nodejs/node/pull/4026
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-11-30 23:58:32 +01:00
Ben Noordhuis
ee72ee7531 module,repl: remove repl require() hack
Remove a hack that was introduced in commit bb6d468d from November 2010.
This is groundwork for a follow-up commit that makes it possible to use
internal modules in lib/repl.js.

PR-URL: https://github.com/nodejs/node/pull/4026
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-11-30 23:58:27 +01:00
cjihrig
459b106d6c repl: attach location info to syntax errors
Currently, when a file with a syntax error is imported in the
REPL, no information is provided on the error's location. This
commit adds the error's location to the stack trace.

Refs: https://github.com/nodejs/node/issues/2762
Refs: https://github.com/nodejs/node/issues/3411
Refs: https://github.com/nodejs/node/issues/3784
PR-URL: https://github.com/nodejs/node/pull/4013
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-11-25 13:34:13 -05:00
Wyatt Preul
007cfea308 util: remove pump
Remove util.pump and associated tests

PR-URL: https://github.com/nodejs/node/pull/2531
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2015-11-18 14:28:35 -08:00
Hemanth.HM
354f9ce458 repl: To exit, press ^C again or type .exit.
When the user hits `^C` in the REPL show more info about `.exit`.

The idea was to give more info to the user when they hit ^C.
Current version just displays `(^C again to quit)` and most
of the users are not aware of the `.exit` command that would
Exit the repl.

PR-URL: https://github.com/nodejs/node/pull/3368
Reviewed-By: James M Snell <jasnell@gmail.com>
2015-11-09 11:52:13 -08:00
micnic
20285ad177 lib: Consistent error messages in all modules
This commit fixes some error messages that are not consistent with
some general rules which most of the error messages follow.

PR-URL: https://github.com/nodejs/node/pull/3374
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-11-09 20:08:36 +01:00
Sakthipriyan Vairamani
6cf19103b6 repl: handle comments properly
As it is, the comments are not handled properly in REPL. So, if the
comments have `'` or `"`, then they are treated as incomplete string
literals and the error is thrown in REPL.

This patch refactors the existing logic and groups everything in a
class.

Fixes: https://github.com/nodejs/node/issues/3421
PR-URL: https://github.com/nodejs/node/pull/3515
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-10-28 07:32:07 +05:30
Jeremiah Senkpiel
ecab7a6bee repl: event ordering: delay 'close' until 'flushHistory'
Emitting 'close' before the history has flushed is somewhat incorrect
and rather confusing.

This also makes the 'close' event always asynchronous for consistency.

Refs: https://github.com/nodejs/node/pull/2356
PR-URL: https://github.com/nodejs/node/pull/3435
Reviewed By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-10-22 13:39:04 -04:00
Rich Trott
b354be7761 lib: avoid REPL exit on completion error
If a tab completion is attempted on an undefined reference inside of a
function, the REPL was exiting without reporting an error or anything
else. This change results in the REPL reporting the ReferenceError and
continuing.

Fixes: https://github.com/nodejs/node/issues/3346
PR-URL: https://github.com/nodejs/node/pull/3358
Reviewed-By: James M Snell <jasnell@gmail.com>
2015-10-21 15:30:49 -07:00
Sakthipriyan Vairamani
fcfd87d7e1 repl: backslash bug fix
The actual problem was with the line parsing logic for string literals.
When we use backslash in the string literals, it used to remember the
`\` as the previous character even after we parsed the character next
to it. This leads to REPL thinking that the end of string literals is
not reached.

This patch replaces the previous character with `null`, so that it will
properly skip the character next to it.

Previous Discussion: https://github.com/nodejs/node/pull/2952
Fixes: https://github.com/nodejs/node/issues/2749
PR-URL: https://github.com/nodejs/node/pull/2968
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-09-22 16:43:14 +02:00
cjihrig
a69ab27ab4 node: rename from io.js to node
This commit replaces instances of io.js with Node.js, based on the
recent convergence. There are some remaining instances of io.js,
related to build and the installer.

Fixes: https://github.com/nodejs/node/issues/2361
PR-URL: https://github.com/nodejs/node/pull/2367
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: João Reis <reis@janeasystems.com>
2015-08-23 17:59:43 -04:00
James M Snell
ce145bf358 repl: filter integer keys from repl tab complete list
Refactored version of https://github.com/joyent/node/pull/25819

Removes integer keys (and keys starting with numbers) from
candidate list on repl tab complete. Refactored the originally
submitted change to simplify and ensure that the integer keys
do not show up on objects either.

Reviewed By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/2409
2015-08-21 21:40:44 -07:00
Sakthipriyan Vairamani
ea05e760cd repl: don't clobber RegExp.$ properties
In REPL, if we evaluate the `RegExp` object's predefined properties,
and if they happen to have the same expression, for example,

    > RegExp.$1
    'RegExp.$1'

then doing `eval(RegExp.$1)` would evaluate `RegExp.$1` recursively and
eventually throw `RangeError: Maximum call stack size exceeded`.

This patch stores the old values of `RegExp`'s predefined proprties in
an array and restores them just before the current expression entered
by user is evaluated.

Fixes: https://github.com/nodejs/io.js/issues/597
PR-URL: https://github.com/nodejs/io.js/pull/2137
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-08-04 10:21:37 +05:30
Sakthipriyan Vairamani
afd7e37ee0 repl: better empty line handling
In REPL, if we try to evaluate an empty line, we get `undefined`.

    > process.version
    'v2.3.4'
    >
    undefined
    >
    undefined
    >

This patch prevents `undefined` from printing if the string is empty.

    > process.version
    'v2.3.5-pre'
    >
    >
    >

PR-URL: https://github.com/nodejs/io.js/pull/2163
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-07-25 00:34:06 +05:30
Sakthipriyan Vairamani
81ea52aa01 repl: improving line continuation handling
As it is, REPL doesn't honour the line continuation feature very well.
This patch

 1. keeps track of the beginning of the string literals and if they
    don't end or current line doesn't end with line continuation, then
    error out.

 2. monitors if the line continuation character is used without the
    string literal and errors out if that happens.

PR-URL: https://github.com/nodejs/io.js/pull/2163
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-07-25 00:33:50 +05:30
Sakthipriyan Vairamani
30edb5aee9 repl: preventing REPL crash with inherited properties
When an inherited property is used as a REPL keyword, the REPL crashes.

    ➜  Desktop  iojs
    > process.version
    'v2.3.4'
    > .toString
    readline.js:913
            stream[ESCAPE_DECODER].next(r[i]);
                                    ^
    TypeError: Cannot read property 'call' of undefined
        at REPLServer.parseREPLKeyword (repl.js:746:15)
        at REPLServer.<anonymous> (repl.js:284:16)
        at emitOne (events.js:77:13)
        at REPLServer.emit (events.js:169:7)
        at REPLServer.Interface._onLine (readline.js:210:10)
        at REPLServer.Interface._line (readline.js:549:8)
        at REPLServer.Interface._ttyWrite (readline.js:826:14)
        at ReadStream.onkeypress (readline.js:105:10)
        at emitTwo (events.js:87:13)
        at ReadStream.emit (events.js:172:7)
    ➜  Desktop

This patch makes the internal `commands` object inherit from `null` so
that there will be no inherited properties.

    > process.version
    'v2.3.5-pre'
    > .toString
    Invalid REPL keyword
    >

PR-URL: https://github.com/nodejs/io.js/pull/2163
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-07-25 00:33:35 +05:30
Sakthipriyan Vairamani
77fa385e5d repl: fixing undefined in invalid REPL keyword error
When an invalid REPL keyword is used, we actually print `undefined` as
well in the console.

    > process.version
    'v2.3.4'
    > .invalid_repl_command
    Invalid REPL keyword
    undefined
    >

This patch prevents printing `undefined` in this case.

    > process.version
    'v2.3.5-pre'
    > .invalid_repl_command
    Invalid REPL keyword
    >

PR-URL: https://github.com/nodejs/io.js/pull/2163
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-07-25 00:33:20 +05:30
Sakthipriyan Vairamani
59f6b5da2a repl: Prevent crash when tab-completed with Proxy
If the proxy objects don't have a valid `hasOwnPropertyNames` trap,
REPL crashes with a `TypeError`, as per the bug report
https://github.com/nodejs/io.js/issues/2119

    > var proxy = Proxy.create({ fix: function() { return {}; } });
    undefined
    > proxy.<tab>
    TypeError: Proxy handler #<Object> has no 'getOwnPropertyNames' trap
        at Function.getOwnPropertyNames (native)
        at repl.js:644:40
        at REPLServer.defaultEval (repl.js:169:5)
        at bound (domain.js:254:14)
        at REPLServer.runBound [as eval] (domain.js:267:12)
        at REPLServer.complete (repl.js:639:14)
        at REPLServer.complete [as completer] (repl.js:207:10)
        at REPLServer.Interface._tabComplete (readline.js:377:8)
        at REPLServer.Interface._ttyWrite (readline.js:845:14)
        at ReadStream.onkeypress (readline.js:105:10)

This patch traps the error thrown and suppresses it.

PR-URL: https://github.com/nodejs/io.js/pull/2120
Fixes: https://github.com/nodejs/io.js/issues/2119
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
2015-07-10 07:54:49 -05:00
Rich Trott
eabed2f518 repl: remove obsolete TODO
It's long past v0.3.0 and .break isn't going anywhere anytime soon.

PR-URL: https://github.com/nodejs/io.js/pull/2081
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Brian White <mscdex@mscdex.net>
2015-07-01 22:45:06 -07:00
Julien Gilli
a198c68b56 repl: make 'Unexpected token' errors recoverable
Fix the regexp used to detect 'Unexpected token' errors so that they can
be considered as recoverable. This fixes the following use case:

> var foo = 'bar \
... baz';
undefined
> foo
'bar baz'
>

Fixes: https://github.com/joyent/node/issues/8874
PR-URL: https://github.com/joyent/node/pull/8875
PR-URL: https://github.com/nodejs/io.js/pull/2052
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-06-25 12:17:51 -04:00
Sangmin Yoon
d735b2c6ef repl: fix tab completion for a non-global context
Use vm.isContext() to properly identify contexts.

PR-URL: https://github.com/joyent/node/pull/25382
PR-URL: https://github.com/nodejs/io.js/pull/2052
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-06-25 12:16:41 -04:00
Vladimir Kurchatkin
6d95f4ff92 smalloc: deprecate whole module
It makes no sense to allow people use constants from
`smalloc`, since it will be removed completely eventually.

PR-URL: https://github.com/nodejs/io.js/pull/1822
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-06-04 11:00:19 +03:00
Yazhong Liu
5f33521be5 repl: remove unnecessary check for globals
There is no need to check for globals and also check if it is
an array.

PR-URL: https://github.com/nodejs/io.js/pull/1722
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-05-17 14:03:37 -04:00
Yazhong Liu
6edc900b95 repl: support non-array .scope, document it
REPL evaluate `.scope` when it needs to get a list of the variable names
available in the current scope. Do not throw if the output of such
evaluation is not array, just ignore it.

PR-URL: https://github.com/nodejs/io.js/pull/1682
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2015-05-17 12:22:26 +02:00
Yosuke Furukawa
19ffb5cf1c lib: fix eslint styles
PR-URL: https://github.com/iojs/io.js/pull/1539
Fixes: https://github.com/iojs/io.js/issues/1253
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2015-05-09 12:10:02 +09:00