Commit graph

1125 commits

Author SHA1 Message Date
Linus Groh
0f5d1f4074 js: Load and save history from/to ~/.js-history
This is super useful when hacking on LibJS and in general :^)
2020-10-26 11:27:54 +01:00
asynts
1254cbbd0b AK: Eradicate calls to warn(). 2020-10-25 18:52:51 +01:00
asynts
a5f5c3fd33 LibC+Tests: Fix broken snprintf test.
`snprintf` returns the number of characters that would have been written
had the buffer been large enough.

It's a common trick to call `snprintf(nullptr, 0, ...)` to measure how
large a buffer has to be.

Thus the return value is not zero but fourteen.
2020-10-25 18:52:51 +01:00
Matthew L. Curry
212aa85a55 Userland/sort: Convert sort to use getline
Sort uses a statically sized buffer. This commit changes that to use getline,
so lines of any size will be handled properly.
2020-10-25 14:37:48 +01:00
Matthew L. Curry
0c2327b5b8 Userland/uniq: Add uniq utility
Add an implementation for uniq. While it will be nice in the future to
make more hardened versions of sort and uniq in the future, this
implementation of uniq is compatible with the current version of sort
and its buffer sizes.

This version supports optional input and output files along with stdin
and stdout.
2020-10-25 14:37:39 +01:00
Linus Groh
82956a08b3 LibCore: Rename File::ShouldCloseFile{Description => Descriptor}
From https://youtu.be/YNSAZIW3EM0?t=1474:

"Hmm... I don't think that name is right! From the perspective of
userspace, this is a file descriptor. File description is what the
kernel internally keeps track of, but as far as userspace is concerned,
he just has a file descriptor. [...] Maybe that name should be changed."

Core::File even has a member of this enum type... called
m_should_close_file_descriptor - so let's just rename it :^)
2020-10-25 13:59:41 +01:00
Andreas Kling
ace15e0043 Userland: Add missing license header to hexdump 2020-10-25 10:22:34 +01:00
Andreas Kling
201d34f6cd Userland: Add a very simple hexdump program :^)
This can definitely be improved, but it does the basic job!
2020-10-25 10:12:03 +01:00
asynts
88bca152c9 AK: Eradicate the uses of out(). 2020-10-24 12:56:25 +02:00
Wesley Moore
5ee7e9ab64 rm: Exit with status 0 if stat fails and force is set 2020-10-23 09:39:30 +02:00
Andreas Kling
46c15276e9 LibWeb: Fix Document construction mishap in <template> element
Ref-counted objects must not be stack allocated. Make DOM::Document's
constructor private to avoid this issue. (I wish we could mark classes
as heap-only..)
2020-10-23 08:33:16 +02:00
AnotherTest
5b72d17ff6 Userland: Make man provide a view_width to `render_for_terminal()'
This makes tables actually show up when rendered through `man'
2020-10-22 17:49:03 +02:00
Tom
6413acd78c AK: Make Utf8View and Utf32View more consistent
This enables use of these classes in templated code.
2020-10-22 15:23:45 +02:00
Andreas Kling
50f8f27ac6 Userland: Run clang-format on tree.cpp 2020-10-20 19:19:30 +02:00
Andreas Kling
633b6fbc48 Userland: Use new format functions in some programs 2020-10-20 18:08:37 +02:00
Lenny Maiorani
d1fe6a0b53
Everywhere: Redundant inline specifier on constexpr functions (#3807)
Problem:
- `constexpr` functions are decorated with the `inline` specifier
  keyword. This is redundant because `constexpr` functions are
  implicitly `inline`.
- [dcl.constexpr], §7.1.5/2 in the C++11 standard): "constexpr
  functions and constexpr constructors are implicitly inline (7.1.2)".

Solution:
- Remove the redundant `inline` keyword.
2020-10-20 18:08:13 +02:00
Linus Groh
ed116636ce test-js: Support test262 parser tests
test-js now has a --test262-parser-tests option. Modules are skipped for
now, current results:

    Test Suites: 1309 failed, 4314 passed, 5623 total
    Tests:       1309 failed, 262 skipped, 4052 passed, 5623 total
    Files:       5361 total
    Time:        ~100ms (Lagom) / 600-800ms (Serenity)

For more info, see: https://github.com/tc39/test262-parser-tests
2020-10-19 11:29:55 +02:00
Linus Groh
3a72a93b9d test-js: Exit with 1 if any test failed 2020-10-19 11:29:55 +02:00
Linus Groh
03b817b130 test-js: Include skipped tests in total test count
The current output is a bit strange:

    Tests:       3 skipped, 979 passed, 979 total

This makes more sense to me:

    Tests:       3 skipped, 979 passed, 982 total
2020-10-19 11:29:55 +02:00
Linus Groh
cce673e7b0 test-js: Add argument for explicit test root directory
Right now test-js has a hardcoded test root directory when running on
Serenity or will get it based on SERENITY_ROOT otherwise. Now it is
also possible to pass a path to the command which will take precedence
over these mechanisms.

This will also be useful for adding test262 support as those files will
not have a default location.
2020-10-19 11:29:55 +02:00
Nico Weber
0658051996 ntpquery: Add some more validation of the response header 2020-10-17 23:19:14 +02:00
Nico Weber
18d88e0eaa ntpquery: For stratum 1 servers, print reference ID in ASCII with -v 2020-10-17 23:19:14 +02:00
Nico Weber
52e3a0f16c ntpquery: Add a comment listing a few more NTP servers 2020-10-17 23:19:14 +02:00
Nico Weber
5f50af3b4f ntpquery: Don't leak local time, and check origin time in reply
This implements the transmit time suggestion in (abandoned?)
draft-ietf-ntp-data-minimization. (The other suggestions were already
implemented as far as I can tell.)
2020-10-17 23:19:14 +02:00
Nico Weber
019788a150 ntpquery: Make a few variable names more descriptive 2020-10-17 23:19:14 +02:00
Matthew L. Curry
a45ba638a7 seq: Add help option
Added a help option to the seq command that gives usage information. Further,
when a user gives an incorrect argument, usage is supplied on stderr.
2020-10-15 13:48:42 +02:00
nooga
7b481a2c73 Userland: Add --loop option for aplay
A tiny feature, useful when listening to your favorite song.
2020-10-15 13:47:42 +02:00
Andreas Kling
7b863330dc LibJS: Cache commonly used FlyStrings in the VM
Roughly 7% of test-js runtime was spent creating FlyStrings from string
literals. This patch frontloads that work and caches all the commonly
used names in LibJS on a CommonPropertyNames struct that hangs off VM.
2020-10-13 23:57:45 +02:00
Matthew L. Curry
909687ddf0 Userland/cp: Disallow copying directories into themselves
This patch causes cp to investigate whether a directory is being copied
into a subdirectory of itself. It uses realpath(3) to ensure that links
do not confound detection.
2020-10-13 18:37:32 +02:00
Matthew L. Curry
5d5c32cec1 Style: Remove uses of NULL, substituting nullptr 2020-10-13 13:52:52 +02:00
Linus Groh
fb13ea2259 js: Print negative zero with minus sign 2020-10-12 20:03:54 +02:00
Linus Groh
f0ba536095 html: Replace InProcessWebView with OutOfProcessWebView 2020-10-08 23:20:52 +02:00
Linus Groh
4ef3a55900 html: Create URL from filename, if any
This makes it possible for the WebView to resolve relative paths in
documents loaded from a file.
2020-10-08 23:20:52 +02:00
Nico Weber
f5af127887 ntpquery: Make output less verbose by default 2020-10-05 23:48:33 +02:00
Linus Groh
e80217a746 LibJS: Unify syntax highlighting
So far we have three different syntax highlighters for LibJS:

- js's Line::Editor stylization
- JS::MarkupGenerator
- GUI::JSSyntaxHighlighter

This not only caused repetition of most token types in each highlighter
but also a lot of inconsistency regarding the styling of certain tokens:

- JSSyntaxHighlighter was considering TokenType::Period to be an
  operator whereas MarkupGenerator categorized it as punctuation.
- MarkupGenerator was considering TokenType::{Break,Case,Continue,
  Default,Switch,With} control keywords whereas JSSyntaxHighlighter just
  disregarded them
- MarkupGenerator considered some future reserved keywords invalid and
  others not. JSSyntaxHighlighter and js disregarded most

Adding a new token type meant adding it to ENUMERATE_JS_TOKENS as well
as each individual highlighter's switch/case construct.

I added a TokenCategory enum, and each TokenType is now associated to a
certain category, which the syntax highlighters then can use for styling
rather than operating on the token type directly. This also makes
changing a token's category everywhere easier, should we need to do that
(e.g. I decided to make TokenType::{Period,QuestionMarkPeriod}
TokenCategory::Operator for now, but we might want to change them to
Punctuation.
2020-10-04 23:41:31 +02:00
Andreas Kling
94b95a4924 LibJS: Remove Interpreter::call()
Just use VM::call() directly everywhere.
2020-10-04 23:08:49 +02:00
asynts
d5ffb51a83 AK: Don't add newline for outf/dbgf/warnf.
In the future all (normal) output should be written by any of the
following functions:

    out    (currently called new_out)
    outln
    dbg    (currently called new_dbg)
    dbgln
    warn   (currently called new_warn)
    warnln

However, there are still a ton of uses of the old out/warn/dbg in the
code base so the new functions are called new_out/new_warn/new_dbg. I am
going to rename them as soon as all the other usages are gone (this
might take a while.)

I also added raw_out/raw_dbg/raw_warn which don't do any escaping,
this should be useful if no formatting is required and if the input
contains tons of curly braces. (I am not entirely sure if this function
will stay, but I am adding it for now.)
2020-10-04 17:04:55 +02:00
Andreas Kling
a007b3c379 LibJS: Move "strict mode" state to the call stack
Each call frame now knows whether it's executing in strict mode.
It's no longer necessary to access the scope stack to find this mode.
2020-10-04 17:03:33 +02:00
Peter Elliott
1b3f9c170c Userland: tar: support extracting gzipped files 2020-10-04 00:16:40 +02:00
Peter Elliott
b7c7c80ee2 Userland: Add tar command 2020-10-04 00:16:40 +02:00
Linus Groh
bcfc6f0c57 Everywhere: Fix more typos 2020-10-03 12:36:49 +02:00
Tibor Nagy
422cb50e4e Userland: Fix buffer overflow in unzip
It's not a great idea reading file names into a 4 byte sized buffer.
2020-10-01 21:15:35 +02:00
Andreas Kling
e4bda2e1e7 LibJS: Move Console from Interpreter to GlobalObject
Each JS global object has its own "console", so it makes more sense to
store it in GlobalObject.

We'll need some smartness later to bundle up console messages from all
the different frames that make up a page later, but this works for now.
2020-09-29 21:15:06 +02:00
Andreas Kling
2946a684ef ProtocolServer+LibWeb: Support more detailed HTTP requests
This patch adds the ability for ProtocolServer clients to specify which
HTTP method to use, and also to include an optional HTTP request body.
2020-09-28 11:55:26 +02:00
Benoît Lormeau
f0f6b09acb AK: Remove the ctype adapters and use the actual ctype functions instead
This finally takes care of the kind-of excessive boilerplate code that were the
ctype adapters. On the other hand, I had to link `LibC/ctype.cpp` to the Kernel
(for `AK/JsonParser.cpp` and `AK/Format.cpp`). The previous commit actually makes
sense now: the `string.h` includes in `ctype.{h,cpp}` would require to link more LibC
stuff to the Kernel when it only needs the `_ctype_` array of `ctype.cpp`, and there
wasn't any string stuff used in ctype.
Instead of all this I could have put static derivatives of `is_any_of()` in the
concerned AK files, however that would have meant more boilerplate and workarounds;
so I went for the Kernel approach.
2020-09-27 21:15:25 +02:00
Benoit Lormeau
f158cb27ea LibC: Remove an unneeded string.h include in ctype.h/cpp
And include string.h in the files that actually needed it
2020-09-27 21:15:25 +02:00
AnotherTest
aa65f664a9 LibMarkdown: Take a 'view_width' argument for render_for_terminal()
Some constructs will require the width of the terminal (or a general
'width') to be rendered correctly, such as tables.
2020-09-27 21:14:18 +02:00
Andreas Kling
aaa8b48a4c LibJS: Remove use of Interpreter& in JSONObject code 2020-09-27 20:26:58 +02:00
Andreas Kling
340a115dfe LibJS: Make native function/property callbacks take VM, not Interpreter
More work on decoupling the general runtime from Interpreter. The goal
is becoming clearer. Interpreter should be one possible way to execute
code inside a VM. In the future we might have other ways :^)
2020-09-27 20:26:58 +02:00
Andreas Kling
6861c619c6 LibJS: Move most of Interpreter into VM
This patch moves the exception state, call stack and scope stack from
Interpreter to VM. I'm doing this to help myself discover what the
split between Interpreter and VM should be, by shuffling things around
and seeing what falls where.

With these changes, we no longer have a persistent lexical environment
for the current global object on the Interpreter's call stack. Instead,
we push/pop that environment on Interpreter::run() enter/exit.
Since it should only be used to find the global "this", and not for
variable storage (that goes directly into the global object instead!),
I had to insert some short-circuiting when walking the environment
parent chain during variable lookup.

Note that this is a "stepping stone" commit, not a final design.
2020-09-27 20:26:58 +02:00