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
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
Chris Dickinson
051d482b15 repl: fix _debugger by properly proxying repl
The _debugger module uses the internal REPL module, but expects
to receive the userland REPL module. This fixes the breakage that
occurs by proxying the userland REPL module through the internal
module.

It also fixes an unintended in-REPL bug, where require(node-module)
was not resolving correctly.

PR-URL: https://github.com/iojs/io.js/pull/1605
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-05-04 10:42:42 -07:00
Chris Dickinson
0450ce7db2 repl: add mode detection, cli persistent history
this creates a new internal module responsible for providing
the repl created via "iojs" or "iojs -i," and adds the following
options to the readline and repl subsystems:

* "repl mode" - determine whether a repl is strict mode, sloppy mode,
  or auto-detect mode.
* historySize - determine the maximum number of lines a repl will store
  as history.

The built-in repl gains persistent history support when the
NODE_REPL_HISTORY_FILE environment variable is set. This functionality
is not exposed to userland repl instances.

PR-URL: https://github.com/iojs/io.js/pull/1513
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2015-04-30 19:33:05 -07:00
Ben Noordhuis
2b2e48a4b9 lib: don't error in repl when cwd doesn't exist
The current working directory may not exist when the REPL starts up.
Don't treat that as an error because it's still possible to do many
useful things.  This is like the previous commit but for the REPL.

Fixes: https://github.com/iojs/io.js/issues/1184
PR-URL: https://github.com/iojs/io.js/pull/1194
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Rod Vagg <rod@vagg.org>
2015-03-19 02:11:38 +01:00
cjihrig
6ac8bdc0ab lib: reduce util.is*() usage
Many of the util.is*() methods used to check data types
simply compare against a single value or the result of
typeof. This commit replaces calls to these methods with
equivalent checks. This commit does not touch calls to the
more complex methods (isRegExp(), isDate(), etc.).

Fixes: https://github.com/iojs/io.js/issues/607
PR-URL: https://github.com/iojs/io.js/pull/647
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-31 23:47:29 -05:00
cjihrig
804e7aa9ab lib: use const to define constants
This commit replaces a number of var statements throughout
the lib code with const statements.

PR-URL: https://github.com/iojs/io.js/pull/541
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-21 16:21:31 -05:00
Xiaowei Li
b7365c1559 repl: make REPL support multiline template literals
Let REPL enter multiline mode if user's input contains unterminated
template literals.

PR-URL: https://github.com/iojs/io.js/pull/333
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-19 13:06:37 +01:00
Yosuke Furukawa
fd30eb2152 src: fix jslint errors
PR-URL: https://github.com/iojs/io.js/pull/449
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-15 21:21:31 +01:00
isaacs
3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00
Ben Noordhuis
db595b2de6 lib: reintroduce v8 module
I introduced this module over a year ago in a pull request as the v8
module but it was quickly subsumed by the tracing module.

The tracing module was recently removed again and that is why this
commit introduces the v8 module again, including the new features it
picked up commits d23ac0e and f8076c4.

PR-URL: https://github.com/iojs/io.js/pull/131
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Christian Tellnes <christian@tellnes.no>
Reviewed-By: Thorsten Lorenz <thlorenz@gmx.de>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2014-12-14 18:52:57 +01:00
Bert Belder
2b6a0f85f3 src: remove the tracing module entirely
PR-URL: https://github.com/iojs/io.js/pull/124
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-09 17:57:19 +01:00
Ben Noordhuis
21130c7d6f lib: turn on strict mode
Turn on strict mode for the files in the lib/ directory.  It helps
catch bugs and can have a positive effect on performance.

PR-URL: https://github.com/node-forward/node/pull/64
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-11-22 17:23:30 +01:00
Fedor Indutny
1a84ba2d66 repl: proper setPrompt() and multiline support
fix #8031
2014-07-31 12:30:46 +04:00
Fedor Indutny
1a52d6abcc Revert "repl: fix overwrite for this._prompt"
This reverts commit 7166b55015.
2014-07-31 12:12:18 +04:00
Yazhong Liu
7166b55015 repl: fix overwrite for this._prompt
Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-07-29 12:53:05 +04:00
Fedor Indutny
b5175003bc repl: fix multi-line input
The refactor in 3ae0b17c broke the multiline input's visual appearence.
While actually switching to this mode, the `...` prefix is not
displayed.

Additionally, account only SyntaxErrors that are happening at the parse
time, everything else should not be switching repl to the multiline
mode.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-06-30 13:04:36 +04:00
Brian White
03e9f84933 lib: remove unused variables
Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-06-11 20:41:12 -07:00
Timothy J Fontaine
c0d73e6de1 lint: fix missing semi colon in repl 2014-02-17 16:21:38 -08:00
Yazhong Liu
c980280159 repl: remove a unnecessary concatenation 2014-02-17 16:04:36 -08:00
Yazhong Liu
3ae0b17c76 repl: REPLServer inherits from readline.Interface
This exposes a setPrompt for and other readline features
2014-02-17 16:04:36 -08:00
Ben Noordhuis
010222d39f src: add tracing.v8.on('gc') statistics hooks
Add a new 'tracing' module with a v8 property that lets the user
register listeners for gc events.  The listeners are invoked after
every garbage collection cycle with 'before' and 'after' statistics.
Useful for monitoring tools that want to keep track of memory usage.
2014-02-05 11:49:01 -08:00
Timothy J Fontaine
2329a254b4 Merge remote-tracking branch 'upstream/v0.10'
Conflicts:
	AUTHORS
	ChangeLog
	deps/uv/AUTHORS
	deps/uv/ChangeLog
	deps/uv/README.md
	deps/uv/build.mk
	deps/uv/src/unix/core.c
	deps/uv/src/unix/darwin-proctitle.c
	deps/uv/src/unix/darwin.c
	deps/uv/src/unix/fsevents.c
	deps/uv/src/unix/udp.c
	deps/uv/src/version.c
	deps/v8/src/platform-solaris.cc
	deps/v8/test/cctest/test-api.cc
	lib/tls.js
	src/node.h
	src/node_version.h
2013-11-18 13:41:17 -08:00
Maciej Małecki
568072ceae repl: do not insert duplicates into completions
Fix invalid `hasOwnProperty` function usage.

For example, before in the REPL:

```
> Ar<Tab>
Array

Array        ArrayBuffer
```

Now:

```
> Ar<Tab>
Array

ArrayBuffer
```

Fixes #6255.
Closes #6498.
2013-11-11 15:45:09 -08:00
isaacs
9ef9a9dee5 repl: Simplify paren wrap, continuation-detection
This simplifies the logic that was in isSyntaxError, as well as the
choice to wrap command input in parens to coerce to an expression
statement.

1. Rather than a growing blacklist of allowed-to-throw syntax errors,
just sniff for the one we really care about ("Unexpected end of input")
and let all the others pass through.

2. Wrapping {a:1} in parens makes sense, because blocks and line labels
are silly and confusing and should not be in JavaScript at all.
However, wrapping functions and other types of programs in parens is
weird and required yet *more* hacking to work around.  By only wrapping
statements that start with { and end with }, we can handle the confusing
use-case, without having to then do extra work for functions and other
cases.

This also fixes the repl wart where `console.log)(` works in the repl,
but only by virtue of the fact that it's wrapped in parens first, as
well as potential side effects of double-running the commands, such as:

    > x = 1
    1
    > eval('x++; throw new SyntaxError("e")')
    ... ^C
    > x
    3
2013-09-04 11:13:41 -07:00
Nathan Rajlich
54fbb1da96 repl: treat "Assignment to const" as syntax error
Adding a new `repl-harmony` test file here because adding the
`--use_strict --harmony` flags on the main repl test file was causing
lots of unrelated failures, due to global variable assignments and
things like that. This new test file is based off of the original
repl.js test file, but has a lot of the tests stripped out. A test case
for this commit is included though.

Fixes #6132.
2013-09-04 11:13:41 -07:00
isaacs
4631c503e3 repl: Catch syntax errors better
Replace the growing list of 'isSyntaxError' whackamole conditions with a
smarter approach.  This creates a vm Script object *first*, which will
parse the code and raise a SyntaxError right away.

We still do need the test function, but only because strict mode syntax
errors are not recoverable, and should be raised right away.  Really, we
should probably *only* continue on "unexpected end of input" SyntaxErrors.

Also fixes a very difficult-to-test nit where the '...' indentation is
not properly cleared when you ^C out of a syntax error.

Closes #6093
2013-09-04 11:13:41 -07:00
Domenic Denicola
fd3657610e vm: update API to use options argument
Passing a filename is still supported in place of certain options
arguments, for backward-compatibility, but timeout and display-errors
are not translated since those were undocumented.

Also managed to eliminate an extra stack trace line by not calling
through the `createScript` export.

Added a few message tests to show how `displayErrors` works.
2013-08-28 22:27:24 -07:00
isaacs
eef552774e vm: Put back display_errors flag
This is an important part of the repl use-case.

TODO: The arg parsing in vm.runIn*Context() is rather wonky.
It would be good to move more of that into the Script class,
and/or an options object.
2013-08-21 17:58:12 -07:00
Brian White
6d842897c5 lib: remove unused variables and functions 2013-08-15 17:19:17 -07:00
isaacs
6942a95ae1 repl: Add 'smalloc' to list of known modules 2013-08-05 17:03:08 -07:00
isaacs
22c68fdc1d src: Replace macros with util functions 2013-08-01 15:08:01 -07:00
Ben Noordhuis
0330bdf519 lib: macro-ify type checks
Increases the grep factor. Makes it easier to harmonize type checks
across the code base.
2013-07-24 21:49:35 +02:00
isaacs
2900f0778a Merge remote-tracking branch 'ry/v0.10'
Conflicts:
	ChangeLog
	src/node_version.h
2013-05-31 11:52:57 -07:00
Brian White
774b28fde7 repl: fix JSON.parse error check
Before this, entering something like:

> JSON.parse('066');

resulted in the "..." prompt instead of displaying the expected
"SyntaxError: Unexpected number"
2013-05-30 14:41:00 +02:00
isaacs
2c9a38d059 Merge remote-tracking branch 'ry/v0.10'
Conflicts:
	AUTHORS
	ChangeLog
	deps/v8/src/json-parser.h
	lib/crypto.js
	src/node_version.h
2013-04-05 09:02:48 -07:00
Nathan Rajlich
55ea7ccf70 repl: use more readable RegExp syntax for spaces
This is just a cosmetic change really, nothing major.
2013-03-30 13:35:36 -07:00
Nathan Rajlich
085f9d636b repl: isSyntaxError() catches "strict mode" errors
Closes #5178.
2013-03-30 13:10:30 -07:00
isaacs
c0721bcd66 repl: Use a domain to catch async errors safely
Fix #2031
2013-03-14 16:03:44 -07:00
Sami Samhuri
5eacdd4bf9 repl: emit 'reset' event when context is reset
Closes #1183.
2013-03-14 10:49:14 -10:00
Dave Olszewski
22aa767421 make repl compatible with domains
The try/catch in repl.js keeps any active domain from catching the
error.  Since the domain may not even be enterd until the code is run,
it's not possible to avoid the try/catch, so emit on the domain when an
error is thrown.
2013-03-03 15:28:45 -08:00
Ryunosuke SATO
61741f9a83 repl: fix how to module requiring in code comment
This module requiring style is old.
This API has been changed in Node 0.1.16 726865af.
2013-01-16 10:59:22 -08:00
Nathan Rajlich
bac537b186 repl: fix lint 2013-01-12 12:14:39 -08:00
Felix Böhm
9bce5e8f3e repl: make built-in modules available by default
Closes #3564.
Closes #4578.
2013-01-12 12:10:29 -08:00
Nirk Niggler
0459a23063 REPL: fix floating point number parsing
In JS, the expression ".1" is a floating point number.  Issue 4268 concerns the
REPL interpreting floating point numbers that lead with a "." as keywords.  The
original bugfix worked for this specific case but not for the general case:

    var x = [
        .1,
        .2,
        .3
    ];

The attached change and test (`.1+.1` should be `.2`) fix the bug.

Closes #4513.
2013-01-03 17:11:54 -08:00
Ben Noordhuis
aad2013508 repl: allow overriding builtins
Don't give names of built-in libraries special treatment.
Changes the REPL's behavior from this:

  > var path = 42
  > path
  A different "path" already exists globally

To this:

  > var path = 42
  > path
  42

Fixes #4512.
2013-01-03 19:58:47 +01:00
Ryunosuke SATO
0db521d0b0 repl: remove 'repl' from automatic loading libs
In repl, calling `repl` twice shows the following message:
```
> repl
A different "repl" already exists globally
```
2012-12-26 15:25:00 -08:00
Ryunosuke SATO
31cffae2ba repl: add 'domain' to automatic loading libs
`domain` should be a member of automatic loading libs in `repl`.

Conflicts:

	lib/repl.js
2012-12-26 15:23:31 -08:00
Nathan Rajlich
837df70b75 repl: don't touch require.cache
Fixes #3226.

Consider a production server that uses a REPL to debug. Creating the instance
would wipe out the global cache of modules, and subsequent "require" calls in
the server would be reloaded from disk. The REPL should observe only, without
altering, its environment.
2012-12-21 11:42:40 -08:00
isaacs
17834ed28c Add 'stream' as a native module in repl 2012-12-13 17:00:23 -08:00
Ben Noordhuis
b6e989759b repl: don't interpret floating point numbers
Don't interpret floating point numbers, e.g. ".1234", as REPL commands.

Fixes #4268.
2012-11-10 18:21:17 +01:00
Nathan Rajlich
4b238b4c2a Merge remote-tracking branch 'origin/v0.8'
Conflicts:
	AUTHORS
	ChangeLog
	deps/uv/test/runner-win.c
	doc/api/process.markdown
	lib/repl.js
	src/node_crypto.cc
	src/node_version.h
2012-10-13 16:16:56 -07:00
Nathan Rajlich
b1e78cef09 repl: ensure each REPL instance gets its own "context"
Before there was this weird module-scoped "context" variable which seemingly
shared the "context" of subsequent REPL instances, unless ".clear" was invoked
inside the REPL. To be proper, we need to ensure that each REPL gets its own
"context" object. I literally don't know why this "sharing" behavior was in place
before, but it was just plain wrong.
2012-10-12 16:37:17 -07:00
Nathan Rajlich
7611c7cd25 repl: dynamically lookup the require extensions for tab complete
Removes 2 TODO items
2012-10-07 11:33:33 -07:00
Nathan Rajlich
59c166cfba repl: move "isSyntaxError()" definition to the bottom
fixes lint "line length too long" error
2012-10-05 18:33:28 -07:00
Nathan Rajlich
3b7312d23a repl: make "end of input" JSON.parse() errors throw in the REPL 2012-10-01 11:36:06 -07:00
Nathan Rajlich
f1722a280c repl: make invalid RegExp modifiers throw in the REPL
Fixes #4012.
2012-09-30 22:47:57 -07:00
isaacs
ae40f1c438 Merge remote-tracking branch 'ry/v0.8' into v0.8-merge
Conflicts:
	AUTHORS
	ChangeLog
	deps/openssl/openssl.gyp
	deps/uv/src/unix/linux/linux-core.c
	deps/uv/src/unix/process.c
	deps/uv/src/unix/stream.c
	deps/v8/src/arm/builtins-arm.cc
	deps/v8/src/arm/code-stubs-arm.cc
	deps/v8/src/arm/full-codegen-arm.cc
	lib/tls.js
	src/node_version.h
	test/simple/test-http-client-timeout-agent.js
2012-09-28 09:47:48 -07:00
Nathan Rajlich
4a2670740c repl: make invalid RegExps throw in the REPL
Fixes #2746.
2012-09-21 19:49:29 -07:00
Nathan Rajlich
0285dae26a repl: create a new Console instance for the repl when "useGlobal" is off
Now `console.log('blah')` will work in a REPL running over a socket.

Closes #3876.
2012-08-24 14:31:32 -07:00
isaacs
424cd5a020 Merge remote-tracking branch 'ry/v0.8' into v0.8-merge
Conflicts:
	src/node_version.h
2012-07-11 17:38:11 -07:00
Jonas Westerlund
7e7d5d38ea Move function declaration out of conditional
Also avoid using eval as identifier.
Fixes crashes in strict mode.
2012-07-06 19:28:35 -07:00
Nathan Rajlich
9126dd2d90 repl: fix passing an empty line inserting "undefined" into the buffer
There was a possiblity of insering the string "undefined" into the repl's
command buffer, which would cause interesting results while evaluating.
2012-07-04 11:51:24 -07:00
Maciej Małecki
6a11f3edf4 repl: fix crashes when buffering command
Wrong order of operands was causing problems while trying to use command
buffering:

    > {
    ...   a: 3,
    ...

    repl.js:284
            if (cmd.trim().match(/^npm /) && !self.bufferedCommand) {
                    ^
    TypeError: Cannot call method 'trim' of undefined
        at finish (repl.js:284:17)
        at REPLServer.self.eval (repl.js:118:5)
        at rli.on.e (repl.js:260:20)
        at REPLServer.self.eval (repl.js:118:5)
        at Interface.<anonymous> (repl.js:250:12)
        at Interface.EventEmitter.emit (events.js:88:17)
        at Interface._onLine (readline.js:183:10)
        at Interface._line (readline.js:502:8)
        at Interface._ttyWrite (readline.js:720:14)
        at ReadStream.<anonymous> (readline.js:105:12)

Test included.

Closes #3515.
Closes #3517.
Closes #3621.
2012-07-04 11:22:10 -07:00
Ben Noordhuis
c40875ee13 repl: fix buffer clearing after npm command 2012-06-23 02:29:36 +02:00
Andreas Madsen
1e0ce5d1bd domain: the EventEmitter constructor is now always called in nodecore 2012-06-15 09:49:05 -07:00
isaacs
28e851c169 Warn about running npm in the repl 2012-06-05 12:35:49 -07:00
Nathan Rajlich
a608f65b24 repl: preserve the cursor when redisplaying the prompt on SIGCONT
Otherwise the cursor position was being reset to 0, even when there was
already part of a line, which was strange.

Part of #3295.
2012-05-21 21:09:46 -03:00
Nathan Rajlich
f405daa922 repl: make tab completion read up the prototype of "global"
For example, there's a global "toString()" function, so the REPL's
tab completion should pick that up.
2012-04-25 20:34:34 -07:00
Nathan Rajlich
e16021340d repl: use Object.getPrototypeOf on functions for tab complete() 2012-04-21 13:53:49 -07:00
Nathan Rajlich
327286dbcd repl: update the repl for the new readline behavior
This fixes the failing REPL tests.
2012-04-17 11:53:50 -07:00
Nathan Rajlich
ca8dea83a9 repl: make the completer use newlines
Fixes the repl.complete() function when terminal is false, since it
is now explicitly looking for a '\n' char.
2012-04-06 16:13:40 -07:00
Nathan Rajlich
48bbdde66b repl: don't write a newline on the readline 'end' event
In the case of the input stream *actually* having been closed, then we
can't write to a closed socket.

Fixes test/simple/test-repl.js
2012-03-28 08:42:40 -07:00
Nathan Rajlich
208b230744 repl: add a 'useColors' option to the repl
This should only be minimally used, since the `terminal` value will usually be
what you are expecting. This option is specifically for the case where `terminal`
is false, but you still want colors to be output (or vice-versa).
2012-03-27 18:00:59 -07:00
Nathan Rajlich
b187e96ec9 repl: add a 'writer' option to the repl
Previously this was a module-level setting, meaning that all REPL instances
had to share the same writer function. Turning it into one of the options
allows individual REPL instances to use their own writer function.
2012-03-27 17:39:14 -07:00
Nathan Rajlich
228ddddc1c repl: ensure that 'repl.ignoreUndefined' is a boolean 2012-03-27 17:35:33 -07:00
Nathan Rajlich
e7065eaa93 repl: ensure that 'repl.useGlobal' is a boolean 2012-03-27 17:34:55 -07:00
Nathan Rajlich
f41901cdf6 repl: make ^D emit an 'end' event on the readline instance
Also emit 'exit' on the repl when 'end' is emitted on the readline.

Fixes `node debug test/fixtures/breakpoints.js` when ^D is pressed.
2012-03-27 13:54:49 -07:00
Nathan Rajlich
aad12d0b26 readline: migrate ansi/vt100 logic from tty to readline
The overall goal here is to make readline more interoperable with other node
Streams like say a net.Socket instance, in "terminal" mode.

See #2922 for all the details.
Closes #2922.
2012-03-26 15:21:25 -07:00
Alex Kocharin
06a058d731 readline: row-agnostic multiline readline implementation
Fixes #2959.
2012-03-20 15:37:06 -07:00
Alex Kocharin
415bff26fe repl: fix space autocompletion bug
Tapping <SP> + <TAB> would exit the REPL.
2012-03-20 12:27:59 +01:00
Fedor Indutny
b6cb6ce0d3 debugger: remove 'repl' command from builtinLibs
* It was displaying useless warning
2012-03-19 22:21:28 +06:00
Nathan Rajlich
f214758dd1 repl: better SIGINT handling behavior
Before:

☮ ~ (master)  node
> asdf
(^C again to quit)
> sdcasd☮ ~ (master) 

Now:

☮ ~/node (repl)  ./node
> asfs
> sda
>
(^C again to quit)
> scdsdc
> sdcsdc
>
(^C again to quit)
> sdc
>
(^C again to quit)
>
☮ ~/node (repl) 

^ note that each new line above is a ctrl+c sequence
2012-03-13 19:58:52 +01:00
Nathan Rajlich
6b5a34cdf3 repl: remove redundant check of rli.rine.length
It get's set to '' 1 line above, so we know that that's always 0.
2012-03-13 19:58:52 +01:00
Nathan Rajlich
b7ddd30181 repl: make sure the REPL always flushes with a newline 2012-03-13 19:58:51 +01:00
Nathan Rajlich
659d449460 repl: make REPLServer emit an "exit" event
This can happen when "SIGINT" is processed by the readline interface,
or when the user types ".exit" into the REPL.
2012-03-13 19:58:50 +01:00
Nathan Rajlich
4f63f9f327 repl: make REPLServer inherit from EventEmitter
This is because it should emit an "exit" event when "SIGINT" is received
from the readline interface, or when ".exit" is typed by the user.
2012-03-13 19:58:50 +01:00
Nathan Rajlich
109b16d488 repl: use path.resolve() for the module.filename
Windows was seeing: "C:\\path\\to\\cwd/repl"
2012-03-13 19:58:49 +01:00
Colton Baker
fd61bfc731 readline: ^Z (SIGSTP) handling
Bugfix and update.

- Fixed bug where Node's REPL wouldn't continue when returning from ^Z
  (SIGTSTP)
- Removed old readline callback

Readline API update with docs.

- ^Z (SIGTSTP) is now bypassed on Windows systems.
- SIGCONT is now bypassed on Windows systems.
- Docs updated to reflect above.
2012-02-22 16:07:23 -08:00
Brandon Benvie
b72277183f repl: add automatic loading of built-in libs 2012-02-20 13:56:27 +01:00
isaacs
0cdf85e28d Lint all the JavaScripts. 2012-02-18 15:34:57 -08:00
isaacs
31721da4b1 Merge remote-tracking branch 'ry/v0.6' into v0.6-merge
Conflicts:
	AUTHORS
	ChangeLog
	Makefile
	doc/about/index.html
	doc/api/tls.markdown
	doc/community/index.html
	doc/index.html
	doc/logos/index.html
	doc/template.html
	lib/http.js
	lib/tls.js
	src/node_version.h
	src/platform_win32.cc
	test/simple/test-tls-connect-given-socket.js
2012-02-18 09:46:58 -08:00
Fedor Indutny
ae5e23310e repl: remove double calls where possible
Repl is doing double evaluation of code: wrapped in parens and without
them. That's needed to allow users typing multiline chunks of code by
handling syntax errors on repl side. However if function declaration is
wrapped in parens (`(function a() {})`) calling it will be impossible,
so we're evaluating functions twice. That works fine for declaration,
but if entered code chunk returns function - it should not be called
twice.

fix #2773
2012-02-18 00:30:52 +06:00
Nathan Rajlich
a118f21728 repl: make tab completion work on non-objects 2012-02-17 15:51:33 +01:00
Colton Baker
ce485791db Readline proposal and bugfixes. Related: #2737 #2756
- Removed extra newline from .question(); Users can input a
  newline if it they require it.
- Removed .close() due to it only emulating closing, causing a bug where
  readline is left open to trigger events such as .on('line', ...').
- Removed ._attemptClose()
- .pause() now triggers event .on('pause', ...)
- .resume() now triggers event .on('resume', ...)
- CTRL-C (SIGINT) in readline will now default to .pause() if no SIGINT event
  is present.
- CTRL-D (delete right) will also default to .pause() if there is nothing to
  delete (signaling the end of the file).
- Added new event `SIGTSTP`
- Added new event `SIGCONT`
- Added `resume` to `write` to resume the stream if paused.
- Docs updated.
- Updated repl.js
2012-02-16 12:12:03 +06:00
Ben Noordhuis
c123ac05dc Merge remote-tracking branch 'origin/v0.6'
Conflicts:
	src/udp_wrap.cc
2012-01-02 12:29:39 +01:00
isaacs
8e57398b20 Fix #2034 repl message for .clear when useGlobal=true 2011-12-31 03:20:41 +01:00
Damon Oehlman
744ed46970 repl: fix repl.start not passing the ignoreUndefined arg to the REPLServer constructor 2011-12-29 14:46:04 +01:00
Fedor Indutny
c07edd90f5 preserve cursor pos
* configurable via .prompt()'s preserveCursor argument (false by default)
2011-12-19 11:09:16 -08:00
seebees
3421f43351 .load, .save and local scope tab completion
Fixes #2063.

REPLServer.prototype.resetContext:
Reset the line cache

REPLServer.prototype.memory (don't know if I like that name, called from finish)
pushes what cmd's have been executed against it into this.lines
pushes the "tab depth" for bufferedCommands, in this.lines.level

REPLServer.prototype.displayPrompt:
Uses "tab depth" from this.lines.level to adjust the prompt to visually
denote this depth e.g.
> asdf = function () {
… var inner = {
….. one:1

REPLServer.prototype.complete:
Now notices if there is a bufferedCommand and attempts determine locally
scoped variables by removing any functions from this.lines and evaling these
lines in a nested REPL e.g.
> asdf = function () {
… var inner = { one: 1};
… inn\t
will complete to 'inner' and inner.o\t will complete to 'inner.one'
If the nested REPL still has a bufferedCommand it will falls back to the
default.

ArrayStream is a helper class for the nested REPL to get commands pushed to it.
new REPLServer('', new ArrayStream());

Finally added two new REPL commands .save and .load, each takes 1 parameter,
a file and attempts to save or load the file to or from the REPL
respectively.
2011-11-12 11:34:55 -08:00
Fedor Indutny
9ad27f7853 ignore undefined messages in the debugger repl
fixes #1995
2011-11-02 15:55:36 -07:00
Nathan Rajlich
bdb9d09aef Print out undefined on the REPL when returned.
util.inspect() has a special case for "undefined", so it's nice to be able to
distinguish visually that undefined is the result of an expression.
2011-10-22 14:02:35 +09:00
isaacs
2d02e6a992 Add useGlobal flag for standard node repl 2011-10-21 13:02:49 -07:00
isaacs
caf70f5e94 Revert "Don't use a separate context for the repl."
This reverts commit b70fed48a7.
2011-10-21 13:00:37 -07:00
Nathan Rajlich
95d530f2b4 repl: print out undefined
util.inspect() has a special case for "undefined", so it's nice to be able to
distinguish visually that undefined is the result of an expression.
2011-10-20 08:41:33 -07:00
isaacs
b70fed48a7 Don't use a separate context for the repl.
Fix #1484
Fix #1834
Fix #1482
Fix #771

It's been a while now, and we've seen how this separate context thing
works.  It constantly confuses people, and no one actually uses '.clear'
anyway, so the benefit of that feature does not justify the constant
WTFery.

This makes repl.context actually be a getter that returns the global
object, and prints a deprecation warning.  The '.clear' command is gone,
and will report that it's an invalid repl keyword.  Tests updated to
allow the require, module, and exports globals, which are still
available in the repl just like they were before, by making them global.
2011-10-18 18:18:32 -07:00
Colton Baker
87286cc737 Fixed a lot of jslint errors.
Fixes #1831
2011-10-05 18:51:06 -07:00
Bert Belder
81425598db Enable console colors on windows by default 2011-09-27 13:03:29 -07:00
Fedor Indutny
67706b8bb7 Export disableColors from repl, share with debugger 2011-09-27 11:58:02 +02:00
Fedor Indutny
2010071339 readline: custom streams support 2011-09-23 13:42:41 -07:00
Fedor Indutny
1e37efb08b initial tests
* Don't buffer command, before it's execution (repl)
* `quit` command, custom streams for .start, stubbed out test, disable
  history repeation for non-tty (debugger)
2011-09-23 09:38:24 -07:00
Fedor Indutny
41a41825f6 micro-refactor, use rli.output.write instead of rli.write ('line' event was emitted for those writes) 2011-09-20 08:35:15 -07:00
Ryan Dahl
a1bafc5566 Merge remote branch 'origin/v0.4'
Conflicts:
	deps/http_parser/http_parser.c
	deps/http_parser/test.c
	lib/repl.js
2011-09-15 11:48:37 -07:00
isaacs
e06ce7562c Fix #1707 hasOwnProperty usage
If hasOwnProperty is overridden, then calling `obj.hasOwnProperty(prop)`
can fail.  Any time a dictionary of user-generated items is built, we
cannot rely on hasOwnProperty being safe, so must call it from the
Object.prototype explicitly.
2011-09-15 10:54:08 -07:00
isaacs
98990b9779 Fix #1707 hasOwnProperty usage 2011-09-15 09:46:30 -07:00
Fedor Indutny
57388d8b2e [repl] add error handling for async scope fetching 2011-09-13 20:40:21 -07:00
Fedor Indutny
df480e0357 fix syntax error handling for 'throw ...', fix return value assertion 2011-09-11 02:19:42 -07:00
Fedor Indutny
e13ed4a8d0 [repl, readline] refactor async completion and execution 2011-09-09 02:06:07 +07:00
Fedor Indutny
0d4dc3a8b5 [repl] let self.eval be configurable on REPLServer initialization 2011-09-09 02:06:06 +07:00
Fedor Indutny
eab65e214e [repl] Async global completion 2011-09-09 02:06:06 +07:00
Fedor Indutny
71a9aefa0f [readline, repl] Fix completion grouping, fix parens eval results
handling
2011-09-09 02:06:06 +07:00
Fedor Indutny
42b8b77d9f [repl, readline] async interface
Add async completion and execution interface for repl and readline
2011-09-09 02:06:06 +07:00
Nathan Rajlich
cf24f561a3 repl: don't eval twice when an Error is thrown 2011-09-01 17:15:07 +02:00
Nathan Rajlich
8ec31a3362 Use Object.getPrototypeOf() on the object in the REPL tab-completion.
Some people use __proto__ to augment an Object's prototype after it's been created.
This patch helps make the "new" prototype properties visible if necessary.

This is also more consistent with the while logic below.
2011-08-23 15:35:36 -07:00
Robert Mustacchi
de0b8d601c jslint cleanup: path.js, readline.js, repl.js, tls.js, tty_win32.js, url.js 2011-07-29 11:58:02 -07:00
isaacs
c050d0fa19 Finish removing require.paths
Fix require() completion bug in repl, and correct man output
2011-07-24 18:04:45 -07:00
isaacs
205b9beb6b Merge branch 'v0.4'
Conflicts:
	lib/tls.js
	lib/url.js
	src/node_version.h
	test/simple/test-buffer.js
	test/simple/test-url.js
2011-05-07 20:38:32 -07:00
isaacs
bbffd9e502 Close #983 Better JSON.parse error detection
Previous pattern would only catch ILLEGAL, not { or other
known-but-unexpected JSON tokens.
2011-04-26 09:48:28 -07:00
Tim Baumann
6c7c4aeab6 Don't overwrite an user-specified repl.writer 2011-04-21 12:26:27 -07:00
Wade Simmons
d00739ce56 make it possible to do repl.start('', stream) 2011-04-21 12:20:50 -07:00
isaacs
0b3ecc05a6 Close #955 Change ^C handling in REPL
Press with text on the line: Cancels
Press on a bare line: Print a message
Press again on a bare line: Exit
2011-04-21 12:17:21 -07:00
Ben Weaver
d63a551f86 Update how REPLServer uses contexts
* Always use `this.context` or `self.context`.
* Move `resetContext` to `REPLServer.createContext`.
* Add `REPLServer.resetContext`, memoize `context` here.
* Memoize `exports.repl` in `start`.

Closes GH-851.
2011-04-11 16:52:23 -07:00
Ryan Dahl
55048cdf79 Update copyright headers 2011-03-14 17:37:05 -07:00
isaacs
a48f73d0d3 Closes GH-232 Make the repl's global the right thing 2011-02-27 17:13:52 -08:00
isaacs
2cfe7b847d Closes GH-184 Clear require cache on repl .clear 2011-02-27 17:07:08 -08:00
isaacs
f07041e6cd Make the repl respect node_modules folders.
This is important so that in the future, this will work:

    $ cd ~/dev/js/some-project
    $ npm install redis
    $ node
    > require.resolve('redis')
    '/Users/isaacs/dev/js/some-project/node_modules/redis/index.js'
2011-02-14 13:43:22 -08:00
Ryan Dahl
192d2e0803 REPL: disable colors in windows for now 2011-01-28 12:58:19 -08:00
Ryan Dahl
9e976abad9 lint 2011-01-24 10:55:30 -08:00
Ryan Dahl
ba80d4d8a9 Transfer data gathering responsibility to readline
Fixes non-raw REPL/Debugger on Posix.
2011-01-19 11:46:16 -08:00
Bert Belder
4475b76535 Readline: use symbolic key names instead of ascii control codes 2011-01-18 23:22:38 -08:00
Ryan Dahl
5a05992155 Lint 2011-01-06 16:06:27 -08:00
Bert Belder
1ac133ea6f Replace string magic + path.join by path.resolve
Because path.resolve is more elegant and windows-safe.
2011-01-06 15:39:51 -08:00
Ryan Dahl
b6dafc1a47 Allow for two streams in REPL
Towards windows compatibility.
2011-01-06 13:42:32 -08:00
Ryan Dahl
feb77eab65 Fix REPL for named functions
add some tests.
2011-01-02 18:27:14 -08:00
Ryan Dahl
c82fe30ca1 repl.js style 2011-01-01 21:41:07 -08:00
Ryan Dahl
00974df3e5 Allow for evaling statements in REPL too 2011-01-01 21:05:23 -08:00
Ryan Dahl
b45698e676 Improve how REPL commands are evaled
Before:
> {a: 1}
1
> (function() {
...   // foo
...   return 1;
... })();
...

Now:
> {a: 1}
{ a : 1 }
> (function() {
...   // foo
...   return 1;
... })();
1
>
2011-01-01 17:54:48 -08:00
Brian White
6d75c06e64 Add os module to repl's built-in lib list 2010-12-16 17:37:00 -08:00
Brian White
e41e078159 Make sure REPL doesn't get borked when invalid REPL keywords are entered 2010-12-03 09:57:36 -08:00
Ryan Dahl
e232f6e735 more lint 2010-12-01 20:28:28 -08:00
Marco Rogers
118b88e44f update repl to distinguish JSON.parse SyntaxErrors from the rest 2010-11-20 20:36:14 -08:00
Brian White
5908bdab9a Make sure raw mode is disabled when exiting a terminal-based REPL. 2010-11-17 18:45:34 -08:00
Ryan Dahl
8e09b1e2e1 Simplify REPL displayPrompt
Now that we insert \r into the stream and aren't switching back and forth
between termios modes, not need to worry about when to display the prompt.
2010-11-12 14:39:42 -08:00
isaacs
bfc6b51d95 The cwdRequire hack is no longer necessary with the require.resolve refactor. 2010-10-20 15:22:02 -07:00
isaacs
226eff5104 Add require.resolve.
Also, hack the repl so that it works as expected there, too.
2010-10-20 12:12:07 -07:00
Sami Samhuri
56df0cbf93 new api for defining repl commands 2010-10-18 13:46:54 -07:00
Micheil Smith
e38eb0c5a4 Soft migration of sys -> util, Removal of deprecated utils module. 2010-10-11 15:21:36 -07:00
Ryan Dahl
783f5019b0 Add flag to disable colors in REPL 2010-10-09 12:46:06 -07:00
Sean Coates
ae87007478 add $ to variable name character matching patterns in repl completer 2010-10-09 10:04:13 -07:00
Joshaven Potter
3d4e4d8909 syntax fixes to pass jslint 2010-10-06 20:40:57 -07:00
Ryan Dahl
5829716649 Fix REPL crash on tabbing 'this.'
Thanks to Tim Becker for pointing this out.
2010-10-01 11:31:22 -07:00
Ryan Dahl
d2de8ba400 ^c to get out of '...' in REPL 2010-09-16 21:07:22 -07:00
Ryan Dahl
42eb5a6898 Simplify REPL 2010-09-16 20:50:56 -07:00
Trent Mick
1d961a6630 add ANSI coloring option to sys.inspect and, by default, to the repl 2010-09-08 09:47:13 -07:00
Trent Mick
293809b8b6 drop obsolete TODO comment 2010-08-18 23:02:54 -07:00
Trent Mick
5c1ffa165f repl completion: completion for arguments to "require" 2010-08-18 22:59:49 -07:00
Trent Mick
2134982ea4 repl completion: comment/TODO cleanup, no functional change 2010-08-18 22:59:35 -07:00
Trent Mick
1c9a85b9a6 First pass at tab-completion in the REPL 2010-08-11 13:42:45 -07:00
Blake Mizerany
8c8534046c fix whitespace errors 2010-06-29 23:59:24 -07:00
Ruben Rodriguez
242161bef2 Added new API to Script, and implemented it in the REPL 2010-06-28 15:16:26 -07:00
isaacs
e65e6039a8 Fix #169. Expose require members in the repl.
This fixes #169 by putting the require members onto the cwdRequire function
which is exposed to the repl scope.
2010-06-11 14:04:58 -07:00
Ryan Dahl
adc06dd705 Add NODE_NO_READLINE check for REPL
Setting this environmental variable to a non-zero integer will start all
REPL interfaces without readline. For use with rlwrap.
2010-06-08 15:44:43 -07:00
Ryan Dahl
a6942b345d Fix test-repl 2010-06-07 17:39:52 -07:00
Matt Ranney
09af242c89 Support more readline navigation keys. 2010-06-07 16:51:07 -07:00
Ryan Dahl
41f213be18 Add binding to termios, implement readline for repl 2010-06-07 15:24:21 -07:00
isaacs
a26f7d753d Make require() from the repl be relative to cwd 2010-05-29 12:35:30 -07:00
isaacs
82813f2f8c Execute repl code in new context 2010-05-29 12:33:55 -07:00
Ryan Dahl
e97a481785 Destroy REPL pipes instead of shutting down. 2010-05-24 17:14:13 -07:00
Matt Ranney
39464b498f Add docs for new REPL options and fill out description of commands. 2010-04-15 18:03:56 -07:00
Matt Ranney
b7441040f8 REPL can be run from multiple different streams.
e.g. from UNIX sockets with socat.
2010-04-12 00:31:51 -07:00
isaacs
57fbb627ca trailing whitespace fixes 2010-04-11 14:48:23 -07:00
isaacs
de9778b5bd Add line breaks to the code when the user types a line break 2010-04-08 08:12:30 -07:00
Ryan Dahl
fdf46a65c9 Use streams for stdout and stdin 2010-03-15 15:11:40 -07:00
elliottcable
52f088b966 Providing the option for a repl-printer other than sys.p 2010-01-05 00:14:03 -08:00
visionmedia
a650138ebf Moved help msg to node-repl 2010-01-04 22:06:18 -08:00
Ryan Dahl
7a2e784ad7 Module refactor - almost CommonJS compatible now
API change summary:

  * require("/sys.js") becomes require("sys")

  * require("circle.js") becomes require("./circle")

  * process.path.join() becomes require("path").join()
2009-10-31 19:10:30 +01:00
Ryan Dahl
ad0a4cefb8 Namespace EVERYTHING under process; introduce GLOBAL
http://groups.google.com/group/nodejs/browse_thread/thread/1034fd2ad2cd93e8
2009-10-29 23:36:41 +01:00
Ryan Dahl
2b8ab7e24f utils.js links to sys.js instead of other way around 2009-10-13 19:55:28 +02:00
Ryan Dahl
27738d8e60 Clean up some things in the repl, add docs. 2009-09-28 18:48:19 +02:00
Ryan Dahl
c27d9f986a include utils in the repl. 2009-09-28 18:48:18 +02:00
Ryan Dahl
7abad8b7b3 API: Move node.puts(), node.exec() and others to /utils.js 2009-09-28 12:06:30 +02:00
Ryan Dahl
4f69871c17 Add node.inspect() and deprecate p(). 2009-09-27 12:33:44 +02:00
RayMorgan
028e24c9f5 When printing, check to see if value is undefined. If so, print nothing. 2009-09-24 22:16:07 -07:00
RayMorgan
7674bd5004 Added _ that is te result of the previous command. 2009-09-24 19:53:11 -07:00
RayMorgan
6915188a46 Enhanced the repl library.
Now supports:
- command options: .help, .break, .clear, .exit
- local vars and global functions
- ability to print 0, false and ""
- when value is a function, prints [Function]
- when object is circular, prints [Circular Object] instead of throwing an error
2009-09-24 18:56:37 -07:00
Ryan Dahl
ffded5ac86 Extract the good parts of node-repl into standalone library.
Now you can require("/repl.js") in your server to be able to examine it
while it's running.
2009-09-24 00:56:24 +02:00