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.
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
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.
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
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.
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.
Before this, entering something like:
> JSON.parse('066');
resulted in the "..." prompt instead of displaying the expected
"SyntaxError: Unexpected number"
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.
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.
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.
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.
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.
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.
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).
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.
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.
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
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.
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
- 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
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.
Fix#1484Fix#1834Fix#1482Fix#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.
* 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)
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.