joyent/node — pull request #5278 by seebees (2013-04-11 14:46:16+00:00)
Title: REPL should not capture aborted statements

The "memory" for the REPL was "saved" even in the case of a `bufferedCommand`. This causes `.save` to write out aborted multi-line statements e.g.

```
>var top = function() {
>.. var something = 1;
>.. CTRL-C
```

This is a problem in two cases.
1. The REPL will save these lines and write them out during the `.save` function
2. The REPL will remember these lines and potentially inject nonexistent variables into other local tab completions.

The basic fix is to move the `memory` call from the top of `finish` to below the bufferedCommand check.

The fallout was to remove the side effects from the `memory` function. So it could be used in the `complete` function to append the `bufferedCommand`.

I also updated the nested "magic" REPL to pass the useGlobal:false param instead of injecting my own context.

This should fix #4514

The part I really don't like about this is I don't know how to test the CTRL-C business. I wanted to append a test to `.save` that would verify that the first part, but I can't figure out how to send it... `'\x03'` does not work :(. If anyone could give me suggestions I'll write the two tests and all will be right with the world.