Commit graph

29072 commits

Author SHA1 Message Date
Andreas Kling 3b0da8b28c LibWeb: Add a missing null check in StyleComputer::compute_font() 2021-10-09 16:35:25 +02:00
Linus Groh 9d352c602c LibJS: Add callee realm fallback to ordinary_call_bind_this()
This makes ECMAScriptFunctionObject calls in the bytecode interpreter
work again (regressed in #10402).
2021-10-09 15:18:29 +01:00
Ali Mohammad Pur b9ffa0ad2e LibRegex: Transform 0,1 min/unbounded max repetitions to * or +
The implementation of transform_bytecode_repetition_min_max expects at
least min=1, so let's also optimise on our way out of a bug where
'x{0,}' would cause a crash.
2021-10-09 15:57:05 +02:00
huwdp ec43f7a2b0 LibWeb: Add initial version of pointer-events CSS property 2021-10-09 14:48:30 +01:00
Linus Groh fe5c2b7bb9 LibJS: Decouple new_function_environment() from FunctionObject
Now that only ECMAScriptFunctionObject uses this, we can remove the
FunctionObject::new_function_environment() pure virtual method and just
implement it as a standalone AO with an ECMAScriptFunctionObject
parameter, next to the other NewFooEnvironment AOs.
2021-10-09 14:29:20 +01:00
Linus Groh 53af66d57d LibJS: Move ordinary_call_bind_this() to ECMAScriptFunctionObject
Now that it only needs to deal with ECMAScriptFunctionObject via
internal_call() / internal_construct(), we can:

- Remove the generic FunctionObject parameter
- Move it from the VM to ECMAScriptFunctionObject
- Make it private
2021-10-09 14:29:20 +01:00
Linus Groh 25bcd36116 LibJS: Move prepare_for_ordinary_call() to ECMAScriptFunctionObject
Now that it only needs to deal with ECMAScriptFunctionObject via
internal_call() / internal_construct(), we can:

- Remove the generic FunctionObject parameter
- Move it from the VM to ECMAScriptFunctionObject
- Make it private
2021-10-09 14:29:20 +01:00
Linus Groh cf168fac50 LibJS: Implement [[Call]] and [[Construct]] internal slots properly
This patch implements:

- Spec compliant [[Call]] and [[Construct]] internal slots, as virtual
  FunctionObject::internal_{call,construct}(). These effectively replace
  the old virtual FunctionObject::{call,construct}(), but with several
  advantages:
  - Clear and consistent naming, following the object internal methods
  - Use of completions
  - internal_construct() returns an Object, and not Value! This has been
    a source of confusion for a long time, since in the spec there's
    always an Object returned but the Value return type in LibJS meant
    that this could not be fully trusted and something could screw you
    over.
  - Arguments are passed explicitly in form of a MarkedValueList,
    allowing manipulation (BoundFunction). We still put them on the
    execution context as a lot of code depends on it (VM::arguments()),
    but not from the Call() / Construct() AOs anymore, which now allows
    for bypassing them and invoking [[Call]] / [[Construct]] directly.
    Nothing but Call() / Construct() themselves do that at the moment,
    but future additions to ECMA262 or already existing web specs might.
- Spec compliant, standalone Call() and Construct() AOs: currently the
  closest we have is VM::{call,construct}(), but those try to cater to
  all the different function object subclasses at once, resulting in a
  horrible mess and calling AOs with functions they should never be
  called with; most prominently PrepareForOrdinaryCall and
  OrdinaryCallBindThis, which are only for ECMAScriptFunctionObject.

As a result this also contains an implicit optimization: we no longer
need to create a new function environment for NativeFunctions - which,
worth mentioning, is what started this whole crusade in the first place
:^)
2021-10-09 14:29:20 +01:00
Linus Groh 58c34012dd LibJS: Pop execution context after running queued jobs in run()
These would crash starting with the next commit otherwise, calling a
function always requires the running execution context to exist.
2021-10-09 14:29:20 +01:00
Linus Groh 72f5252826 LibJS: Forward BoundFunction::has_constructor() to bound target function
A BoundFunction only implements [[Construct]] (has_constructor() in
LibJS) if its bound target function does.
2021-10-09 14:29:20 +01:00
Linus Groh 7fc2807929 LibJS: Add Completion::is_abrupt()
This is commonly used in the spec.
2021-10-09 14:29:20 +01:00
Maciej c58d51ce40 Base: Add all Latin-1 Supplement glyphs to KaticaBold12 2021-10-09 14:43:27 +02:00
Maciej 6331da6469 Base: Add all Latin-1 Supplement glyphs to KaticaRegular12 2021-10-09 14:43:27 +02:00
Maciej 32015be34a Base: Add some new characters to Katica*10.font
This commit adds the following characters to Katica 10 fonts:
- U+2010 HYPHEN, U+2012 FIGURE DASH, U+2013 EN DASH,
  U+2014 EM DASH (Bold), U+2020 DAGGER, U+2021 DOUBLE DAGGER,
  U+2022 BULLET, U+2023 TRIANGULAR BULLET, U+2024 ONE DOT LEADER,
  U+2025 TWO DOT LEADER, U+2030 PER MILLE SIGN, U+2039 SINGLE LEFT-
  POINTING QUOTATION MARK, U+2040 SINGLE RIGHT-POINTING QUOTATION
  MARK, U+203B REFERENCE MARK and U+203C DOUBLE EXCLAMATION MARK.
2021-10-09 14:43:27 +02:00
Linus Groh 12b634a91e LibWeb: Fix WebAssembly.Memory.prototype.buffer build 2021-10-09 13:03:40 +01:00
Linus Groh 5b61b60bbd LibJS: Use AllocateArrayBuffer where the spec tells us to 2021-10-09 12:36:28 +01:00
Linus Groh 1fba5ca8c3 LibJS: Implement the AllocateArrayBuffer() AO
This should be used instead of ArrayBuffer::create() in most places, as
it uses OrdinaryCreateFromConstructor to allow for a custom prototype.

The data block (ByteBuffer) is allocated separately and attached
afterwards, if we didn't fail due to OOM.
2021-10-09 12:36:28 +01:00
Liav A f8489da8ee Kernel/SysFS: Provide a way to "truncate" and "set" mtime on inodes
Normally, trying to truncate a SysFSInode should result in EPERM error.
However, as suggested by Ali (@alimpfard), we can allow the PowerState
node to be "truncated" so one can open that file with O_TRUNC option.
Likewise, we also need to provide a way to set modified time on SysFS
inodes. For most inodes, we should return ENOTIMPL error, but for the
power state switch, we ignore the modified time setting and just return
KSuccess.

These fixes allow to do "echo -n 1 > /sys/firmware/power_state" in Shell
after gaining root permissions, to switch the power state.
2021-10-09 12:07:56 +02:00
David Isaksson 7269ce15fc Base: Add man page for blockdev utility 2021-10-09 12:06:47 +02:00
David Isaksson 410d81706d Utilities: Add way to get a storage devices block size in blockdev 2021-10-09 12:06:47 +02:00
David Isaksson b2e57f555b Kernel: Add ioctl request for getting a storage device's block size 2021-10-09 12:06:47 +02:00
David Isaksson 8d631dcd5e Utilities: Add blockdev utility
This new utility queries a block device for its size via the newly
introduced ioctl STORAGE_DEVICE_GET_SIZE request.
2021-10-09 12:06:47 +02:00
David Isaksson 3b089032f4 Kernel: Add STORAGE_DEVICE_GET_SIZE ioctl request
This ioctl request makes it possible to get the size of a storage device
that has not yet been mounted.
2021-10-09 12:06:47 +02:00
David Isaksson 88eb7a634f LibMarkdown: Have one newline between lists in terminal renders
Before this patch the markdown lists would have two space inbetween each
item. This patch removes one of these newlines for a nicer render.
2021-10-09 12:05:38 +02:00
Liav A 741c871bc1 Kernel/Storage: Unify all ATA devices
There's basically no real difference in software between a SATA harddisk
and IDE harddisk. The difference in the implementation is for the host
bus adapter protocol and registers layout.
Therefore, there's no point in putting a distinction in software to
these devices.

This change also greatly simplifies and removes stale APIs and removes
unnecessary parameters in constructor calls, which tighten things
further everywhere.
2021-10-09 01:39:55 +02:00
Ralf Donau 9f501d7e71 Base: Fix typo in the proc(7) manpage 2021-10-09 01:39:03 +02:00
Andreas Kling eafbf372d0 LibJS: Elide empty declarative environments inside switch statements
Most switch statements don't have any lexically scoped declarations,
so let's avoid allocating an environment in the common case where we
don't have to.
2021-10-09 00:42:10 +02:00
Nico Weber 9d06448bc7 Shell: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
Nico Weber f46a40a471 Utilities: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
Nico Weber b8dc3661ac Libraries: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
Nico Weber 96666f3209 Tests: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
Nico Weber 1cdb12e920 Kernel: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
Liav A e84c03ad61 Base: Add 2 manual pages to describe the ProcFS and SysFS 2021-10-08 23:33:38 +02:00
Sam Atkins 5098cd22a4 LibWeb: Evaluate @media rules
We now evaluate the conditions of `@media` rules at the same point in
the HTML event loop as evaluation of `MediaQueryList`s. This is not
strictly to spec, but since the spec doesn't actually say when to do
this, it seems to make the most sense. In any case, it works! :^)
2021-10-08 23:02:57 +02:00
Sam Atkins 57a25139a5 LibWeb: Implement @supports rule :^)
The main thing missing is that we don't serialize the supports clause,
but for actually using a `@supports (something: cool) {}` rule in CSS,
it works!
2021-10-08 23:02:57 +02:00
Sam Atkins 439d978ea5 LibWeb: Make style-rule iteration aware of CSSMediaRule
The logic is handled by `CSSGroupingRule` and `CSSConditionRule`, so
`CSSMediaRule` only has to report if its condition matches.

Right now, that condition is always false because we do not evaluate the
media query.
2021-10-08 23:02:57 +02:00
Sam Atkins df08b25b3f LibWeb: Move CSSRule iteration to CSSRuleList
CSSStyleSheet is no longer the only class that contains a list of rules,
so this will save duplicating the logic in multiple places.
2021-10-08 23:02:57 +02:00
Sam Atkins bc0ef5f69d LibWeb: Implement CSS.supports(string) function :^)
Websites being able to query whether we support a given CSS feature
should prevent them from loading unnecessary polyfills for things we
already support! Or at least, that's the nice theory. :^)
2021-10-08 23:02:57 +02:00
Sam Atkins b1f8a73a05 LibWeb: Parse CSS Supports
... according to
https://www.w3.org/TR/css-conditional-3/#typedef-supports-condition

This works very similarly to `@media`, but is different enough to
require its own parsing. (Though, the draft of Conditional-4 currently
mentions combining the two into a `@when` rule.)

Made some small changes to parsing code to make this work. Notably,
making `consume_a_declaration()` fail gracefully instead of
`VERIFY()`ing.
2021-10-08 23:02:57 +02:00
Sam Atkins 87a30418bf LibWeb: Add CSS 'Supports' class
The name is a little awkward, but this corresponds to the condition of a
`@supports` rule or the `CSS.supports("")` function.

A supports query only gets evaluated once, since its condition cannot
change during runtime. (We either support something or we don't, and the
spec specifically mentions that user preferences that disable features
do not affect the result here.) We keep a representation of it around
though, so that it can be serialized if needed. This is a little awkward
since we hold onto a `StyleDeclarationRule` which should be an internal
Parser class. This means making some Parser functions more public.

Potentially we could evaluate the Supports inside the Parser, and have
it only store a String representation of itself. But this works for now.
:^)
2021-10-08 23:02:57 +02:00
Sam Atkins 2a2efdedf7 Base: Add CSS.supports / @supports {} test-page 2021-10-08 23:02:57 +02:00
Sam Atkins 2b67f87629 LibWeb: Implement 2-argument version of CSS.supports()
This version takes a property name and value as separate parameters.
2021-10-08 23:02:57 +02:00
Sam Atkins 575ce04148 LibWeb: Add CSS.escape() JS function
This is the `CSS` namespace defined in IDL here:
https://www.w3.org/TR/cssom-1/#namespacedef-css , not to be confused
with our `Web::CSS` namespace. Words are hard.

`CSS.escape()` lets you escape identifiers that can then be used to
create a CSS string.

I've also stubbed out the `CSS.supports()` function.
2021-10-08 23:02:57 +02:00
Andreas Kling 3c0b55c284 LibWeb: Add DOMRectReadOnly and make DOMRect inherit from it
This matches the class hierarchy of the CSS Geometry Interfaces Module.
2021-10-08 23:00:49 +02:00
Andreas Kling 77f72c7cfe AK: Always inline the RefCountedBase functions 2021-10-08 22:11:39 +02:00
Andreas Kling 2495460f6e LibJS: Prune WeakContainers before freeing HeapBlocks
WeakContainers need to look at the Cell::State bits to know if their
weak pointees got swept by garbage collection. So we must do this before
potentially freeing one or more HeapBlocks by notifying the allocator
that a block became empty.
2021-10-08 19:47:25 +02:00
Ali Mohammad Pur 13138811df LibJS: Partially revert 12b283f
This commit partially reverts "LibJS: Make accessing the current
function's arguments cheaper".
While the change passed all the currently passing test262 tests, it
seems to have _some_ flaw that silently breaks with some real-world
websites.
As the speedup with negligible at best, let's just revert it until we
can implement it more correctly.
2021-10-08 19:56:02 +03:30
Andreas Kling fa6c06ce8d LibJS: Elide some declarative environments in ECMAScript function calls
By spec, calling an ECMAScript function object in non-strict mode should
always create a new top-level declarative environment, even if there are
no lexically scoped bindings (let/const) that belong in it. This is
used for scope disambiguation in direct eval() calls.

However, if there are no direct eval() calls within the function, and no
lexically scoped bindings, we can simply not allocate the extra
environment and save ourselves the trouble.
2021-10-08 15:00:34 +02:00
Andreas Kling b2de563166 LibJS: Propagate "contains direct call to eval()" flag from parser
We now propagate this flag to FunctionDeclaration, and then also into
ECMAScriptFunctionObject.

This will be used to disable optimizations that aren't safe in the
presence of direct eval().
2021-10-08 12:43:38 +02:00
Ali Mohammad Pur 12b283f32f LibJS: Make accessing the current function's arguments cheaper
Instead of going through an environment record, make arguments of the
currently executing function generate references via the argument index,
which can later be resolved directly through the ExecutionContext.
2021-10-08 12:25:24 +02:00