diff options
author | Maciej <sppmacd@pm.me> | 2022-03-07 18:11:13 +0100 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2022-03-08 07:47:24 -0500 |
commit | efd9c70d94980add804f1001331b05c5bda4b23b (patch) | |
tree | d89a58d5b41aaa26a9543ee80b2ca51df589e43a /Userland/Utilities/js.cpp | |
parent | 0706f0d487b59eb1abab7b54a7ba670c42d2abda (diff) | |
download | serenity-efd9c70d94980add804f1001331b05c5bda4b23b.zip |
js: Don't try to run empty scripts
When you try to run script containing only whitespace, it will return
undefined and doesn't do anything anyway. Let's match NodeJS behavior
and just don't display anything.
This only applies to REPL input and not to modules.
Diffstat (limited to 'Userland/Utilities/js.cpp')
-rw-r--r-- | Userland/Utilities/js.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index c9ec2e29b5..25423b4641 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -55,6 +55,7 @@ #include <LibJS/Runtime/ShadowRealm.h> #include <LibJS/Runtime/Shape.h> #include <LibJS/Runtime/StringObject.h> +#include <LibJS/Runtime/StringPrototype.h> #include <LibJS/Runtime/Temporal/Calendar.h> #include <LibJS/Runtime/Temporal/Duration.h> #include <LibJS/Runtime/Temporal/Instant.h> @@ -1273,8 +1274,9 @@ static void repl(JS::Interpreter& interpreter) { while (!s_fail_repl) { String piece = read_next_piece(); - if (piece.is_empty()) + if (Utf8View { piece }.trim(JS::whitespace_characters).is_empty()) continue; + repl_statements.append(piece); parse_and_run(interpreter, piece, "REPL"); } |