Skip to content

Commit 3364ddf

Browse files
authored
Merge pull request #276 from Distributive-Network/wes/pmjs-regressions-276
pmjs - fix .python command, peter-jr - fix sigint
2 parents 59a180f + face689 commit 3364ddf

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

peter-jr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ findTests \
142142
| (shuf 2>/dev/null || cat) \
143143
| while read file
144144
do
145+
trap 'echo -e "\nAborted." >&2; exit 130' 2
145146
printf "Testing %-${longestFilenameLen}s ... " "${file}"
146147
ext="${file##*.}"
147148
testName="${file%.failing}"
@@ -168,7 +169,7 @@ findTests \
168169
exitCode="$?"
169170
;;
170171
"bash")
171-
eval timeout -s9 "${timeout:-${defaultTimeout}}" bash \"$file\"
172+
eval timeout -s9 --foreground "${timeout:-${defaultTimeout}}" bash \"$file\"
172173
exitCode="$?"
173174
;;
174175
*)

python/pythonmonkey/cli/pmjs.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
3636
cmds.exit = python.exit;
3737
cmds.python = function pythonCmd(...args) {
38+
var retval;
3839
const cmd = args.join(' ').trim();
3940
4041
if (cmd === 'reset')
@@ -46,23 +47,20 @@
4647
}
4748
4849
if (cmd === '')
49-
{
5050
return;
51-
}
52-
53-
try {
51+
52+
try
53+
{
5454
if (arguments[0] === 'from' || arguments[0] === 'import')
55-
{
5655
return python.exec(cmd);
57-
}
58-
59-
const retval = python.eval(cmd);
56+
retval = python.eval(cmd);
6057
}
61-
catch(error) {
58+
catch(error)
59+
{
6260
globalThis._error = error;
6361
return util.inspect(error);
6462
}
65-
63+
6664
pythonCmd.serial = (pythonCmd.serial || 0) + 1;
6765
globalThis['$' + pythonCmd.serial] = retval;
6866
python.stdout.write('$' + pythonCmd.serial + ' = ');
@@ -72,7 +70,7 @@
7270
/**
7371
* Handle a .xyz repl command. Invokes function cmds[XXX], passing arguments that the user typed as the
7472
* function arguments. The function arguments are space-delimited arguments; arguments surrounded by
75-
* quotes can include spaces, similar to how bash parses arguments. Argument parsing cribbed from
73+
* quotes can include spaces, similar to how bash parses arguments. Argument parsing cribbed from
7674
* stackoverflow user Tsuneo Yoshioka, question 4031900.
7775
*
7876
* @param {string} cmdLine the command the user typed, without the leading .
@@ -107,9 +105,9 @@
107105
var result;
108106
var mightBeObjectLiteral = false;
109107
110-
/* A statement which starts with a { and does not end with a ; is treated as an object literal,
108+
/* A statement which starts with a { and does not end with a ; is treated as an object literal,
111109
* and to get the parser in to Expression mode instead of Statement mode, we surround any expression
112-
* like that which is also a valid compilation unit with parens, then if that is a syntax error,
110+
* like that which is also a valid compilation unit with parens, then if that is a syntax error,
113111
* we re-evaluate without the parens.
114112
*/
115113
if (/^\\s*\\{.*[^;\\s]\\s*$/.test(statement))
@@ -152,7 +150,7 @@ def repl():
152150
Start a REPL to evaluate JavaScript code in the extra-module environment. Multi-line statements and
153151
readline history are supported. ^C support is sketchy. Exit the REPL with ^D or ".quit".
154152
"""
155-
153+
156154
print('Welcome to PythonMonkey v' + pm.__version__ +'.')
157155
print('Type ".help" for more information.')
158156
readline.parse_and_bind('set editing-mode emacs')
@@ -167,7 +165,7 @@ def repl():
167165
statement = ''
168166
readline_skip_chars = 0
169167
inner_loop = False
170-
168+
171169
def save_history():
172170
nonlocal histfile
173171
readline.write_history_file(histfile)
@@ -240,7 +238,7 @@ def sigint_handler(signum, frame):
240238
if (statement == ""):
241239
statement = input('> ')[readline_skip_chars:]
242240
readline_skip_chars = 0
243-
241+
244242
if (len(statement) == 0):
245243
continue
246244
if (statement[0] == '.'):
@@ -291,7 +289,7 @@ def usage():
291289
-v, --version print PythonMonkey version
292290
--use-strict evaluate -e, -p, and REPL code in strict mode
293291
--inspect enable pmdb, a gdb-like JavaScript debugger interface
294-
292+
295293
Environment variables:
296294
TZ specify the timezone configuration
297295
PMJS_PATH ':'-separated list of directories prefixed to the module search path
@@ -322,7 +320,7 @@ def main():
322320
forceRepl = False
323321
globalInitModule = initGlobalThis()
324322
global requirePath
325-
323+
326324
try:
327325
opts, args = getopt.getopt(sys.argv[1:], "hie:p:r:v", ["help", "eval=", "print=", "require=", "version", "interactive", "use-strict", "inspect"])
328326
except getopt.GetoptError as err:

0 commit comments

Comments
 (0)