Commit Graph

9774 Commits

Author SHA1 Message Date
Linus Groh
78fd8c1ca2 LibJS: Make escape_regexp_pattern() a RegExpObject member function
Similarly to regexp_initialize() this can be a member function instead
of taking a RegExpObject argument.
Having it available outside RegExpPrototype is also useful for other
things that need RegExp.prototype.source behavior - e.g. the REPL for
pretty-printing.
2021-10-05 18:35:49 +01:00
Andreas Kling
83bd675477 LibJS: Make WeakContainer pruning do less work
Instead of iterating *all* swept cells when pruning weak containers,
only iterate the cells actually *in* the container.

Also, instead of compiling a list of all swept cells, we can simply
check the Cell::state() flag to know if something should be pruned.
2021-10-05 18:52:00 +02:00
Sam Atkins
050823bea7 LibWeb: Fire MediaQueryListEvents when an MQL's match-state changes
The HTML event loop does a check for MQL match-state changes and
dispatches the events. This requires us to keep a list of MQLs on the
Document.
2021-10-05 18:51:39 +02:00
Sam Atkins
1c829e0417 LibWeb: Implement MediaQuery matching :^)
Currently, `evaluate()` recalculates whether the MediaQuery matches or
not, and stores it in `m_matches`, which users can query using
`matches()`. This allows us to know when the match-state changes, which
is required to fire MediaQueryList's change event.
2021-10-05 18:51:39 +02:00
Sam Atkins
f354fd72f1 LibWeb: Split Length::absolute_length_to_px() out from to_px()
In cases where we know the Length is absolute, we know we don't need to
pass in a Layout::Node or FontMetrics etc, and yet we were required to
before. Splitting it means jumping through less hoops that we don't have
to. :^)
2021-10-05 18:51:39 +02:00
Sam Atkins
fd51b02f9d LibWeb: Implement Window::query_media_feature()
This method provides the needed information to evaluate media queries.

Every feature in Media Queries Level 4 is present, either as code or as
a FIXME: https://www.w3.org/TR/mediaqueries-4/#media-descriptor-table
There's a draft Level 5 which I have ignored for now.

Some are unimplemented for now since we do not have access to the
requested information. Some require StyleValue types that we do not yet
support. Many are hard-coded for now since we do not (and may never)
support monochrome or text-only displays for Browser.
2021-10-05 18:51:39 +02:00
Sam Atkins
de82764f2f LibWeb: Add identifiers used by MEDIAQUERIES-4
To avoid duplicating a lot of functionality, we're using StyleValues for
the values of media-features. So, we need their identifiers added here.
2021-10-05 18:51:39 +02:00
Sam Atkins
68c246368b LibWeb: Predeclare MediaList and CSSRuleList 2021-10-05 18:51:39 +02:00
Sam Atkins
341c67453c LibWeb: Add resolved style lookup for border properties
The only one I didn't implement is `border` itself, because there isn't
an obvious sensible value for it if the borders are different.
2021-10-05 18:49:47 +02:00
Sam Atkins
a521c02db2 LibWeb: Add resolved style lookup for margin/padding shorthands 2021-10-05 18:49:47 +02:00
Sam Atkins
fc7af21c7c LibWeb: Make things aware of box-sizing
Of course, we don't actually *use* the box-sizing property yet, but the
value is applied and shows up in the computed style.
2021-10-05 18:49:47 +02:00
Marco Cutecchia
80e70f95ab PixelPaint: Fix first undo action not working 2021-10-05 15:41:21 +02:00
Marco Cutecchia
c7431da3f2 PixelPaint: Ensure a layer is selected when restoring a snapshot
Previously when restoring the starting snapshot in the UndoStack we
would end up with no layer selected, which was kinda annoying
2021-10-05 15:41:21 +02:00
Andreas Kling
6108bac606 LibJS: Only do a single property lookup in internal_get_own_property()
Instead of checking storage_has(), followed by storage_get(), we can do
storage_get() directly and avoid a redundant property lookup.

This exposed a bug in SimpleIndexedPropertyStorage::get() which would
previously succeed for array holes.
2021-10-05 15:15:29 +02:00
Linus Groh
8074bdc049 LibJS: Skip declarative env in block statement without lexical decls
The idea here is simple: If the block statement doesn't contain any
lexical declarations, we don't need to allocate, initialize and
eventually garbage collect a new declarative environment.
This even makes lookups across nested blocks slightly faster as we don't
have to traverse a chain of empty environments anymore - instead, the
execution context just stores the outermost non-empty one.

This doesn't speed up test-js considerably, but has a noticeable effect
on test262 and real-world web content :^)
2021-10-05 14:52:53 +02:00
Mohsan Ali
d609dde7b0 2048: Let user decide if he wants to continue the game
Before game finish when a player has reached target tile,
Now player will be able to decide if he wants to continue or not
2021-10-05 13:27:57 +03:30
Peter Elliott
285038ebcf LibMarkdown: Add start numbers for ordered lists
5. hey -> <ol start="5"><li>hey</li></ol>
2021-10-05 13:27:25 +03:30
Peter Elliott
a76a23e33b LibMarkdown: Allow spaces before list items
also allow '+' as an unordered list marker
2021-10-05 13:27:25 +03:30
Peter Elliott
0a21c2bace LibMarkdown: Implement "tightness" for lists
From the commonmark spec:
A list is loose if any of its constituent list items are separated by
blank lines, or if any of its constituent list items directly contain
two block-level elements with a blank line between them. Otherwise a
list is tight. (The difference in HTML output is that paragraphs in a
loose list are wrapped in <p> tags, while paragraphs in a tight list are
not.)
2021-10-05 13:27:25 +03:30
Peter Elliott
5bb87c630c LibMarkdown: Allow non-text items in Lists 2021-10-05 13:27:25 +03:30
Peter Elliott
10f6f6a723 LibMarkdown: Add LineIterator
LineIterator wraps a vector's ConstIterator, to provide an iterator that
can work on indented container blocks (like lists and blockquotes).
2021-10-05 13:27:25 +03:30
Peter Elliott
cd560d3ae3 LibMarkdown: Refactor Document's parser into ContainerBlock
This will better allow us too do things like have Lists and blockquotes
support multiple blocks.
2021-10-05 13:27:25 +03:30
Linus Groh
4fa5748093 LibJS: Add an optimization to avoid needless arguments object creation
This gives FunctionNode a "might need arguments object" boolean flag and
sets it based on the simplest possible heuristic for this: if we
encounter an identifier called "arguments" or "eval" up to the next
(nested) function declaration or expression, we won't need an arguments
object. Otherwise, we *might* need one - the final decision is made in
the FunctionDeclarationInstantiation AO.

Now, this is obviously not perfect. Even if you avoid eval, something
like `foo.arguments` will still trigger a false positive - but it's a
start and already massively cuts down on needlessly allocated objects,
especially in real-world code that is often minified, and so a full
"arguments" identifier will be an actual arguments object more often
than not.

To illustrate the actual impact of this change, here's the number of
allocated arguments objects during a full test-js run:

Before:
- Unmapped arguments objects: 78765
- Mapped arguments objects: 2455

After:
- Unmapped arguments objects: 18
- Mapped arguments objects: 37

This results in a ~5% speedup of test-js on my Linux host machine, and
about 3.5% on i686 Serenity in QEMU (warm runs, average of 5).

The following microbenchmark (calling an empty function 1M times) runs
25% faster on Linux and 45% on Serenity:

    function foo() {}
    for (var i = 0; i < 1_000_000; ++i)
        foo();

test262 reports no changes in either direction, apart from a speedup :^)
2021-10-05 10:15:14 +01:00
Linus Groh
fcb355f193 LibJS: Set arguments_object_needed = false if scope_body == nullptr
For obvious reasons.
2021-10-05 10:15:14 +01:00
Linus Groh
b2bded390a LibJS: Stop iterating lexically declared names once 'arguments' is found
In ECMAScriptFunctionObject::function_declaration_instantiation() we
iterate over all lexically declared names of the function scope body to
determine whether any of them is named 'arguments', because we don't
need to create an arguments object in that case. We can also stop at
that point, because the decision won't change anymore.
2021-10-05 10:15:14 +01:00
Linus Groh
3ab22c8012 LibJS: Rename needs_argument_object to arguments_object_needed
- It's an "arguments object", not "argument object"
- This is what the spec calls it (argumentsObjectNeeded)
2021-10-05 10:15:14 +01:00
fleximus
3115a5306d LookupServer: Fix to handle whitespaces and tabs in /etc/hosts 2021-10-05 02:23:45 +02:00
Jan de Visser
fe50598a03 LibSQL: Allow expressions and column names in SELECT ... FROM
Up to now the only ``SELECT`` statement that worked was ``SELECT *
FROM <table>``. This commit allows a column list consisting of
column names and expressions in addition to ``*``. ``WHERE``
still doesn't work though.
2021-10-05 02:22:19 +02:00
Jan de Visser
f33a288ca4 SQL Utility: Implement reading sql files
Add a number of command line switches:
- '-r/--read': Read a SQL file and quit the REPL when done
- '-s/--source': Read a SQL file and return to a SQL prompt when done
- '--no-sqlrc': Do not read ~/.sqlrc on startup (see below)

Add a dot-command:
.read <filename>: Read a SQL file and return to a SQL prompt when done

In addition, the sql REPL will source the ~/.sqlrc file on startup if
it exists, unless the --no-sqlrc flag is set on startup.

Note the slight asymmetry between the --read command line flag (which
results in the program quitting when the file is read) and the .read
command (which doesn't cause a quit).

Also fix merge conflict with #10091
2021-10-05 02:22:19 +02:00
Jan de Visser
89835ec83c SQL Utility: Redesigned the input loop
The existing input loop called the `read_sql` method recursively. This
lead to strange behaviour in the event loop. This is solved by
encapsulating the REPL in an object and ensuring the `read_sql` method
is not called recursively. The method now returns after the first
recognized SQL statement or command.
2021-10-05 02:22:19 +02:00
Jan de Visser
9d9f082221 SQL Utility: Implement connection switching
You can now connect to a different database using the .connect meta
command.
2021-10-05 02:22:19 +02:00
Jan de Visser
e923cb3739 SQLServer+SQL+LibSQL: Allow sql client to specify the database name
The database the sql client connected to was 'hardcoded' to the login
name of the calling user.
- Extended the IPC API to be more expressive when connecting, by
returning the name of the database the client connected to in the
'connected' callback.
- Gave the sql client a command line argument (-d/--database) allowing
an alternative database name to be specified

A subsequent commit will have a dot command allowing the user to
connect to different databases from the same sql session.
2021-10-05 02:22:19 +02:00
Jan de Visser
c5c7a9d198 SQLServer: Do not capture stack variables by reference in lambdas
If you capture a stack variable by reference in a lamdba definition,
and this lambda outlives the scope of the stack variable, this reference
may point to garbage when the lambda is executed. Therefore capture as
little as possible (typically only ``this``), and what is captured is
captured by value
2021-10-05 02:22:19 +02:00
Ben Wiederhake
52e9f25403 Everywhere: Change from http to https where feasible
I used "git grep -FIn http://" to find all occurrences, and looked at
each one. If an occurrence was really just a link, and if a https
version exists, and if our Browser can access it at least as well as the
http version, then I changed the occurrence to https.

I'm happy to report that I didn't run into a single site where Browser
can't deal with the https version.
2021-10-05 02:08:08 +02:00
Andreas Kling
d872f0d503 LibJS: Avoid an unnecessary String in create_mapped_arguments_object() 2021-10-04 22:54:50 +02:00
Andreas Kling
f4180b7269 LibJS: Avoid an unnecessary String in create_list_from_array_like() 2021-10-04 22:54:50 +02:00
Andreas Kling
a31855ae10 LibWeb: Improve resolved style for CSS {min,max}-{width,height}
If the specified value for these properties is "none", we end up storing
it as an "undefined" CSS::Length in the computed values.

We need to convert it back into "none" for getComputedStyle().
2021-10-04 22:54:50 +02:00
Idan Horowitz
4bd089616e LibWeb: Implement window.location's stringifier
The location IDL interface includes a stringifier on the href
attribute i.e. the object's toString should return the value of the
href attribute.
2021-10-04 18:42:58 +01:00
Tobias Christiansen
0c0951d2ce LibWeb: Flexbox: Don't outgrow parent in main axis when using wrap 2021-10-04 18:54:52 +02:00
Tobias Christiansen
6283086c2f LibWeb: Handle inline-block children of a flex-container as block
We don't want to wrap the inline-blocks the same way we want to wrap
pure inline children.
2021-10-04 18:54:52 +02:00
Tobias Christiansen
6102a486ee LibWeb: Flexbox: Collect empty inline-block flex children
A flex-child that was display:inline-block but also had no text inside
of it was previously skipped.
2021-10-04 18:54:52 +02:00
Ali Mohammad Pur
5b185d9cb5 LibHTTP: Bump max HTTP header size up to 32KiB
Apparently discord likes to feed us headers as big as 6KiB, so clearly
there are large headers out there in the wild.
For reference, Apache's limit is 8KiB, and IIS's limit is 16KiB (this
limit is not defined by the spec, so nothing can stop a server from
sending massive headers - sadly)
2021-10-04 18:26:16 +02:00
Mahmoud Mandour
aca87ce146 sql: Account for the single quotes in syntax highlighting
Previously, a String literal token like 'hello' had every char
highlighted but for the last 'o' and the closing single quote. This is
because the token start is at the opening single quote but the `length`
variable only accounted for the value length without the single quotes.
2021-10-04 15:51:48 +02:00
Mahmoud Mandour
0906e3c206 LibSQL: Check data types in INSERT statement parsing
Data types are now checked against the table data types. When multiple
rows are inserted at once, we check all rows to be matching W.R.T data
types. Only then we insert the rows.
2021-10-04 15:51:48 +02:00
Mahmoud Mandour
f390478127 LibSQL: Parse INSERT statement without column names
This adds the ability to parse SQL INSERT statements in the following
form:

    INSERT INTO schema.tablename VALUES (column1, column2, ...),
                                        (column1, column2, ...), ...
2021-10-04 15:51:48 +02:00
Ali Mohammad Pur
64e231bd38 LibHTTP+LibGemini: Set underlying sockets as idle when detaching
This ultimately makes the sockets not spin while unused (particularly in
the 10s shutdown period that RequestServer's cache has).
2021-10-04 15:31:26 +02:00
Ali Mohammad Pur
29acb7fcf8 LibCore: Add a Socket::set_idle() API that turns the notifiers on/off
When a socket's user doesn't need it to be active, but wants to keep it
open, the socket's notifiers should not be enabled to avoid hogging the
CPU with effectively useless notifications.
This API can be used to disable said notifiers until the user needs the
notifications.
2021-10-04 15:31:26 +02:00
Ali Mohammad Pur
830b0e8f2d LibHTTP: Treat EOF on a non-Finished state as an error 2021-10-04 15:31:26 +02:00
Tobias Christiansen
873e95cb6a LibWeb: Flexbox: Care more about cross-axis margins
Auto margins are still not supported at all, but this is a good start
into supporting margins on flex items.
The way cross-before (top for row, left for column) is handled is very
naive.
2021-10-04 13:59:28 +02:00
Tobias Christiansen
9af85881f5 LibWeb: Flexbox: Take parents' specified main size into account
Previously, if the parent of the container had a definite main size, it
would've been disregarded when calculating the main size of the
container if it had no definite size and neither min- nor max-main-size
constraints.
This patch fixes that behavior by additionally checking whether the main
size is not only not constrained but also infinite.
2021-10-04 13:35:36 +02:00