Commit graph

13706 commits

Author SHA1 Message Date
Lenny Maiorani 18a40587ea HashFunctions: constexpr capability
Problem:
- Hash functions can be `constexpr`, but are not.

Solution:
- Change `inline` keyword to `constexpr`.
- Add `static_assert` tests to ensure the hash functions work in a
  `constexpr` context.
2020-10-21 19:42:12 +02:00
Lenny Maiorani 070fc69562 TestHashFunctions: Tests to bind hash functionality
Problem:
- The hash functions have no associated tests, so there is nothing
  binding their behavior.

Solution:
- Bind the hash function behavior by adding tests.
- Use the existing behavior as "correct".
2020-10-21 19:42:12 +02:00
Linus Groh 1e86379327 LibJS: Rest parameter in setter functions is a syntax error 2020-10-20 20:27:58 +02:00
Linus Groh 6331d45a6f LibJS: Move checks for invalid getter/setter params to parse_function_node
This allows us to provide better error messages as we can point the
syntax error location to the exact first invalid parameter instead of
always the end of the function within a object literal or class
definition.

Before this change:

    const Foo = { set bar() {} }
                               ^
    Uncaught exception: [SyntaxError]: Object setter property must have one argument (line: 1, column: 28)

    class Foo { set bar() {} }
                             ^
    Uncaught exception: [SyntaxError]: Class setter method must have one argument (line: 1, column: 26)

After this change:

    const Foo = { set bar() {} }
                          ^
    Uncaught exception: [SyntaxError]: Setter function must have one argument (line: 1, column: 23)

    class Foo { set bar() {} }
                        ^
    Uncaught exception: [SyntaxError]: Setter function must have one argument (line: 1, column: 21)

The only possible downside of this change is that class getters/setters
and functions in objects are not distinguished in the message anymore -
I don't think that's important though, and classes are (mostly) just
syntactic sugar anyway.
2020-10-20 20:27:58 +02:00
Linus Groh db75be1119 LibJS: Refactor parse_function_node() bool parameters into bit flags
I'm about to add even more options and a bunch of unnamed true/false
arguments is really not helpful. Let's make this a single parse options
parameter using bit flags.
2020-10-20 20:27:58 +02:00
Andreas Kling 50f8f27ac6 Userland: Run clang-format on tree.cpp 2020-10-20 19:19:30 +02:00
Andreas Kling f5f99ccd6a WindowServer: Return some event members by const reference 2020-10-20 18:10:22 +02:00
Andreas Kling c8c7db8c33 LibC: Fix a warning when building LibC with -O2 2020-10-20 18:10:22 +02:00
Andreas Kling ce6ef54337 ICMP: Check that incoming ICMP echo requests are large enough
Otherwise, just ignore them.
2020-10-20 18:10:10 +02:00
Andreas Kling 0af2795662 LibWeb: Tear down layout trees properly
Instead of just ripping out the root of the layout tree from its RefPtr
in Document, actually go through the DOM and gather up all the layout
nodes. Then destroy them all in one swoop.

Also, make sure to do this when detaching Document from Frame,
to enforce the invariant that layout only occurs in framed documents.
2020-10-20 18:08:37 +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
Lenny Maiorani a40abd6ce3 Checked: constexpr support
Problem:
- `Checked` is not `constexpr`-aware.

Solution:
- Decorate member functions with `constexpr` keyword.
- Add tests to ensure the functionality where possible.
2020-10-20 16:31:24 +02:00
Lenny Maiorani bd99083436 Checked: Use default compiler-generated functions
Problem:
- Compiler-generated functions are being defined which results in
  extra code to maintain.

Solution:
- Switch to compiler-generated default functions for default
  construction, copy assignment, move assignment, copy construction
  and move construction.
2020-10-20 16:31:24 +02:00
Laurent Cimon b4790010a8 Build: Modify various parts to allow the build to succeed on FreeBSD 2020-10-20 14:40:47 +02:00
Linus Groh a82c56f9f7 LibJS: Speed up IndexedPropertyIterator by computing non-empty indices
This provides a huge speed-up for objects with large numbers as property
keys in some situation. Previously we would simply iterate from 0-<max>
and check if there's a non-empty value at each index - now we're being
smarter and compute a list of non-empty indices upfront, by checking
each value in the packed elements vector and appending the sparse
elements hashmap keys (for GenericIndexedPropertyStorage).

Consider this example, an object with a single own property, which is a
number increasing by a factor of 10 each iteration:

    for (let i = 0; i < 10; ++i) {
        const o = {[10 ** i]: "foo"};
        const start = Date.now();
        Object.getOwnPropertyNames(o);  // <-- IndexedPropertyIterator
        const end = Date.now();
        console.log(`${10 ** i} -> ${(end - start) / 1000}s`);
    }

Before this change:

    1 -> 0.0000s
    10 -> 0.0000s
    100 -> 0.0000s
    1000 -> 0.0000s
    10000 -> 0.0005s
    100000 -> 0.0039s
    1000000 -> 0.0295s
    10000000 -> 0.2489s
    100000000 -> 2.4758s
    1000000000 -> 25.5669s

After this change:

    1 -> 0.0000s
    10 -> 0.0000s
    100 -> 0.0000s
    1000 -> 0.0000s
    10000 -> 0.0000s
    100000 -> 0.0000s
    1000000 -> 0.0000s
    10000000 -> 0.0000s
    100000000 -> 0.0000s
    1000000000 -> 0.0000s

Fixes #3805.
2020-10-20 08:51:41 +02:00
Andreas Kling 0e900ca5df LibX86: clang-format 2020-10-20 08:41:59 +02:00
Nico Weber 2c82b69bd7 LibX86: malloc a bit less
This reduces malloc()/free() calls in `disasm /bin/id` by 30%
according to LIBC_DUMP_MALLOC_STATS.

No measurable performance change (the number of empty block hits
remains unchanged, and that's what's slow), but maybe a nice
change regardless?
2020-10-19 22:44:24 +02:00
Linus Groh 8fe89cf441 Toolchain: Set CACHED_TOOLCHAIN_ARCHIVE after computing hash 2020-10-19 21:11:39 +02:00
Andreas Kling be4005cb9e Profiler: Implement "Top functions" feature like Instruments.app has
This view mode takes every stack frame and turns it into a root in the
profile graph. This allows functions that are called from many places
to bubble up to the top. It's a very handy way to discover heavy things
in a profile that are otherwise obscured by having many callers.
2020-10-19 20:08:57 +02:00
Linus Groh 46cc1f718e LibJS: Unprefixed octal numbers are a syntax error in strict mode 2020-10-19 20:08:22 +02:00
Linus Groh 602eb98479 Toolchain: Remove cached archive and rebuild if extracting fails
This is currently the case on Travis CI: the file exists but fails to
extract, breaking all the CI builds.
2020-10-19 20:06:59 +02:00
Linus Groh e898c98873 LibJS: Don't parse arrow function with newline between ) and =>
If there's a newline between the closing paren and arrow it's not a
valid arrow function, ASI should kick in instead (it'll then fail with
"Unexpected token Arrow")
2020-10-19 11:31:55 +02:00
Linus Groh 965d952ff3 LibJS: Share parameter parsing between regular and arrow functions
This simplifies try_parse_arrow_function_expression() and fixes a few
cases that should not produce an arrow function AST but did:

    (a,,) => {}
    (a b) => {}
    (a ...b) => {}
    (...b a) => {}

The new parsing logic checks whether parens are expected and uses
parse_function_parameters() if so, rolling back if a new syntax error
occurs during that. Otherwise it's just an identifier in which case we
parse the single parameter ourselves.
2020-10-19 11:31:55 +02:00
Linus Groh aa68de3530 LibJS: Fix dump() indentation of UpdateExpression with suffix operator 2020-10-19 11:31:55 +02:00
Linus Groh 2dbea60fe2 LibJS: Multiple 'default' clauses in switch statement are a syntax error 2020-10-19 11:30:14 +02:00
Linus Groh 57e7b2f8e4 Base: Update test-js(1) man page 2020-10-19 11:29:55 +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
Andreas Kling 69a015cd9a Documentation: Remove outdated comment about global git identity
This was used by the toolchain build script at one point but is now
only used when running BuildIt.sh with --dev.
2020-10-18 20:33:02 +02:00
Andreas Kling 57c2da1f86 Documentation: Remove "flock" from dependencies
The build system no longer uses "flock", so stop telling people they
need to install it.
2020-10-18 20:33:02 +02:00
Linus Groh f8886ef5ba LibJS: Handle continue in switch statement unwinding 2020-10-18 19:08:52 +02:00
Linus Groh 8f54edb7a0 LibJS: Handle return value in switch statement unwinding
Fixes #3790.
2020-10-18 19:08:52 +02:00
Stephan Unverwerth 2c888b3c6e LibJS: Fix parsing of invalid numeric literals
i.e. "1e" "0x" "0b" "0o" used to be parsed as valid literals.
They now produce invalid tokens. Fixes #3716
2020-10-18 15:38:57 +02:00
Dano Perniš 3efd4c105f AK: Reduce memory writes in HashTable destructor 2020-10-18 14:44:23 +02:00
Dano Perniš d30c559774 AK: Implement HashTable assignment in terms of swap 2020-10-18 14:44:23 +02:00
Dano Perniš 7f3f63dd92 AK: Provide swap() for HashTable 2020-10-18 14:44:23 +02:00
Andreas Kling af20b9424f Kernel: Unbreak /proc/interrupts when running with APIC
We can't assert here since these are exposed through /proc JSON.
2020-10-18 14:40:16 +02:00
Andreas Kling c7a13b7a74 Kernel: Tweak strange PAGE_ROUND_UP(1) in APIC code 2020-10-18 14:18:38 +02:00
Andreas Kling 24162127ba LibWeb: Dispatch "load" on document and window
These happen right after "DOMContentLoaded" for now, which is incorrect
since they should really wait until subresources have loaded.
However, this makes a bunch of things work already so let's do it.
2020-10-18 13:45:28 +02:00
Andreas Kling b71c1851b7 LibWeb: Dispatch "load" event on script elements 2020-10-18 13:44:20 +02:00
Andreas Kling b92bc9c6e5 LibWeb: Make DOM::Window into an EventTarget
This will allow us to dispatch window events.
2020-10-18 13:43:44 +02:00
Andreas Kling 77c1957961 LibJS: Use allocate_without_global_object for allocating Shapes 2020-10-17 23:47:07 +02:00
Andreas Kling d8269c343c LibJS: Avoid creating temporary Strings to look up tokens while lexing
It would be cool to solve this in a general way so that looking up
a string literal or StringView in a HashMap with String keys avoids
creating a temp string.

For now, this patch simply addresses the issue in JS::Lexer.
This is a 2-3% speed-up on test-js.
2020-10-17 23:44:41 +02:00
Andreas Kling d3dfd55472 LibJS: Prebake the empty object ({}) with a prototype
Instead of performing a prototype transition for every new object we
create via {}, prebake the object returned by Object::create_empty()
with a shape with ObjectPrototype as the prototype.

We also prebake the shape for the object assigned to the "prototype"
property of new ScriptFunction objects, since those are extremely
common and that code broke from this change anyway.

This avoid a large number of transitions and is a small speed-up on
test-js.
2020-10-17 23:23:53 +02:00
Lenny Maiorani 919fc7a814 CircularQueue: Ensure constructor does not construct any values
Problem:
- There is no test which guarantees the CircularQueue does not
  construct any objects of the value type. The goal is to have
  uninitialized memory which can be used.

Solution:
- Add a test requiring that the constructor of the value type is never
  called.
2020-10-17 23:21:00 +02:00
asynts c9ca897a45 LibCore: Use new format functions in some places. 2020-10-17 23:20:31 +02:00
asynts 43e37c7cde LibChess: Use new format functions. 2020-10-17 23:20:31 +02:00