Commit graph

4896 commits

Author SHA1 Message Date
Brendan Coles
d4c34d50c9 LibChess: Forbid King moving into check by a pawn on the home rank
A player can no longer move the King piece into any position on
their home rank if the move would place the King in check.

A player can also no longer ignore a check position when in check
by a pawn on their home rank. The player must now resolve the check
during their move.
2020-10-30 16:51:41 +01:00
Andreas Kling
23c4f10027 LibGUI: Add TextDocument::span_at(TextPosition) 2020-10-29 23:52:07 +01:00
Andreas Kling
77e9eadd9d Userland+LibC: Add "kill -l" to show all known signal names/numbers 2020-10-29 23:32:18 +01:00
Andreas Kling
662959b173 LibC: Use NSIG instead of hard-coding 32 as the signal count 2020-10-29 23:32:18 +01:00
Linus Groh
69845ae460 LibJS: "-->" preceded by token on same line isn't start of HTML-like comment
B.1.3 HTML-like Comments

The syntax and semantics of 11.4 is extended as follows except that this
extension is not allowed when parsing source code using the goal symbol
Module:

Syntax (only relevant part included)

    SingleLineHTMLCloseComment ::
        LineTerminatorSequence HTMLCloseComment

    HTMLCloseComment ::
        WhiteSpaceSequence[opt] SingleLineDelimitedCommentSequence[opt] --> SingleLineCommentChars[opt]

Fixes #3810.
2020-10-29 22:28:15 +01:00
Linus Groh
a10d09faba LibJS: Tweak generated source in 'new Function()' to match ES 2015 spec
ES 5(.1) described parsing of the function body string as:

https://www.ecma-international.org/ecma-262/5.1/#sec-15.3.2.1

7. If P is not parsable as a FormalParameterList[opt] then throw a SyntaxError exception.
8. If body is not parsable as FunctionBody then throw a SyntaxError exception.

We implemented it as building the source string of a complete function
and feeding that to the parser, with the same outcome. ES 2015+ does
exactly that, but with newlines at certain positions:

https://tc39.es/ecma262/#sec-createdynamicfunction

16. Let bodyString be the string-concatenation of 0x000A (LINE FEED), ? ToString(bodyArg), and 0x000A (LINE FEED).
17. Let prefix be the prefix associated with kind in Table 49.
18. Let sourceString be the string-concatenation of prefix, " anonymous(", P, 0x000A (LINE FEED), ") {", bodyString, and "}".

This patch updates the generated source string to match these
requirements. This will make certain edge cases work, e.g.
'new Function("-->")', where the user supplied input must be placed on
its own line to be valid syntax.
2020-10-29 22:27:55 +01:00
asynts
607931268e CMake: Use CONFIGURE_DEPENDS in existing globs. 2020-10-29 11:52:47 +01:00
Linus Groh
3dbf4c62b0 LibJS: Use GenericLexer for Token::string_value()
This is, and I can't stress this enough, a lot better than all the
manual bounds checking and indexing that was going on before.

Also fixes a small bug where "\u{}" wouldn't get rejected as invalid
unicode escape sequence.
2020-10-29 11:52:31 +01:00
Andreas Kling
ad0295d033 LibC: Move getsignalbyname() helper from Userland/kill into LibC 2020-10-29 11:49:24 +01:00
Andreas Kling
d27a8e505f LibGUI: IconView was hard-coding column 0 instead of model_column()
Some of the indexes generated during cursor movement were using column
instead of model_column(), which caused inconsistent display of items
under the cursor.
2020-10-28 21:41:51 +01:00
Andreas Kling
de3dc15a6e LibGUI: Default-initialize cursor when focusing an AbstractView
If an AbstractView receives focus without a valid cursor index, we now
ask it to move its cursor to the home position. This way, the user can
actually start moving the cursor after tabbing to a view.
2020-10-28 21:40:31 +01:00
Andreas Kling
1f789a07b1 LibGUI: Don't start AbstractView type-ahead search with tab key
This was preventing views from relinquishing focus via the keyboard.

Fixes #3862.
2020-10-28 21:26:27 +01:00
Andreas Kling
80e12999c4 LibGUI: Model-less views should not swallow key events
At least pass them up to GUI::Widget so they can be handled there.
2020-10-28 21:26:27 +01:00
Linus Groh
b5bd05b717 LibJS: Don't parse numeric literal containing 8 or 9 as octal
If the value has a leading zero (allowed in non-strict mode) but
contains the digits 8 or 9 it can't be an octal number.
2020-10-28 21:11:32 +01:00
Linus Groh
b4e51249e9 LibJS: Always insert semicolon after do-while statement if missing
https://tc39.es/ecma262/#sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions

11.9.1: In ECMAScript 2015, Automatic Semicolon Insertion adds a
semicolon at the end of a do-while statement if the semicolon is
missing. This change aligns the specification with the actual behaviour
of most existing implementations.
2020-10-28 21:11:32 +01:00
Linus Groh
d278f61f4c LibJS: Restrict toEval() failures to SyntaxError
We only use expect(...).toEval() / not.toEval() for checking syntax
errors, where we obviously can't put the code in a regular function. For
runtime errors we do exactly that, so toEval() should not fail - this
allows us to use undefined identifiers in syntax tests.
2020-10-28 21:11:32 +01:00
Andreas Kling
3ec19ae4b6 LibGUI+LibGfx+WindowServer: Auto-generate disabled action icons :^)
This patch adds a simple filter that makes button and menu item icons
have that "'90s disabled" look when disabled. It's pretty awesome.
2020-10-27 21:25:40 +01:00
Andreas Kling
ea14c67e29 LibGUI: Make TreeView use the view cursor properly
TreeView was still partly sticking to the pre-cursor way of using the
first index in the selection as the implied cursor. This patch fixes
all of the TreeView code to operate on the cursor instead.

This makes trees behave much more intuitively when alternating between
mouse and keyboard interaction.
2020-10-27 21:00:12 +01:00
Andreas Kling
0391806eec LibGUI: Shrink the default selection rect of TreeView items
Instead of filling the whole row with selection color, only fill behind
the text. This gives a snugger, more focused appearance.

For embedders that want the entire row to get filled with the selection
color when selected, they can opt in to the old behavior by calling
TreeView::set_should_fill_selected_rows(). This is used by Profiler.
2020-10-27 20:33:30 +01:00
Andreas Kling
df98c9ebbe LibGUI: Run clang-format on TableView.cpp 2020-10-27 20:21:51 +01:00
Andreas Kling
f7d8174bee LibGUI: Paint a focus rect around the cursor index in ColumnsView 2020-10-27 16:20:20 +01:00
Andreas Kling
c0076681ad LibGUI: Paint a focus rect around the cursor index in TableView 2020-10-27 16:18:55 +01:00
Andreas Kling
5030f1ed4b LibGUI: Paint a focus rect around the cursor index in IconView
This makes the cursor actually visible to the user, and looks rather
neat if I may say so. :^)
2020-10-27 16:12:54 +01:00
Andreas Kling
272af7685b LibGUI: Improve and simplify IconView item name wrapping
Move the wrapping logic to get_item_rects(). This makes mouse events
able to hit the wrapped labels, and various other little things stop
glitching out as well.

Also, instead of having a per-line width when wrapping icon names,
make the text rect wide enough to fit every line.
2020-10-27 16:10:30 +01:00
Linus Groh
7112031bfb LibJS: Use message from invalid token in syntax error 2020-10-26 21:38:34 +01:00
Linus Groh
6a3389cec6 LibJS: Emit token message for invalid numeric literals 2020-10-26 21:38:34 +01:00
Linus Groh
19edcbd79c LibJS: Emit TokenType::Invalid for unterminated multi-line comments 2020-10-26 21:38:34 +01:00
Linus Groh
03c1d43f6e LibJS: Add message string to Token
This allows us to communicate details about invalid tokens to the parser
without having to invent a bunch of specific invalid tokens like
TokenType::InvalidNumericLiteral.
2020-10-26 21:38:34 +01:00
Andreas Kling
4bc8768737 LibGUI: Tint selected icons in {Icon,Table,Columns}View
Add a gentle tint to selected icons based on the selection color. :^)
2020-10-26 21:32:27 +01:00
Andreas Kling
d172783d33 LibGUI: Fix bogus focus rect in buttons with icon but no text 2020-10-26 21:08:01 +01:00
Andreas Kling
06b5d292d7 LibGUI: Allow activating a focused button by pressing the space key :^)
This applies to normal push buttons, checkboxes, and radio buttons.
It feels very natural. Even moreso than activating with return..
2020-10-26 21:01:45 +01:00
Andreas Kling
b7dfa83223 LibGUI+LibGfx: Improve focus rect appearance
Draw a dotted focus rect to make it stand out more. Also make it much
larger on regular text-only GUI::Buttons.
2020-10-26 21:01:45 +01:00
Andreas Kling
f6084d42d9 LibGUI: Call up to the correct base class in GUI::AbstractView 2020-10-26 21:01:45 +01:00
Andreas Kling
f57c058c5e LibGUI: Call up to the correct base class in GUI::TextEditor 2020-10-26 21:01:45 +01:00
Andreas Kling
4e1dabeb15 LibGUI: Tweak "OK" button height in GUI::AboutDialog 2020-10-26 21:01:45 +01:00
Linus Groh
9735879318 LibMarkdown: Don't parse lines starting with a space as heading
This fixes a bug where lines starting with a space would get parsed as
"level 0" headings - it would not find a "#" and therefore never
increase the level counter (starting at zero), which then would cause
the check for "space after #" pass (again, there is no "#").

Eventually we would get funny results like this:

    <h0>[n-1 spaces]oops!</h0>

Also ASSERT(level > 0) in the Heading constructor.
2020-10-26 19:13:19 +01:00
Nico Weber
63dcd59fa5 LibGfx: Make Color formattable 2020-10-26 18:55:36 +01:00
Linus Groh
d412fbdcf3 Shell+LibLine: Support HISTCONTROL environment variable
This is implemented in Line::Editor meaning not only the Shell will
respect it, but also js, Debugger etc.

Possible values are "ignorespace", "ignoredups" and "ignoreboth", as
documented in Shell-vars(7), for now.

The default value for the anon user (set in .shellrc) is "ignoreboth".
2020-10-26 11:27:54 +01:00
Linus Groh
b2e4fe1299 Shell+LibLine: Move Shell::{load,save}_history() to Line::Editor
This allows us to easily re-use history loading and saving in other
programs using Line::Editor, as well as implementing universally
recognized HISTCONTROL.
2020-10-26 11:27:54 +01:00
AnotherTest
af05671843 LibMarkdown: Flush the pending paragraphs when encountering empty lines
Fixes #3854.
2020-10-26 09:36:12 +01:00
Luke
63a94deb43 LibTLS: Treat a close_notify before agreeing on a cipher suite as a handshake failure
Some TLS implementations (namely, AWS CloudFront) do this instead of
sending handshake_failure for some reason.
2020-10-26 08:59:57 +01:00
Andreas Kling
9d347352a1 LibGfx+LibGUI+Clients: Make fonts findable by their qualified name
The qualified name of a font is "<Family> <Size> <Weight>". You can
get the QN of a Font via the Font::qualified_name() API, and you can
get any system font by QN from the GUI::FontDatabase. :^)
2020-10-25 21:18:18 +01:00
Linus Groh
66e315959d LibJS: Allow all line terminators to be used for line continuations 2020-10-25 19:45:47 +01:00
Andreas Kling
7b638e2d0d LibGUI: Make the Cancel/Okay buttons in GUI::FilePicker a little taller 2020-10-25 15:36:09 +01:00
Andreas Kling
8b12d200ba LibGUI: Raise toolbar button icons slightly when hovered :^)
This make buttons look extra clickable when hovered by lifting up their
icons (-1,-1) and painting a little icon-shaped shadow under them.

Partially inspired by the Office XP toolbars, although we don't go all
the way with the faux-hyperlink stuff that was all the rage back then.
2020-10-25 15:32:19 +01:00
Marcin Gasperowicz
e5ddcadd3c LibJS: Parse line continuations in string literals properly
Newlines after line continuation were inserted into the string 
literals. This patch makes the parser ignore the newlines after \ and
also makes it so that "use strict" containing a line continuation is 
not a valid "use strict".
2020-10-25 15:16:47 +01:00
Andreas Kling
387607503c LibCore: IODevice::can_read_line() should succeed for newline-less file
If the first call to populate_read_buffer() hits EOF but something did
get buffered, we can indeed read a line.
2020-10-25 14:38:07 +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
Linus Groh
dca9e4ec10 LibJS: Implement rules for duplicate function parameters
- A regular function can have duplicate parameters except in strict mode
  or if its parameter list is not "simple" (has a default or rest
  parameter)
- An arrow function can never have duplicate parameters

Compared to other engines I opted for more useful syntax error messages
than a generic "duplicate parameter name not allowed in this context":

    "use strict"; function test(foo, foo) {}
                                     ^
    Uncaught exception: [SyntaxError]: Duplicate parameter 'foo' not allowed in strict mode (line: 1, column: 34)

    function test(foo, foo = 1) {}
                       ^
    Uncaught exception: [SyntaxError]: Duplicate parameter 'foo' not allowed in function with default parameter (line: 1, column: 20)

    function test(foo, ...foo) {}
                          ^
    Uncaught exception: [SyntaxError]: Duplicate parameter 'foo' not allowed in function with rest parameter (line: 1, column: 23)

    (foo, foo) => {}
          ^
    Uncaught exception: [SyntaxError]: Duplicate parameter 'foo' not allowed in arrow function (line: 1, column: 7)
2020-10-25 12:56:02 +01:00
Andreas Kling
b1eeb15129 LibGfx: Handle TextAlignment::BottomRight in do_draw_text() 2020-10-25 11:50:38 +01:00